2
* Copyright (C) 2017 Canonical, Ltd.
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.
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.
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/>.
17
#include "qtubuntuextraactionhandler.h"
19
#include "gmenumodelexporter.h"
22
static const gchar introspection_xml[] =
24
" <interface name='qtubuntu.actions.extra'>"
25
" <method name='aboutToShow'>"
26
" <arg type='t' name='tag' direction='in'/>"
31
static void handle_method_call (GDBusConnection *,
35
const gchar *method_name,
37
GDBusMethodInvocation *invocation,
41
if (g_strcmp0 (method_name, "aboutToShow") == 0)
43
if (g_variant_check_format_string(parameters, "(t)", false)) {
44
auto obj = static_cast<UbuntuGMenuModelExporter*>(user_data);
47
g_variant_get (parameters, "(t)", &tag);
48
obj->aboutToShow(tag);
51
g_dbus_method_invocation_return_value (invocation, NULL);
53
g_dbus_method_invocation_return_error(invocation,
55
G_DBUS_ERROR_UNKNOWN_METHOD,
61
static const GDBusInterfaceVTable interface_vtable =
69
QtUbuntuExtraActionHandler::QtUbuntuExtraActionHandler()
70
: m_registration_id(0)
72
m_introspection_data = g_dbus_node_info_new_for_xml (introspection_xml, NULL);
75
QtUbuntuExtraActionHandler::~QtUbuntuExtraActionHandler()
77
g_clear_pointer(&m_introspection_data, g_dbus_node_info_unref);
80
bool QtUbuntuExtraActionHandler::connect(GDBusConnection *connection, const QByteArray &menuPath, UbuntuGMenuModelExporter *gmenuexporter)
82
if (m_registration_id != 0) {
83
qCWarning(ubuntuappmenu, "Called connect in an already connected QtUbuntuExtraActionHandler");
87
GError *error = nullptr;
88
m_registration_id = g_dbus_connection_register_object (connection, menuPath.constData(),
89
m_introspection_data->interfaces[0],
95
if (!m_registration_id) {
96
qCWarning(ubuntuappmenu, "Failed to extra actions - %s", error ? error->message : "unknown error");
97
g_clear_error(&error);
100
return m_registration_id != 0;
103
void QtUbuntuExtraActionHandler::disconnect(GDBusConnection *connection) {
104
if (m_registration_id) {
105
g_dbus_connection_unregister_object (connection, m_registration_id);