libqutim  0.3.1.0
emoticons.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** qutIM - instant messenger
4 **
5 ** Copyright © 2011 Ruslan Nigmatullin <euroelessar@yandex.ru>
6 **
7 *****************************************************************************
8 **
9 ** $QUTIM_BEGIN_LICENSE$
10 ** This program is free software: you can redistribute it and/or modify
11 ** it under the terms of the GNU General Public License as published by
12 ** the Free Software Foundation, either version 3 of the License, or
13 ** (at your option) any later version.
14 **
15 ** This program is distributed in the hope that it will be useful,
16 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 ** See the GNU General Public License for more details.
19 **
20 ** You should have received a copy of the GNU General Public License
21 ** along with this program. If not, see http://www.gnu.org/licenses/.
22 ** $QUTIM_END_LICENSE$
23 **
24 ****************************************************************************/
25 
26 #ifndef EMOTICONS_H
27 #define EMOTICONS_H
28 
29 #include "libqutim_global.h"
30 #include <QSharedData>
31 #include <QStringList>
32 
33 namespace qutim_sdk_0_3
34 {
35 class EmoticonsProvider;
36 struct EmoticonsThemeData;
37 struct EmoticonsProviderPrivate;
38 
40 {
41 public:
43  {
44  DefaultParse = 0,
45  StrictParse = 0x01,
46  };
47  Q_DECLARE_FLAGS(ParseMode, ParseModeFlag)
48 
49  enum TokenType
50  {
53  Image
54  };
55 
56  struct Token
57  {
58  inline Token() : type(Undefined) {}
59  inline Token(const QString &t) : type(Text), text(t) {}
60  inline Token(const QString &t, const QString &p, const QString &h)
61  : type(Image), text(t), imgPath(p), imgHtmlCode(h) {}
63  QString text;
64  QString imgPath;
65  QString imgHtmlCode;
66  };
67 
68  EmoticonsTheme(const QString &name = QString());
69  EmoticonsTheme(EmoticonsThemeData *data);
71  ~EmoticonsTheme();
72  EmoticonsTheme &operator =(const EmoticonsTheme &theme);
73 
74  bool isNull() const;
75 
76  QHash<QString, QStringList> emoticonsMap() const;
77  QStringList emoticonsIndexes() const;
78  QString themeName() const;
79 
80  // EmoticonsTheme pseudoClone();
81 
82  QString parseEmoticons(const QString &text, ParseMode mode = DefaultParse, const QStringList &exclude = QStringList());
83  QList<Token> tokenize(const QString &text, ParseMode mode = DefaultParse);
84 private:
85  QExplicitlySharedDataPointer<EmoticonsThemeData> p;
86 };
87 
89 {
90 public:
91  // Emoticon has the same structure as in KDE for binary hacks
92  struct Emoticon
93  {
95  /* sort by longest to shortest matchText */
96  bool operator < (const Emoticon &e) const { return matchText.length() > e.matchText.length(); }
97  QString matchText;
99  QString picPath;
100  QString picHTMLCode;
101  };
103  virtual ~EmoticonsProvider();
104  QHash<QString, QStringList> emoticonsMap() const;
105  QStringList emoticonsIndexes() const;
106  QHash<QChar, QList<Emoticon> > emoticonsByChar() const;
107  virtual QString themeName() const;
108  virtual bool saveTheme();
109  // Warning: QStringList must contain lower-case strings
110  virtual bool addEmoticon(const QString &imgPath, const QStringList &codes);
111  virtual bool removeEmoticon(const QStringList &codes);
112 protected:
113  void clearEmoticons();
114  void appendEmoticon(const QString &imgPath, const QStringList &codes);
115  void removeEmoticon(const QString &imgPath, const QStringList &codes);
116 private:
117  QScopedPointer<EmoticonsProviderPrivate> p;
118 };
119 
120 class LIBQUTIM_EXPORT EmoticonsBackend : public QObject
121 {
122  Q_OBJECT
123 public:
124  virtual QStringList themeList() = 0;
125  virtual EmoticonsProvider *loadTheme(const QString &name) = 0;
126 };
127 
128 namespace Emoticons
129 {
132 LIBQUTIM_EXPORT EmoticonsTheme theme(const QString &name);
133 LIBQUTIM_EXPORT QStringList themeList();
134 LIBQUTIM_EXPORT void setTheme(const QString &name);
135 LIBQUTIM_EXPORT void setTheme(const EmoticonsTheme &theme);
136 }
137 }
138 
139 Q_DECLARE_OPERATORS_FOR_FLAGS(qutim_sdk_0_3::EmoticonsTheme::ParseMode)
140 
141 #endif // EMOTICONS_H
142 

Generated by Doxygen