File indexing completed on 2024-05-05 17:32:29
0001 // SPDX-FileCopyrightText: 2021 Jonah BrĂ¼chert <jbb@kaidan.im> 0002 // 0003 // SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0004 0005 #pragma once 0006 0007 #include <functional> 0008 0009 #include <QDBusArgument> 0010 #include <QDebug> 0011 #include <QSharedDataPointer> 0012 #include <QString> 0013 0014 #include <global.h> 0015 0016 struct PhoneNumberPrivate; 0017 0018 /// 0019 /// Represents a phone number. 0020 /// It can be efficiently converted into different phone number formats. 0021 /// 0022 /// It is useful as an interface type, so the caller doesn't need to convert the phone number to any specific format. 0023 /// 0024 class PhoneNumber 0025 { 0026 public: 0027 PhoneNumber(); 0028 PhoneNumber(const PhoneNumber &other); 0029 ~PhoneNumber(); 0030 PhoneNumber &operator=(const PhoneNumber &other); 0031 0032 explicit PhoneNumber(const QString &number); 0033 0034 bool operator==(const PhoneNumber &other) const; 0035 0036 QString toInternational() const; 0037 QString toNational() const; 0038 QString toE164() const; 0039 bool isValid() const; 0040 static void setCountryCode(const QString &countryCode); 0041 0042 private: 0043 QSharedDataPointer<PhoneNumberPrivate> d; 0044 static std::string countryCode; 0045 }; 0046 0047 inline QDebug &operator<<(QDebug &debug, const PhoneNumber &phoneNumber) 0048 { 0049 return debug << phoneNumber.toInternational(); 0050 } 0051 0052 inline uint qHash(const PhoneNumber &phoneNum) 0053 { 0054 return hash(phoneNum.toInternational()); 0055 } 0056 0057 Q_DECLARE_METATYPE(PhoneNumber)