File indexing completed on 2024-04-28 05:35:32

0001 /* This file is part of the dbusmenu-qt library
0002     SPDX-FileCopyrightText: 2009 Canonical
0003     SPDX-FileContributor: Aurelien Gateau <aurelien.gateau@canonical.com>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 #pragma once
0008 
0009 // Qt
0010 #include <QObject>
0011 
0012 class QAction;
0013 class QDBusPendingCallWatcher;
0014 class QIcon;
0015 class QMenu;
0016 
0017 class DBusMenuImporterPrivate;
0018 
0019 /**
0020  * A DBusMenuImporter instance can recreate a menu serialized over DBus by
0021  * DBusMenuExporter
0022  */
0023 class DBusMenuImporter : public QObject
0024 {
0025     Q_OBJECT
0026 public:
0027     /**
0028      * Creates a DBusMenuImporter listening over DBus on service, path
0029      */
0030     DBusMenuImporter(const QString &service, const QString &path, QObject *parent = nullptr);
0031 
0032     ~DBusMenuImporter() override;
0033 
0034     QAction *actionForId(int id) const;
0035 
0036     /**
0037      * The menu created from listening to the DBusMenuExporter over DBus
0038      */
0039     QMenu *menu() const;
0040 
0041 public Q_SLOTS:
0042     /**
0043      * Load the menu
0044      *
0045      * Will Q_EMIT menuUpdated() when complete.
0046      * This should be done before showing a menu
0047      */
0048     void updateMenu();
0049 
0050     void updateMenu(QMenu *menu);
0051 
0052 Q_SIGNALS:
0053     /**
0054      * Emitted after a call to updateMenu().
0055      * @see updateMenu()
0056      */
0057     void menuUpdated(QMenu *);
0058 
0059     /**
0060      * Emitted when the exporter was asked to activate an action
0061      */
0062     void actionActivationRequested(QAction *);
0063 
0064 protected:
0065     /**
0066      * Must create a menu, may be customized to fit host appearance.
0067      * Default implementation creates a simple QMenu.
0068      */
0069     virtual QMenu *createMenu(QWidget *parent);
0070 
0071     /**
0072      * Must convert a name into an icon.
0073      * Default implementation returns a null icon.
0074      */
0075     virtual QIcon iconForName(const QString &);
0076 
0077 private Q_SLOTS:
0078     void sendClickedEvent(int);
0079     void slotMenuAboutToShow();
0080     void slotMenuAboutToHide();
0081     void slotAboutToShowDBusCallFinished(QDBusPendingCallWatcher *);
0082     void slotItemActivationRequested(int id, uint timestamp);
0083     void processPendingLayoutUpdates();
0084     void slotLayoutUpdated(uint revision, int parentId);
0085     void slotGetLayoutFinished(QDBusPendingCallWatcher *);
0086 
0087 private:
0088     Q_DISABLE_COPY(DBusMenuImporter)
0089     DBusMenuImporterPrivate *const d;
0090     friend class DBusMenuImporterPrivate;
0091 
0092     // Use Q_PRIVATE_SLOT to avoid exposing DBusMenuItemList
0093     Q_PRIVATE_SLOT(d, void slotItemsPropertiesUpdated(const DBusMenuItemList &updatedList, const DBusMenuItemKeysList &removedList))
0094 };