Wed, 27 Jun 2007 19:31:39 +0000
merge of '4af4ad27f3c03e26c9e862f5b8052197deea9270'
and '334e85ce3bdf0ee762dd602084a41689f8d5ea64'
| 8089 | 1 | /* |
| 15884 | 2 | * Evolution integration plugin for Purple |
| 8089 | 3 | * |
| 4 | * Copyright (C) 2003 Christian Hammond. | |
| 5 | * | |
| 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 | |
| 8 | * published by the Free Software Foundation; either version 2 of the | |
| 9 | * License, or (at your option) any later version. | |
| 10 | * | |
| 11 | * This program is distributed in the hope that it will be useful, but | |
| 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 14 | * General Public License for more details. | |
| 15 | * | |
| 16 | * You should have received a copy of the GNU General Public License | |
| 17 | * along with this program; if not, write to the Free Software | |
| 18 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | |
| 19 | * 02111-1307, USA. | |
| 20 | */ | |
| 21 | #include "internal.h" | |
| 15577 | 22 | #include "pidgin.h" |
| 8089 | 23 | |
| 24 | #include "connection.h" | |
| 25 | #include "debug.h" | |
| 26 | #include "prefs.h" | |
| 11117 | 27 | #include "notify.h" |
| 8089 | 28 | #include "signals.h" |
|
10831
fbe1ff83d5a9
[gaim-migrate @ 12499]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10662
diff
changeset
|
29 | #include "util.h" |
| 9954 | 30 | #include "version.h" |
| 8089 | 31 | |
|
9821
d02520c59822
[gaim-migrate @ 10692]
Mark Doliner <markdoliner@pidgin.im>
parents:
9354
diff
changeset
|
32 | #include "gtkblist.h" |
| 8089 | 33 | #include "gtkconv.h" |
| 34 | #include "gtkplugin.h" | |
| 35 | #include "gtkutils.h" | |
| 36 | ||
| 37 | #include "gevolution.h" | |
| 38 | ||
| 39 | #include <libedata-book/Evolution-DataServer-Addressbook.h> | |
| 40 | ||
| 41 | #include <libedata-book/e-data-book-factory.h> | |
| 42 | #include <bonobo/bonobo-main.h> | |
| 43 | ||
| 11117 | 44 | #include <glib.h> |
| 45 | ||
| 8089 | 46 | #define GEVOLUTION_PLUGIN_ID "gtk-x11-gevolution" |
| 47 | ||
| 48 | #define E_DATA_BOOK_FACTORY_OAF_ID \ | |
| 49 | "OAFIID:GNOME_Evolution_DataServer_BookFactory" | |
| 50 | ||
| 51 | enum | |
| 52 | { | |
| 53 | COLUMN_AUTOADD, | |
| 54 | COLUMN_ICON, | |
| 55 | COLUMN_SCREENNAME, | |
| 56 | COLUMN_DATA, | |
| 57 | NUM_COLUMNS | |
| 58 | }; | |
| 59 | ||
| 15884 | 60 | static PurpleBlistUiOps *backup_blist_ui_ops = NULL; |
| 61 | static PurpleBlistUiOps *blist_ui_ops = NULL; | |
| 8089 | 62 | static EBook *book = NULL; |
| 63 | static gulong timer = 0; | |
| 64 | static gulong book_view_tag = 0; | |
| 65 | static EBookView *book_view = NULL; | |
| 66 | ||
| 67 | static void | |
| 68 | update_ims_from_contact(EContact *contact, const char *name, | |
| 69 | const char *prpl_id, EContactField field) | |
| 70 | { | |
| 71 | GList *ims = e_contact_get(contact, field); | |
|
18122
9bf9970c1b6a
disapproval of revision '2d8ea56b90971e7851442d96b7d74ecb4f052126'
Richard Laager <rlaager@pidgin.im>
parents:
18121
diff
changeset
|
72 | GList *l, *l2; |
| 8089 | 73 | |
| 74 | if (ims == NULL) | |
| 75 | return; | |
| 76 | ||
| 15884 | 77 | for (l = purple_connections_get_all(); l != NULL; l = l->next) |
| 8089 | 78 | { |
| 15884 | 79 | PurpleConnection *gc = (PurpleConnection *)l->data; |
| 80 | PurpleAccount *account = purple_connection_get_account(gc); | |
|
14848
0cbce2b9b92d
[gaim-migrate @ 17550]
Henning Norén <henning.noren@gmail.com>
parents:
14253
diff
changeset
|
81 | char *me; |
| 8089 | 82 | |
| 15884 | 83 | if (strcmp(purple_account_get_protocol_id(account), prpl_id)) |
| 8089 | 84 | continue; |
| 85 | ||
| 15884 | 86 | if (!purple_account_get_bool(account, "gevo-autoadd", FALSE)) |
| 8089 | 87 | continue; |
| 88 | ||
| 15884 | 89 | me = g_strdup(purple_normalize(account, purple_account_get_username(account))); |
| 8089 | 90 | for (l2 = ims; l2 != NULL; l2 = l2->next) |
| 91 | { | |
| 15884 | 92 | if (purple_find_buddy(account, l2->data) != NULL || |
| 93 | !strcmp(me, purple_normalize(account, l2->data))) | |
| 8089 | 94 | continue; |
| 95 | ||
| 96 | gevo_add_buddy(account, _("Buddies"), l2->data, name); | |
| 97 | } | |
|
10831
fbe1ff83d5a9
[gaim-migrate @ 12499]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10662
diff
changeset
|
98 | g_free(me); |
| 8089 | 99 | } |
| 100 | ||
| 101 | g_list_foreach(ims, (GFunc)g_free, NULL); | |
| 102 | g_list_free(ims); | |
| 103 | } | |
| 104 | ||
| 105 | static void | |
| 106 | update_buddies_from_contact(EContact *contact) | |
| 107 | { | |
| 108 | const char *name; | |
| 109 | ||
| 110 | name = e_contact_get_const(contact, E_CONTACT_FULL_NAME); | |
| 111 | ||
| 112 | update_ims_from_contact(contact, name, "prpl-oscar", E_CONTACT_IM_AIM); | |
| 113 | update_ims_from_contact(contact, name, "prpl-jabber", E_CONTACT_IM_JABBER); | |
| 114 | update_ims_from_contact(contact, name, "prpl-yahoo", E_CONTACT_IM_YAHOO); | |
| 115 | update_ims_from_contact(contact, name, "prpl-msn", E_CONTACT_IM_MSN); | |
| 116 | update_ims_from_contact(contact, name, "prpl-oscar", E_CONTACT_IM_ICQ); | |
|
11054
ba2440c5ee48
[gaim-migrate @ 12992]
Stanislav Brabec <sbrabec@suse.cz>
parents:
11033
diff
changeset
|
117 | update_ims_from_contact(contact, name, "prpl-novell", E_CONTACT_IM_GROUPWISE); |
| 8089 | 118 | } |
| 119 | ||
| 120 | static void | |
|
18190
bcf28ef7e8ff
Re-fix the DBus list handling code by killing const GList* / const GSList*
Richard Laager <rlaager@pidgin.im>
parents:
18186
diff
changeset
|
121 | contacts_changed_cb(EBookView *book_view, GList *contacts) |
| 8089 | 122 | { |
|
18190
bcf28ef7e8ff
Re-fix the DBus list handling code by killing const GList* / const GSList*
Richard Laager <rlaager@pidgin.im>
parents:
18186
diff
changeset
|
123 | GList *l; |
| 8089 | 124 | |
| 15884 | 125 | if (purple_connections_get_all() == NULL) |
| 8089 | 126 | return; |
| 127 | ||
| 128 | for (l = contacts; l != NULL; l = l->next) | |
| 129 | { | |
| 130 | EContact *contact = (EContact *)l->data; | |
| 131 | ||
| 132 | update_buddies_from_contact(contact); | |
| 133 | } | |
| 134 | } | |
| 135 | ||
| 136 | static void | |
| 15884 | 137 | request_add_buddy(PurpleAccount *account, const char *username, |
| 8089 | 138 | const char *group, const char *alias) |
| 139 | { | |
| 140 | if (book == NULL) | |
| 141 | { | |
| 142 | backup_blist_ui_ops->request_add_buddy(account, username, group, | |
| 143 | alias); | |
| 144 | } | |
| 145 | else | |
| 146 | { | |
| 147 | gevo_add_buddy_dialog_show(account, username, group, alias); | |
| 148 | } | |
| 149 | } | |
| 150 | ||
| 151 | static void | |
| 152 | got_book_view_cb(EBook *book, EBookStatus status, EBookView *view, | |
| 153 | gpointer user_data) | |
| 154 | { | |
| 155 | book_view_tag = 0; | |
| 156 | ||
| 157 | if (status != E_BOOK_ERROR_OK) | |
| 158 | { | |
| 15884 | 159 | purple_debug_error("evolution", "Unable to retrieve book view! :(\n"); |
| 8089 | 160 | |
| 161 | return; | |
| 162 | } | |
| 163 | ||
| 164 | book_view = view; | |
| 165 | ||
| 166 | g_object_ref(book_view); | |
| 167 | ||
| 168 | g_signal_connect(G_OBJECT(book_view), "contacts_changed", | |
| 169 | G_CALLBACK(contacts_changed_cb), book); | |
| 170 | ||
| 171 | g_signal_connect(G_OBJECT(book_view), "contacts_added", | |
| 172 | G_CALLBACK(contacts_changed_cb), book); | |
| 173 | ||
| 174 | e_book_view_start(view); | |
| 175 | } | |
| 176 | ||
| 177 | static void | |
| 15884 | 178 | signed_on_cb(PurpleConnection *gc) |
| 8089 | 179 | { |
| 180 | EBookQuery *query; | |
| 181 | gboolean status; | |
| 182 | GList *contacts; | |
| 183 | GList *l; | |
| 184 | ||
| 185 | if (book == NULL) | |
| 186 | return; | |
| 187 | ||
| 188 | query = e_book_query_any_field_contains(""); | |
| 189 | ||
| 190 | status = e_book_get_contacts(book, query, &contacts, NULL); | |
| 191 | ||
| 192 | e_book_query_unref(query); | |
| 193 | ||
| 194 | if (!status) | |
| 195 | return; | |
| 196 | ||
| 197 | for (l = contacts; l != NULL; l = l->next) | |
| 198 | { | |
| 199 | EContact *contact = E_CONTACT(l->data); | |
| 200 | ||
| 201 | update_buddies_from_contact(contact); | |
| 202 | ||
| 203 | g_object_unref(contact); | |
| 204 | } | |
| 205 | ||
| 206 | g_list_free(contacts); | |
| 207 | } | |
| 208 | ||
| 209 | static void | |
| 15884 | 210 | menu_item_activate_cb(PurpleBlistNode *node, gpointer user_data) |
| 8089 | 211 | { |
| 15884 | 212 | PurpleBuddy *buddy = (PurpleBuddy *)node; |
| 8089 | 213 | gevo_associate_buddy_dialog_new(buddy); |
| 214 | } | |
| 215 | ||
| 216 | static void | |
| 15884 | 217 | menu_item_send_mail_activate_cb(PurpleBlistNode *node, gpointer user_data) |
| 11117 | 218 | { |
| 15884 | 219 | PurpleBuddy *buddy = (PurpleBuddy *)node; |
| 11117 | 220 | char *mail = NULL; |
| 221 | ||
|
15026
be82a893c65e
[gaim-migrate @ 17743]
Christian Hammond <chipx86@chipx86.com>
parents:
15025
diff
changeset
|
222 | mail = gevo_get_email_for_buddy(buddy); |
| 11117 | 223 | |
| 224 | if (mail != NULL) | |
| 225 | { | |
| 226 | char *app = g_find_program_in_path("evolution"); | |
| 227 | if (app != NULL) | |
| 228 | { | |
| 229 | char *command_line = g_strdup_printf("%s mailto:%s", app, mail); | |
| 230 | g_free(app); | |
| 231 | g_free(mail); | |
| 232 | ||
| 233 | g_spawn_command_line_async(command_line, NULL); | |
| 234 | g_free(command_line); | |
| 235 | } | |
| 236 | else | |
| 237 | { | |
| 15884 | 238 | purple_notify_error(NULL, NULL, _("Unable to send e-mail"), |
| 11117 | 239 | _("The evolution executable was not found in the PATH.")); |
| 240 | } | |
| 241 | } | |
| 242 | else | |
| 243 | { | |
| 15884 | 244 | purple_notify_error(NULL, NULL, _("Unable to send e-mail"), |
|
15026
be82a893c65e
[gaim-migrate @ 17743]
Christian Hammond <chipx86@chipx86.com>
parents:
15025
diff
changeset
|
245 | _("An e-mail address was not found for this buddy.")); |
| 11117 | 246 | } |
| 247 | } | |
| 248 | ||
| 249 | static void | |
| 15884 | 250 | blist_node_extended_menu_cb(PurpleBlistNode *node, GList **menu) |
| 8089 | 251 | { |
| 15884 | 252 | PurpleMenuAction *act; |
| 253 | PurpleBuddy *buddy; | |
| 254 | PurpleAccount *account; | |
|
15025
4bb4a1b56c14
[gaim-migrate @ 17742]
Christian Hammond <chipx86@chipx86.com>
parents:
14848
diff
changeset
|
255 | EContact *contact; |
|
15026
be82a893c65e
[gaim-migrate @ 17743]
Christian Hammond <chipx86@chipx86.com>
parents:
15025
diff
changeset
|
256 | char *mail; |
| 8089 | 257 | |
| 15884 | 258 | if (!PURPLE_BLIST_NODE_IS_BUDDY(node)) |
| 9051 | 259 | return; |
| 260 | ||
| 15884 | 261 | buddy = (PurpleBuddy *)node; |
| 262 | account = purple_buddy_get_account(buddy); | |
| 9051 | 263 | |
|
15026
be82a893c65e
[gaim-migrate @ 17743]
Christian Hammond <chipx86@chipx86.com>
parents:
15025
diff
changeset
|
264 | if (!gevo_prpl_is_supported(account, buddy)) |
|
15025
4bb4a1b56c14
[gaim-migrate @ 17742]
Christian Hammond <chipx86@chipx86.com>
parents:
14848
diff
changeset
|
265 | return; |
|
4bb4a1b56c14
[gaim-migrate @ 17742]
Christian Hammond <chipx86@chipx86.com>
parents:
14848
diff
changeset
|
266 | |
|
4bb4a1b56c14
[gaim-migrate @ 17742]
Christian Hammond <chipx86@chipx86.com>
parents:
14848
diff
changeset
|
267 | contact = gevo_search_buddy_in_contacts(buddy, NULL); |
|
4bb4a1b56c14
[gaim-migrate @ 17742]
Christian Hammond <chipx86@chipx86.com>
parents:
14848
diff
changeset
|
268 | |
|
4bb4a1b56c14
[gaim-migrate @ 17742]
Christian Hammond <chipx86@chipx86.com>
parents:
14848
diff
changeset
|
269 | if (contact == NULL) |
| 8089 | 270 | { |
| 15884 | 271 | act = purple_menu_action_new(_("Add to Address Book"), |
| 272 | PURPLE_CALLBACK(menu_item_activate_cb), | |
| 12919 | 273 | NULL, NULL); |
| 9051 | 274 | *menu = g_list_append(*menu, act); |
| 8089 | 275 | } |
|
15026
be82a893c65e
[gaim-migrate @ 17743]
Christian Hammond <chipx86@chipx86.com>
parents:
15025
diff
changeset
|
276 | else |
|
be82a893c65e
[gaim-migrate @ 17743]
Christian Hammond <chipx86@chipx86.com>
parents:
15025
diff
changeset
|
277 | g_object_unref(contact); |
|
15025
4bb4a1b56c14
[gaim-migrate @ 17742]
Christian Hammond <chipx86@chipx86.com>
parents:
14848
diff
changeset
|
278 | |
|
15026
be82a893c65e
[gaim-migrate @ 17743]
Christian Hammond <chipx86@chipx86.com>
parents:
15025
diff
changeset
|
279 | mail = gevo_get_email_for_buddy(buddy); |
|
be82a893c65e
[gaim-migrate @ 17743]
Christian Hammond <chipx86@chipx86.com>
parents:
15025
diff
changeset
|
280 | |
|
be82a893c65e
[gaim-migrate @ 17743]
Christian Hammond <chipx86@chipx86.com>
parents:
15025
diff
changeset
|
281 | if (mail != NULL) |
|
be82a893c65e
[gaim-migrate @ 17743]
Christian Hammond <chipx86@chipx86.com>
parents:
15025
diff
changeset
|
282 | { |
| 15884 | 283 | act = purple_menu_action_new(_("Send E-Mail"), |
| 284 | PURPLE_CALLBACK(menu_item_send_mail_activate_cb), NULL, NULL); | |
|
15026
be82a893c65e
[gaim-migrate @ 17743]
Christian Hammond <chipx86@chipx86.com>
parents:
15025
diff
changeset
|
285 | *menu = g_list_append(*menu, act); |
|
be82a893c65e
[gaim-migrate @ 17743]
Christian Hammond <chipx86@chipx86.com>
parents:
15025
diff
changeset
|
286 | g_free(mail); |
|
be82a893c65e
[gaim-migrate @ 17743]
Christian Hammond <chipx86@chipx86.com>
parents:
15025
diff
changeset
|
287 | } |
| 8089 | 288 | } |
| 289 | ||
|
11919
64764637df2a
[gaim-migrate @ 14210]
Mark Doliner <markdoliner@pidgin.im>
parents:
11256
diff
changeset
|
290 | /* TODO: Something in here leaks 1 reference to a bonobo object! */ |
| 8089 | 291 | static gboolean |
| 292 | load_timeout(gpointer data) | |
| 293 | { | |
| 15884 | 294 | PurplePlugin *plugin = (PurplePlugin *)data; |
|
8127
da683b4a5dc0
[gaim-migrate @ 8832]
Christian Hammond <chipx86@chipx86.com>
parents:
8089
diff
changeset
|
295 | EBookQuery *query; |
| 8089 | 296 | |
| 297 | timer = 0; | |
| 298 | ||
|
11919
64764637df2a
[gaim-migrate @ 14210]
Mark Doliner <markdoliner@pidgin.im>
parents:
11256
diff
changeset
|
299 | /* Maybe this is it? */ |
|
10081
64e398f0eaa3
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
10055
diff
changeset
|
300 | if (!gevo_load_addressbook(NULL, &book, NULL)) |
| 8089 | 301 | return FALSE; |
| 302 | ||
|
8127
da683b4a5dc0
[gaim-migrate @ 8832]
Christian Hammond <chipx86@chipx86.com>
parents:
8089
diff
changeset
|
303 | query = e_book_query_any_field_contains(""); |
|
da683b4a5dc0
[gaim-migrate @ 8832]
Christian Hammond <chipx86@chipx86.com>
parents:
8089
diff
changeset
|
304 | |
|
11919
64764637df2a
[gaim-migrate @ 14210]
Mark Doliner <markdoliner@pidgin.im>
parents:
11256
diff
changeset
|
305 | /* Is it this? */ |
|
8127
da683b4a5dc0
[gaim-migrate @ 8832]
Christian Hammond <chipx86@chipx86.com>
parents:
8089
diff
changeset
|
306 | book_view_tag = e_book_async_get_book_view(book, query, NULL, -1, |
|
da683b4a5dc0
[gaim-migrate @ 8832]
Christian Hammond <chipx86@chipx86.com>
parents:
8089
diff
changeset
|
307 | got_book_view_cb, NULL); |
|
da683b4a5dc0
[gaim-migrate @ 8832]
Christian Hammond <chipx86@chipx86.com>
parents:
8089
diff
changeset
|
308 | |
|
da683b4a5dc0
[gaim-migrate @ 8832]
Christian Hammond <chipx86@chipx86.com>
parents:
8089
diff
changeset
|
309 | e_book_query_unref(query); |
| 8089 | 310 | |
| 15884 | 311 | purple_signal_connect(purple_blist_get_handle(), "blist-node-extended-menu", |
| 312 | plugin, PURPLE_CALLBACK(blist_node_extended_menu_cb), NULL); | |
| 8089 | 313 | |
| 314 | return FALSE; | |
| 315 | } | |
| 316 | ||
| 317 | static gboolean | |
| 15884 | 318 | plugin_load(PurplePlugin *plugin) |
| 8089 | 319 | { |
| 320 | bonobo_activate(); | |
| 321 | ||
| 15884 | 322 | backup_blist_ui_ops = purple_blist_get_ui_ops(); |
| 8089 | 323 | |
| 15884 | 324 | blist_ui_ops = g_memdup(backup_blist_ui_ops, sizeof(PurpleBlistUiOps)); |
| 8089 | 325 | blist_ui_ops->request_add_buddy = request_add_buddy; |
| 326 | ||
| 15884 | 327 | purple_blist_set_ui_ops(blist_ui_ops); |
| 8089 | 328 | |
| 15884 | 329 | purple_signal_connect(purple_connections_get_handle(), "signed-on", |
| 330 | plugin, PURPLE_CALLBACK(signed_on_cb), NULL); | |
| 8089 | 331 | |
| 332 | timer = g_timeout_add(1, load_timeout, plugin); | |
| 333 | ||
| 334 | return TRUE; | |
| 335 | } | |
| 336 | ||
| 337 | static gboolean | |
| 15884 | 338 | plugin_unload(PurplePlugin *plugin) |
| 8089 | 339 | { |
| 15884 | 340 | purple_blist_set_ui_ops(backup_blist_ui_ops); |
| 8089 | 341 | |
| 342 | g_free(blist_ui_ops); | |
| 343 | ||
| 344 | backup_blist_ui_ops = NULL; | |
| 345 | blist_ui_ops = NULL; | |
| 346 | ||
| 347 | if (book_view != NULL) | |
| 348 | { | |
| 349 | e_book_view_stop(book_view); | |
| 350 | g_object_unref(book_view); | |
| 351 | book_view = NULL; | |
| 352 | } | |
| 353 | ||
| 354 | if (book != NULL) | |
| 355 | { | |
| 356 | g_object_unref(book); | |
| 357 | book = NULL; | |
| 358 | } | |
| 359 | ||
| 360 | return TRUE; | |
| 361 | } | |
| 362 | ||
| 363 | static void | |
| 15884 | 364 | plugin_destroy(PurplePlugin *plugin) |
| 8089 | 365 | { |
| 10055 | 366 | bonobo_debug_shutdown(); |
| 8089 | 367 | } |
| 368 | ||
| 369 | static void | |
| 370 | autoadd_toggled_cb(GtkCellRendererToggle *renderer, gchar *path_str, | |
| 371 | gpointer data) | |
| 372 | { | |
| 15884 | 373 | PurpleAccount *account; |
| 8089 | 374 | GtkTreeModel *model = (GtkTreeModel *)data; |
| 375 | GtkTreeIter iter; | |
| 376 | gboolean autoadd; | |
| 377 | ||
| 378 | gtk_tree_model_get_iter_from_string(model, &iter, path_str); | |
| 379 | gtk_tree_model_get(model, &iter, | |
| 380 | COLUMN_DATA, &account, | |
| 381 | COLUMN_AUTOADD, &autoadd, | |
| 382 | -1); | |
| 383 | ||
| 15884 | 384 | purple_account_set_bool(account, "gevo-autoadd", !autoadd); |
| 8089 | 385 | |
| 386 | gtk_list_store_set(GTK_LIST_STORE(model), &iter, | |
| 387 | COLUMN_AUTOADD, !autoadd, | |
| 388 | -1); | |
| 389 | } | |
| 390 | ||
| 391 | static GtkWidget * | |
| 15884 | 392 | get_config_frame(PurplePlugin *plugin) |
| 8089 | 393 | { |
| 394 | GtkWidget *ret; | |
| 395 | GtkWidget *vbox; | |
| 396 | GtkWidget *label; | |
| 397 | GtkWidget *sw; | |
| 398 | GtkWidget *treeview; | |
| 399 | GtkTreeViewColumn *column; | |
| 400 | GtkCellRenderer *renderer; | |
|
13091
b5ed878998dd
[gaim-migrate @ 15452]
Mark Doliner <markdoliner@pidgin.im>
parents:
12919
diff
changeset
|
401 | GdkPixbuf *pixbuf; |
| 8089 | 402 | GtkListStore *model; |
|
18122
9bf9970c1b6a
disapproval of revision '2d8ea56b90971e7851442d96b7d74ecb4f052126'
Richard Laager <rlaager@pidgin.im>
parents:
18121
diff
changeset
|
403 | GList *l; |
| 8089 | 404 | |
| 405 | /* Outside container */ | |
| 406 | ret = gtk_vbox_new(FALSE, 18); | |
| 407 | gtk_container_set_border_width(GTK_CONTAINER(ret), 12); | |
| 408 | ||
| 409 | /* Configuration frame */ | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
410 | vbox = pidgin_make_frame(ret, _("Evolution Integration Configuration")); |
| 8089 | 411 | |
| 412 | /* Label */ | |
| 413 | label = gtk_label_new(_("Select all accounts that buddies should be " | |
| 414 | "auto-added to.")); | |
| 415 | gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
| 416 | gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0); | |
| 417 | gtk_widget_show(label); | |
| 418 | ||
| 419 | /* Scrolled window */ | |
| 420 | sw = gtk_scrolled_window_new(0, 0); | |
| 421 | gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), | |
| 422 | GTK_POLICY_AUTOMATIC, | |
| 423 | GTK_POLICY_ALWAYS); | |
| 424 | gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw), | |
| 425 | GTK_SHADOW_IN); | |
| 426 | gtk_box_pack_start(GTK_BOX(vbox), sw, TRUE, TRUE, 0); | |
| 427 | gtk_widget_set_size_request(sw, 300, 300); | |
| 428 | gtk_widget_show(sw); | |
| 429 | ||
| 430 | /* Create the list model for the treeview. */ | |
| 431 | model = gtk_list_store_new(NUM_COLUMNS, | |
| 432 | G_TYPE_BOOLEAN, GDK_TYPE_PIXBUF, | |
| 433 | G_TYPE_STRING, G_TYPE_POINTER); | |
| 434 | ||
| 435 | /* Setup the treeview */ | |
| 436 | treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(model)); | |
| 437 | gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(treeview), TRUE); | |
| 438 | gtk_container_add(GTK_CONTAINER(sw), treeview); | |
| 439 | gtk_widget_show(treeview); | |
| 440 | ||
| 441 | /* Setup the column */ | |
| 442 | column = gtk_tree_view_column_new(); | |
| 443 | gtk_tree_view_column_set_title(column, _("Account")); | |
| 444 | gtk_tree_view_insert_column(GTK_TREE_VIEW(treeview), column, -1); | |
| 445 | ||
| 446 | /* Checkbox */ | |
| 447 | renderer = gtk_cell_renderer_toggle_new(); | |
| 448 | ||
| 449 | g_signal_connect(G_OBJECT(renderer), "toggled", | |
| 450 | G_CALLBACK(autoadd_toggled_cb), model); | |
| 451 | ||
| 452 | gtk_tree_view_column_pack_start(column, renderer, FALSE); | |
| 453 | gtk_tree_view_column_add_attribute(column, renderer, | |
| 454 | "active", COLUMN_AUTOADD); | |
| 455 | ||
| 456 | /* Icon */ | |
| 457 | renderer = gtk_cell_renderer_pixbuf_new(); | |
| 458 | gtk_tree_view_column_pack_start(column, renderer, FALSE); | |
| 459 | gtk_tree_view_column_add_attribute(column, renderer, | |
| 460 | "pixbuf", COLUMN_ICON); | |
| 461 | ||
| 462 | /* Screenname */ | |
| 463 | renderer = gtk_cell_renderer_text_new(); | |
| 464 | gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
| 465 | gtk_tree_view_column_add_attribute(column, renderer, | |
| 466 | "text", COLUMN_SCREENNAME); | |
| 467 | ||
| 468 | ||
| 469 | /* Populate */ | |
| 15884 | 470 | for (l = purple_accounts_get_all(); l != NULL; l = l->next) |
| 8089 | 471 | { |
| 15884 | 472 | PurpleAccount *account = (PurpleAccount *)l->data; |
| 8089 | 473 | GtkTreeIter iter; |
| 474 | ||
| 15884 | 475 | purple_debug_info("evolution", "Adding account\n"); |
| 8089 | 476 | |
| 477 | gtk_list_store_append(model, &iter); | |
| 478 | ||
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
479 | pixbuf = pidgin_create_prpl_icon(account, 0.5); |
| 15884 | 480 | if ((pixbuf != NULL) && (!purple_account_is_connected(account))) |
|
13091
b5ed878998dd
[gaim-migrate @ 15452]
Mark Doliner <markdoliner@pidgin.im>
parents:
12919
diff
changeset
|
481 | gdk_pixbuf_saturate_and_pixelate(pixbuf, pixbuf, 0.0, FALSE); |
| 8089 | 482 | |
| 483 | gtk_list_store_set(model, &iter, | |
| 484 | COLUMN_AUTOADD, | |
| 15884 | 485 | purple_account_get_bool(account, "gevo-autoadd", |
| 8089 | 486 | FALSE), |
|
13091
b5ed878998dd
[gaim-migrate @ 15452]
Mark Doliner <markdoliner@pidgin.im>
parents:
12919
diff
changeset
|
487 | COLUMN_ICON, pixbuf, |
| 8089 | 488 | COLUMN_SCREENNAME, |
| 15884 | 489 | purple_account_get_username(account), |
| 8089 | 490 | COLUMN_DATA, account, |
| 491 | -1); | |
| 492 | ||
|
13091
b5ed878998dd
[gaim-migrate @ 15452]
Mark Doliner <markdoliner@pidgin.im>
parents:
12919
diff
changeset
|
493 | if (pixbuf != NULL) |
|
b5ed878998dd
[gaim-migrate @ 15452]
Mark Doliner <markdoliner@pidgin.im>
parents:
12919
diff
changeset
|
494 | g_object_unref(G_OBJECT(pixbuf)); |
| 8089 | 495 | } |
| 496 | ||
| 497 | gtk_widget_show_all(ret); | |
| 498 | ||
| 499 | return ret; | |
| 500 | } | |
| 501 | ||
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
502 | static PidginPluginUiInfo ui_info = |
| 8089 | 503 | { |
|
12219
2265c26be232
[gaim-migrate @ 14521]
Richard Laager <rlaager@pidgin.im>
parents:
11919
diff
changeset
|
504 | get_config_frame, /**< get_config_frame */ |
|
16788
417d0e8d6f3f
Add padding to structs to fix compiler warnings
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
505 | 0, /**< page_num */ |
|
417d0e8d6f3f
Add padding to structs to fix compiler warnings
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
506 | /* Padding */ |
|
417d0e8d6f3f
Add padding to structs to fix compiler warnings
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
507 | NULL, |
|
417d0e8d6f3f
Add padding to structs to fix compiler warnings
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
508 | NULL, |
|
417d0e8d6f3f
Add padding to structs to fix compiler warnings
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
509 | NULL, |
|
417d0e8d6f3f
Add padding to structs to fix compiler warnings
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
510 | NULL |
| 8089 | 511 | }; |
| 512 | ||
| 15884 | 513 | static PurplePluginInfo info = |
| 8089 | 514 | { |
| 15884 | 515 | PURPLE_PLUGIN_MAGIC, |
| 516 | PURPLE_MAJOR_VERSION, | |
| 517 | PURPLE_MINOR_VERSION, | |
| 518 | PURPLE_PLUGIN_STANDARD, /**< type */ | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
519 | PIDGIN_PLUGIN_TYPE, /**< ui_requirement */ |
| 8089 | 520 | 0, /**< flags */ |
| 521 | NULL, /**< dependencies */ | |
| 15884 | 522 | PURPLE_PRIORITY_DEFAULT, /**< priority */ |
| 8089 | 523 | |
| 524 | GEVOLUTION_PLUGIN_ID, /**< id */ | |
| 525 | N_("Evolution Integration"), /**< name */ | |
| 526 | VERSION, /**< version */ | |
| 527 | /** summary */ | |
| 11117 | 528 | N_("Provides integration with Evolution."), |
| 8089 | 529 | /** description */ |
| 11117 | 530 | N_("Provides integration with Evolution."), |
|
15025
4bb4a1b56c14
[gaim-migrate @ 17742]
Christian Hammond <chipx86@chipx86.com>
parents:
14848
diff
changeset
|
531 | "Christian Hammond <chipx86@chipx86.com>", /**< author */ |
| 15884 | 532 | PURPLE_WEBSITE, /**< homepage */ |
| 8089 | 533 | |
| 534 | plugin_load, /**< load */ | |
| 535 | plugin_unload, /**< unload */ | |
| 536 | plugin_destroy, /**< destroy */ | |
| 537 | ||
| 538 | &ui_info, /**< ui_info */ | |
| 8993 | 539 | NULL, /**< extra_info */ |
| 540 | NULL, | |
|
16788
417d0e8d6f3f
Add padding to structs to fix compiler warnings
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
541 | NULL, |
|
417d0e8d6f3f
Add padding to structs to fix compiler warnings
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
542 | |
|
417d0e8d6f3f
Add padding to structs to fix compiler warnings
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
543 | /* Padding */ |
|
417d0e8d6f3f
Add padding to structs to fix compiler warnings
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
544 | NULL, |
|
417d0e8d6f3f
Add padding to structs to fix compiler warnings
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
545 | NULL, |
|
417d0e8d6f3f
Add padding to structs to fix compiler warnings
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
546 | NULL, |
| 8993 | 547 | NULL |
| 8089 | 548 | }; |
| 549 | ||
| 550 | static void | |
| 15884 | 551 | init_plugin(PurplePlugin *plugin) |
| 8089 | 552 | { |
| 553 | /* TODO: Change to core-remote when possible. */ | |
| 554 | /* info.dependencies = g_list_append(info.dependencies, "gtk-remote"); */ | |
| 555 | ||
| 556 | /* | |
| 557 | * I'm going to rant a little bit here... | |
| 558 | * | |
| 559 | * For some reason, when we init bonobo from inside a plugin, it will | |
| 560 | * segfault when destroyed. The backtraces are within gmodule somewhere. | |
| 561 | * There's not much I can do, and I'm not sure where the bug lies. | |
| 15884 | 562 | * However, plugins are only destroyed when Purple is shutting down. After |
| 563 | * destroying the plugins, purple ends, and anything else is of course | |
| 8089 | 564 | * freed. That includes this, if we make the module resident, which |
| 565 | * prevents us from being able to actually unload it. | |
| 566 | * | |
| 567 | * So, in conclusion, this is an evil hack, but it doesn't harm anything | |
| 568 | * and it works. | |
| 569 | */ | |
| 570 | g_module_make_resident(plugin->handle); | |
| 10055 | 571 | |
| 572 | if (!bonobo_init_full(NULL, NULL, bonobo_activation_orb_get(), | |
| 573 | CORBA_OBJECT_NIL, CORBA_OBJECT_NIL)) | |
| 574 | { | |
| 15884 | 575 | purple_debug_error("evolution", "Unable to initialize bonobo.\n"); |
| 10055 | 576 | } |
| 8089 | 577 | } |
| 578 | ||
| 15884 | 579 | PURPLE_INIT_PLUGIN(gevolution, init_plugin, info) |