/*******************************************************
 * Create the Assistant
 *******************************************************/
static GtkWidget *
csv_import_assistant_create (CsvImportInfo *info)
{
    GtkBuilder *builder;
    GtkWidget *window;
    GtkWidget *box, *h_box;
    GtkWidget *button;
    GtkCellRenderer *renderer;
    GtkTreeViewColumn *column;

    builder = gtk_builder_new();
    gnc_builder_add_from_file  (builder , "assistant-csv-account-import.glade", "num_hrows_adj");
    gnc_builder_add_from_file  (builder , "assistant-csv-account-import.glade", "CSV Account Import Assistant");
    window = GTK_WIDGET(gtk_builder_get_object (builder, "CSV Account Import Assistant"));
    info->window = window;

    /* Set the assistant colors */
    gnc_assistant_set_colors (GTK_ASSISTANT (info->window));

    /* Load default settings */
    load_settings (info);

    /* Enable buttons on all page. */
    gtk_assistant_set_page_complete (GTK_ASSISTANT (window),
                                     GTK_WIDGET(gtk_builder_get_object(builder, "start_page")),
                                     TRUE);
    gtk_assistant_set_page_complete (GTK_ASSISTANT (window),
                                     GTK_WIDGET(gtk_builder_get_object(builder, "file_page")),
                                     FALSE);
    gtk_assistant_set_page_complete (GTK_ASSISTANT (window),
                                     GTK_WIDGET(gtk_builder_get_object(builder, "import_tree_page")),
                                     TRUE);
    gtk_assistant_set_page_complete (GTK_ASSISTANT (window),
                                     GTK_WIDGET(gtk_builder_get_object(builder, "end_page")),
                                     FALSE);
    gtk_assistant_set_page_complete (GTK_ASSISTANT (window),
                                     GTK_WIDGET(gtk_builder_get_object(builder, "summary_page")),
                                     TRUE);

    /* Start Page */

    /* File chooser Page */
    info->file_chooser = gtk_file_chooser_widget_new (GTK_FILE_CHOOSER_ACTION_OPEN);
    g_signal_connect (G_OBJECT (info->file_chooser), "file-activated",
                      G_CALLBACK (csv_import_file_chooser_confirm_cb), info);
    button = gtk_button_new_from_stock(GTK_STOCK_OK);
    gtk_widget_set_size_request (button, 100, -1);
    gtk_widget_show (button);
    h_box = gtk_hbox_new(TRUE, 0);
    gtk_box_pack_start(GTK_BOX(h_box), button, FALSE, FALSE, 0);
    gtk_file_chooser_set_extra_widget (GTK_FILE_CHOOSER(info->file_chooser), h_box);
    g_signal_connect (G_OBJECT (button), "clicked",
                      G_CALLBACK (csv_import_file_chooser_confirm_cb), info);

    box = GTK_WIDGET(gtk_builder_get_object(builder, "file_page"));
    gtk_box_pack_start (GTK_BOX (box), info->file_chooser, TRUE, TRUE, 6);
    gtk_widget_show (info->file_chooser);

    /* Account Tree Page */
    info->header_row_spin = GTK_WIDGET(gtk_builder_get_object (builder, "num_hrows"));
    info->tree_view = GTK_WIDGET(gtk_builder_get_object (builder, "treeview"));

    info->regexp = g_string_new ( "^(?<type>[^;]*);(?<full_name>[^;]*);(?<name>[^;]*);(?<code>[^;]*);?(?<description>[^;]*);?(?<color>[^;]*);?(?<notes>[^;]*);?(?<commoditym>[^;]*);?(?<commodityn>[^;]*);?(?<hidden>[^;]*);?(?<tax>[^;]*);?(?<place_holder>[^;]*)$");

    /* create model and bind to view */
    info->store = gtk_list_store_new (N_COLUMNS,
                                      G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING,
                                      G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
    gtk_tree_view_set_model( GTK_TREE_VIEW(info->tree_view), GTK_TREE_MODEL(info->store) );
#define CREATE_COLUMN(description,column_id) \
  renderer = gtk_cell_renderer_text_new (); \
  column = gtk_tree_view_column_new_with_attributes (mnemonic_escape(_(description)), renderer, "text", column_id, NULL); \
  gtk_tree_view_column_add_attribute(column, renderer, "background", ROW_COLOR); \
  gtk_tree_view_column_set_resizable (column, TRUE); \
  gtk_tree_view_append_column (GTK_TREE_VIEW (info->tree_view), column);
    CREATE_COLUMN ("type", TYPE);
    CREATE_COLUMN ("full_name", FULL_NAME);
    CREATE_COLUMN ("name", NAME);
    CREATE_COLUMN ("code", CODE);
    CREATE_COLUMN ("description", DESCRIPTION);
    CREATE_COLUMN ("color", COLOR);
    CREATE_COLUMN ("notes", NOTES);
    CREATE_COLUMN ("commoditym", COMMODITYM);
    CREATE_COLUMN ("commodityn", COMMODITYN);
    CREATE_COLUMN ("hidden", HIDDEN);
    CREATE_COLUMN ("tax", TAX);
    CREATE_COLUMN ("place_holder", PLACE_HOLDER);

    /* Finish Page */
    info->finish_label = GTK_WIDGET(gtk_builder_get_object(builder, "end_page"));
    /* Summary Page */
    info->summary_label = GTK_WIDGET(gtk_builder_get_object(builder, "summary_label"));
    info->summary_error_view = GTK_WIDGET(gtk_builder_get_object(builder, "summary_error_view"));

    g_signal_connect (G_OBJECT(window), "destroy",
                      G_CALLBACK (csv_import_assistant_destroy_cb), info);

    gnc_restore_window_size (GCONF_SECTION, GTK_WINDOW(info->window));

    gtk_builder_connect_signals(builder, info);
    g_object_unref(G_OBJECT(builder));
    return window;
}
CustomerImportGui *
gnc_plugin_customer_import_showGUI(GtkWindow *parent)
{
    CustomerImportGui *gui;
    //gktbuilderXML *xml;
    GtkBuilder *builder;
    GList *glist;
    GtkCellRenderer *renderer;
    GtkTreeViewColumn *column;

    // if window exists already, activate it
    glist = gnc_find_gui_components ("dialog-customer-import-gui", NULL, NULL);
    if (glist)
    {
        // window found
        gui = g_list_nth_data (glist, 0);
        g_list_free (glist);
        gtk_window_present (GTK_WINDOW(gui->dialog));
        return gui;
    }

    // create new window
    gui = g_new0 (CustomerImportGui, 1);

    builder = gtk_builder_new();
    gnc_builder_add_from_file (builder, "dialog-customer-import-gui.glade", "customer_import_dialog");
    gui->dialog = GTK_WIDGET(gtk_builder_get_object (builder, "customer_import_dialog"));
    gui->tree_view = GTK_WIDGET(gtk_builder_get_object (builder, "treeview1"));
    gui->entryFilename = GTK_WIDGET(gtk_builder_get_object (builder, "entryFilename"));
    gui->type = "CUSTOMER"; // Set a default type to import

    // Set the style context for this dialog so it can be easily manipulated with css
    gnc_widget_set_style_context (GTK_WIDGET(gui->dialog), "GncCustomerImportDialog");

    gtk_window_set_transient_for (GTK_WINDOW (gui->dialog), parent);

    gui->regexp = g_string_new ( "^(?<id>[^;]+);(?<company>[^;]*);(?<name>[^;]+);(?<addr1>[^;]+);?(?<addr2>[^;]*);?(?<addr3>[^;]*);?(?<addr4>[^;]*);?(?<phone>[^;]*);?(?<fax>[^;]*);?(?<email>[^;]*);?(?<shipname>[^;]*);?(?<shipaddr1>[^;]*);?(?<shipaddr2>[^;]*);?(?<shipaddr3>[^;]*);?(?<shipaddr4>[^;]*);?(?<shipphone>[^;]*);?(?<shipfax>[^;]*);?(?<shipemail>[^;]*)");
    gui->book = gnc_get_current_book();

    // create model and bind to view
    gui->store = gtk_list_store_new (CI_N_COLUMNS,
                                     G_TYPE_STRING, G_TYPE_STRING,
                                     G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING,
                                     G_TYPE_STRING,
                                     G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
    gtk_tree_view_set_model( GTK_TREE_VIEW(gui->tree_view), GTK_TREE_MODEL(gui->store) );
#define CREATE_COLUMN(description,column_id) \
  renderer = gtk_cell_renderer_text_new (); \
  column = gtk_tree_view_column_new_with_attributes (description, renderer, "text", column_id, NULL); \
  gtk_tree_view_column_set_resizable (column, TRUE); \
  gtk_tree_view_append_column (GTK_TREE_VIEW (gui->tree_view), column);
    CREATE_COLUMN ("id", CI_ID);
    CREATE_COLUMN ("company", CI_COMPANY);
    CREATE_COLUMN ("name", CI_NAME);
    CREATE_COLUMN ("addr1", CI_ADDR1);
    CREATE_COLUMN ("addr2", CI_ADDR2);
    CREATE_COLUMN ("addr3", CI_ADDR3);
    CREATE_COLUMN ("addr4", CI_ADDR4);
    CREATE_COLUMN ("phone", CI_PHONE);
    CREATE_COLUMN ("fax", CI_FAX);
    CREATE_COLUMN ("email", CI_EMAIL);
    CREATE_COLUMN ("notes", CI_NOTES);
    CREATE_COLUMN ("shipname", CI_SHIPNAME);
    CREATE_COLUMN ("shipaddr1", CI_SHIPADDR1);
    CREATE_COLUMN ("shipaddr2", CI_SHIPADDR2);
    CREATE_COLUMN ("shipaddr3", CI_SHIPADDR3);
    CREATE_COLUMN ("shipaddr4", CI_SHIPADDR4);
    CREATE_COLUMN ("shipphone", CI_SHIPPHONE);
    CREATE_COLUMN ("shipfax", CI_SHIPFAX);
    CREATE_COLUMN ("shipemail", CI_SHIPEMAIL);

    gui->component_id = gnc_register_gui_component ("dialog-customer-import-gui",
                        NULL,
                        gnc_customer_import_gui_close_handler,
                        gui);

    /* Setup signals */
    gtk_builder_connect_signals_full (builder, gnc_builder_connect_full_func, gui);
    gtk_widget_show_all ( gui->dialog );
    return gui;
}
Exemple #3
0
BillImportGui *
gnc_plugin_bi_import_showGUI(void)
{
    BillImportGui *gui;
    GtkBuilder *builder;
    GList *glist;
    GtkCellRenderer *renderer;
    GtkTreeViewColumn *column;

    // if window exists already, activate it
    glist = gnc_find_gui_components ("dialog-bi-import-gui", NULL, NULL);
    if (glist)
    {
        // window found
        gui = g_list_nth_data (glist, 0);
        g_list_free (glist);
        gtk_window_present (GTK_WINDOW(gui->dialog));
        return gui;
    }

    // create new window
    gui = g_new0 (BillImportGui, 1);
    gui->type = "BILL"; // Set default type to match gui.  really shouldn't be here TODO change me
    gui->open_mode = "ALL";

    builder = gtk_builder_new();
    gnc_builder_add_from_file (builder, "dialog-bi-import-gui.glade", "bi-import Dialog");
    gui->dialog = GTK_WIDGET(gtk_builder_get_object (builder, "bi-import Dialog"));
    gui->tree_view = GTK_WIDGET(gtk_builder_get_object (builder, "treeview1"));
    gui->entryFilename = GTK_WIDGET(gtk_builder_get_object (builder, "entryFilename"));

    gui->book = gnc_get_current_book();

    gui->regexp = g_string_new ( "^(?<id>[^;]*);(?<date_opened>[^;]*);(?<owner_id>[^;]*);(?<billing_id>[^;]*);?(?<notes>[^;]*);?(?<date>[^;]*);?(?<desc>[^;]*);?(?<action>[^;]*);?(?<account>[^;]*);?(?<quantity>[^;]*);?(?<price>[^;]*);?(?<disc_type>[^;]*);?(?<disc_how>[^;]*);?(?<discount>[^;]*);?(?<taxable>[^;]*);?(?<taxincluded>[^;]*);?(?<tax_table>[^;]*);(?<date_posted>[^;]*);(?<due_date>[^;]*);(?<account_posted>[^;]*);(?<memo_posted>[^;]*);(?<accu_splits>[^;]*)$");

    // create model and bind to view
    gui->store = gtk_list_store_new (N_COLUMNS,
                                     G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, // invoice settings
                                     G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, // entry settings
                                     G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING); // autopost settings
    gtk_tree_view_set_model( GTK_TREE_VIEW(gui->tree_view), GTK_TREE_MODEL(gui->store) );
#define CREATE_COLUMN(description,column_id) \
  renderer = gtk_cell_renderer_text_new (); \
  column = gtk_tree_view_column_new_with_attributes (description, renderer, "text", column_id, NULL); \
  gtk_tree_view_column_set_resizable (column, TRUE); \
  gtk_tree_view_append_column (GTK_TREE_VIEW (gui->tree_view), column);
    CREATE_COLUMN ("id", ID);
    CREATE_COLUMN ("date__opened", DATE_OPENED);
    CREATE_COLUMN ("owner__id", OWNER_ID);
    CREATE_COLUMN ("billing__id", BILLING_ID);
    CREATE_COLUMN ("notes", NOTES);

    CREATE_COLUMN ("date", DATE);
    CREATE_COLUMN ("desc", DESC);
    CREATE_COLUMN ("action", ACTION);
    CREATE_COLUMN ("account", ACCOUNT);
    CREATE_COLUMN ("quantity", QUANTITY);
    CREATE_COLUMN ("price", PRICE);
    CREATE_COLUMN ("disc__type", DISC_TYPE);
    CREATE_COLUMN ("disc__how", DISC_HOW);
    CREATE_COLUMN ("discount", DISCOUNT);
    CREATE_COLUMN ("taxable", TAXABLE);
    CREATE_COLUMN ("taxincluded", TAXINCLUDED);
    CREATE_COLUMN ("tax__table", TAX_TABLE);

    CREATE_COLUMN ("date__posted", DATE_POSTED);
    CREATE_COLUMN ("due__date", DUE_DATE);
    CREATE_COLUMN ("account__posted", ACCOUNT_POSTED);
    CREATE_COLUMN ("memo__posted", MEMO_POSTED);
    CREATE_COLUMN ("accu__splits", ACCU_SPLITS);

    gui->component_id = gnc_register_gui_component ("dialog-bi-import-gui",
                        NULL,
                        gnc_bi_import_gui_close_handler,
                        gui);

    /* Setup signals */
    gtk_builder_connect_signals_full (builder, gnc_builder_connect_full_func, gui);

    gtk_widget_show_all ( gui->dialog );

    g_object_unref(G_OBJECT(builder));

    return gui;
}
/*******************************************************
 * Create the Assistant
 *******************************************************/
static GtkWidget *
csv_import_assistant_create (CsvImportInfo *info)
{
    GtkBuilder *builder;
    GtkWidget *window;
    GtkWidget *box, *h_box;
    GtkWidget *button;
    GtkCellRenderer *renderer;
    GtkTreeViewColumn *column;
    gchar *mnemonic_desc = NULL;

    builder = gtk_builder_new();
    gnc_builder_add_from_file  (builder, "assistant-csv-account-import.glade", "num_hrows_adj");
    gnc_builder_add_from_file  (builder, "assistant-csv-account-import.glade", "csv_account_import_assistant");
    window = GTK_WIDGET(gtk_builder_get_object (builder, "csv_account_import_assistant"));
    info->window = window;

    // Set the style context for this dialog so it can be easily manipulated with css
    gnc_widget_set_style_context (GTK_WIDGET(window), "GncAssistAccountImport");

    /* Load default settings */
    load_settings (info);

    /* Enable buttons on all page. */
    gtk_assistant_set_page_complete (GTK_ASSISTANT(window),
                                     GTK_WIDGET(gtk_builder_get_object(builder, "start_page")),
                                     TRUE);
    gtk_assistant_set_page_complete (GTK_ASSISTANT(window),
                                     GTK_WIDGET(gtk_builder_get_object(builder, "file_page")),
                                     FALSE);
    gtk_assistant_set_page_complete (GTK_ASSISTANT(window),
                                     GTK_WIDGET(gtk_builder_get_object(builder, "import_tree_page")),
                                     TRUE);
    gtk_assistant_set_page_complete (GTK_ASSISTANT(window),
                                     GTK_WIDGET(gtk_builder_get_object(builder, "end_page")),
                                     FALSE);
    gtk_assistant_set_page_complete (GTK_ASSISTANT(window),
                                     GTK_WIDGET(gtk_builder_get_object(builder, "summary_page")),
                                     TRUE);

    /* Start Page */

    /* File chooser Page */
    info->file_chooser = gtk_file_chooser_widget_new (GTK_FILE_CHOOSER_ACTION_OPEN);
    g_signal_connect (G_OBJECT(info->file_chooser), "file-activated",
                      G_CALLBACK(csv_import_file_chooser_confirm_cb), info);
    button = gtk_button_new_with_mnemonic (_("_OK"));
    gtk_widget_set_size_request (button, 100, -1);
    gtk_widget_show (button);
    h_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
    gtk_box_set_homogeneous (GTK_BOX (h_box), TRUE);
    gtk_widget_set_hexpand (GTK_WIDGET(h_box), TRUE);
    gtk_box_pack_start (GTK_BOX(h_box), button, FALSE, FALSE, 0);
    gtk_file_chooser_set_extra_widget (GTK_FILE_CHOOSER(info->file_chooser), h_box);
    g_signal_connect (G_OBJECT(button), "clicked",
                      G_CALLBACK(csv_import_file_chooser_confirm_cb), info);

    box = GTK_WIDGET(gtk_builder_get_object(builder, "file_page"));
    gtk_box_pack_start (GTK_BOX(box), info->file_chooser, TRUE, TRUE, 6);
    gtk_widget_show (info->file_chooser);

    /* Account Tree Page */
    info->header_row_spin = GTK_WIDGET(gtk_builder_get_object (builder, "num_hrows"));
    info->tree_view = GTK_WIDGET(gtk_builder_get_object (builder, "treeview"));

    /* Comma Separated file default */
    info->regexp = g_string_new ("");
    create_regex (info->regexp, ",");

    /* create model and bind to view */
    info->store = gtk_list_store_new (N_COLUMNS,
                                      G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING,
                                      G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
    gtk_tree_view_set_model (GTK_TREE_VIEW(info->tree_view), GTK_TREE_MODEL(info->store));
#define CREATE_COLUMN(description,column_id) \
  renderer = gtk_cell_renderer_text_new (); \
  mnemonic_desc = mnemonic_escape (_(description)); \
  column = gtk_tree_view_column_new_with_attributes (mnemonic_desc, renderer, "text", column_id, NULL); \
  gtk_tree_view_column_add_attribute (column, renderer, "background", ROW_COLOR); \
  gtk_tree_view_column_set_resizable (column, TRUE); \
  gtk_tree_view_append_column (GTK_TREE_VIEW(info->tree_view), column); \
  g_free (mnemonic_desc);
    CREATE_COLUMN ("type", TYPE);
    CREATE_COLUMN ("full_name", FULL_NAME);
    CREATE_COLUMN ("name", NAME);
    CREATE_COLUMN ("code", CODE);
    CREATE_COLUMN ("description", DESCRIPTION);
    CREATE_COLUMN ("color", COLOR);
    CREATE_COLUMN ("notes", NOTES);
    CREATE_COLUMN ("commoditym", COMMODITYM);
    CREATE_COLUMN ("commodityn", COMMODITYN);
    CREATE_COLUMN ("hidden", HIDDEN);
    CREATE_COLUMN ("tax", TAX);
    CREATE_COLUMN ("place_holder", PLACE_HOLDER);

    /* Finish Page */
    info->finish_label = GTK_WIDGET(gtk_builder_get_object (builder, "end_page"));
    /* Summary Page */
    info->summary_label = GTK_WIDGET(gtk_builder_get_object (builder, "summary_label"));
    info->summary_error_view = GTK_WIDGET(gtk_builder_get_object (builder, "summary_error_view"));

    g_signal_connect (G_OBJECT(window), "destroy",
                      G_CALLBACK(csv_import_assistant_destroy_cb), info);

    gnc_restore_window_size (GNC_PREFS_GROUP, GTK_WINDOW(info->window));

    gtk_builder_connect_signals (builder, info);
    g_object_unref (G_OBJECT(builder));
    return window;
}