Skip to content

Commit

Permalink
Use vcard4 internal file reading method
Browse files Browse the repository at this point in the history
  • Loading branch information
Ri0n committed Jun 20, 2024
1 parent 257a7e8 commit 8efb20f
Showing 1 changed file with 5 additions and 14 deletions.
19 changes: 5 additions & 14 deletions src/vcardfactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,20 +156,11 @@ void VCardFactory::saveVCard(const Jid &j, const VCard4::VCard &vcard, Flags fla
if (!v.exists())
p.mkdir("vcard");

QFile file(ApplicationInfo::vCardDir() + '/' + JIDUtil::encode(j.bare()).toLower() + ".xml");
auto filename = ApplicationInfo::vCardDir() + '/' + JIDUtil::encode(j.bare()).toLower() + ".xml";
if (vcard) {
file.open(QIODevice::WriteOnly);
QTextStream out(&file);
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
out.setEncoding(QStringConverter::Utf8);
#else
out.setCodec("UTF-8");
#endif
QDomDocument doc;
doc.appendChild(vcard.toXmlElement(doc));
out << doc.toString(4);
} else if (file.exists()) {
file.remove();
vcard.save(filename);
} else {
QFile::remove(filename);
}

Jid jid = j;
Expand Down Expand Up @@ -211,11 +202,11 @@ VCard4::VCard VCardFactory::vcard(const Jid &j, Flags flags)
// REVIEW we can cache which files were really missed. or maybe set a flag for the contact
return {};
}
QDomDocument doc;

VCard4::VCard v4 = VCard4::VCard::fromDevice(&file);
if (!v4) {
file.seek(0);
QDomDocument doc;
if (doc.setContent(&file, false)) {
VCard vcard = VCard::fromXml(doc.documentElement());
if (!vcard.isNull()) {
Expand Down

0 comments on commit 8efb20f

Please sign in to comment.