Mercurial > pidgin
comparison src/dialogs.c @ 2382:569ae9f2bb89
[gaim-migrate @ 2395]
big reorg of code. list.c contains 0 gtk.
committer: Tailor Script <tailor@pidgin.im>
| author | Eric Warmenhoven <eric@warmenhoven.org> |
|---|---|
| date | Fri, 28 Sep 2001 07:46:36 +0000 |
| parents | cacaf7ace3a5 |
| children | a7ecfd3f7714 |
comparison
equal
deleted
inserted
replaced
| 2381:427ccd7dfdd2 | 2382:569ae9f2bb89 |
|---|---|
| 2779 | 2779 |
| 2780 /*------------------------------------------------------------------------*/ | 2780 /*------------------------------------------------------------------------*/ |
| 2781 /* The dialog for import/export */ | 2781 /* The dialog for import/export */ |
| 2782 /*------------------------------------------------------------------------*/ | 2782 /*------------------------------------------------------------------------*/ |
| 2783 | 2783 |
| 2784 static gchar *get_screenname_filename(const char *name) | 2784 static void do_import_dialog(GtkWidget *w, struct gaim_connection *gc) |
| 2785 { | 2785 { |
| 2786 gchar **split; | 2786 char *file = gtk_file_selection_get_filename(GTK_FILE_SELECTION(importdialog)); |
| 2787 gchar *good; | 2787 if (file_is_dir(file, importdialog)) { |
| 2788 int i; | |
| 2789 | |
| 2790 split = g_strsplit(name, G_DIR_SEPARATOR_S, -1); | |
| 2791 good = g_strjoinv(NULL, split); | |
| 2792 g_strfreev(split); | |
| 2793 | |
| 2794 for (i = 0; i < strlen(good); i++) | |
| 2795 good[i] = toupper(good[i]); | |
| 2796 | |
| 2797 return good; | |
| 2798 } | |
| 2799 | |
| 2800 /* see if a buddy list cache file for this user exists */ | |
| 2801 | |
| 2802 gboolean bud_list_cache_exists(struct gaim_connection *gc) | |
| 2803 { | |
| 2804 gboolean ret = FALSE; | |
| 2805 char path[PATHSIZE]; | |
| 2806 char *file; | |
| 2807 struct stat sbuf; | |
| 2808 char *g_screenname; | |
| 2809 | |
| 2810 g_screenname = get_screenname_filename(gc->username); | |
| 2811 | |
| 2812 file = gaim_user_dir(); | |
| 2813 if (file != (char *)NULL) { | |
| 2814 g_snprintf(path, sizeof path, "%s/%s.%d.blist", file, g_screenname, | |
| 2815 (gc->protocol == PROTO_OSCAR) ? PROTO_TOC : gc->protocol); | |
| 2816 if (!stat(path, &sbuf)) { | |
| 2817 debug_printf("%s exists.\n", path); | |
| 2818 ret = TRUE; | |
| 2819 } else { | |
| 2820 char path2[PATHSIZE]; | |
| 2821 debug_printf("%s does not exist.\n", path); | |
| 2822 g_snprintf(path2, sizeof path2, "%s/%s.blist", file, g_screenname); | |
| 2823 if (!stat(path2, &sbuf)) { | |
| 2824 debug_printf("%s exists, moving to %s\n", path2, path); | |
| 2825 if (rename(path2, path)) | |
| 2826 debug_printf("rename didn't work!\n"); | |
| 2827 else | |
| 2828 ret = TRUE; | |
| 2829 } | |
| 2830 } | |
| 2831 g_free(file); | |
| 2832 } | |
| 2833 g_free(g_screenname); | |
| 2834 return ret; | |
| 2835 } | |
| 2836 | |
| 2837 /* if dummy is 0, save to ~/.gaim/screenname.blist, where screenname is each | |
| 2838 * signed in user. Else, let user choose */ | |
| 2839 | |
| 2840 void do_export(struct gaim_connection *g) | |
| 2841 { | |
| 2842 FILE *dir; | |
| 2843 FILE *f; | |
| 2844 char buf[32 * 1024]; | |
| 2845 char *file; | |
| 2846 char path[PATHSIZE]; | |
| 2847 char *g_screenname; | |
| 2848 | |
| 2849 /* | |
| 2850 if ( show_dialog == 1 ) { | |
| 2851 file = gtk_file_selection_get_filename(GTK_FILE_SELECTION(exportdialog)); | |
| 2852 strncpy( path, file, PATHSIZE - 1 ); | |
| 2853 if (file_is_dir(path, exportdialog)) { | |
| 2854 return; | |
| 2855 } | |
| 2856 if ((f = fopen(path,"w"))) { | |
| 2857 toc_build_config(connections->data, buf, 8192 - 1, TRUE); | |
| 2858 fprintf(f, "%s\n", buf); | |
| 2859 fclose(f); | |
| 2860 chmod(buf, S_IRUSR | S_IWUSR); | |
| 2861 } else { | |
| 2862 g_snprintf(buf, BUF_LONG / 2, _("Error writing file %s"), file); | |
| 2863 do_error_dialog(buf, _("Error")); | |
| 2864 } | |
| 2865 destroy_dialog(NULL, exportdialog); | |
| 2866 exportdialog = NULL; | |
| 2867 } else { | |
| 2868 */ | |
| 2869 | |
| 2870 file = gaim_user_dir(); | |
| 2871 if (!file) | |
| 2872 return; | 2788 return; |
| 2873 | 2789 } |
| 2874 strcpy(buf, file); | 2790 /* FIXME : import buddy list file. moderately important */ |
| 2875 dir = fopen(buf, "r"); | 2791 do_import(connections->data, file); |
| 2876 if (!dir) | 2792 destroy_dialog(NULL, importdialog); |
| 2877 mkdir(buf, S_IRUSR | S_IWUSR | S_IXUSR); | 2793 importdialog = NULL; |
| 2878 else | 2794 do_export(connections->data); |
| 2879 fclose(dir); | 2795 } |
| 2880 | 2796 |
| 2881 g_screenname = get_screenname_filename(g->username); | 2797 void show_import_dialog() |
| 2882 | 2798 { |
| 2883 sprintf(path, "%s/%s.%d.blist", file, g_screenname, | 2799 char *buf = g_malloc(BUF_LEN); |
| 2884 (g->protocol == PROTO_OSCAR) ? PROTO_TOC : g->protocol); | 2800 if (!importdialog) { |
| 2885 if ((f = fopen(path, "w"))) { | 2801 importdialog = gtk_file_selection_new(_("Gaim - Import Buddy List")); |
| 2886 debug_printf("writing %s\n", path); | 2802 |
| 2887 toc_build_config(g, buf, 8192 - 1, TRUE); | 2803 gtk_file_selection_hide_fileop_buttons(GTK_FILE_SELECTION(importdialog)); |
| 2888 fprintf(f, "%s\n", buf); | 2804 |
| 2889 fclose(f); | 2805 g_snprintf(buf, BUF_LEN - 1, "%s/", getenv("HOME")); |
| 2890 chmod(buf, S_IRUSR | S_IWUSR); | 2806 |
| 2891 } else { | 2807 gtk_file_selection_set_filename(GTK_FILE_SELECTION(importdialog), buf); |
| 2892 debug_printf("unable to write %s\n", path); | 2808 gtk_signal_connect(GTK_OBJECT(importdialog), "destroy", |
| 2893 } | 2809 GTK_SIGNAL_FUNC(destroy_dialog), importdialog); |
| 2894 | 2810 |
| 2895 g_free(g_screenname); | 2811 gtk_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(importdialog)->ok_button), |
| 2896 g_free(file); | 2812 "clicked", GTK_SIGNAL_FUNC(do_import_dialog), NULL); |
| 2897 } | 2813 gtk_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(importdialog)->cancel_button), |
| 2898 | 2814 "clicked", GTK_SIGNAL_FUNC(destroy_dialog), importdialog); |
| 2815 | |
| 2816 | |
| 2817 } | |
| 2818 | |
| 2819 g_free(buf); | |
| 2820 gtk_widget_show(importdialog); | |
| 2821 gdk_window_raise(importdialog->window); | |
| 2822 } | |
| 2899 | 2823 |
| 2900 /* | 2824 /* |
| 2901 void show_export_dialog() | 2825 void show_export_dialog() |
| 2902 { | 2826 { |
| 2903 char *buf = g_malloc(BUF_LEN); | 2827 char *buf = g_malloc(BUF_LEN); |
| 2925 gtk_widget_show(exportdialog); | 2849 gtk_widget_show(exportdialog); |
| 2926 gdk_window_raise(exportdialog->window); | 2850 gdk_window_raise(exportdialog->window); |
| 2927 | 2851 |
| 2928 } | 2852 } |
| 2929 */ | 2853 */ |
| 2930 | |
| 2931 /* if gc is non-NULL, then import from ~/.gaim/gc->username.blist, else let user | |
| 2932 choose */ | |
| 2933 | |
| 2934 void do_import(GtkWidget *w, struct gaim_connection *gc) | |
| 2935 { | |
| 2936 char *buf = g_malloc(BUF_LONG * 2); | |
| 2937 char *buf2; | |
| 2938 char *first = g_malloc(64); | |
| 2939 char *file; | |
| 2940 char path[PATHSIZE]; | |
| 2941 char *g_screenname; | |
| 2942 int len; | |
| 2943 FILE *f; | |
| 2944 gboolean from_dialog = FALSE; | |
| 2945 | |
| 2946 if (!gc) { | |
| 2947 debug_printf("want to import file "); | |
| 2948 file = gtk_file_selection_get_filename(GTK_FILE_SELECTION(importdialog)); | |
| 2949 debug_printf("%s", file); | |
| 2950 if (file_is_dir(file, importdialog)) { | |
| 2951 debug_printf(" but it is a directory\n"); | |
| 2952 g_free(buf); | |
| 2953 g_free(first); | |
| 2954 return; | |
| 2955 } | |
| 2956 strncpy(path, file, PATHSIZE - 1); | |
| 2957 /* FIXME : import buddy list file. moderately important */ | |
| 2958 gc = connections->data; | |
| 2959 from_dialog = TRUE; | |
| 2960 } else { | |
| 2961 g_screenname = get_screenname_filename(gc->username); | |
| 2962 | |
| 2963 file = gaim_user_dir(); | |
| 2964 if (file != (char *)NULL) { | |
| 2965 sprintf(path, "%s/%s.%d.blist", file, g_screenname, | |
| 2966 (gc->protocol == PROTO_OSCAR) ? PROTO_TOC : gc->protocol); | |
| 2967 g_free(file); | |
| 2968 g_free(g_screenname); | |
| 2969 } else { | |
| 2970 g_free(g_screenname); | |
| 2971 g_free(buf); | |
| 2972 g_free(first); | |
| 2973 return; | |
| 2974 } | |
| 2975 } | |
| 2976 | |
| 2977 if (!(f = fopen(path, "r"))) { | |
| 2978 if (from_dialog) { | |
| 2979 debug_printf(" but it can't be opened\n"); | |
| 2980 g_snprintf(buf, BUF_LONG / 2, _("Error reading file %s"), path); | |
| 2981 do_error_dialog(buf, _("Error")); | |
| 2982 destroy_dialog(NULL, importdialog); | |
| 2983 importdialog = NULL; | |
| 2984 } | |
| 2985 debug_printf("Unable to open %s.\n", path); | |
| 2986 g_free(buf); | |
| 2987 g_free(first); | |
| 2988 return; | |
| 2989 } | |
| 2990 | |
| 2991 fgets(first, 64, f); | |
| 2992 | |
| 2993 /* AIM 4 buddy list */ | |
| 2994 if (!g_strncasecmp(first, "Config {", strlen("Config {"))) { | |
| 2995 debug_printf("aim 4\n"); | |
| 2996 rewind(f); | |
| 2997 translate_blt(f, buf); | |
| 2998 debug_printf("%s\n", buf); | |
| 2999 buf2 = buf; | |
| 3000 buf = g_malloc(8193); | |
| 3001 g_snprintf(buf, 8192, "toc_set_config {%s}\n", buf2); | |
| 3002 g_free(buf2); | |
| 3003 /* AIM 3 buddy list */ | |
| 3004 } else if (strstr(first, "group") != NULL) { | |
| 3005 debug_printf("aim 3\n"); | |
| 3006 rewind(f); | |
| 3007 translate_lst(f, buf); | |
| 3008 debug_printf("%s\n", buf); | |
| 3009 buf2 = buf; | |
| 3010 buf = g_malloc(8193); | |
| 3011 g_snprintf(buf, 8192, "toc_set_config {%s}\n", buf2); | |
| 3012 g_free(buf2); | |
| 3013 /* GAIM buddy list - no translation */ | |
| 3014 } else if (first[0] == 'm') { | |
| 3015 rewind(f); | |
| 3016 len = fread(buf, 1, BUF_LONG * 2, f); | |
| 3017 buf[len] = '\0'; | |
| 3018 buf2 = buf; | |
| 3019 buf = g_malloc(8193); | |
| 3020 g_snprintf(buf, 8192, "toc_set_config {%s}\n", buf2); | |
| 3021 g_free(buf2); | |
| 3022 /* Something else */ | |
| 3023 } else { | |
| 3024 if (from_dialog) { | |
| 3025 debug_printf(" but I don't recognize the format\n"); | |
| 3026 destroy_dialog(NULL, importdialog); | |
| 3027 importdialog = NULL; | |
| 3028 } | |
| 3029 g_free(buf); | |
| 3030 g_free(first); | |
| 3031 fclose(f); | |
| 3032 return; | |
| 3033 } | |
| 3034 | |
| 3035 if (from_dialog) | |
| 3036 debug_printf("\n"); | |
| 3037 | |
| 3038 parse_toc_buddy_list(gc, buf, 1); | |
| 3039 | |
| 3040 fclose(f); | |
| 3041 | |
| 3042 if (from_dialog) { | |
| 3043 /* save what we just did to cache */ | |
| 3044 | |
| 3045 do_export(gc); | |
| 3046 destroy_dialog(NULL, importdialog); | |
| 3047 importdialog = NULL; | |
| 3048 } | |
| 3049 | |
| 3050 g_free(buf); | |
| 3051 g_free(first); | |
| 3052 } | |
| 3053 | |
| 3054 void show_import_dialog() | |
| 3055 { | |
| 3056 char *buf = g_malloc(BUF_LEN); | |
| 3057 if (!importdialog) { | |
| 3058 importdialog = gtk_file_selection_new(_("Gaim - Import Buddy List")); | |
| 3059 | |
| 3060 gtk_file_selection_hide_fileop_buttons(GTK_FILE_SELECTION(importdialog)); | |
| 3061 | |
| 3062 g_snprintf(buf, BUF_LEN - 1, "%s/", getenv("HOME")); | |
| 3063 | |
| 3064 gtk_file_selection_set_filename(GTK_FILE_SELECTION(importdialog), buf); | |
| 3065 gtk_signal_connect(GTK_OBJECT(importdialog), "destroy", | |
| 3066 GTK_SIGNAL_FUNC(destroy_dialog), importdialog); | |
| 3067 | |
| 3068 gtk_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(importdialog)->ok_button), | |
| 3069 "clicked", GTK_SIGNAL_FUNC(do_import), NULL); | |
| 3070 gtk_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(importdialog)->cancel_button), | |
| 3071 "clicked", GTK_SIGNAL_FUNC(destroy_dialog), importdialog); | |
| 3072 | |
| 3073 | |
| 3074 } | |
| 3075 | |
| 3076 g_free(buf); | |
| 3077 gtk_widget_show(importdialog); | |
| 3078 gdk_window_raise(importdialog->window); | |
| 3079 } | |
| 3080 | |
| 3081 | 2854 |
| 3082 /*------------------------------------------------------------------------*/ | 2855 /*------------------------------------------------------------------------*/ |
| 3083 /* The dialog for new away messages */ | 2856 /* The dialog for new away messages */ |
| 3084 /*------------------------------------------------------------------------*/ | 2857 /*------------------------------------------------------------------------*/ |
| 3085 | 2858 |
