1 /* 2 Copyright © 2014-2019 by The qTox Project Contributors 3 4 This file is part of qTox, a Qt-based graphical interface for Tox. 5 6 qTox is libre software: you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation, either version 3 of the License, or 9 (at your option) any later version. 10 11 qTox is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with qTox. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 #ifndef SMILEYPACK_H 21 #define SMILEYPACK_H 22 23 #include <QIcon> 24 #include <QMap> 25 #include <QMutex> 26 #include <QRegularExpression> 27 28 #include <memory> 29 30 class QTimer; 31 32 class SmileyPack : public QObject 33 { 34 Q_OBJECT 35 36 public: 37 static SmileyPack& getInstance(); 38 static QList<QPair<QString, QString>> listSmileyPacks(const QStringList& paths); 39 static QList<QPair<QString, QString>> listSmileyPacks(); 40 41 QString smileyfied(const QString& msg); 42 QList<QStringList> getEmoticons() const; 43 std::shared_ptr<QIcon> getAsIcon(const QString& key) const; 44 45 private slots: 46 void onSmileyPackChanged(); 47 void cleanupIconsCache(); 48 49 private: 50 SmileyPack(); 51 SmileyPack(SmileyPack&) = delete; 52 SmileyPack& operator=(const SmileyPack&) = delete; 53 ~SmileyPack() override; 54 55 bool load(const QString& filename); 56 void constructRegex(); 57 58 mutable std::map<QString, std::shared_ptr<QIcon>> cachedIcon; 59 QHash<QString, QString> emoticonToPath; 60 QList<QStringList> emoticons; 61 QString path; 62 QTimer* cleanupTimer; 63 QRegularExpression smilify; 64 mutable QMutex loadingMutex; 65 }; 66 67 #endif // SMILEYPACK_H 68