annotate src/status.c @ 8367:5f78e96ff135

[gaim-migrate @ 9092] I think these scale values might be a bit more sane (they make gaim behave the same as it did before if your default font is 12pt) committer: Tailor Script <tailor@pidgin.im>
author Nathan Walp <nwalp@pidgin.im>
date Sun, 29 Feb 2004 05:40:45 +0000
parents f24172f53650
children 1a016d979ce0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6065
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1 /*
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2 * gaim
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3 *
8046
fa6395637e2c [gaim-migrate @ 8730]
Sean Egan <seanegan@gmail.com>
parents: 6371
diff changeset
4 * Gaim is the legal property of its developers, whose names are too numerous
fa6395637e2c [gaim-migrate @ 8730]
Sean Egan <seanegan@gmail.com>
parents: 6371
diff changeset
5 * to list here. Please refer to the COPYRIGHT file distributed with this
fa6395637e2c [gaim-migrate @ 8730]
Sean Egan <seanegan@gmail.com>
parents: 6371
diff changeset
6 * source distribution.
6065
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
7 *
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
8 * This program is free software; you can redistribute it and/or modify
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
9 * it under the terms of the GNU General Public License as published by
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
10 * the Free Software Foundation; either version 2 of the License, or
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
11 * (at your option) any later version.
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
12 *
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful,
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
16 * GNU General Public License for more details.
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
17 *
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
19 * along with this program; if not, write to the Free Software
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
21 */
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
22
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
23 #include "status.h"
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
24 #include "internal.h"
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
25 #include "debug.h"
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
26 #include "util.h"
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
27
6371
8f94cce8faa5 [gaim-migrate @ 6876]
Christian Hammond <chipx86@chipx86.com>
parents: 6321
diff changeset
28 /* XXX CORE/UI */
8f94cce8faa5 [gaim-migrate @ 6876]
Christian Hammond <chipx86@chipx86.com>
parents: 6321
diff changeset
29 #include "gtkinternal.h"
8f94cce8faa5 [gaim-migrate @ 6876]
Christian Hammond <chipx86@chipx86.com>
parents: 6321
diff changeset
30 #include "ui.h"
8f94cce8faa5 [gaim-migrate @ 6876]
Christian Hammond <chipx86@chipx86.com>
parents: 6321
diff changeset
31
8f94cce8faa5 [gaim-migrate @ 6876]
Christian Hammond <chipx86@chipx86.com>
parents: 6321
diff changeset
32
6065
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
33 /* for people like myself who are too lazy to add an away msg :) */
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
34 /* I don't know who "myself" is in this context. The exclamation point
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
35 * makes it slightly less boring ;) */
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
36 #define BORING_DEFAULT_AWAY_MSG _("Sorry, I ran out for a bit!")
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
37
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
38 /* XML File Saving */
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
39
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
40 /* All of this code is adapted from Nathan Walp's. It's adapted all over the place
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
41 * for accounts, the buddy list, pounces, preferences, and the likes. It would be
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
42 * neat if we could somehow make this more generic. */
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
43 static gboolean status_loaded = FALSE;
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
44 static guint status_save_timer = 0;
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
45
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
46
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
47 typedef enum
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
48 {
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
49 TAG_NONE = 0,
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
50 TAG_STATUS,
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
51 TAG_STATE,
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
52 TAG_MESSAGE,
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
53
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
54 } StatusParserTag;
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
55
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
56
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
57 typedef struct
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
58 {
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
59 StatusParserTag tag;
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
60 GString *buffer;
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
61 struct away_message *am;
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
62
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
63 } StatusParserData;
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
64
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
65 static void
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
66 free_parser_data(gpointer user_data)
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
67 {
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
68 StatusParserData *data = user_data;
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
69
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
70 if (data->buffer != NULL)
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
71 g_string_free(data->buffer, TRUE);
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
72
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
73 g_free(data);
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
74 }
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
75
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
76 static void gaim_status_write(FILE *fp, struct away_message *am)
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
77 {
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
78 char *esc = NULL;
6216
dc42b27101c0 [gaim-migrate @ 6702]
Nathan Walp <nwalp@pidgin.im>
parents: 6113
diff changeset
79
6065
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
80 esc = g_markup_escape_text(am->name, -1);
6216
dc42b27101c0 [gaim-migrate @ 6702]
Nathan Walp <nwalp@pidgin.im>
parents: 6113
diff changeset
81 fprintf(fp, "\t<status name=\"%s\">\n", esc);
6065
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
82 g_free(esc);
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
83
6216
dc42b27101c0 [gaim-migrate @ 6702]
Nathan Walp <nwalp@pidgin.im>
parents: 6113
diff changeset
84 fprintf(fp, "\t\t<state>away</state>\n");
dc42b27101c0 [gaim-migrate @ 6702]
Nathan Walp <nwalp@pidgin.im>
parents: 6113
diff changeset
85
dc42b27101c0 [gaim-migrate @ 6702]
Nathan Walp <nwalp@pidgin.im>
parents: 6113
diff changeset
86 esc = g_markup_escape_text(am->message, -1);
dc42b27101c0 [gaim-migrate @ 6702]
Nathan Walp <nwalp@pidgin.im>
parents: 6113
diff changeset
87 fprintf(fp, "\t\t<message>%s</message>\n", esc);
dc42b27101c0 [gaim-migrate @ 6702]
Nathan Walp <nwalp@pidgin.im>
parents: 6113
diff changeset
88 g_free(esc);
dc42b27101c0 [gaim-migrate @ 6702]
Nathan Walp <nwalp@pidgin.im>
parents: 6113
diff changeset
89
dc42b27101c0 [gaim-migrate @ 6702]
Nathan Walp <nwalp@pidgin.im>
parents: 6113
diff changeset
90 fprintf(fp, "\t</status>\n");
6065
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
91 }
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
92
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
93 static gboolean
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
94 status_save_cb(gpointer unused)
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
95 {
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
96 gaim_status_sync();
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
97 status_save_timer = 0;
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
98
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
99 return FALSE;
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
100 }
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
101
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
102 static void
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
103 schedule_status_save()
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
104 {
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
105 if (!status_save_timer)
8273
f24172f53650 [gaim-migrate @ 8997]
Christian Hammond <chipx86@chipx86.com>
parents: 8046
diff changeset
106 status_save_timer = gaim_timeout_add(5000, status_save_cb, NULL);
6065
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
107 }
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
108
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
109 static void
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
110 start_element_handler(GMarkupParseContext *context,
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
111 const gchar *element_name,
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
112 const gchar **attribute_names,
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
113 const gchar **attribute_values,
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
114 gpointer user_data, GError **error)
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
115 {
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
116 const char *value;
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
117 StatusParserData *data = user_data;
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
118 GHashTable *atts;
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
119 int i;
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
120
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
121 atts = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
122
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
123 for (i = 0; attribute_names[i] != NULL; i++) {
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
124 g_hash_table_insert(atts, g_strdup(attribute_names[i]),
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
125 g_strdup(attribute_values[i]));
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
126 }
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
127
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
128 if (data->buffer != NULL) {
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
129 g_string_free(data->buffer, TRUE);
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
130 data->buffer = NULL;
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
131 }
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
132
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
133 if (!strcmp(element_name, "status")) {
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
134 data->tag = TAG_STATUS;
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
135 if ((value = g_hash_table_lookup(atts, "name")) != NULL) {
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
136 data->am = g_new0(struct away_message, 1);
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
137 g_snprintf(data->am->name, sizeof(data->am->name), "%s", value);
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
138 away_messages = g_slist_append(away_messages, data->am);
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
139 }
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
140 } else if (!strcmp(element_name, "message")) {
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
141 data->tag = TAG_MESSAGE;
6216
dc42b27101c0 [gaim-migrate @ 6702]
Nathan Walp <nwalp@pidgin.im>
parents: 6113
diff changeset
142
6065
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
143 }
6113
30d4c432101c [gaim-migrate @ 6575]
Mark Doliner <mark@kingant.net>
parents: 6065
diff changeset
144
30d4c432101c [gaim-migrate @ 6575]
Mark Doliner <mark@kingant.net>
parents: 6065
diff changeset
145 g_hash_table_destroy(atts);
6065
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
146 }
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
147
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
148 static void
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
149 end_element_handler(GMarkupParseContext *context, const gchar *element_name,
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
150 gpointer user_data, GError **error)
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
151 {
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
152 StatusParserData *data = user_data;
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
153 gchar *buffer;
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
154
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
155 if (data->buffer == NULL)
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
156 return;
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
157
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
158 buffer = g_string_free(data->buffer, FALSE);
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
159 data->buffer = NULL;
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
160
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
161 if (data->tag == TAG_MESSAGE) {
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
162 if (*buffer != '\0')
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
163 g_snprintf(data->am->message, sizeof(data->am->message), "%s", buffer);
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
164 }
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
165
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
166 data->tag = TAG_NONE;
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
167
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
168 g_free(buffer);
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
169 }
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
170
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
171 static void
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
172 text_handler(GMarkupParseContext *context, const gchar *text,
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
173 gsize text_len, gpointer user_data, GError **error)
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
174 {
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
175 StatusParserData *data = user_data;
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
176
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
177 if (data->buffer == NULL)
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
178 data->buffer = g_string_new_len(text, text_len);
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
179 else
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
180 g_string_append_len(data->buffer, text, text_len);
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
181 }
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
182
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
183 static GMarkupParser status_parser =
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
184 {
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
185 start_element_handler,
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
186 end_element_handler,
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
187 text_handler,
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
188 NULL,
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
189 NULL
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
190 };
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
191
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
192 void gaim_status_sync()
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
193 {
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
194 FILE *fp;
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
195 const char *user_dir = gaim_user_dir();
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
196 char *filename, *filename_real;
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
197
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
198 if (!status_loaded) {
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
199 gaim_debug(GAIM_DEBUG_WARNING, "status", "Writing status to disk.\n");
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
200 schedule_status_save();
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
201 return;
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
202 }
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
203
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
204 if (user_dir == NULL)
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
205 return;
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
206
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
207 gaim_debug(GAIM_DEBUG_INFO, "status", "Saving statuses to disk\n");
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
208
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
209 fp = fopen(user_dir, "r");
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
210
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
211 if (fp == NULL)
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
212 mkdir(user_dir, S_IRUSR | S_IWUSR | S_IXUSR);
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
213 else
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
214 fclose(fp);
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
215
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
216 filename = g_build_filename(user_dir, "status.xml.save", NULL);
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
217
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
218 if ((fp = fopen(filename, "w")) != NULL) {
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
219 GSList *l;
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
220
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
221 fprintf(fp, "<?xml version='1.0' encoding='UTF-8' ?>\n\n");
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
222 fprintf(fp, "<statuses>\n");
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
223
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
224 for (l = away_messages; l != NULL; l = l->next)
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
225 gaim_status_write(fp, l->data);
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
226
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
227 fprintf(fp, "</statuses>\n");
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
228
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
229 fclose(fp);
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
230 chmod(filename, S_IRUSR | S_IWUSR);
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
231 }
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
232 else {
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
233 gaim_debug(GAIM_DEBUG_ERROR, "status", "Unable to write %s\n",
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
234 filename);
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
235 }
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
236
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
237 filename_real = g_build_filename(user_dir, "status.xml", NULL);
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
238
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
239 if (rename(filename, filename_real) < 0) {
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
240 gaim_debug(GAIM_DEBUG_ERROR, "status", "Error renaming %s to %s\n",
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
241 filename, filename_real);
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
242 }
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
243
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
244 g_free(filename);
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
245 g_free(filename_real);
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
246
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
247 }
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
248
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
249 void gaim_status_load()
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
250 {
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
251 gchar *filename = g_build_filename(gaim_user_dir(), "status.xml", NULL);
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
252 gchar *contents = NULL;
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
253 gsize length;
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
254 GMarkupParseContext *context;
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
255 GError *error = NULL;
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
256 StatusParserData *parser_data;
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
257
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
258 if (filename == NULL) {
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
259 status_loaded = TRUE;
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
260 return;
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
261 }
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
262
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
263 if (!g_file_get_contents(filename, &contents, &length, &error)) {
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
264 gaim_debug(GAIM_DEBUG_ERROR, "status",
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
265 "Error reading statuses: %s\n", error->message);
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
266 g_error_free(error);
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
267 g_free(filename);
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
268 status_loaded = TRUE;
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
269 if (!away_messages) {
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
270 struct away_message *a = g_new0(struct away_message, 1);
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
271 g_snprintf(a->name, sizeof(a->name), _("Slightly less boring default"));
6321
3613007cbb6e [gaim-migrate @ 6820]
Luke Schierer <lschiere@pidgin.im>
parents: 6216
diff changeset
272 g_snprintf(a->message, sizeof(a->message), "%s", _(BORING_DEFAULT_AWAY_MSG));
6065
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
273 away_messages = g_slist_append(away_messages, a);
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
274 }
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
275 return;
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
276 }
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
277
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
278 parser_data = g_new0(StatusParserData, 1);
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
279
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
280 context = g_markup_parse_context_new(&status_parser, 0,
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
281 parser_data, free_parser_data);
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
282
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
283 if (!g_markup_parse_context_parse(context, contents, length, NULL)) {
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
284 g_markup_parse_context_free(context);
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
285 g_free(contents);
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
286 g_free(filename);
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
287 status_loaded = TRUE;
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
288 return;
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
289 }
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
290
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
291 if (!g_markup_parse_context_end_parse(context, NULL)) {
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
292 gaim_debug(GAIM_DEBUG_ERROR, "status", "Error parsing %s\n",
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
293 filename);
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
294 g_markup_parse_context_free(context);
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
295 g_free(contents);
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
296 g_free(filename);
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
297 status_loaded = TRUE;
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
298 return;
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
299 }
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
300
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
301 g_markup_parse_context_free(context);
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
302 g_free(contents);
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
303 g_free(filename);
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
304 status_loaded = TRUE;
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
305 return;
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
306 }