File indexing completed on 2024-06-23 03:56:31

0001 /* This file is part of the dbusmenu-qt library
0002    SPDX-FileCopyrightText: 2009 Canonical
0003    Author: Aurelien Gateau <aurelien.gateau@canonical.com>
0004 
0005    SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 #ifndef DBUSMENUEXPORTER_H
0008 #define DBUSMENUEXPORTER_H
0009 
0010 // Qt
0011 #include <QDBusConnection>
0012 #include <QObject>
0013 
0014 class QAction;
0015 class QMenu;
0016 
0017 class DBusMenuExporterPrivate;
0018 
0019 /**
0020  * A DBusMenuExporter instance can serialize a menu over DBus
0021  */
0022 class DBusMenuExporter : public QObject
0023 {
0024     Q_OBJECT
0025 public:
0026     /**
0027      * Creates a DBusMenuExporter exporting menu at the dbus object path
0028      * dbusObjectPath, using the given dbusConnection.
0029      * The instance adds itself to the menu children.
0030      */
0031     DBusMenuExporter(const QString &dbusObjectPath, QMenu *menu, const QDBusConnection &dbusConnection = QDBusConnection::sessionBus());
0032 
0033     ~DBusMenuExporter() override;
0034 
0035     /**
0036      * Asks the matching DBusMenuImporter to activate @p action. For menus it
0037      * means popup them, for items it means triggering the associated action.
0038      */
0039     void activateAction(QAction *action);
0040 
0041     /**
0042      * The status of the menu. Can be one of "normal" or "notice". This can be
0043      * used to notify the other side the menu should be made more visible.
0044      * For example, appmenu uses it to tell Unity panel to show/hide the menubar
0045      * when the Alt modifier is pressed/released.
0046      */
0047     void setStatus(const QString &status);
0048 
0049     /**
0050      * Returns the status of the menu.
0051      * @ref setStatus
0052      */
0053     QString status() const;
0054 
0055 protected:
0056     /**
0057      * Must extract the icon name for action. This is the name which will
0058      * be used to present the icon over DBus.
0059      * Default implementation returns action->icon().name() when built on Qt
0060      * >= 4.7 and a null string otherwise.
0061      */
0062     virtual QString iconNameForAction(QAction *action);
0063 
0064 private Q_SLOTS:
0065     void doUpdateActions();
0066     void doEmitLayoutUpdated();
0067     void slotActionDestroyed(QObject *);
0068 
0069 private:
0070     Q_DISABLE_COPY(DBusMenuExporter)
0071     DBusMenuExporterPrivate *const d;
0072 
0073     friend class DBusMenuExporterPrivate;
0074     friend class DBusMenuExporterDBus;
0075     friend class DBusMenu;
0076 };
0077 
0078 #endif /* DBUSMENUEXPORTER_H */