- About dialogs and menubar
[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
33 #include "MainWindow.h"
34
35
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"));
42
43
44
45 MainWindow::MainWindow():
46         QMainWindow(), // Superclass
47         tabWidget_(NULL),
48         dlView_(NULL),
49         seedView_(NULL)
50 {
51         
52         // MENUBAR 
53         QMenuBar *menuBar = new QMenuBar();
54         QMenu *tempMenu = NULL;
55         
56         tempMenu = menuBar->addMenu(tr("&File"));
57         tempMenu->addAction(tr("&Open"));
58         
59         tempMenu = menuBar->addMenu(tr("&Help"));
60         QAction *aboutAction = tempMenu->addAction(tr("&About"));
61         QAction *aboutQtAction = tempMenu->addAction(tr("About &Qt"));
62         
63         setMenuBar(menuBar);
64         connect(aboutAction, SIGNAL(triggered()), this, SLOT(on_aboutAction_clicked()));
65         connect(aboutQtAction, SIGNAL(triggered()), this, SLOT(on_aboutQtAction_clicked()));
66         
67         
68         // TABWIDGET (central widget)
69         tabWidget_ = new QTabWidget();
70         
71         /// @todo Exception handling
72         dlView_ = new DownloadView(this);
73         seedView_ = new SeedView(this);
74         
75         tabWidget_->addTab(dlView_, tr("Downloads"));
76         tabWidget_->addTab(seedView_, tr("Seeds"));
77         
78         // Tab widget as central widget.
79         setCentralWidget(tabWidget_);
80         
81         
82         // TOOLBAR
83         QToolBar *toolBar = new QToolBar();
84         toolBar->addAction(tr("Open"));
85         
86         addToolBar(Qt::TopToolBarArea, toolBar);
87         connect(toolBar, SIGNAL(actionTriggered(QAction*)), this, SLOT(handleToolBarAction(QAction*)));
88 }
89
90
91 MainWindow::~MainWindow()
92 {
93 }
94
95
96 void MainWindow::on_aboutAction_clicked()
97 {
98         QMessageBox::about(this, tr("About QtRapids"), ABOUT_TEXT); 
99 }
100                 
101 void MainWindow::on_aboutQtAction_clicked()
102 {
103         QMessageBox::aboutQt (this, tr("About Qt"));
104 }
105
106
107 void MainWindow::handleToolBarAction(QAction* action)
108 {
109         if (action->text() == "Open") {
110                 QFileDialog *dialog = new QFileDialog( this, "Open torrent file", QString(), tr("Torrent files (*.torrent)"));
111                 dialog->setFileMode(QFileDialog::ExistingFile);
112                 dialog->show();
113         } else {
114         }
115 }
116