create PresenceManager that manage global presence state and message
[makneto-zunavac1.git] / src / ui-kde / account-presence-button.cpp
blob0ce8bcf8fed34a6f2a47034ba49cb40110654940
1 #include <QIcon>
3 #include <TelepathyQt4/Account>
4 #include <TelepathyQt4/PendingOperation>
6 #include "account-presence-button.h"
8 AccountPresenceButton::AccountPresenceButton(Tp::AccountPtr account, QWidget* parent)
9 : QToolButton(parent),
10 m_account(account)
12 QString iconPath = account->iconName();
13 qDebug() << "ICON NAME: " << iconPath;
14 setIcon(QIcon(iconPath));
16 setAutoRaise(true);
17 setPopupMode(QToolButton::InstantPopup);
19 QActionGroup *presenceActions = new QActionGroup(this);
20 presenceActions->setExclusive(true);
22 QAction *availableAction = new QAction(QString("available"), this);
23 QAction *awayAction = new QAction(QString("away"),this);
24 QAction *dndAction = new QAction(QString("DND"),this);
25 QAction *invisibleAction = new QAction(QString("invisible"),this);
26 QAction *offlineAction = new QAction(QString("offline"),this);
28 availableAction->setData(qVariantFromValue(Tp::Presence::available()));
29 awayAction->setData(qVariantFromValue(Tp::Presence::away()));
30 dndAction->setData(qVariantFromValue(Tp::Presence::busy()));
31 invisibleAction->setData(qVariantFromValue(Tp::Presence::hidden()));
32 offlineAction->setData(qVariantFromValue(Tp::Presence::offline()));
34 presenceActions->addAction(availableAction);
35 presenceActions->addAction(awayAction);
36 presenceActions->addAction(dndAction);
37 presenceActions->addAction(invisibleAction);
38 presenceActions->addAction(offlineAction);
40 addActions(presenceActions->actions());
42 foreach (QAction *action, actions()) {
43 action->setCheckable(true);
45 if (m_account->currentPresence().status() == qVariantValue<Tp::Presence>(action->data()).status()) {
46 action->setChecked(true);
50 connect(this, SIGNAL(triggered(QAction*)),
51 this, SLOT(setAccountStatus(QAction*)));
52 connect(m_account.data(), SIGNAL(currentPresenceChanged(const Tp::Presence &)),
53 this, SLOT(presenceChanged(const Tp::Presence &)));
57 QString AccountPresenceButton::accountId()
59 return m_account->uniqueIdentifier();
63 void AccountPresenceButton::setAccountStatus(QAction *action)
65 Tp::SimplePresence presence;
66 presence.type = qVariantValue<Tp::Presence>(action->data()).type();
67 // presence.status = qVariantValue<Tp::Presence>(action->data()).status();
69 Q_ASSERT(!m_account.isNull());
71 Tp::PendingOperation* presenceRequest = m_account->setRequestedPresence(presence);
73 connect(presenceRequest, SIGNAL(finished(Tp::PendingOperation*)),
74 this, SLOT(updateToolTip()));
78 void AccountPresenceButton::presenceChanged(const Tp::Presence &presence)
80 foreach (QAction *action, actions()) {
81 if (presence.status() == qVariantValue<Tp::Presence>(action->data()).status()) {
82 action->setChecked(true);
83 break;