Skip to content

Commit

Permalink
vcard4: use new vcard4 api + fixed endless recursion/stack overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Ri0n committed Jun 12, 2024
1 parent f76f9e8 commit 235bc8f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 31 deletions.
2 changes: 1 addition & 1 deletion iris
8 changes: 6 additions & 2 deletions src/avatars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
43 changes: 18 additions & 25 deletions src/infodlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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(
[]<typename T>(T const &v) {
if constexpr (std::is_same_v<T, QString>) {
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));
Expand All @@ -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()) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/vcardfactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand All @@ -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);
}
}
Expand All @@ -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;
Expand Down

0 comments on commit 235bc8f

Please sign in to comment.