Merge lp:~robru/libfriends/exceptions into lp:libfriends

Proposed by Robert Bruce Park
Status: Merged
Approved by: Ken VanDine
Approved revision: 54
Merged at revision: 45
Proposed branch: lp:~robru/libfriends/exceptions
Merge into: lp:libfriends
Diff against target: 854 lines (+216/-171)
6 files modified
examples/example-vala.vala (+48/-11)
gtk/account.vala (+18/-4)
gtk/entry.vala (+58/-23)
src/service.vala (+69/-121)
src/utils.vala (+0/-1)
tests/vala/test-service.vala (+23/-11)
To merge this branch: bzr merge lp:~robru/libfriends/exceptions
Reviewer Review Type Date Requested Status
Ken VanDine Approve
Review via email: mp+143167@code.launchpad.net

Commit message

Make libfriends throw exceptions, so we can catch and test for them in the testsuite.

Description of the change

Ok Ken, I massaged this to get rid of as many compiler warnings as I could.

To post a comment you must log in.
Revision history for this message
Ken VanDine (ken-vandine) wrote :

My previous branch was missing descriptions in the docstrings for all the throws I added. I've fixed that in lp:~ken-vandine/friends/exceptions

Please merge that into your branch.

lp:~robru/libfriends/exceptions updated
54. By Robert Bruce Park

Add descriptions for @throws documentation.

Revision history for this message
Ken VanDine (ken-vandine) wrote :

