qTox  Version: nightly | Commit: bc751c8e1cac455f9690654fcfe0f560d2d7dfdd
smileypack.h
Go to the documentation of this file.
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 #pragma once
21 
22 #include <QIcon>
23 #include <QMap>
24 #include <QMutex>
25 #include <QRegularExpression>
26 
27 #include <memory>
28 
29 class QTimer;
30 
31 class SmileyPack : public QObject
32 {
33  Q_OBJECT
34 
35 public:
36  static SmileyPack& getInstance();
37  static QList<QPair<QString, QString>> listSmileyPacks(const QStringList& paths);
39 
40  QString smileyfied(const QString& msg);
42  std::shared_ptr<QIcon> getAsIcon(const QString& key) const;
43 
44 private slots:
45  void onSmileyPackChanged();
46  void cleanupIconsCache();
47 
48 private:
49  SmileyPack();
50  SmileyPack(SmileyPack&) = delete;
51  SmileyPack& operator=(const SmileyPack&) = delete;
52  ~SmileyPack() override;
53 
54  bool load(const QString& filename);
55  void constructRegex();
56 
57  mutable std::map<QString, std::shared_ptr<QIcon>> cachedIcon;
60  QString path;
61  QTimer* cleanupTimer;
62  QRegularExpression smilify;
63  mutable QMutex loadingMutex;
64 };
SmileyPack::getAsIcon
std::shared_ptr< QIcon > getAsIcon(const QString &key) const
Gets icon accoring to passed emoticon.
Definition: smileypack.cpp:336
SmileyPack::cachedIcon
std::map< QString, std::shared_ptr< QIcon > > cachedIcon
Definition: smileypack.h:57
SmileyPack::loadingMutex
QMutex loadingMutex
Definition: smileypack.h:63
SmileyPack::~SmileyPack
~SmileyPack() override
Definition: smileypack.cpp:126
QList
Definition: friendlist.h:25
SmileyPack::cleanupTimer
QTimer * cleanupTimer
Definition: smileypack.h:61
SmileyPack::getEmoticons
QList< QStringList > getEmoticons() const
Returns all emoticons that was extracted from files, grouped by according icon file.
Definition: smileypack.cpp:325
SmileyPack::constructRegex
void constructRegex()
Creates the regex for replacing emoticons with the path to their pictures.
Definition: smileypack.cpp:264
SmileyPack::load
bool load(const QString &filename)
Load smile pack.
Definition: smileypack.cpp:203
SmileyPack::SmileyPack
SmileyPack()
Definition: smileypack.cpp:115
SmileyPack::path
QString path
directory containing the cfg and image files
Definition: smileypack.h:60
SmileyPack::smilify
QRegularExpression smilify
Definition: smileypack.h:62
SmileyPack::getInstance
static SmileyPack & getInstance()
Returns the singleton instance.
Definition: smileypack.cpp:147
SmileyPack::onSmileyPackChanged
void onSmileyPackChanged()
Definition: smileypack.cpp:354
SmileyPack::smileyfied
QString smileyfied(const QString &msg)
Replaces all found text emoticons to HTML reference with its according icon filename.
Definition: smileypack.cpp:303
SmileyPack::cleanupIconsCache
void cleanupIconsCache()
Definition: smileypack.cpp:131
SmileyPack::emoticonToPath
QHash< QString, QString > emoticonToPath
Definition: smileypack.h:58
QHash< QString, QString >
SmileyPack::listSmileyPacks
static QList< QPair< QString, QString > > listSmileyPacks()
Does the same as listSmileyPaths, but with default paths.
Definition: smileypack.cpp:156
SmileyPack::emoticons
QList< QStringList > emoticons
{{ ":)", ":-)" }, {":(", ...}, ... }
Definition: smileypack.h:59
SmileyPack::operator=
SmileyPack & operator=(const SmileyPack &)=delete
SmileyPack
Maps emoticons to smileys.
Definition: smileypack.h:31