File indexing completed on 2024-04-28 15:29:12

0001 /*
0002     This file is part of the KDE libraries
0003     SPDX-FileCopyrightText: 2009 Marco Martin <notmart@gmail.com>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #ifndef KSTATUSNOTIFIERITEMDBUS_H
0009 #define KSTATUSNOTIFIERITEMDBUS_H
0010 
0011 #include <QDBusArgument>
0012 #include <QDBusConnection>
0013 #include <QDBusObjectPath>
0014 #include <QObject>
0015 #include <QString>
0016 #include <QVector>
0017 
0018 // Custom message type for DBus
0019 struct KDbusImageStruct {
0020     int width;
0021     int height;
0022     QByteArray data;
0023 };
0024 
0025 typedef QVector<KDbusImageStruct> KDbusImageVector;
0026 
0027 struct KDbusToolTipStruct {
0028     QString icon;
0029     KDbusImageVector image;
0030     QString title;
0031     QString subTitle;
0032 };
0033 
0034 class KStatusNotifierItem;
0035 
0036 class KStatusNotifierItemDBus : public QObject
0037 {
0038     Q_OBJECT
0039 
0040     Q_PROPERTY(QString Category READ Category)
0041     Q_PROPERTY(QString Id READ Id)
0042     Q_PROPERTY(QString Title READ Title)
0043     Q_PROPERTY(QString Status READ Status)
0044     Q_PROPERTY(int WindowId READ WindowId)
0045     Q_PROPERTY(bool ItemIsMenu READ ItemIsMenu)
0046     Q_PROPERTY(QString IconName READ IconName)
0047     Q_PROPERTY(KDbusImageVector IconPixmap READ IconPixmap)
0048     Q_PROPERTY(QString OverlayIconName READ OverlayIconName)
0049     Q_PROPERTY(KDbusImageVector OverlayIconPixmap READ OverlayIconPixmap)
0050     Q_PROPERTY(QString AttentionIconName READ AttentionIconName)
0051     Q_PROPERTY(KDbusImageVector AttentionIconPixmap READ AttentionIconPixmap)
0052     Q_PROPERTY(QString AttentionMovieName READ AttentionMovieName)
0053     Q_PROPERTY(KDbusToolTipStruct ToolTip READ ToolTip)
0054     Q_PROPERTY(QString IconThemePath READ IconThemePath)
0055     Q_PROPERTY(QDBusObjectPath Menu READ Menu)
0056 
0057     friend class KStatusNotifierItem;
0058 
0059 public:
0060     explicit KStatusNotifierItemDBus(KStatusNotifierItem *parent);
0061     ~KStatusNotifierItemDBus() override;
0062 
0063     /**
0064      * @return the dbus connection used by this object
0065      */
0066     QDBusConnection dbusConnection() const;
0067 
0068     /**
0069      * @return the service this object is registered on the bus under
0070      */
0071     QString service() const;
0072 
0073     /**
0074      * @return the category of the application associated to this item
0075      * @see Category
0076      */
0077     QString Category() const;
0078 
0079     /**
0080      * @return the id of this item
0081      */
0082     QString Id() const;
0083 
0084     /**
0085      * @return the title of this item
0086      */
0087     QString Title() const;
0088 
0089     /**
0090      * @return The status of this item
0091      * @see Status
0092      */
0093     QString Status() const;
0094 
0095     /**
0096      * @return The id of the main window of the application that controls the item
0097      */
0098     int WindowId() const;
0099 
0100     /**
0101      * @return The item only support the context menu, the visualization should prefer sending ContextMenu() instead of Activate()
0102      */
0103     bool ItemIsMenu() const;
0104 
0105     /**
0106      * @return the name of the main icon to be displayed
0107      * if image() is not empty this will always return an empty string
0108      */
0109     QString IconName() const;
0110 
0111     /**
0112      * @return a serialization of the icon data
0113      */
0114     KDbusImageVector IconPixmap() const;
0115 
0116     /**
0117      * @return the name of the overlay of the main icon to be displayed
0118      * if image() is not empty this will always return an empty string
0119      */
0120     QString OverlayIconName() const;
0121 
0122     /**
0123      * @return a serialization of the icon data
0124      */
0125     KDbusImageVector OverlayIconPixmap() const;
0126 
0127     /**
0128      * @return the name of the icon to be displayed when the application
0129      * is requesting the user's attention
0130      * if attentionImage() is not empty this will always return an empty string
0131      */
0132     QString AttentionIconName() const;
0133 
0134     /**
0135      * @return a serialization of the requesting attention icon data
0136      */
0137     KDbusImageVector AttentionIconPixmap() const;
0138 
0139     /**
0140      * @return the name of the attention movie
0141      */
0142     QString AttentionMovieName() const;
0143 
0144     /**
0145      * all the data needed for a tooltip
0146      */
0147     KDbusToolTipStruct ToolTip() const;
0148 
0149     /**
0150      * @return path to extra icon theme, to load application specific icons
0151      */
0152     QString IconThemePath() const;
0153 
0154     /**
0155      * @return object path to the dbusmenu object
0156      */
0157     QDBusObjectPath Menu() const;
0158 
0159 public Q_SLOTS:
0160     // interaction
0161     /**
0162      * Shows the context menu associated to this item
0163      * at the desired screen position
0164      */
0165     void ContextMenu(int x, int y);
0166 
0167     /**
0168      * Shows the main widget and try to position it on top
0169      * of the other windows, if the widget is already visible, hide it.
0170      */
0171     void Activate(int x, int y);
0172 
0173     /**
0174      * The user activated the item in an alternate way (for instance with middle mouse button, this depends from the systray implementation)
0175      */
0176     void SecondaryActivate(int x, int y);
0177 
0178     /**
0179      * Inform this item that the mouse wheel was used on its representation
0180      */
0181     void Scroll(int delta, const QString &orientation);
0182 
0183     /**
0184      * Provide a @p token for xdg_activation_v1
0185      *
0186      * So that the Wayland compositor knows who is requesting an activation.
0187      */
0188     void ProvideXdgActivationToken(const QString &token);
0189 
0190 Q_SIGNALS:
0191     /**
0192      * Inform the systemtray that the own main icon has been changed,
0193      * so should be reloaded
0194      */
0195     void NewIcon();
0196 
0197     /**
0198      * Inform the systemtray that there is a new icon to be used as overlay
0199      */
0200     void NewOverlayIcon();
0201 
0202     /**
0203      * Inform the systemtray that the requesting attention icon
0204      * has been changed, so should be reloaded
0205      */
0206     void NewAttentionIcon();
0207 
0208     /**
0209      * Inform the systemtray that a new context menu has been set.
0210      */
0211     void NewMenu();
0212 
0213     /**
0214      * Inform the systemtray that something in the tooltip has been changed
0215      */
0216     void NewToolTip();
0217 
0218     /**
0219      * Signal the new status when it has been changed
0220      * @see Status
0221      */
0222     void NewStatus(const QString &status);
0223 
0224 private:
0225     KStatusNotifierItem *m_statusNotifierItem;
0226     QString m_connId;
0227     QString m_xdgActivationToken;
0228     QDBusConnection m_dbus;
0229     static int s_serviceCount;
0230 };
0231 
0232 const QDBusArgument &operator<<(QDBusArgument &argument, const KDbusImageStruct &icon);
0233 const QDBusArgument &operator>>(const QDBusArgument &argument, KDbusImageStruct &icon);
0234 
0235 Q_DECLARE_METATYPE(KDbusImageStruct)
0236 
0237 const QDBusArgument &operator<<(QDBusArgument &argument, const KDbusImageVector &iconVector);
0238 const QDBusArgument &operator>>(const QDBusArgument &argument, KDbusImageVector &iconVector);
0239 
0240 Q_DECLARE_METATYPE(KDbusImageVector)
0241 
0242 const QDBusArgument &operator<<(QDBusArgument &argument, const KDbusToolTipStruct &toolTip);
0243 const QDBusArgument &operator>>(const QDBusArgument &argument, KDbusToolTipStruct &toolTip);
0244 
0245 Q_DECLARE_METATYPE(KDbusToolTipStruct)
0246 
0247 #endif