1 /***************************************************************************
2 * Copyright (C) 2009 by Lassi Väätämöinen *
3 * lassi.vaatamoinen@ixonos.com *
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. *
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. *
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 ***************************************************************************/
27 #include <QFileDialog>
28 #include <QMessageBox>
30 #include "DownloadView.h"
32 #include "AlertWaiterThread.h"
34 #include "MainWindow.h"
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"));
46 MainWindow::MainWindow():
47 QMainWindow(), // Superclass
54 QMenuBar *menuBar = new QMenuBar();
55 QMenu *tempMenu = NULL;
57 tempMenu = menuBar->addMenu(tr("&File"));
58 tempMenu->addAction(tr("&Open"));
60 tempMenu = menuBar->addMenu(tr("&Help"));
61 QAction *aboutAction = tempMenu->addAction(tr("&About"));
62 QAction *aboutQtAction = tempMenu->addAction(tr("About &Qt"));
65 connect(aboutAction, SIGNAL(triggered()), this, SLOT(on_aboutAction_clicked()));
66 connect(aboutQtAction, SIGNAL(triggered()), this, SLOT(on_aboutQtAction_clicked()));
69 // TABWIDGET (central widget)
70 tabWidget_ = new QTabWidget();
72 /// @todo Exception handling
73 dlView_ = new DownloadView(this);
74 seedView_ = new SeedView(this);
76 tabWidget_->addTab(dlView_, tr("Downloads"));
77 tabWidget_->addTab(seedView_, tr("Seeds"));
79 // Tab widget as central widget.
80 setCentralWidget(tabWidget_);
84 QToolBar *toolBar = new QToolBar();
85 toolBar->addAction(tr("Open"));
87 addToolBar(Qt::TopToolBarArea, toolBar);
88 connect(toolBar, SIGNAL(actionTriggered(QAction*)), this, SLOT(handleToolBarAction(QAction*)));
90 alertWaiter_ = new AlertWaiterThread(this);
91 connect(alertWaiter_, SIGNAL(alert()), this, SLOT(on_alert()));
92 alertWaiter_->start();
96 MainWindow::~MainWindow()
101 void MainWindow::on_aboutAction_clicked()
103 QMessageBox::about(this, tr("About QtRapids"), ABOUT_TEXT);
106 void MainWindow::on_aboutQtAction_clicked()
108 QMessageBox::aboutQt (this, tr("About Qt"));
112 void MainWindow::handleToolBarAction(QAction* action)
114 if (action->text() == "Open") {
115 QFileDialog *dialog = new QFileDialog( this, "Open torrent file", QString(), tr("Torrent files (*.torrent)"));
116 dialog->setFileMode(QFileDialog::ExistingFile);
122 void MainWindow::on_alert()
124 qDebug() << "MainWindow: got alert()";