18
19
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27
#include <dbus/dbus-glib.h>
29
24
#include "feedlist.h"
25
#include "net_monitor.h"
31
26
#include "subscription.h"
32
27
#include "ui/liferea_shell.h"
29
static GDBusNodeInfo *introspection_data = NULL;
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' />"
37
" <method name='SetOnline'>"
38
" <arg name='online' type='b' />"
39
" <arg name='result' type='b' direction='out' />"
41
" <method name='Subscribe'>"
42
" <arg name='url' type='s' />"
43
" <arg name='result' type='b' direction='out' />"
45
" <method name='GetUnreadItems'>"
46
" <arg name='result' type='i' direction='out' />"
48
" <method name='GetNewItems'>"
49
" <arg name='result' type='i' direction='out' />"
51
" <method name='Refresh'>"
52
" <arg name='result' type='b' direction='out' />"
34
57
G_DEFINE_TYPE(LifereaDBus, liferea_dbus, G_TYPE_OBJECT)
37
liferea_dbus_ping (LifereaDBus *self, gboolean *ret, GError **err)
44
liferea_dbus_set_online (LifereaDBus *self, gboolean online, gboolean *ret, GError **err)
46
network_set_online (online);
52
liferea_dbus_subscribe (LifereaDBus *self, gchar *url, gboolean *ret, GError **err)
60
liferea_dbus_ping (LifereaDBus *self, GError **err)
66
liferea_dbus_set_online (LifereaDBus *self, gboolean online, GError **err)
68
network_monitor_set_online (online);
73
liferea_dbus_subscribe (LifereaDBus *self, const gchar *url, GError **err)
54
75
liferea_shell_present ();
55
feedlist_add_subscription (url, NULL, NULL, FEED_REQ_RESET_TITLE);
61
liferea_dbus_get_unread_items (LifereaDBus *self, guint *ret, GError **err)
63
*ret = feedlist_get_unread_item_count ();
68
liferea_dbus_get_new_items (LifereaDBus *self, guint *ret, GError **err)
70
*ret = feedlist_get_new_item_count ();
74
#include "dbus_wrap.c"
76
feedlist_add_subscription (url, NULL, NULL, 0);
81
liferea_dbus_get_unread_items (LifereaDBus *self, GError **err)
83
return feedlist_get_unread_item_count ();
87
liferea_dbus_get_new_items (LifereaDBus *self, GError **err)
89
return feedlist_get_new_item_count ();
93
liferea_dbus_refresh (LifereaDBus *self, GError **err)
95
node_update_subscription (feedlist_get_root (), GUINT_TO_POINTER (0));
100
handle_method_call (GDBusConnection *connection,
102
const gchar *object_path,
103
const gchar *interface_name,
104
const gchar *method_name,
105
GVariant *parameters,
106
GDBusMethodInvocation *invocation,
109
LifereaDBus *self = user_data;
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)"))) {
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)"))) {
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));
143
g_warning ("Unknown method name or unknown parameters: %s",
148
static const GDBusInterfaceVTable interface_vtable =
156
on_bus_acquired (GDBusConnection *connection,
162
debug_enter ("on_bus_acquired");
164
/* parse introspection data */
165
introspection_data = g_dbus_node_info_new_for_xml (introspection_xml,
168
id = g_dbus_connection_register_object (connection,
170
introspection_data->interfaces[0],
172
NULL, /* user_data */
173
NULL, /* user_data_free_func */
174
NULL); /* GError** */
178
debug_exit ("on_bus_acquired");
182
on_name_acquired (GDBusConnection *connection,
186
debug1 (DEBUG_GUI, "Acquired the name %s on the session bus\n", name);
190
on_name_lost (GDBusConnection *connection,
194
debug1 (DEBUG_GUI, "Lost the name %s on the session bus\n", name);
76
197
static void liferea_dbus_init(LifereaDBus *obj) { }
200
liferea_dbus_dispose (GObject *obj)
202
LifereaDBus *self = LIFEREA_DBUS (obj);
204
g_bus_unown_name (self->owner_id);
206
G_OBJECT_CLASS (liferea_dbus_parent_class)->dispose (obj);
79
210
liferea_dbus_class_init (LifereaDBusClass *klass)
81
dbus_g_object_type_install_info (LIFEREA_DBUS_TYPE, &dbus_glib_liferea_dbus_object_info);
212
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
214
gobject_class->dispose = liferea_dbus_dispose;
85
218
liferea_dbus_new (void)
87
220
LifereaDBus *obj = NULL;
89
DBusGProxy *bus_proxy;
91
guint request_name_result;
93
bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
97
bus_proxy = dbus_g_proxy_new_for_name (bus, "org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus");
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))
222
debug_enter ("liferea_dbus_new");
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));
226
obj->owner_id = g_bus_own_name (G_BUS_TYPE_SESSION,
228
G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT,
235
debug_exit ("liferea_dbus_new");
110
#endif /* USE_DBUS */