void ContactListModel::Private::updateAccount() { PsiAccount *account = qobject_cast<PsiAccount*>(sender()); if (account->enabled()) { ContactListItem *root = static_cast<ContactListItem*>(q->root());; ContactListItem *accountItem = root->findAccount(account); Q_ASSERT(accountItem); q->updateItem(accountItem); } else { cleanUpAccount(account); } }
void ContactListModel::Private::cleanUpAccount(PsiAccount *account) { disconnect(account, nullptr, this, nullptr); ContactListItem *root = static_cast<ContactListItem*>(q->root()); ContactListItem *item = root->findAccount(account); if (!item) { qCritical("BUG: account was already removed from the list"); return; } QModelIndex index = q->toModelIndex(item); q->beginRemoveRows(index.parent(), index.row(), index.row()); delete item; q->endRemoveRows(); }
void ContactListModel::Private::realAddContact(PsiContact *contact) { ContactListItem *root = static_cast<ContactListItem*>(q->root());; if (accountsEnabled) { PsiAccount *account = contact->account(); ContactListItem *accountItem = root->findAccount(account); if (!accountItem) { accountItem = new ContactListItem(q, ContactListItem::Type::AccountType); accountItem->setAccount(account); accountItem->setExpanded(!collapsed.contains(accountItem->internalName())); connect(account, SIGNAL(accountDestroyed()), SLOT(onAccountDestroyed())); connect(account, SIGNAL(updatedAccount()), SLOT(updateAccount())); root->appendChild(accountItem); } root = accountItem; } if (!contact->isSelf() && groupsEnabled) { ContactListItem::SpecialGroupType specialGroupType = specialGroupFor(contact); QStringList groups = specialGroupType == ContactListItem::SpecialGroupType::NoneSpecialGroupType ? contact->groups() : QStringList{QString()}; for (const QString &groupName: groups) { ContactListItem *groupItem = nullptr; if (specialGroupType == ContactListItem::SpecialGroupType::NoneSpecialGroupType) groupItem = root->findGroup(groupName); else groupItem = root->findGroup(specialGroupType); // No duplicates if (groupItem && groupItem->findContact(contact)) { continue; } ContactListItem *item = new ContactListItem(q, ContactListItem::Type::ContactType); item->setContact(contact); if (!groupItem) { groupItem = new ContactListItem(q, ContactListItem::Type::GroupType, specialGroupType); if (specialGroupType == ContactListItem::SpecialGroupType::NoneSpecialGroupType) groupItem->setName(groupName); root->appendChild(groupItem); groupItem->setExpanded(!collapsed.contains(groupItem->internalName())); groupItem->setHidden(hidden.contains(groupItem->internalName())); } groupItem->appendChild(item); monitoredContacts.insertMulti(contact, q->toModelIndex(item)); } } else { ContactListItem *item = new ContactListItem(q, ContactListItem::Type::ContactType); item->setContact(contact); root->appendChild(item); monitoredContacts.insertMulti(contact, q->toModelIndex(item)); } connect(contact, SIGNAL(destroyed(PsiContact*)), SLOT(removeContact(PsiContact*))); connect(contact, SIGNAL(groupsChanged()), SLOT(contactGroupsChanged())); connect(contact, SIGNAL(updated()), SLOT(contactUpdated())); connect(contact, SIGNAL(alert()), SLOT(contactUpdated())); connect(contact, SIGNAL(anim()), SLOT(contactUpdated())); }