[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:06 UTC 2016
Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-contact-list.git;a=commitdiff;h=6478703
The following commit has been merged in the master branch:
commit 6478703e74c54baf8e7fddb4cdfdbf8ca6f8af06
Author: Paolo Capriotti <p.capriotti at gmail.com>
Date: Mon Jul 18 00:00:36 2011 +0100
Refactor presence handling in AccountButton.
* Factored out a function to get the correct action corresponding to the
current presence.
* Use status first for matching, then type if status fails.
* Use 'away' icon for the BRB action.
* Remove unused code.
REVIEW: 101992
Reviewed-by: Martin Klapetek
---
account-button.cpp | 79 +++++++++++++++++++++++++++++-------------------------
account-button.h | 11 +++-----
2 files changed, 47 insertions(+), 43 deletions(-)
diff --git a/account-button.cpp b/account-button.cpp
index 7763858..5c9e135 100644
--- a/account-button.cpp
+++ b/account-button.cpp
@@ -35,7 +35,9 @@
#include <TelepathyQt4/PendingOperation>
AccountButton::AccountButton(const Tp::AccountPtr &account, QWidget* parent)
- : QToolButton(parent), m_busyOverlay(0)
+ : QToolButton(parent),
+ m_busyOverlay(0),
+ m_offlineAction(0)
{
m_account = account;
@@ -43,23 +45,15 @@ AccountButton::AccountButton(const Tp::AccountPtr &account, QWidget* parent)
m_busyOverlay->setWidget(this);
m_busyOverlay->setSequence(KPixmapSequence(QString("process-working")));
- m_errorPixmap = KIconLoader::global()->loadIcon("dialog-error", KIconLoader::NoGroup, 16);
- m_onlinePixmap = KIconLoader::global()->loadIcon("user-online", KIconLoader::NoGroup, 16);
- m_awayPixmap = KIconLoader::global()->loadIcon("user-away", KIconLoader::NoGroup, 16);
- m_awayExPixmap = KIconLoader::global()->loadIcon("user-away-extended", KIconLoader::NoGroup, 16);
- m_busyPixmap = KIconLoader::global()->loadIcon("user-busy", KIconLoader::NoGroup, 16);
- m_hiddenPixmap = KIconLoader::global()->loadIcon("user-invisible", KIconLoader::NoGroup, 16);
- m_offlinePixmap = KIconLoader::global()->loadIcon("user-offline", KIconLoader::NoGroup, 16);
-
QString iconPath = account->iconName();
setIcon(KIcon(iconPath));
-
if (!account->isValid()) {
//we paint a warning symbol in the right-bottom corner
+ QPixmap errorPixmap = KIconLoader::global()->loadIcon("dialog-error", KIconLoader::NoGroup, 16);
QPixmap pixmap = icon().pixmap(32, 32);
QPainter painter(&pixmap);
- painter.drawPixmap(15, 15, 16, 16, m_errorPixmap);
+ painter.drawPixmap(15, 15, 16, 16, errorPixmap);
setIcon(KIcon(pixmap));
}
@@ -75,12 +69,12 @@ AccountButton::AccountButton(const Tp::AccountPtr &account, QWidget* parent)
KAction *onlineAction = new KAction(KIcon("user-online"), i18nc("@action:inmenu This is an IM user status", "Available"), this);
KAction *awayAction = new KAction(KIcon("user-away"), i18nc("@action:inmenu This is an IM user status", "Away"), this);
- KAction *brbAction = new KAction(KIcon("user-busy"), i18nc("@action:inmenu This is an IM user status", "Be right back"), this);
+ KAction *brbAction = new KAction(KIcon("user-away"), i18nc("@action:inmenu This is an IM user status", "Be right back"), this);
KAction *busyAction = new KAction(KIcon("user-busy"), i18nc("@action:inmenu This is an IM user status", "Busy"), this);
KAction *dndAction = new KAction(KIcon("user-busy"), i18nc("@action:inmenu This is an IM user status", "Do not disturb"), this);
KAction *xaAction = new KAction(KIcon("user-away-extended"), i18nc("@action:inmenu This is an IM user status", "Extended Away"), this);
KAction *invisibleAction = new KAction(KIcon("user-invisible"), i18nc("@action:inmenu This is an IM user status", "Invisible"), this);
- KAction *offlineAction = new KAction(KIcon("user-offline"), i18nc("@action:inmenu This is an IM user status", "Offline"), this);
+ m_offlineAction = new KAction(KIcon("user-offline"), i18nc("@action:inmenu This is an IM user status", "Offline"), this);
m_presenceMessageWidget = new KLineEdit(this);
m_presenceMessageWidget->setClearButtonShown(true);
@@ -102,10 +96,13 @@ AccountButton::AccountButton(const Tp::AccountPtr &account, QWidget* parent)
awayAction->setData(qVariantFromValue(Tp::Presence::away()));
brbAction->setData(qVariantFromValue(Tp::Presence::brb()));
busyAction->setData(qVariantFromValue(Tp::Presence::busy()));
- dndAction->setData(qVariantFromValue(Tp::Presence::busy()));
+ dndAction->setData(qVariantFromValue(Tp::Presence(
+ Tp::ConnectionPresenceTypeBusy,
+ QLatin1String("dnd"),
+ QLatin1String(""))));
xaAction->setData(qVariantFromValue(Tp::Presence::xa()));
invisibleAction->setData(qVariantFromValue(Tp::Presence::hidden()));
- offlineAction->setData(qVariantFromValue(Tp::Presence::offline()));
+ m_offlineAction->setData(qVariantFromValue(Tp::Presence::offline()));
presenceActions->addAction(onlineAction);
presenceActions->addAction(awayAction);
@@ -114,7 +111,7 @@ AccountButton::AccountButton(const Tp::AccountPtr &account, QWidget* parent)
presenceActions->addAction(dndAction);
presenceActions->addAction(xaAction);
presenceActions->addAction(invisibleAction);
- presenceActions->addAction(offlineAction);
+ presenceActions->addAction(m_offlineAction);
presenceActions->addAction(presenceMessageAction);
addActions(presenceActions->actions());
@@ -203,28 +200,39 @@ void AccountButton::presenceChanged(const Tp::Presence &presence)
return;
}
- bool accountPresenceFound = false;
+ QAction *action = actionForPresence(presence);
+ if (!action) {
+ action = m_offlineAction;
+ }
- foreach (QAction *a, actions()) {
- if (presence.type() == qVariantValue<Tp::Presence>(a->data()).type()) {
- a->setChecked(true);
- updateToolTip();
+ action->setChecked(true);
+ updateToolTip();
- accountPresenceFound = true;
+ QPixmap pixmap = icon().pixmap(32, 32);
+ QPainter painter(&pixmap);
+ KIcon(action->icon()).paint(&painter, 15, 15, 16, 16);
- QPixmap pixmap = icon().pixmap(32, 32);
- QPainter painter(&pixmap);
- KIcon(a->icon()).paint(&painter, 15, 15, 16, 16);
+ setIcon(KIcon(pixmap));
+}
- setIcon(KIcon(pixmap));
+QAction *AccountButton::actionForPresence(const Tp::Presence &presence) const
+{
+ QAction *match = 0;
- break;
+ foreach (QAction *a, actions()) {
+ Tp::Presence actionPresence = qVariantValue<Tp::Presence>(a->data());
+ if (presence.status() == actionPresence.status()) {
+ // if a matching status is found, return it immediately
+ return a;
+ } else if (!match && presence.type() == actionPresence.type()) {
+ // if no matching status is found, the first action with matching
+ // type will be returned, so save it for later
+ match = a;
}
}
- if (!accountPresenceFound) {
- presenceChanged(Tp::Presence::offline());
- }
+ // return the best match, which could be a null pointer
+ return match;
}
/* since there is no easy way to get this string by Tp::Presence,
@@ -232,13 +240,12 @@ void AccountButton::presenceChanged(const Tp::Presence &presence)
This will also get us i18n strings for free. */
QString AccountButton::presenceDisplayString(const Tp::Presence &presence)
{
- foreach (QAction *a, actions()) {
- if (presence.status() == qVariantValue<Tp::Presence>(a->data()).status()) {
- return KGlobal::locale()->removeAcceleratorMarker(a->text());
- }
+ QAction *action = actionForPresence(presence);
+ if (action) {
+ return KGlobal::locale()->removeAcceleratorMarker(action->text());
+ } else {
+ return QString();
}
-
- return QString();
}
void AccountButton::setCustomPresenceMessage(const QString& message)
diff --git a/account-button.h b/account-button.h
index fb98a0d..8dbf315 100644
--- a/account-button.h
+++ b/account-button.h
@@ -66,6 +66,9 @@ public Q_SLOTS:
void setCustomPresenceMessage(const QString &message);
private:
+
+ QAction *actionForPresence(const Tp::Presence &presence) const;
+
///Holds the account it controls
Tp::AccountPtr m_account;
@@ -77,13 +80,7 @@ private:
KLineEdit *m_presenceMessageWidget;
- QPixmap m_errorPixmap;
- QPixmap m_onlinePixmap;
- QPixmap m_awayPixmap;
- QPixmap m_busyPixmap;
- QPixmap m_awayExPixmap;
- QPixmap m_hiddenPixmap;
- QPixmap m_offlinePixmap;
+ QAction *m_offlineAction;
};
#endif // TELEPATHY_ACCOUNTBUTTON_H
--
ktp-contact-list packaging
More information about the pkg-kde-commits
mailing list