[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:15:00 UTC 2016
Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-kded-module.git;a=commitdiff;h=bd1be06
The following commit has been merged in the master branch:
commit bd1be061e0b96860637b1b430aff19353e2d6a64
Author: David Edmundson <kde at davidedmundson.co.uk>
Date: Mon Mar 4 00:33:12 2013 +0000
Track error messages and only emit after 30 seconds to allow time to reconnect and hopefully reduce the number of error messages we emit
Group messages together
Also show server messages to user to the user
REVIEW: 109277
---
error-handler.cpp | 164 +++++++++++++++++++++++++++++++++++++++++++++++-------
error-handler.h | 10 ++++
2 files changed, 154 insertions(+), 20 deletions(-)
diff --git a/error-handler.cpp b/error-handler.cpp
index c309f1c..9e60337 100644
--- a/error-handler.cpp
+++ b/error-handler.cpp
@@ -20,14 +20,88 @@
#include "error-handler.h"
+#include <QScopedPointer>
+#include <QTimer>
+
#include <KNotification>
#include <KAboutData>
#include <KDebug>
#include <KTp/error-dictionary.h>
+#include <TelepathyQt/Account>
+#include <TelepathyQt/Connection>
+
#include <Solid/Networking>
+/** Stores the last error message for an account
+ For every new error if we're online we wait 30 seconds and show 1 notification for all errors. This will be the only error we show for that account until the user reconnects.
+*/
+
+class ConnectionError
+{
+public:
+ ConnectionError(Tp::ConnectionStatusReason connectionStatusReason,
+ const QString &connectionError,
+ const Tp::Connection::ErrorDetails &connectionErrorDetails);
+
+ Tp::ConnectionStatusReason connectionStatusReason() const;
+ QString connectionError() const;
+ Tp::Connection::ErrorDetails connectionErrorDetails() const;
+
+ bool shown() const;
+ void setShown(bool);
+
+ QDateTime errorTime() const;
+
+private:
+ bool m_shown;
+ Tp::ConnectionStatusReason m_connectionStatusReason;
+ Tp::Connection::ErrorDetails m_connectionErrorDetails;
+ QString m_connectionError;
+ QDateTime m_errorTime;
+};
+
+ConnectionError::ConnectionError(Tp::ConnectionStatusReason connectionStatusReason, const QString &connectionError, const Tp::Connection::ErrorDetails &connectionErrorDetails):
+ m_connectionStatusReason(connectionStatusReason),
+ m_connectionErrorDetails(connectionErrorDetails),
+ m_connectionError(connectionError)
+{
+ m_shown = false;
+ m_errorTime = QDateTime::currentDateTime();
+}
+
+Tp::ConnectionStatusReason ConnectionError::connectionStatusReason() const
+{
+ return m_connectionStatusReason;
+}
+
+QString ConnectionError::connectionError() const
+{
+ return m_connectionError;
+}
+
+Tp::Connection::ErrorDetails ConnectionError::connectionErrorDetails() const
+{
+ return m_connectionErrorDetails;
+}
+
+QDateTime ConnectionError::errorTime() const
+{
+ return m_errorTime;
+}
+
+bool ConnectionError::shown() const
+{
+ return m_shown;
+}
+
+void ConnectionError::setShown(bool)
+{
+ m_shown = true;
+}
+
+
ErrorHandler::ErrorHandler(const Tp::AccountManagerPtr& am, QObject* parent)
: QObject(parent)
{
@@ -46,41 +120,81 @@ ErrorHandler::~ErrorHandler()
}
-void ErrorHandler::onConnectionStatusChanged(const Tp::ConnectionStatus status)
+void ErrorHandler::showErrorNotification()
{
- Tp::AccountPtr account(qobject_cast< Tp::Account* >(sender()));
-
- //if we're not connected to the network, don't display any errors.
+ //if we're not currently connected to the network, any older errors were probably related to this, ignore them.
if (Solid::Networking::status() != Solid::Networking::Connected) {
return;
}
- if (status == Tp::ConnectionStatusDisconnected) {
- QString connectionError = account->connectionError();
-
- Tp::ConnectionStatusReason reason = account->connectionStatusReason();
+ QString errorMessage;
- kDebug() << reason;
- kDebug() << account->connectionError();
- kDebug() << account->connectionErrorDetails().allDetails();
+ QHash<Tp::AccountPtr, ConnectionError>::const_iterator i = m_errorMap.constBegin();
+ while (i != m_errorMap.constEnd()) {
+ const Tp::AccountPtr account = i.key();
+ ConnectionError error = i.value();
- switch (reason) {
- case Tp::ConnectionStatusReasonRequested:
- //do nothing
- break;
- case Tp::ConnectionStatusReasonAuthenticationFailed:
- showMessageToUser(i18nc("%1 is the account name", "Could not connect %1. Authentication failed (is your password correct?)", account->displayName()), ErrorHandler::SystemMessageError);
- break;
+ //try to group as many error messages as we can, but we still want to give accounts a chance to reconnect
+ //only want to show messages that are at least 20 seconds old to give the account a chance to connect.
+ if (!error.shown() && error.errorTime().secsTo(QDateTime::currentDateTime()) > 20) {
+ switch (error.connectionStatusReason()) {
case Tp::ConnectionStatusReasonNetworkError:
- showMessageToUser(i18nc("%1 is the account name", "Could not connect %1. There was a network error, check your connection", account->displayName()), ErrorHandler::SystemMessageError);
+ errorMessage += i18nc("%1 is the account name", "Could not connect %1. There was a network error, check your connection", account->displayName()) + QLatin1Char('
');
break;
default:
- showMessageToUser(i18nc("%1 is the account name, %2 the error message", "There was a problem while trying to connect %1 - %2", account->displayName(), KTp::ErrorDictionary::displayVerboseErrorMessage(connectionError)), ErrorHandler::SystemMessageError);
+ if (error.connectionErrorDetails().hasServerMessage()) {
+ errorMessage += i18nc("%1 is the account name, %2 the error message", "There was a problem while trying to connect %1 - %2", account->displayName(), error.connectionErrorDetails().serverMessage()) + QLatin1Char('
');
+ } else {
+ errorMessage += i18nc("%1 is the account name, %2 the error message", "There was a problem while trying to connect %1 - %2", account->displayName(), KTp::ErrorDictionary::displayVerboseErrorMessage(error.connectionError())) + QLatin1Char('
');
+ }
break;
+ }
+ error.setShown(true);
+ }
+ ++i;
+ }
+
+ if (!errorMessage.isEmpty()) {
+ if (errorMessage.endsWith(QLatin1Char('
'))) {
+ errorMessage.chop(1);
}
+
+ showMessageToUser(errorMessage, ErrorHandler::SystemMessageError);
}
}
+void ErrorHandler::onConnectionStatusChanged(const Tp::ConnectionStatus status)
+{
+ Tp::AccountPtr account(qobject_cast< Tp::Account* >(sender()));
+
+ //if we're not connected to the network, errors are pointless
+ if (Solid::Networking::status() != Solid::Networking::Connected) {
+ return;
+ }
+
+ if (status == Tp::ConnectionStatusDisconnected) {
+ //if this is the first error for this account, store the details of the error to show
+ if (account->connectionStatusReason() == Tp::ConnectionStatusReasonRequested) {
+ m_errorMap.remove(account);
+ }
+
+ if (!m_errorMap.contains(account)) {
+ m_errorMap.insert(account, ConnectionError(account->connectionStatusReason(), account->connectionError(), account->connectionErrorDetails()));
+ QTimer::singleShot(30 * 1000, this, SLOT(showErrorNotification())); //a timer is kept per account because we want to show 30 seconds after the first still valid error.
+ }
+
+ } else if (status == Tp::ConnectionStatusConnected) {
+ //we are now connected, removed pending error messages
+ m_errorMap.remove(account);
+ }
+}
+
+void ErrorHandler::onRequestedPresenceChanged()
+{
+ Tp::AccountPtr account(qobject_cast< Tp::Account* >(sender()));
+ m_errorMap.remove(account);
+}
+
void ErrorHandler::showMessageToUser(const QString &text, const ErrorHandler::SystemMessageType type)
{
//The pointer is automatically deleted when the event is closed
@@ -102,4 +216,14 @@ void ErrorHandler::onNewAccount(const Tp::AccountPtr& account)
{
connect(account.data(), SIGNAL(connectionStatusChanged(Tp::ConnectionStatus)),
this, SLOT(onConnectionStatusChanged(Tp::ConnectionStatus)));
+
+ connect(account.data(), SIGNAL(requestedPresenceChanged(Tp::Presence)) , SLOT(onRequestedPresenceChanged()));
+ connect(account.data(), SIGNAL(removed()), SLOT(onAccountRemoved()));
+}
+
+void ErrorHandler::onAccountRemoved()
+{
+ Tp::AccountPtr account(qobject_cast<Tp::Account*>(sender()));
+ Q_ASSERT(account);
+ m_errorMap.remove(account);
}
diff --git a/error-handler.h b/error-handler.h
index 60fe5e8..dd62822 100644
--- a/error-handler.h
+++ b/error-handler.h
@@ -22,8 +22,11 @@
#define ERROR_HANDLER_H
#include <QObject>
+
#include <TelepathyQt/AccountManager>
+class ConnectionError;
+
class ErrorHandler : public QObject
{
Q_OBJECT
@@ -47,13 +50,20 @@ public:
SystemMessageError
};
+public Q_SLOTS:
+ /** Loop through all errors we have yet to show, and show anything*/
+ void showErrorNotification();
+
private Q_SLOTS:
void onConnectionStatusChanged(const Tp::ConnectionStatus status);
+ void onRequestedPresenceChanged();
void onNewAccount(const Tp::AccountPtr &account);
+ void onAccountRemoved();
private:
void showMessageToUser(const QString &text, const ErrorHandler::SystemMessageType type);
Tp::AccountManagerPtr m_accountManager;
+ QHash<Tp::AccountPtr, ConnectionError> m_errorMap;
};
#endif // ERROR_HANDLER_H
--
ktp-kded-integration-module packaging
More information about the pkg-kde-commits
mailing list