← Back to team overview

ubuntu-sdk-team team mailing list archive

[Merge] lp:~artmello/ubuntu-ui-toolkit/ubuntu-ui-toolkit-clipboard-dbus into lp:ubuntu-ui-toolkit

 

Arthur Mello has proposed merging lp:~artmello/ubuntu-ui-toolkit/ubuntu-ui-toolkit-clipboard-dbus into lp:ubuntu-ui-toolkit.

Commit message:
Add support for interacting with Content Hub Clipboard UI via DBus calls

Requested reviews:
  Ubuntu SDK team (ubuntu-sdk-team)

For more details, see:
https://code.launchpad.net/~artmello/ubuntu-ui-toolkit/ubuntu-ui-toolkit-clipboard-dbus/+merge/313136

Add support for interacting with Content Hub Clipboard UI via DBus calls
-- 
Your team Ubuntu SDK team is requested to review the proposed merge of lp:~artmello/ubuntu-ui-toolkit/ubuntu-ui-toolkit-clipboard-dbus into lp:ubuntu-ui-toolkit.
=== modified file 'src/UbuntuToolkit/UbuntuToolkit.pro'
--- src/UbuntuToolkit/UbuntuToolkit.pro	2016-09-12 14:56:56 +0000
+++ src/UbuntuToolkit/UbuntuToolkit.pro	2016-12-13 14:18:44 +0000
@@ -49,6 +49,7 @@
     $$PWD/privates/listviewextensions_p.h \
     $$PWD/privates/splitviewhandler_p.h \
     $$PWD/privates/threelabelsslot_p.h \
+    $$PWD/privates/uccontenthub_p.h \
     $$PWD/privates/ucpagewrapper_p.h \
     $$PWD/privates/ucpagewrapper_p_p.h \
     $$PWD/privates/ucpagewrapperincubator_p.h \
@@ -160,6 +161,7 @@
     $$PWD/privates/listviewextensions.cpp \
     $$PWD/privates/splitviewhandler.cpp \
     $$PWD/privates/threelabelsslot_p.cpp \
+    $$PWD/privates/uccontenthub.cpp \
     $$PWD/privates/ucpagewrapper.cpp \
     $$PWD/privates/ucpagewrapperincubator.cpp \
     $$PWD/privates/ucscrollbarutils.cpp \

=== added file 'src/UbuntuToolkit/privates/uccontenthub.cpp'
--- src/UbuntuToolkit/privates/uccontenthub.cpp	1970-01-01 00:00:00 +0000
+++ src/UbuntuToolkit/privates/uccontenthub.cpp	2016-12-13 14:18:44 +0000
@@ -0,0 +1,94 @@
+/*
+ * Copyright 2016 Canonical Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; version 3.
+ *
+ * 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 Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Arthur Mello <arthur.mello@xxxxxxxxxxxxx>
+ */
+
+#include "privates/uccontenthub_p.h"
+
+#include <QtCore/QLoggingCategory>
+
+Q_LOGGING_CATEGORY(ucContentHub, "ubuntu.components.PrivateContentHub", QtMsgType::QtWarningMsg)
+
+#define CONTHUB_TRACE(params) qCDebug(ucContentHub) << params
+
+static const QString contentHubService = QStringLiteral("com.ubuntu.content.dbus.Service");
+static const QString contentHubObjectPath = QStringLiteral("/");
+static const QString contentHubInterface = QStringLiteral("com.ubuntu.content.dbus.Service");
+
+static const QString dbusService = QStringLiteral("org.freedesktop.DBus");
+static const QString dbusObjectPath = QStringLiteral("/org/freedesktop/DBus");
+static const QString dbusInterface = QStringLiteral("org.freedesktop.DBus");
+
+UT_NAMESPACE_BEGIN
+
+UCContentHub::UCContentHub(QObject *parent)
+    : QObject(parent),
+      m_dbusIface(0),
+      m_contentHubIface(0)
+{
+    m_dbusIface = new QDBusInterface(dbusService,
+                                     dbusObjectPath,
+                                     dbusInterface,
+                                     QDBusConnection::sessionBus(),
+                                     this);
+
+    m_contentHubIface = new QDBusInterface(contentHubService,
+                                           contentHubObjectPath,
+                                           contentHubInterface,
+                                           QDBusConnection::sessionBus(),
+                                           this);
+}
+
+UCContentHub::~UCContentHub()
+{
+    if (m_dbusIface) {
+        delete m_dbusIface;
+    }
+
+    if (m_contentHubIface) {
+        delete m_contentHubIface;
+    }
+}
+
+void UCContentHub::requestPaste()
+{
+    if (!m_contentHubIface->isValid()) {
+        CONTHUB_TRACE("Invalid Content Hub DBusInterface");
+        return;
+    }
+
+    QString appProfile = getAppProfile();
+    qDebug() << "[UITK ContentHub] AppArmor profile:" << appProfile;
+
+    m_contentHubIface->call(QStringLiteral("RequestPasteByAppId"), appProfile);
+}
+
+QString UCContentHub::getAppProfile()
+{
+    if (!m_dbusIface->isValid()) {
+        CONTHUB_TRACE("Invalid DBus DBusInterface");
+        return QString();
+    }
+
+    QDBusReply<QString> reply = m_dbusIface->call("GetConnectionAppArmorSecurityContext", QDBusConnection::sessionBus().baseService());
+    if (reply.isValid()) {
+        return reply.value();
+    }
+
+    return QString();
+}
+
+UT_NAMESPACE_END

