Mercurial > pidgin
comparison src/status.c @ 10415:5b7a74d397cc
[gaim-migrate @ 11665]
Ability to save statuses.
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Sat, 25 Dec 2004 19:54:24 +0000 |
parents | 26eac2362c32 |
children | 823ad21cd95a |
comparison
equal
deleted
inserted
replaced
10414:26eac2362c32 | 10415:5b7a74d397cc |
---|---|
164 -5 /* idle time, special case. */ | 164 -5 /* idle time, special case. */ |
165 }; | 165 }; |
166 | 166 |
167 static GHashTable *buddy_presences = NULL; | 167 static GHashTable *buddy_presences = NULL; |
168 static GList *saved_statuses = NULL; | 168 static GList *saved_statuses = NULL; |
169 gboolean have_read_saved_statuses = FALSE; | |
169 | 170 |
170 #define SCORE_IDLE 5 | 171 #define SCORE_IDLE 5 |
171 #define SCORE_IDLE_TIME 6 | 172 #define SCORE_IDLE_TIME 6 |
172 | 173 |
173 /** | 174 /** |
1998 gchar *filename; | 1999 gchar *filename; |
1999 gchar *msg; | 2000 gchar *msg; |
2000 | 2001 |
2001 g_return_if_fail(user_dir != NULL); | 2002 g_return_if_fail(user_dir != NULL); |
2002 | 2003 |
2004 have_read_saved_statuses = TRUE; | |
2005 | |
2003 filename = g_build_filename(user_dir, "status.xml", NULL); | 2006 filename = g_build_filename(user_dir, "status.xml", NULL); |
2004 | 2007 |
2005 if (g_file_test(filename, G_FILE_TEST_EXISTS)) | 2008 if (g_file_test(filename, G_FILE_TEST_EXISTS)) |
2006 { | 2009 { |
2007 if (!gaim_statuses_read(filename)) | 2010 if (!gaim_statuses_read(filename)) |
2016 } | 2019 } |
2017 | 2020 |
2018 g_free(filename); | 2021 g_free(filename); |
2019 } | 2022 } |
2020 | 2023 |
2024 static xmlnode * | |
2025 gaim_status_get_as_xmlnode(GaimStatusSaved *status) | |
2026 { | |
2027 xmlnode *node, *child; | |
2028 | |
2029 node = xmlnode_new("status"); | |
2030 xmlnode_set_attrib(node, "name", status->title); | |
2031 | |
2032 child = xmlnode_new("state"); | |
2033 xmlnode_insert_data(child, primitive_names[status->type], -1); | |
2034 xmlnode_insert_child(node, child); | |
2035 | |
2036 child = xmlnode_new("message"); | |
2037 xmlnode_insert_data(child, status->message, -1); | |
2038 xmlnode_insert_child(node, child); | |
2039 | |
2040 /* TODO: Add substatuses to the tree */ | |
2041 | |
2042 return node; | |
2043 } | |
2044 | |
2045 static xmlnode * | |
2046 gaim_statuses_get_as_xmlnode() | |
2047 { | |
2048 xmlnode *node, *child; | |
2049 GList *cur; | |
2050 | |
2051 node = xmlnode_new("statuses"); | |
2052 xmlnode_set_attrib(node, "version", "1"); | |
2053 | |
2054 for (cur = saved_statuses; cur != NULL; cur = cur->next) | |
2055 { | |
2056 child = gaim_status_get_as_xmlnode(cur->data); | |
2057 xmlnode_insert_child(node, child); | |
2058 } | |
2059 | |
2060 return node; | |
2061 } | |
2062 | |
2021 void | 2063 void |
2022 gaim_statuses_sync(void) | 2064 gaim_statuses_sync(void) |
2023 { | 2065 { |
2024 /* TODO: Only attempt to write if we've already read the file. */ | 2066 xmlnode *statuses; |
2025 | 2067 char *data; |
2026 //gaim_util_write_xml_file("status.xml", data); | 2068 |
2027 } | 2069 if (!have_read_saved_statuses) { |
2070 gaim_debug_error("status", "Attempted to save statuses before they " | |
2071 "were read!\n"); | |
2072 return; | |
2073 } | |
2074 | |
2075 statuses = gaim_statuses_get_as_xmlnode(); | |
2076 data = xmlnode_to_formatted_str(statuses, NULL); | |
2077 gaim_util_write_data_to_file("status.xml", data, -1); | |
2078 g_free(data); | |
2079 xmlnode_free(statuses); | |
2080 } |