annotate src/savedstatuses.c @ 11773:92cf092f194e

[gaim-migrate @ 14064] killing a warning... committer: Tailor Script <tailor@pidgin.im>
author Gary Kramlich <grim@reaperworld.com>
date Sun, 23 Oct 2005 23:27:59 +0000
parents a25be0e70a67
children 7584d802f0ac
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
1 /**
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
2 * @file savedstatus.c Saved Status API
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
3 * @ingroup core
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
4 *
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
5 * gaim
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
6 *
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
7 * Gaim is the legal property of its developers, whose names are too numerous
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
8 * to list here. Please refer to the COPYRIGHT file distributed with this
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
9 * source distribution.
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
10 *
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
11 * This program is free software; you can redistribute it and/or modify
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
12 * it under the terms of the GNU General Public License as published by
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
13 * the Free Software Foundation; either version 2 of the License, or
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
14 * (at your option) any later version.
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
15 *
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
16 * This program is distributed in the hope that it will be useful,
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
19 * GNU General Public License for more details.
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
20 *
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
21 * You should have received a copy of the GNU General Public License
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
22 * along with this program; if not, write to the Free Software
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
24 */
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
25 #include "internal.h"
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
26
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
27 #include "debug.h"
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
28 #include "notify.h"
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
29 #include "savedstatuses.h"
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
30 #include "status.h"
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
31 #include "util.h"
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
32 #include "xmlnode.h"
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
33
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
34 /**
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
35 * The information of a snap-shot of the statuses of all
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
36 * your accounts. Basically these are your saved away messages.
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
37 * There is an overall status and message that applies to
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
38 * all your accounts, and then each individual account can
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
39 * optionally have a different custom status and message.
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
40 *
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
41 * The changes to status.xml caused by the new status API
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
42 * are fully backward compatible. The new status API just
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
43 * adds the optional sub-statuses to the XML file.
10738
55af3fa46329 [gaim-migrate @ 12340]
Mark Doliner <mark@kingant.net>
parents: 10429
diff changeset
44 *
55af3fa46329 [gaim-migrate @ 12340]
Mark Doliner <mark@kingant.net>
parents: 10429
diff changeset
45 * TODO: This should probably just use a GaimStatus...
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
46 */
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
47 struct _GaimSavedStatus
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
48 {
11651
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
49 /**
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
50 * A "transient" status is one that was used recently by
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
51 * a Gaim user, but was not explicitly created using the
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
52 * saved status UI. For example, Gaim's previous status
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
53 * is saved in the status.xml file, but should not show
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
54 * up in the UI.
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
55 */
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
56 gboolean transient;
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
57
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
58 char *title;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
59 GaimStatusPrimitive type;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
60 char *message;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
61
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
62 GList *substatuses; /**< A list of GaimSavedStatusSub's. */
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
63 };
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
64
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
65 /*
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
66 * TODO: If an account is deleted, need to also delete any associated
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
67 * GaimSavedStatusSub's.
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
68 * TODO: If a GaimStatusType is deleted, need to also delete any
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
69 * associated GaimSavedStatusSub's?
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
70 */
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
71 struct _GaimSavedStatusSub
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
72 {
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
73 GaimAccount *account;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
74 const GaimStatusType *type;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
75 char *message;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
76 };
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
77
10423
3232e1a33899 [gaim-migrate @ 11675]
Mark Doliner <mark@kingant.net>
parents: 10420
diff changeset
78 static GList *saved_statuses = NULL;
10428
04c663ccbcb1 [gaim-migrate @ 11680]
Mark Doliner <mark@kingant.net>
parents: 10427
diff changeset
79 static guint save_timer = 0;
10423
3232e1a33899 [gaim-migrate @ 11675]
Mark Doliner <mark@kingant.net>
parents: 10420
diff changeset
80 static gboolean statuses_loaded = FALSE;
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
81
10427
16d63d8c26d8 [gaim-migrate @ 11679]
Mark Doliner <mark@kingant.net>
parents: 10426
diff changeset
82
10428
04c663ccbcb1 [gaim-migrate @ 11680]
Mark Doliner <mark@kingant.net>
parents: 10427
diff changeset
83 /*********************************************************************
04c663ccbcb1 [gaim-migrate @ 11680]
Mark Doliner <mark@kingant.net>
parents: 10427
diff changeset
84 * Private utility functions *
04c663ccbcb1 [gaim-migrate @ 11680]
Mark Doliner <mark@kingant.net>
parents: 10427
diff changeset
85 *********************************************************************/
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
86
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
87 static void
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
88 free_statussavedsub(GaimSavedStatusSub *substatus)
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
89 {
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
90 g_return_if_fail(substatus != NULL);
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
91
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
92 g_free(substatus->message);
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
93 g_free(substatus);
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
94 }
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
95
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
96 static void
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
97 free_statussaved(GaimSavedStatus *status)
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
98 {
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
99 g_return_if_fail(status != NULL);
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
100
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
101 g_free(status->title);
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
102 g_free(status->message);
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
103
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
104 while (status->substatuses != NULL)
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
105 {
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
106 GaimSavedStatusSub *substatus = status->substatuses->data;
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
107 status->substatuses = g_list_remove(status->substatuses, substatus);
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
108 free_statussavedsub(substatus);
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
109 }
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
110
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
111 g_free(status);
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
112 }
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
113
10428
04c663ccbcb1 [gaim-migrate @ 11680]
Mark Doliner <mark@kingant.net>
parents: 10427
diff changeset
114 /*********************************************************************
10429
e41f0668a648 [gaim-migrate @ 11681]
Mark Doliner <mark@kingant.net>
parents: 10428
diff changeset
115 * Writing to disk *
10428
04c663ccbcb1 [gaim-migrate @ 11680]
Mark Doliner <mark@kingant.net>
parents: 10427
diff changeset
116 *********************************************************************/
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
117
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
118 static xmlnode *
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
119 substatus_to_xmlnode(GaimSavedStatusSub *substatus)
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
120 {
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
121 xmlnode *node, *child;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
122
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
123 node = xmlnode_new("substatus");
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
124
10424
108151be77a3 [gaim-migrate @ 11676]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
125 child = xmlnode_new_child(node, "account");
108151be77a3 [gaim-migrate @ 11676]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
126 xmlnode_set_attrib(child, "protocol", gaim_account_get_protocol_id(substatus->account));
108151be77a3 [gaim-migrate @ 11676]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
127 xmlnode_insert_data(child, gaim_account_get_username(substatus->account), -1);
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
128
10424
108151be77a3 [gaim-migrate @ 11676]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
129 child = xmlnode_new_child(node, "state");
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
130 xmlnode_insert_data(child, gaim_status_type_get_id(substatus->type), -1);
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
131
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
132 if (substatus->message != NULL)
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
133 {
10424
108151be77a3 [gaim-migrate @ 11676]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
134 child = xmlnode_new_child(node, "message");
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
135 xmlnode_insert_data(child, substatus->message, -1);
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
136 }
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
137
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
138 return node;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
139 }
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
140
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
141 static xmlnode *
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
142 status_to_xmlnode(GaimSavedStatus *status)
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
143 {
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
144 xmlnode *node, *child;
11651
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
145 char transient[2];
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
146 GList *cur;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
147
11651
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
148 snprintf(transient, sizeof(transient), "%d", status->transient);
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
149
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
150 node = xmlnode_new("status");
11651
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
151 xmlnode_set_attrib(node, "transient", transient);
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
152 xmlnode_set_attrib(node, "name", status->title);
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
153
10424
108151be77a3 [gaim-migrate @ 11676]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
154 child = xmlnode_new_child(node, "state");
108151be77a3 [gaim-migrate @ 11676]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
155 xmlnode_insert_data(child, gaim_primitive_get_id_from_type(status->type), -1);
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
156
11651
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
157 if (status->message != NULL)
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
158 {
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
159 child = xmlnode_new_child(node, "message");
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
160 xmlnode_insert_data(child, status->message, -1);
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
161 }
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
162
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
163 for (cur = status->substatuses; cur != NULL; cur = cur->next)
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
164 {
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
165 child = substatus_to_xmlnode(cur->data);
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
166 xmlnode_insert_child(node, child);
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
167 }
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
168
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
169 return node;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
170 }
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
171
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
172 static xmlnode *
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
173 statuses_to_xmlnode(void)
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
174 {
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
175 xmlnode *node, *child;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
176 GList *cur;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
177
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
178 node = xmlnode_new("statuses");
10423
3232e1a33899 [gaim-migrate @ 11675]
Mark Doliner <mark@kingant.net>
parents: 10420
diff changeset
179 xmlnode_set_attrib(node, "version", "1.0");
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
180
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
181 for (cur = saved_statuses; cur != NULL; cur = cur->next)
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
182 {
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
183 child = status_to_xmlnode(cur->data);
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
184 xmlnode_insert_child(node, child);
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
185 }
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
186
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
187 return node;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
188 }
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
189
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
190 static void
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
191 sync_statuses(void)
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
192 {
10423
3232e1a33899 [gaim-migrate @ 11675]
Mark Doliner <mark@kingant.net>
parents: 10420
diff changeset
193 xmlnode *node;
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
194 char *data;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
195
10428
04c663ccbcb1 [gaim-migrate @ 11680]
Mark Doliner <mark@kingant.net>
parents: 10427
diff changeset
196 if (!statuses_loaded)
04c663ccbcb1 [gaim-migrate @ 11680]
Mark Doliner <mark@kingant.net>
parents: 10427
diff changeset
197 {
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
198 gaim_debug_error("status", "Attempted to save statuses before they "
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
199 "were read!\n");
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
200 return;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
201 }
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
202
10423
3232e1a33899 [gaim-migrate @ 11675]
Mark Doliner <mark@kingant.net>
parents: 10420
diff changeset
203 node = statuses_to_xmlnode();
3232e1a33899 [gaim-migrate @ 11675]
Mark Doliner <mark@kingant.net>
parents: 10420
diff changeset
204 data = xmlnode_to_formatted_str(node, NULL);
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
205 gaim_util_write_data_to_file("status.xml", data, -1);
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
206 g_free(data);
10423
3232e1a33899 [gaim-migrate @ 11675]
Mark Doliner <mark@kingant.net>
parents: 10420
diff changeset
207 xmlnode_free(node);
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
208 }
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
209
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
210 static gboolean
10428
04c663ccbcb1 [gaim-migrate @ 11680]
Mark Doliner <mark@kingant.net>
parents: 10427
diff changeset
211 save_cb(gpointer data)
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
212 {
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
213 sync_statuses();
10428
04c663ccbcb1 [gaim-migrate @ 11680]
Mark Doliner <mark@kingant.net>
parents: 10427
diff changeset
214 save_timer = 0;
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
215 return FALSE;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
216 }
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
217
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
218 static void
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
219 schedule_save(void)
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
220 {
10428
04c663ccbcb1 [gaim-migrate @ 11680]
Mark Doliner <mark@kingant.net>
parents: 10427
diff changeset
221 if (save_timer == 0)
04c663ccbcb1 [gaim-migrate @ 11680]
Mark Doliner <mark@kingant.net>
parents: 10427
diff changeset
222 save_timer = gaim_timeout_add(5000, save_cb, NULL);
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
223 }
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
224
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
225
10428
04c663ccbcb1 [gaim-migrate @ 11680]
Mark Doliner <mark@kingant.net>
parents: 10427
diff changeset
226 /*********************************************************************
04c663ccbcb1 [gaim-migrate @ 11680]
Mark Doliner <mark@kingant.net>
parents: 10427
diff changeset
227 * Reading from disk *
04c663ccbcb1 [gaim-migrate @ 11680]
Mark Doliner <mark@kingant.net>
parents: 10427
diff changeset
228 *********************************************************************/
04c663ccbcb1 [gaim-migrate @ 11680]
Mark Doliner <mark@kingant.net>
parents: 10427
diff changeset
229
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
230 static GaimSavedStatusSub *
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
231 parse_substatus(xmlnode *substatus)
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
232 {
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
233 GaimSavedStatusSub *ret;
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
234 xmlnode *node;
10425
9903182f2aac [gaim-migrate @ 11677]
Mark Doliner <mark@kingant.net>
parents: 10424
diff changeset
235 char *data;
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
236
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
237 ret = g_new0(GaimSavedStatusSub, 1);
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
238
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
239 /* Read the account */
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
240 node = xmlnode_get_child(substatus, "account");
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
241 if (node != NULL)
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
242 {
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
243 char *acct_name;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
244 const char *protocol;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
245 acct_name = xmlnode_get_data(node);
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
246 protocol = xmlnode_get_attrib(node, "protocol");
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
247 if ((acct_name != NULL) && (protocol != NULL))
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
248 ret->account = gaim_accounts_find(acct_name, protocol);
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
249 g_free(acct_name);
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
250 }
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
251
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
252 if (ret->account == NULL)
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
253 {
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
254 g_free(ret);
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
255 return NULL;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
256 }
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
257
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
258 /* Read the state */
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
259 node = xmlnode_get_child(substatus, "state");
10426
30d9ec7d001b [gaim-migrate @ 11678]
Mark Doliner <mark@kingant.net>
parents: 10425
diff changeset
260 if ((node != NULL) && ((data = xmlnode_get_data(node)) != NULL))
10425
9903182f2aac [gaim-migrate @ 11677]
Mark Doliner <mark@kingant.net>
parents: 10424
diff changeset
261 {
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
262 ret->type = gaim_status_type_find_with_id(
10425
9903182f2aac [gaim-migrate @ 11677]
Mark Doliner <mark@kingant.net>
parents: 10424
diff changeset
263 ret->account->status_types, data);
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
264 g_free(data);
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
265 }
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
266
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
267 /* Read the message */
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
268 node = xmlnode_get_child(substatus, "message");
10426
30d9ec7d001b [gaim-migrate @ 11678]
Mark Doliner <mark@kingant.net>
parents: 10425
diff changeset
269 if ((node != NULL) && ((data = xmlnode_get_data(node)) != NULL))
10425
9903182f2aac [gaim-migrate @ 11677]
Mark Doliner <mark@kingant.net>
parents: 10424
diff changeset
270 {
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
271 ret->message = data;
10425
9903182f2aac [gaim-migrate @ 11677]
Mark Doliner <mark@kingant.net>
parents: 10424
diff changeset
272 }
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
273
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
274 return ret;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
275 }
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
276
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
277 /**
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
278 * Parse a saved status and add it to the saved_statuses linked list.
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
279 *
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
280 * Here's an example of the XML for a saved status:
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
281 * <status name="Girls">
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
282 * <state>away</state>
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
283 * <message>I like the way that they walk
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
284 * And it's chill to hear them talk
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
285 * And I can always make them smile
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
286 * From White Castle to the Nile</message>
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
287 * <substatus>
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
288 * <account protocol='prpl-oscar'>markdoliner</account>
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
289 * <state>available</state>
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
290 * <message>The ladies man is here to answer your queries.</message>
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
291 * </substatus>
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
292 * <substatus>
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
293 * <account protocol='prpl-oscar'>giantgraypanda</account>
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
294 * <state>away</state>
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
295 * <message>A.C. ain't in charge no more.</message>
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
296 * </substatus>
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
297 * </status>
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
298 *
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
299 * I know. Moving, huh?
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
300 */
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
301 static GaimSavedStatus *
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
302 parse_status(xmlnode *status)
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
303 {
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
304 GaimSavedStatus *ret;
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
305 xmlnode *node;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
306 const char *attrib;
10425
9903182f2aac [gaim-migrate @ 11677]
Mark Doliner <mark@kingant.net>
parents: 10424
diff changeset
307 char *data;
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
308 int i;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
309
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
310 ret = g_new0(GaimSavedStatus, 1);
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
311
11651
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
312 /* Read the transient property */
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
313 attrib = xmlnode_get_attrib(status, "transient");
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
314 if ((attrib != NULL) && (attrib[0] == '1'))
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
315 ret->transient = TRUE;
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
316
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
317 /* Read the title */
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
318 attrib = xmlnode_get_attrib(status, "name");
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
319 if (attrib == NULL)
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
320 attrib = "No Title";
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
321 /* Ensure the title is unique */
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
322 ret->title = g_strdup(attrib);
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
323 i = 2;
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
324 while (gaim_savedstatus_find(ret->title) != NULL)
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
325 {
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
326 g_free(ret->title);
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
327 ret->title = g_strdup_printf("%s %d", attrib, i);
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
328 i++;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
329 }
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
330
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
331 /* Read the primitive status type */
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
332 node = xmlnode_get_child(status, "state");
10426
30d9ec7d001b [gaim-migrate @ 11678]
Mark Doliner <mark@kingant.net>
parents: 10425
diff changeset
333 if ((node != NULL) && ((data = xmlnode_get_data(node)) != NULL))
10425
9903182f2aac [gaim-migrate @ 11677]
Mark Doliner <mark@kingant.net>
parents: 10424
diff changeset
334 {
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
335 ret->type = gaim_primitive_get_type_from_id(data);
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
336 g_free(data);
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
337 }
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
338
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
339 /* Read the message */
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
340 node = xmlnode_get_child(status, "message");
10426
30d9ec7d001b [gaim-migrate @ 11678]
Mark Doliner <mark@kingant.net>
parents: 10425
diff changeset
341 if ((node != NULL) && ((data = xmlnode_get_data(node)) != NULL))
10425
9903182f2aac [gaim-migrate @ 11677]
Mark Doliner <mark@kingant.net>
parents: 10424
diff changeset
342 {
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
343 ret->message = data;
10425
9903182f2aac [gaim-migrate @ 11677]
Mark Doliner <mark@kingant.net>
parents: 10424
diff changeset
344 }
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
345
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
346 /* Read substatuses */
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
347 for (node = xmlnode_get_child(status, "status"); node != NULL;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
348 node = xmlnode_get_next_twin(node))
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
349 {
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
350 GaimSavedStatusSub *new;
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
351 new = parse_substatus(node);
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
352 if (new != NULL)
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
353 ret->substatuses = g_list_append(ret->substatuses, new);
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
354 }
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
355
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
356 return ret;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
357 }
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
358
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
359 /**
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
360 * Read the saved statuses from a file in the Gaim user dir.
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
361 *
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
362 * @return TRUE on success, FALSE on failure (if the file can not
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
363 * be opened, or if it contains invalid XML).
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
364 */
10425
9903182f2aac [gaim-migrate @ 11677]
Mark Doliner <mark@kingant.net>
parents: 10424
diff changeset
365 static void
9903182f2aac [gaim-migrate @ 11677]
Mark Doliner <mark@kingant.net>
parents: 10424
diff changeset
366 load_statuses(void)
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
367 {
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
368 xmlnode *statuses, *status;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
369
10426
30d9ec7d001b [gaim-migrate @ 11678]
Mark Doliner <mark@kingant.net>
parents: 10425
diff changeset
370 statuses_loaded = TRUE;
30d9ec7d001b [gaim-migrate @ 11678]
Mark Doliner <mark@kingant.net>
parents: 10425
diff changeset
371
10425
9903182f2aac [gaim-migrate @ 11677]
Mark Doliner <mark@kingant.net>
parents: 10424
diff changeset
372 statuses = gaim_util_read_xml_from_file("status.xml", _("saved statuses"));
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
373
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
374 if (statuses == NULL)
10425
9903182f2aac [gaim-migrate @ 11677]
Mark Doliner <mark@kingant.net>
parents: 10424
diff changeset
375 return;
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
376
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
377 for (status = xmlnode_get_child(statuses, "status"); status != NULL;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
378 status = xmlnode_get_next_twin(status))
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
379 {
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
380 GaimSavedStatus *new;
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
381 new = parse_status(status);
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
382 saved_statuses = g_list_append(saved_statuses, new);
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
383 }
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
384
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
385 xmlnode_free(statuses);
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
386 }
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
387
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
388
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
389 /**************************************************************************
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
390 * Saved status API
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
391 **************************************************************************/
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
392 GaimSavedStatus *
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
393 gaim_savedstatus_new(const char *title, GaimStatusPrimitive type)
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
394 {
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
395 GaimSavedStatus *status;
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
396
10420
854c972ea863 [gaim-migrate @ 11671]
Mark Doliner <mark@kingant.net>
parents: 10419
diff changeset
397 g_return_val_if_fail(gaim_savedstatus_find(title) == NULL, NULL);
854c972ea863 [gaim-migrate @ 11671]
Mark Doliner <mark@kingant.net>
parents: 10419
diff changeset
398
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
399 status = g_new0(GaimSavedStatus, 1);
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
400 status->title = g_strdup(title);
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
401 status->type = type;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
402
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
403 saved_statuses = g_list_append(saved_statuses, status);
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
404
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
405 schedule_save();
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
406
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
407 return status;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
408 }
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
409
10420
854c972ea863 [gaim-migrate @ 11671]
Mark Doliner <mark@kingant.net>
parents: 10419
diff changeset
410 void
11651
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
411 gaim_savedstatus_set_type(GaimSavedStatus *status, GaimStatusPrimitive type)
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
412 {
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
413 g_return_if_fail(status != NULL);
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
414
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
415 status->type = type;
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
416
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
417 schedule_save();
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
418 }
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
419
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
420 void
10420
854c972ea863 [gaim-migrate @ 11671]
Mark Doliner <mark@kingant.net>
parents: 10419
diff changeset
421 gaim_savedstatus_set_message(GaimSavedStatus *status, const char *message)
854c972ea863 [gaim-migrate @ 11671]
Mark Doliner <mark@kingant.net>
parents: 10419
diff changeset
422 {
854c972ea863 [gaim-migrate @ 11671]
Mark Doliner <mark@kingant.net>
parents: 10419
diff changeset
423 g_return_if_fail(status != NULL);
854c972ea863 [gaim-migrate @ 11671]
Mark Doliner <mark@kingant.net>
parents: 10419
diff changeset
424
854c972ea863 [gaim-migrate @ 11671]
Mark Doliner <mark@kingant.net>
parents: 10419
diff changeset
425 g_free(status->message);
854c972ea863 [gaim-migrate @ 11671]
Mark Doliner <mark@kingant.net>
parents: 10419
diff changeset
426 status->message = g_strdup(message);
854c972ea863 [gaim-migrate @ 11671]
Mark Doliner <mark@kingant.net>
parents: 10419
diff changeset
427
854c972ea863 [gaim-migrate @ 11671]
Mark Doliner <mark@kingant.net>
parents: 10419
diff changeset
428 schedule_save();
854c972ea863 [gaim-migrate @ 11671]
Mark Doliner <mark@kingant.net>
parents: 10419
diff changeset
429 }
854c972ea863 [gaim-migrate @ 11671]
Mark Doliner <mark@kingant.net>
parents: 10419
diff changeset
430
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
431 gboolean
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
432 gaim_savedstatus_delete(const char *title)
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
433 {
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
434 GaimSavedStatus *status;
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
435
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
436 status = gaim_savedstatus_find(title);
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
437
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
438 if (status == NULL)
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
439 return FALSE;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
440
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
441 saved_statuses = g_list_remove(saved_statuses, status);
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
442 free_statussaved(status);
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
443
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
444 schedule_save();
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
445
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
446 return TRUE;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
447 }
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
448
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
449 const GList *
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
450 gaim_savedstatuses_get_all(void)
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
451 {
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
452 return saved_statuses;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
453 }
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
454
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
455 GaimSavedStatus *
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
456 gaim_savedstatus_find(const char *title)
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
457 {
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
458 GList *l;
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
459 GaimSavedStatus *status;
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
460
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
461 for (l = saved_statuses; l != NULL; l = g_list_next(l))
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
462 {
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
463 status = (GaimSavedStatus *)l->data;
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
464 if (!strcmp(status->title, title))
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
465 return status;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
466 }
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
467
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
468 return NULL;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
469 }
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
470
11651
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
471 gboolean
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
472 gaim_savedstatus_is_transient(const GaimSavedStatus *saved_status)
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
473 {
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
474 return saved_status->transient;
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
475 }
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
476
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
477 const char *
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
478 gaim_savedstatus_get_title(const GaimSavedStatus *saved_status)
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
479 {
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
480 return saved_status->title;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
481 }
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
482
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
483 GaimStatusPrimitive
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
484 gaim_savedstatus_get_type(const GaimSavedStatus *saved_status)
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
485 {
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
486 return saved_status->type;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
487 }
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
488
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
489 const char *
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
490 gaim_savedstatus_get_message(const GaimSavedStatus *saved_status)
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
491 {
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
492 return saved_status->message;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
493 }
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
494
11651
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
495 gboolean
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
496 gaim_savedstatus_has_substatuses(const GaimSavedStatus *saved_status)
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
497 {
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
498 return (saved_status->substatuses != NULL);
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
499 }
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
500
11724
a8ec0a291d14 [gaim-migrate @ 14015]
Mark Doliner <mark@kingant.net>
parents: 11651
diff changeset
501 void
a8ec0a291d14 [gaim-migrate @ 14015]
Mark Doliner <mark@kingant.net>
parents: 11651
diff changeset
502 gaim_savedstatus_activate(const GaimSavedStatus *saved_status)
a8ec0a291d14 [gaim-migrate @ 14015]
Mark Doliner <mark@kingant.net>
parents: 11651
diff changeset
503 {
11733
ef511dec9903 [gaim-migrate @ 14024]
Mark Doliner <mark@kingant.net>
parents: 11727
diff changeset
504 GList *accounts, *node;
11724
a8ec0a291d14 [gaim-migrate @ 14015]
Mark Doliner <mark@kingant.net>
parents: 11651
diff changeset
505
11727
8657ad65e257 [gaim-migrate @ 14018]
Mark Doliner <mark@kingant.net>
parents: 11724
diff changeset
506 g_return_if_fail(saved_status != NULL);
8657ad65e257 [gaim-migrate @ 14018]
Mark Doliner <mark@kingant.net>
parents: 11724
diff changeset
507
11724
a8ec0a291d14 [gaim-migrate @ 14015]
Mark Doliner <mark@kingant.net>
parents: 11651
diff changeset
508 accounts = gaim_accounts_get_all_active();
a8ec0a291d14 [gaim-migrate @ 14015]
Mark Doliner <mark@kingant.net>
parents: 11651
diff changeset
509
11733
ef511dec9903 [gaim-migrate @ 14024]
Mark Doliner <mark@kingant.net>
parents: 11727
diff changeset
510 for (node = accounts; node != NULL; node = node->next)
11724
a8ec0a291d14 [gaim-migrate @ 14015]
Mark Doliner <mark@kingant.net>
parents: 11651
diff changeset
511 {
a8ec0a291d14 [gaim-migrate @ 14015]
Mark Doliner <mark@kingant.net>
parents: 11651
diff changeset
512 GaimAccount *account;
a8ec0a291d14 [gaim-migrate @ 14015]
Mark Doliner <mark@kingant.net>
parents: 11651
diff changeset
513
11733
ef511dec9903 [gaim-migrate @ 14024]
Mark Doliner <mark@kingant.net>
parents: 11727
diff changeset
514 account = node->data;
11724
a8ec0a291d14 [gaim-migrate @ 14015]
Mark Doliner <mark@kingant.net>
parents: 11651
diff changeset
515 gaim_savedstatus_activate_for_account(saved_status, account);
a8ec0a291d14 [gaim-migrate @ 14015]
Mark Doliner <mark@kingant.net>
parents: 11651
diff changeset
516 }
11733
ef511dec9903 [gaim-migrate @ 14024]
Mark Doliner <mark@kingant.net>
parents: 11727
diff changeset
517
ef511dec9903 [gaim-migrate @ 14024]
Mark Doliner <mark@kingant.net>
parents: 11727
diff changeset
518 g_list_free(accounts);
11724
a8ec0a291d14 [gaim-migrate @ 14015]
Mark Doliner <mark@kingant.net>
parents: 11651
diff changeset
519 }
a8ec0a291d14 [gaim-migrate @ 14015]
Mark Doliner <mark@kingant.net>
parents: 11651
diff changeset
520
a8ec0a291d14 [gaim-migrate @ 14015]
Mark Doliner <mark@kingant.net>
parents: 11651
diff changeset
521 void
a8ec0a291d14 [gaim-migrate @ 14015]
Mark Doliner <mark@kingant.net>
parents: 11651
diff changeset
522 gaim_savedstatus_activate_for_account(const GaimSavedStatus *saved_status,
a8ec0a291d14 [gaim-migrate @ 14015]
Mark Doliner <mark@kingant.net>
parents: 11651
diff changeset
523 GaimAccount *account)
a8ec0a291d14 [gaim-migrate @ 14015]
Mark Doliner <mark@kingant.net>
parents: 11651
diff changeset
524 {
a8ec0a291d14 [gaim-migrate @ 14015]
Mark Doliner <mark@kingant.net>
parents: 11651
diff changeset
525 GaimStatusType *status_type;
a8ec0a291d14 [gaim-migrate @ 14015]
Mark Doliner <mark@kingant.net>
parents: 11651
diff changeset
526
11727
8657ad65e257 [gaim-migrate @ 14018]
Mark Doliner <mark@kingant.net>
parents: 11724
diff changeset
527 g_return_if_fail(saved_status != NULL);
8657ad65e257 [gaim-migrate @ 14018]
Mark Doliner <mark@kingant.net>
parents: 11724
diff changeset
528 g_return_if_fail(account != NULL);
8657ad65e257 [gaim-migrate @ 14018]
Mark Doliner <mark@kingant.net>
parents: 11724
diff changeset
529
11739
a25be0e70a67 [gaim-migrate @ 14030]
Mark Doliner <mark@kingant.net>
parents: 11733
diff changeset
530 status_type = gaim_account_get_status_type_with_primitive(account, saved_status->type);
a25be0e70a67 [gaim-migrate @ 14030]
Mark Doliner <mark@kingant.net>
parents: 11733
diff changeset
531
a25be0e70a67 [gaim-migrate @ 14030]
Mark Doliner <mark@kingant.net>
parents: 11733
diff changeset
532 if (status_type != NULL)
11724
a8ec0a291d14 [gaim-migrate @ 14015]
Mark Doliner <mark@kingant.net>
parents: 11651
diff changeset
533 {
11739
a25be0e70a67 [gaim-migrate @ 14030]
Mark Doliner <mark@kingant.net>
parents: 11733
diff changeset
534 if (saved_status->message != NULL)
a25be0e70a67 [gaim-migrate @ 14030]
Mark Doliner <mark@kingant.net>
parents: 11733
diff changeset
535 gaim_account_set_status(account, gaim_status_type_get_id(status_type),
a25be0e70a67 [gaim-migrate @ 14030]
Mark Doliner <mark@kingant.net>
parents: 11733
diff changeset
536 TRUE, "message", saved_status->message, NULL);
a25be0e70a67 [gaim-migrate @ 14030]
Mark Doliner <mark@kingant.net>
parents: 11733
diff changeset
537 else
a25be0e70a67 [gaim-migrate @ 14030]
Mark Doliner <mark@kingant.net>
parents: 11733
diff changeset
538 gaim_account_set_status(account, gaim_status_type_get_id(status_type),
a25be0e70a67 [gaim-migrate @ 14030]
Mark Doliner <mark@kingant.net>
parents: 11733
diff changeset
539 TRUE, NULL);
11724
a8ec0a291d14 [gaim-migrate @ 14015]
Mark Doliner <mark@kingant.net>
parents: 11651
diff changeset
540 }
a8ec0a291d14 [gaim-migrate @ 14015]
Mark Doliner <mark@kingant.net>
parents: 11651
diff changeset
541 }
a8ec0a291d14 [gaim-migrate @ 14015]
Mark Doliner <mark@kingant.net>
parents: 11651
diff changeset
542
11318
519dc2186438 [gaim-migrate @ 13521]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10738
diff changeset
543 void *
519dc2186438 [gaim-migrate @ 13521]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10738
diff changeset
544 gaim_savedstatuses_get_handle(void)
519dc2186438 [gaim-migrate @ 13521]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10738
diff changeset
545 {
519dc2186438 [gaim-migrate @ 13521]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10738
diff changeset
546 static int handle;
519dc2186438 [gaim-migrate @ 13521]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10738
diff changeset
547
519dc2186438 [gaim-migrate @ 13521]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10738
diff changeset
548 return &handle;
519dc2186438 [gaim-migrate @ 13521]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10738
diff changeset
549 }
519dc2186438 [gaim-migrate @ 13521]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10738
diff changeset
550
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
551 void
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
552 gaim_savedstatuses_init(void)
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
553 {
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
554 load_statuses();
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
555 }
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
556
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
557 void
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
558 gaim_savedstatuses_uninit(void)
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
559 {
10428
04c663ccbcb1 [gaim-migrate @ 11680]
Mark Doliner <mark@kingant.net>
parents: 10427
diff changeset
560 if (save_timer != 0)
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
561 {
10428
04c663ccbcb1 [gaim-migrate @ 11680]
Mark Doliner <mark@kingant.net>
parents: 10427
diff changeset
562 gaim_timeout_remove(save_timer);
04c663ccbcb1 [gaim-migrate @ 11680]
Mark Doliner <mark@kingant.net>
parents: 10427
diff changeset
563 save_timer = 0;
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
564 sync_statuses();
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
565 }
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
566
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
567 while (saved_statuses != NULL) {
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
568 GaimSavedStatus *status = saved_statuses->data;
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
569 saved_statuses = g_list_remove(saved_statuses, status);
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
570 free_statussaved(status);
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
571 }
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
572 }