[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [plasma-settings] /: bind a global settingsApp object
From:       Marco Martin <null () kde ! org>
Date:       2017-10-31 15:25:36
Message-ID: E1e9YQ4-0007fX-Fz () code ! kde ! org
[Download RAW message or body]

Git commit 3ad88ec14b4447f72d52d7df735e9e406a1f1df9 by Marco Martin.
Committed on 31/10/2017 at 15:25.
Pushed by mart into branch 'master'.

bind a global settingsApp object

use it to manage the dbus unique connection

M  +9    -1    package/contents/ui/ModulesList.qml
M  +8    -0    package/contents/ui/main.qml
M  +1    -0    src/CMakeLists.txt
M  +6    -8    src/main.cpp
C  +33   -27   src/settingsapp.cpp [from: package/contents/ui/main.qml - 062% \
similarity] C  +26   -34   src/settingsapp.h [from: package/contents/ui/main.qml - \
069% similarity]

https://commits.kde.org/plasma-settings/3ad88ec14b4447f72d52d7df735e9e406a1f1df9

diff --git a/package/contents/ui/ModulesList.qml \
b/package/contents/ui/ModulesList.qml index 3b39295..c888f12 100644
--- a/package/contents/ui/ModulesList.qml
+++ b/package/contents/ui/ModulesList.qml
@@ -65,11 +65,19 @@ Kirigami.ScrollablePage {
                     Controls.Label {
                         text: description
                         Layout.fillWidth: true
-                        font.pointSize: theme.defaultFont.pointSize -1
+                        font.pointSize: Kirigami.Theme.defaultFont.pointSize -1
                         opacity: 0.6
                         elide: Text.ElideRight
                     }
                 }
+                Connections {
+                    target: settingsApp
+                    onModuleRequested: {
+                        if (rootItem.currentModule == model.module) {
+                            listView.currentIndex = index;
+                        }
+                    }
+                }
             }
 
             onClicked: {
diff --git a/package/contents/ui/main.qml b/package/contents/ui/main.qml
index a63be81..74ec0a3 100644
--- a/package/contents/ui/main.qml
+++ b/package/contents/ui/main.qml
@@ -31,6 +31,14 @@ Kirigami.ApplicationWindow {
     header: Kirigami.ApplicationHeader {}
     pageStack.initialPage: modulesList
 
+    Connections {
+        target: settingsApp
+        onActivateRequested: rootItem.requestActivate();
+        onModuleRequested: {
+            pageStack.currentIndex = 0;
+            rootItem.currentModule = module;
+        }
+    }
     onCurrentModuleChanged: {
         if (currentModule.length > 0) {
             pageStack.push(moduleItem);
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 806677e..af7b617 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -4,6 +4,7 @@ find_package(Qt5 REQUIRED NO_MODULE COMPONENTS Gui)
 
 set(plasma-settings_SRCS
     main.cpp
+    settingsapp.cpp
 )
 
 add_executable(plasma-settings ${plasma-settings_SRCS})
diff --git a/src/main.cpp b/src/main.cpp
index 61d5b1f..d8b1354 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -22,6 +22,8 @@
 #include <iostream>
 #include <iomanip>
 
+//own
+#include "settingsapp.h"
 
 // Qt
 #include <QApplication>
@@ -148,15 +150,11 @@ int main(int argc, char **argv)
 
     KPackage::Package package = \
KPackage::PackageLoader::self()->loadPackage("KPackage/GenericQML");  \
                package.setPath(ui);
-/*
-    KDeclarative::QmlObjectSharedEngine qmlObject;
-    qmlObject.setInitializationDelayed(true);
-
-    qmlObject.setSource(QUrl::fromLocalFile(package.filePath("mainscript")));
-    qmlObject.engine()->rootContext()->setContextProperty("startModule", module);
-    qmlObject.completeInitialization();
-    */
+
+    SettingsApp *settingsApp = new SettingsApp(parser);
+
     QQmlApplicationEngine engine;
+    engine.rootContext()->setContextProperty("settingsApp", settingsApp);
     engine.rootContext()->setContextProperty("startModule", module);
     engine.load(package.filePath("mainscript"));
     
diff --git a/package/contents/ui/main.qml b/src/settingsapp.cpp
similarity index 62%
copy from package/contents/ui/main.qml
copy to src/settingsapp.cpp
index a63be81..268ed65 100644
--- a/package/contents/ui/main.qml
+++ b/src/settingsapp.cpp
@@ -1,7 +1,7 @@
 /***************************************************************************
  *                                                                         *
- *   Copyright 2017 Marco Martin <mart@kde.org>                            *
  *   Copyright 2011-2014 Sebastian Kügler <sebas@kde.org>                  *
+ *   Copyright 2017 Marco Martin <mart@kde.org>                            *
  *                                                                         *
  *   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  *
@@ -19,36 +19,42 @@
  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA .        *
  ***************************************************************************/
 
-import QtQuick 2.6
-import QtQuick.Controls 2.2 as Controls
-import org.kde.kirigami 2.2 as Kirigami
+#include "settingsapp.h"
 
-Kirigami.ApplicationWindow {
-    id: rootItem
+#include <QDebug>
+#include <QQmlContext>
+#include <QQmlEngine>
 
-    property alias currentModule: moduleItem.module
+#include <KDBusService>
 
-    header: Kirigami.ApplicationHeader {}
-    pageStack.initialPage: modulesList
+#include <KLocalizedString>
 
-    onCurrentModuleChanged: {
-        if (currentModule.length > 0) {
-            pageStack.push(moduleItem);
-        }
-        pageStack.currentIndex = 1;
-    }
 
-    Component.onCompleted: {
-        if (startModule.length > 0) {
-            rootItem.currentModule = startModule;
+SettingsApp::SettingsApp(QCommandLineParser &parser, QObject *parent)
+    : QObject(parent),
+      m_parser(&parser)
+{
+    setupKDBus();
+}
+
+SettingsApp::~SettingsApp()
+{
+}
+
+void SettingsApp::setupKDBus()
+{
+    QCoreApplication::setOrganizationDomain("kde.org");
+    KDBusService* service = new KDBusService(KDBusService::Unique, this);
+
+    QObject::connect(service, &KDBusService::activateRequested, this, [this](const \
QStringList &arguments, const QString &workingDirectory) { +        qDebug() << \
"activateRequested" << arguments; +        m_parser->parse(arguments);
+        if (m_parser->isSet("module")) {
+            const QString module = m_parser->value("module");
+            qDebug() << "Loading module:" << module;
+            emit moduleRequested(module);
         }
-    }
-    ModulesList {
-        id: modulesList
-    }
-
-    ModuleItem {
-        id: moduleItem
-        visible: false
-    }
+        emit activateRequested();
+    } );
 }
+
diff --git a/package/contents/ui/main.qml b/src/settingsapp.h
similarity index 69%
copy from package/contents/ui/main.qml
copy to src/settingsapp.h
index a63be81..fc36517 100644
--- a/package/contents/ui/main.qml
+++ b/src/settingsapp.h
@@ -1,7 +1,7 @@
 /***************************************************************************
  *                                                                         *
- *   Copyright 2017 Marco Martin <mart@kde.org>                            *
  *   Copyright 2011-2014 Sebastian Kügler <sebas@kde.org>                  *
+ *   Copyright 2017 Marco Martin <mart@kde.org>                            *
  *                                                                         *
  *   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  *
@@ -19,36 +19,28 @@
  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA .        *
  ***************************************************************************/
 
-import QtQuick 2.6
-import QtQuick.Controls 2.2 as Controls
-import org.kde.kirigami 2.2 as Kirigami
-
-Kirigami.ApplicationWindow {
-    id: rootItem
-
-    property alias currentModule: moduleItem.module
-
-    header: Kirigami.ApplicationHeader {}
-    pageStack.initialPage: modulesList
-
-    onCurrentModuleChanged: {
-        if (currentModule.length > 0) {
-            pageStack.push(moduleItem);
-        }
-        pageStack.currentIndex = 1;
-    }
-
-    Component.onCompleted: {
-        if (startModule.length > 0) {
-            rootItem.currentModule = startModule;
-        }
-    }
-    ModulesList {
-        id: modulesList
-    }
-
-    ModuleItem {
-        id: moduleItem
-        visible: false
-    }
-}
+#ifndef SETTINGSAPP_H
+#define SETTINGSAPP_H
+
+#include <QObject>
+#include <QCommandLineParser>
+
+class SettingsApp : public QObject
+{
+    Q_OBJECT
+
+public:
+    explicit SettingsApp(QCommandLineParser &parser, QObject *parent = 0 );
+    ~SettingsApp();
+
+Q_SIGNALS:
+    void moduleRequested(const QString &module);
+    void activateRequested();
+
+
+private:
+    void setupKDBus();
+    QCommandLineParser *m_parser;
+};
+
+#endif // SettingsApp_H


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic