Mercurial > pidgin
annotate src/prpl.c @ 12141:dcd2bcad2f3d
[gaim-migrate @ 14442]
These strings have been bothering me for quite some time. Flame me if you object to the changes. I also changed the default pounce action to 'pop up notification'. This isn't a big deal, as the action(s) you choose are saved as the default for the next time.
committer: Tailor Script <tailor@pidgin.im>
| author | Richard Laager <rlaager@wiktel.com> |
|---|---|
| date | Fri, 18 Nov 2005 23:35:26 +0000 |
| parents | 35c4797c5c57 |
| children | 6f41d8d33989 |
| 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 static gboolean | |
| 62 set_value_from_arg(GaimStatus *status, const char *id, va_list *args) | |
| 63 { | |
| 64 GaimValue *value; | |
| 65 | |
| 66 value = gaim_status_get_attr_value(status, id); | |
| 67 | |
| 68 if (value == NULL) | |
| 69 { | |
| 70 gaim_debug_error("prpl", | |
| 71 "Attempted to set an unknown attribute %s on " | |
| 72 "status %s\n", | |
| 73 id, gaim_status_get_id(status)); | |
| 74 return FALSE; | |
| 75 } | |
| 76 | |
| 77 switch (gaim_value_get_type(value)) | |
| 78 { | |
| 79 case GAIM_TYPE_CHAR: | |
| 80 gaim_value_set_char(value, (char)va_arg(*args, int)); | |
| 81 break; | |
| 82 | |
| 83 case GAIM_TYPE_UCHAR: | |
| 84 gaim_value_set_uchar(value, | |
| 85 (unsigned char)va_arg(*args, unsigned int)); | |
| 86 break; | |
| 87 | |
| 88 case GAIM_TYPE_BOOLEAN: | |
| 89 gaim_value_set_boolean(value, va_arg(*args, gboolean)); | |
| 90 break; | |
| 91 | |
| 92 case GAIM_TYPE_SHORT: | |
| 93 gaim_value_set_short(value, (short)va_arg(*args, int)); | |
| 94 break; | |
| 95 | |
| 96 case GAIM_TYPE_USHORT: | |
| 97 gaim_value_set_ushort(value, | |
| 98 (unsigned short)va_arg(*args, unsigned int)); | |
| 99 break; | |
| 100 | |
| 101 case GAIM_TYPE_INT: | |
| 102 gaim_value_set_int(value, va_arg(*args, int)); | |
| 103 break; | |
| 104 | |
| 105 case GAIM_TYPE_UINT: | |
| 106 gaim_value_set_uint(value, va_arg(*args, unsigned int)); | |
| 107 break; | |
| 108 | |
| 109 case GAIM_TYPE_LONG: | |
| 110 gaim_value_set_long(value, va_arg(*args, long)); | |
| 111 break; | |
| 112 | |
| 113 case GAIM_TYPE_ULONG: | |
| 114 gaim_value_set_ulong(value, va_arg(*args, unsigned long)); | |
| 115 break; | |
| 116 | |
| 117 case GAIM_TYPE_INT64: | |
| 118 gaim_value_set_int64(value, va_arg(*args, gint64)); | |
| 119 break; | |
| 120 | |
| 121 case GAIM_TYPE_UINT64: | |
| 122 gaim_value_set_uint64(value, va_arg(*args, guint64)); | |
| 123 break; | |
| 124 | |
| 125 case GAIM_TYPE_STRING: | |
| 126 gaim_value_set_string(value, va_arg(*args, char *)); | |
| 127 break; | |
| 128 | |
| 129 case GAIM_TYPE_OBJECT: | |
| 130 gaim_value_set_object(value, va_arg(*args, void *)); | |
| 131 break; | |
| 132 | |
| 133 case GAIM_TYPE_POINTER: | |
| 134 gaim_value_set_pointer(value, va_arg(*args, void *)); | |
| 135 break; | |
| 136 | |
| 137 case GAIM_TYPE_ENUM: | |
| 138 gaim_value_set_enum(value, va_arg(*args, int)); | |
| 139 break; | |
| 140 | |
| 141 case GAIM_TYPE_BOXED: | |
| 142 gaim_value_set_boxed(value, va_arg(*args, void *)); | |
| 143 break; | |
| 144 | |
| 145 default: | |
| 146 return FALSE; | |
| 147 } | |
| 148 | |
| 149 return TRUE; | |
| 150 } | |
| 151 | |
| 152 void | |
| 153 gaim_prpl_got_account_status(GaimAccount *account, const char *status_id, | |
| 154 const char *attr_id, ...) | |
| 155 { | |
| 156 GaimPresence *presence; | |
| 157 GaimStatus *status; | |
| 158 | |
| 159 g_return_if_fail(account != NULL); | |
| 160 g_return_if_fail(status_id != NULL); | |
| 161 g_return_if_fail(gaim_account_is_connected(account)); | |
| 162 | |
| 163 presence = gaim_account_get_presence(account); | |
| 164 status = gaim_presence_get_status(presence, status_id); | |
| 165 | |
| 166 g_return_if_fail(status != NULL); | |
| 167 | |
| 168 if (attr_id != NULL) | |
| 169 { | |
| 170 va_list args; | |
| 171 | |
| 172 va_start(args, attr_id); | |
| 173 | |
| 174 while (attr_id != NULL) | |
| 175 { | |
| 176 set_value_from_arg(status, attr_id, &args); | |
| 177 | |
| 178 attr_id = va_arg(args, char *); | |
| 179 } | |
| 180 | |
| 181 va_end(args); | |
| 182 } | |
| 183 | |
| 184 gaim_presence_set_status_active(presence, status_id, TRUE); | |
| 185 } | |
| 186 | |
| 187 void | |
| 188 gaim_prpl_got_user_idle(GaimAccount *account, const char *name, | |
| 189 gboolean idle, time_t idle_time) | |
| 190 { | |
|
12126
35c4797c5c57
[gaim-migrate @ 14426]
Richard Laager <rlaager@wiktel.com>
parents:
12108
diff
changeset
|
191 GSList *list, *iter; |
| 9949 | 192 |
| 193 g_return_if_fail(account != NULL); | |
| 194 g_return_if_fail(name != NULL); | |
| 195 g_return_if_fail(gaim_account_is_connected(account)); | |
| 196 | |
|
12126
35c4797c5c57
[gaim-migrate @ 14426]
Richard Laager <rlaager@wiktel.com>
parents:
12108
diff
changeset
|
197 list = gaim_find_buddies(account, name); |
|
35c4797c5c57
[gaim-migrate @ 14426]
Richard Laager <rlaager@wiktel.com>
parents:
12108
diff
changeset
|
198 for (iter = list; iter != NULL; iter = iter->next) |
| 10554 | 199 { |
| 200 GaimBuddy *buddy; | |
| 201 GaimPresence *presence; | |
| 9949 | 202 |
|
12126
35c4797c5c57
[gaim-migrate @ 14426]
Richard Laager <rlaager@wiktel.com>
parents:
12108
diff
changeset
|
203 buddy = (GaimBuddy *)iter->data; |
| 10007 | 204 |
| 10554 | 205 presence = gaim_buddy_get_presence(buddy); |
| 206 | |
| 207 gaim_presence_set_idle(presence, idle, idle_time); | |
| 208 } | |
|
12126
35c4797c5c57
[gaim-migrate @ 14426]
Richard Laager <rlaager@wiktel.com>
parents:
12108
diff
changeset
|
209 g_slist_free(list); |
| 9949 | 210 } |
| 211 | |
| 212 void | |
| 213 gaim_prpl_got_user_login_time(GaimAccount *account, const char *name, | |
| 214 time_t login_time) | |
| 215 { | |
|
12126
35c4797c5c57
[gaim-migrate @ 14426]
Richard Laager <rlaager@wiktel.com>
parents:
12108
diff
changeset
|
216 GSList *list, *iter; |
| 9949 | 217 |
| 218 g_return_if_fail(account != NULL); | |
| 219 g_return_if_fail(name != NULL); | |
| 220 | |
|
12126
35c4797c5c57
[gaim-migrate @ 14426]
Richard Laager <rlaager@wiktel.com>
parents:
12108
diff
changeset
|
221 list = gaim_find_buddies(account, name); |
|
35c4797c5c57
[gaim-migrate @ 14426]
Richard Laager <rlaager@wiktel.com>
parents:
12108
diff
changeset
|
222 for (iter = list; iter != NULL; iter = iter->next) |
| 10554 | 223 { |
| 224 GaimBuddy *buddy; | |
| 225 GaimPresence *presence; | |
| 226 | |
|
12126
35c4797c5c57
[gaim-migrate @ 14426]
Richard Laager <rlaager@wiktel.com>
parents:
12108
diff
changeset
|
227 buddy = (GaimBuddy *)iter->data; |
| 9949 | 228 |
| 10554 | 229 if (login_time == 0) |
| 230 login_time = time(NULL); | |
| 9949 | 231 |
| 10554 | 232 presence = gaim_buddy_get_presence(buddy); |
| 9949 | 233 |
| 10554 | 234 gaim_presence_set_login_time(presence, login_time); |
| 235 } | |
|
12126
35c4797c5c57
[gaim-migrate @ 14426]
Richard Laager <rlaager@wiktel.com>
parents:
12108
diff
changeset
|
236 g_slist_free(list); |
| 9949 | 237 } |
| 238 | |
| 239 void | |
| 240 gaim_prpl_got_user_status(GaimAccount *account, const char *name, | |
| 241 const char *status_id, const char *attr_id, ...) | |
| 242 { | |
|
12126
35c4797c5c57
[gaim-migrate @ 14426]
Richard Laager <rlaager@wiktel.com>
parents:
12108
diff
changeset
|
243 GSList *list, *iter; |
| 9949 | 244 |
| 245 g_return_if_fail(account != NULL); | |
| 246 g_return_if_fail(name != NULL); | |
| 247 g_return_if_fail(status_id != NULL); | |
| 248 g_return_if_fail(gaim_account_is_connected(account)); | |
| 249 | |
|
12126
35c4797c5c57
[gaim-migrate @ 14426]
Richard Laager <rlaager@wiktel.com>
parents:
12108
diff
changeset
|
250 list = gaim_find_buddies(account, name); |
|
35c4797c5c57
[gaim-migrate @ 14426]
Richard Laager <rlaager@wiktel.com>
parents:
12108
diff
changeset
|
251 for (iter = list; iter != NULL; iter = iter->next) |
| 10554 | 252 { |
| 253 GaimBuddy *buddy; | |
| 254 GaimPresence *presence; | |
| 255 GaimStatus *status; | |
| 256 GaimStatus *old_status; | |
| 9949 | 257 |
|
12126
35c4797c5c57
[gaim-migrate @ 14426]
Richard Laager <rlaager@wiktel.com>
parents:
12108
diff
changeset
|
258 buddy = (GaimBuddy *)iter->data; |
| 10554 | 259 presence = gaim_buddy_get_presence(buddy); |
| 260 status = gaim_presence_get_status(presence, status_id); | |
| 9949 | 261 |
| 10554 | 262 g_return_if_fail(status != NULL); |
| 9949 | 263 |
| 10554 | 264 if (attr_id != NULL) |
| 265 { | |
| 266 va_list args; | |
| 9949 | 267 |
| 10554 | 268 va_start(args, attr_id); |
| 9949 | 269 |
| 10554 | 270 while (attr_id != NULL) |
| 271 { | |
| 272 set_value_from_arg(status, attr_id, &args); | |
| 9949 | 273 |
| 10554 | 274 attr_id = va_arg(args, char *); |
| 275 } | |
| 276 | |
| 277 va_end(args); | |
| 9949 | 278 } |
| 279 | |
| 10554 | 280 old_status = gaim_presence_get_active_status(presence); |
| 281 gaim_presence_set_status_active(presence, status_id, TRUE); | |
| 282 gaim_blist_update_buddy_status(buddy, old_status); | |
| 9949 | 283 } |
|
12126
35c4797c5c57
[gaim-migrate @ 14426]
Richard Laager <rlaager@wiktel.com>
parents:
12108
diff
changeset
|
284 g_slist_free(list); |
| 9949 | 285 } |
| 286 | |
| 287 void | |
| 10447 | 288 gaim_prpl_change_account_status(GaimAccount *account, |
| 289 GaimStatus *old_status, GaimStatus *new_status) | |
| 9949 | 290 { |
| 291 GaimPlugin *prpl; | |
| 292 GaimPluginProtocolInfo *prpl_info; | |
| 293 | |
| 10447 | 294 g_return_if_fail(account != NULL); |
| 295 g_return_if_fail(old_status != NULL); | |
| 296 g_return_if_fail(new_status != NULL); | |
| 9949 | 297 |
| 11718 | 298 if (gaim_status_is_online(new_status) && |
| 299 gaim_account_is_disconnected(account)) | |
| 300 { | |
| 301 gaim_account_connect(account); | |
| 302 return; | |
| 303 } | |
| 304 | |
| 11927 | 305 if (!gaim_status_is_online(new_status)) |
| 11718 | 306 { |
| 11927 | 307 if (!gaim_account_is_disconnected(account)) |
| 308 gaim_account_disconnect(account); | |
| 11718 | 309 return; |
| 310 } | |
| 311 | |
| 12108 | 312 if (gaim_account_is_connecting(account)) |
| 313 /* | |
| 314 * We don't need to call the set_status PRPL function because | |
| 315 * the PRPL will take care of setting its status during the | |
| 316 * connection process. | |
| 317 */ | |
| 318 return; | |
| 319 | |
| 9949 | 320 prpl = gaim_find_prpl(gaim_account_get_protocol_id(account)); |
| 321 | |
| 322 if (prpl == NULL) | |
| 323 return; | |
| 324 | |
| 325 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl); | |
| 326 | |
| 327 if (prpl_info->set_status != NULL) | |
| 11628 | 328 { |
| 10447 | 329 prpl_info->set_status(account, new_status); |
| 11628 | 330 gaim_signal_emit(gaim_accounts_get_handle(), "account-status-changed", |
| 331 account, old_status, new_status); | |
| 332 } | |
| 9949 | 333 } |
| 334 | |
| 10006 | 335 GList * |
| 336 gaim_prpl_get_statuses(GaimAccount *account, GaimPresence *presence) | |
| 337 { | |
| 338 GaimPlugin *prpl; | |
| 339 GaimPluginProtocolInfo *prpl_info; | |
| 340 GList *statuses = NULL; | |
|
11730
ef57eccb9a3b
[gaim-migrate @ 14021]
Richard Laager <rlaager@wiktel.com>
parents:
11718
diff
changeset
|
341 GList *l, *list; |
| 10006 | 342 GaimStatus *status; |
| 343 | |
| 10447 | 344 g_return_val_if_fail(account != NULL, NULL); |
| 10006 | 345 g_return_val_if_fail(presence != NULL, NULL); |
| 346 | |
| 347 prpl = gaim_find_prpl(gaim_account_get_protocol_id(account)); | |
| 10046 | 348 |
| 10006 | 349 if (prpl == NULL) |
| 350 return NULL; | |
| 10046 | 351 |
| 10006 | 352 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl); |
| 353 if (prpl_info == NULL || prpl_info->status_types == NULL) | |
| 354 return NULL; | |
| 355 | |
|
11730
ef57eccb9a3b
[gaim-migrate @ 14021]
Richard Laager <rlaager@wiktel.com>
parents:
11718
diff
changeset
|
356 for (l = list = prpl_info->status_types(account); l != NULL; l = l->next) |
| 10006 | 357 { |
| 358 status = gaim_status_new((GaimStatusType *)l->data, presence); | |
| 359 statuses = g_list_append(statuses, status); | |
| 360 } | |
| 361 | |
|
11730
ef57eccb9a3b
[gaim-migrate @ 14021]
Richard Laager <rlaager@wiktel.com>
parents:
11718
diff
changeset
|
362 g_list_free(list); |
|
ef57eccb9a3b
[gaim-migrate @ 14021]
Richard Laager <rlaager@wiktel.com>
parents:
11718
diff
changeset
|
363 |
| 10006 | 364 return statuses; |
| 365 } | |
| 366 | |
| 9949 | 367 |
| 368 /************************************************************************** | |
| 369 * Protocol Plugin Subsystem API | |
| 370 **************************************************************************/ | |
| 371 | |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5161
diff
changeset
|
372 GaimPlugin * |
| 7956 | 373 gaim_find_prpl(const char *id) |
| 981 | 374 { |
|
5573
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
375 GList *l; |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5161
diff
changeset
|
376 GaimPlugin *plugin; |
| 981 | 377 |
|
10036
0ddc38f8db4a
[gaim-migrate @ 10995]
Luke Schierer <lschiere@pidgin.im>
parents:
10023
diff
changeset
|
378 g_return_val_if_fail(id != NULL, NULL); |
|
0ddc38f8db4a
[gaim-migrate @ 10995]
Luke Schierer <lschiere@pidgin.im>
parents:
10023
diff
changeset
|
379 |
|
5573
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
380 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
|
381 plugin = (GaimPlugin *)l->data; |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5161
diff
changeset
|
382 |
| 11948 | 383 if (!strcmp(plugin->info->id, id)) |
| 384 return plugin; | |
| 981 | 385 } |
| 386 | |
| 387 return NULL; | |
| 388 } |
