void ContactListModelUpdater::addContact(PsiContact* contact)
{
	// qWarning(">>> addContact: %s", qPrintable(contact->jid()));
	Q_ASSERT(!monitoredContacts_.contains(contact));
	if (monitoredContacts_.contains(contact))
		return;
	monitoredContacts_[contact] = true;
// qWarning("updater(%x):addContact: %s", (int)this, qPrintable(contact->jid().full()));
	addOperation(contact, AddContact);
	connect(contact, SIGNAL(destroyed(PsiContact*)), SLOT(removeContact(PsiContact*)));
	connect(contact, SIGNAL(updated()), SLOT(contactUpdated()));
	connect(contact, SIGNAL(groupsChanged()), SLOT(contactGroupsChanged()));
}
void ContactListModelUpdater::commit()
{
	if (!updatesEnabled())
		return;

// qWarning("updater(%x):commit", (int)this);
	// qWarning("*** ContactListModelUpdater::commit(). operationQueue_.count() = %d", operationQueue_.count());
	commitTimerStartTime_ = QDateTime();
	commitTimer_->stop();
	if (operationQueue_.isEmpty())
		return;

	bool doBulkUpdate = operationQueue_.count() > 1;
	if (doBulkUpdate)
		emit beginBulkContactUpdate();

	QHashIterator<PsiContact*, int> it(operationQueue_);
	while (it.hasNext()) {
		it.next();

		int operations = simplifiedOperationList(it.value());
		if (operations & AddContact)
			emit addedContact(it.key());
		if (operations & RemoveContact)
			Q_ASSERT(false);
		if (operations & UpdateContact)
			emit contactUpdated(it.key());
		if (operations & ContactGroupsChanged)
			emit contactGroupsChanged(it.key());
	}

	if (doBulkUpdate)
		emit endBulkContactUpdate();

	operationQueue_.clear();
}
Example #3
0
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()));
}