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"
33 #include "MainWindow.h"
36 const QString ABOUT_TEXT
37 = QString(QObject::trUtf8("QtRapids, a simple BitTorrent client based on"
38 "\nQt and Libtorrent."
39 "\n\nURL: http://qtrapids.garage.maemo.org/"
40 "\n\nAuthor(s):\nLassi Väätämöinen, lassi.vaatamoinen@ixonos.com"
41 "\n\nIxonos Plc, Finland\n"));
45 MainWindow::MainWindow():
46 QMainWindow(), // Superclass
53 QMenuBar *menuBar = new QMenuBar();
54 QMenu *tempMenu = NULL;
56 tempMenu = menuBar->addMenu(tr("&File"));
57 tempMenu->addAction(tr("&Open"));
59 tempMenu = menuBar->addMenu(tr("&Help"));
60 QAction *aboutAction = tempMenu->addAction(tr("&About"));
61 QAction *aboutQtAction = tempMenu->addAction(tr("About &Qt"));
64 connect(aboutAction, SIGNAL(triggered()), this, SLOT(on_aboutAction_clicked()));
65 connect(aboutQtAction, SIGNAL(triggered()), this, SLOT(on_aboutQtAction_clicked()));
68 // TABWIDGET (central widget)
69 tabWidget_ = new QTabWidget();
71 /// @todo Exception handling
72 dlView_ = new DownloadView(this);
73 seedView_ = new SeedView(this);
75 tabWidget_->addTab(dlView_, tr("Downloads"));
76 tabWidget_->addTab(seedView_, tr("Seeds"));
78 // Tab widget as central widget.
79 setCentralWidget(tabWidget_);
83 QToolBar *toolBar = new QToolBar();
84 toolBar->addAction(tr("Open"));
86 addToolBar(Qt::TopToolBarArea, toolBar);
87 connect(toolBar, SIGNAL(actionTriggered(QAction*)), this, SLOT(handleToolBarAction(QAction*)));
91 MainWindow::~MainWindow()
96 void MainWindow::on_aboutAction_clicked()
98 QMessageBox::about(this, tr("About QtRapids"), ABOUT_TEXT);
101 void MainWindow::on_aboutQtAction_clicked()
103 QMessageBox::aboutQt (this, tr("About Qt"));
107 void MainWindow::handleToolBarAction(QAction* action)
109 if (action->text() == "Open") {
110 QFileDialog *dialog = new QFileDialog( this, "Open torrent file", QString(), tr("Torrent files (*.torrent)"));
111 dialog->setFileMode(QFileDialog::ExistingFile);