File indexing completed on 2024-04-28 11:43:45

0001 /*
0002     SPDX-FileCopyrightText: 2005-2009 Olivier Goffart <ogoffart at kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005 */
0006 
0007 #ifndef KNOTIFYCONFIG_H
0008 #define KNOTIFYCONFIG_H
0009 
0010 #include <KSharedConfig>
0011 
0012 #include "knotifications_export.h"
0013 #include <QImage>
0014 #include <QObject> //for Wid
0015 #include <QPair>
0016 
0017 typedef QList<QPair<QString, QString>> ContextList;
0018 
0019 /**
0020  * @class KNotifyImage knotifyconfig.h KNotifyConfig
0021  *
0022  * An image with lazy loading from the byte array
0023  */
0024 class KNOTIFICATIONS_EXPORT KNotifyImage
0025 {
0026 public:
0027     KNotifyImage()
0028         : dirty(false)
0029     {
0030     }
0031     KNotifyImage(const QByteArray &data)
0032         : source(data)
0033         , dirty(true)
0034     {
0035     }
0036     QImage toImage();
0037     bool isNull()
0038     {
0039         return dirty ? source.isEmpty() : image.isNull();
0040     }
0041     QByteArray data() const
0042     {
0043         return source;
0044     }
0045 
0046 private:
0047     QByteArray source;
0048     QImage image;
0049     bool dirty;
0050 };
0051 
0052 /**
0053  * @class KNotifyConfig knotifyconfig.h KNotifyConfig
0054  *
0055  * Represent the configuration for an event
0056  * @author Olivier Goffart <ogoffart@kde.org>
0057  */
0058 class KNOTIFICATIONS_EXPORT KNotifyConfig
0059 {
0060 public:
0061     KNotifyConfig(const QString &appname, const ContextList &_contexts, const QString &_eventid);
0062     ~KNotifyConfig();
0063 
0064     KNotifyConfig *copy() const;
0065 
0066     /**
0067      * @return entry from the knotifyrc file
0068      *
0069      * This will return the configuration from the user for the given key.
0070      * It first look into the user config file, and then in the global config file.
0071      *
0072      * return a null string if the entry doesn't exist
0073      */
0074     QString readEntry(const QString &entry, bool path = false);
0075 
0076     /**
0077      * the pixmap to put on the notification
0078      */
0079     KNotifyImage image;
0080 
0081     /**
0082      * the name of the application that triggered the notification
0083      */
0084     QString appname;
0085 
0086     /**
0087      * @internal
0088      */
0089     KSharedConfig::Ptr eventsfile, configfile;
0090     ContextList contexts;
0091 
0092     /**
0093      * the name of the notification
0094      */
0095     QString eventid;
0096 
0097     /**
0098      * reparse the cached configs.  to be used when the config may have changed
0099      */
0100     static void reparseConfiguration();
0101 
0102     static void reparseSingleConfiguration(const QString &app);
0103 };
0104 
0105 #endif