comparison src/dialogs.c @ 228:f3b61c04f44e

[gaim-migrate @ 238] Buddy lists (and changes) are cached to ~/.gaimbdcache_<sn> where <sn> is your screen name (folder to uppercase). If for some reason, you log into the AOL server and the buddy list comes back empty, we check for a cache file, and, if we find one, read it in. This essentially implements recovery from a server crash at AOL (AOL does not back up machines that contain TOC-based buddy lists, unfortunately). committer: Tailor Script <tailor@pidgin.im>
author Syd Logan <slogan>
date Wed, 10 May 2000 07:41:25 +0000
parents 73e9a0bfff62
children e8ea7f37e28f
comparison
equal deleted inserted replaced
227:fb8e65df5fe7 228:f3b61c04f44e
673 build_edit_tree(); 673 build_edit_tree();
674 674
675 serv_save_config(); 675 serv_save_config();
676 676
677 serv_add_buddy(who); 677 serv_add_buddy(who);
678
679 do_export( (GtkWidget *) NULL, 0 );
678 680
679 update_num_groups(); 681 update_num_groups();
680 682
681 destroy_dialog(NULL, a->window); 683 destroy_dialog(NULL, a->window);
682 } 684 }
1932 1934
1933 /*------------------------------------------------------------------------*/ 1935 /*------------------------------------------------------------------------*/
1934 /* The dialog for import/export */ 1936 /* The dialog for import/export */
1935 /*------------------------------------------------------------------------*/ 1937 /*------------------------------------------------------------------------*/
1936 1938
1939 #define PATHSIZE 1024
1940
1941 /* if dummy is 0, save to ~/.gaimbdcache_screenname */
1942
1937 void do_export(GtkWidget *w, void *dummy) 1943 void do_export(GtkWidget *w, void *dummy)
1938 { 1944 {
1939 FILE *f; 1945 FILE *f;
1946 gint show_dialog = (int) dummy;
1940 char *buf = g_malloc(BUF_LONG); 1947 char *buf = g_malloc(BUF_LONG);
1941 char *file = gtk_file_selection_get_filename(GTK_FILE_SELECTION(exportdialog)); 1948 char *file;
1942 1949 char path[PATHSIZE];
1943 if ((f = fopen(file,"w"))) { 1950 extern char g_screenname[];
1944 toc_build_config(buf, BUF_LONG - 1); 1951
1952 if ( show_dialog == 1 ) {
1953 file = gtk_file_selection_get_filename(GTK_FILE_SELECTION(exportdialog));
1954 strncpy( path, file, PATHSIZE - 1 );
1955 }
1956 else {
1957 file = getenv( "HOME" );
1958 if ( file != (char *) NULL )
1959 sprintf( path, "%s/.gaimbdcache_%s", file, g_screenname );
1960 else
1961 return;
1962 }
1963 if ((f = fopen(path,"w"))) {
1964 toc_build_config(buf, 1024 - 1);
1945 fprintf(f, "%s\n", buf); 1965 fprintf(f, "%s\n", buf);
1946 fclose(f); 1966 fclose(f);
1947 chmod(buf, S_IRUSR | S_IWUSR); 1967 chmod(buf, S_IRUSR | S_IWUSR);
1948 } else { 1968 } else if ( show_dialog == 1 ) {
1949 g_snprintf(buf, BUF_LONG / 2, "Error writing file %s", file); 1969 g_snprintf(buf, BUF_LONG / 2, "Error writing file %s", file);
1950 do_error_dialog(buf, "Error"); 1970 do_error_dialog(buf, "Error");
1951 } 1971 }
1952 destroy_dialog(NULL, exportdialog); 1972 if ( show_dialog == 1 ) {
1953 exportdialog = NULL; 1973 destroy_dialog(NULL, exportdialog);
1974 exportdialog = NULL;
1975 }
1954 1976
1955 g_free(buf); 1977 g_free(buf);
1956
1957 1978
1958 } 1979 }
1959 1980
1960 1981
1961 void show_export_dialog() 1982 void show_export_dialog()
1971 gtk_file_selection_set_filename(GTK_FILE_SELECTION(exportdialog), buf); 1992 gtk_file_selection_set_filename(GTK_FILE_SELECTION(exportdialog), buf);
1972 gtk_signal_connect(GTK_OBJECT(exportdialog), "destroy", 1993 gtk_signal_connect(GTK_OBJECT(exportdialog), "destroy",
1973 GTK_SIGNAL_FUNC(destroy_dialog), exportdialog); 1994 GTK_SIGNAL_FUNC(destroy_dialog), exportdialog);
1974 1995
1975 gtk_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(exportdialog)->ok_button), 1996 gtk_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(exportdialog)->ok_button),
1976 "clicked", GTK_SIGNAL_FUNC(do_export), NULL); 1997 "clicked", GTK_SIGNAL_FUNC(do_export), 1);
1977 gtk_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(exportdialog)->cancel_button), 1998 gtk_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(exportdialog)->cancel_button),
1978 "clicked", GTK_SIGNAL_FUNC(destroy_dialog), exportdialog); 1999 "clicked", GTK_SIGNAL_FUNC(destroy_dialog), exportdialog);
1979 2000
1980 2001
1981 } 2002 }
1985 gtk_widget_show(exportdialog); 2006 gtk_widget_show(exportdialog);
1986 gdk_window_raise(exportdialog->window); 2007 gdk_window_raise(exportdialog->window);
1987 2008
1988 } 2009 }
1989 2010
2011 /* if dummy is 0, then import from ~/.gaimbdcache_screenname */
2012
1990 void do_import(GtkWidget *w, void *dummy) 2013 void do_import(GtkWidget *w, void *dummy)
1991 { 2014 {
2015 gint show_dialog = (int) dummy;
1992 GList *grp, *grp2; 2016 GList *grp, *grp2;
1993 char *buf = g_malloc(BUF_LONG); 2017 char *buf = g_malloc(BUF_LONG);
1994 char *buf2; 2018 char *buf2;
1995 char *first = g_malloc(64); 2019 char *first = g_malloc(64);
1996 char *file = gtk_file_selection_get_filename(GTK_FILE_SELECTION(importdialog)); 2020 char *file;
2021 char path[PATHSIZE];
1997 FILE *f; 2022 FILE *f;
1998 2023 extern char g_screenname[];
1999 if (!(f = fopen(file,"r"))) { 2024
2000 g_snprintf(buf, BUF_LONG / 2, "Error reading file %s", file); 2025 if ( show_dialog == 1 ) {
2001 do_error_dialog(buf, "Error"); 2026 file = gtk_file_selection_get_filename(GTK_FILE_SELECTION(importdialog));
2002 destroy_dialog(NULL, importdialog); 2027 strncpy( path, file, PATHSIZE - 1 );
2003 importdialog = NULL; 2028 }
2029 else {
2030 file = getenv( "HOME" );
2031 if ( file != (char *) NULL )
2032 sprintf( path, "%s/.gaimbdcache_%s", file, g_screenname );
2033 else
2034 return;
2035 }
2036
2037 if (!(f = fopen(path,"r"))) {
2038 if ( show_dialog == 1 ) {
2039 g_snprintf(buf, BUF_LONG / 2, "Error reading file %s", file);
2040 do_error_dialog(buf, "Error");
2041 destroy_dialog(NULL, importdialog);
2042 importdialog = NULL;
2043 }
2004 g_free(buf); 2044 g_free(buf);
2005 g_free(first); 2045 g_free(first);
2006 return; 2046 return;
2007 } 2047 }
2008 2048
2009 fgets(first, 64, f); 2049 fgets(first, 64, f);
2010 2050
2011 if (!strcasecmp(first, "Config {\n")) { 2051 if (!strcasecmp(first, "Config {\n")) {
2012 destroy_dialog(NULL, importdialog); 2052 if ( show_dialog == 1 ) {
2013 importdialog = NULL; 2053 destroy_dialog(NULL, importdialog);
2054 importdialog = NULL;
2055 }
2014 g_free(buf); 2056 g_free(buf);
2015 g_free(first); 2057 g_free(first);
2058 fclose( f );
2016 return; 2059 return;
2017 } else if (buf[0] == 'm') { 2060 } else if (buf[0] == 'm') {
2018 buf2 = buf; 2061 buf2 = buf;
2019 buf = g_malloc(1025); 2062 buf = g_malloc(1025);
2020 g_snprintf(buf, 1024, "toc_set_config {%s}\n", buf2); 2063 g_snprintf(buf, 1024, "toc_set_config {%s}\n", buf2);
2039 serv_save_config(); 2082 serv_save_config();
2040 2083
2041 build_edit_tree(); 2084 build_edit_tree();
2042 build_permit_tree(); 2085 build_permit_tree();
2043 2086
2044 destroy_dialog(NULL, importdialog); 2087 fclose( f );
2045 importdialog = NULL; 2088
2089 if ( show_dialog == 1 ) {
2090 /* save what we just did to cache */
2091
2092 do_export( (GtkWidget *) NULL, 0 );
2093 destroy_dialog(NULL, importdialog);
2094 importdialog = NULL;
2095 }
2046 2096
2047 g_free(buf); 2097 g_free(buf);
2048 g_free(first); 2098 g_free(first);
2049
2050 } 2099 }
2051 2100
2052 void show_import_dialog() 2101 void show_import_dialog()
2053 { 2102 {
2054 char *buf = g_malloc(BUF_LEN); 2103 char *buf = g_malloc(BUF_LEN);
2062 gtk_file_selection_set_filename(GTK_FILE_SELECTION(importdialog), buf); 2111 gtk_file_selection_set_filename(GTK_FILE_SELECTION(importdialog), buf);
2063 gtk_signal_connect(GTK_OBJECT(importdialog), "destroy", 2112 gtk_signal_connect(GTK_OBJECT(importdialog), "destroy",
2064 GTK_SIGNAL_FUNC(destroy_dialog), importdialog); 2113 GTK_SIGNAL_FUNC(destroy_dialog), importdialog);
2065 2114
2066 gtk_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(importdialog)->ok_button), 2115 gtk_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(importdialog)->ok_button),
2067 "clicked", GTK_SIGNAL_FUNC(do_import), NULL); 2116 "clicked", GTK_SIGNAL_FUNC(do_import), 1);
2068 gtk_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(importdialog)->cancel_button), 2117 gtk_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(importdialog)->cancel_button),
2069 "clicked", GTK_SIGNAL_FUNC(destroy_dialog), importdialog); 2118 "clicked", GTK_SIGNAL_FUNC(destroy_dialog), importdialog);
2070 2119
2071 2120
2072 } 2121 }