[SCM] ktp-kded-integration-module packaging branch, master, updated. debian/15.12.1-2-382-gbd961c2

Maximiliano Curia maxy at moszumanska.debian.org
Sat May 28 00:12:40 UTC 2016


Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-kded-module.git;a=commitdiff;h=4b99d5c

The following commit has been merged in the master branch:
commit 4b99d5cce094e3fb1ee47b2773ea9b385ae220c0
Author: Martin Klapetek <martin.klapetek at gmail.com>
Date:   Wed Sep 28 19:10:00 2011 +0200

    New class ErrorHandler which watches for connection errors and informs the user in case of any error
    
    Reviewed-by: David Edmundson
---
 CMakeLists.txt                |  5 ++-
 error-handler.cpp             | 93 +++++++++++++++++++++++++++++++++++++++++++
 autoaway.h => error-handler.h | 50 ++++++++++++-----------
 telepathy-module.cpp          |  3 ++
 telepathy-module.h            |  2 +
 5 files changed, 128 insertions(+), 25 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 28a8d21..3c96af6 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -27,9 +27,12 @@ include_directories (${KDE4_INCLUDES}
 
 set (telepathy_module_SRCS
      telepathy-module.cpp
+     autoaway.cpp
+     telepathy-mpris.cpp
+     error-handler.cpp
 )
 
-kde4_add_plugin (kded_telepathy_module autoaway.cpp telepathy-mpris.cpp
+kde4_add_plugin (kded_telepathy_module
                  ${telepathy_module_SRCS}
 )
 
diff --git a/error-handler.cpp b/error-handler.cpp
new file mode 100644
index 0000000..f8e2d42
--- /dev/null
+++ b/error-handler.cpp
@@ -0,0 +1,93 @@
+/*
+    Class for displaying connection errors
+    Copyright (C) 2011  Martin Klapetek <martin.klapetek 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 Street, Fifth Floor, Boston, MA  02110-1301  USA
+*/
+
+
+#include "error-handler.h"
+
+#include <KNotification>
+#include <KAboutData>
+
+ErrorHandler::ErrorHandler(const Tp::AccountManagerPtr& am, QObject* parent)
+    : QObject(parent)
+{
+    m_accountManager = am;
+
+    Q_FOREACH(const Tp::AccountPtr &account, am->allAccounts()) {
+        connect(account.data(),
+                SIGNAL(connectionStatusChanged(Tp::ConnectionStatus)),
+                this, SLOT(handleErrors(Tp::ConnectionStatus)));
+    }
+
+    connect(m_accountManager.data(), SIGNAL(newAccount(Tp::AccountPtr)),
+            this, SLOT(handleNewAccount(Tp::AccountPtr)));
+}
+
+ErrorHandler::~ErrorHandler()
+{
+
+}
+
+void ErrorHandler::handleError(const Tp::ConnectionStatus status)
+{
+    Tp::AccountPtr account(qobject_cast< Tp::Account* >(sender()));
+
+    if (status == Tp::ConnectionStatusDisconnected) {
+        QString connectionError = account->connectionError();
+
+        Tp::ConnectionStatusReason reason = account->connectionStatusReason();
+
+        switch (reason) {
+            case Tp::ConnectionStatusReasonRequested:
+                //do nothing
+                break;
+            case Tp::ConnectionStatusReasonAuthenticationFailed:
+                showMessageToUser(i18n("Could not connect %1. Authentication failed (is your password correct?)", account->displayName()), ErrorHandler::SystemMessageError);
+                break;
+            case Tp::ConnectionStatusReasonNetworkError:
+                showMessageToUser(i18n("Could not connect %1. There was a network error, check your connection", account->displayName()), ErrorHandler::SystemMessageError);
+                break;
+            default:
+                showMessageToUser(i18n("An unexpected error has occurred with %1: '%2'", account->displayName(), account->connectionError()), ErrorHandler::SystemMessageError);
+                break;
+        }
+    }
+}
+
+void ErrorHandler::showMessageToUser(const QString& text, const ErrorHandler::SystemMessageType type)
+{
+    //The pointer is automatically deleted when the event is closed
+    KNotification *notification;
+    if (type == ErrorHandler::SystemMessageError) {
+        notification = new KNotification("telepathyError", this);
+    } else {
+        notification = new KNotification("telepathyInfo", this);
+    }
+
+    KAboutData aboutData("ktelepathy",0,KLocalizedString(),0);
+    notification->setComponentData(KComponentData(aboutData));
+
+    notification->setText(text);
+    notification->sendEvent();
+}
+
+void ErrorHandler::handleNewAccount(const Tp::AccountPtr& account)
+{
+    connect(account.data(), SIGNAL(connectionStatusChanged(Tp::ConnectionStatus)),
+            this, SLOT(handleErrors(Tp::ConnectionStatus)));
+}
diff --git a/autoaway.h b/error-handler.h
similarity index 51%
copy from autoaway.h
copy to error-handler.h
index a95f49a..3aeeeb4 100644
--- a/autoaway.h
+++ b/error-handler.h
@@ -1,5 +1,5 @@
 /*
-    Auto away-presence setter-class
+    Class for displaying connection errors
     Copyright (C) 2011  Martin Klapetek <martin.klapetek at gmail.com>
 
     This library is free software; you can redistribute it and/or
@@ -18,40 +18,42 @@
 */
 
 
-#ifndef AUTOAWAY_H
-#define AUTOAWAY_H
+#ifndef ERROR_HANDLER_H
+#define ERROR_HANDLER_H
 
 #include <QObject>
-
-#include <TelepathyQt4/Presence>
 #include <TelepathyQt4/AccountManager>
 
-class AutoAway : public QObject
+class ErrorHandler : public QObject
 {
     Q_OBJECT
-
 public:
-    AutoAway(const Tp::AccountManagerPtr& am, QObject* parent = 0);
-    ~AutoAway();
-
-    void readConfig();
-
-Q_SIGNALS:
-    void setPresence(const Tp::Presence &presence);
-
-public Q_SLOTS:
-    void onSettingsChanged();
+    ErrorHandler(const Tp::AccountManagerPtr& am, QObject *parent = 0);
+    virtual ~ErrorHandler();
+
+    enum SystemMessageType {
+        /*
+         * this will show a system message to the user
+         * but it will fade after short timout,
+         * thus it should be used for non-important messages
+         * like "Connecting..." etc.
+         */
+        SystemMessageInfo,
+
+        /*
+         * message with this class will stay visible until user
+         * closes it and will have light-red background
+         */
+        SystemMessageError
+    };
 
 private Q_SLOTS:
-    void timeoutReached(int);
-    void backFromIdle();
+    void handleErrors(const Tp::ConnectionStatus status);
+    void showMessageToUser(const QString& text, const ErrorHandler::SystemMessageType type);
+    void handleNewAccount(const Tp::AccountPtr &account);
 
 private:
-    int m_awayTimeoutId;
-    int m_extAwayTimeoutId;
-
-    Tp::Presence m_prevPresence;
     Tp::AccountManagerPtr m_accountManager;
 };
 
-#endif // AUTOAWAY_H
+#endif // ERROR_HANDLER_H
diff --git a/telepathy-module.cpp b/telepathy-module.cpp
index 526be4f..174cecf 100644
--- a/telepathy-module.cpp
+++ b/telepathy-module.cpp
@@ -29,6 +29,7 @@
 
 #include "telepathy-mpris.h"
 #include "autoaway.h"
+#include "error-handler.h"
 
 K_PLUGIN_FACTORY(TelepathyModuleFactory, registerPlugin<TelepathyModule>(); )
 K_EXPORT_PLUGIN(TelepathyModuleFactory("telepathy_module"))
@@ -89,6 +90,8 @@ void TelepathyModule::onAccountManagerReady(Tp::PendingOperation* op)
 
     connect(this, SIGNAL(settingsChanged()),
             m_mpris, SLOT(onSettingsChanged()));
+
+    m_errorHandler = new ErrorHandler(m_accountManager, this);
 }
 
 void TelepathyModule::setPresence(const Tp::Presence &presence)
diff --git a/telepathy-module.h b/telepathy-module.h
index 474b67f..815ee38 100644
--- a/telepathy-module.h
+++ b/telepathy-module.h
@@ -25,6 +25,7 @@
 
 #include <TelepathyQt4/AccountManager>
 
+class ErrorHandler;
 class TelepathyMPRIS;
 class AutoAway;
 namespace Tp {
@@ -52,6 +53,7 @@ private:
     Tp::AccountManagerPtr m_accountManager;
     AutoAway *m_autoAway;
     TelepathyMPRIS *m_mpris;
+    ErrorHandler *m_errorHandler;
 };
 
 #endif // TELEPATHY_MODULE_H

-- 
ktp-kded-integration-module packaging



More information about the pkg-kde-commits mailing list