Added TorrentPickerPage.
authorlvaatamoinen <lassi.vaatamoinen@ixonos.com>
Sun, 29 Jan 2012 21:29:53 +0000 (21:29 +0000)
committerlvaatamoinen <lassi.vaatamoinen@ixonos.com>
Sun, 29 Jan 2012 21:29:53 +0000 (21:29 +0000)
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
src/qml-client/MainPageHandler.cpp [new file with mode: 0644]
src/qml-client/MainPageHandler.h [new file with mode: 0644]
src/qml-client/main.cpp
src/qml-client/qml/MainPage.qml
src/qml-client/qml/TorrentPickerPage.qml [new file with mode: 0644]
src/qml-client/qml/qml.qrc

index 873b699..a9d4dbc 100644 (file)
@@ -19,31 +19,21 @@ INCLUDE_DIRECTORIES(
    ${QT_QTDBUS}
    ${QT_QTGUI}
    ${QT_QTDECLARATIVE_INCLUDE_DIR}
    ${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
 )
 
 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
     ./models/QDeclarativeDownloadListModel.h
     ./models/QDeclarativeDownloadListModel_p.h
-#     ./DownloadView.h
-#     ./models/Plugin.h
-#   ./MainWindow.h
-#   ./PreferencesDialog.h
-#   ./proxy.h
-#   ./SeedView.h
-#   ./ColumnSelectorDialog.h
 )
 
 SET(SRC
 )
 
 SET(SRC
-#     ./DownloadView.cpp
     ./main.cpp
     ./main.cpp
+    ./MainPageHandler.cpp
     ./models/QDeclarativeDownloadListModel.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
   ${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.
 )
 
 # 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 (file)
index 0000000..26a7760
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+    <one line to give the program's name and a brief idea of what it does.>
+    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 <QtCore/QString>
+#include <QtCore/QDebug>
+#include <QFileDialog>
+#include <meegotouch/mwindow.h>
+
+#include "MainPageHandler.h"
+
+
+namespace qtrapids
+{
+
+MainPageHandler::MainPageHandler(QObject *parent) :
+    QObject(parent)
+{
+}
+
+MainPageHandler::~MainPageHandler()
+{
+}
+
+void MainPageHandler::fileSelectorOpen()
+{
+    qDebug() << Q_FUNC_INFO;
+    QWidget* widget = qobject_cast<QWidget*>(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 (file)
index 0000000..ada83d1
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+    <one line to give the program's name and a brief idea of what it does.>
+    Copyright (C) 2012  <copyright holder> <email>
+
+    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 <meegotouch/mapplication.h> 
+#include <QtCore/QObject>
+
+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
index 9d992b8..674eb3e 100644 (file)
  *   Free Software Foundation, Inc.,                                       *
  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
  ***************************************************************************/
  *   Free Software Foundation, Inc.,                                       *
  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
  ***************************************************************************/
-#include <QApplication>
 #include <QtDeclarative>
 #include <QDeclarativeContext>
 #include <QTest>
 #include <QDebug>
 #include <QtDeclarative>
 #include <QDeclarativeContext>
 #include <QTest>
 #include <QDebug>
-//#include <QDesktopWidget>
-//#include "DownloadView.h"
 #include <QtDeclarative/qdeclarative.h>
 #include <QtDeclarative/qdeclarative.h>
-#include "models/QDeclarativeDownloadListModel.h"
+#include <meegotouch/mapplicationpage.h>
+#include <meegotouch/mapplicationwindow.h>
 
 
-#include "MainWindow.h"
+#include "models/QDeclarativeDownloadListModel.h"
+#include "MainPageHandler.h"
 #include "../include/qtrapids/dbus.hpp"
 
 #include "../include/qtrapids/dbus.hpp"
 
-using qtrapids::MainWindow;
-
 int main(int argc, char *argv[])
 {
 
 int main(int argc, char *argv[])
 {
 
-
-
+    // TODO: Check: could we use MApplication:: instead?
     QCoreApplication::setOrganizationName("Ixonos");
     QCoreApplication::setOrganizationDomain("ixonos.com");
     QCoreApplication::setApplicationName("QtRapids");
     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);
     QApplication app(argc, argv);
     //MainWindow mainWindow;
     app.setProperty("NoMStyle", true);
-    
-    // Register our types:
+
+    // Register our types (e.g. models and stuff):
     qmlRegisterType<qtrapids::QDeclarativeDownloadListModel>("QtRapids", 1, 0, "DownloadListModel");
 
     QDir::setCurrent(app.applicationDirPath());
 
     QDeclarativeView window;
     qmlRegisterType<qtrapids::QDeclarativeDownloadListModel>("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::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);
     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.setSource(QUrl("qrc:/main.qml"));
 
     window.showFullScreen();
-//    window.show();
-
 
 
+    
     /* TODO: Enable this once we have the views up & running
     /* 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");
     QDBusConnection dbus = QDBusConnection::sessionBus();
     dbus.registerObject("/qtrapids_gui", &mainWindow);
     dbus.registerService("com.ixonos.qtrapids_gui");
index a189bab..65c8a86 100644 (file)
@@ -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 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 {
 
 import QtRapids 1.0
 
 Page {
-    id: tabbarPage
+    id: mainPage
 
     property bool busy: Boolean(tabGroup.currentTab.busy)
     anchors.margins: rootWindow.pageMargin
 
     property bool busy: Boolean(tabGroup.currentTab.busy)
     anchors.margins: rootWindow.pageMargin
@@ -25,7 +26,10 @@ Page {
                 tab: seeds
             }
         }
                 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!"
     }
 //  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
 }
\ 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 (file)
index 0000000..44226af
--- /dev/null
@@ -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
index 955eecb..15e17c2 100644 (file)
@@ -4,6 +4,7 @@
  <qresource prefix="/">
     <file>main.qml</file>
     <file>MainPage.qml</file>
  <qresource prefix="/">
     <file>main.qml</file>
     <file>MainPage.qml</file>
+    <file>TorrentPickerPage.qml</file>
  </qresource>
 
  </RCC>
\ No newline at end of file
  </qresource>
 
  </RCC>
\ No newline at end of file