diff --git a/autotests/phonenumbertest.cpp b/autotests/phonenumbertest.cpp index cc8d7c9f..eb26cf38 100644 --- a/autotests/phonenumbertest.cpp +++ b/autotests/phonenumbertest.cpp @@ -1,348 +1,350 @@ /* This file is part of the KContacts framework. Copyright (c) 2007 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. */ #include "phonenumbertest.h" #include "kcontacts/phonenumber.h" #include #include #include #include QTEST_MAIN(PhoneNumberTest) #ifndef Q_OS_WIN void initLocale() { qputenv("LC_ALL", "en_US.utf-8"); } Q_CONSTRUCTOR_FUNCTION(initLocale) #endif void PhoneNumberTest::emptyTest() { KContacts::PhoneNumber number; QVERIFY(number.isEmpty()); } void PhoneNumberTest::storeTest() { KContacts::PhoneNumber number; number.setId(QStringLiteral("My Id")); number.setType(KContacts::PhoneNumber::Work | KContacts::PhoneNumber::Cell); number.setNumber(QStringLiteral("2734826345")); QVERIFY(number.id() == QLatin1String("My Id")); QVERIFY(number.type() == (KContacts::PhoneNumber::Work | KContacts::PhoneNumber::Cell)); QVERIFY(number.number() == QLatin1String("2734826345")); } void PhoneNumberTest::equalsTest() { KContacts::PhoneNumber number1, number2; number1.setId(QStringLiteral("My Id")); number1.setType(KContacts::PhoneNumber::Work | KContacts::PhoneNumber::Cell); number1.setNumber(QStringLiteral("2734826345")); number2.setId(QStringLiteral("My Id")); number2.setType(KContacts::PhoneNumber::Work | KContacts::PhoneNumber::Cell); number2.setNumber(QStringLiteral("2734826345")); QVERIFY(number1 == number2); } void PhoneNumberTest::differsTest() { KContacts::PhoneNumber number1(QStringLiteral("123"), KContacts::PhoneNumber::Home); KContacts::PhoneNumber number2(QStringLiteral("123"), KContacts::PhoneNumber::Work); QVERIFY(number1 != number2); } void PhoneNumberTest::assignmentTest() { KContacts::PhoneNumber number1, number2; number1.setId(QStringLiteral("My Id")); number1.setType(KContacts::PhoneNumber::Work | KContacts::PhoneNumber::Cell); number1.setNumber(QStringLiteral("2734826345")); number1 = number2; QVERIFY(number1 == number2); } void PhoneNumberTest::serializeTest() { KContacts::PhoneNumber number1, number2; number1.setId(QStringLiteral("My Id")); number1.setType(KContacts::PhoneNumber::Work | KContacts::PhoneNumber::Cell); number1.setNumber(QStringLiteral("2734826345")); QByteArray data; QDataStream s(&data, QIODevice::WriteOnly); s << number1; QDataStream t(&data, QIODevice::ReadOnly); t >> number2; QVERIFY(number1 == number2); } void PhoneNumberTest::labelTest() { QMap labels; const KContacts::PhoneNumber::TypeList types = KContacts::PhoneNumber::typeList(); // check all types standalone for (KContacts::PhoneNumber::Type type : types) { const KContacts::PhoneNumber phone(QStringLiteral("1"), type); QCOMPARE(phone.type(), type); // Pref is special cased if (type != KContacts::PhoneNumber::Pref) { QCOMPARE(phone.typeLabel(), KContacts::PhoneNumber::typeFlagLabel((KContacts::PhoneNumber::TypeFlag)(int)type)); labels.insert(type, phone.typeLabel()); } else { labels.insert(type, KContacts::PhoneNumber::typeFlagLabel((KContacts::PhoneNumber::TypeFlag)(int)type)); } QCOMPARE(KContacts::PhoneNumber::typeLabel(type), phone.typeLabel()); } // combine all with Pref for (KContacts::PhoneNumber::Type type : qAsConst(types)) { KContacts::PhoneNumber::Type combinedType = type | KContacts::PhoneNumber::Pref; const KContacts::PhoneNumber phone(QLatin1String("1"), combinedType); QCOMPARE(phone.type(), combinedType); QCOMPARE(KContacts::PhoneNumber::typeLabel(combinedType), phone.typeLabel()); if (type < KContacts::PhoneNumber::Pref) { const QString expectedCombinedString = QStringLiteral("%1/%2").arg(labels[type]).arg(labels[KContacts::PhoneNumber::Pref]); QCOMPARE(phone.typeLabel(), expectedCombinedString); } else if (type > KContacts::PhoneNumber::Pref) { const QString expectedCombinedString = QStringLiteral("%1/%2").arg(labels[KContacts::PhoneNumber::Pref]).arg(labels[type]); QCOMPARE(phone.typeLabel(), expectedCombinedString); } } // combine all with Fax for (KContacts::PhoneNumber::Type type : qAsConst(types)) { KContacts::PhoneNumber::Type combinedType = type | KContacts::PhoneNumber::Fax; const KContacts::PhoneNumber phone(QLatin1String("1"), combinedType); QCOMPARE(phone.type(), combinedType); QCOMPARE(KContacts::PhoneNumber::typeLabel(combinedType), phone.typeLabel()); if (type == KContacts::PhoneNumber::Home || type == KContacts::PhoneNumber::Work) { // special cased } else if (type < KContacts::PhoneNumber::Fax) { const QString expectedCombinedString = QStringLiteral("%1/%2").arg(labels[type]).arg(labels[KContacts::PhoneNumber::Fax]); QCOMPARE(phone.typeLabel(), expectedCombinedString); } else if (type > KContacts::PhoneNumber::Fax) { const QString expectedCombinedString = QStringLiteral("%1/%2").arg(labels[KContacts::PhoneNumber::Fax]).arg(labels[type]); QCOMPARE(phone.typeLabel(), expectedCombinedString); } } // special cases QCOMPARE(KContacts::PhoneNumber::typeLabel(KContacts::PhoneNumber::Pref), QLatin1String("Preferred Number")); QCOMPARE(KContacts::PhoneNumber::typeLabel(KContacts::PhoneNumber::Home |KContacts::PhoneNumber::Fax), QLatin1String("Home Fax")); QCOMPARE(KContacts::PhoneNumber::typeLabel(KContacts::PhoneNumber::Work |KContacts::PhoneNumber::Fax), QLatin1String("Work Fax")); QCOMPARE(KContacts::PhoneNumber::typeLabel(KContacts::PhoneNumber::Home |KContacts::PhoneNumber::Fax |KContacts::PhoneNumber::Pref), QLatin1String("Home Fax/Preferred")); QCOMPARE(KContacts::PhoneNumber::typeLabel(KContacts::PhoneNumber::Work |KContacts::PhoneNumber::Fax |KContacts::PhoneNumber::Pref), QLatin1String("Work Fax/Preferred")); } void PhoneNumberTest::shouldParseVCard21() { QByteArray vcarddata("BEGIN:VCARD\n" "VERSION:2.1\n" "EMAIL:foo@kde.org\n" "N:;;;;\n" "TEL;CELL;WORK:+1-919-676-9564\n" "UID:testuid\n" "END:VCARD\n" "\n"); KContacts::VCardTool vcard; const KContacts::AddresseeList lst = vcard.parseVCards(vcarddata); QCOMPARE(lst.count(), 1); KContacts::Addressee addr = lst.at(0); QCOMPARE(addr.phoneNumbers().count(), 1); KContacts::PhoneNumber number1 = addr.phoneNumbers().at(0); - //QCOMPARE(number1.number(), QString()); + QCOMPARE(number1.number(), QLatin1String("+1-919-676-9564")); + QVERIFY(number1.supportsSms()); + QVERIFY(!number1.isPreferred()); } void PhoneNumberTest::shouldExportVCard21() { KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("foo@kde.org")); addr.setUid(QStringLiteral("testuid")); KContacts::PhoneNumber number1; number1.setId(QStringLiteral("My Id")); number1.setType(KContacts::PhoneNumber::Work | KContacts::PhoneNumber::Cell); number1.setNumber(QStringLiteral("+1-919-676-9564")); addr.setPhoneNumbers(KContacts::PhoneNumber::List() << number1); lst << addr; KContacts::VCardTool vcard; const QByteArray ba = vcard.exportVCards(lst, KContacts::VCard::v2_1); QByteArray expected("BEGIN:VCARD\r\n" "VERSION:2.1\r\n" "EMAIL:foo@kde.org\r\n" "N:;;;;\r\n" "TEL;CELL;WORK:+1-919-676-9564\r\n" "UID:testuid\r\n" "END:VCARD\r\n" "\r\n"); QCOMPARE(ba, expected); } void PhoneNumberTest::shouldExportVCard3() { KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("foo@kde.org")); addr.setUid(QStringLiteral("testuid")); KContacts::PhoneNumber number1; number1.setId(QStringLiteral("My Id")); number1.setType(KContacts::PhoneNumber::Work | KContacts::PhoneNumber::Cell); number1.setNumber(QStringLiteral("+1-919-676-9564")); addr.setPhoneNumbers(KContacts::PhoneNumber::List() << number1); lst << addr; KContacts::VCardTool vcard; const QByteArray ba = vcard.exportVCards(lst, KContacts::VCard::v3_0); QByteArray expected("BEGIN:VCARD\r\n" "VERSION:3.0\r\n" "EMAIL:foo@kde.org\r\n" "N:;;;;\r\n" "TEL;TYPE=CELL,WORK:+1-919-676-9564\r\n" "UID:testuid\r\n" "END:VCARD\r\n" "\r\n"); QCOMPARE(ba, expected); } void PhoneNumberTest::shouldExportVCard4() { KContacts::AddresseeList lst; KContacts::Addressee addr; addr.setEmails(QStringList() << QStringLiteral("foo@kde.org")); addr.setUid(QStringLiteral("testuid")); KContacts::PhoneNumber number1; number1.setId(QStringLiteral("My Id")); number1.setType(KContacts::PhoneNumber::Work | KContacts::PhoneNumber::Cell); number1.setNumber(QStringLiteral("+1-919-676-9564")); addr.setPhoneNumbers(KContacts::PhoneNumber::List() << number1); lst << addr; KContacts::VCardTool vcard; const QByteArray ba = vcard.exportVCards(lst, KContacts::VCard::v4_0); QByteArray expected("BEGIN:VCARD\r\n" "VERSION:4.0\r\n" "EMAIL:foo@kde.org\r\n" "N:;;;;\r\n" "TEL;TYPE=\"cell,work\":+1-919-676-9564\r\n" "UID:testuid\r\n" "END:VCARD\r\n" "\r\n"); QCOMPARE(ba, expected); } void PhoneNumberTest::shouldParseVcard3() { QByteArray vcarddata("BEGIN:VCARD\n" "VERSION:3.0\n" "N:LastName;FirstName;;;\n" "TEL;VALUE=uri;PREF=1;TYPE=\"voice,home\":tel:+44-555-555-5555;ext=5555\r\n" "TEL;VALUE=uri;TYPE=\"voice,cell,text\":tel:+44-555-555-6666\r\n" "TEL;VALUE=uri;TYPE=\"voice,work\":tel:+44-555-555-7777\r\n" "UID:c80cf296-0825-4eb0-ab16-1fac1d522a33@xxxxxx.xx\n" "LANG:fr\n" "REV:2015-03-14T09:24:45+00:00\n" "FN:FirstName LastName\n" "END:VCARD\n"); KContacts::VCardTool vcard; const KContacts::AddresseeList lst = vcard.parseVCards(vcarddata); QCOMPARE(lst.count(), 1); KContacts::Addressee addr = lst.at(0); QCOMPARE(addr.phoneNumbers().count(), 3); } void PhoneNumberTest::shouldParseVcard4() { QByteArray vcarddata("BEGIN:VCARD\n" "VERSION:4.0\n" "N:LastName;FirstName;;;\n" "TEL;VALUE=uri;PREF=1;TYPE=\"voice,home\":tel:+44-555-555-5555;ext=5555\r\n" "TEL;VALUE=uri;TYPE=\"voice,cell,text\":tel:+44-555-555-6666\r\n" "TEL;VALUE=uri;TYPE=\"voice,work\":tel:+44-555-555-7777\r\n" "UID:c80cf296-0825-4eb0-ab16-1fac1d522a33@xxxxxx.xx\n" "LANG:fr\n" "REV:2015-03-14T09:24:45+00:00\n" "FN:FirstName LastName\n" "END:VCARD\n"); KContacts::VCardTool vcard; const KContacts::AddresseeList lst = vcard.parseVCards(vcarddata); QCOMPARE(lst.count(), 1); KContacts::Addressee addr = lst.at(0); QCOMPARE(addr.phoneNumbers().count(), 3); } void PhoneNumberTest::testNormalizeNumber_data() { QTest::addColumn("input"); QTest::addColumn("expected"); QTest::newRow("empty") << QString() << QString(); QTest::newRow("normalized") << QStringLiteral("+49123456789") << QStringLiteral("+49123456789"); QTest::newRow("formatted") << QStringLiteral("+49(123) 456 - 789") << QStringLiteral("+49123456789"); } void PhoneNumberTest::testNormalizeNumber() { QFETCH(QString, input); QFETCH(QString, expected); KContacts::PhoneNumber num; num.setNumber(input); QCOMPARE(num.normalizedNumber(), expected); } diff --git a/src/phonenumber.cpp b/src/phonenumber.cpp index 0368239c..a69c10bd 100644 --- a/src/phonenumber.cpp +++ b/src/phonenumber.cpp @@ -1,309 +1,319 @@ /* 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 "phonenumber.h" #include #include #include #include using namespace KContacts; static QString cleanupNumber(const QString &input) { return input.simplified(); } class Q_DECL_HIDDEN PhoneNumber::Private : public QSharedData { public: Private(Type type) : mId(KRandom::randomString(8)) , mType(type) { } Private(const Private &other) : QSharedData(other) { mId = other.mId; mType = other.mType; mNumber = other.mNumber; } QString mId; QString mNumber; Type mType; QMap mParameters; }; PhoneNumber::PhoneNumber() : d(new Private(Home)) { } PhoneNumber::PhoneNumber(const QString &number, Type type) : d(new Private(type)) { d->mNumber = cleanupNumber(number); } PhoneNumber::PhoneNumber(const PhoneNumber &other) : d(other.d) { } PhoneNumber::~PhoneNumber() { } bool PhoneNumber::operator==(const PhoneNumber &other) const { if (d->mId != other.d->mId) { return false; } if (d->mNumber != other.d->mNumber) { return false; } if (d->mType != other.d->mType) { return false; } if (d->mParameters != other.d->mParameters) { return false; } return true; } bool PhoneNumber::operator!=(const PhoneNumber &other) const { return !(other == *this); } PhoneNumber &PhoneNumber::operator=(const PhoneNumber &other) { if (this != &other) { d = other.d; } return *this; } bool PhoneNumber::isEmpty() const { return d->mNumber.isEmpty(); } void PhoneNumber::setId(const QString &id) { d->mId = id; } QString PhoneNumber::id() const { return d->mId; } void PhoneNumber::setNumber(const QString &number) { d->mNumber = cleanupNumber(number); } QString PhoneNumber::number() const { return d->mNumber; } QString PhoneNumber::normalizedNumber() const { QString result; result.reserve(d->mNumber.size()); for (const auto &c : d->mNumber) { if (c.isDigit() || (c == QLatin1Char('+') && result.isEmpty())) { result.push_back(c); } } return result; } void PhoneNumber::setType(Type type) { d->mType = type; } PhoneNumber::Type PhoneNumber::type() const { return d->mType; } QString PhoneNumber::typeLabel() const { return typeLabel(type()); } PhoneNumber::TypeList PhoneNumber::typeList() { static TypeList list; if (list.isEmpty()) { list << Home << Work << Msg << Pref << Voice << Fax << Cell << Video << Bbs << Modem << Car << Isdn << Pcs << Pager << Undefined; } return list; } QString PhoneNumber::typeFlagLabel(TypeFlag type) { switch (type) { case Undefined: return i18nc("Undefined phone type", "Telephone number"); case Home: return i18nc("Home phone", "Home"); case Work: return i18nc("Work phone", "Work"); case Msg: return i18n("Messenger"); case Pref: return i18nc("Preferred phone", "Preferred"); case Voice: return i18n("Voice"); case Fax: return i18n("Fax"); case Cell: return i18nc("Mobile Phone", "Mobile"); case Video: return i18nc("Video phone", "Video"); case Bbs: return i18n("Mailbox"); case Modem: return i18n("Modem"); case Car: return i18nc("Car Phone", "Car"); case Isdn: return i18n("ISDN"); case Pcs: return i18n("PCS"); case Pager: return i18n("Pager"); default: return i18nc("another type of phone", "Other"); } } QString PhoneNumber::typeLabel(Type type) { QString label; bool first = true; // special cases // Pref stand alone -> Preferred Number // Home+Fax or Work+Fax -> combine as initial string if (type == Pref) { return i18n("Preferred Number"); } if (type & Fax) { if (type & Home) { label = i18n("Home Fax"); first = false; type &= ~Fax; type &= ~Home; } else if (type & Work) { label = i18n("Work Fax"); first = false; type &= ~Fax; type &= ~Work; } } const TypeList list = typeList(); TypeList::ConstIterator it; TypeList::ConstIterator end(list.constEnd()); for (it = list.constBegin(); 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; } +bool PhoneNumber::isPreferred() const +{ + return type() & Pref; +} + +bool PhoneNumber::supportsSms() const +{ + return type() & Cell; +} + QString PhoneNumber::toString() const { QString str = QLatin1String("PhoneNumber {\n"); str += QStringLiteral(" Id: %1\n").arg(d->mId); str += QStringLiteral(" Type: %1\n").arg(typeLabel(d->mType)); if (!d->mParameters.isEmpty()) { QString param; QMap::const_iterator it = d->mParameters.constBegin(); const QMap::const_iterator end = d->mParameters.constEnd(); while (it != end) { param += QStringLiteral("%1 %2").arg(it.key(), it.value().join(QLatin1Char(','))); ++it; } str += QStringLiteral(" parameters: %1\n").arg(param); } str += QStringLiteral(" Number: %1\n").arg(d->mNumber); str += QLatin1String("}\n"); return str; } void PhoneNumber::setParameters(const QMap ¶ms) { d->mParameters = params; } QMap PhoneNumber::parameters() const { return d->mParameters; } QDataStream &KContacts::operator<<(QDataStream &s, const PhoneNumber &phone) { return s << phone.d->mId << (uint)phone.d->mType << phone.d->mNumber << phone.d->mParameters; } QDataStream &KContacts::operator>>(QDataStream &s, PhoneNumber &phone) { uint type; s >> phone.d->mId >> type >> phone.d->mNumber >> phone.d->mParameters; phone.d->mType = PhoneNumber::Type(type); return s; } diff --git a/src/phonenumber.h b/src/phonenumber.h index b4972e38..52461f01 100644 --- a/src/phonenumber.h +++ b/src/phonenumber.h @@ -1,255 +1,268 @@ /* 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 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) + Q_PROPERTY(bool isPreferred READ isPreferred) + Q_PROPERTY(bool supportsSms READ supportsSms) 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 whether this phone number is marked as preferred. + * @since 5.12 + */ + Q_REQUIRED_RESULT bool isPreferred() const; + /** + * Returns whether this phone number is expected to support receiving SMS messages. + * @since 5.12 + */ + Q_REQUIRED_RESULT bool supportsSms() const; + /** * 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