Mercurial > pidgin.yaz
annotate src/prpl.c @ 14133:31d33e7bc0e6
[gaim-migrate @ 16775]
A global buddy icon selector in the statusbox.
This is done totally in the GTK+ UI; the core still sees a buddy icon as
belonging to an account.
Per-account icons can override the global one in Modify Account.
There are some caching issues to work out, still.
committer: Tailor Script <tailor@pidgin.im>
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Tue, 15 Aug 2006 23:25:29 +0000 |
parents | 8bda65b88e49 |
children | cef7f6a93592 |
rev | line source |
---|---|
981 | 1 /* |
2 * gaim | |
3 * | |
8046 | 4 * Gaim is the legal property of its developers, whose names are too numerous |
5 * to list here. Please refer to the COPYRIGHT file distributed with this | |
6 * source distribution. | |
6460
ff4551719cc7
[gaim-migrate @ 6969]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
7 * |
981 | 8 * This program is free software; you can redistribute it and/or modify |
9 * it under the terms of the GNU General Public License as published by | |
10 * the Free Software Foundation; either version 2 of the License, or | |
11 * (at your option) any later version. | |
12 * | |
13 * This program is distributed in the hope that it will be useful, | |
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 * GNU General Public License for more details. | |
17 * | |
18 * You should have received a copy of the GNU General Public License | |
19 * along with this program; if not, write to the Free Software | |
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
21 * | |
22 */ | |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5717
diff
changeset
|
23 #include "internal.h" |
5945
2a18e7b5917e
[gaim-migrate @ 6386]
Christian Hammond <chipx86@chipx86.com>
parents:
5943
diff
changeset
|
24 #include "conversation.h" |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5717
diff
changeset
|
25 #include "debug.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5717
diff
changeset
|
26 #include "notify.h" |
981 | 27 #include "prpl.h" |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5717
diff
changeset
|
28 #include "request.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5717
diff
changeset
|
29 #include "util.h" |
3738 | 30 |
9949 | 31 /**************************************************************************/ |
32 /** @name Protocol Plugin API */ | |
33 /**************************************************************************/ | |
34 void | |
35 gaim_prpl_got_account_idle(GaimAccount *account, gboolean idle, | |
36 time_t idle_time) | |
37 { | |
38 g_return_if_fail(account != NULL); | |
39 g_return_if_fail(gaim_account_is_connected(account)); | |
40 | |
41 gaim_presence_set_idle(gaim_account_get_presence(account), | |
42 idle, idle_time); | |
43 } | |
44 | |
45 void | |
10870 | 46 gaim_prpl_got_account_login_time(GaimAccount *account, time_t login_time) |
9949 | 47 { |
48 GaimPresence *presence; | |
49 | |
50 g_return_if_fail(account != NULL); | |
51 g_return_if_fail(gaim_account_is_connected(account)); | |
52 | |
53 if (login_time == 0) | |
54 login_time = time(NULL); | |
55 | |
56 presence = gaim_account_get_presence(account); | |
57 | |
10007 | 58 gaim_presence_set_login_time(presence, login_time); |
9949 | 59 } |
60 | |
61 void | |
13373 | 62 gaim_prpl_got_account_status(GaimAccount *account, const char *status_id, ...) |
9949 | 63 { |
64 GaimPresence *presence; | |
65 GaimStatus *status; | |
13373 | 66 va_list args; |
9949 | 67 |
68 g_return_if_fail(account != NULL); | |
69 g_return_if_fail(status_id != NULL); | |
70 g_return_if_fail(gaim_account_is_connected(account)); | |
71 | |
72 presence = gaim_account_get_presence(account); | |
73 status = gaim_presence_get_status(presence, status_id); | |
74 | |
75 g_return_if_fail(status != NULL); | |
76 | |
13373 | 77 va_start(args, status_id); |
78 gaim_status_set_active_with_attrs(status, TRUE, args); | |
79 va_end(args); | |
9949 | 80 } |
81 | |
82 void | |
83 gaim_prpl_got_user_idle(GaimAccount *account, const char *name, | |
84 gboolean idle, time_t idle_time) | |
85 { | |
12176 | 86 GaimBuddy *buddy; |
87 GaimPresence *presence; | |
9949 | 88 |
89 g_return_if_fail(account != NULL); | |
90 g_return_if_fail(name != NULL); | |
91 g_return_if_fail(gaim_account_is_connected(account)); | |
92 | |
12176 | 93 if ((buddy = gaim_find_buddy(account, name)) == NULL) |
94 return; | |
9949 | 95 |
12176 | 96 presence = gaim_buddy_get_presence(buddy); |
10554 | 97 |
12176 | 98 gaim_presence_set_idle(presence, idle, idle_time); |
9949 | 99 } |
100 | |
101 void | |
102 gaim_prpl_got_user_login_time(GaimAccount *account, const char *name, | |
103 time_t login_time) | |
104 { | |
12176 | 105 GaimBuddy *buddy; |
106 GaimPresence *presence; | |
9949 | 107 |
108 g_return_if_fail(account != NULL); | |
109 g_return_if_fail(name != NULL); | |
110 | |
12176 | 111 if ((buddy = gaim_find_buddy(account, name)) == NULL) |
112 return; | |
9949 | 113 |
12176 | 114 if (login_time == 0) |
115 login_time = time(NULL); | |
9949 | 116 |
12176 | 117 presence = gaim_buddy_get_presence(buddy); |
9949 | 118 |
12176 | 119 gaim_presence_set_login_time(presence, login_time); |
9949 | 120 } |
121 | |
122 void | |
123 gaim_prpl_got_user_status(GaimAccount *account, const char *name, | |
13373 | 124 const char *status_id, ...) |
9949 | 125 { |
14035 | 126 GSList *list; |
12176 | 127 GaimBuddy *buddy; |
128 GaimPresence *presence; | |
129 GaimStatus *status; | |
130 GaimStatus *old_status; | |
13373 | 131 va_list args; |
9949 | 132 |
133 g_return_if_fail(account != NULL); | |
134 g_return_if_fail(name != NULL); | |
135 g_return_if_fail(status_id != NULL); | |
12377 | 136 g_return_if_fail(gaim_account_is_connected(account) || gaim_account_is_connecting(account)); |
9949 | 137 |
12176 | 138 if ((buddy = gaim_find_buddy(account, name)) == NULL) |
139 return; | |
140 | |
141 presence = gaim_buddy_get_presence(buddy); | |
142 status = gaim_presence_get_status(presence, status_id); | |
143 | |
144 g_return_if_fail(status != NULL); | |
145 | |
13373 | 146 old_status = gaim_presence_get_active_status(presence); |
12176 | 147 |
13373 | 148 va_start(args, status_id); |
149 gaim_status_set_active_with_attrs(status, TRUE, args); | |
150 va_end(args); | |
12176 | 151 |
12126
35c4797c5c57
[gaim-migrate @ 14426]
Richard Laager <rlaager@wiktel.com>
parents:
12108
diff
changeset
|
152 list = gaim_find_buddies(account, name); |
14035 | 153 g_slist_foreach(list, (GFunc)gaim_blist_update_buddy_status, old_status); |
12126
35c4797c5c57
[gaim-migrate @ 14426]
Richard Laager <rlaager@wiktel.com>
parents:
12108
diff
changeset
|
154 g_slist_free(list); |
12654 | 155 |
156 if (!gaim_status_is_online(status)) | |
157 serv_got_typing_stopped(gaim_account_get_connection(account), name); | |
9949 | 158 } |
159 | |
12304 | 160 static void |
161 do_prpl_change_account_status(GaimAccount *account, | |
10447 | 162 GaimStatus *old_status, GaimStatus *new_status) |
9949 | 163 { |
164 GaimPlugin *prpl; | |
165 GaimPluginProtocolInfo *prpl_info; | |
166 | |
11718 | 167 if (gaim_status_is_online(new_status) && |
168 gaim_account_is_disconnected(account)) | |
169 { | |
170 gaim_account_connect(account); | |
171 return; | |
172 } | |
173 | |
174 | |
12108 | 175 if (gaim_account_is_connecting(account)) |
176 /* | |
177 * We don't need to call the set_status PRPL function because | |
178 * the PRPL will take care of setting its status during the | |
179 * connection process. | |
180 */ | |
181 return; | |
182 | |
9949 | 183 prpl = gaim_find_prpl(gaim_account_get_protocol_id(account)); |
184 | |
185 if (prpl == NULL) | |
186 return; | |
187 | |
188 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl); | |
189 | |
13334
99d081c638f6
[gaim-migrate @ 15704]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13330
diff
changeset
|
190 if (!gaim_account_is_disconnected(account) && prpl_info->set_status != NULL) |
11628 | 191 { |
10447 | 192 prpl_info->set_status(account, new_status); |
11628 | 193 } |
13330 | 194 |
195 if (!gaim_status_is_online(new_status)) | |
196 { | |
197 if (!gaim_account_is_disconnected(account)) | |
198 gaim_account_disconnect(account); | |
199 return; | |
200 } | |
9949 | 201 } |
202 | |
12304 | 203 void |
204 gaim_prpl_change_account_status(GaimAccount *account, | |
205 GaimStatus *old_status, GaimStatus *new_status) | |
206 { | |
207 g_return_if_fail(account != NULL); | |
208 g_return_if_fail(old_status != NULL); | |
209 g_return_if_fail(new_status != NULL); | |
210 | |
211 do_prpl_change_account_status(account, old_status, new_status); | |
212 | |
213 gaim_signal_emit(gaim_accounts_get_handle(), "account-status-changed", | |
214 account, old_status, new_status); | |
215 } | |
216 | |
10006 | 217 GList * |
218 gaim_prpl_get_statuses(GaimAccount *account, GaimPresence *presence) | |
219 { | |
220 GaimPlugin *prpl; | |
221 GaimPluginProtocolInfo *prpl_info; | |
222 GList *statuses = NULL; | |
11730
ef57eccb9a3b
[gaim-migrate @ 14021]
Richard Laager <rlaager@wiktel.com>
parents:
11718
diff
changeset
|
223 GList *l, *list; |
10006 | 224 GaimStatus *status; |
225 | |
10447 | 226 g_return_val_if_fail(account != NULL, NULL); |
10006 | 227 g_return_val_if_fail(presence != NULL, NULL); |
228 | |
229 prpl = gaim_find_prpl(gaim_account_get_protocol_id(account)); | |
10046 | 230 |
10006 | 231 if (prpl == NULL) |
232 return NULL; | |
10046 | 233 |
10006 | 234 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl); |
235 if (prpl_info == NULL || prpl_info->status_types == NULL) | |
236 return NULL; | |
237 | |
11730
ef57eccb9a3b
[gaim-migrate @ 14021]
Richard Laager <rlaager@wiktel.com>
parents:
11718
diff
changeset
|
238 for (l = list = prpl_info->status_types(account); l != NULL; l = l->next) |
10006 | 239 { |
240 status = gaim_status_new((GaimStatusType *)l->data, presence); | |
241 statuses = g_list_append(statuses, status); | |
242 } | |
243 | |
11730
ef57eccb9a3b
[gaim-migrate @ 14021]
Richard Laager <rlaager@wiktel.com>
parents:
11718
diff
changeset
|
244 g_list_free(list); |
ef57eccb9a3b
[gaim-migrate @ 14021]
Richard Laager <rlaager@wiktel.com>
parents:
11718
diff
changeset
|
245 |
10006 | 246 return statuses; |
247 } | |
248 | |
9949 | 249 |
250 /************************************************************************** | |
251 * Protocol Plugin Subsystem API | |
252 **************************************************************************/ | |
253 | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5161
diff
changeset
|
254 GaimPlugin * |
7956 | 255 gaim_find_prpl(const char *id) |
981 | 256 { |
5573
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
257 GList *l; |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5161
diff
changeset
|
258 GaimPlugin *plugin; |
981 | 259 |
10036
0ddc38f8db4a
[gaim-migrate @ 10995]
Luke Schierer <lschiere@pidgin.im>
parents:
10023
diff
changeset
|
260 g_return_val_if_fail(id != NULL, NULL); |
0ddc38f8db4a
[gaim-migrate @ 10995]
Luke Schierer <lschiere@pidgin.im>
parents:
10023
diff
changeset
|
261 |
5573
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
262 for (l = gaim_plugins_get_protocols(); l != NULL; l = l->next) { |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5161
diff
changeset
|
263 plugin = (GaimPlugin *)l->data; |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5161
diff
changeset
|
264 |
11948 | 265 if (!strcmp(plugin->info->id, id)) |
266 return plugin; | |
981 | 267 } |
268 | |
269 return NULL; | |
270 } |