1 | /********************************************************************************** |
2 | * Copyright (C) 2008 by Carlo Segato <brandon.ml@gmail.com> * |
3 | * * |
4 | * This library is free software; you can redistribute it and/or * |
5 | * modify it under the terms of the GNU Lesser General Public * |
6 | * License as published by the Free Software Foundation; either * |
7 | * version 2.1 of the License, or (at your option) any later version. * |
8 | * * |
9 | * This library is distributed in the hope that it will be useful, * |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * |
12 | * Lesser General Public License for more details. * |
13 | * * |
14 | * You should have received a copy of the GNU Lesser General Public * |
15 | * License along with this library. If not, see <http://www.gnu.org/licenses/>.* |
16 | * * |
17 | **********************************************************************************/ |
18 | |
19 | #ifndef KEMOTICONS_PROVIDER_H |
20 | #define KEMOTICONS_PROVIDER_H |
21 | |
22 | #include "kemoticons_export.h" |
23 | #include <QtCore/QObject> |
24 | #include <QtCore/QVariant> |
25 | #include <QtCore/QStringList> |
26 | #include <QtCore/QPair> |
27 | |
28 | class QString; |
29 | class KEmoticonsProviderPrivate; |
30 | struct Emoticon; |
31 | |
32 | /** |
33 | * This is the base class for the emoticons provider plugins |
34 | */ |
35 | class KEMOTICONS_EXPORT KEmoticonsProvider : public QObject |
36 | { |
37 | Q_OBJECT |
38 | public: |
39 | struct Emoticon |
40 | { |
41 | Emoticon(){} |
42 | /* sort by longest to shortest matchText */ |
43 | bool operator < (const Emoticon &e) const { return matchText.length() > e.matchText.length(); } |
44 | QString matchText; |
45 | QString matchTextEscaped; |
46 | QString picPath; |
47 | QString picHTMLCode; |
48 | }; |
49 | |
50 | /** |
51 | * Options to pass to addEmoticon |
52 | */ |
53 | enum AddEmoticonOption { |
54 | DoNotCopy, /**<< Don't copy the emoticon file into the theme directory */ |
55 | Copy /**<< Copy the emoticon file into the theme directory */ |
56 | }; |
57 | |
58 | /** |
59 | * Default constructor |
60 | */ |
61 | explicit KEmoticonsProvider(QObject *parent = 0); |
62 | |
63 | /** |
64 | * Destructor |
65 | */ |
66 | virtual ~KEmoticonsProvider(); |
67 | |
68 | /** |
69 | * Load the theme inside the directory @p path |
70 | * @param path path to the directory |
71 | */ |
72 | virtual bool loadTheme(const QString &path); |
73 | |
74 | /** |
75 | * Remove the emoticon @p emo, this will not delete the image file too |
76 | * @param emo the emoticon text to remove |
77 | * @return @c true if it can delete the emoticon |
78 | */ |
79 | virtual bool removeEmoticon(const QString &emo); |
80 | |
81 | /** |
82 | * Add the emoticon @p emo with text @p text |
83 | * @param emo path to the emoticon image |
84 | * @param text the text of the emoticon separated by space for multiple text |
85 | * @param copy whether or not copy @p emo into the theme directory |
86 | * @return @c true if it can add the emoticon |
87 | */ |
88 | virtual bool addEmoticon(const QString &emo, const QString &text, AddEmoticonOption option = DoNotCopy); |
89 | |
90 | /** |
91 | * Save the emoticon theme |
92 | */ |
93 | virtual void save(); |
94 | |
95 | /** |
96 | * Returns the theme name |
97 | */ |
98 | QString themeName() const; |
99 | |
100 | /** |
101 | * Set the theme name |
102 | * @param name name of the theme |
103 | */ |
104 | void setThemeName(const QString &name); |
105 | |
106 | /** |
107 | * Returns the theme path |
108 | */ |
109 | QString themePath() const; |
110 | |
111 | /** |
112 | * Returns the file name of the theme |
113 | */ |
114 | QString fileName() const; |
115 | |
116 | /** |
117 | * Returns a QHash that contains the emoticons path as keys and the text as values |
118 | */ |
119 | QHash<QString, QStringList> emoticonsMap() const; |
120 | |
121 | /** |
122 | * Returns a QHash that contains emoticons indexed by the first char |
123 | */ |
124 | QHash<QChar, QList<Emoticon> > emoticonsIndex() const; |
125 | |
126 | /** |
127 | * Create a new theme |
128 | */ |
129 | virtual void createNew(); |
130 | |
131 | protected: |
132 | /** |
133 | * Clears the emoticons map |
134 | */ |
135 | void clearEmoticonsMap(); |
136 | |
137 | /** |
138 | * Insert a new item in the emoticons map |
139 | */ |
140 | void addEmoticonsMap(QString key, QStringList value); |
141 | |
142 | /** |
143 | * Remove an item from the emoticons map |
144 | */ |
145 | void removeEmoticonsMap(QString key); |
146 | |
147 | /** |
148 | * Add an emoticon to the index |
149 | * @param path path to the emoticon |
150 | * @param emoList list of text associated with this emoticon |
151 | */ |
152 | void addEmoticonIndex(const QString &path, const QStringList &emoList); |
153 | |
154 | /** |
155 | * Remove an emoticon from the index |
156 | * @param path path to the emoticon |
157 | * @param emoList list of text associated with this emoticon |
158 | */ |
159 | void removeEmoticonIndex(const QString &path, const QStringList &emoList); |
160 | |
161 | /** |
162 | * Private class |
163 | */ |
164 | KEmoticonsProviderPrivate * const d; |
165 | }; |
166 | |
167 | #endif /* KEMOTICONS_PROVIDER_H */ |
168 | |
169 | // kate: space-indent on; indent-width 4; replace-tabs on; |
170 | |