diff --git a/CMakeLists.txt b/CMakeLists.txt index 9c4d78d3..268a3841 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,7 +37,7 @@ include(policyRules) set(CMAKE_AUTOMOC ON) set(CMAKE_INCLUDE_CURRENT_DIR ON) -set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD 20) # Detect MXE cross-compilation set(IRIS_DEFAULT_BUNDLED_USRSCTP OFF) @@ -69,8 +69,6 @@ option(IRIS_ENABLE_DEBUG "Enable debugging code paths" OFF) set(IRIS_INSTALL_INCLUDEDIR ${CMAKE_INSTALL_INCLUDEDIR}/xmpp/iris) -set(CMAKE_CXX_STANDARD 17) - if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug" OR ("${CMAKE_BUILD_TYPE}" STREQUAL "RelWithDebInfo")) include(debug-definitions) endif() diff --git a/src/irisnet/corelib/netinterface_qtnet.cpp b/src/irisnet/corelib/netinterface_qtnet.cpp index 2a303ad8..52e7399f 100644 --- a/src/irisnet/corelib/netinterface_qtnet.cpp +++ b/src/irisnet/corelib/netinterface_qtnet.cpp @@ -51,7 +51,7 @@ class InterfaceMonitor : public QObject { notifier = new QSocketNotifier(netlinkFd, QSocketNotifier::Read, this); connect(notifier, &QSocketNotifier::activated, this, - [=](QSocketDescriptor, QSocketNotifier::Type) { emit changed(); }); + [this](QSocketDescriptor, QSocketNotifier::Type) { emit changed(); }); } ~InterfaceMonitor() diff --git a/src/xmpp/xmpp-im/xmpp_vcard4.cpp b/src/xmpp/xmpp-im/xmpp_vcard4.cpp index dbbf3983..efc32308 100644 --- a/src/xmpp/xmpp-im/xmpp_vcard4.cpp +++ b/src/xmpp/xmpp-im/xmpp_vcard4.cpp @@ -80,7 +80,7 @@ namespace { } auto doc = parent.ownerDocument(); auto bday = parent.appendChild(doc.createElement(QLatin1String(tagName))).toElement(); - historical.first.addTo(bday); + historical.parameters.addTo(bday); using Tv = std::decay_t; if constexpr (std::is_same_v) { VCardHelper::addTextElement(doc, bday, QLatin1String("text"), QStringList { v }); @@ -95,7 +95,7 @@ namespace { QStringList { v.toString(Qt::ISODate) }); } }, - historical.second); + historical.data); } template @@ -113,17 +113,17 @@ namespace { } template - static void serializeList(QDomElement &parent, const QList> &list, - const QString &tagName, const QString &innerTagName = QLatin1String("text")) + static void serializeList(QDomElement &parent, const TaggedList &list, const QString &tagName, + const QString &innerTagName = QLatin1String("text")) { auto document = parent.ownerDocument(); for (const auto &entry : list) { QDomElement element = document.createElement(tagName); - entry.first.addTo(element); + entry.parameters.addTo(element); if constexpr (std::is_same_v) { - addTextElement(document, element, QLatin1String("text"), QStringList { entry.second }); + addTextElement(document, element, QLatin1String("text"), QStringList { entry.data }); } else if constexpr (std::is_same_v || std::is_same_v) { - addTextElement(document, element, QLatin1String("uri"), QStringList { entry.second.toString() }); + addTextElement(document, element, QLatin1String("uri"), QStringList { entry.data.toString() }); } else if constexpr (std::is_same_v) { std::visit( [&](auto v) { @@ -134,9 +134,9 @@ namespace { addTextElement(document, element, QLatin1String("text"), QStringList { v }); } }, - entry.second); + entry.data); } else if constexpr (std::is_same_v) { - for (auto const &s : entry.second) { + for (auto const &s : entry.data) { element.appendChild(document.createElement(QLatin1String("text"))) .appendChild(document.createTextNode(s)); } @@ -158,7 +158,7 @@ namespace { addTextElement(document, element, QLatin1String("text"), QStringList { v }); } }, - entry.second); + entry.data); } else { throw std::logic_error("should never happen. some type is not supported"); } @@ -202,8 +202,7 @@ namespace { } template - static void fillContainer(QDomElement parent, const char *tagName, - QList> &container) + static void fillContainer(QDomElement parent, const char *tagName, TaggedList &container) { auto tn = QString::fromLatin1(tagName); for (auto e = parent.firstChildElement(tn); !e.isNull(); e = e.nextSiblingElement(tn)) { @@ -253,28 +252,28 @@ namespace { if (source.isNull()) { return; } - to.first = Parameters(source.firstChildElement(QLatin1String("parameters"))); - auto v = VCardHelper::extractText(source, "date"); + to.parameters = Parameters(source.firstChildElement(QLatin1String("parameters"))); + auto v = VCardHelper::extractText(source, "date"); if (v.isNull()) { v = VCardHelper::extractText(source, "date-time"); if (v.isNull()) { v = VCardHelper::extractText(source, "time"); if (v.isNull()) { - to.second = VCardHelper::extractText(source, "text"); + to.data = VCardHelper::extractText(source, "text"); } else { - to.second = QTime::fromString(v, Qt::ISODate); + to.data = QTime::fromString(v, Qt::ISODate); } } else { - to.second = QDateTime::fromString(v, Qt::ISODate); + to.data = QDateTime::fromString(v, Qt::ISODate); } } else { - to.second = QDate::fromString(v, Qt::ISODate); + to.data = QDate::fromString(v, Qt::ISODate); } } static bool isNull(const PHistorical &h) { - return std::visit([](auto const &v) { return v.isNull(); }, h.second); + return std::visit([](auto const &v) { return v.isNull(); }, h.data); } }; @@ -480,7 +479,7 @@ class VCard::VCardData : public QSharedData { QString genderComment; // Delivery Addressing Properties - QList> addresses; // any number of addresses + PAddresses addresses; // any number of addresses // Communications Properties PUrisOrTexts tels; // any number of telephones @@ -605,7 +604,7 @@ class VCard::VCardData : public QSharedData { bool isEmpty() const { - return fullName.isEmpty() && names.second.isEmpty() && nickname.isEmpty() && emails.isEmpty() && tels.isEmpty() + return fullName.isEmpty() && names.data.isEmpty() && nickname.isEmpty() && emails.isEmpty() && tels.isEmpty() && org.isEmpty() && title.isEmpty() && role.isEmpty() && note.isEmpty() && urls.isEmpty() && VCardHelper::isNull(bday) && VCardHelper::isNull(anniversary) && gender == VCard4::Gender::Undefined && uid.isEmpty() && kind.isEmpty() && categories.isEmpty() && busyTimeUrl.isEmpty() @@ -640,9 +639,9 @@ QDomElement VCard::toXmlElement(QDomDocument &document) const QDomElement vCardElement = document.createElement(QLatin1String("vcard")); VCardHelper::serializeList(vCardElement, d->fullName, QLatin1String("fn")); - if (!d->names.second.isEmpty()) { - auto e = vCardElement.appendChild(d->names.second.toXmlElement(document)).toElement(); - d->names.first.addTo(e); + if (!d->names.data.isEmpty()) { + auto e = vCardElement.appendChild(d->names.data.toXmlElement(document)).toElement(); + d->names.parameters.addTo(e); } VCardHelper::serializeList(vCardElement, d->nickname, QLatin1String("nickname"), QLatin1String("text")); VCardHelper::serializeList(vCardElement, d->emails, QLatin1String("email"), QLatin1String("text")); @@ -694,8 +693,8 @@ QDomElement VCard::toXmlElement(QDomDocument &document) const for (const auto &address : d->addresses) { QDomElement adrElement = document.createElement(QLatin1String("adr")); - address.first.addTo(adrElement); - adrElement.appendChild(address.second.toXmlElement(document)); + address.parameters.addTo(adrElement); + adrElement.appendChild(address.data.toXmlElement(document)); vCardElement.appendChild(adrElement); } @@ -791,9 +790,9 @@ void VCard::setEmails(const PStrings &emails) d->emails = emails; } -PUrisOrTexts VCard::tels() const { return d ? d->tels : PUrisOrTexts(); } +PUrisOrTexts VCard::phones() const { return d ? d->tels : PUrisOrTexts(); } -void VCard::setTels(const PUrisOrTexts &tels) +void VCard::setPhones(const PUrisOrTexts &tels) { INIT_D(); d->tels = tels; @@ -951,9 +950,9 @@ void VCard::setKey(const PUrisOrTexts &key) d->key = key; } -PStrings VCard::lang() const { return d ? d->lang : PStrings(); } +PStrings VCard::languages() const { return d ? d->lang : PStrings(); } -void VCard::setLang(const PStrings &lang) +void VCard::setLanguages(const PStrings &lang) { INIT_D(); d->lang = lang; @@ -1031,12 +1030,9 @@ void VCard::setTimeZone(const PTimeZones &timeZone) d->timeZone = timeZone; } -QList> VCard::addresses() const -{ - return d ? d->addresses : QList>(); -} +PAddresses VCard::addresses() const { return d ? d->addresses : PAddresses(); } -void VCard::setAddresses(const QList> &addresses) +void VCard::setAddresses(const PAddresses &addresses) { INIT_D(); d->addresses = addresses; diff --git a/src/xmpp/xmpp-im/xmpp_vcard4.h b/src/xmpp/xmpp-im/xmpp_vcard4.h index fb13d86a..6c578a86 100644 --- a/src/xmpp/xmpp-im/xmpp_vcard4.h +++ b/src/xmpp/xmpp-im/xmpp_vcard4.h @@ -30,6 +30,7 @@ #include #include +#include #include /** @@ -100,28 +101,49 @@ class UriValue { QString mediaType; }; +template struct Item { + Parameters parameters; + T data; + + operator QString() const { return data; } +}; + +template class TaggedList : public QList { +public: + using item_type = T; + + T preferred() const + { + if (this->empty()) { + return {}; + } + return *std::ranges::max_element( + *this, [](auto const &a, auto const &b) { return a.parameters.pref > b.parameters.pref; }); + } +}; + using UriOrText = std::variant; using TimeZone = std::variant; using Historical = std::variant; -using PStringList = std::pair; -using PString = std::pair; -using PUri = std::pair; -using PDate = std::pair; -using PAdvUri = std::pair; -using PAddress = std::pair; -using PNames = std::pair; -using PUriOrText = std::pair; -using PTimeZone = std::pair; -using PHistorical = std::pair; - -using PStringLists = QList; -using PStrings = QList; -using PUris = QList; -using PAdvUris = QList; -using PAddresses = QList; -using PUrisOrTexts = QList; -using PTimeZones = QList; +using PStringList = Item; +using PString = Item; +using PUri = Item; +using PDate = Item; +using PAdvUri = Item; +using PAddress = Item
; +using PNames = Item; +using PUriOrText = Item; +using PTimeZone = Item; +using PHistorical = Item; + +using PStringLists = TaggedList; +using PStrings = TaggedList; +using PUris = TaggedList; +using PAdvUris = TaggedList; +using PAddresses = TaggedList; +using PUrisOrTexts = TaggedList; +using PTimeZones = TaggedList; class VCard { public: @@ -150,8 +172,8 @@ class VCard { PStrings emails() const; void setEmails(const PStrings &emails); - PUrisOrTexts tels() const; - void setTels(const PUrisOrTexts &tels); + PUrisOrTexts phones() const; + void setPhones(const PUrisOrTexts &tels); PStringLists org() const; void setOrg(const PStringLists &org); @@ -210,8 +232,8 @@ class VCard { PUrisOrTexts key() const; void setKey(const PUrisOrTexts &key); - PStrings lang() const; - void setLang(const PStrings &lang); + PStrings languages() const; + void setLanguages(const PStrings &lang); PAdvUris logo() const; void setLogo(const PAdvUris &logo);