From a4530ce6a29ea37465dd6acc9a359c6be5061e1d Mon Sep 17 00:00:00 2001 From: lvaatamoinen Date: Sun, 29 Jan 2012 21:29:53 +0000 Subject: [PATCH] Added TorrentPickerPage. Added MainHandler to be used with Dbus. TODO: Make torrent picker work and actually load torrent to server process. git-svn-id: file:///svnroot/qtrapids/trunk@87 42ac0dd5-4c8c-4c71-bb3e-ecdfe252ffda --- src/qml-client/CMakeLists.txt | 17 ++----- src/qml-client/MainPageHandler.cpp | 72 ++++++++++++++++++++++++++++++ src/qml-client/MainPageHandler.h | 50 +++++++++++++++++++++ src/qml-client/main.cpp | 30 +++++++------ src/qml-client/qml/MainPage.qml | 24 ++++++++-- src/qml-client/qml/TorrentPickerPage.qml | 55 +++++++++++++++++++++++ src/qml-client/qml/qml.qrc | 1 + 7 files changed, 219 insertions(+), 30 deletions(-) create mode 100644 src/qml-client/MainPageHandler.cpp create mode 100644 src/qml-client/MainPageHandler.h create mode 100644 src/qml-client/qml/TorrentPickerPage.qml diff --git a/src/qml-client/CMakeLists.txt b/src/qml-client/CMakeLists.txt index 873b699..a9d4dbc 100644 --- a/src/qml-client/CMakeLists.txt +++ b/src/qml-client/CMakeLists.txt @@ -19,31 +19,21 @@ INCLUDE_DIRECTORIES( ${QT_QTDBUS} ${QT_QTGUI} ${QT_QTDECLARATIVE_INCLUDE_DIR} + /usr/include/meegotouch ) SET_SOURCE_FILES_PROPERTIES(${CMAKE_CURRENT_SOURCE_DIR}/proxy.cpp ${CMAKE_CURRENT_SOURCE_DIR}/proxy.h PROPERTIES GENERATED 1) SET(MOC_HEADERS + ./MainPageHandler.h ./models/QDeclarativeDownloadListModel.h ./models/QDeclarativeDownloadListModel_p.h -# ./DownloadView.h -# ./models/Plugin.h -# ./MainWindow.h -# ./PreferencesDialog.h -# ./proxy.h -# ./SeedView.h -# ./ColumnSelectorDialog.h ) SET(SRC -# ./DownloadView.cpp ./main.cpp + ./MainPageHandler.cpp ./models/QDeclarativeDownloadListModel.cpp -# ./MainWindow.cpp -# ./PreferencesDialog.cpp -# ./proxy.cpp -# ./SeedView.cpp -# ./ColumnSelectorDialog.cpp ) @@ -83,6 +73,7 @@ TARGET_LINK_LIBRARIES(qml-client ${QT_QTTEST_LIBRARY} ${QT_QTDECLARATIVE_LIBRARY} -lboost_system-mt + -lmeegotouchcore ) # Check if we are building under scratchbox and link with QtMaemo5 only in that case. diff --git a/src/qml-client/MainPageHandler.cpp b/src/qml-client/MainPageHandler.cpp new file mode 100644 index 0000000..26a7760 --- /dev/null +++ b/src/qml-client/MainPageHandler.cpp @@ -0,0 +1,72 @@ +/* + + Copyright (C) 2012 Ixonos Plc + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#include +#include +#include +#include + +#include "MainPageHandler.h" + + +namespace qtrapids +{ + +MainPageHandler::MainPageHandler(QObject *parent) : + QObject(parent) +{ +} + +MainPageHandler::~MainPageHandler() +{ +} + +void MainPageHandler::fileSelectorOpen() +{ + qDebug() << Q_FUNC_INFO; + QWidget* widget = qobject_cast(MApplication::activeWindow()); + QString filename = QFileDialog::getOpenFileName(widget, tr("Open torrent file"), QString(), tr("Torrent files (*.torrent)") ); + on_torrentFileSelected(filename); +} + + +void MainPageHandler::on_torrentFileSelected(const QString& file) +{ + qDebug() << Q_FUNC_INFO << " file selected: " << 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 { + // TODO: Enable this once server_ is in place +// server_.addTorrent(file, +// settings_.value("download/directory").toString(), +// ParamsMap_t()); + } catch (...) { + qDebug() << Q_FUNC_INFO << "Exception adding torrent"; + } +} + +} //namespace qtrapids diff --git a/src/qml-client/MainPageHandler.h b/src/qml-client/MainPageHandler.h new file mode 100644 index 0000000..ada83d1 --- /dev/null +++ b/src/qml-client/MainPageHandler.h @@ -0,0 +1,50 @@ +/* + + Copyright (C) 2012 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + + +#ifndef MAINPAGEHANDLER_H +#define MAINPAGEHANDLER_H + +// Used in this class and main.cpp, so include here +#include +#include + +namespace qtrapids +{ + +class MainPageHandler : public QObject +{ + Q_OBJECT +public: + MainPageHandler(QObject *parent = 0); + virtual ~MainPageHandler(); + + Q_INVOKABLE void fileSelectorOpen(); + +private slots: + void on_torrentFileSelected(const QString& file); + +private: + Q_DISABLE_COPY(MainPageHandler); +}; + +} // namespace qtrapids + + +#endif // MAINPAGEHANDLER_H diff --git a/src/qml-client/main.cpp b/src/qml-client/main.cpp index 9d992b8..674eb3e 100644 --- a/src/qml-client/main.cpp +++ b/src/qml-client/main.cpp @@ -15,26 +15,22 @@ * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#include #include #include #include #include -//#include -//#include "DownloadView.h" #include -#include "models/QDeclarativeDownloadListModel.h" +#include +#include -#include "MainWindow.h" +#include "models/QDeclarativeDownloadListModel.h" +#include "MainPageHandler.h" #include "../include/qtrapids/dbus.hpp" -using qtrapids::MainWindow; - int main(int argc, char *argv[]) { - - + // TODO: Check: could we use MApplication:: instead? QCoreApplication::setOrganizationName("Ixonos"); QCoreApplication::setOrganizationDomain("ixonos.com"); QCoreApplication::setApplicationName("QtRapids"); @@ -43,24 +39,30 @@ int main(int argc, char *argv[]) QApplication app(argc, argv); //MainWindow mainWindow; app.setProperty("NoMStyle", true); - - // Register our types: + + // Register our types (e.g. models and stuff): qmlRegisterType("QtRapids", 1, 0, "DownloadListModel"); QDir::setCurrent(app.applicationDirPath()); QDeclarativeView window; - //QDeclarativeEngine engine; + // Setting the root context properties. Create an QObject-derived + // object: qtrapids::QDeclarativeDownloadListModel downloadModel; + qtrapids::MainPageHandler mainPageHandler; + // ... and add to QML context. This can then be used in QML context. QDeclarativeContext *context = window.rootContext(); context->setContextProperty("downloadModel", &downloadModel); + context->setContextProperty("mainPageHandler", &mainPageHandler); + + // Initial QML file/resource: window.setSource(QUrl("qrc:/main.qml")); window.showFullScreen(); -// window.show(); - + /* TODO: Enable this once we have the views up & running + * TODO: We can add this to mainPageHandler now... QDBusConnection dbus = QDBusConnection::sessionBus(); dbus.registerObject("/qtrapids_gui", &mainWindow); dbus.registerService("com.ixonos.qtrapids_gui"); diff --git a/src/qml-client/qml/MainPage.qml b/src/qml-client/qml/MainPage.qml index a189bab..65c8a86 100644 --- a/src/qml-client/qml/MainPage.qml +++ b/src/qml-client/qml/MainPage.qml @@ -3,11 +3,12 @@ import Qt.labs.components 1.0 import com.nokia.meego 1.0 import com.meego 1.0 import com.nokia.extras 1.0 +import Qt 4.7 import QtRapids 1.0 Page { - id: tabbarPage + id: mainPage property bool busy: Boolean(tabGroup.currentTab.busy) anchors.margins: rootWindow.pageMargin @@ -25,7 +26,10 @@ Page { tab: seeds } } - ToolIcon { iconId: "toolbar-view-menu"; onClicked: (myMenu.status == DialogStatus.Closed) ? myMenu.open() : myMenu.close() } + ToolIcon { + iconId: "toolbar-view-menu" + onClicked: (myMenu.status == DialogStatus.Closed) ? myMenu.open() : myMenu.close() + } } // Text { // text: "Hello World!" @@ -173,5 +177,19 @@ Page { } } } - + Menu { + id: myMenu + visualParent: mainPage + MenuLayout { + MenuItem { + id: menuItemOpenFile + text: "Open" + onClicked: { console.log("opening torrent picker"); pageStack.push(torrentPickerComp); } + } + } + } + Component { + id: torrentPickerComp + TorrentPickerPage { } + } } \ No newline at end of file diff --git a/src/qml-client/qml/TorrentPickerPage.qml b/src/qml-client/qml/TorrentPickerPage.qml new file mode 100644 index 0000000..44226af --- /dev/null +++ b/src/qml-client/qml/TorrentPickerPage.qml @@ -0,0 +1,55 @@ +import QtQuick 1.1 +import Qt.labs.components 1.0 +import com.nokia.meego 1.0 +import com.meego 1.0 +import com.nokia.extras 1.0 + +import QtMobility.gallery 1.1 +import QtRapids 1.0 + +Page { + + id: torrentPickerPage + Component.onCompleted: console.log("TorrentPicker Running!") + DocumentGalleryModel { + id: torrentFileModel + + rootType: DocumentGallery.File + properties: ["url"] + filter: GalleryWildcardFilter { + property: "fileName"; + value: "*.torrent"; + } + + onProgressChanged: console.log("Width has changed to: ", progress) + +// onCountChanged: { +// selection.clear() +// for (var i = 0; i < count; i++) +// selection.append({"selected": false}) +// } + } + // TODO: Don't really need this, we can only select one file, I guess? +// ListModel { +// id: selection +// } + ListView { + width: 200; height: 400 + model: torrentFileModel + delegate: torrentFileDelegate + } + Component { + id: torrentFileDelegate + + Item { + height: 60 + width: parent.width + Text { + text: "Torrent" + } + Text { + text: url + } + } + } +} \ No newline at end of file diff --git a/src/qml-client/qml/qml.qrc b/src/qml-client/qml/qml.qrc index 955eecb..15e17c2 100644 --- a/src/qml-client/qml/qml.qrc +++ b/src/qml-client/qml/qml.qrc @@ -4,6 +4,7 @@ main.qml MainPage.qml + TorrentPickerPage.qml \ No newline at end of file -- 1.7.9.5