/** * Update start date... right now we always base this off the transaction * start date, but ideally we want to respect what the user has in the field, * somehow. **/ static void sxftd_freq_combo_changed( GtkWidget *w, gpointer user_data ) { SXFromTransInfo *sxfti = (SXFromTransInfo*)user_data; GDate date, nextDate; time_t tmp_tt; struct tm *tmpTm; GList *schedule = NULL; tmp_tt = xaccTransGetDate( sxfti->trans ); g_date_set_time_t( &date, tmp_tt ); g_date_clear(&nextDate, 1); sxftd_update_schedule(sxfti, &date, &schedule); recurrenceListNextInstance(schedule, &date, &nextDate); tmpTm = g_new0( struct tm, 1 ); g_date_to_struct_tm( &nextDate, tmpTm ); tmp_tt = mktime( tmpTm ); g_free( tmpTm ); gnc_date_edit_set_time( sxfti->startDateGDE, tmp_tt ); recurrenceListFree(&schedule); sxftd_update_example_cal( sxfti ); }
void gnc_date_edit_set_gdate (GNCDateEdit *gde, const GDate *date) { struct tm mytm; time64 t; g_return_if_fail(gde && GNC_IS_DATE_EDIT(gde) && date && g_date_valid(date)); g_date_to_struct_tm(date, &mytm); t = gnc_mktime(&mytm); gnc_date_edit_set_time(gde, t); }
/** * gnc_date_edit_new_flags: * @the_time: The initial time for the date editor. * @flags: A bitmask of GNCDateEditFlags values. * * Creates a new GNCDateEdit widget with the specified flags. * * Return value: the newly-created date editor widget. **/ GtkWidget * gnc_date_edit_new_flags (time64 the_time, GNCDateEditFlags flags) { GNCDateEdit *gde; gde = g_object_new (GNC_TYPE_DATE_EDIT, NULL, NULL); gde->flags = flags; gde->initial_time = -1; create_children (gde); gnc_date_edit_set_time (gde, the_time); return GTK_WIDGET (gde); }
static int date_focus_out_event(GtkWidget *widget, GdkEventKey *event, gpointer data) { GNCDateEdit *gde = data; struct tm tm; /* Get the date entered and attempt to use it. */ tm = gnc_date_edit_get_date_internal (gde); gnc_date_edit_set_time (gde, gnc_mktime (&tm)); /* Get the date again in case it was invalid the first time. */ tm = gnc_date_edit_get_date_internal (gde); g_signal_emit (gde, date_edit_signals [DATE_CHANGED], 0); g_signal_emit (gde, date_edit_signals [TIME_CHANGED], 0); return FALSE; }
/* This code should be kept in sync with src/register/datecell.c */ static int date_accel_key_press(GtkWidget *widget, GdkEventKey *event, gpointer data) { GNCDateEdit *gde = data; const char *string; struct tm tm; string = gtk_entry_get_text (GTK_ENTRY (widget)); tm = gnc_date_edit_get_date_internal (gde); if (!gnc_handle_date_accelerator (event, &tm, string)) return FALSE; gnc_date_edit_set_time (gde, gnc_mktime (&tm)); g_signal_emit (G_OBJECT (gde), date_edit_signals [TIME_CHANGED], 0); return TRUE; }
/** * Update start date... right now we always base this off the transaction * start date, but ideally we want to respect what the user has in the field, * somehow. **/ static void sxftd_freq_combo_changed( GtkWidget *w, gpointer user_data ) { SXFromTransInfo *sxfti = (SXFromTransInfo*)user_data; GDate date, nextDate; time64 tmp_tt; GList *schedule = NULL; tmp_tt = xaccTransGetDate( sxfti->trans ); gnc_gdate_set_time64 (&date, tmp_tt); g_date_clear(&nextDate, 1); sxftd_update_schedule(sxfti, &date, &schedule); recurrenceListNextInstance(schedule, &date, &nextDate); tmp_tt = gnc_time64_get_day_start_gdate (&nextDate); gnc_date_edit_set_time( sxfti->startDateGDE, tmp_tt ); recurrenceListFree(&schedule); sxftd_update_example_cal( sxfti ); }
void gnc_recurrence_set(GncRecurrence *gr, const Recurrence *r) { PeriodType pt; guint mult; GDate start; g_return_if_fail(gr && r); pt = recurrenceGetPeriodType(r); mult = recurrenceGetMultiplier(r); start = recurrenceGetDate(r); gtk_spin_button_set_value(gr->gsb_mult, (gdouble) mult); // is there some better way? { time64 t; t = gnc_time64_get_day_start_gdate (&start); gnc_date_edit_set_time (GNC_DATE_EDIT(gr->gde_start), t); } set_pt_ui(gr, pt); }
static gint sxftd_init( SXFromTransInfo *sxfti ) { GtkWidget *w; const char *transName; gint pos; GList *schedule = NULL; time64 start_tt; struct tm *tmpTm; GDate date, nextDate; if ( ! sxfti->sx ) { return -1; } if ( ! sxfti->trans ) { return -2; } if ( xaccTransIsOpen( sxfti->trans ) ) { return SXFTD_ERRNO_OPEN_XACTION; } /* Setup Widgets */ { sxfti->ne_but = GTK_TOGGLE_BUTTON(gtk_builder_get_object(sxfti->builder, "never_end_button")); sxfti->ed_but = GTK_TOGGLE_BUTTON(gtk_builder_get_object(sxfti->builder, "end_on_date_button")); sxfti->oc_but = GTK_TOGGLE_BUTTON(gtk_builder_get_object(sxfti->builder, "n_occurrences_button")); sxfti->n_occurences = GTK_ENTRY(gtk_builder_get_object(sxfti->builder, "n_occurrences_entry")); } /* Get the name from the transaction, try that as the initial SX name. */ transName = xaccTransGetDescription( sxfti->trans ); xaccSchedXactionSetName( sxfti->sx, transName ); sxfti->name = GTK_ENTRY(gtk_builder_get_object(sxfti->builder, "name_entry" )); pos = 0; gtk_editable_insert_text( GTK_EDITABLE(sxfti->name), transName, (strlen(transName) * sizeof(char)), &pos ); sxfti_attach_callbacks(sxfti); /* Setup the example calendar and related data structures. */ { int num_marks = SXFTD_EXCAL_NUM_MONTHS * 31; w = GTK_WIDGET(gtk_builder_get_object(sxfti->builder, "ex_cal_frame" )); sxfti->dense_cal_model = gnc_dense_cal_store_new(num_marks); sxfti->example_cal = GNC_DENSE_CAL(gnc_dense_cal_new_with_model(GNC_DENSE_CAL_MODEL(sxfti->dense_cal_model))); g_object_ref_sink(sxfti->example_cal); g_assert(sxfti->example_cal); gnc_dense_cal_set_num_months( sxfti->example_cal, SXFTD_EXCAL_NUM_MONTHS ); gnc_dense_cal_set_months_per_col( sxfti->example_cal, SXFTD_EXCAL_MONTHS_PER_COL ); gtk_container_add( GTK_CONTAINER(w), GTK_WIDGET(sxfti->example_cal) ); } /* Setup the start and end dates as GNCDateEdits */ { GtkWidget *paramTable = GTK_WIDGET(gtk_builder_get_object(sxfti->builder, "param_table" )); sxfti->startDateGDE = GNC_DATE_EDIT( gnc_date_edit_new (gnc_time (NULL), FALSE, FALSE)); gtk_table_attach( GTK_TABLE(paramTable), GTK_WIDGET( sxfti->startDateGDE ), 1, 2, 2, 3, (GTK_EXPAND | GTK_FILL), GTK_FILL, 0, 0 ); g_signal_connect( sxfti->startDateGDE, "date-changed", G_CALLBACK( sxftd_update_excal_adapt ), sxfti ); } { GtkWidget *endDateBox = GTK_WIDGET(gtk_builder_get_object(sxfti->builder, "end_date_hbox" )); sxfti->endDateGDE = GNC_DATE_EDIT( gnc_date_edit_new (gnc_time (NULL), FALSE, FALSE)); gtk_box_pack_start( GTK_BOX( endDateBox ), GTK_WIDGET( sxfti->endDateGDE ), TRUE, TRUE, 0 ); g_signal_connect( sxfti->endDateGDE, "date-changed", G_CALLBACK( sxftd_update_excal_adapt ), sxfti ); } /* Setup the initial start date for user display/confirmation */ /* compute good initial date. */ start_tt = xaccTransGetDate( sxfti->trans ); gnc_gdate_set_time64( &date, start_tt ); sxfti->freq_combo = GTK_COMBO_BOX(gtk_builder_get_object(sxfti->builder, "freq_combo_box")); gtk_combo_box_set_active(GTK_COMBO_BOX(sxfti->freq_combo), 0); g_signal_connect( sxfti->freq_combo, "changed", G_CALLBACK(sxftd_freq_combo_changed), sxfti ); sxftd_update_schedule( sxfti, &date, &schedule); recurrenceListNextInstance(schedule, &date, &nextDate); recurrenceListFree(&schedule); start_tt = gnc_time64_get_day_start_gdate (&nextDate); gnc_date_edit_set_time( sxfti->startDateGDE, start_tt ); g_signal_connect( G_OBJECT(sxfti->name), "destroy", G_CALLBACK(sxftd_destroy), sxfti ); sxftd_update_example_cal( sxfti ); return 0; }
/******************************************************* * Create the Assistant *******************************************************/ static GtkWidget * csv_export_assistant_create (CsvExportInfo *info) { GtkBuilder *builder; GtkWidget *window; GtkWidget *box, *h_box; GtkWidget *button; GtkWidget *table, *hbox; time64 start_time, end_time; builder = gtk_builder_new(); gnc_builder_add_from_file (builder , "assistant-csv-export.glade", "CSV Export Assistant"); window = GTK_WIDGET(gtk_builder_get_object (builder, "CSV Export Assistant")); info->window = window; /* Set the assistant colors */ gnc_assistant_set_colors (GTK_ASSISTANT (info->window)); /* Load default settings */ load_settings (info); /* Start Page */ info->start_page = GTK_WIDGET(gtk_builder_get_object(builder, "start_page")); info->start_label = GTK_WIDGET(gtk_builder_get_object(builder, "start_label")); info->custom_entry = GTK_WIDGET(gtk_builder_get_object(builder, "custom_entry")); gtk_widget_set_sensitive (info->custom_entry, FALSE); /* Account Page */ info->account_page = GTK_WIDGET(gtk_builder_get_object(builder, "account_page")); if (info->export_type == XML_EXPORT_TREE) gtk_widget_destroy (info->account_page); else { GtkTreeView *tree_view; GtkTreeSelection *selection; GtkWidget *box, *label; info->csva.acct_info = GTK_WIDGET(gtk_builder_get_object (builder, "acct_info_vbox")); info->csva.num_acct_label = GTK_WIDGET(gtk_builder_get_object (builder, "num_accounts_label")); tree_view = gnc_tree_view_account_new (FALSE); info->csva.account_treeview = GTK_WIDGET(tree_view); selection = gtk_tree_view_get_selection (tree_view); gtk_tree_selection_set_mode (selection, GTK_SELECTION_EXTENDED); g_signal_connect (G_OBJECT(selection), "changed", G_CALLBACK(csv_export_account_changed_cb), info); gtk_widget_show (info->csva.account_treeview); box = GTK_WIDGET(gtk_builder_get_object (builder, "account_scroll")); gtk_container_add (GTK_CONTAINER(box), info->csva.account_treeview); label = GTK_WIDGET(gtk_builder_get_object (builder, "accounts_label")); gtk_label_set_mnemonic_widget (GTK_LABEL(label), GTK_WIDGET(tree_view)); /* select subaccounts button */ button = GTK_WIDGET(gtk_builder_get_object (builder, "select_subaccounts_button")); info->csva.select_button = button; g_signal_connect (G_OBJECT(button), "clicked", G_CALLBACK(csv_export_select_subaccounts_clicked_cb), info); g_signal_connect (G_OBJECT(info->csva.account_treeview), "cursor_changed", G_CALLBACK(csv_export_cursor_changed_cb), info); /* Set the date info */ button = GTK_WIDGET(gtk_builder_get_object (builder, "show_range")); /* Earliest and Latest in Book */ start_time = get_earliest_in_book (gnc_get_current_book()); end_time = gnc_time (NULL); info->csvd.start_time = start_time; info->csvd.end_time = end_time; gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(button), FALSE); table = GTK_WIDGET(gtk_builder_get_object (builder, "select_range_table")); info->csvd.table = table; gtk_widget_set_sensitive (GTK_WIDGET(table), FALSE); info->csvd.start_date_choose = GTK_WIDGET(gtk_builder_get_object (builder, "start_date_choose")); info->csvd.start_date_today = GTK_WIDGET(gtk_builder_get_object (builder, "start_date_today")); info->csvd.end_date_choose = GTK_WIDGET(gtk_builder_get_object (builder, "end_date_choose")); info->csvd.end_date_today = GTK_WIDGET(gtk_builder_get_object (builder, "end_date_today")); /* Start date info */ info->csvd.start_date = gnc_date_edit_new (gnc_time (NULL), FALSE, FALSE); hbox = GTK_WIDGET(gtk_builder_get_object (builder, "start_date_hbox")); gtk_box_pack_start (GTK_BOX(hbox), info->csvd.start_date, TRUE, TRUE, 0); gtk_widget_show (info->csvd.start_date); gnc_date_edit_set_time (GNC_DATE_EDIT(info->csvd.start_date), start_time); g_signal_connect (G_OBJECT(info->csvd.start_date), "date-changed", G_CALLBACK(csv_export_date_changed_cb), info); /* End date info */ info->csvd.end_date = gnc_date_edit_new (gnc_time (NULL), FALSE, FALSE); hbox = GTK_WIDGET(gtk_builder_get_object (builder, "end_date_hbox")); gtk_box_pack_start (GTK_BOX(hbox), info->csvd.end_date, TRUE, TRUE, 0); gtk_widget_show (info->csvd.end_date); gnc_date_edit_set_time (GNC_DATE_EDIT(info->csvd.end_date), end_time); g_signal_connect (G_OBJECT (info->csvd.end_date), "date-changed", G_CALLBACK (csv_export_date_changed_cb), info); /* Load Accounts */ show_acct_type_accounts (info); update_accounts_tree (info); } /* File chooser Page */ info->file_page = GTK_WIDGET(gtk_builder_get_object(builder, "file_page")); info->file_chooser = gtk_file_chooser_widget_new (GTK_FILE_CHOOSER_ACTION_SAVE); 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_export_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); /* 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_page")); g_signal_connect (G_OBJECT(window), "destroy", G_CALLBACK(csv_export_assistant_destroy_cb), info); gnc_restore_window_size (GNC_PREFS_GROUP, GTK_WINDOW(info->window)); if (gnc_prefs_get_bool (GNC_PREFS_GROUP_GENERAL, GNC_PREF_SAVE_GEOMETRY)) { GObject *object = gtk_builder_get_object (builder, "paned"); gnc_prefs_bind (GNC_PREFS_GROUP, GNC_PREF_PANED_POS, object, "position"); } gtk_builder_connect_signals (builder, info); g_object_unref (G_OBJECT(builder)); return window; }
static gint sxftd_init( SXFromTransInfo *sxfti ) { GtkWidget *w; const char *transName; gint pos; GList *schedule = NULL; time_t start_tt; struct tm *tmpTm; GDate date, nextDate; if ( ! sxfti->sx ) { return -1; } if ( ! sxfti->trans ) { return -2; } if ( xaccTransIsOpen( sxfti->trans ) ) { return SXFTD_ERRNO_OPEN_XACTION; } sxfti_attach_callbacks(sxfti); /* Setup the example calendar and related data structures. */ { int num_marks = SXFTD_EXCAL_NUM_MONTHS * 31; w = GTK_WIDGET(glade_xml_get_widget( sxfti->gxml, SXFTD_EX_CAL_FRAME )); sxfti->dense_cal_model = gnc_dense_cal_store_new(num_marks); sxfti->example_cal = GNC_DENSE_CAL(gnc_dense_cal_new_with_model(GNC_DENSE_CAL_MODEL(sxfti->dense_cal_model))); g_object_ref_sink(sxfti->example_cal); g_assert(sxfti->example_cal); gnc_dense_cal_set_num_months( sxfti->example_cal, SXFTD_EXCAL_NUM_MONTHS ); gnc_dense_cal_set_months_per_col( sxfti->example_cal, SXFTD_EXCAL_MONTHS_PER_COL ); gtk_container_add( GTK_CONTAINER(w), GTK_WIDGET(sxfti->example_cal) ); } /* Setup the start and end dates as GNCDateEdits */ { GtkWidget *paramTable = glade_xml_get_widget( sxfti->gxml, SXFTD_PARAM_TABLE ); sxfti->startDateGDE = GNC_DATE_EDIT( gnc_date_edit_new( time( NULL ), FALSE, FALSE ) ); gtk_table_attach( GTK_TABLE(paramTable), GTK_WIDGET( sxfti->startDateGDE ), 1, 2, 2, 3, (GTK_EXPAND | GTK_FILL), GTK_FILL, 0, 0 ); g_signal_connect( sxfti->startDateGDE, "date-changed", G_CALLBACK( sxftd_update_excal_adapt ), sxfti ); } { GtkWidget *endDateBox = glade_xml_get_widget( sxfti->gxml, SXFTD_END_DATE_BOX ); sxfti->endDateGDE = GNC_DATE_EDIT( gnc_date_edit_new( time( NULL ), FALSE, FALSE ) ); gtk_box_pack_start( GTK_BOX( endDateBox ), GTK_WIDGET( sxfti->endDateGDE ), FALSE, TRUE, 0 ); g_signal_connect( sxfti->endDateGDE, "date-changed", G_CALLBACK( sxftd_update_excal_adapt ), sxfti ); } /* Get the name from the transaction, try that as the initial SX name. */ transName = xaccTransGetDescription( sxfti->trans ); xaccSchedXactionSetName( sxfti->sx, transName ); /* Setup the initial start date for user display/confirmation */ /* compute good initial date. */ start_tt = xaccTransGetDate( sxfti->trans ); g_date_set_time_t( &date, start_tt ); w = glade_xml_get_widget(sxfti->gxml, SXFTD_FREQ_COMBO_BOX); gtk_combo_box_set_active(GTK_COMBO_BOX(w), 0); g_signal_connect( w, "changed", G_CALLBACK(sxftd_freq_combo_changed), sxfti ); sxftd_update_schedule( sxfti, &date, &schedule); recurrenceListNextInstance(schedule, &date, &nextDate); recurrenceListFree(&schedule); tmpTm = g_new0( struct tm, 1 ); g_date_to_struct_tm( &nextDate, tmpTm ); start_tt = mktime( tmpTm ); g_free( tmpTm ); gnc_date_edit_set_time( sxfti->startDateGDE, start_tt ); w = glade_xml_get_widget( sxfti->gxml, SXFTD_NAME_ENTRY ); pos = 0; gtk_editable_insert_text( GTK_EDITABLE(w), transName, (strlen(transName) * sizeof(char)), &pos ); g_signal_connect( GTK_OBJECT(w), "destroy", G_CALLBACK(sxftd_destroy), sxfti ); sxftd_update_example_cal( sxfti ); return 0; }
void gnc_date_edit_set_time_ts (GNCDateEdit *gde, Timespec the_time) { gnc_date_edit_set_time (gde, the_time.tv_sec); }