./0000755000004100000410000000000013051427137011246 5ustar www-datawww-data./.qmake.conf0000644000004100000410000000000013051427137013257 0ustar www-datawww-data./README0000644000004100000410000000123313051427137012125 0ustar www-datawww-data# Usage After installing the appmenu-qt5 platform theme (to the qt5/plugins/platformthemes/ plugin directory) for the appmenu support to work you need to force Qt5 to use this platform theme plugin. This can be done by setting the QT_QPA_PLATFORMTHEME environment variable to appmenu-qt5, e.g.: QT_QPA_PLATFORMTHEME=appmenu-qt5 Now every Qt5 application that is started in the environment will export its menu through DBus. The source also provides a profile.d script that sets the environment to enable appmenu-qt5 as the platformtheme by default. To install this script, simply run `qmake CONFIG+=enable-by-default` when configuring the source before building. ./COPYING0000644000004100000410000001674313051427137012314 0ustar www-datawww-data GNU LESSER GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU General Public License, supplemented by the additional permissions listed below. 0. Additional Definitions. As used herein, "this License" refers to version 3 of the GNU Lesser General Public License, and the "GNU GPL" refers to version 3 of the GNU General Public License. "The Library" refers to a covered work governed by this License, other than an Application or a Combined Work as defined below. An "Application" is any work that makes use of an interface provided by the Library, but which is not otherwise based on the Library. Defining a subclass of a class defined by the Library is deemed a mode of using an interface provided by the Library. A "Combined Work" is a work produced by combining or linking an Application with the Library. The particular version of the Library with which the Combined Work was made is also called the "Linked Version". The "Minimal Corresponding Source" for a Combined Work means the Corresponding Source for the Combined Work, excluding any source code for portions of the Combined Work that, considered in isolation, are based on the Application, and not on the Linked Version. The "Corresponding Application Code" for a Combined Work means the object code and/or source code for the Application, including any data and utility programs needed for reproducing the Combined Work from the Application, but excluding the System Libraries of the Combined Work. 1. Exception to Section 3 of the GNU GPL. You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL. 2. Conveying Modified Versions. If you modify a copy of the Library, and, in your modifications, a facility refers to a function or data to be supplied by an Application that uses the facility (other than as an argument passed when the facility is invoked), then you may convey a copy of the modified version: a) under this License, provided that you make a good faith effort to ensure that, in the event an Application does not supply the function or data, the facility still operates, and performs whatever part of its purpose remains meaningful, or b) under the GNU GPL, with none of the additional permissions of this License applicable to that copy. 3. Object Code Incorporating Material from Library Header Files. The object code form of an Application may incorporate material from a header file that is part of the Library. You may convey such object code under terms of your choice, provided that, if the incorporated material is not limited to numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length), you do both of the following: a) Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the object code with a copy of the GNU GPL and this license document. 4. Combined Works. You may convey a Combined Work under terms of your choice that, taken together, effectively do not restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications, if you also do each of the following: a) Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the Combined Work with a copy of the GNU GPL and this license document. c) For a Combined Work that displays copyright notices during execution, include the copyright notice for the Library among these notices, as well as a reference directing the user to the copies of the GNU GPL and this license document. d) Do one of the following: 0) Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source. 1) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user's computer system, and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version. e) Provide Installation Information, but only if you would otherwise be required to provide such information under section 6 of the GNU GPL, and only to the extent that such information is necessary to install and execute a modified version of the Combined Work produced by recombining or relinking the Application with a modified version of the Linked Version. (If you use option 4d0, the Installation Information must accompany the Minimal Corresponding Source and Corresponding Application Code. If you use option 4d1, you must provide the Installation Information in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.) 5. Combined Libraries. You may place library facilities that are a work based on the Library side by side in a single library together with other library facilities that are not Applications and are not covered by this License, and convey such a combined library under terms of your choice, if you do both of the following: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities, conveyed under the terms of this License. b) Give prominent notice with the combined library that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 6. Revised Versions of the GNU Lesser General Public License. The Free Software Foundation may publish revised and/or new versions of the GNU Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library as you received it specifies that a certain numbered version of the GNU Lesser General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that published version or of any later version published by the Free Software Foundation. If the Library as you received it does not specify a version number of the GNU Lesser General Public License, you may choose any version of the GNU Lesser General Public License ever published by the Free Software Foundation. If the Library as you received it specifies that a proxy can decide whether future versions of the GNU Lesser General Public License shall apply, that proxy's public statement of acceptance of any version is permanent authorization for you to choose that version for the Library. ./src/0000755000004100000410000000000013051427141012030 5ustar www-datawww-data./src/appmenuplatformmenubar.h0000644000004100000410000000361613051427137017000 0ustar www-datawww-data/* * Copyright 2013-2014 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, version 3 of the License. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Author: Łukasz 'sil2100' Zemczak */ #ifndef APPMENUPLATFORMMENUBAR_H #define APPMENUPLATFORMMENUBAR_H #include #include #include class QMenuBar; class QWindow; class QString; class MenuBarAdapter; class AppMenuPlatformMenuBar : public QPlatformMenuBar { Q_OBJECT public: AppMenuPlatformMenuBar(); virtual ~AppMenuPlatformMenuBar(); virtual void insertMenu(QPlatformMenu *menu, QPlatformMenu* before); virtual void removeMenu(QPlatformMenu *menu); virtual void syncMenu(QPlatformMenu *menuItem); virtual void handleReparent(QWindow *newParentWindow); virtual QPlatformMenu *menuForTag(quintptr tag) const; private: QMenuBar *m_menubar; QWindow *m_window; MenuBarAdapter *m_adapter; QString m_objectPath; }; class AppMenuPlatformThemePlugin : public QPlatformThemePlugin { Q_OBJECT Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QPA.QPlatformThemeFactoryInterface.5.1" FILE "appmenu-qt5.json") public: AppMenuPlatformThemePlugin(QObject *parent = 0); virtual QPlatformTheme *create(const QString &key, const QStringList ¶mList); static const char *name; }; QT_END_NAMESPACE #endif ./src/appmenuplatformmenuitem.h0000644000004100000410000000336113051427137017167 0ustar www-datawww-data/* * Copyright 2014 Dmitry Shachnev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, version 3 of the License. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ #ifndef APPMENUPLATFORMMENUITEM_H #define APPMENUPLATFORMMENUITEM_H #include #include class AppMenuPlatformMenuItem : public QPlatformMenuItem { Q_OBJECT friend class AppMenuPlatformMenu; public: AppMenuPlatformMenuItem(); virtual ~AppMenuPlatformMenuItem(); virtual void setTag(quintptr tag); virtual quintptr tag() const; virtual void setText(const QString &text); virtual void setIcon(const QIcon &icon); virtual void setMenu(QPlatformMenu *menu); virtual void setVisible(bool isVisible); virtual void setIsSeparator(bool isSeparator); virtual void setFont(const QFont &font); virtual void setRole(MenuRole role); virtual void setCheckable(bool checkable); virtual void setChecked(bool isChecked); virtual void setShortcut(const QKeySequence& shortcut); virtual void setEnabled(bool enabled); virtual void setIconSize(int size); private: Q_DISABLE_COPY(AppMenuPlatformMenuItem) QAction *m_action; quintptr m_tag; }; #endif /* APPMENUPLATFORMMENUITEM_H */ ./src/src.pro0000644000004100000410000000152313051427137013347 0ustar www-datawww-dataTARGET = appmenu-qt5 PLUGIN_TYPE = platformthemes PLUGIN_CLASS_NAME = AppMenuPlatformThemePlugin load(qt_plugin) QT += core-private gui-private platformsupport-private dbus widgets DBUS_INTERFACES += com.canonical.AppMenu.Registrar.xml DBUS_ADAPTORS += org.kde.StatusNotifierItem.xml QDBUSXML2CPP_ADAPTOR_HEADER_FLAGS += -i dbusstructures.h CONFIG += X11 link_pkgconfig debug PKGCONFIG += dbusmenu-qt5 gtk+-2.0 DESTDIR = ./ HEADERS += \ appmenuplatformmenuitem.h \ appmenuplatformmenu.h \ appmenuplatformmenubar.h \ appmenuplatformsystemtrayicon.h \ dbusstructures.h \ iconcache.h SOURCES += \ appmenuplatformmenuitem.cpp \ appmenuplatformmenu.cpp \ appmenuplatformmenubar.cpp \ appmenuplatformsystemtrayicon.cpp \ dbusstructures.cpp \ iconcache.cpp ./src/appmenuplatformmenubar.cpp0000644000004100000410000003130313051427141017320 0ustar www-datawww-data/* * Copyright 2013-2014 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, version 3 of the License. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Author: Łukasz 'sil2100' Zemczak */ #include "appmenuplatformmenubar.h" #include "appmenuplatformmenuitem.h" #include "appmenuplatformsystemtrayicon.h" #include "registrar_interface.h" // Ugly, but sadly we need to use private headers for desktop-theme related classes #include #include #include #include #include #include #include #include #include #include #include #undef signals // Needed to make sure we can include gtk.h #include #include #define LOG qDebug() << "appmenu-qt:" << __FUNCTION__ << __LINE__ #define LOG_VAR(x) qDebug() << "appmenu-qt:" << __FUNCTION__ << __LINE__ << #x ":" << x #define WARN qWarning() << "appmenu-qt:" << __FUNCTION__ << __LINE__ QT_BEGIN_NAMESPACE static const char* REGISTRAR_SERVICE = "com.canonical.AppMenu.Registrar"; static const char* REGISTRAR_PATH = "/com/canonical/AppMenu/Registrar"; bool useGlobalMenu() { bool haveAppMenu = QDBusConnection::sessionBus().interface()->isServiceRegistered(REGISTRAR_SERVICE).value(); QByteArray menuProxy = qgetenv("UBUNTU_MENUPROXY"); bool menuProxyIsGood = menuProxy.isNull() || (!menuProxy.isEmpty() && menuProxy.at(0) != '0'); return haveAppMenu && menuProxyIsGood; } /* * The menubar adapter communicates over DBus with the menubar renderer. * It is responsible for registering windows to it and exposing their menubars * if they have one. */ class MenuBarAdapter { public: MenuBarAdapter(QMenuBar*, const QString&); ~MenuBarAdapter(); bool registerWindow(); void resetRegisteredWinId(); private: uint m_registeredWinId; DBusMenuExporter* m_exporter; QMenuBar* m_menuBar; QString m_objectPath; }; QList globalMenuBars; /////////////////////////////////////////////////////////// AppMenuPlatformMenuBar::AppMenuPlatformMenuBar() : QPlatformMenuBar(), m_menubar(0), m_window(0), m_adapter(0) { } AppMenuPlatformMenuBar::~AppMenuPlatformMenuBar() { } void AppMenuPlatformMenuBar::insertMenu(QPlatformMenu *menu, QPlatformMenu *before) { Q_UNUSED(menu); Q_UNUSED(before); return; } void AppMenuPlatformMenuBar::removeMenu(QPlatformMenu *menu) { Q_UNUSED(menu); return; } void AppMenuPlatformMenuBar::syncMenu(QPlatformMenu *menuItem) { Q_UNUSED(menuItem); handleReparent(m_window); return; } void AppMenuPlatformMenuBar::handleReparent(QWindow *newParentWindow) { if (!newParentWindow) return; static int menuBarId = 1; m_objectPath = QString(QLatin1String("/MenuBar/%1")).arg(menuBarId++); m_window = newParentWindow; QWidget *window = QWidget::find(m_window->winId()); m_menubar = window->findChild(); if (!m_menubar) { // Something went wrong, this shouldn't have happened WARN << "The given QWindow has no QMenuBar assigned"; return; } if (globalMenuBars.indexOf(m_menubar) != -1) { WARN << "The given QMenuBar is already registered by appmenu-qt5, skipping"; m_menubar = 0; return; } delete m_adapter; m_adapter = new MenuBarAdapter(m_menubar, m_objectPath); if (m_adapter->registerWindow()) { globalMenuBars.push_back(m_menubar); } } QPlatformMenu * AppMenuPlatformMenuBar::menuForTag(quintptr tag) const { Q_UNUSED(tag); return NULL; } /////////////////////////////////////////////////////////// MenuBarAdapter::MenuBarAdapter(QMenuBar* _menuBar, const QString& _objectPath) : m_registeredWinId(0), m_exporter(0), m_menuBar(_menuBar), m_objectPath(_objectPath) { } MenuBarAdapter::~MenuBarAdapter() { delete m_exporter; m_exporter = 0; globalMenuBars.removeAll(m_menuBar); } bool MenuBarAdapter::registerWindow() { static com::canonical::AppMenu::Registrar *registrar = 0; if (globalMenuBars.indexOf(m_menuBar) >= 0) { WARN << "Already present, error!"; return false; } if (!m_menuBar->window()) { WARN << "No parent for this menubar"; return false; } uint winId = m_menuBar->window()->winId(); if (winId == m_registeredWinId) return true; if (!registrar) registrar = new com::canonical::AppMenu::Registrar(REGISTRAR_SERVICE, REGISTRAR_PATH, QDBusConnection::sessionBus(), 0); if (!registrar || !registrar->isValid()) return false; Q_FOREACH(QAction *action, m_menuBar->actions()) { if (!action->isSeparator()) { WARN << action->text(); } } if (!m_exporter) m_exporter = new DBusMenuExporter(m_objectPath, (QMenu *)m_menuBar); m_registeredWinId = winId; registrar->RegisterWindow(winId, QDBusObjectPath(m_objectPath)); return true; } void MenuBarAdapter::resetRegisteredWinId() { m_registeredWinId = 0; } /////////////////////////////////////////////////////////// /* Helper function, as copy-pasted from Qt 5.2.1 gtk2 platformthemeplugin */ static QString gtkSetting(const gchar *propertyName) { if (qgetenv("DISPLAY").isEmpty()) { return QString(); } GtkSettings *settings = gtk_settings_get_default(); gchararray value; g_object_get(settings, propertyName, &value, NULL); QString str = QString::fromUtf8(value); g_free(value); return str; } /* * The GnomeAppMenuPlatformTheme is a platform theme providing the platform * menubar functionality with the Qt5 QGnomeTheme look */ class GnomeAppMenuPlatformTheme : public QGnomeTheme { public: GnomeAppMenuPlatformTheme(); virtual QPlatformMenuItem* createPlatformMenuItem() const { return new AppMenuPlatformMenuItem(); } virtual QPlatformMenu* createPlatformMenu() const { return 0; } virtual QPlatformMenuBar* createPlatformMenuBar() const; virtual QPlatformSystemTrayIcon* createPlatformSystemTrayIcon() const { return new AppMenuPlatformSystemTrayIcon(); } virtual QVariant themeHint(QPlatformTheme::ThemeHint hint) const; }; GnomeAppMenuPlatformTheme::GnomeAppMenuPlatformTheme() : QGnomeTheme() { if (!qgetenv("DISPLAY").isEmpty()) { int (*oldErrorHandler)(Display *, XErrorEvent *) = XSetErrorHandler(NULL); gtk_init(0, 0); XSetErrorHandler(oldErrorHandler); } } QVariant GnomeAppMenuPlatformTheme::themeHint(QPlatformTheme::ThemeHint hint) const { if (qgetenv("DISPLAY").isEmpty()) { return QVariant(QVariant::String); } switch (hint) { case QPlatformTheme::SystemIconThemeName: return QVariant(gtkSetting("gtk-icon-theme-name")); case QPlatformTheme::SystemIconFallbackThemeName: return QVariant(gtkSetting("gtk-fallback-icon-theme")); default: return QGnomeTheme::themeHint(hint); } } QPlatformMenuBar * GnomeAppMenuPlatformTheme::createPlatformMenuBar() const { if (useGlobalMenu()) { return new AppMenuPlatformMenuBar(); } else { return QGnomeTheme::createPlatformMenuBar(); } } /////////////////////////////////////////////////////////// #ifndef QKDETHEME_STILL_PRIVATE /* * The KdeAppMenuPlatformTheme is a platform theme providing the platform * menubar functionality with the Qt5 QKdeTheme look */ class KdeAppMenuPlatformTheme : public QKdeTheme { public: #if (QT_VERSION >= QT_VERSION_CHECK(5, 4, 0)) KdeAppMenuPlatformTheme(const QStringList &kdeDirs, int kdeVersion) : QKdeTheme(kdeDirs, kdeVersion) { } #else KdeAppMenuPlatformTheme(const QString &kdeHome, int kdeVersion) : QKdeTheme(kdeHome, kdeVersion) { } #endif virtual QPlatformMenuItem* createPlatformMenuItem() const { return new AppMenuPlatformMenuItem(); } virtual QPlatformMenu* createPlatformMenu() const { return 0; } virtual QPlatformMenuBar* createPlatformMenuBar() const; }; QPlatformMenuBar * KdeAppMenuPlatformTheme::createPlatformMenuBar() const { if (useGlobalMenu()) { return new AppMenuPlatformMenuBar(); } else { return QKdeTheme::createPlatformMenuBar(); } } #endif /////////////////////////////////////////////////////////// const char *AppMenuPlatformThemePlugin::name = "appmenu-qt5"; AppMenuPlatformThemePlugin::AppMenuPlatformThemePlugin(QObject *parent) { Q_UNUSED(parent); } QPlatformTheme * AppMenuPlatformThemePlugin::create(const QString &key, const QStringList ¶mList) { if (key.compare(QLatin1String(AppMenuPlatformThemePlugin::name), Qt::CaseInsensitive)) return 0; #ifndef QKDETHEME_STILL_PRIVATE if (paramList.indexOf("kde") >= 0) { // This check is copy-pasted from the Qt5 source code // We need to determine the version number of KDE and the kde home dir const QByteArray kdeVersionBA = qgetenv("KDE_SESSION_VERSION"); const int kdeVersion = kdeVersionBA.toInt(); if (kdeVersion >= 4) { #if (QT_VERSION >= QT_VERSION_CHECK(5, 4, 0)) // Determine KDE prefixes in the following priority order: // - KDEHOME and KDEDIRS environment variables // - ~/.kde() // - read prefixes from /etc/kderc // - fallback to /etc/kde QStringList kdeDirs; const QString kdeHomePathVar = QFile::decodeName(qgetenv("KDEHOME")); if (!kdeHomePathVar.isEmpty()) kdeDirs += kdeHomePathVar; const QString kdeDirsVar = QFile::decodeName(qgetenv("KDEDIRS")); if (!kdeDirsVar.isEmpty()) kdeDirs += kdeDirsVar.split(QLatin1Char(':'), QString::SkipEmptyParts); const QString kdeVersionHomePath = QDir::homePath() + QStringLiteral("/.kde") + QLatin1String(kdeVersionBA); if (QFileInfo(kdeVersionHomePath).isDir()) kdeDirs += kdeVersionHomePath; const QString kdeHomePath = QDir::homePath() + QStringLiteral("/.kde"); if (QFileInfo(kdeHomePath).isDir()) kdeDirs += kdeHomePath; const QString kdeRcPath = QStringLiteral("/etc/kde") + QLatin1String(kdeVersionBA) + QStringLiteral("rc"); if (QFileInfo(kdeRcPath).isReadable()) { QSettings kdeSettings(kdeRcPath, QSettings::IniFormat); kdeSettings.beginGroup(QStringLiteral("Directories-default")); kdeDirs += kdeSettings.value(QStringLiteral("prefixes")).toStringList(); } const QString kdeVersionPrefix = QStringLiteral("/etc/kde") + QLatin1String(kdeVersionBA); if (QFileInfo(kdeVersionPrefix).isDir()) kdeDirs += kdeVersionPrefix; kdeDirs.removeDuplicates(); if (!kdeDirs.isEmpty()) { return new KdeAppMenuPlatformTheme(kdeDirs, kdeVersion); } else { qWarning("%s: Unable to determine KDE dirs", Q_FUNC_INFO); WARN << "Unable to determine KDE dirs, falling back to the gnome theme"; } #else const QString kdeHomePathVar = QString::fromLocal8Bit(qgetenv("KDEHOME")); if (!kdeHomePathVar.isEmpty()) return new KdeAppMenuPlatformTheme(kdeHomePathVar, kdeVersion); const QString kdeVersionHomePath = QDir::homePath() + QStringLiteral("/.kde") + QLatin1String(kdeVersionBA); if (QFileInfo(kdeVersionHomePath).isDir()) return new KdeAppMenuPlatformTheme(kdeVersionHomePath, kdeVersion); const QString kdeHomePath = QDir::homePath() + QStringLiteral("/.kde"); if (QFileInfo(kdeHomePath).isDir()) return new KdeAppMenuPlatformTheme(kdeHomePath, kdeVersion); #endif // QT_VERSION_CHECK } else { WARN << "KDE version too old or cannot be properly identified, " "falling back to the gnome theme"; } } #endif // QKDETHEME_STILL_PRIVATE // Fallback path - use the Gnome theme in this case return new GnomeAppMenuPlatformTheme(); } /////////////////////////////////////////////////////////// QT_END_NAMESPACE ./src/appmenuplatformmenu.h0000644000004100000410000000402513051427137016306 0ustar www-datawww-data/* * Copyright 2014 Dmitry Shachnev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, version 3 of the License. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ #ifndef APPMENUPLATFORMMENU_H #define APPMENUPLATFORMMENU_H #include #include #include #include "appmenuplatformmenuitem.h" class AppMenuPlatformMenu : public QPlatformMenu { Q_OBJECT friend class AppMenuPlatformMenuItem; friend class AppMenuPlatformSystemTrayIcon; public: AppMenuPlatformMenu(); virtual ~AppMenuPlatformMenu(); virtual void insertMenuItem(QPlatformMenuItem *menuItem, QPlatformMenuItem *before); virtual void removeMenuItem(QPlatformMenuItem *menuItem); virtual void syncMenuItem(QPlatformMenuItem *menuItem); virtual void syncSeparatorsCollapsible(bool enable); virtual void setTag(quintptr tag); virtual quintptr tag() const; virtual void setText(const QString &text); virtual void setIcon(const QIcon &icon); virtual void setEnabled(bool enabled); virtual void setVisible(bool visible); virtual void setMinimumWidth(int width); virtual void setFont(const QFont &font); virtual QPlatformMenuItem *menuItemAt(int position) const; virtual QPlatformMenuItem *menuItemForTag(quintptr tag) const; virtual QPlatformMenuItem *createMenuItem() const; private: Q_DISABLE_COPY(AppMenuPlatformMenu) QMenu *m_menu; QList m_menuitems; quintptr m_tag; }; #endif /* APPMENUPLATFORMMENU_H */ ./src/appmenuplatformsystemtrayicon.cpp0000644000004100000410000001562513051427141020775 0ustar www-datawww-data/* * Copyright 2011 Canonical Ltd. * Copyright 2014 Dmitry Shachnev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, version 3 of the License. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Based on sni-qt code by Aurelien Gateau . */ #include #include #include #include #include "appmenuplatformmenu.h" #include "appmenuplatformsystemtrayicon.h" #include "iconcache.h" static const char *SNW_INTERFACE = "org.kde.StatusNotifierWatcher"; static const char *SNW_SERVICE = "org.kde.StatusNotifierWatcher"; static const char *SNW_PATH = "/StatusNotifierWatcher"; static const char *NOTIFICATION_INTERFACE = "org.freedesktop.Notifications"; static const char *NOTIFICATION_SERVICE = "org.freedesktop.Notifications"; static const char *NOTIFICATION_PATH = "/org/freedesktop/Notifications"; static const QString KDEItemFormat = QStringLiteral("org.kde.StatusNotifierItem-%1-%2"); static int instanceCount = 0; static IconCache iconCache; AppMenuPlatformSystemTrayIcon::AppMenuPlatformSystemTrayIcon(): m_serviceName(KDEItemFormat.arg(QCoreApplication::applicationPid()).arg(++instanceCount)), m_objectPath("/StatusNotifierItem"), m_connection(QDBusConnection::connectToBus(QDBusConnection::SessionBus, m_serviceName)), m_sniAdaptor(new StatusNotifierItemAdaptor(this)), m_dbusMenuExporter(Q_NULLPTR) { registerMetaTypes(); m_connection.registerService(m_serviceName); m_connection.registerObject(m_objectPath, this, QDBusConnection::ExportAdaptors); QDBusInterface snw(SNW_SERVICE, SNW_PATH, SNW_INTERFACE); snw.asyncCall("RegisterStatusNotifierItem", m_serviceName); } AppMenuPlatformSystemTrayIcon::~AppMenuPlatformSystemTrayIcon() { m_connection.unregisterObject(m_objectPath, QDBusConnection::UnregisterTree); m_connection.unregisterService(m_serviceName); delete m_sniAdaptor; } // QPlatformSystemTrayIcon implementation void AppMenuPlatformSystemTrayIcon::init() { m_status = QStringLiteral("Active"); emit NewStatus(m_status); } void AppMenuPlatformSystemTrayIcon::cleanup() { m_status = QStringLiteral("Passive"); emit NewStatus(m_status); } void AppMenuPlatformSystemTrayIcon::updateIcon(const QIcon &icon) { m_icon = icon; emit NewIcon(); emit NewToolTip(); // ToolTip contains the icon } void AppMenuPlatformSystemTrayIcon::updateToolTip(const QString &tooltip) { m_tooltip = tooltip; emit NewToolTip(); } void AppMenuPlatformSystemTrayIcon::updateMenu(QPlatformMenu *menu) { QMenu *qMenu = qobject_cast(menu)->m_menu; QString menuObjectPath = m_objectPath + QStringLiteral("/menu"); m_dbusMenuExporter = new DBusMenuExporter(menuObjectPath, qMenu, m_connection); } QRect AppMenuPlatformSystemTrayIcon::geometry() const { return QRect(); } void AppMenuPlatformSystemTrayIcon::showMessage(const QString &title, const QString &msg, const QIcon &icon, MessageIcon iconType, int msecs) { QString iconString = icon.name(); if (iconString.isEmpty()) { switch (iconType) { case NoIcon: break; case Information: iconString = "dialog-information"; break; case Warning: iconString = "dialog-warning"; break; case Critical: iconString = "dialog-error"; break; } } QDBusInterface iface(NOTIFICATION_SERVICE, NOTIFICATION_PATH, NOTIFICATION_INTERFACE); iface.asyncCall("Notify", id(), quint32(0), // replaces_id iconString, title, msg, QStringList(), // actions QVariantMap(), // hints msecs); // timeout } bool AppMenuPlatformSystemTrayIcon::isSystemTrayAvailable() const { const QDBusConnectionInterface *interface = QDBusConnection::sessionBus().interface(); if (!interface->isServiceRegistered(SNW_SERVICE).value()) { return false; } QDBusInterface snw(SNW_SERVICE, SNW_PATH, SNW_INTERFACE); QVariant value = snw.property("IsStatusNotifierHostRegistered"); if (!value.canConvert()) { return false; } return value.toBool(); } bool AppMenuPlatformSystemTrayIcon::supportsMessages() const { const QDBusConnectionInterface *interface = QDBusConnection::sessionBus().interface(); return interface->isServiceRegistered(NOTIFICATION_SERVICE).value(); } QPlatformMenu *AppMenuPlatformSystemTrayIcon::createMenu() const { return new AppMenuPlatformMenu(); } // Properties QString AppMenuPlatformSystemTrayIcon::category() const { return QStringLiteral("ApplicationStatus"); } QString AppMenuPlatformSystemTrayIcon::id() const { return QCoreApplication::applicationFilePath().section('/', -1); } QString AppMenuPlatformSystemTrayIcon::title() const { QString title = QCoreApplication::applicationName(); return title.isEmpty() ? id() : title; } QString AppMenuPlatformSystemTrayIcon::status() const { return m_status; } QString AppMenuPlatformSystemTrayIcon::iconThemePath() const { return iconCache.themePath(m_icon); } QString AppMenuPlatformSystemTrayIcon::iconName() const { if (m_icon.isNull()) { return QString(); } QString name = m_icon.name(); if (!name.isEmpty()) { return name; } return iconCache.nameForIcon(m_icon); } DBusToolTip AppMenuPlatformSystemTrayIcon::toolTip() const { DBusToolTip tip; tip.iconName = iconName(); tip.title = m_tooltip; return tip; } QDBusObjectPath AppMenuPlatformSystemTrayIcon::menu() const { return m_dbusMenuExporter ? QDBusObjectPath(m_objectPath + QStringLiteral("/menu")) : QDBusObjectPath("/invalid"); } // StatusNotifierItem implementation void AppMenuPlatformSystemTrayIcon::ContextMenu(int x, int y) { Q_UNUSED(x); Q_UNUSED(y); } void AppMenuPlatformSystemTrayIcon::Activate(int x, int y) { Q_UNUSED(x); Q_UNUSED(y); emit activated(Trigger); } void AppMenuPlatformSystemTrayIcon::SecondaryActivate(int x, int y) { Q_UNUSED(x); Q_UNUSED(y); emit activated(MiddleClick); } void AppMenuPlatformSystemTrayIcon::Scroll(int delta, const QString& orientation) { Q_UNUSED(delta); Q_UNUSED(orientation); } ./src/dbusstructures.h0000644000004100000410000000321113051427137015304 0ustar www-datawww-data/* * Copyright 2011 Canonical Ltd. * Copyright 2014 Dmitry Shachnev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, version 3 of the License. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Based on sni-qt code by Aurelien Gateau . */ #ifndef DBUSSTRUCTURES_H #define DBUSSTRUCTURES_H #include #include #include #include #include #include struct DBusImage { int width; int height; QByteArray pixels; }; Q_DECLARE_METATYPE(DBusImage) typedef QList DBusImageList; Q_DECLARE_METATYPE(DBusImageList) struct DBusToolTip { QString iconName; DBusImageList iconPixmap; QString title; QString description; }; Q_DECLARE_METATYPE(DBusToolTip) QDBusArgument &operator<<(QDBusArgument&, const DBusImage&); const QDBusArgument &operator>>(const QDBusArgument&, DBusImage&); QDBusArgument &operator<<(QDBusArgument&, const DBusToolTip&); const QDBusArgument &operator>>(const QDBusArgument&, DBusToolTip&); void registerMetaTypes(); #endif /* DBUSSTRUCTURES_H */ ./src/com.canonical.AppMenu.Registrar.xml0000644000004100000410000000475613051427137020604 0ustar www-datawww-data An interface to register a menu from an application's window to be displayed in another window.  This manages that association between XWindow Window IDs and the dbus address and object that provides the menu using the dbusmenu dbus interface. The XWindow ID of the window The object on the dbus interface implementing the dbusmenu interface A method to allow removing a window from the database. Windows will also be removed when the client drops off DBus so this is not required. It is polite though. And important for testing. The XWindow ID of the window Gets the registered menu for a given window ID. The XWindow ID of the window to get The address of the connection on DBus (e.g. :1.23 or org.example.service) The path to the object which implements the com.canonical.dbusmenu interface. ./src/appmenu-qt5.json0000644000004100000410000000004213051427137015100 0ustar www-datawww-data{ "Keys": [ "appmenu-qt5" ] } ./src/iconcache.cpp0000644000004100000410000001243613051427141014456 0ustar www-datawww-data/* * Copyright 2011 Canonical Ltd. * Copyright 2014 Dmitry Shachnev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, version 3 of the License. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Based on sni-qt code by Aurelien Gateau . */ #include #include #include #include #include #include #include "iconcache.h" const int IconCache::MaxIconCount = 20; IconCache::IconCache(QObject *parent): QObject(parent), m_temporaryDir(Q_NULLPTR) { } IconCache::~IconCache() { if (m_temporaryDir) { delete m_temporaryDir; } } QString IconCache::themePath(const QIcon &icon) { if (!m_temporaryDir) { QString dir; QString runtimeDir = QString::fromUtf8(getenv("XDG_RUNTIME_DIR")); if (!runtimeDir.isEmpty()) { dir = runtimeDir; QDir d(dir); if (!d.exists()) { d.mkpath("."); } } else if (!getenv("SNAP")) { dir = QDir::tempPath(); } else { // Try to get the .cache from $XDG_CACHE_HOME, if it's not set, // it has to be in ~/.cache as per XDG standard dir = QString::fromUtf8(getenv("XDG_CACHE_HOME")); if (dir.isEmpty()) { dir = QDir::cleanPath(QDir::homePath() + QStringLiteral("/.cache")); } QDir d(dir); if (!d.exists()) { d.mkpath("."); } } QString path = dir + QStringLiteral("/qt-tray-iconcache-XXXXXX"); m_temporaryDir = new QTemporaryDir(path); } if (!icon.isNull() && !icon.name().isEmpty() && QIcon::hasThemeIcon(icon.name())) { QString dataHome = QString::fromUtf8(getenv("XDG_DATA_HOME")); if (dataHome.isEmpty()) { dataHome = QDir::homePath() + "/.local/share"; } return QDir::cleanPath(dataHome + "/icons"); } return m_temporaryDir->path(); } QString IconCache::nameForIcon(const QIcon &icon) { if (icon.isNull()) { return QString(); } qint64 key = icon.cacheKey(); QList::iterator it = qFind(m_cacheKeys.begin(), m_cacheKeys.end(), key); if (it == m_cacheKeys.end()) { cacheIcon(key, icon); trimCache(); } else { // Place key at the end of list as it is the most recently accessed m_cacheKeys.erase(it); m_cacheKeys.append(key); } return QString::number(key); } void IconCache::trimCache() { QDir dir(themePath() + "/hicolor"); dir.setFilter(QDir::Dirs); while (m_cacheKeys.count() > MaxIconCount) { qint64 cacheKey = m_cacheKeys.takeFirst(); Q_FOREACH(const QString &sizeDir, dir.entryList()) { QString iconSubPath = QString("%1/apps/%2.png").arg(sizeDir).arg(cacheKey); if (dir.exists(iconSubPath)) { dir.remove(iconSubPath); } } } } void touch(const QString &_name, const QDateTime &time) { QByteArray name = QFile::encodeName(_name); struct utimbuf buf; buf.actime = time.toTime_t(); buf.modtime = buf.actime; int ret = utime(name.data(), &buf); if (ret) { qCritical("Failed to touch %s: %s", name.data(), strerror(errno)); } } void IconCache::cacheIcon(qint64 key, const QIcon &icon) { QList sizes; //= icon.availableSizes(); if (sizes.isEmpty()) { // sizes can be empty if icon is an SVG. In this case generate images for a few sizes sizes << QSize(16, 16) << QSize(22, 22) << QSize(32, 32) << QSize(48, 48); } QDir dir(themePath()); Q_FOREACH(const QSize &size, sizes) { QPixmap pix = icon.pixmap(size); QString dirName = QString("hicolor/%1x%1/apps").arg(size.width()); if (!dir.exists(dirName)) { if (!dir.mkpath(dirName)) { qWarning("Could not create '%s' dir in '%s'", qPrintable(themePath()), qPrintable(dirName)); continue; } } QString pixPath = QString("%1/%2/%3.png") .arg(themePath()).arg(dirName).arg(key); if (!pix.save(pixPath, "png")) { qWarning("Could not save icon as '%s'", qPrintable(pixPath)); } } m_cacheKeys << key; // Touch the theme path: GTK icon loading system checks the mtime of the // dir to decide whether it should look for new icons in the theme dir. // // Note: We do not use QDateTime::currentDateTime() as the new time because // if the icon is updated in less than one second, GTK won't notice it. // See https://bugs.launchpad.net/sni-qt/+bug/812884 QFileInfo info(themePath()); QDateTime mtime = info.lastModified(); touch(themePath(), mtime.addSecs(1)); } ./src/appmenuplatformsystemtrayicon.h0000644000004100000410000000731513051427137020444 0ustar www-datawww-data/* * Copyright 2014 Dmitry Shachnev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, version 3 of the License. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ #ifndef APPMENUPLATFORMSYSTEMTRAYICON_H #define APPMENUPLATFORMSYSTEMTRAYICON_H #include #include #include #include #include #include "statusnotifieritem_adaptor.h" class AppMenuPlatformSystemTrayIcon : public QPlatformSystemTrayIcon { Q_OBJECT Q_PROPERTY(QString Category READ category) Q_PROPERTY(QString Id READ id) Q_PROPERTY(QString Title READ title) Q_PROPERTY(QString Status READ status) Q_PROPERTY(quint32 WindowId READ windowId) Q_PROPERTY(QString IconThemePath READ iconThemePath) Q_PROPERTY(QString IconName READ iconName) Q_PROPERTY(DBusImageList IconPixmap READ iconPixmap) Q_PROPERTY(QString OverlayIconName READ overlayIconName) Q_PROPERTY(DBusImageList OverlayIconPixmap READ overlayIconPixmap) Q_PROPERTY(QString AttentionIconName READ attentionIconName) Q_PROPERTY(DBusImageList AttentionIconPixmap READ attentionIconPixmap) Q_PROPERTY(QString AttentionMovieName READ attentionMovieName) Q_PROPERTY(DBusToolTip ToolTip READ toolTip) Q_PROPERTY(QDBusObjectPath Menu READ menu) public: AppMenuPlatformSystemTrayIcon(); virtual ~AppMenuPlatformSystemTrayIcon(); // QPlatformSystemTrayIcon virtual void init(); virtual void cleanup(); virtual void updateIcon(const QIcon &icon); virtual void updateToolTip(const QString &tooltip); virtual void updateMenu(QPlatformMenu *menu); virtual QRect geometry() const; virtual void showMessage(const QString &title, const QString &msg, const QIcon &icon, MessageIcon iconType, int msecs); virtual bool isSystemTrayAvailable() const; virtual bool supportsMessages() const; virtual QPlatformMenu *createMenu() const; // Properties QString category() const; QString id() const; QString title() const; QString status() const; quint32 windowId() const { return 0; } QString iconThemePath() const; QString iconName() const; DBusImageList iconPixmap() const { return DBusImageList(); } QString overlayIconName() const { return QString(); } DBusImageList overlayIconPixmap() const { return DBusImageList(); } QString attentionIconName() const { return QString(); } DBusImageList attentionIconPixmap() const { return DBusImageList(); } QString attentionMovieName() const { return QString(); } DBusToolTip toolTip() const; QDBusObjectPath menu() const; // StatusNotifierItem void ContextMenu(int x, int y); void Activate(int x, int y); void SecondaryActivate(int x, int y); void Scroll(int delta, const QString& orientation); Q_SIGNALS: void NewStatus(const QString &status); void NewIcon(); void NewToolTip(); private: QString m_serviceName; QString m_objectPath; QString m_status; QIcon m_icon; QString m_tooltip; QDBusConnection m_connection; StatusNotifierItemAdaptor *m_sniAdaptor; DBusMenuExporter *m_dbusMenuExporter; }; #endif /* APPMENUPLATFORMSYSTEMTRAYICON_H */ ./src/appmenuplatformmenu.cpp0000644000004100000410000000642613051427137016650 0ustar www-datawww-data/* * Copyright 2014 Dmitry Shachnev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, version 3 of the License. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ #include "appmenuplatformmenuitem.h" #include "appmenuplatformmenu.h" AppMenuPlatformMenu::AppMenuPlatformMenu(): m_menu(new QMenu()), m_tag(0) { connect(m_menu, &QMenu::aboutToShow, this, &QPlatformMenu::aboutToShow); connect(m_menu, &QMenu::aboutToHide, this, &QPlatformMenu::aboutToHide); } AppMenuPlatformMenu::~AppMenuPlatformMenu() { delete m_menu; } void AppMenuPlatformMenu::insertMenuItem(QPlatformMenuItem *menuItem, QPlatformMenuItem *before) { AppMenuPlatformMenuItem *myMenuItem = qobject_cast(menuItem); AppMenuPlatformMenuItem *myBefore = qobject_cast(before); QAction *beforeAction = myBefore ? myBefore->m_action : Q_NULLPTR; m_menu->insertAction(beforeAction, myMenuItem->m_action); if (!myBefore) { m_menuitems.append(myMenuItem); return; } for (int i = 0; i < m_menuitems.size(); ++i) { if (m_menuitems.at(i)->m_action == beforeAction) { m_menuitems.insert(i, myMenuItem); return; } } } void AppMenuPlatformMenu::removeMenuItem(QPlatformMenuItem *menuItem) { AppMenuPlatformMenuItem *myMenuItem = qobject_cast(menuItem); m_menuitems.removeOne(myMenuItem); m_menu->removeAction(myMenuItem->m_action); } void AppMenuPlatformMenu::syncMenuItem(QPlatformMenuItem *menuItem) { Q_UNUSED(menuItem); } void AppMenuPlatformMenu::syncSeparatorsCollapsible(bool enable) { m_menu->setSeparatorsCollapsible(enable); } void AppMenuPlatformMenu::setTag(quintptr tag) { m_tag = tag; } quintptr AppMenuPlatformMenu::tag() const { return m_tag; } void AppMenuPlatformMenu::setText(const QString &text) { m_menu->setTitle(text); } void AppMenuPlatformMenu::setIcon(const QIcon &icon) { m_menu->setIcon(icon); } void AppMenuPlatformMenu::setEnabled(bool enabled) { m_menu->setEnabled(enabled); } void AppMenuPlatformMenu::setVisible(bool visible) { m_menu->setVisible(visible); } void AppMenuPlatformMenu::setMinimumWidth(int width) { m_menu->setMinimumWidth(width); } void AppMenuPlatformMenu::setFont(const QFont &font) { m_menu->setFont(font); } QPlatformMenuItem *AppMenuPlatformMenu::menuItemAt(int position) const { return m_menuitems.at(position); } QPlatformMenuItem *AppMenuPlatformMenu::menuItemForTag(quintptr tag) const { foreach (AppMenuPlatformMenuItem *item, m_menuitems) { if (item->m_tag == tag) { return item; } } return Q_NULLPTR; } QPlatformMenuItem *AppMenuPlatformMenu::createMenuItem() const { return new AppMenuPlatformMenuItem(); } ./src/appmenuplatformmenuitem.cpp0000644000004100000410000000573413051427137017530 0ustar www-datawww-data/* * Copyright 2014 Dmitry Shachnev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, version 3 of the License. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ #include "appmenuplatformmenuitem.h" #include "appmenuplatformmenu.h" AppMenuPlatformMenuItem::AppMenuPlatformMenuItem(): m_action(new QAction(this)), m_tag(0) { connect(m_action, &QAction::triggered, this, &QPlatformMenuItem::activated); connect(m_action, &QAction::hovered, this, &QPlatformMenuItem::hovered); } AppMenuPlatformMenuItem::~AppMenuPlatformMenuItem() { delete m_action; } void AppMenuPlatformMenuItem::setTag(quintptr tag) { m_tag = tag; } quintptr AppMenuPlatformMenuItem::tag() const { return m_tag; } void AppMenuPlatformMenuItem::setText(const QString &text) { m_action->setText(text); } void AppMenuPlatformMenuItem::setIcon(const QIcon &icon) { m_action->setIcon(icon); } void AppMenuPlatformMenuItem::setMenu(QPlatformMenu *menu) { if (menu) { AppMenuPlatformMenu *myMenu = qobject_cast(menu); m_action->setMenu(myMenu->m_menu); } } void AppMenuPlatformMenuItem::setVisible(bool isVisible) { m_action->setVisible(isVisible); } void AppMenuPlatformMenuItem::setIsSeparator(bool isSeparator) { m_action->setSeparator(isSeparator); } void AppMenuPlatformMenuItem::setFont(const QFont &font) { m_action->setFont(font); } void AppMenuPlatformMenuItem::setRole(MenuRole role) { QAction::MenuRole newRole; switch (role) { case TextHeuristicRole: newRole = QAction::TextHeuristicRole; break; case ApplicationSpecificRole: newRole = QAction::ApplicationSpecificRole; break; case AboutRole: newRole = QAction::AboutRole; break; case PreferencesRole: newRole = QAction::PreferencesRole; break; case QuitRole: newRole = QAction::QuitRole; break; default: newRole = QAction::NoRole; } m_action->setMenuRole(newRole); } void AppMenuPlatformMenuItem::setCheckable(bool checkable) { m_action->setCheckable(checkable); } void AppMenuPlatformMenuItem::setChecked(bool isChecked) { m_action->setChecked(isChecked); } void AppMenuPlatformMenuItem::setShortcut(const QKeySequence& shortcut) { m_action->setShortcut(shortcut); } void AppMenuPlatformMenuItem::setEnabled(bool enabled) { m_action->setEnabled(enabled); } void AppMenuPlatformMenuItem::setIconSize(int size) { Q_UNUSED(size); } ./src/dbusstructures.cpp0000644000004100000410000000376013051427137015650 0ustar www-datawww-data/* * Copyright 2011 Canonical Ltd. * Copyright 2014 Dmitry Shachnev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, version 3 of the License. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Based on sni-qt code by Aurelien Gateau . */ #include #include "dbusstructures.h" QDBusArgument &operator<<(QDBusArgument &argument, const DBusImage &image) { argument.beginStructure(); argument << image.width << image.height << image.pixels; argument.endStructure(); return argument; } const QDBusArgument &operator>>(const QDBusArgument &argument, DBusImage &image) { argument.beginStructure(); argument >> image.width >> image.height >> image.pixels; argument.endStructure(); return argument; } QDBusArgument &operator<<(QDBusArgument &argument, const DBusToolTip &tip) { argument.beginStructure(); argument << tip.iconName << tip.iconPixmap << tip.title << tip.description; argument.endStructure(); return argument; } const QDBusArgument &operator>>(const QDBusArgument &argument, DBusToolTip &tip) { argument.beginStructure(); argument >> tip.iconName >> tip.iconPixmap >> tip.title >> tip.description; argument.endStructure(); return argument; } void registerMetaTypes() { static bool registered = false; if (registered) { return; } qDBusRegisterMetaType(); qDBusRegisterMetaType(); qDBusRegisterMetaType(); } ./src/org.kde.StatusNotifierItem.xml0000644000004100000410000000600713051427137017714 0ustar www-datawww-data ./src/iconcache.h0000644000004100000410000000301713051427141014116 0ustar www-datawww-data/* * Copyright 2011 Canonical Ltd. * Copyright 2014 Dmitry Shachnev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, version 3 of the License. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Based on sni-qt code by Aurelien Gateau . */ #ifndef ICONCACHE_H #define ICONCACHE_H #include #include #include #include #include /** * This class will save pixmaps from icons in a temporary dir on the disk, * making it possible to pass filenames for icons without names. */ class IconCache : public QObject { Q_OBJECT public: IconCache(QObject* parent=0); ~IconCache(); static const int MaxIconCount; QString themePath(const QIcon &icon = QIcon()); QString nameForIcon(const QIcon &icon); private: QTemporaryDir *m_temporaryDir; mutable QList m_cacheKeys; void cacheIcon(qint64 key, const QIcon &); void trimCache(); }; #endif /* ICONCACHE_H */ ./appmenu.pro0000644000004100000410000000023113051427137013431 0ustar www-datawww-dataTEMPLATE = subdirs SUBDIRS += src # Add the enable-by-default flag if you want the profile.d files installed enable-by-default { SUBDIRS += data } ./data/0000755000004100000410000000000013051427137012157 5ustar www-datawww-data./data/appmenu-qt5.sh0000644000004100000410000000005013051427137014662 0ustar www-datawww-dataexport QT_QPA_PLATFORMTHEME=appmenu-qt5 ./data/data.pro0000644000004100000410000000013413051427137013610 0ustar www-datawww-dataprofile.path = /etc/profile.d/ profile.files = appmenu-qt5.sh TARGET = INSTALLS = profile