File indexing completed on 2024-04-21 04:56:57
0001 /** 0002 * SPDX-FileCopyrightText: 2019 Simon Redman <simon@ergotech.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0005 */ 0006 0007 #ifndef SMSHELPER_H 0008 #define SMSHELPER_H 0009 0010 #include <QIcon> 0011 #include <QJSEngine> 0012 #include <QQmlEngine> 0013 #include <QSharedPointer> 0014 0015 #include <KPeople/PersonData> 0016 0017 #include "interfaces/conversationmessage.h" 0018 0019 #include "smsapp/smscharcount.h" 0020 0021 class PersonsCache; 0022 0023 class SmsHelper : public QObject 0024 { 0025 Q_OBJECT 0026 public: 0027 static QObject *singletonProvider(QQmlEngine *engine, QJSEngine *scriptEngine); 0028 0029 enum CountryCode { 0030 Australia, 0031 CzechRepublic, 0032 Other, // I only care about a few country codes 0033 }; 0034 0035 /** 0036 * Return true to indicate the two phone numbers should be considered the same, false otherwise 0037 */ 0038 Q_INVOKABLE static bool isPhoneNumberMatch(const QString &phone1, const QString &phone2); 0039 0040 /** 0041 * Return true to indicate the two phone numbers should be considered the same, false otherwise 0042 * Requires canonicalized phone numbers as inputs 0043 */ 0044 Q_INVOKABLE static bool isPhoneNumberMatchCanonicalized(const QString &canonicalPhone1, const QString &canonicalPhone2); 0045 0046 /** 0047 * See inline comments for how short codes are determined 0048 * All information from https://en.wikipedia.org/wiki/Short_code 0049 */ 0050 Q_INVOKABLE static bool isShortCode(const QString &canonicalNumber, const CountryCode &country); 0051 0052 /** 0053 * Try to guess the country code from the passed number 0054 */ 0055 static CountryCode determineCountryCode(const QString &canonicalNumber); 0056 0057 /** 0058 * Simplify a phone number to a known form 0059 */ 0060 Q_INVOKABLE static QString canonicalizePhoneNumber(const QString &phoneNumber); 0061 0062 /** 0063 * Get the data for a particular person given their contact address 0064 */ 0065 Q_INVOKABLE static QSharedPointer<KPeople::PersonData> lookupPersonByAddress(const QString &address); 0066 0067 /** 0068 * Make an icon which combines the many icons 0069 * 0070 * This mimics what Android does: 0071 * If there is only one icon, use that one 0072 * If there are two icons, put one in the top-left corner and one in the bottom right 0073 * If there are three, put one in the middle of the top and the remaining two in the bottom 0074 * If there are four or more, put one in each corner (If more than four, some will be left out) 0075 */ 0076 Q_INVOKABLE static QIcon combineIcons(const QList<QPixmap> &icons); 0077 0078 /** 0079 * Get a combination of all the addresses as a comma-separated list of: 0080 * - The KPeople contact's name (if known) 0081 * - The address (if the contact is not known) 0082 */ 0083 Q_INVOKABLE static QString getTitleForAddresses(const QList<ConversationAddress> &addresses); 0084 0085 /** 0086 * Get a combined icon for all contacts by finding: 0087 * - The KPeople contact's icon (if known) 0088 * - A generic icon 0089 * and then using SmsHelper::combineIcons 0090 */ 0091 Q_INVOKABLE static QIcon getIconForAddresses(const QList<ConversationAddress> &addresses); 0092 0093 /** 0094 * Put the specified text into the system clipboard 0095 */ 0096 Q_INVOKABLE static void copyToClipboard(const QString &text); 0097 0098 /** 0099 * Get the data for all persons currently stored on device 0100 */ 0101 static QList<QSharedPointer<KPeople::PersonData>> getAllPersons(); 0102 0103 /** 0104 * Get SMS character count status of SMS. It contains number of remaining characters 0105 * in current SMS (automatically selects 7-bit, 8-bit or 16-bit mode), octet count and 0106 * number of messages in concatenated SMS. 0107 */ 0108 Q_INVOKABLE static SmsCharCount getCharCount(const QString &message); 0109 0110 /** 0111 * Used to validate arbitrary phone number entered by the user 0112 */ 0113 Q_INVOKABLE static bool isAddressValid(const QString &address); 0114 0115 /** 0116 * Return the total size of the message 0117 */ 0118 Q_INVOKABLE static quint64 totalMessageSize(const QList<QUrl> &urls, const QString &text); 0119 0120 /** 0121 * Gets a thumbnail for the given attachment 0122 */ 0123 Q_INVOKABLE static QIcon getThumbnailForAttachment(const Attachment &attachment); 0124 0125 private: 0126 static bool isInGsmAlphabet(const QChar &ch); 0127 static bool isInGsmAlphabetExtension(const QChar &ch); 0128 }; 0129 0130 #endif // SMSHELPER_H