dlView_(NULL),
seedView_(NULL),
preferencesDialog_(NULL),
- settings_(),
+ settings_(),
+// torrentHandles_(),
btSession_()
{
// MENUBAR
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 *aboutAction = tempMenu->addAction(tr("&About"));
QAction *aboutQtAction = tempMenu->addAction(tr("About &Qt"));
- setMenuBar(menuBar);
+ 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()));
/// @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(toolBar, SIGNAL(actionTriggered(QAction*)), this, SLOT(handleToolBarAction(QAction*)));
+ connect(this, SIGNAL(itemSelected(bool)), removeAction,
+ SLOT(setEnabled(bool)));
+ connect(toolBar, SIGNAL(actionTriggered(QAction*)), this,
+ SLOT(handleToolBarAction(QAction*)));
- connect(&btSession_, SIGNAL(alert(std::auto_ptr<TorrentAlert>)),
- this, SLOT(on_torrentAlert(std::auto_ptr<TorrentAlert>)));
+ connect(&btSession_, SIGNAL(alert(std::auto_ptr<Alert>)),
+ this, SLOT(on_alert(std::auto_ptr<Alert>)));
}
}
+void MainWindow::on_removeAction_clicked()
+{
+ QTorrentHandle handle = dlView_->removeSelected();
+ btSession_.removeTorrent(handle);
+}
void MainWindow::on_quitAction_clicked()
{
}
+void MainWindow::on_downloadItemSelectionChanged()
+{
+ 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));
+ }
+}
+
void MainWindow::handleToolBarAction(QAction* action)
{
if (action->text() == "Open") {
on_openAction_clicked();
- } else {
+ } else if (action->text() == "Remove") {
+ on_removeAction_clicked();
}
}
// save_path is the only mandatory parameter, rest are optional.
addParams.save_path = boost::filesystem::path(settings_.value("download/directory").toString().toStdString());
//addParams.storage_mode = libtorrent::storage_mode_allocate;
- std::auto_ptr<QTorrentHandle> handlePtr = btSession_.addTorrent(addParams);
- dlView_->newItem(handlePtr.get());
- qDebug() << "Is valid: " << handlePtr->isValid();
+ QTorrentHandle handle = btSession_.addTorrent(addParams);
+ dlView_->newItem(handle);
+// torrentHandles_.push_back(handlePtr);
+ qDebug() << "Is valid: " << handle.isValid();
+}
+
+
+void MainWindow::on_alert(std::auto_ptr<Alert> al)
+{
+ if (al.get() != NULL) {
+ qDebug()
+ << "MainWindow::on_torrentAlert(): "
+ << QString::fromStdString(al->message());
+
+ TorrentAlert *torrentAlert
+ = dynamic_cast<TorrentAlert*> (al.get());
+ if (torrentAlert) {
+ dlView_->updateItem(QTorrentHandle(torrentAlert->handle));
+ }
+
+ }
+
+
+
}
-void MainWindow::on_torrentAlert(std::auto_ptr<TorrentAlert> al)
+/*
+bool MainWindow::IsNewTorrent(std::auto_ptr<QTorrentHandle> handlePtr)
{
- if (al.get() != NULL)
- qDebug() << "MainWindow::on_torrentAlert(): " << QString::fromStdString(al->message());
-}
\ No newline at end of file
+ for (unsigned i = 0; i < torrentHandles_.size(); ++i) {
+ if (torrentHandles_.at(i).get() == handlePtr.get()) {
+ return false;
+ } else {
+ return true;
+ }
+ }
+}
+*/