comparison libpurple/notify.c @ 22820:5e6b42e77fb7

Cleanup and avoid unnecessary alloc/free.
author Daniel Atallah <daniel.atallah@gmail.com>
date Fri, 02 May 2008 23:16:11 +0000
parents 93c40e412b54
children 84693a70ea3a
comparison
equal deleted inserted replaced
22819:42dfa1139b5c 22820:5e6b42e77fb7
64 g_return_val_if_fail(primary != NULL, NULL); 64 g_return_val_if_fail(primary != NULL, NULL);
65 65
66 ops = purple_notify_get_ui_ops(); 66 ops = purple_notify_get_ui_ops();
67 67
68 if (ops != NULL && ops->notify_message != NULL) { 68 if (ops != NULL && ops->notify_message != NULL) {
69 PurpleNotifyInfo *info; 69 void *ui_handle = ops->notify_message(type, title, primary,
70
71 info = g_new0(PurpleNotifyInfo, 1);
72 info->type = PURPLE_NOTIFY_MESSAGE;
73 info->handle = handle;
74 info->ui_handle = ops->notify_message(type, title, primary,
75 secondary); 70 secondary);
76 info->cb = cb; 71 if (ui_handle != NULL) {
77 info->cb_user_data = user_data; 72
78 73 PurpleNotifyInfo *info = g_new0(PurpleNotifyInfo, 1);
79 if (info->ui_handle != NULL) { 74 info->type = PURPLE_NOTIFY_MESSAGE;
75 info->handle = handle;
76 info->ui_handle = ui_handle;
77 info->cb = cb;
78 info->cb_user_data = user_data;
79
80 handles = g_list_append(handles, info); 80 handles = g_list_append(handles, info);
81 81
82 return info->ui_handle; 82 return info->ui_handle;
83
84 } else {
85 if (info->cb != NULL)
86 info->cb(info->cb_user_data);
87
88 g_free(info);
89
90 return NULL;
91 } 83 }
92 84
93 } else { 85 }
94 if (cb != NULL) 86
95 cb(user_data); 87 if (cb != NULL)
96 } 88 cb(user_data);
97 89
98 return NULL; 90 return NULL;
99 } 91 }
100 92
101 void * 93 void *
106 PurpleNotifyUiOps *ops; 98 PurpleNotifyUiOps *ops;
107 99
108 ops = purple_notify_get_ui_ops(); 100 ops = purple_notify_get_ui_ops();
109 101
110 if (ops != NULL && ops->notify_email != NULL) { 102 if (ops != NULL && ops->notify_email != NULL) {
111 PurpleNotifyInfo *info; 103 void *ui_handle;
112
113 info = g_new0(PurpleNotifyInfo, 1);
114 info->type = PURPLE_NOTIFY_EMAIL;
115 info->handle = handle;
116 104
117 purple_signal_emit(purple_notify_get_handle(), "displaying-email-notification", 105 purple_signal_emit(purple_notify_get_handle(), "displaying-email-notification",
118 subject, from, to, url); 106 subject, from, to, url);
119 107
120 info->ui_handle = ops->notify_email(handle, subject, from, to, url); 108 ui_handle = ops->notify_email(handle, subject, from, to, url);
121 info->cb = cb; 109
122 info->cb_user_data = user_data; 110 if (ui_handle != NULL) {
123 111
124 if (info->ui_handle != NULL) { 112 PurpleNotifyInfo *info = g_new0(PurpleNotifyInfo, 1);
113 info->type = PURPLE_NOTIFY_EMAIL;
114 info->handle = handle;
115 info->ui_handle = ui_handle;
116 info->cb = cb;
117 info->cb_user_data = user_data;
118
125 handles = g_list_append(handles, info); 119 handles = g_list_append(handles, info);
126 120
127 return info->ui_handle; 121 return info->ui_handle;
128
129 } else {
130 if (info->cb != NULL)
131 info->cb(info->cb_user_data);
132
133 g_free(info);
134
135 return NULL;
136 } 122 }
137 } else { 123 }
138 if (cb != NULL) 124
139 cb(user_data); 125 if (cb != NULL)
140 } 126 cb(user_data);
141 127
142 return NULL; 128 return NULL;
143 } 129 }
144 130
145 void * 131 void *
160 } 146 }
161 147
162 ops = purple_notify_get_ui_ops(); 148 ops = purple_notify_get_ui_ops();
163 149
164 if (ops != NULL && ops->notify_emails != NULL) { 150 if (ops != NULL && ops->notify_emails != NULL) {
165 PurpleNotifyInfo *info; 151 void *ui_handle;
166
167 info = g_new0(PurpleNotifyInfo, 1);
168 info->type = PURPLE_NOTIFY_EMAILS;
169 info->handle = handle;
170 152
171 purple_signal_emit(purple_notify_get_handle(), "displaying-emails-notification", 153 purple_signal_emit(purple_notify_get_handle(), "displaying-emails-notification",
172 subjects, froms, tos, urls, count); 154 subjects, froms, tos, urls, count);
173 155
174 info->ui_handle = ops->notify_emails(handle, count, detailed, subjects, 156 ui_handle = ops->notify_emails(handle, count, detailed, subjects,
175 froms, tos, urls); 157 froms, tos, urls);
176 info->cb = cb; 158
177 info->cb_user_data = user_data; 159 if (ui_handle != NULL) {
178 160 PurpleNotifyInfo *info = g_new0(PurpleNotifyInfo, 1);
179 if (info->ui_handle != NULL) { 161 info->type = PURPLE_NOTIFY_EMAILS;
162 info->handle = handle;
163 info->ui_handle = ui_handle;
164 info->cb = cb;
165 info->cb_user_data = user_data;
166
180 handles = g_list_append(handles, info); 167 handles = g_list_append(handles, info);
181 168
182 return info->ui_handle; 169 return info->ui_handle;
183
184 } else {
185 if (info->cb != NULL)
186 info->cb(info->cb_user_data);
187
188 g_free(info);
189
190 return NULL;
191 } 170 }
192 171
193 } else { 172 }
194 if (cb != NULL) 173
195 cb(user_data); 174 if (cb != NULL)
196 } 175 cb(user_data);
197 176
198 return NULL; 177 return NULL;
199 } 178 }
200 179
201 void * 180 void *
208 g_return_val_if_fail(primary != NULL, NULL); 187 g_return_val_if_fail(primary != NULL, NULL);
209 188
210 ops = purple_notify_get_ui_ops(); 189 ops = purple_notify_get_ui_ops();
211 190
212 if (ops != NULL && ops->notify_formatted != NULL) { 191 if (ops != NULL && ops->notify_formatted != NULL) {
213 PurpleNotifyInfo *info; 192 void *ui_handle = ops->notify_formatted(title, primary, secondary, text);
214 193
215 info = g_new0(PurpleNotifyInfo, 1); 194 if (ui_handle != NULL) {
216 info->type = PURPLE_NOTIFY_FORMATTED; 195
217 info->handle = handle; 196 PurpleNotifyInfo *info = g_new0(PurpleNotifyInfo, 1);
218 info->ui_handle = ops->notify_formatted(title, primary, secondary, text); 197 info->type = PURPLE_NOTIFY_FORMATTED;
219 info->cb = cb; 198 info->handle = handle;
220 info->cb_user_data = user_data; 199 info->ui_handle = ui_handle;
221 200 info->cb = cb;
222 if (info->ui_handle != NULL) { 201 info->cb_user_data = user_data;
202
223 handles = g_list_append(handles, info); 203 handles = g_list_append(handles, info);
224 204
225 return info->ui_handle; 205 return info->ui_handle;
226
227 } else {
228 if (info->cb != NULL)
229 info->cb(info->cb_user_data);
230
231 g_free(info);
232
233 return NULL;
234 } 206 }
235 207 }
236 } else { 208
237 if (cb != NULL) 209 if (cb != NULL)
238 cb(user_data); 210 cb(user_data);
239 }
240
241 return NULL; 211 return NULL;
242 } 212 }
243 213
244 void * 214 void *
245 purple_notify_searchresults(PurpleConnection *gc, const char *title, 215 purple_notify_searchresults(PurpleConnection *gc, const char *title,
250 PurpleNotifyUiOps *ops; 220 PurpleNotifyUiOps *ops;
251 221
252 ops = purple_notify_get_ui_ops(); 222 ops = purple_notify_get_ui_ops();
253 223
254 if (ops != NULL && ops->notify_searchresults != NULL) { 224 if (ops != NULL && ops->notify_searchresults != NULL) {
255 PurpleNotifyInfo *info; 225 void *ui_handle = ops->notify_searchresults(gc, title, primary,
256
257 info = g_new0(PurpleNotifyInfo, 1);
258 info->type = PURPLE_NOTIFY_SEARCHRESULTS;
259 info->handle = gc;
260 info->ui_handle = ops->notify_searchresults(gc, title, primary,
261 secondary, results, user_data); 226 secondary, results, user_data);
262 info->cb = cb; 227 if (ui_handle != NULL) {
263 info->cb_user_data = user_data; 228
264 229 PurpleNotifyInfo *info = g_new0(PurpleNotifyInfo, 1);
265 if (info->ui_handle != NULL) { 230 info->type = PURPLE_NOTIFY_SEARCHRESULTS;
231 info->handle = gc;
232 info->ui_handle = ui_handle;
233 info->cb = cb;
234 info->cb_user_data = user_data;
235
266 handles = g_list_append(handles, info); 236 handles = g_list_append(handles, info);
267 237
268 return info->ui_handle; 238 return info->ui_handle;
269
270 } else {
271 if (info->cb != NULL)
272 info->cb(info->cb_user_data);
273
274 g_free(info);
275
276 return NULL;
277 } 239 }
278 240 }
279 } else { 241
280 if (cb != NULL) 242 if (cb != NULL)
281 cb(user_data); 243 cb(user_data);
282 }
283 244
284 return NULL; 245 return NULL;
285 } 246 }
286 247
287 void 248 void
447 g_return_val_if_fail(who != NULL, NULL); 408 g_return_val_if_fail(who != NULL, NULL);
448 409
449 ops = purple_notify_get_ui_ops(); 410 ops = purple_notify_get_ui_ops();
450 411
451 if (ops != NULL && ops->notify_userinfo != NULL) { 412 if (ops != NULL && ops->notify_userinfo != NULL) {
452 PurpleNotifyInfo *info; 413 void *ui_handle;
453
454 info = g_new0(PurpleNotifyInfo, 1);
455 info->type = PURPLE_NOTIFY_USERINFO;
456 info->handle = gc;
457 414
458 purple_signal_emit(purple_notify_get_handle(), "displaying-userinfo", 415 purple_signal_emit(purple_notify_get_handle(), "displaying-userinfo",
459 purple_connection_get_account(gc), who, user_info); 416 purple_connection_get_account(gc), who, user_info);
460 417
461 info->ui_handle = ops->notify_userinfo(gc, who, user_info); 418 ui_handle = ops->notify_userinfo(gc, who, user_info);
462 info->cb = cb; 419
463 info->cb_user_data = user_data; 420 if (ui_handle != NULL) {
464 421
465 if (info->ui_handle != NULL) { 422 PurpleNotifyInfo *info = g_new0(PurpleNotifyInfo, 1);
423 info->type = PURPLE_NOTIFY_USERINFO;
424 info->handle = gc;
425 info->ui_handle = ui_handle;
426 info->cb = cb;
427 info->cb_user_data = user_data;
428
466 handles = g_list_append(handles, info); 429 handles = g_list_append(handles, info);
467 430
468 return info->ui_handle; 431 return info->ui_handle;
469
470 } else {
471 if (info->cb != NULL)
472 info->cb(info->cb_user_data);
473
474 g_free(info);
475
476 return NULL;
477 } 432 }
478 433 }
479 } else { 434
480 if (cb != NULL) 435 if (cb != NULL)
481 cb(user_data); 436 cb(user_data);
482 }
483 437
484 return NULL; 438 return NULL;
485 } 439 }
486 440
487 PurpleNotifyUserInfoEntry * 441 PurpleNotifyUserInfoEntry *
703 g_return_val_if_fail(uri != NULL, NULL); 657 g_return_val_if_fail(uri != NULL, NULL);
704 658
705 ops = purple_notify_get_ui_ops(); 659 ops = purple_notify_get_ui_ops();
706 660
707 if (ops != NULL && ops->notify_uri != NULL) { 661 if (ops != NULL && ops->notify_uri != NULL) {
708 PurpleNotifyInfo *info; 662
709 663 void *ui_handle = ops->notify_uri(uri);
710 info = g_new0(PurpleNotifyInfo, 1); 664
711 info->type = PURPLE_NOTIFY_URI; 665 if (ui_handle != NULL) {
712 info->handle = handle; 666
713 info->ui_handle = ops->notify_uri(uri); 667 PurpleNotifyInfo *info = g_new0(PurpleNotifyInfo, 1);
714 668 info->type = PURPLE_NOTIFY_URI;
715 if (info->ui_handle != NULL) { 669 info->handle = handle;
670 info->ui_handle = ui_handle;
671
716 handles = g_list_append(handles, info); 672 handles = g_list_append(handles, info);
717 673
718 return info->ui_handle; 674 return info->ui_handle;
719
720 } else {
721 g_free(info);
722
723 return NULL;
724 } 675 }
725 } 676 }
726 677
727 return NULL; 678 return NULL;
728 } 679 }