File indexing completed on 2024-05-05 05:28:47
0001 // SPDX-FileCopyrightText: 2020 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 <QObject> 0008 #include <QRegularExpression> 0009 0010 #include <KContacts/PhoneNumber> 0011 #include <KContacts/VCardConverter> 0012 0013 #include <phonenumberlist.h> 0014 0015 class QQmlApplicationEngine; 0016 class QQuickWindow; 0017 0018 class Utils : public QObject 0019 { 0020 Q_OBJECT 0021 0022 public: 0023 enum PassiveNotificationDuation { 0024 ShortNotificationDuration, 0025 LongNotificationDuration, 0026 }; 0027 Q_ENUM(PassiveNotificationDuation) 0028 0029 explicit Utils(QQmlApplicationEngine *engine); 0030 void showPassiveNotification(const QString &message, int timeout = 0); 0031 void showPassiveNotification(const QString &message, PassiveNotificationDuation timeout); 0032 0033 Q_INVOKABLE bool isPhoneNumber(const QString &text) const; 0034 Q_INVOKABLE bool isPremiumNumber(const PhoneNumberList &phoneNumberList) const; 0035 Q_INVOKABLE static void launchPhonebook(); 0036 Q_INVOKABLE void copyTextToClipboard(const QString &text) const; 0037 Q_INVOKABLE PhoneNumber phoneNumber(const QString &number) const; 0038 Q_INVOKABLE PhoneNumberList phoneNumberList(const QStringList &phoneNumbers) const; 0039 0040 /// Currently only used to normalize contact model. Please try not to use this. 0041 Q_INVOKABLE QString phoneNumberToInternationalString(const PhoneNumber &phoneNumber) const; 0042 0043 /// Currently only used to add a phone number to an image provider uri. 0044 /// Please try not to use this. 0045 Q_INVOKABLE QString phoneNumberListToString(const PhoneNumberList &phoneNumberList) const; 0046 0047 bool isLocale24HourTime(); 0048 0049 Q_INVOKABLE static QString textToHtml(const QString &text); 0050 0051 Q_INVOKABLE QVariantList phoneNumbers(const QString &kPeopleUri); 0052 0053 static Utils *instance(); 0054 0055 static Utils *s_instance; 0056 0057 QQmlApplicationEngine *qmlEngine() const; 0058 0059 private: 0060 QQmlApplicationEngine *m_engine; 0061 QQuickWindow *m_window = nullptr; 0062 const KContacts::VCardConverter converter; 0063 };