=== added file 'src/UbuntuToolkit/privates/uccontenthub_p.h'
--- src/UbuntuToolkit/privates/uccontenthub_p.h	1970-01-01 00:00:00 +0000
+++ src/UbuntuToolkit/privates/uccontenthub_p.h	2016-12-13 14:18:44 +0000
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2016 Canonical Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; version 3.
+ *
+ * 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 Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Arthur Mello <arthur.mello@xxxxxxxxxxxxx>
+ */
+
+#ifndef UCCONTENTHUB_P_H
+#define UCCONTENTHUB_P_H
+
+#include <QtCore/QObject>
+#include <QtDBus/QDBusInterface>
+#include <QtDBus/QDBusConnection>
+
+#include <UbuntuToolkit/ubuntutoolkitglobal.h>
+
+UT_NAMESPACE_BEGIN
+
+class UBUNTUTOOLKIT_EXPORT UCContentHub : public QObject
+{
+    Q_OBJECT
+
+public:
+    UCContentHub(QObject* parent = 0);
+    ~UCContentHub();
+
+    Q_INVOKABLE void requestPaste();
+
+private:
+    QString getAppProfile();
+
+    QDBusInterface *m_dbusIface;
+    QDBusInterface *m_contentHubIface;
+};
+
+UT_NAMESPACE_END
+
+#endif  // UCCONTENTHUB_P_H

=== modified file 'src/UbuntuToolkit/ubuntutoolkitmodule.cpp'
--- src/UbuntuToolkit/ubuntutoolkitmodule.cpp	2016-09-29 10:19:06 +0000
+++ src/UbuntuToolkit/ubuntutoolkitmodule.cpp	2016-12-13 14:18:44 +0000
@@ -44,6 +44,7 @@
 #include "menugroup_p.h"
 #include "privates/appheaderbase_p.h"
 #include "privates/frame_p.h"
+#include "privates/uccontenthub_p.h"
 #include "privates/ucpagewrapper_p.h"
 #include "privates/ucscrollbarutils_p.h"
 #include "qquickclipboard_p.h"
@@ -262,6 +263,8 @@
     qmlRegisterType<UCAppHeaderBase>(privateUri, 1, 3, "AppHeaderBase");
     qmlRegisterType<Tree>(privateUri, 1, 3, "Tree");
 
+    qmlRegisterSimpleSingletonType<UCContentHub>(privateUri, 1, 3, "PrivateContentHub");
+
     //FIXME: move to a more generic location, i.e StyledItem or QuickUtils
     qmlRegisterSimpleSingletonType<UCScrollbarUtils>(privateUri, 1, 3, "PrivateScrollbarUtils");
 

=== modified file 'src/imports/Components/1.3/TextInputPopover.qml'
--- src/imports/Components/1.3/TextInputPopover.qml	2015-12-14 15:15:46 +0000
+++ src/imports/Components/1.3/TextInputPopover.qml	2016-12-13 14:18:44 +0000
@@ -17,6 +17,7 @@
 import QtQuick 2.4
 import Ubuntu.Components 1.3
 import Ubuntu.Components.Popups 1.3
+import Ubuntu.Components.Private 1.3 as Private
 
 Popover {
     id: popover
@@ -54,12 +55,12 @@
             }
         },
         Action {
-            text: i18n.dtr('ubuntu-ui-toolkit', "Paste")
+            text: i18n.dtr('ubuntu-ui-toolkit', "Paste...")
             iconName: "edit-paste"
-            enabled: target && target.canPaste
+            //enabled: target && target.canPaste
             onTriggered: {
                 PopupUtils.close(popover);
-                target.paste();
+                Private.PrivateContentHub.requestPaste();
             }
         }
     ]