appmenu-qt5-0.3.0+14.04.20140415/ 0000755 0000153 0177776 00000000000 12323205166 016264 5 ustar pbuser nogroup 0000000 0000000 appmenu-qt5-0.3.0+14.04.20140415/.qmake.conf 0000644 0000153 0177776 00000000000 12323204544 020274 0 ustar pbuser nogroup 0000000 0000000 appmenu-qt5-0.3.0+14.04.20140415/data/ 0000755 0000153 0177776 00000000000 12323205166 017175 5 ustar pbuser nogroup 0000000 0000000 appmenu-qt5-0.3.0+14.04.20140415/data/appmenu-qt5.sh 0000644 0000153 0177776 00000000050 12323204544 021677 0 ustar pbuser nogroup 0000000 0000000 export QT_QPA_PLATFORMTHEME=appmenu-qt5
appmenu-qt5-0.3.0+14.04.20140415/data/data.pro 0000644 0000153 0177776 00000000134 12323204544 020625 0 ustar pbuser nogroup 0000000 0000000 profile.path = /etc/profile.d/
profile.files = appmenu-qt5.sh
TARGET =
INSTALLS = profile
appmenu-qt5-0.3.0+14.04.20140415/appmenu.pro 0000644 0000153 0177776 00000000231 12323204544 020446 0 ustar pbuser nogroup 0000000 0000000 TEMPLATE = subdirs
SUBDIRS += src
# Add the enable-by-default flag if you want the profile.d files installed
enable-by-default {
SUBDIRS += data
}
appmenu-qt5-0.3.0+14.04.20140415/COPYING 0000644 0000153 0177776 00000016743 12323204544 017331 0 ustar pbuser nogroup 0000000 0000000 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.
appmenu-qt5-0.3.0+14.04.20140415/src/ 0000755 0000153 0177776 00000000000 12323205166 017053 5 ustar pbuser nogroup 0000000 0000000 appmenu-qt5-0.3.0+14.04.20140415/src/src.pro 0000644 0000153 0177776 00000000643 12323204554 020367 0 ustar pbuser nogroup 0000000 0000000 TARGET = 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
CONFIG += X11 link_pkgconfig debug
PKGCONFIG += dbusmenu-qt5 gtk+-2.0
DESTDIR = ./
HEADERS += \
appmenuplatformmenubar.h
SOURCES += \
appmenuplatformmenubar.cpp
appmenu-qt5-0.3.0+14.04.20140415/src/com.canonical.AppMenu.Registrar.xml 0000644 0000153 0177776 00000004756 12323204544 025621 0 ustar pbuser nogroup 0000000 0000000
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.
appmenu-qt5-0.3.0+14.04.20140415/src/appmenuplatformmenubar.cpp 0000644 0000153 0177776 00000022667 12323204554 024360 0 ustar pbuser nogroup 0000000 0000000 /*
* 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 "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";
/*
* 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)
{
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 0; }
virtual QPlatformMenu* createPlatformMenu() const { return 0; }
virtual QPlatformMenuBar* createPlatformMenuBar() const;
virtual QVariant themeHint(QPlatformTheme::ThemeHint hint) const;
};
GnomeAppMenuPlatformTheme::GnomeAppMenuPlatformTheme()
: QGnomeTheme()
{
int (*oldErrorHandler)(Display *, XErrorEvent *) = XSetErrorHandler(NULL);
gtk_init(0, 0);
XSetErrorHandler(oldErrorHandler);
}
QVariant GnomeAppMenuPlatformTheme::themeHint(QPlatformTheme::ThemeHint hint) const
{
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
{
return new AppMenuPlatformMenuBar();
}
///////////////////////////////////////////////////////////
#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:
KdeAppMenuPlatformTheme(const QString &kdeHome, int kdeVersion);
virtual QPlatformMenuItem* createPlatformMenuItem() const { return 0; }
virtual QPlatformMenu* createPlatformMenu() const { return 0; }
virtual QPlatformMenuBar* createPlatformMenuBar() const;
};
KdeAppMenuPlatformTheme::KdeAppMenuPlatformTheme(const QString &kdeHome, int kdeVersion)
: QKdeTheme(kdeHome, kdeVersion)
{
}
QPlatformMenuBar *
KdeAppMenuPlatformTheme::createPlatformMenuBar() const
{
return new AppMenuPlatformMenuBar();
}
#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) {
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);
WARN << "Unable to determine KDEHOME, falling back to the gnome theme";
}
else {
WARN << "KDE version too old or cannot be properly identified, "
"falling back to the gnome theme";
}
}
#endif
return new GnomeAppMenuPlatformTheme();
}
///////////////////////////////////////////////////////////
QT_END_NAMESPACE
appmenu-qt5-0.3.0+14.04.20140415/src/appmenu-qt5.json 0000644 0000153 0177776 00000000042 12323204544 022115 0 ustar pbuser nogroup 0000000 0000000 {
"Keys": [ "appmenu-qt5" ]
}
appmenu-qt5-0.3.0+14.04.20140415/src/appmenuplatformmenubar.h 0000644 0000153 0177776 00000003616 12323204544 024015 0 ustar pbuser nogroup 0000000 0000000 /*
* 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
appmenu-qt5-0.3.0+14.04.20140415/README 0000644 0000153 0177776 00000001233 12323204544 017142 0 ustar pbuser nogroup 0000000 0000000 # 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.