21 #include <TelepathyQt/Account>
22 #include <TelepathyQt/Contact>
23 #include <TelepathyQt/ContactCapabilities>
24 #include <TelepathyQt/Connection>
25 #include <TelepathyQt/ContactManager>
31 class KTp::ContactsListModel::Private
34 QList<Tp::ContactPtr> contacts;
43 d->contactManager = 0;
45 QHash<int, QByteArray> roles = roleNames();
78 connect(d->contactManager, SIGNAL(allKnownContactsChanged(Tp::Contacts,Tp::Contacts)), SLOT(onContactsChanged(Tp::Contacts,Tp::Contacts)));
83 if (!parent.isValid()) {
84 return d->contacts.size();
92 int row = index.row();
94 if (row >=0 && row < d->contacts.size()) {
95 const KTp::ContactPtr contact = KTp::ContactPtr::qObjectCast(d->contacts[row]);
96 Q_ASSERT_X(!contact.isNull(),
"KTp::ContactListModel::data()",
97 "Failed to cast Tp::ContactPtr to KTp::ContactPtr. Are you using KTp::ContactFactory?");
102 case Qt::DisplayRole:
103 return contact->alias();
105 return contact->id();
108 return QVariant::fromValue(contact);
110 return QVariant::fromValue(d->contactManager->accountForContact(contact));
113 return contact->clientTypes();
115 return contact->avatarData().fileName;
117 return contact->avatarPixmap();
119 return contact->groups();
122 return contact->presence().displayString();
124 return contact->presence().statusMessage();
126 return contact->presence().type();
128 return contact->presence().iconName();
131 return contact->subscriptionState();
133 return contact->publishState();
135 return contact->isBlocked();
140 return contact->fileTransferCapability();
142 return contact->audioCallCapability();
144 return contact->videoCallCapability();
147 return QStringList() << contact->capabilities().streamTubeServices()
148 << contact->capabilities().dbusTubeServices();
157 void KTp::ContactsListModel::onContactsChanged(
const Tp::Contacts &added,
const Tp::Contacts &removed)
162 KTp::ContactPtr contact = KTp::ContactPtr::qObjectCast(contact_uncasted);
164 connect(contact.data(),
165 SIGNAL(aliasChanged(QString)),
167 connect(contact.data(),
168 SIGNAL(avatarTokenChanged(QString)),
170 connect(contact.data(),
171 SIGNAL(avatarDataChanged(Tp::AvatarData)),
173 connect(contact.data(),
174 SIGNAL(presenceChanged(Tp::Presence)),
176 connect(contact->manager()->connection()->selfContact().data(),
177 SIGNAL(capabilitiesChanged(Tp::ContactCapabilities)),
179 connect(contact.data(),
180 SIGNAL(capabilitiesChanged(Tp::ContactCapabilities)),
182 connect(contact.data(),
183 SIGNAL(locationUpdated(Tp::LocationInfo)),
185 connect(contact.data(),
186 SIGNAL(infoFieldsChanged(Tp::Contact::InfoFields)),
188 connect(contact.data(),
189 SIGNAL(subscriptionStateChanged(Tp::Contact::PresenceState)),
191 connect(contact.data(),
192 SIGNAL(publishStateChanged(Tp::Contact::PresenceState,QString)),
194 connect(contact.data(),
195 SIGNAL(blockStatusChanged(
bool)),
197 connect(contact.data(),
198 SIGNAL(clientTypesChanged(QStringList)),
200 connect(contact.data(),
201 SIGNAL(addedToGroup(QString)),
203 connect(contact.data(),
204 SIGNAL(removedFromGroup(QString)),
207 connect(contact.data(),
208 SIGNAL(invalidated()),
209 SLOT(onConnectionDropped()));
212 if (added.size() > 0) {
213 beginInsertRows(QModelIndex(), d->contacts.size(), d->contacts.size() + added.size() -1);
214 d->contacts.append(added.toList());
220 int row = d->contacts.indexOf(contact);
222 beginRemoveRows(QModelIndex(), row, row);
223 d->contacts.removeOne(contact);
229 void KTp::ContactsListModel::onChanged()
232 int row = d->contacts.indexOf(contact);
234 QModelIndex index = createIndex(row, 0);
235 dataChanged(index, index);
239 void KTp::ContactsListModel::onConnectionDropped()
242 onContactsChanged(Tp::Contacts(), Tp::Contacts() << contact);