comparison pidgin/plugins/gevolution/gevolution.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 535f002e7b0f
children 89bbced1589f
comparison
equal deleted inserted replaced
15822:84b0f9b23ede 15823:32c366eeeb99
1 /* 1 /*
2 * Evolution integration plugin for Gaim 2 * Evolution integration plugin for Purple
3 * 3 *
4 * Copyright (C) 2003 Christian Hammond. 4 * Copyright (C) 2003 Christian Hammond.
5 * 5 *
6 * This program is free software; you can redistribute it and/or 6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as 7 * modify it under the terms of the GNU General Public License as
56 COLUMN_SCREENNAME, 56 COLUMN_SCREENNAME,
57 COLUMN_DATA, 57 COLUMN_DATA,
58 NUM_COLUMNS 58 NUM_COLUMNS
59 }; 59 };
60 60
61 static GaimBlistUiOps *backup_blist_ui_ops = NULL; 61 static PurpleBlistUiOps *backup_blist_ui_ops = NULL;
62 static GaimBlistUiOps *blist_ui_ops = NULL; 62 static PurpleBlistUiOps *blist_ui_ops = NULL;
63 static EBook *book = NULL; 63 static EBook *book = NULL;
64 static gulong timer = 0; 64 static gulong timer = 0;
65 static gulong book_view_tag = 0; 65 static gulong book_view_tag = 0;
66 static EBookView *book_view = NULL; 66 static EBookView *book_view = NULL;
67 67
73 GList *l, *l2; 73 GList *l, *l2;
74 74
75 if (ims == NULL) 75 if (ims == NULL)
76 return; 76 return;
77 77
78 for (l = gaim_connections_get_all(); l != NULL; l = l->next) 78 for (l = purple_connections_get_all(); l != NULL; l = l->next)
79 { 79 {
80 GaimConnection *gc = (GaimConnection *)l->data; 80 PurpleConnection *gc = (PurpleConnection *)l->data;
81 GaimAccount *account = gaim_connection_get_account(gc); 81 PurpleAccount *account = purple_connection_get_account(gc);
82 char *me; 82 char *me;
83 83
84 if (strcmp(gaim_account_get_protocol_id(account), prpl_id)) 84 if (strcmp(purple_account_get_protocol_id(account), prpl_id))
85 continue; 85 continue;
86 86
87 if (!gaim_account_get_bool(account, "gevo-autoadd", FALSE)) 87 if (!purple_account_get_bool(account, "gevo-autoadd", FALSE))
88 continue; 88 continue;
89 89
90 me = g_strdup(gaim_normalize(account, gaim_account_get_username(account))); 90 me = g_strdup(purple_normalize(account, purple_account_get_username(account)));
91 for (l2 = ims; l2 != NULL; l2 = l2->next) 91 for (l2 = ims; l2 != NULL; l2 = l2->next)
92 { 92 {
93 if (gaim_find_buddy(account, l2->data) != NULL || 93 if (purple_find_buddy(account, l2->data) != NULL ||
94 !strcmp(me, gaim_normalize(account, l2->data))) 94 !strcmp(me, purple_normalize(account, l2->data)))
95 continue; 95 continue;
96 96
97 gevo_add_buddy(account, _("Buddies"), l2->data, name); 97 gevo_add_buddy(account, _("Buddies"), l2->data, name);
98 } 98 }
99 g_free(me); 99 g_free(me);
121 static void 121 static void
122 contacts_changed_cb(EBookView *book_view, const GList *contacts) 122 contacts_changed_cb(EBookView *book_view, const GList *contacts)
123 { 123 {
124 const GList *l; 124 const GList *l;
125 125
126 if (gaim_connections_get_all() == NULL) 126 if (purple_connections_get_all() == NULL)
127 return; 127 return;
128 128
129 for (l = contacts; l != NULL; l = l->next) 129 for (l = contacts; l != NULL; l = l->next)
130 { 130 {
131 EContact *contact = (EContact *)l->data; 131 EContact *contact = (EContact *)l->data;
133 update_buddies_from_contact(contact); 133 update_buddies_from_contact(contact);
134 } 134 }
135 } 135 }
136 136
137 static void 137 static void
138 request_add_buddy(GaimAccount *account, const char *username, 138 request_add_buddy(PurpleAccount *account, const char *username,
139 const char *group, const char *alias) 139 const char *group, const char *alias)
140 { 140 {
141 if (book == NULL) 141 if (book == NULL)
142 { 142 {
143 backup_blist_ui_ops->request_add_buddy(account, username, group, 143 backup_blist_ui_ops->request_add_buddy(account, username, group,
155 { 155 {
156 book_view_tag = 0; 156 book_view_tag = 0;
157 157
158 if (status != E_BOOK_ERROR_OK) 158 if (status != E_BOOK_ERROR_OK)
159 { 159 {
160 gaim_debug_error("evolution", "Unable to retrieve book view! :(\n"); 160 purple_debug_error("evolution", "Unable to retrieve book view! :(\n");
161 161
162 return; 162 return;
163 } 163 }
164 164
165 book_view = view; 165 book_view = view;
174 174
175 e_book_view_start(view); 175 e_book_view_start(view);
176 } 176 }
177 177
178 static void 178 static void
179 signed_on_cb(GaimConnection *gc) 179 signed_on_cb(PurpleConnection *gc)
180 { 180 {
181 EBookQuery *query; 181 EBookQuery *query;
182 gboolean status; 182 gboolean status;
183 GList *contacts; 183 GList *contacts;
184 GList *l; 184 GList *l;
206 206
207 g_list_free(contacts); 207 g_list_free(contacts);
208 } 208 }
209 209
210 static void 210 static void
211 menu_item_activate_cb(GaimBlistNode *node, gpointer user_data) 211 menu_item_activate_cb(PurpleBlistNode *node, gpointer user_data)
212 { 212 {
213 GaimBuddy *buddy = (GaimBuddy *)node; 213 PurpleBuddy *buddy = (PurpleBuddy *)node;
214 gevo_associate_buddy_dialog_new(buddy); 214 gevo_associate_buddy_dialog_new(buddy);
215 } 215 }
216 216
217 static void 217 static void
218 menu_item_send_mail_activate_cb(GaimBlistNode *node, gpointer user_data) 218 menu_item_send_mail_activate_cb(PurpleBlistNode *node, gpointer user_data)
219 { 219 {
220 GaimBuddy *buddy = (GaimBuddy *)node; 220 PurpleBuddy *buddy = (PurpleBuddy *)node;
221 char *mail = NULL; 221 char *mail = NULL;
222 222
223 mail = gevo_get_email_for_buddy(buddy); 223 mail = gevo_get_email_for_buddy(buddy);
224 224
225 if (mail != NULL) 225 if (mail != NULL)
234 g_spawn_command_line_async(command_line, NULL); 234 g_spawn_command_line_async(command_line, NULL);
235 g_free(command_line); 235 g_free(command_line);
236 } 236 }
237 else 237 else
238 { 238 {
239 gaim_notify_error(NULL, NULL, _("Unable to send e-mail"), 239 purple_notify_error(NULL, NULL, _("Unable to send e-mail"),
240 _("The evolution executable was not found in the PATH.")); 240 _("The evolution executable was not found in the PATH."));
241 } 241 }
242 } 242 }
243 else 243 else
244 { 244 {
245 gaim_notify_error(NULL, NULL, _("Unable to send e-mail"), 245 purple_notify_error(NULL, NULL, _("Unable to send e-mail"),
246 _("An e-mail address was not found for this buddy.")); 246 _("An e-mail address was not found for this buddy."));
247 } 247 }
248 } 248 }
249 249
250 static void 250 static void
251 blist_node_extended_menu_cb(GaimBlistNode *node, GList **menu) 251 blist_node_extended_menu_cb(PurpleBlistNode *node, GList **menu)
252 { 252 {
253 GaimMenuAction *act; 253 PurpleMenuAction *act;
254 GaimBuddy *buddy; 254 PurpleBuddy *buddy;
255 GaimAccount *account; 255 PurpleAccount *account;
256 EContact *contact; 256 EContact *contact;
257 char *mail; 257 char *mail;
258 258
259 if (!GAIM_BLIST_NODE_IS_BUDDY(node)) 259 if (!PURPLE_BLIST_NODE_IS_BUDDY(node))
260 return; 260 return;
261 261
262 buddy = (GaimBuddy *)node; 262 buddy = (PurpleBuddy *)node;
263 account = gaim_buddy_get_account(buddy); 263 account = purple_buddy_get_account(buddy);
264 264
265 if (!gevo_prpl_is_supported(account, buddy)) 265 if (!gevo_prpl_is_supported(account, buddy))
266 return; 266 return;
267 267
268 contact = gevo_search_buddy_in_contacts(buddy, NULL); 268 contact = gevo_search_buddy_in_contacts(buddy, NULL);
269 269
270 if (contact == NULL) 270 if (contact == NULL)
271 { 271 {
272 act = gaim_menu_action_new(_("Add to Address Book"), 272 act = purple_menu_action_new(_("Add to Address Book"),
273 GAIM_CALLBACK(menu_item_activate_cb), 273 PURPLE_CALLBACK(menu_item_activate_cb),
274 NULL, NULL); 274 NULL, NULL);
275 *menu = g_list_append(*menu, act); 275 *menu = g_list_append(*menu, act);
276 } 276 }
277 else 277 else
278 g_object_unref(contact); 278 g_object_unref(contact);
279 279
280 mail = gevo_get_email_for_buddy(buddy); 280 mail = gevo_get_email_for_buddy(buddy);
281 281
282 if (mail != NULL) 282 if (mail != NULL)
283 { 283 {
284 act = gaim_menu_action_new(_("Send E-Mail"), 284 act = purple_menu_action_new(_("Send E-Mail"),
285 GAIM_CALLBACK(menu_item_send_mail_activate_cb), NULL, NULL); 285 PURPLE_CALLBACK(menu_item_send_mail_activate_cb), NULL, NULL);
286 *menu = g_list_append(*menu, act); 286 *menu = g_list_append(*menu, act);
287 g_free(mail); 287 g_free(mail);
288 } 288 }
289 } 289 }
290 290
291 /* TODO: Something in here leaks 1 reference to a bonobo object! */ 291 /* TODO: Something in here leaks 1 reference to a bonobo object! */
292 static gboolean 292 static gboolean
293 load_timeout(gpointer data) 293 load_timeout(gpointer data)
294 { 294 {
295 GaimPlugin *plugin = (GaimPlugin *)data; 295 PurplePlugin *plugin = (PurplePlugin *)data;
296 EBookQuery *query; 296 EBookQuery *query;
297 297
298 timer = 0; 298 timer = 0;
299 299
300 /* Maybe this is it? */ 300 /* Maybe this is it? */
307 book_view_tag = e_book_async_get_book_view(book, query, NULL, -1, 307 book_view_tag = e_book_async_get_book_view(book, query, NULL, -1,
308 got_book_view_cb, NULL); 308 got_book_view_cb, NULL);
309 309
310 e_book_query_unref(query); 310 e_book_query_unref(query);
311 311
312 gaim_signal_connect(gaim_blist_get_handle(), "blist-node-extended-menu", 312 purple_signal_connect(purple_blist_get_handle(), "blist-node-extended-menu",
313 plugin, GAIM_CALLBACK(blist_node_extended_menu_cb), NULL); 313 plugin, PURPLE_CALLBACK(blist_node_extended_menu_cb), NULL);
314 314
315 return FALSE; 315 return FALSE;
316 } 316 }
317 317
318 static gboolean 318 static gboolean
319 plugin_load(GaimPlugin *plugin) 319 plugin_load(PurplePlugin *plugin)
320 { 320 {
321 bonobo_activate(); 321 bonobo_activate();
322 322
323 backup_blist_ui_ops = gaim_blist_get_ui_ops(); 323 backup_blist_ui_ops = purple_blist_get_ui_ops();
324 324
325 blist_ui_ops = g_memdup(backup_blist_ui_ops, sizeof(GaimBlistUiOps)); 325 blist_ui_ops = g_memdup(backup_blist_ui_ops, sizeof(PurpleBlistUiOps));
326 blist_ui_ops->request_add_buddy = request_add_buddy; 326 blist_ui_ops->request_add_buddy = request_add_buddy;
327 327
328 gaim_blist_set_ui_ops(blist_ui_ops); 328 purple_blist_set_ui_ops(blist_ui_ops);
329 329
330 gaim_signal_connect(gaim_connections_get_handle(), "signed-on", 330 purple_signal_connect(purple_connections_get_handle(), "signed-on",
331 plugin, GAIM_CALLBACK(signed_on_cb), NULL); 331 plugin, PURPLE_CALLBACK(signed_on_cb), NULL);
332 332
333 timer = g_timeout_add(1, load_timeout, plugin); 333 timer = g_timeout_add(1, load_timeout, plugin);
334 334
335 return TRUE; 335 return TRUE;
336 } 336 }
337 337
338 static gboolean 338 static gboolean
339 plugin_unload(GaimPlugin *plugin) 339 plugin_unload(PurplePlugin *plugin)
340 { 340 {
341 gaim_blist_set_ui_ops(backup_blist_ui_ops); 341 purple_blist_set_ui_ops(backup_blist_ui_ops);
342 342
343 g_free(blist_ui_ops); 343 g_free(blist_ui_ops);
344 344
345 backup_blist_ui_ops = NULL; 345 backup_blist_ui_ops = NULL;
346 blist_ui_ops = NULL; 346 blist_ui_ops = NULL;
360 360
361 return TRUE; 361 return TRUE;
362 } 362 }
363 363
364 static void 364 static void
365 plugin_destroy(GaimPlugin *plugin) 365 plugin_destroy(PurplePlugin *plugin)
366 { 366 {
367 bonobo_debug_shutdown(); 367 bonobo_debug_shutdown();
368 } 368 }
369 369
370 static void 370 static void
371 autoadd_toggled_cb(GtkCellRendererToggle *renderer, gchar *path_str, 371 autoadd_toggled_cb(GtkCellRendererToggle *renderer, gchar *path_str,
372 gpointer data) 372 gpointer data)
373 { 373 {
374 GaimAccount *account; 374 PurpleAccount *account;
375 GtkTreeModel *model = (GtkTreeModel *)data; 375 GtkTreeModel *model = (GtkTreeModel *)data;
376 GtkTreeIter iter; 376 GtkTreeIter iter;
377 gboolean autoadd; 377 gboolean autoadd;
378 378
379 gtk_tree_model_get_iter_from_string(model, &iter, path_str); 379 gtk_tree_model_get_iter_from_string(model, &iter, path_str);
380 gtk_tree_model_get(model, &iter, 380 gtk_tree_model_get(model, &iter,
381 COLUMN_DATA, &account, 381 COLUMN_DATA, &account,
382 COLUMN_AUTOADD, &autoadd, 382 COLUMN_AUTOADD, &autoadd,
383 -1); 383 -1);
384 384
385 gaim_account_set_bool(account, "gevo-autoadd", !autoadd); 385 purple_account_set_bool(account, "gevo-autoadd", !autoadd);
386 386
387 gtk_list_store_set(GTK_LIST_STORE(model), &iter, 387 gtk_list_store_set(GTK_LIST_STORE(model), &iter,
388 COLUMN_AUTOADD, !autoadd, 388 COLUMN_AUTOADD, !autoadd,
389 -1); 389 -1);
390 } 390 }
391 391
392 static GtkWidget * 392 static GtkWidget *
393 get_config_frame(GaimPlugin *plugin) 393 get_config_frame(PurplePlugin *plugin)
394 { 394 {
395 GtkWidget *ret; 395 GtkWidget *ret;
396 GtkWidget *vbox; 396 GtkWidget *vbox;
397 GtkWidget *label; 397 GtkWidget *label;
398 GtkWidget *sw; 398 GtkWidget *sw;
466 gtk_tree_view_column_add_attribute(column, renderer, 466 gtk_tree_view_column_add_attribute(column, renderer,
467 "text", COLUMN_SCREENNAME); 467 "text", COLUMN_SCREENNAME);
468 468
469 469
470 /* Populate */ 470 /* Populate */
471 for (l = gaim_accounts_get_all(); l != NULL; l = l->next) 471 for (l = purple_accounts_get_all(); l != NULL; l = l->next)
472 { 472 {
473 GaimAccount *account = (GaimAccount *)l->data; 473 PurpleAccount *account = (PurpleAccount *)l->data;
474 GtkTreeIter iter; 474 GtkTreeIter iter;
475 475
476 gaim_debug_info("evolution", "Adding account\n"); 476 purple_debug_info("evolution", "Adding account\n");
477 477
478 gtk_list_store_append(model, &iter); 478 gtk_list_store_append(model, &iter);
479 479
480 pixbuf = pidgin_create_prpl_icon(account, 0.5); 480 pixbuf = pidgin_create_prpl_icon(account, 0.5);
481 if ((pixbuf != NULL) && (!gaim_account_is_connected(account))) 481 if ((pixbuf != NULL) && (!purple_account_is_connected(account)))
482 gdk_pixbuf_saturate_and_pixelate(pixbuf, pixbuf, 0.0, FALSE); 482 gdk_pixbuf_saturate_and_pixelate(pixbuf, pixbuf, 0.0, FALSE);
483 483
484 gtk_list_store_set(model, &iter, 484 gtk_list_store_set(model, &iter,
485 COLUMN_AUTOADD, 485 COLUMN_AUTOADD,
486 gaim_account_get_bool(account, "gevo-autoadd", 486 purple_account_get_bool(account, "gevo-autoadd",
487 FALSE), 487 FALSE),
488 COLUMN_ICON, pixbuf, 488 COLUMN_ICON, pixbuf,
489 COLUMN_SCREENNAME, 489 COLUMN_SCREENNAME,
490 gaim_account_get_username(account), 490 purple_account_get_username(account),
491 COLUMN_DATA, account, 491 COLUMN_DATA, account,
492 -1); 492 -1);
493 493
494 if (pixbuf != NULL) 494 if (pixbuf != NULL)
495 g_object_unref(G_OBJECT(pixbuf)); 495 g_object_unref(G_OBJECT(pixbuf));
504 { 504 {
505 get_config_frame, /**< get_config_frame */ 505 get_config_frame, /**< get_config_frame */
506 0 /**< page_num */ 506 0 /**< page_num */
507 }; 507 };
508 508
509 static GaimPluginInfo info = 509 static PurplePluginInfo info =
510 { 510 {
511 GAIM_PLUGIN_MAGIC, 511 PURPLE_PLUGIN_MAGIC,
512 GAIM_MAJOR_VERSION, 512 PURPLE_MAJOR_VERSION,
513 GAIM_MINOR_VERSION, 513 PURPLE_MINOR_VERSION,
514 GAIM_PLUGIN_STANDARD, /**< type */ 514 PURPLE_PLUGIN_STANDARD, /**< type */
515 PIDGIN_PLUGIN_TYPE, /**< ui_requirement */ 515 PIDGIN_PLUGIN_TYPE, /**< ui_requirement */
516 0, /**< flags */ 516 0, /**< flags */
517 NULL, /**< dependencies */ 517 NULL, /**< dependencies */
518 GAIM_PRIORITY_DEFAULT, /**< priority */ 518 PURPLE_PRIORITY_DEFAULT, /**< priority */
519 519
520 GEVOLUTION_PLUGIN_ID, /**< id */ 520 GEVOLUTION_PLUGIN_ID, /**< id */
521 N_("Evolution Integration"), /**< name */ 521 N_("Evolution Integration"), /**< name */
522 VERSION, /**< version */ 522 VERSION, /**< version */
523 /** summary */ 523 /** summary */
524 N_("Provides integration with Evolution."), 524 N_("Provides integration with Evolution."),
525 /** description */ 525 /** description */
526 N_("Provides integration with Evolution."), 526 N_("Provides integration with Evolution."),
527 "Christian Hammond <chipx86@chipx86.com>", /**< author */ 527 "Christian Hammond <chipx86@chipx86.com>", /**< author */
528 GAIM_WEBSITE, /**< homepage */ 528 PURPLE_WEBSITE, /**< homepage */
529 529
530 plugin_load, /**< load */ 530 plugin_load, /**< load */
531 plugin_unload, /**< unload */ 531 plugin_unload, /**< unload */
532 plugin_destroy, /**< destroy */ 532 plugin_destroy, /**< destroy */
533 533
536 NULL, 536 NULL,
537 NULL 537 NULL
538 }; 538 };
539 539
540 static void 540 static void
541 init_plugin(GaimPlugin *plugin) 541 init_plugin(PurplePlugin *plugin)
542 { 542 {
543 /* TODO: Change to core-remote when possible. */ 543 /* TODO: Change to core-remote when possible. */
544 /* info.dependencies = g_list_append(info.dependencies, "gtk-remote"); */ 544 /* info.dependencies = g_list_append(info.dependencies, "gtk-remote"); */
545 545
546 /* 546 /*
547 * I'm going to rant a little bit here... 547 * I'm going to rant a little bit here...
548 * 548 *
549 * For some reason, when we init bonobo from inside a plugin, it will 549 * For some reason, when we init bonobo from inside a plugin, it will
550 * segfault when destroyed. The backtraces are within gmodule somewhere. 550 * segfault when destroyed. The backtraces are within gmodule somewhere.
551 * There's not much I can do, and I'm not sure where the bug lies. 551 * There's not much I can do, and I'm not sure where the bug lies.
552 * However, plugins are only destroyed when Gaim is shutting down. After 552 * However, plugins are only destroyed when Purple is shutting down. After
553 * destroying the plugins, gaim ends, and anything else is of course 553 * destroying the plugins, purple ends, and anything else is of course
554 * freed. That includes this, if we make the module resident, which 554 * freed. That includes this, if we make the module resident, which
555 * prevents us from being able to actually unload it. 555 * prevents us from being able to actually unload it.
556 * 556 *
557 * So, in conclusion, this is an evil hack, but it doesn't harm anything 557 * So, in conclusion, this is an evil hack, but it doesn't harm anything
558 * and it works. 558 * and it works.
560 g_module_make_resident(plugin->handle); 560 g_module_make_resident(plugin->handle);
561 561
562 if (!bonobo_init_full(NULL, NULL, bonobo_activation_orb_get(), 562 if (!bonobo_init_full(NULL, NULL, bonobo_activation_orb_get(),
563 CORBA_OBJECT_NIL, CORBA_OBJECT_NIL)) 563 CORBA_OBJECT_NIL, CORBA_OBJECT_NIL))
564 { 564 {
565 gaim_debug_error("evolution", "Unable to initialize bonobo.\n"); 565 purple_debug_error("evolution", "Unable to initialize bonobo.\n");
566 } 566 }
567 } 567 }
568 568
569 GAIM_INIT_PLUGIN(gevolution, init_plugin, info) 569 PURPLE_INIT_PLUGIN(gevolution, init_plugin, info)