From 235bc8f64c920cf957dee5783c00377754bba34a Mon Sep 17 00:00:00 2001 From: Sergei Ilinykh Date: Wed, 12 Jun 2024 22:07:06 +0300 Subject: [PATCH] vcard4: use new vcard4 api + fixed endless recursion/stack overflow --- iris | 2 +- src/avatars.cpp | 8 ++++++-- src/infodlg.cpp | 43 ++++++++++++++++++------------------------- src/vcardfactory.cpp | 6 +++--- 4 files changed, 28 insertions(+), 31 deletions(-) diff --git a/iris b/iris index 7d70c4118..8ddfef163 160000 --- a/iris +++ b/iris @@ -1 +1 @@ -Subproject commit 7d70c41182102ffc8e62aab5370f46a594136853 +Subproject commit 8ddfef163e0835fc8767a057cd4310b0dcd43cfa diff --git a/src/avatars.cpp b/src/avatars.cpp index 7e0812c29..184f44a05 100644 --- a/src/avatars.cpp +++ b/src/avatars.cpp @@ -879,8 +879,12 @@ AvatarFactory::AvatarFactory(PsiAccount *pa) : d(new Private) // Connect signals connect(AvatarCache::instance(), &AvatarCache::avatarChanged, this, &AvatarFactory::avatarChanged); - connect(d->pa_->client(), &XMPP::Client::resourceAvailable, this, - [this](const Jid &jid, const Resource &r) { statusUpdate(jid.withResource(QString()), r.status()); }); + connect(d->pa_->client(), &XMPP::Client::resourceAvailable, this, [this](const Jid &jid, const Resource &r) { + if (jid.compare(d->pa_->jid(), false)) { + return; // to avoid + } + statusUpdate(jid.withResource(QString()), r.status()); + }); // PEP connect(d->pa_->pepManager(), &PEPManager::itemPublished, this, diff --git a/src/infodlg.cpp b/src/infodlg.cpp index 88ebd3413..775a87745 100644 --- a/src/infodlg.cpp +++ b/src/infodlg.cpp @@ -403,11 +403,15 @@ void InfoWidget::setData(const VCard4::VCard &i) m_ui.le_bday->setText(d->bday.toString(d->dateTextFormat)); const QString fullName = i.fullName().value(0).data; - if (d->type != Self && d->type != MucAdm && fullName.isEmpty()) { - m_ui.le_fullname->setText( - QString("%1 %2 %3") - .arg(names.data.given.value(0), names.data.additional.value(0), names.data.surname.value(0)) - .simplified()); + if (d->type != MucAdm && fullName.isEmpty()) { + auto fn = QString("%1 %2 %3") + .arg(names.data.given.value(0), names.data.additional.value(0), names.data.surname.value(0)) + .simplified(); + if (d->type == Self) { + m_ui.le_fullname->setPlaceholderText(fn); + } else { + m_ui.le_fullname->setText(fn); + } } else { m_ui.le_fullname->setText(fullName); } @@ -426,21 +430,10 @@ void InfoWidget::setData(const VCard4::VCard &i) addTypes |= (email.parameters.type.contains(QLatin1String("work")) ? AddressTypeDlg::Work : AddressTypeDlg::None); d->emailsDlg->setTypes(addTypes); - m_ui.le_homepage->setText(i.urls().preferred().data.toString()); + QUrl homepage = i.urls(); + m_ui.le_homepage->setText(homepage.toString()); d->homepageAction->setVisible(!m_ui.le_homepage->text().isEmpty()); - - QString phone; - if (!i.phones().isEmpty()) - phone = std::visit( - [](T const &v) { - if constexpr (std::is_same_v) { - return v; - } else { - return v.toString(); - } - }, - i.phones()[0].data); - m_ui.le_phone->setText(phone); + m_ui.le_phone->setText(i.phones()); auto addr = i.addresses().preferred().data; m_ui.le_street->setText(addr.street.value(0)); @@ -450,11 +443,11 @@ void InfoWidget::setData(const VCard4::VCard &i) m_ui.le_pcode->setText(addr.code.value(0)); m_ui.le_country->setText(addr.country.value(0)); - m_ui.le_orgName->setText(i.org().preferred().data.value(0)); + m_ui.le_orgName->setText(i.org()); - m_ui.le_title->setText(i.title().preferred().data); - m_ui.le_role->setText(i.role().preferred().data); - m_ui.te_desc->setPlainText(i.note().preferred().data); + m_ui.le_title->setText(i.title()); + m_ui.le_role->setText(i.role()); + m_ui.te_desc->setPlainText(i.note()); d->photo = i.photo(); if (!d->photo.isEmpty()) { @@ -781,7 +774,7 @@ VCard4::VCard InfoWidget::makeVCard() // Nickname QString nickName = m_ui.le_nickname->text(); if (!nickName.isEmpty()) { - v.setNickName({ { { PStringList { Parameters(), { nickName } } } } }); + v.setNickName({ nickName }); } // Birthday @@ -825,7 +818,7 @@ VCard4::VCard InfoWidget::makeVCard() if (!homepage.isEmpty()) { QUrl url(homepage); if (url.isValid()) { - v.setUrls({ { PUri { Parameters(), url } } }); + v.setUrls(url); } } diff --git a/src/vcardfactory.cpp b/src/vcardfactory.cpp index 9d637b7a9..c5dca8780 100644 --- a/src/vcardfactory.cpp +++ b/src/vcardfactory.cpp @@ -271,7 +271,7 @@ void VCardFactory::setPhoto(const Jid &j, const QByteArray &photo, Flags flags) vc = vcard(sj); } if (vc && vc.photo() != photo) { - vc.setPhoto({}); + vc.setPhoto(VCard4::UriValue {}); saveVCard(sj, vc, flags); } } @@ -288,7 +288,7 @@ void VCardFactory::deletePhoto(const Jid &j, Flags flags) vc = vcard(sj); } if (vc && !vc.photo().isEmpty()) { - vc.setPhoto({}); + vc.setPhoto(VCard4::UriValue {}); saveVCard(sj, vc, flags); } } @@ -305,7 +305,7 @@ void VCardFactory::ensureVCardPhotoUpdated(PsiAccount *acc, const Jid &jid, Flag if (!vc || vc.photo().isEmpty()) { // we didn't have it and still don't return; } - vc.setPhoto({}); // reset photo; + vc.setPhoto(VCard4::UriValue {}); // reset photo; saveVCard(jid, vc, flags); return;