~ubuntu-branches/ubuntu/vivid/liferea/vivid-proposed

« back to all changes in this revision

Viewing changes to src/dbus.c

  • Committer: Package Import Robot
  • Author(s): bojo42
  • Date: 2012-03-29 14:17:21 UTC
  • mfrom: (1.3.9) (3.2.5 sid)
  • Revision ID: package-import@ubuntu.com-20120329141721-tbfopcrc5797wxt7
Tags: 1.8.3-0.1ubuntu1
* New upstream release (LP: #290666, #371754, #741543, #716688)
* Merge from Debian unstable (LP: #935147), remaining changes:
* debian/patches:
  - drop gtk-status-icon.patch & notification-append as in upstream
  - drop fix_systray_behavior as mostly upstreamed and rest seems unused
  - 01_ubuntu_feedlists: update & rename, move planets to "Open Source"  
  - add_X-Ubuntu-Gettext-Domain: rebase
  - libunity.patch: rebase, apply before indicator patch (liferea_shell.c)
  - libindicate_increase_version.patch: exclude from libindicate.patch
  - deactivate libindicate.patch, seems partly upstreamed and needs rework
* debian/control: libindicate-dev, libindicate-gtk-dev & libunity-dev
* debian/liferea.indicate & liferea.install: ship indicator desktop file
* debian/rules: enable libindicate

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 * @file dbus.c DBUS interface to control Liferea
3
3
 * 
4
4
 * Copyright (C) 2007 mooonz <mooonz@users.sourceforge.net>
 
5
 * Copyright (C) 2010 Emilio Pozuelo Monfort <pochu27@gmail.com>
5
6
 *
6
7
 * This program is free software; you can redistribute it and/or modify
7
8
 * it under the terms of the GNU General Public License as published by
18
19
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
20
 */
20
21
 
21
 
#ifdef HAVE_CONFIG_H
22
 
#  include <config.h>
23
 
#endif 
24
 
 
25
 
#ifdef USE_DBUS 
26
 
 
27
 
#include <dbus/dbus-glib.h>
28
22
#include "dbus.h"
 
23
#include "debug.h"
29
24
#include "feedlist.h"
30
 
#include "net.h"
 
25
#include "net_monitor.h"
31
26
#include "subscription.h"
32
27
#include "ui/liferea_shell.h"
33
28
 
 
29
static GDBusNodeInfo *introspection_data = NULL;
 
30
 
 
31
static const gchar introspection_xml[] =
 
32
"<node name='/org/gnome/feed/Reader'>"
 
33
"  <interface name='org.gnome.feed.Reader'>"
 
34
"    <method name='Ping'>"
 
35
"      <arg name='result' type='b' direction='out' />"
 
36
"    </method>"
 
37
"    <method name='SetOnline'>"
 
38
"      <arg name='online' type='b' />"
 
39
"      <arg name='result' type='b' direction='out' />"
 
40
"    </method>"
 
41
"    <method name='Subscribe'>"
 
42
"      <arg name='url' type='s' />"
 
43
"      <arg name='result' type='b' direction='out' />"
 
44
"    </method>"
 
45
"    <method name='GetUnreadItems'>"
 
46
"      <arg name='result' type='i' direction='out' />"
 
47
"    </method>"
 
48
"    <method name='GetNewItems'>"
 
49
"      <arg name='result' type='i' direction='out' />"
 
50
"    </method>"
 
51
"    <method name='Refresh'>"
 
52
"      <arg name='result' type='b' direction='out' />"
 
53
"    </method>"
 
54
"  </interface>"
 
55
"</node>";
 
56
 
34
57
G_DEFINE_TYPE(LifereaDBus, liferea_dbus, G_TYPE_OBJECT)
35
58
 
36
 
gboolean
37
 
liferea_dbus_ping (LifereaDBus *self, gboolean *ret, GError **err)
38
 
{
39
 
        *ret = TRUE;
40
 
        return TRUE;
41
 
}
42
 
 
43
 
gboolean
44
 
liferea_dbus_set_online (LifereaDBus *self, gboolean online, gboolean *ret, GError **err)
45
 
{
46
 
        network_set_online (online);
47
 
        *ret = TRUE;
48
 
        return TRUE;
49
 
}
50
 
 
51
 
gboolean
52
 
liferea_dbus_subscribe (LifereaDBus *self, gchar *url, gboolean *ret, GError **err)
 
59
static gboolean
 
60
liferea_dbus_ping (LifereaDBus *self, GError **err)
 
61
{
 
62
        return TRUE;
 
63
}
 
64
 
 
65
static gboolean
 
66
liferea_dbus_set_online (LifereaDBus *self, gboolean online, GError **err)
 
67
{
 
68
        network_monitor_set_online (online);
 
69
        return TRUE;
 
70
}
 
71
 
 
72
static gboolean
 
73
liferea_dbus_subscribe (LifereaDBus *self, const gchar *url, GError **err)
53
74
{
54
75
        liferea_shell_present ();
55
 
        feedlist_add_subscription (url, NULL, NULL, FEED_REQ_RESET_TITLE);
56
 
        *ret = TRUE;
57
 
        return TRUE;
58
 
}
59
 
 
60
 
gboolean
61
 
liferea_dbus_get_unread_items (LifereaDBus *self, guint *ret, GError **err)
62
 
{
63
 
        *ret = feedlist_get_unread_item_count ();
64
 
        return TRUE;
65
 
}
66
 
 
67
 
gboolean
68
 
liferea_dbus_get_new_items (LifereaDBus *self, guint *ret, GError **err)
69
 
{
70
 
        *ret = feedlist_get_new_item_count ();
71
 
        return TRUE;
72
 
}
73
 
 
74
 
#include "dbus_wrap.c"
 
76
        feedlist_add_subscription (url, NULL, NULL, 0);
 
77
        return TRUE;
 
78
}
 
79
 
 
80
static guint
 
81
liferea_dbus_get_unread_items (LifereaDBus *self, GError **err)
 
82
{
 
83
        return feedlist_get_unread_item_count ();
 
84
}
 
85
 
 
86
static guint
 
87
liferea_dbus_get_new_items (LifereaDBus *self, GError **err)
 
88
{
 
89
        return feedlist_get_new_item_count ();
 
90
}
 
91
 
 
92
static gboolean
 
93
liferea_dbus_refresh (LifereaDBus *self, GError **err)
 
94
{
 
95
        node_update_subscription (feedlist_get_root (), GUINT_TO_POINTER (0));
 
96
        return TRUE;
 
97
}
 
98
 
 
99
static void
 
100
handle_method_call (GDBusConnection       *connection,
 
101
                    const gchar           *sender,
 
102
                    const gchar           *object_path,
 
103
                    const gchar           *interface_name,
 
104
                    const gchar           *method_name,
 
105
                    GVariant              *parameters,
 
106
                    GDBusMethodInvocation *invocation,
 
107
                    gpointer               user_data)
 
108
{
 
109
        LifereaDBus *self = user_data;
 
110
        gboolean res;
 
111
 
 
112
        if (g_str_equal (method_name, "Ping")) {
 
113
                res = liferea_dbus_ping (self, NULL);
 
114
                g_dbus_method_invocation_return_value (invocation,
 
115
                        g_variant_new ("(b)", res));
 
116
        } else if (g_str_equal (method_name, "SetOnline") &&
 
117
            g_variant_is_of_type (parameters, G_VARIANT_TYPE ("(b)"))) {
 
118
                gboolean set_online;
 
119
                g_variant_get (parameters, "(b)", &set_online);
 
120
                res = liferea_dbus_set_online (self, set_online, NULL);
 
121
                g_dbus_method_invocation_return_value (invocation,
 
122
                        g_variant_new ("(b)", res));
 
123
        } else if (g_str_equal (method_name, "Subscribe") &&
 
124
            g_variant_is_of_type (parameters, G_VARIANT_TYPE ("(s)"))) {
 
125
                const gchar *url;
 
126
                g_variant_get (parameters, "(s)", &url);
 
127
                res = liferea_dbus_subscribe (self, url, NULL);
 
128
                g_dbus_method_invocation_return_value (invocation,
 
129
                        g_variant_new ("(b)", res));
 
130
        } else if (g_str_equal (method_name, "GetUnreadItems")) {
 
131
                guint num = liferea_dbus_get_unread_items (self, NULL);
 
132
                g_dbus_method_invocation_return_value (invocation,
 
133
                        g_variant_new ("(i)", num));
 
134
        } else if (g_str_equal (method_name, "GetNewItems")) {
 
135
                guint num = liferea_dbus_get_new_items (self, NULL);
 
136
                g_dbus_method_invocation_return_value (invocation,
 
137
                        g_variant_new ("(i)", num));
 
138
        } else if (g_str_equal (method_name, "Refresh")) {
 
139
                res = liferea_dbus_refresh (self, NULL);
 
140
                g_dbus_method_invocation_return_value (invocation,
 
141
                        g_variant_new ("(b)", res));
 
142
        } else {
 
143
                g_warning ("Unknown method name or unknown parameters: %s",
 
144
                           method_name);
 
145
        }
 
146
}
 
147
 
 
148
static const GDBusInterfaceVTable interface_vtable =
 
149
{
 
150
  handle_method_call,
 
151
  NULL,
 
152
  NULL
 
153
};
 
154
 
 
155
static void
 
156
on_bus_acquired (GDBusConnection *connection,
 
157
                 const gchar     *name,
 
158
                 gpointer         user_data)
 
159
{
 
160
        guint id;
 
161
 
 
162
        debug_enter ("on_bus_acquired");
 
163
 
 
164
        /* parse introspection data */
 
165
        introspection_data = g_dbus_node_info_new_for_xml (introspection_xml,
 
166
                                                           NULL);
 
167
 
 
168
        id = g_dbus_connection_register_object (connection,
 
169
                                                LF_DBUS_PATH,
 
170
                                                introspection_data->interfaces[0],
 
171
                                                &interface_vtable,
 
172
                                                NULL,  /* user_data */
 
173
                                                NULL,  /* user_data_free_func */
 
174
                                                NULL); /* GError** */
 
175
 
 
176
        g_assert (id > 0);
 
177
 
 
178
        debug_exit ("on_bus_acquired");
 
179
}
 
180
 
 
181
static void
 
182
on_name_acquired (GDBusConnection *connection,
 
183
                  const gchar     *name,
 
184
                  gpointer         user_data)
 
185
{
 
186
        debug1 (DEBUG_GUI, "Acquired the name %s on the session bus\n", name);
 
187
}
 
188
 
 
189
static void
 
190
on_name_lost (GDBusConnection *connection,
 
191
              const gchar     *name,
 
192
              gpointer         user_data)
 
193
{
 
194
        debug1 (DEBUG_GUI, "Lost the name %s on the session bus\n", name);
 
195
}
75
196
 
76
197
static void liferea_dbus_init(LifereaDBus *obj) { }
77
198
 
78
199
static void
 
200
liferea_dbus_dispose (GObject *obj)
 
201
{
 
202
        LifereaDBus *self = LIFEREA_DBUS (obj);
 
203
 
 
204
        g_bus_unown_name (self->owner_id);
 
205
 
 
206
        G_OBJECT_CLASS (liferea_dbus_parent_class)->dispose (obj);
 
207
}
 
208
 
 
209
static void
79
210
liferea_dbus_class_init (LifereaDBusClass *klass)
80
211
{
81
 
        dbus_g_object_type_install_info (LIFEREA_DBUS_TYPE, &dbus_glib_liferea_dbus_object_info);
 
212
        GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
 
213
 
 
214
        gobject_class->dispose = liferea_dbus_dispose;
82
215
}
83
216
 
84
217
LifereaDBus*
85
218
liferea_dbus_new (void)
86
219
{
87
220
        LifereaDBus *obj = NULL;
88
 
        DBusGConnection *bus;
89
 
        DBusGProxy *bus_proxy;
90
 
        GError *error = NULL;
91
 
        guint request_name_result;
92
 
        
93
 
        bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
94
 
        if (!bus)
95
 
                return NULL;
96
 
 
97
 
        bus_proxy = dbus_g_proxy_new_for_name (bus, "org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus");
98
 
 
99
 
        if (!dbus_g_proxy_call (bus_proxy, "RequestName", &error,
100
 
                                G_TYPE_STRING, LF_DBUS_SERVICE, G_TYPE_UINT, 0, G_TYPE_INVALID,
101
 
                                G_TYPE_UINT, &request_name_result, G_TYPE_INVALID))
102
 
                return NULL;
 
221
 
 
222
        debug_enter ("liferea_dbus_new");
103
223
 
104
224
        obj = (LifereaDBus*)g_object_new(LIFEREA_DBUS_TYPE, NULL);
105
 
        dbus_g_connection_register_g_object (bus, LF_DBUS_PATH, G_OBJECT (obj));
106
 
        
 
225
 
 
226
        obj->owner_id = g_bus_own_name (G_BUS_TYPE_SESSION,
 
227
                                        LF_DBUS_SERVICE,
 
228
                                        G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT,
 
229
                                        on_bus_acquired,
 
230
                                        on_name_acquired,
 
231
                                        on_name_lost,
 
232
                                        NULL,
 
233
                                        NULL);
 
234
 
 
235
        debug_exit ("liferea_dbus_new");
 
236
 
107
237
        return obj;
108
238
}
109
 
 
110
 
#endif /* USE_DBUS */