2019-06-02 15:52:54 +01:00
|
|
|
/**
|
2020-08-17 10:48:10 +01:00
|
|
|
* SPDX-FileCopyrightText: 2019 Simon Redman <simon@ergotech.com>
|
2019-06-02 15:52:54 +01:00
|
|
|
*
|
2020-08-17 10:48:10 +01:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
2019-06-02 15:52:54 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SMSHELPER_H
|
|
|
|
#define SMSHELPER_H
|
|
|
|
|
2019-07-19 18:33:15 +01:00
|
|
|
#include <QIcon>
|
2020-05-09 17:50:08 +01:00
|
|
|
#include <QJSEngine>
|
|
|
|
#include <QQmlEngine>
|
|
|
|
#include <QSharedPointer>
|
2019-06-02 15:52:54 +01:00
|
|
|
|
2019-07-22 12:40:33 +01:00
|
|
|
#include <KPeople/PersonData>
|
2019-07-19 18:33:15 +01:00
|
|
|
|
|
|
|
#include "interfaces/conversationmessage.h"
|
|
|
|
|
2020-03-22 18:47:12 +00:00
|
|
|
#include "smsapp/smscharcount.h"
|
2019-06-02 15:52:54 +01:00
|
|
|
|
2020-03-21 22:57:28 +00:00
|
|
|
class PersonsCache;
|
|
|
|
|
2020-07-30 09:28:15 +01:00
|
|
|
class SmsHelper : public QObject
|
2019-06-02 15:52:54 +01:00
|
|
|
{
|
2020-05-09 17:50:08 +01:00
|
|
|
Q_OBJECT
|
2019-06-02 15:52:54 +01:00
|
|
|
public:
|
2020-05-09 17:50:08 +01:00
|
|
|
SmsHelper() = default;
|
2021-10-27 05:53:06 +01:00
|
|
|
~SmsHelper() override = default;
|
2020-05-09 17:50:08 +01:00
|
|
|
|
2022-09-10 22:23:52 +01:00
|
|
|
static QObject *singletonProvider(QQmlEngine *engine, QJSEngine *scriptEngine);
|
2020-05-09 17:50:08 +01:00
|
|
|
|
2019-06-02 15:52:54 +01:00
|
|
|
enum CountryCode {
|
|
|
|
Australia,
|
|
|
|
CzechRepublic,
|
|
|
|
Other, // I only care about a few country codes
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return true to indicate the two phone numbers should be considered the same, false otherwise
|
|
|
|
*/
|
2022-09-10 22:23:52 +01:00
|
|
|
Q_INVOKABLE static bool isPhoneNumberMatch(const QString &phone1, const QString &phone2);
|
2019-06-02 15:52:54 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return true to indicate the two phone numbers should be considered the same, false otherwise
|
|
|
|
* Requires canonicalized phone numbers as inputs
|
|
|
|
*/
|
2022-09-10 22:23:52 +01:00
|
|
|
Q_INVOKABLE static bool isPhoneNumberMatchCanonicalized(const QString &canonicalPhone1, const QString &canonicalPhone2);
|
2019-06-02 15:52:54 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* See inline comments for how short codes are determined
|
|
|
|
* All information from https://en.wikipedia.org/wiki/Short_code
|
|
|
|
*/
|
2022-09-10 22:23:52 +01:00
|
|
|
Q_INVOKABLE static bool isShortCode(const QString &canonicalNumber, const CountryCode &country);
|
2019-06-02 15:52:54 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Try to guess the country code from the passed number
|
|
|
|
*/
|
2022-09-10 22:23:52 +01:00
|
|
|
static CountryCode determineCountryCode(const QString &canonicalNumber);
|
2019-06-02 15:52:54 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Simplify a phone number to a known form
|
|
|
|
*/
|
2022-09-10 22:23:52 +01:00
|
|
|
Q_INVOKABLE static QString canonicalizePhoneNumber(const QString &phoneNumber);
|
2019-06-02 15:52:54 +01:00
|
|
|
|
2019-07-19 18:33:15 +01:00
|
|
|
/**
|
|
|
|
* Get the data for a particular person given their contact address
|
|
|
|
*/
|
2022-09-10 22:23:52 +01:00
|
|
|
Q_INVOKABLE static QSharedPointer<KPeople::PersonData> lookupPersonByAddress(const QString &address);
|
2019-07-19 18:33:15 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Make an icon which combines the many icons
|
|
|
|
*
|
|
|
|
* This mimics what Android does:
|
|
|
|
* If there is only one icon, use that one
|
|
|
|
* If there are two icons, put one in the top-left corner and one in the bottom right
|
|
|
|
* If there are three, put one in the middle of the top and the remaining two in the bottom
|
|
|
|
* If there are four or more, put one in each corner (If more than four, some will be left out)
|
|
|
|
*/
|
2022-09-10 22:23:52 +01:00
|
|
|
Q_INVOKABLE static QIcon combineIcons(const QList<QPixmap> &icons);
|
2019-07-19 18:33:15 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a combination of all the addresses as a comma-separated list of:
|
|
|
|
* - The KPeople contact's name (if known)
|
|
|
|
* - The address (if the contact is not known)
|
|
|
|
*/
|
2022-09-10 22:23:52 +01:00
|
|
|
Q_INVOKABLE static QString getTitleForAddresses(const QList<ConversationAddress> &addresses);
|
2019-07-19 18:33:15 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a combined icon for all contacts by finding:
|
|
|
|
* - The KPeople contact's icon (if known)
|
|
|
|
* - A generic icon
|
|
|
|
* and then using SmsHelper::combineIcons
|
|
|
|
*/
|
2022-09-10 22:23:52 +01:00
|
|
|
Q_INVOKABLE static QIcon getIconForAddresses(const QList<ConversationAddress> &addresses);
|
2020-05-09 17:50:08 +01:00
|
|
|
|
|
|
|
/**
|
2022-09-10 22:23:52 +01:00
|
|
|
* Put the specified text into the system clipboard
|
|
|
|
*/
|
|
|
|
Q_INVOKABLE static void copyToClipboard(const QString &text);
|
2019-07-19 18:33:15 +01:00
|
|
|
|
2020-03-21 22:57:28 +00:00
|
|
|
/**
|
|
|
|
* Get the data for all persons currently stored on device
|
|
|
|
*/
|
|
|
|
static QList<QSharedPointer<KPeople::PersonData>> getAllPersons();
|
2020-05-09 17:50:08 +01:00
|
|
|
|
2020-03-22 18:47:12 +00:00
|
|
|
/**
|
|
|
|
* Get SMS character count status of SMS. It contains number of remaining characters
|
|
|
|
* in current SMS (automatically selects 7-bit, 8-bit or 16-bit mode), octet count and
|
|
|
|
* number of messages in concatenated SMS.
|
|
|
|
*/
|
2022-09-10 22:23:52 +01:00
|
|
|
Q_INVOKABLE static SmsCharCount getCharCount(const QString &message);
|
2020-03-22 09:33:04 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Used to validate arbitrary phone number entered by the user
|
|
|
|
*/
|
2022-09-10 22:23:52 +01:00
|
|
|
Q_INVOKABLE static bool isAddressValid(const QString &address);
|
2020-03-22 09:33:04 +00:00
|
|
|
|
2020-08-31 11:05:25 +01:00
|
|
|
/**
|
|
|
|
* Return the total size of the message
|
|
|
|
*/
|
2022-09-10 22:23:52 +01:00
|
|
|
Q_INVOKABLE static quint64 totalMessageSize(const QList<QUrl> &urls, const QString &text);
|
2020-08-31 11:05:25 +01:00
|
|
|
|
2020-09-27 04:51:17 +01:00
|
|
|
/**
|
|
|
|
* Gets a thumbnail for the given attachment
|
|
|
|
*/
|
2022-09-10 22:23:52 +01:00
|
|
|
Q_INVOKABLE static QIcon getThumbnailForAttachment(const Attachment &attachment);
|
2020-09-27 04:51:17 +01:00
|
|
|
|
2019-06-02 15:52:54 +01:00
|
|
|
private:
|
2022-09-10 22:23:52 +01:00
|
|
|
static bool isInGsmAlphabet(const QChar &ch);
|
|
|
|
static bool isInGsmAlphabetExtension(const QChar &ch);
|
2019-06-02 15:52:54 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // SMSHELPER_H
|