2003-07-11 03:28:00 +00:00
|
|
|
/*
|
2003-10-23 04:33:18 +00:00
|
|
|
* import-format-dialog.c -- provides a UI to ask for users to resolve
|
|
|
|
|
* ambiguities.
|
2003-07-11 03:28:00 +00:00
|
|
|
*
|
|
|
|
|
* Created by: Derek Atkins <derek@ihtfp.com>
|
2003-10-23 04:33:18 +00:00
|
|
|
* Copyright (c) 2003 Derek Atkins <warlord@MIT.EDU>
|
2003-07-11 03:28:00 +00:00
|
|
|
*
|
2003-10-23 04:33:18 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
|
* published by the Free Software Foundation; either version 2 of
|
|
|
|
|
* the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, contact:
|
|
|
|
|
*
|
|
|
|
|
* Free Software Foundation Voice: +1-617-542-5942
|
2005-11-17 05:35:02 +00:00
|
|
|
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652
|
|
|
|
|
* Boston, MA 02110-1301, USA gnu@gnu.org
|
2003-07-11 03:28:00 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
|
#include "config.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
2005-11-19 23:53:34 +00:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
#include <glib/gi18n.h>
|
2003-07-11 03:28:00 +00:00
|
|
|
#include "dialog-utils.h"
|
2012-08-01 13:53:58 +00:00
|
|
|
#include "import-parse.h"
|
2003-07-11 03:28:00 +00:00
|
|
|
#include "gnc-ui-util.h"
|
|
|
|
|
|
|
|
|
|
#define MAX_CHOICES 6
|
|
|
|
|
|
|
|
|
|
static void
|
2012-08-01 13:53:58 +00:00
|
|
|
option_changed_cb (GtkWidget *widget, gpointer index_p)
|
2003-07-11 03:28:00 +00:00
|
|
|
{
|
2010-02-18 05:31:54 +00:00
|
|
|
gint *my_index = index_p;
|
2012-08-01 13:53:58 +00:00
|
|
|
*my_index = gtk_combo_box_get_active(GTK_COMBO_BOX(widget));
|
2003-07-11 03:28:00 +00:00
|
|
|
}
|
2012-08-01 13:53:58 +00:00
|
|
|
|
2003-07-11 03:28:00 +00:00
|
|
|
|
|
|
|
|
static GncImportFormat
|
|
|
|
|
add_menu_and_run_dialog(GtkWidget *dialog, GtkWidget *menu_box, GncImportFormat fmt)
|
|
|
|
|
{
|
2012-08-01 13:53:58 +00:00
|
|
|
GtkComboBox *combo;
|
|
|
|
|
GtkListStore *store;
|
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
GtkCellRenderer *cell;
|
2010-02-18 05:31:54 +00:00
|
|
|
gint index = 0, count = 0;
|
2012-08-01 13:53:58 +00:00
|
|
|
gint *index_p = &index;
|
2010-02-18 05:31:54 +00:00
|
|
|
GncImportFormat formats[MAX_CHOICES];
|
|
|
|
|
|
2012-08-01 13:53:58 +00:00
|
|
|
store = gtk_list_store_new(1, G_TYPE_STRING);
|
2010-02-18 05:31:54 +00:00
|
|
|
|
|
|
|
|
if (fmt & GNCIF_NUM_PERIOD)
|
|
|
|
|
{
|
2012-08-01 13:53:58 +00:00
|
|
|
gtk_list_store_append (store, &iter);
|
|
|
|
|
gtk_list_store_set (store, &iter, 0, _("Period: 123,456.78"), -1);
|
2010-02-18 05:31:54 +00:00
|
|
|
formats[count] = GNCIF_NUM_PERIOD;
|
|
|
|
|
count++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (fmt & GNCIF_NUM_COMMA)
|
|
|
|
|
{
|
2012-08-01 13:53:58 +00:00
|
|
|
gtk_list_store_append (store, &iter);
|
|
|
|
|
gtk_list_store_set (store, &iter, 0, _("Comma: 123.456,78"), -1);
|
2010-02-18 05:31:54 +00:00
|
|
|
formats[count] = GNCIF_NUM_COMMA;
|
|
|
|
|
count++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (fmt & GNCIF_DATE_MDY)
|
|
|
|
|
{
|
2012-08-01 13:53:58 +00:00
|
|
|
gtk_list_store_append (store, &iter);
|
|
|
|
|
gtk_list_store_set (store, &iter, 0, _("m/d/y"), -1);
|
2010-02-18 05:31:54 +00:00
|
|
|
formats[count] = GNCIF_DATE_MDY;
|
|
|
|
|
count++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (fmt & GNCIF_DATE_DMY)
|
|
|
|
|
{
|
2012-08-01 13:53:58 +00:00
|
|
|
gtk_list_store_append (store, &iter);
|
|
|
|
|
gtk_list_store_set (store, &iter, 0, _("d/m/y"), -1);
|
2010-02-18 05:31:54 +00:00
|
|
|
formats[count] = GNCIF_DATE_DMY;
|
|
|
|
|
count++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (fmt & GNCIF_DATE_YMD)
|
|
|
|
|
{
|
2012-08-01 13:53:58 +00:00
|
|
|
gtk_list_store_append (store, &iter);
|
|
|
|
|
gtk_list_store_set (store, &iter, 0, _("y/m/d"), -1);
|
2010-02-18 05:31:54 +00:00
|
|
|
formats[count] = GNCIF_DATE_YMD;
|
|
|
|
|
count++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (fmt & GNCIF_DATE_YDM)
|
|
|
|
|
{
|
2012-08-01 13:53:58 +00:00
|
|
|
gtk_list_store_append (store, &iter);
|
|
|
|
|
gtk_list_store_set (store, &iter, 0, _("y/d/m"), -1);
|
2010-02-18 05:31:54 +00:00
|
|
|
formats[count] = GNCIF_DATE_YDM;
|
|
|
|
|
count++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_assert(count > 1);
|
2012-08-01 13:53:58 +00:00
|
|
|
|
|
|
|
|
combo = GTK_COMBO_BOX(gtk_combo_box_new_with_model(GTK_TREE_MODEL(store)));
|
|
|
|
|
g_object_unref(store);
|
|
|
|
|
|
|
|
|
|
/* Create cell renderer. */
|
|
|
|
|
cell = gtk_cell_renderer_text_new();
|
|
|
|
|
|
|
|
|
|
/* Pack it to the combo box. */
|
|
|
|
|
gtk_cell_layout_pack_start( GTK_CELL_LAYOUT( combo ), cell, FALSE );
|
|
|
|
|
|
|
|
|
|
/* Connect renderer to data source */
|
|
|
|
|
gtk_cell_layout_set_attributes( GTK_CELL_LAYOUT( combo ), cell, "text", 0, NULL );
|
|
|
|
|
|
|
|
|
|
g_signal_connect(G_OBJECT(combo), "changed",
|
2013-10-31 22:22:53 +00:00
|
|
|
G_CALLBACK(option_changed_cb), index_p);
|
2012-08-01 13:53:58 +00:00
|
|
|
|
|
|
|
|
gtk_box_pack_start(GTK_BOX(menu_box), GTK_WIDGET(combo), TRUE, TRUE, 0);
|
2010-02-18 05:31:54 +00:00
|
|
|
|
|
|
|
|
gtk_widget_show_all(dialog);
|
|
|
|
|
gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
|
|
|
|
|
gtk_dialog_run(GTK_DIALOG(dialog));
|
|
|
|
|
gtk_widget_destroy(dialog);
|
|
|
|
|
|
|
|
|
|
return formats[index];
|
2003-07-11 03:28:00 +00:00
|
|
|
}
|
|
|
|
|
|
2012-08-01 13:53:58 +00:00
|
|
|
|
2003-07-11 03:28:00 +00:00
|
|
|
GncImportFormat
|
|
|
|
|
gnc_import_choose_fmt(const char* msg, GncImportFormat fmts, gpointer data)
|
|
|
|
|
{
|
2011-12-17 11:02:55 +00:00
|
|
|
GtkBuilder *builder;
|
2010-02-18 05:31:54 +00:00
|
|
|
GtkWidget *dialog;
|
|
|
|
|
GtkWidget *widget;
|
2003-07-11 03:28:00 +00:00
|
|
|
|
2010-02-18 05:31:54 +00:00
|
|
|
g_return_val_if_fail(fmts, FALSE);
|
2003-07-11 03:28:00 +00:00
|
|
|
|
2017-01-16 23:03:50 +01:00
|
|
|
/* if there is only one format available, just return it */
|
2010-02-18 05:31:54 +00:00
|
|
|
if (!(fmts & (fmts - 1)))
|
|
|
|
|
{
|
|
|
|
|
return fmts;
|
|
|
|
|
}
|
2011-12-17 11:02:55 +00:00
|
|
|
/* Open the Glade Builder file */
|
|
|
|
|
builder = gtk_builder_new();
|
2012-03-16 20:27:09 +00:00
|
|
|
gnc_builder_add_from_file (builder, "dialog-import.glade", "format_picker");
|
2011-12-17 11:02:55 +00:00
|
|
|
dialog = GTK_WIDGET(gtk_builder_get_object (builder, "format_picker"));
|
|
|
|
|
widget = GTK_WIDGET(gtk_builder_get_object (builder, "msg_label"));
|
2010-02-18 05:31:54 +00:00
|
|
|
gtk_label_set_text(GTK_LABEL(widget), msg);
|
2003-07-11 03:28:00 +00:00
|
|
|
|
2011-12-17 11:02:55 +00:00
|
|
|
widget = GTK_WIDGET(gtk_builder_get_object (builder, "menu_box"));
|
|
|
|
|
|
|
|
|
|
g_object_unref(G_OBJECT(builder));
|
|
|
|
|
|
2010-02-18 05:31:54 +00:00
|
|
|
return add_menu_and_run_dialog(dialog, widget, fmts);
|
2003-07-11 03:28:00 +00:00
|
|
|
}
|