annotate src/savedstatuses.c @ 14068:6cb8bdc3366f

[gaim-migrate @ 16689] Plug a leak that I didn't notice while making the other fixes. committer: Tailor Script <tailor@pidgin.im>
author Daniel Atallah <daniel.atallah@gmail.com>
date Thu, 10 Aug 2006 21:22:55 +0000
parents ec858948d292
children a8a033a89ee0
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 /**
13761
ec858948d292 [gaim-migrate @ 16173]
Richard Laager <rlaager@wiktel.com>
parents: 13681
diff changeset
2 * @file savedstatuses.c Saved Status API
10418
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"
13761
ec858948d292 [gaim-migrate @ 16173]
Richard Laager <rlaager@wiktel.com>
parents: 13681
diff changeset
30 #include "dbus-maybe.h"
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
31 #include "status.h"
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
32 #include "util.h"
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
33 #include "xmlnode.h"
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
34
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
35 /**
12327
508ac301e74b [gaim-migrate @ 14631]
Mark Doliner <mark@kingant.net>
parents: 12309
diff changeset
36 * The maximum number of transient statuses to save. This
508ac301e74b [gaim-migrate @ 14631]
Mark Doliner <mark@kingant.net>
parents: 12309
diff changeset
37 * is used during the shutdown process to clean out old
508ac301e74b [gaim-migrate @ 14631]
Mark Doliner <mark@kingant.net>
parents: 12309
diff changeset
38 * transient statuses.
508ac301e74b [gaim-migrate @ 14631]
Mark Doliner <mark@kingant.net>
parents: 12309
diff changeset
39 */
508ac301e74b [gaim-migrate @ 14631]
Mark Doliner <mark@kingant.net>
parents: 12309
diff changeset
40 #define MAX_TRANSIENTS 5
508ac301e74b [gaim-migrate @ 14631]
Mark Doliner <mark@kingant.net>
parents: 12309
diff changeset
41
508ac301e74b [gaim-migrate @ 14631]
Mark Doliner <mark@kingant.net>
parents: 12309
diff changeset
42 /**
13681
c4be649e2aca [gaim-migrate @ 16084]
Mark Doliner <mark@kingant.net>
parents: 13675
diff changeset
43 * The default message to use when the user becomes auto-away.
c4be649e2aca [gaim-migrate @ 16084]
Mark Doliner <mark@kingant.net>
parents: 13675
diff changeset
44 */
c4be649e2aca [gaim-migrate @ 16084]
Mark Doliner <mark@kingant.net>
parents: 13675
diff changeset
45 #define DEFAULT_AUTOAWAY_MESSAGE _("I'm not here right now")
c4be649e2aca [gaim-migrate @ 16084]
Mark Doliner <mark@kingant.net>
parents: 13675
diff changeset
46
c4be649e2aca [gaim-migrate @ 16084]
Mark Doliner <mark@kingant.net>
parents: 13675
diff changeset
47 /**
12125
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
48 * The information stores a snap-shot of the statuses of all
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
49 * your accounts. Basically these are your saved away messages.
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
50 * There is an overall status and message that applies to
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
51 * all your accounts, and then each individual account can
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
52 * optionally have a different custom status and message.
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
53 *
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
54 * The changes to status.xml caused by the new status API
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
55 * are fully backward compatible. The new status API just
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
56 * adds the optional sub-statuses to the XML file.
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
57 */
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
58 struct _GaimSavedStatus
10418
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 char *title;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
61 GaimStatusPrimitive type;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
62 char *message;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
63
12125
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
64 /** 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
65 time_t creation_time;
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
66
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
67 time_t lastused;
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
68
12688
473c23442a36 [gaim-migrate @ 15031]
Mark Doliner <mark@kingant.net>
parents: 12552
diff changeset
69 unsigned int usage_count;
473c23442a36 [gaim-migrate @ 15031]
Mark Doliner <mark@kingant.net>
parents: 12552
diff changeset
70
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
71 GList *substatuses; /**< A list of GaimSavedStatusSub's. */
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
72 };
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
73
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
74 /*
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
75 * 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
76 * associated GaimSavedStatusSub's?
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
77 */
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
78 struct _GaimSavedStatusSub
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
79 {
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
80 GaimAccount *account;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
81 const GaimStatusType *type;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
82 char *message;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
83 };
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
84
12125
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
85 static GList *saved_statuses = NULL;
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
86 static guint save_timer = 0;
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
87 static gboolean statuses_loaded = FALSE;
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
88
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
89 /*
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
90 * This hash table keeps track of which timestamps we've
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
91 * 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
92 * same 'creation_time' timestamp. The 'created' timestamp
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
93 * is used as a unique identifier.
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
94 *
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
95 * 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
96 * the value is a pointer to the GaimSavedStatus.
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
97 */
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
98 static GHashTable *creation_times;
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
99
12327
508ac301e74b [gaim-migrate @ 14631]
Mark Doliner <mark@kingant.net>
parents: 12309
diff changeset
100 static void schedule_save(void);
10427
16d63d8c26d8 [gaim-migrate @ 11679]
Mark Doliner <mark@kingant.net>
parents: 10426
diff changeset
101
10428
04c663ccbcb1 [gaim-migrate @ 11680]
Mark Doliner <mark@kingant.net>
parents: 10427
diff changeset
102 /*********************************************************************
04c663ccbcb1 [gaim-migrate @ 11680]
Mark Doliner <mark@kingant.net>
parents: 10427
diff changeset
103 * Private utility functions *
04c663ccbcb1 [gaim-migrate @ 11680]
Mark Doliner <mark@kingant.net>
parents: 10427
diff changeset
104 *********************************************************************/
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
105
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
106 static void
12724
10ef9171ca87 [gaim-migrate @ 15068]
Mark Doliner <mark@kingant.net>
parents: 12690
diff changeset
107 free_saved_status_sub(GaimSavedStatusSub *substatus)
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
108 {
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
109 g_return_if_fail(substatus != NULL);
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
110
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
111 g_free(substatus->message);
13761
ec858948d292 [gaim-migrate @ 16173]
Richard Laager <rlaager@wiktel.com>
parents: 13681
diff changeset
112 GAIM_DBUS_UNREGISTER_POINTER(substatus);
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
113 g_free(substatus);
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
114 }
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 static void
12724
10ef9171ca87 [gaim-migrate @ 15068]
Mark Doliner <mark@kingant.net>
parents: 12690
diff changeset
117 free_saved_status(GaimSavedStatus *status)
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
118 {
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
119 g_return_if_fail(status != NULL);
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
120
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
121 g_free(status->title);
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
122 g_free(status->message);
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
123
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
124 while (status->substatuses != NULL)
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
125 {
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
126 GaimSavedStatusSub *substatus = status->substatuses->data;
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
127 status->substatuses = g_list_remove(status->substatuses, substatus);
12724
10ef9171ca87 [gaim-migrate @ 15068]
Mark Doliner <mark@kingant.net>
parents: 12690
diff changeset
128 free_saved_status_sub(substatus);
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
129 }
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
130
13761
ec858948d292 [gaim-migrate @ 16173]
Richard Laager <rlaager@wiktel.com>
parents: 13681
diff changeset
131 GAIM_DBUS_UNREGISTER_POINTER(status);
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
132 g_free(status);
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
133 }
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
134
12125
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 * Set the timestamp for when this saved status was created, and
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
137 * make sure it is unique.
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
138 */
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
139 static void
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
140 set_creation_time(GaimSavedStatus *status, time_t creation_time)
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
141 {
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
142 g_return_if_fail(status != NULL);
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
143
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
144 /* Avoid using 0 because it's an invalid hash key */
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
145 status->creation_time = creation_time != 0 ? creation_time : 1;
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
146
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
147 while (g_hash_table_lookup(creation_times, &status->creation_time) != NULL)
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
148 status->creation_time++;
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
149
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
150 g_hash_table_insert(creation_times,
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
151 &status->creation_time,
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
152 status);
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
153 }
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
154
12724
10ef9171ca87 [gaim-migrate @ 15068]
Mark Doliner <mark@kingant.net>
parents: 12690
diff changeset
155 /**
10ef9171ca87 [gaim-migrate @ 15068]
Mark Doliner <mark@kingant.net>
parents: 12690
diff changeset
156 * A magic number is calcuated for each status, and then the
10ef9171ca87 [gaim-migrate @ 15068]
Mark Doliner <mark@kingant.net>
parents: 12690
diff changeset
157 * statuses are ordered by the magic number. The magic number
10ef9171ca87 [gaim-migrate @ 15068]
Mark Doliner <mark@kingant.net>
parents: 12690
diff changeset
158 * is the date the status was last used offset by one day for
10ef9171ca87 [gaim-migrate @ 15068]
Mark Doliner <mark@kingant.net>
parents: 12690
diff changeset
159 * each time the status has been used (but only by 10 days at
10ef9171ca87 [gaim-migrate @ 15068]
Mark Doliner <mark@kingant.net>
parents: 12690
diff changeset
160 * the most).
10ef9171ca87 [gaim-migrate @ 15068]
Mark Doliner <mark@kingant.net>
parents: 12690
diff changeset
161 *
10ef9171ca87 [gaim-migrate @ 15068]
Mark Doliner <mark@kingant.net>
parents: 12690
diff changeset
162 * The goal is to have recently used statuses at the top of
10ef9171ca87 [gaim-migrate @ 15068]
Mark Doliner <mark@kingant.net>
parents: 12690
diff changeset
163 * the list, but to also keep frequently used statuses near
10ef9171ca87 [gaim-migrate @ 15068]
Mark Doliner <mark@kingant.net>
parents: 12690
diff changeset
164 * the top.
10ef9171ca87 [gaim-migrate @ 15068]
Mark Doliner <mark@kingant.net>
parents: 12690
diff changeset
165 */
12327
508ac301e74b [gaim-migrate @ 14631]
Mark Doliner <mark@kingant.net>
parents: 12309
diff changeset
166 static gint
12724
10ef9171ca87 [gaim-migrate @ 15068]
Mark Doliner <mark@kingant.net>
parents: 12690
diff changeset
167 saved_statuses_sort_func(gconstpointer a, gconstpointer b)
12327
508ac301e74b [gaim-migrate @ 14631]
Mark Doliner <mark@kingant.net>
parents: 12309
diff changeset
168 {
12724
10ef9171ca87 [gaim-migrate @ 15068]
Mark Doliner <mark@kingant.net>
parents: 12690
diff changeset
169 const GaimSavedStatus *saved_status_a = a;
10ef9171ca87 [gaim-migrate @ 15068]
Mark Doliner <mark@kingant.net>
parents: 12690
diff changeset
170 const GaimSavedStatus *saved_status_b = b;
10ef9171ca87 [gaim-migrate @ 15068]
Mark Doliner <mark@kingant.net>
parents: 12690
diff changeset
171 time_t time_a = saved_status_a->lastused +
10ef9171ca87 [gaim-migrate @ 15068]
Mark Doliner <mark@kingant.net>
parents: 12690
diff changeset
172 (MIN(saved_status_a->usage_count, 10) * 86400);
10ef9171ca87 [gaim-migrate @ 15068]
Mark Doliner <mark@kingant.net>
parents: 12690
diff changeset
173 time_t time_b = saved_status_b->lastused +
10ef9171ca87 [gaim-migrate @ 15068]
Mark Doliner <mark@kingant.net>
parents: 12690
diff changeset
174 (MIN(saved_status_b->usage_count, 10) * 86400);
10ef9171ca87 [gaim-migrate @ 15068]
Mark Doliner <mark@kingant.net>
parents: 12690
diff changeset
175 if (time_a > time_b)
12327
508ac301e74b [gaim-migrate @ 14631]
Mark Doliner <mark@kingant.net>
parents: 12309
diff changeset
176 return -1;
12724
10ef9171ca87 [gaim-migrate @ 15068]
Mark Doliner <mark@kingant.net>
parents: 12690
diff changeset
177 if (time_a < time_b)
12327
508ac301e74b [gaim-migrate @ 14631]
Mark Doliner <mark@kingant.net>
parents: 12309
diff changeset
178 return 1;
508ac301e74b [gaim-migrate @ 14631]
Mark Doliner <mark@kingant.net>
parents: 12309
diff changeset
179 return 0;
508ac301e74b [gaim-migrate @ 14631]
Mark Doliner <mark@kingant.net>
parents: 12309
diff changeset
180 }
508ac301e74b [gaim-migrate @ 14631]
Mark Doliner <mark@kingant.net>
parents: 12309
diff changeset
181
508ac301e74b [gaim-migrate @ 14631]
Mark Doliner <mark@kingant.net>
parents: 12309
diff changeset
182 /**
508ac301e74b [gaim-migrate @ 14631]
Mark Doliner <mark@kingant.net>
parents: 12309
diff changeset
183 * Transient statuses are added and removed automatically by
508ac301e74b [gaim-migrate @ 14631]
Mark Doliner <mark@kingant.net>
parents: 12309
diff changeset
184 * Gaim. If they're not used for a certain length of time then
508ac301e74b [gaim-migrate @ 14631]
Mark Doliner <mark@kingant.net>
parents: 12309
diff changeset
185 * they'll expire and be automatically removed. This function
508ac301e74b [gaim-migrate @ 14631]
Mark Doliner <mark@kingant.net>
parents: 12309
diff changeset
186 * does the expiration.
508ac301e74b [gaim-migrate @ 14631]
Mark Doliner <mark@kingant.net>
parents: 12309
diff changeset
187 */
508ac301e74b [gaim-migrate @ 14631]
Mark Doliner <mark@kingant.net>
parents: 12309
diff changeset
188 static void
508ac301e74b [gaim-migrate @ 14631]
Mark Doliner <mark@kingant.net>
parents: 12309
diff changeset
189 remove_old_transient_statuses()
508ac301e74b [gaim-migrate @ 14631]
Mark Doliner <mark@kingant.net>
parents: 12309
diff changeset
190 {
508ac301e74b [gaim-migrate @ 14631]
Mark Doliner <mark@kingant.net>
parents: 12309
diff changeset
191 GList *l, *next;
13197
22f8ed4e5294 [gaim-migrate @ 15560]
Mark Doliner <mark@kingant.net>
parents: 13012
diff changeset
192 GaimSavedStatus *saved_status, *current_status;
12724
10ef9171ca87 [gaim-migrate @ 15068]
Mark Doliner <mark@kingant.net>
parents: 12690
diff changeset
193 int count;
10ef9171ca87 [gaim-migrate @ 15068]
Mark Doliner <mark@kingant.net>
parents: 12690
diff changeset
194 time_t creation_time;
12327
508ac301e74b [gaim-migrate @ 14631]
Mark Doliner <mark@kingant.net>
parents: 12309
diff changeset
195
13197
22f8ed4e5294 [gaim-migrate @ 15560]
Mark Doliner <mark@kingant.net>
parents: 13012
diff changeset
196 current_status = gaim_savedstatus_get_current();
22f8ed4e5294 [gaim-migrate @ 15560]
Mark Doliner <mark@kingant.net>
parents: 13012
diff changeset
197
12724
10ef9171ca87 [gaim-migrate @ 15068]
Mark Doliner <mark@kingant.net>
parents: 12690
diff changeset
198 /*
10ef9171ca87 [gaim-migrate @ 15068]
Mark Doliner <mark@kingant.net>
parents: 12690
diff changeset
199 * Iterate through the list of saved statuses. Delete all
10ef9171ca87 [gaim-migrate @ 15068]
Mark Doliner <mark@kingant.net>
parents: 12690
diff changeset
200 * transient statuses except for the first MAX_TRANSIENTS
10ef9171ca87 [gaim-migrate @ 15068]
Mark Doliner <mark@kingant.net>
parents: 12690
diff changeset
201 * (remember, the saved statuses are already sorted by popularity).
10ef9171ca87 [gaim-migrate @ 15068]
Mark Doliner <mark@kingant.net>
parents: 12690
diff changeset
202 */
10ef9171ca87 [gaim-migrate @ 15068]
Mark Doliner <mark@kingant.net>
parents: 12690
diff changeset
203 count = 0;
12327
508ac301e74b [gaim-migrate @ 14631]
Mark Doliner <mark@kingant.net>
parents: 12309
diff changeset
204 for (l = saved_statuses; l != NULL; l = next)
508ac301e74b [gaim-migrate @ 14631]
Mark Doliner <mark@kingant.net>
parents: 12309
diff changeset
205 {
508ac301e74b [gaim-migrate @ 14631]
Mark Doliner <mark@kingant.net>
parents: 12309
diff changeset
206 next = l->next;
508ac301e74b [gaim-migrate @ 14631]
Mark Doliner <mark@kingant.net>
parents: 12309
diff changeset
207 saved_status = l->data;
12724
10ef9171ca87 [gaim-migrate @ 15068]
Mark Doliner <mark@kingant.net>
parents: 12690
diff changeset
208 if (gaim_savedstatus_is_transient(saved_status))
12327
508ac301e74b [gaim-migrate @ 14631]
Mark Doliner <mark@kingant.net>
parents: 12309
diff changeset
209 {
12724
10ef9171ca87 [gaim-migrate @ 15068]
Mark Doliner <mark@kingant.net>
parents: 12690
diff changeset
210 if (count == MAX_TRANSIENTS)
10ef9171ca87 [gaim-migrate @ 15068]
Mark Doliner <mark@kingant.net>
parents: 12690
diff changeset
211 {
13197
22f8ed4e5294 [gaim-migrate @ 15560]
Mark Doliner <mark@kingant.net>
parents: 13012
diff changeset
212 if (saved_status != current_status)
22f8ed4e5294 [gaim-migrate @ 15560]
Mark Doliner <mark@kingant.net>
parents: 13012
diff changeset
213 {
22f8ed4e5294 [gaim-migrate @ 15560]
Mark Doliner <mark@kingant.net>
parents: 13012
diff changeset
214 saved_statuses = g_list_remove(saved_statuses, saved_status);
22f8ed4e5294 [gaim-migrate @ 15560]
Mark Doliner <mark@kingant.net>
parents: 13012
diff changeset
215 creation_time = gaim_savedstatus_get_creation_time(saved_status);
22f8ed4e5294 [gaim-migrate @ 15560]
Mark Doliner <mark@kingant.net>
parents: 13012
diff changeset
216 g_hash_table_remove(creation_times, &creation_time);
22f8ed4e5294 [gaim-migrate @ 15560]
Mark Doliner <mark@kingant.net>
parents: 13012
diff changeset
217 free_saved_status(saved_status);
22f8ed4e5294 [gaim-migrate @ 15560]
Mark Doliner <mark@kingant.net>
parents: 13012
diff changeset
218 }
12724
10ef9171ca87 [gaim-migrate @ 15068]
Mark Doliner <mark@kingant.net>
parents: 12690
diff changeset
219 }
10ef9171ca87 [gaim-migrate @ 15068]
Mark Doliner <mark@kingant.net>
parents: 12690
diff changeset
220 else
10ef9171ca87 [gaim-migrate @ 15068]
Mark Doliner <mark@kingant.net>
parents: 12690
diff changeset
221 count++;
12327
508ac301e74b [gaim-migrate @ 14631]
Mark Doliner <mark@kingant.net>
parents: 12309
diff changeset
222 }
508ac301e74b [gaim-migrate @ 14631]
Mark Doliner <mark@kingant.net>
parents: 12309
diff changeset
223 }
12724
10ef9171ca87 [gaim-migrate @ 15068]
Mark Doliner <mark@kingant.net>
parents: 12690
diff changeset
224
10ef9171ca87 [gaim-migrate @ 15068]
Mark Doliner <mark@kingant.net>
parents: 12690
diff changeset
225 if (count == MAX_TRANSIENTS)
10ef9171ca87 [gaim-migrate @ 15068]
Mark Doliner <mark@kingant.net>
parents: 12690
diff changeset
226 schedule_save();
12327
508ac301e74b [gaim-migrate @ 14631]
Mark Doliner <mark@kingant.net>
parents: 12309
diff changeset
227 }
508ac301e74b [gaim-migrate @ 14631]
Mark Doliner <mark@kingant.net>
parents: 12309
diff changeset
228
10428
04c663ccbcb1 [gaim-migrate @ 11680]
Mark Doliner <mark@kingant.net>
parents: 10427
diff changeset
229 /*********************************************************************
10429
e41f0668a648 [gaim-migrate @ 11681]
Mark Doliner <mark@kingant.net>
parents: 10428
diff changeset
230 * Writing to disk *
10428
04c663ccbcb1 [gaim-migrate @ 11680]
Mark Doliner <mark@kingant.net>
parents: 10427
diff changeset
231 *********************************************************************/
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
232
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
233 static xmlnode *
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
234 substatus_to_xmlnode(GaimSavedStatusSub *substatus)
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 xmlnode *node, *child;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
237
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
238 node = xmlnode_new("substatus");
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
239
10424
108151be77a3 [gaim-migrate @ 11676]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
240 child = xmlnode_new_child(node, "account");
108151be77a3 [gaim-migrate @ 11676]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
241 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
242 xmlnode_insert_data(child, gaim_account_get_username(substatus->account), -1);
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
243
10424
108151be77a3 [gaim-migrate @ 11676]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
244 child = xmlnode_new_child(node, "state");
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
245 xmlnode_insert_data(child, gaim_status_type_get_id(substatus->type), -1);
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
246
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
247 if (substatus->message != NULL)
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
248 {
10424
108151be77a3 [gaim-migrate @ 11676]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
249 child = xmlnode_new_child(node, "message");
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
250 xmlnode_insert_data(child, substatus->message, -1);
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
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
253 return node;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
254 }
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
255
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
256 static xmlnode *
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
257 status_to_xmlnode(GaimSavedStatus *status)
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
258 {
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
259 xmlnode *node, *child;
12125
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
260 char buf[21];
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
261 GList *cur;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
262
12125
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
263 node = xmlnode_new("status");
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
264 if (status->title != NULL)
12283
4396691844e2 [gaim-migrate @ 14587]
Mark Doliner <mark@kingant.net>
parents: 12197
diff changeset
265 {
12125
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
266 xmlnode_set_attrib(node, "name", status->title);
12283
4396691844e2 [gaim-migrate @ 14587]
Mark Doliner <mark@kingant.net>
parents: 12197
diff changeset
267 }
4396691844e2 [gaim-migrate @ 14587]
Mark Doliner <mark@kingant.net>
parents: 12197
diff changeset
268 else
4396691844e2 [gaim-migrate @ 14587]
Mark Doliner <mark@kingant.net>
parents: 12197
diff changeset
269 {
4396691844e2 [gaim-migrate @ 14587]
Mark Doliner <mark@kingant.net>
parents: 12197
diff changeset
270 /*
4396691844e2 [gaim-migrate @ 14587]
Mark Doliner <mark@kingant.net>
parents: 12197
diff changeset
271 * Gaim 1.5.0 and earlier require a name to be set, so we
4396691844e2 [gaim-migrate @ 14587]
Mark Doliner <mark@kingant.net>
parents: 12197
diff changeset
272 * do this little hack to maintain backward compatability
12309
b3385115815c [gaim-migrate @ 14613]
Mark Doliner <mark@kingant.net>
parents: 12283
diff changeset
273 * in the status.xml file. Eventually this should be removed
12283
4396691844e2 [gaim-migrate @ 14587]
Mark Doliner <mark@kingant.net>
parents: 12197
diff changeset
274 * and we should determine if a status is transient by
4396691844e2 [gaim-migrate @ 14587]
Mark Doliner <mark@kingant.net>
parents: 12197
diff changeset
275 * whether the "name" attribute is set to something or if
4396691844e2 [gaim-migrate @ 14587]
Mark Doliner <mark@kingant.net>
parents: 12197
diff changeset
276 * it does not exist at all.
4396691844e2 [gaim-migrate @ 14587]
Mark Doliner <mark@kingant.net>
parents: 12197
diff changeset
277 */
4396691844e2 [gaim-migrate @ 14587]
Mark Doliner <mark@kingant.net>
parents: 12197
diff changeset
278 xmlnode_set_attrib(node, "name", "Auto-Cached");
4396691844e2 [gaim-migrate @ 14587]
Mark Doliner <mark@kingant.net>
parents: 12197
diff changeset
279 xmlnode_set_attrib(node, "transient", "true");
4396691844e2 [gaim-migrate @ 14587]
Mark Doliner <mark@kingant.net>
parents: 12197
diff changeset
280 }
11651
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
281
12125
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
282 snprintf(buf, sizeof(buf), "%lu", status->creation_time);
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
283 xmlnode_set_attrib(node, "created", buf);
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
284
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
285 snprintf(buf, sizeof(buf), "%lu", status->lastused);
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
286 xmlnode_set_attrib(node, "lastused", buf);
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
287
12688
473c23442a36 [gaim-migrate @ 15031]
Mark Doliner <mark@kingant.net>
parents: 12552
diff changeset
288 snprintf(buf, sizeof(buf), "%u", status->usage_count);
473c23442a36 [gaim-migrate @ 15031]
Mark Doliner <mark@kingant.net>
parents: 12552
diff changeset
289 xmlnode_set_attrib(node, "usage_count", buf);
473c23442a36 [gaim-migrate @ 15031]
Mark Doliner <mark@kingant.net>
parents: 12552
diff changeset
290
10424
108151be77a3 [gaim-migrate @ 11676]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
291 child = xmlnode_new_child(node, "state");
108151be77a3 [gaim-migrate @ 11676]
Mark Doliner <mark@kingant.net>
parents: 10423
diff changeset
292 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
293
11651
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
294 if (status->message != NULL)
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
295 {
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
296 child = xmlnode_new_child(node, "message");
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
297 xmlnode_insert_data(child, status->message, -1);
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
298 }
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
299
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
300 for (cur = status->substatuses; cur != NULL; cur = cur->next)
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
301 {
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
302 child = substatus_to_xmlnode(cur->data);
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
303 xmlnode_insert_child(node, child);
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
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
306 return node;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
307 }
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
308
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
309 static xmlnode *
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
310 statuses_to_xmlnode(void)
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
311 {
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
312 xmlnode *node, *child;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
313 GList *cur;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
314
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
315 node = xmlnode_new("statuses");
10423
3232e1a33899 [gaim-migrate @ 11675]
Mark Doliner <mark@kingant.net>
parents: 10420
diff changeset
316 xmlnode_set_attrib(node, "version", "1.0");
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
317
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
318 for (cur = saved_statuses; cur != NULL; cur = cur->next)
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
319 {
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
320 child = status_to_xmlnode(cur->data);
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
321 xmlnode_insert_child(node, child);
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
322 }
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
323
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
324 return node;
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
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
327 static void
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
328 sync_statuses(void)
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
329 {
10423
3232e1a33899 [gaim-migrate @ 11675]
Mark Doliner <mark@kingant.net>
parents: 10420
diff changeset
330 xmlnode *node;
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
331 char *data;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
332
10428
04c663ccbcb1 [gaim-migrate @ 11680]
Mark Doliner <mark@kingant.net>
parents: 10427
diff changeset
333 if (!statuses_loaded)
04c663ccbcb1 [gaim-migrate @ 11680]
Mark Doliner <mark@kingant.net>
parents: 10427
diff changeset
334 {
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
335 gaim_debug_error("status", "Attempted to save statuses before they "
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
336 "were read!\n");
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
337 return;
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
10423
3232e1a33899 [gaim-migrate @ 11675]
Mark Doliner <mark@kingant.net>
parents: 10420
diff changeset
340 node = statuses_to_xmlnode();
3232e1a33899 [gaim-migrate @ 11675]
Mark Doliner <mark@kingant.net>
parents: 10420
diff changeset
341 data = xmlnode_to_formatted_str(node, NULL);
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
342 gaim_util_write_data_to_file("status.xml", data, -1);
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
343 g_free(data);
10423
3232e1a33899 [gaim-migrate @ 11675]
Mark Doliner <mark@kingant.net>
parents: 10420
diff changeset
344 xmlnode_free(node);
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
345 }
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
346
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
347 static gboolean
10428
04c663ccbcb1 [gaim-migrate @ 11680]
Mark Doliner <mark@kingant.net>
parents: 10427
diff changeset
348 save_cb(gpointer data)
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
349 {
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
350 sync_statuses();
10428
04c663ccbcb1 [gaim-migrate @ 11680]
Mark Doliner <mark@kingant.net>
parents: 10427
diff changeset
351 save_timer = 0;
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
352 return FALSE;
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
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
355 static void
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
356 schedule_save(void)
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
357 {
10428
04c663ccbcb1 [gaim-migrate @ 11680]
Mark Doliner <mark@kingant.net>
parents: 10427
diff changeset
358 if (save_timer == 0)
04c663ccbcb1 [gaim-migrate @ 11680]
Mark Doliner <mark@kingant.net>
parents: 10427
diff changeset
359 save_timer = gaim_timeout_add(5000, save_cb, NULL);
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
360 }
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
361
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
362
10428
04c663ccbcb1 [gaim-migrate @ 11680]
Mark Doliner <mark@kingant.net>
parents: 10427
diff changeset
363 /*********************************************************************
04c663ccbcb1 [gaim-migrate @ 11680]
Mark Doliner <mark@kingant.net>
parents: 10427
diff changeset
364 * Reading from disk *
04c663ccbcb1 [gaim-migrate @ 11680]
Mark Doliner <mark@kingant.net>
parents: 10427
diff changeset
365 *********************************************************************/
04c663ccbcb1 [gaim-migrate @ 11680]
Mark Doliner <mark@kingant.net>
parents: 10427
diff changeset
366
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
367 static GaimSavedStatusSub *
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
368 parse_substatus(xmlnode *substatus)
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
369 {
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
370 GaimSavedStatusSub *ret;
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
371 xmlnode *node;
10425
9903182f2aac [gaim-migrate @ 11677]
Mark Doliner <mark@kingant.net>
parents: 10424
diff changeset
372 char *data;
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
373
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
374 ret = g_new0(GaimSavedStatusSub, 1);
13761
ec858948d292 [gaim-migrate @ 16173]
Richard Laager <rlaager@wiktel.com>
parents: 13681
diff changeset
375 GAIM_DBUS_REGISTER_POINTER(ret, GaimSavedStatusSub);
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
376
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
377 /* Read the account */
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
378 node = xmlnode_get_child(substatus, "account");
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
379 if (node != NULL)
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
380 {
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
381 char *acct_name;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
382 const char *protocol;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
383 acct_name = xmlnode_get_data(node);
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
384 protocol = xmlnode_get_attrib(node, "protocol");
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
385 if ((acct_name != NULL) && (protocol != NULL))
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
386 ret->account = gaim_accounts_find(acct_name, protocol);
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
387 g_free(acct_name);
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
388 }
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
389
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
390 if (ret->account == NULL)
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 g_free(ret);
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
393 return NULL;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
394 }
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
395
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
396 /* Read the state */
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
397 node = xmlnode_get_child(substatus, "state");
10426
30d9ec7d001b [gaim-migrate @ 11678]
Mark Doliner <mark@kingant.net>
parents: 10425
diff changeset
398 if ((node != NULL) && ((data = xmlnode_get_data(node)) != NULL))
10425
9903182f2aac [gaim-migrate @ 11677]
Mark Doliner <mark@kingant.net>
parents: 10424
diff changeset
399 {
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
400 ret->type = gaim_status_type_find_with_id(
10425
9903182f2aac [gaim-migrate @ 11677]
Mark Doliner <mark@kingant.net>
parents: 10424
diff changeset
401 ret->account->status_types, data);
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
402 g_free(data);
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
403 }
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
404
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
405 /* Read the message */
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
406 node = xmlnode_get_child(substatus, "message");
10426
30d9ec7d001b [gaim-migrate @ 11678]
Mark Doliner <mark@kingant.net>
parents: 10425
diff changeset
407 if ((node != NULL) && ((data = xmlnode_get_data(node)) != NULL))
10425
9903182f2aac [gaim-migrate @ 11677]
Mark Doliner <mark@kingant.net>
parents: 10424
diff changeset
408 {
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
409 ret->message = data;
10425
9903182f2aac [gaim-migrate @ 11677]
Mark Doliner <mark@kingant.net>
parents: 10424
diff changeset
410 }
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
411
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
412 return ret;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
413 }
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
414
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 * 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
417 *
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
418 * Here's an example of the XML for a saved status:
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
419 * <status name="Girls">
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
420 * <state>away</state>
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
421 * <message>I like the way that they walk
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
422 * And it's chill to hear them talk
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
423 * And I can always make them smile
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
424 * From White Castle to the Nile</message>
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
425 * <substatus>
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
426 * <account protocol='prpl-oscar'>markdoliner</account>
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
427 * <state>available</state>
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
428 * <message>The ladies man is here to answer your queries.</message>
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
429 * </substatus>
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
430 * <substatus>
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
431 * <account protocol='prpl-oscar'>giantgraypanda</account>
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
432 * <state>away</state>
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
433 * <message>A.C. ain't in charge no more.</message>
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
434 * </substatus>
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
435 * </status>
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
436 *
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
437 * I know. Moving, huh?
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
438 */
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
439 static GaimSavedStatus *
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
440 parse_status(xmlnode *status)
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
441 {
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
442 GaimSavedStatus *ret;
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
443 xmlnode *node;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
444 const char *attrib;
10425
9903182f2aac [gaim-migrate @ 11677]
Mark Doliner <mark@kingant.net>
parents: 10424
diff changeset
445 char *data;
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
446 int i;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
447
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
448 ret = g_new0(GaimSavedStatus, 1);
13761
ec858948d292 [gaim-migrate @ 16173]
Richard Laager <rlaager@wiktel.com>
parents: 13681
diff changeset
449 GAIM_DBUS_REGISTER_POINTER(ret, GaimSavedStatus);
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
450
12283
4396691844e2 [gaim-migrate @ 14587]
Mark Doliner <mark@kingant.net>
parents: 12197
diff changeset
451 attrib = xmlnode_get_attrib(status, "transient");
4396691844e2 [gaim-migrate @ 14587]
Mark Doliner <mark@kingant.net>
parents: 12197
diff changeset
452 if ((attrib == NULL) || (strcmp(attrib, "true")))
4396691844e2 [gaim-migrate @ 14587]
Mark Doliner <mark@kingant.net>
parents: 12197
diff changeset
453 {
4396691844e2 [gaim-migrate @ 14587]
Mark Doliner <mark@kingant.net>
parents: 12197
diff changeset
454 /* Read the title */
4396691844e2 [gaim-migrate @ 14587]
Mark Doliner <mark@kingant.net>
parents: 12197
diff changeset
455 attrib = xmlnode_get_attrib(status, "name");
4396691844e2 [gaim-migrate @ 14587]
Mark Doliner <mark@kingant.net>
parents: 12197
diff changeset
456 ret->title = g_strdup(attrib);
4396691844e2 [gaim-migrate @ 14587]
Mark Doliner <mark@kingant.net>
parents: 12197
diff changeset
457 }
12125
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
458
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
459 if (ret->title != NULL)
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
460 {
12125
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
461 /* Ensure the title is unique */
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
462 i = 2;
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
463 while (gaim_savedstatus_find(ret->title) != NULL)
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
464 {
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
465 g_free(ret->title);
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
466 ret->title = g_strdup_printf("%s %d", attrib, i);
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
467 i++;
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
468 }
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
469 }
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
470
12125
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
471 /* Read the creation time */
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
472 attrib = xmlnode_get_attrib(status, "created");
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
473 set_creation_time(ret, (attrib != NULL ? atol(attrib) : 0));
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
474
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
475 /* Read the last used time */
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
476 attrib = xmlnode_get_attrib(status, "lastused");
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
477 ret->lastused = (attrib != NULL ? atol(attrib) : 0);
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
478
12688
473c23442a36 [gaim-migrate @ 15031]
Mark Doliner <mark@kingant.net>
parents: 12552
diff changeset
479 /* Read the usage count */
473c23442a36 [gaim-migrate @ 15031]
Mark Doliner <mark@kingant.net>
parents: 12552
diff changeset
480 attrib = xmlnode_get_attrib(status, "usage_count");
473c23442a36 [gaim-migrate @ 15031]
Mark Doliner <mark@kingant.net>
parents: 12552
diff changeset
481 ret->usage_count = (attrib != NULL ? atol(attrib) : 0);
473c23442a36 [gaim-migrate @ 15031]
Mark Doliner <mark@kingant.net>
parents: 12552
diff changeset
482
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
483 /* Read the primitive status type */
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
484 node = xmlnode_get_child(status, "state");
10426
30d9ec7d001b [gaim-migrate @ 11678]
Mark Doliner <mark@kingant.net>
parents: 10425
diff changeset
485 if ((node != NULL) && ((data = xmlnode_get_data(node)) != NULL))
10425
9903182f2aac [gaim-migrate @ 11677]
Mark Doliner <mark@kingant.net>
parents: 10424
diff changeset
486 {
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
487 ret->type = gaim_primitive_get_type_from_id(data);
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
488 g_free(data);
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
489 }
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
490
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
491 /* Read the message */
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
492 node = xmlnode_get_child(status, "message");
10426
30d9ec7d001b [gaim-migrate @ 11678]
Mark Doliner <mark@kingant.net>
parents: 10425
diff changeset
493 if ((node != NULL) && ((data = xmlnode_get_data(node)) != NULL))
10425
9903182f2aac [gaim-migrate @ 11677]
Mark Doliner <mark@kingant.net>
parents: 10424
diff changeset
494 {
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
495 ret->message = data;
10425
9903182f2aac [gaim-migrate @ 11677]
Mark Doliner <mark@kingant.net>
parents: 10424
diff changeset
496 }
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
497
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
498 /* Read substatuses */
12056
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
499 for (node = xmlnode_get_child(status, "substatus"); node != NULL;
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
500 node = xmlnode_get_next_twin(node))
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
501 {
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
502 GaimSavedStatusSub *new;
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
503 new = parse_substatus(node);
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
504 if (new != NULL)
12056
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
505 ret->substatuses = g_list_prepend(ret->substatuses, new);
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
506 }
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
507
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
508 return ret;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
509 }
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
510
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
511 /**
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
512 * Read the saved statuses from a file in the Gaim user dir.
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
513 *
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
514 * @return TRUE on success, FALSE on failure (if the file can not
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
515 * be opened, or if it contains invalid XML).
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
516 */
10425
9903182f2aac [gaim-migrate @ 11677]
Mark Doliner <mark@kingant.net>
parents: 10424
diff changeset
517 static void
9903182f2aac [gaim-migrate @ 11677]
Mark Doliner <mark@kingant.net>
parents: 10424
diff changeset
518 load_statuses(void)
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
519 {
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
520 xmlnode *statuses, *status;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
521
10426
30d9ec7d001b [gaim-migrate @ 11678]
Mark Doliner <mark@kingant.net>
parents: 10425
diff changeset
522 statuses_loaded = TRUE;
30d9ec7d001b [gaim-migrate @ 11678]
Mark Doliner <mark@kingant.net>
parents: 10425
diff changeset
523
10425
9903182f2aac [gaim-migrate @ 11677]
Mark Doliner <mark@kingant.net>
parents: 10424
diff changeset
524 statuses = gaim_util_read_xml_from_file("status.xml", _("saved statuses"));
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
525
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
526 if (statuses == NULL)
10425
9903182f2aac [gaim-migrate @ 11677]
Mark Doliner <mark@kingant.net>
parents: 10424
diff changeset
527 return;
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
528
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
529 for (status = xmlnode_get_child(statuses, "status"); status != NULL;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
530 status = xmlnode_get_next_twin(status))
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
531 {
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
532 GaimSavedStatus *new;
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
533 new = parse_status(status);
12056
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
534 saved_statuses = g_list_prepend(saved_statuses, new);
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
535 }
12724
10ef9171ca87 [gaim-migrate @ 15068]
Mark Doliner <mark@kingant.net>
parents: 12690
diff changeset
536 saved_statuses = g_list_sort(saved_statuses, saved_statuses_sort_func);
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
537
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
538 xmlnode_free(statuses);
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
539 }
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
540
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 /**************************************************************************
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
543 * Saved status API
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
544 **************************************************************************/
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
545 GaimSavedStatus *
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
546 gaim_savedstatus_new(const char *title, GaimStatusPrimitive type)
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
547 {
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
548 GaimSavedStatus *status;
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
549
12056
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
550 /* 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
551 if (title != NULL)
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
552 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
553
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
554 status = g_new0(GaimSavedStatus, 1);
13761
ec858948d292 [gaim-migrate @ 16173]
Richard Laager <rlaager@wiktel.com>
parents: 13681
diff changeset
555 GAIM_DBUS_REGISTER_POINTER(status, GaimSavedStatus);
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
556 status->title = g_strdup(title);
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
557 status->type = type;
12125
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
558 set_creation_time(status, time(NULL));
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
559
12724
10ef9171ca87 [gaim-migrate @ 15068]
Mark Doliner <mark@kingant.net>
parents: 12690
diff changeset
560 saved_statuses = g_list_insert_sorted(saved_statuses, status, saved_statuses_sort_func);
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
561
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
562 schedule_save();
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 return status;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
565 }
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
566
10420
854c972ea863 [gaim-migrate @ 11671]
Mark Doliner <mark@kingant.net>
parents: 10419
diff changeset
567 void
12056
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
568 gaim_savedstatus_set_title(GaimSavedStatus *status, const char *title)
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
569 {
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
570 g_return_if_fail(status != NULL);
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
571
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
572 /* 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
573 g_return_if_fail(gaim_savedstatus_find(title) == NULL);
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
574
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
575 g_free(status->title);
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
576 status->title = g_strdup(title);
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
577
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
578 schedule_save();
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
579 }
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
580
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
581 void
11651
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
582 gaim_savedstatus_set_type(GaimSavedStatus *status, GaimStatusPrimitive type)
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
583 {
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
584 g_return_if_fail(status != NULL);
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
585
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
586 status->type = type;
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
587
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
588 schedule_save();
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
589 }
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
590
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
591 void
10420
854c972ea863 [gaim-migrate @ 11671]
Mark Doliner <mark@kingant.net>
parents: 10419
diff changeset
592 gaim_savedstatus_set_message(GaimSavedStatus *status, const char *message)
854c972ea863 [gaim-migrate @ 11671]
Mark Doliner <mark@kingant.net>
parents: 10419
diff changeset
593 {
854c972ea863 [gaim-migrate @ 11671]
Mark Doliner <mark@kingant.net>
parents: 10419
diff changeset
594 g_return_if_fail(status != NULL);
854c972ea863 [gaim-migrate @ 11671]
Mark Doliner <mark@kingant.net>
parents: 10419
diff changeset
595
854c972ea863 [gaim-migrate @ 11671]
Mark Doliner <mark@kingant.net>
parents: 10419
diff changeset
596 g_free(status->message);
13246
24ac8fc885b8 [gaim-migrate @ 15612]
Mark Doliner <mark@kingant.net>
parents: 13244
diff changeset
597 if ((message != NULL) && (*message == '\0'))
24ac8fc885b8 [gaim-migrate @ 15612]
Mark Doliner <mark@kingant.net>
parents: 13244
diff changeset
598 status->message = NULL;
24ac8fc885b8 [gaim-migrate @ 15612]
Mark Doliner <mark@kingant.net>
parents: 13244
diff changeset
599 else
24ac8fc885b8 [gaim-migrate @ 15612]
Mark Doliner <mark@kingant.net>
parents: 13244
diff changeset
600 status->message = g_strdup(message);
10420
854c972ea863 [gaim-migrate @ 11671]
Mark Doliner <mark@kingant.net>
parents: 10419
diff changeset
601
854c972ea863 [gaim-migrate @ 11671]
Mark Doliner <mark@kingant.net>
parents: 10419
diff changeset
602 schedule_save();
854c972ea863 [gaim-migrate @ 11671]
Mark Doliner <mark@kingant.net>
parents: 10419
diff changeset
603 }
854c972ea863 [gaim-migrate @ 11671]
Mark Doliner <mark@kingant.net>
parents: 10419
diff changeset
604
12056
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
605 void
12080
3b52d94437f3 [gaim-migrate @ 14377]
Mark Doliner <mark@kingant.net>
parents: 12056
diff changeset
606 gaim_savedstatus_set_substatus(GaimSavedStatus *saved_status,
3b52d94437f3 [gaim-migrate @ 14377]
Mark Doliner <mark@kingant.net>
parents: 12056
diff changeset
607 const GaimAccount *account,
3b52d94437f3 [gaim-migrate @ 14377]
Mark Doliner <mark@kingant.net>
parents: 12056
diff changeset
608 const GaimStatusType *type,
3b52d94437f3 [gaim-migrate @ 14377]
Mark Doliner <mark@kingant.net>
parents: 12056
diff changeset
609 const char *message)
12056
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
610 {
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
611 GaimSavedStatusSub *substatus;
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
612
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
613 g_return_if_fail(saved_status != NULL);
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
614 g_return_if_fail(account != NULL);
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
615 g_return_if_fail(type != NULL);
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
616
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
617 /* Find an existing substatus or create a new one */
12080
3b52d94437f3 [gaim-migrate @ 14377]
Mark Doliner <mark@kingant.net>
parents: 12056
diff changeset
618 substatus = gaim_savedstatus_get_substatus(saved_status, account);
12056
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
619 if (substatus == NULL)
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
620 {
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
621 substatus = g_new0(GaimSavedStatusSub, 1);
13761
ec858948d292 [gaim-migrate @ 16173]
Richard Laager <rlaager@wiktel.com>
parents: 13681
diff changeset
622 GAIM_DBUS_REGISTER_POINTER(substatus, GaimSavedStatusSub);
12056
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
623 substatus->account = (GaimAccount *)account;
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
624 saved_status->substatuses = g_list_prepend(saved_status->substatuses, substatus);
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
625 }
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
626
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
627 substatus->type = type;
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
628 g_free(substatus->message);
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
629 substatus->message = g_strdup(message);
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
630
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
631 schedule_save();
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
632 }
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
633
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
634 void
12080
3b52d94437f3 [gaim-migrate @ 14377]
Mark Doliner <mark@kingant.net>
parents: 12056
diff changeset
635 gaim_savedstatus_unset_substatus(GaimSavedStatus *saved_status,
3b52d94437f3 [gaim-migrate @ 14377]
Mark Doliner <mark@kingant.net>
parents: 12056
diff changeset
636 const GaimAccount *account)
12056
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
637 {
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
638 GList *iter;
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
639 GaimSavedStatusSub *substatus;
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
640
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
641 g_return_if_fail(saved_status != NULL);
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
642 g_return_if_fail(account != NULL);
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
643
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
644 for (iter = saved_status->substatuses; iter != NULL; iter = iter->next)
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
645 {
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
646 substatus = iter->data;
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
647 if (substatus->account == account)
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
648 {
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
649 saved_status->substatuses = g_list_delete_link(saved_status->substatuses, iter);
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
650 g_free(substatus->message);
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
651 g_free(substatus);
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
652 return;
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
653 }
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
654 }
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
655 }
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
656
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
657 gboolean
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
658 gaim_savedstatus_delete(const char *title)
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
659 {
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
660 GaimSavedStatus *status;
12125
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
661 time_t creation_time, current, idleaway;
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
662
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
663 status = gaim_savedstatus_find(title);
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
664
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
665 if (status == NULL)
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
666 return FALSE;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
667
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
668 saved_statuses = g_list_remove(saved_statuses, status);
12125
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
669 creation_time = gaim_savedstatus_get_creation_time(status);
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
670 g_hash_table_remove(creation_times, &creation_time);
12724
10ef9171ca87 [gaim-migrate @ 15068]
Mark Doliner <mark@kingant.net>
parents: 12690
diff changeset
671 free_saved_status(status);
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
672
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
673 schedule_save();
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
674
12125
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
675 /*
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
676 * If we just deleted our current status or our idleaway status,
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
677 * then set the appropriate pref back to 0.
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
678 */
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
679 current = gaim_prefs_get_int("/core/savedstatus/current");
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
680 if (current == creation_time)
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
681 gaim_prefs_set_int("/core/savedstatus/current", 0);
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
682
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
683 idleaway = gaim_prefs_get_int("/core/savedstatus/idleaway");
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
684 if (idleaway == creation_time)
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
685 gaim_prefs_set_int("/core/savedstatus/idleaway", 0);
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
686
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
687 return TRUE;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
688 }
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
689
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
690 const GList *
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
691 gaim_savedstatuses_get_all(void)
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
692 {
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
693 return saved_statuses;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
694 }
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
695
12688
473c23442a36 [gaim-migrate @ 15031]
Mark Doliner <mark@kingant.net>
parents: 12552
diff changeset
696 GList *
473c23442a36 [gaim-migrate @ 15031]
Mark Doliner <mark@kingant.net>
parents: 12552
diff changeset
697 gaim_savedstatuses_get_popular(unsigned int how_many)
473c23442a36 [gaim-migrate @ 15031]
Mark Doliner <mark@kingant.net>
parents: 12552
diff changeset
698 {
13673
5948086807cd [gaim-migrate @ 16075]
Mark Doliner <mark@kingant.net>
parents: 13387
diff changeset
699 GList *popular = NULL;
12688
473c23442a36 [gaim-migrate @ 15031]
Mark Doliner <mark@kingant.net>
parents: 12552
diff changeset
700 GList *cur;
473c23442a36 [gaim-migrate @ 15031]
Mark Doliner <mark@kingant.net>
parents: 12552
diff changeset
701 int i;
13675
53fdb7cc6940 [gaim-migrate @ 16077]
Mark Doliner <mark@kingant.net>
parents: 13673
diff changeset
702 GaimSavedStatus *current, *next;
13673
5948086807cd [gaim-migrate @ 16075]
Mark Doliner <mark@kingant.net>
parents: 13387
diff changeset
703
5948086807cd [gaim-migrate @ 16075]
Mark Doliner <mark@kingant.net>
parents: 13387
diff changeset
704 /* We don't want the current status to be in the GList */
5948086807cd [gaim-migrate @ 16075]
Mark Doliner <mark@kingant.net>
parents: 13387
diff changeset
705 current = gaim_savedstatus_get_current();
12688
473c23442a36 [gaim-migrate @ 15031]
Mark Doliner <mark@kingant.net>
parents: 12552
diff changeset
706
473c23442a36 [gaim-migrate @ 15031]
Mark Doliner <mark@kingant.net>
parents: 12552
diff changeset
707 /* Copy 'how_many' elements to a new list */
13673
5948086807cd [gaim-migrate @ 16075]
Mark Doliner <mark@kingant.net>
parents: 13387
diff changeset
708 i = 0;
5948086807cd [gaim-migrate @ 16075]
Mark Doliner <mark@kingant.net>
parents: 13387
diff changeset
709 cur = saved_statuses;
5948086807cd [gaim-migrate @ 16075]
Mark Doliner <mark@kingant.net>
parents: 13387
diff changeset
710 while ((i < how_many) && (cur != NULL))
12688
473c23442a36 [gaim-migrate @ 15031]
Mark Doliner <mark@kingant.net>
parents: 12552
diff changeset
711 {
13675
53fdb7cc6940 [gaim-migrate @ 16077]
Mark Doliner <mark@kingant.net>
parents: 13673
diff changeset
712 next = cur->data;
53fdb7cc6940 [gaim-migrate @ 16077]
Mark Doliner <mark@kingant.net>
parents: 13673
diff changeset
713 if ((next != current) && (!gaim_savedstatus_is_transient(next)
53fdb7cc6940 [gaim-migrate @ 16077]
Mark Doliner <mark@kingant.net>
parents: 13673
diff changeset
714 || gaim_savedstatus_get_message(next) != NULL))
13673
5948086807cd [gaim-migrate @ 16075]
Mark Doliner <mark@kingant.net>
parents: 13387
diff changeset
715 {
5948086807cd [gaim-migrate @ 16075]
Mark Doliner <mark@kingant.net>
parents: 13387
diff changeset
716 popular = g_list_prepend(popular, cur->data);
5948086807cd [gaim-migrate @ 16075]
Mark Doliner <mark@kingant.net>
parents: 13387
diff changeset
717 i++;
5948086807cd [gaim-migrate @ 16075]
Mark Doliner <mark@kingant.net>
parents: 13387
diff changeset
718 }
12688
473c23442a36 [gaim-migrate @ 15031]
Mark Doliner <mark@kingant.net>
parents: 12552
diff changeset
719 cur = cur->next;
473c23442a36 [gaim-migrate @ 15031]
Mark Doliner <mark@kingant.net>
parents: 12552
diff changeset
720 }
473c23442a36 [gaim-migrate @ 15031]
Mark Doliner <mark@kingant.net>
parents: 12552
diff changeset
721
13673
5948086807cd [gaim-migrate @ 16075]
Mark Doliner <mark@kingant.net>
parents: 13387
diff changeset
722 popular = g_list_reverse(popular);
5948086807cd [gaim-migrate @ 16075]
Mark Doliner <mark@kingant.net>
parents: 13387
diff changeset
723
5948086807cd [gaim-migrate @ 16075]
Mark Doliner <mark@kingant.net>
parents: 13387
diff changeset
724 return popular;
12688
473c23442a36 [gaim-migrate @ 15031]
Mark Doliner <mark@kingant.net>
parents: 12552
diff changeset
725 }
473c23442a36 [gaim-migrate @ 15031]
Mark Doliner <mark@kingant.net>
parents: 12552
diff changeset
726
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
727 GaimSavedStatus *
12125
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
728 gaim_savedstatus_get_current()
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
729 {
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
730 int creation_time;
12197
0ab1c9916dc2 [gaim-migrate @ 14499]
Mark Doliner <mark@kingant.net>
parents: 12125
diff changeset
731 GaimSavedStatus *saved_status = NULL;
12125
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
732
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
733 creation_time = gaim_prefs_get_int("/core/savedstatus/current");
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
734
12197
0ab1c9916dc2 [gaim-migrate @ 14499]
Mark Doliner <mark@kingant.net>
parents: 12125
diff changeset
735 if (creation_time != 0)
0ab1c9916dc2 [gaim-migrate @ 14499]
Mark Doliner <mark@kingant.net>
parents: 12125
diff changeset
736 saved_status = g_hash_table_lookup(creation_times, &creation_time);
0ab1c9916dc2 [gaim-migrate @ 14499]
Mark Doliner <mark@kingant.net>
parents: 12125
diff changeset
737
0ab1c9916dc2 [gaim-migrate @ 14499]
Mark Doliner <mark@kingant.net>
parents: 12125
diff changeset
738 if (saved_status == NULL)
12125
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
739 {
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
740 /*
13681
c4be649e2aca [gaim-migrate @ 16084]
Mark Doliner <mark@kingant.net>
parents: 13675
diff changeset
741 * We don't have a current saved status! This is either a new
12197
0ab1c9916dc2 [gaim-migrate @ 14499]
Mark Doliner <mark@kingant.net>
parents: 12125
diff changeset
742 * Gaim user or someone upgrading from Gaim 1.5.0 or older, or
0ab1c9916dc2 [gaim-migrate @ 14499]
Mark Doliner <mark@kingant.net>
parents: 12125
diff changeset
743 * possibly someone who deleted the status they were currently
0ab1c9916dc2 [gaim-migrate @ 14499]
Mark Doliner <mark@kingant.net>
parents: 12125
diff changeset
744 * using? In any case, add a default status.
12125
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
745 */
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
746 saved_status = gaim_savedstatus_new(NULL, GAIM_STATUS_AVAILABLE);
13246
24ac8fc885b8 [gaim-migrate @ 15612]
Mark Doliner <mark@kingant.net>
parents: 13244
diff changeset
747 gaim_prefs_set_int("/core/savedstatus/current",
24ac8fc885b8 [gaim-migrate @ 15612]
Mark Doliner <mark@kingant.net>
parents: 13244
diff changeset
748 gaim_savedstatus_get_creation_time(saved_status));
12125
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
749 }
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
750
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
751 return saved_status;
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
752 }
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
753
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
754 GaimSavedStatus *
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
755 gaim_savedstatus_get_idleaway()
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
756 {
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
757 int creation_time;
13681
c4be649e2aca [gaim-migrate @ 16084]
Mark Doliner <mark@kingant.net>
parents: 13675
diff changeset
758 GaimSavedStatus *saved_status = NULL;
12125
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
759
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
760 creation_time = gaim_prefs_get_int("/core/savedstatus/idleaway");
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
761
13681
c4be649e2aca [gaim-migrate @ 16084]
Mark Doliner <mark@kingant.net>
parents: 13675
diff changeset
762 if (creation_time != 0)
c4be649e2aca [gaim-migrate @ 16084]
Mark Doliner <mark@kingant.net>
parents: 13675
diff changeset
763 saved_status = g_hash_table_lookup(creation_times, &creation_time);
c4be649e2aca [gaim-migrate @ 16084]
Mark Doliner <mark@kingant.net>
parents: 13675
diff changeset
764
c4be649e2aca [gaim-migrate @ 16084]
Mark Doliner <mark@kingant.net>
parents: 13675
diff changeset
765 if (saved_status == NULL)
12125
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
766 {
13681
c4be649e2aca [gaim-migrate @ 16084]
Mark Doliner <mark@kingant.net>
parents: 13675
diff changeset
767 /* We don't have a specified "idle" status! Weird. */
c4be649e2aca [gaim-migrate @ 16084]
Mark Doliner <mark@kingant.net>
parents: 13675
diff changeset
768 saved_status = gaim_savedstatus_find_transient_by_type_and_message(
c4be649e2aca [gaim-migrate @ 16084]
Mark Doliner <mark@kingant.net>
parents: 13675
diff changeset
769 GAIM_STATUS_AWAY, DEFAULT_AUTOAWAY_MESSAGE);
c4be649e2aca [gaim-migrate @ 16084]
Mark Doliner <mark@kingant.net>
parents: 13675
diff changeset
770
c4be649e2aca [gaim-migrate @ 16084]
Mark Doliner <mark@kingant.net>
parents: 13675
diff changeset
771 if (saved_status == NULL)
c4be649e2aca [gaim-migrate @ 16084]
Mark Doliner <mark@kingant.net>
parents: 13675
diff changeset
772 {
c4be649e2aca [gaim-migrate @ 16084]
Mark Doliner <mark@kingant.net>
parents: 13675
diff changeset
773 saved_status = gaim_savedstatus_new(NULL, GAIM_STATUS_AWAY);
c4be649e2aca [gaim-migrate @ 16084]
Mark Doliner <mark@kingant.net>
parents: 13675
diff changeset
774 gaim_savedstatus_set_message(saved_status, DEFAULT_AUTOAWAY_MESSAGE);
c4be649e2aca [gaim-migrate @ 16084]
Mark Doliner <mark@kingant.net>
parents: 13675
diff changeset
775 gaim_prefs_set_int("/core/savedstatus/idleaway",
c4be649e2aca [gaim-migrate @ 16084]
Mark Doliner <mark@kingant.net>
parents: 13675
diff changeset
776 gaim_savedstatus_get_creation_time(saved_status));
c4be649e2aca [gaim-migrate @ 16084]
Mark Doliner <mark@kingant.net>
parents: 13675
diff changeset
777 }
12125
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
778 }
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
779
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
780 return saved_status;
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
781 }
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
782
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
783 GaimSavedStatus *
13681
c4be649e2aca [gaim-migrate @ 16084]
Mark Doliner <mark@kingant.net>
parents: 13675
diff changeset
784 gaim_savedstatus_get_startup()
c4be649e2aca [gaim-migrate @ 16084]
Mark Doliner <mark@kingant.net>
parents: 13675
diff changeset
785 {
c4be649e2aca [gaim-migrate @ 16084]
Mark Doliner <mark@kingant.net>
parents: 13675
diff changeset
786 int creation_time;
c4be649e2aca [gaim-migrate @ 16084]
Mark Doliner <mark@kingant.net>
parents: 13675
diff changeset
787 GaimSavedStatus *saved_status = NULL;
c4be649e2aca [gaim-migrate @ 16084]
Mark Doliner <mark@kingant.net>
parents: 13675
diff changeset
788
c4be649e2aca [gaim-migrate @ 16084]
Mark Doliner <mark@kingant.net>
parents: 13675
diff changeset
789 creation_time = gaim_prefs_get_int("/core/savedstatus/startup");
c4be649e2aca [gaim-migrate @ 16084]
Mark Doliner <mark@kingant.net>
parents: 13675
diff changeset
790
c4be649e2aca [gaim-migrate @ 16084]
Mark Doliner <mark@kingant.net>
parents: 13675
diff changeset
791 if (creation_time != 0)
c4be649e2aca [gaim-migrate @ 16084]
Mark Doliner <mark@kingant.net>
parents: 13675
diff changeset
792 saved_status = g_hash_table_lookup(creation_times, &creation_time);
c4be649e2aca [gaim-migrate @ 16084]
Mark Doliner <mark@kingant.net>
parents: 13675
diff changeset
793
c4be649e2aca [gaim-migrate @ 16084]
Mark Doliner <mark@kingant.net>
parents: 13675
diff changeset
794 if (saved_status == NULL)
c4be649e2aca [gaim-migrate @ 16084]
Mark Doliner <mark@kingant.net>
parents: 13675
diff changeset
795 {
c4be649e2aca [gaim-migrate @ 16084]
Mark Doliner <mark@kingant.net>
parents: 13675
diff changeset
796 /*
c4be649e2aca [gaim-migrate @ 16084]
Mark Doliner <mark@kingant.net>
parents: 13675
diff changeset
797 * We don't have a status to apply.
c4be649e2aca [gaim-migrate @ 16084]
Mark Doliner <mark@kingant.net>
parents: 13675
diff changeset
798 * This may be the first login, or the user wants to
c4be649e2aca [gaim-migrate @ 16084]
Mark Doliner <mark@kingant.net>
parents: 13675
diff changeset
799 * restore the "current" status.
c4be649e2aca [gaim-migrate @ 16084]
Mark Doliner <mark@kingant.net>
parents: 13675
diff changeset
800 */
c4be649e2aca [gaim-migrate @ 16084]
Mark Doliner <mark@kingant.net>
parents: 13675
diff changeset
801 saved_status = gaim_savedstatus_get_current();
c4be649e2aca [gaim-migrate @ 16084]
Mark Doliner <mark@kingant.net>
parents: 13675
diff changeset
802 }
c4be649e2aca [gaim-migrate @ 16084]
Mark Doliner <mark@kingant.net>
parents: 13675
diff changeset
803
c4be649e2aca [gaim-migrate @ 16084]
Mark Doliner <mark@kingant.net>
parents: 13675
diff changeset
804 return saved_status;
c4be649e2aca [gaim-migrate @ 16084]
Mark Doliner <mark@kingant.net>
parents: 13675
diff changeset
805 }
c4be649e2aca [gaim-migrate @ 16084]
Mark Doliner <mark@kingant.net>
parents: 13675
diff changeset
806
c4be649e2aca [gaim-migrate @ 16084]
Mark Doliner <mark@kingant.net>
parents: 13675
diff changeset
807
c4be649e2aca [gaim-migrate @ 16084]
Mark Doliner <mark@kingant.net>
parents: 13675
diff changeset
808 GaimSavedStatus *
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
809 gaim_savedstatus_find(const char *title)
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
810 {
12056
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
811 GList *iter;
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
812 GaimSavedStatus *status;
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
813
11977
0ea9a52fd333 [gaim-migrate @ 14270]
Mark Doliner <mark@kingant.net>
parents: 11975
diff changeset
814 g_return_val_if_fail(title != NULL, NULL);
0ea9a52fd333 [gaim-migrate @ 14270]
Mark Doliner <mark@kingant.net>
parents: 11975
diff changeset
815
12056
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
816 for (iter = saved_statuses; iter != NULL; iter = iter->next)
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
817 {
12056
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
818 status = (GaimSavedStatus *)iter->data;
12125
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
819 if ((status->title != NULL) && !strcmp(status->title, title))
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
820 return status;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
821 }
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
822
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
823 return NULL;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
824 }
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
825
12690
d03afaccd41c [gaim-migrate @ 15033]
Mark Doliner <mark@kingant.net>
parents: 12688
diff changeset
826 GaimSavedStatus *
d03afaccd41c [gaim-migrate @ 15033]
Mark Doliner <mark@kingant.net>
parents: 12688
diff changeset
827 gaim_savedstatus_find_by_creation_time(time_t creation_time)
d03afaccd41c [gaim-migrate @ 15033]
Mark Doliner <mark@kingant.net>
parents: 12688
diff changeset
828 {
d03afaccd41c [gaim-migrate @ 15033]
Mark Doliner <mark@kingant.net>
parents: 12688
diff changeset
829 GList *iter;
d03afaccd41c [gaim-migrate @ 15033]
Mark Doliner <mark@kingant.net>
parents: 12688
diff changeset
830 GaimSavedStatus *status;
d03afaccd41c [gaim-migrate @ 15033]
Mark Doliner <mark@kingant.net>
parents: 12688
diff changeset
831
d03afaccd41c [gaim-migrate @ 15033]
Mark Doliner <mark@kingant.net>
parents: 12688
diff changeset
832 for (iter = saved_statuses; iter != NULL; iter = iter->next)
d03afaccd41c [gaim-migrate @ 15033]
Mark Doliner <mark@kingant.net>
parents: 12688
diff changeset
833 {
d03afaccd41c [gaim-migrate @ 15033]
Mark Doliner <mark@kingant.net>
parents: 12688
diff changeset
834 status = (GaimSavedStatus *)iter->data;
d03afaccd41c [gaim-migrate @ 15033]
Mark Doliner <mark@kingant.net>
parents: 12688
diff changeset
835 if (status->creation_time == creation_time)
d03afaccd41c [gaim-migrate @ 15033]
Mark Doliner <mark@kingant.net>
parents: 12688
diff changeset
836 return status;
d03afaccd41c [gaim-migrate @ 15033]
Mark Doliner <mark@kingant.net>
parents: 12688
diff changeset
837 }
d03afaccd41c [gaim-migrate @ 15033]
Mark Doliner <mark@kingant.net>
parents: 12688
diff changeset
838
d03afaccd41c [gaim-migrate @ 15033]
Mark Doliner <mark@kingant.net>
parents: 12688
diff changeset
839 return NULL;
d03afaccd41c [gaim-migrate @ 15033]
Mark Doliner <mark@kingant.net>
parents: 12688
diff changeset
840 }
d03afaccd41c [gaim-migrate @ 15033]
Mark Doliner <mark@kingant.net>
parents: 12688
diff changeset
841
13012
e3b9c6c7bcf6 [gaim-migrate @ 15365]
Mark Doliner <mark@kingant.net>
parents: 12857
diff changeset
842 GaimSavedStatus *
13244
c97c76d9d347 [gaim-migrate @ 15610]
Mark Doliner <mark@kingant.net>
parents: 13197
diff changeset
843 gaim_savedstatus_find_transient_by_type_and_message(GaimStatusPrimitive type,
c97c76d9d347 [gaim-migrate @ 15610]
Mark Doliner <mark@kingant.net>
parents: 13197
diff changeset
844 const char *message)
13012
e3b9c6c7bcf6 [gaim-migrate @ 15365]
Mark Doliner <mark@kingant.net>
parents: 12857
diff changeset
845 {
e3b9c6c7bcf6 [gaim-migrate @ 15365]
Mark Doliner <mark@kingant.net>
parents: 12857
diff changeset
846 GList *iter;
e3b9c6c7bcf6 [gaim-migrate @ 15365]
Mark Doliner <mark@kingant.net>
parents: 12857
diff changeset
847 GaimSavedStatus *status;
e3b9c6c7bcf6 [gaim-migrate @ 15365]
Mark Doliner <mark@kingant.net>
parents: 12857
diff changeset
848
e3b9c6c7bcf6 [gaim-migrate @ 15365]
Mark Doliner <mark@kingant.net>
parents: 12857
diff changeset
849 for (iter = saved_statuses; iter != NULL; iter = iter->next)
e3b9c6c7bcf6 [gaim-migrate @ 15365]
Mark Doliner <mark@kingant.net>
parents: 12857
diff changeset
850 {
e3b9c6c7bcf6 [gaim-migrate @ 15365]
Mark Doliner <mark@kingant.net>
parents: 12857
diff changeset
851 status = (GaimSavedStatus *)iter->data;
13244
c97c76d9d347 [gaim-migrate @ 15610]
Mark Doliner <mark@kingant.net>
parents: 13197
diff changeset
852 if ((status->type == type) && gaim_savedstatus_is_transient(status) &&
13012
e3b9c6c7bcf6 [gaim-migrate @ 15365]
Mark Doliner <mark@kingant.net>
parents: 12857
diff changeset
853 (((status->message == NULL) && (message == NULL)) ||
e3b9c6c7bcf6 [gaim-migrate @ 15365]
Mark Doliner <mark@kingant.net>
parents: 12857
diff changeset
854 ((status->message != NULL) && (message != NULL) && !strcmp(status->message, message))))
e3b9c6c7bcf6 [gaim-migrate @ 15365]
Mark Doliner <mark@kingant.net>
parents: 12857
diff changeset
855 {
e3b9c6c7bcf6 [gaim-migrate @ 15365]
Mark Doliner <mark@kingant.net>
parents: 12857
diff changeset
856 return status;
e3b9c6c7bcf6 [gaim-migrate @ 15365]
Mark Doliner <mark@kingant.net>
parents: 12857
diff changeset
857 }
e3b9c6c7bcf6 [gaim-migrate @ 15365]
Mark Doliner <mark@kingant.net>
parents: 12857
diff changeset
858 }
e3b9c6c7bcf6 [gaim-migrate @ 15365]
Mark Doliner <mark@kingant.net>
parents: 12857
diff changeset
859
e3b9c6c7bcf6 [gaim-migrate @ 15365]
Mark Doliner <mark@kingant.net>
parents: 12857
diff changeset
860 return NULL;
e3b9c6c7bcf6 [gaim-migrate @ 15365]
Mark Doliner <mark@kingant.net>
parents: 12857
diff changeset
861 }
e3b9c6c7bcf6 [gaim-migrate @ 15365]
Mark Doliner <mark@kingant.net>
parents: 12857
diff changeset
862
11651
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
863 gboolean
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
864 gaim_savedstatus_is_transient(const GaimSavedStatus *saved_status)
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
865 {
12197
0ab1c9916dc2 [gaim-migrate @ 14499]
Mark Doliner <mark@kingant.net>
parents: 12125
diff changeset
866 g_return_val_if_fail(saved_status != NULL, TRUE);
0ab1c9916dc2 [gaim-migrate @ 14499]
Mark Doliner <mark@kingant.net>
parents: 12125
diff changeset
867
12125
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
868 return (saved_status->title == NULL);
11651
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
869 }
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
870
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
871 const char *
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
872 gaim_savedstatus_get_title(const GaimSavedStatus *saved_status)
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
873 {
12690
d03afaccd41c [gaim-migrate @ 15033]
Mark Doliner <mark@kingant.net>
parents: 12688
diff changeset
874 const char *message;
d03afaccd41c [gaim-migrate @ 15033]
Mark Doliner <mark@kingant.net>
parents: 12688
diff changeset
875
12197
0ab1c9916dc2 [gaim-migrate @ 14499]
Mark Doliner <mark@kingant.net>
parents: 12125
diff changeset
876 g_return_val_if_fail(saved_status != NULL, NULL);
0ab1c9916dc2 [gaim-migrate @ 14499]
Mark Doliner <mark@kingant.net>
parents: 12125
diff changeset
877
12690
d03afaccd41c [gaim-migrate @ 15033]
Mark Doliner <mark@kingant.net>
parents: 12688
diff changeset
878 /* If we have a title then return it */
d03afaccd41c [gaim-migrate @ 15033]
Mark Doliner <mark@kingant.net>
parents: 12688
diff changeset
879 if (saved_status->title != NULL)
d03afaccd41c [gaim-migrate @ 15033]
Mark Doliner <mark@kingant.net>
parents: 12688
diff changeset
880 return saved_status->title;
d03afaccd41c [gaim-migrate @ 15033]
Mark Doliner <mark@kingant.net>
parents: 12688
diff changeset
881
d03afaccd41c [gaim-migrate @ 15033]
Mark Doliner <mark@kingant.net>
parents: 12688
diff changeset
882 /* Otherwise, this is a transient status and we make up a title on the fly */
d03afaccd41c [gaim-migrate @ 15033]
Mark Doliner <mark@kingant.net>
parents: 12688
diff changeset
883 message = gaim_savedstatus_get_message(saved_status);
12688
473c23442a36 [gaim-migrate @ 15031]
Mark Doliner <mark@kingant.net>
parents: 12552
diff changeset
884
12781
ab65ade2e93f [gaim-migrate @ 15128]
Mark Doliner <mark@kingant.net>
parents: 12729
diff changeset
885 if ((message == NULL) || (*message == '\0'))
12690
d03afaccd41c [gaim-migrate @ 15033]
Mark Doliner <mark@kingant.net>
parents: 12688
diff changeset
886 {
d03afaccd41c [gaim-migrate @ 15033]
Mark Doliner <mark@kingant.net>
parents: 12688
diff changeset
887 GaimStatusPrimitive primitive;
d03afaccd41c [gaim-migrate @ 15033]
Mark Doliner <mark@kingant.net>
parents: 12688
diff changeset
888 primitive = gaim_savedstatus_get_type(saved_status);
12814
f88f145884c0 [gaim-migrate @ 15162]
Richard Laager <rlaager@wiktel.com>
parents: 12781
diff changeset
889 return gaim_primitive_get_name_from_type(primitive);
12690
d03afaccd41c [gaim-migrate @ 15033]
Mark Doliner <mark@kingant.net>
parents: 12688
diff changeset
890 }
d03afaccd41c [gaim-migrate @ 15033]
Mark Doliner <mark@kingant.net>
parents: 12688
diff changeset
891 else
d03afaccd41c [gaim-migrate @ 15033]
Mark Doliner <mark@kingant.net>
parents: 12688
diff changeset
892 {
d03afaccd41c [gaim-migrate @ 15033]
Mark Doliner <mark@kingant.net>
parents: 12688
diff changeset
893 char *stripped;
d03afaccd41c [gaim-migrate @ 15033]
Mark Doliner <mark@kingant.net>
parents: 12688
diff changeset
894 static char buf[64];
d03afaccd41c [gaim-migrate @ 15033]
Mark Doliner <mark@kingant.net>
parents: 12688
diff changeset
895 stripped = gaim_markup_strip_html(message);
d03afaccd41c [gaim-migrate @ 15033]
Mark Doliner <mark@kingant.net>
parents: 12688
diff changeset
896 gaim_util_chrreplace(stripped, '\n', ' ');
d03afaccd41c [gaim-migrate @ 15033]
Mark Doliner <mark@kingant.net>
parents: 12688
diff changeset
897 strncpy(buf, stripped, sizeof(buf));
d03afaccd41c [gaim-migrate @ 15033]
Mark Doliner <mark@kingant.net>
parents: 12688
diff changeset
898 buf[sizeof(buf) - 1] = '\0';
d03afaccd41c [gaim-migrate @ 15033]
Mark Doliner <mark@kingant.net>
parents: 12688
diff changeset
899 if ((strlen(stripped) + 1) > sizeof(buf))
12688
473c23442a36 [gaim-migrate @ 15031]
Mark Doliner <mark@kingant.net>
parents: 12552
diff changeset
900 {
12690
d03afaccd41c [gaim-migrate @ 15033]
Mark Doliner <mark@kingant.net>
parents: 12688
diff changeset
901 /* Truncate and ellipsize */
d03afaccd41c [gaim-migrate @ 15033]
Mark Doliner <mark@kingant.net>
parents: 12688
diff changeset
902 char *tmp = g_utf8_find_prev_char(buf, &buf[sizeof(buf) - 4]);
d03afaccd41c [gaim-migrate @ 15033]
Mark Doliner <mark@kingant.net>
parents: 12688
diff changeset
903 strcpy(tmp, "...");
12688
473c23442a36 [gaim-migrate @ 15031]
Mark Doliner <mark@kingant.net>
parents: 12552
diff changeset
904 }
12690
d03afaccd41c [gaim-migrate @ 15033]
Mark Doliner <mark@kingant.net>
parents: 12688
diff changeset
905 g_free(stripped);
d03afaccd41c [gaim-migrate @ 15033]
Mark Doliner <mark@kingant.net>
parents: 12688
diff changeset
906 return buf;
12688
473c23442a36 [gaim-migrate @ 15031]
Mark Doliner <mark@kingant.net>
parents: 12552
diff changeset
907 }
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
908 }
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
909
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
910 GaimStatusPrimitive
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
911 gaim_savedstatus_get_type(const GaimSavedStatus *saved_status)
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
912 {
12197
0ab1c9916dc2 [gaim-migrate @ 14499]
Mark Doliner <mark@kingant.net>
parents: 12125
diff changeset
913 g_return_val_if_fail(saved_status != NULL, GAIM_STATUS_OFFLINE);
0ab1c9916dc2 [gaim-migrate @ 14499]
Mark Doliner <mark@kingant.net>
parents: 12125
diff changeset
914
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
915 return saved_status->type;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
916 }
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
917
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
918 const char *
10419
c9b1f3fac753 [gaim-migrate @ 11670]
Mark Doliner <mark@kingant.net>
parents: 10418
diff changeset
919 gaim_savedstatus_get_message(const GaimSavedStatus *saved_status)
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
920 {
12197
0ab1c9916dc2 [gaim-migrate @ 14499]
Mark Doliner <mark@kingant.net>
parents: 12125
diff changeset
921 g_return_val_if_fail(saved_status != NULL, NULL);
0ab1c9916dc2 [gaim-migrate @ 14499]
Mark Doliner <mark@kingant.net>
parents: 12125
diff changeset
922
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
923 return saved_status->message;
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
924 }
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
925
12125
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
926 time_t
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
927 gaim_savedstatus_get_creation_time(const GaimSavedStatus *saved_status)
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
928 {
12197
0ab1c9916dc2 [gaim-migrate @ 14499]
Mark Doliner <mark@kingant.net>
parents: 12125
diff changeset
929 g_return_val_if_fail(saved_status != NULL, 0);
0ab1c9916dc2 [gaim-migrate @ 14499]
Mark Doliner <mark@kingant.net>
parents: 12125
diff changeset
930
12125
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
931 return saved_status->creation_time;
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
932 }
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
933
11651
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
934 gboolean
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
935 gaim_savedstatus_has_substatuses(const GaimSavedStatus *saved_status)
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
936 {
12197
0ab1c9916dc2 [gaim-migrate @ 14499]
Mark Doliner <mark@kingant.net>
parents: 12125
diff changeset
937 g_return_val_if_fail(saved_status != NULL, FALSE);
0ab1c9916dc2 [gaim-migrate @ 14499]
Mark Doliner <mark@kingant.net>
parents: 12125
diff changeset
938
11651
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
939 return (saved_status->substatuses != NULL);
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
940 }
723487d07aa0 [gaim-migrate @ 13935]
Mark Doliner <mark@kingant.net>
parents: 11318
diff changeset
941
12056
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
942 GaimSavedStatusSub *
12080
3b52d94437f3 [gaim-migrate @ 14377]
Mark Doliner <mark@kingant.net>
parents: 12056
diff changeset
943 gaim_savedstatus_get_substatus(const GaimSavedStatus *saved_status,
3b52d94437f3 [gaim-migrate @ 14377]
Mark Doliner <mark@kingant.net>
parents: 12056
diff changeset
944 const GaimAccount *account)
12056
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
945 {
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
946 GList *iter;
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
947 GaimSavedStatusSub *substatus;
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
948
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
949 g_return_val_if_fail(saved_status != NULL, NULL);
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
950 g_return_val_if_fail(account != NULL, NULL);
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
951
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
952 for (iter = saved_status->substatuses; iter != NULL; iter = iter->next)
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
953 {
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
954 substatus = iter->data;
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
955 if (substatus->account == account)
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
956 return substatus;
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
957 }
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
958
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
959 return NULL;
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
960 }
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
961
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
962 const GaimStatusType *
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
963 gaim_savedstatus_substatus_get_type(const GaimSavedStatusSub *substatus)
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
964 {
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
965 g_return_val_if_fail(substatus != NULL, NULL);
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
966
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
967 return substatus->type;
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
968 }
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
969
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
970 const char *
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
971 gaim_savedstatus_substatus_get_message(const GaimSavedStatusSub *substatus)
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
972 {
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
973 g_return_val_if_fail(substatus != NULL, NULL);
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
974
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
975 return substatus->message;
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
976 }
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
977
11724
a8ec0a291d14 [gaim-migrate @ 14015]
Mark Doliner <mark@kingant.net>
parents: 11651
diff changeset
978 void
12125
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
979 gaim_savedstatus_activate(GaimSavedStatus *saved_status)
11724
a8ec0a291d14 [gaim-migrate @ 14015]
Mark Doliner <mark@kingant.net>
parents: 11651
diff changeset
980 {
11733
ef511dec9903 [gaim-migrate @ 14024]
Mark Doliner <mark@kingant.net>
parents: 11727
diff changeset
981 GList *accounts, *node;
13387
d9dbb874a30c [gaim-migrate @ 15760]
Richard Laager <rlaager@wiktel.com>
parents: 13246
diff changeset
982 GaimSavedStatus *old = gaim_savedstatus_get_current();
11724
a8ec0a291d14 [gaim-migrate @ 14015]
Mark Doliner <mark@kingant.net>
parents: 11651
diff changeset
983
11727
8657ad65e257 [gaim-migrate @ 14018]
Mark Doliner <mark@kingant.net>
parents: 11724
diff changeset
984 g_return_if_fail(saved_status != NULL);
8657ad65e257 [gaim-migrate @ 14018]
Mark Doliner <mark@kingant.net>
parents: 11724
diff changeset
985
12729
d3232d64fafd [gaim-migrate @ 15073]
Mark Doliner <mark@kingant.net>
parents: 12724
diff changeset
986 /* Make sure our list of saved statuses remains sorted */
d3232d64fafd [gaim-migrate @ 15073]
Mark Doliner <mark@kingant.net>
parents: 12724
diff changeset
987 saved_status->lastused = time(NULL);
d3232d64fafd [gaim-migrate @ 15073]
Mark Doliner <mark@kingant.net>
parents: 12724
diff changeset
988 saved_status->usage_count++;
d3232d64fafd [gaim-migrate @ 15073]
Mark Doliner <mark@kingant.net>
parents: 12724
diff changeset
989 saved_statuses = g_list_remove(saved_statuses, saved_status);
d3232d64fafd [gaim-migrate @ 15073]
Mark Doliner <mark@kingant.net>
parents: 12724
diff changeset
990 saved_statuses = g_list_insert_sorted(saved_statuses, saved_status, saved_statuses_sort_func);
d3232d64fafd [gaim-migrate @ 15073]
Mark Doliner <mark@kingant.net>
parents: 12724
diff changeset
991
11724
a8ec0a291d14 [gaim-migrate @ 14015]
Mark Doliner <mark@kingant.net>
parents: 11651
diff changeset
992 accounts = gaim_accounts_get_all_active();
11733
ef511dec9903 [gaim-migrate @ 14024]
Mark Doliner <mark@kingant.net>
parents: 11727
diff changeset
993 for (node = accounts; node != NULL; node = node->next)
11724
a8ec0a291d14 [gaim-migrate @ 14015]
Mark Doliner <mark@kingant.net>
parents: 11651
diff changeset
994 {
a8ec0a291d14 [gaim-migrate @ 14015]
Mark Doliner <mark@kingant.net>
parents: 11651
diff changeset
995 GaimAccount *account;
a8ec0a291d14 [gaim-migrate @ 14015]
Mark Doliner <mark@kingant.net>
parents: 11651
diff changeset
996
11733
ef511dec9903 [gaim-migrate @ 14024]
Mark Doliner <mark@kingant.net>
parents: 11727
diff changeset
997 account = node->data;
12857
e5f780a6137b [gaim-migrate @ 15208]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12814
diff changeset
998
11724
a8ec0a291d14 [gaim-migrate @ 14015]
Mark Doliner <mark@kingant.net>
parents: 11651
diff changeset
999 gaim_savedstatus_activate_for_account(saved_status, account);
a8ec0a291d14 [gaim-migrate @ 14015]
Mark Doliner <mark@kingant.net>
parents: 11651
diff changeset
1000 }
11733
ef511dec9903 [gaim-migrate @ 14024]
Mark Doliner <mark@kingant.net>
parents: 11727
diff changeset
1001
ef511dec9903 [gaim-migrate @ 14024]
Mark Doliner <mark@kingant.net>
parents: 11727
diff changeset
1002 g_list_free(accounts);
11954
351f4dd75718 [gaim-migrate @ 14245]
Mark Doliner <mark@kingant.net>
parents: 11806
diff changeset
1003
12125
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
1004 gaim_prefs_set_int("/core/savedstatus/current",
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
1005 gaim_savedstatus_get_creation_time(saved_status));
13387
d9dbb874a30c [gaim-migrate @ 15760]
Richard Laager <rlaager@wiktel.com>
parents: 13246
diff changeset
1006
d9dbb874a30c [gaim-migrate @ 15760]
Richard Laager <rlaager@wiktel.com>
parents: 13246
diff changeset
1007 gaim_signal_emit(gaim_savedstatuses_get_handle(), "savedstatus-changed",
d9dbb874a30c [gaim-migrate @ 15760]
Richard Laager <rlaager@wiktel.com>
parents: 13246
diff changeset
1008 saved_status, old);
d9dbb874a30c [gaim-migrate @ 15760]
Richard Laager <rlaager@wiktel.com>
parents: 13246
diff changeset
1009
11724
a8ec0a291d14 [gaim-migrate @ 14015]
Mark Doliner <mark@kingant.net>
parents: 11651
diff changeset
1010 }
a8ec0a291d14 [gaim-migrate @ 14015]
Mark Doliner <mark@kingant.net>
parents: 11651
diff changeset
1011
a8ec0a291d14 [gaim-migrate @ 14015]
Mark Doliner <mark@kingant.net>
parents: 11651
diff changeset
1012 void
a8ec0a291d14 [gaim-migrate @ 14015]
Mark Doliner <mark@kingant.net>
parents: 11651
diff changeset
1013 gaim_savedstatus_activate_for_account(const GaimSavedStatus *saved_status,
a8ec0a291d14 [gaim-migrate @ 14015]
Mark Doliner <mark@kingant.net>
parents: 11651
diff changeset
1014 GaimAccount *account)
a8ec0a291d14 [gaim-migrate @ 14015]
Mark Doliner <mark@kingant.net>
parents: 11651
diff changeset
1015 {
12056
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
1016 const GaimStatusType *status_type;
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
1017 const GaimSavedStatusSub *substatus;
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
1018 const char *message = NULL;
11724
a8ec0a291d14 [gaim-migrate @ 14015]
Mark Doliner <mark@kingant.net>
parents: 11651
diff changeset
1019
11727
8657ad65e257 [gaim-migrate @ 14018]
Mark Doliner <mark@kingant.net>
parents: 11724
diff changeset
1020 g_return_if_fail(saved_status != NULL);
8657ad65e257 [gaim-migrate @ 14018]
Mark Doliner <mark@kingant.net>
parents: 11724
diff changeset
1021 g_return_if_fail(account != NULL);
8657ad65e257 [gaim-migrate @ 14018]
Mark Doliner <mark@kingant.net>
parents: 11724
diff changeset
1022
12080
3b52d94437f3 [gaim-migrate @ 14377]
Mark Doliner <mark@kingant.net>
parents: 12056
diff changeset
1023 substatus = gaim_savedstatus_get_substatus(saved_status, account);
12056
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
1024 if (substatus != NULL)
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
1025 {
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
1026 status_type = substatus->type;
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
1027 message = substatus->message;
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
1028 }
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
1029 else
11724
a8ec0a291d14 [gaim-migrate @ 14015]
Mark Doliner <mark@kingant.net>
parents: 11651
diff changeset
1030 {
12056
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
1031 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
1032 if (status_type == NULL)
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
1033 return;
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
1034 message = saved_status->message;
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
1035 }
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
1036
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
1037 if ((message != NULL) &&
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
1038 (gaim_status_type_get_attr(status_type, "message")))
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
1039 {
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
1040 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
1041 TRUE, "message", message, NULL);
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
1042 }
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
1043 else
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
1044 {
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
1045 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
1046 TRUE, NULL);
11724
a8ec0a291d14 [gaim-migrate @ 14015]
Mark Doliner <mark@kingant.net>
parents: 11651
diff changeset
1047 }
a8ec0a291d14 [gaim-migrate @ 14015]
Mark Doliner <mark@kingant.net>
parents: 11651
diff changeset
1048 }
a8ec0a291d14 [gaim-migrate @ 14015]
Mark Doliner <mark@kingant.net>
parents: 11651
diff changeset
1049
11318
519dc2186438 [gaim-migrate @ 13521]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10738
diff changeset
1050 void *
519dc2186438 [gaim-migrate @ 13521]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10738
diff changeset
1051 gaim_savedstatuses_get_handle(void)
519dc2186438 [gaim-migrate @ 13521]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10738
diff changeset
1052 {
519dc2186438 [gaim-migrate @ 13521]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10738
diff changeset
1053 static int handle;
519dc2186438 [gaim-migrate @ 13521]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10738
diff changeset
1054
519dc2186438 [gaim-migrate @ 13521]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10738
diff changeset
1055 return &handle;
519dc2186438 [gaim-migrate @ 13521]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10738
diff changeset
1056 }
519dc2186438 [gaim-migrate @ 13521]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10738
diff changeset
1057
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
1058 void
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
1059 gaim_savedstatuses_init(void)
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
1060 {
13387
d9dbb874a30c [gaim-migrate @ 15760]
Richard Laager <rlaager@wiktel.com>
parents: 13246
diff changeset
1061 void *handle = gaim_savedstatuses_get_handle();
d9dbb874a30c [gaim-migrate @ 15760]
Richard Laager <rlaager@wiktel.com>
parents: 13246
diff changeset
1062
12125
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
1063 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
1064
12125
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
1065 /*
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
1066 * Using 0 as the creation_time is a special case.
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
1067 * If someone calls gaim_savedstatus_get_current() or
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
1068 * gaim_savedstatus_get_idleaway() and either of those functions
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
1069 * 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
1070 * saved status and return that to the user.
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
1071 */
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
1072 gaim_prefs_add_none("/core/savedstatus");
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
1073 gaim_prefs_add_int("/core/savedstatus/current", 0);
12857
e5f780a6137b [gaim-migrate @ 15208]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12814
diff changeset
1074 gaim_prefs_add_int("/core/savedstatus/startup", 0);
e5f780a6137b [gaim-migrate @ 15208]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12814
diff changeset
1075 gaim_prefs_add_bool("/core/savedstatus/startup_current_status", TRUE);
12125
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
1076 gaim_prefs_add_int("/core/savedstatus/idleaway", 0);
11975
aadf61b30056 [gaim-migrate @ 14268]
Mark Doliner <mark@kingant.net>
parents: 11954
diff changeset
1077
12125
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
1078 load_statuses();
13387
d9dbb874a30c [gaim-migrate @ 15760]
Richard Laager <rlaager@wiktel.com>
parents: 13246
diff changeset
1079
d9dbb874a30c [gaim-migrate @ 15760]
Richard Laager <rlaager@wiktel.com>
parents: 13246
diff changeset
1080 gaim_signal_register(handle, "savedstatus-changed",
d9dbb874a30c [gaim-migrate @ 15760]
Richard Laager <rlaager@wiktel.com>
parents: 13246
diff changeset
1081 gaim_marshal_VOID__POINTER_POINTER, NULL, 2,
d9dbb874a30c [gaim-migrate @ 15760]
Richard Laager <rlaager@wiktel.com>
parents: 13246
diff changeset
1082 gaim_value_new(GAIM_TYPE_SUBTYPE,
d9dbb874a30c [gaim-migrate @ 15760]
Richard Laager <rlaager@wiktel.com>
parents: 13246
diff changeset
1083 GAIM_SUBTYPE_SAVEDSTATUS),
d9dbb874a30c [gaim-migrate @ 15760]
Richard Laager <rlaager@wiktel.com>
parents: 13246
diff changeset
1084 gaim_value_new(GAIM_TYPE_SUBTYPE,
d9dbb874a30c [gaim-migrate @ 15760]
Richard Laager <rlaager@wiktel.com>
parents: 13246
diff changeset
1085 GAIM_SUBTYPE_SAVEDSTATUS));
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
1086 }
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
1087
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
1088 void
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
1089 gaim_savedstatuses_uninit(void)
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
1090 {
12327
508ac301e74b [gaim-migrate @ 14631]
Mark Doliner <mark@kingant.net>
parents: 12309
diff changeset
1091 remove_old_transient_statuses();
508ac301e74b [gaim-migrate @ 14631]
Mark Doliner <mark@kingant.net>
parents: 12309
diff changeset
1092
10428
04c663ccbcb1 [gaim-migrate @ 11680]
Mark Doliner <mark@kingant.net>
parents: 10427
diff changeset
1093 if (save_timer != 0)
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
1094 {
10428
04c663ccbcb1 [gaim-migrate @ 11680]
Mark Doliner <mark@kingant.net>
parents: 10427
diff changeset
1095 gaim_timeout_remove(save_timer);
04c663ccbcb1 [gaim-migrate @ 11680]
Mark Doliner <mark@kingant.net>
parents: 10427
diff changeset
1096 save_timer = 0;
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
1097 sync_statuses();
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
1098 }
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
1099
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
1100 while (saved_statuses != NULL) {
12056
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
1101 GaimSavedStatus *saved_status = saved_statuses->data;
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
1102 saved_statuses = g_list_remove(saved_statuses, saved_status);
12724
10ef9171ca87 [gaim-migrate @ 15068]
Mark Doliner <mark@kingant.net>
parents: 12690
diff changeset
1103 free_saved_status(saved_status);
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
1104 }
12125
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
1105
3c1bac709234 [gaim-migrate @ 14425]
Mark Doliner <mark@kingant.net>
parents: 12123
diff changeset
1106 g_hash_table_destroy(creation_times);
13387
d9dbb874a30c [gaim-migrate @ 15760]
Richard Laager <rlaager@wiktel.com>
parents: 13246
diff changeset
1107
d9dbb874a30c [gaim-migrate @ 15760]
Richard Laager <rlaager@wiktel.com>
parents: 13246
diff changeset
1108 gaim_signals_unregister_by_instance(gaim_savedstatuses_get_handle());
10418
bed2c96bc1fb [gaim-migrate @ 11669]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
1109 }
12056
6dc48f991b8d [gaim-migrate @ 14351]
Mark Doliner <mark@kingant.net>
parents: 11977
diff changeset
1110