// Consturctor
MainWindow::MainWindow() :
- QMainWindow(), // Superclass
- tabWidget_(NULL),
- dlView_(NULL),
- seedView_(NULL),
- preferencesDialog_(NULL),
- settings_(QCoreApplication::organizationName()
- , QCoreApplication::applicationName()),
- server_(QtRapidsServer::staticInterfaceName()
- , "/qtrapids", QDBusConnection::sessionBus())
- // torrentHandles_(),
+ QMainWindow(), // Superclass
+ tabWidget_(NULL),
+ dlView_(NULL),
+ seedView_(NULL),
+ preferencesDialog_(NULL),
+ settings_(QCoreApplication::organizationName()
+ , QCoreApplication::applicationName()),
+ server_(QtRapidsServer::staticInterfaceName()
+ , "/qtrapids", QDBusConnection::sessionBus())
+ // torrentHandles_(),
{
- // MENUBAR
- QMenuBar *menuBar = new QMenuBar();
- QMenu *tempMenu = NULL;
-
- tempMenu = menuBar->addMenu(tr("&File"));
- QAction *openAction = tempMenu->addAction(tr("&Open"));
- QAction *removeAction = tempMenu->addAction(tr("&Remove"));
- removeAction->setEnabled(false);
- QAction *quitAction = tempMenu->addAction(tr("&Quit"));
-
- tempMenu = menuBar->addMenu(tr("&Settings"));
- QAction *preferencesAction = tempMenu->addAction(tr("&Preferences"));
-
- tempMenu = menuBar->addMenu(tr("&Help"));
- QAction *aboutAction = tempMenu->addAction(tr("&About"));
- QAction *aboutQtAction = tempMenu->addAction(tr("About &Qt"));
-
- setMenuBar(menuBar);
- connect(openAction, SIGNAL(triggered()), this, SLOT(on_openAction_clicked()));
- connect(removeAction, SIGNAL(triggered()), this, SLOT(on_removeAction_clicked()));
- connect(this, SIGNAL(itemSelected(bool)), removeAction, SLOT(setEnabled(bool)));
- connect(quitAction, SIGNAL(triggered()), this, SLOT(on_quitAction_clicked()));
- connect(preferencesAction, SIGNAL(triggered()), this, SLOT(on_preferencesAction_clicked()));
- 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"));
- connect(dlView_, SIGNAL(itemSelectionChanged()), this,
- SLOT(on_downloadItemSelectionChanged()));
-
- connect(seedView_, SIGNAL(itemSelectionChanged()), this,
- SLOT(on_seedItemSelectionChanged()));
-
- // Tab widget as central widget.
- setCentralWidget(tabWidget_);
-
- // TOOLBAR
- QToolBar *toolBar = new QToolBar();
- toolBar->addAction(tr("Open"));
- removeAction = toolBar->addAction(tr("Remove"));
- removeAction->setEnabled(false);
- addToolBar(Qt::TopToolBarArea, toolBar);
-
- connect(this, SIGNAL(itemSelected(bool)), removeAction,
- SLOT(setEnabled(bool)));
- connect(toolBar, SIGNAL(actionTriggered(QAction*)), this,
- SLOT(handleToolBarAction(QAction*)));
-
- QVariant geometry(settings_.value("geometry"));
- if (!geometry.isNull())
- {
- qDebug() << "restoring geometry";
- restoreGeometry(geometry.toByteArray());
- }
+ // MENUBAR
+ QMenuBar *menuBar = new QMenuBar();
+ QMenu *tempMenu = NULL;
+
+ tempMenu = menuBar->addMenu(tr("&File"));
+ QAction *openAction = tempMenu->addAction(tr("&Open"));
+ QAction *removeAction = tempMenu->addAction(tr("&Remove"));
+ removeAction->setEnabled(false);
+ QAction *quitAction = tempMenu->addAction(tr("&Quit"));
+
+ tempMenu = menuBar->addMenu(tr("&Settings"));
+ QAction *preferencesAction = tempMenu->addAction(tr("&Preferences"));
+
+ tempMenu = menuBar->addMenu(tr("&Help"));
+ QAction *aboutAction = tempMenu->addAction(tr("&About"));
+ QAction *aboutQtAction = tempMenu->addAction(tr("About &Qt"));
+
+ setMenuBar(menuBar);
+ connect(openAction, SIGNAL(triggered()), this, SLOT(on_openAction_clicked()));
+ connect(removeAction, SIGNAL(triggered()), this, SLOT(on_removeAction_clicked()));
+ connect(this, SIGNAL(itemSelected(bool)), removeAction, SLOT(setEnabled(bool)));
+ connect(quitAction, SIGNAL(triggered()), this, SLOT(on_quitAction_clicked()));
+ connect(preferencesAction, SIGNAL(triggered()), this, SLOT(on_preferencesAction_clicked()));
+ 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"));
+ connect(dlView_, SIGNAL(itemSelectionChanged()), this,
+ SLOT(on_downloadItemSelectionChanged()));
+
+ connect(seedView_, SIGNAL(itemSelectionChanged()), this,
+ SLOT(on_seedItemSelectionChanged()));
+
+ // Tab widget as central widget.
+ setCentralWidget(tabWidget_);
+
+ // TOOLBAR
+ QToolBar *toolBar = new QToolBar();
+ toolBar->addAction(tr("Open"));
+ removeAction = toolBar->addAction(tr("Remove"));
+ removeAction->setEnabled(false);
+ addToolBar(Qt::TopToolBarArea, toolBar);
+
+ connect(this, SIGNAL(itemSelected(bool)), removeAction,
+ SLOT(setEnabled(bool)));
+ connect(toolBar, SIGNAL(actionTriggered(QAction*)), this,
+ SLOT(handleToolBarAction(QAction*)));
+
+ QVariant geometry(settings_.value("geometry"));
+ if (!geometry.isNull()) {
+ qDebug() << "restoring geometry";
+ restoreGeometry(geometry.toByteArray());
+ }
}
MainWindow::~MainWindow()
{
- settings_.setValue("geometry", saveGeometry());
+ settings_.setValue("geometry", saveGeometry());
}
// =========================== SLOTS =================================
void MainWindow::on_openAction_clicked()
{
- QFileDialog *dialog = new QFileDialog( this, "Open torrent file", QString(), tr("Torrent files (*.torrent)"));
- dialog->setFileMode(QFileDialog::ExistingFile);
- connect(dialog, SIGNAL(fileSelected(const QString&)), this, SLOT(on_torrentFileSelected(const QString&)));
- dialog->show();
+ QFileDialog *dialog = new QFileDialog( this, "Open torrent file", QString(), tr("Torrent files (*.torrent)"));
+ dialog->setFileMode(QFileDialog::ExistingFile);
+ connect(dialog, SIGNAL(fileSelected(const QString&)), this, SLOT(on_torrentFileSelected(const QString&)));
+ dialog->show();
}
void MainWindow::on_removeAction_clicked()
{
- QString hash = dlView_->prepareRemoveSelected();
- try
- {
- server_.removeTorrent(hash);
- }
- catch (...)
- {
- qDebug() << "Exception removing torrent";
- }
+ QString hash = dlView_->prepareRemoveSelected();
+ try {
+ server_.removeTorrent(hash);
+ } catch (...) {
+ qDebug() << "Exception removing torrent";
+ }
}
void MainWindow::on_quitAction_clicked()
{
- close();
+ close();
}
void MainWindow::on_preferencesAction_clicked()
{
- if (!preferencesDialog_)
- {
- preferencesDialog_ = new PreferencesDialog(this);
- }
- preferencesDialog_->show();
- preferencesDialog_->raise();
- preferencesDialog_->activateWindow();
+ if (!preferencesDialog_) {
+ preferencesDialog_ = new PreferencesDialog(this);
+ }
+ preferencesDialog_->show();
+ preferencesDialog_->raise();
+ preferencesDialog_->activateWindow();
}
void MainWindow::on_aboutAction_clicked()
{
- QMessageBox::about(this, tr("About QtRapids"), ABOUT_TEXT);
+ QMessageBox::about(this, tr("About QtRapids"), ABOUT_TEXT);
}
void MainWindow::on_aboutQtAction_clicked()
{
- QMessageBox::aboutQt (this, tr("About Qt"));
+ QMessageBox::aboutQt (this, tr("About Qt"));
}
void MainWindow::on_downloadItemSelectionChanged()
{
- qDebug() << "MainWindow::on_seedItemSelectionChanged():" << dlView_->currentItem();
- if (dlView_->currentItem() != NULL)
- {
- emit(itemSelected(true));
- }
- else
- {
- emit(itemSelected(false));
- }
+ qDebug() << "MainWindow::on_seedItemSelectionChanged():" << dlView_->currentItem();
+ if (dlView_->currentItem() != NULL) {
+ emit(itemSelected(true));
+ } else {
+ emit(itemSelected(false));
+ }
}
void MainWindow::on_seedItemSelectionChanged()
{
- qDebug() << "MainWindow::on_seedItemSelectionChanged():" << seedView_->currentItem();
- if (seedView_->currentItem() != NULL)
- {
- emit(itemSelected(true));
- }
- else
- {
- emit(itemSelected(false));
- }
+ qDebug() << "MainWindow::on_seedItemSelectionChanged():" << seedView_->currentItem();
+ if (seedView_->currentItem() != NULL) {
+ emit(itemSelected(true));
+ } else {
+ emit(itemSelected(false));
+ }
}
void MainWindow::handleToolBarAction(QAction* action)
{
- if (action->text() == "Open")
- {
- on_openAction_clicked();
- }
- else if (action->text() == "Remove")
- {
- on_removeAction_clicked();
- }
+ if (action->text() == "Open") {
+ on_openAction_clicked();
+ } else if (action->text() == "Remove") {
+ on_removeAction_clicked();
+ }
}
void MainWindow::on_torrentFileSelected(const QString& file)
{
- qDebug() << " MainWindow::on_torrentFileSelected(): " << file;
- // Torrent filename empty, do nothing.
- if (file == "")
- {
- return;
- }
-
- // Otherwise add torrent
- // For params, see: http://www.rasterbar.com/products/libtorrent/manual.html#add-torrent
- // save_path is the only mandatory parameter, rest are optional.
- //addParams.storage_mode = libtorrent::storage_mode_allocate;
- try
- {
- server_.addTorrent(file, settings_.value("download/directory").toString()
- , ParamsMap_t());
- }
- catch (...)
- {
- qDebug() << "Exception adding torrent";
- }
+ qDebug() << " MainWindow::on_torrentFileSelected(): " << file;
+ // Torrent filename empty, do nothing.
+ if (file == "") {
+ return;
+ }
+
+ // Otherwise add torrent
+ // For params, see: http://www.rasterbar.com/products/libtorrent/manual.html#add-torrent
+ // save_path is the only mandatory parameter, rest are optional.
+ //addParams.storage_mode = libtorrent::storage_mode_allocate;
+ try {
+ server_.addTorrent(file, settings_.value("download/directory").toString()
+ , ParamsMap_t());
+ } catch (...) {
+ qDebug() << "Exception adding torrent";
+ }
}
void MainWindow::alert(qtrapids::TorrentState info, qtrapids::ParamsMap_t other_info)
{
- std::cerr << "got alert" << std::endl;
- dlView_->updateItem(info, other_info);
+ std::cerr << "got alert" << std::endl;
+ dlView_->updateItem(info, other_info);
}
} // namespace qtrapids