annotate plugins/gevolution/gevo-util.c @ 10547:82d6760ba000

[gaim-migrate @ 11917] I think some of us agree that this 1. Could break something if a conversation is actually removed 2. Should not be done anyway committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Thu, 27 Jan 2005 03:48:25 +0000
parents a66cf83552dc
children bc700cc98b82
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8089
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1 /*
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2 * Evolution integration plugin for Gaim
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3 *
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4 * Copyright (C) 2003 Christian Hammond.
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
5 *
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
6 * This program is free software; you can redistribute it and/or
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
7 * modify it under the terms of the GNU General Public License as
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
8 * published by the Free Software Foundation; either version 2 of the
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
9 * License, or (at your option) any later version.
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
10 *
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
11 * This program is distributed in the hope that it will be useful, but
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
14 * General Public License for more details.
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
15 *
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
16 * You should have received a copy of the GNU General Public License
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
17 * along with this program; if not, write to the Free Software
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
19 * 02111-1307, USA.
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
20 */
9825
c00def44d76a [gaim-migrate @ 10696]
Christian Hammond <chipx86@chipx86.com>
parents: 9824
diff changeset
21 #include "internal.h"
8089
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
22 #include "gtkblist.h"
9824
94910b9520cf [gaim-migrate @ 10695]
Mark Doliner <mark@kingant.net>
parents: 9354
diff changeset
23 #include "gtkgaim.h"
8089
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
24 #include "gtkutils.h"
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
25
9046
c307cf4c84d2 [gaim-migrate @ 9822]
Christian Hammond <chipx86@chipx86.com>
parents: 8474
diff changeset
26 #include "gevolution.h"
c307cf4c84d2 [gaim-migrate @ 9822]
Christian Hammond <chipx86@chipx86.com>
parents: 8474
diff changeset
27
8089
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
28 void
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
29 gevo_add_buddy(GaimAccount *account, const char *group_name,
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
30 const char *screenname, const char *alias)
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
31 {
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
32 GaimConversation *conv = NULL;
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
33 GaimBuddy *buddy;
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
34 GaimGroup *group;
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
35
10246
a66cf83552dc [gaim-migrate @ 11386]
Mark Doliner <mark@kingant.net>
parents: 10081
diff changeset
36 conv = gaim_find_conversation_with_account(GAIM_CONV_IM, screenname, account);
8089
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
37
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
38 if ((group = gaim_find_group(group_name)) == NULL)
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
39 {
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
40 group = gaim_group_new(group_name);
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
41 gaim_blist_add_group(group, NULL);
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
42 }
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
43
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
44 buddy = gaim_buddy_new(account, screenname, alias);
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
45 gaim_blist_add_buddy(buddy, NULL, group, NULL);
9293
d92ee4b0e44b [gaim-migrate @ 10096]
Christian Hammond <chipx86@chipx86.com>
parents: 9095
diff changeset
46 serv_add_buddy(gaim_account_get_connection(account), buddy);
8089
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
47
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
48 if (conv != NULL)
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
49 {
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
50 gaim_buddy_icon_update(gaim_conv_im_get_icon(GAIM_CONV_IM(conv)));
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
51 gaim_conversation_update(conv, GAIM_CONV_UPDATE_ADD);
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
52 }
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
53 }
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
54
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
55 GList *
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
56 gevo_get_groups(void)
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
57 {
10081
ff4be2d1401d [gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents: 9825
diff changeset
58 GList *list = NULL;
8089
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
59 GaimGroup *g;
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
60 GaimBlistNode *gnode;
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
61
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
62 if (gaim_get_blist()->root == NULL)
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
63 {
10081
ff4be2d1401d [gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents: 9825
diff changeset
64 list = g_list_append(list, _("Buddies"));
8089
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
65 }
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
66 else
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
67 {
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
68 for (gnode = gaim_get_blist()->root;
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
69 gnode != NULL;
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
70 gnode = gnode->next)
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
71 {
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
72 if (GAIM_BLIST_NODE_IS_GROUP(gnode))
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
73 {
10081
ff4be2d1401d [gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents: 9825
diff changeset
74 g = (GaimGroup *)gnode;
ff4be2d1401d [gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents: 9825
diff changeset
75 list = g_list_append(list, g->name);
8089
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
76 }
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
77 }
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
78 }
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
79
10081
ff4be2d1401d [gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents: 9825
diff changeset
80 return list;
8089
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
81 }
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
82
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
83 EContactField
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
84 gevo_prpl_get_field(GaimAccount *account, GaimBuddy *buddy)
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
85 {
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
86 EContactField protocol_field = 0;
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
87 const char *protocol_id;
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
88
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
89 g_return_val_if_fail(account != NULL, 0);
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
90
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
91 protocol_id = gaim_account_get_protocol_id(account);
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
92
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
93 if (!strcmp(protocol_id, "prpl-oscar"))
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
94 {
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
95 GaimConnection *gc;
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
96 GaimPluginProtocolInfo *prpl_info;
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
97
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
98 gc = gaim_account_get_connection(account);
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
99
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
100 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl);
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
101
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
102 if (!strcmp("aim", prpl_info->list_icon(account, buddy)))
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
103 {
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
104 protocol_field = E_CONTACT_IM_AIM;
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
105 }
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
106 else
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
107 protocol_field = E_CONTACT_IM_ICQ;
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
108 }
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
109 else if (!strcmp(protocol_id, "prpl-msn"))
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
110 protocol_field = E_CONTACT_IM_MSN;
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
111 else if (!strcmp(protocol_id, "prpl-yahoo"))
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
112 protocol_field = E_CONTACT_IM_YAHOO;
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
113 else if (!strcmp(protocol_id, "prpl-jabber"))
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
114 protocol_field = E_CONTACT_IM_JABBER;
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
115
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
116 return protocol_field;
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
117 }
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
118
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
119 gboolean
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
120 gevo_prpl_is_supported(GaimAccount *account, GaimBuddy *buddy)
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
121 {
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
122 return (gevo_prpl_get_field(account, buddy) != 0);
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
123 }
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
124
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
125 gboolean
10081
ff4be2d1401d [gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents: 9825
diff changeset
126 gevo_load_addressbook(const gchar* uri, EBook **book, GError **error)
8089
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
127 {
9046
c307cf4c84d2 [gaim-migrate @ 9822]
Christian Hammond <chipx86@chipx86.com>
parents: 8474
diff changeset
128 gboolean result = FALSE;
8089
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
129
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
130 g_return_val_if_fail(book != NULL, FALSE);
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
131
10081
ff4be2d1401d [gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents: 9825
diff changeset
132 if (uri == NULL)
ff4be2d1401d [gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents: 9825
diff changeset
133 *book = e_book_new_system_addressbook(NULL);
ff4be2d1401d [gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents: 9825
diff changeset
134 else
ff4be2d1401d [gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents: 9825
diff changeset
135 *book = e_book_new_from_uri(uri, error);
9046
c307cf4c84d2 [gaim-migrate @ 9822]
Christian Hammond <chipx86@chipx86.com>
parents: 8474
diff changeset
136
9352
cc2baf349805 [gaim-migrate @ 10160]
Christian Hammond <chipx86@chipx86.com>
parents: 9293
diff changeset
137 result = e_book_open(*book, FALSE, NULL);
8089
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
138
9046
c307cf4c84d2 [gaim-migrate @ 9822]
Christian Hammond <chipx86@chipx86.com>
parents: 8474
diff changeset
139 if (!result && *book != NULL)
8089
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
140 {
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
141 g_object_unref(*book);
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
142 *book = NULL;
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
143 }
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
144
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
145 return result;
35db601609e3 [gaim-migrate @ 8788]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
146 }