[SCM] ktp-contact-list packaging branch, master, updated. debian/15.12.1-2-1070-g6c56f91
Maximiliano Curia
maxy at moszumanska.debian.org
Sat May 28 00:07:43 UTC 2016
Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-contact-list.git;a=commitdiff;h=09840af
The following commit has been merged in the master branch:
commit 09840af6d0a8c57fdf9f9f2c0e7bca15d46bdbe0
Author: David Edmundson <kde at davidedmundson.co.uk>
Date: Sat Sep 17 17:22:43 2011 +0100
Start of global presence chooser
---
CMakeLists.txt | 2 +
global-presence-chooser.cpp | 54 +++++++++++++++++++
global-presence-chooser.h | 25 +++++++++
global-presence.cpp | 127 ++++++++++++++++++++++++++++++++++++++++++++
global-presence.h | 66 +++++++++++++++++++++++
main-widget.cpp | 1 +
main-widget.ui | 12 ++++-
7 files changed, 285 insertions(+), 2 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index a258313..9ea3bb9 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -47,6 +47,8 @@ set (contactlist_SRCS
main.cpp
main-widget.cpp
fetch-avatar-job.cpp
+ global-presence.cpp
+ global-presence-chooser.cpp
dialogs/add-contact-dialog.cpp
dialogs/join-chat-room-dialog.cpp
dialogs/remove-contact-dialog.cpp
diff --git a/global-presence-chooser.cpp b/global-presence-chooser.cpp
new file mode 100644
index 0000000..fab3f4a
--- /dev/null
+++ b/global-presence-chooser.cpp
@@ -0,0 +1,54 @@
+#include "global-presence-chooser.h"
+
+#include "global-presence.h"
+
+#include <KIcon>
+#include <KLocale>
+
+#include <TelepathyQt4/Presence>
+
+GlobalPresenceChooser::GlobalPresenceChooser(QWidget *parent) :
+ QComboBox(parent),
+ m_globalPresence(new GlobalPresence(this))
+{
+ addItem(KIcon("user-online"), i18n("Available"), qVariantFromValue(Tp::Presence::available()));
+ addItem(KIcon("user-away"), i18n("Away"), qVariantFromValue(Tp::Presence::away()));
+ addItem(KIcon("user-away"), i18n("Be Right Back"), qVariantFromValue(Tp::Presence::brb()));
+ addItem(KIcon("user-busy"), i18n("Busy"), qVariantFromValue(Tp::Presence::busy()));
+ addItem(KIcon("user-busy"), i18n("Do Not Disturb"), qVariantFromValue(Tp::Presence(
+ Tp::ConnectionPresenceTypeBusy,
+ QLatin1String("dnd"),
+ QLatin1String(""))));
+ addItem(KIcon("user-away-extended"), i18n("Extended Away"), qVariantFromValue(Tp::Presence::xa()));
+ addItem(KIcon("user-invisible"), i18n("Invisible"), qVariantFromValue(Tp::Presence::hidden()));
+ addItem(KIcon("user-offline"), i18n("Offline"), qVariantFromValue(Tp::Presence::offline()));
+
+ connect(this, SIGNAL(activated(int)), SLOT(onCurrentIndexChanged(int)));
+ connect(m_globalPresence, SIGNAL(currentPresenceChanged(Tp::Presence)), SLOT(onPresenceChanged(Tp::Presence)));
+}
+
+void GlobalPresenceChooser::setAccountManager(const Tp::AccountManagerPtr &accountManager)
+{
+ m_globalPresence->setAccountManager(accountManager);
+}
+
+void GlobalPresenceChooser::onCurrentIndexChanged(int index)
+{
+ Tp::Presence presence = itemData(index).value<Tp::Presence>();
+ m_globalPresence->setPresence(presence);
+}
+
+void GlobalPresenceChooser::onPresenceChanged(const Tp::Presence &presence)
+{
+ qDebug() << "presence changing";
+ for (int i=0; i < count() ; i++) {
+ Tp::Presence itemPresence = itemData(i).value<Tp::Presence>();
+ if (itemPresence.type() == presence.type() && itemPresence.status() == presence.status()) {
+ setCurrentIndex(i);
+ qDebug() << "found item";
+ }
+ }
+
+ //FIXME if we can't find the correct value, create an entry.
+}
+
diff --git a/global-presence-chooser.h b/global-presence-chooser.h
new file mode 100644
index 0000000..337a135
--- /dev/null
+++ b/global-presence-chooser.h
@@ -0,0 +1,25 @@
+#ifndef GLOBALPRESENCECHOOSER_H
+#define GLOBALPRESENCECHOOSER_H
+
+#include <QComboBox>
+
+#include <TelepathyQt4/AccountManager>
+
+class GlobalPresence;
+
+class GlobalPresenceChooser : public QComboBox
+{
+ Q_OBJECT
+public:
+ explicit GlobalPresenceChooser(QWidget *parent = 0);
+ void setAccountManager(const Tp::AccountManagerPtr &accountManager);
+
+private slots:
+ void onCurrentIndexChanged(int index);
+ void onPresenceChanged(const Tp::Presence &presence);
+
+private:
+ GlobalPresence *m_globalPresence;
+};
+
+#endif // GLOBALPRESENCECHOOSER_H
diff --git a/global-presence.cpp b/global-presence.cpp
new file mode 100644
index 0000000..1171ffc
--- /dev/null
+++ b/global-presence.cpp
@@ -0,0 +1,127 @@
+#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 changingPresence = false;
+ Q_FOREACH(const Tp::AccountPtr &account, m_enabledAccounts->accounts()) {
+ if (account->isChangingPresence()) {
+ changingPresence = true;
+ }
+ }
+
+ if (changingPresence != m_changingPresence) {
+ m_changingPresence = changingPresence;
+ Q_EMIT (m_changingPresence);
+ }
+}
+
diff --git a/global-presence.h b/global-presence.h
new file mode 100644
index 0000000..b2d2475
--- /dev/null
+++ b/global-presence.h
@@ -0,0 +1,66 @@
+#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);
+
+public slots:
+
+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/main-widget.cpp b/main-widget.cpp
index 494936d..3a74345 100644
--- a/main-widget.cpp
+++ b/main-widget.cpp
@@ -341,6 +341,7 @@ void MainWidget::onAccountManagerReady(Tp::PendingOperation* op)
m_avatarButton->initialize(m_model, m_accountManager);
m_accountButtons->setAccountManager(m_accountManager);
+ m_presenceChooser->setAccountManager(m_accountManager);
QList<Tp::AccountPtr> accounts = m_accountManager->allAccounts();
diff --git a/main-widget.ui b/main-widget.ui
index a84e682..42725fe 100644
--- a/main-widget.ui
+++ b/main-widget.ui
@@ -46,7 +46,7 @@
</property>
</widget>
</item>
- <item row="0" column="0" rowspan="3">
+ <item row="0" column="0" rowspan="4">
<widget class="AvatarButton" name="m_avatarButton">
<property name="minimumSize">
<size>
@@ -71,9 +71,12 @@
</property>
</widget>
</item>
- <item row="2" column="1">
+ <item row="3" column="1">
<widget class="AccountButtonsPanel" name="m_accountButtons" native="true"/>
</item>
+ <item row="2" column="1">
+ <widget class="GlobalPresenceChooser" name="m_presenceChooser"/>
+ </item>
</layout>
</item>
<item>
@@ -126,6 +129,11 @@
<header>account-buttons-panel.h</header>
<container>1</container>
</customwidget>
+ <customwidget>
+ <class>GlobalPresenceChooser</class>
+ <extends>QComboBox</extends>
+ <header>global-presence-chooser.h</header>
+ </customwidget>
</customwidgets>
<resources/>
<connections/>
--
ktp-contact-list packaging
More information about the pkg-kde-commits
mailing list