[SCM] ktp-common-internals packaging branch, master, updated. debian/15.12.1-2-1839-gf0635e9

Maximiliano Curia maxy at moszumanska.debian.org
Mon May 9 09:04:34 UTC 2016


Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-common-internals.git;a=commitdiff;h=c40803d

The following commit has been merged in the master branch:
commit c40803d7a68d0a22e3634c1fc8e85b67d5106809
Author: George Kiagiadakis <george.kiagiadakis at collabora.com>
Date:   Mon Sep 19 20:45:50 2011 +0300

    Add a new class to watch for the availability of krfb.
    
    This is because the self contact capabilities do not advertise
    the availability of krfb; they only advertise the availability of krdc.
---
 service-availability-checker.cpp | 107 +++++++++++++++++++++++++++++++++++++++
 service-availability-checker.h   |  50 ++++++++++++++++++
 2 files changed, 157 insertions(+)

diff --git a/service-availability-checker.cpp b/service-availability-checker.cpp
new file mode 100644
index 0000000..bed93b3
--- /dev/null
+++ b/service-availability-checker.cpp
@@ -0,0 +1,107 @@
+/*
+    Copyright (C) 2011 Collabora Ltd. <info at collabora.com>
+      @author George Kiagiadakis <george.kiagiadakis at collabora.com>
+
+    This library 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; either version 2.1 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 Lesser General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+#include "service-availability-checker.h"
+
+#include <QtDBus/QDBusConnectionInterface>
+#include <QtDBus/QDBusServiceWatcher>
+#include <QtDBus/QDBusPendingCall>
+#include <QtDBus/QDBusReply>
+
+#include <KDebug>
+
+struct ServiceAvailabilityChecker::Private
+{
+    QString serviceName;
+    bool serviceAvailable;
+    bool serviceActivatable;
+};
+
+ServiceAvailabilityChecker::ServiceAvailabilityChecker(const QString & serviceName, QObject *parent)
+    : QObject(parent), d(new Private)
+{
+    d->serviceName = serviceName;
+    d->serviceAvailable = false;
+    d->serviceActivatable = false;
+
+    QDBusServiceWatcher *serviceWatcher = new QDBusServiceWatcher(serviceName,
+            QDBusConnection::sessionBus(),
+            QDBusServiceWatcher::WatchForRegistration | QDBusServiceWatcher::WatchForUnregistration,
+            this);
+    connect(serviceWatcher, SIGNAL(serviceOwnerChanged(QString,QString,QString)),
+            this, SLOT(onServiceOwnerChanged(QString,QString,QString)));
+
+    introspect();
+}
+
+ServiceAvailabilityChecker::~ServiceAvailabilityChecker()
+{
+    delete d;
+}
+
+bool ServiceAvailabilityChecker::isAvailable() const
+{
+    return d->serviceAvailable || d->serviceActivatable;
+}
+
+void ServiceAvailabilityChecker::introspect()
+{
+    QDBusConnectionInterface *dbusIface = QDBusConnection::sessionBus().interface();
+
+    QDBusPendingCall call = dbusIface->asyncCall(QLatin1String("ListActivatableNames"));
+    QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(call, this);
+    connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)),
+            this, SLOT(onCallFinished(QDBusPendingCallWatcher*)));
+    watcher->setObjectName(QLatin1String("ListActivatableNamesWatcher"));
+
+    call = dbusIface->asyncCall(QLatin1String("ListNames"));
+    watcher = new QDBusPendingCallWatcher(call, this);
+    connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)),
+            this, SLOT(onCallFinished(QDBusPendingCallWatcher*)));
+}
+
+void ServiceAvailabilityChecker::onCallFinished(QDBusPendingCallWatcher *watcher)
+{
+    QDBusReply<QStringList> reply = *watcher;
+    if (!reply.isValid()) {
+        kDebug() << "Got error while introspecting service availability:" << reply.error();
+    } else {
+        bool *var = (watcher->objectName() == QLatin1String("ListActivatableNamesWatcher"))
+                            ? &d->serviceActivatable : &d->serviceAvailable;
+
+        if (!*var) {
+            *var = reply.value().contains(d->serviceName);
+        } else {
+            Q_ASSERT(var == &d->serviceAvailable); //this is the serviceAvailable variable
+            //... and onServiceOwnerChanged() got there first...
+        }
+    }
+
+    watcher->deleteLater();
+}
+
+void ServiceAvailabilityChecker::onServiceOwnerChanged(const QString & service,
+        const QString & oldOwner, const QString & newOwner)
+{
+    Q_UNUSED(oldOwner);
+
+    if (service == d->serviceName) {
+        d->serviceAvailable = !newOwner.isEmpty();
+    }
+}
+
+#include "service-availability-checker.moc"
diff --git a/service-availability-checker.h b/service-availability-checker.h
new file mode 100644
index 0000000..8883fe6
--- /dev/null
+++ b/service-availability-checker.h
@@ -0,0 +1,50 @@
+/*
+    Copyright (C) 2011 Collabora Ltd. <info at collabora.com>
+      @author George Kiagiadakis <george.kiagiadakis at collabora.com>
+
+    This library 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; either version 2.1 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 Lesser General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+#ifndef SERVICE_AVAILABILITY_CHECKER_H
+#define SERVICE_AVAILABILITY_CHECKER_H
+
+#include <QtCore/QObject>
+
+class QDBusPendingCallWatcher;
+
+/**
+ * This class watches if a given d-bus service is either
+ * available on the bus or can be activated on demand.
+ */
+class ServiceAvailabilityChecker : public QObject
+{
+    Q_OBJECT
+public:
+    ServiceAvailabilityChecker(const QString & serviceName, QObject *parent = 0);
+    virtual ~ServiceAvailabilityChecker();
+
+    bool isAvailable() const;
+
+private Q_SLOTS:
+    void introspect();
+    void onCallFinished(QDBusPendingCallWatcher *watcher);
+    void onServiceOwnerChanged(const QString & service,
+                               const QString & oldOwner,
+                               const QString & newOwner);
+
+private:
+    struct Private;
+    Private * const d;
+};
+
+#endif // SERVICE_AVAILABILITY_CHECKER_H

-- 
ktp-common-internals packaging



More information about the pkg-kde-commits mailing list