/***************************
 *                         *
 * Encodings dialog window *
 *                         *
 **************************/
void
gxi_edit_encodings_clicked_cb (GtkButton *button, GncXmlImportData *data)
{
    GtkBuilder *builder;
    GtkWidget *dialog;
    GtkListStore *list_store;
    GtkTreeStore *tree_store;
    GtkTreeIter iter, parent, *parent_ptr;
    GList *encodings_bak, *enc_iter;
    const gchar *encoding;
    system_encoding_type *system_enc;
    gpointer enc_ptr;
    gint i, j;

    builder = gtk_builder_new();
    gnc_builder_add_from_file (builder, "assistant-xml-encoding.glade", "encodings_dialog");
    dialog = GTK_WIDGET(gtk_builder_get_object (builder, "encodings_dialog"));
    data->encodings_dialog = dialog;


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

    gtk_builder_connect_signals_full (builder, gnc_builder_connect_full_func, data);

    gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (data->assistant));

    data->available_encs_view = GTK_TREE_VIEW (gtk_builder_get_object (builder, "available_encs_view"));

    data->custom_enc_entry = GTK_WIDGET(gtk_builder_get_object (builder, "custom_enc_entry"));

    /* set up selected encodings list */
    data->selected_encs_view = GTK_TREE_VIEW (gtk_builder_get_object (builder, "selected_encs_view"));
    list_store = gtk_list_store_new (ENC_NUM_COLS, G_TYPE_STRING, G_TYPE_POINTER);
    for (enc_iter = data->encodings; enc_iter; enc_iter = enc_iter->next)
    {
        encoding = g_quark_to_string (GPOINTER_TO_UINT (enc_iter->data));
        gtk_list_store_append (list_store, &iter);
        gtk_list_store_set (list_store, &iter, ENC_COL_STRING, encoding,
                            ENC_COL_QUARK, enc_iter->data, -1);
    }
    gtk_tree_view_insert_column_with_attributes (
        data->selected_encs_view, -1, NULL,
        gtk_cell_renderer_text_new (), "text", ENC_COL_STRING, NULL);
    gtk_tree_view_set_model (data->selected_encs_view,
                             GTK_TREE_MODEL (list_store));
    g_object_unref (list_store);

    /* set up system encodings list */
    data->available_encs_view = GTK_TREE_VIEW (gtk_builder_get_object (builder, "available_encs_view"));
    tree_store = gtk_tree_store_new (ENC_NUM_COLS, G_TYPE_STRING, G_TYPE_POINTER);
    for (i = 0, system_enc = system_encodings;
            i < n_system_encodings;
            i++, system_enc++)
    {
        if (i == 0)
        {
            /* first system encoding */
            parent_ptr = NULL;
        }
        else
        {
            parent_ptr = &iter;
            for (j = 0; j < system_enc->parent; j++)
                if (gtk_tree_model_iter_parent (GTK_TREE_MODEL (tree_store),
                                                &parent, &iter))
                {
                    /* go up one level */
                    iter = parent;
                }
                else
                {
                    /* no parent to toplevel element */
                    parent_ptr = NULL;
                }
        }
        if (system_enc->encoding)
            enc_ptr = GUINT_TO_POINTER (g_quark_from_string (system_enc->encoding));
        else
            enc_ptr = NULL;

        gtk_tree_store_append (tree_store, &iter, parent_ptr);
        gtk_tree_store_set (tree_store, &iter, ENC_COL_STRING,
                            gettext (system_enc->text), ENC_COL_QUARK, enc_ptr, -1);
    }
    gtk_tree_view_insert_column_with_attributes (
        data->available_encs_view, -1, NULL,
        gtk_cell_renderer_text_new (), "text", ENC_COL_STRING, NULL);
    gtk_tree_view_set_model (data->available_encs_view,
                             GTK_TREE_MODEL (tree_store));
    g_object_unref (tree_store);

    /* run the dialog */
    encodings_bak = g_list_copy (data->encodings);
    if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK)
    {
        g_list_free (encodings_bak);
        if (!g_list_find (data->encodings,
                          GUINT_TO_POINTER (data->default_encoding)))
        {
            /* choose top level encoding then */
            data->default_encoding = GPOINTER_TO_UINT (data->encodings->data);
        }

        /* update whole page */
        gxi_check_file (data);
        gxi_update_default_enc_combo (data);
        gxi_update_string_box (data);
        gxi_update_conversion_forward (data);
    }
    else
    {
        g_list_free (data->encodings);
        data->encodings = encodings_bak;
    }
    g_object_unref(G_OBJECT(builder));

    gtk_widget_destroy (dialog);
    data->encodings_dialog = NULL;
}
Beispiel #2
0
void
gnc_ui_fincalc_dialog_create(GtkWindow *parent)
{
    FinCalcDialog *fcd;
    GtkWidget *button;
    GtkWidget *combo;
    GtkWidget *edit;
    GtkWidget *hbox;
    GtkBuilder *builder;

    if (gnc_forall_gui_components (DIALOG_FINCALC_CM_CLASS,
                                   show_handler, NULL))
        return;


    fcd = g_new0(FinCalcDialog, 1);

    builder = gtk_builder_new();
    gnc_builder_add_from_file (builder, "dialog-fincalc.glade", "liststore1");
    gnc_builder_add_from_file (builder, "dialog-fincalc.glade", "liststore2");
    gnc_builder_add_from_file (builder, "dialog-fincalc.glade", "financial_calculator_dialog");

    fcd->dialog = GTK_WIDGET(gtk_builder_get_object (builder, "financial_calculator_dialog"));

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

    /* parent */
    if (parent != NULL)
        gtk_window_set_transient_for (GTK_WINDOW(fcd->dialog), GTK_WINDOW(parent));

    gnc_register_gui_component (DIALOG_FINCALC_CM_CLASS,
                                NULL, close_handler, fcd);

    g_signal_connect (G_OBJECT (fcd->dialog), "destroy",
                      G_CALLBACK (fincalc_dialog_destroy), fcd);


    hbox = GTK_WIDGET(gtk_builder_get_object (builder, "payment_periods_hbox"));
    edit = gnc_amount_edit_new();
    fincalc_init_gae (GNC_AMOUNT_EDIT (edit), 0, 0, 1);
    fcd->amounts[PAYMENT_PERIODS] = edit;
    gtk_box_pack_end(GTK_BOX(hbox), edit, FALSE, FALSE, 0);
    g_signal_connect (G_OBJECT(edit), "changed",
                      G_CALLBACK (fincalc_update_calc_button_cb), fcd);

    button = GTK_WIDGET(gtk_builder_get_object (builder, "payment_periods_clear_button"));
    g_object_set_data(G_OBJECT(button), "edit", edit);

    hbox = GTK_WIDGET(gtk_builder_get_object (builder, "interest_rate_hbox"));
    edit = gnc_amount_edit_new();
    fincalc_init_gae (GNC_AMOUNT_EDIT (edit), 2, 5, 100000);
    fcd->amounts[INTEREST_RATE] = edit;
    gtk_box_pack_end(GTK_BOX(hbox), edit, FALSE, FALSE, 0);
    g_signal_connect (G_OBJECT(edit), "changed",
                      G_CALLBACK (fincalc_update_calc_button_cb), fcd);

    button = GTK_WIDGET(gtk_builder_get_object (builder, "interest_rate_clear_button"));
    g_object_set_data(G_OBJECT(button), "edit", edit);

    hbox = GTK_WIDGET(gtk_builder_get_object (builder, "present_value_hbox"));
    edit = gnc_amount_edit_new();
    fincalc_init_commodity_gae (GNC_AMOUNT_EDIT (edit));
    fcd->amounts[PRESENT_VALUE] = edit;
    gtk_box_pack_end(GTK_BOX(hbox), edit, FALSE, FALSE, 0);
    g_signal_connect (G_OBJECT(edit), "changed",
                      G_CALLBACK (fincalc_update_calc_button_cb), fcd);

    button = GTK_WIDGET(gtk_builder_get_object (builder, "present_value_clear_button"));
    g_object_set_data(G_OBJECT(button), "edit", edit);

    hbox = GTK_WIDGET(gtk_builder_get_object (builder, "periodic_payment_hbox"));
    edit = gnc_amount_edit_new();
    fincalc_init_commodity_gae (GNC_AMOUNT_EDIT (edit));
    fcd->amounts[PERIODIC_PAYMENT] = edit;
    gtk_box_pack_end(GTK_BOX(hbox), edit, FALSE, FALSE, 0);
    g_signal_connect (G_OBJECT(edit), "changed",
                      G_CALLBACK (fincalc_update_calc_button_cb), fcd);

    button = GTK_WIDGET(gtk_builder_get_object (builder, "periodic_payment_clear_button"));
    g_object_set_data(G_OBJECT(button), "edit", edit);

    hbox = GTK_WIDGET(gtk_builder_get_object (builder, "future_value_hbox"));
    edit = gnc_amount_edit_new();
    fincalc_init_commodity_gae (GNC_AMOUNT_EDIT (edit));
    fcd->amounts[FUTURE_VALUE] = edit;
    gtk_box_pack_end(GTK_BOX(hbox), edit, FALSE, FALSE, 0);
    g_signal_connect (G_OBJECT(edit), "changed",
                      G_CALLBACK (fincalc_update_calc_button_cb), fcd);

    button = GTK_WIDGET(gtk_builder_get_object (builder, "future_value_clear_button"));
    g_object_set_data(G_OBJECT(button), "edit", edit);


    fcd->calc_button = GTK_WIDGET(gtk_builder_get_object (builder, "calc_button"));


    combo = GTK_WIDGET(gtk_builder_get_object (builder, "compounding_combo"));
    fcd->compounding_combo = combo;
    g_signal_connect(fcd->compounding_combo, "changed",
                     G_CALLBACK (fincalc_update_calc_button_cb), fcd);

    combo = GTK_WIDGET(gtk_builder_get_object (builder, "payment_combo"));
    fcd->payment_combo = combo;
    g_signal_connect(fcd->compounding_combo, "changed",
                     G_CALLBACK (fincalc_update_calc_button_cb), fcd);

    button = GTK_WIDGET(gtk_builder_get_object (builder, "period_payment_radio"));
    fcd->end_of_period_radio = button;

    button = GTK_WIDGET(gtk_builder_get_object (builder, "discrete_compounding_radio"));
    fcd->discrete_compounding_radio = button;

    fcd->payment_total_label = GTK_WIDGET(gtk_builder_get_object (builder, "payment_total_label"));

    button = GTK_WIDGET(gtk_builder_get_object (builder, "schedule_button"));
    gtk_widget_hide (button);

    init_fi(fcd);

    fi_to_gui(fcd);

    gtk_widget_grab_focus(fcd->amounts[PAYMENT_PERIODS]);

    /* Connect all signals specified in glade. */
    gtk_builder_connect_signals(builder, fcd);
    g_object_unref(G_OBJECT(builder));

    gnc_restore_window_size(GNC_PREFS_GROUP, GTK_WINDOW(fcd->dialog));
    gtk_widget_show(fcd->dialog);
}
BillImportGui *
gnc_plugin_bi_import_showGUI (GtkWindow *parent)
{
    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_set_transient_for(GTK_WINDOW(gui->dialog), GTK_WINDOW(parent));
        gui->parent = parent;
        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"));
    gtk_window_set_transient_for(GTK_WINDOW(gui->dialog), GTK_WINDOW(parent));
    gui->parent = parent;
    gui->tree_view = GTK_WIDGET(gtk_builder_get_object (builder, "treeview1"));
    gui->entryFilename = GTK_WIDGET(gtk_builder_get_object (builder, "entryFilename"));

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

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

    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;
}