diff --git a/src/phonedirectorymodel.cpp b/src/phonedirectorymodel.cpp index 8acf19ff42b08003057495afe3716735d5b0c287..814c0acaaf396114701a8e0d85ca8b2fc0648f40 100644 --- a/src/phonedirectorymodel.cpp +++ b/src/phonedirectorymodel.cpp @@ -249,28 +249,36 @@ QVariant PhoneDirectoryModel::data(const QModelIndex& index, int role ) const return number->uid(); } break; + case PhoneDirectoryModelPrivate::Columns::REGISTERED_NAME: + switch (role) { + case Qt::DisplayRole: + case Qt::ToolTipRole: + return number->registeredName(); + } + break; } return QVariant(); } int PhoneDirectoryModel::rowCount(const QModelIndex& parent ) const { - if (parent.isValid()) - return 0; - return d_ptr->m_lNumbers.size(); + return parent.isValid() ? 0 : d_ptr->m_lNumbers.size(); } int PhoneDirectoryModel::columnCount(const QModelIndex& parent ) const { - Q_UNUSED(parent) - return 19; + return parent.isValid() ? 0 : 20; } Qt::ItemFlags PhoneDirectoryModel::flags(const QModelIndex& index ) const { - Q_UNUSED(index) - const ContactMethod* number = d_ptr->m_lNumbers[index.row()]; + + // Mark the "old" duplicate as disabled. They are now zombies acting as + // proxies to the real contact methods. + if (number->isDuplicate()) + return Qt::NoItemFlags; + const bool enabled = !((index.column() == static_cast<int>(PhoneDirectoryModelPrivate::Columns::TRACKED) || static_cast<int>(PhoneDirectoryModelPrivate::Columns::PRESENT)) && number->account() && (!number->account()->supportPresenceSubscribe())); @@ -298,7 +306,7 @@ QVariant PhoneDirectoryModel::headerData(int section, Qt::Orientation orientatio Q_UNUSED(orientation) static const QString headers[] = {tr("URI"), tr("Type"), tr("Person"), tr("Account"), tr("State"), tr("Call count"), tr("Week count"), tr("Trimester count"), tr("Have Called"), tr("Last used"), tr("Name_count"),tr("Total (in seconds)"), tr("Popularity_index"), - tr("Bookmarked"), tr("Tracked"), tr("Has certificate"), tr("Present"), tr("Presence message"), tr("Uid") }; + tr("Bookmarked"), tr("Tracked"), tr("Has certificate"), tr("Present"), tr("Presence message"), tr("Uid"), tr("Registered name") }; if (role == Qt::DisplayRole) return headers[section]; return QVariant(); } @@ -314,12 +322,12 @@ void PhoneDirectoryModelPrivate::setAccount(ContactMethod* number, Account* acco number->setAccount(account); if (!hasAtSign) { - NumberWrapper* wrap = m_hDirectory[strippedUri]; + const QString extendedUri = strippedUri+'@'+account->hostname(); + NumberWrapper* wrap = m_hDirectory[extendedUri]; //Let make sure none is created in the future for nothing if (!wrap) { //It won't be a duplicate as none exist for this URI - const QString extendedUri = strippedUri+'@'+account->hostname(); wrap = new NumberWrapper(); m_hDirectory [extendedUri] = wrap; m_hSortedNumbers[extendedUri] = wrap; @@ -456,6 +464,7 @@ ContactMethod* PhoneDirectoryModel::getNumber(const URI& uri, const QString& typ connect(number,SIGNAL(changed()),d_ptr.data(),SLOT(slotChanged())); connect(number,&ContactMethod::lastUsedChanged,d_ptr.data(), &PhoneDirectoryModelPrivate::slotLastUsedChanged); connect(number,&ContactMethod::contactChanged ,d_ptr.data(), &PhoneDirectoryModelPrivate::slotContactChanged); + connect(number,&ContactMethod::rebased ,d_ptr.data(), &PhoneDirectoryModelPrivate::slotContactMethodMerged); // add the new cm into the historic. for (auto col : CategorizedHistoryModel::instance().collections(CollectionInterface::SupportedFeatures::ADD)) { @@ -587,6 +596,7 @@ ContactMethod* PhoneDirectoryModel::getNumber(const QString& uri, Person* contac connect(number,SIGNAL(changed()),d_ptr.data(),SLOT(slotChanged())); connect(number,&ContactMethod::lastUsedChanged,d_ptr.data(), &PhoneDirectoryModelPrivate::slotLastUsedChanged); connect(number,&ContactMethod::contactChanged ,d_ptr.data(), &PhoneDirectoryModelPrivate::slotContactChanged ); + connect(number,&ContactMethod::rebased ,d_ptr.data(), &PhoneDirectoryModelPrivate::slotContactMethodMerged); if (!wrap) { wrap = new NumberWrapper(); d_ptr->m_hDirectory [strippedUri] = wrap; @@ -731,10 +741,21 @@ void PhoneDirectoryModelPrivate::slotChanged() if (idx<0) qDebug() << "Invalid slotChanged() index!" << idx; #endif - emit q_ptr->dataChanged(q_ptr->index(idx,0),q_ptr->index(idx,static_cast<int>(Columns::UID))); + emit q_ptr->dataChanged(q_ptr->index(idx,0),q_ptr->index(idx,static_cast<int>(Columns::REGISTERED_NAME))); } } +/// Remove +void PhoneDirectoryModelPrivate::slotContactMethodMerged(ContactMethod* other) +{ + // Other == cm when the person they depend on got merged. As a CM is an + // "person-lite" this still counts as most code paths care about both. Not + // this, so lets ignore the merged persons. + auto cm = qobject_cast<ContactMethod*>(sender()); + if (other != cm) + emit q_ptr->contactMethodMerged(cm, other); +} + void PhoneDirectoryModelPrivate::slotLastUsedChanged(time_t t) { ContactMethod* cm = qobject_cast<ContactMethod*>(QObject::sender()); diff --git a/src/phonedirectorymodel.h b/src/phonedirectorymodel.h index f31ddef8f324e0f6bff32f3157b99c321aaccc1b..a94f05a6f7d0e29149b1119aaa4fbc3986ebbf57 100644 --- a/src/phonedirectorymodel.h +++ b/src/phonedirectorymodel.h @@ -112,5 +112,6 @@ Q_SIGNALS: void lastUsedChanged(ContactMethod* cm, time_t t); void contactChanged(ContactMethod* cm, Person* newContact, Person* oldContact); void incomingMessage(ContactMethod* cm, const QMap<QString, QString>& payloads); + void contactMethodMerged(ContactMethod* cm, ContactMethod* into); }; Q_DECLARE_METATYPE(PhoneDirectoryModel*) diff --git a/src/private/phonedirectorymodel_p.h b/src/private/phonedirectorymodel_p.h index 8fe4afe82f25b52574b28b4d72da31b55dbedd69..3607b3ca525b962a931c0e0e6b6c7769a5f985c6 100644 --- a/src/private/phonedirectorymodel_p.h +++ b/src/private/phonedirectorymodel_p.h @@ -74,6 +74,7 @@ public: PRESENT = 16, PRESENCE_MESSAGE = 17, UID = 18, + REGISTERED_NAME = 19, }; @@ -104,6 +105,7 @@ private Q_SLOTS: void slotContactChanged(Person* newContact, Person* oldContact); void slotIncomingAccountMessage(const QString& account, const QString& from, const MapStringString& payloads); void slotRegisteredNameFound(const Account* account, NameDirectory::LookupStatus status, const QString& address, const QString& name); + void slotContactMethodMerged(ContactMethod* other); //From DBus void slotNewBuddySubscription(const QString& uri, const QString& accountId, bool status, const QString& message);