~ps-jenkins/indicator-transfer/ubuntu-vivid-proposed

« back to all changes in this revision

Viewing changes to src/exporter.cpp

  • Committer: Charles Kerr
  • Date: 2014-06-17 01:36:16 UTC
  • mto: This revision was merged to the branch mainline in revision 2.
  • Revision ID: charles.kerr@canonical.com-20140617013616-7fcd22wh3hbgaovh
code drop

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright 2013 Canonical Ltd.
3
 
 *
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.
7
 
 *
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.
12
 
 *
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/>.
15
 
 *
16
 
 * Authors:
17
 
 *   Charles Kerr <charles.kerr@canonical.com>
18
 
 */
19
 
 
20
 
#include <transfer/dbus-shared.h>
21
 
#include <transfer/exporter.h>
22
 
 
23
 
#include <glib/gi18n.h>
24
 
#include <gio/gio.h>
25
 
 
26
 
namespace unity {
27
 
namespace indicator {
28
 
namespace transfer {
29
 
 
30
 
/***
31
 
****
32
 
***/
33
 
 
34
 
Exporter::~Exporter()
35
 
{
36
 
    if (m_dbus_connection != nullptr)
37
 
    {
38
 
        for(const auto& id : m_exported_menu_ids)
39
 
            g_dbus_connection_unexport_menu_model(m_dbus_connection, id);
40
 
 
41
 
        if (m_exported_actions_id)
42
 
            g_dbus_connection_unexport_action_group(m_dbus_connection, m_exported_actions_id);
43
 
    }
44
 
 
45
 
    if (m_own_id)
46
 
        g_bus_unown_name(m_own_id);
47
 
 
48
 
    g_clear_object(&m_dbus_connection);
49
 
}
50
 
 
51
 
/***
52
 
****
53
 
***/
54
 
 
55
 
void
56
 
Exporter::on_bus_acquired(GDBusConnection* connection, const gchar* name, gpointer gthis)
57
 
{
58
 
    g_debug("bus acquired: %s", name);
59
 
    static_cast<Exporter*>(gthis)->on_bus_acquired(connection, name);
60
 
}
61
 
 
62
 
void
63
 
Exporter::on_bus_acquired(GDBusConnection* connection, const gchar* /*name*/)
64
 
{
65
 
    m_dbus_connection = static_cast<GDBusConnection*>(g_object_ref(G_OBJECT(connection)));
66
 
 
67
 
    // export the actions
68
 
    GError * error = nullptr;
69
 
    const auto id = g_dbus_connection_export_action_group(m_dbus_connection,
70
 
                                                          BUS_PATH,
71
 
                                                          m_gactions->action_group(),
72
 
                                                          &error);
73
 
    if (id)
74
 
    {
75
 
        m_exported_actions_id = id;
76
 
    }
77
 
    else
78
 
    {
79
 
        g_warning("cannot export action group: %s", error->message);
80
 
        g_clear_error(&error);
81
 
    }
82
 
 
83
 
    // export the menus
84
 
    for(auto& menu : m_menus)
85
 
    {
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);
88
 
        if (id)
89
 
        {
90
 
            m_exported_menu_ids.insert(id);
91
 
        }
92
 
        else
93
 
        {
94
 
            if (error != nullptr)
95
 
                g_warning("cannot export %s menu: %s", menu->name(), error->message);
96
 
            g_clear_error(&error);
97
 
        }
98
 
    }
99
 
}
100
 
 
101
 
/***
102
 
****
103
 
***/
104
 
 
105
 
void
106
 
Exporter::on_name_lost(GDBusConnection* connection, const gchar* name, gpointer gthis)
107
 
{
108
 
    g_debug("name lost: %s", name);
109
 
    static_cast<Exporter*>(gthis)->on_name_lost(connection, name);
110
 
}
111
 
 
112
 
void
113
 
Exporter::on_name_lost(GDBusConnection* /*connection*/, const gchar* /*name*/)
114
 
{
115
 
    name_lost();
116
 
}
117
 
 
118
 
/***
119
 
****
120
 
***/
121
 
 
122
 
void
123
 
Exporter::publish(const std::shared_ptr<GActions>& gactions,
124
 
                  const std::vector<std::shared_ptr<Menu>>& menus)
125
 
{
126
 
    m_gactions = gactions;
127
 
    m_menus = menus;
128
 
    m_own_id = g_bus_own_name(G_BUS_TYPE_SESSION,
129
 
                              BUS_NAME,
130
 
                              G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT,
131
 
                              on_bus_acquired,
132
 
                              nullptr,
133
 
                              on_name_lost,
134
 
                              this,
135
 
                              nullptr);
136
 
}
137
 
 
138
 
/***
139
 
****
140
 
***/
141
 
 
142
 
} // namespace transfer
143
 
} // namespace indicator
144
 
} // namespace unity
145