annotate src/savedstatuses.c @ 13737:2b9aa05b6fa1

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