25 #include <TelepathyQt/AccountSet>
26 #include <TelepathyQt/Account>
35 m_changingPresence(false)
38 unknown.setStatus(Tp::ConnectionPresenceTypeUnknown, QLatin1String(
"unknown"), QString());
46 if (! accountManager->isReady()) {
47 kWarning() <<
"GlobalPresence used with unready account manager";
50 m_enabledAccounts = accountManager->enabledAccounts();
51 m_onlineAccounts = accountManager->onlineAccounts();
53 Q_FOREACH(
const Tp::AccountPtr &account, m_enabledAccounts->accounts()) {
54 onAccountAdded(account);
57 onCurrentPresenceChanged();
58 onRequestedPresenceChanged();
61 connect(m_enabledAccounts.data(), SIGNAL(accountAdded(Tp::AccountPtr)), SLOT(onAccountAdded(Tp::AccountPtr)));
67 return m_connectionStatus;
72 return m_currentPresence;
77 return m_requestedPresence;
82 return m_changingPresence;
87 if (m_enabledAccounts.isNull()) {
88 kWarning() <<
"Requested presence change on empty accounts set";
92 Q_FOREACH(
const Tp::AccountPtr &account, m_enabledAccounts->accounts()) {
93 account->setRequestedPresence(presence);
97 void GlobalPresence::onAccountAdded(
const Tp::AccountPtr &account)
99 connect(account.data(), SIGNAL(
connectionStatusChanged(Tp::ConnectionStatus)), SLOT(onConnectionStatusChanged()));
100 connect(account.data(), SIGNAL(
changingPresence(
bool)), SLOT(onChangingPresence()));
105 void GlobalPresence::onCurrentPresenceChanged()
107 Tp::Presence highestCurrentPresence = Tp::Presence::offline();
108 Q_FOREACH(
const Tp::AccountPtr &account, m_enabledAccounts->accounts()) {
110 highestCurrentPresence = account->currentPresence();
114 kDebug() <<
"Current presence changed";
116 if (highestCurrentPresence.type() != m_currentPresence.type() ||
117 highestCurrentPresence.status() != m_currentPresence.status() ||
118 highestCurrentPresence.statusMessage() != m_currentPresence.statusMessage()) {
120 m_currentPresence =
Presence(highestCurrentPresence);
125 void GlobalPresence::onRequestedPresenceChanged()
127 Tp::Presence highestRequestedPresence = Tp::Presence::offline();
128 Q_FOREACH(
const Tp::AccountPtr &account, m_enabledAccounts->accounts()) {
130 highestRequestedPresence = account->requestedPresence();
134 if (highestRequestedPresence.type() != m_requestedPresence.type() ||
135 highestRequestedPresence.status() != m_requestedPresence.status() ||
136 highestRequestedPresence.statusMessage() != m_requestedPresence.statusMessage()) {
137 m_requestedPresence =
Presence(highestRequestedPresence);
142 void GlobalPresence::onChangingPresence()
145 Q_FOREACH(
const Tp::AccountPtr &account, m_enabledAccounts->accounts()) {
146 if (account->isChangingPresence()) {
147 isChangingPresence =
true;
151 if (isChangingPresence != m_changingPresence) {
157 void GlobalPresence::onConnectionStatusChanged()
161 Q_FOREACH(
const Tp::AccountPtr &account, m_enabledAccounts->accounts()) {
162 switch (account->connectionStatus()) {
163 case Tp::ConnectionStatusConnecting:
165 connectionStatus = Tp::ConnectionStatusConnecting;
167 case Tp::ConnectionStatusConnected:
169 if (connectionStatus == Tp::ConnectionStatusDisconnected) {
170 connectionStatus = Tp::ConnectionStatusConnected;
178 if (connectionStatus != m_connectionStatus) {
187 if (m_enabledAccounts->accounts().isEmpty()) {
196 kDebug() <<
"Saving presence with message:" << m_currentPresence.statusMessage();
197 m_savedPresence = m_currentPresence;
202 kDebug() << m_savedPresence.statusMessage();
208 return m_onlineAccounts;
214 #include "global-presence.moc"