void gnm_date_add_days (GDate *d, int n) { if (!g_date_valid (d)) return; if (n >= 0) { guint32 lim = 23936166; /* 31-Dec-65535 */ guint32 j = g_date_get_julian (d); if (j > lim || (unsigned)n > lim - j) goto bad; g_date_add_days (d, n); } else { int m = g_date_get_julian (d) - 1; if (m + n <= 0) goto bad; g_date_subtract_days (d, -n); } return; bad: g_date_clear (d, 1); }
/* ** fill in our gtkentry from our GDate */ static void gtk_dateentry_datetoentry(GtkDateEntry * dateentry) { gchar buffer[256]; DB( g_print(" (dateentry) date2entry\n") ); g_date_clamp(dateentry->date, &dateentry->mindate, &dateentry->maxdate); if(g_date_valid(dateentry->date) == TRUE) { g_date_strftime (buffer, 256 - 1, "%x", dateentry->date); gtk_entry_set_text (GTK_ENTRY (dateentry->entry), buffer); DB( g_print(" = %s\n", buffer) ); } else gtk_entry_set_text (GTK_ENTRY (dateentry->entry), "??"); /* emit the signal */ if(dateentry->lastdate != g_date_get_julian(dateentry->date)) { DB( g_print(" **emit signal**\n") ); g_signal_emit_by_name (dateentry, "changed", NULL, NULL); } dateentry->lastdate = g_date_get_julian(dateentry->date); }
gint g_date_days_between (const GDate *d1, const GDate *d2) { g_return_val_if_fail (g_date_valid (d1), 0); g_return_val_if_fail (g_date_valid (d2), 0); return (gint)g_date_get_julian (d2) - (gint)g_date_get_julian (d1); }
/* return an julian date ... 1 = no date set */ guint32 gtodo_todo_item_get_stop_date_as_julian(GTodoItem *item) { if(item->stop == NULL || !g_date_valid(item->stop)) return 1; else { if(!g_date_valid_julian(g_date_get_julian(item->stop))) return 1; return g_date_get_julian(item->stop); } }
static void convert_timestamp_to_string( const time_t timestamp, std::string& timestamp_string) { GDate mtime, now; gint days_diff; struct tm tm_mtime; time_t time_now; const gchar *format; gchar buf[256]; if (timestamp == 0) { timestamp_string = "Unknown"; return; } localtime_r(×tamp, &tm_mtime); g_date_set_time_t(&mtime, timestamp); time_now = time(NULL); g_date_set_time_t(&now, time_now); days_diff = g_date_get_julian(&now) - g_date_get_julian(&mtime); if (days_diff == 0) { format = "Today at %H:%M"; } else if (days_diff == 1) { format = "Yesterday at %H:%M"; } else { if (days_diff > 1 && days_diff < 7) { format = "%A"; /* Days from last week */ } else { format = "%x"; /* Any other date */ } } if (strftime(buf, sizeof(buf), format, &tm_mtime) != 0) { timestamp_string = buf; } else { timestamp_string = "Unknown"; } }
gchar * get_readable_date (const gchar * format_string, const time_t file_time_raw) { struct tm * file_time; gchar * format; GDate * today; GDate * file_date; guint32 file_date_age; gchar * readable_date; file_time = localtime (&file_time_raw); /* Base format of date column on nautilus date_format key */ if (format_string != NULL) { if (strcmp(format_string, GSEARCH_DATE_FORMAT_LOCALE) == 0) { return gsearchtool_strdup_strftime ("%c", file_time); } else if (strcmp (format_string, GSEARCH_DATE_FORMAT_ISO) == 0) { return gsearchtool_strdup_strftime ("%Y-%m-%d %H:%M:%S", file_time); } } file_date = g_date_new_dmy (file_time->tm_mday, file_time->tm_mon + 1, file_time->tm_year + 1900); today = g_date_new (); g_date_set_time_t (today, time (NULL)); file_date_age = g_date_get_julian (today) - g_date_get_julian (file_date); g_date_free (today); g_date_free (file_date); if (file_date_age == 0) { /* Translators: Below are the strings displayed in the 'Date Modified' column of the list view. The format of this string can vary depending on age of a file. Please modify the format of the timestamp to match your locale. For example, to display 24 hour time replace the '%-I' with '%-H' and remove the '%p'. (See bugzilla report #120434.) */ format = g_strdup(_("today at %-I:%M %p")); } else if (file_date_age == 1) { format = g_strdup(_("yesterday at %-I:%M %p")); } else if (file_date_age < 7) { format = g_strdup(_("%A, %B %-d %Y at %-I:%M:%S %p")); } else { format = g_strdup(_("%A, %B %-d %Y at %-I:%M:%S %p")); } readable_date = gsearchtool_strdup_strftime (format, file_time); g_free (format); return readable_date; }
/* return an julian date ... 1 = no date set */ guint32 gtodo_todo_item_get_due_date_as_julian(GTodoItem *item) { if(item->due == NULL || !g_date_valid(item->due)) { return GTODO_NO_DUE_DATE; } else { if(!g_date_valid_julian(g_date_get_julian(item->due))) return GTODO_NO_DUE_DATE; return g_date_get_julian(item->due); } }
static Recurrence* _get_day_of_month_recurrence(GncFrequency *gf, GDate *start_date, int multiplier, char *combo_name, char *combo_weekend_name) { Recurrence *r; GtkWidget *day_of_month_combo = glade_xml_get_widget(gf->gxml, combo_name); int day_of_month_index = gtk_combo_box_get_active(GTK_COMBO_BOX(day_of_month_combo)); GtkWidget *weekend_adjust_combo = glade_xml_get_widget(gf->gxml, combo_weekend_name); int weekend_adjust = gtk_combo_box_get_active(GTK_COMBO_BOX(weekend_adjust_combo)); GDateWeekday selected_day_of_week; GDate *day_of_week_date; int selected_index, selected_week; r = g_new0(Recurrence, 1); if (day_of_month_index > LAST_DAY_OF_MONTH_OPTION_INDEX + 7) { selected_index = day_of_month_index - LAST_DAY_OF_MONTH_OPTION_INDEX - 7; day_of_week_date = g_date_new_julian(g_date_get_julian(start_date)); selected_week = (selected_index - 1) / 7 == 4 ? 3 : (selected_index - 1) / 7; selected_day_of_week = selected_index - 7 * selected_week; g_date_set_day(day_of_week_date, 1); while (g_date_get_weekday(day_of_week_date) != selected_day_of_week) g_date_add_days(day_of_week_date, 1); g_date_add_days(day_of_week_date, 7 * selected_week); recurrenceSet(r, multiplier, PERIOD_NTH_WEEKDAY, day_of_week_date, WEEKEND_ADJ_NONE); } else if (day_of_month_index > LAST_DAY_OF_MONTH_OPTION_INDEX) { day_of_week_date = g_date_new_julian(g_date_get_julian(start_date)); selected_day_of_week = day_of_month_index - LAST_DAY_OF_MONTH_OPTION_INDEX; // increment until we align on the DOW, but stay inside the month g_date_set_day(day_of_week_date, 1); while (g_date_get_weekday(day_of_week_date) != selected_day_of_week) g_date_add_days(day_of_week_date, 1); recurrenceSet(r, multiplier, PERIOD_LAST_WEEKDAY, day_of_week_date, weekend_adjust); } else if (day_of_month_index == LAST_DAY_OF_MONTH_OPTION_INDEX) { GDate *day_of_month = g_date_new_julian(g_date_get_julian(start_date)); recurrenceSet(r, multiplier, PERIOD_END_OF_MONTH, day_of_month, weekend_adjust); } else { int allowable_date = -1; GDate *day_of_month = g_date_new_julian(g_date_get_julian(start_date)); allowable_date = MIN(day_of_month_index + 1, g_date_get_days_in_month(g_date_get_month(day_of_month), g_date_get_year(day_of_month))); g_date_set_day(day_of_month, allowable_date); recurrenceSet(r, multiplier, PERIOD_MONTH, day_of_month, weekend_adjust); } return r; }
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); }
static gpointer gdate_copy (gpointer boxed) { const GDate *date = (const GDate*) boxed; return g_date_new_julian (g_date_get_julian (date)); }
static gboolean check_readonly_threshold (const gchar *datestr, GDate *d) { GDate *readonly_threshold = qof_book_get_autoreadonly_gdate(gnc_get_current_book()); if (g_date_compare(d, readonly_threshold) < 0) { #if 0 gchar *dialog_msg = _("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."); gchar *dialog_title = _("Cannot store a transaction at this date"); GtkWidget *dialog = gtk_message_dialog_new(NULL, 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "%s", dialog_title); gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog), "%s", dialog_msg); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); #endif g_warning("Entered date %s is before the \"auto-read-only threshold\";" " resetting to the threshold.", datestr); // Reset the date to the threshold date g_date_set_julian (d, g_date_get_julian (readonly_threshold)); g_date_free (readonly_threshold); return TRUE; } g_date_free (readonly_threshold); return FALSE; }
static void gst_date_gulong_transform (const GValue *src, GValue *dest) { const GDate *date = gst_value_get_date (src); g_value_set_ulong (dest, (date) ? g_date_get_julian (date) : 0); }
}void gnc_gdate_set_today (GDate* gd) { GDate *today = gnc_g_date_new_today (); g_date_set_julian (gd, g_date_get_julian (today)); g_date_free (today); }
guint32 utl_date_get_current_julian (void) { GDate *d = utl_date_new_current (); guint32 julian = g_date_get_julian (d); g_date_free (d); return julian; }
guint32 utl_date_dmy_to_julian (guint day, guint month, guint year) { g_return_val_if_fail (g_date_valid_dmy (day, month, year), 0); GDate *d = g_date_new_dmy (day, month, year); guint32 julian = g_date_get_julian (d); g_date_free (d); return julian; }
/* return an julian date ... -1 = no date set */ guint32 gtodo_todo_item_get_last_edited_date_as_julian(GTodoItem *item) { if(item->last_edited == 0 ) return 1; else { GDate *date = g_date_new(); guint32 julian=1; g_date_set_time_t(date, item->last_edited); julian = g_date_get_julian(date); g_date_free(date); return julian; } }
Day * logview_utils_day_copy (Day *day) { Day *retval; retval = g_slice_new0 (Day); retval->date = g_date_new_julian (g_date_get_julian (day->date)); retval->first_line = day->first_line; retval->last_line = day->last_line; retval->timestamp_len = day->timestamp_len; return retval; }
guint32 get_current_date() { GDate *date = g_date_new (); g_date_set_time_t(date, time(NULL)); guint32 julian = g_date_get_julian (date); g_date_free(date); return julian; }
/* From GLlib 2.6. */ static guint stolen_g_date_get_iso8601_week_of_year (const GDate *d) { guint j, d4, L, d1, w; /* Formula taken from the Calendar FAQ; the formula was for the * Julian Period which starts on 1 January 4713 BC, so we add * 1,721,425 to the number of days before doing the formula. */ j = g_date_get_julian (d) + 1721425; d4 = (j + 31741 - (j % 7)) % 146097 % 36524 % 1461; L = d4 / 1460; d1 = ((d4 - L) % 365) + L; w = d1 / 7 + 1; return w; }
static void yearCriteriaGetWidgetData (GtkWidget *widget, GValue *val) { GDate *date = NULL; gint num = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (widget)); guint32 display_date; g_assert (num >= 0); g_value_init (val, G_TYPE_ULONG); if (num != 0) { /* New date structure, use year set in widget */ date = g_date_new_dmy (1, G_DATE_JANUARY, num); display_date = g_date_get_julian (date); g_date_free(date); } else { display_date = 0; } g_value_set_ulong (val, (gulong)display_date); }
void cal_remove_note (GDate *date, GUI *appGUI) { GSList *lnode; struct note *a; gint i; if (appGUI->cal->notes_list == NULL) return; for (i = 0, lnode = appGUI->cal->notes_list; lnode != NULL; lnode = lnode->next, i++) { a = g_slist_nth_data (appGUI->cal->notes_list, i); if (a->date == g_date_get_julian (date)) { if (a->color != NULL) g_free (a->color); if (a->note != NULL) g_free (a->note); appGUI->cal->notes_list = g_slist_remove (appGUI->cal->notes_list, a); break; } } }
gchar * cal_get_note (GDate *date, GUI *appGUI) { GSList *lnode; struct note *a; gint i; if (appGUI->cal->notes_list != NULL) { for (i = 0, lnode = appGUI->cal->notes_list; lnode != NULL; lnode = lnode->next, i++) { a = g_slist_nth_data (appGUI->cal->notes_list, i); if (a->date == g_date_get_julian (date)) return a->note; } } return NULL; }
void cal_add_note (GDate *date, gchar *color_str, gchar *text_note, GUI *appGUI) { struct note *a; g_return_if_fail (text_note != NULL); a = g_malloc (sizeof (struct note)); g_assert (a != NULL); a->date = g_date_get_julian (date); a->day = g_date_get_day (date); a->month = g_date_get_month (date); a->year = g_date_get_year (date); a->color = (color_str != NULL) ? g_strdup (color_str) : NULL; a->note = g_strdup (text_note); cal_remove_note (date, appGUI); appGUI->cal->notes_list = g_slist_append (appGUI->cal->notes_list, a); }
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; }
void gnc_frequency_save_to_recurrence(GncFrequency *gf, GList **recurrences, GDate *out_start_date) { GDate start_date; gint page_index; gnc_date_edit_get_gdate(gf->startDate, &start_date); if (out_start_date != NULL) *out_start_date = start_date; if (recurrences == NULL) return; page_index = gtk_notebook_get_current_page(gf->nb); switch (page_index) { case PAGE_NONE: { // empty-recurrence list ~~ none. } break; case PAGE_ONCE: { Recurrence *r = g_new0(Recurrence, 1); recurrenceSet(r, 1, PERIOD_ONCE, &start_date, WEEKEND_ADJ_NONE); *recurrences = g_list_append(*recurrences, r); } break; case PAGE_DAILY: { gint multiplier = _get_multiplier_from_widget(gf, "daily_spin"); Recurrence *r = g_new0(Recurrence, 1); recurrenceSet(r, multiplier, PERIOD_DAY, &start_date, WEEKEND_ADJ_NONE); *recurrences = g_list_append(*recurrences, r); } break; case PAGE_WEEKLY: { int multiplier = _get_multiplier_from_widget(gf, "weekly_spin"); int checkbox_idx; for (checkbox_idx = 0; CHECKBOX_NAMES[checkbox_idx] != NULL; checkbox_idx++) { GDate *day_of_week_aligned_date; Recurrence *r; const char *day_widget_name = CHECKBOX_NAMES[checkbox_idx]; GtkWidget *weekday_checkbox = glade_xml_get_widget(gf->gxml, day_widget_name); if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(weekday_checkbox))) continue; day_of_week_aligned_date = g_date_new_julian(g_date_get_julian(&start_date)); // increment until we align on the DOW. while ((g_date_get_weekday(day_of_week_aligned_date) % 7) != checkbox_idx) g_date_add_days(day_of_week_aligned_date, 1); r = g_new0(Recurrence, 1); recurrenceSet(r, multiplier, PERIOD_WEEK, day_of_week_aligned_date, WEEKEND_ADJ_NONE); *recurrences = g_list_append(*recurrences, r); } } break; case PAGE_SEMI_MONTHLY: { int multiplier = _get_multiplier_from_widget(gf, "semimonthly_spin"); *recurrences = g_list_append(*recurrences, _get_day_of_month_recurrence(gf, &start_date, multiplier, "semimonthly_first", "semimonthly_first_weekend")); *recurrences = g_list_append(*recurrences, _get_day_of_month_recurrence(gf, &start_date, multiplier, "semimonthly_second", "semimonthly_second_weekend")); } break; case PAGE_MONTHLY: { int multiplier = _get_multiplier_from_widget(gf, "monthly_spin"); Recurrence *r = _get_day_of_month_recurrence(gf, &start_date, multiplier, "monthly_day", "monthly_weekend"); *recurrences = g_list_append(*recurrences, r); } break; default: g_error("unknown page index [%d]", page_index); break; } }
/* This is the only real algorithm related to recurrences. It goes: Step 1) Go forward one period from the reference date. Step 2) Back up to align to the phase of the start date. */ void recurrenceNextInstance(const Recurrence *r, const GDate *ref, GDate *next) { PeriodType pt; const GDate *start; guint mult; WeekendAdjust wadj; g_return_if_fail(r); g_return_if_fail(ref); g_return_if_fail(g_date_valid(&r->start)); g_return_if_fail(g_date_valid(ref)); /* If the ref date comes before the start date then the next occurrence is always the start date, and we're done. */ start = &r->start; if (g_date_compare(ref, start) < 0) { g_date_set_julian(next, g_date_get_julian(start)); return; } g_date_set_julian(next, g_date_get_julian(ref)); /* start at refDate */ /* Step 1: move FORWARD one period, passing exactly one occurrence. */ mult = r->mult; pt = r->ptype; wadj = r->wadj; switch (pt) { case PERIOD_YEAR: mult *= 12; /* fall through */ case PERIOD_MONTH: case PERIOD_NTH_WEEKDAY: case PERIOD_LAST_WEEKDAY: case PERIOD_END_OF_MONTH: /* Takes care of short months. */ if (r->wadj == WEEKEND_ADJ_BACK && (pt == PERIOD_YEAR || pt == PERIOD_MONTH || pt == PERIOD_END_OF_MONTH) && (g_date_get_weekday(next) == G_DATE_SATURDAY || g_date_get_weekday(next) == G_DATE_SUNDAY)) { /* Allows the following Friday-based calculations to proceed if 'next' is between Friday and the target day. */ g_date_subtract_days(next, g_date_get_weekday(next) == G_DATE_SATURDAY ? 1 : 2); } if (r->wadj == WEEKEND_ADJ_BACK && (pt == PERIOD_YEAR || pt == PERIOD_MONTH || pt == PERIOD_END_OF_MONTH) && g_date_get_weekday(next) == G_DATE_FRIDAY) { GDate tmp_sat; GDate tmp_sun; g_date_set_julian(&tmp_sat, g_date_get_julian(next)); g_date_set_julian(&tmp_sun, g_date_get_julian(next)); g_date_add_days(&tmp_sat, 1); g_date_add_days(&tmp_sun, 2); if (pt == PERIOD_END_OF_MONTH) { if (g_date_is_last_of_month(next) || g_date_is_last_of_month(&tmp_sat) || g_date_is_last_of_month(&tmp_sun)) g_date_add_months(next, mult); else /* one fewer month fwd because of the occurrence in this month */ g_date_add_months(next, mult - 1); } else { if (g_date_get_day(&tmp_sat) == g_date_get_day(start)) { g_date_add_days(next, 1); g_date_add_months(next, mult); } else if (g_date_get_day(&tmp_sun) == g_date_get_day(start)) { g_date_add_days(next, 2); g_date_add_months(next, mult); } else if (g_date_get_day(next) >= g_date_get_day(start)) { g_date_add_months(next, mult); } else if (g_date_is_last_of_month(next)) { g_date_add_months(next, mult); } else if (g_date_is_last_of_month(&tmp_sat)) { g_date_add_days(next, 1); g_date_add_months(next, mult); } else if (g_date_is_last_of_month(&tmp_sun)) { g_date_add_days(next, 2); g_date_add_months(next, mult); } else { /* one fewer month fwd because of the occurrence in this month */ g_date_add_months(next, mult - 1); } } } else if ( g_date_is_last_of_month(next) || ((pt == PERIOD_MONTH || pt == PERIOD_YEAR) && g_date_get_day(next) >= g_date_get_day(start)) || ((pt == PERIOD_NTH_WEEKDAY || pt == PERIOD_LAST_WEEKDAY) && nth_weekday_compare(start, next, pt) <= 0) ) g_date_add_months(next, mult); else /* one fewer month fwd because of the occurrence in this month */ g_date_add_months(next, mult - 1); break; case PERIOD_WEEK: mult *= 7; /* fall through */ case PERIOD_DAY: g_date_add_days(next, mult); break; case PERIOD_ONCE: g_date_clear(next, 1); /* We already caught the case where ref is */ return; /* earlier than start, so this is invalid. */ default: PERR("Invalid period type"); break; } /* Step 2: Back up to align to the base phase. To ensure forward progress, we never subtract as much as we added (x % mult < mult). */ switch (pt) { case PERIOD_YEAR: case PERIOD_MONTH: case PERIOD_NTH_WEEKDAY: case PERIOD_LAST_WEEKDAY: case PERIOD_END_OF_MONTH: { guint dim, n_months; n_months = 12 * (g_date_get_year(next) - g_date_get_year(start)) + (g_date_get_month(next) - g_date_get_month(start)); g_date_subtract_months(next, n_months % mult); /* Ok, now we're in the right month, so we just have to align the day in one of the three possible ways. */ dim = g_date_get_days_in_month(g_date_get_month(next), g_date_get_year(next)); if (pt == PERIOD_LAST_WEEKDAY || pt == PERIOD_NTH_WEEKDAY) { gint wdresult = nth_weekday_compare(start, next, pt); if (wdresult < 0) { wdresult = -wdresult; g_date_subtract_days(next, wdresult); } else g_date_add_days(next, wdresult); } else if (pt == PERIOD_END_OF_MONTH || g_date_get_day(start) >= dim) g_date_set_day(next, dim); /* last day in the month */ else g_date_set_day(next, g_date_get_day(start)); /*same day as start*/ /* Adjust for dates on the weekend. */ if (pt == PERIOD_YEAR || pt == PERIOD_MONTH || pt == PERIOD_END_OF_MONTH) { if (g_date_get_weekday(next) == G_DATE_SATURDAY || g_date_get_weekday(next) == G_DATE_SUNDAY) { switch (wadj) { case WEEKEND_ADJ_BACK: g_date_subtract_days(next, g_date_get_weekday(next) == G_DATE_SATURDAY ? 1 : 2); break; case WEEKEND_ADJ_FORWARD: g_date_add_days(next, g_date_get_weekday(next) == G_DATE_SATURDAY ? 2 : 1); break; case WEEKEND_ADJ_NONE: default: break; } } } } break; case PERIOD_WEEK: case PERIOD_DAY: g_date_subtract_days(next, g_date_days_between(start, next) % mult); break; default: PERR("Invalid period type"); break; } }
static RhythmDBEntry * add_mtp_track_to_db (RBMtpSource *source, RhythmDB *db, LIBMTP_track_t *track) { RhythmDBEntry *entry = NULL; RhythmDBEntryType *entry_type; RBMtpSourcePrivate *priv = MTP_SOURCE_GET_PRIVATE (source); char *name = NULL; /* ignore everything except audio (allow audio/video types too, since they're probably pretty common) */ if (!(LIBMTP_FILETYPE_IS_AUDIO (track->filetype) || LIBMTP_FILETYPE_IS_AUDIOVIDEO (track->filetype))) { rb_debug ("ignoring non-audio item %d (filetype %s)", track->item_id, LIBMTP_Get_Filetype_Description (track->filetype)); return NULL; } /* Set URI */ g_object_get (G_OBJECT (source), "entry-type", &entry_type, NULL); name = g_strdup_printf ("xrbmtp://%i/%s", track->item_id, track->filename); entry = rhythmdb_entry_new (RHYTHMDB (db), entry_type, name); g_free (name); g_object_unref (entry_type); if (entry == NULL) { rb_debug ("cannot create entry %i", track->item_id); g_object_unref (G_OBJECT (db)); return NULL; } /* Set track number */ if (track->tracknumber != 0) { GValue value = {0, }; g_value_init (&value, G_TYPE_ULONG); g_value_set_ulong (&value, track->tracknumber); rhythmdb_entry_set (RHYTHMDB (db), entry, RHYTHMDB_PROP_TRACK_NUMBER, &value); g_value_unset (&value); } /* Set length */ if (track->duration != 0) { GValue value = {0, }; g_value_init (&value, G_TYPE_ULONG); g_value_set_ulong (&value, track->duration/1000); rhythmdb_entry_set (RHYTHMDB (db), entry, RHYTHMDB_PROP_DURATION, &value); g_value_unset (&value); } /* Set file size */ if (track->filesize != 0) { GValue value = {0, }; g_value_init (&value, G_TYPE_UINT64); g_value_set_uint64 (&value, track->filesize); rhythmdb_entry_set (RHYTHMDB (db), entry, RHYTHMDB_PROP_FILE_SIZE, &value); g_value_unset (&value); } /* Set playcount */ if (track->usecount != 0) { GValue value = {0, }; g_value_init (&value, G_TYPE_ULONG); g_value_set_ulong (&value, track->usecount); rhythmdb_entry_set (RHYTHMDB (db), entry, RHYTHMDB_PROP_PLAY_COUNT, &value); g_value_unset (&value); } /* Set rating */ if (track->rating != 0) { GValue value = {0, }; g_value_init (&value, G_TYPE_DOUBLE); g_value_set_double (&value, track->rating/20); rhythmdb_entry_set (RHYTHMDB (db), entry, RHYTHMDB_PROP_RATING, &value); g_value_unset (&value); } /* Set release date */ if (track->date != NULL && track->date[0] != '\0') { GTimeVal tv; if (g_time_val_from_iso8601 (track->date, &tv)) { GDate d; GValue value = {0, }; g_value_init (&value, G_TYPE_ULONG); g_date_set_time_val (&d, &tv); g_value_set_ulong (&value, g_date_get_julian (&d)); rhythmdb_entry_set (RHYTHMDB (db), entry, RHYTHMDB_PROP_DATE, &value); g_value_unset (&value); } } /* Set title */ entry_set_string_prop (RHYTHMDB (db), entry, RHYTHMDB_PROP_TITLE, track->title); /* Set album, artist and genre from MTP */ entry_set_string_prop (RHYTHMDB (db), entry, RHYTHMDB_PROP_ARTIST, track->artist); entry_set_string_prop (RHYTHMDB (db), entry, RHYTHMDB_PROP_ALBUM, track->album); entry_set_string_prop (RHYTHMDB (db), entry, RHYTHMDB_PROP_GENRE, track->genre); g_hash_table_insert (priv->entry_map, entry, track); rhythmdb_commit (RHYTHMDB (db)); return entry; }
static void annum_shell_view_date_navigator_selection_changed_cb (AnnumShellView * self, ECalendarItem * calitem) { AnnumShellContent *prox_shell_content; GnomeCalendarViewType switch_to; GnomeCalendarViewType view_type; GnomeCalendar *calendar; ECalModel *model; GDate start_date, end_date; GDate new_start_date, new_end_date; icaltimetype tt; icaltimezone *timezone; time_t start, end, new_time; gboolean starts_on_week_start_day; gint new_days_shown; gint week_start_day; prox_shell_content = self->priv->prox_shell_content; calendar = annum_shell_content_get_calendar (prox_shell_content); model = gnome_calendar_get_model (calendar); view_type = gnome_calendar_get_view (calendar); switch_to = view_type; timezone = e_cal_model_get_timezone (model); week_start_day = e_cal_model_get_week_start_day (model); e_cal_model_get_time_range (model, &start, &end); time_to_gdate_with_zone (&start_date, start, timezone); time_to_gdate_with_zone (&end_date, end, timezone); if (view_type == GNOME_CAL_MONTH_VIEW) { EWeekView *week_view; ECalendarView *calendar_view; gboolean multi_week_view; gboolean compress_weekend; calendar_view = gnome_calendar_get_calendar_view (calendar, GNOME_CAL_MONTH_VIEW); week_view = E_WEEK_VIEW (calendar_view); multi_week_view = e_week_view_get_multi_week_view (week_view); compress_weekend = e_week_view_get_compress_weekend (week_view); if (week_start_day == 0 && (!multi_week_view || compress_weekend)) g_date_add_days (&start_date, 1); } g_date_subtract_days (&end_date, 1); e_calendar_item_get_selection (calitem, &new_start_date, &new_end_date); /* There used to be a check here to make sure the rest of the * code only ran when the date actually changed. We do not * this to simplify always having three columns for the day * view. */ new_days_shown = g_date_get_julian (&new_end_date) - g_date_get_julian (&new_start_date) + 1; /* If a complete week is selected we show the week view. * Note that if weekends are compressed and the week start * day is set to Sunday, we don't actually show complete * weeks in the week view, so this may need tweaking. */ starts_on_week_start_day = (g_date_get_weekday (&new_start_date) % 7 == week_start_day); /* Update selection to be in the new time range. */ tt = icaltime_null_time (); tt.year = g_date_get_year (&new_start_date); tt.month = g_date_get_month (&new_start_date); tt.day = g_date_get_day (&new_start_date); new_time = icaltime_as_timet_with_zone (tt, timezone); /* Switch views as appropriate, and change the number of * days or weeks shown. */ if (new_days_shown > 9) { if (view_type != GNOME_CAL_LIST_VIEW) { ECalendarView *calendar_view; calendar_view = gnome_calendar_get_calendar_view (calendar, GNOME_CAL_MONTH_VIEW); e_week_view_set_weeks_shown (E_WEEK_VIEW (calendar_view), (new_days_shown + 6) / 7); switch_to = GNOME_CAL_MONTH_VIEW; } } else if (new_days_shown == 7 && starts_on_week_start_day) switch_to = GNOME_CAL_WEEK_VIEW; else { ECalendarView *calendar_view; calendar_view = gnome_calendar_get_calendar_view (calendar, GNOME_CAL_DAY_VIEW); /* We always show three days */ if (new_days_shown == 1) new_days_shown = 3; e_day_view_set_days_shown (E_DAY_VIEW (calendar_view), new_days_shown); if (new_days_shown != 5 || !starts_on_week_start_day) switch_to = GNOME_CAL_DAY_VIEW; else if (view_type != GNOME_CAL_WORK_WEEK_VIEW) switch_to = GNOME_CAL_DAY_VIEW; } /* Make the views display things properly. */ gnome_calendar_update_view_times (calendar, new_time); gnome_calendar_set_view (calendar, switch_to); gnome_calendar_set_range_selected (calendar, TRUE); gnome_calendar_notify_dates_shown_changed (calendar); g_signal_emit (self, signals[DATE_CHANGED], 0, switch_to); }
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); }
gboolean gtodo_client_save_todo_item(GTodoClient *cl, GTodoItem *item) { xmlNodePtr cur = cl->root->xmlChildrenNode; if(!gtodo_client_category_exists(cl, item->category)) { gtodo_client_category_new(cl, item->category); } while (cur != NULL) { xmlChar *temp2; temp2 = xmlGetProp(cur, (const xmlChar *)"title"); if(xmlStrEqual(temp2, (xmlChar *)item->category)) { gchar *temp1; xmlNodePtr newn, newa; newn = xmlNewChild(cur, NULL, (xmlChar *)"item", NULL); /* id */ newa = xmlNewChild(newn, NULL, (xmlChar *)"attribute", NULL); temp1 = g_strdup_printf("%i", item->id); xmlSetProp(newa, (xmlChar *)"id", (xmlChar *)temp1); g_free(temp1); /* priority */ temp1 = g_strdup_printf("%i", item->priority); xmlSetProp(newa, (xmlChar *)"priority", (xmlChar *)temp1); g_free(temp1); /* done */ temp1 = g_strdup_printf("%i", item->done); xmlSetProp(newa, (xmlChar *)"done", (xmlChar *)temp1); g_free(temp1); /* START_DATE */ /* if new item .. nothing is done yet */ if(item->start != NULL) { guint32 julian = g_date_get_julian(item->start); temp1 = g_strdup_printf("%u", julian); xmlSetProp(newa, (xmlChar *)"start_date", (xmlChar *)temp1); g_free(temp1); } /*( COMPLETED_DATE */ if(item->stop != NULL && item->done) { guint32 julian = g_date_get_julian(item->stop); temp1 = g_strdup_printf("%u", julian); xmlSetProp(newa, (xmlChar *)"completed_date", (xmlChar *)temp1); g_free(temp1); } /* enddate (to the start date attribute) */ if(item->due != NULL) { guint32 julian = g_date_get_julian(item->due); temp1 = g_strdup_printf("%u", julian); xmlSetProp(newa, (xmlChar *)"enddate", (xmlChar *)temp1); g_free(temp1); } /* enddate (to the start date attribute) */ { temp1 = g_strdup_printf("%i", (gint)item->notify); xmlSetProp(newa, (xmlChar *)"notify", (xmlChar *)temp1); g_free(temp1); } /* endtime (to the start date attribute) */ if(item->due != NULL) { temp1 = g_strdup_printf("%i", (item->due_time[GTODO_DUE_TIME_HOURE]*60)+item->due_time[GTODO_DUE_TIME_MINUTE]); xmlSetProp(newa, (xmlChar *)"endtime", (xmlChar *)temp1); g_free(temp1); } /* last edited (to the start date attribute) */ { temp1 = g_strdup_printf("%u", time(NULL)); xmlSetProp(newa, (xmlChar *)"last_edited", (xmlChar *)temp1); g_free(temp1); } /* summary */ newa = xmlNewChild(newn, NULL, (xmlChar *)"summary", (xmlChar *)item->summary); /* comment */ newa = xmlNewChild(newn, NULL, (xmlChar *)"comment", (xmlChar *)item->comment); } g_free(temp2); cur = cur->next; } gtodo_client_save_xml(cl,NULL); return TRUE; }