static void test_specific(PeriodType pt, guint16 mult, GDateMonth sm, GDateDay sd, GDateYear sy, GDateMonth rm, GDateDay rd, GDateYear ry, GDateMonth nm, GDateDay nd, GDateYear ny) { GDate start; GDate ref, next, true_next; Recurrence r; g_date_set_dmy(&start, sd, sm, sy); g_date_set_dmy(&ref, rd, rm, ry); g_date_set_dmy(&true_next, nd, nm, ny); recurrenceSet(&r, mult, pt, &start, WEEKEND_ADJ_NONE); recurrenceNextInstance(&r, &ref, &next); check_valid(&next, &ref, &start, mult, pt, WEEKEND_ADJ_NONE); if (!test_equal(&next, &true_next)) { gchar s1[21], s2[21], s3[21]; g_date_strftime(s1, 20, "%x", &start); g_date_strftime(s2, 20, "%x", &ref); g_date_strftime(s3, 20, "%x", &true_next); printf("pt = %d; mult = %d; start = %s; ref = %s; true_next = %s\n", pt, mult, s1, s2, s3); } }
static void test_nth(GDateMonth sm, GDateDay sd, GDateYear sy, GDateMonth nm, GDateDay nd, GDateYear ny, gint diff, PeriodType pt) { GDate start, next; gint d; g_date_set_dmy(&start, sd, sm, sy); g_date_set_dmy(&next, nd, nm, ny); d = nth_weekday_compare(&start, &next, pt); do_test(d == diff, "nth"); }
guint g_date_sunday_week_of_year (GDate *d) { GDateWeekday wd; guint day; GDate first; g_return_val_if_fail (d != NULL, 0); g_return_val_if_fail (g_date_valid (d), 0); if (!d->dmy) { g_date_update_dmy (d); } g_return_val_if_fail (d->dmy, 0); g_date_clear (&first, 1); g_date_set_dmy (&first, 1, 1, d->year); wd = g_date_weekday (&first); if (wd == 7) wd = 0; /* make Sunday day 0 */ day = g_date_day_of_year (d) - 1; return ((day + wd)/7U + (wd == 0 ? 1 : 0)); }
static guint32 year_to_julian (guint32 year) { GDate v = {0,}; g_date_set_dmy (&v, 1, G_DATE_JANUARY, year); return g_date_get_julian (&v); }
void gnc_gdate_set_time64 (GDate* gd, time64 time) { struct tm tm; gnc_localtime_r(&time, &tm); g_date_set_dmy (gd, tm.tm_mday, static_cast<GDateMonth>(tm.tm_mon + 1), tm.tm_year + 1900); }
/* ** store the calendar date to GDate, update our gtkentry */ static void gtk_dateentry_calendar_getfrom(GtkWidget * calendar, GtkDateEntry * dateentry) { guint year, month, day; DB( g_print(" (dateentry) get from calendar\n") ); gtk_calendar_get_date (GTK_CALENDAR (dateentry->calendar), &year, &month, &day); g_date_set_dmy (dateentry->date, day, month + 1, year); gtk_dateentry_datetoentry(dateentry); }
guint8 g_date_get_sunday_weeks_in_year (GDateYear year) { GDate d; g_return_val_if_fail (g_date_valid_year (year), 0); g_date_clear (&d, 1); g_date_set_dmy (&d, 1, 1, year); if (g_date_get_weekday (&d) == G_DATE_SUNDAY) return 53; g_date_set_dmy (&d, 31, 12, year); if (g_date_get_weekday (&d) == G_DATE_SUNDAY) return 53; if (g_date_is_leap_year (year)) { g_date_set_dmy (&d, 2, 1, year); if (g_date_get_weekday (&d) == G_DATE_SUNDAY) return 53; g_date_set_dmy (&d, 30, 12, year); if (g_date_get_weekday (&d) == G_DATE_SUNDAY) return 53; } return 52; }
/* The GDate setter functions all in the end use g_date_set_time_t, * which in turn relies on localtime and is therefore subject to the * 2038 bug. */ GDate timespec_to_gdate (Timespec ts) { GDate result; gint day, month, year; g_date_clear (&result, 1); gnc_timespec2dmy (ts, &day, &month, &year); g_date_set_dmy (&result, day, static_cast<GDateMonth>(month), year); g_assert(g_date_valid (&result)); return result; }
/** * time_to_gdate_with_zone: * @date: Destination #GDate value. * @time: A time value. * @zone: Desired timezone for destination @date, or NULL if the UTC timezone * is desired. * * Converts a time_t value to a #GDate structure using the specified timezone. * This is analogous to g_date_set_time() but takes the timezone into account. **/ void time_to_gdate_with_zone (GDate *date, time_t time, icaltimezone *zone) { struct icaltimetype tt; g_return_if_fail (date != NULL); g_return_if_fail (time != -1); tt = icaltime_from_timet_with_zone (time, FALSE, zone ? zone : icaltimezone_get_utc_timezone ()); g_date_set_dmy (date, tt.day, tt.month, tt.year); }
/* The GDate setter functions all in the end use g_date_set_time_t, * which in turn relies on localtime and is therefore subject to the * 2038 bug. */ GDate timespec_to_gdate (Timespec ts) { GDate result; g_date_clear (&result, 1); GncDateTime time(ts.tv_sec); auto date = time.date().year_month_day(); g_date_set_dmy (&result, date.day, static_cast<GDateMonth>(date.month), date.year); g_assert(g_date_valid (&result)); return result; }
SXTmpStateData* gnc_sx_create_temporal_state(const SchedXaction *sx ) { SXTmpStateData *toRet = g_new0( SXTmpStateData, 1 ); if (g_date_valid (&(sx->last_date))) toRet->last_date = sx->last_date; else g_date_set_dmy (&(toRet->last_date), 1, 1, 1970); toRet->num_occur_rem = sx->num_occurances_remain; toRet->num_inst = sx->instance_num; return toRet; }
void mrp_time2_set_date (MrpTime *t, gint year, gint month, gint day) { g_return_if_fail (t != NULL); g_return_if_fail (year >= 1 && year <= 9999); g_return_if_fail (month >= 1 && month <= 12); g_return_if_fail (day >= 1 && day <= 31); g_date_set_dmy (&t->date, day, month, year); }
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); }
time_t mrp_time2_get_epoch (MrpTime *t) { GDate date; time_t epoch; g_date_set_dmy (&date, 1, 1, 1970); epoch = SECS_IN_DAY * g_date_days_between (&date, &t->date); epoch += t->hour * SECS_IN_HOUR + t->min * SECS_IN_MIN + t->sec; return epoch; }
void gth_datetime_from_struct_tm (GthDateTime *dt, struct tm *tm) { if (tm->tm_hour < 0) gth_time_clear (dt->time); else gth_time_set_hms (dt->time, tm->tm_hour, tm->tm_min, tm->tm_sec, 0); if ((tm->tm_year < 0) || (tm->tm_mday < 1) || (tm->tm_mday > 31) || (tm->tm_mon < 0) || (tm->tm_mon > 11)) g_date_clear (dt->date, 1); else g_date_set_dmy (dt->date, tm->tm_mday, tm->tm_mon + 1, 1900 + tm->tm_year); }
void gnc_date_cell_get_date_gdate (DateCell *cell, GDate *date) { PopBox *box = cell->cell.gui_private; if (!cell || !date) return; gnc_parse_date (&(box->date), cell->cell.value); g_date_set_dmy(date, box->date.tm_mday, box->date.tm_mon + 1, box->date.tm_year + 1900); }
static void g_date_determine_dmy(void) { GDate d; gchar buf[128]; GDateParseTokens testpt; gint i; DB( g_print(" (dateentry) determine dmy\n") ); g_date_clear (&d, 1); /* clear for scratch use */ /* had to pick a random day - don't change this, some strftimes * are broken on some days, and this one is good so far. */ g_date_set_dmy (&d, 4, 7, 1976); g_date_strftime (buf, 127, "%x", &d); g_date_fill_parse_tokens (buf, &testpt); i = 0; while (i < testpt.num_ints) { switch (testpt.n[i]) { case 7: dmy_order[i] = G_DATE_MONTH; break; case 4: dmy_order[i] = G_DATE_DAY; break; //case 76: //using_twodigit_years = TRUE; /* FALL THRU */ case 1976: dmy_order[2] = G_DATE_YEAR; break; } ++i; } DB( g_print(" dmy legend: 0=day, 1=month, 2=year\n") ); DB( g_print(" dmy is: %d %d %d\n", dmy_order[0], dmy_order[1], dmy_order[2]) ); }
/** * Prints the version notice. This is shown when Metacity is called * with the --version switch. */ static void version (void) { const int latest_year = 2009; char yearbuffer[256]; GDate date; /* this is all so the string to translate stays constant. * see how much we love the translators. */ g_date_set_dmy (&date, 1, G_DATE_JANUARY, latest_year); if (g_date_strftime (yearbuffer, sizeof (yearbuffer), "%Y", &date)==0) /* didn't work? fall back to decimal representation */ g_sprintf (yearbuffer, "%d", latest_year); g_print (_("metacity %s\n" "Copyright (C) 2001-%s Havoc Pennington, Red Hat, Inc., and others\n" "This is free software; see the source for copying conditions.\n" "There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"), VERSION, yearbuffer); exit (0); }
guint g_date_get_monday_week_of_year (const GDate *d) { GDateWeekday wd; guint day; GDate first; g_return_val_if_fail (g_date_valid (d), 0); if (!d->dmy) g_date_update_dmy (d); g_return_val_if_fail (d->dmy, 0); g_date_clear (&first, 1); g_date_set_dmy (&first, 1, 1, d->year); wd = g_date_get_weekday (&first) - 1; /* make Monday day 0 */ day = g_date_get_day_of_year (d) - 1; return ((day + wd)/7U + (wd == 0 ? 1 : 0)); }
static gboolean update_year_cb (GtkWidget *widget, GdkEventFocus *event, RBAudioCdSource *source) { const char *text; int year; GDate date; GValue v = {0, }; text = gtk_entry_get_text (GTK_ENTRY (widget)); if (text[0] == '\0') { return FALSE; } year = strtol (text, NULL, 10); g_date_clear (&date, 1); g_date_set_dmy (&date, 1, 1, year); g_value_init (&v, G_TYPE_ULONG); g_value_set_ulong (&v, g_date_get_julian (&date)); update_tracks (source, RHYTHMDB_PROP_DATE, &v); g_value_unset (&v); return FALSE; }
/** * gck_attribute_get_date: * @attr: The attribute to retrieve value from. * @value: The date value to fill in with the parsed date. * * Get the CK_DATE of a PKCS#11 attribute. No * conversion is performed. It is an error to pass an attribute * to this function unless you're know it's supposed to contain * a value of the right type. */ void gck_attribute_get_date (GckAttribute *attr, GDate *value) { guint year, month, day; gchar buffer[5]; CK_DATE *date; gchar *end; g_return_if_fail (attr); if (gck_attribute_is_invalid (attr)) { g_date_clear (value, 1); return; } g_return_if_fail (attr->length == sizeof (CK_DATE)); g_return_if_fail (attr->value); date = (CK_DATE*)attr->value; memset (&buffer, 0, sizeof (buffer)); memcpy (buffer, date->year, 4); year = strtol (buffer, &end, 10); g_return_if_fail (end != buffer && !*end); memset (&buffer, 0, sizeof (buffer)); memcpy (buffer, date->month, 2); month = strtol (buffer, &end, 10); g_return_if_fail (end != buffer && !*end); memset (&buffer, 0, sizeof (buffer)); memcpy (buffer, date->day, 2); day = strtol (buffer, &end, 10); g_return_if_fail (end != buffer && !*end); g_date_set_dmy (value, day, month, year); }
/* utility functions shared between all contact importers */ static void preview_contact (EWebViewPreview *preview, EContact *contact) { gint idx; gboolean had_value = FALSE; const gint fields[] = { E_CONTACT_FILE_AS, E_CONTACT_CATEGORIES, E_CONTACT_IS_LIST, E_CONTACT_LIST_SHOW_ADDRESSES, E_CONTACT_WANTS_HTML, E_CONTACT_FULL_NAME, E_CONTACT_GIVEN_NAME, E_CONTACT_FAMILY_NAME, E_CONTACT_NICKNAME, E_CONTACT_SPOUSE, E_CONTACT_BIRTH_DATE, E_CONTACT_ANNIVERSARY, E_CONTACT_MAILER, E_CONTACT_EMAIL, -1, E_CONTACT_ORG, E_CONTACT_ORG_UNIT, E_CONTACT_OFFICE, E_CONTACT_TITLE, E_CONTACT_ROLE, E_CONTACT_MANAGER, E_CONTACT_ASSISTANT, -1, E_CONTACT_PHONE_ASSISTANT, E_CONTACT_PHONE_BUSINESS, E_CONTACT_PHONE_BUSINESS_2, E_CONTACT_PHONE_BUSINESS_FAX, E_CONTACT_PHONE_CALLBACK, E_CONTACT_PHONE_CAR, E_CONTACT_PHONE_COMPANY, E_CONTACT_PHONE_HOME, E_CONTACT_PHONE_HOME_2, E_CONTACT_PHONE_HOME_FAX, E_CONTACT_PHONE_ISDN, E_CONTACT_PHONE_MOBILE, E_CONTACT_PHONE_OTHER, E_CONTACT_PHONE_OTHER_FAX, E_CONTACT_PHONE_PAGER, E_CONTACT_PHONE_PRIMARY, E_CONTACT_PHONE_RADIO, E_CONTACT_PHONE_TELEX, E_CONTACT_PHONE_TTYTDD, -1, E_CONTACT_ADDRESS_HOME, E_CONTACT_ADDRESS_WORK, E_CONTACT_ADDRESS_OTHER, -1, E_CONTACT_HOMEPAGE_URL, E_CONTACT_BLOG_URL, E_CONTACT_CALENDAR_URI, E_CONTACT_FREEBUSY_URL, E_CONTACT_ICS_CALENDAR, E_CONTACT_VIDEO_URL, -1, E_CONTACT_IM_AIM, E_CONTACT_IM_GROUPWISE, E_CONTACT_IM_JABBER, E_CONTACT_IM_YAHOO, E_CONTACT_IM_MSN, E_CONTACT_IM_ICQ, E_CONTACT_IM_GADUGADU, E_CONTACT_IM_SKYPE, -1, E_CONTACT_NOTE }; g_return_if_fail (preview != NULL); g_return_if_fail (contact != NULL); for (idx = 0; idx < G_N_ELEMENTS (fields); idx++) { EContactField field; if (fields[idx] == -1) { if (had_value) e_web_view_preview_add_empty_line (preview); had_value = FALSE; continue; } field = fields[idx]; if (field == E_CONTACT_BIRTH_DATE || field == E_CONTACT_ANNIVERSARY) { EContactDate *dt = e_contact_get (contact, field); if (dt) { GDate gd = { 0 }; struct tm tm; gchar *value; g_date_set_dmy (&gd, dt->day, dt->month, dt->year); g_date_to_struct_tm (&gd, &tm); value = e_datetime_format_format_tm ( "addressbook", "table", DTFormatKindDate, &tm); if (value) { e_web_view_preview_add_section ( preview, e_contact_pretty_name (field), value); had_value = TRUE; } g_free (value); e_contact_date_free (dt); } } else if (field == E_CONTACT_IS_LIST || field == E_CONTACT_WANTS_HTML || field == E_CONTACT_LIST_SHOW_ADDRESSES) { if (e_contact_get (contact, field)) { e_web_view_preview_add_text ( preview, e_contact_pretty_name (field)); had_value = TRUE; } } else if (field == E_CONTACT_ADDRESS_HOME || field == E_CONTACT_ADDRESS_WORK || field == E_CONTACT_ADDRESS_OTHER) { EContactAddress *addr = e_contact_get (contact, field); if (addr) { gboolean have = FALSE; #define add_it(_what) \ if (addr->_what && *addr->_what) { \ e_web_view_preview_add_section ( \ preview, have ? NULL : \ e_contact_pretty_name (field), addr->_what); \ have = TRUE; \ had_value = TRUE; \ } add_it (po); add_it (ext); add_it (street); add_it (locality); add_it (region); add_it (code); add_it (country); #undef add_it e_contact_address_free (addr); } } else if (field == E_CONTACT_IM_AIM || field == E_CONTACT_IM_GROUPWISE || field == E_CONTACT_IM_JABBER || field == E_CONTACT_IM_YAHOO || field == E_CONTACT_IM_MSN || field == E_CONTACT_IM_ICQ || field == E_CONTACT_IM_GADUGADU || field == E_CONTACT_IM_SKYPE || field == E_CONTACT_EMAIL) { GList *attrs, *a; gboolean have = FALSE; const gchar *pretty_name; pretty_name = e_contact_pretty_name (field); attrs = e_contact_get_attributes (contact, field); for (a = attrs; a; a = a->next) { EVCardAttribute *attr = a->data; GList *value; if (!attr) continue; value = e_vcard_attribute_get_values (attr); while (value != NULL) { const gchar *str = value->data; if (str && *str) { e_web_view_preview_add_section ( preview, have ? NULL : pretty_name, str); have = TRUE; had_value = TRUE; } value = value->next; } e_vcard_attribute_free (attr); } g_list_free (attrs); } else if (field == E_CONTACT_CATEGORIES) { const gchar *pretty_name; const gchar *value; pretty_name = e_contact_pretty_name (field); value = e_contact_get_const (contact, field); if (value != NULL && *value != '\0') { e_web_view_preview_add_section ( preview, pretty_name, value); had_value = TRUE; } } else { const gchar *pretty_name; const gchar *value; pretty_name = e_contact_pretty_name (field); value = e_contact_get_const (contact, field); if (value != NULL && *value != '\0') { e_web_view_preview_add_section ( preview, pretty_name, value); had_value = TRUE; } } } }
gboolean gnc_handle_date_accelerator (GdkEventKey *event, struct tm *tm, const char *date_str) { GDate gdate; g_return_val_if_fail (event != NULL, FALSE); g_return_val_if_fail (tm != NULL, FALSE); g_return_val_if_fail (date_str != NULL, FALSE); if (event->type != GDK_KEY_PRESS) return FALSE; if ((tm->tm_mday <= 0) || (tm->tm_mon == -1) || (tm->tm_year == -1)) return FALSE; // Make sure we have a valid date before we proceed if (!g_date_valid_dmy (tm->tm_mday, tm->tm_mon + 1, tm->tm_year + 1900)) return FALSE; g_date_set_dmy (&gdate, tm->tm_mday, tm->tm_mon + 1, tm->tm_year + 1900); /* * Check those keys where the code does different things depending * upon the modifiers. */ switch (event->keyval) { case GDK_KEY_KP_Add: case GDK_KEY_plus: case GDK_KEY_equal: if (event->state & GDK_SHIFT_MASK) g_date_add_days (&gdate, 7); else if (event->state & GDK_MOD1_MASK) g_date_add_months (&gdate, 1); else if (event->state & GDK_CONTROL_MASK) g_date_add_years (&gdate, 1); else g_date_add_days (&gdate, 1); g_date_to_struct_tm (&gdate, tm); return TRUE; case GDK_KEY_minus: case GDK_KEY_KP_Subtract: case GDK_KEY_underscore: if ((strlen (date_str) != 0) && (dateSeparator () == '-')) { const char *c; gunichar uc; int count = 0; /* rough check for existing date */ c = date_str; while (*c) { uc = g_utf8_get_char (c); if (uc == '-') count++; c = g_utf8_next_char (c); } if (count < 2) return FALSE; } if (event->state & GDK_SHIFT_MASK) g_date_subtract_days (&gdate, 7); else if (event->state & GDK_MOD1_MASK) g_date_subtract_months (&gdate, 1); else if (event->state & GDK_CONTROL_MASK) g_date_subtract_years (&gdate, 1); else g_date_subtract_days (&gdate, 1); g_date_to_struct_tm (&gdate, tm); return TRUE; default: break; } /* * Control and Alt key combinations should be ignored by this * routine so that the menu system gets to handle them. This * prevents weird behavior of the menu accelerators (i.e. work in * some widgets but not others.) */ if (event->state & (GDK_CONTROL_MASK | GDK_MOD1_MASK)) return FALSE; /* Now check for the remaining keystrokes. */ switch (event->keyval) { case GDK_KEY_braceright: case GDK_KEY_bracketright: /* increment month */ g_date_add_months (&gdate, 1); break; case GDK_KEY_braceleft: case GDK_KEY_bracketleft: /* decrement month */ g_date_subtract_months (&gdate, 1); break; case GDK_KEY_M: case GDK_KEY_m: /* beginning of month */ g_date_set_day (&gdate, 1); break; case GDK_KEY_H: case GDK_KEY_h: /* end of month */ g_date_set_day (&gdate, 1); g_date_add_months (&gdate, 1); g_date_subtract_days (&gdate, 1); break; case GDK_KEY_Y: case GDK_KEY_y: /* beginning of year */ g_date_set_day (&gdate, 1); g_date_set_month (&gdate, 1); break; case GDK_KEY_R: case GDK_KEY_r: /* end of year */ g_date_set_day (&gdate, 1); g_date_set_month (&gdate, 1); g_date_add_years (&gdate, 1); g_date_subtract_days (&gdate, 1); break; case GDK_KEY_T: case GDK_KEY_t: /* today */ gnc_gdate_set_today (&gdate); break; default: return FALSE; } g_date_to_struct_tm (&gdate, tm); return TRUE; }
void test_qofsession_aqb_kvp( void ) { /* load the accounts from the users datafile */ /* but first, check to make sure we've got a session going. */ QofBackendError io_err; char *file1 = get_filepath("file-book.gnucash"); char *file2 = get_filepath("file-book-hbcislot.gnucash"); if (1) { // A file with no content at all, but a valid XML file QofSession *new_session = qof_session_new (); char *newfile = g_strdup_printf("file://%s", file1); qof_session_begin (new_session, newfile, TRUE, FALSE, FALSE); io_err = qof_session_get_error (new_session); //printf("io_err1 = %d\n", io_err); g_assert(io_err != ERR_BACKEND_NO_HANDLER); // Do not have no handler g_assert(io_err != ERR_BACKEND_NO_SUCH_DB); // DB must exist g_assert(io_err != ERR_BACKEND_LOCKED); g_assert(io_err == 0); qof_session_load (new_session, NULL); io_err = qof_session_get_error (new_session); //printf("io_err2 = %d\n", io_err); g_assert(io_err == 0); g_free(newfile); g_free(file1); gnc_hook_run(HOOK_BOOK_CLOSED, new_session); //qof_session_destroy(new_session); // tries to delete the LCK file but it wasn't created in the first place } if (1) { // A file with no content except for the book_template_list kvp // slot QofSession *new_session = qof_session_new (); char *newfile = g_strdup_printf("file://%s", file2); qof_session_begin (new_session, newfile, TRUE, FALSE, FALSE); io_err = qof_session_get_error (new_session); //printf("io_err1 = %d\n", io_err); g_assert(io_err != ERR_BACKEND_NO_HANDLER); // Do not have no handler g_assert(io_err != ERR_BACKEND_NO_SUCH_DB); // DB must exist g_assert(io_err != ERR_BACKEND_LOCKED); g_assert(io_err == 0); qof_session_load (new_session, NULL); io_err = qof_session_get_error (new_session); //printf("io_err2 = %d\n", io_err); g_assert(io_err == 0); { GList *templ_list; GncABTransTempl *templ; QofBook *book = qof_session_get_book(new_session); const char* ORIGINAL_NAME = "Some Name"; const char* CHANGED_NAME = "Some Changed Name"; templ_list = gnc_ab_trans_templ_list_new_from_book (book); g_assert_cmpint(g_list_length(templ_list), ==, 1); templ = templ_list->data; //Raise the edit level so that we can check that it's marked dirty. qof_instance_increase_editlevel(QOF_INSTANCE(book)); g_assert_cmpstr(gnc_ab_trans_templ_get_name(templ), ==, ORIGINAL_NAME); // ok, name from file is here // Now we change the name into something else and verify it can be saved gnc_ab_trans_templ_set_name(templ, CHANGED_NAME); { g_assert(!qof_instance_get_dirty(QOF_INSTANCE(book))); // not yet dirty // Here we save the changed kvp gnc_ab_set_book_template_list(book, templ_list); g_assert(qof_instance_get_dirty(QOF_INSTANCE(book))); // yup, now dirty gnc_ab_trans_templ_list_free(templ_list); } { templ_list = gnc_ab_trans_templ_list_new_from_book (book); g_assert_cmpint(g_list_length(templ_list), ==, 1); templ = templ_list->data; g_assert_cmpstr(gnc_ab_trans_templ_get_name(templ), ==, CHANGED_NAME); // ok, the change has been saved! gnc_ab_trans_templ_list_free(templ_list); } } { // Check the kvp slots of a aqbanking-enabled account QofBook *book = qof_session_get_book(new_session); Account* account = gnc_book_get_root_account(book); GDate retrieved_date, original_date; gchar buff[MAX_DATE_LENGTH]; g_assert(account); // The interesting test case here: Can we read the correct date // from the xml file? if (1) { Timespec retrieved_ts = gnc_ab_get_account_trans_retrieval(account); g_test_message("retrieved_ts=%s\n", gnc_print_date(retrieved_ts)); //printf("Time=%s\n", gnc_print_date(retrieved_ts)); retrieved_date = timespec_to_gdate(retrieved_ts); g_date_set_dmy(&original_date, 29, 8, 2014); g_assert_cmpint(g_date_compare(&retrieved_date, &original_date), ==, 0); } // A lower-level test here: Can we write and read again the // trans_retrieval date? This wouldn't need this particular // Account, just a general Account object. if (0) { Timespec original_ts = timespec_now(), retrieved_ts; // Check whether the "ab-trans-retrieval" property of Account // is written and read again correctly. gnc_ab_set_account_trans_retrieval(account, original_ts); retrieved_ts = gnc_ab_get_account_trans_retrieval(account); // printf("original_ts=%s = %d retrieved_ts=%s = %d\n", // gnc_print_date(original_ts), original_ts.tv_sec, // gnc_print_date(retrieved_ts), retrieved_ts.tv_sec); original_date = timespec_to_gdate(original_ts); retrieved_date = timespec_to_gdate(retrieved_ts); qof_print_gdate (buff, sizeof (buff), &original_date); //printf("original_date=%s\n", buff); qof_print_gdate (buff, sizeof (buff), &retrieved_date); //printf("retrieved_date=%s\n", buff); // Is the retrieved date identical to the one written g_assert_cmpint(g_date_compare(&retrieved_date, &original_date), ==, 0); }
static void gtk_dateentry_init (GtkDateEntry * dateentry) { GtkWidget *widget; GtkWidget *arrow; DB( g_print(" (dateentry) init\n") ); widget=GTK_WIDGET(dateentry); GTK_BOX(widget)->homogeneous = FALSE; dateentry->date = g_date_new(); /* today's date */ g_date_set_time_t(dateentry->date, time(NULL)); g_date_set_dmy(&dateentry->mindate, 1, 1, 1900); g_date_set_dmy(&dateentry->maxdate, 31, 12, 2200); dateentry->entry = gtk_entry_new (); gtk_widget_set_size_request(dateentry->entry, 90, -1); gtk_box_pack_start (GTK_BOX (dateentry), dateentry->entry, TRUE, TRUE, 0); dateentry->arrow = gtk_toggle_button_new (); arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_IN); gtk_container_add (GTK_CONTAINER (dateentry->arrow), arrow); gtk_box_pack_end (GTK_BOX (dateentry), dateentry->arrow, FALSE, FALSE, 0); gtk_widget_show (dateentry->entry); gtk_widget_show (dateentry->arrow); g_signal_connect (GTK_OBJECT (dateentry->arrow), "toggled", G_CALLBACK (gtk_dateentry_arrow_press), dateentry); g_signal_connect (GTK_OBJECT (dateentry->entry), "activate", G_CALLBACK (gtk_dateentry_entry_new), dateentry); g_signal_connect (GTK_OBJECT (dateentry->entry), "focus-out-event", G_CALLBACK (gtk_dateentry_focus), dateentry); g_signal_connect (GTK_OBJECT (dateentry->entry), "key_press_event", G_CALLBACK (gtk_dateentry_entry_key), dateentry); /* our popup window */ dateentry->popwin = gtk_window_new (GTK_WINDOW_POPUP); gtk_widget_set_events (dateentry->popwin, gtk_widget_get_events(dateentry->popwin) | GDK_KEY_PRESS_MASK); dateentry->frame = gtk_frame_new (NULL); gtk_container_add (GTK_CONTAINER (dateentry->popwin), dateentry->frame); gtk_frame_set_shadow_type (GTK_FRAME (dateentry->frame), GTK_SHADOW_OUT); gtk_widget_show (dateentry->frame); dateentry->calendar = gtk_calendar_new (); gtk_container_add (GTK_CONTAINER (dateentry->frame), dateentry->calendar); gtk_widget_show (dateentry->calendar); g_signal_connect (GTK_OBJECT (dateentry->popwin), "key_press_event", G_CALLBACK (key_press_popup), dateentry); g_signal_connect (GTK_OBJECT (dateentry->popwin), "button_press_event", G_CALLBACK (gtk_dateentry_button_press), dateentry); g_signal_connect (GTK_OBJECT (dateentry->calendar), "prev-year", G_CALLBACK (gtk_dateentry_calendar_year), dateentry); g_signal_connect (GTK_OBJECT (dateentry->calendar), "next-year", G_CALLBACK (gtk_dateentry_calendar_year), dateentry); g_signal_connect (GTK_OBJECT (dateentry->calendar), "prev-month", G_CALLBACK (gtk_dateentry_calendar_year), dateentry); g_signal_connect (GTK_OBJECT (dateentry->calendar), "next-month", G_CALLBACK (gtk_dateentry_calendar_year), dateentry); g_signal_connect (GTK_OBJECT (dateentry->calendar), "day-selected", G_CALLBACK (gtk_dateentry_calendar_getfrom), dateentry); g_signal_connect (GTK_OBJECT (dateentry->calendar), "day-selected-double-click", G_CALLBACK (gtk_dateentry_calendar_select), dateentry); gtk_dateentry_calendar_getfrom(NULL, dateentry); }
void calendar_create_fullyear_window (GUI *appGUI) { GtkWidget *vbox1, *vbox2; GtkWidget *hseparator; GtkWidget *hbuttonbox; GtkWidget *close_button; GtkWidget *hbox1; GtkWidget *prev_button; GtkWidget *info_button; GtkObject *fy_spinbutton_adj; GtkWidget *next_button; GtkWidget *fycal_scrolledwindow; GtkWidget *fycal_viewport; GtkWidget *fycal_alternative_view_checkbutton; GtkWidget *vseparator; GtkWidget *label; GtkWidget *fycal_label, *fycal_vbox; #ifdef HAVE_LIBICAL GtkWidget *button; #endif /* HAVE_LIBICAL */ gchar tmpbuf[BUFFER_SIZE], buffer[BUFFER_SIZE]; gint i, j, x, y, idx; GDate *cdate; guint month, year; cdate = g_date_new (); g_return_if_fail (cdate != NULL); g_date_set_time_t (cdate, time (NULL)); appGUI->cal->fullyear_window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_title (GTK_WINDOW (appGUI->cal->fullyear_window), _("Full-year calendar")); gtk_window_set_position (GTK_WINDOW (appGUI->cal->fullyear_window), GTK_WIN_POS_CENTER_ALWAYS); gtk_window_set_default_size (GTK_WINDOW (appGUI->cal->fullyear_window), config.fy_window_size_x, config.fy_window_size_y); gtk_window_set_modal (GTK_WINDOW (appGUI->cal->fullyear_window), TRUE); g_signal_connect (G_OBJECT (appGUI->cal->fullyear_window), "delete_event", G_CALLBACK (fullyear_window_close_cb), appGUI); gtk_window_set_transient_for (GTK_WINDOW (appGUI->cal->fullyear_window), GTK_WINDOW (appGUI->main_window)); gtk_container_set_border_width (GTK_CONTAINER (appGUI->cal->fullyear_window), 8); g_signal_connect (G_OBJECT (appGUI->cal->fullyear_window), "key_press_event", G_CALLBACK (fullyear_key_press_cb), appGUI); vbox1 = gtk_vbox_new (FALSE, 0); gtk_widget_show (vbox1); gtk_container_add (GTK_CONTAINER (appGUI->cal->fullyear_window), vbox1); hbox1 = gtk_hbox_new (FALSE, 0); gtk_widget_show (hbox1); gtk_box_pack_start (GTK_BOX (vbox1), hbox1, FALSE, FALSE, 4); g_snprintf (tmpbuf, BUFFER_SIZE, "<b>%s:</b>", _("Year")); label = gtk_label_new (tmpbuf); gtk_widget_show (label); gtk_box_pack_start (GTK_BOX (hbox1), label, FALSE, TRUE, 0); gtk_label_set_use_markup (GTK_LABEL (label), TRUE); gtk_misc_set_padding (GTK_MISC (label), 0, 4); fy_spinbutton_adj = gtk_adjustment_new (get_gdate_current_year (), JULIAN_GREGORIAN_YEAR, 9999, 1, 10, 10); appGUI->cal->fy_spinbutton = gtk_spin_button_new (GTK_ADJUSTMENT (fy_spinbutton_adj), 1, 0); gtk_widget_show (appGUI->cal->fy_spinbutton); g_signal_connect(appGUI->cal->fy_spinbutton, "value-changed", G_CALLBACK(change_year_spin_button_cb), appGUI); gtk_box_pack_start (GTK_BOX (hbox1), appGUI->cal->fy_spinbutton, FALSE, FALSE, 8); gtk_widget_set_size_request (appGUI->cal->fy_spinbutton, 80, -1); gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (appGUI->cal->fy_spinbutton), TRUE); gtk_spin_button_set_update_policy (GTK_SPIN_BUTTON (appGUI->cal->fy_spinbutton), GTK_UPDATE_IF_VALID); if (config.default_stock_icons) { info_button = gui_stock_button (GTK_STOCK_INFO, FALSE); } else { info_button = gui_stock_button (OSMO_STOCK_BUTTON_INFO, FALSE); } GTK_WIDGET_UNSET_FLAGS(info_button, GTK_CAN_FOCUS); gtk_widget_show (info_button); g_signal_connect (info_button, "clicked", G_CALLBACK (year_info_cb), appGUI); gtk_tooltips_set_tip (appGUI->osmo_tooltips, info_button, _("Year info"), NULL); gtk_button_set_relief (GTK_BUTTON (info_button), GTK_RELIEF_NONE); gtk_box_pack_start (GTK_BOX (hbox1), info_button, FALSE, FALSE, 2); vseparator = gtk_vseparator_new (); gtk_widget_show (vseparator); gtk_box_pack_start (GTK_BOX (hbox1), vseparator, FALSE, FALSE, 8); if (config.default_stock_icons) { prev_button = gui_stock_button (GTK_STOCK_GO_BACK, FALSE); } else { prev_button = gui_stock_button (OSMO_STOCK_BUTTON_PREV_YEAR, FALSE); } GTK_WIDGET_UNSET_FLAGS (prev_button, GTK_CAN_FOCUS); gtk_widget_show (prev_button); g_signal_connect (prev_button, "clicked", G_CALLBACK (change_to_previous_year_cb), appGUI); gtk_tooltips_set_tip (appGUI->osmo_tooltips, prev_button, _("Previous year"), NULL); gtk_button_set_relief (GTK_BUTTON (prev_button), GTK_RELIEF_NONE); gtk_box_pack_start (GTK_BOX (hbox1), prev_button, FALSE, FALSE, 2); if (config.default_stock_icons) { appGUI->cal->cyear_button = gui_stock_button (GTK_STOCK_HOME, FALSE); } else { appGUI->cal->cyear_button = gui_stock_button (OSMO_STOCK_BUTTON_TODAY, FALSE); } GTK_WIDGET_UNSET_FLAGS (appGUI->cal->cyear_button, GTK_CAN_FOCUS); gtk_widget_show (appGUI->cal->cyear_button); g_signal_connect (appGUI->cal->cyear_button, "clicked", G_CALLBACK (change_to_current_year_cb), appGUI); gtk_tooltips_set_tip (appGUI->osmo_tooltips, appGUI->cal->cyear_button, _("Current year"), NULL); gtk_button_set_relief (GTK_BUTTON (appGUI->cal->cyear_button), GTK_RELIEF_NONE); gtk_box_pack_start (GTK_BOX (hbox1), appGUI->cal->cyear_button, FALSE, FALSE, 2); if (config.default_stock_icons) { next_button = gui_stock_button (GTK_STOCK_GO_FORWARD, FALSE); } else { next_button = gui_stock_button (OSMO_STOCK_BUTTON_NEXT_YEAR, FALSE); } GTK_WIDGET_UNSET_FLAGS(next_button, GTK_CAN_FOCUS); gtk_widget_show (next_button); g_signal_connect (next_button, "clicked", G_CALLBACK (change_to_next_year_cb), appGUI); gtk_tooltips_set_tip (appGUI->osmo_tooltips, next_button, _("Next year"), NULL); gtk_button_set_relief (GTK_BUTTON (next_button), GTK_RELIEF_NONE); gtk_box_pack_start (GTK_BOX (hbox1), next_button, FALSE, FALSE, 2); vseparator = gtk_vseparator_new (); gtk_widget_show (vseparator); gtk_box_pack_start (GTK_BOX (hbox1), vseparator, FALSE, FALSE, 8); fycal_alternative_view_checkbutton = gtk_check_button_new_with_mnemonic (_("Alternative view")); GTK_WIDGET_UNSET_FLAGS (fycal_alternative_view_checkbutton, GTK_CAN_FOCUS); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (fycal_alternative_view_checkbutton), config.fy_alternative_view); g_signal_connect (G_OBJECT (fycal_alternative_view_checkbutton), "toggled", G_CALLBACK (alternative_view_cb), appGUI); gtk_box_pack_start (GTK_BOX (hbox1), fycal_alternative_view_checkbutton, FALSE, FALSE, 2); gtk_widget_show (fycal_alternative_view_checkbutton); #ifdef HAVE_LIBICAL if (appGUI->calendar_only == FALSE) { button = gtk_button_new_with_label (_("Browse iCal events")); GTK_WIDGET_UNSET_FLAGS(button, GTK_CAN_FOCUS); gtk_widget_show (button); gtk_box_pack_end (GTK_BOX (hbox1), button, FALSE, FALSE, 2); g_signal_connect (button, "clicked", G_CALLBACK (browse_ical_events_cb), appGUI); } #endif /* HAVE_LIBICAL */ fycal_scrolledwindow = gtk_scrolled_window_new (NULL, NULL); gtk_widget_show (fycal_scrolledwindow); gtk_box_pack_start (GTK_BOX (vbox1), fycal_scrolledwindow, TRUE, TRUE, 0); gtk_container_set_border_width (GTK_CONTAINER (fycal_scrolledwindow), 4); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (fycal_scrolledwindow), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); fycal_viewport = gtk_viewport_new (NULL, NULL); gtk_widget_show (fycal_viewport); gtk_container_add (GTK_CONTAINER (fycal_scrolledwindow), fycal_viewport); vbox2 = gtk_vbox_new (FALSE, 0); gtk_widget_show (vbox2); gtk_container_add (GTK_CONTAINER (fycal_viewport), vbox2); /*-------------------------------------------------------------------------------------*/ /* First view */ if (config.fy_simple_view == TRUE) { appGUI->cal->fycal_table_1 = gtk_table_new (MAX_MONTHS + 2, FULL_YEAR_COLS + 1, FALSE); } else { appGUI->cal->fycal_table_1 = gtk_table_new (MAX_MONTHS + 4, FULL_YEAR_COLS + 3, FALSE); } if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (fycal_alternative_view_checkbutton)) == FALSE) { gtk_widget_show (appGUI->cal->fycal_table_1); } gtk_box_pack_start (GTK_BOX (vbox2), appGUI->cal->fycal_table_1, TRUE, TRUE, 0); vseparator = gtk_vseparator_new (); gtk_widget_show (vseparator); if (config.fy_simple_view == TRUE) { gtk_table_attach (GTK_TABLE (appGUI->cal->fycal_table_1), vseparator, 1, 2, 0, 14, (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), 0, 0); } else { gtk_table_attach (GTK_TABLE (appGUI->cal->fycal_table_1), vseparator, 1, 2, 0, 16, (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), 0, 0); } hseparator = gtk_hseparator_new (); gtk_widget_show (hseparator); gtk_table_attach (GTK_TABLE (appGUI->cal->fycal_table_1), hseparator, 2, 39, 1, 2, (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), (GtkAttachOptions) (GTK_FILL), 0, 0); hseparator = gtk_hseparator_new (); gtk_widget_show (hseparator); gtk_table_attach (GTK_TABLE (appGUI->cal->fycal_table_1), hseparator, 0, 1, 1, 2, (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), (GtkAttachOptions) (GTK_FILL), 0, 0); if (config.fy_simple_view == FALSE) { vseparator = gtk_vseparator_new (); gtk_widget_show (vseparator); gtk_table_attach (GTK_TABLE (appGUI->cal->fycal_table_1), vseparator, FULL_YEAR_COLS + 2, FULL_YEAR_COLS + 3, 0, 16, (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), 0, 0); hseparator = gtk_hseparator_new (); gtk_widget_show (hseparator); gtk_table_attach (GTK_TABLE (appGUI->cal->fycal_table_1), hseparator, 2, 39, MAX_MONTHS + 2, MAX_MONTHS + 3, (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), (GtkAttachOptions) (GTK_FILL), 0, 0); hseparator = gtk_hseparator_new (); gtk_widget_show (hseparator); gtk_table_attach (GTK_TABLE (appGUI->cal->fycal_table_1), hseparator, 0, 1, MAX_MONTHS + 2, MAX_MONTHS + 3, (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), (GtkAttachOptions) (GTK_FILL), 0, 0); hseparator = gtk_hseparator_new (); gtk_widget_show (hseparator); gtk_table_attach (GTK_TABLE (appGUI->cal->fycal_table_1), hseparator, FULL_YEAR_COLS + 3, FULL_YEAR_COLS + 4, 1, 2, (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), (GtkAttachOptions) (GTK_FILL), 0, 0); hseparator = gtk_hseparator_new (); gtk_widget_show (hseparator); gtk_table_attach (GTK_TABLE (appGUI->cal->fycal_table_1), hseparator, FULL_YEAR_COLS + 3, FULL_YEAR_COLS + 4, MAX_MONTHS + 2, MAX_MONTHS + 3, (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), (GtkAttachOptions) (GTK_FILL), 0, 0); } g_date_set_day (cdate, 1); for (month = G_DATE_JANUARY; month <= G_DATE_DECEMBER; month++) { g_date_set_month (cdate, month); g_date_strftime (buffer, BUFFER_SIZE, config.fy_simple_view ? "%b" : "%B", cdate); g_snprintf (tmpbuf, BUFFER_SIZE, (month % 2) ? "%s" : "<span foreground='medium blue'>%s</span>", buffer); label = gtk_label_new (NULL); gtk_widget_show (label); gtk_table_attach (GTK_TABLE (appGUI->cal->fycal_table_1), label, 0, 1, month + 1, month + 2, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0); gtk_misc_set_padding (GTK_MISC (label), 8, 0); gtk_label_set_markup (GTK_LABEL (label), tmpbuf); if (config.fy_simple_view == FALSE) { label = gtk_label_new (NULL); gtk_widget_show (label); gtk_table_attach (GTK_TABLE (appGUI->cal->fycal_table_1), label, FULL_YEAR_COLS + 3, FULL_YEAR_COLS + 4, month + 1, month + 2, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0); gtk_misc_set_padding (GTK_MISC (label), 8, 0); gtk_label_set_markup (GTK_LABEL (label), tmpbuf); } } /* start with monday */ g_date_set_dmy (cdate, 1, 1, 2007); for (i = 0; i < FULL_YEAR_COLS; i++) { g_date_set_day (cdate, (i % DAYS_PER_WEEK) + 1); g_date_strftime (buffer, BUFFER_SIZE, "%a", cdate); if (i % 7 + 1 == G_DATE_SATURDAY || i % 7 + 1 == G_DATE_SUNDAY) { g_snprintf (tmpbuf, BUFFER_SIZE, "<span foreground='firebrick'>%s</span>", buffer); } else { g_snprintf (tmpbuf, BUFFER_SIZE, "%s", buffer); } label = gtk_label_new (NULL); gtk_widget_show (label); gtk_table_attach (GTK_TABLE (appGUI->cal->fycal_table_1), label, i + 2, i + 3, 0, 1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0); gtk_misc_set_padding (GTK_MISC (label), 4, 0); gtk_label_set_angle (GTK_LABEL (label), 90); gtk_label_set_markup (GTK_LABEL (label), tmpbuf); if (config.fy_simple_view == FALSE) { label = gtk_label_new (NULL); gtk_widget_show (label); gtk_table_attach (GTK_TABLE (appGUI->cal->fycal_table_1), label, i + 2, i + 3, MAX_MONTHS + 3, MAX_MONTHS + 4, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0); gtk_misc_set_padding (GTK_MISC (label), 4, 0); gtk_label_set_angle (GTK_LABEL (label), 90); gtk_label_set_markup (GTK_LABEL (label), tmpbuf); } } for (month = G_DATE_JANUARY; month <= G_DATE_DECEMBER; month++) { for (j = 0; j < FULL_YEAR_COLS; j++) { i = month - 1; idx = i * FULL_YEAR_COLS + j; appGUI->cal->calendar_buttons[idx] = gtk_button_new (); GTK_WIDGET_UNSET_FLAGS (appGUI->cal->calendar_buttons[idx], GTK_CAN_FOCUS); gtk_button_set_relief (GTK_BUTTON (appGUI->cal->calendar_buttons[idx]), GTK_RELIEF_NONE); gtk_widget_show (appGUI->cal->calendar_buttons[idx]); gtk_table_attach (GTK_TABLE (appGUI->cal->fycal_table_1), appGUI->cal->calendar_buttons[idx], j+2, j+3, i+2, i+3, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0); } } display_calendar (get_current_year (), appGUI); gtk_widget_set_sensitive (appGUI->cal->cyear_button, FALSE); /*-------------------------------------------------------------------------------------*/ /* Second view */ appGUI->cal->fycal_table_2 = gtk_table_new (3, 4, FALSE); if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (fycal_alternative_view_checkbutton)) == TRUE) { gtk_widget_show (appGUI->cal->fycal_table_2); } gtk_box_pack_start (GTK_BOX (vbox2), appGUI->cal->fycal_table_2, TRUE, TRUE, 0); for (i = y = 0; y < 3; y++) { for (x = 0; x < 4; x++, i++) { fycal_vbox = gtk_vbox_new (FALSE, 0); gtk_widget_show (fycal_vbox); gtk_table_attach (GTK_TABLE (appGUI->cal->fycal_table_2), fycal_vbox, x, x + 1, y, y + 1, (GtkAttachOptions) (GTK_FILL | GTK_EXPAND), (GtkAttachOptions) (0), 0, 0); fycal_label = gtk_label_new (NULL); gtk_widget_show (fycal_label); gtk_box_pack_start (GTK_BOX (fycal_vbox), fycal_label, FALSE, FALSE, 0); appGUI->cal->fy_calendars[i] = gui_calendar_new (); gtk_widget_show (appGUI->cal->fy_calendars[i]); GTK_WIDGET_UNSET_FLAGS (appGUI->cal->fy_calendars[i], GTK_CAN_FOCUS); gui_calendar_set_display_options (GUI_CALENDAR (appGUI->cal->fy_calendars[i]), (config.display_options & (GUI_CALENDAR_SHOW_DAY_NAMES | GUI_CALENDAR_WEEK_START_MONDAY)) | GUI_CALENDAR_NO_MONTH_CHANGE); gui_calendar_enable_cursor (GUI_CALENDAR (appGUI->cal->fy_calendars[i]), FALSE); gui_calendar_set_event_marker_type (GUI_CALENDAR (appGUI->cal->fy_calendars[i]), config.event_marker_type); gui_calendar_set_event_marker_color (GUI_CALENDAR (appGUI->cal->fy_calendars[i]), config.mark_color); gui_calendar_set_selector_color (GUI_CALENDAR (appGUI->cal->fy_calendars[i]), config.selection_color); gui_calendar_set_header_color (GUI_CALENDAR (appGUI->cal->fy_calendars[i]), config.header_color); gui_calendar_set_weekend_color (GUI_CALENDAR (appGUI->cal->fy_calendars[i]), config.weekend_color); gui_calendar_set_day_note_marker_type (GUI_CALENDAR (appGUI->cal->fy_calendars[i]), config.day_note_marker); gui_calendar_set_today_marker_type (GUI_CALENDAR (appGUI->cal->fy_calendars[i]), config.today_marker_type); gui_calendar_set_today_marker_color (GUI_CALENDAR (appGUI->cal->fy_calendars[i]), config.mark_current_day_color); gui_calendar_set_today_marker_alpha (GUI_CALENDAR (appGUI->cal->fy_calendars[i]), config.mark_current_day_alpha); year = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (appGUI->cal->fy_spinbutton)); month = i + 1; gui_calendar_select_month (GUI_CALENDAR (appGUI->cal->fy_calendars[i]), month - 1, year); mark_events (appGUI->cal->fy_calendars[i], month - 1, year, appGUI); g_date_set_dmy (cdate, 1, month, year); g_date_strftime (buffer, BUFFER_SIZE, "%B", cdate); gtk_label_set_text (GTK_LABEL (fycal_label), buffer); gtk_box_pack_start (GTK_BOX (fycal_vbox), appGUI->cal->fy_calendars[i], FALSE, FALSE, 0); } } /*-------------------------------------------------------------------------------------*/ hseparator = gtk_hseparator_new (); gtk_widget_show (hseparator); gtk_box_pack_start (GTK_BOX (vbox1), hseparator, FALSE, TRUE, 4); hbuttonbox = gtk_hbutton_box_new (); gtk_widget_show (hbuttonbox); gtk_box_pack_start (GTK_BOX (vbox1), hbuttonbox, FALSE, TRUE, 0); gtk_button_box_set_layout (GTK_BUTTON_BOX (hbuttonbox), GTK_BUTTONBOX_END); gtk_box_set_spacing (GTK_BOX (hbuttonbox), 4); if (config.default_stock_icons) { close_button = gtk_button_new_from_stock (GTK_STOCK_CLOSE); } else { close_button = gtk_button_new_from_stock (OSMO_STOCK_BUTTON_CLOSE); } gtk_widget_show (close_button); g_signal_connect (close_button, "clicked", G_CALLBACK (button_fullyear_window_close_cb), appGUI); gtk_container_add (GTK_CONTAINER (hbuttonbox), close_button); gtk_widget_show (appGUI->cal->fullyear_window); }
/* HOLDS: g_date_global_lock */ static void g_date_prepare_to_parse (const gchar *str, GDateParseTokens *pt) { const gchar *locale = setlocale (LC_TIME, NULL); gboolean recompute_localeinfo = FALSE; GDate d; g_return_if_fail (locale != NULL); /* should not happen */ g_date_clear (&d, 1); /* clear for scratch use */ if ( (current_locale == NULL) || (strcmp (locale, current_locale) != 0) ) recompute_localeinfo = TRUE; /* Uh, there used to be a reason for the temporary */ if (recompute_localeinfo) { int i = 1; GDateParseTokens testpt; gchar buf[128]; g_free (current_locale); /* still works if current_locale == NULL */ current_locale = g_strdup (locale); short_month_names[0] = "Error"; long_month_names[0] = "Error"; while (i < 13) { gchar *casefold; g_date_set_dmy (&d, 1, i, 1); g_return_if_fail (g_date_valid (&d)); g_date_strftime (buf, 127, "%b", &d); casefold = g_utf8_casefold (buf, -1); g_free (short_month_names[i]); short_month_names[i] = g_utf8_normalize (casefold, -1, G_NORMALIZE_ALL); g_free (casefold); g_date_strftime (buf, 127, "%B", &d); casefold = g_utf8_casefold (buf, -1); g_free (long_month_names[i]); long_month_names[i] = g_utf8_normalize (casefold, -1, G_NORMALIZE_ALL); g_free (casefold); ++i; } /* Determine DMY order */ /* had to pick a random day - don't change this, some strftimes * are broken on some days, and this one is good so far. */ g_date_set_dmy (&d, 4, 7, 1976); g_date_strftime (buf, 127, "%x", &d); g_date_fill_parse_tokens (buf, &testpt); i = 0; while (i < testpt.num_ints) { switch (testpt.n[i]) { case 7: dmy_order[i] = G_DATE_MONTH; break; case 4: dmy_order[i] = G_DATE_DAY; break; case 76: using_twodigit_years = TRUE; /* FALL THRU */ case 1976: dmy_order[i] = G_DATE_YEAR; break; default: /* assume locale era */ locale_era_adjust = 1976 - testpt.n[i]; dmy_order[i] = G_DATE_YEAR; break; } ++i; } #ifdef G_ENABLE_DEBUG DEBUG_MSG (("**GDate prepared a new set of locale-specific parse rules.")); i = 1; while (i < 13) { DEBUG_MSG ((" %s %s", long_month_names[i], short_month_names[i])); ++i; } if (using_twodigit_years) DEBUG_MSG (("**Using twodigit years with cutoff year: %u", twodigit_start_year)); { gchar *strings[3]; i = 0; while (i < 3) { switch (dmy_order[i]) { case G_DATE_MONTH: strings[i] = "Month"; break; case G_DATE_YEAR: strings[i] = "Year"; break; case G_DATE_DAY: strings[i] = "Day"; break; default: strings[i] = NULL; break; } ++i; } DEBUG_MSG (("**Order: %s, %s, %s", strings[0], strings[1], strings[2])); DEBUG_MSG (("**Sample date in this locale: `%s'", buf)); } #endif } g_date_fill_parse_tokens (str, pt); }
int main(int argc, char** argv) { GDate* d; guint32 j; GDateMonth m; GDateYear y, prev_y; GDateDay day; gchar buf[101]; gchar* loc; /* Try to get all the leap year cases. */ GDateYear check_years[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 98, 99, 100, 101, 102, 103, 397, 398, 399, 400, 401, 402, 403, 404, 405, 406, 1598, 1599, 1600, 1601, 1602, 1650, 1651, 1897, 1898, 1899, 1900, 1901, 1902, 1903, 1961, 1962, 1963, 1964, 1965, 1967, 1968, 1969, 1970, 1971, 1972, 1973, 1974, 1975, 1976, 1977, 1978, 1979, 1980, 1981, 1982, 1983, 1984, 1985, 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 3000, 3001, 3002, 3998, 3999, 4000, 4001, 4002, 4003 }; guint n_check_years = sizeof(check_years)/sizeof(GDateYear); guint i; gboolean discontinuity; g_print("checking GDate..."); TEST("sizeof(GDate) is not more than 8 bytes on this platform", sizeof(GDate) < 9); d = g_date_new(); TEST("Empty constructor produces invalid date", !g_date_valid(d)); g_date_free(d); d = g_date_new_dmy(1,1,1); TEST("January 1, Year 1 created and valid", g_date_valid(d)); j = g_date_get_julian(d); TEST("January 1, Year 1 is Julian date 1", j == 1); TEST("Returned month is January", g_date_get_month(d) == G_DATE_JANUARY); TEST("Returned day is 1", g_date_get_day(d) == 1); TEST("Returned year is 1", g_date_get_year(d) == 1); TEST("Bad month is invalid", !g_date_valid_month(G_DATE_BAD_MONTH)); TEST("Month 13 is invalid", !g_date_valid_month(13)); TEST("Bad day is invalid", !g_date_valid_day(G_DATE_BAD_DAY)); TEST("Day 32 is invalid", !g_date_valid_day(32)); TEST("Bad year is invalid", !g_date_valid_year(G_DATE_BAD_YEAR)); TEST("Bad julian is invalid", !g_date_valid_julian(G_DATE_BAD_JULIAN)); TEST("Bad weekday is invalid", !g_date_valid_weekday(G_DATE_BAD_WEEKDAY)); TEST("Year 2000 is a leap year", g_date_is_leap_year(2000)); TEST("Year 1999 is not a leap year", !g_date_is_leap_year(1999)); TEST("Year 1996 is a leap year", g_date_is_leap_year(1996)); TEST("Year 1600 is a leap year", g_date_is_leap_year(1600)); TEST("Year 2100 is not a leap year", !g_date_is_leap_year(2100)); TEST("Year 1800 is not a leap year", !g_date_is_leap_year(1800)); g_date_free(d); loc = setlocale(LC_ALL,""); if (loc) g_print("\nLocale set to %s\n", loc); else g_print("\nLocale unchanged\n"); d = g_date_new(); g_date_set_time(d, time(NULL)); TEST("Today is valid", g_date_valid(d)); g_date_strftime(buf,100,"Today is a %A, %x\n", d); g_print("%s", buf); g_date_set_time(d, 1); TEST("Beginning of Unix epoch is valid", g_date_valid(d)); g_date_strftime(buf,100,"1 second into the Unix epoch it was a %A, in the month of %B, %x\n", d); g_print("%s", buf); g_date_set_julian(d, 1); TEST("GDate's \"Julian\" epoch's first day is valid", g_date_valid(d)); g_date_strftime(buf,100,"Our \"Julian\" epoch begins on a %A, in the month of %B, %x\n", d); g_print("%s", buf); g_date_set_dmy(d, 10, 1, 2000); g_date_strftime(buf,100,"%x", d); g_date_set_parse(d, buf); /* Note: this test will hopefully work, but no promises. */ TEST("Successfully parsed a %x-formatted string", g_date_valid(d) && g_date_get_month(d) == 1 && g_date_get_day(d) == 10 && g_date_get_year(d) == 2000); if (failed) g_date_debug_print(d); g_date_free(d); j = G_DATE_BAD_JULIAN; i = 0; discontinuity = TRUE; y = check_years[0]; prev_y = G_DATE_BAD_YEAR; while (i < n_check_years) { guint32 first_day_of_year = G_DATE_BAD_JULIAN; guint16 days_in_year = g_date_is_leap_year(y) ? 366 : 365; guint sunday_week_of_year = 0; guint sunday_weeks_in_year = g_date_get_sunday_weeks_in_year(y); guint monday_week_of_year = 0; guint monday_weeks_in_year = g_date_get_monday_weeks_in_year(y); guint iso8601_week_of_year = 0; if (discontinuity) g_print(" (Break in sequence of requested years to check)\n"); g_print("Checking year %u", y); TEST("Year is valid", g_date_valid_year(y)); TEST("Number of Sunday weeks in year is 52 or 53", sunday_weeks_in_year == 52 || sunday_weeks_in_year == 53); TEST("Number of Monday weeks in year is 52 or 53", monday_weeks_in_year == 52 || monday_weeks_in_year == 53); m = 1; while (m < 13) { guint8 dim = g_date_get_days_in_month(m,y); GDate days[31]; /* This is the fast way, no allocation */ TEST("Sensible number of days in month", (dim > 0 && dim < 32)); TEST("Month between 1 and 12 is valid", g_date_valid_month(m)); day = 1; g_date_clear(days, 31); while (day <= dim) { guint i; GDate tmp; TEST("DMY triplet is valid", g_date_valid_dmy(day,m,y)); /* Create GDate with triplet */ d = &days[day-1]; TEST("Cleared day is invalid", !g_date_valid(d)); g_date_set_dmy(d,day,m,y); TEST("Set day is valid", g_date_valid(d)); if (m == G_DATE_JANUARY && day == 1) { first_day_of_year = g_date_get_julian(d); } g_assert(first_day_of_year != G_DATE_BAD_JULIAN); TEST("Date with DMY triplet is valid", g_date_valid(d)); TEST("Month accessor works", g_date_get_month(d) == m); TEST("Year accessor works", g_date_get_year(d) == y); TEST("Day of month accessor works", g_date_get_day(d) == day); TEST("Day of year is consistent with Julian dates", ((g_date_get_julian(d) + 1 - first_day_of_year) == (g_date_get_day_of_year(d)))); if (failed) { g_print("first day: %u this day: %u day of year: %u\n", first_day_of_year, g_date_get_julian(d), g_date_get_day_of_year(d)); } if (m == G_DATE_DECEMBER && day == 31) { TEST("Last day of year equals number of days in year", g_date_get_day_of_year(d) == days_in_year); if (failed) { g_print("last day: %u days in year: %u\n", g_date_get_day_of_year(d), days_in_year); } } TEST("Day of year is not more than number of days in the year", g_date_get_day_of_year(d) <= days_in_year); TEST("Monday week of year is not more than number of weeks in the year", g_date_get_monday_week_of_year(d) <= monday_weeks_in_year); if (failed) { g_print("Weeks in year: %u\n", monday_weeks_in_year); g_date_debug_print(d); } TEST("Monday week of year is >= than last week of year", g_date_get_monday_week_of_year(d) >= monday_week_of_year); if (g_date_get_weekday(d) == G_DATE_MONDAY) { TEST("Monday week of year on Monday 1 more than previous day's week of year", (g_date_get_monday_week_of_year(d) - monday_week_of_year) == 1); if ((m == G_DATE_JANUARY && day <= 4) || (m == G_DATE_DECEMBER && day >= 29)) { TEST("ISO 8601 week of year on Monday Dec 29 - Jan 4 is 1", (g_date_get_iso8601_week_of_year(d) == 1)); } else { TEST("ISO 8601 week of year on Monday 1 more than previous day's week of year", (g_date_get_iso8601_week_of_year(d) - iso8601_week_of_year) == 1); } } else { TEST("Monday week of year on non-Monday 0 more than previous day's week of year", (g_date_get_monday_week_of_year(d) - monday_week_of_year) == 0); if (!(day == 1 && m == G_DATE_JANUARY)) { TEST("ISO 8601 week of year on non-Monday 0 more than previous day's week of year (", (g_date_get_iso8601_week_of_year(d) - iso8601_week_of_year) == 0); } } monday_week_of_year = g_date_get_monday_week_of_year(d); iso8601_week_of_year = g_date_get_iso8601_week_of_year(d); TEST("Sunday week of year is not more than number of weeks in the year", g_date_get_sunday_week_of_year(d) <= sunday_weeks_in_year); if (failed) { g_date_debug_print(d); } TEST("Sunday week of year is >= than last week of year", g_date_get_sunday_week_of_year(d) >= sunday_week_of_year); if (g_date_get_weekday(d) == G_DATE_SUNDAY) { TEST("Sunday week of year on Sunday 1 more than previous day's week of year", (g_date_get_sunday_week_of_year(d) - sunday_week_of_year) == 1); } else { TEST("Sunday week of year on non-Sunday 0 more than previous day's week of year", (g_date_get_sunday_week_of_year(d) - sunday_week_of_year) == 0); } sunday_week_of_year = g_date_get_sunday_week_of_year(d); TEST("Date is equal to itself", g_date_compare(d,d) == 0); /*************** Increments ***********/ i = 1; while (i < 402) /* Need to get 400 year increments in */ { /***** Days ******/ tmp = *d; g_date_add_days(d, i); TEST("Adding days gives a value greater than previous", g_date_compare(d, &tmp) > 0); g_date_subtract_days(d, i); TEST("Forward days then backward days returns us to current day", g_date_get_day(d) == day); if (failed) { g_print(" (increment %u, dmy %u %u %u) ", i, day, m, y); g_date_debug_print(d); } TEST("Forward days then backward days returns us to current month", g_date_get_month(d) == m); if (failed) { g_print(" (increment %u, dmy %u %u %u) ", i, day, m, y); g_date_debug_print(d); } TEST("Forward days then backward days returns us to current year", g_date_get_year(d) == y); if (failed) { g_print(" (increment %u, dmy %u %u %u) ", i, day, m, y); g_date_debug_print(d); } /******* Months ********/ tmp = *d; g_date_add_months(d, i); TEST("Adding months gives a larger value", g_date_compare(d, &tmp) > 0); g_date_subtract_months(d, i); TEST("Forward months then backward months returns us to current month", g_date_get_month(d) == m); if (failed) { g_print(" (increment %u, dmy %u %u %u) ", i, day, m, y); g_date_debug_print(d); } TEST("Forward months then backward months returns us to current year", g_date_get_year(d) == y); if (failed) { g_print(" (increment %u, dmy %u %u %u) ", i, day, m, y); g_date_debug_print(d); } if (day < 29) { /* Day should be unchanged */ TEST("Forward months then backward months returns us to current day", g_date_get_day(d) == day); if (failed) { g_print(" (increment %u, dmy %u %u %u) ", i, day, m, y); g_date_debug_print(d); } } else { /* reset the day for later tests */ g_date_set_day(d, day); } /******* Years ********/ tmp = *d; g_date_add_years(d, i); TEST("Adding years gives a larger value", g_date_compare(d,&tmp) > 0); g_date_subtract_years(d, i); TEST("Forward years then backward years returns us to current month", g_date_get_month(d) == m); if (failed) { g_print(" (increment %u, dmy %u %u %u) ", i, day, m, y); g_date_debug_print(d); } TEST("Forward years then backward years returns us to current year", g_date_get_year(d) == y); if (failed) { g_print(" (increment %u, dmy %u %u %u) ", i, day, m, y); g_date_debug_print(d); } if (m != 2 && day != 29) { TEST("Forward years then backward years returns us to current day", g_date_get_day(d) == day); if (failed) { g_print(" (increment %u, dmy %u %u %u) ", i, day, m, y); g_date_debug_print(d); } } else { g_date_set_day(d, day); /* reset */ } i += 10; } /***** increment test relative to our local Julian count */ if (!discontinuity) { /* We can only run sequence tests between sequential years */ TEST("Julians are sequential with increment 1", j+1 == g_date_get_julian(d)); if (failed) { g_print("Out of sequence, prev: %u expected: %u got: %u\n", j, j+1, g_date_get_julian(d)); } g_date_add_days(d,1); TEST("Next day has julian 1 higher", g_date_get_julian(d) == j + 2); g_date_subtract_days(d, 1); if (j != G_DATE_BAD_JULIAN) { g_date_subtract_days(d, 1); TEST("Previous day has julian 1 lower", g_date_get_julian(d) == j); g_date_add_days(d, 1); /* back to original */ } } discontinuity = FALSE; /* goes away now */ fflush(stdout); fflush(stderr); j = g_date_get_julian(d); /* inc current julian */ ++day; } ++m; } g_print(" done\n"); ++i; prev_y = y; y = check_years[i]; if (prev_y == G_DATE_BAD_YEAR || (prev_y + 1) != y) discontinuity = TRUE; } g_print("\n%u tests passed, %u failed\n",passed, notpassed); return 0; }
void display_calendar (guint year, GUI *appGUI) { static MESSAGE selected_date[MAX_MONTHS * FULL_YEAR_COLS]; GDate *cdate; gint calendar_table[MAX_MONTHS * FULL_YEAR_COLS]; guint current_day, current_month, current_year; guint month; gint i, idx, day, first_day, days; gchar tmpbuf[BUFFER_SIZE], tmpbuf2[BUFFER_SIZE]; for (i = 0; i < MAX_MONTHS * FULL_YEAR_COLS; i++) { calendar_table[i] = -1; } cdate = g_date_new (); g_return_if_fail (cdate != NULL); for (month = G_DATE_JANUARY; month <= G_DATE_DECEMBER; month++) { g_date_set_dmy (cdate, 1, month, year); first_day = g_date_get_weekday (cdate); days = g_date_get_days_in_month (month, year); for (i = 1; i <= days; i++) { calendar_table[(month - 1) * FULL_YEAR_COLS + first_day + i - 2] = i; } } g_date_set_time_t (cdate, time (NULL)); current_day = g_date_get_day (cdate); current_month = g_date_get_month (cdate); current_year = g_date_get_year (cdate); for (month = G_DATE_JANUARY; month <= G_DATE_DECEMBER; month++) { for (i = 0; i < FULL_YEAR_COLS; i++) { idx = (month - 1) * FULL_YEAR_COLS + i; g_signal_handlers_disconnect_by_func (G_OBJECT (appGUI->cal->calendar_buttons[idx]), G_CALLBACK (select_date_day_cb), &selected_date[idx]); day = calendar_table[idx]; if (day > 0) { if (day == current_day && month == current_month && year == current_year) { g_snprintf (tmpbuf2, BUFFER_SIZE, "<b><u>%2d</u></b>", day); } else { g_snprintf (tmpbuf2, BUFFER_SIZE, "%2d", day); } if (i % 7 + 1 == G_DATE_SATURDAY || i % 7 + 1 == G_DATE_SUNDAY) { g_snprintf (tmpbuf, BUFFER_SIZE, "<span foreground='firebrick'>%s</span>", tmpbuf2); } else if (month % 2 == 0) { g_snprintf (tmpbuf, BUFFER_SIZE, "<span foreground='medium blue'>%s</span>", tmpbuf2); } else { g_strlcpy (tmpbuf, tmpbuf2, BUFFER_SIZE); } g_date_set_dmy (cdate, (GDateDay) day, month, (GDateYear) gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (appGUI->cal->fy_spinbutton))); selected_date[idx].data = (gpointer) g_date_get_julian (cdate); selected_date[idx].appGUI = appGUI; g_signal_connect (G_OBJECT (appGUI->cal->calendar_buttons[idx]), "clicked", G_CALLBACK (select_date_day_cb), &selected_date[idx]); gtk_button_set_label (GTK_BUTTON (appGUI->cal->calendar_buttons[idx]), ""); gtk_label_set_markup (GTK_LABEL (GTK_BIN (appGUI->cal->calendar_buttons[idx])->child), tmpbuf); gtk_widget_show (appGUI->cal->calendar_buttons[idx]); } else { gtk_button_set_label (GTK_BUTTON (appGUI->cal->calendar_buttons[idx]), ""); gtk_widget_hide (GTK_WIDGET (appGUI->cal->calendar_buttons[idx])); } } } g_date_free (cdate); }
void cal_read_notes (GUI *appGUI) { xmlDocPtr doc; xmlChar *key, *prop; xmlNodePtr node, cnode, category_node; GtkTreeIter iter; GdkPixbuf *image; guint32 julian; gint day, month, year; gchar *color_str, *note; GDate *date; appGUI->cal->notes_list = NULL; date = g_date_new (); g_return_if_fail (date != NULL); if (g_file_test (prefs_get_config_filename (CALENDAR_NOTES_FILENAME, appGUI), G_FILE_TEST_IS_REGULAR) == FALSE) return; if ((doc = xmlParseFile (prefs_get_config_filename (CALENDAR_NOTES_FILENAME, appGUI)))) { if (!(node = xmlDocGetRootElement (doc))) return; if (!xmlStrcmp (node->name, (xmlChar *) CALENDAR_NOTES_NAME)) { /* read note */ node = node->xmlChildrenNode; while (node != NULL) { if (!xmlStrcmp (node->name, (xmlChar *) CALENDAR_DAY_CATEGORIES_NAME)) { category_node = node->xmlChildrenNode; while (category_node != NULL) { if ((!xmlStrcmp (category_node->name, (const xmlChar *) "name"))) { key = xmlNodeListGetString (doc, category_node->xmlChildrenNode, 1); prop = xmlGetProp (category_node, (const xmlChar *) "color"); if (key != NULL) { image = gui_create_color_swatch ((gchar *) prop); gtk_list_store_append (appGUI->opt->calendar_category_store, &iter); gtk_list_store_set (appGUI->opt->calendar_category_store, &iter, 0, image, 1, prop, 2, (gchar *) key, -1); g_object_unref (image); xmlFree (key); } } category_node = category_node->next; } } if (!xmlStrcmp (node->name, (xmlChar *) "note")) { cnode = node->xmlChildrenNode; julian = 0; day = month = year = 0; color_str = NULL; note = NULL; while (cnode != NULL) { utl_xml_get_int ("day", &day, cnode, doc); utl_xml_get_int ("month", &month, cnode, doc); utl_xml_get_int ("year", &year, cnode, doc); utl_xml_get_uint ("date", &julian, cnode, doc); utl_xml_get_str ("color", &color_str, cnode, doc); utl_xml_get_str ("message", ¬e, cnode, doc); cnode = cnode->next; } if (note != NULL && (g_date_valid_dmy (day, month, year) || g_date_valid_julian (julian))) { if (g_date_valid_julian (julian)) g_date_set_julian (date, julian); else g_date_set_dmy (date, day, month, year); cal_add_note (date, color_str, note, appGUI); if (color_str != NULL) g_free (color_str); g_free (note); } } node = node->next; } } xmlFree (node); xmlFreeDoc (doc); } g_date_free (date); }