annotate src/savedstatuses.c @ 12147:9ce0a5f9443b

[gaim-migrate @ 14448] GaimConnection is a type, whereas GaimConnect is not. This makes Sametime compile after rlaager's last commit. committer: Tailor Script <tailor@pidgin.im>
author Ethan Blanton <elb@pidgin.im>
date Sat, 19 Nov 2005 01:37:11 +0000
parents 3c1bac709234
children 0ab1c9916dc2
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 /**
12125
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
35 * The information stores a snap-shot of the statuses of all
10418
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.
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
44 */
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
45 struct _GaimSavedStatus
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
46 {
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
47 char *title;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
48 GaimStatusPrimitive type;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
49 char *message;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
50
12125
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
51 /** The timestamp when this saved status was created. This must be unique. */
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
52 time_t creation_time;
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
53
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
54 time_t lastused;
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
55
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
56 GList *substatuses; /**< A list of GaimSavedStatusSub's. */
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
57 };
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
58
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
59 /*
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
60 * 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
61 * associated GaimSavedStatusSub's?
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
62 */
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
63 struct _GaimSavedStatusSub
10418
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 GaimAccount *account;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
66 const GaimStatusType *type;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
67 char *message;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
68 };
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
69
12125
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
70 static GList *saved_statuses = NULL;
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
71 static guint save_timer = 0;
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
72 static gboolean statuses_loaded = FALSE;
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
73
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
74 /*
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
75 * This hash table keeps track of which timestamps we've
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
76 * used so that we don't have two saved statuses with the
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
77 * same 'creation_time' timestamp. The 'created' timestamp
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
78 * is used as a unique identifier.
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
79 *
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
80 * So the key in this hash table is the creation_time and
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
81 * the value is a pointer to the GaimSavedStatus.
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
82 */
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
83 static GHashTable *creation_times;
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
84
10427
16d63d8c26d8 [gaim-migrate @ 11679]
Mark Doliner <mark@kingant.net>
parents: 10426
diff changeset
85
10428
04c663ccbcb1 [gaim-migrate @ 11680]
Mark Doliner <mark@kingant.net>
parents: 10427
diff changeset
86 /*********************************************************************
04c663ccbcb1 [gaim-migrate @ 11680]
Mark Doliner <mark@kingant.net>
parents: 10427
diff changeset
87 * Private utility functions *
04c663ccbcb1 [gaim-migrate @ 11680]
Mark Doliner <mark@kingant.net>
parents: 10427
diff changeset
88 *********************************************************************/
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 static void
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
91 free_statussavedsub(GaimSavedStatusSub *substatus)
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
92 {
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
93 g_return_if_fail(substatus != NULL);
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 g_free(substatus->message);
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
96 g_free(substatus);
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
97 }
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 static void
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
100 free_statussaved(GaimSavedStatus *status)
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
101 {
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
102 g_return_if_fail(status != NULL);
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 g_free(status->title);
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
105 g_free(status->message);
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
106
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
107 while (status->substatuses != NULL)
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
108 {
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
109 GaimSavedStatusSub *substatus = status->substatuses->data;
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
110 status->substatuses = g_list_remove(status->substatuses, substatus);
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
111 free_statussavedsub(substatus);
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
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
114 g_free(status);
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
115 }
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
116
12125
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
117 /*
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
118 * Set the timestamp for when this saved status was created, and
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
119 * make sure it is unique.
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
120 */
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
121 static void
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
122 set_creation_time(GaimSavedStatus *status, time_t creation_time)
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
123 {
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
124 g_return_if_fail(status != NULL);
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
125
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
126 /* Avoid using 0 because it's an invalid hash key */
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
127 status->creation_time = creation_time != 0 ? creation_time : 1;
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
128
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
129 while (g_hash_table_lookup(creation_times, &status->creation_time) != NULL)
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
130 status->creation_time++;
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
131
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
132 g_hash_table_insert(creation_times,
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
133 &status->creation_time,
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
134 status);
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
135 }
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
136
10428
04c663ccbcb1 [gaim-migrate @ 11680]
Mark Doliner <mark@kingant.net>
parents: 10427
diff changeset
137 /*********************************************************************
10429
e41f0668a648 [gaim-migrate @ 11681]
Mark Doliner <mark@kingant.net>
parents: 10428
diff changeset
138 * Writing to disk *
10428
04c663ccbcb1 [gaim-migrate @ 11680]
Mark Doliner <mark@kingant.net>
parents: 10427
diff changeset
139 *********************************************************************/
10418
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 substatus_to_xmlnode(GaimSavedStatusSub *substatus)
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;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
145
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
146 node = xmlnode_new("substatus");
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
147
10424
108151be77a3 [gaim-migrate @ 11676]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
148 child = xmlnode_new_child(node, "account");
108151be77a3 [gaim-migrate @ 11676]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
149 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
150 xmlnode_insert_data(child, gaim_account_get_username(substatus->account), -1);
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
151
10424
108151be77a3 [gaim-migrate @ 11676]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
152 child = xmlnode_new_child(node, "state");
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
153 xmlnode_insert_data(child, gaim_status_type_get_id(substatus->type), -1);
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
154
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
155 if (substatus->message != NULL)
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
156 {
10424
108151be77a3 [gaim-migrate @ 11676]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
157 child = xmlnode_new_child(node, "message");
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
158 xmlnode_insert_data(child, substatus->message, -1);
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
159 }
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
160
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
161 return node;
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
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
164 static xmlnode *
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
165 status_to_xmlnode(GaimSavedStatus *status)
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
166 {
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
167 xmlnode *node, *child;
12125
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
168 char buf[21];
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
169 GList *cur;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
170
12125
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
171 node = xmlnode_new("status");
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
172 if (status->title != NULL)
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
173 xmlnode_set_attrib(node, "name", status->title);
11651
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
174
12125
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
175 snprintf(buf, sizeof(buf), "%lu", status->creation_time);
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
176 xmlnode_set_attrib(node, "created", buf);
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
177
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
178 snprintf(buf, sizeof(buf), "%lu", status->lastused);
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
179 xmlnode_set_attrib(node, "lastused", buf);
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
180
10424
108151be77a3 [gaim-migrate @ 11676]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
181 child = xmlnode_new_child(node, "state");
108151be77a3 [gaim-migrate @ 11676]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
182 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
183
11651
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
184 if (status->message != NULL)
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
185 {
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
186 child = xmlnode_new_child(node, "message");
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
187 xmlnode_insert_data(child, status->message, -1);
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
188 }
10418
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 for (cur = status->substatuses; cur != NULL; cur = cur->next)
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
191 {
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
192 child = substatus_to_xmlnode(cur->data);
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
193 xmlnode_insert_child(node, child);
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
194 }
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
195
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
196 return node;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
197 }
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
198
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
199 static xmlnode *
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
200 statuses_to_xmlnode(void)
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 xmlnode *node, *child;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
203 GList *cur;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
204
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
205 node = xmlnode_new("statuses");
10423
3232e1a33899 [gaim-migrate @ 11675]
Mark Doliner <mark@kingant.net>
parents: 10420
diff changeset
206 xmlnode_set_attrib(node, "version", "1.0");
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
207
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
208 for (cur = saved_statuses; cur != NULL; cur = cur->next)
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 child = status_to_xmlnode(cur->data);
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
211 xmlnode_insert_child(node, child);
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
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
214 return node;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
215 }
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 static void
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
218 sync_statuses(void)
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
219 {
10423
3232e1a33899 [gaim-migrate @ 11675]
Mark Doliner <mark@kingant.net>
parents: 10420
diff changeset
220 xmlnode *node;
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
221 char *data;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
222
10428
04c663ccbcb1 [gaim-migrate @ 11680]
Mark Doliner <mark@kingant.net>
parents: 10427
diff changeset
223 if (!statuses_loaded)
04c663ccbcb1 [gaim-migrate @ 11680]
Mark Doliner <mark@kingant.net>
parents: 10427
diff changeset
224 {
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
225 gaim_debug_error("status", "Attempted to save statuses before they "
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
226 "were read!\n");
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
227 return;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
228 }
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
229
10423
3232e1a33899 [gaim-migrate @ 11675]
Mark Doliner <mark@kingant.net>
parents: 10420
diff changeset
230 node = statuses_to_xmlnode();
3232e1a33899 [gaim-migrate @ 11675]
Mark Doliner <mark@kingant.net>
parents: 10420
diff changeset
231 data = xmlnode_to_formatted_str(node, NULL);
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
232 gaim_util_write_data_to_file("status.xml", data, -1);
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
233 g_free(data);
10423
3232e1a33899 [gaim-migrate @ 11675]
Mark Doliner <mark@kingant.net>
parents: 10420
diff changeset
234 xmlnode_free(node);
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
235 }
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
236
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
237 static gboolean
10428
04c663ccbcb1 [gaim-migrate @ 11680]
Mark Doliner <mark@kingant.net>
parents: 10427
diff changeset
238 save_cb(gpointer data)
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
239 {
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
240 sync_statuses();
10428
04c663ccbcb1 [gaim-migrate @ 11680]
Mark Doliner <mark@kingant.net>
parents: 10427
diff changeset
241 save_timer = 0;
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
242 return FALSE;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
243 }
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
244
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
245 static void
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
246 schedule_save(void)
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
247 {
10428
04c663ccbcb1 [gaim-migrate @ 11680]
Mark Doliner <mark@kingant.net>
parents: 10427
diff changeset
248 if (save_timer == 0)
04c663ccbcb1 [gaim-migrate @ 11680]
Mark Doliner <mark@kingant.net>
parents: 10427
diff changeset
249 save_timer = gaim_timeout_add(5000, save_cb, NULL);
10418
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
10428
04c663ccbcb1 [gaim-migrate @ 11680]
Mark Doliner <mark@kingant.net>
parents: 10427
diff changeset
253 /*********************************************************************
04c663ccbcb1 [gaim-migrate @ 11680]
Mark Doliner <mark@kingant.net>
parents: 10427
diff changeset
254 * Reading from disk *
04c663ccbcb1 [gaim-migrate @ 11680]
Mark Doliner <mark@kingant.net>
parents: 10427
diff changeset
255 *********************************************************************/
04c663ccbcb1 [gaim-migrate @ 11680]
Mark Doliner <mark@kingant.net>
parents: 10427
diff changeset
256
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
257 static GaimSavedStatusSub *
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
258 parse_substatus(xmlnode *substatus)
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
259 {
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
260 GaimSavedStatusSub *ret;
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
261 xmlnode *node;
10425
9903182f2aac [gaim-migrate @ 11677]
Mark Doliner <mark@kingant.net>
parents: 10424
diff changeset
262 char *data;
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
263
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
264 ret = g_new0(GaimSavedStatusSub, 1);
10418
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 /* Read the account */
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
267 node = xmlnode_get_child(substatus, "account");
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
268 if (node != NULL)
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
269 {
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
270 char *acct_name;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
271 const char *protocol;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
272 acct_name = xmlnode_get_data(node);
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
273 protocol = xmlnode_get_attrib(node, "protocol");
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
274 if ((acct_name != NULL) && (protocol != NULL))
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
275 ret->account = gaim_accounts_find(acct_name, protocol);
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
276 g_free(acct_name);
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
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
279 if (ret->account == NULL)
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
280 {
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
281 g_free(ret);
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
282 return NULL;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
283 }
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
284
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
285 /* Read the state */
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
286 node = xmlnode_get_child(substatus, "state");
10426
30d9ec7d001b [gaim-migrate @ 11678]
Mark Doliner <mark@kingant.net>
parents: 10425
diff changeset
287 if ((node != NULL) && ((data = xmlnode_get_data(node)) != NULL))
10425
9903182f2aac [gaim-migrate @ 11677]
Mark Doliner <mark@kingant.net>
parents: 10424
diff changeset
288 {
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
289 ret->type = gaim_status_type_find_with_id(
10425
9903182f2aac [gaim-migrate @ 11677]
Mark Doliner <mark@kingant.net>
parents: 10424
diff changeset
290 ret->account->status_types, data);
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
291 g_free(data);
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
292 }
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
293
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
294 /* Read the message */
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
295 node = xmlnode_get_child(substatus, "message");
10426
30d9ec7d001b [gaim-migrate @ 11678]
Mark Doliner <mark@kingant.net>
parents: 10425
diff changeset
296 if ((node != NULL) && ((data = xmlnode_get_data(node)) != NULL))
10425
9903182f2aac [gaim-migrate @ 11677]
Mark Doliner <mark@kingant.net>
parents: 10424
diff changeset
297 {
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
298 ret->message = data;
10425
9903182f2aac [gaim-migrate @ 11677]
Mark Doliner <mark@kingant.net>
parents: 10424
diff changeset
299 }
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
300
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
301 return ret;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
302 }
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
303
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
304 /**
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
305 * 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
306 *
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
307 * Here's an example of the XML for a saved status:
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
308 * <status name="Girls">
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
309 * <state>away</state>
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
310 * <message>I like the way that they walk
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
311 * And it's chill to hear them talk
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
312 * And I can always make them smile
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
313 * From White Castle to the Nile</message>
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
314 * <substatus>
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
315 * <account protocol='prpl-oscar'>markdoliner</account>
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
316 * <state>available</state>
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
317 * <message>The ladies man is here to answer your queries.</message>
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
318 * </substatus>
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
319 * <substatus>
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
320 * <account protocol='prpl-oscar'>giantgraypanda</account>
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
321 * <state>away</state>
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
322 * <message>A.C. ain't in charge no more.</message>
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
323 * </substatus>
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
324 * </status>
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 * I know. Moving, huh?
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
327 */
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
328 static GaimSavedStatus *
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
329 parse_status(xmlnode *status)
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
330 {
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
331 GaimSavedStatus *ret;
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
332 xmlnode *node;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
333 const char *attrib;
10425
9903182f2aac [gaim-migrate @ 11677]
Mark Doliner <mark@kingant.net>
parents: 10424
diff changeset
334 char *data;
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
335 int i;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
336
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
337 ret = g_new0(GaimSavedStatus, 1);
10418
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 title */
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
340 attrib = xmlnode_get_attrib(status, "name");
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
341 ret->title = g_strdup(attrib);
12125
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
342
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
343 if (ret->title != NULL)
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
344 {
12125
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
345 /* Ensure the title is unique */
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
346 i = 2;
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
347 while (gaim_savedstatus_find(ret->title) != NULL)
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
348 {
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
349 g_free(ret->title);
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
350 ret->title = g_strdup_printf("%s %d", attrib, i);
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
351 i++;
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
352 }
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
353 }
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
354
12125
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
355 /* Read the creation time */
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
356 attrib = xmlnode_get_attrib(status, "created");
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
357 set_creation_time(ret, (attrib != NULL ? atol(attrib) : 0));
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
358
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
359 /* Read the last used time */
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
360 attrib = xmlnode_get_attrib(status, "lastused");
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
361 ret->lastused = (attrib != NULL ? atol(attrib) : 0);
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
362
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
363 /* Read the primitive status type */
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
364 node = xmlnode_get_child(status, "state");
10426
30d9ec7d001b [gaim-migrate @ 11678]
Mark Doliner <mark@kingant.net>
parents: 10425
diff changeset
365 if ((node != NULL) && ((data = xmlnode_get_data(node)) != NULL))
10425
9903182f2aac [gaim-migrate @ 11677]
Mark Doliner <mark@kingant.net>
parents: 10424
diff changeset
366 {
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
367 ret->type = gaim_primitive_get_type_from_id(data);
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
368 g_free(data);
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
369 }
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
370
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
371 /* Read the message */
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
372 node = xmlnode_get_child(status, "message");
10426
30d9ec7d001b [gaim-migrate @ 11678]
Mark Doliner <mark@kingant.net>
parents: 10425
diff changeset
373 if ((node != NULL) && ((data = xmlnode_get_data(node)) != NULL))
10425
9903182f2aac [gaim-migrate @ 11677]
Mark Doliner <mark@kingant.net>
parents: 10424
diff changeset
374 {
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
375 ret->message = data;
10425
9903182f2aac [gaim-migrate @ 11677]
Mark Doliner <mark@kingant.net>
parents: 10424
diff changeset
376 }
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
377
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
378 /* Read substatuses */
12056
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
379 for (node = xmlnode_get_child(status, "substatus"); node != NULL;
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
380 node = xmlnode_get_next_twin(node))
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
381 {
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
382 GaimSavedStatusSub *new;
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
383 new = parse_substatus(node);
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
384 if (new != NULL)
12056
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
385 ret->substatuses = g_list_prepend(ret->substatuses, new);
10418
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 return ret;
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
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
391 /**
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
392 * Read the saved statuses from a file in the Gaim user dir.
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
393 *
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
394 * @return TRUE on success, FALSE on failure (if the file can not
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
395 * be opened, or if it contains invalid XML).
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
396 */
10425
9903182f2aac [gaim-migrate @ 11677]
Mark Doliner <mark@kingant.net>
parents: 10424
diff changeset
397 static void
9903182f2aac [gaim-migrate @ 11677]
Mark Doliner <mark@kingant.net>
parents: 10424
diff changeset
398 load_statuses(void)
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
399 {
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
400 xmlnode *statuses, *status;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
401
10426
30d9ec7d001b [gaim-migrate @ 11678]
Mark Doliner <mark@kingant.net>
parents: 10425
diff changeset
402 statuses_loaded = TRUE;
30d9ec7d001b [gaim-migrate @ 11678]
Mark Doliner <mark@kingant.net>
parents: 10425
diff changeset
403
10425
9903182f2aac [gaim-migrate @ 11677]
Mark Doliner <mark@kingant.net>
parents: 10424
diff changeset
404 statuses = gaim_util_read_xml_from_file("status.xml", _("saved statuses"));
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
405
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
406 if (statuses == NULL)
10425
9903182f2aac [gaim-migrate @ 11677]
Mark Doliner <mark@kingant.net>
parents: 10424
diff changeset
407 return;
10418
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 for (status = xmlnode_get_child(statuses, "status"); status != NULL;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
410 status = xmlnode_get_next_twin(status))
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
411 {
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
412 GaimSavedStatus *new;
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
413 new = parse_status(status);
12056
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
414 saved_statuses = g_list_prepend(saved_statuses, new);
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
415 }
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
416
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
417 xmlnode_free(statuses);
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
418 }
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
419
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
420
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
421 /**************************************************************************
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
422 * Saved status API
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
423 **************************************************************************/
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
424 GaimSavedStatus *
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
425 gaim_savedstatus_new(const char *title, GaimStatusPrimitive type)
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
426 {
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
427 GaimSavedStatus *status;
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
428
12056
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
429 /* Make sure we don't already have a saved status with this title. */
12125
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
430 if (title != NULL)
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
431 g_return_val_if_fail(gaim_savedstatus_find(title) == NULL, NULL);
10420
854c972ea863 [gaim-migrate @ 11671]
Mark Doliner <mark@kingant.net>
parents: 10419
diff changeset
432
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
433 status = g_new0(GaimSavedStatus, 1);
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
434 status->title = g_strdup(title);
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
435 status->type = type;
12125
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
436 set_creation_time(status, time(NULL));
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
437
12056
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
438 saved_statuses = g_list_prepend(saved_statuses, status);
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
439
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
440 schedule_save();
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
441
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
442 return 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
10420
854c972ea863 [gaim-migrate @ 11671]
Mark Doliner <mark@kingant.net>
parents: 10419
diff changeset
445 void
12056
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
446 gaim_savedstatus_set_title(GaimSavedStatus *status, const char *title)
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
447 {
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
448 g_return_if_fail(status != NULL);
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
449
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
450 /* Make sure we don't already have a saved status with this title. */
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
451 g_return_if_fail(gaim_savedstatus_find(title) == NULL);
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
452
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
453 g_free(status->title);
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
454 status->title = g_strdup(title);
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
455
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
456 schedule_save();
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
457 }
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
458
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
459 void
11651
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
460 gaim_savedstatus_set_type(GaimSavedStatus *status, GaimStatusPrimitive type)
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
461 {
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
462 g_return_if_fail(status != NULL);
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
463
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
464 status->type = type;
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
465
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
466 schedule_save();
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
467 }
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
468
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
469 void
10420
854c972ea863 [gaim-migrate @ 11671]
Mark Doliner <mark@kingant.net>
parents: 10419
diff changeset
470 gaim_savedstatus_set_message(GaimSavedStatus *status, const char *message)
854c972ea863 [gaim-migrate @ 11671]
Mark Doliner <mark@kingant.net>
parents: 10419
diff changeset
471 {
854c972ea863 [gaim-migrate @ 11671]
Mark Doliner <mark@kingant.net>
parents: 10419
diff changeset
472 g_return_if_fail(status != NULL);
854c972ea863 [gaim-migrate @ 11671]
Mark Doliner <mark@kingant.net>
parents: 10419
diff changeset
473
854c972ea863 [gaim-migrate @ 11671]
Mark Doliner <mark@kingant.net>
parents: 10419
diff changeset
474 g_free(status->message);
854c972ea863 [gaim-migrate @ 11671]
Mark Doliner <mark@kingant.net>
parents: 10419
diff changeset
475 status->message = g_strdup(message);
854c972ea863 [gaim-migrate @ 11671]
Mark Doliner <mark@kingant.net>
parents: 10419
diff changeset
476
854c972ea863 [gaim-migrate @ 11671]
Mark Doliner <mark@kingant.net>
parents: 10419
diff changeset
477 schedule_save();
854c972ea863 [gaim-migrate @ 11671]
Mark Doliner <mark@kingant.net>
parents: 10419
diff changeset
478 }
854c972ea863 [gaim-migrate @ 11671]
Mark Doliner <mark@kingant.net>
parents: 10419
diff changeset
479
12056
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
480 void
12080
3b52d94437f3 [gaim-migrate @ 14377]
Mark Doliner <mark@kingant.net>
parents: 12056
diff changeset
481 gaim_savedstatus_set_substatus(GaimSavedStatus *saved_status,
3b52d94437f3 [gaim-migrate @ 14377]
Mark Doliner <mark@kingant.net>
parents: 12056
diff changeset
482 const GaimAccount *account,
3b52d94437f3 [gaim-migrate @ 14377]
Mark Doliner <mark@kingant.net>
parents: 12056
diff changeset
483 const GaimStatusType *type,
3b52d94437f3 [gaim-migrate @ 14377]
Mark Doliner <mark@kingant.net>
parents: 12056
diff changeset
484 const char *message)
12056
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
485 {
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
486 GaimSavedStatusSub *substatus;
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
487
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
488 g_return_if_fail(saved_status != NULL);
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
489 g_return_if_fail(account != NULL);
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
490 g_return_if_fail(type != NULL);
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
491
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
492 /* Find an existing substatus or create a new one */
12080
3b52d94437f3 [gaim-migrate @ 14377]
Mark Doliner <mark@kingant.net>
parents: 12056
diff changeset
493 substatus = gaim_savedstatus_get_substatus(saved_status, account);
12056
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
494 if (substatus == NULL)
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
495 {
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
496 substatus = g_new0(GaimSavedStatusSub, 1);
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
497 substatus->account = (GaimAccount *)account;
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
498 saved_status->substatuses = g_list_prepend(saved_status->substatuses, substatus);
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
499 }
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
500
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
501 substatus->type = type;
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
502 g_free(substatus->message);
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
503 substatus->message = g_strdup(message);
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
504
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
505 schedule_save();
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
506 }
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
507
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
508 void
12080
3b52d94437f3 [gaim-migrate @ 14377]
Mark Doliner <mark@kingant.net>
parents: 12056
diff changeset
509 gaim_savedstatus_unset_substatus(GaimSavedStatus *saved_status,
3b52d94437f3 [gaim-migrate @ 14377]
Mark Doliner <mark@kingant.net>
parents: 12056
diff changeset
510 const GaimAccount *account)
12056
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
511 {
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
512 GList *iter;
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
513 GaimSavedStatusSub *substatus;
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
514
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
515 g_return_if_fail(saved_status != NULL);
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
516 g_return_if_fail(account != NULL);
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
517
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
518 for (iter = saved_status->substatuses; iter != NULL; iter = iter->next)
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
519 {
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
520 substatus = iter->data;
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
521 if (substatus->account == account)
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
522 {
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
523 saved_status->substatuses = g_list_delete_link(saved_status->substatuses, iter);
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
524 g_free(substatus->message);
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
525 g_free(substatus);
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
526 return;
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
527 }
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
528 }
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
529 }
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
530
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
531 gboolean
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
532 gaim_savedstatus_delete(const char *title)
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
533 {
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
534 GaimSavedStatus *status;
12125
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
535 time_t creation_time, current, idleaway;
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
536
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
537 status = gaim_savedstatus_find(title);
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
538
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
539 if (status == NULL)
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
540 return FALSE;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
541
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
542 saved_statuses = g_list_remove(saved_statuses, status);
12125
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
543 creation_time = gaim_savedstatus_get_creation_time(status);
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
544 g_hash_table_remove(creation_times, &creation_time);
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
545 free_statussaved(status);
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
546
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
547 schedule_save();
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
548
12125
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
549 /*
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
550 * If we just deleted our current status or our idleaway status,
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
551 * then set the appropriate pref back to 0.
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
552 */
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
553 current = gaim_prefs_get_int("/core/savedstatus/current");
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
554 if (current == creation_time)
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
555 gaim_prefs_set_int("/core/savedstatus/current", 0);
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
556
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
557 idleaway = gaim_prefs_get_int("/core/savedstatus/idleaway");
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
558 if (idleaway == creation_time)
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
559 gaim_prefs_set_int("/core/savedstatus/idleaway", 0);
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
560
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
561 return TRUE;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
562 }
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
563
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
564 const GList *
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
565 gaim_savedstatuses_get_all(void)
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 return saved_statuses;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
568 }
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
569
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
570 GaimSavedStatus *
12125
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
571 gaim_savedstatus_get_current()
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
572 {
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
573 int creation_time;
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
574 GaimSavedStatus *saved_status;
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
575
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
576 creation_time = gaim_prefs_get_int("/core/savedstatus/current");
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
577
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
578 if (creation_time == 0)
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
579 {
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
580 /*
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
581 * We don't have a current saved statuses! This is either a new
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
582 * Gaim user or someone upgrading from Gaim 1.5.0 or older. Add
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
583 * a default status.
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
584 */
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
585 saved_status = gaim_savedstatus_new(NULL, GAIM_STATUS_AVAILABLE);
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
586 gaim_savedstatus_set_message(saved_status, _("Hello!"));
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
587 }
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
588 else
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
589 {
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
590 saved_status = g_hash_table_lookup(creation_times, &creation_time);
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
591 }
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
592
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
593 return saved_status;
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
594 }
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
595
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
596 GaimSavedStatus *
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
597 gaim_savedstatus_get_idleaway()
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
598 {
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
599 int creation_time;
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
600 GaimSavedStatus *saved_status;
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
601
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
602 creation_time = gaim_prefs_get_int("/core/savedstatus/idleaway");
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
603
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
604 if (creation_time == 0)
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
605 {
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
606 /*
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
607 * We don't have a current saved statuses! This is either a new
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
608 * Gaim user or someone upgrading from Gaim 1.5.0 or older. Add
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
609 * a default status.
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
610 */
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
611 saved_status = gaim_savedstatus_new(NULL, GAIM_STATUS_AWAY);
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
612 gaim_savedstatus_set_message(saved_status, _("I'm not here right now"));
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
613 }
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
614 else
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
615 {
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
616 saved_status = g_hash_table_lookup(creation_times, &creation_time);
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
617 }
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
618
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
619 return saved_status;
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
620 }
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
621
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
622 GaimSavedStatus *
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
623 gaim_savedstatus_find(const char *title)
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
624 {
12056
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
625 GList *iter;
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
626 GaimSavedStatus *status;
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
627
11977
0ea9a52fd333 [gaim-migrate @ 14270]
Mark Doliner <mark@kingant.net>
parents: 11975
diff changeset
628 g_return_val_if_fail(title != NULL, NULL);
0ea9a52fd333 [gaim-migrate @ 14270]
Mark Doliner <mark@kingant.net>
parents: 11975
diff changeset
629
12056
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
630 for (iter = saved_statuses; iter != NULL; iter = iter->next)
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
631 {
12056
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
632 status = (GaimSavedStatus *)iter->data;
12125
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
633 if ((status->title != NULL) && !strcmp(status->title, title))
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
634 return status;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
635 }
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
636
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
637 return NULL;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
638 }
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
639
11651
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
640 gboolean
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
641 gaim_savedstatus_is_transient(const GaimSavedStatus *saved_status)
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
642 {
12125
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
643 return (saved_status->title == NULL);
11651
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
644 }
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
645
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
646 const char *
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
647 gaim_savedstatus_get_title(const GaimSavedStatus *saved_status)
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
648 {
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
649 return saved_status->title;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
650 }
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
651
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
652 GaimStatusPrimitive
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
653 gaim_savedstatus_get_type(const GaimSavedStatus *saved_status)
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
654 {
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
655 return saved_status->type;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
656 }
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
657
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
658 const char *
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
659 gaim_savedstatus_get_message(const GaimSavedStatus *saved_status)
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
660 {
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
661 return saved_status->message;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
662 }
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
663
12125
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
664 time_t
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
665 gaim_savedstatus_get_creation_time(const GaimSavedStatus *saved_status)
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
666 {
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
667 return saved_status->creation_time;
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
668 }
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
669
11651
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
670 gboolean
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
671 gaim_savedstatus_has_substatuses(const GaimSavedStatus *saved_status)
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
672 {
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
673 return (saved_status->substatuses != NULL);
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
674 }
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
675
12056
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
676 GaimSavedStatusSub *
12080
3b52d94437f3 [gaim-migrate @ 14377]
Mark Doliner <mark@kingant.net>
parents: 12056
diff changeset
677 gaim_savedstatus_get_substatus(const GaimSavedStatus *saved_status,
3b52d94437f3 [gaim-migrate @ 14377]
Mark Doliner <mark@kingant.net>
parents: 12056
diff changeset
678 const GaimAccount *account)
12056
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
679 {
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
680 GList *iter;
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
681 GaimSavedStatusSub *substatus;
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
682
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
683 g_return_val_if_fail(saved_status != NULL, NULL);
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
684 g_return_val_if_fail(account != NULL, NULL);
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
685
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
686 for (iter = saved_status->substatuses; iter != NULL; iter = iter->next)
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
687 {
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
688 substatus = iter->data;
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
689 if (substatus->account == account)
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
690 return substatus;
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
691 }
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
692
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
693 return NULL;
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
694 }
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
695
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
696 const GaimStatusType *
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
697 gaim_savedstatus_substatus_get_type(const GaimSavedStatusSub *substatus)
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
698 {
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
699 g_return_val_if_fail(substatus != NULL, NULL);
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
700
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
701 return substatus->type;
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
702 }
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
703
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
704 const char *
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
705 gaim_savedstatus_substatus_get_message(const GaimSavedStatusSub *substatus)
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
706 {
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
707 g_return_val_if_fail(substatus != NULL, NULL);
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
708
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
709 return substatus->message;
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
710 }
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
711
11724
a8ec0a291d14 [gaim-migrate @ 14015]
Mark Doliner <mark@kingant.net>
parents: 11651
diff changeset
712 void
12125
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
713 gaim_savedstatus_activate(GaimSavedStatus *saved_status)
11724
a8ec0a291d14 [gaim-migrate @ 14015]
Mark Doliner <mark@kingant.net>
parents: 11651
diff changeset
714 {
11733
ef511dec9903 [gaim-migrate @ 14024]
Mark Doliner <mark@kingant.net>
parents: 11727
diff changeset
715 GList *accounts, *node;
11724
a8ec0a291d14 [gaim-migrate @ 14015]
Mark Doliner <mark@kingant.net>
parents: 11651
diff changeset
716
11727
8657ad65e257 [gaim-migrate @ 14018]
Mark Doliner <mark@kingant.net>
parents: 11724
diff changeset
717 g_return_if_fail(saved_status != NULL);
8657ad65e257 [gaim-migrate @ 14018]
Mark Doliner <mark@kingant.net>
parents: 11724
diff changeset
718
11724
a8ec0a291d14 [gaim-migrate @ 14015]
Mark Doliner <mark@kingant.net>
parents: 11651
diff changeset
719 accounts = gaim_accounts_get_all_active();
a8ec0a291d14 [gaim-migrate @ 14015]
Mark Doliner <mark@kingant.net>
parents: 11651
diff changeset
720
11733
ef511dec9903 [gaim-migrate @ 14024]
Mark Doliner <mark@kingant.net>
parents: 11727
diff changeset
721 for (node = accounts; node != NULL; node = node->next)
11724
a8ec0a291d14 [gaim-migrate @ 14015]
Mark Doliner <mark@kingant.net>
parents: 11651
diff changeset
722 {
a8ec0a291d14 [gaim-migrate @ 14015]
Mark Doliner <mark@kingant.net>
parents: 11651
diff changeset
723 GaimAccount *account;
a8ec0a291d14 [gaim-migrate @ 14015]
Mark Doliner <mark@kingant.net>
parents: 11651
diff changeset
724
11733
ef511dec9903 [gaim-migrate @ 14024]
Mark Doliner <mark@kingant.net>
parents: 11727
diff changeset
725 account = node->data;
11724
a8ec0a291d14 [gaim-migrate @ 14015]
Mark Doliner <mark@kingant.net>
parents: 11651
diff changeset
726 gaim_savedstatus_activate_for_account(saved_status, account);
a8ec0a291d14 [gaim-migrate @ 14015]
Mark Doliner <mark@kingant.net>
parents: 11651
diff changeset
727 }
11733
ef511dec9903 [gaim-migrate @ 14024]
Mark Doliner <mark@kingant.net>
parents: 11727
diff changeset
728
ef511dec9903 [gaim-migrate @ 14024]
Mark Doliner <mark@kingant.net>
parents: 11727
diff changeset
729 g_list_free(accounts);
11954
351f4dd75718 [gaim-migrate @ 14245]
Mark Doliner <mark@kingant.net>
parents: 11806
diff changeset
730
12125
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
731 /*
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
732 * TODO: Need to rotate the old status out of here so we
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
733 * can keep track of recently used statuses.
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
734 */
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
735 saved_status->lastused = time(NULL);
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
736 gaim_prefs_set_int("/core/savedstatus/current",
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
737 gaim_savedstatus_get_creation_time(saved_status));
11724
a8ec0a291d14 [gaim-migrate @ 14015]
Mark Doliner <mark@kingant.net>
parents: 11651
diff changeset
738 }
a8ec0a291d14 [gaim-migrate @ 14015]
Mark Doliner <mark@kingant.net>
parents: 11651
diff changeset
739
a8ec0a291d14 [gaim-migrate @ 14015]
Mark Doliner <mark@kingant.net>
parents: 11651
diff changeset
740 void
a8ec0a291d14 [gaim-migrate @ 14015]
Mark Doliner <mark@kingant.net>
parents: 11651
diff changeset
741 gaim_savedstatus_activate_for_account(const GaimSavedStatus *saved_status,
a8ec0a291d14 [gaim-migrate @ 14015]
Mark Doliner <mark@kingant.net>
parents: 11651
diff changeset
742 GaimAccount *account)
a8ec0a291d14 [gaim-migrate @ 14015]
Mark Doliner <mark@kingant.net>
parents: 11651
diff changeset
743 {
12056
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
744 const GaimStatusType *status_type;
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
745 const GaimSavedStatusSub *substatus;
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
746 const char *message = NULL;
11724
a8ec0a291d14 [gaim-migrate @ 14015]
Mark Doliner <mark@kingant.net>
parents: 11651
diff changeset
747
11727
8657ad65e257 [gaim-migrate @ 14018]
Mark Doliner <mark@kingant.net>
parents: 11724
diff changeset
748 g_return_if_fail(saved_status != NULL);
8657ad65e257 [gaim-migrate @ 14018]
Mark Doliner <mark@kingant.net>
parents: 11724
diff changeset
749 g_return_if_fail(account != NULL);
8657ad65e257 [gaim-migrate @ 14018]
Mark Doliner <mark@kingant.net>
parents: 11724
diff changeset
750
12080
3b52d94437f3 [gaim-migrate @ 14377]
Mark Doliner <mark@kingant.net>
parents: 12056
diff changeset
751 substatus = gaim_savedstatus_get_substatus(saved_status, account);
12056
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
752 if (substatus != NULL)
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
753 {
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
754 status_type = substatus->type;
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
755 message = substatus->message;
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
756 }
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
757 else
11724
a8ec0a291d14 [gaim-migrate @ 14015]
Mark Doliner <mark@kingant.net>
parents: 11651
diff changeset
758 {
12056
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
759 status_type = gaim_account_get_status_type_with_primitive(account, saved_status->type);
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
760 if (status_type == NULL)
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
761 return;
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
762 message = saved_status->message;
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
763 }
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
764
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
765 if ((message != NULL) &&
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
766 (gaim_status_type_get_attr(status_type, "message")))
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
767 {
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
768 gaim_account_set_status(account, gaim_status_type_get_id(status_type),
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
769 TRUE, "message", message, NULL);
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
770 }
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
771 else
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
772 {
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
773 gaim_account_set_status(account, gaim_status_type_get_id(status_type),
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
774 TRUE, NULL);
11724
a8ec0a291d14 [gaim-migrate @ 14015]
Mark Doliner <mark@kingant.net>
parents: 11651
diff changeset
775 }
a8ec0a291d14 [gaim-migrate @ 14015]
Mark Doliner <mark@kingant.net>
parents: 11651
diff changeset
776 }
a8ec0a291d14 [gaim-migrate @ 14015]
Mark Doliner <mark@kingant.net>
parents: 11651
diff changeset
777
11318
519dc2186438 [gaim-migrate @ 13521]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10738
diff changeset
778 void *
519dc2186438 [gaim-migrate @ 13521]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10738
diff changeset
779 gaim_savedstatuses_get_handle(void)
519dc2186438 [gaim-migrate @ 13521]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10738
diff changeset
780 {
519dc2186438 [gaim-migrate @ 13521]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10738
diff changeset
781 static int handle;
519dc2186438 [gaim-migrate @ 13521]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10738
diff changeset
782
519dc2186438 [gaim-migrate @ 13521]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10738
diff changeset
783 return &handle;
519dc2186438 [gaim-migrate @ 13521]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10738
diff changeset
784 }
519dc2186438 [gaim-migrate @ 13521]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10738
diff changeset
785
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
786 void
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
787 gaim_savedstatuses_init(void)
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
788 {
12125
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
789 creation_times = g_hash_table_new(g_int_hash, g_int_equal);
11975
aadf61b30056 [gaim-migrate @ 14268]
Mark Doliner <mark@kingant.net>
parents: 11954
diff changeset
790
12125
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
791 /*
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
792 * Using 0 as the creation_time is a special case.
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
793 * If someone calls gaim_savedstatus_get_current() or
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
794 * gaim_savedstatus_get_idleaway() and either of those functions
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
795 * sees a creation_time of 0, then it will create a default
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
796 * saved status and return that to the user.
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
797 */
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
798 gaim_prefs_add_none("/core/savedstatus");
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
799 gaim_prefs_add_int("/core/savedstatus/current", 0);
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
800 gaim_prefs_add_int("/core/savedstatus/idleaway", 0);
11975
aadf61b30056 [gaim-migrate @ 14268]
Mark Doliner <mark@kingant.net>
parents: 11954
diff changeset
801
12125
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
802 load_statuses();
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
803 }
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
804
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
805 void
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
806 gaim_savedstatuses_uninit(void)
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
807 {
10428
04c663ccbcb1 [gaim-migrate @ 11680]
Mark Doliner <mark@kingant.net>
parents: 10427
diff changeset
808 if (save_timer != 0)
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
809 {
10428
04c663ccbcb1 [gaim-migrate @ 11680]
Mark Doliner <mark@kingant.net>
parents: 10427
diff changeset
810 gaim_timeout_remove(save_timer);
04c663ccbcb1 [gaim-migrate @ 11680]
Mark Doliner <mark@kingant.net>
parents: 10427
diff changeset
811 save_timer = 0;
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
812 sync_statuses();
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
813 }
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
814
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
815 while (saved_statuses != NULL) {
12056
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
816 GaimSavedStatus *saved_status = saved_statuses->data;
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
817 saved_statuses = g_list_remove(saved_statuses, saved_status);
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
818 free_statussaved(saved_status);
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
819 }
12125
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
820
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
821 g_hash_table_destroy(creation_times);
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
822 }
12056
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
823