[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:36 UTC 2016
Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-common-internals.git;a=commitdiff;h=0f23ea4
The following commit has been merged in the master branch:
commit 0f23ea4338afab252a5b39a523b18cedc0536d3f
Author: David Edmundson <kde at davidedmundson.co.uk>
Date: Mon Oct 24 15:26:25 2011 +0100
Add GlobalPresence and KPresence classes from the contact list.
---
global-presence.cpp | 148 ++++++++++++++++++++++++++++++++++++++++++++++++++++
global-presence.h | 84 +++++++++++++++++++++++++++++
kpresence.cpp | 98 ++++++++++++++++++++++++++++++++++
kpresence.h | 41 +++++++++++++++
4 files changed, 371 insertions(+)
diff --git a/global-presence.cpp b/global-presence.cpp
new file mode 100644
index 0000000..ba772b8
--- /dev/null
+++ b/global-presence.cpp
@@ -0,0 +1,148 @@
+/*
+ * Global Presence - wraps calls to set and get presence for all accounts.
+ *
+ * Copyright (C) 2011 David Edmundson <kde at davidedmundson.co.uk>
+ *
+ * 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 "global-presence.h"
+
+#include <TelepathyQt4/AccountSet>
+#include <TelepathyQt4/Account>
+
+#include <KDebug>
+
+GlobalPresence::GlobalPresence(QObject *parent)
+ : QObject(parent),
+ m_requestedPresence(Tp::Presence::offline()),
+ m_currentPresence(Tp::Presence::offline()),
+ m_changingPresence(false)
+{
+ m_presenceSorting[Tp::ConnectionPresenceTypeAvailable] = 0;
+ m_presenceSorting[Tp::ConnectionPresenceTypeBusy] = 1;
+ m_presenceSorting[Tp::ConnectionPresenceTypeHidden] = 2;
+ m_presenceSorting[Tp::ConnectionPresenceTypeAway] = 3;
+ m_presenceSorting[Tp::ConnectionPresenceTypeExtendedAway] = 4;
+ //don't distinguish between the following three presences
+ m_presenceSorting[Tp::ConnectionPresenceTypeError] = 5;
+ m_presenceSorting[Tp::ConnectionPresenceTypeUnknown] = 5;
+ m_presenceSorting[Tp::ConnectionPresenceTypeUnset] = 5;
+ m_presenceSorting[Tp::ConnectionPresenceTypeOffline] = 6;
+
+}
+
+void GlobalPresence::setAccountManager(const Tp::AccountManagerPtr &accountManager)
+{
+ if (! accountManager->isReady()) {
+ kFatal("GlobalPresence used with unready account manager");
+ }
+
+ m_enabledAccounts = accountManager->enabledAccounts();
+
+ Q_FOREACH(const Tp::AccountPtr &account, m_enabledAccounts->accounts()) {
+ onAccountAdded(account);
+ }
+
+ onCurrentPresenceChanged();
+ onRequestedPresenceChanged();
+ onChangingPresence();
+
+ connect(m_enabledAccounts.data(), SIGNAL(accountAdded(Tp::AccountPtr)), SLOT(onAccountAdded(Tp::AccountPtr)));
+}
+
+
+Tp::Presence GlobalPresence::currentPresence() const
+{
+ return m_currentPresence;
+}
+
+Tp::Presence GlobalPresence::requestedPresence() const
+{
+ return m_requestedPresence;
+}
+
+bool GlobalPresence::isChangingPresence() const
+{
+ return m_changingPresence;
+}
+
+
+void GlobalPresence::setPresence(const Tp::Presence &presence)
+{
+ Q_FOREACH(const Tp::AccountPtr &account, m_enabledAccounts->accounts()) {
+ account->setRequestedPresence(presence);
+ }
+}
+
+
+void GlobalPresence::onAccountAdded(const Tp::AccountPtr &account)
+{
+ connect(account.data(), SIGNAL(changingPresence(bool)), SLOT(onChangingPresence()));
+ connect(account.data(), SIGNAL(requestedPresenceChanged(Tp::Presence)), SLOT(onRequestedPresenceChanged()));
+ connect(account.data(), SIGNAL(currentPresenceChanged(Tp::Presence)), SLOT(onCurrentPresenceChanged()));
+}
+
+void GlobalPresence::onCurrentPresenceChanged()
+{
+ Tp::Presence highestCurrentPresence = Tp::Presence::offline();
+ Q_FOREACH(const Tp::AccountPtr &account, m_enabledAccounts->accounts()) {
+ if (m_presenceSorting[account->currentPresence().type()] < m_presenceSorting[highestCurrentPresence.type()]) {
+ highestCurrentPresence = account->currentPresence();
+ }
+ }
+
+ qDebug() << "current presence changed";
+
+ if (highestCurrentPresence.type() != m_currentPresence.type() ||
+ highestCurrentPresence.status() != m_requestedPresence.status()) {
+ m_currentPresence = highestCurrentPresence;
+ qDebug() << "emit";
+ Q_EMIT currentPresenceChanged(m_currentPresence);
+ }
+}
+
+void GlobalPresence::onRequestedPresenceChanged()
+{
+ Tp::Presence highestRequestedPresence = Tp::Presence::offline();
+ Q_FOREACH(const Tp::AccountPtr &account, m_enabledAccounts->accounts()) {
+ if (m_presenceSorting[account->requestedPresence().type()] < m_presenceSorting[highestRequestedPresence.type()]) {
+ highestRequestedPresence = account->currentPresence();
+ }
+ }
+
+ if (highestRequestedPresence.type() != m_requestedPresence.type() &&
+ highestRequestedPresence.status() != m_requestedPresence.status()) {
+ m_requestedPresence = highestRequestedPresence;
+ Q_EMIT requestedPresenceChanged(m_requestedPresence);
+ }
+}
+
+void GlobalPresence::onChangingPresence()
+{
+ bool isChangingPresence = false;
+ Q_FOREACH(const Tp::AccountPtr &account, m_enabledAccounts->accounts()) {
+ if (account->isChangingPresence()) {
+ isChangingPresence = true;
+ }
+ }
+
+ if (isChangingPresence != m_changingPresence) {
+ m_changingPresence = isChangingPresence;
+ Q_EMIT changingPresence(m_changingPresence);
+ }
+}
+
+#include "global-presence.moc"
diff --git a/global-presence.h b/global-presence.h
new file mode 100644
index 0000000..3ffe8b7
--- /dev/null
+++ b/global-presence.h
@@ -0,0 +1,84 @@
+/*
+ * Global Presence - wraps calls to set and get presence for all accounts.
+ *
+ * Copyright (C) 2011 David Edmundson <kde at davidedmundson.co.uk>
+ *
+ * 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 GLOBALPRESENCE_H
+#define GLOBALPRESENCE_H
+
+#include <QObject>
+#include <TelepathyQt4/AccountManager>
+#include <TelepathyQt4/AccountSet>
+
+
+/** This class handles the presence between all enabled accounts
+ * It shows the highest current available presence, indicates if any accounts are changing, and what they are changing to.
+*/
+
+class GlobalPresence : public QObject
+{
+ Q_OBJECT
+public:
+
+ explicit GlobalPresence(QObject *parent = 0);
+
+ /** Set the account manager to use
+ * @param accountManager should be ready.
+ */
+ void setAccountManager(const Tp::AccountManagerPtr &accountManager);
+
+
+ /** The most online presence of any account*/
+ Tp::Presence currentPresence() const;
+
+ /** The most online presence requested for any account if any of the accounts are changing state.
+ otherwise returns current presence*/
+ Tp::Presence requestedPresence() const;
+
+ /** Returns true if any account is changing state (i.e connecting*/
+ bool isChangingPresence() const;
+
+ /** Set all enabled accounts to the specified presence*/
+ void setPresence(const Tp::Presence &presence);
+
+signals:
+ void requestedPresenceChanged(const Tp::Presence &customPresence);
+ void currentPresenceChanged(const Tp::Presence &presence);
+ void changingPresence(bool isChanging);
+
+private slots:
+ void onCurrentPresenceChanged();
+ void onRequestedPresenceChanged();
+ void onChangingPresence();
+
+ void onAccountAdded(const Tp::AccountPtr &account);
+
+private:
+ Tp::AccountSetPtr m_enabledAccounts;
+
+ /** A cache of the last sent requested presence, to avoid resignalling*/
+ Tp::Presence m_requestedPresence;
+ /** A cache of the last sent presence*/
+ Tp::Presence m_currentPresence;
+ bool m_changingPresence;
+
+ /// Sets the sorting order of presences
+ QHash<uint, int> m_presenceSorting;
+};
+
+#endif // GLOBALPRESENCE_H
diff --git a/kpresence.cpp b/kpresence.cpp
new file mode 100644
index 0000000..3ec484e
--- /dev/null
+++ b/kpresence.cpp
@@ -0,0 +1,98 @@
+/*
+ * Global Presence - wrap Tp::Presence with KDE functionality
+ *
+ * Copyright (C) 2011 David Edmundson <kde at davidedmundson.co.uk>
+ *
+ * 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 "kpresence.h"
+#include <KLocalizedString>
+
+KPresence::KPresence() :
+ Tp::Presence()
+{
+}
+
+KPresence::KPresence(const Tp::Presence &presence) :
+ Tp::Presence(presence)
+{
+}
+
+KIcon KPresence::icon() const
+{
+ switch (type()) {
+ case Tp::ConnectionPresenceTypeAvailable:
+ return KIcon(QLatin1String("user-online"));
+ case Tp::ConnectionPresenceTypeBusy:
+ return KIcon("user-busy");
+ case Tp::ConnectionPresenceTypeAway:
+ return KIcon("user-away");
+ case Tp::ConnectionPresenceTypeExtendedAway:
+ return KIcon("user-away-extended");
+ case Tp::ConnectionPresenceTypeHidden:
+ return KIcon("user-invisible");
+ case Tp::ConnectionPresenceTypeOffline:
+ return KIcon("user-offline");
+ default:
+ return KIcon();
+ }
+}
+
+bool KPresence::operator <(const KPresence &other) const
+{
+ /// Sets the sorting order of presences
+ QHash<uint, int> m_presenceSorting;
+
+ m_presenceSorting[Tp::ConnectionPresenceTypeAvailable] = 0;
+ m_presenceSorting[Tp::ConnectionPresenceTypeBusy] = 1;
+ m_presenceSorting[Tp::ConnectionPresenceTypeHidden] = 2;
+ m_presenceSorting[Tp::ConnectionPresenceTypeAway] = 3;
+ m_presenceSorting[Tp::ConnectionPresenceTypeExtendedAway] = 4;
+ m_presenceSorting[Tp::ConnectionPresenceTypeHidden] = 5;
+ //don't distinguish between the following three presences
+ m_presenceSorting[Tp::ConnectionPresenceTypeError] = 6;
+ m_presenceSorting[Tp::ConnectionPresenceTypeUnknown] = 6;
+ m_presenceSorting[Tp::ConnectionPresenceTypeUnset] = 6;
+ m_presenceSorting[Tp::ConnectionPresenceTypeOffline] = 7;
+
+ if (m_presenceSorting[type()] < m_presenceSorting[other.type()]) {
+ return true;
+ } else if (m_presenceSorting[type()] == m_presenceSorting[other.type()]) {
+ return (statusMessage() < other.statusMessage());
+ } else {
+ return false;
+ }
+}
+
+QString KPresence::displayString() const
+{
+ switch (type()) {
+ case Tp::ConnectionPresenceTypeAvailable:
+ return i18n("Available");
+ case Tp::ConnectionPresenceTypeBusy:
+ return i18n("Busy");
+ case Tp::ConnectionPresenceTypeAway:
+ return i18n("Away");
+ case Tp::ConnectionPresenceTypeExtendedAway:
+ return i18n("Not available");
+ case Tp::ConnectionPresenceTypeHidden:
+ return i18n("Invisible");
+ case Tp::ConnectionPresenceTypeOffline:
+ return i18n("Offline");
+ default:
+ return QString();
+ }
+}
diff --git a/kpresence.h b/kpresence.h
new file mode 100644
index 0000000..2321816
--- /dev/null
+++ b/kpresence.h
@@ -0,0 +1,41 @@
+/*
+ * Global Presence - wrap Tp::Presence with KDE functionality
+ *
+ * Copyright (C) 2011 David Edmundson <kde at davidedmundson.co.uk>
+ *
+ * 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 KPRESENCE_H
+#define KPRESENCE_H
+
+#include <TelepathyQt4/Presence>
+
+#include <KIcon>
+
+class KPresence : public Tp::Presence
+{
+public:
+ KPresence();
+ KPresence(const Tp::Presence &presence);
+ KIcon icon() const;
+
+ /** Returns which presence is "more available" */
+ bool operator <(const KPresence &other) const;
+
+ QString displayString() const;
+};
+
+#endif // KPRESENCE_H
--
ktp-common-internals packaging
More information about the pkg-kde-commits
mailing list