File indexing completed on 2024-05-19 15:10:51

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_H
0008 #define KEMOTICONS_H
0009 
0010 #include "kemoticons_export.h"
0011 #include "kemoticonstheme.h"
0012 
0013 #include <QObject>
0014 
0015 #include <KServiceTypeTrader>
0016 
0017 class KEmoticonsPrivate;
0018 
0019 /**
0020  * This class can be used to retrieve, install, create emoticons theme.
0021  * For example, if you want to get the current emoticon theme
0022  * @code
0023  * KEmoticons ke;
0024  * KEmoticonsTheme et = ke.theme();
0025  * //do whatever you want with the theme
0026  * @endcode
0027  * It can also be used to set the emoticon theme and the parse mode in the config file
0028  * @author Carlo Segato (brandon.ml@gmail.com)
0029  */
0030 
0031 class KEMOTICONS_EXPORT KEmoticons : public QObject
0032 {
0033     Q_OBJECT
0034 public:
0035 
0036     /**
0037      * Default constructor
0038      */
0039     KEmoticons();
0040 
0041     /**
0042      * Destructor
0043      */
0044     ~KEmoticons() override;
0045 
0046     /**
0047      * Retrieves the current emoticon theme
0048      * @return the current KEmoticonsTheme
0049      */
0050     KEmoticonsTheme theme() const;
0051 
0052     /**
0053     * Retrieves the emoticon theme with name @p name
0054     * @param name name of the theme
0055     * @return the KEmoticonsTheme with name @p name
0056     */
0057     KEmoticonsTheme theme(const QString &name) const;
0058 
0059     /**
0060      * Retrieves the current emoticon theme name
0061      */
0062     static QString currentThemeName();
0063 
0064     /**
0065      * Returns a list of installed emoticon themes
0066      */
0067     static QStringList themeList();
0068 
0069     /**
0070      * Sets @p theme as the current emoticon theme
0071      * @param theme a reference to a KEmoticonsTheme object
0072      */
0073     static void setTheme(const KEmoticonsTheme &theme);
0074 
0075     /**
0076      * Sets @p theme as the current emoticon theme
0077      * @param theme the name of a theme
0078      */
0079     static void setTheme(const QString &theme);
0080 
0081     /**
0082      * Creates a new emoticon theme
0083      * @code
0084      * KEmoticonsTheme theme;
0085      * KService::List srv = KServiceTypeTrader::self()->query("KEmoticons");
0086      * for (int i = 0; i < srv.size(); ++i) {
0087      *     // we want to create a kde emoticons theme
0088      *     if (srv.at(i)->property("X-KDE-EmoticonsFileName").toString() == "emoticons.xml") {
0089      *         theme = KEmoticons().newTheme("test", srv.at(i));
0090      *     }
0091      * }
0092      * @endcode
0093      * @param name the name of the new emoticon theme
0094      * @param service the kind of emoticon theme to create
0095      */
0096     KEmoticonsTheme newTheme(const QString &name, const KService::Ptr &service);
0097 
0098     /**
0099      * Installs all emoticon themes inside the archive @p archiveName
0100      * @param archiveName path to the archive
0101      * @return a list of installed themes
0102      */
0103     QStringList installTheme(const QString &archiveName);
0104 
0105     /**
0106      * Sets the parse mode to @p mode
0107      */
0108     static void setParseMode(KEmoticonsTheme::ParseMode mode);
0109 
0110     /**
0111      * Returns the current parse mode
0112      */
0113     static KEmoticonsTheme::ParseMode parseMode();
0114 
0115     /**
0116      * If a preferred size is set, all parsed emoticons will be
0117      * returned with the @p size
0118      *
0119      * @param size The desired QSize of parsed emoticons
0120      * @since 5.23
0121      */
0122     void setPreferredEmoticonSize(const QSize &size);
0123 
0124     /**
0125      * Returns size in which parsed emoticons will be returned.
0126      *
0127      * If the QSize returned is not valid (isValid() == false),
0128      * then the default will be used, that is the actual file size.
0129      *
0130      * @since 5.23
0131      */
0132     QSize preferredEmoticonSize() const;
0133 
0134 private:
0135     /**
0136      * Private implementation class
0137      */
0138     const QScopedPointer<KEmoticonsPrivate> d;
0139 };
0140 
0141 #endif /* KEMOTICONS_H */
0142