From 4fda70ff265b1a5a1f37597f57253272a2b22fbf Mon Sep 17 00:00:00 2001 From: deztructor Date: Wed, 18 Nov 2009 11:04:43 +0000 Subject: [PATCH] formatting is changed according to last astyle settings git-svn-id: file:///svnroot/qtrapids/trunk@36 42ac0dd5-4c8c-4c71-bb3e-ecdfe252ffda --- src/client/DownloadView.cpp | 261 ++++++++++----------- src/client/DownloadView.h | 93 ++++---- src/client/MainWindow.cpp | 268 ++++++++++------------ src/client/MainWindow.h | 69 +++--- src/client/PreferencesDialog.cpp | 127 +++++----- src/client/PreferencesDialog.h | 24 +- src/client/SeedView.cpp | 12 +- src/client/SeedView.h | 59 +++-- src/client/main.cpp | 70 +++--- src/engine/AlertWaiterThread.cpp | 42 ++-- src/engine/AlertWaiterThread.h | 20 +- src/engine/QBittorrentSession.cpp | 32 +-- src/engine/QBittorrentSession.h | 20 +- src/engine/QTorrentHandle.cpp | 98 ++++---- src/engine/QTorrentHandle.h | 59 +++-- src/gui/DownloadView.cpp | 286 +++++++++++------------ src/gui/DownloadView.h | 83 ++++--- src/gui/MainWindow.cpp | 356 ++++++++++++++--------------- src/gui/MainWindow.h | 62 ++--- src/gui/PreferencesDialog.cpp | 127 +++++----- src/gui/PreferencesDialog.h | 24 +- src/gui/SeedView.cpp | 14 +- src/gui/SeedView.h | 71 +++--- src/gui/main.cpp | 66 +++--- src/include/qtrapids/dbus.hpp | 143 ++++++------ src/include/qtrapids/error.hpp | 29 ++- src/include/qtrapids/format.hpp | 40 ++-- src/include/qtrapids/info.hpp | 26 +-- src/include/qtrapids/settings.hpp | 13 +- src/plugins/PluginInterface.h | 64 +++--- src/plugins/searchplugin/SearchPlugin.cpp | 134 ++++++----- src/plugins/searchplugin/SearchPlugin.h | 24 +- src/server/AlertWaiterThread.cpp | 40 ++-- src/server/AlertWaiterThread.hpp | 14 +- src/server/ServerDb.hpp | 174 +++++++------- src/server/TorrentHandle.cpp | 65 +++--- src/server/TorrentHandle.hpp | 47 ++-- src/server/TorrentSession.cpp | 237 +++++++++---------- src/server/TorrentSession.hpp | 24 +- src/server/main.cpp | 16 +- 40 files changed, 1651 insertions(+), 1782 deletions(-) diff --git a/src/client/DownloadView.cpp b/src/client/DownloadView.cpp index d097234..94bcaf4 100644 --- a/src/client/DownloadView.cpp +++ b/src/client/DownloadView.cpp @@ -29,14 +29,14 @@ namespace qtrapids { DownloadView::DownloadView(QWidget* parent) : - QTreeWidget(parent), - items_() + QTreeWidget(parent), + items_() { - setRootIsDecorated(false); // Hide branch lines, making one-level treeview (similar to list) - setHeaderItem(DownloadViewItem::getHeaderItem()); + 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))); + connect(this, SIGNAL(itemPressed(QTreeWidgetItem*, int)), + this, SLOT(on_itemClicked(QTreeWidgetItem*, int))); } @@ -47,177 +47,164 @@ DownloadView::~DownloadView() void DownloadView::updateItem(TorrentState const& info, ParamsMap_t other_info) { - DownloadItems_t::iterator p = items_.find(info.hash); - switch (info.action) - { - case TorrentState::action_add : - if (p == items_.end()) - { - addItem_(info, other_info); - } - else - { - qWarning() << "item with similar info hash marked as added"; - updateItem_(p.value(), info, other_info); - } - break; - case TorrentState::action_update : - if (p != items_.end()) - { - updateItem_(p.value(), info, other_info); - } - else - { - qWarning() << "item does not exist in list but information update arrived"; - } - break; - case TorrentState::action_remove : - if (p != items_.end()) - { - removeItem_(p.value(), info); - } - else - { - qWarning() << "item removal request arrived but there is no such item"; - } - break; - default: - qWarning() << "unknown action requested: " << info.action; - break; - } + DownloadItems_t::iterator p = items_.find(info.hash); + switch (info.action) { + case TorrentState::action_add : + if (p == items_.end()) { + addItem_(info, other_info); + } else { + qWarning() << "item with similar info hash marked as added"; + updateItem_(p.value(), info, other_info); + } + break; + case TorrentState::action_update : + if (p != items_.end()) { + updateItem_(p.value(), info, other_info); + } else { + qWarning() << "item does not exist in list but information update arrived"; + } + break; + case TorrentState::action_remove : + if (p != items_.end()) { + removeItem_(p.value(), info); + } else { + qWarning() << "item removal request arrived but there is no such item"; + } + break; + default: + qWarning() << "unknown action requested: " << info.action; + break; + } } void DownloadView::removeItem_(DownloadViewItem *item, TorrentState const& info) { - QString hash = item->getHash(); + QString hash = item->getHash(); - int removed = items_.remove(hash); - if (!removed) - qDebug() << "Inconsistent download view state on item removal"; + int removed = items_.remove(hash); + if (!removed) + qDebug() << "Inconsistent download view state on item removal"; - int index = indexOfTopLevelItem(item); - if (index >= 0) - { - takeTopLevelItem(index); - } + int index = indexOfTopLevelItem(item); + if (index >= 0) { + takeTopLevelItem(index); + } } void DownloadView::addItem_(TorrentState const& info, ParamsMap_t) { - DownloadViewItem *item = new DownloadViewItem - ( info.hash, - QStringList() - << info.name - << formatSize(info.total_size) - << GetStatusString((TorrentStatus::Id)info.state) - << formatProgress(info.progress) - << QString::number(info.down_rate, 'f', 2) - << QString::number(info.up_rate, 'f', 2) - << QString::number(info.seeds) + "/" + QString::number(info.leeches) - << QString::number(info.ratio) - << "ETA" ); - - QBrush brushTmp(GetStatusColor((TorrentStatus::Id)info.state)); - item->setForeground(2, brushTmp); - - addTopLevelItem(item); - items_[info.hash] = item; + DownloadViewItem *item = new DownloadViewItem + ( info.hash, + QStringList() + << info.name + << formatSize(info.total_size) + << GetStatusString((TorrentStatus::Id)info.state) + << formatProgress(info.progress) + << QString::number(info.down_rate, 'f', 2) + << QString::number(info.up_rate, 'f', 2) + << QString::number(info.seeds) + "/" + QString::number(info.leeches) + << QString::number(info.ratio) + << "ETA" ); + + QBrush brushTmp(GetStatusColor((TorrentStatus::Id)info.state)); + item->setForeground(2, brushTmp); + + addTopLevelItem(item); + items_[info.hash] = item; } void DownloadView::updateItem_(DownloadViewItem *item , TorrentState const& info, ParamsMap_t) { - item->setData(2, Qt::DisplayRole, - QVariant(GetStatusString((TorrentStatus::Id)info.state))); - item->setData(3, Qt::DisplayRole, - QVariant(formatProgress(info.progress))); - item->setData(4, Qt::DisplayRole, - QVariant(QString::number(info.down_rate))); - item->setData(5, Qt::DisplayRole, - QVariant(QString::number(info.up_rate))); - item->setData(6, Qt::DisplayRole, - QString::number(info.seeds) + "/" + QString::number(info.leeches)); - - QBrush brushTmp(GetStatusColor((TorrentStatus::Id)info.state)); - item->setForeground(2, brushTmp); + item->setData(2, Qt::DisplayRole, + QVariant(GetStatusString((TorrentStatus::Id)info.state))); + item->setData(3, Qt::DisplayRole, + QVariant(formatProgress(info.progress))); + item->setData(4, Qt::DisplayRole, + QVariant(QString::number(info.down_rate))); + item->setData(5, Qt::DisplayRole, + QVariant(QString::number(info.up_rate))); + item->setData(6, Qt::DisplayRole, + QString::number(info.seeds) + "/" + QString::number(info.leeches)); + + QBrush brushTmp(GetStatusColor((TorrentStatus::Id)info.state)); + item->setForeground(2, brushTmp); } QString DownloadView::prepareRemoveSelected() { - qDebug() << "DownloadView::removeSelected() " << topLevelItemCount() ; + qDebug() << "DownloadView::removeSelected() " << topLevelItemCount() ; - DownloadViewItem *item = dynamic_cast (currentItem()); - QString hash = item->getHash(); + DownloadViewItem *item = dynamic_cast (currentItem()); + QString hash = item->getHash(); - item->setDisabled(true); + item->setDisabled(true); - qDebug() << "DownloadView::removeSelected() " << topLevelItemCount() ; + qDebug() << "DownloadView::removeSelected() " << topLevelItemCount() ; - return hash; + return hash; } void DownloadView::on_itemClicked(QTreeWidgetItem * , int) { - /* - qDebug() << "DownloadView::on_itemClicked(()" << item << "," << column; - qDebug() << "current item" << currentItem(); - - if (item == currentItem() && item->isSelected()) { - item->setSelected(false); - } - */ + /* + qDebug() << "DownloadView::on_itemClicked(()" << item << "," << column; + qDebug() << "current item" << currentItem(); + + if (item == currentItem() && item->isSelected()) { + item->setSelected(false); + } + */ } QString DownloadView::GetStatusString(TorrentStatus::Id status) { - switch (status) - { - case TorrentStatus::QUEUED_FOR_CHECKING : - return tr("Queued"); - case TorrentStatus::CHECKING_FILES : - return tr("Checking"); - case TorrentStatus::DOWNLOADING_METADATA : - return tr("DL meta"); - case TorrentStatus::DOWNLOADING : - return tr("Downloading"); - case TorrentStatus::FINISHED : - return tr("Finished"); - case TorrentStatus::SEEDING : - return tr("Seeding"); - case TorrentStatus::ALLOCATING : - return tr("Allocating"); - case TorrentStatus::CHECKING_RESUME_DATA : - return tr("Checking resume"); - default: - return tr("N/A"); - } + switch (status) { + case TorrentStatus::QUEUED_FOR_CHECKING : + return tr("Queued"); + case TorrentStatus::CHECKING_FILES : + return tr("Checking"); + case TorrentStatus::DOWNLOADING_METADATA : + return tr("DL meta"); + case TorrentStatus::DOWNLOADING : + return tr("Downloading"); + case TorrentStatus::FINISHED : + return tr("Finished"); + case TorrentStatus::SEEDING : + return tr("Seeding"); + case TorrentStatus::ALLOCATING : + return tr("Allocating"); + case TorrentStatus::CHECKING_RESUME_DATA : + return tr("Checking resume"); + default: + return tr("N/A"); + } } QColor DownloadView::GetStatusColor(TorrentStatus::Id status) { - QColor green(40,205,40); - QColor yellow(255,174,0); - - switch (status) - { - case TorrentStatus::QUEUED_FOR_CHECKING : - case TorrentStatus::CHECKING_FILES : - case TorrentStatus::DOWNLOADING_METADATA : - case TorrentStatus::ALLOCATING : - case TorrentStatus::CHECKING_RESUME_DATA: - return yellow; - case TorrentStatus::DOWNLOADING : - case TorrentStatus::FINISHED : - case TorrentStatus::SEEDING : - return green; - default: - return QColor(); - } + QColor green(40,205,40); + QColor yellow(255,174,0); + + switch (status) { + case TorrentStatus::QUEUED_FOR_CHECKING : + case TorrentStatus::CHECKING_FILES : + case TorrentStatus::DOWNLOADING_METADATA : + case TorrentStatus::ALLOCATING : + case TorrentStatus::CHECKING_RESUME_DATA: + return yellow; + case TorrentStatus::DOWNLOADING : + case TorrentStatus::FINISHED : + case TorrentStatus::SEEDING : + return green; + default: + return QColor(); + } } } // namespace qtrapids diff --git a/src/client/DownloadView.h b/src/client/DownloadView.h index caf3daf..459bde2 100644 --- a/src/client/DownloadView.h +++ b/src/client/DownloadView.h @@ -41,32 +41,32 @@ typedef QHash DownloadItems_t; */ class DownloadView : public QTreeWidget { - Q_OBJECT + Q_OBJECT public: - DownloadView(QWidget* parent); + DownloadView(QWidget* parent); - ~DownloadView(); + ~DownloadView(); - void updateItem(TorrentState const& info, ParamsMap_t other_info); - QString prepareRemoveSelected(); + void updateItem(TorrentState const& info, ParamsMap_t other_info); + QString prepareRemoveSelected(); private slots: - void on_itemClicked(QTreeWidgetItem * item, int column); + void on_itemClicked(QTreeWidgetItem * item, int column); private: - void addItem_(TorrentState const& info, ParamsMap_t other_info); - void updateItem_(DownloadViewItem *item - , TorrentState const& info, ParamsMap_t other_info); - void removeItem_(DownloadViewItem *item, TorrentState const& info); + void addItem_(TorrentState const& info, ParamsMap_t other_info); + void updateItem_(DownloadViewItem *item + , TorrentState const& info, ParamsMap_t other_info); + void removeItem_(DownloadViewItem *item, TorrentState const& info); - // Maps torrent to downloadview item. - // Key: SHA1 info hash of torrent. Data: View item corresponding to torrent. - DownloadItems_t items_; + // Maps torrent to downloadview item. + // Key: SHA1 info hash of torrent. Data: View item corresponding to torrent. + DownloadItems_t items_; - // Private functions. - static QString GetStatusString(TorrentStatus::Id status); - static QColor GetStatusColor(TorrentStatus::Id status); + // Private functions. + static QString GetStatusString(TorrentStatus::Id status); + static QColor GetStatusColor(TorrentStatus::Id status); }; @@ -78,40 +78,37 @@ class DownloadViewItem : public QTreeWidgetItem { public: - DownloadViewItem(QTreeWidget* parent, int type) : - QTreeWidgetItem(parent, type = QTreeWidgetItem::UserType) {}; - - DownloadViewItem(QString hash, const QStringList& strings, - int type = QTreeWidgetItem::UserType) : - QTreeWidgetItem (strings, type = Type), - hash_(hash) - {} - - - /// @return An item comprising of string list, suitable for QTableView - /// header. - static DownloadViewItem *getHeaderItem() - { - DownloadViewItem *item - = new DownloadViewItem("", QStringList() - << "Name" - << "Size" << "Status" - << "Progress" << "DL speed" - << "UL speed" << "Seeds/Leechers" - << "Ratio" << "ETA"); - - return item; - } - - /// @todo QTorrentHandle as one hidden column - - QString getHash() const - { - return hash_; - } + DownloadViewItem(QTreeWidget* parent, int type) : + QTreeWidgetItem(parent, type = QTreeWidgetItem::UserType) {}; + + DownloadViewItem(QString hash, const QStringList& strings, + int type = QTreeWidgetItem::UserType) : + QTreeWidgetItem (strings, type = Type), + hash_(hash) {} + + + /// @return An item comprising of string list, suitable for QTableView + /// header. + static DownloadViewItem *getHeaderItem() { + DownloadViewItem *item + = new DownloadViewItem("", QStringList() + << "Name" + << "Size" << "Status" + << "Progress" << "DL speed" + << "UL speed" << "Seeds/Leechers" + << "Ratio" << "ETA"); + + return item; + } + + /// @todo QTorrentHandle as one hidden column + + QString getHash() const { + return hash_; + } private: - QString hash_; + QString hash_; }; } // namespace qtrapids diff --git a/src/client/MainWindow.cpp b/src/client/MainWindow.cpp index e5e591f..5549bb9 100644 --- a/src/client/MainWindow.cpp +++ b/src/client/MainWindow.cpp @@ -49,204 +49,186 @@ const QString ABOUT_TEXT // 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 diff --git a/src/client/MainWindow.h b/src/client/MainWindow.h index 0cef789..9b55d5b 100644 --- a/src/client/MainWindow.h +++ b/src/client/MainWindow.h @@ -39,57 +39,56 @@ class SeedView; */ class MainWindow : public QMainWindow { - Q_OBJECT; + Q_OBJECT; public: - MainWindow(); - ~MainWindow(); + MainWindow(); + ~MainWindow(); - void connectToServer() - { - qDBusRegisterMetaType(); - qDBusRegisterMetaType(); + void connectToServer() { + qDBusRegisterMetaType(); + qDBusRegisterMetaType(); - connect(&server_ - , SIGNAL(alert(qtrapids::TorrentState - , qtrapids::ParamsMap_t)) - , this - , SLOT(alert(qtrapids::TorrentState - , qtrapids::ParamsMap_t))); - server_.getState(); - } + connect(&server_ + , SIGNAL(alert(qtrapids::TorrentState + , qtrapids::ParamsMap_t)) + , this + , SLOT(alert(qtrapids::TorrentState + , qtrapids::ParamsMap_t))); + server_.getState(); + } signals: - void itemSelected(bool enabled); + 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 alert(qtrapids::TorrentState, qtrapids::ParamsMap_t); + 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 alert(qtrapids::TorrentState, qtrapids::ParamsMap_t); private: - QTabWidget *tabWidget_; - DownloadView *dlView_; - SeedView *seedView_; - PreferencesDialog *preferencesDialog_; - QSettings settings_; + QTabWidget *tabWidget_; + DownloadView *dlView_; + SeedView *seedView_; + PreferencesDialog *preferencesDialog_; + QSettings settings_; - //std::vector< std::auto_ptr const > torrentHandles_; + //std::vector< std::auto_ptr const > torrentHandles_; - QtRapidsServer server_; + QtRapidsServer server_; - //bool IsNewTorrent(std::auto_ptr handlePtr); + //bool IsNewTorrent(std::auto_ptr handlePtr); }; } // namespace qtrapids diff --git a/src/client/PreferencesDialog.cpp b/src/client/PreferencesDialog.cpp index 3742c41..e541e90 100644 --- a/src/client/PreferencesDialog.cpp +++ b/src/client/PreferencesDialog.cpp @@ -29,42 +29,42 @@ #include "PreferencesDialog.h" PreferencesDialog::PreferencesDialog(QWidget* parent, Qt::WindowFlags f) : - QDialog(parent, f), // Superclass - dirLineEdit_(NULL), - dialogButtons_(NULL), - settings_() + QDialog(parent, f), // Superclass + dirLineEdit_(NULL), + dialogButtons_(NULL), + settings_() { - setWindowTitle("Preferences"); + setWindowTitle("Preferences"); - QBoxLayout *verticalBox = new QBoxLayout(QBoxLayout::TopToBottom); - QBoxLayout *horizontalBox1 = new QBoxLayout(QBoxLayout::LeftToRight); - setLayout(verticalBox); - verticalBox->addLayout(horizontalBox1); + QBoxLayout *verticalBox = new QBoxLayout(QBoxLayout::TopToBottom); + QBoxLayout *horizontalBox1 = new QBoxLayout(QBoxLayout::LeftToRight); + setLayout(verticalBox); + verticalBox->addLayout(horizontalBox1); - QLabel *dirLabel = new QLabel(tr("Download directory: ")); - dirLineEdit_ = new QLineEdit(this); - QPushButton *browseDirButton = new QPushButton(tr("Browse..")); + QLabel *dirLabel = new QLabel(tr("Download directory: ")); + dirLineEdit_ = new QLineEdit(this); + QPushButton *browseDirButton = new QPushButton(tr("Browse..")); - horizontalBox1->addWidget(dirLabel); - horizontalBox1->addWidget(dirLineEdit_); - horizontalBox1->addWidget(browseDirButton); + horizontalBox1->addWidget(dirLabel); + horizontalBox1->addWidget(dirLineEdit_); + horizontalBox1->addWidget(browseDirButton); - connect(browseDirButton, SIGNAL(clicked()), - this, SLOT(on_browseDirButtonClicked())); + connect(browseDirButton, SIGNAL(clicked()), + this, SLOT(on_browseDirButtonClicked())); - dialogButtons_ = new QDialogButtonBox(this); - dialogButtons_->setStandardButtons(QDialogButtonBox::Ok - | QDialogButtonBox::Apply - | QDialogButtonBox::Cancel); + dialogButtons_ = new QDialogButtonBox(this); + dialogButtons_->setStandardButtons(QDialogButtonBox::Ok + | QDialogButtonBox::Apply + | QDialogButtonBox::Cancel); - verticalBox->addWidget(dialogButtons_); + verticalBox->addWidget(dialogButtons_); - connect(dialogButtons_, SIGNAL(clicked(QAbstractButton*)), - this, SLOT(on_buttonClicked(QAbstractButton*))); + connect(dialogButtons_, SIGNAL(clicked(QAbstractButton*)), + this, SLOT(on_buttonClicked(QAbstractButton*))); - // Set saved preference values to fields. - ReadSettings(); + // Set saved preference values to fields. + ReadSettings(); } @@ -76,68 +76,67 @@ PreferencesDialog::~PreferencesDialog() // ======================== SLOTS ======================== void PreferencesDialog::on_browseDirButtonClicked() { - QFileDialog *dialog - = new QFileDialog(this, "Download directory", - QString(), tr("Torrent files (*.torrent)")); + QFileDialog *dialog + = new QFileDialog(this, "Download directory", + QString(), tr("Torrent files (*.torrent)")); - dialog->setFileMode(QFileDialog::Directory); - dialog->setOption(QFileDialog::ShowDirsOnly, true); + dialog->setFileMode(QFileDialog::Directory); + dialog->setOption(QFileDialog::ShowDirsOnly, true); - connect(dialog, SIGNAL(fileSelected(const QString&)), - this, SLOT(on_downloadDirectorySelected(const QString&))); + connect(dialog, SIGNAL(fileSelected(const QString&)), + this, SLOT(on_downloadDirectorySelected(const QString&))); - dialog->show(); + dialog->show(); } void PreferencesDialog::on_buttonClicked(QAbstractButton* button) { - switch (dialogButtons_->buttonRole ( button ) ) - { - case QDialogButtonBox::AcceptRole : - qDebug() << "PreferencesDialog: OK"; - WriteSettings(); - close(); - break; - case QDialogButtonBox::ApplyRole : - qDebug() << "PreferencesDialog: APPLY"; - WriteSettings(); - break; - case QDialogButtonBox::RejectRole : - qDebug() << "PreferencesDialog: CANCEL"; - close(); - break; - default: - return; - } + switch (dialogButtons_->buttonRole ( button ) ) { + case QDialogButtonBox::AcceptRole : + qDebug() << "PreferencesDialog: OK"; + WriteSettings(); + close(); + break; + case QDialogButtonBox::ApplyRole : + qDebug() << "PreferencesDialog: APPLY"; + WriteSettings(); + break; + case QDialogButtonBox::RejectRole : + qDebug() << "PreferencesDialog: CANCEL"; + close(); + break; + default: + return; + } } void PreferencesDialog::on_downloadDirectorySelected(const QString& directory) { - qDebug() << "PreferencesDialog::on_downloadDirectorySelected(): " << directory; - // Torrent filename empty, do nothing. - if (directory == "") - return; + qDebug() << "PreferencesDialog::on_downloadDirectorySelected(): " << directory; + // Torrent filename empty, do nothing. + if (directory == "") + return; - dirLineEdit_->insert(directory); + dirLineEdit_->insert(directory); - /// @todo check that user has privileges to write to this directory. + /// @todo check that user has privileges to write to this directory. } // ========================= Private functions ========================== void PreferencesDialog::WriteSettings() { - settings_.setValue("download/directory", dirLineEdit_->text()); + settings_.setValue("download/directory", dirLineEdit_->text()); - // NOTE: We might need to call QSettigns::sync() here to instantly write settings. - // settings are written also by QSettings() destructor and by event loop at regular interval. + // NOTE: We might need to call QSettigns::sync() here to instantly write settings. + // settings are written also by QSettings() destructor and by event loop at regular interval. } void PreferencesDialog::ReadSettings() { - dirLineEdit_->insert(settings_.value("download/directory").toString()); + dirLineEdit_->insert(settings_.value("download/directory").toString()); - // NOTE: We might need to call QSettigns::sync() here to instantly write settings. - // settings are written also by QSettings() destructor and by event loop at regular interval. + // NOTE: We might need to call QSettigns::sync() here to instantly write settings. + // settings are written also by QSettings() destructor and by event loop at regular interval. } diff --git a/src/client/PreferencesDialog.h b/src/client/PreferencesDialog.h index e6f685a..387a1e5 100644 --- a/src/client/PreferencesDialog.h +++ b/src/client/PreferencesDialog.h @@ -34,26 +34,26 @@ class QDialogButtonBox; class PreferencesDialog : public QDialog { - Q_OBJECT + Q_OBJECT public: - PreferencesDialog(QWidget* parent = 0, Qt::WindowFlags f = 0); + PreferencesDialog(QWidget* parent = 0, Qt::WindowFlags f = 0); - ~PreferencesDialog(); + ~PreferencesDialog(); private slots: - void on_browseDirButtonClicked(); - void on_buttonClicked(QAbstractButton* button); - void on_downloadDirectorySelected(const QString& directory); + void on_browseDirButtonClicked(); + void on_buttonClicked(QAbstractButton* button); + void on_downloadDirectorySelected(const QString& directory); private: - QLineEdit *dirLineEdit_; - QDialogButtonBox *dialogButtons_; - QSettings settings_; + QLineEdit *dirLineEdit_; + QDialogButtonBox *dialogButtons_; + QSettings settings_; - // Private functions: - void WriteSettings(); - void ReadSettings(); + // Private functions: + void WriteSettings(); + void ReadSettings(); }; #endif diff --git a/src/client/SeedView.cpp b/src/client/SeedView.cpp index 17c986b..b98308b 100644 --- a/src/client/SeedView.cpp +++ b/src/client/SeedView.cpp @@ -25,13 +25,13 @@ namespace qtrapids { SeedView::SeedView(QWidget* parent): - QTreeWidget(parent) + QTreeWidget(parent) { - setRootIsDecorated(false); // Hide branch lines, making one-level treeview (similar to list) - setHeaderItem(SeedViewItem::getHeaderItem()); + 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))); + connect(this, SIGNAL(itemPressed(QTreeWidgetItem*, int)), + this, SLOT(on_itemPressed(QTreeWidgetItem*, int))); } @@ -41,7 +41,7 @@ SeedView::~SeedView() void SeedView::on_itemPressed(QTreeWidgetItem * item, int column) { - qDebug() << "SeedView::on_itemPressed() " << item << "," << column; + qDebug() << "SeedView::on_itemPressed() " << item << "," << column; } } // namespace qtrapids diff --git a/src/client/SeedView.h b/src/client/SeedView.h index 7961138..91f69aa 100644 --- a/src/client/SeedView.h +++ b/src/client/SeedView.h @@ -33,25 +33,25 @@ class SeedViewItem; */ class SeedView : public QTreeWidget { - Q_OBJECT + Q_OBJECT public: - SeedView(QWidget* parent); + SeedView(QWidget* parent); - ~SeedView(); + ~SeedView(); private slots: - void on_itemPressed(QTreeWidgetItem *item, int column); + void on_itemPressed(QTreeWidgetItem *item, int column); private: - // Name - // Size - // Status - // UP speed - // Seeds/Leechers - // Connected peers - // total uploaded - // ratio + // Name + // Size + // Status + // UP speed + // Seeds/Leechers + // Connected peers + // total uploaded + // ratio }; /** @@ -63,29 +63,28 @@ class SeedViewItem : public QTreeWidgetItem public: - SeedViewItem(QTreeWidget* parent, int type) : - QTreeWidgetItem(parent, type = QTreeWidgetItem::UserType) {}; + SeedViewItem(QTreeWidget* parent, int type) : + QTreeWidgetItem(parent, type = QTreeWidgetItem::UserType) {}; - SeedViewItem(const QStringList& strings, int type = QTreeWidgetItem::UserType ) : - QTreeWidgetItem (strings, type = Type) {}; + SeedViewItem(const QStringList& strings, int type = QTreeWidgetItem::UserType ) : + QTreeWidgetItem (strings, type = Type) {}; - /// @return An item comprising of string list, suitable for QTableView - /// header. - static SeedViewItem *getHeaderItem() - { - SeedViewItem *item - = new SeedViewItem(QStringList() - << "Name" - << "Size" << "Status" - << "Progress" << "UL speed" << "Seeds/Leechers" - << "Conn. peers" - << "Ratio"); + /// @return An item comprising of string list, suitable for QTableView + /// header. + static SeedViewItem *getHeaderItem() { + SeedViewItem *item + = new SeedViewItem(QStringList() + << "Name" + << "Size" << "Status" + << "Progress" << "UL speed" << "Seeds/Leechers" + << "Conn. peers" + << "Ratio"); - return item; - } + return item; + } - /// @todo TorrentHandle as one hidden column + /// @todo TorrentHandle as one hidden column }; } // namespace qtrapids diff --git a/src/client/main.cpp b/src/client/main.cpp index 6968465..9198bb1 100644 --- a/src/client/main.cpp +++ b/src/client/main.cpp @@ -30,45 +30,45 @@ using qtrapids::MainWindow; int main(int argc, char *argv[]) { - QCoreApplication::setOrganizationName("Ixonos"); - QCoreApplication::setOrganizationDomain("ixonos.com"); - QCoreApplication::setApplicationName("QtRapids"); + QCoreApplication::setOrganizationName("Ixonos"); + QCoreApplication::setOrganizationDomain("ixonos.com"); + QCoreApplication::setApplicationName("QtRapids"); - // Q_INIT_RESOURCE(application); - QApplication app(argc, argv); - MainWindow mainWindow; - mainWindow.connectToServer(); - // mainWindow->setGeometry(QApplication::desktop()->screenGeometry()); + // Q_INIT_RESOURCE(application); + QApplication app(argc, argv); + MainWindow mainWindow; + mainWindow.connectToServer(); + // mainWindow->setGeometry(QApplication::desktop()->screenGeometry()); - mainWindow.show(); + mainWindow.show(); - /* - DownloadView* dlw = new DownloadView(NULL); - //qtrapids * mw = new qtrapids(); - dlw->show(); - DownloadViewItem* dlwItem = new DownloadViewItem(QStringList() << "Name" - << "Size" << "Status" - << "Progress" << "DL speed" - << "UL speed" << "Seeds/Leechers" - << "ratio"); - DownloadViewItem* dlwItem2 = new DownloadViewItem(QStringList() << "Name" - << "1000" << "Downloading" - << "23%" << "11" - << "0.1" << "0/2" - << "1.10"); - //dlwItem->insertChild(0, new DownloadViewItem(QStringList() << "Name")); - dlw->insertTopLevelItem(0,dlwItem); - dlw->insertTopLevelItem(1,dlwItem2); + /* + DownloadView* dlw = new DownloadView(NULL); + //qtrapids * mw = new qtrapids(); + dlw->show(); + DownloadViewItem* dlwItem = new DownloadViewItem(QStringList() << "Name" + << "Size" << "Status" + << "Progress" << "DL speed" + << "UL speed" << "Seeds/Leechers" + << "ratio"); + DownloadViewItem* dlwItem2 = new DownloadViewItem(QStringList() << "Name" + << "1000" << "Downloading" + << "23%" << "11" + << "0.1" << "0/2" + << "1.10"); + //dlwItem->insertChild(0, new DownloadViewItem(QStringList() << "Name")); + dlw->insertTopLevelItem(0,dlwItem); + dlw->insertTopLevelItem(1,dlwItem2); - for (unsigned i = 0; i < 10; ++i) - { - DownloadViewItem *editItem = dynamic_cast - (dlw->itemAt(QPoint(0,0))); - editItem->setData ( 8, Qt::DisplayRole, QVariant("EDITED" + QString::number(i, 'g', 2))); - QTest::qSleep(2000); - } - */ + for (unsigned i = 0; i < 10; ++i) + { + DownloadViewItem *editItem = dynamic_cast + (dlw->itemAt(QPoint(0,0))); + editItem->setData ( 8, Qt::DisplayRole, QVariant("EDITED" + QString::number(i, 'g', 2))); + QTest::qSleep(2000); + } + */ - return app.exec(); + return app.exec(); } diff --git a/src/engine/AlertWaiterThread.cpp b/src/engine/AlertWaiterThread.cpp index 0274064..c2f4182 100644 --- a/src/engine/AlertWaiterThread.cpp +++ b/src/engine/AlertWaiterThread.cpp @@ -30,8 +30,8 @@ const libtorrent::time_duration ALERT_WAIT_TIMEOUT AlertWaiterThread::AlertWaiterThread(TorrentSession *const session, QObject* parent) : - QThread(parent), - btSession_(session) + QThread(parent), + btSession_(session) { } @@ -43,32 +43,28 @@ AlertWaiterThread::~AlertWaiterThread() void AlertWaiterThread::allAlerts(bool enable) { - // If all enabled, set all alert cateogries: - if (enable) - { - btSession_->set_alert_mask(libtorrent::alert::all_categories); - } - else - { - // Otherwise set to default, which is only error notifications. - btSession_->set_alert_mask(libtorrent::alert::error_notification); - } + // If all enabled, set all alert cateogries: + if (enable) { + btSession_->set_alert_mask(libtorrent::alert::all_categories); + } else { + // Otherwise set to default, which is only error notifications. + btSession_->set_alert_mask(libtorrent::alert::error_notification); + } } void AlertWaiterThread::run() { - Alert const *alertTemp = NULL; - while (true) - { + Alert const *alertTemp = NULL; + while (true) { #ifdef QTRAPIDS_DEBUG - qDebug() << "AlertWaiter running"; + qDebug() << "AlertWaiter running"; #endif - // wait_for_alert() call blocks. Returns libtorrent alert. - // Returns NULL, if no alerts in timeout period. - alertTemp = btSession_->wait_for_alert(ALERT_WAIT_TIMEOUT); - emit alert(alertTemp); - // 2000 us = 2ms. Gives main thread time to handle alert signal. - usleep(2000); - } + // wait_for_alert() call blocks. Returns libtorrent alert. + // Returns NULL, if no alerts in timeout period. + alertTemp = btSession_->wait_for_alert(ALERT_WAIT_TIMEOUT); + emit alert(alertTemp); + // 2000 us = 2ms. Gives main thread time to handle alert signal. + usleep(2000); + } } diff --git a/src/engine/AlertWaiterThread.h b/src/engine/AlertWaiterThread.h index 4ee3b87..5c4af3f 100644 --- a/src/engine/AlertWaiterThread.h +++ b/src/engine/AlertWaiterThread.h @@ -29,25 +29,25 @@ */ class AlertWaiterThread : public QThread { - Q_OBJECT + Q_OBJECT public: - AlertWaiterThread(TorrentSession *const session, QObject *parent = 0); + AlertWaiterThread(TorrentSession *const session, QObject *parent = 0); - virtual ~AlertWaiterThread(); + virtual ~AlertWaiterThread(); - void allAlerts(bool enable = true); + void allAlerts(bool enable = true); - virtual void run(); // Overridden from QThread + virtual void run(); // Overridden from QThread signals: - /// @TODO alert() uses direct connection, so th connected slot is executed by AlertWaiterThread - /// Hence, QMutex is needed in receiver slot/thread for thread-safety. - /// @NOTE Alternatively, we could use an event loop in the thread and use queued signal (is it heavier?) - void alert(Alert const *alert); + /// @TODO alert() uses direct connection, so th connected slot is executed by AlertWaiterThread + /// Hence, QMutex is needed in receiver slot/thread for thread-safety. + /// @NOTE Alternatively, we could use an event loop in the thread and use queued signal (is it heavier?) + void alert(Alert const *alert); private: - TorrentSession *const btSession_; + TorrentSession *const btSession_; }; diff --git a/src/engine/QBittorrentSession.cpp b/src/engine/QBittorrentSession.cpp index e474f7d..5084f5d 100644 --- a/src/engine/QBittorrentSession.cpp +++ b/src/engine/QBittorrentSession.cpp @@ -27,14 +27,14 @@ namespace qtrapids { QBittorrentSession::QBittorrentSession(QObject *parent): - QObject(parent), - btSession_(), - alertWaiter_(NULL) + QObject(parent), + btSession_(), + alertWaiter_(NULL) { - alertWaiter_ = new AlertWaiterThread(&btSession_, this); - alertWaiter_->allAlerts(); - connect(alertWaiter_, SIGNAL(alert(Alert const*)), this, SLOT(on_alert(Alert const*))); - alertWaiter_->start(); + alertWaiter_ = new AlertWaiterThread(&btSession_, this); + alertWaiter_->allAlerts(); + connect(alertWaiter_, SIGNAL(alert(Alert const*)), this, SLOT(on_alert(Alert const*))); + alertWaiter_->start(); } @@ -46,16 +46,16 @@ QBittorrentSession::~QBittorrentSession() qtrapids::QTorrentHandle QBittorrentSession::addTorrent(AddTorrentParams const& params) { - // Delegate to Libtorrent and return QTorrentHandle. - //std::auto_ptr handlePtr(new QTorrentHandle(btSession_.add_torrent(params))); - qtrapids::QTorrentHandle handle = qtrapids::QTorrentHandle(btSession_.add_torrent(params)); - return handle; + // Delegate to Libtorrent and return QTorrentHandle. + //std::auto_ptr handlePtr(new QTorrentHandle(btSession_.add_torrent(params))); + qtrapids::QTorrentHandle handle = qtrapids::QTorrentHandle(btSession_.add_torrent(params)); + return handle; } void QBittorrentSession::removeTorrent(qtrapids::QTorrentHandle const& handle) { - btSession_.remove_torrent(handle.getHandle()); + btSession_.remove_torrent(handle.getHandle()); } @@ -67,12 +67,12 @@ void QBittorrentSession::on_alert(Alert const *al) { #ifdef QTRAPIDS_DEBUG - if (al) - qDebug() << "on_alert():" << QString::fromStdString(al->message()); + if (al) + qDebug() << "on_alert():" << QString::fromStdString(al->message()); #endif - std::auto_ptr alertPtr = btSession_.pop_alert(); - emit alert(alertPtr); + std::auto_ptr alertPtr = btSession_.pop_alert(); + emit alert(alertPtr); } } //namespace qtrapids diff --git a/src/engine/QBittorrentSession.h b/src/engine/QBittorrentSession.h index 10f49e9..ac2fa8c 100644 --- a/src/engine/QBittorrentSession.h +++ b/src/engine/QBittorrentSession.h @@ -48,26 +48,26 @@ namespace qtrapids */ class QBittorrentSession : public QObject { - Q_OBJECT + Q_OBJECT // class BitTorrentSession; public: - QBittorrentSession(QObject *parent = 0); - ~QBittorrentSession(); + QBittorrentSession(QObject *parent = 0); + ~QBittorrentSession(); - /// @brief Add torrent to session. - qtrapids::QTorrentHandle addTorrent(AddTorrentParams const& params); - void removeTorrent(qtrapids::QTorrentHandle const& handle); + /// @brief Add torrent to session. + qtrapids::QTorrentHandle addTorrent(AddTorrentParams const& params); + void removeTorrent(qtrapids::QTorrentHandle const& handle); signals: - void alert(std::auto_ptr al); + void alert(std::auto_ptr al); private slots: - void on_alert(Alert const *al); + void on_alert(Alert const *al); private: - TorrentSession btSession_; - AlertWaiterThread *alertWaiter_; + TorrentSession btSession_; + AlertWaiterThread *alertWaiter_; }; diff --git a/src/engine/QTorrentHandle.cpp b/src/engine/QTorrentHandle.cpp index 093b1a3..ff8a1ab 100644 --- a/src/engine/QTorrentHandle.cpp +++ b/src/engine/QTorrentHandle.cpp @@ -26,7 +26,7 @@ namespace qtrapids QTorrentHandle::QTorrentHandle(libtorrent::torrent_handle handle) : - torrentHandle_(handle) + torrentHandle_(handle) { } @@ -38,127 +38,123 @@ QTorrentHandle::~QTorrentHandle() TorrentStatus QTorrentHandle::status() const { - return torrentHandle_.status(); + return torrentHandle_.status(); } TorrentInfo const& QTorrentHandle::getTorrentInfo() const { - return torrentHandle_.get_torrent_info(); + return torrentHandle_.get_torrent_info(); } bool QTorrentHandle::isValid() const { - return torrentHandle_.is_valid(); + return torrentHandle_.is_valid(); } QString QTorrentHandle::name() const { - return QString::fromStdString(torrentHandle_.name()); + return QString::fromStdString(torrentHandle_.name()); } size_t QTorrentHandle::getTotalSize() const { - TorrentInfo info = getTorrentInfo(); - return static_cast (info.total_size()); + TorrentInfo info = getTorrentInfo(); + return static_cast (info.total_size()); } QTorrentHandle::State QTorrentHandle::state() const { - TorrentStatus statusTmp = status(); + TorrentStatus statusTmp = status(); - switch (statusTmp.state) - { - case TorrentStatus::queued_for_checking : - return QTorrentHandle::QUEUED_FOR_CHECKING; - case TorrentStatus::checking_files : - return QTorrentHandle::CHECKING_FILES; - case TorrentStatus::downloading_metadata : - return QTorrentHandle::DOWNLOADING_METADATA; - case TorrentStatus::downloading : - return QTorrentHandle::DOWNLOADING; - case TorrentStatus::finished : - return QTorrentHandle::FINISHED; - case TorrentStatus::seeding : - return QTorrentHandle::SEEDING; - case TorrentStatus::allocating : - return QTorrentHandle::ALLOCATING; - default: - return QTorrentHandle::UNSPECIFIED; - } + switch (statusTmp.state) { + case TorrentStatus::queued_for_checking : + return QTorrentHandle::QUEUED_FOR_CHECKING; + case TorrentStatus::checking_files : + return QTorrentHandle::CHECKING_FILES; + case TorrentStatus::downloading_metadata : + return QTorrentHandle::DOWNLOADING_METADATA; + case TorrentStatus::downloading : + return QTorrentHandle::DOWNLOADING; + case TorrentStatus::finished : + return QTorrentHandle::FINISHED; + case TorrentStatus::seeding : + return QTorrentHandle::SEEDING; + case TorrentStatus::allocating : + return QTorrentHandle::ALLOCATING; + default: + return QTorrentHandle::UNSPECIFIED; + } } float QTorrentHandle::progress() const { - TorrentStatus statusTmp = status(); - return statusTmp.progress; + TorrentStatus statusTmp = status(); + return statusTmp.progress; } float QTorrentHandle::uploadRate() const { - TorrentStatus statusTmp = status(); - return statusTmp.upload_rate; + TorrentStatus statusTmp = status(); + return statusTmp.upload_rate; } float QTorrentHandle::downloadRate() const { - TorrentStatus statusTmp = status(); - return statusTmp.download_rate; + TorrentStatus statusTmp = status(); + return statusTmp.download_rate; } qint32 QTorrentHandle::numSeeds() const { - TorrentStatus statusTmp = status(); - return statusTmp.list_seeds; + TorrentStatus statusTmp = status(); + return statusTmp.list_seeds; } qint32 QTorrentHandle::numLeeches() const { - TorrentStatus statusTmp = status(); - return (statusTmp.list_peers - statusTmp.list_seeds); + TorrentStatus statusTmp = status(); + return (statusTmp.list_peers - statusTmp.list_seeds); } qint32 QTorrentHandle::ratio() const { - TorrentStatus statusTmp = status(); - size_t ratio; - if (statusTmp.total_payload_download == 0) - { - ratio = 0; - } - else - { - ratio = static_cast (statusTmp.total_payload_upload / statusTmp.total_payload_download); - } + TorrentStatus statusTmp = status(); + size_t ratio; + if (statusTmp.total_payload_download == 0) { + ratio = 0; + } else { + ratio = static_cast (statusTmp.total_payload_upload / statusTmp.total_payload_download); + } - return ratio; + return ratio; } TorrentHandle QTorrentHandle::getHandle() const { - return torrentHandle_; + return torrentHandle_; } bool QTorrentHandle::operator==(QTorrentHandle const& h) const { - return torrentHandle_ == h.torrentHandle_; + return torrentHandle_ == h.torrentHandle_; } bool QTorrentHandle::operator<(QTorrentHandle const& h) const { - return torrentHandle_ < h.torrentHandle_; + return torrentHandle_ < h.torrentHandle_; } } // namespace qtrapids diff --git a/src/engine/QTorrentHandle.h b/src/engine/QTorrentHandle.h index e68a940..e0d797d 100644 --- a/src/engine/QTorrentHandle.h +++ b/src/engine/QTorrentHandle.h @@ -41,47 +41,46 @@ class QTorrentHandle { public: - enum State - { - QUEUED_FOR_CHECKING = TorrentStatus::queued_for_checking, - CHECKING_FILES, - DOWNLOADING_METADATA, - DOWNLOADING, - FINISHED, - SEEDING, - ALLOCATING, - UNSPECIFIED - }; + enum State { + QUEUED_FOR_CHECKING = TorrentStatus::queued_for_checking, + CHECKING_FILES, + DOWNLOADING_METADATA, + DOWNLOADING, + FINISHED, + SEEDING, + ALLOCATING, + UNSPECIFIED + }; - QTorrentHandle(libtorrent::torrent_handle handle); - ~QTorrentHandle(); + QTorrentHandle(libtorrent::torrent_handle handle); + ~QTorrentHandle(); - TorrentInfo const& getTorrentInfo() const; + TorrentInfo const& getTorrentInfo() const; - bool isValid() const; + bool isValid() const; - QString name() const; - size_t getTotalSize() const; - QTorrentHandle::State state() const; - float progress() const; - float uploadRate() const; - float downloadRate() const; - qint32 numSeeds() const; - qint32 numLeeches() const; - qint32 ratio() const; + QString name() const; + size_t getTotalSize() const; + QTorrentHandle::State state() const; + float progress() const; + float uploadRate() const; + float downloadRate() const; + qint32 numSeeds() const; + qint32 numLeeches() const; + qint32 ratio() const; - TorrentHandle getHandle() const; + TorrentHandle getHandle() const; - bool operator==(QTorrentHandle const& h) const; - bool operator<(QTorrentHandle const& h) const; + bool operator==(QTorrentHandle const& h) const; + bool operator<(QTorrentHandle const& h) const; private: - QTorrentHandle(); // Prevent default construct. - TorrentHandle torrentHandle_; + QTorrentHandle(); // Prevent default construct. + TorrentHandle torrentHandle_; - TorrentStatus status() const; + TorrentStatus status() const; }; diff --git a/src/gui/DownloadView.cpp b/src/gui/DownloadView.cpp index da9642b..03458db 100644 --- a/src/gui/DownloadView.cpp +++ b/src/gui/DownloadView.cpp @@ -25,19 +25,19 @@ DownloadView::DownloadView(QWidget* parent) : - QTreeWidget(parent), - items_(), - timer_(NULL) + QTreeWidget(parent), + items_(), + timer_(NULL) { - setRootIsDecorated(false); // Hide branch lines, making one-level treeview (similar to list) - setHeaderItem(DownloadViewItem::getHeaderItem()); + 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))); + connect(this, SIGNAL(itemPressed(QTreeWidgetItem*, int)), + this, SLOT(on_itemClicked(QTreeWidgetItem*, int))); - timer_ = new QTimer(this); - connect(timer_, SIGNAL(timeout()), this, SLOT(on_timeout())); - timer_->start(5000); + timer_ = new QTimer(this); + connect(timer_, SIGNAL(timeout()), this, SLOT(on_timeout())); + timer_->start(5000); } @@ -50,68 +50,66 @@ DownloadView::~DownloadView() void DownloadView::newItem(qtrapids::QTorrentHandle handle) { #ifdef QTRAPIDS_DEBUG - qDebug() << "DownloadView::newItem() " << items_.count(handle); + qDebug() << "DownloadView::newItem() " << items_.count(handle); #endif - DownloadViewItem *item = new DownloadViewItem(QStringList() - << handle.name() - << QString::number(handle.getTotalSize()) - << GetStatusString(handle.state()) - << QString::number(100*handle.progress() + '%') - << QString::number(handle.downloadRate(), 'f', 2) - << QString::number(handle.uploadRate(), 'f', 2) - << QString::number(handle.numSeeds()) + "/" - + QString::number(handle.numLeeches()) - << QString::number(handle.ratio()) - << "ETA" ); - - // Set text color for status: - QBrush brushTmp(GetStatusColor(handle.state())); - item->setForeground(2, brushTmp); - - addTopLevelItem(item); - items_[handle] = item; + DownloadViewItem *item = new DownloadViewItem(QStringList() + << handle.name() + << QString::number(handle.getTotalSize()) + << GetStatusString(handle.state()) + << QString::number(100*handle.progress() + '%') + << QString::number(handle.downloadRate(), 'f', 2) + << QString::number(handle.uploadRate(), 'f', 2) + << QString::number(handle.numSeeds()) + "/" + + QString::number(handle.numLeeches()) + << QString::number(handle.ratio()) + << "ETA" ); + + // Set text color for status: + QBrush brushTmp(GetStatusColor(handle.state())); + item->setForeground(2, brushTmp); + + addTopLevelItem(item); + items_[handle] = item; } void DownloadView::updateItem(qtrapids::QTorrentHandle handle) { - //qDebug() << "DownloadView::updateItem() " << items_.count(handle); - - static float lastProg = 0; - - // If there are items currently downloading, update: - if (items_.count(handle) > 0) - { - - DownloadViewItem *item = items_[handle]; - - // Only the changing fields are being updated: - item->setData(2, Qt::DisplayRole, - QVariant(GetStatusString(handle.state()))); - item->setData(4, Qt::DisplayRole, - QVariant(QString::number(handle.downloadRate(), 'f', 2))); - item->setData(5, Qt::DisplayRole, - QVariant(QString::number(handle.uploadRate(), 'f', 2))); - item->setData(6, Qt::DisplayRole, - QString::number(handle.numSeeds()) + "/" - + QString::number(handle.numLeeches())); - - // Set progress if increment is 1 percent. - float prog = handle.progress(); - if ((prog-lastProg) >= 0.01 || prog >= 1.0) - { - item->setData(3, Qt::DisplayRole, - QVariant(QString::number(100*prog) + '%')); - lastProg = prog; - } - - /// @TODO: ETA-counter adjusting,if ETA is to be implemented - - // Adjust color - QBrush brushTmp(GetStatusColor(handle.state())); - item->setForeground(2, brushTmp); - } + //qDebug() << "DownloadView::updateItem() " << items_.count(handle); + + static float lastProg = 0; + + // If there are items currently downloading, update: + if (items_.count(handle) > 0) { + + DownloadViewItem *item = items_[handle]; + + // Only the changing fields are being updated: + item->setData(2, Qt::DisplayRole, + QVariant(GetStatusString(handle.state()))); + item->setData(4, Qt::DisplayRole, + QVariant(QString::number(handle.downloadRate(), 'f', 2))); + item->setData(5, Qt::DisplayRole, + QVariant(QString::number(handle.uploadRate(), 'f', 2))); + item->setData(6, Qt::DisplayRole, + QString::number(handle.numSeeds()) + "/" + + QString::number(handle.numLeeches())); + + // Set progress if increment is 1 percent. + float prog = handle.progress(); + if ((prog-lastProg) >= 0.01 || prog >= 1.0) { + item->setData(3, Qt::DisplayRole, + QVariant(QString::number(100*prog) + '%')); + lastProg = prog; + } + + /// @TODO: ETA-counter adjusting,if ETA is to be implemented + + // Adjust color + QBrush brushTmp(GetStatusColor(handle.state())); + item->setForeground(2, brushTmp); + } } @@ -119,40 +117,37 @@ void DownloadView::updateItem(qtrapids::QTorrentHandle handle) qtrapids::QTorrentHandle DownloadView::removeSelected() { #ifdef QTRAPIDS_DEBUG - qDebug() << "DownloadView::removeSelected() " << topLevelItemCount() ; + qDebug() << "DownloadView::removeSelected() " << topLevelItemCount() ; #endif - DownloadViewItem *item = dynamic_cast (currentItem()); + DownloadViewItem *item = dynamic_cast (currentItem()); - std::map::iterator listIter - = items_.begin(); - std::map::iterator listEnd - = items_.end(); + std::map::iterator listIter + = items_.begin(); + std::map::iterator listEnd + = items_.end(); - while (listIter != listEnd) - { - if (listIter->second == item) - { - break; - } - ++listIter; - } + while (listIter != listEnd) { + if (listIter->second == item) { + break; + } + ++listIter; + } - qtrapids::QTorrentHandle handle = listIter->first; - items_.erase(listIter); + qtrapids::QTorrentHandle handle = listIter->first; + items_.erase(listIter); - int index = indexOfTopLevelItem(currentItem()); - if (index >= 0) - { - takeTopLevelItem(index); - } + int index = indexOfTopLevelItem(currentItem()); + if (index >= 0) { + takeTopLevelItem(index); + } #ifdef QTRAPIDS_DEBUG - qDebug() << "DownloadView::removeSelected() " << topLevelItemCount() ; + qDebug() << "DownloadView::removeSelected() " << topLevelItemCount() ; #endif - return handle; + return handle; } @@ -163,89 +158,86 @@ void DownloadView::removeItem(qtrapids::QTorrentHandle handle) void DownloadView::setRefreshInterval(int msec) { - timer_->setInterval(msec); + timer_->setInterval(msec); } 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); - } - */ + /* + qDebug() << "DownloadView::on_itemClicked(()" << item << "," << column; + qDebug() << "current item" << currentItem(); + + if (item == currentItem() && item->isSelected()) { + item->setSelected(false); + } + */ } void DownloadView::on_timeout() { #ifdef QTRAPIDS_DEBUG - qDebug() << "DownloadView::on_timeout()"; + qDebug() << "DownloadView::on_timeout()"; #endif - UpdateView(); + UpdateView(); } QString DownloadView::GetStatusString(qtrapids::QTorrentHandle::State const& status) const { - switch (status) - { - case qtrapids::QTorrentHandle::QUEUED_FOR_CHECKING : - return tr("Queued"); - case qtrapids::QTorrentHandle::CHECKING_FILES : - return tr("Checking"); - case qtrapids::QTorrentHandle::DOWNLOADING_METADATA : - return tr("DL meta"); - case qtrapids::QTorrentHandle::DOWNLOADING : - return tr("Downloading"); - case qtrapids::QTorrentHandle::FINISHED : - return tr("Finished"); - case qtrapids::QTorrentHandle::SEEDING : - return tr("Seeding"); - case qtrapids::QTorrentHandle::ALLOCATING : - return tr("Allocating"); - default: - return tr("N/A"); - } + switch (status) { + case qtrapids::QTorrentHandle::QUEUED_FOR_CHECKING : + return tr("Queued"); + case qtrapids::QTorrentHandle::CHECKING_FILES : + return tr("Checking"); + case qtrapids::QTorrentHandle::DOWNLOADING_METADATA : + return tr("DL meta"); + case qtrapids::QTorrentHandle::DOWNLOADING : + return tr("Downloading"); + case qtrapids::QTorrentHandle::FINISHED : + return tr("Finished"); + case qtrapids::QTorrentHandle::SEEDING : + return tr("Seeding"); + case qtrapids::QTorrentHandle::ALLOCATING : + return tr("Allocating"); + default: + return tr("N/A"); + } } QColor DownloadView::GetStatusColor(qtrapids::QTorrentHandle::State const& status) const { - QColor green(40,205,40); - QColor yellow(255,174,0); - - switch (status) - { - case qtrapids::QTorrentHandle::QUEUED_FOR_CHECKING : - case qtrapids::QTorrentHandle::CHECKING_FILES : - case qtrapids::QTorrentHandle::DOWNLOADING_METADATA : - case qtrapids::QTorrentHandle::ALLOCATING : - return yellow; - case qtrapids::QTorrentHandle::DOWNLOADING : - case qtrapids::QTorrentHandle::FINISHED : - case qtrapids::QTorrentHandle::SEEDING : - return green; - default: - return QColor(); - } + QColor green(40,205,40); + QColor yellow(255,174,0); + + switch (status) { + case qtrapids::QTorrentHandle::QUEUED_FOR_CHECKING : + case qtrapids::QTorrentHandle::CHECKING_FILES : + case qtrapids::QTorrentHandle::DOWNLOADING_METADATA : + case qtrapids::QTorrentHandle::ALLOCATING : + return yellow; + case qtrapids::QTorrentHandle::DOWNLOADING : + case qtrapids::QTorrentHandle::FINISHED : + case qtrapids::QTorrentHandle::SEEDING : + return green; + default: + return QColor(); + } } void DownloadView::UpdateView() { - DownloadViewItem *item = dynamic_cast (currentItem()); - - std::map::iterator listIter - = items_.begin(); - std::map::iterator listEnd - = items_.end(); - - while (listIter != listEnd) - { - updateItem(listIter->first); - ++listIter; - } + DownloadViewItem *item = dynamic_cast (currentItem()); + + std::map::iterator listIter + = items_.begin(); + std::map::iterator listEnd + = items_.end(); + + while (listIter != listEnd) { + updateItem(listIter->first); + ++listIter; + } } diff --git a/src/gui/DownloadView.h b/src/gui/DownloadView.h index 1ffc529..2a66141 100644 --- a/src/gui/DownloadView.h +++ b/src/gui/DownloadView.h @@ -36,33 +36,33 @@ class QTimer; */ class DownloadView : public QTreeWidget { - Q_OBJECT + Q_OBJECT public: - DownloadView(QWidget* parent); + DownloadView(QWidget* parent); - ~DownloadView(); + ~DownloadView(); - void newItem(qtrapids::QTorrentHandle handle); - void updateItem(qtrapids::QTorrentHandle handle); - qtrapids::QTorrentHandle removeSelected(); - void removeItem(qtrapids::QTorrentHandle handle); - void setRefreshInterval(int msec); + void newItem(qtrapids::QTorrentHandle handle); + void updateItem(qtrapids::QTorrentHandle handle); + qtrapids::QTorrentHandle removeSelected(); + void removeItem(qtrapids::QTorrentHandle handle); + void setRefreshInterval(int msec); private slots: - void on_itemClicked(QTreeWidgetItem * item, int column); - void on_timeout(); + void on_itemClicked(QTreeWidgetItem * item, int column); + void on_timeout(); private: - // Maps torrent to downloadview item. - // Key: SHA1 info hash of torrent. Data: View item corresponding to torrent. - std::map items_; - QTimer *timer_; + // Maps torrent to downloadview item. + // Key: SHA1 info hash of torrent. Data: View item corresponding to torrent. + std::map items_; + QTimer *timer_; - // Private functions. - QString GetStatusString(qtrapids::QTorrentHandle::State const& status) const; - QColor GetStatusColor(qtrapids::QTorrentHandle::State const& status) const; - void UpdateView(); + // Private functions. + QString GetStatusString(qtrapids::QTorrentHandle::State const& status) const; + QColor GetStatusColor(qtrapids::QTorrentHandle::State const& status) const; + void UpdateView(); }; @@ -76,30 +76,29 @@ class DownloadViewItem : public QTreeWidgetItem { public: - DownloadViewItem(QTreeWidget* parent, int type) : - QTreeWidgetItem(parent, type = QTreeWidgetItem::UserType) {}; - - DownloadViewItem(const QStringList& strings, - int type = QTreeWidgetItem::UserType) : - QTreeWidgetItem (strings, type = Type) {}; - - - /// @return An item comprising of string list, suitable for QTableView - /// header. - static DownloadViewItem *getHeaderItem() - { - DownloadViewItem *item - = new DownloadViewItem(QStringList() - << "Name" - << "Size" << "Status" - << "Progress" << "DL speed" - << "UL speed" << "Seeds/Leechers" - << "Ratio" << "ETA"); - - return item; - } - - /// @todo QTorrentHandle as one hidden column + DownloadViewItem(QTreeWidget* parent, int type) : + QTreeWidgetItem(parent, type = QTreeWidgetItem::UserType) {}; + + DownloadViewItem(const QStringList& strings, + int type = QTreeWidgetItem::UserType) : + QTreeWidgetItem (strings, type = Type) {}; + + + /// @return An item comprising of string list, suitable for QTableView + /// header. + static DownloadViewItem *getHeaderItem() { + DownloadViewItem *item + = new DownloadViewItem(QStringList() + << "Name" + << "Size" << "Status" + << "Progress" << "DL speed" + << "UL speed" << "Seeds/Leechers" + << "Ratio" << "ETA"); + + return item; + } + + /// @todo QTorrentHandle as one hidden column }; #endif diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 35ee2da..2425ffc 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -45,75 +45,75 @@ const QString ABOUT_TEXT // Consturctor MainWindow::MainWindow(): - QMainWindow(), // Superclass - tabWidget_(NULL), - dlView_(NULL), - seedView_(NULL), - preferencesDialog_(NULL), - settings_(), + QMainWindow(), // Superclass + tabWidget_(NULL), + dlView_(NULL), + seedView_(NULL), + preferencesDialog_(NULL), + settings_(), // torrentHandles_(), - btSession_() + btSession_() { - // 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(); - tabWidget_->setTabsClosable(true); - - /// @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*))); - - connect(&btSession_, SIGNAL(alert(std::auto_ptr)), - this, SLOT(on_alert(std::auto_ptr))); - - LoadPlugins(); + // 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(); + tabWidget_->setTabsClosable(true); + + /// @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*))); + + connect(&btSession_, SIGNAL(alert(std::auto_ptr)), + this, SLOT(on_alert(std::auto_ptr))); + + LoadPlugins(); } @@ -125,22 +125,22 @@ MainWindow::~MainWindow() bool MainWindow::setGui(qtrapids::PluginInterface* from, QWidget* widget) { #ifdef QTRAPIDS_DEBUG - qDebug() << "MainWindow::setGui():" << dlView_->currentItem(); + qDebug() << "MainWindow::setGui():" << dlView_->currentItem(); #endif - tabWidget_->addTab(widget, tr("Search")); - return true; + tabWidget_->addTab(widget, tr("Search")); + return true; } /// @todo Add PluginInterface parameter check which plugin gives the widget to handle appropriately void MainWindow::addPluginWidget(qtrapids::PluginInterface* from, QWidget* widget) { #ifdef QTRAPIDS_DEBUG - qDebug() << "MainWindow::addPluginWidget():" << dlView_->currentItem(); + qDebug() << "MainWindow::addPluginWidget():" << dlView_->currentItem(); #endif - int index = tabWidget_->addTab(widget, tr("Test")); - tabWidget_->setCurrentIndex(index); - //layout_->addWidget(widget); + int index = tabWidget_->addTab(widget, tr("Test")); + tabWidget_->setCurrentIndex(index); + //layout_->addWidget(widget); } void MainWindow::addToolbar(qtrapids::PluginInterface* from, QWidget* widget) @@ -163,48 +163,39 @@ void MainWindow::addMenuItem(qtrapids::PluginInterface* from, QWidget* widget) void MainWindow::LoadPlugins() { - /// @todo get plugin directory from settings or go through multiple diectories - /// Now we only check the application directory - pluginsDir_ = QDir(qApp->applicationDirPath()); - pluginsDir_.cd("plugins"); - QStringList nameFilters; - nameFilters << "*.so"; - - foreach (QString fileName, pluginsDir_.entryList(nameFilters, QDir::Files)) - { - QPluginLoader pluginLoader(pluginsDir_.absoluteFilePath(fileName)); - - if (!QLibrary::isLibrary(fileName)) - { - qDebug() << fileName << " not a library"; - } - - if (pluginLoader.load()) - { - qDebug() << "Plugin loaded: " << fileName; - } - else - { - qDebug() << "Plugin load failed: " << pluginLoader.errorString(); - } - - QObject *baseInstance = pluginLoader.instance(); - if (!baseInstance) - { - qDebug() << "Base instance = NULL."; - } - - qtrapids::PluginInterface *plugin = qobject_cast(baseInstance); - - if (!plugin) - { - qDebug() << "Cast failed."; - } - else - { - plugin->initialize(this); - pluginFileNames_ += fileName; - } + /// @todo get plugin directory from settings or go through multiple diectories + /// Now we only check the application directory + pluginsDir_ = QDir(qApp->applicationDirPath()); + pluginsDir_.cd("plugins"); + QStringList nameFilters; + nameFilters << "*.so"; + + foreach (QString fileName, pluginsDir_.entryList(nameFilters, QDir::Files)) { + QPluginLoader pluginLoader(pluginsDir_.absoluteFilePath(fileName)); + + if (!QLibrary::isLibrary(fileName)) { + qDebug() << fileName << " not a library"; + } + + if (pluginLoader.load()) { + qDebug() << "Plugin loaded: " << fileName; + } else { + qDebug() << "Plugin load failed: " << pluginLoader.errorString(); + } + + QObject *baseInstance = pluginLoader.instance(); + if (!baseInstance) { + qDebug() << "Base instance = NULL."; + } + + qtrapids::PluginInterface *plugin = qobject_cast(baseInstance); + + if (!plugin) { + qDebug() << "Cast failed."; + } else { + plugin->initialize(this); + pluginFileNames_ += fileName; + } // QObject *plugin = pluginLoader.instance(); // if (plugin) { @@ -212,9 +203,9 @@ void MainWindow::LoadPlugins() // pluginFileNames += fileName; // } - } + } - //pluginLoader_.setFileName("../libsearchplugin.so"); + //pluginLoader_.setFileName("../libsearchplugin.so"); @@ -224,136 +215,123 @@ void MainWindow::LoadPlugins() // =========================== 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() { - qtrapids::QTorrentHandle handle = dlView_->removeSelected(); - btSession_.removeTorrent(handle); + qtrapids::QTorrentHandle handle = dlView_->removeSelected(); + btSession_.removeTorrent(handle); } 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() { #ifdef QTRAPIDS_DEBUG - qDebug() << "MainWindow::on_seedItemSelectionChanged():" << dlView_->currentItem(); + qDebug() << "MainWindow::on_seedItemSelectionChanged():" << dlView_->currentItem(); #endif - if (dlView_->currentItem() != NULL) - { - emit(itemSelected(true)); - } - else - { - emit(itemSelected(false)); - } + if (dlView_->currentItem() != NULL) { + emit(itemSelected(true)); + } else { + emit(itemSelected(false)); + } } void MainWindow::on_seedItemSelectionChanged() { #ifdef QTRAPIDS_DEBUG - qDebug() << "MainWindow::on_seedItemSelectionChanged():" << seedView_->currentItem(); + qDebug() << "MainWindow::on_seedItemSelectionChanged():" << seedView_->currentItem(); #endif - if (seedView_->currentItem() != NULL) - { - emit(itemSelected(true)); - } - else - { - emit(itemSelected(false)); - } + 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) { #ifdef QTRAPIDS_DEBUG - qDebug() << " MainWindow::on_torrentFileSelected(): " << file; + qDebug() << " MainWindow::on_torrentFileSelected(): " << file; #endif - // Torrent filename empty, do nothing. - if (file == "") - { - return; - } - - // Otherwise add torrent - // For params, see: http://www.rasterbar.com/products/libtorrent/manual.html#add-torrent - AddTorrentParams addParams; - boost::intrusive_ptr tiTmp = - new libtorrent::torrent_info(boost::filesystem::path(file.toStdString())); - addParams.ti = tiTmp; - // 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; - qtrapids::QTorrentHandle handle = btSession_.addTorrent(addParams); - dlView_->newItem(handle); + // Torrent filename empty, do nothing. + if (file == "") { + return; + } + + // Otherwise add torrent + // For params, see: http://www.rasterbar.com/products/libtorrent/manual.html#add-torrent + AddTorrentParams addParams; + boost::intrusive_ptr tiTmp = + new libtorrent::torrent_info(boost::filesystem::path(file.toStdString())); + addParams.ti = tiTmp; + // 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; + qtrapids::QTorrentHandle handle = btSession_.addTorrent(addParams); + dlView_->newItem(handle); // torrentHandles_.push_back(handlePtr); #ifdef QTRAPIDS_DEBUG - qDebug() << "Is valid: " << handle.isValid(); + qDebug() << "Is valid: " << handle.isValid(); #endif } void MainWindow::on_alert(std::auto_ptr al) { - if (al.get() != NULL) - { + if (al.get() != NULL) { // qDebug() // << "MainWindow::on_torrentAlert(): " // << QString::fromStdString(al->message()); - TorrentAlert *torrentAlert - = dynamic_cast (al.get()); + TorrentAlert *torrentAlert + = dynamic_cast (al.get()); - if (torrentAlert) - { - qtrapids::QTorrentHandle torrentHandle = qtrapids::QTorrentHandle(torrentAlert->handle); - dlView_->updateItem(qtrapids::QTorrentHandle(torrentAlert->handle)); - } + if (torrentAlert) { + qtrapids::QTorrentHandle torrentHandle = qtrapids::QTorrentHandle(torrentAlert->handle); + dlView_->updateItem(qtrapids::QTorrentHandle(torrentAlert->handle)); + } - } + } } /* diff --git a/src/gui/MainWindow.h b/src/gui/MainWindow.h index a47ca78..8dd1fdc 100644 --- a/src/gui/MainWindow.h +++ b/src/gui/MainWindow.h @@ -38,51 +38,51 @@ class PreferencesDialog; */ class MainWindow : public QMainWindow, public qtrapids::PluginHostInterface { - Q_OBJECT + Q_OBJECT public: - MainWindow(); + MainWindow(); - virtual ~MainWindow(); + virtual ~MainWindow(); - // Implemented from PluginHostInterface - virtual bool setGui(qtrapids::PluginInterface* from, QWidget* widget); - virtual void addPluginWidget(qtrapids::PluginInterface* from, QWidget* widget); - virtual void addToolbar(qtrapids::PluginInterface* from, QWidget* widget); - virtual void addToolItem(qtrapids::PluginInterface* from, QWidget* widget); - virtual void addMenu(qtrapids::PluginInterface* from, QWidget* widget); - virtual void addMenuItem(qtrapids::PluginInterface* from, QWidget* widget); + // Implemented from PluginHostInterface + virtual bool setGui(qtrapids::PluginInterface* from, QWidget* widget); + virtual void addPluginWidget(qtrapids::PluginInterface* from, QWidget* widget); + virtual void addToolbar(qtrapids::PluginInterface* from, QWidget* widget); + virtual void addToolItem(qtrapids::PluginInterface* from, QWidget* widget); + virtual void addMenu(qtrapids::PluginInterface* from, QWidget* widget); + virtual void addMenuItem(qtrapids::PluginInterface* from, QWidget* widget); signals: - void itemSelected(bool enabled); + 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_alert(std::auto_ptr al); + 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_alert(std::auto_ptr al); private: - void LoadPlugins(); + void LoadPlugins(); private: - QTabWidget *tabWidget_; - DownloadView *dlView_; - SeedView *seedView_; - PreferencesDialog *preferencesDialog_; - QSettings settings_; - QDir pluginsDir_; - QStringList pluginFileNames_; + QTabWidget *tabWidget_; + DownloadView *dlView_; + SeedView *seedView_; + PreferencesDialog *preferencesDialog_; + QSettings settings_; + QDir pluginsDir_; + QStringList pluginFileNames_; - qtrapids::QBittorrentSession btSession_; + qtrapids::QBittorrentSession btSession_; }; diff --git a/src/gui/PreferencesDialog.cpp b/src/gui/PreferencesDialog.cpp index 3742c41..e541e90 100644 --- a/src/gui/PreferencesDialog.cpp +++ b/src/gui/PreferencesDialog.cpp @@ -29,42 +29,42 @@ #include "PreferencesDialog.h" PreferencesDialog::PreferencesDialog(QWidget* parent, Qt::WindowFlags f) : - QDialog(parent, f), // Superclass - dirLineEdit_(NULL), - dialogButtons_(NULL), - settings_() + QDialog(parent, f), // Superclass + dirLineEdit_(NULL), + dialogButtons_(NULL), + settings_() { - setWindowTitle("Preferences"); + setWindowTitle("Preferences"); - QBoxLayout *verticalBox = new QBoxLayout(QBoxLayout::TopToBottom); - QBoxLayout *horizontalBox1 = new QBoxLayout(QBoxLayout::LeftToRight); - setLayout(verticalBox); - verticalBox->addLayout(horizontalBox1); + QBoxLayout *verticalBox = new QBoxLayout(QBoxLayout::TopToBottom); + QBoxLayout *horizontalBox1 = new QBoxLayout(QBoxLayout::LeftToRight); + setLayout(verticalBox); + verticalBox->addLayout(horizontalBox1); - QLabel *dirLabel = new QLabel(tr("Download directory: ")); - dirLineEdit_ = new QLineEdit(this); - QPushButton *browseDirButton = new QPushButton(tr("Browse..")); + QLabel *dirLabel = new QLabel(tr("Download directory: ")); + dirLineEdit_ = new QLineEdit(this); + QPushButton *browseDirButton = new QPushButton(tr("Browse..")); - horizontalBox1->addWidget(dirLabel); - horizontalBox1->addWidget(dirLineEdit_); - horizontalBox1->addWidget(browseDirButton); + horizontalBox1->addWidget(dirLabel); + horizontalBox1->addWidget(dirLineEdit_); + horizontalBox1->addWidget(browseDirButton); - connect(browseDirButton, SIGNAL(clicked()), - this, SLOT(on_browseDirButtonClicked())); + connect(browseDirButton, SIGNAL(clicked()), + this, SLOT(on_browseDirButtonClicked())); - dialogButtons_ = new QDialogButtonBox(this); - dialogButtons_->setStandardButtons(QDialogButtonBox::Ok - | QDialogButtonBox::Apply - | QDialogButtonBox::Cancel); + dialogButtons_ = new QDialogButtonBox(this); + dialogButtons_->setStandardButtons(QDialogButtonBox::Ok + | QDialogButtonBox::Apply + | QDialogButtonBox::Cancel); - verticalBox->addWidget(dialogButtons_); + verticalBox->addWidget(dialogButtons_); - connect(dialogButtons_, SIGNAL(clicked(QAbstractButton*)), - this, SLOT(on_buttonClicked(QAbstractButton*))); + connect(dialogButtons_, SIGNAL(clicked(QAbstractButton*)), + this, SLOT(on_buttonClicked(QAbstractButton*))); - // Set saved preference values to fields. - ReadSettings(); + // Set saved preference values to fields. + ReadSettings(); } @@ -76,68 +76,67 @@ PreferencesDialog::~PreferencesDialog() // ======================== SLOTS ======================== void PreferencesDialog::on_browseDirButtonClicked() { - QFileDialog *dialog - = new QFileDialog(this, "Download directory", - QString(), tr("Torrent files (*.torrent)")); + QFileDialog *dialog + = new QFileDialog(this, "Download directory", + QString(), tr("Torrent files (*.torrent)")); - dialog->setFileMode(QFileDialog::Directory); - dialog->setOption(QFileDialog::ShowDirsOnly, true); + dialog->setFileMode(QFileDialog::Directory); + dialog->setOption(QFileDialog::ShowDirsOnly, true); - connect(dialog, SIGNAL(fileSelected(const QString&)), - this, SLOT(on_downloadDirectorySelected(const QString&))); + connect(dialog, SIGNAL(fileSelected(const QString&)), + this, SLOT(on_downloadDirectorySelected(const QString&))); - dialog->show(); + dialog->show(); } void PreferencesDialog::on_buttonClicked(QAbstractButton* button) { - switch (dialogButtons_->buttonRole ( button ) ) - { - case QDialogButtonBox::AcceptRole : - qDebug() << "PreferencesDialog: OK"; - WriteSettings(); - close(); - break; - case QDialogButtonBox::ApplyRole : - qDebug() << "PreferencesDialog: APPLY"; - WriteSettings(); - break; - case QDialogButtonBox::RejectRole : - qDebug() << "PreferencesDialog: CANCEL"; - close(); - break; - default: - return; - } + switch (dialogButtons_->buttonRole ( button ) ) { + case QDialogButtonBox::AcceptRole : + qDebug() << "PreferencesDialog: OK"; + WriteSettings(); + close(); + break; + case QDialogButtonBox::ApplyRole : + qDebug() << "PreferencesDialog: APPLY"; + WriteSettings(); + break; + case QDialogButtonBox::RejectRole : + qDebug() << "PreferencesDialog: CANCEL"; + close(); + break; + default: + return; + } } void PreferencesDialog::on_downloadDirectorySelected(const QString& directory) { - qDebug() << "PreferencesDialog::on_downloadDirectorySelected(): " << directory; - // Torrent filename empty, do nothing. - if (directory == "") - return; + qDebug() << "PreferencesDialog::on_downloadDirectorySelected(): " << directory; + // Torrent filename empty, do nothing. + if (directory == "") + return; - dirLineEdit_->insert(directory); + dirLineEdit_->insert(directory); - /// @todo check that user has privileges to write to this directory. + /// @todo check that user has privileges to write to this directory. } // ========================= Private functions ========================== void PreferencesDialog::WriteSettings() { - settings_.setValue("download/directory", dirLineEdit_->text()); + settings_.setValue("download/directory", dirLineEdit_->text()); - // NOTE: We might need to call QSettigns::sync() here to instantly write settings. - // settings are written also by QSettings() destructor and by event loop at regular interval. + // NOTE: We might need to call QSettigns::sync() here to instantly write settings. + // settings are written also by QSettings() destructor and by event loop at regular interval. } void PreferencesDialog::ReadSettings() { - dirLineEdit_->insert(settings_.value("download/directory").toString()); + dirLineEdit_->insert(settings_.value("download/directory").toString()); - // NOTE: We might need to call QSettigns::sync() here to instantly write settings. - // settings are written also by QSettings() destructor and by event loop at regular interval. + // NOTE: We might need to call QSettigns::sync() here to instantly write settings. + // settings are written also by QSettings() destructor and by event loop at regular interval. } diff --git a/src/gui/PreferencesDialog.h b/src/gui/PreferencesDialog.h index e6f685a..387a1e5 100644 --- a/src/gui/PreferencesDialog.h +++ b/src/gui/PreferencesDialog.h @@ -34,26 +34,26 @@ class QDialogButtonBox; class PreferencesDialog : public QDialog { - Q_OBJECT + Q_OBJECT public: - PreferencesDialog(QWidget* parent = 0, Qt::WindowFlags f = 0); + PreferencesDialog(QWidget* parent = 0, Qt::WindowFlags f = 0); - ~PreferencesDialog(); + ~PreferencesDialog(); private slots: - void on_browseDirButtonClicked(); - void on_buttonClicked(QAbstractButton* button); - void on_downloadDirectorySelected(const QString& directory); + void on_browseDirButtonClicked(); + void on_buttonClicked(QAbstractButton* button); + void on_downloadDirectorySelected(const QString& directory); private: - QLineEdit *dirLineEdit_; - QDialogButtonBox *dialogButtons_; - QSettings settings_; + QLineEdit *dirLineEdit_; + QDialogButtonBox *dialogButtons_; + QSettings settings_; - // Private functions: - void WriteSettings(); - void ReadSettings(); + // Private functions: + void WriteSettings(); + void ReadSettings(); }; #endif diff --git a/src/gui/SeedView.cpp b/src/gui/SeedView.cpp index d90daeb..431e50e 100644 --- a/src/gui/SeedView.cpp +++ b/src/gui/SeedView.cpp @@ -21,14 +21,14 @@ #include "SeedView.h" SeedView::SeedView(QWidget* parent): - QTreeWidget(parent), - items_() + QTreeWidget(parent), + items_() { - setRootIsDecorated(false); // Hide branch lines, making one-level treeview (similar to list) - setHeaderItem(SeedViewItem::getHeaderItem()); + 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))); + connect(this, SIGNAL(itemPressed( QTreeWidgetItem*, int)), + this, SLOT(on_itemPressed(QTreeWidgetItem*, int))); } @@ -38,6 +38,6 @@ SeedView::~SeedView() void SeedView::on_itemPressed(QTreeWidgetItem * item, int column) { - qDebug() << "SeedView::on_itemPressed() " << item << "," << column; + qDebug() << "SeedView::on_itemPressed() " << item << "," << column; } diff --git a/src/gui/SeedView.h b/src/gui/SeedView.h index 766fe19..37fdf75 100644 --- a/src/gui/SeedView.h +++ b/src/gui/SeedView.h @@ -31,31 +31,31 @@ class SeedViewItem; */ class SeedView : public QTreeWidget { - Q_OBJECT + Q_OBJECT public: - SeedView(QWidget* parent); + SeedView(QWidget* parent); - ~SeedView(); + ~SeedView(); - void newItem(qtrapids::QTorrentHandle const* handle); - void updateItem(qtrapids::QTorrentHandle const* handle); + void newItem(qtrapids::QTorrentHandle const* handle); + void updateItem(qtrapids::QTorrentHandle const* handle); private slots: - void on_itemPressed(QTreeWidgetItem *item, int column); + 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. - std::map items_; - - // Name - // Size - // Status - // UP speed - // Seeds/Leechers - // Connected peers - // total uploaded - // ratio + // Maps torrent to SeedView item. + // Key: SHA1 info hash of torrent. Data: View item corresponding to torrent. + std::map items_; + + // Name + // Size + // Status + // UP speed + // Seeds/Leechers + // Connected peers + // total uploaded + // ratio }; /** @@ -67,29 +67,28 @@ class SeedViewItem : public QTreeWidgetItem public: - SeedViewItem(QTreeWidget* parent, int type) : - QTreeWidgetItem(parent, type = QTreeWidgetItem::UserType) {}; + SeedViewItem(QTreeWidget* parent, int type) : + QTreeWidgetItem(parent, type = QTreeWidgetItem::UserType) {}; - SeedViewItem(const QStringList& strings, int type = QTreeWidgetItem::UserType ) : - QTreeWidgetItem (strings, type = Type) {}; + SeedViewItem(const QStringList& strings, int type = QTreeWidgetItem::UserType ) : + QTreeWidgetItem (strings, type = Type) {}; - /// @return An item comprising of string list, suitable for QTableView - /// header. - static SeedViewItem *getHeaderItem() - { - SeedViewItem *item - = new SeedViewItem(QStringList() - << "Name" - << "Size" << "Status" - << "Progress" << "UL speed" << "Seeds/Leechers" - << "Conn. peers" - << "Ratio"); + /// @return An item comprising of string list, suitable for QTableView + /// header. + static SeedViewItem *getHeaderItem() { + SeedViewItem *item + = new SeedViewItem(QStringList() + << "Name" + << "Size" << "Status" + << "Progress" << "UL speed" << "Seeds/Leechers" + << "Conn. peers" + << "Ratio"); - return item; - } + return item; + } - /// @todo QTorrentHandle as one hidden column + /// @todo QTorrentHandle as one hidden column }; #endif diff --git a/src/gui/main.cpp b/src/gui/main.cpp index c6032bd..ceccaa5 100644 --- a/src/gui/main.cpp +++ b/src/gui/main.cpp @@ -27,42 +27,42 @@ int main(int argc, char *argv[]) { - QCoreApplication::setOrganizationName("Ixonos"); - QCoreApplication::setOrganizationDomain("ixonos.com"); - QCoreApplication::setApplicationName("QtRapids"); + QCoreApplication::setOrganizationName("Ixonos"); + QCoreApplication::setOrganizationDomain("ixonos.com"); + QCoreApplication::setApplicationName("QtRapids"); - // Q_INIT_RESOURCE(application); - QApplication app(argc, argv); - MainWindow *mainWindow = new MainWindow(); - mainWindow->show(); + // Q_INIT_RESOURCE(application); + QApplication app(argc, argv); + MainWindow *mainWindow = new MainWindow(); + mainWindow->show(); - /* - DownloadView* dlw = new DownloadView(NULL); - //qtrapids * mw = new qtrapids(); - dlw->show(); - DownloadViewItem* dlwItem = new DownloadViewItem(QStringList() << "Name" - << "Size" << "Status" - << "Progress" << "DL speed" - << "UL speed" << "Seeds/Leechers" - << "ratio"); - DownloadViewItem* dlwItem2 = new DownloadViewItem(QStringList() << "Name" - << "1000" << "Downloading" - << "23%" << "11" - << "0.1" << "0/2" - << "1.10"); - //dlwItem->insertChild(0, new DownloadViewItem(QStringList() << "Name")); - dlw->insertTopLevelItem(0,dlwItem); - dlw->insertTopLevelItem(1,dlwItem2); + /* + DownloadView* dlw = new DownloadView(NULL); + //qtrapids * mw = new qtrapids(); + dlw->show(); + DownloadViewItem* dlwItem = new DownloadViewItem(QStringList() << "Name" + << "Size" << "Status" + << "Progress" << "DL speed" + << "UL speed" << "Seeds/Leechers" + << "ratio"); + DownloadViewItem* dlwItem2 = new DownloadViewItem(QStringList() << "Name" + << "1000" << "Downloading" + << "23%" << "11" + << "0.1" << "0/2" + << "1.10"); + //dlwItem->insertChild(0, new DownloadViewItem(QStringList() << "Name")); + dlw->insertTopLevelItem(0,dlwItem); + dlw->insertTopLevelItem(1,dlwItem2); - for (unsigned i = 0; i < 10; ++i) - { - DownloadViewItem *editItem = dynamic_cast - (dlw->itemAt(QPoint(0,0))); - editItem->setData ( 8, Qt::DisplayRole, QVariant("EDITED" + QString::number(i, 'g', 2))); - QTest::qSleep(2000); - } - */ + for (unsigned i = 0; i < 10; ++i) + { + DownloadViewItem *editItem = dynamic_cast + (dlw->itemAt(QPoint(0,0))); + editItem->setData ( 8, Qt::DisplayRole, QVariant("EDITED" + QString::number(i, 'g', 2))); + QTest::qSleep(2000); + } + */ - return app.exec(); + return app.exec(); } diff --git a/src/include/qtrapids/dbus.hpp b/src/include/qtrapids/dbus.hpp index c7e91c4..79d1cd5 100644 --- a/src/include/qtrapids/dbus.hpp +++ b/src/include/qtrapids/dbus.hpp @@ -11,40 +11,37 @@ namespace qtrapids { -struct TorrentState -{ - - enum torrent_action - { - action_add, - action_remove, - action_update - }; - - TorrentState() - : hash("") - , name("") - , state(0) - , progress(0) - , down_rate(0) - , up_rate(0) - , seeds(0) - , leeches(0) - , ratio(0) - , total_size(0) - { } - - QString hash; - QString name; - torrent_action action; - uint state; - uint progress; - uint down_rate; - uint up_rate; - uint seeds; - uint leeches; - uint ratio; - qulonglong total_size; +struct TorrentState { + + enum torrent_action { + action_add, + action_remove, + action_update + }; + + TorrentState() + : hash("") + , name("") + , state(0) + , progress(0) + , down_rate(0) + , up_rate(0) + , seeds(0) + , leeches(0) + , ratio(0) + , total_size(0) { } + + QString hash; + QString name; + torrent_action action; + uint state; + uint progress; + uint down_rate; + uint up_rate; + uint seeds; + uint leeches; + uint ratio; + qulonglong total_size; }; typedef QHash ParamsMap_t; @@ -55,61 +52,59 @@ typedef QHash::const_iterator ParamsMapConstIterator_t; static inline QDBusArgument& operator << (QDBusArgument& argument , TorrentState const& state) { - std::cout << "serialize" << std::endl; - argument.beginStructure(); - argument << state.hash << state.name << (uint)(state.action) << state.state << state.progress - << state.down_rate << state.up_rate << state.seeds - << state.leeches << state.ratio << state.total_size; - argument.endStructure(); - return argument; + std::cout << "serialize" << std::endl; + argument.beginStructure(); + argument << state.hash << state.name << (uint)(state.action) << state.state << state.progress + << state.down_rate << state.up_rate << state.seeds + << state.leeches << state.ratio << state.total_size; + argument.endStructure(); + return argument; } static inline QDBusArgument const& operator >> (QDBusArgument const& argument , TorrentState& state) { - std::cout << "deserialize" << std::endl; - argument.beginStructure(); - uint action; - argument >> state.hash >> state.name >> action >> state.state >> state.progress - >> state.down_rate >> state.up_rate >> state.seeds - >> state.leeches >> state.ratio >> state.total_size; - state.action = (TorrentState::torrent_action)action; - argument.endStructure(); - return argument; + std::cout << "deserialize" << std::endl; + argument.beginStructure(); + uint action; + argument >> state.hash >> state.name >> action >> state.state >> state.progress + >> state.down_rate >> state.up_rate >> state.seeds + >> state.leeches >> state.ratio >> state.total_size; + state.action = (TorrentState::torrent_action)action; + argument.endStructure(); + return argument; } static inline QDBusArgument& operator << (QDBusArgument& argument , ParamsMapConst_t& params) { - ParamsMapConstIterator_t p; - std::cout << "serialize params" << std::endl; - argument.beginMap(); - for (p = params.constBegin(); p != params.constEnd(); ++p) - { - argument.beginMapEntry(); - argument << p.key() << p.value(); - argument.endMapEntry(); - } - argument.endMap(); - return argument; + ParamsMapConstIterator_t p; + std::cout << "serialize params" << std::endl; + argument.beginMap(); + for (p = params.constBegin(); p != params.constEnd(); ++p) { + argument.beginMapEntry(); + argument << p.key() << p.value(); + argument.endMapEntry(); + } + argument.endMap(); + return argument; } static inline QDBusArgument const& operator >> (QDBusArgument const& argument , ParamsMap_t& params) { - ParamsMapConstIterator_t p; - QString key, value; - std::cout << "deserialize params" << std::endl; - argument.beginMap(); - for (p = params.constBegin(); p != params.constEnd(); ++p) - { - argument.beginMapEntry(); - argument >> key >> value; - params[key] = value; - argument.endMapEntry(); - } - argument.endMap(); - return argument; + ParamsMapConstIterator_t p; + QString key, value; + std::cout << "deserialize params" << std::endl; + argument.beginMap(); + for (p = params.constBegin(); p != params.constEnd(); ++p) { + argument.beginMapEntry(); + argument >> key >> value; + params[key] = value; + argument.endMapEntry(); + } + argument.endMap(); + return argument; } diff --git a/src/include/qtrapids/error.hpp b/src/include/qtrapids/error.hpp index f6e8946..d5a6685 100644 --- a/src/include/qtrapids/error.hpp +++ b/src/include/qtrapids/error.hpp @@ -10,30 +10,27 @@ class Error { public: - Error() - : msg_("") - { } + Error() + : msg_("") { } - Error(char const *msg) - : msg_(msg) - {} + Error(char const *msg) + : msg_(msg) {} - template - void append_to_msg(T val) - { - msg_ << val; - } + template + void append_to_msg(T val) { + msg_ << val; + } private: - QString msg_; + QString msg_; }; template Error& operator << (Error &self, T val) { - self.append_to_msg(val); - return self; + self.append_to_msg(val); + return self; } class InvalidArgument : public Error @@ -43,8 +40,8 @@ class InvalidArgument : public Error template InvalidArgument& operator << (InvalidArgument &self, T val) { - self.append_to_msg(val); - return self; + self.append_to_msg(val); + return self; } } diff --git a/src/include/qtrapids/format.hpp b/src/include/qtrapids/format.hpp index 8880348..2fcbc6f 100644 --- a/src/include/qtrapids/format.hpp +++ b/src/include/qtrapids/format.hpp @@ -12,40 +12,36 @@ namespace qtrapids static inline QString formatProgress(uint progress) { - return QString::number(progress / torrent_progress_percent); + return QString::number(progress / torrent_progress_percent); } -namespace -{ +namespace { static const qulonglong size_KB = 1024; static const qulonglong size_MB = size_KB << 10; static const qulonglong size_GB = size_MB << 10; -static char const* size_names[] = -{ - "GB", - "MB", - "KB", - "B" +static char const* size_names[] = { + "GB", + "MB", + "KB", + "B" }; } static inline QString formatSize(qulonglong size) { - qulonglong unit = size_GB; - char const ** unit_name = &size_names[0]; - QString ret(""); - for (unit = size_GB; unit > 0; unit >>= 10, ++unit_name) - { - if (size & (~(unit - 1))) - { - ret += (QString::number(size / unit) + *unit_name); - return ret; - } - } - ret = QString::number(size) + "B"; - return ret; + qulonglong unit = size_GB; + char const ** unit_name = &size_names[0]; + QString ret(""); + for (unit = size_GB; unit > 0; unit >>= 10, ++unit_name) { + if (size & (~(unit - 1))) { + ret += (QString::number(size / unit) + *unit_name); + return ret; + } + } + ret = QString::number(size) + "B"; + return ret; } diff --git a/src/include/qtrapids/info.hpp b/src/include/qtrapids/info.hpp index 221cc7a..81c7017 100644 --- a/src/include/qtrapids/info.hpp +++ b/src/include/qtrapids/info.hpp @@ -16,20 +16,18 @@ static const uint32_t torrent_progress_percent = 10000; typedef libtorrent::torrent_status TorrentStatus_t; typedef libtorrent::torrent_status::state_t TorrentStatusIds_t; -struct TorrentStatus -{ - enum Id - { - QUEUED_FOR_CHECKING = TorrentStatus_t::queued_for_checking, - CHECKING_FILES = TorrentStatus_t::checking_files, - DOWNLOADING_METADATA = TorrentStatus_t::downloading_metadata, - DOWNLOADING = TorrentStatus_t::downloading, - FINISHED = TorrentStatus_t::finished, - SEEDING = TorrentStatus_t::seeding, - ALLOCATING = TorrentStatus_t::allocating, - CHECKING_RESUME_DATA = TorrentStatus_t::checking_resume_data, - UNSPECIFIED - }; +struct TorrentStatus { + enum Id { + QUEUED_FOR_CHECKING = TorrentStatus_t::queued_for_checking, + CHECKING_FILES = TorrentStatus_t::checking_files, + DOWNLOADING_METADATA = TorrentStatus_t::downloading_metadata, + DOWNLOADING = TorrentStatus_t::downloading, + FINISHED = TorrentStatus_t::finished, + SEEDING = TorrentStatus_t::seeding, + ALLOCATING = TorrentStatus_t::allocating, + CHECKING_RESUME_DATA = TorrentStatus_t::checking_resume_data, + UNSPECIFIED + }; }; } diff --git a/src/include/qtrapids/settings.hpp b/src/include/qtrapids/settings.hpp index bc2ab96..071d0f8 100644 --- a/src/include/qtrapids/settings.hpp +++ b/src/include/qtrapids/settings.hpp @@ -8,14 +8,13 @@ static inline QVariant GetSettingsStoreDefault(QSettings &settings , QString const& name , QVariant const& default_value) { - QVariant v(settings.value(name)); - if (!v.isNull()) - { - return v; - } + QVariant v(settings.value(name)); + if (!v.isNull()) { + return v; + } - settings.setValue(name, default_value); - return default_value; + settings.setValue(name, default_value); + return default_value; } } diff --git a/src/plugins/PluginInterface.h b/src/plugins/PluginInterface.h index 019dc9a..427c330 100644 --- a/src/plugins/PluginInterface.h +++ b/src/plugins/PluginInterface.h @@ -40,20 +40,20 @@ class PluginHostInterface { public: - /// @brief Sets the plugin GUI element to host application - /// @note It is up to the host application to decide how to manage - /// and show the actual widget. - virtual bool setGui(PluginInterface* from, QWidget* widget) = 0; - - /// @brief Adds additional plugin wigdets to the host application. - /// This functio can be called by the plugin recursively, i.e. when GUI events occur - /// The host application must handle placing the additional widgets. - /// @todo Could we implement this using in a more manageable way, e.g. signal-slot? - virtual void addPluginWidget(PluginInterface* from, QWidget* widget) = 0; - virtual void addToolbar(PluginInterface* from, QWidget* widget) = 0; - virtual void addToolItem(PluginInterface* from, QWidget* widget) = 0; - virtual void addMenu(PluginInterface* from, QWidget* widget) = 0; - virtual void addMenuItem(PluginInterface* from, QWidget* widget) = 0; + /// @brief Sets the plugin GUI element to host application + /// @note It is up to the host application to decide how to manage + /// and show the actual widget. + virtual bool setGui(PluginInterface* from, QWidget* widget) = 0; + + /// @brief Adds additional plugin wigdets to the host application. + /// This functio can be called by the plugin recursively, i.e. when GUI events occur + /// The host application must handle placing the additional widgets. + /// @todo Could we implement this using in a more manageable way, e.g. signal-slot? + virtual void addPluginWidget(PluginInterface* from, QWidget* widget) = 0; + virtual void addToolbar(PluginInterface* from, QWidget* widget) = 0; + virtual void addToolItem(PluginInterface* from, QWidget* widget) = 0; + virtual void addMenu(PluginInterface* from, QWidget* widget) = 0; + virtual void addMenuItem(PluginInterface* from, QWidget* widget) = 0; }; ======= >>>>>>> .r31 @@ -70,21 +70,21 @@ public: { public: - >>>>>>> .r31 - /// @brief Sets the plugin GUI element to host application - /// @note It is up to the host application to decide how to manage - /// and show the actual widget. - virtual bool setGui(QWidget* widget) = 0; - - /// @brief Adds additional plugin wigdets to the host application. - /// This functio can be called by the plugin recursively, i.e. when GUI events occur - /// The host application must handle placing the additional widgets. - /// @todo Could we implement this using in a more manageable way, e.g. signal-slot? - virtual void addPluginWidget(QWidget* widget) = 0; - virtual void addToolbar() = 0; - virtual void addToolItem() = 0; - virtual void addMenu() = 0; - virtual void addMenuItem() = 0; + >>>>>>> .r31 + /// @brief Sets the plugin GUI element to host application + /// @note It is up to the host application to decide how to manage + /// and show the actual widget. + virtual bool setGui(QWidget* widget) = 0; + + /// @brief Adds additional plugin wigdets to the host application. + /// This functio can be called by the plugin recursively, i.e. when GUI events occur + /// The host application must handle placing the additional widgets. + /// @todo Could we implement this using in a more manageable way, e.g. signal-slot? + virtual void addPluginWidget(QWidget* widget) = 0; + virtual void addToolbar() = 0; + virtual void addToolItem() = 0; + virtual void addMenu() = 0; + virtual void addMenuItem() = 0; }; @@ -96,9 +96,9 @@ public: class PluginInterface : public QObject { public: - /// @brief Initializes the plugin instance. - virtual void initialize(PluginHostInterface* host) = 0; - virtual QWidget* getGui() = 0; + /// @brief Initializes the plugin instance. + virtual void initialize(PluginHostInterface* host) = 0; + virtual QWidget* getGui() = 0; }; } //namespace qtrapids diff --git a/src/plugins/searchplugin/SearchPlugin.cpp b/src/plugins/searchplugin/SearchPlugin.cpp index 65f3b89..8c6aac4 100644 --- a/src/plugins/searchplugin/SearchPlugin.cpp +++ b/src/plugins/searchplugin/SearchPlugin.cpp @@ -35,126 +35,122 @@ namespace qtrapids { <<<<<<< .mine SearchPlugin::SearchPlugin() : - comboBox_(NULL), searchLine_(NULL), searchButton_(NULL), host_(NULL) + comboBox_(NULL), searchLine_(NULL), searchButton_(NULL), host_(NULL) { - // TODO: Parse engine descriptions. - // -Add engines to model - // -Show model in comboBox + // TODO: Parse engine descriptions. + // -Add engines to model + // -Show model in comboBox } void SearchPlugin::initialize(PluginHostInterface* host) { - host_ = host; + host_ = host; - if (host_ != NULL) - { + if (host_ != NULL) { - QWidget *pluginWidget = new QWidget; - QVBoxLayout *vbox = new QVBoxLayout; - QHBoxLayout *hbox = new QHBoxLayout; - comboBox_ = new QComboBox; - searchLine_ = new QLineEdit; - searchButton_ = new QPushButton("Search"); + QWidget *pluginWidget = new QWidget; + QVBoxLayout *vbox = new QVBoxLayout; + QHBoxLayout *hbox = new QHBoxLayout; + comboBox_ = new QComboBox; + searchLine_ = new QLineEdit; + searchButton_ = new QPushButton("Search"); - hbox->addWidget(searchLine_); - hbox->addWidget(searchButton_); - vbox->addWidget(comboBox_); - vbox->addLayout(hbox); - pluginWidget->setLayout(vbox); + hbox->addWidget(searchLine_); + hbox->addWidget(searchButton_); + vbox->addWidget(comboBox_); + vbox->addLayout(hbox); + pluginWidget->setLayout(vbox); - connect(searchButton_, SIGNAL(clicked()), this, SLOT(on_searchButton_clicked())); - //connect(this, SIGNAL(searchResult(QWidget*)), this, SLOT(on_searchResult(QWidget*))); + connect(searchButton_, SIGNAL(clicked()), this, SLOT(on_searchButton_clicked())); + //connect(this, SIGNAL(searchResult(QWidget*)), this, SLOT(on_searchResult(QWidget*))); - host_->setGui(this, pluginWidget); - } + host_->setGui(this, pluginWidget); + } } QWidget* SearchPlugin::getGui() { - return NULL; + return NULL; } void SearchPlugin::on_searchButton_clicked() { - QUrl searchUrl(QString("http://www.google.fi/search?q=" - + searchLine_->text())); - qDebug() << searchUrl; - QWebView *result = new QWebView; - result->load(searchUrl); + QUrl searchUrl(QString("http://www.google.fi/search?q=" + + searchLine_->text())); + qDebug() << searchUrl; + QWebView *result = new QWebView; + result->load(searchUrl); - on_searchResult((QWidget*)result); + on_searchResult((QWidget*)result); } void SearchPlugin::on_searchResult(QWidget* resultWidget) { - qDebug() << "on_searchResult()"; - if (host_) - { - host_->addPluginWidget(this, resultWidget); - } + qDebug() << "on_searchResult()"; + if (host_) { + host_->addPluginWidget(this, resultWidget); + } } ======= SearchPlugin::SearchPlugin() : - comboBox_(NULL), searchLine_(NULL), searchButton_(NULL), host_(NULL) + comboBox_(NULL), searchLine_(NULL), searchButton_(NULL), host_(NULL) { - // TODO: Parse engine descriptions. - // -Add engines to model - // -Show model in comboBox - >>>>>>> .r31 + // TODO: Parse engine descriptions. + // -Add engines to model + // -Show model in comboBox + >>>>>>> .r31 } void SearchPlugin::initialize(PluginHostInterface* host) { - host_ = host; + host_ = host; - if (host_ != NULL) - { + if (host_ != NULL) { - QWidget *pluginWidget = new QWidget; - QVBoxLayout *vbox = new QVBoxLayout; - QHBoxLayout *hbox = new QHBoxLayout; - comboBox_ = new QComboBox; - searchLine_ = new QLineEdit; - searchButton_ = new QPushButton("Search"); + QWidget *pluginWidget = new QWidget; + QVBoxLayout *vbox = new QVBoxLayout; + QHBoxLayout *hbox = new QHBoxLayout; + comboBox_ = new QComboBox; + searchLine_ = new QLineEdit; + searchButton_ = new QPushButton("Search"); - hbox->addWidget(searchLine_); - hbox->addWidget(searchButton_); - vbox->addWidget(comboBox_); - vbox->addLayout(hbox); - pluginWidget->setLayout(vbox); + hbox->addWidget(searchLine_); + hbox->addWidget(searchButton_); + vbox->addWidget(comboBox_); + vbox->addLayout(hbox); + pluginWidget->setLayout(vbox); - connect(searchButton_, SIGNAL(clicked()), this, SLOT(on_searchButton_clicked())); - //connect(this, SIGNAL(searchResult(QWidget*)), this, SLOT(on_searchResult(QWidget*))); + connect(searchButton_, SIGNAL(clicked()), this, SLOT(on_searchButton_clicked())); + //connect(this, SIGNAL(searchResult(QWidget*)), this, SLOT(on_searchResult(QWidget*))); - host_->setGui(pluginWidget); - } + host_->setGui(pluginWidget); + } } QWidget* SearchPlugin::getGui() { - return NULL; + return NULL; } void SearchPlugin::on_searchButton_clicked() { - QUrl searchUrl(QString("http://www.google.fi/search?q=" - + searchLine_->text())); - qDebug() << searchUrl; - QWebView *result = new QWebView; - result->load(searchUrl); + QUrl searchUrl(QString("http://www.google.fi/search?q=" + + searchLine_->text())); + qDebug() << searchUrl; + QWebView *result = new QWebView; + result->load(searchUrl); - on_searchResult((QWidget*)result); + on_searchResult((QWidget*)result); } void SearchPlugin::on_searchResult(QWidget* resultWidget) { - qDebug() << "on_searchResult()"; - if (host_) - { - host_->addPluginWidget(resultWidget); - } + qDebug() << "on_searchResult()"; + if (host_) { + host_->addPluginWidget(resultWidget); + } } } // namespace qtrapids diff --git a/src/plugins/searchplugin/SearchPlugin.h b/src/plugins/searchplugin/SearchPlugin.h index f8320fc..ff709b2 100644 --- a/src/plugins/searchplugin/SearchPlugin.h +++ b/src/plugins/searchplugin/SearchPlugin.h @@ -35,26 +35,26 @@ namespace qtrapids class SearchPlugin : public PluginInterface { - Q_OBJECT - Q_INTERFACES(qtrapids::PluginInterface) + Q_OBJECT + Q_INTERFACES(qtrapids::PluginInterface) public: - SearchPlugin(); - virtual void initialize(PluginHostInterface* host); - virtual QWidget* getGui(); + SearchPlugin(); + virtual void initialize(PluginHostInterface* host); + virtual QWidget* getGui(); signals: - void searchResult(QWidget* resultwidget); + void searchResult(QWidget* resultwidget); private slots: - void on_searchButton_clicked(); - void on_searchResult(QWidget* resultWidget); + void on_searchButton_clicked(); + void on_searchResult(QWidget* resultWidget); private: - QComboBox *comboBox_; - QLineEdit *searchLine_; - QPushButton *searchButton_; - PluginHostInterface* host_; + QComboBox *comboBox_; + QLineEdit *searchLine_; + QPushButton *searchButton_; + PluginHostInterface* host_; }; diff --git a/src/server/AlertWaiterThread.cpp b/src/server/AlertWaiterThread.cpp index 69ad8db..77e7767 100644 --- a/src/server/AlertWaiterThread.cpp +++ b/src/server/AlertWaiterThread.cpp @@ -32,8 +32,8 @@ const libtorrent::time_duration ALERT_WAIT_TIMEOUT AlertWaiterThread::AlertWaiterThread(session_t *session, QObject* parent) : - QThread(parent), - btSession_(session) + QThread(parent), + btSession_(session) { } @@ -45,31 +45,27 @@ AlertWaiterThread::~AlertWaiterThread() void AlertWaiterThread::allAlerts(bool enable) { - // If all enabled, set all alert cateogries: - if (enable) - { - btSession_->set_alert_mask(libtorrent::alert::all_categories); - } - else - { - // Otherwise set to default, which is only error notifications. - btSession_->set_alert_mask(libtorrent::alert::error_notification); - } + // If all enabled, set all alert cateogries: + if (enable) { + btSession_->set_alert_mask(libtorrent::alert::all_categories); + } else { + // Otherwise set to default, which is only error notifications. + btSession_->set_alert_mask(libtorrent::alert::error_notification); + } } void AlertWaiterThread::run() { - alert_t const *alertTemp = NULL; - while (true) - { - // wait_for_alert() call blocks. Returns libtorrent alert. - // Returns NULL, if no alerts in timeout period. - alertTemp = btSession_->wait_for_alert(ALERT_WAIT_TIMEOUT); - emit alert(); - // 2000 us = 2ms. Gives main thread time to handle alert signal. - usleep(2000); - } + alert_t const *alertTemp = NULL; + while (true) { + // wait_for_alert() call blocks. Returns libtorrent alert. + // Returns NULL, if no alerts in timeout period. + alertTemp = btSession_->wait_for_alert(ALERT_WAIT_TIMEOUT); + emit alert(); + // 2000 us = 2ms. Gives main thread time to handle alert signal. + usleep(2000); + } } } diff --git a/src/server/AlertWaiterThread.hpp b/src/server/AlertWaiterThread.hpp index ef13a8c..3008638 100644 --- a/src/server/AlertWaiterThread.hpp +++ b/src/server/AlertWaiterThread.hpp @@ -31,22 +31,22 @@ namespace qtrapids */ class AlertWaiterThread : public QThread { - Q_OBJECT + Q_OBJECT public: - AlertWaiterThread(session_t *session, QObject *parent = 0); + AlertWaiterThread(session_t *session, QObject *parent = 0); - virtual ~AlertWaiterThread(); + virtual ~AlertWaiterThread(); - void allAlerts(bool enable = true); + void allAlerts(bool enable = true); - virtual void run(); // Overridden from QThread + virtual void run(); // Overridden from QThread signals: - void alert(); + void alert(); private: - session_t *const btSession_; + session_t *const btSession_; }; diff --git a/src/server/ServerDb.hpp b/src/server/ServerDb.hpp index fdda0a0..342d26a 100644 --- a/src/server/ServerDb.hpp +++ b/src/server/ServerDb.hpp @@ -12,120 +12,104 @@ class ServerSettings { public: - ServerSettings(QSettings *settings) - : settings_(settings) - { } + ServerSettings(QSettings *settings) + : settings_(settings) { } - ~ServerSettings() - { + ~ServerSettings() { - } + } - QString getDbEngine() const - { - return getParamAndStore("db_engine", getDefaultDbEngine()).toString(); - } + QString getDbEngine() const { + return getParamAndStore("db_engine", getDefaultDbEngine()).toString(); + } - QString getDbName() const - { - QString default_db_path(QDir::home().filePath(appName() + ".sqlite")); - return getParamAndStore("db", default_db_path).toString(); - } + QString getDbName() const { + QString default_db_path(QDir::home().filePath(appName() + ".sqlite")); + return getParamAndStore("db", default_db_path).toString(); + } - QString getTorrentsDir() const - { - QString default_dir(QDir::home().filePath(QString(".") + appName())); - return getParamAndStore("db", default_dir).toString(); + QString getTorrentsDir() const { + QString default_dir(QDir::home().filePath(QString(".") + appName())); + return getParamAndStore("db", default_dir).toString(); - } + } private: - ServerSettings(ServerSettings const&); - ServerSettings& operator= (ServerSettings const&); - - static inline QString appName() - { - return QCoreApplication::applicationName(); - } - - static QString getDefaultDbEngine() - { - // for (QStringListIterator p = QSqlDatabase::drivers(); p.hasNext();) { - // return p.next(); - // } - return "QSQLITE"; - } - - QVariant getParamAndStore(QString const& name, QVariant default_value) const - { - QVariant v(settings_->value(name)); - if (!v.isNull()) - { - return v; - } - - settings_->setValue(name, default_value); - return default_value; - } - - mutable QSettings *settings_; + ServerSettings(ServerSettings const&); + ServerSettings& operator= (ServerSettings const&); + + static inline QString appName() { + return QCoreApplication::applicationName(); + } + + static QString getDefaultDbEngine() { + // for (QStringListIterator p = QSqlDatabase::drivers(); p.hasNext();) { + // return p.next(); + // } + return "QSQLITE"; + } + + QVariant getParamAndStore(QString const& name, QVariant default_value) const { + QVariant v(settings_->value(name)); + if (!v.isNull()) { + return v; + } + + settings_->setValue(name, default_value); + return default_value; + } + + mutable QSettings *settings_; }; class ServerDb { public: - ServerDb(ServerSettings *settings) - : db_(QSqlDatabase::addDatabase(settings->getDbEngine())) - { - QString db_name(settings->getDbName()); - db_.setDatabaseName(db_name); - - if (!db_.open()) - { - qDebug() << "cant open db"; - return; - } - qDebug() << "opened " << db_name; - - QSqlQuery q; - if (!q.exec("create table torrents (hash varchar primary key, path varchar, savepath varchar);\n")) - { - qDebug() << "cant create table: " << q.lastError().text(); - } - } - - ~ServerDb() - { - db_.close(); - } - - void addTorrent(const QString &hash, const QString &path, const QString &save_path) - { - if (!db_.open()) - { - qDebug() << "cant open db"; - } - QSqlQuery query_add_; - query_add_.prepare("INSERT INTO torrents (hash, path, savepath) VALUES (?, ?, ?)"); - query_add_.bindValue(0, hash); - query_add_.bindValue(1, path); - query_add_.bindValue(2, save_path); - if (!query_add_.exec()) - { - qDebug() << "cant add torrent info into db: " - << query_add_.lastError().text(); - } - db_.close(); - } + ServerDb(ServerSettings *settings) + : db_(QSqlDatabase::addDatabase(settings->getDbEngine())) { + QString db_name(settings->getDbName()); + db_.setDatabaseName(db_name); + + if (!db_.open()) { + qDebug() << "cant open db"; + return; + } + qDebug() << "opened " << db_name; + + QSqlQuery q; + if (!q.exec("create table torrents (hash varchar primary key, path varchar, savepath varchar);\n")) { + qDebug() << "cant create table: " << q.lastError().text(); + } + } + + ~ServerDb() { + db_.close(); + } + + void addTorrent(const QString &hash, const QString &path, const QString &save_path) { + if (!db_.open()) { + qDebug() << "cant open db"; + } + QSqlQuery query_add_; + query_add_.prepare("INSERT INTO torrents (hash, path, savepath) VALUES (?, ?, ?)"); + query_add_.bindValue(0, hash); + query_add_.bindValue(1, path); + query_add_.bindValue(2, save_path); + if (!query_add_.exec()) { + qDebug() << "cant add torrent info into db: " + << query_add_.lastError().text(); + } + db_.close(); + } private: - ServerDb(ServerDb const&); - ServerDb& operator= (ServerDb const&); + ServerDb(ServerDb const&); + ServerDb& operator= (ServerDb const&); - QSqlDatabase db_; + QSqlDatabase db_; }; } // namespace qtrapids diff --git a/src/server/TorrentHandle.cpp b/src/server/TorrentHandle.cpp index 017d338..5cb7b72 100644 --- a/src/server/TorrentHandle.cpp +++ b/src/server/TorrentHandle.cpp @@ -26,7 +26,7 @@ namespace qtrapids { TorrentHandle::TorrentHandle(libtorrent::torrent_handle handle) : - torrentHandle_(handle) + torrentHandle_(handle) { } @@ -38,108 +38,105 @@ TorrentHandle::~TorrentHandle() TorrentStatus_t TorrentHandle::status() const { - return torrentHandle_.status(); + return torrentHandle_.status(); } torrent_info_cref TorrentHandle::getTorrentInfo() const { - return torrentHandle_.get_torrent_info(); + return torrentHandle_.get_torrent_info(); } bool TorrentHandle::isValid() const { - return torrentHandle_.is_valid(); + return torrentHandle_.is_valid(); } QString TorrentHandle::name() const { - return QString::fromStdString(torrentHandle_.name()); + return QString::fromStdString(torrentHandle_.name()); } size_t TorrentHandle::getTotalSize() const { - torrent_info_cref info = getTorrentInfo(); - return static_cast (info.total_size()); + torrent_info_cref info = getTorrentInfo(); + return static_cast (info.total_size()); } TorrentStatus::Id TorrentHandle::state() const { - TorrentStatus::Id s = (TorrentStatus::Id)(status().state); - return ( (s < TorrentStatus::UNSPECIFIED) - ? s : TorrentStatus::UNSPECIFIED ); + TorrentStatus::Id s = (TorrentStatus::Id)(status().state); + return ( (s < TorrentStatus::UNSPECIFIED) + ? s : TorrentStatus::UNSPECIFIED ); } float TorrentHandle::progress() const { - TorrentStatus_t statusTmp = status(); - return statusTmp.progress; + TorrentStatus_t statusTmp = status(); + return statusTmp.progress; } float TorrentHandle::uploadRate() const { - TorrentStatus_t statusTmp = status(); - return statusTmp.upload_rate; + TorrentStatus_t statusTmp = status(); + return statusTmp.upload_rate; } float TorrentHandle::downloadRate() const { - TorrentStatus_t statusTmp = status(); - return statusTmp.download_rate; + TorrentStatus_t statusTmp = status(); + return statusTmp.download_rate; } qint32 TorrentHandle::numSeeds() const { - TorrentStatus_t statusTmp = status(); - return statusTmp.list_seeds; + TorrentStatus_t statusTmp = status(); + return statusTmp.list_seeds; } qint32 TorrentHandle::numLeeches() const { - TorrentStatus_t statusTmp = status(); - return (statusTmp.list_peers - statusTmp.list_seeds); + TorrentStatus_t statusTmp = status(); + return (statusTmp.list_peers - statusTmp.list_seeds); } qint32 TorrentHandle::ratio() const { - TorrentStatus_t statusTmp = status(); - size_t ratio; - if (statusTmp.total_payload_download == 0) - { - ratio = 0; - } - else - { - ratio = static_cast (statusTmp.total_payload_upload / statusTmp.total_payload_download); - } + TorrentStatus_t statusTmp = status(); + size_t ratio; + if (statusTmp.total_payload_download == 0) { + ratio = 0; + } else { + ratio = static_cast (statusTmp.total_payload_upload / statusTmp.total_payload_download); + } - return ratio; + return ratio; } torrent_handle_t TorrentHandle::getHandle() const { - return torrentHandle_; + return torrentHandle_; } bool TorrentHandle::operator==(TorrentHandle const& h) const { - return torrentHandle_ == h.torrentHandle_; + return torrentHandle_ == h.torrentHandle_; } bool TorrentHandle::operator<(TorrentHandle const& h) const { - return torrentHandle_ < h.torrentHandle_; + return torrentHandle_ < h.torrentHandle_; } diff --git a/src/server/TorrentHandle.hpp b/src/server/TorrentHandle.hpp index bf4423e..9bd716f 100644 --- a/src/server/TorrentHandle.hpp +++ b/src/server/TorrentHandle.hpp @@ -36,7 +36,7 @@ typedef libtorrent::sha1_hash Sha1Hash; inline QString Hash2QStr(Sha1Hash const& hash) { - return QString(hash.to_string().c_str()); + return QString(hash.to_string().c_str()); } /** @@ -46,39 +46,38 @@ class TorrentHandle { public: - TorrentHandle(libtorrent::torrent_handle handle); - ~TorrentHandle(); + TorrentHandle(libtorrent::torrent_handle handle); + ~TorrentHandle(); - torrent_info_cref getTorrentInfo() const; + torrent_info_cref getTorrentInfo() const; - bool isValid() const; + bool isValid() const; - Sha1Hash hash() const - { - return torrentHandle_.info_hash(); - } + Sha1Hash hash() const { + return torrentHandle_.info_hash(); + } - QString name() const; - size_t getTotalSize() const; - TorrentStatus::Id state() const; - float progress() const; - float uploadRate() const; - float downloadRate() const; - qint32 numSeeds() const; - qint32 numLeeches() const; - qint32 ratio() const; + QString name() const; + size_t getTotalSize() const; + TorrentStatus::Id state() const; + float progress() const; + float uploadRate() const; + float downloadRate() const; + qint32 numSeeds() const; + qint32 numLeeches() const; + qint32 ratio() const; - torrent_handle_t getHandle() const; - bool operator==(TorrentHandle const& h) const; - bool operator<(TorrentHandle const& h) const; + torrent_handle_t getHandle() const; + bool operator==(TorrentHandle const& h) const; + bool operator<(TorrentHandle const& h) const; private: - TorrentHandle(); // Prevent default construct. - torrent_handle_t torrentHandle_; + TorrentHandle(); // Prevent default construct. + torrent_handle_t torrentHandle_; - TorrentStatus_t status() const; + TorrentStatus_t status() const; }; diff --git a/src/server/TorrentSession.cpp b/src/server/TorrentSession.cpp index c2fb92b..c6d8b31 100644 --- a/src/server/TorrentSession.cpp +++ b/src/server/TorrentSession.cpp @@ -9,21 +9,21 @@ namespace qtrapids TorrentSession::TorrentSession(QObject *parent, QSettings *settings) - : QObject(parent) - , btSession_() - , alertWaiter_(new AlertWaiterThread(&btSession_, this)) + : QObject(parent) + , btSession_() + , alertWaiter_(new AlertWaiterThread(&btSession_, this)) { - qDBusRegisterMetaType(); - qDBusRegisterMetaType(); - new QtRapidsServer(this); + qDBusRegisterMetaType(); + qDBusRegisterMetaType(); + new QtRapidsServer(this); - QDBusConnection dbus = QDBusConnection::sessionBus(); - dbus.registerObject("/qtrapids", this); - dbus.registerService("com.ixonos.qtrapids"); + QDBusConnection dbus = QDBusConnection::sessionBus(); + dbus.registerObject("/qtrapids", this); + dbus.registerService("com.ixonos.qtrapids"); - alertWaiter_->allAlerts(); - connect(alertWaiter_, SIGNAL(alert()), this, SLOT(on_alert())); - alertWaiter_->start(); + alertWaiter_->allAlerts(); + connect(alertWaiter_, SIGNAL(alert()), this, SLOT(on_alert())); + alertWaiter_->start(); } @@ -32,141 +32,132 @@ void TorrentSession::on_alert() //NOTE: al parameter not necessarily needed here, as we pop_alert() now! { - //qDebug() << "QBittorrentSession:on_alert(" << al << ")"; - // if (al) - // qDebug() << "on_alert():" << QString::fromStdString(al->message()); + //qDebug() << "QBittorrentSession:on_alert(" << al << ")"; + // if (al) + // qDebug() << "on_alert():" << QString::fromStdString(al->message()); - std::auto_ptr alertPtr = btSession_.pop_alert(); + std::auto_ptr alertPtr = btSession_.pop_alert(); - if (alertPtr.get() != NULL) - { + if (alertPtr.get() != NULL) { - torrent_alert_t *ta = dynamic_cast (alertPtr.get()); + torrent_alert_t *ta = dynamic_cast (alertPtr.get()); - qDebug() - << "QBittorrentSession::on_alert(): " - << QString::fromStdString(alertPtr->message()); + qDebug() + << "QBittorrentSession::on_alert(): " + << QString::fromStdString(alertPtr->message()); - if (ta) - { + if (ta) { - if (!ta->handle.is_valid()) - { - qDebug() << "handle is invalid"; - return; - } + if (!ta->handle.is_valid()) { + qDebug() << "handle is invalid"; + return; + } - TorrentHandle handle(ta->handle); - TorrentState state; + TorrentHandle handle(ta->handle); + TorrentState state; - state.hash = Hash2QStr(handle.hash()); - state.action = TorrentState::action_update; - state.state = handle.state(); - state.progress = handle.progress() * torrent_progress_max; - state.down_rate = handle.downloadRate(); - state.up_rate = handle.uploadRate(); - state.seeds = handle.numSeeds(); - state.leeches = handle.numLeeches(); + state.hash = Hash2QStr(handle.hash()); + state.action = TorrentState::action_update; + state.state = handle.state(); + state.progress = handle.progress() * torrent_progress_max; + state.down_rate = handle.downloadRate(); + state.up_rate = handle.uploadRate(); + state.seeds = handle.numSeeds(); + state.leeches = handle.numLeeches(); - ParamsMap_t params; - emit alert(state, params); - } + ParamsMap_t params; + emit alert(state, params); + } - } + } } void TorrentSession::getState() { - torrents_t::const_iterator p; - for (p = torrents_.constBegin(); p != torrents_.constEnd(); ++p) - { - TorrentHandlePtr handle = *p; - TorrentState state; - QString hash = Hash2QStr(handle->hash()); - - state.hash = hash; - state.name = handle->name(); - state.action = TorrentState::action_add; - state.state = handle->state(); - state.progress = handle->progress() * torrent_progress_max; - state.down_rate = handle->downloadRate(); - state.up_rate = handle->uploadRate(); - state.seeds = handle->numSeeds(); - state.leeches = handle->numLeeches(); - state.total_size = handle->getTotalSize(); - - emit alert(state, ParamsMap_t()); - } + torrents_t::const_iterator p; + for (p = torrents_.constBegin(); p != torrents_.constEnd(); ++p) { + TorrentHandlePtr handle = *p; + TorrentState state; + QString hash = Hash2QStr(handle->hash()); + + state.hash = hash; + state.name = handle->name(); + state.action = TorrentState::action_add; + state.state = handle->state(); + state.progress = handle->progress() * torrent_progress_max; + state.down_rate = handle->downloadRate(); + state.up_rate = handle->uploadRate(); + state.seeds = handle->numSeeds(); + state.leeches = handle->numLeeches(); + state.total_size = handle->getTotalSize(); + + emit alert(state, ParamsMap_t()); + } } void TorrentSession::addTorrent(const QString &path, const QString &save_path , qtrapids::ParamsMap_t other_params) { - add_torrent_params_t addParams; - QFile torrent_file(path); - if (!torrent_file.exists()) - { - qWarning() << "Torrent file " << path << "doesn't exist"; - return; - } - - qDebug() << "addTorrent: " << path << " save to " << save_path; - boost::intrusive_ptr tiTmp - = new libtorrent::torrent_info - (boost::filesystem::path(path.toStdString())); - addParams.ti = tiTmp; - - // save_path is the only mandatory parameter, rest are optional. - addParams.save_path = boost::filesystem::path(save_path.toStdString()); - //addParams.storage_mode = libtorrent::storage_mode_allocate; - - TorrentHandlePtr handle(new TorrentHandle(btSession_.add_torrent(addParams))); - QString hash = Hash2QStr(handle->hash()); - - TorrentState state; - - state.hash = hash; - state.name = handle->name(); - state.action = TorrentState::action_add; - state.state = handle->state(); - state.progress = handle->progress() * torrent_progress_max; - state.down_rate = handle->downloadRate(); - state.up_rate = handle->uploadRate(); - state.seeds = handle->numSeeds(); - state.leeches = handle->numLeeches(); - state.total_size = handle->getTotalSize(); - - torrents_[hash] = handle; - - emit alert(state, ParamsMap_t()); + add_torrent_params_t addParams; + QFile torrent_file(path); + if (!torrent_file.exists()) { + qWarning() << "Torrent file " << path << "doesn't exist"; + return; + } + + qDebug() << "addTorrent: " << path << " save to " << save_path; + boost::intrusive_ptr tiTmp + = new libtorrent::torrent_info + (boost::filesystem::path(path.toStdString())); + addParams.ti = tiTmp; + + // save_path is the only mandatory parameter, rest are optional. + addParams.save_path = boost::filesystem::path(save_path.toStdString()); + //addParams.storage_mode = libtorrent::storage_mode_allocate; + + TorrentHandlePtr handle(new TorrentHandle(btSession_.add_torrent(addParams))); + QString hash = Hash2QStr(handle->hash()); + + TorrentState state; + + state.hash = hash; + state.name = handle->name(); + state.action = TorrentState::action_add; + state.state = handle->state(); + state.progress = handle->progress() * torrent_progress_max; + state.down_rate = handle->downloadRate(); + state.up_rate = handle->uploadRate(); + state.seeds = handle->numSeeds(); + state.leeches = handle->numLeeches(); + state.total_size = handle->getTotalSize(); + + torrents_[hash] = handle; + + emit alert(state, ParamsMap_t()); } void TorrentSession::removeTorrent(const QString &hash) { - torrents_t::iterator p = torrents_.find(hash); - - if (p == torrents_.end()) - { - qDebug() << "Invalid request to remove torrent with hash " << hash; - return; - } - try - { - btSession_.remove_torrent(p.value()->getHandle()); - } - catch (torrent_exception_t e) - { - qDebug() << // e.what() - "exception catched" - ; - } - - TorrentState state; - state.hash = hash; - state.action = TorrentState::action_remove; - emit alert(state, ParamsMap_t()); - torrents_.erase(p); + torrents_t::iterator p = torrents_.find(hash); + + if (p == torrents_.end()) { + qDebug() << "Invalid request to remove torrent with hash " << hash; + return; + } + try { + btSession_.remove_torrent(p.value()->getHandle()); + } catch (torrent_exception_t e) { + qDebug() << // e.what() + "exception catched" + ; + } + + TorrentState state; + state.hash = hash; + state.action = TorrentState::action_remove; + emit alert(state, ParamsMap_t()); + torrents_.erase(p); } diff --git a/src/server/TorrentSession.hpp b/src/server/TorrentSession.hpp index 85a8c3f..6240024 100644 --- a/src/server/TorrentSession.hpp +++ b/src/server/TorrentSession.hpp @@ -42,30 +42,30 @@ class ServerSettings; class TorrentSession : public QObject { - Q_OBJECT; - Q_CLASSINFO("D-Bus Interface", "com.ixonos.qtrapids"); + Q_OBJECT; + Q_CLASSINFO("D-Bus Interface", "com.ixonos.qtrapids"); public: - TorrentSession(QObject *parent, QSettings *); + TorrentSession(QObject *parent, QSettings *); public slots: - void getState(); - void addTorrent(const QString &path, const QString &save_path - , qtrapids::ParamsMap_t other_params); - void removeTorrent(const QString &hash); + void getState(); + void addTorrent(const QString &path, const QString &save_path + , qtrapids::ParamsMap_t other_params); + void removeTorrent(const QString &hash); signals: - void alert(qtrapids::TorrentState info, qtrapids::ParamsMap_t other_info); + void alert(qtrapids::TorrentState info, qtrapids::ParamsMap_t other_info); private slots: - void on_alert(); + void on_alert(); private: - session_t btSession_; - AlertWaiterThread *alertWaiter_; - torrents_t torrents_; + session_t btSession_; + AlertWaiterThread *alertWaiter_; + torrents_t torrents_; }; } // namespace qtrapids diff --git a/src/server/main.cpp b/src/server/main.cpp index 9427202..7c3ab9f 100644 --- a/src/server/main.cpp +++ b/src/server/main.cpp @@ -7,13 +7,13 @@ using qtrapids::settings_weak_ptr; int main(int argc, char *argv[]) { - QCoreApplication::setOrganizationName("Ixonos"); - QCoreApplication::setOrganizationDomain("ixonos.com"); - QCoreApplication::setApplicationName("QtRapids"); - QSettings settings(QCoreApplication::organizationName() - , QCoreApplication::applicationName()); + QCoreApplication::setOrganizationName("Ixonos"); + QCoreApplication::setOrganizationDomain("ixonos.com"); + QCoreApplication::setApplicationName("QtRapids"); + QSettings settings(QCoreApplication::organizationName() + , QCoreApplication::applicationName()); - QCoreApplication app(argc, argv); - TorrentSession server(&app, &settings); - return app.exec(); + QCoreApplication app(argc, argv); + TorrentSession server(&app, &settings); + return app.exec(); } -- 1.7.9.5