X-Git-Url: http://vcs.maemo.org/git/?a=blobdiff_plain;f=src%2Fqml-client%2FMainPageHandler.cpp;fp=src%2Fqml-client%2FMainPageHandler.cpp;h=0d3e94f1679400ad4009aa35292a4896f5662686;hb=f77461be3060e91809309f18dcbe791d77cdde2a;hp=26a7760ff5ace8d92d1840248a91ec5cb83c989c;hpb=9de6d5abeb5e02284ffaf786b360776b83077045;p=qtrapids diff --git a/src/qml-client/MainPageHandler.cpp b/src/qml-client/MainPageHandler.cpp index 26a7760..0d3e94f 100644 --- a/src/qml-client/MainPageHandler.cpp +++ b/src/qml-client/MainPageHandler.cpp @@ -19,24 +19,76 @@ #include #include -#include +#include +#include +//#include #include #include "MainPageHandler.h" +#include "qtrapids/dbus.hpp" namespace qtrapids { -MainPageHandler::MainPageHandler(QObject *parent) : - QObject(parent) +MainPageHandler::MainPageHandler(QDeclarativeEngine *engine, QObject *parent) : + QObject(parent), + engine_(engine), + settings_(QCoreApplication::organizationName(), + QCoreApplication::applicationName()), + server_(QtRapidsServer::staticInterfaceName(), + "/qtrapids", QDBusConnection::sessionBus()) { + QDBusConnection dbus = QDBusConnection::sessionBus(); + dbus.registerObject("/qtrapids_gui", this); + dbus.registerService("com.ixonos.qtrapids_gui"); + + connectToServer(); + restoreSettings(); + // Add to QML context. This can then be used in QML context. + QDeclarativeContext *context = engine->rootContext(); + context->setContextProperty("downloadModel", &downloadModel_); + context->setContextProperty("mainPageHandler", this); + + connect(&server_, SIGNAL(alert(qtrapids::TorrentState, qtrapids::ParamsMap_t)), + this, SLOT(on_alert(qtrapids::TorrentState, qtrapids::ParamsMap_t))); + // TODO: Check if this is a problem, as connection is done also in connectToServer() +// connect(&server_, SIGNAL(alert(qtrapids::TorrentState, qtrapids::ParamsMap_t)), +// this, SLOT(on_alert(qtrapids::TorrentState, qtrapids::ParamsMap_t))); + connect(&server_, SIGNAL(sessionTerminated()), this, SLOT(on_serverTerminated())); } MainPageHandler::~MainPageHandler() { } +void MainPageHandler::connectToServer() { + qDBusRegisterMetaType(); + qDBusRegisterMetaType(); + + connect(&server_, + SIGNAL(alert(qtrapids::TorrentState, qtrapids::ParamsMap_t)), + this, SLOT(on_alert(qtrapids::TorrentState, qtrapids::ParamsMap_t))); + // Request server state. + // NOTE: This call starts qtrapids-server automatically with the GUI, + // if the .service file is in /usr/share/dbus-1/services/ + server_.getState(); +} + +void MainPageHandler::restoreSettings() +{ + + // TODO: Rewrite restore to QML age.. + // Restore DownloadView columns: + //dlView_->restoreView(); + + // Restore torrent session settings to server: + qtrapids::ParamsMap_t options; + options["net/downloadRate"] = settings_.value("net/downloadRate").toString(); + options["net/uploadRate"] = settings_.value("net/uploadRate").toString(); + server_.setOptions(options); +} + void MainPageHandler::fileSelectorOpen() { qDebug() << Q_FUNC_INFO; @@ -46,12 +98,19 @@ void MainPageHandler::fileSelectorOpen() } -void MainPageHandler::on_torrentFileSelected(const QString& file) +void MainPageHandler::on_torrentFileSelected(const QString& fileUrl) { - qDebug() << Q_FUNC_INFO << " file selected: " << file; + qDebug() << Q_FUNC_INFO << " file selected: " << fileUrl; + + QUrl filePathUrl(fileUrl); + + if (filePathUrl.scheme() != "file" && filePathUrl.scheme() != "") { + qDebug() << Q_FUNC_INFO << ": currently file:// scheme only supported"; + } // Torrent filename empty, do nothing. - if (file == "") { + if (filePathUrl.toLocalFile().isEmpty()) { + qDebug() << Q_FUNC_INFO << ": empty torrent file path. No action."; return; } @@ -61,12 +120,18 @@ void MainPageHandler::on_torrentFileSelected(const QString& file) //addParams.storage_mode = libtorrent::storage_mode_allocate; try { // TODO: Enable this once server_ is in place -// server_.addTorrent(file, -// settings_.value("download/directory").toString(), -// ParamsMap_t()); + server_.addTorrent(filePathUrl.toString(QUrl::RemoveScheme), + settings_.value("download/directory").toString(), + ParamsMap_t()); } catch (...) { qDebug() << Q_FUNC_INFO << "Exception adding torrent"; } } +void MainPageHandler::on_alert(qtrapids::TorrentState info, qtrapids::ParamsMap_t other_info) +{ + qDebug() << "got alert"; + downloadModel_.updateItem(info, other_info); +} + } //namespace qtrapids