18 #include "cntpresencelistener.h" |
18 #include "cntpresencelistener.h" |
19 |
19 |
20 #include <prcpresencebuddyinfo_qt.h> |
20 #include <prcpresencebuddyinfo_qt.h> |
21 #include <prcpresencereader_qt.h> |
21 #include <prcpresencereader_qt.h> |
22 |
22 |
|
23 /*! |
|
24 Presence listener for contact card. It provides aggregated |
|
25 presence information for a contact and separately for each |
|
26 valid QContactOnlineAccount. |
|
27 */ |
23 CntPresenceListener::CntPresenceListener(const QContact& contact, QObject* parent) : |
28 CntPresenceListener::CntPresenceListener(const QContact& contact, QObject* parent) : |
24 QObject(parent), |
29 QObject(parent), |
25 mReader(NULL), |
30 mReader(NULL), |
26 mContact(contact) |
31 mContact(contact) |
27 { |
32 { |
28 mReader = PrcPresenceReader::createReader(); |
33 mReader = PrcPresenceReader::createReader(); |
29 connect(mReader, SIGNAL(signalPresenceNotification(bool, PrcPresenceBuddyInfoQt*)), |
34 connect(mReader, SIGNAL(signalPresenceNotification(bool, PrcPresenceBuddyInfoQt*)), |
30 this, SLOT(handlePresenceUpdate(bool, PrcPresenceBuddyInfoQt*))); |
35 this, SLOT(handlePresenceUpdate(bool, PrcPresenceBuddyInfoQt*))); |
31 } |
36 } |
32 |
37 |
|
38 /*! |
|
39 Destructor |
|
40 */ |
33 CntPresenceListener::~CntPresenceListener() |
41 CntPresenceListener::~CntPresenceListener() |
34 { |
42 { |
35 delete mReader; |
43 delete mReader; |
36 mReader = NULL; |
44 mReader = NULL; |
37 } |
45 } |
38 |
46 |
|
47 /*! |
|
48 Subscribes all valid QContactOnlineAccounts to receive status updates from presence cache and |
|
49 returns initial presence statuses for each of the accounts. |
|
50 |
|
51 \param combinedOnlineStatus aggregated online status |
|
52 \return QMap with account specific (for example "sip:sip@sip.com") online information |
|
53 */ |
39 QMap<QString, bool> CntPresenceListener::initialPresences(bool &combinedOnlineStatus) |
54 QMap<QString, bool> CntPresenceListener::initialPresences(bool &combinedOnlineStatus) |
40 { |
55 { |
41 QMap<QString, bool> initialMap; |
56 QMap<QString, bool> initialMap; |
42 |
57 |
43 QList<QContactOnlineAccount> accounts = mContact.details<QContactOnlineAccount>(); |
58 QList<QContactOnlineAccount> accounts = mContact.details<QContactOnlineAccount>(); |
65 combinedOnlineStatus = parsePresence(buddies); |
80 combinedOnlineStatus = parsePresence(buddies); |
66 qDeleteAll(buddies); |
81 qDeleteAll(buddies); |
67 |
82 |
68 return initialMap; |
83 return initialMap; |
69 } |
84 } |
|
85 |
|
86 /*! |
|
87 Private slot that handles emitting changes for separate accounts along |
|
88 with the aggregated information. |
70 |
89 |
|
90 \param aSuccess information if the request/update was succesful |
|
91 \param aPresenceBuddyInfo the account that got updated |
|
92 */ |
71 void CntPresenceListener::handlePresenceUpdate(bool aSuccess, PrcPresenceBuddyInfoQt* aPresenceBuddyInfo) |
93 void CntPresenceListener::handlePresenceUpdate(bool aSuccess, PrcPresenceBuddyInfoQt* aPresenceBuddyInfo) |
72 { |
94 { |
73 if (aSuccess && aPresenceBuddyInfo != NULL) |
95 if (aSuccess && aPresenceBuddyInfo != NULL) |
74 { |
96 { |
75 if (mAccountList.contains(aPresenceBuddyInfo->buddyId())) |
97 if (mAccountList.contains(aPresenceBuddyInfo->buddyId())) |
88 { |
110 { |
89 buddies.append(buddy); |
111 buddies.append(buddy); |
90 } |
112 } |
91 } |
113 } |
92 |
114 |
93 // emit the combined presence status |
115 // emit the aggregated presence status |
94 emit fullPresenceUpdated(parsePresence(buddies)); |
116 emit fullPresenceUpdated(parsePresence(buddies)); |
95 |
117 |
96 qDeleteAll(buddies); |
118 qDeleteAll(buddies); |
97 } |
119 } |
98 } |
120 } |
99 } |
121 } |
100 |
122 |
|
123 /*! |
|
124 Returns the aggregated online status. |
|
125 |
|
126 \param buddyList list of accounts to parse the aggregated status from |
|
127 \return bool true if any of the accounts is online |
|
128 */ |
101 bool CntPresenceListener::parsePresence(QList<PrcPresenceBuddyInfoQt*> buddyList) |
129 bool CntPresenceListener::parsePresence(QList<PrcPresenceBuddyInfoQt*> buddyList) |
102 { |
130 { |
103 foreach (PrcPresenceBuddyInfoQt* buddy, buddyList) |
131 foreach (PrcPresenceBuddyInfoQt* buddy, buddyList) |
104 { |
132 { |
105 PrcPresenceBuddyInfoQt::AvailabilityValues availability = buddy->availability(); |
133 PrcPresenceBuddyInfoQt::AvailabilityValues availability = buddy->availability(); |