static void gnc_parse_date (struct tm *parsed, const char * datestr) { int day, month, year; gboolean use_autoreadonly = qof_book_uses_autoreadonly(gnc_get_current_book()); if (!parsed) return; if (!datestr) return; if (!qof_scan_date (datestr, &day, &month, &year)) { // Couldn't parse date, use today struct tm tm_today; memset (&tm_today, 0, sizeof (struct tm)); gnc_tm_get_today_start (&tm_today); day = tm_today.tm_mday; month = tm_today.tm_mon + 1; year = tm_today.tm_year + 1900; } // If we have an auto-read-only threshold, do not accept a date that is // older than the threshold. if (use_autoreadonly) { GDate *d = g_date_new_dmy(day, month, year); if (check_readonly_threshold (datestr, d)) { day = g_date_get_day (d); month = g_date_get_month (d); year = g_date_get_year (d); } g_date_free (d); } parsed->tm_mday = day; parsed->tm_mon = month - 1; parsed->tm_year = year - 1900; gnc_tm_set_day_start(parsed); /* Using gnc_mktime purely for its side effect of filling in the * rest of parsed and to check that it's valid. */ if (gnc_mktime (parsed) == -1) gnc_tm_get_today_start (parsed); gnc_mktime (parsed); }
void gnc_tree_util_split_reg_parse_date (GDate *parsed, const char *datestr) { int day, month, year; gboolean use_autoreadonly = qof_book_uses_autoreadonly (gnc_get_current_book ()); if (!parsed) return; if (!datestr) return; if (!qof_scan_date (datestr, &day, &month, &year)) { // Couldn't parse date, use today struct tm tm_today; gnc_tm_get_today_start (&tm_today); day = tm_today.tm_mday; month = tm_today.tm_mon + 1; year = tm_today.tm_year + 1900; } // If we have an auto-read-only threshold, do not accept a date that is // older than the threshold. if (use_autoreadonly) { GDate *d = g_date_new_dmy (day, month, year); GDate *readonly_threshold = qof_book_get_autoreadonly_gdate (gnc_get_current_book()); if (g_date_compare (d, readonly_threshold) < 0) { g_warning("Entered date %s is before the \"auto-read-only threshold\"; resetting to the threshold.", datestr); #if 0 GtkWidget *dialog = gtk_message_dialog_new (NULL, 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "%s", _("Cannot store a transaction at this date")); gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s", _("The entered date of the new transaction is older than the \"Read-Only Threshold\" set for this book. " "This setting can be changed in File -> Properties -> Accounts.")); gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); #endif // Reset the date to the threshold date day = g_date_get_day (readonly_threshold); month = g_date_get_month (readonly_threshold); year = g_date_get_year (readonly_threshold); } g_date_free (d); g_date_free (readonly_threshold); } g_date_set_dmy (parsed, day, month, year); }
/* Opens up a general journal window. */ GNCLedgerDisplay * gnc_ledger_display_gl (void) { Query *query; time64 start; struct tm tm; GNCLedgerDisplay *ld; ENTER(" "); query = qof_query_create_for(GNC_ID_SPLIT); qof_query_set_book (query, gnc_get_current_book()); /* In lieu of not "mis-using" some portion of the infrastructure by writing * a bunch of new code, we just filter out the accounts of the template * transactions. While these are in a seperate Account trees just for this * reason, the query engine makes no distinction between Account trees. * See Gnome Bug 86302. * -- jsled */ { Account *tRoot; GList *al; tRoot = gnc_book_get_template_root( gnc_get_current_book() ); al = gnc_account_get_descendants( tRoot ); if (g_list_length(al) != 0) xaccQueryAddAccountMatch( query, al, QOF_GUID_MATCH_NONE, QOF_QUERY_AND ); g_list_free (al); al = NULL; tRoot = NULL; } gnc_tm_get_today_start(&tm); tm.tm_mon--; /* Default the register to the last month's worth of transactions. */ start = gnc_mktime (&tm); xaccQueryAddDateMatchTT (query, TRUE, start, FALSE, 0, QOF_QUERY_AND); ld = gnc_ledger_display_internal (NULL, query, LD_GL, GENERAL_JOURNAL, REG_STYLE_JOURNAL, FALSE, FALSE); LEAVE("%p", ld); return ld; }
static void gnc_date_edit_popup (GNCDateEdit *gde) { GtkWidget *toplevel; struct tm mtm; gboolean date_was_valid; GdkDevice *device, *keyboard, *pointer; g_return_if_fail (GNC_IS_DATE_EDIT (gde)); ENTER("gde %p", gde); device = gtk_get_current_event_device (); /* This code is pretty much just copied from gtk_date_edit_get_date */ date_was_valid = qof_scan_date (gtk_entry_get_text (GTK_ENTRY (gde->date_entry)), &mtm.tm_mday, &mtm.tm_mon, &mtm.tm_year); if (!date_was_valid) { /* No valid date. Hacky workaround: Instead of crashing we randomly choose today's date. */ gnc_tm_get_today_start(&mtm); } mtm.tm_mon--; /* Hope the user does not actually mean years early in the A.D. days... * This date widget will obviously not work for a history program :-) */ if (mtm.tm_year >= 1900) mtm.tm_year -= 1900; gnc_tm_set_day_start(&mtm); /* Set the calendar. */ gtk_calendar_select_day (GTK_CALENDAR (gde->calendar), 1); gtk_calendar_select_month (GTK_CALENDAR (gde->calendar), mtm.tm_mon, 1900 + mtm.tm_year); gtk_calendar_select_day (GTK_CALENDAR (gde->calendar), mtm.tm_mday); /* Make sure we'll get notified of clicks outside the popup * window so we can properly pop down if that happens. */ toplevel = gtk_widget_get_toplevel (GTK_WIDGET (gde)); if (GTK_IS_WINDOW (toplevel)) { gtk_window_group_add_window ( gtk_window_get_group (GTK_WINDOW (toplevel)), GTK_WINDOW (gde->cal_popup)); gtk_window_set_transient_for (GTK_WINDOW (gde->cal_popup), GTK_WINDOW (toplevel)); } position_popup (gde); gtk_widget_show (gde->cal_popup); gtk_widget_grab_focus (gde->cal_popup); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (gde->date_button), TRUE); if (gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD) { keyboard = device; pointer = gdk_device_get_associated_device (device); } else { pointer = device; keyboard = gdk_device_get_associated_device (device); } if (!gtk_widget_has_focus (gde->calendar)) gtk_widget_grab_focus (gde->calendar); if (!popup_grab_on_window (gtk_widget_get_window ((GTK_WIDGET(gde->cal_popup))), keyboard, pointer, GDK_CURRENT_TIME)) { gtk_widget_hide (gde->cal_popup); LEAVE("Failed to grab window"); return; } gtk_grab_add (gde->cal_popup); LEAVE(" "); }
static struct tm gnc_date_edit_get_date_internal (GNCDateEdit *gde) { struct tm tm = {0}; char *str; gchar *flags = NULL; gboolean date_was_valid; /* Assert, because we're just hosed if it's NULL */ g_assert(gde != NULL); g_assert(GNC_IS_DATE_EDIT(gde)); date_was_valid = qof_scan_date (gtk_entry_get_text (GTK_ENTRY (gde->date_entry)), &tm.tm_mday, &tm.tm_mon, &tm.tm_year); if (!date_was_valid) { /* Hm... no valid date. What should we do not? As a hacky workaround we revert to today's date. Alternatively we can return some value that signals that we don't get a valid date, but all callers of this function will have to check this. Alas, I'm too lazy to do this here. */ gnc_tm_get_today_start(&tm); } tm.tm_mon--; tm.tm_year -= 1900; if (gde->flags & GNC_DATE_EDIT_SHOW_TIME) { char *tokp = NULL; gchar *temp; str = g_strdup (gtk_entry_get_text (GTK_ENTRY (gde->time_entry))); temp = gnc_strtok_r (str, ": ", &tokp); if (temp) { tm.tm_hour = atoi (temp); temp = gnc_strtok_r (NULL, ": ", &tokp); if (temp) { if (isdigit (*temp)) { tm.tm_min = atoi (temp); flags = gnc_strtok_r (NULL, ": ", &tokp); if (flags && isdigit (*flags)) { tm.tm_sec = atoi (flags); flags = gnc_strtok_r (NULL, ": ", &tokp); } } else flags = temp; } } if (flags && (strcasecmp (flags, "PM") == 0)) { if (tm.tm_hour < 12) tm.tm_hour += 12; } g_free (str); } else { gnc_tm_set_day_start(&tm); } tm.tm_isdst = -1; return tm; }