Merge lp:~ted/libindicate/helpers into lp:libindicate/0.6

Proposed by Ted Gould
Status: Merged
Merged at revision: not available
Proposed branch: lp:~ted/libindicate/helpers
Merge into: lp:libindicate/0.6
Diff against target: None lines
To merge this branch: bzr merge lp:~ted/libindicate/helpers
Reviewer Review Type Date Requested Status
Aurélien Gâteau (community) Approve
Review via email: mp+11704@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Aurélien Gâteau (agateau) wrote :

Looks good!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'libindicate/indicator.c'
2--- libindicate/indicator.c 2009-09-01 17:05:33 +0000
3+++ libindicate/indicator.c 2009-09-14 14:48:43 +0000
4@@ -424,6 +424,48 @@
5 }
6
7 /**
8+ indicate_indicator_set_property_int:
9+ @indicator: a #IndicateIndicator to act on
10+ @key: name of the property
11+ @value: integer to set property with
12+
13+ This is a helper function that wraps around #indicate_indicator_set_property
14+ but takes an integer property and turns into a string and
15+ uses that data to call #indicate_indicator_set_property.
16+*/
17+void
18+indicate_indicator_set_property_int (IndicateIndicator * indicator, const gchar * key, gint value)
19+{
20+ gchar * valuestr = g_strdup_printf("%d", value);
21+ if (valuestr != NULL) {
22+ indicate_indicator_set_property(indicator, key, valuestr);
23+ }
24+ g_free(valuestr);
25+ return;
26+}
27+
28+/**
29+ indicate_indicator_set_property_bool:
30+ @indicator: a #IndicateIndicator to act on
31+ @key: name of the property
32+ @value: integer to set property with
33+
34+ This is a helper function that wraps around #indicate_indicator_set_property
35+ but takes a boolean property and turns into a string and
36+ uses that data to call #indicate_indicator_set_property.
37+*/
38+void
39+indicate_indicator_set_property_bool (IndicateIndicator * indicator, const gchar * key, gboolean value)
40+{
41+ if (value) {
42+ indicate_indicator_set_property(indicator, key, INDICATE_INDICATOR_VALUE_TRUE);
43+ } else {
44+ indicate_indicator_set_property(indicator, key, INDICATE_INDICATOR_VALUE_FALSE);
45+ }
46+ return;
47+}
48+
49+/**
50 indicate_indicator_get_property:
51 @indicator: a #IndicateIndicator to act on
52 @key: name of the property
53
54=== modified file 'libindicate/indicator.h'
55--- libindicate/indicator.h 2009-08-31 21:26:29 +0000
56+++ libindicate/indicator.h 2009-09-14 14:48:43 +0000
57@@ -43,6 +43,11 @@
58 #define INDICATE_IS_INDICATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), INDICATE_TYPE_INDICATOR))
59 #define INDICATE_INDICATOR_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS((object), INDICATE_TYPE_INDICATOR, IndicateIndicatorClass))
60
61+/* Some values that are commonly used. Most likely only
62+ internal, but if you need them, here they are! */
63+#define INDICATE_INDICATOR_VALUE_TRUE "true"
64+#define INDICATE_INDICATOR_VALUE_FALSE "false"
65+
66 /* This is a signal that signals to the indicator that the user
67 * has done an action where they'd like this indicator to be
68 * displayed. */
69@@ -142,6 +147,9 @@
70 /* Properties handling */
71 void indicate_indicator_set_property (IndicateIndicator * indicator, const gchar * key, const gchar * data);
72 void indicate_indicator_set_property_time (IndicateIndicator * indicator, const gchar * key, GTimeVal * time);
73+void indicate_indicator_set_property_int (IndicateIndicator * indicator, const gchar * key, gint value);
74+void indicate_indicator_set_property_bool (IndicateIndicator * indicator, const gchar * key, gboolean value);
75+
76 const gchar * indicate_indicator_get_property (IndicateIndicator * indicator, const gchar * key);
77 GPtrArray * indicate_indicator_list_properties (IndicateIndicator * indicator);
78
79
80=== modified file 'libindicate/listener.c'
81--- libindicate/listener.c 2009-09-08 22:01:57 +0000
82+++ libindicate/listener.c 2009-09-14 15:30:59 +0000
83@@ -742,7 +742,9 @@
84 typedef enum _get_property_type get_property_type;
85 enum _get_property_type {
86 PROPERTY_TYPE_STRING,
87- PROPERTY_TYPE_TIME
88+ PROPERTY_TYPE_TIME,
89+ PROPERTY_TYPE_INT,
90+ PROPERTY_TYPE_BOOL
91 };
92
93 typedef struct _get_property_t get_property_t;
94@@ -756,6 +758,14 @@
95 get_property_type type;
96 };
97
98+/* Look at the right align on this comment. Sweeeeeeeet */
99+/* A callback from getting a property that takes the string
100+ passed across the bus and turning it into something more
101+ related to what we want on this side. If it's a time it
102+ gets converted to a #GTimeVal, if it's an int it goes to
103+ a gint and if it's a bool we check that too. This makes
104+ it nice to work with properties and the listener.
105+*/
106 static void
107 get_property_cb (DBusGProxy *proxy, char * OUT_value, GError *error, gpointer userdata)
108 {
109@@ -769,11 +779,13 @@
110
111 switch (get_property_data->type) {
112 case PROPERTY_TYPE_STRING: {
113+ /* Just pass the string along. */
114 indicate_listener_get_property_cb cb = (indicate_listener_get_property_cb)get_property_data->cb;
115 cb(get_property_data->listener, get_property_data->server, get_property_data->indicator, get_property_data->property, OUT_value, get_property_data->data);
116 break;
117 }
118 case PROPERTY_TYPE_TIME: {
119+ /* Convert it to a time val */
120 indicate_listener_get_property_time_cb cb = (indicate_listener_get_property_time_cb)get_property_data->cb;
121 GTimeVal time;
122 if (g_time_val_from_iso8601(OUT_value, &time)) {
123@@ -781,6 +793,25 @@
124 }
125 break;
126 }
127+ case PROPERTY_TYPE_INT: {
128+ /* Take the string and convert it to an integer */
129+ indicate_listener_get_property_int_cb cb = (indicate_listener_get_property_int_cb)get_property_data->cb;
130+ if (OUT_value == NULL) break;
131+ gint intval = atoi(OUT_value);
132+ cb(get_property_data->listener, get_property_data->server, get_property_data->indicator, get_property_data->property, intval, get_property_data->data);
133+ break;
134+ }
135+ case PROPERTY_TYPE_BOOL: {
136+ /* Check to see if it's 'true', if not assume that
137+ it's false */
138+ indicate_listener_get_property_bool_cb cb = (indicate_listener_get_property_bool_cb)get_property_data->cb;
139+ if (g_strcmp0(OUT_value, INDICATE_INDICATOR_VALUE_TRUE) == 0) {
140+ cb(get_property_data->listener, get_property_data->server, get_property_data->indicator, get_property_data->property, TRUE, get_property_data->data);
141+ } else {
142+ cb(get_property_data->listener, get_property_data->server, get_property_data->indicator, get_property_data->property, FALSE, get_property_data->data);
143+ }
144+ break;
145+ }
146 }
147
148 g_free(get_property_data->property);
149@@ -789,6 +820,9 @@
150 return;
151 };
152
153+/* A small function to take the common list of parameters and
154+ build a callback structure to hold them all. Eventually we
155+ get the data and unwind this structure. */
156 static void
157 get_property_helper (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, GCallback callback, gpointer data, get_property_type prop_type)
158 {
159@@ -807,18 +841,95 @@
160 return;
161 }
162
163+/**
164+ indicate_listener_get_property:
165+ @listener: The #IndicateListener representing the connection
166+ @server: The server that the indicator is on
167+ @indicator: Which indicator is being queried
168+ @property: Name of the property to get
169+ @callback: The callback function to call with the data
170+ @data: Arbitrary data to give the callback
171+
172+ A function to get a property from an indicator on a server
173+ and bring it back locally. This wraps all the hassle of using
174+ the DBus API and makes it pretty easy to get properties.
175+*/
176 void
177 indicate_listener_get_property (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, indicate_listener_get_property_cb callback, gpointer data)
178 {
179 return get_property_helper(listener, server, indicator, property, G_CALLBACK(callback), data, PROPERTY_TYPE_STRING);
180 }
181
182+/**
183+ indicate_listener_get_property_time:
184+ @listener: The #IndicateListener representing the connection
185+ @server: The server that the indicator is on
186+ @indicator: Which indicator is being queried
187+ @property: Name of the property to get
188+ @callback: The callback function to call with the data
189+ @data: Arbitrary data to give the callback
190+
191+ A function to get a property from an indicator on a server
192+ and bring it back locally. This wraps all the hassle of using
193+ the DBus API and makes it pretty easy to get properties.
194+
195+ Very similar to #indicate_listener_get_property but converts
196+ the final value into a GTimeVal for easy (and type-safe)
197+ usage by listeners.
198+*/
199 void
200 indicate_listener_get_property_time (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, indicate_listener_get_property_time_cb callback, gpointer data)
201 {
202 return get_property_helper(listener, server, indicator, property, G_CALLBACK(callback), data, PROPERTY_TYPE_TIME);
203 }
204
205+/**
206+ indicate_listener_get_property_int:
207+ @listener: The #IndicateListener representing the connection
208+ @server: The server that the indicator is on
209+ @indicator: Which indicator is being queried
210+ @property: Name of the property to get
211+ @callback: The callback function to call with the data
212+ @data: Arbitrary data to give the callback
213+
214+ A function to get a property from an indicator on a server
215+ and bring it back locally. This wraps all the hassle of using
216+ the DBus API and makes it pretty easy to get properties.
217+
218+ Very similar to #indicate_listener_get_property but converts
219+ the final value into a gint for easy (and type-safe)
220+ usage by listeners.
221+*/
222+void
223+indicate_listener_get_property_int (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, indicate_listener_get_property_int_cb callback, gpointer data)
224+{
225+ return get_property_helper(listener, server, indicator, property, G_CALLBACK(callback), data, PROPERTY_TYPE_INT);
226+}
227+
228+/**
229+ indicate_listener_get_property_bool:
230+ @listener: The #IndicateListener representing the connection
231+ @server: The server that the indicator is on
232+ @indicator: Which indicator is being queried
233+ @property: Name of the property to get
234+ @callback: The callback function to call with the data
235+ @data: Arbitrary data to give the callback
236+
237+ A function to get a property from an indicator on a server
238+ and bring it back locally. This wraps all the hassle of using
239+ the DBus API and makes it pretty easy to get properties.
240+
241+ Very similar to #indicate_listener_get_property but converts
242+ the final value into a gboolean for easy (and type-safe)
243+ usage by listeners.
244+*/
245+void
246+indicate_listener_get_property_bool (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, indicate_listener_get_property_bool_cb callback, gpointer data)
247+{
248+ return get_property_helper(listener, server, indicator, property, G_CALLBACK(callback), data, PROPERTY_TYPE_BOOL);
249+}
250+
251+
252 gboolean
253 _indicate_listener_get_indicator_servers (IndicateListener * listener, GList * servers)
254 {
255
256=== modified file 'libindicate/listener.h'
257--- libindicate/listener.h 2009-09-05 16:38:55 +0000
258+++ libindicate/listener.h 2009-09-14 15:01:18 +0000
259@@ -112,6 +112,8 @@
260
261 typedef void (*indicate_listener_get_property_cb) (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, gchar * propertydata, gpointer data);
262 typedef void (*indicate_listener_get_property_time_cb) (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, GTimeVal * propertydata, gpointer data);
263+typedef void (*indicate_listener_get_property_int_cb) (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, gint propertydata, gpointer data);
264+typedef void (*indicate_listener_get_property_bool_cb) (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, gboolean propertydata, gpointer data);
265 typedef void (*indicate_listener_get_server_property_cb) (IndicateListener * listener, IndicateListenerServer * server, gchar * value, gpointer data);
266 typedef void (*indicate_listener_get_server_uint_property_cb) (IndicateListener * listener, IndicateListenerServer * server, guint value, gpointer data);
267
268@@ -130,6 +132,18 @@
269 gchar * property,
270 indicate_listener_get_property_time_cb callback,
271 gpointer data);
272+void indicate_listener_get_property_int (IndicateListener * listener,
273+ IndicateListenerServer * server,
274+ IndicateListenerIndicator * indicator,
275+ gchar * property,
276+ indicate_listener_get_property_int_cb callback,
277+ gpointer data);
278+void indicate_listener_get_property_bool (IndicateListener * listener,
279+ IndicateListenerServer * server,
280+ IndicateListenerIndicator * indicator,
281+ gchar * property,
282+ indicate_listener_get_property_bool_cb callback,
283+ gpointer data);
284 void indicate_listener_display (IndicateListener * listener,
285 IndicateListenerServer * server,
286 IndicateListenerIndicator * indicator);
287
288=== modified file 'libindicate/server.c'
289--- libindicate/server.c 2009-09-08 20:58:26 +0000
290+++ libindicate/server.c 2009-09-14 14:12:39 +0000
291@@ -1047,6 +1047,28 @@
292 return;
293 }
294
295+/**
296+ indicate_server_set_count:
297+ @server: The #IndicateServer to set the type of
298+ @count: The number of items that the server believes the user
299+ would be interested in.
300+
301+ A small convience function to set the #IndicateServer:count
302+ property on the server. This should represent a number of messages
303+ on a particular server. This should not be used at the same time
304+ as individual indicators to show information to the users. They
305+ sound be used independently.
306+*/
307+void
308+indicate_server_set_count (IndicateServer * server, guint count)
309+{
310+ GValue value = {0};
311+ g_value_init(&value, G_TYPE_UINT);
312+ g_value_set_uint(&value, count);
313+ g_object_set_property(G_OBJECT(server), "count", &value);
314+ return;
315+}
316+
317 static IndicateServer * default_indicate_server = NULL;
318
319 /**

Subscribers

People subscribed via source and target branches

to all changes: