comparison finch/gntnotify.c @ 15823:32c366eeeb99

sed -ie 's/gaim/purple/g'
author Sean Egan <seanegan@gmail.com>
date Mon, 19 Mar 2007 07:01:17 +0000
parents 0e3a8505ebbe
children 66dff3dfdea6
comparison
equal deleted inserted replaced
15822:84b0f9b23ede 15823:32c366eeeb99
1 /** 1 /**
2 * @file gntnotify.c GNT Notify API 2 * @file gntnotify.c GNT Notify API
3 * @ingroup gntui 3 * @ingroup gntui
4 * 4 *
5 * gaim 5 * purple
6 * 6 *
7 * Gaim is the legal property of its developers, whose names are too numerous 7 * Purple is the legal property of its developers, whose names are too numerous
8 * to list here. Please refer to the COPYRIGHT file distributed with this 8 * to list here. Please refer to the COPYRIGHT file distributed with this
9 * source distribution. 9 * source distribution.
10 * 10 *
11 * This program is free software; you can redistribute it and/or modify 11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by 12 * it under the terms of the GNU General Public License as published by
29 #include <gnttree.h> 29 #include <gnttree.h>
30 30
31 #include <util.h> 31 #include <util.h>
32 32
33 #include "gntnotify.h" 33 #include "gntnotify.h"
34 #include "gntgaim.h" 34 #include "finch.h"
35 35
36 static struct 36 static struct
37 { 37 {
38 GntWidget *window; 38 GntWidget *window;
39 GntWidget *tree; 39 GntWidget *tree;
40 } emaildialog; 40 } emaildialog;
41 41
42 static void 42 static void
43 notify_msg_window_destroy_cb(GntWidget *window, GaimNotifyMsgType type) 43 notify_msg_window_destroy_cb(GntWidget *window, PurpleNotifyMsgType type)
44 { 44 {
45 gaim_notify_close(type, window); 45 purple_notify_close(type, window);
46 } 46 }
47 47
48 static void * 48 static void *
49 finch_notify_message(GaimNotifyMsgType type, const char *title, 49 finch_notify_message(PurpleNotifyMsgType type, const char *title,
50 const char *primary, const char *secondary) 50 const char *primary, const char *secondary)
51 { 51 {
52 GntWidget *window, *button; 52 GntWidget *window, *button;
53 GntTextFormatFlags pf = 0, sf = 0; 53 GntTextFormatFlags pf = 0, sf = 0;
54 54
55 switch (type) 55 switch (type)
56 { 56 {
57 case GAIM_NOTIFY_MSG_ERROR: 57 case PURPLE_NOTIFY_MSG_ERROR:
58 sf |= GNT_TEXT_FLAG_BOLD; 58 sf |= GNT_TEXT_FLAG_BOLD;
59 case GAIM_NOTIFY_MSG_WARNING: 59 case PURPLE_NOTIFY_MSG_WARNING:
60 pf |= GNT_TEXT_FLAG_UNDERLINE; 60 pf |= GNT_TEXT_FLAG_UNDERLINE;
61 case GAIM_NOTIFY_MSG_INFO: 61 case PURPLE_NOTIFY_MSG_INFO:
62 pf |= GNT_TEXT_FLAG_BOLD; 62 pf |= GNT_TEXT_FLAG_BOLD;
63 break; 63 break;
64 } 64 }
65 65
66 window = gnt_box_new(FALSE, TRUE); 66 window = gnt_box_new(FALSE, TRUE);
86 gnt_widget_show(window); 86 gnt_widget_show(window);
87 return window; 87 return window;
88 } 88 }
89 89
90 /* handle is, in all/most occasions, a GntWidget * */ 90 /* handle is, in all/most occasions, a GntWidget * */
91 static void finch_close_notify(GaimNotifyType type, void *handle) 91 static void finch_close_notify(PurpleNotifyType type, void *handle)
92 { 92 {
93 GntWidget *widget = handle; 93 GntWidget *widget = handle;
94 94
95 if (!widget) 95 if (!widget)
96 return; 96 return;
97 97
98 while (widget->parent) 98 while (widget->parent)
99 widget = widget->parent; 99 widget = widget->parent;
100 100
101 if (type == GAIM_NOTIFY_SEARCHRESULTS) 101 if (type == PURPLE_NOTIFY_SEARCHRESULTS)
102 gaim_notify_searchresults_free(g_object_get_data(handle, "notify-results")); 102 purple_notify_searchresults_free(g_object_get_data(handle, "notify-results"));
103 #if 1 103 #if 1
104 /* This did not seem to be necessary */ 104 /* This did not seem to be necessary */
105 g_signal_handlers_disconnect_by_func(G_OBJECT(widget), 105 g_signal_handlers_disconnect_by_func(G_OBJECT(widget),
106 G_CALLBACK(notify_msg_window_destroy_cb), GINT_TO_POINTER(type)); 106 G_CALLBACK(notify_msg_window_destroy_cb), GINT_TO_POINTER(type));
107 #endif 107 #endif
111 static void *finch_notify_formatted(const char *title, const char *primary, 111 static void *finch_notify_formatted(const char *title, const char *primary,
112 const char *secondary, const char *text) 112 const char *secondary, const char *text)
113 { 113 {
114 /* XXX: For now, simply strip the html and use _notify_message. For future use, 114 /* XXX: For now, simply strip the html and use _notify_message. For future use,
115 * there should be some way of parsing the makrups from GntTextView */ 115 * there should be some way of parsing the makrups from GntTextView */
116 char *unformat = gaim_markup_strip_html(text); 116 char *unformat = purple_markup_strip_html(text);
117 char *t = g_strdup_printf("%s%s%s", 117 char *t = g_strdup_printf("%s%s%s",
118 secondary ? secondary : "", 118 secondary ? secondary : "",
119 secondary ? "\n" : "", 119 secondary ? "\n" : "",
120 unformat ? unformat : ""); 120 unformat ? unformat : "");
121 121
122 void *ret = finch_notify_message(GAIM_NOTIFY_FORMATTED, title, primary, t); 122 void *ret = finch_notify_message(PURPLE_NOTIFY_FORMATTED, title, primary, t);
123 123
124 g_free(t); 124 g_free(t);
125 g_free(unformat); 125 g_free(unformat);
126 126
127 return ret; 127 return ret;
166 g_signal_connect_swapped(G_OBJECT(button), "activate", G_CALLBACK(gnt_widget_destroy), box); 166 g_signal_connect_swapped(G_OBJECT(button), "activate", G_CALLBACK(gnt_widget_destroy), box);
167 g_signal_connect(G_OBJECT(box), "destroy", G_CALLBACK(reset_email_dialog), NULL); 167 g_signal_connect(G_OBJECT(box), "destroy", G_CALLBACK(reset_email_dialog), NULL);
168 } 168 }
169 169
170 static void * 170 static void *
171 finch_notify_emails(GaimConnection *gc, size_t count, gboolean detailed, 171 finch_notify_emails(PurpleConnection *gc, size_t count, gboolean detailed,
172 const char **subjects, const char **froms, const char **tos, 172 const char **subjects, const char **froms, const char **tos,
173 const char **urls) 173 const char **urls)
174 { 174 {
175 GaimAccount *account = gaim_connection_get_account(gc); 175 PurpleAccount *account = purple_connection_get_account(gc);
176 GString *message = g_string_new(NULL); 176 GString *message = g_string_new(NULL);
177 void *ret; 177 void *ret;
178 178
179 if (!detailed) 179 if (!detailed)
180 { 180 {
181 g_string_append_printf(message, 181 g_string_append_printf(message,
182 ngettext("%s (%s) has %d new message.", 182 ngettext("%s (%s) has %d new message.",
183 "%s (%s) has %d new messages.", 183 "%s (%s) has %d new messages.",
184 (int)count), 184 (int)count),
185 tos ? *tos : gaim_account_get_username(account), 185 tos ? *tos : purple_account_get_username(account),
186 gaim_account_get_protocol_name(account), (int)count); 186 purple_account_get_protocol_name(account), (int)count);
187 } 187 }
188 else 188 else
189 { 189 {
190 char *to; 190 char *to;
191 191
192 setup_email_dialog(); 192 setup_email_dialog();
193 193
194 to = g_strdup_printf("%s (%s)", tos ? *tos : gaim_account_get_username(account), 194 to = g_strdup_printf("%s (%s)", tos ? *tos : purple_account_get_username(account),
195 gaim_account_get_protocol_name(account)); 195 purple_account_get_protocol_name(account));
196 gnt_tree_add_row_after(GNT_TREE(emaildialog.tree), GINT_TO_POINTER(time(NULL)), 196 gnt_tree_add_row_after(GNT_TREE(emaildialog.tree), GINT_TO_POINTER(time(NULL)),
197 gnt_tree_create_row(GNT_TREE(emaildialog.tree), to, 197 gnt_tree_create_row(GNT_TREE(emaildialog.tree), to,
198 froms ? *froms : "[Unknown sender]", 198 froms ? *froms : "[Unknown sender]",
199 *subjects), 199 *subjects),
200 NULL, NULL); 200 NULL, NULL);
201 g_free(to); 201 g_free(to);
202 gnt_widget_show(emaildialog.window); 202 gnt_widget_show(emaildialog.window);
203 return NULL; 203 return NULL;
204 } 204 }
205 205
206 ret = finch_notify_message(GAIM_NOTIFY_EMAIL, _("New Mail"), _("You have mail!"), message->str); 206 ret = finch_notify_message(PURPLE_NOTIFY_EMAIL, _("New Mail"), _("You have mail!"), message->str);
207 g_string_free(message, TRUE); 207 g_string_free(message, TRUE);
208 return ret; 208 return ret;
209 } 209 }
210 210
211 static void * 211 static void *
212 finch_notify_email(GaimConnection *gc, const char *subject, const char *from, 212 finch_notify_email(PurpleConnection *gc, const char *subject, const char *from,
213 const char *to, const char *url) 213 const char *to, const char *url)
214 { 214 {
215 return finch_notify_emails(gc, 1, subject != NULL, 215 return finch_notify_emails(gc, 1, subject != NULL,
216 subject ? &subject : NULL, 216 subject ? &subject : NULL,
217 from ? &from : NULL, 217 from ? &from : NULL,
218 to ? &to : NULL, 218 to ? &to : NULL,
219 url ? &url : NULL); 219 url ? &url : NULL);
220 } 220 }
221 221
222 static void * 222 static void *
223 finch_notify_userinfo(GaimConnection *gc, const char *who, GaimNotifyUserInfo *user_info) 223 finch_notify_userinfo(PurpleConnection *gc, const char *who, PurpleNotifyUserInfo *user_info)
224 { 224 {
225 /* Xeroxed from gtknotify.c */ 225 /* Xeroxed from gtknotify.c */
226 char *primary; 226 char *primary;
227 char *info; 227 char *info;
228 void *ui_handle; 228 void *ui_handle;
229 229
230 primary = g_strdup_printf(_("Info for %s"), who); 230 primary = g_strdup_printf(_("Info for %s"), who);
231 info = gaim_notify_user_info_get_text_with_newline(user_info, "<BR>"); 231 info = purple_notify_user_info_get_text_with_newline(user_info, "<BR>");
232 ui_handle = finch_notify_formatted(_("Buddy Information"), primary, NULL, info); 232 ui_handle = finch_notify_formatted(_("Buddy Information"), primary, NULL, info);
233 g_free(info); 233 g_free(info);
234 g_free(primary); 234 g_free(primary);
235 return ui_handle; 235 return ui_handle;
236 } 236 }
237 237
238 static void 238 static void
239 notify_button_activated(GntWidget *widget, GaimNotifySearchButton *b) 239 notify_button_activated(GntWidget *widget, PurpleNotifySearchButton *b)
240 { 240 {
241 GList *list = NULL; 241 GList *list = NULL;
242 GaimAccount *account = g_object_get_data(G_OBJECT(widget), "notify-account"); 242 PurpleAccount *account = g_object_get_data(G_OBJECT(widget), "notify-account");
243 gpointer data = g_object_get_data(G_OBJECT(widget), "notify-data"); 243 gpointer data = g_object_get_data(G_OBJECT(widget), "notify-data");
244 244
245 list = gnt_tree_get_selection_text_list(GNT_TREE(widget)); 245 list = gnt_tree_get_selection_text_list(GNT_TREE(widget));
246 246
247 b->callback(gaim_account_get_connection(account), list, data); 247 b->callback(purple_account_get_connection(account), list, data);
248 g_list_foreach(list, (GFunc)g_free, NULL); 248 g_list_foreach(list, (GFunc)g_free, NULL);
249 g_list_free(list); 249 g_list_free(list);
250 } 250 }
251 251
252 static void 252 static void
253 finch_notify_sr_new_rows(GaimConnection *gc, 253 finch_notify_sr_new_rows(PurpleConnection *gc,
254 GaimNotifySearchResults *results, void *data) 254 PurpleNotifySearchResults *results, void *data)
255 { 255 {
256 GntTree *tree = GNT_TREE(data); 256 GntTree *tree = GNT_TREE(data);
257 GList *o; 257 GList *o;
258 258
259 /* XXX: Do I need to empty the tree here? */ 259 /* XXX: Do I need to empty the tree here? */
265 NULL, NULL); 265 NULL, NULL);
266 } 266 }
267 } 267 }
268 268
269 static void * 269 static void *
270 finch_notify_searchresults(GaimConnection *gc, const char *title, 270 finch_notify_searchresults(PurpleConnection *gc, const char *title,
271 const char *primary, const char *secondary, 271 const char *primary, const char *secondary,
272 GaimNotifySearchResults *results, gpointer data) 272 PurpleNotifySearchResults *results, gpointer data)
273 { 273 {
274 GntWidget *window, *tree, *box, *button; 274 GntWidget *window, *tree, *box, *button;
275 GList *iter; 275 GList *iter;
276 276
277 window = gnt_vbox_new(FALSE); 277 window = gnt_vbox_new(FALSE);
292 292
293 box = gnt_hbox_new(TRUE); 293 box = gnt_hbox_new(TRUE);
294 294
295 for (iter = results->buttons; iter; iter = iter->next) 295 for (iter = results->buttons; iter; iter = iter->next)
296 { 296 {
297 GaimNotifySearchButton *b = iter->data; 297 PurpleNotifySearchButton *b = iter->data;
298 const char *text; 298 const char *text;
299 299
300 switch (b->type) 300 switch (b->type)
301 { 301 {
302 case GAIM_NOTIFY_BUTTON_LABELED: 302 case PURPLE_NOTIFY_BUTTON_LABELED:
303 text = b->label; 303 text = b->label;
304 break; 304 break;
305 case GAIM_NOTIFY_BUTTON_CONTINUE: 305 case PURPLE_NOTIFY_BUTTON_CONTINUE:
306 text = _("Continue"); 306 text = _("Continue");
307 break; 307 break;
308 case GAIM_NOTIFY_BUTTON_ADD: 308 case PURPLE_NOTIFY_BUTTON_ADD:
309 text = _("Add"); 309 text = _("Add");
310 break; 310 break;
311 case GAIM_NOTIFY_BUTTON_INFO: 311 case PURPLE_NOTIFY_BUTTON_INFO:
312 text = _("Info"); 312 text = _("Info");
313 break; 313 break;
314 case GAIM_NOTIFY_BUTTON_IM: 314 case PURPLE_NOTIFY_BUTTON_IM:
315 text = _("IM"); 315 text = _("IM");
316 break; 316 break;
317 case GAIM_NOTIFY_BUTTON_JOIN: 317 case PURPLE_NOTIFY_BUTTON_JOIN:
318 text = _("Join"); 318 text = _("Join");
319 break; 319 break;
320 case GAIM_NOTIFY_BUTTON_INVITE: 320 case PURPLE_NOTIFY_BUTTON_INVITE:
321 text = _("Invite"); 321 text = _("Invite");
322 break; 322 break;
323 default: 323 default:
324 text = _("(none)"); 324 text = _("(none)");
325 } 325 }
326 326
327 button = gnt_button_new(text); 327 button = gnt_button_new(text);
328 g_object_set_data(G_OBJECT(button), "notify-account", gaim_connection_get_account(gc)); 328 g_object_set_data(G_OBJECT(button), "notify-account", purple_connection_get_account(gc));
329 g_object_set_data(G_OBJECT(button), "notify-data", data); 329 g_object_set_data(G_OBJECT(button), "notify-data", data);
330 g_signal_connect_swapped(G_OBJECT(button), "activate", 330 g_signal_connect_swapped(G_OBJECT(button), "activate",
331 G_CALLBACK(notify_button_activated), b); 331 G_CALLBACK(notify_button_activated), b);
332 332
333 gnt_box_add_widget(GNT_BOX(box), button); 333 gnt_box_add_widget(GNT_BOX(box), button);
341 g_object_set_data(G_OBJECT(window), "notify-results", results); 341 g_object_set_data(G_OBJECT(window), "notify-results", results);
342 342
343 return tree; 343 return tree;
344 } 344 }
345 345
346 static GaimNotifyUiOps ops = 346 static PurpleNotifyUiOps ops =
347 { 347 {
348 .notify_message = finch_notify_message, 348 .notify_message = finch_notify_message,
349 .close_notify = finch_close_notify, /* The rest of the notify-uiops return a GntWidget. 349 .close_notify = finch_close_notify, /* The rest of the notify-uiops return a GntWidget.
350 These widgets should be destroyed from here. */ 350 These widgets should be destroyed from here. */
351 .notify_formatted = finch_notify_formatted, 351 .notify_formatted = finch_notify_formatted,
356 .notify_searchresults = finch_notify_searchresults, 356 .notify_searchresults = finch_notify_searchresults,
357 .notify_searchresults_new_rows = finch_notify_sr_new_rows, 357 .notify_searchresults_new_rows = finch_notify_sr_new_rows,
358 .notify_uri = NULL /* This is of low-priority to me */ 358 .notify_uri = NULL /* This is of low-priority to me */
359 }; 359 };
360 360
361 GaimNotifyUiOps *finch_notify_get_ui_ops() 361 PurpleNotifyUiOps *finch_notify_get_ui_ops()
362 { 362 {
363 return &ops; 363 return &ops;
364 } 364 }
365 365
366 void finch_notify_init() 366 void finch_notify_init()