void AlertWaiterThread::run()
{
- TorrentAlert const *alertTemp = NULL;
+ Alert const *alertTemp = NULL;
while (true)
{
qDebug() << "AlertWaiter running";
virtual void run(); // Overridden from QThread
signals:
- void alert(TorrentAlert const *alert);
+ void alert(Alert const *alert);
private:
TorrentSession *const btSession_;
{
alertWaiter_ = new AlertWaiterThread(&btSession_, this);
alertWaiter_->allAlerts();
- connect(alertWaiter_, SIGNAL(alert(TorrentAlert const*)), this, SLOT(on_alert(TorrentAlert const*)));
+ connect(alertWaiter_, SIGNAL(alert(Alert const*)), this, SLOT(on_alert(Alert const*)));
alertWaiter_->start();
}
}
-std::auto_ptr<QTorrentHandle>
+QTorrentHandle
QBittorrentSession::addTorrent(AddTorrentParams const& params)
{
// Delegate to Libtorrent and return QTorrentHandle.
- std::auto_ptr<QTorrentHandle> handlePtr(new QTorrentHandle(btSession_.add_torrent(params)));
- return handlePtr;
+ //std::auto_ptr<QTorrentHandle> handlePtr(new QTorrentHandle(btSession_.add_torrent(params)));
+ QTorrentHandle handle = QTorrentHandle(btSession_.add_torrent(params));
+ return handle;
+}
+
+
+void QBittorrentSession::removeTorrent(QTorrentHandle const& handle)
+{
+ btSession_.remove_torrent(handle.getHandle());
}
// ========================== SLOTS ==============================
-void QBittorrentSession::on_alert(TorrentAlert const *al)
+void QBittorrentSession::on_alert(Alert const *al)
//NOTE: al parameter not necessarily needed here, as we pop_alert() now!
{
// if (al)
// qDebug() << "on_alert():" << QString::fromStdString(al->message());
- std::auto_ptr<TorrentAlert> alertPtr = btSession_.pop_alert();
+ std::auto_ptr<Alert> alertPtr = btSession_.pop_alert();
emit alert(alertPtr);
}
+
#include <libtorrent/session.hpp>
#include <libtorrent/torrent_info.hpp>
+#include <libtorrent/alert_types.hpp>
#include "QTorrentHandle.h"
class AlertWaiterThread;
typedef libtorrent::session TorrentSession;
typedef libtorrent::add_torrent_params AddTorrentParams;
-typedef libtorrent::alert TorrentAlert;
+typedef libtorrent::alert Alert;
+typedef libtorrent::torrent_alert TorrentAlert;
typedef libtorrent::sha1_hash Sha1Hash;
~QBittorrentSession();
/// @brief Add torrent to session.
- std::auto_ptr<QTorrentHandle> addTorrent(AddTorrentParams const& params);
+ QTorrentHandle addTorrent(AddTorrentParams const& params);
+ void removeTorrent(QTorrentHandle const& handle);
signals:
- void alert(std::auto_ptr<TorrentAlert> al);
+ void alert(std::auto_ptr<Alert> al);
private slots:
- void on_alert(TorrentAlert const *al);
+ void on_alert(Alert const *al);
private:
TorrentSession btSession_;
return QString::fromStdString(torrentHandle_.name());
}
-
-
-
-bool QTorrentHandle::operator==(QTorrentHandle const& h)
-{
- return torrentHandle_ == h.torrentHandle_;
-}
-
-
-bool QTorrentHandle::operator<(QTorrentHandle const& h)
-{
- return torrentHandle_ < h.torrentHandle_;
-}
-
size_t QTorrentHandle::getTotalSize() const
{
TorrentInfo info = getTorrentInfo();
return statusTmp.download_rate;
}
+
qint32 QTorrentHandle::numSeeds() const
{
TorrentStatus statusTmp = status();
return statusTmp.list_seeds;
}
+
qint32 QTorrentHandle::numLeeches() const
{
TorrentStatus statusTmp = status();
return (statusTmp.list_peers - statusTmp.list_seeds);
}
+
qint32 QTorrentHandle::ratio() const
{
TorrentStatus statusTmp = status();
}
+TorrentHandle QTorrentHandle::getHandle() const
+{
+ return torrentHandle_;
+}
+
+
+bool QTorrentHandle::operator==(QTorrentHandle const& h) const
+{
+ return torrentHandle_ == h.torrentHandle_;
+}
+
+
+bool QTorrentHandle::operator<(QTorrentHandle const& h) const
+{
+ return torrentHandle_ < h.torrentHandle_;
+}
+
+
+
QString QTorrentHandle::GetStatusString(TorrentStatus const& status) const
{
switch (status.state) {
}
}
+
\ No newline at end of file
typedef libtorrent::torrent_status TorrentStatus;
typedef libtorrent::torrent_info TorrentInfo;
+typedef libtorrent::torrent_handle TorrentHandle;
/**
@author Lassi Väätämöinen <lassi.vaatamoinen@ixonos.com>
qint32 numLeeches() const;
qint32 ratio() const;
-
- bool operator==(QTorrentHandle const& h);
- bool operator<(QTorrentHandle const& h);
+ TorrentHandle getHandle() const;
+
+ bool operator==(QTorrentHandle const& h) const;
+ bool operator<(QTorrentHandle const& h) const;
private:
QTorrentHandle(); // Prevent default construct.
- libtorrent::torrent_handle torrentHandle_;
+ TorrentHandle torrentHandle_;
// Private functions.
QString GetStatusString(TorrentStatus const& status) const;
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
+#include <QDebug>
#include "DownloadView.h"
DownloadView::DownloadView(QWidget* parent) :
{
setRootIsDecorated(false); // Hide branch lines, making one-level treeview (similar to list)
setHeaderItem(DownloadViewItem::getHeaderItem());
+
+ connect(this, SIGNAL(itemPressed(QTreeWidgetItem*, int)),
+ this, SLOT(on_itemClicked(QTreeWidgetItem*, int)));
+
}
{
}
-void DownloadView::newItem(QTorrentHandle const* handle)
+
+void DownloadView::newItem(QTorrentHandle handle)
{
+ qDebug() << "DownloadView::newItem() " << items_.count(handle);
DownloadViewItem *item = new DownloadViewItem(QStringList()
- << handle->name()
- << QString::number(handle->getTotalSize())
- << handle->state()
- << QString::number(handle->progress())
- << QString::number(handle->downloadRate())
- << QString::number(handle->uploadRate())
- << QString::number(handle->numSeeds()) + "/" + QString::number(handle->numLeeches())
- << QString::number(handle->ratio())
+ << handle.name()
+ << QString::number(handle.getTotalSize())
+ << handle.state()
+ << QString::number(handle.progress())
+ << QString::number(handle.downloadRate())
+ << QString::number(handle.uploadRate())
+ << QString::number(handle.numSeeds()) + "/"
+ + QString::number(handle.numLeeches())
+ << QString::number(handle.ratio())
<< "ETA" );
addTopLevelItem(item);
+ items_[handle] = item;
+}
+
+
+void DownloadView::updateItem(QTorrentHandle handle)
+{
+ qDebug() << "DownloadView::updateItem() " << items_.count(handle);
+ if (items_.count(handle) > 0) {
+ DownloadViewItem *item = items_[handle];
+ item->setData(2, Qt::DisplayRole, QVariant(handle.state()));
+ item->setData(3, Qt::DisplayRole,
+ QVariant(QString::number(handle.progress())));
+ item->setData(4, Qt::DisplayRole,
+ QVariant(QString::number(handle.downloadRate())));
+ item->setData(5, Qt::DisplayRole,
+ QVariant(QString::number(handle.uploadRate())));
+ item->setData(6, Qt::DisplayRole,
+ QString::number(handle.numSeeds()) + "/"
+ + QString::number(handle.numLeeches()));
+ }
}
-void DownloadView::updateItem(QTorrentHandle const* handle)
+
+QTorrentHandle DownloadView::removeSelected()
{
+ qDebug() << "DownloadView::removeSelected() " << topLevelItemCount() ;
+
+ DownloadViewItem *item = dynamic_cast<DownloadViewItem*> (currentItem());
+
+ std::map<QTorrentHandle, DownloadViewItem*>::iterator listIter
+ = items_.begin();
+ std::map<QTorrentHandle, DownloadViewItem*>::iterator listEnd
+ = items_.end();
+
+ while (listIter != listEnd) {
+ if (listIter->second == item) {
+ break;
+ }
+ ++listIter;
+ }
+
+ QTorrentHandle handle = listIter->first;
+ items_.erase(listIter);
+
+
+ int index = indexOfTopLevelItem(currentItem());
+ if (index >= 0) {
+ takeTopLevelItem(index);
+ }
+
+ qDebug() << "DownloadView::removeSelected() " << topLevelItemCount() ;
+
+ return handle;
}
+void DownloadView::removeItem(QTorrentHandle handle)
+{
+}
+
+
+void DownloadView::on_itemClicked(QTreeWidgetItem * item, int column)
+{/*
+ qDebug() << "DownloadView::on_itemClicked(()" << item << "," << column;
+ qDebug() << "current item" << currentItem();
+
+ if (item == currentItem() && item->isSelected()) {
+ item->setSelected(false);
+ }
+ */
+}
+
~DownloadView();
- void newItem(QTorrentHandle const* handle);
- void updateItem(QTorrentHandle const* handle);
+ void newItem(QTorrentHandle handle);
+ void updateItem(QTorrentHandle handle);
+ QTorrentHandle removeSelected();
+ void removeItem(QTorrentHandle handle);
+ private slots:
+ void on_itemClicked(QTreeWidgetItem * item, int column);
private:
// Maps torrent to downloadview item.
// Key: SHA1 info hash of torrent. Data: View item corresponding to torrent.
- std::map<Sha1Hash, DownloadViewItem*> items_;
+ std::map<QTorrentHandle, DownloadViewItem*> items_;
};
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;
+ }
+ }
+}
+*/
~MainWindow();
+ signals:
+ void itemSelected(bool enabled);
+
public slots:
private slots:
void on_openAction_clicked();
+ void on_removeAction_clicked();
void on_quitAction_clicked();
void on_preferencesAction_clicked();
void on_aboutAction_clicked();
void on_aboutQtAction_clicked();
+ void on_downloadItemSelectionChanged();
+ void on_seedItemSelectionChanged();
void handleToolBarAction(QAction* action);
void on_torrentFileSelected(const QString& file);
- void on_torrentAlert(std::auto_ptr<TorrentAlert> al);
+ void on_alert(std::auto_ptr<Alert> al);
private:
QTabWidget *tabWidget_;
PreferencesDialog *preferencesDialog_;
QSettings settings_;
+ //std::vector< std::auto_ptr<QTorrentHandle> const > torrentHandles_;
+
QBittorrentSession btSession_;
+ //bool IsNewTorrent(std::auto_ptr<QTorrentHandle> handlePtr);
};
#endif
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
+#include <QDebug>
#include "SeedView.h"
SeedView::SeedView(QWidget* parent):
{
setRootIsDecorated(false); // Hide branch lines, making one-level treeview (similar to list)
setHeaderItem(SeedViewItem::getHeaderItem());
+
+ connect(this, SIGNAL(itemPressed( QTreeWidgetItem*, int)),
+ this, SLOT(on_itemPressed(QTreeWidgetItem*, int)));
}
{
}
+void SeedView::on_itemPressed(QTreeWidgetItem * item, int column)
+{
+ qDebug() << "SeedView::on_itemPressed() " << item << "," << column;
+}
void newItem(QTorrentHandle const* handle);
void updateItem(QTorrentHandle const* handle);
+ private slots:
+ void on_itemPressed(QTreeWidgetItem *item, int column);
+
private:
// Maps torrent to SeedView item.
// Key: SHA1 info hash of torrent. Data: View item corresponding to torrent.