| 1 | /* |
| 2 | * Copyright (C) 2016 Canonical, Ltd. |
| 3 | * |
| 4 | * This program is free software: you can redistribute it and/or modify it under |
| 5 | * the terms of the GNU Lesser General Public License version 3, as published by |
| 6 | * the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 9 | * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, |
| 10 | * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 11 | * Lesser General Public License for more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU Lesser General Public License |
| 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 15 | */ |
| 16 | |
| 17 | #ifndef GMENUMODELEXPORTER_H |
| 18 | #define GMENUMODELEXPORTER_H |
| 19 | |
| 20 | #include "gmenumodelplatformmenu.h" |
| 21 | |
| 22 | #include <gio/gio.h> |
| 23 | |
| 24 | #include <QTimer> |
| 25 | #include <QMap> |
| 26 | #include <QSet> |
| 27 | #include <QMetaObject> |
| 28 | |
| 29 | class LomiriAppMenuExtraActionHandler; |
| 30 | |
| 31 | // Base class for a gmenumodel exporter |
| 32 | class LomiriGMenuModelExporter : public QObject |
| 33 | { |
| 34 | Q_OBJECT |
| 35 | public: |
| 36 | virtual ~LomiriGMenuModelExporter(); |
| 37 | |
| 38 | void exportModels(); |
| 39 | void unexportModels(); |
| 40 | |
| 41 | QString menuPath() const { return m_menuPath;} |
| 42 | |
| 43 | void aboutToShow(quint64 tag); |
| 44 | |
| 45 | protected: |
| 46 | LomiriGMenuModelExporter(QObject *parent); |
| 47 | |
| 48 | GMenuItem *createSubmenu(QPlatformMenu* platformMenu, LomiriPlatformMenuItem* forItem); |
| 49 | GMenuItem *createMenuItem(QPlatformMenuItem* platformMenuItem, GMenu *parentMenu); |
| 50 | GMenuItem *createSection(QList<QPlatformMenuItem*>::const_iterator iter, QList<QPlatformMenuItem*>::const_iterator end); |
| 51 | void addAction(const QByteArray& name, LomiriPlatformMenuItem* gplatformItem, GMenu *parentMenu); |
| 52 | |
| 53 | void addSubmenuItems(LomiriPlatformMenu* gplatformMenu, GMenu* menu); |
| 54 | void processItemForGMenu(QPlatformMenuItem* item, GMenu* gmenu); |
| 55 | |
| 56 | void clear(); |
| 57 | |
| 58 | void timerEvent(QTimerEvent *e) override; |
| 59 | |
| 60 | protected: |
| 61 | GDBusConnection *m_connection; |
| 62 | GMenu *m_gmainMenu; |
| 63 | GSimpleActionGroup *m_gactionGroup; |
| 64 | guint m_exportedModel; |
| 65 | guint m_exportedActions; |
| 66 | LomiriAppMenuExtraActionHandler *m_lomiriAppMenuExtraHandler; |
| 67 | QTimer m_structureTimer; |
| 68 | QString m_menuPath; |
| 69 | |
| 70 | // LomiriPlatformMenu::tag -> LomiriPlatformMenu |
| 71 | QMap<quint64, LomiriPlatformMenu*> m_submenusWithTag; |
| 72 | |
| 73 | // LomiriPlatformMenu -> reload TimerId (startTimer) |
| 74 | QHash<LomiriPlatformMenu*, int> m_reloadMenuTimers; |
| 75 | |
| 76 | QHash<LomiriPlatformMenu*, GMenu*> m_gmenusForMenus; |
| 77 | |
| 78 | QHash<GMenu*, QSet<QByteArray>> m_actions; |
| 79 | QHash<GMenu*, QVector<QMetaObject::Connection>> m_propertyConnections; |
| 80 | |
| 81 | }; |
| 82 | |
| 83 | // Class which exports a qt platform menu bar. |
| 84 | class LomiriMenuBarExporter : public LomiriGMenuModelExporter |
| 85 | { |
| 86 | public: |
| 87 | LomiriMenuBarExporter(LomiriPlatformMenuBar *parent); |
| 88 | ~LomiriMenuBarExporter(); |
| 89 | }; |
| 90 | |
| 91 | // Class which exports a qt platform menu. |
| 92 | // This will allow exporting of context menus. |
| 93 | class LomiriMenuExporter : public LomiriGMenuModelExporter |
| 94 | { |
| 95 | public: |
| 96 | LomiriMenuExporter(LomiriPlatformMenu *parent); |
| 97 | ~LomiriMenuExporter(); |
| 98 | }; |
| 99 | |
| 100 | #endif // GMENUMODELEXPORTER_H |