thanks!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'examples/example-vala.vala'
--- examples/example-vala.vala 2013-01-09 19:30:53 +0000
+++ examples/example-vala.vala 2013-01-14 19:51:21 +0000
@@ -29,7 +29,12 @@
2929
30 public Example (MainLoop loop)30 public Example (MainLoop loop)
31 {31 {
32 service = new Friends.Service();32 try {
33 service = new Friends.Service();
34 } catch (GLib.IOError e) {
35 warning (e.message);
36 service = null;
37 }
33 }38 }
3439
35 public void run_example (string[] args)40 public void run_example (string[] args)
@@ -41,7 +46,11 @@
41 switch (args[1]) {46 switch (args[1]) {
42 case "--refresh":47 case "--refresh":
43 stdout.printf("Refreshing friends\n");48 stdout.printf("Refreshing friends\n");
44 service.refresh();49 try {
50 service.refresh();
51 } catch (GLib.IOError e) {
52 warning (e.message);
53 }
45 return;54 return;
46 case "--features":55 case "--features":
47 if (args.length < 3) {56 if (args.length < 3) {
@@ -49,13 +58,21 @@
49 return;58 return;
50 }59 }
51 stdout.printf("Getting features for %s\n", args[2]);60 stdout.printf("Getting features for %s\n", args[2]);
52 var features = service.features(args[2]);61 try {
53 foreach(string feature in features)62 var features = service.features(args[2]);
54 stdout.printf("%s\n", feature);63 foreach(string feature in features)
64 stdout.printf("%s\n", feature);
65 } catch (GLib.IOError e) {
66 warning (e.message);
67 }
55 return;68 return;
56 case "--shutdown":69 case "--shutdown":
57 stdout.printf("Shutting down the friends service\n");70 stdout.printf("Shutting down the friends service\n");
58 service.quit();71 try {
72 service.quit();
73 } catch (GLib.IOError e) {
74 warning (e.message);
75 }
59 return;76 return;
6077
61 case "--like":78 case "--like":
@@ -69,7 +86,11 @@
69 uint acct = int.parse(args[i+1]);86 uint acct = int.parse(args[i+1]);
70 string id = args[i+2];87 string id = args[i+2];
71 stdout.printf("Liked...\n");88 stdout.printf("Liked...\n");
72 service.like(acct, id);89 try {
90 service.like(acct, id);
91 } catch (GLib.IOError e) {
92 warning (e.message);
93 }
73 } else {94 } else {
74 PrintUsage ();95 PrintUsage ();
75 }96 }
@@ -82,7 +103,11 @@
82 uint acct = int.parse(args[i+1]);103 uint acct = int.parse(args[i+1]);
83 string id = args[i+2];104 string id = args[i+2];
84 stdout.printf("Unliked...\n");105 stdout.printf("Unliked...\n");
85 service.unlike(acct, id);106 try {
107 service.unlike(acct, id);
108 } catch (GLib.IOError e) {
109 warning (e.message);
110 }
86 } else {111 } else {
87 PrintUsage ();112 PrintUsage ();
88 }113 }
@@ -95,7 +120,11 @@
95 uint acct = int.parse(args[i+1]);120 uint acct = int.parse(args[i+1]);
96 string id = args[i+2];121 string id = args[i+2];
97 stdout.printf("Retweet...\n");122 stdout.printf("Retweet...\n");
98 service.retweet(acct, id);123 try {
124 service.retweet(acct, id);
125 } catch (GLib.IOError e) {
126 warning (e.message);
127 }
99 } else {128 } else {
100 PrintUsage ();129 PrintUsage ();
101 }130 }
@@ -132,7 +161,11 @@
132 string message = args[i+2];161 string message = args[i+2];
133 stdout.printf("Posting...\n");162 stdout.printf("Posting...\n");
134 stdout.printf ("message: %s\n account: %u\n", message, acct);163 stdout.printf ("message: %s\n account: %u\n", message, acct);
135 service.send_message(acct, message);164 try {
165 service.send_message(acct, message);
166 } catch (GLib.IOError e) {
167 warning (e.message);
168 }
136 } else {169 } else {
137 PrintUsage ();170 PrintUsage ();
138 }171 }
@@ -151,7 +184,11 @@
151 string message_id = args[i+2];184 string message_id = args[i+2];
152 string message = args[i+3];185 string message = args[i+3];
153 stdout.printf("Replying...\n");186 stdout.printf("Replying...\n");
154 service.send_reply(acct, message_id, message);187 try {
188 service.send_reply(acct, message_id, message);
189 } catch (GLib.IOError e) {
190 warning (e.message);
191 }
155 } else {192 } else {
156 PrintUsage ();193 PrintUsage ();
157 }194 }
158195
=== modified file 'gtk/account.vala'
--- gtk/account.vala 2013-01-11 17:25:44 +0000
+++ gtk/account.vala 2013-01-14 19:51:21 +0000
@@ -82,8 +82,15 @@
82 }82 }
83 set {83 set {
84 GLib.Value t = value;84 GLib.Value t = value;
85 _account.set_value("friends/color", t);85 try
86 _account.store_blocking();86 {
87 _account.set_value("friends/color", t);
88 _account.store_blocking();
89 }
90 catch (Ag.AccountsError e)
91 {
92 warning (e.message);
93 }
87 }94 }
88 }95 }
8996
@@ -117,8 +124,15 @@
117 GLib.Value t = false;124 GLib.Value t = false;
118 if (value == "1")125 if (value == "1")
119 t = true;126 t = true;
120 _account.set_value("friends/send_enabled", t);127 try
121 _account.store_blocking();128 {
129 _account.set_value("friends/send_enabled", t);
130 _account.store_blocking();
131 }
132 catch (Ag.AccountsError e)
133 {
134 warning (e.message);
135 }
122 }136 }
123 }137 }
124138
125139
=== modified file 'gtk/entry.vala'
--- gtk/entry.vala 2013-01-11 17:25:44 +0000
+++ gtk/entry.vala 2013-01-14 19:51:21 +0000
@@ -48,7 +48,12 @@
48 construct48 construct
49 {49 {
50 set_orientation (Gtk.Orientation.VERTICAL);50 set_orientation (Gtk.Orientation.VERTICAL);
51 service = new Friends.Service ();51 try {
52 service = new Friends.Service ();
53 } catch (GLib.IOError e) {
54 warning (e.message);
55 return;
56 }
5257
53 text_view = new InputTextView (service);58 text_view = new InputTextView (service);
54 target_bar = new AccountTargetBar ();59 target_bar = new AccountTargetBar ();
@@ -97,7 +102,12 @@
97102
98 construct103 construct
99 {104 {
100 service = new Friends.Service ();105 try {
106 service = new Friends.Service ();
107 } catch (GLib.IOError e) {
108 warning (e.message);
109 return;
110 }
101111
102 text_view = new InputTextView (service);112 text_view = new InputTextView (service);
103 send_bar = new SendBar ();113 send_bar = new SendBar ();
@@ -124,14 +134,14 @@
124 private Friends.Service service;134 private Friends.Service service;
125135
126 /**136 /**
127 * The {@link Gdk.Color} for the foreground137 * The {@link Gdk.RGBA} for the foreground
128 */138 */
129 public Gdk.Color fg_color;139 public Gdk.RGBA fg_color;
130140
131 /**141 /**
132 * The {@link Gdk.Color} for the error state142 * The {@link Gdk.RGBA} for the error state
133 */143 */
134 public Gdk.Color error_color;144 public Gdk.RGBA error_color;
135145
136 bool last_was_shortened = false;146 bool last_was_shortened = false;
137 private string _mid = null;147 private string _mid = null;
@@ -152,16 +162,25 @@
152162
153 construct163 construct
154 {164 {
155 service = new Friends.Service ();165 try {
166 service = new Friends.Service ();
167 } catch (GLib.IOError e) {
168 warning (e.message);
169 return;
170 }
156171
157 unowned Gtk.BindingSet binding_set;172 unowned Gtk.BindingSet binding_set;
158 binding_set = Gtk.BindingSet.by_class (typeof (InputTextView).class_ref ());173 binding_set = Gtk.BindingSet.by_class (typeof (InputTextView).class_ref ());
159 Gtk.BindingEntry.add_signal (binding_set, Gdk.keyval_from_name ("Return"), 0, "submit", 0);174 Gtk.BindingEntry.add_signal (binding_set, Gdk.keyval_from_name ("Return"), 0, "submit", 0);
160 Gtk.BindingEntry.add_signal (binding_set, Gdk.keyval_from_name ("KP_Enter"), 0, "submit", 0);175 Gtk.BindingEntry.add_signal (binding_set, Gdk.keyval_from_name ("KP_Enter"), 0, "submit", 0);
161 Gtk.BindingEntry.add_signal (binding_set, Gdk.keyval_from_name ("Escape"), 0, "clear", 0);176 Gtk.BindingEntry.add_signal (binding_set, Gdk.keyval_from_name ("Escape"), 0, "clear", 0);
162 fg_color = get_style ().text[Gtk.StateType.NORMAL];177
163178 // FIXME: How do we tell this StyleContext to get the color from the right place?
164 Gdk.Color.parse ("indianred", out error_color);179 Gtk.StyleContext context = new Gtk.StyleContext ();
180 fg_color = context.get_color (Gtk.StateFlags.NORMAL);
181
182 error_color = Gdk.RGBA ();
183 error_color.parse("indianred");
165184
166 get_buffer ().changed.connect (on_text_changed);185 get_buffer ().changed.connect (on_text_changed);
167 get_buffer ().insert_text.connect (on_text_inserted);186 get_buffer ().insert_text.connect (on_text_inserted);
@@ -232,8 +251,12 @@
232 service.send_message(msg, null, null, null);251 service.send_message(msg, null, null, null);
233 }252 }
234 */253 */
235 service.send_message(null, msg);254 try {
236 debug ("(submit) Message: %s posted", msg);255 service.send_message(null, msg);
256 debug ("(submit) Message: %s posted", msg);
257 } catch (GLib.IOError e) {
258 warning (e.message);
259 }
237 reset();260 reset();
238 }261 }
239262
@@ -245,8 +268,10 @@
245 private void on_text_changed ()268 private void on_text_changed ()
246 {269 {
247 var chars = get_buffer ().get_char_count ();270 var chars = get_buffer ().get_char_count ();
248 modify_fg (Gtk.StateType.NORMAL,271 override_color (
249 chars > MAX_MESSAGE_LENGTH ? error_color : fg_color);272 Gtk.StateFlags.NORMAL,
273 chars > MAX_MESSAGE_LENGTH ? error_color : fg_color
274 );
250 }275 }
251276
252 private void on_text_inserted (ref Gtk.TextIter iter, string text, int len)277 private void on_text_inserted (ref Gtk.TextIter iter, string text, int len)
@@ -258,9 +283,14 @@
258 {283 {
259 var buf = get_buffer ();284 var buf = get_buffer ();
260 Signal.stop_emission_by_name (buf, "insert-text") ;285 Signal.stop_emission_by_name (buf, "insert-text") ;
261 var shrt = service.shorten (text);286 try {
262 last_was_shortened = true;287 var shrt = service.shorten (text);
263 buf.insert (ref iter, shrt, -1);288 last_was_shortened = true;
289 buf.insert (ref iter, shrt, -1);
290 } catch (GLib.IOError e) {
291 warning (e.message);
292 return;
293 }
264 }294 }
265 else295 else
266 {296 {
@@ -300,9 +330,9 @@
300 {330 {
301 context.translate(-1, -1);331 context.translate(-1, -1);
302 factor = 1.0;332 factor = 1.0;
303 } else if (get_state () == 2) {333 } else if (get_state_flags () == Gtk.StateFlags.PRELIGHT) {
304 factor = 0.3;334 factor = 0.3;
305 } else if (get_state () == 1) {335 } else if (get_state_flags () == Gtk.StateFlags.ACTIVE) {
306 factor = 0.5;336 factor = 0.5;
307 }337 }
308338
@@ -354,10 +384,10 @@
354 {384 {
355 Object (spacing:0);385 Object (spacing:0);
356 }386 }
357 387
358 /*388 /*
359 * The {@Ag.Account.id} of the account button to be displayed389 * The {@Ag.Account.id} of the account button to be displayed
360 * This is used in the case of replies or private messages 390 * This is used in the case of replies or private messages
361 * where the post will only go to a single account391 * where the post will only go to a single account
362 */392 */
363 public uint? selected {393 public uint? selected {
@@ -402,7 +432,12 @@
402 if (GLib.FileUtils.test (local_icon_path, GLib.FileTest.IS_DIR))432 if (GLib.FileUtils.test (local_icon_path, GLib.FileTest.IS_DIR))
403 icon_theme.prepend_search_path (local_icon_path);433 icon_theme.prepend_search_path (local_icon_path);
404434
405 service = new Friends.Service();435 try {
436 service = new Friends.Service ();
437 } catch (GLib.IOError e) {
438 warning (e.message);
439 return;
440 }
406 accounts_service = new FriendsAccounts();441 accounts_service = new FriendsAccounts();
407442
408 // Add buttons to button area at the bottom443 // Add buttons to button area at the bottom
@@ -490,7 +525,7 @@
490 return account_button;525 return account_button;
491 }526 }
492527
493 /* 528 /*
494 * Set the number of remaining characters allowed to post529 * Set the number of remaining characters allowed to post
495 * @param chars Number of characters remaining530 * @param chars Number of characters remaining
496 */531 */
497532
=== modified file 'src/service.vala'
--- src/service.vala 2013-01-11 18:53:44 +0000
+++ src/service.vala 2013-01-14 19:51:21 +0000
@@ -51,8 +51,10 @@
51 /**51 /**
52 * Establish a connection to the local Friends Service daemon.52 * Establish a connection to the local Friends Service daemon.
53 * @return a new Service53 * @return a new Service
54 * @throws GLib.IOError if failed to connect to the
55 * Friends Service daemon.
54 */56 */
55 public Service ()57 public Service () throws IOError
56 {58 {
57 Object ();59 Object ();
58 try60 try
@@ -65,7 +67,8 @@
65 }67 }
66 catch (GLib.IOError e)68 catch (GLib.IOError e)
67 {69 {
68 warning ("Unable to get Gwibber service: "+e.message);70 warning ("Unable to get Friends service: "+e.message);
71 throw (e);
69 }72 }
70 }73 }
7174
@@ -82,16 +85,17 @@
82 * parameter and is rather arbitrary.85 * parameter and is rather arbitrary.
83 *86 *
84 * @since 0.187 * @since 0.1
88 * @throws GLib.IOError if action failed.
85 */89 */
86 private bool do(string action, string account_id, string argument)90 private bool do(string action, string account_id, string argument) throws IOError
87 {91 {
88 try {92 try {
89 service.Do(action, account_id, argument);93 service.Do(action, account_id, argument);
90 return true;94 return true;
91 } catch (GLib.Error e) {95 } catch (GLib.IOError e) {
92 warning (e.message);96 warning (e.message);
97 throw (e);
93 }98 }
94 return false;
95 }99 }
96100
97 /**101 /**
@@ -101,28 +105,22 @@
101 * to exit, preventing any other clients from accessing it.105 * to exit, preventing any other clients from accessing it.
102 *106 *
103 * @since 0.1107 * @since 0.1
108 * @throws GLib.IOError if the call to Friends.Service.Quit fails.
104 */109 */
105 public void quit()110 public void quit() throws IOError
106 {111 {
107 try {112 service.Quit();
108 service.Quit();
109 } catch (GLib.IOError e) {
110 warning (e.message);
111 }
112 }113 }
113114
114 /**115 /**
115 * Perform a refresh of all enabled accounts.116 * Perform a refresh of all enabled accounts.
116 *117 *
117 * @since 0.1118 * @since 0.1
119 * @throws GLib.IOError if the call to Friends.Service.Refresh fails.
118 */120 */
119 public void refresh()121 public void refresh() throws IOError
120 {122 {
121 try {123 service.Refresh();
122 service.Refresh();
123 } catch (GLib.IOError e) {
124 warning (e.message);
125 }
126 }124 }
127125
128 /**126 /**
@@ -137,8 +135,9 @@
137 * uploaded photo.135 * uploaded photo.
138 *136 *
139 * @since 0.1137 * @since 0.1
138 * @throws GLib.IOError if the call to Friends.Service.Upload fails.
140 */139 */
141 public void upload(uint account_id, string uri, string description)140 public void upload(uint account_id, string uri, string description) throws IOError
142 {141 {
143 string result_url = null;142 string result_url = null;
144 service.Upload.begin(account_id.to_string(), uri, description, (obj, res) => {143 service.Upload.begin(account_id.to_string(), uri, description, (obj, res) => {
@@ -146,6 +145,7 @@
146 service.Upload.end(res, out result_url);145 service.Upload.end(res, out result_url);
147 } catch (IOError e) {146 } catch (IOError e) {
148 warning (e.message);147 warning (e.message);
148 throw (e);
149 }149 }
150 });150 });
151 }151 }
@@ -161,16 +161,11 @@
161 * uploaded file.161 * uploaded file.
162 *162 *
163 * @since 0.1163 * @since 0.1
164 * @throws GLib.IOError if uploading the image failed.164 * @throws GLib.IOError if the call to Friends.Service.Upload fails.
165 */165 */
166 public async void upload_async(uint account_id, string uri, string description, out string result_url) throws IOError166 public async void upload_async(uint account_id, string uri, string description, out string result_url) throws IOError
167 {167 {
168 try {168 yield service.Upload(account_id.to_string(), uri, description, out result_url);
169 yield service.Upload(account_id.to_string(), uri, description, out result_url);
170 } catch (IOError e) {
171 warning (e.message);
172 throw (e);
173 }
174 }169 }
175170
176171
@@ -189,16 +184,17 @@
189 * @return ``true`` for success, ``false`` otherwise184 * @return ``true`` for success, ``false`` otherwise
190 *185 *
191 * @since 0.1186 * @since 0.1
187 * @throws GLib.IOError if the call to Friends.Service.SendReply fails.
192 */188 */
193 public bool send_reply(uint account_id, string message_id, string message)189 public bool send_reply(uint account_id, string message_id, string message) throws IOError
194 {190 {
195 try {191 try {
196 service.SendReply(message, account_id.to_string(), message_id);192 service.SendReply(message, account_id.to_string(), message_id);
197 return true;193 return true;
198 } catch (GLib.Error e) {194 } catch (GLib.IOError e) {
199 warning (e.message);195 warning (e.message);
196 throw (e);
200 }197 }
201 return false;
202 }198 }
203199
204200
@@ -210,19 +206,15 @@
210 * @return ``true`` for success, ``false`` otherwise206 * @return ``true`` for success, ``false`` otherwise
211 *207 *
212 * @since 0.1208 * @since 0.1
209 * @throws GLib.IOError if the call to Friends.Service.SendMessage fails.
213 */210 */
214 public bool send_message(uint? account_id, string message)211 public bool send_message(uint? account_id, string message) throws IOError
215 {212 {
216 try {213 if (account_id != null)
217 if (account_id != null)214 return do("send", account_id.to_string(), message);
218 return do("send", account_id.to_string(), message);215 else
219 else216 service.SendMessage(message);
220 service.SendMessage(message);217 return true;
221 return true;
222 } catch (GLib.Error e) {
223 warning (e.message);
224 }
225 return false;
226 }218 }
227219
228 /**220 /**
@@ -233,15 +225,11 @@
233 * @return ``true`` for success, ``false`` otherwise225 * @return ``true`` for success, ``false`` otherwise
234 *226 *
235 * @since 0.1227 * @since 0.1
228 * @throws GLib.IOError if the call to Friends.Service.Do fails.
236 */229 */
237 public bool retweet(uint account_id, string message_id)230 public bool retweet(uint account_id, string message_id) throws IOError
238 {231 {
239 try {232 return do("retweet", account_id.to_string(), message_id);
240 return do("retweet", account_id.to_string(), message_id);
241 } catch (GLib.Error e) {
242 warning (e.message);
243 }
244 return false;
245 }233 }
246234
247 /**235 /**
@@ -254,15 +242,11 @@
254 * @return ``true`` for success, ``false`` otherwise242 * @return ``true`` for success, ``false`` otherwise
255 *243 *
256 * @since 0.1244 * @since 0.1
245 * @throws GLib.IOError if the call to Friends.Service.Do fails.
257 */246 */
258 public bool home(uint account_id)247 public bool home(uint account_id) throws IOError
259 {248 {
260 try {249 return do("home", account_id.to_string(), "");
261 return do("home", account_id.to_string(), "");
262 } catch (GLib.Error e) {
263 warning (e.message);
264 }
265 return false;
266 }250 }
267251
268 /**252 /**
@@ -276,15 +260,11 @@
276 * @return ``true`` for success, ``false`` otherwise260 * @return ``true`` for success, ``false`` otherwise
277 *261 *
278 * @since 0.1262 * @since 0.1
263 * @throws GLib.IOError if the call to Friends.Service.Do fails.
279 */264 */
280 public bool wall(uint account_id)265 public bool wall(uint account_id) throws IOError
281 {266 {
282 try {267 return do("wall", account_id.to_string(), "");
283 return do("wall", account_id.to_string(), "");
284 } catch (GLib.Error e) {
285 warning (e.message);
286 }
287 return false;
288 }268 }
289269
290 /**270 /**
@@ -296,18 +276,14 @@
296 * @return ``true`` for success, ``false`` otherwise276 * @return ``true`` for success, ``false`` otherwise
297 *277 *
298 * @since 0.1278 * @since 0.1
279 * @throws GLib.IOError if the call to Friends.Service.Do fails.
299 */280 */
300 public bool search(uint? account_id, string query)281 public bool search(uint? account_id, string query) throws IOError
301 {282 {
302 try {283 if (account_id != null)
303 if (account_id != null)284 return do("search", account_id.to_string(), query);
304 return do("search", account_id.to_string(), query);285 else
305 else286 return do("search", "", query);
306 return do("search", "", query);
307 } catch (GLib.Error e) {
308 warning (e.message);
309 }
310 return false;
311 }287 }
312288
313 /**289 /**
@@ -319,15 +295,11 @@
319 * @return ``true`` for success, ``false`` otherwise295 * @return ``true`` for success, ``false`` otherwise
320 *296 *
321 * @since 0.1297 * @since 0.1
298 * @throws GLib.IOError if the call to Friends.Service.Do fails.
322 */299 */
323 public bool like(uint account_id, string message_id)300 public bool like(uint account_id, string message_id) throws IOError
324 {301 {
325 try {302 return do("like", account_id.to_string(), message_id);
326 return do("like", account_id.to_string(), message_id);
327 } catch (GLib.Error e) {
328 warning (e.message);
329 }
330 return false;
331 }303 }
332304
333 /**305 /**
@@ -339,15 +311,11 @@
339 * @return ``true`` for success, ``false`` otherwise311 * @return ``true`` for success, ``false`` otherwise
340 *312 *
341 * @since 0.1313 * @since 0.1
314 * @throws GLib.IOError if the call to Friends.Service.Do fails.
342 */315 */
343 public bool unlike(uint account_id, string message_id)316 public bool unlike(uint account_id, string message_id) throws IOError
344 {317 {
345 try {318 return do("unlike", account_id.to_string(), message_id);
346 return do("unlike", account_id.to_string(), message_id);
347 } catch (GLib.Error e) {
348 warning (e.message);
349 }
350 return false;
351 }319 }
352320
353 /**321 /**
@@ -359,15 +327,11 @@
359 * @return ``true`` for success, ``false`` otherwise327 * @return ``true`` for success, ``false`` otherwise
360 *328 *
361 * @since 0.1329 * @since 0.1
330 * @throws GLib.IOError if the call to Friends.Service.Do fails.
362 */331 */
363 public bool delete(uint account_id, string message_id)332 public bool delete(uint account_id, string message_id) throws IOError
364 {333 {
365 try {334 return do("delete", account_id.to_string(), message_id);
366 return do("delete", account_id.to_string(), message_id);
367 } catch (GLib.Error e) {
368 warning (e.message);
369 }
370 return false;
371 }335 }
372336
373 /**337 /**
@@ -378,15 +342,11 @@
378 * @return ``true`` for success, ``false`` otherwise342 * @return ``true`` for success, ``false`` otherwise
379 *343 *
380 * @since 0.1344 * @since 0.1
345 * @throws GLib.IOError if the call to Friends.Service.Do fails.
381 */346 */
382 public bool contacts(uint account_id)347 public bool contacts(uint account_id) throws IOError
383 {348 {
384 try {349 return do("contacts", account_id.to_string(), "");
385 return do("contacts", account_id.to_string(), "");
386 } catch (GLib.Error e) {
387 warning (e.message);
388 }
389 return false;
390 }350 }
391351
392 /**352 /**
@@ -396,25 +356,18 @@
396 * @return The shortened URL.356 * @return The shortened URL.
397 *357 *
398 * @since 0.1358 * @since 0.1
359 * @throws GLib.IOError if the call to Friends.Service.URLShorten fails.
399 */360 */
400 public string shorten(string url)361 public string shorten(string url) throws IOError
401 {362 {
402 try363 return service.URLShorten(url);
403 {
404 return service.URLShorten(url);
405 }
406 catch (GLib.IOError e)
407 {
408 warning (e.message);
409 return url;
410 }
411 }364 }
412365
413 /**366 /**
414 * This method returns a list of all the possible actions367 * This method returns a list of all the possible actions
415 * supported by a given protocol. This can be used to368 * supported by a given protocol. This can be used to
416 * determine what actions are available for the requested 369 * determine what actions are available for the requested
417 * protocol. 370 * protocol.
418 *371 *
419 * @param protocol One of ``facebook``, ``flickr``,372 * @param protocol One of ``facebook``, ``flickr``,
420 * ``foursquare``, ``identica``, or ``twitter``.373 * ``foursquare``, ``identica``, or ``twitter``.
@@ -422,19 +375,16 @@
422 * features) if there are no features found for ``protocol``.375 * features) if there are no features found for ``protocol``.
423 *376 *
424 * @since 0.1377 * @since 0.1
378 * @throws GLib.Error if the call to Friends.Service.GetFeatures fails.
425 */379 */
426 public string[] features(string protocol)380 public string[] features(string protocol) throws Error
427 {381 {
428 string[] _features = null;382 string[] _features = null;
429 try {
430 var parser = new Json.Parser();383 var parser = new Json.Parser();
431 parser.load_from_data(service.GetFeatures(protocol), -1);384 parser.load_from_data(service.GetFeatures(protocol), -1);
432 var nodes = parser.get_root().get_array().get_elements();385 var nodes = parser.get_root().get_array().get_elements();
433 foreach(var node in nodes)386 foreach(var node in nodes)
434 _features += node.dup_string ();387 _features += node.dup_string ();
435 } catch(GLib.Error e) {
436 warning(e.message);
437 }
438 return _features;388 return _features;
439 }389 }
440390
@@ -442,14 +392,12 @@
442 * Clear all notifications from the messaging menu.392 * Clear all notifications from the messaging menu.
443 *393 *
444 * @since 0.1394 * @since 0.1
395 * @throws GLib.IOError if the call to Friends.Service.ClearIndicators
396 * fails.
445 */397 */
446 public void messaging_menu_clear()398 public void messaging_menu_clear() throws IOError
447 {399 {
448 try {400 service.ClearIndicators();
449 service.ClearIndicators();
450 } catch (GLib.IOError e) {
451 warning (e.message);
452 }
453 }401 }
454402
455 private void connection_offline()403 private void connection_offline()
456404
=== modified file 'src/utils.vala'
--- src/utils.vala 2013-01-09 18:50:08 +0000
+++ src/utils.vala 2013-01-14 19:51:21 +0000
@@ -54,7 +54,6 @@
54 {54 {
55 string _avatar_cache_image = Path.build_path (Path.DIR_SEPARATOR_S, Environment.get_user_cache_dir(), "friends/avatars", GLib.Checksum.compute_for_string (GLib.ChecksumType.SHA1, url));55 string _avatar_cache_image = Path.build_path (Path.DIR_SEPARATOR_S, Environment.get_user_cache_dir(), "friends/avatars", GLib.Checksum.compute_for_string (GLib.ChecksumType.SHA1, url));
56 debug ("AVATAR PATH: %s", _avatar_cache_image);56 debug ("AVATAR PATH: %s", _avatar_cache_image);
57 var file = File.new_for_path (_avatar_cache_image);
58 return _avatar_cache_image;57 return _avatar_cache_image;
59 }58 }
60 }59 }
6160
=== modified file 'tests/vala/test-service.vala'
--- tests/vala/test-service.vala 2013-01-09 19:41:41 +0000
+++ tests/vala/test-service.vala 2013-01-14 19:51:21 +0000
@@ -61,9 +61,20 @@
61 ServiceSuite.test_url_shorten);61 ServiceSuite.test_url_shorten);
62 }62 }
6363
64 static Friends.Service? get_service ()
65 {
66 Friends.Service service = null;
67 try {
68 service = new Friends.Service ();
69 } catch (GLib.IOError e) {
70 warning(e.message);
71 }
72 return service;
73 }
74
64 internal static void test_refresh ()75 internal static void test_refresh ()
65 {76 {
66 var service = new Friends.Service ();77 var service = get_service ();
67 bool success = false;78 bool success = false;
68 try79 try
69 {80 {
@@ -80,7 +91,7 @@
8091
81 internal static void test_quit ()92 internal static void test_quit ()
82 {93 {
83 var service = new Friends.Service ();94 var service = get_service ();
84 bool success = false;95 bool success = false;
85 try96 try
86 {97 {
@@ -97,22 +108,23 @@
97108
98 internal static void test_features ()109 internal static void test_features ()
99 {110 {
100 var service = new Friends.Service ();111 var service = get_service ();
101 string[] features;112 string[] features = null;
102 try113 try
103 {114 {
104 features = service.features ("twitter");115 features = service.features ("twitter");
105 }116 }
106 catch (GLib.IOError e)117 catch (GLib.Error e)
107 {118 {
108 warning ("Failed to get features - %s", e.message);119 warning ("Failed to get features - %s", e.message);
109 }120 }
121 assert (features != null);
110 assert ("send" in features);122 assert ("send" in features);
111 }123 }
112124
113 internal static void test_upload ()125 internal static void test_upload ()
114 {126 {
115 var service = new Friends.Service ();127 var service = get_service ();
116 uint acct = 1;128 uint acct = 1;
117 string uri = "file:///tmp/foo.png";129 string uri = "file:///tmp/foo.png";
118 string desc = "Something interesting to say";130 string desc = "Something interesting to say";
@@ -129,7 +141,7 @@
129141
130 internal static void test_send_message ()142 internal static void test_send_message ()
131 {143 {
132 var service = new Friends.Service ();144 var service = get_service ();
133 uint? acct = null;145 uint? acct = null;
134 string msg = "A message";146 string msg = "A message";
135 bool success = false;147 bool success = false;
@@ -147,7 +159,7 @@
147159
148 internal static void test_send_message_with_account ()160 internal static void test_send_message_with_account ()
149 {161 {
150 var service = new Friends.Service ();162 var service = get_service ();
151 uint acct = 1;163 uint acct = 1;
152 string msg = "A message";164 string msg = "A message";
153 bool success = false;165 bool success = false;
@@ -165,7 +177,7 @@
165177
166 internal static void test_send_reply ()178 internal static void test_send_reply ()
167 {179 {
168 var service = new Friends.Service ();180 var service = get_service ();
169 uint acct = 1;181 uint acct = 1;
170 string msg = "A message";182 string msg = "A message";
171 string msg_id = "100";183 string msg_id = "100";
@@ -184,7 +196,7 @@
184196
185 internal static void test_clear_indicators ()197 internal static void test_clear_indicators ()
186 {198 {
187 var service = new Friends.Service ();199 var service = get_service ();
188 bool success = false;200 bool success = false;
189 try201 try
190 {202 {
@@ -200,7 +212,7 @@
200212
201 internal static void test_url_shorten ()213 internal static void test_url_shorten ()
202 {214 {
203 var service = new Friends.Service ();215 var service = get_service ();
204 string result = "";216 string result = "";
205 try217 try
206 {218 {

Subscribers

People subscribed via source and target branches