diff --git a/CMakeLists.txt b/CMakeLists.txt index 7da1940c..c0c12a81 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,85 +1,85 @@ cmake_minimum_required(VERSION 3.5) -set(PIM_VERSION "5.11.41") +set(PIM_VERSION "5.11.42") project(KContacts VERSION ${PIM_VERSION}) # ECM setup set(QT_REQUIRED_VERSION "5.10.0") set(KF5_MIN_VERSION "5.57.0") find_package(ECM ${KF5_MIN_VERSION} CONFIG REQUIRED) set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${KContacts_SOURCE_DIR}/cmake) set(CMAKE_AUTORCC ON) include(GenerateExportHeader) include(ECMGenerateHeaders) include(ECMGeneratePriFile) include(ECMSetupVersion) include(FeatureSummary) include(KDEInstallDirs) include(KDECMakeSettings) include(KDEFrameworkCompilerSettings NO_POLICY_SCOPE) include(ECMQtDeclareLoggingCategory) set(KCONTACTS_LIB_VERSION ${PIM_VERSION}) ecm_setup_version(PROJECT VARIABLE_PREFIX KContacts VERSION_HEADER "${CMAKE_CURRENT_BINARY_DIR}/kcontacts_version.h" PACKAGE_VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/KF5ContactsConfigVersion.cmake" SOVERSION 5 ) ########### Find packages ########### find_package(Qt5 ${QT_REQUIRED_VERSION} REQUIRED COMPONENTS Gui) find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS CoreAddons I18n Config Codecs) find_package(IsoCodes MODULE) set_package_properties("IsoCodes" PROPERTIES PURPOSE "Needed for country name translations." TYPE RUNTIME) ########### Targets ########### add_definitions(-DTRANSLATION_DOMAIN=\"kcontacts5\") # workaround for https://bugreports.qt.io/browse/QTBUG-74665 (bug in qt5.13 reevaluate it) if (${Qt5Gui_VERSION} STREQUAL "5.13.0") MESSAGE(STATUS "Qt version: ${Qt5Gui_VERSION} DISABLE compile without deprecated methods. bug QTBUG-74665") else() add_definitions(-DQT_DISABLE_DEPRECATED_BEFORE=0x060000) endif() add_definitions(-DQT_NO_FOREACH) add_subdirectory(src) if(BUILD_TESTING) add_subdirectory(autotests) add_subdirectory(tests) endif() ########### CMake Config Files ########### set(CMAKECONFIG_INSTALL_DIR "${KDE_INSTALL_CMAKEPACKAGEDIR}/KF5Contacts") configure_package_config_file( "${CMAKE_CURRENT_SOURCE_DIR}/KF5ContactsConfig.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/KF5ContactsConfig.cmake" INSTALL_DESTINATION ${CMAKECONFIG_INSTALL_DIR} ) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/KF5ContactsConfig.cmake" "${CMAKE_CURRENT_BINARY_DIR}/KF5ContactsConfigVersion.cmake" DESTINATION "${CMAKECONFIG_INSTALL_DIR}" COMPONENT Devel ) install(EXPORT KF5ContactsTargets DESTINATION "${CMAKECONFIG_INSTALL_DIR}" FILE KF5ContactsTargets.cmake NAMESPACE KF5::) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/kcontacts_version.h DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5} COMPONENT Devel ) install( FILES kcontacts.renamecategories kcontacts.categories DESTINATION ${KDE_INSTALL_CONFDIR} ) feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES) diff --git a/src/address.cpp b/src/address.cpp index d42e7208..2cbd54cf 100644 --- a/src/address.cpp +++ b/src/address.cpp @@ -1,723 +1,722 @@ /* This file is part of the KContacts framework. Copyright (c) 2001 Cornelius Schumacher This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "address.h" -#include "geo.h" #include "countrytoisomap_data.cpp" #include "isotocountrymap_data.cpp" #include "kcontacts_debug.h" #include #include #include #include #include #include #include #include #include #include #include using namespace KContacts; // template tags for address formatting localization #define KCONTACTS_FMTTAG_realname QStringLiteral("%n") #define KCONTACTS_FMTTAG_REALNAME QStringLiteral("%N") #define KCONTACTS_FMTTAG_company QStringLiteral("%cm") #define KCONTACTS_FMTTAG_COMPANY QStringLiteral("%CM") #define KCONTACTS_FMTTAG_pobox QStringLiteral("%p") #define KCONTACTS_FMTTAG_street QStringLiteral("%s") #define KCONTACTS_FMTTAG_STREET QStringLiteral("%S") #define KCONTACTS_FMTTAG_zipcode QStringLiteral("%z") #define KCONTACTS_FMTTAG_location QStringLiteral("%l") #define KCONTACTS_FMTTAG_LOCATION QStringLiteral("%L") #define KCONTACTS_FMTTAG_region QStringLiteral("%r") #define KCONTACTS_FMTTAG_REGION QStringLiteral("%R") #define KCONTACTS_FMTTAG_newline QStringLiteral("\\n") #define KCONTACTS_FMTTAG_condcomma QStringLiteral("%,") #define KCONTACTS_FMTTAG_condwhite QStringLiteral("%w") #define KCONTACTS_FMTTAG_purgeempty QStringLiteral("%0") /** Finds the balanced closing bracket starting from the opening bracket at pos in tsection. @return position of closing bracket, -1 for unbalanced brackets */ static int findBalancedBracket(const QString &tsection, int pos) { int balancecounter = 0; for (int i = pos + 1; i < tsection.length(); ++i) { if (QLatin1Char(')') == tsection[i] && 0 == balancecounter) { // found end of brackets return i; } else { if (QLatin1Char('(') == tsection[i]) { // nested brackets balancecounter++; } } } return -1; } /** Parses a snippet of an address template @param tsection the template string to be parsed @param result QString reference in which the result will be stored @return true if at least one tag evaluated positively, else false */ static bool parseAddressTemplateSection(const QString &tsection, QString &result, const QString &realName, const QString &orgaName, const KContacts::Address &address) { // This method first parses and substitutes any bracketed sections and // after that replaces any tags with their values. If a bracketed section // or a tag evaluate to zero, they are not just removed but replaced // with a placeholder. This is because in the last step conditionals are // resolved which depend on information about zero-evaluations. result = tsection; int stpos = 0; bool ret = false; // first check for brackets that have to be evaluated first int fpos = result.indexOf(KCONTACTS_FMTTAG_purgeempty, stpos); while (-1 != fpos) { int bpos1 = fpos + KCONTACTS_FMTTAG_purgeempty.length(); // expect opening bracket and find next balanced closing bracket. If // next char is no opening bracket, continue parsing (no valid tag) if (QLatin1Char('(') == result[bpos1]) { int bpos2 = findBalancedBracket(result, bpos1); if (-1 != bpos2) { // we have balanced brackets, recursively parse: QString rplstr; bool purge = !parseAddressTemplateSection(result.mid(bpos1 + 1, bpos2 - bpos1 - 1), rplstr, realName, orgaName, address); if (purge) { // purge -> remove all // replace with !_P_!, so conditional tags work later result.replace(fpos, bpos2 - fpos + 1, QStringLiteral("!_P_!")); // leave stpos as it is } else { // no purge -> replace with recursively parsed string result.replace(fpos, bpos2 - fpos + 1, rplstr); ret = true; stpos = fpos + rplstr.length(); } } else { // unbalanced brackets: keep on parsing (should not happen // and will result in bad formatting) stpos = bpos1; } } fpos = result.indexOf(KCONTACTS_FMTTAG_purgeempty, stpos); } // after sorting out all purge tags, we just search'n'replace the rest, // keeping track of whether at least one tag evaluates to something. // The following macro needs QString for R_FIELD // It substitutes !_P_! for empty fields so conditional tags work later #define REPLTAG(R_TAG, R_FIELD) \ if (result.contains(R_TAG)) { \ QString rpl = R_FIELD.isEmpty() ? QStringLiteral("!_P_!") : R_FIELD; \ result.replace(R_TAG, rpl); \ if (!R_FIELD.isEmpty()) { \ ret = true; \ } \ } REPLTAG(KCONTACTS_FMTTAG_realname, realName); REPLTAG(KCONTACTS_FMTTAG_REALNAME, realName.toUpper()); REPLTAG(KCONTACTS_FMTTAG_company, orgaName); REPLTAG(KCONTACTS_FMTTAG_COMPANY, orgaName.toUpper()); REPLTAG(KCONTACTS_FMTTAG_pobox, address.postOfficeBox()); REPLTAG(KCONTACTS_FMTTAG_street, address.street()); REPLTAG(KCONTACTS_FMTTAG_STREET, address.street().toUpper()); REPLTAG(KCONTACTS_FMTTAG_zipcode, address.postalCode()); REPLTAG(KCONTACTS_FMTTAG_location, address.locality()); REPLTAG(KCONTACTS_FMTTAG_LOCATION, address.locality().toUpper()); REPLTAG(KCONTACTS_FMTTAG_region, address.region()); REPLTAG(KCONTACTS_FMTTAG_REGION, address.region().toUpper()); result.replace(KCONTACTS_FMTTAG_newline, QLatin1String("\n")); #undef REPLTAG // conditional comma fpos = result.indexOf(KCONTACTS_FMTTAG_condcomma, 0); while (-1 != fpos) { const QString str1 = result.mid(fpos - 5, 5); const QString str2 = result.mid(fpos + 2, 5); if (str1 != QLatin1String("!_P_!") && str2 != QLatin1String("!_P_!")) { result.replace(fpos, 2, QStringLiteral(", ")); } else { result.remove(fpos, 2); } fpos = result.indexOf(KCONTACTS_FMTTAG_condcomma, fpos); } // conditional whitespace fpos = result.indexOf(KCONTACTS_FMTTAG_condwhite, 0); while (-1 != fpos) { const QString str1 = result.mid(fpos - 5, 5); const QString str2 = result.mid(fpos + 2, 5); if (str1 != QLatin1String("!_P_!") && str2 != QLatin1String("!_P_!")) { result.replace(fpos, 2, QLatin1Char(' ')); } else { result.remove(fpos, 2); } fpos = result.indexOf(KCONTACTS_FMTTAG_condwhite, fpos); } // remove purged: result.remove(QStringLiteral("!_P_!")); return ret; } class Q_DECL_HIDDEN Address::Private : public QSharedData { public: Private() : mEmpty(true) , mType(nullptr) { mId = KRandom::randomString(10); } Private(const Private &other) : QSharedData(other) { mEmpty = other.mEmpty; mId = other.mId; mType = other.mType; mPostOfficeBox = other.mPostOfficeBox; mExtended = other.mExtended; mStreet = other.mStreet; mLocality = other.mLocality; mRegion = other.mRegion; mPostalCode = other.mPostalCode; mCountry = other.mCountry; mLabel = other.mLabel; } bool mEmpty; QString mId; Type mType; Geo mGeo; QString mPostOfficeBox; QString mExtended; QString mStreet; QString mLocality; QString mRegion; QString mPostalCode; QString mCountry; QString mLabel; }; Address::Address() : d(new Private) { } Address::Address(Type type) : d(new Private) { d->mType = type; } Address::Address(const Address &other) : d(other.d) { } Address::~Address() { } Address &Address::operator=(const Address &other) { if (this != &other) { d = other.d; } return *this; } bool Address::operator==(const Address &other) const { if (d->mId != other.d->mId) { return false; } if (d->mType != other.d->mType) { return false; } if (d->mPostOfficeBox != other.d->mPostOfficeBox) { return false; } if (d->mExtended != other.d->mExtended) { return false; } if (d->mStreet != other.d->mStreet) { return false; } if (d->mLocality != other.d->mLocality) { return false; } if (d->mRegion != other.d->mRegion) { return false; } if (d->mPostalCode != other.d->mPostalCode) { return false; } if (d->mCountry != other.d->mCountry) { return false; } if (d->mLabel != other.d->mLabel) { return false; } if (d->mGeo != other.d->mGeo) { return false; } return true; } bool Address::operator!=(const Address &a) const { return !(a == *this); } bool Address::isEmpty() const { return d->mEmpty; } void Address::clear() { *this = Address(); } void Address::setId(const QString &id) { d->mEmpty = false; d->mId = id; } QString Address::id() const { return d->mId; } void Address::setType(Type type) { d->mEmpty = false; d->mType = type; } Address::Type Address::type() const { return d->mType; } QString Address::typeLabel(Type type) { QString label; bool first = true; const TypeList list = typeList(); TypeList::ConstIterator it; TypeList::ConstIterator end(list.end()); for (it = list.begin(); it != end; ++it) { // these are actually flags const TypeFlag flag = static_cast(static_cast(*it)); if (type & flag) { if (!first) { label.append(QLatin1Char('/')); } label.append(typeFlagLabel(flag)); if (first) { first = false; } } } return label; } QString Address::typeLabel() const { QString label; bool first = true; const TypeList list = typeList(); TypeList::ConstIterator it; for (it = list.begin(); it != list.end(); ++it) { if ((type() & (*it)) && ((*it) != Pref)) { if (!first) { label.append(QLatin1Char('/')); } label.append(typeLabel(*it)); if (first) { first = false; } } } return label; } void Address::setPostOfficeBox(const QString &postOfficeBox) { d->mEmpty = false; d->mPostOfficeBox = postOfficeBox; } QString Address::postOfficeBox() const { return d->mPostOfficeBox; } QString Address::postOfficeBoxLabel() { return i18n("Post Office Box"); } void Address::setExtended(const QString &extended) { d->mEmpty = false; d->mExtended = extended; } QString Address::extended() const { return d->mExtended; } QString Address::extendedLabel() { return i18n("Extended Address Information"); } void Address::setStreet(const QString &street) { d->mEmpty = false; d->mStreet = street; } QString Address::street() const { return d->mStreet; } QString Address::streetLabel() { return i18n("Street"); } void Address::setLocality(const QString &locality) { d->mEmpty = false; d->mLocality = locality; } QString Address::locality() const { return d->mLocality; } QString Address::localityLabel() { return i18n("Locality"); } void Address::setRegion(const QString ®ion) { d->mEmpty = false; d->mRegion = region; } QString Address::region() const { return d->mRegion; } QString Address::regionLabel() { return i18n("Region"); } void Address::setPostalCode(const QString &postalCode) { d->mEmpty = false; d->mPostalCode = postalCode; } QString Address::postalCode() const { return d->mPostalCode; } QString Address::postalCodeLabel() { return i18n("Postal Code"); } void Address::setCountry(const QString &country) { d->mEmpty = false; d->mCountry = country; } QString Address::country() const { return d->mCountry; } QString Address::countryLabel() { return i18n("Country"); } void Address::setLabel(const QString &label) { d->mEmpty = false; d->mLabel = label; } QString Address::label() const { return d->mLabel; } QString Address::labelLabel() { return i18n("Delivery Label"); } Address::TypeList Address::typeList() { static TypeList list; if (list.isEmpty()) { list << Dom << Intl << Postal << Parcel << Home << Work << Pref; } return list; } QString Address::typeFlagLabel(TypeFlag type) { switch (type) { case Dom: return i18nc("Address is in home country", "Domestic"); case Intl: return i18nc("Address is not in home country", "International"); case Postal: return i18nc("Address for delivering letters", "Postal"); case Parcel: return i18nc("Address for delivering packages", "Parcel"); case Home: return i18nc("Home Address", "Home"); case Work: return i18nc("Work Address", "Work"); case Pref: return i18n("Preferred Address"); } return i18nc("another type of address", "Other"); } void Address::setGeo(const Geo &geo) { d->mEmpty = false; d->mGeo = geo; } Geo Address::geo() const { return d->mGeo; } QString Address::toString() const { QString str = QLatin1String("Address {\n"); str += QStringLiteral(" IsEmpty: %1\n"). arg(d->mEmpty ? QStringLiteral("true") : QStringLiteral("false")); str += QStringLiteral(" Id: %1\n").arg(d->mId); str += QStringLiteral(" Type: %1\n").arg(typeLabel(d->mType)); str += QStringLiteral(" Post office box: %1\n").arg(d->mPostOfficeBox); str += QStringLiteral(" Extended: %1\n").arg(d->mExtended); str += QStringLiteral(" Street: %1\n").arg(d->mStreet); str += QStringLiteral(" Locality: %1\n").arg(d->mLocality); str += QStringLiteral(" Region: %1\n").arg(d->mRegion); str += QStringLiteral(" Postal code: %1\n").arg(d->mPostalCode); str += QStringLiteral(" Country: %1\n").arg(d->mCountry); str += QStringLiteral(" Label: %1\n").arg(d->mLabel); str += QStringLiteral(" Geo: %1\n").arg(d->mGeo.toString()); str += QLatin1String("}\n"); return str; } static QString countryCodeFromLocale() { const auto n = QLocale().name(); // this is in the form _, with the exception of 'C' const auto idx = n.indexOf(QLatin1Char('_')); if (idx > 0) { return n.mid(idx + 1).toLower(); } return {}; } static QString addressFormatRc() { Q_INIT_RESOURCE(kcontacts); // must be called outside of a namespace return QStringLiteral(":/org.kde.kcontacts/addressformatrc"); } QString Address::formattedAddress(const QString &realName, const QString &orgaName) const { QString ciso; QString addrTemplate; QString ret; // FIXME: first check for iso-country-field and prefer that one if (!country().isEmpty()) { ciso = countryToISO(country()); } else { // fall back to our own country ciso = countryCodeFromLocale(); } static const KConfig entry(addressFormatRc()); KConfigGroup group = entry.group(ciso); // decide whether this needs special business address formatting if (orgaName.isEmpty()) { addrTemplate = group.readEntry("AddressFormat"); } else { addrTemplate = group.readEntry("BusinessAddressFormat"); if (addrTemplate.isEmpty()) { addrTemplate = group.readEntry("AddressFormat"); } } // in the case there's no format found at all, default to what we've always // used: if (addrTemplate.isEmpty()) { qCWarning(KCONTACTS_LOG) << "address format database incomplete" << "(no format for locale" << ciso << "found). Using default address formatting."; addrTemplate = QStringLiteral("%0(%n\\n)%0(%cm\\n)%0(%s\\n)%0(PO BOX %p\\n)%0(%l%w%r)%,%z"); } // scan parseAddressTemplateSection(addrTemplate, ret, realName, orgaName, *this); // now add the country line if needed (formatting this time according to // the rules of our own system country ) if (!country().isEmpty()) { // Don't include line breaks if country is the only text if (ret.isEmpty()) { return country().toUpper(); } KConfigGroup group = entry.group(countryCodeFromLocale()); QString cpos = group.readEntry("AddressCountryPosition"); if (QLatin1String("BELOW") == cpos || cpos.isEmpty()) { ret = ret + QLatin1String("\n\n") + country().toUpper(); } else if (QLatin1String("below") == cpos) { ret = ret + QLatin1String("\n\n") + country(); } else if (QLatin1String("ABOVE") == cpos) { ret = country().toUpper() + QLatin1String("\n\n") + ret; } else if (QLatin1String("above") == cpos) { ret = country() + QLatin1String("\n\n") + ret; } } return ret; } QString Address::countryToISO(const QString &cname) { const auto lookupKey = normalizeCountryName(cname); // look for an exact match auto it = std::lower_bound(std::begin(country_to_iso_index), std::end(country_to_iso_index), lookupKey, [](const CountryToIsoIndex &lhs, const QByteArray &rhs) { return strcmp(country_name_stringtable + lhs.m_offset, rhs.constData()) < 0; }); if (it != std::end(country_to_iso_index) && strcmp(country_name_stringtable + (*it).m_offset, lookupKey.constData()) == 0) { return (*it).isoCode(); } // a unique prefix will do too it = std::lower_bound(std::begin(country_to_iso_index), std::end(country_to_iso_index), lookupKey, [](const CountryToIsoIndex &lhs, const QByteArray &rhs) { return strncmp(country_name_stringtable + lhs.m_offset, rhs.constData(), strlen(country_name_stringtable + lhs.m_offset)) < 0; }); const auto endIt = std::upper_bound(std::begin(country_to_iso_index), std::end(country_to_iso_index), lookupKey, [](const QByteArray &lhs, const CountryToIsoIndex &rhs) { return strncmp(lhs.constData(), country_name_stringtable + rhs.m_offset, strlen(country_name_stringtable + rhs.m_offset)) < 0; }); if (it != std::end(country_to_iso_index) && endIt == (it + 1) && strncmp(country_name_stringtable + (*it).m_offset, lookupKey.constData(), strlen(country_name_stringtable + (*it).m_offset)) == 0) { return (*it).isoCode(); } return {}; } QString Address::ISOtoCountry(const QString &ISOname) { // get country name from ISO country code (e.g. "no" -> i18n("Norway")) const auto iso = ISOname.simplified().toLower().toUtf8(); if (iso.size() != 2) { return ISOname; } const auto it = std::lower_bound(std::begin(iso_to_country_index), std::end(iso_to_country_index), iso.constData(), [](const IsoToCountryIndex &lhs, const char *rhs) { return strncmp(&lhs.m_c1, rhs, 2) < 0; }); if (it != std::end(iso_to_country_index) && strncmp(&(*it).m_c1, iso.constData(), 2) == 0) { return i18nd("iso_3166-1", en_country_name_stringtable + (*it).m_offset); } return ISOname; } QDataStream &KContacts::operator<<(QDataStream &s, const Address &addr) { return s << addr.d->mId << (uint)addr.d->mType << addr.d->mPostOfficeBox << addr.d->mExtended << addr.d->mStreet << addr.d->mLocality << addr.d->mRegion << addr.d->mPostalCode << addr.d->mCountry << addr.d->mLabel << addr.d->mEmpty << addr.d->mGeo; } QDataStream &KContacts::operator>>(QDataStream &s, Address &addr) { uint type; s >> addr.d->mId >> type >> addr.d->mPostOfficeBox >> addr.d->mExtended >> addr.d->mStreet >> addr.d->mLocality >> addr.d->mRegion >> addr.d->mPostalCode >> addr.d->mCountry >> addr.d->mLabel >> addr.d->mEmpty >> addr.d->mGeo; addr.d->mType = Address::Type(type); return s; } diff --git a/src/address.h b/src/address.h index 4778e1ab..a450844e 100644 --- a/src/address.h +++ b/src/address.h @@ -1,351 +1,371 @@ /* This file is part of the KContacts framework. Copyright (c) 2001 Cornelius Schumacher This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KCONTACTS_ADDRESS_H #define KCONTACTS_ADDRESS_H +#include "kcontacts_export.h" +#include "geo.h" + +#include #include #include #include -#include "kcontacts_export.h" - namespace KContacts { class Geo; /** @brief Postal address information. This class represents information about a postal address. */ class KCONTACTS_EXPORT Address { friend KCONTACTS_EXPORT QDataStream &operator<<(QDataStream &s, const Address &addr); friend KCONTACTS_EXPORT QDataStream &operator>>(QDataStream &s, Address &addr); + Q_GADGET + Q_PROPERTY(QString id READ id WRITE setId) + Q_PROPERTY(bool isEmpty READ isEmpty) + Q_PROPERTY(Type type READ type WRITE setType) + Q_PROPERTY(QString typeLabel READ typeLabel) + Q_PROPERTY(QString postOfficeBox READ postOfficeBox WRITE setPostOfficeBox) + Q_PROPERTY(QString extended READ extended WRITE setExtended) + Q_PROPERTY(QString street READ street WRITE setStreet) + Q_PROPERTY(QString locality READ locality WRITE setLocality) + Q_PROPERTY(QString region READ region WRITE setRegion) + Q_PROPERTY(QString postalCode READ postalCode WRITE setPostalCode) + Q_PROPERTY(QString country READ country WRITE setCountry) + Q_PROPERTY(QString label READ label WRITE setLabel) + Q_PROPERTY(KContacts::Geo geo READ geo WRITE setGeo) + public: /** List of addresses. */ typedef QVector
List; /** Address types: */ enum TypeFlag { Dom = 1, /**< domestic */ Intl = 2, /**< international */ Postal = 4, /**< postal */ Parcel = 8, /**< parcel */ Home = 16, /**< home address */ Work = 32, /**< address at work */ Pref = 64 /**< preferred address */ }; Q_DECLARE_FLAGS(Type, TypeFlag) + Q_FLAG(Type) /** List of address types. */ typedef QList TypeList; /** Creates an empty address. */ Address(); /** Creates an address of the given @p type. */ Address(Type type); /** Copy constructor. */ Address(const Address &address); /** Destroys the address. */ ~Address(); /** Equality operator. @param addr the address to compare to @return @c true if @c this and @p addr are equal, otherwise @c false */ Q_REQUIRED_RESULT bool operator==(const Address &other) const; /** Not-equal operator. @param addr the address to compare to @return @c true if @c this and @p addr are not equal, otherwise @c false */ Q_REQUIRED_RESULT bool operator!=(const Address &other) const; /** Assignment operator. @param addr the address data to assign to @c this @return a reference to @c this */ Address &operator=(const Address &other); /** Returns true, if the address is empty. */ Q_REQUIRED_RESULT bool isEmpty() const; /** Clears all entries of the address. */ void clear(); /** Sets the unique @p identifier. */ void setId(const QString &identifier); /** Returns the unique identifier. */ Q_REQUIRED_RESULT QString id() const; /** Sets the type of address. See enum for definiton of types. @param type type, can be a bitwise or of multiple types. */ void setType(Type type); /** Returns the type of address. Can be a bitwise or of multiple types. */ Q_REQUIRED_RESULT Type type() const; /** Returns a translated string of all types the address has. */ Q_REQUIRED_RESULT QString typeLabel() const; /** Sets the post office box. */ void setPostOfficeBox(const QString &postOfficeBox); /** Returns the post office box. */ Q_REQUIRED_RESULT QString postOfficeBox() const; /** Returns the translated label for post office box field. */ static QString postOfficeBoxLabel(); /** Sets the @p extended address information. */ void setExtended(const QString &extended); /** Returns the extended address information. */ Q_REQUIRED_RESULT QString extended() const; /** Returns the translated label for extended field. */ static QString extendedLabel(); /** Sets the @p street (including house number). */ void setStreet(const QString &street); /** Returns the street. */ Q_REQUIRED_RESULT QString street() const; /** Returns the translated label for street field. */ static QString streetLabel(); /** Sets the @p locality, e.g. city. @param locality the locality of the address, e.g. city */ void setLocality(const QString &locality); /** Returns the locality. */ Q_REQUIRED_RESULT QString locality() const; /** Returns the translated label for locality field. */ static QString localityLabel(); /** Sets the @p region, e.g. state. @param region the region the address falls into, e.g. state */ void setRegion(const QString ®ion); /** Returns the region. */ Q_REQUIRED_RESULT QString region() const; /** Returns the translated label for region field. */ static QString regionLabel(); /** Sets the postal @p code. */ void setPostalCode(const QString &code); /** Returns the postal code. */ Q_REQUIRED_RESULT QString postalCode() const; /** Returns the translated label for postal code field. */ static QString postalCodeLabel(); /** Sets the @p country. */ void setCountry(const QString &country); /** Returns the country. */ Q_REQUIRED_RESULT QString country() const; /** Returns the translated label for country field. */ static QString countryLabel(); /** Sets the delivery @p label. This is the literal text to be used as label. @param label the string to use for delivery labels */ void setLabel(const QString &label); /** Returns the delivery label. */ Q_REQUIRED_RESULT QString label() const; /** Returns the translated label for delivery label field. */ static QString labelLabel(); /** Returns the list of available types. */ static TypeList typeList(); /** Returns the translated label for the given @p type. */ static QString typeLabel(Type type); /** Returns a string representation of the address. */ Q_REQUIRED_RESULT QString toString() const; /** Returns this address formatted according to the country-specific address formatting rules. The formatting rules applied depend on either the addresses {@link #country country} field, or (if the latter is empty) on the system country setting. If companyName is provided, an available business address format will be preferred. @param realName the formatted name of the contact @param orgaName the name of the organization or company @return the formatted address (containing newline characters) */ Q_REQUIRED_RESULT QString formattedAddress(const QString &realName = QString(), const QString &orgaName = QString()) const; /** Returns ISO code for a localized country name. Only localized country names will be understood. @param cname name of the country @return two digit ISO code, empty string if the country was not recognized */ static QString countryToISO(const QString &cname); /** Returns a localized country name for a ISO code. This might be replaced by a KLocale method in the future. @param ISOname two digit ISO code @return localized name of the country */ static QString ISOtoCountry(const QString &ISOname); static QString typeFlagLabel(TypeFlag type); /** Set geographic position. */ void setGeo(const Geo &geo); /** Return geographic position. */ Q_REQUIRED_RESULT Geo geo() const; private: class Private; QSharedDataPointer d; }; Q_DECLARE_OPERATORS_FOR_FLAGS(Address::Type) /** Serializes the @p address object into the @p stream. */ KCONTACTS_EXPORT QDataStream &operator<<(QDataStream &stream, const Address &address); /** Initializes the @p address object from the @p stream. */ KCONTACTS_EXPORT QDataStream &operator>>(QDataStream &stream, Address &address); } +Q_DECLARE_METATYPE(KContacts::Address) + #endif diff --git a/src/addressee.cpp b/src/addressee.cpp index e5ce1159..ec1bfa0f 100644 --- a/src/addressee.cpp +++ b/src/addressee.cpp @@ -1,2663 +1,2695 @@ /* This file is part of the KContacts framework. Copyright (c) 2001 Cornelius Schumacher Copyright (c) 2003 Carsten Pfeiffer Copyright (c) 2005 Ingo Kloecker This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include #include #include #include #include #include "kcontacts_debug.h" #include #include "addresseehelper.h" #include "field.h" #include "addressee.h" using namespace KContacts; static bool matchBinaryPattern(int value, int pattern); template static bool listEquals(const QVector &list, const QVector &pattern); static bool listEquals(const QStringList &list, const QStringList &pattern); class Q_DECL_HIDDEN Addressee::Private : public QSharedData { public: Private() : mUid(QUuid::createUuid().toString().mid(1, 36)) , mEmpty(true) , mChanged(false) , mBirthdayWithTime(false) { //We avoid the curly braces so the string is RFC4122 compliant and can be used as urn } Private(const Private &other) : QSharedData(other) { mUid = other.mUid; mName = other.mName; mFormattedName = other.mFormattedName; mFamilyName = other.mFamilyName; mGivenName = other.mGivenName; mAdditionalName = other.mAdditionalName; mPrefix = other.mPrefix; mSuffix = other.mSuffix; mBirthday = other.mBirthday; mBirthdayWithTime = other.mBirthdayWithTime; mMailer = other.mMailer; mTimeZone = other.mTimeZone; mGeo = other.mGeo; mDepartment = other.mDepartment; mNote = other.mNote; mProductId = other.mProductId; mRevision = other.mRevision; mSortString = other.mSortString; mSecrecy = other.mSecrecy; mLogo = other.mLogo; mPhoto = other.mPhoto; mSound = other.mSound; mPhoneNumbers = other.mPhoneNumbers; mAddresses = other.mAddresses; mKeys = other.mKeys; mLangs = other.mLangs; mGender = other.mGender; mEmails = other.mEmails; mCategories = other.mCategories; mCustomFields = other.mCustomFields; mCalendarUrl = other.mCalendarUrl; mSoundListExtra = other.mSoundListExtra; mPhotoExtraList = other.mPhotoExtraList; mLogoExtraList = other.mLogoExtraList; mUrlExtraList = other.mUrlExtraList; mMembers = other.mMembers; mRelationShips = other.mRelationShips; mSources = other.mSources; mEmpty = other.mEmpty; mImpps = other.mImpps; mChanged = other.mChanged; mTitleExtraList = other.mTitleExtraList; mRoleExtraList = other.mRoleExtraList; mOrgExtraList = other.mOrgExtraList; } ~Private() { } QString mUid; QString mName; QString mFormattedName; QString mFamilyName; QString mGivenName; QString mAdditionalName; QString mPrefix; QString mSuffix; QDateTime mBirthday; QString mMailer; TimeZone mTimeZone; Geo mGeo; QString mDepartment; QString mNote; QString mProductId; QDateTime mRevision; QString mSortString; Secrecy mSecrecy; Picture mLogo; Picture mPhoto; Sound mSound; PhoneNumber::List mPhoneNumbers; Address::List mAddresses; Key::List mKeys; Email::List mEmails; Lang::List mLangs; Impp::List mImpps; Gender mGender; QString mKind; QStringList mCategories; QHash mCustomFields; CalendarUrl::List mCalendarUrl; Sound::List mSoundListExtra; Picture::List mPhotoExtraList; Picture::List mLogoExtraList; ResourceLocatorUrl::List mUrlExtraList; QVector mSources; QStringList mMembers; Related::List mRelationShips; FieldGroup::List mFieldGroupList; Title::List mTitleExtraList; Role::List mRoleExtraList; Org::List mOrgExtraList; NickName::List mNickNameExtraList; ClientPidMap::List mClientPidMapList; bool mEmpty : 1; bool mChanged : 1; bool mBirthdayWithTime; }; Addressee::Addressee() : d(new Private) { } Addressee::~Addressee() { } Addressee::Addressee(const Addressee &other) : d(other.d) { } Addressee &Addressee::operator=(const Addressee &other) { if (this != &other) { d = other.d; } return *this; } bool Addressee::operator==(const Addressee &addressee) const { if (d->mUid != addressee.d->mUid) { qCDebug(KCONTACTS_LOG) << "uid differs"; return false; } if (d->mName != addressee.d->mName && !(d->mName.isEmpty() && addressee.d->mName.isEmpty())) { qCDebug(KCONTACTS_LOG) << "name differs"; return false; } if (d->mFormattedName != addressee.d->mFormattedName && !(d->mFormattedName.isEmpty() && addressee.d->mFormattedName.isEmpty())) { qCDebug(KCONTACTS_LOG) << "formattedName differs"; return false; } if (d->mFamilyName != addressee.d->mFamilyName && !(d->mFamilyName.isEmpty() && addressee.d->mFamilyName.isEmpty())) { qCDebug(KCONTACTS_LOG) << "familyName differs"; return false; } if (d->mGivenName != addressee.d->mGivenName && !(d->mGivenName.isEmpty() && addressee.d->mGivenName.isEmpty())) { qCDebug(KCONTACTS_LOG) << "givenName differs"; return false; } if (d->mAdditionalName != addressee.d->mAdditionalName && !(d->mAdditionalName.isEmpty() && addressee.d->mAdditionalName.isEmpty())) { qCDebug(KCONTACTS_LOG) << "additionalName differs"; return false; } if (d->mPrefix != addressee.d->mPrefix && !(d->mPrefix.isEmpty() && addressee.d->mPrefix.isEmpty())) { qCDebug(KCONTACTS_LOG) << "prefix differs"; return false; } if (d->mSuffix != addressee.d->mSuffix && !(d->mSuffix.isEmpty() && addressee.d->mSuffix.isEmpty())) { qCDebug(KCONTACTS_LOG) << "suffix differs"; return false; } if (d->mBirthday != addressee.d->mBirthday || d->mBirthdayWithTime != addressee.d->mBirthdayWithTime) { qCDebug(KCONTACTS_LOG) << "birthday differs"; return false; } if (d->mMailer != addressee.d->mMailer && !(d->mMailer.isEmpty() && addressee.d->mMailer.isEmpty())) { qCDebug(KCONTACTS_LOG) << "mailer differs"; return false; } if (d->mTimeZone != addressee.d->mTimeZone) { qCDebug(KCONTACTS_LOG) << "timeZone differs"; return false; } if (d->mGeo != addressee.d->mGeo) { qCDebug(KCONTACTS_LOG) << "geo differs"; return false; } if (d->mDepartment != addressee.d->mDepartment && !(d->mDepartment.isEmpty() && addressee.d->mDepartment.isEmpty())) { qCDebug(KCONTACTS_LOG) << "department differs"; return false; } if (d->mNote != addressee.d->mNote && !(d->mNote.isEmpty() && addressee.d->mNote.isEmpty())) { qCDebug(KCONTACTS_LOG) << "note differs"; return false; } if (d->mProductId != addressee.d->mProductId && !(d->mProductId.isEmpty() && addressee.d->mProductId.isEmpty())) { qCDebug(KCONTACTS_LOG) << "productId differs"; return false; } if (d->mSortString != addressee.d->mSortString && !(d->mSortString.isEmpty() && addressee.d->mSortString.isEmpty())) { qCDebug(KCONTACTS_LOG) << "sortString differs"; return false; } if (d->mSecrecy != addressee.d->mSecrecy) { qCDebug(KCONTACTS_LOG) << "secrecy differs"; return false; } if (d->mLogo != addressee.d->mLogo) { qCDebug(KCONTACTS_LOG) << "logo differs"; return false; } if (d->mPhoto != addressee.d->mPhoto) { qCDebug(KCONTACTS_LOG) << "photo differs"; return false; } if (d->mSound != addressee.d->mSound) { qCDebug(KCONTACTS_LOG) << "sound differs"; return false; } if (!listEquals(d->mPhoneNumbers, addressee.d->mPhoneNumbers)) { qCDebug(KCONTACTS_LOG) << "phoneNumbers differs"; return false; } if (!listEquals(d->mAddresses, addressee.d->mAddresses)) { qCDebug(KCONTACTS_LOG) << "addresses differs"; return false; } if (!listEquals(d->mKeys, addressee.d->mKeys)) { qCDebug(KCONTACTS_LOG) << "keys differs"; return false; } if (!listEquals(d->mEmails, addressee.d->mEmails)) { qCDebug(KCONTACTS_LOG) << "emails differs"; return false; } if (!listEquals(d->mCategories, addressee.d->mCategories)) { qCDebug(KCONTACTS_LOG) << "categories differs"; return false; } if (d->mCustomFields != addressee.d->mCustomFields) { qCDebug(KCONTACTS_LOG) << "custom differs"; return false; } if (d->mLangs != addressee.d->mLangs) { qCDebug(KCONTACTS_LOG) << "langs differs"; return false; } if (d->mImpps != addressee.d->mImpps) { qCDebug(KCONTACTS_LOG) << "impps differs"; return false; } if (d->mGender != addressee.d->mGender) { qCDebug(KCONTACTS_LOG) << "gender differs"; return false; } if (d->mKind != addressee.d->mKind) { qCDebug(KCONTACTS_LOG) << "kind differs"; return false; } if (!listEquals(d->mCalendarUrl, addressee.d->mCalendarUrl)) { qCDebug(KCONTACTS_LOG) << "calendarUrl differs"; return false; } if (!listEquals(d->mSoundListExtra, addressee.d->mSoundListExtra)) { qCDebug(KCONTACTS_LOG) << "Extra sound differs"; return false; } if (!listEquals(d->mPhotoExtraList, addressee.d->mPhotoExtraList)) { qCDebug(KCONTACTS_LOG) << "Extra photo differs"; return false; } if (!listEquals(d->mLogoExtraList, addressee.d->mLogoExtraList)) { qCDebug(KCONTACTS_LOG) << "Extra logo differs"; return false; } if (!listEquals(d->mUrlExtraList, addressee.d->mUrlExtraList)) { qCDebug(KCONTACTS_LOG) << "Extra url differs"; return false; } if (!listEquals(d->mMembers, addressee.d->mMembers)) { qCDebug(KCONTACTS_LOG) << "Extra url differs"; return false; } if (!listEquals(d->mRelationShips, addressee.d->mRelationShips)) { qCDebug(KCONTACTS_LOG) << "RelationShips differs"; return false; } if (!listEquals(d->mSources, addressee.d->mSources)) { qCDebug(KCONTACTS_LOG) << "Sources differs"; return false; } if (!listEquals(d->mFieldGroupList, addressee.d->mFieldGroupList)) { qCDebug(KCONTACTS_LOG) << "Field Groups differs"; return false; } if (!listEquals(d->mTitleExtraList, addressee.d->mTitleExtraList)) { qCDebug(KCONTACTS_LOG) << "Extra TitleList differs"; return false; } if (!listEquals(d->mRoleExtraList, addressee.d->mRoleExtraList)) { qCDebug(KCONTACTS_LOG) << "Extra RoleList differs"; return false; } if (!listEquals(d->mOrgExtraList, addressee.d->mOrgExtraList)) { qCDebug(KCONTACTS_LOG) << "Extra Organization List differs"; return false; } if (!listEquals(d->mNickNameExtraList, addressee.d->mNickNameExtraList)) { qCDebug(KCONTACTS_LOG) << "Extra NickName List differs"; return false; } if (!listEquals(d->mClientPidMapList, addressee.d->mClientPidMapList)) { qCDebug(KCONTACTS_LOG) << "ClientPidMap List differs"; return false; } return true; } bool Addressee::operator!=(const Addressee &a) const { return !(a == *this); } bool Addressee::isEmpty() const { return d->mEmpty; } void Addressee::setUid(const QString &id) { if (id == d->mUid) { return; } d->mEmpty = false; d->mUid = id; } QString Addressee::uid() const { return d->mUid; } QString Addressee::uidLabel() { return i18n("Unique Identifier"); } void Addressee::setName(const QString &name) { if (name == d->mName) { return; } d->mEmpty = false; d->mName = name; } QString Addressee::name() const { return d->mName; } QString Addressee::nameLabel() { return i18n("Name"); } void Addressee::setKind(const QString &kind) { if (kind == d->mKind) { return; } d->mEmpty = false; d->mKind = kind; } QString Addressee::kind() const { return d->mKind; } void Addressee::insertExtraSound(const Sound &sound) { d->mEmpty = false; d->mSoundListExtra.append(sound); } Sound::List Addressee::extraSoundList() const { return d->mSoundListExtra; } void Addressee::insertExtraPhoto(const Picture &picture) { d->mEmpty = false; d->mPhotoExtraList.append(picture); } Picture::List Addressee::extraPhotoList() const { return d->mPhotoExtraList; } void Addressee::insertExtraLogo(const Picture &logo) { d->mEmpty = false; d->mLogoExtraList.append(logo); } Picture::List Addressee::extraLogoList() const { return d->mLogoExtraList; } void Addressee::setExtraSoundList(const Sound::List &soundList) { d->mEmpty = false; d->mSoundListExtra = soundList; } void Addressee::setExtraPhotoList(const Picture::List &pictureList) { d->mEmpty = false; d->mPhotoExtraList = pictureList; } void Addressee::setExtraLogoList(const Picture::List &logoList) { d->mEmpty = false; d->mLogoExtraList = logoList; } void Addressee::insertExtraUrl(const ResourceLocatorUrl &url) { if (url.isValid()) { d->mEmpty = false; d->mUrlExtraList.append(url); } } void Addressee::setExtraUrlList(const ResourceLocatorUrl::List &urlList) { d->mEmpty = false; d->mUrlExtraList = urlList; } ResourceLocatorUrl::List Addressee::extraUrlList() const { return d->mUrlExtraList; } void Addressee::insertSourceUrl(const QUrl &url) { d->mEmpty = false; d->mSources.append(url); } void Addressee::setSourcesUrlList(const QVector &urlList) { d->mEmpty = false; d->mSources = urlList; } QVector Addressee::sourcesUrlList() const { return d->mSources; } FieldGroup::List Addressee::fieldGroupList() const { return d->mFieldGroupList; } void Addressee::setFieldGroupList(const FieldGroup::List &fieldGroupList) { d->mEmpty = false; d->mFieldGroupList = fieldGroupList; } void Addressee::insertFieldGroup(const FieldGroup &fieldGroup) { if (fieldGroup.isValid()) { d->mEmpty = false; //TODO don't duplicate ? d->mFieldGroupList.append(fieldGroup); } } ClientPidMap::List Addressee::clientPidMapList() const { return d->mClientPidMapList; } void Addressee::setClientPidMapList(const ClientPidMap::List &clientpidmaplist) { d->mEmpty = false; d->mClientPidMapList = clientpidmaplist; } void Addressee::insertClientPidMap(const ClientPidMap &clientpidmap) { if (clientpidmap.isValid()) { d->mEmpty = false; //TODO don't duplicate ? d->mClientPidMapList.append(clientpidmap); } } void Addressee::insertImpp(const Impp &impp) { if (impp.isValid()) { d->mEmpty = false; //Don't duplicate ? d->mImpps.append(impp); } } void Addressee::setImppList(const Impp::List &imppList) { d->mEmpty = false; d->mImpps = imppList; } Impp::List Addressee::imppList() const { return d->mImpps; } void Addressee::insertCalendarUrl(const CalendarUrl &calendarUrl) { d->mEmpty = false; //TODO verify that there is not same calendarurl if (calendarUrl.isValid()) { d->mCalendarUrl.append(calendarUrl); } } CalendarUrl::List Addressee::calendarUrlList() const { return d->mCalendarUrl; } void Addressee::setFormattedName(const QString &formattedName) { if (formattedName == d->mFormattedName) { return; } d->mEmpty = false; d->mFormattedName = formattedName; } QString Addressee::formattedName() const { return d->mFormattedName; } QString Addressee::formattedNameLabel() { return i18n("Formatted Name"); } void Addressee::setFamilyName(const QString &familyName) { if (familyName == d->mFamilyName) { return; } d->mEmpty = false; d->mFamilyName = familyName; } QString Addressee::familyName() const { return d->mFamilyName; } QString Addressee::familyNameLabel() { return i18n("Family Name"); } void Addressee::setGivenName(const QString &givenName) { if (givenName == d->mGivenName) { return; } d->mEmpty = false; d->mGivenName = givenName; } QString Addressee::givenName() const { return d->mGivenName; } QString Addressee::givenNameLabel() { return i18n("Given Name"); } void Addressee::setAdditionalName(const QString &additionalName) { if (additionalName == d->mAdditionalName) { return; } d->mEmpty = false; d->mAdditionalName = additionalName; } QString Addressee::additionalName() const { return d->mAdditionalName; } QString Addressee::additionalNameLabel() { return i18n("Additional Names"); } void Addressee::setPrefix(const QString &prefix) { if (prefix == d->mPrefix) { return; } d->mEmpty = false; d->mPrefix = prefix; } QString Addressee::prefix() const { return d->mPrefix; } QString Addressee::prefixLabel() { return i18n("Honorific Prefixes"); } void Addressee::setSuffix(const QString &suffix) { if (suffix == d->mSuffix) { return; } d->mEmpty = false; d->mSuffix = suffix; } QString Addressee::suffix() const { return d->mSuffix; } QString Addressee::suffixLabel() { return i18n("Honorific Suffixes"); } void Addressee::setNickName(const QString &nickName) { NickName t(nickName); if (!d->mNickNameExtraList.isEmpty()) { t = d->mNickNameExtraList.takeFirst(); t.setNickName(nickName); d->mNickNameExtraList.prepend(t); d->mEmpty = false; } else { insertExtraNickName(t); } } void Addressee::setNickName(const NickName &nickName) { insertExtraNickName(nickName); } void Addressee::insertExtraNickName(const NickName &nickName) { if (nickName.isValid()) { d->mEmpty = false; d->mNickNameExtraList.append(nickName); } } void Addressee::setExtraNickNameList(const NickName::List &nickNameList) { d->mEmpty = false; d->mNickNameExtraList = nickNameList; } NickName::List Addressee::extraNickNameList() const { return d->mNickNameExtraList; } QString Addressee::nickName() const { if (d->mNickNameExtraList.isEmpty()) { return {}; } else { return d->mNickNameExtraList.at(0).nickname(); } } QString Addressee::nickNameLabel() { return i18n("Nick Name"); } void Addressee::setBirthday(const QDateTime &birthday, bool withTime) { if (birthday == d->mBirthday && d->mBirthdayWithTime == withTime) { return; } d->mEmpty = false; d->mBirthday = birthday; if (!withTime) { d->mBirthday.setTime(QTime()); } d->mBirthdayWithTime = withTime; } void Addressee::setBirthday(const QDate &birthday) { if (birthday == d->mBirthday.date() && !d->mBirthdayWithTime) { return; } d->mEmpty = false; d->mBirthday = QDateTime(birthday, QTime()); d->mBirthdayWithTime = false; } QDateTime Addressee::birthday() const { return d->mBirthday; } bool Addressee::birthdayHasTime() const { return d->mBirthdayWithTime; } QString Addressee::birthdayLabel() { return i18n("Birthday"); } QString Addressee::homeAddressStreetLabel() { return i18n("Home Address Street"); } QString Addressee::homeAddressPostOfficeBoxLabel() { return i18n("Home Address Post Office Box"); } QString Addressee::homeAddressLocalityLabel() { return i18n("Home Address City"); } QString Addressee::homeAddressRegionLabel() { return i18n("Home Address State"); } QString Addressee::homeAddressPostalCodeLabel() { return i18n("Home Address Zip Code"); } QString Addressee::homeAddressCountryLabel() { return i18n("Home Address Country"); } QString Addressee::homeAddressLabelLabel() { return i18n("Home Address Label"); } QString Addressee::businessAddressStreetLabel() { return i18n("Business Address Street"); } QString Addressee::businessAddressPostOfficeBoxLabel() { return i18n("Business Address Post Office Box"); } QString Addressee::businessAddressLocalityLabel() { return i18n("Business Address City"); } QString Addressee::businessAddressRegionLabel() { return i18n("Business Address State"); } QString Addressee::businessAddressPostalCodeLabel() { return i18n("Business Address Zip Code"); } QString Addressee::businessAddressCountryLabel() { return i18n("Business Address Country"); } QString Addressee::businessAddressLabelLabel() { return i18n("Business Address Label"); } QString Addressee::homePhoneLabel() { return i18n("Home Phone"); } QString Addressee::businessPhoneLabel() { return i18n("Business Phone"); } QString Addressee::mobilePhoneLabel() { return i18n("Mobile Phone"); } QString Addressee::homeFaxLabel() { return i18n("Home Fax"); } QString Addressee::businessFaxLabel() { return i18n("Business Fax"); } QString Addressee::carPhoneLabel() { return i18n("Car Phone"); } QString Addressee::isdnLabel() { return i18n("ISDN"); } QString Addressee::pagerLabel() { return i18n("Pager"); } QString Addressee::emailLabel() { return i18n("Email Address"); } void Addressee::setMailer(const QString &mailer) { if (mailer == d->mMailer) { return; } d->mEmpty = false; d->mMailer = mailer; } QString Addressee::mailer() const { return d->mMailer; } QString Addressee::mailerLabel() { return i18n("Mail Client"); } void Addressee::setTimeZone(const TimeZone &timeZone) { if (timeZone == d->mTimeZone) { return; } d->mEmpty = false; d->mTimeZone = timeZone; } TimeZone Addressee::timeZone() const { return d->mTimeZone; } QString Addressee::timeZoneLabel() { return i18n("Time Zone"); } void Addressee::setGeo(const Geo &geo) { if (geo == d->mGeo) { return; } d->mEmpty = false; d->mGeo = geo; } Geo Addressee::geo() const { return d->mGeo; } QString Addressee::geoLabel() { return i18n("Geographic Position"); } void Addressee::setTitle(const QString &title) { Title t(title); if (!d->mTitleExtraList.isEmpty()) { t = d->mTitleExtraList.takeFirst(); t.setTitle(title); d->mTitleExtraList.prepend(t); d->mEmpty = false; } else { insertExtraTitle(title); } } void Addressee::setTitle(const Title &title) { insertExtraTitle(title); } void Addressee::insertExtraTitle(const Title &title) { if (title.isValid()) { d->mEmpty = false; d->mTitleExtraList.append(title); } } QString Addressee::title() const { if (d->mTitleExtraList.isEmpty()) { return {}; } else { return d->mTitleExtraList.at(0).title(); } } Title::List Addressee::extraTitleList() const { return d->mTitleExtraList; } void Addressee::setExtraTitleList(const Title::List &urltitle) { d->mEmpty = false; d->mTitleExtraList = urltitle; } QString Addressee::titleLabel() { return i18nc("a person's title", "Title"); } void Addressee::setRole(const QString &role) { Role t(role); if (!d->mRoleExtraList.isEmpty()) { t = d->mRoleExtraList.takeFirst(); t.setRole(role); d->mRoleExtraList.prepend(t); d->mEmpty = false; } else { insertExtraRole(t); } } void Addressee::setRole(const Role &role) { insertExtraRole(role); } void Addressee::insertExtraRole(const Role &role) { if (role.isValid()) { d->mEmpty = false; d->mRoleExtraList.append(role); } } void Addressee::setExtraRoleList(const Role::List &roleList) { d->mEmpty = false; d->mRoleExtraList = roleList; } Role::List Addressee::extraRoleList() const { return d->mRoleExtraList; } QString Addressee::role() const { if (d->mRoleExtraList.isEmpty()) { return {}; } else { return d->mRoleExtraList.at(0).role(); } } QString Addressee::roleLabel() { return i18nc("of a person in an organization", "Role"); } void Addressee::setOrganization(const QString &organization) { Org t(organization); if (!d->mOrgExtraList.isEmpty()) { t = d->mOrgExtraList.takeFirst(); t.setOrganization(organization); d->mOrgExtraList.prepend(t); d->mEmpty = false; } else { insertExtraOrganization(t); } } void Addressee::setOrganization(const Org &organization) { insertExtraOrganization(organization); } void Addressee::insertExtraOrganization(const Org &organization) { if (organization.isValid()) { d->mEmpty = false; d->mOrgExtraList.append(organization); } } void Addressee::setExtraOrganizationList(const Org::List &orgList) { d->mEmpty = false; d->mOrgExtraList = orgList; } Org::List Addressee::extraOrganizationList() const { return d->mOrgExtraList; } QString Addressee::organization() const { if (d->mOrgExtraList.isEmpty()) { return {}; } else { return d->mOrgExtraList.at(0).organization(); } } QString Addressee::organizationLabel() { return i18n("Organization"); } void Addressee::setDepartment(const QString &department) { if (department == d->mDepartment) { return; } d->mEmpty = false; d->mDepartment = department; } QString Addressee::department() const { return d->mDepartment; } QString Addressee::departmentLabel() { return i18n("Department"); } void Addressee::setNote(const QString ¬e) { if (note == d->mNote) { return; } d->mEmpty = false; d->mNote = note; } QString Addressee::note() const { return d->mNote; } QString Addressee::noteLabel() { return i18n("Note"); } void Addressee::setProductId(const QString &productId) { if (productId == d->mProductId) { return; } d->mEmpty = false; d->mProductId = productId; } QString Addressee::productId() const { return d->mProductId; } QString Addressee::productIdLabel() { return i18n("Product Identifier"); } void Addressee::setRevision(const QDateTime &revision) { if (revision == d->mRevision) { return; } d->mEmpty = false; d->mRevision = revision; } QDateTime Addressee::revision() const { return d->mRevision; } QString Addressee::revisionLabel() { return i18n("Revision Date"); } void Addressee::setSortString(const QString &sortString) { if (sortString == d->mSortString) { return; } d->mEmpty = false; d->mSortString = sortString; } QString Addressee::sortString() const { return d->mSortString; } QString Addressee::sortStringLabel() { return i18n("Sort String"); } void Addressee::setUrl(const QUrl &url) { KContacts::ResourceLocatorUrl resourceLocator; resourceLocator.setUrl(url); insertExtraUrl(resourceLocator); } void Addressee::setUrl(const ResourceLocatorUrl &url) { insertExtraUrl(url); } ResourceLocatorUrl Addressee::url() const { if (d->mUrlExtraList.isEmpty()) { return ResourceLocatorUrl(); } else { return d->mUrlExtraList.at(0); } } QString Addressee::urlLabel() { return i18n("Homepage"); } void Addressee::setSecrecy(const Secrecy &secrecy) { if (secrecy == d->mSecrecy) { return; } d->mEmpty = false; d->mSecrecy = secrecy; } Secrecy Addressee::secrecy() const { return d->mSecrecy; } QString Addressee::secrecyLabel() { return i18n("Security Class"); } void Addressee::setLogo(const Picture &logo) { if (logo == d->mLogo) { return; } d->mEmpty = false; d->mLogo = logo; } Picture Addressee::logo() const { return d->mLogo; } QString Addressee::logoLabel() { return i18n("Logo"); } void Addressee::setPhoto(const Picture &photo) { if (photo == d->mPhoto) { return; } d->mEmpty = false; d->mPhoto = photo; } Picture Addressee::photo() const { return d->mPhoto; } QString Addressee::photoLabel() { return i18n("Photo"); } void Addressee::setSound(const Sound &sound) { if (sound == d->mSound) { return; } d->mEmpty = false; d->mSound = sound; } Sound Addressee::sound() const { return d->mSound; } QString Addressee::soundLabel() { return i18n("Sound"); } void Addressee::setNameFromString(const QString &s) { QString str = s; //remove enclosing quotes from string if (str.length() > 1 && s[0] == QLatin1Char('"') && s[s.length() - 1] == QLatin1Char('"')) { str = s.mid(1, s.length() - 2); } setFormattedName(str); setName(str); // clear all name parts setPrefix(QString()); setGivenName(QString()); setAdditionalName(QString()); setFamilyName(QString()); setSuffix(QString()); if (str.isEmpty()) { return; } static QString spaceStr = QStringLiteral(" "); static QString emptyStr = QStringLiteral(""); AddresseeHelper *helper = AddresseeHelper::self(); int i = str.indexOf(QLatin1Char(',')); if (i < 0) { QStringList parts = str.split(spaceStr); int leftOffset = 0; int rightOffset = parts.count() - 1; QString suffix; while (rightOffset >= 0) { if (helper->containsSuffix(parts[rightOffset])) { suffix.prepend(parts[rightOffset] + (suffix.isEmpty() ? emptyStr : spaceStr)); rightOffset--; } else { break; } } setSuffix(suffix); if (rightOffset < 0) { return; } if (rightOffset - 1 >= 0 && helper->containsPrefix(parts[rightOffset - 1].toLower())) { setFamilyName(parts[rightOffset - 1] + spaceStr + parts[rightOffset]); rightOffset--; } else { if (helper->treatAsFamilyName()) { setFamilyName(parts[rightOffset]); } else { setGivenName(parts[rightOffset]); } } QString prefix; while (leftOffset < rightOffset) { if (helper->containsTitle(parts[leftOffset])) { prefix.append((prefix.isEmpty() ? emptyStr : spaceStr) + parts[leftOffset]); leftOffset++; } else { break; } } setPrefix(prefix); if (leftOffset < rightOffset) { setGivenName(parts[leftOffset]); leftOffset++; } QString additionalName; while (leftOffset < rightOffset) { additionalName.append((additionalName.isEmpty() ? emptyStr : spaceStr) + parts[leftOffset]); leftOffset++; } setAdditionalName(additionalName); } else { QString part1 = str.left(i); QString part2 = str.mid(i + 1); QStringList parts = part1.split(spaceStr); int leftOffset = 0; int rightOffset = parts.count() - 1; if (!parts.isEmpty()) { QString suffix; while (rightOffset >= 0) { if (helper->containsSuffix(parts[rightOffset])) { suffix.prepend(parts[rightOffset] + (suffix.isEmpty() ? emptyStr : spaceStr)); rightOffset--; } else { break; } } setSuffix(suffix); if (rightOffset - 1 >= 0 && helper->containsPrefix(parts[rightOffset - 1].toLower())) { setFamilyName(parts[rightOffset - 1] + spaceStr + parts[rightOffset]); rightOffset--; } else { setFamilyName(parts[rightOffset]); } QString prefix; while (leftOffset < rightOffset) { if (helper->containsTitle(parts[leftOffset])) { prefix.append((prefix.isEmpty() ? emptyStr : spaceStr) + parts[leftOffset]); leftOffset++; } else { break; } } } else { setPrefix(QString()); setFamilyName(QString()); setSuffix(QString()); } parts = part2.split(spaceStr); leftOffset = 0; rightOffset = parts.count(); if (!parts.isEmpty()) { QString prefix; while (leftOffset < rightOffset) { if (helper->containsTitle(parts[leftOffset])) { prefix.append((prefix.isEmpty() ? emptyStr : spaceStr) + parts[leftOffset]); leftOffset++; } else { break; } } setPrefix(prefix); if (leftOffset < rightOffset) { setGivenName(parts[leftOffset]); leftOffset++; } QString additionalName; while (leftOffset < rightOffset) { additionalName.append((additionalName.isEmpty() ? emptyStr : spaceStr) + parts[leftOffset]); leftOffset++; } setAdditionalName(additionalName); } else { setGivenName(QString()); setAdditionalName(QString()); } } } QString Addressee::realName() const { QString n(formattedName()); if (!n.isEmpty()) { return n; } n = assembledName(); if (!n.isEmpty()) { return n; } n = name(); if (!n.isEmpty()) { return n; } return organization(); } QString Addressee::assembledName() const { const QString name = prefix() + QLatin1Char(' ') +givenName() + QLatin1Char(' ') +additionalName() + QLatin1Char(' ') +familyName() + QLatin1Char(' ') +suffix(); return name.simplified(); } QString Addressee::fullEmail(const QString &email) const { QString e; if (email.isNull()) { e = preferredEmail(); } else { e = email; } if (e.isEmpty()) { return QString(); } QString text; if (realName().isEmpty()) { text = e; } else { QRegExp needQuotes(QStringLiteral("[^ 0-9A-Za-z\\x0080-\\xFFFF]")); if (realName().indexOf(needQuotes) != -1) { QString name = realName(); name.replace(QLatin1String("\""), QLatin1String("\\\"")); text = QLatin1String("\"") + name + QLatin1String("\" <") + e + QLatin1Char('>'); } else { text = realName() + QLatin1String(" <") + e + QLatin1Char('>'); } } return text; } void Addressee::insertEmail(const QString &email, bool preferred, const QMap ¶m) { if (email.simplified().isEmpty()) { return; } for (int i = 0; i < d->mEmails.size(); ++i) { if (d->mEmails.at(i).mail() == email) { if (!preferred || i == 0) { return; } Email tempMail = d->mEmails.takeAt(i); d->mEmails.prepend(tempMail); return; } } Email mail(email); mail.setParameters(param); d->mEmpty = false; if (preferred) { d->mEmails.prepend(mail); } else { d->mEmails.append(mail); } } void Addressee::removeEmail(const QString &email) { for (int i = 0; i < d->mEmails.size(); ++i) { if (d->mEmails.at(i).mail() == email) { d->mEmails.removeAt(i); } } } QString Addressee::preferredEmail() const { if (d->mEmails.isEmpty()) { return QString(); } else { return d->mEmails.first().mail(); } } QStringList Addressee::emails() const { QStringList list; const int numberOfEmail = d->mEmails.size(); list.reserve(numberOfEmail); for (int i = 0; i < numberOfEmail; ++i) { list << d->mEmails.at(i).mail(); } return list; } Email::List Addressee::emailList() const { return d->mEmails; } void Addressee::setEmails(const QStringList &emails) { d->mEmails.clear(); const int numEmails = emails.size(); d->mEmails.reserve(numEmails); for (int i = 0; i < numEmails; ++i) { d->mEmails.append(Email(emails.at(i))); } d->mEmpty = false; } void Addressee::setEmailList(const Email::List &list) { d->mEmails = list; d->mEmpty = false; } void Addressee::removeLang(const QString &language) { for (int i = 0; i < d->mLangs.size(); ++i) { if (d->mLangs.at(i).language() == language) { d->mLangs.removeAt(i); } } } void Addressee::setLangs(const Lang::List &langs) { d->mLangs = langs; d->mEmpty = false; } void Addressee::insertLang(const Lang &language) { const QString languageStr = language.language(); if (languageStr.simplified().isEmpty()) { return; } d->mEmpty = false; Lang::List::Iterator it; Lang::List::Iterator end(d->mLangs.end()); for (it = d->mLangs.begin(); it != end; ++it) { if ((*it).language() == languageStr) { (*it).setParameters(language.parameters()); return; } } d->mLangs.append(language); } Lang::List Addressee::langs() const { return d->mLangs; } void Addressee::setGender(const Gender &gender) { if (gender == d->mGender) { return; } d->mEmpty = false; d->mGender = gender; } Gender Addressee::gender() const { return d->mGender; } void Addressee::insertPhoneNumber(const PhoneNumber &phoneNumber) { d->mEmpty = false; PhoneNumber::List::Iterator it; PhoneNumber::List::Iterator end(d->mPhoneNumbers.end()); for (it = d->mPhoneNumbers.begin(); it != end; ++it) { if ((*it).id() == phoneNumber.id()) { *it = phoneNumber; return; } } if (!phoneNumber.number().simplified().isEmpty()) { d->mPhoneNumbers.append(phoneNumber); } } void Addressee::removePhoneNumber(const PhoneNumber &phoneNumber) { PhoneNumber::List::Iterator it; for (it = d->mPhoneNumbers.begin(); it != d->mPhoneNumbers.end(); ++it) { if ((*it).id() == phoneNumber.id()) { d->mPhoneNumbers.erase(it); return; } } } PhoneNumber Addressee::phoneNumber(PhoneNumber::Type type) const { PhoneNumber phoneNumber(QString(), type); PhoneNumber::List::ConstIterator it; for (it = d->mPhoneNumbers.constBegin(); it != d->mPhoneNumbers.constEnd(); ++it) { if (matchBinaryPattern((*it).type(), type)) { if ((*it).type() & PhoneNumber::Pref) { return *it; } else if (phoneNumber.number().isEmpty()) { phoneNumber = (*it); } } } return phoneNumber; } PhoneNumber::List Addressee::phoneNumbers() const { return d->mPhoneNumbers; } void Addressee::setPhoneNumbers(const PhoneNumber::List &phoneNumbers) { d->mEmpty = false; d->mPhoneNumbers.clear(); d->mPhoneNumbers = phoneNumbers; } PhoneNumber::List Addressee::phoneNumbers(PhoneNumber::Type type) const { PhoneNumber::List list; PhoneNumber::List::ConstIterator it; const PhoneNumber::List::ConstIterator end(d->mPhoneNumbers.constEnd()); for (it = d->mPhoneNumbers.constBegin(); it != end; ++it) { if (matchBinaryPattern((*it).type(), type)) { list.append(*it); } } return list; } PhoneNumber Addressee::findPhoneNumber(const QString &id) const { PhoneNumber::List::ConstIterator it; const PhoneNumber::List::ConstIterator end(d->mPhoneNumbers.constEnd()); for (it = d->mPhoneNumbers.constBegin(); it != end; ++it) { if ((*it).id() == id) { return *it; } } return PhoneNumber(); } void Addressee::insertKey(const Key &key) { d->mEmpty = false; Key::List::Iterator it; Key::List::Iterator end(d->mKeys.end()); for (it = d->mKeys.begin(); it != end; ++it) { if ((*it).id() == key.id()) { *it = key; return; } } d->mKeys.append(key); } void vectorRemoveAll(Key::List &t, const Key &key) { t.removeAll(key); } void Addressee::removeKey(const Key &key) { Key::List::Iterator it; for (it = d->mKeys.begin(); it != d->mKeys.end(); ++it) { if ((*it).id() == key.id()) { d->mKeys.removeAll(key); return; } } } Key Addressee::key(Key::Type type, const QString &customTypeString) const { Key::List::ConstIterator it; Key::List::ConstIterator end(d->mKeys.constEnd()); for (it = d->mKeys.constBegin(); it != end; ++it) { if ((*it).type() == type) { if (type == Key::Custom) { if (customTypeString.isEmpty()) { return *it; } else { if ((*it).customTypeString() == customTypeString) { return *it; } } } else { return *it; } } } return Key(QString(), type); } void Addressee::setKeys(const Key::List &list) { d->mKeys = list; d->mEmpty = false; } Key::List Addressee::keys() const { return d->mKeys; } Key::List Addressee::keys(Key::Type type, const QString &customTypeString) const { Key::List list; Key::List::ConstIterator it; Key::List::ConstIterator end(d->mKeys.constEnd()); for (it = d->mKeys.constBegin(); it != end; ++it) { if ((*it).type() == type) { if (type == Key::Custom) { if (customTypeString.isEmpty()) { list.append(*it); } else { if ((*it).customTypeString() == customTypeString) { list.append(*it); } } } else { list.append(*it); } } } return list; } Key Addressee::findKey(const QString &id) const { Key::List::ConstIterator it; Key::List::ConstIterator end(d->mKeys.constEnd()); for (it = d->mKeys.constBegin(); it != end; ++it) { if ((*it).id() == id) { return *it; } } return Key(); } QString Addressee::toString() const { QString str = QLatin1String("Addressee {\n"); str += QStringLiteral(" Uid: %1\n").arg(uid()); str += QStringLiteral(" Name: %1\n").arg(name()); str += QStringLiteral(" FormattedName: %1\n").arg(formattedName()); str += QStringLiteral(" FamilyName: %1\n").arg(familyName()); str += QStringLiteral(" GivenName: %1\n").arg(givenName()); str += QStringLiteral(" AdditionalName: %1\n").arg(additionalName()); str += QStringLiteral(" Prefix: %1\n").arg(prefix()); str += QStringLiteral(" Suffix: %1\n").arg(suffix()); str += QStringLiteral(" NickName: %1\n").arg(nickName()); str += QStringLiteral(" Birthday: %1\n").arg(birthday().toString()); str += QStringLiteral(" Mailer: %1\n").arg(mailer()); str += QStringLiteral(" TimeZone: %1\n").arg(timeZone().toString()); str += QStringLiteral(" Geo: %1\n").arg(geo().toString()); str += QStringLiteral(" Title: %1\n").arg(title()); str += QStringLiteral(" Role: %1\n").arg(role()); str += QStringLiteral(" Organization: %1\n").arg(organization()); str += QStringLiteral(" Department: %1\n").arg(department()); str += QStringLiteral(" Note: %1\n").arg(note()); str += QStringLiteral(" ProductId: %1\n").arg(productId()); str += QStringLiteral(" Revision: %1\n").arg(revision().toString()); str += QStringLiteral(" SortString: %1\n").arg(sortString()); str += QStringLiteral(" Url: %1\n").arg(url().url().url()); str += QStringLiteral(" Secrecy: %1\n").arg(secrecy().toString()); str += QStringLiteral(" Logo: %1\n").arg(logo().toString()); str += QStringLiteral(" Photo: %1\n").arg(photo().toString()); str += QStringLiteral(" Sound: %1\n").arg(sound().toString()); str += QStringLiteral(" Gender: %1\n").arg(gender().toString()); str += QStringLiteral(" Kind: %1\n").arg(kind()); str += QLatin1String(" Emails {\n"); const Email::List listEmail = d->mEmails; Email::List::ConstIterator it5; for (it5 = listEmail.begin(); it5 != listEmail.end(); ++it5) { str += (*it5).toString(); } str += QLatin1String(" }\n"); str += QLatin1String(" Langs {\n"); const Lang::List listLang = d->mLangs; Lang::List::ConstIterator it6; for (it6 = listLang.begin(); it6 != listLang.end(); ++it6) { str += (*it6).toString(); } str += QLatin1String(" }\n"); str += QLatin1String(" PhoneNumbers {\n"); const PhoneNumber::List p = phoneNumbers(); PhoneNumber::List::ConstIterator it2; for (it2 = p.begin(); it2 != p.end(); ++it2) { str += (*it2).toString(); } str += QLatin1String(" }\n"); str += QLatin1String(" Addresses {\n"); const Address::List a = addresses(); Address::List::ConstIterator it3; for (it3 = a.begin(); it3 != a.end(); ++it3) { str += (*it3).toString(); } str += QLatin1String(" }\n"); str += QLatin1String(" Keys {\n"); const Key::List k = keys(); Key::List::ConstIterator it4; for (it4 = k.begin(); it4 != k.end(); ++it4) { str += (*it4).toString(); } str += QLatin1String(" }\n"); str += QLatin1String("}\n"); return str; } void Addressee::insertAddress(const Address &address) { if (address.isEmpty()) { return; } d->mEmpty = false; Address::List::Iterator it; Address::List::Iterator end(d->mAddresses.end()); for (it = d->mAddresses.begin(); it != end; ++it) { if ((*it).id() == address.id()) { *it = address; return; } } d->mAddresses.append(address); } void Addressee::removeAddress(const Address &address) { Address::List::Iterator it; for (it = d->mAddresses.begin(); it != d->mAddresses.end(); ++it) { if ((*it).id() == address.id()) { d->mAddresses.erase(it); return; } } } Address Addressee::address(Address::Type type) const { Address address(type); Address::List::ConstIterator it; Address::List::ConstIterator end(d->mAddresses.constEnd()); for (it = d->mAddresses.constBegin(); it != end; ++it) { if (matchBinaryPattern((*it).type(), type)) { if ((*it).type() & Address::Pref) { return *it; } else if (address.isEmpty()) { address = (*it); } } } return address; } Address::List Addressee::addresses() const { return d->mAddresses; } Address::List Addressee::addresses(Address::Type type) const { Address::List list; Address::List::ConstIterator it; Address::List::ConstIterator end(d->mAddresses.constEnd()); for (it = d->mAddresses.constBegin(); it != end; ++it) { if (matchBinaryPattern((*it).type(), type)) { list.append(*it); } } return list; } Address Addressee::findAddress(const QString &id) const { Address::List::ConstIterator it; Address::List::ConstIterator end(d->mAddresses.constEnd()); for (it = d->mAddresses.constBegin(); it != end; ++it) { if ((*it).id() == id) { return *it; } } return Address(); } void Addressee::insertCategory(const QString &c) { d->mEmpty = false; if (d->mCategories.contains(c)) { return; } d->mCategories.append(c); } void Addressee::removeCategory(const QString &category) { if (d->mCategories.contains(category)) { d->mCategories.removeAll(category); } } bool Addressee::hasCategory(const QString &category) const { return d->mCategories.contains(category); } void Addressee::setCategories(const QStringList &c) { d->mEmpty = false; d->mCategories = c; } QStringList Addressee::categories() const { return d->mCategories; } void Addressee::insertMember(const QString &member) { d->mEmpty = false; if (d->mMembers.contains(member)) { return; } d->mMembers.append(member); } void Addressee::setMembers(const QStringList &m) { d->mEmpty = false; d->mMembers = m; } QStringList Addressee::members() const { return d->mMembers; } void Addressee::insertRelationShip(const Related &relation) { d->mEmpty = false; if (d->mRelationShips.contains(relation)) { return; } d->mRelationShips.append(relation); } void Addressee::setRelationShips(const Related::List &c) { d->mEmpty = false; d->mRelationShips = c; } Related::List Addressee::relationShips() const { return d->mRelationShips; } static const auto VENDOR_ID = QStringLiteral("KADDRESSBOOK"); static const auto X_ANNIVERSARY = QStringLiteral("X-Anniversary"); static const auto X_ASSISTANTSNAME = QStringLiteral("X-AssistantsName"); static const auto BLOGFEED = QStringLiteral("BlogFeed"); static const auto X_MANAGERSNAME = QStringLiteral("X-ManagersName"); static const auto X_OFFICE = QStringLiteral("X-Office"); static const auto X_PROFESSION = QStringLiteral("X-Profession"); static const auto X_SPOUSESNAME = QStringLiteral("X-SpousesName"); QDate Addressee::anniversary() const { return QDate::fromString(custom(VENDOR_ID, X_ANNIVERSARY), Qt::ISODate); } void Addressee::setAnniversary(const QDate &anniversary) { if (anniversary.isValid()) { insertCustom(VENDOR_ID, X_ANNIVERSARY, anniversary.toString(Qt::ISODate)); } else { removeCustom(VENDOR_ID, X_ANNIVERSARY); } } QString Addressee::assistantsName() const { return custom(VENDOR_ID, X_ASSISTANTSNAME); } void Addressee::setAssistantsName(const QString &assistantsName) { if (!assistantsName.isEmpty()) { insertCustom(VENDOR_ID, X_ASSISTANTSNAME, assistantsName); } else { removeCustom(VENDOR_ID, X_ASSISTANTSNAME); } } QString Addressee::blogFeed() const { return custom(VENDOR_ID, BLOGFEED); } void Addressee::setBlogFeed(const QString &blogFeed) { if (!blogFeed.isEmpty()) { insertCustom(VENDOR_ID, BLOGFEED, blogFeed); } else { removeCustom(VENDOR_ID, BLOGFEED); } } QString Addressee::managersName() const { return custom(VENDOR_ID, X_MANAGERSNAME); } void Addressee::setManagersName(const QString &managersName) { if (!managersName.isEmpty()) { insertCustom(VENDOR_ID, X_MANAGERSNAME, managersName); } else { removeCustom(VENDOR_ID, X_MANAGERSNAME); } } QString Addressee::office() const { return custom(VENDOR_ID, X_OFFICE); } void Addressee::setOffice(const QString &office) { if (!office.isEmpty()) { insertCustom(VENDOR_ID, X_OFFICE, office); } else { removeCustom(VENDOR_ID, X_OFFICE); } } QString Addressee::profession() const { return custom(VENDOR_ID, X_PROFESSION); } void Addressee::setProfession(const QString &profession) { if (!profession.isEmpty()) { insertCustom(VENDOR_ID, X_PROFESSION, profession); } else { removeCustom(VENDOR_ID, X_PROFESSION); } } QString Addressee::spousesName() const { return custom(VENDOR_ID, X_SPOUSESNAME); } void Addressee::setSpousesName(const QString &spousesName) { if (!spousesName.isEmpty()) { insertCustom(VENDOR_ID, X_SPOUSESNAME, spousesName); } else { removeCustom(VENDOR_ID, X_SPOUSESNAME); } } void Addressee::insertCustom(const QString &app, const QString &name, const QString &value) { if (value.isEmpty() || name.isEmpty() || app.isEmpty()) { return; } d->mEmpty = false; const QString qualifiedName = app + QLatin1Char('-') + name; d->mCustomFields.insert(qualifiedName, value); } void Addressee::removeCustom(const QString &app, const QString &name) { const QString qualifiedName = app + QLatin1Char('-') + name; d->mCustomFields.remove(qualifiedName); } QString Addressee::custom(const QString &app, const QString &name) const { const QString qualifiedName = app + QLatin1Char('-') + name; return d->mCustomFields.value(qualifiedName); } void Addressee::setCustoms(const QStringList &customs) { d->mEmpty = false; d->mCustomFields.clear(); for (const QString &custom : customs) { const int index = custom.indexOf(QLatin1Char(':')); if (index == -1) { continue; } const QString qualifiedName = custom.left(index); const QString value = custom.mid(index + 1); d->mCustomFields.insert(qualifiedName, value); } } QStringList Addressee::customs() const { QStringList result; QHash::const_iterator it = d->mCustomFields.constBegin(); const QHash::const_iterator end = d->mCustomFields.constEnd(); result.reserve(d->mCustomFields.count()); while (it != end) { result << it.key() + QLatin1Char(':') + it.value(); ++it; } return result; } void Addressee::parseEmailAddress(const QString &rawEmail, QString &fullName, QString &email) { // This is a simplified version of KPIM::splitAddress(). fullName.clear(); email.clear(); if (rawEmail.isEmpty()) { return; // KPIM::AddressEmpty; } // The code works on 8-bit strings, so convert the input to UTF-8. QByteArray address = rawEmail.toUtf8(); QByteArray displayName; QByteArray addrSpec; QByteArray comment; // The following is a primitive parser for a mailbox-list (cf. RFC 2822). // The purpose is to extract a displayable string from the mailboxes. // Comments in the addr-spec are not handled. No error checking is done. enum sourceLevel { TopLevel, InComment, InAngleAddress }; sourceLevel context = TopLevel; bool inQuotedString = false; int commentLevel = 0; bool stop = false; for (char *p = address.data(); *p && !stop; ++p) { switch (context) { case TopLevel: switch (*p) { case '"': inQuotedString = !inQuotedString; displayName += *p; break; case '(': if (!inQuotedString) { context = InComment; commentLevel = 1; } else { displayName += *p; } break; case '<': if (!inQuotedString) { context = InAngleAddress; } else { displayName += *p; } break; case '\\': // quoted character displayName += *p; ++p; // skip the '\' if (*p) { displayName += *p; } else { //return KPIM::UnexpectedEnd; goto ABORT_PARSING; } break; case ',': if (!inQuotedString) { //if ( allowMultipleAddresses ) // stop = true; //else // return KPIM::UnexpectedComma; goto ABORT_PARSING; } else { displayName += *p; } break; default: displayName += *p; } break; case InComment: switch (*p) { case '(': ++commentLevel; comment += *p; break; case ')': --commentLevel; if (commentLevel == 0) { context = TopLevel; comment += ' '; // separate the text of several comments } else { comment += *p; } break; case '\\': // quoted character comment += *p; ++p; // skip the '\' if (*p) { comment += *p; } else { //return KPIM::UnexpectedEnd; goto ABORT_PARSING; } break; default: comment += *p; } break; case InAngleAddress: switch (*p) { case '"': inQuotedString = !inQuotedString; addrSpec += *p; break; case '>': if (!inQuotedString) { context = TopLevel; } else { addrSpec += *p; } break; case '\\': // quoted character addrSpec += *p; ++p; // skip the '\' if (*p) { addrSpec += *p; } else { //return KPIM::UnexpectedEnd; goto ABORT_PARSING; } break; default: addrSpec += *p; } break; } // switch ( context ) } ABORT_PARSING: displayName = displayName.trimmed(); comment = comment.trimmed(); addrSpec = addrSpec.trimmed(); fullName = QString::fromUtf8(displayName); email = QString::fromUtf8(addrSpec); // check for errors if (inQuotedString) { return; // KPIM::UnbalancedQuote; } if (context == InComment) { return; // KPIM::UnbalancedParens; } if (context == InAngleAddress) { return; // KPIM::UnclosedAngleAddr; } if (addrSpec.isEmpty()) { if (displayName.isEmpty()) { return; // KPIM::NoAddressSpec; } else { //addrSpec = displayName; //displayName.truncate( 0 ); // Address of the form "foo@bar" or "foo@bar (Name)". email = fullName; fullName = QString::fromUtf8(comment); } } email = email.toLower(); // Check that we do not have any extra characters on the end of the // strings unsigned int len = fullName.length(); if (fullName[0] == QLatin1Char('"') && fullName[len - 1] == QLatin1Char('"')) { fullName = fullName.mid(1, len - 2); } } void Addressee::setChanged(bool value) { d->mChanged = value; } bool Addressee::changed() const { return d->mChanged; } QString Addressee::mimeType() { return QStringLiteral("text/directory"); } QDataStream &KContacts::operator<<(QDataStream &s, const Addressee &a) { s << a.d->mUid; s << a.d->mName; s << a.d->mFormattedName; s << a.d->mFamilyName; s << a.d->mGivenName; s << a.d->mAdditionalName; s << a.d->mPrefix; s << a.d->mSuffix; s << a.d->mBirthday; s << a.d->mBirthdayWithTime; s << a.d->mMailer; s << a.d->mTimeZone; s << a.d->mGeo; s << a.d->mDepartment; s << a.d->mNote; s << a.d->mProductId; s << a.d->mRevision; s << a.d->mSortString; s << a.d->mSecrecy; s << a.d->mLogo; s << a.d->mPhoto; s << a.d->mSound; s << a.d->mPhoneNumbers; s << a.d->mAddresses; s << a.d->mEmails; s << a.d->mCategories; s << a.customs(); s << a.d->mKeys; s << a.d->mLangs; s << a.d->mGender; s << a.d->mKind; s << a.d->mCalendarUrl; s << a.d->mSoundListExtra; s << a.d->mPhotoExtraList; s << a.d->mLogoExtraList; s << a.d->mUrlExtraList; s << a.d->mMembers; s << a.d->mRelationShips; s << a.d->mSources; s << a.d->mImpps; s << a.d->mFieldGroupList; s << a.d->mTitleExtraList; s << a.d->mRoleExtraList; s << a.d->mOrgExtraList; s << a.d->mNickNameExtraList; s << a.d->mClientPidMapList; return s; } QDataStream &KContacts::operator>>(QDataStream &s, Addressee &a) { s >> a.d->mUid; s >> a.d->mName; s >> a.d->mFormattedName; s >> a.d->mFamilyName; s >> a.d->mGivenName; s >> a.d->mAdditionalName; s >> a.d->mPrefix; s >> a.d->mSuffix; s >> a.d->mBirthday; s >> a.d->mBirthdayWithTime; s >> a.d->mMailer; s >> a.d->mTimeZone; s >> a.d->mGeo; s >> a.d->mDepartment; s >> a.d->mNote; s >> a.d->mProductId; s >> a.d->mRevision; s >> a.d->mSortString; s >> a.d->mSecrecy; s >> a.d->mLogo; s >> a.d->mPhoto; s >> a.d->mSound; s >> a.d->mPhoneNumbers; s >> a.d->mAddresses; s >> a.d->mEmails; s >> a.d->mCategories; QStringList customFields; s >> customFields; a.setCustoms(customFields); s >> a.d->mKeys; s >> a.d->mLangs; s >> a.d->mGender; s >> a.d->mKind; s >> a.d->mCalendarUrl; s >> a.d->mSoundListExtra; s >> a.d->mPhotoExtraList; s >> a.d->mLogoExtraList; s >> a.d->mUrlExtraList; s >> a.d->mMembers; s >> a.d->mRelationShips; s >> a.d->mSources; s >> a.d->mImpps; s >> a.d->mFieldGroupList; s >> a.d->mTitleExtraList; s >> a.d->mRoleExtraList; s >> a.d->mOrgExtraList; s >> a.d->mNickNameExtraList; s >> a.d->mClientPidMapList; a.d->mEmpty = false; return s; } bool matchBinaryPattern(int value, int pattern) { /** We want to match all telephonnumbers/addresses which have the bits in the pattern set. More are allowed. if pattern == 0 we have a special handling, then we want only those with exactly no bit set. */ if (pattern == 0) { return value == 0; } else { return pattern == (pattern & value); } } template bool listEquals(const QVector &list, const QVector &pattern) { if (list.count() != pattern.count()) { return false; } const int numberOfElement(list.count()); for (int i = 0; i < numberOfElement; ++i) { if (!pattern.contains(list[i])) { return false; } } return true; } bool listEquals(const QStringList &list, const QStringList &pattern) { if (list.count() != pattern.count()) { return false; } const int numberOfElement(list.count()); for (int i = 0; i < numberOfElement; ++i) { if (!pattern.contains(list[i])) { return false; } } return true; } + +QVariantList Addressee::emailsVariant() const +{ + QVariantList l; + l.reserve(d->mEmails.size()); + std::transform(d->mEmails.constBegin(), d->mEmails.constEnd(), std::back_inserter(l), [](const Email &email) { + return QVariant::fromValue(email); + }); + return l; +} + +QVariantList Addressee::phoneNumbersVariant() const +{ + QVariantList l; + l.reserve(d->mPhoneNumbers.size()); + std::transform(d->mPhoneNumbers.constBegin(), d->mPhoneNumbers.constEnd(), std::back_inserter(l), [](const PhoneNumber &num) { + return QVariant::fromValue(num); + }); + return l; +} + +QVariantList Addressee::addressesVariant() const +{ + QVariantList l; + l.reserve(d->mAddresses.size()); + std::transform(d->mAddresses.constBegin(), d->mAddresses.constEnd(), std::back_inserter(l), [](const Address &addr) { + return QVariant::fromValue(addr); + }); + return l; +} + +#include "moc_addressee.cpp" diff --git a/src/addressee.h b/src/addressee.h index 62009f45..435e8663 100644 --- a/src/addressee.h +++ b/src/addressee.h @@ -1,1165 +1,1218 @@ /* This file is part of the KContacts framework. Copyright (c) 2001 Cornelius Schumacher 2013 Tobias Koenig This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KCONTACTS_ADDRESSEE_H #define KCONTACTS_ADDRESSEE_H #include #include #include #include #include #include "address.h" #include "geo.h" #include "key.h" #include "email.h" #include "lang.h" #include "gender.h" #include "phonenumber.h" #include "picture.h" #include "secrecy.h" #include "sound.h" #include "impp.h" #include "timezone.h" #include "calendarurl.h" #include "related.h" #include "addresseelist.h" #include "resourcelocatorurl.h" #include "fieldgroup.h" #include "title.h" #include "nickname.h" #include "role.h" #include "org.h" #include "clientpidmap.h" namespace KContacts { /** @short address book entry This class represents an entry in the address book. The data of this class is implicitly shared. You can pass this class by value. If you need the name of a field for presenting it to the user you should use the functions ending in Label(). They return a translated string which can be used as label for the corresponding field. About the name fields: givenName() is the first name and familyName() the last name. In some countries the family name comes first, that's the reason for the naming. formattedName() is the full name with the correct formatting. It is used as an override, when the correct formatting can't be generated from the other name fields automatically. realName() returns a fully formatted name(). It uses formattedName, if set, otherwise it constucts the name from the name fields. As fallback, if nothing else is set it uses name(). name() is the NAME type of RFC2426. It can be used as internal name for the data enty, but shouldn't be used for displaying the data to the user. */ class KCONTACTS_EXPORT Addressee { friend KCONTACTS_EXPORT QDataStream &operator<<(QDataStream &, const Addressee &); friend KCONTACTS_EXPORT QDataStream &operator>>(QDataStream &, Addressee &); + Q_GADGET + Q_PROPERTY(bool isEmpty READ isEmpty) + Q_PROPERTY(QString uid READ uid WRITE setUid) + Q_PROPERTY(QString name READ name WRITE setName) + Q_PROPERTY(QString formattedName READ formattedName WRITE setFormattedName) + Q_PROPERTY(QString familyName READ familyName WRITE setFamilyName) + Q_PROPERTY(QString givenName READ givenName WRITE setGivenName) + Q_PROPERTY(QString additionalName READ additionalName WRITE setAdditionalName) + Q_PROPERTY(QString prefix READ prefix WRITE setPrefix) + Q_PROPERTY(QString suffix READ suffix WRITE setSuffix) + Q_PROPERTY(QString nickName READ nickName) + Q_PROPERTY(QDateTime birthday READ birthday) // ### can't set this due to withTime argument + Q_PROPERTY(bool birthdayHasTime READ birthdayHasTime) + Q_PROPERTY(QString mailer READ mailer WRITE setMailer) + Q_PROPERTY(KContacts::Geo geo READ geo WRITE setGeo) + Q_PROPERTY(QString title READ title) + Q_PROPERTY(QString role READ role) + Q_PROPERTY(QString organization READ organization) + Q_PROPERTY(QString department READ department WRITE setDepartment) + Q_PROPERTY(QString note READ note WRITE setNote) + Q_PROPERTY(QString productId READ productId WRITE setProductId) + Q_PROPERTY(QDateTime revision READ revision) + Q_PROPERTY(QString sortString READ sortString WRITE setSortString) + Q_PROPERTY(KContacts::ResourceLocatorUrl url READ url WRITE setUrl) + Q_PROPERTY(QString realName READ realName) + Q_PROPERTY(QString assembledName READ assembledName) + Q_PROPERTY(QString preferredEmail READ preferredEmail) + Q_PROPERTY(QStringList categories READ categories WRITE setCategories) + Q_PROPERTY(QStringList customs READ customs) + Q_PROPERTY(bool changed READ changed WRITE setChanged) + Q_PROPERTY(QDate anniversary READ anniversary WRITE setAnniversary) + Q_PROPERTY(QString assistantsName READ assistantsName WRITE setAssistantsName) + Q_PROPERTY(QString managersName READ managersName WRITE setManagersName) + Q_PROPERTY(QString office READ office WRITE setOffice) + Q_PROPERTY(QString profession READ profession WRITE setProfession) + Q_PROPERTY(QString spousesName READ spousesName WRITE setSpousesName) + + // using variants for QML compatibility, can be changed to proper types once QML supports that + Q_PROPERTY(QVariantList emails READ emailsVariant) + Q_PROPERTY(QVariantList phoneNumbers READ phoneNumbersVariant) + Q_PROPERTY(QVariantList addresses READ addressesVariant) + + // ### the following properties are still missing: + // - logos, photos, sounds + // - keys + // - the list variants for nicks, titles, roles, orgs, urls + // - timezone, secrecy, gender, kind, members, relationships, impps, language + // - field groups, sourceUrls, calendarUrls + public: /** A list of addressee objects */ typedef AddresseeList List; /** A map from unique identifier to addressee. @see uid() */ typedef QHash Map; /** Construct an empty address book entry. */ Addressee(); /** Destroys the address book entry. */ ~Addressee(); /** Copy constructor. */ Addressee(const Addressee &other); /** Assignment operator. @return a reference to @c this */ Addressee &operator=(const Addressee &other); /** Equality operator. @return @c true if @c this and the given addressee are equal, otherwise @c false */ bool operator==(const Addressee &other) const; /** Not-equal operator. @return @c true if @c this and the given addressee are not equal, otherwise @c false */ bool operator!=(const Addressee &other) const; /** Return if the address book entry is empty. */ bool isEmpty() const; /** Set unique identifier. @param uid the KABC unique identifier */ void setUid(const QString &uid); /** Return unique identifier. */ QString uid() const; /** Return translated label for uid field. */ static QString uidLabel(); /** Set name. */ void setName(const QString &name); /** Return name. */ QString name() const; /** Return translated label for name field. */ static QString nameLabel(); /** Set formatted name. */ void setFormattedName(const QString &formattedName); /** Return formatted name. */ QString formattedName() const; /** Return translated label for formattedName field. */ static QString formattedNameLabel(); /** Set family name. */ void setFamilyName(const QString &familyName); /** Return family name. */ QString familyName() const; /** Return translated label for familyName field. */ static QString familyNameLabel(); /** Set given name. */ void setGivenName(const QString &givenName); /** Return given name. */ QString givenName() const; /** Return translated label for givenName field. */ static QString givenNameLabel(); /** Set additional names. */ void setAdditionalName(const QString &additionalName); /** Return additional names. */ QString additionalName() const; /** Return translated label for additionalName field. */ static QString additionalNameLabel(); /** Set honorific prefixes. */ void setPrefix(const QString &prefix); /** Return honorific prefixes. */ QString prefix() const; /** Return translated label for prefix field. */ static QString prefixLabel(); /** Set honorific suffixes. */ void setSuffix(const QString &suffix); /** Return honorific suffixes. */ QString suffix() const; /** Return translated label for suffix field. */ static QString suffixLabel(); /** Set nick name. */ void setNickName(const QString &nickName); void setNickName(const NickName &nickName); void insertExtraNickName(const NickName &nickName); void setExtraNickNameList(const NickName::List &nickNameList); NickName::List extraNickNameList() const; /** Return nick name. */ QString nickName() const; /** Return translated label for nickName field. */ static QString nickNameLabel(); /** Set birthday (date and time). If withTime is false the time will be set to midnight and birthdayHasTime() will return false afterwards. @since 5.4 */ void setBirthday(const QDateTime &birthday, bool withTime = true); /** Set birthday (date only). birthdayHasTime() will return false afterwards. */ void setBirthday(const QDate &birthday); /** Return birthday. (If a valid date has been set, birthday().time() will always return a valid QTime!) */ QDateTime birthday() const; /** Returns true if birthday has been set with a time. Returns false otherwise. */ bool birthdayHasTime() const; /** Return translated label for birthday field. */ static QString birthdayLabel(); /** Return translated label for homeAddressStreet field. */ static QString homeAddressStreetLabel(); /** Return translated label for homeAddressPostOfficeBox field. */ static QString homeAddressPostOfficeBoxLabel(); /** Return translated label for homeAddressLocality field. */ static QString homeAddressLocalityLabel(); /** Return translated label for homeAddressRegion field. */ static QString homeAddressRegionLabel(); /** Return translated label for homeAddressPostalCode field. */ static QString homeAddressPostalCodeLabel(); /** Return translated label for homeAddressCountry field. */ static QString homeAddressCountryLabel(); /** Return translated label for homeAddressLabel field. */ static QString homeAddressLabelLabel(); /** Return translated label for businessAddressStreet field. */ static QString businessAddressStreetLabel(); /** Return translated label for businessAddressPostOfficeBox field. */ static QString businessAddressPostOfficeBoxLabel(); /** Return translated label for businessAddressLocality field. */ static QString businessAddressLocalityLabel(); /** Return translated label for businessAddressRegion field. */ static QString businessAddressRegionLabel(); /** Return translated label for businessAddressPostalCode field. */ static QString businessAddressPostalCodeLabel(); /** Return translated label for businessAddressCountry field. */ static QString businessAddressCountryLabel(); /** Return translated label for businessAddressLabel field. */ static QString businessAddressLabelLabel(); /** Return translated label for homePhone field. */ static QString homePhoneLabel(); /** Return translated label for businessPhone field. */ static QString businessPhoneLabel(); /** Return translated label for mobilePhone field. */ static QString mobilePhoneLabel(); /** Return translated label for homeFax field. */ static QString homeFaxLabel(); /** Return translated label for businessFax field. */ static QString businessFaxLabel(); /** Return translated label for carPhone field. */ static QString carPhoneLabel(); /** Return translated label for isdn field. */ static QString isdnLabel(); /** Return translated label for pager field. */ static QString pagerLabel(); /** Return translated label for email field. */ static QString emailLabel(); /** Set mail client. */ void setMailer(const QString &mailer); /** Return mail client. */ QString mailer() const; /** Return translated label for mailer field. */ static QString mailerLabel(); /** Set time zone. */ void setTimeZone(const TimeZone &timeZone); /** Return time zone. */ TimeZone timeZone() const; /** Return translated label for timeZone field. */ static QString timeZoneLabel(); /** Set geographic position. */ void setGeo(const Geo &geo); /** Return geographic position. */ Geo geo() const; /** Return translated label for geo field. */ static QString geoLabel(); /** Set title. */ //Remove in kf6 void setTitle(const QString &title); void setTitle(const Title &title); void insertExtraTitle(const Title &title); void setExtraTitleList(const Title::List &urltitle); Title::List extraTitleList() const; /** Return title. */ QString title() const; /** Return translated label for title field. */ static QString titleLabel(); /** Set role. */ void setRole(const QString &role); void setRole(const Role &role); void insertExtraRole(const Role &role); void setExtraRoleList(const Role::List &roleList); Role::List extraRoleList() const; /** Return role. */ QString role() const; /** Return translated label for role field. */ static QString roleLabel(); /** Set organization. */ //Remove in kf6 void setOrganization(const QString &organization); void setOrganization(const Org &organization); void insertExtraOrganization(const Org &organization); void setExtraOrganizationList(const Org::List &orgList); Org::List extraOrganizationList() const; /** Return organization. */ QString organization() const; /** Return translated label for organization field. */ static QString organizationLabel(); /** Set department. */ void setDepartment(const QString &department); /** Return department. */ QString department() const; /** Return translated label for department field. */ static QString departmentLabel(); /** Set note. */ void setNote(const QString ¬e); /** Return note. */ QString note() const; /** Return translated label for note field. */ static QString noteLabel(); /** Set product identifier. */ void setProductId(const QString &productId); /** Return product identifier. */ QString productId() const; /** Return translated label for productId field. */ static QString productIdLabel(); /** Set revision date. */ void setRevision(const QDateTime &revision); /** Return revision date. */ QDateTime revision() const; /** Return translated label for revision field. */ static QString revisionLabel(); /** Set sort string. */ void setSortString(const QString &sortString); /** Return sort string. */ QString sortString() const; /** Return translated label for sortString field. */ static QString sortStringLabel(); /** Set homepage. */ void setUrl(const ResourceLocatorUrl &url); //kf6: remove it void setUrl(const QUrl &url); /** Return homepage. */ ResourceLocatorUrl url() const; /** Return translated label for url field. */ static QString urlLabel(); /** Set security class. */ void setSecrecy(const Secrecy &secrecy); /** Return security class. */ Secrecy secrecy() const; /** Return translated label for secrecy field. */ static QString secrecyLabel(); /** Set logo. */ void setLogo(const Picture &logo); /** Return logo. */ Picture logo() const; /** Return translated label for logo field. */ static QString logoLabel(); /** Set photo. */ void setPhoto(const Picture &photo); /** Return photo. */ Picture photo() const; /** Return translated label for photo field. */ static QString photoLabel(); /** Set sound. */ void setSound(const Sound &sound); /** Return sound. */ Sound sound() const; /** Return translated label for sound field. */ static QString soundLabel(); /** Set name fields by parsing the given string and trying to associate the parts of the string with according fields. This function should probably be a bit more clever. */ void setNameFromString(const QString &s); /** Return the name of the addressee. This is calculated from all the name fields. */ QString realName() const; /** Return the name that consists of all name parts. */ QString assembledName() const; /** Return email address including real name. @param email Email address to be used to construct the full email string. If this is QString() the preferred email address is used. */ QString fullEmail(const QString &email = QString()) const; /** Insert an email address. If the email address already exists in this addressee it is not duplicated. @param email Email address @param preferred Set to true, if this is the preferred email address of the addressee. */ void insertEmail(const QString &email, bool preferred = false, const QMap ¶m = QMap()); /** Remove email address. If the email address doesn't exist, nothing happens. @param email Email address to remove */ void removeEmail(const QString &email); /** Return preferred email address. This is the first email address or the last one added with insertEmail() with a set preferred parameter. */ QString preferredEmail() const; /** Return list of all email addresses. */ QStringList emails() const; /** Set the emails to @p list. The first email address gets the preferred one! @param list The list of email addresses. */ void setEmails(const QStringList &list); /** Insert a phone number. If a phone number with the same id already exists in this addressee it is not duplicated. @param phoneNumber The telephone number to insert to the addressee */ void insertPhoneNumber(const PhoneNumber &phoneNumber); /** Remove phone number. If no phone number with the given id exists for this addresse nothing happens. @param phoneNumber The telephone number to remove from the addressee */ void removePhoneNumber(const PhoneNumber &phoneNumber); /** Return phone number, which matches the given type. @param type The type of phone number to get */ PhoneNumber phoneNumber(PhoneNumber::Type type) const; /** Return list of all phone numbers. */ PhoneNumber::List phoneNumbers() const; void setPhoneNumbers(const PhoneNumber::List &phoneNumbers); /** Return list of phone numbers with a special type. @param type The type of phone number to get */ PhoneNumber::List phoneNumbers(PhoneNumber::Type type) const; /** Return phone number with the given id. @param id The identifier of the phone number to look for. See PhoneNumber::id() */ PhoneNumber findPhoneNumber(const QString &id) const; /** Insert a key. If a key with the same id already exists in this addressee it is not duplicated. @param key The key to insert */ void insertKey(const Key &key); /** Remove a key. If no key with the given id exists for this addresse nothing happens. @param key The key to remove */ void removeKey(const Key &key); /** Return key, which matches the given type. If @p type == Key::Custom you can specify a string that should match. If you leave the string empty, the first key with a custom value is returned. @param type The type of key to look for @param customTypeString A string to match custom keys against when @p type is @c Key::Custom */ Key key(Key::Type type, const QString &customTypeString = QString()) const; /** Return list of all keys. */ Key::List keys() const; /** Set the list of keys @param keys The keys to be set. */ void setKeys(const Key::List &keys); /** Return list of keys with a special type. If @p type == Key::Custom you can specify a string that should match. If you leave the string empty, all custom keys will be returned. @param type The type of key to look for @param customTypeString A string to match custom keys against when @p type is @c Key::Custom */ Key::List keys(Key::Type type, const QString &customTypeString = QString()) const; /** Return key with the given id. @param id The identifier of the key to look for. See Key::id() */ Key findKey(const QString &id) const; /** Insert an address. If an address with the same id already exists in this addressee it is not duplicated. @param address The address to insert */ void insertAddress(const Address &address); /** Remove address. If no address with the given id exists for this addresse nothing happens. @param address The address to remove */ void removeAddress(const Address &address); /** Return address, which matches the given type. @param type The type of address to look for */ Address address(Address::Type type) const; /** Return list of all addresses. */ Address::List addresses() const; /** Return list of addresses with a special type. @param type The type of addresses to look for */ Address::List addresses(Address::Type type) const; /** Return address with the given id. @param id The identifier of the address to look for. See Address::id() */ Address findAddress(const QString &id) const; /** Insert category. If the category already exists it is not duplicated. */ void insertCategory(const QString &category); /** Remove category. */ void removeCategory(const QString &category); /** Return, if addressee has the given category. */ bool hasCategory(const QString &category) const; /** Set categories to given value. */ void setCategories(const QStringList &category); /** Return list of all set categories. */ QStringList categories() const; /** Insert custom entry. The entry is identified by the name of the inserting application and a unique name. If an entry with the given app and name already exists its value is replaced with the new given value. An empty value isn't allowed (nothing happens if this is called with any of the three arguments being empty) @param app Name of the application inserting this custom entry @param name Name of this application specific custom entry @param value Value of this application specific custom entry */ void insertCustom(const QString &app, const QString &name, const QString &value); /** Remove custom entry. @param app Name of the application which has inserted this custom entry @param name Name of this application specific custom entry */ void removeCustom(const QString &app, const QString &name); /** Return value of custom entry, identified by app and entry name. @param app Name of the application which has inserted this custom entry @param name Name of this application specific custom entry */ QString custom(const QString &app, const QString &name) const; /** Set all custom entries. */ void setCustoms(const QStringList &customs); /** Return list of all custom entries. The format of the custom entries is 'app-key:value' and the list is sorted alphabetically by 'app-key'. */ QStringList customs() const; /** Parse full email address. The result is given back in fullName and email. @param rawEmail The input string to parse for name and email @param fullName The name part of the @p rawEmail input, if it contained one @param email The email part of the @p rawEmail input, if it contained one */ static void parseEmailAddress(const QString &rawEmail, QString &fullName, QString &email); /** Returns string representation of the addressee. */ QString toString() const; /** Mark addressee as changed. @param value Sets the status indicating changed data */ void setChanged(bool value); /** Return whether the addressee is changed. */ bool changed() const; /** Returns the MIME type used for Addressees */ static QString mimeType(); KContacts::Email::List emailList() const; void setEmailList(const Email::List &list); /** * Remove Language * @brief removeLang * @param language */ void removeLang(const QString &language); /** * Insert Language * @brief insertLang * @param language */ void insertLang(const Lang &language); /** * @brief langs * @return List of lang */ Lang::List langs() const; void setLangs(const Lang::List &langs); void setGender(const Gender &gender); Gender gender() const; QString kind() const; void setKind(const QString &kind); void insertCalendarUrl(const CalendarUrl &calendarUrl); CalendarUrl::List calendarUrlList() const; void insertExtraSound(const Sound &sound); void setExtraSoundList(const Sound::List &soundList); Sound::List extraSoundList() const; void insertExtraPhoto(const Picture &picture); void setExtraPhotoList(const Picture::List &pictureList); Picture::List extraPhotoList() const; void insertExtraLogo(const Picture &logo); void setExtraLogoList(const Picture::List &logoList); Picture::List extraLogoList() const; ResourceLocatorUrl::List extraUrlList() const; void setExtraUrlList(const ResourceLocatorUrl::List &urlList); void insertExtraUrl(const ResourceLocatorUrl &url); //Member void insertMember(const QString &member); void setMembers(const QStringList &c); QStringList members() const; //Relation void insertRelationShip(const Related &related); void setRelationShips(const Related::List &c); Related::List relationShips() const; //Source void insertSourceUrl(const QUrl &url); void setSourcesUrlList(const QVector &urlList); QVector sourcesUrlList() const; //Impp Impp::List imppList() const; void setImppList(const Impp::List &imppList); void insertImpp(const Impp &impp); //FieldGroup FieldGroup::List fieldGroupList() const; void setFieldGroupList(const FieldGroup::List &fieldGroupList); void insertFieldGroup(const FieldGroup &fieldGroup); //ClientPidMap ClientPidMap::List clientPidMapList() const; void setClientPidMapList(const ClientPidMap::List &clientpidmaplist); void insertClientPidMap(const ClientPidMap &clientpidmap); /** * Returns the contact's anniversary date. * @note This is a non-standard extension using the @c X-Anniversary field. * @since 5.12 */ QDate anniversary() const; /** * Sets the contact's anniversary date. * @note This is a non-standard extension using the @c X-Anniversary field. * @since 5.12 */ void setAnniversary(const QDate &anniversary); /** * Returns the contact's assistant's name. * @note This is a non-standard extension using the @c X-AssistantsName field. * @since 5.12 */ QString assistantsName() const; /** * Set the contact's assistant's name. * @note This is a non-standard extension using the @c X-AssistantsName field. * @since 5.12 */ void setAssistantsName(const QString &assistantsName); /** * Returns the contact's blog feed. * @note This is a non-standard extension using the @c BlogFeed field. * @since 5.12 */ QString blogFeed() const; /** * Set the contact's blog feed. * @note This is a non-standard extension using the @c BlogFeed field. * @since 5.12 */ void setBlogFeed(const QString &blogFeed); /** * Returns the contact's manager's name. * @note This is a non-standard extension using the @c X-ManagersName field. * @since 5.12 */ QString managersName() const; /** * Set the contact's manager's name. * @note This is a non-standard extension using the @c X-ManagersName field. * @since 5.12 */ void setManagersName(const QString &managersName); /** * Returns the contact's office. * @note This is a non-standard extension using the @c X-Office field. * @since 5.12 */ QString office() const; /** * Set the contact's office. * @note This is a non-standard extension using the @c X-Office field. * @since 5.12 */ void setOffice(const QString &office); /** * Returns the contact's profession. * @note This is a non-standard extension using the @c X-Profession field. * @since 5.12 */ QString profession() const; /** * Set the contact's profession. * @note This is a non-standard extension using the @c X-Profession field. * @since 5.12 */ void setProfession(const QString &profession); /** * Returns the contact's spouse's name. * @note This is a non-standard extension using the @c X-SpousesName field. * @since 5.12 */ QString spousesName() const; /** * Set the contact's spouse's name. * @note This is a non-standard extension using the @c X-SpousesName field. * @since 5.12 */ void setSpousesName(const QString &spousesName); private: + QVariantList emailsVariant() const; + QVariantList phoneNumbersVariant() const; + QVariantList addressesVariant() const; + class Private; QSharedDataPointer d; }; KCONTACTS_EXPORT QDataStream &operator<<(QDataStream &, const Addressee &); KCONTACTS_EXPORT QDataStream &operator>>(QDataStream &, Addressee &); } #define KCONTACTS_ADDRESSEE_METATYPE_DEFINED 1 Q_DECLARE_METATYPE(KContacts::Addressee) #endif diff --git a/src/email.h b/src/email.h index cb964d76..bc633ec5 100644 --- a/src/email.h +++ b/src/email.h @@ -1,74 +1,82 @@ /* This file is part of the KContacts framework. Copyright (C) 2015-2019 Laurent Montel This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef EMAIL_H #define EMAIL_H #include "kcontacts_export.h" + +#include +#include #include #include -#include /** @short Class that holds a Email for a contact. * @since 4.14.5 */ namespace KContacts { class KCONTACTS_EXPORT Email { friend KCONTACTS_EXPORT QDataStream &operator<<(QDataStream &, const Email &); friend KCONTACTS_EXPORT QDataStream &operator>>(QDataStream &, Email &); + + Q_GADGET + Q_PROPERTY(QString email READ mail WRITE setEmail) + Q_PROPERTY(bool isValid READ isValid) + public: /** * Creates an empty email object. */ Email(); Email(const Email &other); Email(const QString &mail); ~Email(); typedef QVector List; void setEmail(const QString &mail); Q_REQUIRED_RESULT QString mail() const; Q_REQUIRED_RESULT bool isValid() const; void setParameters(const QMap ¶ms); Q_REQUIRED_RESULT QMap parameters() const; Q_REQUIRED_RESULT bool operator==(const Email &other) const; Q_REQUIRED_RESULT bool operator!=(const Email &other) const; Email &operator=(const Email &other); Q_REQUIRED_RESULT QString toString() const; private: class Private; QSharedDataPointer d; }; KCONTACTS_EXPORT QDataStream &operator<<(QDataStream &stream, const Email &object); KCONTACTS_EXPORT QDataStream &operator>>(QDataStream &stream, Email &object); } +Q_DECLARE_METATYPE(KContacts::Email) Q_DECLARE_TYPEINFO(KContacts::Email, Q_MOVABLE_TYPE); #endif // EMAIL_H diff --git a/src/geo.h b/src/geo.h index 29d23cb1..3b9421c4 100644 --- a/src/geo.h +++ b/src/geo.h @@ -1,139 +1,147 @@ /* This file is part of the KContacts framework. Copyright (c) 2001 Cornelius Schumacher This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KCONTACTS_GEO_H #define KCONTACTS_GEO_H #include "kcontacts_export.h" + +#include #include #include namespace KContacts { /** * @short Geographic position * * This class represents a geographic position. */ class KCONTACTS_EXPORT Geo { friend KCONTACTS_EXPORT QDataStream &operator<<(QDataStream &, const Geo &); friend KCONTACTS_EXPORT QDataStream &operator>>(QDataStream &, Geo &); + Q_GADGET + Q_PROPERTY(float latitude READ latitude WRITE setLatitude) + Q_PROPERTY(float longitude READ longitude WRITE setLongitude) + Q_PROPERTY(bool isValid READ isValid) + public: /** * Creates an invalid geographics position object. */ Geo(); /** * Creates a geographics position object. * * @param latitude Geographical latitude * @param longitude Geographical longitude */ Geo(float latitude, float longitude); /** * Copy constructor. */ Geo(const Geo &other); /** * Destroys the geographics position object. */ ~Geo(); /** * Sets the @p latitude. * * @param latitude The location's latitude coordinate */ void setLatitude(float latitude); /** * Returns the latitude. */ Q_REQUIRED_RESULT float latitude() const; /** * Sets the @p longitude. * * @param longitude The location's longitude coordinate */ void setLongitude(float longitude); /** * Returns the longitude. */ Q_REQUIRED_RESULT float longitude() const; /** * Returns, whether this object contains a valid geographical position. */ Q_REQUIRED_RESULT bool isValid() const; /** * Equality operator. * * @note Two invalid Geo instance will return @c true */ Q_REQUIRED_RESULT bool operator==(const Geo &other) const; /** * Not-Equal operator. */ bool operator!=(const Geo &other) const; /** * Assignment operator. * * @param other The Geo instance to assign to @c this */ Geo &operator=(const Geo &other); /** * Returns string representation of geographical position. */ Q_REQUIRED_RESULT QString toString() const; /** * Clears the class, marking it as invalid. * * @since 5.6 */ void clear(); private: class Private; QSharedDataPointer d; }; /** * Serializes the geographical position @p object into the @p stream. */ KCONTACTS_EXPORT QDataStream &operator<<(QDataStream &stream, const Geo &object); /** * Initializes the geographical position @p object from the @p stream. */ KCONTACTS_EXPORT QDataStream &operator>>(QDataStream &stream, Geo &object); } +Q_DECLARE_METATYPE(KContacts::Geo) Q_DECLARE_TYPEINFO(KContacts::Geo, Q_MOVABLE_TYPE); #endif diff --git a/src/phonenumber.h b/src/phonenumber.h index ad09b052..b4972e38 100644 --- a/src/phonenumber.h +++ b/src/phonenumber.h @@ -1,244 +1,255 @@ /* This file is part of the KContacts framework. Copyright (c) 2001 Cornelius Schumacher This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KCONTACTS_PHONENUMBER_H #define KCONTACTS_PHONENUMBER_H #include "kcontacts_export.h" +#include +#include #include #include #include -#include namespace KContacts { /** * @short Phonenumber information. * * This class provides phone number information. A phone number is classified by * a type. The following types are available, it's possible to use multiple types * Types for a number by combining them through a logical or. */ class KCONTACTS_EXPORT PhoneNumber { friend KCONTACTS_EXPORT QDataStream &operator<<(QDataStream &, const PhoneNumber &); friend KCONTACTS_EXPORT QDataStream &operator>>(QDataStream &, PhoneNumber &); + Q_GADGET + Q_PROPERTY(QString id READ id WRITE setId) + Q_PROPERTY(QString number READ number WRITE setNumber) + Q_PROPERTY(QString normalizedNumber READ normalizedNumber) + Q_PROPERTY(Type type READ type WRITE setType) + Q_PROPERTY(QString typeLabel READ typeLabel) + Q_PROPERTY(bool isEmpty READ isEmpty) + public: /** Phone number types. */ enum TypeFlag { Home = 1, /**< Home number */ Work = 2, /**< Office number */ Msg = 4, /**< Messaging */ Pref = 8, /**< Preferred number */ Voice = 16, /**< Voice */ Fax = 32, /**< Fax machine */ Cell = 64, /**< Cell phone */ Video = 128, /**< Video phone */ Bbs = 256, /**< Mailbox */ Modem = 512, /**< Modem */ Car = 1024, /**< Car phone */ Isdn = 2048, /**< ISDN connection */ Pcs = 4096, /**< Personal Communication Service*/ Pager = 8192, /**< Pager */ //TODO add Text and textphone support vcard4 Undefined = 16384 /** Undefined number type */ }; Q_DECLARE_FLAGS(Type, TypeFlag) + Q_FLAG(Type) /** * List of phone number types. */ typedef QVector TypeList; /** * List of phone numbers. */ typedef QVector List; /** * Creates an empty phone number object. */ PhoneNumber(); /** * Creates a phone number object. * * @param number Number * @param type Type as defined in enum. Multiple types can be * specified by combining them by a logical or. */ PhoneNumber(const QString &number, Type type = Home); //krazy:exclude=explicit /** * Copy constructor. * * Fast operation, PhoneNumber's data is implicitly shared. * * @param other The PhoneNumber object to copy from */ PhoneNumber(const PhoneNumber &other); /** * Destroys the phone number. */ ~PhoneNumber(); /** * Equality operator. * * @return @c true if number, type and identifier are equal, * otherwise @c false */ Q_REQUIRED_RESULT bool operator==(const PhoneNumber &other) const; /** * Not-Equal operator. */ Q_REQUIRED_RESULT bool operator!=(const PhoneNumber &other) const; /** * Assignment operator. * * Fast operation, PhoneNumber's data is implicitly shared. * * @param other The PhoneNumber object to asssign to @c this */ PhoneNumber &operator=(const PhoneNumber &other); /** * Returns true, if the phone number is empty. */ Q_REQUIRED_RESULT bool isEmpty() const; /** * Sets the unique @p identifier. */ void setId(const QString &identifier); /** * Returns the unique identifier. */ Q_REQUIRED_RESULT QString id() const; /** * Sets the phone @p number. */ void setNumber(const QString &number); /** * Returns the phone number. * This is the number as entered/stored with all formatting preserved. Preferred for display. * @see normalizedNumber() */ Q_REQUIRED_RESULT QString number() const; /** * Returns the phone number normalized for dialing. * This has all formatting stripped for passing to dialers or tel: URLs. * @see number() * @since 5.12 */ Q_REQUIRED_RESULT QString normalizedNumber() const; /** * Sets the @p type. * Multiple types can be specified by combining them by a logical or. * * @param type The #Type of the phone number */ void setType(Type type); /** * Returns the type. Can be a multiple types combined by a logical or. * * @see #TypeFlag * @see typeLabel() */ Q_REQUIRED_RESULT Type type() const; /** * Returns a translated string of the address' type. */ Q_REQUIRED_RESULT QString typeLabel() const; /** * Returns a list of all available types */ Q_REQUIRED_RESULT static TypeList typeList(); /** * Returns the translated label for phone number @p type. * * In opposite to typeFlagLabel( TypeFlag type ), it returns all types * of the phone number concatenated by '/'. * * @param type An OR'ed combination of #TypeFlag * * @see type() */ static QString typeLabel(Type type); /** * Returns the translated label for phone number @p type. * * @param type An OR'ed combination of #TypeFlag * * @see typeLabel() * @since 4.5 */ Q_REQUIRED_RESULT static QString typeFlagLabel(TypeFlag type); /** * Returns a string representation of the phone number. */ QString toString() const; void setParameters(const QMap ¶ms); Q_REQUIRED_RESULT QMap parameters() const; private: class Private; QSharedDataPointer d; }; Q_DECLARE_OPERATORS_FOR_FLAGS(PhoneNumber::Type) /** * Serializes the phone @p number object into the @p stream. * * @param stream The stream to write into * @param number The phone number object to serialize */ KCONTACTS_EXPORT QDataStream &operator<<(QDataStream &stream, const PhoneNumber &number); /** * Initializes the phone @p number object from the @p stream. * * @param stream The stream to read from * @param number The phone number object to deserialize into */ KCONTACTS_EXPORT QDataStream &operator>>(QDataStream &stream, PhoneNumber &number); } +Q_DECLARE_METATYPE(KContacts::PhoneNumber) Q_DECLARE_TYPEINFO(KContacts::PhoneNumber, Q_MOVABLE_TYPE); #endif diff --git a/src/resourcelocatorurl.cpp b/src/resourcelocatorurl.cpp index 5781e1ab..015fdffe 100644 --- a/src/resourcelocatorurl.cpp +++ b/src/resourcelocatorurl.cpp @@ -1,132 +1,131 @@ /* This file is part of the KContacts framework. Copyright (C) 2015-2019 Laurent Montel This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "resourcelocatorurl.h" #include -#include #include #include using namespace KContacts; class Q_DECL_HIDDEN ResourceLocatorUrl::Private : public QSharedData { public: Private() { } Private(const Private &other) : QSharedData(other) { parameters = other.parameters; url = other.url; } QMap parameters; QUrl url; }; ResourceLocatorUrl::ResourceLocatorUrl() : d(new Private) { } ResourceLocatorUrl::ResourceLocatorUrl(const ResourceLocatorUrl &other) : d(other.d) { } ResourceLocatorUrl::~ResourceLocatorUrl() { } QMap ResourceLocatorUrl::parameters() const { return d->parameters; } bool ResourceLocatorUrl::operator==(const ResourceLocatorUrl &other) const { return (d->parameters == other.parameters()) && (d->url == other.url()); } bool ResourceLocatorUrl::operator!=(const ResourceLocatorUrl &other) const { return !(other == *this); } ResourceLocatorUrl &ResourceLocatorUrl::operator=(const ResourceLocatorUrl &other) { if (this != &other) { d = other.d; } return *this; } QString ResourceLocatorUrl::toString() const { QString str = QLatin1String("ResourceLocatorUrl {\n"); str += QStringLiteral(" url: %1\n").arg(d->url.toString()); if (!d->parameters.isEmpty()) { QString param; QMap::const_iterator it = d->parameters.constBegin(); const QMap::const_iterator end = d->parameters.constEnd(); while (it != end) { param += QStringLiteral("%1 %2").arg(it.key(), it.value().join(QLatin1Char(','))); ++it; } str += QStringLiteral(" parameters: %1\n").arg(param); } str += QLatin1String("}\n"); return str; } void ResourceLocatorUrl::setParameters(const QMap ¶ms) { d->parameters = params; } bool ResourceLocatorUrl::isValid() const { return d->url.isValid(); } void ResourceLocatorUrl::setUrl(const QUrl &url) { d->url = url; } QUrl ResourceLocatorUrl::url() const { return d->url; } QDataStream &KContacts::operator<<(QDataStream &s, const ResourceLocatorUrl &calUrl) { return s << calUrl.d->parameters << calUrl.d->url; } QDataStream &KContacts::operator>>(QDataStream &s, ResourceLocatorUrl &calUrl) { s >> calUrl.d->parameters >> calUrl.d->url; return s; } diff --git a/src/resourcelocatorurl.h b/src/resourcelocatorurl.h index 24c96500..fc5acf42 100644 --- a/src/resourcelocatorurl.h +++ b/src/resourcelocatorurl.h @@ -1,73 +1,81 @@ /* This file is part of the KContacts framework. Copyright (C) 2015-2019 Laurent Montel This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef RESOURCELOCATORURL_H #define RESOURCELOCATORURL_H #include "kcontacts_export.h" +#include +#include #include #include -#include -class QUrl; +#include + /** @short Class that holds a Resource Locator * @since 5.0 */ namespace KContacts { class KCONTACTS_EXPORT ResourceLocatorUrl { friend KCONTACTS_EXPORT QDataStream &operator<<(QDataStream &, const ResourceLocatorUrl &); friend KCONTACTS_EXPORT QDataStream &operator>>(QDataStream &, ResourceLocatorUrl &); + + Q_GADGET + Q_PROPERTY(QUrl url READ url WRITE setUrl) + Q_PROPERTY(bool isValid READ isValid) + public: ResourceLocatorUrl(); ResourceLocatorUrl(const ResourceLocatorUrl &other); ~ResourceLocatorUrl(); typedef QVector List; Q_REQUIRED_RESULT bool isValid() const; void setUrl(const QUrl &url); Q_REQUIRED_RESULT QUrl url() const; void setParameters(const QMap ¶ms); Q_REQUIRED_RESULT QMap parameters() const; Q_REQUIRED_RESULT bool operator==(const ResourceLocatorUrl &other) const; Q_REQUIRED_RESULT bool operator!=(const ResourceLocatorUrl &other) const; ResourceLocatorUrl &operator=(const ResourceLocatorUrl &other); Q_REQUIRED_RESULT QString toString() const; private: class Private; QSharedDataPointer d; }; KCONTACTS_EXPORT QDataStream &operator<<(QDataStream &stream, const ResourceLocatorUrl &object); KCONTACTS_EXPORT QDataStream &operator>>(QDataStream &stream, ResourceLocatorUrl &object); } +Q_DECLARE_METATYPE(KContacts::ResourceLocatorUrl) Q_DECLARE_TYPEINFO(KContacts::ResourceLocatorUrl, Q_MOVABLE_TYPE); #endif // RESOURCELOCATORURL_H