10418
|
1 /**
|
|
2 * @file savedstatus.c Saved Status API
|
|
3 * @ingroup core
|
|
4 *
|
|
5 * gaim
|
|
6 *
|
|
7 * Gaim is the legal property of its developers, whose names are too numerous
|
|
8 * to list here. Please refer to the COPYRIGHT file distributed with this
|
|
9 * source distribution.
|
|
10 *
|
|
11 * This program is free software; you can redistribute it and/or modify
|
|
12 * it under the terms of the GNU General Public License as published by
|
|
13 * the Free Software Foundation; either version 2 of the License, or
|
|
14 * (at your option) any later version.
|
|
15 *
|
|
16 * This program is distributed in the hope that it will be useful,
|
|
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
19 * GNU General Public License for more details.
|
|
20 *
|
|
21 * You should have received a copy of the GNU General Public License
|
|
22 * along with this program; if not, write to the Free Software
|
|
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
24 */
|
|
25 #include "internal.h"
|
|
26
|
|
27 #include "debug.h"
|
|
28 #include "notify.h"
|
|
29 #include "savedstatuses.h"
|
|
30 #include "status.h"
|
|
31 #include "util.h"
|
|
32 #include "xmlnode.h"
|
|
33
|
12056
|
34 /*
|
|
35 * TODO: Need to allow transient statuses to have empty titles.
|
|
36 */
|
|
37
|
10418
|
38 /**
|
|
39 * The information of a snap-shot of the statuses of all
|
|
40 * your accounts. Basically these are your saved away messages.
|
|
41 * There is an overall status and message that applies to
|
|
42 * all your accounts, and then each individual account can
|
|
43 * optionally have a different custom status and message.
|
|
44 *
|
|
45 * The changes to status.xml caused by the new status API
|
|
46 * are fully backward compatible. The new status API just
|
|
47 * adds the optional sub-statuses to the XML file.
|
|
48 */
|
10419
|
49 struct _GaimSavedStatus
|
10418
|
50 {
|
11651
|
51 /**
|
|
52 * A "transient" status is one that was used recently by
|
|
53 * a Gaim user, but was not explicitly created using the
|
|
54 * saved status UI. For example, Gaim's previous status
|
|
55 * is saved in the status.xml file, but should not show
|
|
56 * up in the UI.
|
|
57 */
|
|
58 gboolean transient;
|
|
59
|
10418
|
60 char *title;
|
|
61 GaimStatusPrimitive type;
|
|
62 char *message;
|
|
63
|
10419
|
64 GList *substatuses; /**< A list of GaimSavedStatusSub's. */
|
10418
|
65 };
|
|
66
|
|
67 /*
|
|
68 * TODO: If a GaimStatusType is deleted, need to also delete any
|
10419
|
69 * associated GaimSavedStatusSub's?
|
10418
|
70 */
|
10419
|
71 struct _GaimSavedStatusSub
|
10418
|
72 {
|
|
73 GaimAccount *account;
|
|
74 const GaimStatusType *type;
|
|
75 char *message;
|
|
76 };
|
|
77
|
10423
|
78 static GList *saved_statuses = NULL;
|
10428
|
79 static guint save_timer = 0;
|
10423
|
80 static gboolean statuses_loaded = FALSE;
|
10418
|
81
|
10427
|
82
|
10428
|
83 /*********************************************************************
|
|
84 * Private utility functions *
|
|
85 *********************************************************************/
|
10418
|
86
|
|
87 static void
|
10419
|
88 free_statussavedsub(GaimSavedStatusSub *substatus)
|
10418
|
89 {
|
|
90 g_return_if_fail(substatus != NULL);
|
|
91
|
|
92 g_free(substatus->message);
|
|
93 g_free(substatus);
|
|
94 }
|
|
95
|
|
96 static void
|
10419
|
97 free_statussaved(GaimSavedStatus *status)
|
10418
|
98 {
|
|
99 g_return_if_fail(status != NULL);
|
|
100
|
|
101 g_free(status->title);
|
|
102 g_free(status->message);
|
|
103
|
|
104 while (status->substatuses != NULL)
|
|
105 {
|
10419
|
106 GaimSavedStatusSub *substatus = status->substatuses->data;
|
10418
|
107 status->substatuses = g_list_remove(status->substatuses, substatus);
|
|
108 free_statussavedsub(substatus);
|
|
109 }
|
|
110
|
|
111 g_free(status);
|
|
112 }
|
|
113
|
10428
|
114 /*********************************************************************
|
10429
|
115 * Writing to disk *
|
10428
|
116 *********************************************************************/
|
10418
|
117
|
|
118 static xmlnode *
|
10419
|
119 substatus_to_xmlnode(GaimSavedStatusSub *substatus)
|
10418
|
120 {
|
|
121 xmlnode *node, *child;
|
|
122
|
|
123 node = xmlnode_new("substatus");
|
|
124
|
10424
|
125 child = xmlnode_new_child(node, "account");
|
|
126 xmlnode_set_attrib(child, "protocol", gaim_account_get_protocol_id(substatus->account));
|
|
127 xmlnode_insert_data(child, gaim_account_get_username(substatus->account), -1);
|
10418
|
128
|
10424
|
129 child = xmlnode_new_child(node, "state");
|
10418
|
130 xmlnode_insert_data(child, gaim_status_type_get_id(substatus->type), -1);
|
|
131
|
|
132 if (substatus->message != NULL)
|
|
133 {
|
10424
|
134 child = xmlnode_new_child(node, "message");
|
10418
|
135 xmlnode_insert_data(child, substatus->message, -1);
|
|
136 }
|
|
137
|
|
138 return node;
|
|
139 }
|
|
140
|
|
141 static xmlnode *
|
10419
|
142 status_to_xmlnode(GaimSavedStatus *status)
|
10418
|
143 {
|
|
144 xmlnode *node, *child;
|
11651
|
145 char transient[2];
|
10418
|
146 GList *cur;
|
|
147
|
11651
|
148 snprintf(transient, sizeof(transient), "%d", status->transient);
|
|
149
|
10418
|
150 node = xmlnode_new("status");
|
11651
|
151 xmlnode_set_attrib(node, "transient", transient);
|
10418
|
152 xmlnode_set_attrib(node, "name", status->title);
|
|
153
|
10424
|
154 child = xmlnode_new_child(node, "state");
|
|
155 xmlnode_insert_data(child, gaim_primitive_get_id_from_type(status->type), -1);
|
10418
|
156
|
11651
|
157 if (status->message != NULL)
|
|
158 {
|
|
159 child = xmlnode_new_child(node, "message");
|
|
160 xmlnode_insert_data(child, status->message, -1);
|
|
161 }
|
10418
|
162
|
|
163 for (cur = status->substatuses; cur != NULL; cur = cur->next)
|
|
164 {
|
|
165 child = substatus_to_xmlnode(cur->data);
|
|
166 xmlnode_insert_child(node, child);
|
|
167 }
|
|
168
|
|
169 return node;
|
|
170 }
|
|
171
|
|
172 static xmlnode *
|
|
173 statuses_to_xmlnode(void)
|
|
174 {
|
|
175 xmlnode *node, *child;
|
|
176 GList *cur;
|
|
177
|
|
178 node = xmlnode_new("statuses");
|
10423
|
179 xmlnode_set_attrib(node, "version", "1.0");
|
10418
|
180
|
|
181 for (cur = saved_statuses; cur != NULL; cur = cur->next)
|
|
182 {
|
|
183 child = status_to_xmlnode(cur->data);
|
|
184 xmlnode_insert_child(node, child);
|
|
185 }
|
|
186
|
|
187 return node;
|
|
188 }
|
|
189
|
|
190 static void
|
|
191 sync_statuses(void)
|
|
192 {
|
10423
|
193 xmlnode *node;
|
10418
|
194 char *data;
|
|
195
|
10428
|
196 if (!statuses_loaded)
|
|
197 {
|
10418
|
198 gaim_debug_error("status", "Attempted to save statuses before they "
|
|
199 "were read!\n");
|
|
200 return;
|
|
201 }
|
|
202
|
10423
|
203 node = statuses_to_xmlnode();
|
|
204 data = xmlnode_to_formatted_str(node, NULL);
|
10418
|
205 gaim_util_write_data_to_file("status.xml", data, -1);
|
|
206 g_free(data);
|
10423
|
207 xmlnode_free(node);
|
10418
|
208 }
|
|
209
|
|
210 static gboolean
|
10428
|
211 save_cb(gpointer data)
|
10418
|
212 {
|
|
213 sync_statuses();
|
10428
|
214 save_timer = 0;
|
10418
|
215 return FALSE;
|
|
216 }
|
|
217
|
|
218 static void
|
|
219 schedule_save(void)
|
|
220 {
|
10428
|
221 if (save_timer == 0)
|
|
222 save_timer = gaim_timeout_add(5000, save_cb, NULL);
|
10418
|
223 }
|
|
224
|
|
225
|
10428
|
226 /*********************************************************************
|
|
227 * Reading from disk *
|
|
228 *********************************************************************/
|
|
229
|
10419
|
230 static GaimSavedStatusSub *
|
10418
|
231 parse_substatus(xmlnode *substatus)
|
|
232 {
|
10419
|
233 GaimSavedStatusSub *ret;
|
10418
|
234 xmlnode *node;
|
10425
|
235 char *data;
|
10418
|
236
|
10419
|
237 ret = g_new0(GaimSavedStatusSub, 1);
|
10418
|
238
|
|
239 /* Read the account */
|
|
240 node = xmlnode_get_child(substatus, "account");
|
|
241 if (node != NULL)
|
|
242 {
|
|
243 char *acct_name;
|
|
244 const char *protocol;
|
|
245 acct_name = xmlnode_get_data(node);
|
|
246 protocol = xmlnode_get_attrib(node, "protocol");
|
|
247 if ((acct_name != NULL) && (protocol != NULL))
|
|
248 ret->account = gaim_accounts_find(acct_name, protocol);
|
|
249 g_free(acct_name);
|
|
250 }
|
|
251
|
|
252 if (ret->account == NULL)
|
|
253 {
|
|
254 g_free(ret);
|
|
255 return NULL;
|
|
256 }
|
|
257
|
|
258 /* Read the state */
|
|
259 node = xmlnode_get_child(substatus, "state");
|
10426
|
260 if ((node != NULL) && ((data = xmlnode_get_data(node)) != NULL))
|
10425
|
261 {
|
10418
|
262 ret->type = gaim_status_type_find_with_id(
|
10425
|
263 ret->account->status_types, data);
|
10418
|
264 g_free(data);
|
|
265 }
|
|
266
|
|
267 /* Read the message */
|
|
268 node = xmlnode_get_child(substatus, "message");
|
10426
|
269 if ((node != NULL) && ((data = xmlnode_get_data(node)) != NULL))
|
10425
|
270 {
|
10418
|
271 ret->message = data;
|
10425
|
272 }
|
10418
|
273
|
|
274 return ret;
|
|
275 }
|
|
276
|
|
277 /**
|
|
278 * Parse a saved status and add it to the saved_statuses linked list.
|
|
279 *
|
|
280 * Here's an example of the XML for a saved status:
|
|
281 * <status name="Girls">
|
|
282 * <state>away</state>
|
|
283 * <message>I like the way that they walk
|
|
284 * And it's chill to hear them talk
|
|
285 * And I can always make them smile
|
|
286 * From White Castle to the Nile</message>
|
|
287 * <substatus>
|
|
288 * <account protocol='prpl-oscar'>markdoliner</account>
|
|
289 * <state>available</state>
|
|
290 * <message>The ladies man is here to answer your queries.</message>
|
|
291 * </substatus>
|
|
292 * <substatus>
|
|
293 * <account protocol='prpl-oscar'>giantgraypanda</account>
|
|
294 * <state>away</state>
|
|
295 * <message>A.C. ain't in charge no more.</message>
|
|
296 * </substatus>
|
|
297 * </status>
|
|
298 *
|
|
299 * I know. Moving, huh?
|
|
300 */
|
10419
|
301 static GaimSavedStatus *
|
10418
|
302 parse_status(xmlnode *status)
|
|
303 {
|
10419
|
304 GaimSavedStatus *ret;
|
10418
|
305 xmlnode *node;
|
|
306 const char *attrib;
|
10425
|
307 char *data;
|
10418
|
308 int i;
|
|
309
|
10419
|
310 ret = g_new0(GaimSavedStatus, 1);
|
10418
|
311
|
11651
|
312 /* Read the transient property */
|
|
313 attrib = xmlnode_get_attrib(status, "transient");
|
|
314 if ((attrib != NULL) && (attrib[0] == '1'))
|
|
315 ret->transient = TRUE;
|
|
316
|
10418
|
317 /* Read the title */
|
|
318 attrib = xmlnode_get_attrib(status, "name");
|
|
319 if (attrib == NULL)
|
|
320 attrib = "No Title";
|
|
321 /* Ensure the title is unique */
|
|
322 ret->title = g_strdup(attrib);
|
|
323 i = 2;
|
10419
|
324 while (gaim_savedstatus_find(ret->title) != NULL)
|
10418
|
325 {
|
|
326 g_free(ret->title);
|
|
327 ret->title = g_strdup_printf("%s %d", attrib, i);
|
|
328 i++;
|
|
329 }
|
|
330
|
|
331 /* Read the primitive status type */
|
|
332 node = xmlnode_get_child(status, "state");
|
10426
|
333 if ((node != NULL) && ((data = xmlnode_get_data(node)) != NULL))
|
10425
|
334 {
|
10419
|
335 ret->type = gaim_primitive_get_type_from_id(data);
|
10418
|
336 g_free(data);
|
|
337 }
|
|
338
|
|
339 /* Read the message */
|
|
340 node = xmlnode_get_child(status, "message");
|
10426
|
341 if ((node != NULL) && ((data = xmlnode_get_data(node)) != NULL))
|
10425
|
342 {
|
10418
|
343 ret->message = data;
|
10425
|
344 }
|
10418
|
345
|
|
346 /* Read substatuses */
|
12056
|
347 for (node = xmlnode_get_child(status, "substatus"); node != NULL;
|
10418
|
348 node = xmlnode_get_next_twin(node))
|
|
349 {
|
10419
|
350 GaimSavedStatusSub *new;
|
10418
|
351 new = parse_substatus(node);
|
|
352 if (new != NULL)
|
12056
|
353 ret->substatuses = g_list_prepend(ret->substatuses, new);
|
10418
|
354 }
|
|
355
|
|
356 return ret;
|
|
357 }
|
|
358
|
|
359 /**
|
|
360 * Read the saved statuses from a file in the Gaim user dir.
|
|
361 *
|
|
362 * @return TRUE on success, FALSE on failure (if the file can not
|
|
363 * be opened, or if it contains invalid XML).
|
|
364 */
|
10425
|
365 static void
|
|
366 load_statuses(void)
|
10418
|
367 {
|
|
368 xmlnode *statuses, *status;
|
|
369
|
10426
|
370 statuses_loaded = TRUE;
|
|
371
|
10425
|
372 statuses = gaim_util_read_xml_from_file("status.xml", _("saved statuses"));
|
10418
|
373
|
|
374 if (statuses == NULL)
|
10425
|
375 return;
|
10418
|
376
|
|
377 for (status = xmlnode_get_child(statuses, "status"); status != NULL;
|
|
378 status = xmlnode_get_next_twin(status))
|
|
379 {
|
10419
|
380 GaimSavedStatus *new;
|
10418
|
381 new = parse_status(status);
|
12056
|
382 saved_statuses = g_list_prepend(saved_statuses, new);
|
10418
|
383 }
|
|
384
|
|
385 xmlnode_free(statuses);
|
|
386 }
|
|
387
|
|
388
|
|
389 /**************************************************************************
|
|
390 * Saved status API
|
|
391 **************************************************************************/
|
10419
|
392 GaimSavedStatus *
|
|
393 gaim_savedstatus_new(const char *title, GaimStatusPrimitive type)
|
10418
|
394 {
|
10419
|
395 GaimSavedStatus *status;
|
10418
|
396
|
12056
|
397 /* Make sure we don't already have a saved status with this title. */
|
10420
|
398 g_return_val_if_fail(gaim_savedstatus_find(title) == NULL, NULL);
|
|
399
|
10419
|
400 status = g_new0(GaimSavedStatus, 1);
|
10418
|
401 status->title = g_strdup(title);
|
|
402 status->type = type;
|
|
403
|
12056
|
404 saved_statuses = g_list_prepend(saved_statuses, status);
|
10418
|
405
|
|
406 schedule_save();
|
|
407
|
|
408 return status;
|
|
409 }
|
|
410
|
10420
|
411 void
|
12056
|
412 gaim_savedstatus_set_title(GaimSavedStatus *status, const char *title)
|
|
413 {
|
|
414 g_return_if_fail(status != NULL);
|
|
415
|
|
416 /* Make sure we don't already have a saved status with this title. */
|
|
417 g_return_if_fail(gaim_savedstatus_find(title) == NULL);
|
|
418
|
|
419 g_free(status->title);
|
|
420 status->title = g_strdup(title);
|
|
421
|
|
422 schedule_save();
|
|
423 }
|
|
424
|
|
425 void
|
11651
|
426 gaim_savedstatus_set_type(GaimSavedStatus *status, GaimStatusPrimitive type)
|
|
427 {
|
|
428 g_return_if_fail(status != NULL);
|
|
429
|
|
430 status->type = type;
|
|
431
|
|
432 schedule_save();
|
|
433 }
|
|
434
|
|
435 void
|
10420
|
436 gaim_savedstatus_set_message(GaimSavedStatus *status, const char *message)
|
|
437 {
|
|
438 g_return_if_fail(status != NULL);
|
|
439
|
|
440 g_free(status->message);
|
|
441 status->message = g_strdup(message);
|
|
442
|
|
443 schedule_save();
|
|
444 }
|
|
445
|
12056
|
446 void
|
12080
|
447 gaim_savedstatus_set_substatus(GaimSavedStatus *saved_status,
|
|
448 const GaimAccount *account,
|
|
449 const GaimStatusType *type,
|
|
450 const char *message)
|
12056
|
451 {
|
|
452 GaimSavedStatusSub *substatus;
|
|
453
|
|
454 g_return_if_fail(saved_status != NULL);
|
|
455 g_return_if_fail(account != NULL);
|
|
456 g_return_if_fail(type != NULL);
|
|
457
|
|
458 /* Find an existing substatus or create a new one */
|
12080
|
459 substatus = gaim_savedstatus_get_substatus(saved_status, account);
|
12056
|
460 if (substatus == NULL)
|
|
461 {
|
|
462 substatus = g_new0(GaimSavedStatusSub, 1);
|
|
463 substatus->account = (GaimAccount *)account;
|
|
464 saved_status->substatuses = g_list_prepend(saved_status->substatuses, substatus);
|
|
465 }
|
|
466
|
|
467 substatus->type = type;
|
|
468 g_free(substatus->message);
|
|
469 substatus->message = g_strdup(message);
|
|
470
|
|
471 schedule_save();
|
|
472 }
|
|
473
|
|
474 void
|
12080
|
475 gaim_savedstatus_unset_substatus(GaimSavedStatus *saved_status,
|
|
476 const GaimAccount *account)
|
12056
|
477 {
|
|
478 GList *iter;
|
|
479 GaimSavedStatusSub *substatus;
|
|
480
|
|
481 g_return_if_fail(saved_status != NULL);
|
|
482 g_return_if_fail(account != NULL);
|
|
483
|
|
484 for (iter = saved_status->substatuses; iter != NULL; iter = iter->next)
|
|
485 {
|
|
486 substatus = iter->data;
|
|
487 if (substatus->account == account)
|
|
488 {
|
|
489 saved_status->substatuses = g_list_delete_link(saved_status->substatuses, iter);
|
|
490 g_free(substatus->message);
|
|
491 g_free(substatus);
|
|
492 return;
|
|
493 }
|
|
494 }
|
|
495 }
|
|
496
|
10418
|
497 gboolean
|
10419
|
498 gaim_savedstatus_delete(const char *title)
|
10418
|
499 {
|
10419
|
500 GaimSavedStatus *status;
|
10418
|
501
|
10419
|
502 status = gaim_savedstatus_find(title);
|
10418
|
503
|
|
504 if (status == NULL)
|
|
505 return FALSE;
|
|
506
|
|
507 saved_statuses = g_list_remove(saved_statuses, status);
|
|
508 free_statussaved(status);
|
|
509
|
|
510 schedule_save();
|
|
511
|
|
512 return TRUE;
|
|
513 }
|
|
514
|
|
515 const GList *
|
|
516 gaim_savedstatuses_get_all(void)
|
|
517 {
|
|
518 return saved_statuses;
|
|
519 }
|
|
520
|
10419
|
521 GaimSavedStatus *
|
|
522 gaim_savedstatus_find(const char *title)
|
10418
|
523 {
|
12056
|
524 GList *iter;
|
10419
|
525 GaimSavedStatus *status;
|
10418
|
526
|
11977
|
527 g_return_val_if_fail(title != NULL, NULL);
|
|
528
|
12056
|
529 for (iter = saved_statuses; iter != NULL; iter = iter->next)
|
10418
|
530 {
|
12056
|
531 status = (GaimSavedStatus *)iter->data;
|
10418
|
532 if (!strcmp(status->title, title))
|
|
533 return status;
|
|
534 }
|
|
535
|
|
536 return NULL;
|
|
537 }
|
|
538
|
11651
|
539 gboolean
|
|
540 gaim_savedstatus_is_transient(const GaimSavedStatus *saved_status)
|
|
541 {
|
|
542 return saved_status->transient;
|
|
543 }
|
|
544
|
10418
|
545 const char *
|
10419
|
546 gaim_savedstatus_get_title(const GaimSavedStatus *saved_status)
|
10418
|
547 {
|
|
548 return saved_status->title;
|
|
549 }
|
|
550
|
|
551 GaimStatusPrimitive
|
10419
|
552 gaim_savedstatus_get_type(const GaimSavedStatus *saved_status)
|
10418
|
553 {
|
|
554 return saved_status->type;
|
|
555 }
|
|
556
|
|
557 const char *
|
10419
|
558 gaim_savedstatus_get_message(const GaimSavedStatus *saved_status)
|
10418
|
559 {
|
|
560 return saved_status->message;
|
|
561 }
|
|
562
|
11651
|
563 gboolean
|
|
564 gaim_savedstatus_has_substatuses(const GaimSavedStatus *saved_status)
|
|
565 {
|
|
566 return (saved_status->substatuses != NULL);
|
|
567 }
|
|
568
|
12056
|
569 GaimSavedStatusSub *
|
12080
|
570 gaim_savedstatus_get_substatus(const GaimSavedStatus *saved_status,
|
|
571 const GaimAccount *account)
|
12056
|
572 {
|
|
573 GList *iter;
|
|
574 GaimSavedStatusSub *substatus;
|
|
575
|
|
576 g_return_val_if_fail(saved_status != NULL, NULL);
|
|
577 g_return_val_if_fail(account != NULL, NULL);
|
|
578
|
|
579 for (iter = saved_status->substatuses; iter != NULL; iter = iter->next)
|
|
580 {
|
|
581 substatus = iter->data;
|
|
582 if (substatus->account == account)
|
|
583 return substatus;
|
|
584 }
|
|
585
|
|
586 return NULL;
|
|
587 }
|
|
588
|
|
589 const GaimStatusType *
|
|
590 gaim_savedstatus_substatus_get_type(const GaimSavedStatusSub *substatus)
|
|
591 {
|
|
592 g_return_val_if_fail(substatus != NULL, NULL);
|
|
593
|
|
594 return substatus->type;
|
|
595 }
|
|
596
|
|
597 const char *
|
|
598 gaim_savedstatus_substatus_get_message(const GaimSavedStatusSub *substatus)
|
|
599 {
|
|
600 g_return_val_if_fail(substatus != NULL, NULL);
|
|
601
|
|
602 return substatus->message;
|
|
603 }
|
|
604
|
11724
|
605 void
|
|
606 gaim_savedstatus_activate(const GaimSavedStatus *saved_status)
|
|
607 {
|
11733
|
608 GList *accounts, *node;
|
11724
|
609
|
11727
|
610 g_return_if_fail(saved_status != NULL);
|
|
611
|
11724
|
612 accounts = gaim_accounts_get_all_active();
|
|
613
|
11733
|
614 for (node = accounts; node != NULL; node = node->next)
|
11724
|
615 {
|
|
616 GaimAccount *account;
|
|
617
|
11733
|
618 account = node->data;
|
11724
|
619 gaim_savedstatus_activate_for_account(saved_status, account);
|
|
620 }
|
11733
|
621
|
|
622 g_list_free(accounts);
|
11954
|
623
|
12123
|
624 gaim_prefs_set_string("/core/savedstatus/current",
|
11954
|
625 gaim_savedstatus_get_title(saved_status));
|
11724
|
626 }
|
|
627
|
|
628 void
|
|
629 gaim_savedstatus_activate_for_account(const GaimSavedStatus *saved_status,
|
|
630 GaimAccount *account)
|
|
631 {
|
12056
|
632 const GaimStatusType *status_type;
|
|
633 const GaimSavedStatusSub *substatus;
|
|
634 const char *message = NULL;
|
11724
|
635
|
11727
|
636 g_return_if_fail(saved_status != NULL);
|
|
637 g_return_if_fail(account != NULL);
|
|
638
|
12080
|
639 substatus = gaim_savedstatus_get_substatus(saved_status, account);
|
12056
|
640 if (substatus != NULL)
|
|
641 {
|
|
642 status_type = substatus->type;
|
|
643 message = substatus->message;
|
|
644 }
|
|
645 else
|
11724
|
646 {
|
12056
|
647 status_type = gaim_account_get_status_type_with_primitive(account, saved_status->type);
|
|
648 if (status_type == NULL)
|
|
649 return;
|
|
650 message = saved_status->message;
|
|
651 }
|
|
652
|
|
653 if ((message != NULL) &&
|
|
654 (gaim_status_type_get_attr(status_type, "message")))
|
|
655 {
|
|
656 gaim_account_set_status(account, gaim_status_type_get_id(status_type),
|
|
657 TRUE, "message", message, NULL);
|
|
658 }
|
|
659 else
|
|
660 {
|
|
661 gaim_account_set_status(account, gaim_status_type_get_id(status_type),
|
|
662 TRUE, NULL);
|
11724
|
663 }
|
|
664 }
|
|
665
|
11318
|
666 void *
|
|
667 gaim_savedstatuses_get_handle(void)
|
|
668 {
|
|
669 static int handle;
|
|
670
|
|
671 return &handle;
|
|
672 }
|
|
673
|
10418
|
674 void
|
|
675 gaim_savedstatuses_init(void)
|
|
676 {
|
|
677 load_statuses();
|
11975
|
678
|
|
679 if (saved_statuses == NULL)
|
|
680 {
|
|
681 /*
|
|
682 * We don't have any saved statuses! This is probably a new account,
|
|
683 * so we add the "Default" status and the "Default when idle" status.
|
|
684 */
|
|
685 GaimSavedStatus *saved_status;
|
|
686
|
|
687 saved_status = gaim_savedstatus_new(_("Default"), GAIM_STATUS_AVAILABLE);
|
|
688 gaim_savedstatus_set_message(saved_status, _("Hello!"));
|
|
689
|
|
690 saved_status = gaim_savedstatus_new(_("Default when idle"), GAIM_STATUS_AWAY);
|
|
691 gaim_savedstatus_set_message(saved_status, _("I'm not here right now"));
|
|
692 }
|
12123
|
693
|
|
694 gaim_prefs_add_string("/core/savedstatus/current", _("Default"));
|
|
695 gaim_prefs_add_string("/core/savedstatus/idleaway", _("Default when idle"));
|
10418
|
696 }
|
|
697
|
|
698 void
|
|
699 gaim_savedstatuses_uninit(void)
|
|
700 {
|
10428
|
701 if (save_timer != 0)
|
10418
|
702 {
|
10428
|
703 gaim_timeout_remove(save_timer);
|
|
704 save_timer = 0;
|
10418
|
705 sync_statuses();
|
|
706 }
|
|
707
|
|
708 while (saved_statuses != NULL) {
|
12056
|
709 GaimSavedStatus *saved_status = saved_statuses->data;
|
|
710 saved_statuses = g_list_remove(saved_statuses, saved_status);
|
|
711 free_statussaved(saved_status);
|
10418
|
712 }
|
|
713 }
|
12056
|
714
|