2
* Copyright 2013 Canonical Ltd.
4
* This program is free software: you can redistribute it and/or modify it
5
* under the terms of the GNU General Public License version 3, as published
6
* by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful, but
9
* WITHOUT ANY WARRANTY; without even the implied warranties of
10
* MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11
* PURPOSE. See the GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License along
14
* with this program. If not, see <http://www.gnu.org/licenses/>.
17
* Charles Kerr <charles.kerr@canonical.com>
20
#include <transfer/dbus-shared.h>
21
#include <transfer/exporter.h>
23
#include <glib/gi18n.h>
36
if (m_dbus_connection != nullptr)
38
for(const auto& id : m_exported_menu_ids)
39
g_dbus_connection_unexport_menu_model(m_dbus_connection, id);
41
if (m_exported_actions_id)
42
g_dbus_connection_unexport_action_group(m_dbus_connection, m_exported_actions_id);
46
g_bus_unown_name(m_own_id);
48
g_clear_object(&m_dbus_connection);
56
Exporter::on_bus_acquired(GDBusConnection* connection, const gchar* name, gpointer gthis)
58
g_debug("bus acquired: %s", name);
59
static_cast<Exporter*>(gthis)->on_bus_acquired(connection, name);
63
Exporter::on_bus_acquired(GDBusConnection* connection, const gchar* /*name*/)
65
m_dbus_connection = static_cast<GDBusConnection*>(g_object_ref(G_OBJECT(connection)));
68
GError * error = nullptr;
69
const auto id = g_dbus_connection_export_action_group(m_dbus_connection,
71
m_gactions->action_group(),
75
m_exported_actions_id = id;
79
g_warning("cannot export action group: %s", error->message);
80
g_clear_error(&error);
84
for(auto& menu : m_menus)
86
const auto path = std::string(BUS_PATH) + "/" + menu->name();
87
const auto id = g_dbus_connection_export_menu_model(m_dbus_connection, path.c_str(), menu->menu_model(), &error);
90
m_exported_menu_ids.insert(id);
95
g_warning("cannot export %s menu: %s", menu->name(), error->message);
96
g_clear_error(&error);
106
Exporter::on_name_lost(GDBusConnection* connection, const gchar* name, gpointer gthis)
108
g_debug("name lost: %s", name);
109
static_cast<Exporter*>(gthis)->on_name_lost(connection, name);
113
Exporter::on_name_lost(GDBusConnection* /*connection*/, const gchar* /*name*/)
123
Exporter::publish(const std::shared_ptr<GActions>& gactions,
124
const std::vector<std::shared_ptr<Menu>>& menus)
126
m_gactions = gactions;
128
m_own_id = g_bus_own_name(G_BUS_TYPE_SESSION,
130
G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT,
142
} // namespace transfer
143
} // namespace indicator