961595952d8d59e120e1c6800540056dfd3a434d
[qtrapids] / src / gui / MainWindow.cpp
1 /***************************************************************************
2  *   Copyright (C) 2009 by Lassi Väätämöinen   *
3  *   lassi.vaatamoinen@ixonos.com   *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) any later version.                                   *
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19  ***************************************************************************/
20
21
22 #include <QDebug>
23
24 #include <QMenuBar>
25 #include <QToolBar>
26 #include <QAction>
27 #include <QFileDialog>
28 #include <QMessageBox>
29
30 #include "DownloadView.h"
31 #include "SeedView.h"
32 #include "AlertWaiterThread.h"
33
34 #include "MainWindow.h"
35
36
37 const QString ABOUT_TEXT 
38         = QString(QObject::trUtf8("QtRapids, a simple BitTorrent client based on"
39                 "\nQt and Libtorrent."
40                 "\n\nURL: http://qtrapids.garage.maemo.org/"
41                 "\n\nAuthor(s):\nLassi Väätämöinen, lassi.vaatamoinen@ixonos.com"
42                 "\n\nIxonos Plc, Finland\n"));
43
44
45
46 MainWindow::MainWindow():
47         QMainWindow(), // Superclass
48         tabWidget_(NULL),
49         dlView_(NULL),
50         seedView_(NULL)
51 {
52         
53         // MENUBAR 
54         QMenuBar *menuBar = new QMenuBar();
55         QMenu *tempMenu = NULL;
56         
57         tempMenu = menuBar->addMenu(tr("&File"));
58         tempMenu->addAction(tr("&Open"));
59         
60         tempMenu = menuBar->addMenu(tr("&Help"));
61         QAction *aboutAction = tempMenu->addAction(tr("&About"));
62         QAction *aboutQtAction = tempMenu->addAction(tr("About &Qt"));
63         
64         setMenuBar(menuBar);
65         connect(aboutAction, SIGNAL(triggered()), this, SLOT(on_aboutAction_clicked()));
66         connect(aboutQtAction, SIGNAL(triggered()), this, SLOT(on_aboutQtAction_clicked()));
67         
68         
69         // TABWIDGET (central widget)
70         tabWidget_ = new QTabWidget();
71         
72         /// @todo Exception handling
73         dlView_ = new DownloadView(this);
74         seedView_ = new SeedView(this);
75         
76         tabWidget_->addTab(dlView_, tr("Downloads"));
77         tabWidget_->addTab(seedView_, tr("Seeds"));
78         
79         // Tab widget as central widget.
80         setCentralWidget(tabWidget_);
81         
82         
83         // TOOLBAR
84         QToolBar *toolBar = new QToolBar();
85         toolBar->addAction(tr("Open"));
86         
87         addToolBar(Qt::TopToolBarArea, toolBar);
88         connect(toolBar, SIGNAL(actionTriggered(QAction*)), this, SLOT(handleToolBarAction(QAction*)));
89         
90         alertWaiter_ = new AlertWaiterThread(this);
91         connect(alertWaiter_, SIGNAL(alert()), this, SLOT(on_alert()));
92         alertWaiter_->start();
93 }
94
95
96 MainWindow::~MainWindow()
97 {
98 }
99
100
101 void MainWindow::on_aboutAction_clicked()
102 {
103         QMessageBox::about(this, tr("About QtRapids"), ABOUT_TEXT); 
104 }
105                 
106 void MainWindow::on_aboutQtAction_clicked()
107 {
108         QMessageBox::aboutQt (this, tr("About Qt"));
109 }
110
111
112 void MainWindow::handleToolBarAction(QAction* action)
113 {
114         if (action->text() == "Open") {
115                 QFileDialog *dialog = new QFileDialog( this, "Open torrent file", QString(), tr("Torrent files (*.torrent)"));
116                 dialog->setFileMode(QFileDialog::ExistingFile);
117                 dialog->show();
118         } else {
119         }
120 }
121
122 void MainWindow::on_alert()
123 {
124         qDebug() << "MainWindow: got alert()";
125 }