|
GnuCash 2.4.99
|
00001 /* 00002 * import-format-dialog.c -- provides a UI to ask for users to resolve 00003 * ambiguities. 00004 * 00005 * Created by: Derek Atkins <derek@ihtfp.com> 00006 * Copyright (c) 2003 Derek Atkins <warlord@MIT.EDU> 00007 * 00008 * This program is free software; you can redistribute it and/or 00009 * modify it under the terms of the GNU General Public License as 00010 * published by the Free Software Foundation; either version 2 of 00011 * the License, or (at your option) any later version. 00012 * 00013 * This program is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU General Public License 00019 * along with this program; if not, contact: 00020 * 00021 * Free Software Foundation Voice: +1-617-542-5942 00022 * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 00023 * Boston, MA 02110-1301, USA gnu@gnu.org 00024 */ 00025 00026 #ifdef HAVE_CONFIG_H 00027 #include "config.h" 00028 #endif 00029 00030 #include <gtk/gtk.h> 00031 #include <glib/gi18n.h> 00032 00033 #include "import-parse.h" 00034 #include "dialog-utils.h" 00035 #include "gnc-ui-util.h" 00036 00037 #define MAX_CHOICES 6 00038 00039 #ifdef GTKCOMBOBOX_TOOLTIPS_WORK 00040 static void 00041 choice_option_changed (GtkWidget *widget, gpointer index_p) 00042 { 00043 } 00044 #else 00045 static void 00046 choice_option_changed (GtkWidget *widget, gint index, gpointer index_p) 00047 { 00048 gint *my_index = index_p; 00049 *my_index = index; 00050 } 00051 #endif 00052 00053 static GncImportFormat 00054 add_menu_and_run_dialog(GtkWidget *dialog, GtkWidget *menu_box, GncImportFormat fmt) 00055 { 00056 GtkWidget *menu; 00057 gint index = 0, count = 0; 00058 GncImportFormat formats[MAX_CHOICES]; 00059 GNCOptionInfo menus[MAX_CHOICES]; 00060 00061 memset(&menus, 0, sizeof(menus)); 00062 00063 if (fmt & GNCIF_NUM_PERIOD) 00064 { 00065 formats[count] = GNCIF_NUM_PERIOD; 00066 menus[count].name = _("Period: 123,456.78"); 00067 menus[count].callback = choice_option_changed; 00068 menus[count].user_data = &index; 00069 count++; 00070 } 00071 00072 if (fmt & GNCIF_NUM_COMMA) 00073 { 00074 formats[count] = GNCIF_NUM_COMMA; 00075 menus[count].name = _("Comma: 123.456,78"); 00076 menus[count].callback = choice_option_changed; 00077 menus[count].user_data = &index; 00078 count++; 00079 } 00080 00081 if (fmt & GNCIF_DATE_MDY) 00082 { 00083 formats[count] = GNCIF_DATE_MDY; 00084 menus[count].name = _("m/d/y"); 00085 menus[count].callback = choice_option_changed; 00086 menus[count].user_data = &index; 00087 count++; 00088 } 00089 00090 if (fmt & GNCIF_DATE_DMY) 00091 { 00092 formats[count] = GNCIF_DATE_DMY; 00093 menus[count].name = _("d/m/y"); 00094 menus[count].callback = choice_option_changed; 00095 menus[count].user_data = &index; 00096 count++; 00097 } 00098 00099 if (fmt & GNCIF_DATE_YMD) 00100 { 00101 formats[count] = GNCIF_DATE_YMD; 00102 menus[count].name = _("y/m/d"); 00103 menus[count].callback = choice_option_changed; 00104 menus[count].user_data = &index; 00105 count++; 00106 } 00107 00108 if (fmt & GNCIF_DATE_YDM) 00109 { 00110 formats[count] = GNCIF_DATE_YDM; 00111 menus[count].name = _("y/d/m"); 00112 menus[count].callback = choice_option_changed; 00113 menus[count].user_data = &index; 00114 count++; 00115 } 00116 00117 g_assert(count > 1); 00118 menu = gnc_build_option_menu(menus, count); 00119 gtk_box_pack_start(GTK_BOX(menu_box), menu, TRUE, TRUE, 0); 00120 00121 gtk_widget_show_all(dialog); 00122 gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); 00123 gtk_dialog_run(GTK_DIALOG(dialog)); 00124 gtk_widget_destroy(dialog); 00125 00126 return formats[index]; 00127 } 00128 00129 GncImportFormat 00130 gnc_import_choose_fmt(const char* msg, GncImportFormat fmts, gpointer data) 00131 00132 { 00133 GtkBuilder *builder; 00134 GtkWidget *dialog; 00135 GtkWidget *widget; 00136 00137 g_return_val_if_fail(fmts, FALSE); 00138 00139 /* if there is only one format availble, just return it */ 00140 if (!(fmts & (fmts - 1))) 00141 { 00142 return fmts; 00143 } 00144 /* Open the Glade Builder file */ 00145 builder = gtk_builder_new(); 00146 gnc_builder_add_from_file (builder, "dialog-import.glade", "format_picker"); 00147 dialog = GTK_WIDGET(gtk_builder_get_object (builder, "format_picker")); 00148 widget = GTK_WIDGET(gtk_builder_get_object (builder, "msg_label")); 00149 gtk_label_set_text(GTK_LABEL(widget), msg); 00150 00151 widget = GTK_WIDGET(gtk_builder_get_object (builder, "menu_box")); 00152 00153 g_object_unref(G_OBJECT(builder)); 00154 00155 return add_menu_and_run_dialog(dialog, widget, fmts); 00156 }
1.7.4