Skip to content

Commit

Permalink
Merge branch 'jb51531-update-address-book' into 'master'
Browse files Browse the repository at this point in the history
[contacts] Update person's address book when contact data is reset. Fixes JB#51531

See merge request mer-core/nemo-qml-plugin-contacts!45
  • Loading branch information
blam committed Oct 12, 2020
2 parents f471bb3 + 1aba196 commit ed2d0c1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
26 changes: 17 additions & 9 deletions src/seasideperson.cpp
Expand Up @@ -121,31 +121,30 @@ SeasidePerson::SeasidePerson(QObject *parent)
, mAttachState(Unattached)
, mItem(0)
{
setAddressBook(SeasideAddressBook::fromCollectionId(SeasideCache::localCollectionId()));
mContact->setCollectionId(SeasideCache::localCollectionId());
refreshContactDetails();
}

SeasidePerson::SeasidePerson(const QContact &contact, QObject *parent)
: QObject(parent)
, mContact(new QContact(contact))
, mAddressBook(SeasideAddressBook::fromCollectionId(contact.collectionId()))
, mComplete(true)
, mResolving(false)
, mAttachState(Unattached)
, mItem(0)
{
recalculateDisplayLabel();
refreshContactDetails();
}

SeasidePerson::SeasidePerson(QContact *contact, bool complete, QObject *parent)
: QObject(parent)
, mContact(contact)
, mAddressBook(SeasideAddressBook::fromCollectionId(contact->collectionId()))
, mComplete(complete)
, mResolving(false)
, mAttachState(Attached)
, mItem(0)
{
recalculateDisplayLabel();
refreshContactDetails();
}

SeasidePerson::~SeasidePerson()
Expand Down Expand Up @@ -1932,17 +1931,26 @@ void SeasidePerson::setContact(const QContact &contact)
QContact oldContact = *mContact;
*mContact = contact;

recalculateDisplayLabel();
refreshContactDetails();
updateContactDetails(oldContact);
}

void SeasidePerson::refreshContactDetails()
{
recalculateDisplayLabel();
mAddressBook = SeasideAddressBook::fromCollectionId(mContact->collectionId());
}

void SeasidePerson::updateContactDetails(const QContact &oldContact)
{
m_changesReported = false;

if (oldContact.id() != mContact->id())
emitChangeSignal(&SeasidePerson::contactChanged);

if (oldContact.collectionId() != mContact->collectionId())
emitChangeSignal(&SeasidePerson::addressBookChanged);

if (getPrimaryName(oldContact) != primaryName())
emitChangeSignal(&SeasidePerson::primaryNameChanged);

Expand Down Expand Up @@ -2121,7 +2129,7 @@ void SeasidePerson::setContactData(const QVariant &data)
// We don't know if this contact is complete or not - assume it isn't if it has an ID
mComplete = (id() == 0);

recalculateDisplayLabel();
refreshContactDetails();
}

void SeasidePerson::resetContactData()
Expand Down Expand Up @@ -2393,7 +2401,7 @@ void SeasidePerson::addressResolved(const QString &, const QString &, SeasideCac

// Attach to the contact in the cache item
mContact = &item->contact;
recalculateDisplayLabel();
refreshContactDetails();
updateContactDetails(*oldContact);

// Release our previous contact info
Expand Down Expand Up @@ -2442,7 +2450,7 @@ void SeasidePerson::itemAboutToBeRemoved(SeasideCache::CacheItem *item)
mContact->saveDetail(&account);
}

recalculateDisplayLabel();
refreshContactDetails();
updateContactDetails(item->contact);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/seasideperson.h
Expand Up @@ -416,6 +416,7 @@ public slots:
void recalculateDisplayLabel(SeasideCache::DisplayLabelOrder order = SeasideCache::displayLabelOrder()) const;

private:
void refreshContactDetails();
void updateContactDetails(const QContact &oldContact);
void emitChangeSignals();
static QDateTime birthday(const QContact &contact);
Expand Down

0 comments on commit ed2d0c1

Please sign in to comment.