- About dialogs and menubar
[qtrapids] / src / gui / MainWindow.cpp
index bbd5433..dc1d73e 100644 (file)
  *   Free Software Foundation, Inc.,                                       *
  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
  ***************************************************************************/
+
+
+#include <QDebug>
+
+#include <QMenuBar>
+#include <QToolBar>
+#include <QAction>
+#include <QFileDialog>
+#include <QMessageBox>
+
+#include "DownloadView.h"
+#include "SeedView.h"
+
 #include "MainWindow.h"
 
-MainWindow::MainWindow()
+
+const QString ABOUT_TEXT 
+       = QString(QObject::trUtf8("QtRapids, a simple BitTorrent client based on"
+               "\nQt and Libtorrent."
+               "\n\nURL: http://qtrapids.garage.maemo.org/"
+               "\n\nAuthor(s):\nLassi Väätämöinen, lassi.vaatamoinen@ixonos.com"
+               "\n\nIxonos Plc, Finland\n"));
+
+
+
+MainWindow::MainWindow():
+       QMainWindow(), // Superclass
+       tabWidget_(NULL),
+       dlView_(NULL),
+       seedView_(NULL)
 {
+       
+       // MENUBAR 
+       QMenuBar *menuBar = new QMenuBar();
+       QMenu *tempMenu = NULL;
+       
+       tempMenu = menuBar->addMenu(tr("&File"));
+       tempMenu->addAction(tr("&Open"));
+       
+       tempMenu = menuBar->addMenu(tr("&Help"));
+       QAction *aboutAction = tempMenu->addAction(tr("&About"));
+       QAction *aboutQtAction = tempMenu->addAction(tr("About &Qt"));
+       
+       setMenuBar(menuBar);
+       connect(aboutAction, SIGNAL(triggered()), this, SLOT(on_aboutAction_clicked()));
+       connect(aboutQtAction, SIGNAL(triggered()), this, SLOT(on_aboutQtAction_clicked()));
+       
+       
+       // TABWIDGET (central widget)
+       tabWidget_ = new QTabWidget();
+       
+       /// @todo Exception handling
+       dlView_ = new DownloadView(this);
+       seedView_ = new SeedView(this);
+       
+       tabWidget_->addTab(dlView_, tr("Downloads"));
+       tabWidget_->addTab(seedView_, tr("Seeds"));
+       
+       // Tab widget as central widget.
+       setCentralWidget(tabWidget_);
+       
+       
+       // TOOLBAR
+       QToolBar *toolBar = new QToolBar();
+       toolBar->addAction(tr("Open"));
+       
+       addToolBar(Qt::TopToolBarArea, toolBar);
+       connect(toolBar, SIGNAL(actionTriggered(QAction*)), this, SLOT(handleToolBarAction(QAction*)));
 }
 
 
@@ -29,3 +93,24 @@ MainWindow::~MainWindow()
 }
 
 
+void MainWindow::on_aboutAction_clicked()
+{
+       QMessageBox::about(this, tr("About QtRapids"), ABOUT_TEXT); 
+}
+               
+void MainWindow::on_aboutQtAction_clicked()
+{
+       QMessageBox::aboutQt (this, tr("About Qt"));
+}
+
+
+void MainWindow::handleToolBarAction(QAction* action)
+{
+       if (action->text() == "Open") {
+               QFileDialog *dialog = new QFileDialog( this, "Open torrent file", QString(), tr("Torrent files (*.torrent)"));
+               dialog->setFileMode(QFileDialog::ExistingFile);
+               dialog->show();
+       } else {
+       }
+}
+