[SCM] ktp-filetransfer-handler packaging branch, master, updated. debian/15.12.1-2-226-g825cd93

Maximiliano Curia maxy at moszumanska.debian.org
Sat May 28 00:11:35 UTC 2016


Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-filetransfer-handler.git;a=commitdiff;h=ab64c15

The following commit has been merged in the master branch:
commit ab64c15a4f8576dbd325aa127b1a3b9b0864a8d7
Author: Daniele E. Domenichelli <daniele.domenichelli at gmail.com>
Date:   Sat Sep 17 18:44:48 2011 +0100

    Add class Telepathy::TelepathyHandlerApplication
    
    This is a KApplication that exits the application when there are no
    running jobs
    
    Morover it does automatically another few things required by every
    handler:
     - It automatically register Telepathy-Qt Types
     - setQuitOnLastWindowClosed(false)
     - Adds the --persist option to inhibit automatic exit.
     - Adds the --debug option to enable telepathy-qt4 debug
     - Enables telepathy-qt4 warnings
---
 src/telepathy-handler-application.cpp | 177 ++++++++++++++++++++++++++++++++++
 src/telepathy-handler-application.h   |  71 ++++++++++++++
 2 files changed, 248 insertions(+)

diff --git a/src/telepathy-handler-application.cpp b/src/telepathy-handler-application.cpp
new file mode 100644
index 0000000..84774c2
--- /dev/null
+++ b/src/telepathy-handler-application.cpp
@@ -0,0 +1,177 @@
+/*
+* Copyright (C) 2011 Daniele E. Domenichelli <daniele.domenichelli at gmail.com>
+* Copyright (C) 1999 Preston Brown <pbrown at kde.org>
+*
+* 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 library 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 library; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+*/
+
+#include "telepathy-handler-application.h"
+
+#include <QTimer>
+#include <KCmdLineArgs>
+#include <KDebug>
+
+#include <TelepathyQt4/Types>
+#include <TelepathyQt4/Debug>
+
+namespace KTelepathy {
+
+class TelepathyHandlerApplication::Private
+{
+public:
+    Private(TelepathyHandlerApplication *q);
+    ~Private();
+
+    void _k_onInitialTimeout();
+    void _k_onTimeout();
+
+    static KComponentData initHack();
+    void init(int initialTimeout, int timeout);
+
+    TelepathyHandlerApplication *q;
+
+    static bool s_persist;
+    static bool s_debug;
+
+    int timeout;
+    QTimer *timer;
+    bool firstJobStarted;
+    QAtomicInt jobCount;
+};
+
+TelepathyHandlerApplication::Private::Private(TelepathyHandlerApplication *q)
+    : q(q),
+      firstJobStarted(false),
+      jobCount(0)
+{
+}
+
+TelepathyHandlerApplication::Private::~Private()
+{
+}
+
+void TelepathyHandlerApplication::Private::_k_onInitialTimeout()
+{
+    if (jobCount == 0 && jobCount.fetchAndAddOrdered(-1) == 0) {
+        // m_jobCount is now -1
+        kDebug() << "No job received. Exiting";
+        QCoreApplication::quit();
+    }
+}
+
+void TelepathyHandlerApplication::Private::_k_onTimeout()
+{
+    if (jobCount == 0 && jobCount.fetchAndAddOrdered(-1) == 0) {
+        // m_jobCount is now -1
+        kDebug() << "Timeout. Exiting";
+        QCoreApplication::quit();
+    }
+}
+
+// this gets called before even entering QApplication::QApplication()
+KComponentData TelepathyHandlerApplication::Private::initHack()
+{
+    KComponentData cData(KCmdLineArgs::aboutData());
+    KCmdLineOptions handler_options;
+    handler_options.add("persist", ki18n("Persistent mode (do not exit on timeout)"));
+    handler_options.add("debug", ki18n("Show Telepathy debugging information"));
+    KCmdLineArgs::addCmdLineOptions(handler_options, ki18n("KDE Telepathy"), "kde-telepathy", "kde");
+    KCmdLineArgs *args = KCmdLineArgs::parsedArgs("kde-telepathy");
+    Private::s_persist = args->isSet("persist");
+    Private::s_debug = args->isSet("debug");
+    return cData;
+}
+
+void TelepathyHandlerApplication::Private::init(int initialTimeout, int timeout)
+{
+    q->setQuitOnLastWindowClosed(false);
+
+    Tp::registerTypes();
+    //Enable telepathy-Qt4 debug
+    Tp::enableDebug(s_debug);
+    Tp::enableWarnings(true);
+
+    if (!Private::s_persist) {
+        this->timeout = timeout;
+        timer = new QTimer(q);
+        q->connect(timer, SIGNAL(timeout()), q, SLOT(_k_onInitialTimeout()));
+        timer->start(initialTimeout);
+    }
+}
+
+bool TelepathyHandlerApplication::Private::s_persist = false;
+bool TelepathyHandlerApplication::Private::s_debug = false;
+
+
+TelepathyHandlerApplication::TelepathyHandlerApplication(bool GUIenabled,
+                                                         int initialTimeout,
+                                                         int timeout)
+    : KApplication(GUIenabled, Private::initHack()),
+      d(new Private(this))
+{
+    d->init(initialTimeout, timeout);
+}
+
+TelepathyHandlerApplication::TelepathyHandlerApplication(Display *display,
+                                                         Qt::HANDLE visual,
+                                                         Qt::HANDLE colormap,
+                                                         int initialTimeout,
+                                                         int timeout)
+    : KApplication(display, visual, colormap, Private::initHack()),
+      d(new Private(this))
+{
+    d->init(initialTimeout, timeout);
+}
+
+TelepathyHandlerApplication::~TelepathyHandlerApplication()
+{
+    delete d;
+}
+
+int TelepathyHandlerApplication::newJob()
+{
+    TelepathyHandlerApplication *app = qobject_cast<TelepathyHandlerApplication*>(KApplication::kApplication());
+    TelepathyHandlerApplication::Private *d = app->d;
+
+    int ret = d->jobCount.fetchAndAddOrdered(1);
+    if (!Private::s_persist) {
+        if (d->timer->isActive()) {
+            d->timer->stop();
+        }
+        if (!d->firstJobStarted) {
+            disconnect(d->timer, SIGNAL(timeout()), app, SLOT(_k_onInitialTimeout()));
+            connect(d->timer, SIGNAL(timeout()), app, SLOT(_k_onTimeout()));
+            d->firstJobStarted = true;
+        }
+    }
+    return ret;
+}
+
+void TelepathyHandlerApplication::jobFinished()
+{
+    TelepathyHandlerApplication *app = qobject_cast<TelepathyHandlerApplication*>(KApplication::kApplication());
+    TelepathyHandlerApplication::Private *d = app->d;
+
+    if (d->jobCount.fetchAndAddOrdered(-1) <= 1) {
+        kDebug() << "No other jobs at the moment. Starting timer.";
+        if (!Private::s_persist) {
+            d->timer->start(d->timeout);
+        }
+    }
+}
+
+} // namespace KTelepathy
+
+#include "telepathy-handler-application.moc"
diff --git a/src/telepathy-handler-application.h b/src/telepathy-handler-application.h
new file mode 100644
index 0000000..563f04e
--- /dev/null
+++ b/src/telepathy-handler-application.h
@@ -0,0 +1,71 @@
+/*
+* Copyright (C) 2011 Daniele E. Domenichelli <daniele.domenichelli at gmail.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 library 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 library; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+*/
+
+#ifndef UNIQUE_TP_HANDLER_H
+#define UNIQUE_TP_HANDLER_H
+
+#include <KApplication>
+
+
+namespace KTelepathy {
+
+/**
+ * rief A KApplication that exits the application when there are no running jobs
+ *
+ * Morover it does automatically another few things required by every handler:
+ * - It automatically register Telepathy-Qt Types
+ * - setQuitOnLastWindowClosed(false)
+ * - Adds the --persist option to inhibit automatic exit.
+ * - Adds the --debug option to enable telepathy-qt4 debug
+ * - Enables telepathy-qt4 warnings
+ */
+class TelepathyHandlerApplication : public KApplication
+{
+    Q_OBJECT
+
+public:
+    /**
+     * \p initialTimeout Initial timeout time (in msec) after which application exits if no jobs are received.
+     * \p timeout Timeout time (in msec) after which application exits after the last job is finished.
+     */
+    explicit TelepathyHandlerApplication(bool GUIenabled = true,
+                                         int initialTimeout = 15000,
+                                         int timeout = 2000);
+
+    explicit TelepathyHandlerApplication(Display *display,
+                                         Qt::HANDLE visual = 0,
+                                         Qt::HANDLE colormap = 0,
+                                         int initialTimeout = 15000,
+                                         int timeout = 2000);
+
+    virtual ~TelepathyHandlerApplication();
+
+    static int newJob();
+    static void jobFinished();
+
+private:
+    class Private;
+    Private * const d;
+
+    Q_PRIVATE_SLOT(d, void _k_onInitialTimeout())
+    Q_PRIVATE_SLOT(d, void _k_onTimeout())
+};
+
+} // namespace KTelepathy
+
+#endif // UNIQUE_TP_HANDLER_H

-- 
ktp-filetransfer-handler packaging



More information about the pkg-kde-commits mailing list