comparison src/blist.c @ 10337:682201b69107

[gaim-migrate @ 11545] * Preliminary reading of status.xml using xmlnode.[h|c] * I made a few changes the blist.xml readering code that I think makes it cleaner * "gaim_statuses_find_saved" makes more sense to me than "gaim_statuses_find_stored" * struct GaimStatus isn't really supposed to be used for keeping the saved statuses, is it? I don't see how that would work. It seems to make more sense to have a separate data structure for it. Maybe I'm not seeing things clearly. committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Thu, 09 Dec 2004 03:55:19 +0000
parents 8d42237564f6
children ee4f477fc8cf
comparison
equal deleted inserted replaced
10336:114d3ac8ff5a 10337:682201b69107
1954 GError *error; 1954 GError *error;
1955 gchar *contents = NULL; 1955 gchar *contents = NULL;
1956 gsize length; 1956 gsize length;
1957 xmlnode *gaim, *blist, *privacy; 1957 xmlnode *gaim, *blist, *privacy;
1958 1958
1959 gaim_debug(GAIM_DEBUG_INFO, "blist import", 1959 gaim_debug_info("blist", "Reading %s\n", filename);
1960 "Reading %s\n", filename); 1960
1961 if (!g_file_get_contents(filename, &contents, &length, &error)) { 1961 if (!g_file_get_contents(filename, &contents, &length, &error)) {
1962 gaim_debug(GAIM_DEBUG_ERROR, "blist import", 1962 gaim_debug_error("blist", "Error reading blist.xml: %s\n",
1963 "Error reading blist: %s\n", error->message); 1963 error->message);
1964 g_error_free(error); 1964 g_error_free(error);
1965 return FALSE; 1965 return FALSE;
1966 } 1966 }
1967 1967
1968 gaim = xmlnode_from_str(contents, length); 1968 gaim = xmlnode_from_str(contents, length);
1969 1969
1970 if (!gaim) { 1970 if (gaim == NULL) {
1971 FILE *backup; 1971 FILE *backup;
1972 char *name; 1972 char *name;
1973 gaim_debug(GAIM_DEBUG_ERROR, "blist import", "Error parsing %s\n", 1973 gaim_debug_error("blist", "Error parsing blist.xml\n");
1974 filename);
1975 name = g_build_filename(gaim_user_dir(), "blist.xml~", NULL); 1974 name = g_build_filename(gaim_user_dir(), "blist.xml~", NULL);
1976
1977 if ((backup = fopen(name, "w"))) { 1975 if ((backup = fopen(name, "w"))) {
1978 fwrite(contents, length, 1, backup); 1976 fwrite(contents, length, 1, backup);
1979 fclose(backup); 1977 fclose(backup);
1980 chmod(name, S_IRUSR | S_IWUSR); 1978 chmod(name, S_IRUSR | S_IWUSR);
1981 } else { 1979 } else {
1982 gaim_debug(GAIM_DEBUG_ERROR, "blist load", "Unable to write backup %s\n", 1980 gaim_debug_error("blist", "Unable to write backup %s\n", name);
1983 name);
1984 } 1981 }
1985 g_free(name); 1982 g_free(name);
1986 g_free(contents); 1983 g_free(contents);
1987 return FALSE; 1984 return FALSE;
1988 } 1985 }
1989 1986
1990 g_free(contents); 1987 g_free(contents);
1991 1988
1992 blist = xmlnode_get_child(gaim, "blist"); 1989 blist = xmlnode_get_child(gaim, "blist");
1993 if (blist) { 1990 if (blist) {
1994 xmlnode *groupnode; 1991 xmlnode *groupnode;
1995 for (groupnode = xmlnode_get_child(blist, "group"); groupnode; 1992 for (groupnode = xmlnode_get_child(blist, "group"); groupnode != NULL;
1996 groupnode = xmlnode_get_next_twin(groupnode)) { 1993 groupnode = xmlnode_get_next_twin(groupnode)) {
1997 parse_group(groupnode); 1994 parse_group(groupnode);
1998 } 1995 }
1999 } 1996 }
2000 1997
2037 } 2034 }
2038 } 2035 }
2039 } 2036 }
2040 } 2037 }
2041 2038
2042 gaim_debug(GAIM_DEBUG_INFO, "blist import", "Finished reading %s\n", 2039 gaim_debug_info("blist", "Finished reading blist.xml\n");
2043 filename);
2044 2040
2045 xmlnode_free(gaim); 2041 xmlnode_free(gaim);
2042
2046 return TRUE; 2043 return TRUE;
2047 } 2044 }
2048 2045
2049 void gaim_blist_load() 2046 void gaim_blist_load()
2050 { 2047 {
2051 const char *user_dir = gaim_user_dir(); 2048 const char *user_dir = gaim_user_dir();
2052 char *filename; 2049 gchar *filename;
2053 char *msg; 2050 gchar *msg;
2054 2051
2055 blist_safe_to_write = TRUE; 2052 blist_safe_to_write = TRUE;
2056 2053
2057 if (!user_dir) 2054 if (user_dir == NULL)
2058 return; 2055 return;
2059 2056
2060 filename = g_build_filename(user_dir, "blist.xml", NULL); 2057 filename = g_build_filename(user_dir, "blist.xml", NULL);
2061 2058
2062 if (g_file_test(filename, G_FILE_TEST_EXISTS)) { 2059 if (g_file_test(filename, G_FILE_TEST_EXISTS)) {
2063 if (!gaim_blist_read(filename)) { 2060 if (!gaim_blist_read(filename)) {
2064 msg = g_strdup_printf(_("An error was encountered parsing your " 2061 msg = g_strdup_printf(_("An error was encountered parsing the "
2065 "buddy list. It has not been loaded, " 2062 "file containing your buddy list (%s). It has not "
2066 "and the old file has moved to blist.xml~.")); 2063 "been loaded, and the old file has been renamed "
2064 "to blist.xml~."), filename);
2067 gaim_notify_error(NULL, NULL, _("Buddy List Error"), msg); 2065 gaim_notify_error(NULL, NULL, _("Buddy List Error"), msg);
2068 g_free(msg); 2066 g_free(msg);
2069 } 2067 }
2070 } 2068 }
2071 2069