File indexing completed on 2024-05-19 15:10:52
0001 /* 0002 SPDX-FileCopyrightText: 2008 Carlo Segato <brandon.ml@gmail.com> 0003 0004 SPDX-License-Identifier: LGPL-2.1-or-later 0005 */ 0006 0007 #ifndef KEMOTICONS_PROVIDER_H 0008 #define KEMOTICONS_PROVIDER_H 0009 0010 #include <kemoticons_export.h> 0011 0012 #include <QObject> 0013 #include <QStringList> 0014 0015 class KEmoticonsProviderPrivate; 0016 struct Emoticon; 0017 0018 /** 0019 * This is the base abstract class for the emoticon provider plugins. 0020 */ 0021 class KEMOTICONS_EXPORT KEmoticonsProvider : public QObject 0022 { 0023 Q_OBJECT 0024 public: 0025 struct Emoticon { 0026 Emoticon() {} 0027 /* sort by longest to shortest matchText */ 0028 bool operator < (const Emoticon &e) const 0029 { 0030 return matchText.length() > e.matchText.length(); 0031 } 0032 QString matchText; 0033 QString matchTextEscaped; 0034 QString picPath; 0035 QString picHTMLCode; 0036 }; 0037 0038 /** 0039 * Options to pass to addEmoticon 0040 */ 0041 enum AddEmoticonOption { 0042 DoNotCopy, /**<< Don't copy the emoticon file into the theme directory */ 0043 Copy /**<< Copy the emoticon file into the theme directory */ 0044 }; 0045 0046 /** 0047 * Default constructor 0048 */ 0049 explicit KEmoticonsProvider(QObject *parent = nullptr); 0050 0051 /** 0052 * Destructor 0053 */ 0054 ~KEmoticonsProvider() override; 0055 0056 /** 0057 * Loads the emoticon theme inside the directory @p path 0058 * @param path path to the directory 0059 * @return @c true if the emoticon theme is successfully loaded 0060 */ 0061 virtual bool loadTheme(const QString &path) = 0; 0062 0063 /** 0064 * Removes the emoticon @p emo. This doesn't delete the image file. 0065 * @param emo the emoticon text to remove 0066 * @return @c true if the emoticon theme is successfully removed 0067 */ 0068 virtual bool removeEmoticon(const QString &emo) = 0; 0069 0070 /** 0071 * Adds the emoticon @p emo with text @p text 0072 * @param emo path to the emoticon image 0073 * @param text the emoticon text. If alternative texts are to be added, 0074 * use spaces to separate them. 0075 * @param copy whether or not to copy @p emo into the theme directory 0076 * @return @c true if the emoticon is successfully added 0077 */ 0078 virtual bool addEmoticon(const QString &emo, const QString &text, AddEmoticonOption option = DoNotCopy) = 0; 0079 0080 #if KEMOTICONS_ENABLE_DEPRECATED_SINCE(5, 0) 0081 /** 0082 * Saves the emoticon theme 0083 * 0084 * @deprecated since 5.0, use saveTheme() instead 0085 */ 0086 KEMOTICONS_DEPRECATED_VERSION(5, 0, "Use KEmoticonsProvider::saveTheme()") 0087 void save(); 0088 #endif 0089 0090 /** 0091 * Saves the emoticon theme 0092 * @since 5.0 0093 */ 0094 virtual void saveTheme() = 0; 0095 0096 /** 0097 * Returns the theme name 0098 */ 0099 QString themeName() const; 0100 0101 /** 0102 * Sets the emoticon theme name 0103 * @param name name of the theme 0104 */ 0105 void setThemeName(const QString &name); 0106 0107 /** 0108 * Returns the emoticon theme path 0109 */ 0110 QString themePath() const; 0111 0112 /** 0113 * Returns the file name of the emoticon theme 0114 */ 0115 QString fileName() const; 0116 0117 /** 0118 * Returns a QHash that contains the emoticon path as keys and the text as values 0119 */ 0120 QHash<QString, QStringList> emoticonsMap() const; 0121 0122 /** 0123 * Returns a QHash that contains emoticons indexed by the first char 0124 */ 0125 QHash<QChar, QList<Emoticon> > emoticonsIndex() const; 0126 0127 #if KEMOTICONS_ENABLE_DEPRECATED_SINCE(5, 0) 0128 /** 0129 * Creates a new theme 0130 * 0131 * @deprecated since 5.0, use newTheme() instead 0132 */ 0133 KEMOTICONS_DEPRECATED_VERSION(5, 0, "Use KEmoticonsProvider::newTheme()") 0134 void createNew(); 0135 #endif 0136 0137 /** 0138 * Creates a new theme 0139 * @since 5.0 0140 */ 0141 virtual void newTheme() = 0; 0142 0143 /** 0144 * If a preferred size is set, all parsed emoticons will be 0145 * returned with the @p size 0146 * 0147 * @param size The desired QSize of parsed emoticons 0148 * @since 5.23 0149 */ 0150 void setPreferredEmoticonSize(const QSize &size); 0151 0152 /** 0153 * Returns size in which parsed emoticons will be returned. 0154 * 0155 * If the QSize returned is not valid (isValid() == false), 0156 * then the default will be used, that is the actual file size. 0157 * 0158 * @since 5.23 0159 */ 0160 QSize preferredEmoticonSize() const; 0161 0162 protected: 0163 /** 0164 * Sets the theme inside the directory @p path 0165 * @param path path to the directory 0166 * @since 5.0 0167 */ 0168 void setThemePath(const QString &path); 0169 0170 /** 0171 * Copies the emoticon image to the theme directory 0172 * @param emo path to the emoticon image 0173 * @return true if the emoticon is successfully copied 0174 * @since 5.0 0175 */ 0176 bool copyEmoticon(const QString &emo); 0177 0178 /** 0179 * Clears the emoticons map 0180 */ 0181 void clearEmoticonsMap(); 0182 0183 #if KEMOTICONS_ENABLE_DEPRECATED_SINCE(5, 0) 0184 /** 0185 * Inserts a new item in the emoticon map 0186 * 0187 * @deprecated since 5.0, use addMapItem() instead 0188 */ 0189 KEMOTICONS_DEPRECATED_VERSION(5, 0, "Use KEmoticonsProvider::addMapItem(QString, QStringList)") 0190 void addEmoticonsMap(QString key, QStringList value); 0191 #endif 0192 0193 /** 0194 * Inserts a new item in the emoticon map 0195 * @since 5.0 0196 * @see emoticonsMap() 0197 */ 0198 //FIXME kf6: use const'ref here 0199 void addMapItem(QString key, QStringList value); 0200 0201 #if KEMOTICONS_ENABLE_DEPRECATED_SINCE(5, 0) 0202 /** 0203 * Removes an item from the emoticon map 0204 * 0205 * @deprecated since 5.0, use removeMapItem() instead 0206 */ 0207 KEMOTICONS_DEPRECATED_VERSION(5, 0, "Use KEmoticonsProvider::removeMapItem(QString)") 0208 void removeEmoticonsMap(QString key); 0209 #endif 0210 /** 0211 * Removes an item from the emoticon map 0212 * @since 5.0 0213 * @see emoticonsMap() 0214 */ 0215 void removeMapItem(QString key); 0216 0217 #if KEMOTICONS_ENABLE_DEPRECATED_SINCE(5, 0) 0218 /** 0219 * Adds an emoticon to the index 0220 * @param path path to the emoticon 0221 * @param emoList list of text associated with this emoticon 0222 * 0223 * @deprecated since 5.0, use addIndexItem() instead 0224 */ 0225 KEMOTICONS_DEPRECATED_VERSION(5, 0, "Use KEmoticonsProvider::addIndexItem(const QString &, const QStringList &)") 0226 void addEmoticonIndex(const QString &path, const QStringList &emoList); 0227 #endif 0228 /** 0229 * Adds an emoticon to the index 0230 * @param path path to the emoticon 0231 * @param emoList list of text associated with this emoticon 0232 * @since 5.0 0233 * @see emoticonsIndex() 0234 */ 0235 void addIndexItem(const QString &path, const QStringList &emoList); 0236 0237 #if KEMOTICONS_ENABLE_DEPRECATED_SINCE(5, 0) 0238 /** 0239 * Removes an emoticon from the index 0240 * @param path path to the emoticon 0241 * @param emoList list of text associated with this emoticon 0242 * 0243 * @deprecated since 5.0, use removeIndexItem() instead 0244 */ 0245 KEMOTICONS_DEPRECATED_VERSION(5, 0, "Use KEmoticonsProvider::removeIndexItem(const QString &, const QStringList &)") 0246 void removeEmoticonIndex(const QString &path, const QStringList &emoList); 0247 #endif 0248 /** 0249 * Removes an emoticon from the index 0250 * @param path path to the emoticon 0251 * @param emoList list of text associated with this emoticon 0252 * @since 5.0 0253 * @see emoticonsIndex() 0254 */ 0255 void removeIndexItem(const QString &path, const QStringList &emoList); 0256 0257 private: 0258 /** 0259 * Private implementation class 0260 */ 0261 const QScopedPointer<KEmoticonsProviderPrivate> d; 0262 }; 0263 0264 #endif /* KEMOTICONS_PROVIDER_H */ 0265