void CalendarDatePrivate::updateMonthView(gboolean isForceLoad, GTimeSpan changed) { if (NULL == m_swipeBox[VIEWTYPE_MONTH]) { initMonthView(); } int row = 0; int col = 0; int rowCount = 3; int colCount = 4; int cellWidth = MAIN_BOX_DEFAULT_WIDTH / colCount; int cellHeight = MAIN_BOX_DEFAULT_WIDTH / rowCount; GDateTime* nowDate = g_date_time_new_now_local(); m_viewType = VIEWTYPE_MONTH; GDateTime* selectedDate = g_date_time_new_local(m_selectedYear, m_selectedMonth, m_selectedDayOfMonth, 1, 1, 1); gchar* dateLabelText = g_date_time_format(selectedDate, C_("calendar heading", "%Y")); gtk_button_set_label(GTK_BUTTON(m_viewTypeSwitch), dateLabelText); g_date_time_unref(selectedDate); g_free(dateLabelText); for (row = 0; row < rowCount; ++row) { for (col = 0; col < colCount; ++col) { int index = row * colCount + col; if (NULL != m_monthItem[index]) { m_monthItem[index]->addStyleClass("calendar-month-base"); m_monthItem[index]->addStyleClass("calendar-month"); GDateTime* currentDate = g_date_time_new_local(m_selectedYear, index + 1, 1, 0, 0, 0); if (isTheSameMonth(nowDate, currentDate)) { m_monthItem[index]->addStyleClass("calendar-current-month"); } else { m_monthItem[index]->removeStyleClass("calendar-current-month"); } g_date_time_unref(currentDate); m_monthItem[index]->setValue(index + 1); } } } if (NULL != m_swipeBox[VIEWTYPE_MONTH]) { gtk_widget_show_all(m_swipeBox[VIEWTYPE_MONTH]); } if (NULL != m_swipeBox[VIEWTYPE_YEAR]) { gtk_widget_hide(m_swipeBox[VIEWTYPE_YEAR]); } if (NULL != m_swipeBox[VIEWTYPE_DAY]) { gtk_widget_hide(m_swipeBox[VIEWTYPE_DAY]); } apply_css(GTK_WIDGET(m_actor), m_provider); }
void CalendarDatePrivate::initMonthView() { GtkWidget* swipebox = NULL; int row = 0; int col = 0; int rowCount = 3; int colCount = 4; GDateTime* nowDate = g_date_time_new_now_local(); int selectedYear = m_selectedYear; int cellWidth = MAIN_BOX_DEFAULT_WIDTH / colCount; int cellHeight = MAIN_BOX_DEFAULT_WIDTH / rowCount; m_swipeBox[VIEWTYPE_MONTH] = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); swipebox = m_swipeBox[VIEWTYPE_MONTH]; gtk_fixed_put(GTK_FIXED(m_mainBox), GTK_WIDGET(m_swipeBox[VIEWTYPE_MONTH]), 0, 0); gtk_widget_set_name(GTK_WIDGET(swipebox), "calendar-table"); GDateTime* selectedDate = g_date_time_new_local(m_selectedYear, m_selectedMonth, m_selectedDayOfMonth, 1, 1, 1); gchar* dateLabelText = g_date_time_format(selectedDate, C_("calendar heading", "%Y")); gtk_button_set_label(GTK_BUTTON(m_viewTypeSwitch), dateLabelText); g_date_time_unref(selectedDate); g_free(dateLabelText); for (row = 0; row < rowCount; ++row) { GtkWidget* monthlayout = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); for (col = 0; col < colCount; ++col) { int index = row * colCount + col; m_monthItem[index] = new CalendarItem(ITEMTYPE_MONTH, index + 1); m_monthItem[index]->setOnClickedListener(this); m_monthItem[index]->setSize(cellWidth, cellHeight); m_monthItem[index]->setParent(GTK_WIDGET(monthlayout)); } gtk_box_pack_start(GTK_BOX(swipebox), GTK_WIDGET(monthlayout), TRUE, TRUE, 0); } }
static guint calculate_seconds_until_next_minute (void) { guint seconds; GTimeSpan diff; GDateTime * now; GDateTime * next; GDateTime * start_of_next; now = g_date_time_new_now_local (); next = g_date_time_add_minutes (now, 1); start_of_next = g_date_time_new_local (g_date_time_get_year (next), g_date_time_get_month (next), g_date_time_get_day_of_month (next), g_date_time_get_hour (next), g_date_time_get_minute (next), 1); diff = g_date_time_difference (start_of_next, now); seconds = (diff + (G_TIME_SPAN_SECOND - 1)) / G_TIME_SPAN_SECOND; /* cleanup */ g_date_time_unref (start_of_next); g_date_time_unref (next); g_date_time_unref (now); return seconds; }
GstDateTime * gst_date_time_new_local_time (gint year, gint month, gint day, gint hour, gint minute, gdouble seconds) { return gst_date_time_new_from_gdatetime (g_date_time_new_local (year, month, day, hour, minute, seconds)); }
static void _chatwin_history(ProfChatWin *chatwin, const char *const contact) { if (!chatwin->history_shown) { Jid *jid = jid_create(jabber_get_fulljid()); GSList *history = chat_log_get_previous(jid->barejid, contact); jid_destroy(jid); GSList *curr = history; while (curr) { char *line = curr->data; // entry if (line[2] == ':') { char hh[3]; memcpy(hh, &line[0], 2); hh[2] = '\0'; int ihh = atoi(hh); char mm[3]; memcpy(mm, &line[3], 2); mm[2] = '\0'; int imm = atoi(mm); char ss[3]; memcpy(ss, &line[6], 2); ss[2] = '\0'; int iss = atoi(ss); GDateTime *timestamp = g_date_time_new_local(2000, 1, 1, ihh, imm, iss); win_print((ProfWin*)chatwin, '-', 0, timestamp, NO_COLOUR_DATE, 0, "", curr->data+11); g_date_time_unref(timestamp); // header } else { win_print((ProfWin*)chatwin, '-', 0, NULL, 0, 0, "", curr->data); } curr = g_slist_next(curr); } chatwin->history_shown = TRUE; g_slist_free_full(history, free); } }
/** * itl_prayer_getNextDayFajr: * * @prayer: (in): an #ItlPrayer * @cdate: (in): Date for which to calculate Fajr for the day after * * This function calculates prayer times for the given date * * Return value: (transfer full): DateTime struct for next day fajr time */ GDateTime * itl_prayer_getNextDayFajr (ItlPrayer *prayer, GDate *cdate) { Date ITLDate; Prayer cPrayer; GDateTime *NextDayFajr; g_return_val_if_fail (GOBJECT_IS_PRAYER (prayer), 0); g_object_ref (prayer); ITLDate.day = g_date_get_day(cdate); ITLDate.month = g_date_get_month(cdate); ITLDate.year = g_date_get_year(cdate); getNextDayFajr (&prayer->priv->loc, &prayer->priv->method, &ITLDate, &cPrayer); NextDayFajr = g_date_time_new_local(ITLDate.year, ITLDate.month, ITLDate.day, cPrayer.hour, cPrayer.minute, cPrayer.second); g_object_unref (prayer); return(NextDayFajr); }
static GDateTime* gnc_g_date_time_new_local (gint year, gint month, gint day, gint hour, gint minute, gdouble seconds) { #ifndef G_OS_WIN32 return g_date_time_new_local (year, month, day, hour, minute, seconds); #else GTimeZone *tz = gnc_g_time_zone_new_local(); GDateTime *gdt = g_date_time_new (tz, year, month, day, hour, minute, seconds); if (!gdt) return gdt; tz = gnc_g_time_zone_adjust_for_dst (tz, gdt); g_date_time_unref (gdt); /* g_date_time_new truncates nanoseconds to microseconds. Sometimes in * converting (particularly when parsing from a string) the * nanoseconds will have lost 1/2 a femtosecond or so. Adding 1/2 a * nano second ensures that the truncation doesn't lose a micorsecond * in translation. */ seconds += 5e-10; gdt = g_date_time_new (tz, year, month, day, hour, minute, seconds); g_time_zone_unref (tz); return gdt; #endif }
void CalendarDatePrivate::onClicked(CalendarItem* item) { if (NULL == item) { return; } ItemType itemOpt = item->getType(); int itemData = item->getValue(); int newYear = m_selectedYear; int newMonth = m_selectedMonth; int newDayOfMonth = m_selectedDayOfMonth; switch (m_viewType) { case VIEWTYPE_DAY: break; case VIEWTYPE_MONTH: g_return_if_fail(ITEMTYPE_MONTH == itemOpt); newMonth = itemData; updateDayView(FALSE, 0); break; case VIEWTYPE_YEAR: g_return_if_fail(ITEMTYPE_YEAR == itemOpt); newYear = itemData; updateMonthView(FALSE, 0); break; default: break; } GDateTime * newDate = g_date_time_new_local(newYear, newMonth, newDayOfMonth, 0, 0, 0); setDate(newDate, FALSE, 0); g_date_time_unref(newDate); }
void CalendarDatePrivate::applyDateBrowseAction(int yearChange, int monthChange) { GtkWidget* swipebox = NULL; switch (m_viewType) { case VIEWTYPE_DAY: swipebox = m_swipeBox[0]; break; case VIEWTYPE_MONTH: swipebox = m_swipeBox[1]; break; case VIEWTYPE_YEAR: swipebox = m_swipeBox[2]; break; default: break; } g_return_if_fail(NULL != swipebox); gint oldYear = m_selectedYear; gint oldMonth = m_selectedMonth; gint oldDayOfMonth = m_selectedDayOfMonth; gint newMonth = oldMonth + monthChange; if (12 < newMonth) { yearChange = yearChange + 1; newMonth = 1; } else if (1 > newMonth) { yearChange = yearChange - 1; newMonth = 12; } gint newYear = oldYear + yearChange; gint newDayOfMonth = oldDayOfMonth; int newMonthLength = month_length[leap(newYear)][newMonth]; if (newMonthLength < newDayOfMonth) { newDayOfMonth = newMonthLength; } GDateTime * oldDate = g_date_time_new_local(oldYear, oldMonth, oldDayOfMonth, 0, 0, 0); GDateTime * newDate = g_date_time_new_local(newYear, newMonth, newDayOfMonth, 0, 0, 0); setDate(newDate, FALSE, g_date_time_difference(oldDate, newDate)); g_date_time_unref(newDate); g_date_time_unref(oldDate); }
guint CalendarDatePrivate::weekOfYear(guint year, guint mm, guint dd) { GDateTime * dt; guint week; dt = g_date_time_new_local(year, mm, dd, 1, 1, 1); if (NULL == dt) { return 0; } week = g_date_time_get_week_of_year(dt); g_date_time_unref(dt); return week; }
guint CalendarDatePrivate::dayOfWeek(guint year, guint mm, guint dd) { GDateTime * dt; guint days; dt = g_date_time_new_local(year, mm, dd, 1, 1, 1); if (NULL == dt) { return 0; } days = g_date_time_get_day_of_week(dt); g_date_time_unref(dt); return days; }
//-------------------------------------------------------------------- // // 函数功能 :对日期字符串转换为从1970-01-01 00:00:00 UTC开始的秒数。 // 支持格式为: // 1. YYYY-mm-DD HH:MM:SS; // 2. YYYY-mm-DD HH:MM; // 3. YYYY/mm/DD HH:MM:SS; // 4. YYYY/mm/DD HH:MM; // // 函数参数 :gchar* strdate : 日期字符串。 // // 返回值 :gint64 : 对应秒数或0(非法日期格式)。 // // 用法示例 :getStrDate2Int ( "2014-01-01 00:00:00" ); // 返回 : 1388505600 // // 修改记录 : // //-------------------------------------------------------------------- gint64 getStrDate2Int ( gchar *strdate ) { gchar **datetime = g_strsplit ( strdate, " ", 0 ); GDateTime *dt = NULL; if ( g_strv_length(datetime) == 2 ) { gint year, month, day, hour, minute, second; gchar **dates1 = g_strsplit ( datetime[0], "-", 0 ); gchar **dates2 = g_strsplit ( datetime[0], "/", 0 ); if ( g_strv_length(dates1) == 3 ) { year = atoi ( dates1[0] ); month = atoi ( dates1[1] ); day = atoi ( dates1[2] ); } else if ( g_strv_length(dates2) == 3 ) { year = atoi ( dates2[2] ); month = atoi ( dates2[1] ); day = atoi ( dates2[0] ); } else { g_strfreev ( dates1 ); g_strfreev ( dates2 ); g_strfreev ( datetime ); return 0; } gchar **times = g_strsplit ( datetime[1], ":", 0 ); if ( g_strv_length(times) == 3 ) { hour = atoi ( times[0] ); minute = atoi ( times[1] ); second = atoi ( times[2] ); } else if ( g_strv_length(times) == 2 ) { hour = atoi ( times[0] ); minute = atoi ( times[1] ); second = 0; } else { g_strfreev ( times ); g_strfreev ( dates1 ); g_strfreev ( dates2 ); g_strfreev ( datetime ); return 0; } dt = g_date_time_new_local ( year, month, day, hour, minute, second ); g_strfreev ( dates1 ); g_strfreev ( dates2 ); g_strfreev ( times ); g_strfreev ( datetime ); return g_date_time_to_unix ( dt ); } g_strfreev ( datetime ); return 0; }
OgRecord * og_record_new (guint year, guint month, guint day, guint hour, guint minute, guint glycemia) { OgRecord *self; self = g_slice_new0 (OgRecord); self->datetime = g_date_time_new_local (year, month, day, hour, minute, 0); self->glycemia = glycemia; return self; }
void gcal_time_selector_set_time (GcalTimeSelector *selector, GDateTime *time) { g_return_if_fail (GCAL_IS_TIME_SELECTOR (selector)); if (selector->time != time) { gint hour, minute; g_clear_pointer (&selector->time, g_date_time_unref); selector->time = g_date_time_new_local (g_date_time_get_year (time), g_date_time_get_month (time), g_date_time_get_day_of_month (time), g_date_time_get_hour (time), g_date_time_get_minute (time), 0); /* Update the spinners */ g_signal_handlers_block_by_func (selector->hour_adjustment, update_time, selector); g_signal_handlers_block_by_func (selector->minute_adjustment, update_time, selector); hour = g_date_time_get_hour (time); minute = g_date_time_get_minute (time); if (!selector->format_24h) { g_signal_handlers_block_by_func (selector->period_combo, update_time, selector); gtk_combo_box_set_active (GTK_COMBO_BOX (selector->period_combo), hour >= 12); hour = hour % 12; hour = (hour == 0)? 12 : hour; g_signal_handlers_unblock_by_func (selector->period_combo, update_time, selector); } gtk_adjustment_set_value (selector->hour_adjustment, hour); gtk_adjustment_set_value (selector->minute_adjustment, minute); update_label (selector); g_signal_handlers_unblock_by_func (selector->hour_adjustment, update_time, selector); g_signal_handlers_unblock_by_func (selector->minute_adjustment, update_time, selector); g_object_notify (G_OBJECT (selector), "time"); } }
char * cc_util_get_smart_date (GDateTime *date) { gchar *label; GDateTime *today, *local; GTimeSpan span; /* Set today date */ local = g_date_time_new_now_local (); today = g_date_time_new_local (g_date_time_get_year (local), g_date_time_get_month (local), g_date_time_get_day_of_month (local), 0, 0, 0); span = g_date_time_difference (today, date); if (span <= 0) { label = g_strdup (_("Today")); } else if (span <= G_TIME_SPAN_DAY) { label = g_strdup (_("Yesterday")); } else { if (g_date_time_get_year (date) == g_date_time_get_year (today)) { /* Translators: This is a date format string in the style of "Feb 24". */ label = g_date_time_format (date, _("%b %e")); } else { /* Translators: This is a date format string in the style of "Feb 24, 2013". */ label = g_date_time_format (date, _("%b %e, %Y")); } } g_date_time_unref (local); g_date_time_unref (today); return label; }
static void change_date (CcDateTimePanel *self) { CcDateTimePanelPrivate *priv = self->priv; guint mon, y, d; GDateTime *old_date; old_date = priv->date; mon = 1 + gtk_combo_box_get_active (GTK_COMBO_BOX (W ("month-combobox"))); y = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (W ("year-spinbutton"))); d = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (W ("day-spinbutton"))); priv->date = g_date_time_new_local (y, mon, d, g_date_time_get_hour (old_date), g_date_time_get_minute (old_date), g_date_time_get_second (old_date)); g_date_time_unref (old_date); queue_set_datetime (self); }
/** * itl_prayer_getPrayerTimes: * * @prayer: (in): an #ItlPrayer * @cdate: (in): Date for which to calculate prayer times * * This function calculates prayer times for the given date * * Return value: (transfer full) (element-type GLib.DateTime): 6 prayer times from Fajr till Isha' */ GList * itl_prayer_getPrayerTimes (ItlPrayer *prayer, GDate *cdate) { Date ITLDate; GDateTime *fajr, *shurooq, *dhuhr, *asr, *maghrib, *isha; GList *Prayers=NULL; Prayer ITLPrayer[6]; g_return_val_if_fail (GOBJECT_IS_PRAYER (prayer), 0); g_object_ref (prayer); ITLDate.day = g_date_get_day(cdate); ITLDate.month = g_date_get_month(cdate); ITLDate.year = g_date_get_year(cdate); getPrayerTimes (&prayer->priv->loc, &prayer->priv->method, &ITLDate, ITLPrayer); fajr = g_date_time_new_local(ITLDate.year, ITLDate.month, ITLDate.day, ITLPrayer[0].hour, ITLPrayer[0].minute, ITLPrayer[0].second); shurooq = g_date_time_new_local(ITLDate.year, ITLDate.month, ITLDate.day, ITLPrayer[1].hour, ITLPrayer[1].minute, ITLPrayer[1].second); dhuhr = g_date_time_new_local(ITLDate.year, ITLDate.month, ITLDate.day, ITLPrayer[2].hour, ITLPrayer[2].minute, ITLPrayer[2].second); asr = g_date_time_new_local(ITLDate.year, ITLDate.month, ITLDate.day, ITLPrayer[3].hour, ITLPrayer[3].minute, ITLPrayer[3].second); maghrib = g_date_time_new_local(ITLDate.year, ITLDate.month, ITLDate.day, ITLPrayer[4].hour, ITLPrayer[4].minute, ITLPrayer[4].second); isha = g_date_time_new_local(ITLDate.year, ITLDate.month, ITLDate.day, ITLPrayer[5].hour, ITLPrayer[5].minute, ITLPrayer[5].second); Prayers = g_list_append(Prayers, fajr); Prayers = g_list_append(Prayers, shurooq); Prayers = g_list_append(Prayers, dhuhr); Prayers = g_list_append(Prayers, asr); Prayers = g_list_append(Prayers, maghrib); Prayers = g_list_append(Prayers, isha); g_object_unref (prayer); return(Prayers); }
void um_history_dialog_show (UmHistoryDialog *um, GtkWindow *parent) { GDateTime *temp, *local; /* Set the first day of this week */ local = g_date_time_new_now_local (); temp = g_date_time_new_local (g_date_time_get_year (local), g_date_time_get_month (local), g_date_time_get_day_of_month (local), 0, 0, 0); um->week = g_date_time_add_days (temp, 1 - g_date_time_get_day_of_week (temp)); um->current_week = g_date_time_ref (um->week); g_date_time_unref (local); g_date_time_unref (temp); show_week (um); gtk_window_set_transient_for (GTK_WINDOW (um->dialog), parent); gtk_window_present (GTK_WINDOW (um->dialog)); }
static void change_time (CcDateTimePanel *panel) { CcDateTimePanelPrivate *priv = panel->priv; guint h, m; GDateTime *old_date; old_date = priv->date; h = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (W ("h_spinbutton"))); m = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (W ("m_spinbutton"))); if (priv->clock_format == G_DESKTOP_CLOCK_FORMAT_12H) { gboolean is_pm_time; GtkWidget *visible_child; visible_child = gtk_stack_get_visible_child (GTK_STACK (priv->am_pm_stack)); if (visible_child == priv->pm_label) is_pm_time = TRUE; else is_pm_time = FALSE; if (h == 12) h = 0; if (is_pm_time) h += 12; } priv->date = g_date_time_new_local (g_date_time_get_year (old_date), g_date_time_get_month (old_date), g_date_time_get_day_of_month (old_date), h, m, g_date_time_get_second (old_date)); g_date_time_unref (old_date); update_time (panel); queue_set_datetime (panel); }
/** * gst_date_time_new_local_time: * @year: the gregorian year * @month: the gregorian month, or -1 * @day: the day of the gregorian month, or -1 * @hour: the hour of the day, or -1 * @minute: the minute of the hour, or -1 * @seconds: the second of the minute, or -1 * * Creates a new #GstDateTime using the date and times in the gregorian calendar * in the local timezone. * * @year should be from 1 to 9999, @month should be from 1 to 12, @day from * 1 to 31, @hour from 0 to 23, @minutes and @seconds from 0 to 59. * * If @month is -1, then the #GstDateTime created will only contain @year, * and all other fields will be considered not set. * * If @day is -1, then the #GstDateTime created will only contain @year and * @month and all other fields will be considered not set. * * If @hour is -1, then the #GstDateTime created will only contain @year and * @month and @day, and the time fields will be considered not set. In this * case @minute and @seconds should also be -1. * * Free-function: gst_date_time_unref * * Return value: (transfer full) (nullable): the newly created #GstDateTime */ GstDateTime * gst_date_time_new_local_time (gint year, gint month, gint day, gint hour, gint minute, gdouble seconds) { GstDateTimeFields fields; GstDateTime *datetime; g_return_val_if_fail (year > 0 && year <= 9999, NULL); g_return_val_if_fail ((month > 0 && month <= 12) || month == -1, NULL); g_return_val_if_fail ((day > 0 && day <= 31) || day == -1, NULL); g_return_val_if_fail ((hour >= 0 && hour < 24) || hour == -1, NULL); g_return_val_if_fail ((minute >= 0 && minute < 60) || minute == -1, NULL); g_return_val_if_fail ((seconds >= 0 && seconds < 60) || seconds == -1, NULL); fields = gst_date_time_check_fields (&year, &month, &day, &hour, &minute, &seconds); datetime = gst_date_time_new_from_g_date_time (g_date_time_new_local (year, month, day, hour, minute, seconds)); datetime->fields = fields; return datetime; }
static void update_time (GcalTimeSelector *selector) { GDateTime *now, *new_time; gint hour, minute; /* Retrieve current time */ hour = (gint) gtk_adjustment_get_value (selector->hour_adjustment); minute = (gint) gtk_adjustment_get_value (selector->minute_adjustment); if (!selector->format_24h) { hour = hour % 12; if (gtk_combo_box_get_active (GTK_COMBO_BOX (selector->period_combo)) == PM) { g_signal_handlers_block_by_func (selector->period_combo, update_time, selector); gtk_combo_box_set_active (GTK_COMBO_BOX (selector->period_combo), hour >= 12); hour += 12; g_signal_handlers_unblock_by_func (selector->period_combo, update_time, selector); } } now = g_date_time_new_now_local (); new_time = g_date_time_new_local (g_date_time_get_year (now), g_date_time_get_month (now), g_date_time_get_day_of_month (now), hour, minute, 0); /* Set the new time */ gcal_time_selector_set_time (selector, new_time); g_clear_pointer (&new_time, g_date_time_unref); g_clear_pointer (&now, g_date_time_unref); }
void CalendarDatePrivate::setDate(GDateTime * date, gboolean isForceLoad, GTimeSpan changed) { GDateTime* selectedDate = g_date_time_new_local(m_selectedYear, m_selectedMonth, m_selectedDayOfMonth, 1, 1, 1); if (!isTheSameDate(date, selectedDate)) { g_date_time_get_ymd(date, &(m_selectedYear), &(m_selectedMonth), &(m_selectedDayOfMonth)); switch (m_viewType) { case VIEWTYPE_DAY: updateDayView(isForceLoad, changed); break; case VIEWTYPE_MONTH: updateMonthView(isForceLoad, changed); break; case VIEWTYPE_YEAR: updateYearView(isForceLoad, changed); break; default: break; } } else { if (isForceLoad) { updateDayView(isForceLoad, changed); } } g_date_time_unref(selectedDate); }
static void proxy_call_resolve_grlnet_async_cb (GObject *source_object, GAsyncResult *res, gpointer user_data) { RaitvOperation *op = (RaitvOperation *) user_data; xmlDocPtr doc = NULL; xmlXPathContextPtr xpath = NULL; GError *wc_error = NULL; GError *error = NULL; gchar *content = NULL; gsize length; gchar *value; gchar *thumbnail; gchar **tokens; GDateTime *date; GRL_DEBUG ("Response id=%u", op->operation_id); if (g_cancellable_is_cancelled (op->cancellable)) { goto finalize; } if (!grl_net_wc_request_finish (GRL_NET_WC (source_object), res, &content, &length, &wc_error)) { error = g_error_new (GRL_CORE_ERROR, GRL_CORE_ERROR_SEARCH_FAILED, _("Failed to resolve: %s"), wc_error->message); op->resolveCb (op->source, op->operation_id, op->media, op->user_data, error); g_error_free (wc_error); g_error_free (error); return; } doc = xmlRecoverMemory (content, (gint) length); if (!doc) { GRL_DEBUG ("Doc failed"); goto finalize; } xpath = xmlXPathNewContext (doc); if (!xpath) { GRL_DEBUG ("Xpath failed"); goto finalize; } if (!grl_data_has_key (GRL_DATA (op->media), GRL_METADATA_KEY_URL)) { value = eval_xquery ("/html/head/meta[@name='videourl']", xpath); if (value) { grl_media_set_url (op->media, value); g_free (value); } } if (!grl_data_has_key (GRL_DATA (op->media), GRL_METADATA_KEY_TITLE)) { value = eval_xquery ("/html/head/meta[@name='title']", xpath); if (value) { grl_media_set_title (op->media, value); g_free (value); } } if (!grl_data_has_key (GRL_DATA (op->media), GRL_METADATA_KEY_PUBLICATION_DATE)) { value = eval_xquery ("/html/head/meta[@name='itemDate']", xpath); if (value) { tokens = g_strsplit (value, "/", -1); if (g_strv_length (tokens) >= 3) { date = g_date_time_new_local (atoi (tokens[2]), atoi (tokens[1]), atoi (tokens[0]), 0, 0, 0); grl_media_set_publication_date (op->media, date); g_date_time_unref (date); } g_strfreev (tokens); g_free (value); } } if (!grl_data_has_key (GRL_DATA (op->media), GRL_METADATA_KEY_THUMBNAIL)) { value = eval_xquery ("/html/head/meta[@name='vod-image']", xpath); if (value) { /* Sometimes thumbnail doesn't report a complete url */ if (value[0] == '/') { thumbnail = g_strconcat ("http://www.rai.tv", value, NULL); g_free (value); } else { thumbnail = value; } grl_media_set_thumbnail (op->media, thumbnail); g_free (thumbnail); } } finalize: op->resolveCb (op->source, op->operation_id, op->media, op->user_data, NULL); g_clear_pointer (&xpath, xmlXPathFreeContext); g_clear_pointer (&doc, xmlFreeDoc); }
static void proxy_call_browse_grlnet_async_cb (GObject *source_object, GAsyncResult *res, gpointer user_data) { RaitvOperation *op = (RaitvOperation *) user_data; xmlDocPtr doc = NULL; xmlXPathContextPtr xpath = NULL; xmlXPathObjectPtr obj = NULL; gint i, nb_items = 0; gsize length; GRL_DEBUG ("Response id=%u", op->operation_id); GError *wc_error = NULL; GError *error = NULL; gchar *content = NULL; if (g_cancellable_is_cancelled (op->cancellable)) { goto finalize; } if (!grl_net_wc_request_finish (GRL_NET_WC (source_object), res, &content, &length, &wc_error)) { error = g_error_new (GRL_CORE_ERROR, GRL_CORE_ERROR_SEARCH_FAILED, _("Failed to browse: %s"), wc_error->message); op->callback (op->source, op->operation_id, NULL, 0, op->user_data, error); g_error_free (wc_error); g_error_free (error); return; } doc = xmlRecoverMemory (content, (gint) length); if (!doc) { GRL_DEBUG ("Doc failed"); goto finalize; } xpath = xmlXPathNewContext (doc); if (!xpath) { GRL_DEBUG ("Xpath failed"); goto finalize; } gchar* xquery=NULL; switch (classify_media_id (op->container_id)) { case RAITV_MEDIA_TYPE_POPULAR_THEME: xquery = "/CLASSIFICAVISTI/content"; break; case RAITV_MEDIA_TYPE_RECENT_THEME: xquery = "/INFORMAZIONICONTENTS/content"; break; default: goto finalize; } obj = xmlXPathEvalExpression ((xmlChar *) xquery, xpath); if (obj) { nb_items = xmlXPathNodeSetGetLength (obj->nodesetval); xmlXPathFreeObject (obj); } if (nb_items < op->count) op->count = nb_items; op->category_info->count = nb_items; for (i = 0; i < nb_items; i++) { //Skip if(op->skip>0) { op->skip--; continue; } GrlRaitvSource *source = GRL_RAITV_SOURCE (op->source); GList *mapping = source->priv->raitv_browse_mappings; GrlMedia *media = grl_media_video_new (); while (mapping) { gchar *str; gchar *strvalue; RaitvAssoc *assoc = (RaitvAssoc *) mapping->data; str = g_strdup_printf ("string(%s[%i]/%s)", xquery,i + 1, assoc->exp); obj = xmlXPathEvalExpression ((xmlChar *) str, xpath); if (obj) { if (obj->stringval && obj->stringval[0] != '\0') { strvalue = g_strdup((gchar *) obj->stringval); //Sometimes GRL_METADATA_KEY_THUMBNAIL doesn't report complete url if(assoc->grl_key == GRL_METADATA_KEY_THUMBNAIL && !g_str_has_prefix(strvalue,"http://www.rai.tv/")) { strvalue = g_strdup_printf("http://www.rai.tv%s",obj->stringval); } GType _type; _type = grl_metadata_key_get_type (assoc->grl_key); switch (_type) { case G_TYPE_STRING: grl_data_set_string (GRL_DATA (media), assoc->grl_key, strvalue); break; case G_TYPE_INT: grl_data_set_int (GRL_DATA (media), assoc->grl_key, (gint) atoi (strvalue)); break; case G_TYPE_FLOAT: grl_data_set_float (GRL_DATA (media), assoc->grl_key, (gfloat) atof (strvalue)); break; default: /* G_TYPE_DATE_TIME is not a constant, so this has to be * in "default:" */ if (_type == G_TYPE_DATE_TIME) { int year,month,day,hour,minute,seconds; sscanf((const char*)obj->stringval, "%02d/%02d/%04d %02d:%02d:%02d", &day, &month, &year, &hour,&minute, &seconds); GDateTime *date = g_date_time_new_local (year, month, day, hour,minute, seconds); grl_data_set_boxed (GRL_DATA (media), assoc->grl_key, date); if(date) g_date_time_unref (date); } else { GRL_DEBUG ("\tUnexpected data type: %s", g_type_name (_type)); } break; } g_free (strvalue); } xmlXPathFreeObject (obj); } g_free (str); mapping = mapping->next; } op->callback (op->source, op->operation_id, media, --op->count, op->user_data, NULL); if (op->count == 0) { break; } } finalize: g_clear_pointer (&xpath, xmlXPathFreeContext); g_clear_pointer (&doc, xmlFreeDoc); /* Signal the last element if it was not already signaled */ if (nb_items == 0) { op->callback (op->source, op->operation_id, NULL, 0, op->user_data, NULL); } else { //Continue the search if(op->count>0) { //Skip the ones already read op->skip += nb_items; op->offset += nb_items; switch (classify_media_id (op->container_id)) { case RAITV_MEDIA_TYPE_POPULAR_THEME: produce_from_popular_theme(op); break; case RAITV_MEDIA_TYPE_RECENT_THEME: produce_from_recent_theme(op); break; default: g_assert_not_reached (); break; } } } }
static void proxy_call_search_grlnet_async_cb (GObject *source_object, GAsyncResult *res, gpointer user_data) { RaitvOperation *op = (RaitvOperation *) user_data; xmlDocPtr doc = NULL; xmlXPathContextPtr xpath = NULL; xmlXPathObjectPtr obj = NULL; gint i, nb_items = 0; gsize length; GRL_DEBUG ("Response id=%u", op->operation_id); GError *wc_error = NULL; GError *error = NULL; gchar *content = NULL; gboolean g_bVideoNotFound = TRUE; if (g_cancellable_is_cancelled (op->cancellable)) { goto finalize; } if (!grl_net_wc_request_finish (GRL_NET_WC (source_object), res, &content, &length, &wc_error)) { error = g_error_new (GRL_CORE_ERROR, GRL_CORE_ERROR_SEARCH_FAILED, _("Failed to search: %s"), wc_error->message); op->callback (op->source, op->operation_id, NULL, 0, op->user_data, error); g_error_free (wc_error); g_error_free (error); return; } doc = xmlParseMemory (content, (gint) length); if (!doc) { GRL_DEBUG ("Doc failed"); goto finalize; } xpath = xmlXPathNewContext (doc); if (!xpath) { GRL_DEBUG ("Xpath failed"); goto finalize; } obj = xmlXPathEvalExpression ((xmlChar *) "/GSP/RES/R", xpath); if (obj) { nb_items = xmlXPathNodeSetGetLength (obj->nodesetval); xmlXPathFreeObject (obj); } for (i = 0; i < nb_items; i++) { //Search only videos gchar *str; str = g_strdup_printf ("string(/GSP/RES/R[%i]/MT[@N='videourl']/@V)", i + 1); obj = xmlXPathEvalExpression ((xmlChar *) str, xpath); if (obj->stringval && obj->stringval[0] == '\0') continue; if(op->skip>0) { op->skip--; continue; } GrlRaitvSource *source = GRL_RAITV_SOURCE (op->source); GList *mapping = source->priv->raitv_search_mappings; GrlMedia *media = grl_media_video_new (); g_bVideoNotFound = FALSE; GRL_DEBUG ("Mappings count: %d",g_list_length(mapping)); while (mapping) { RaitvAssoc *assoc = (RaitvAssoc *) mapping->data; str = g_strdup_printf ("string(/GSP/RES/R[%i]/%s)", i + 1, assoc->exp); GRL_DEBUG ("Xquery %s", str); gchar *strvalue; obj = xmlXPathEvalExpression ((xmlChar *) str, xpath); if (obj) { if (obj->stringval && obj->stringval[0] != '\0') { strvalue = g_strdup((gchar *) obj->stringval); //Sometimes GRL_METADATA_KEY_THUMBNAIL doesn't report complete url if(assoc->grl_key == GRL_METADATA_KEY_THUMBNAIL && !g_str_has_prefix(strvalue,"http://www.rai.tv")) { strvalue = g_strdup_printf("http://www.rai.tv%s",obj->stringval); } GType _type; GRL_DEBUG ("\t%s -> %s", str, obj->stringval); _type = grl_metadata_key_get_type (assoc->grl_key); switch (_type) { case G_TYPE_STRING: grl_data_set_string (GRL_DATA (media), assoc->grl_key, strvalue); break; case G_TYPE_INT: grl_data_set_int (GRL_DATA (media), assoc->grl_key, (gint) atoi (strvalue)); break; case G_TYPE_FLOAT: grl_data_set_float (GRL_DATA (media), assoc->grl_key, (gfloat) atof (strvalue)); break; default: /* G_TYPE_DATE_TIME is not a constant, so this has to be * in "default:" */ if (_type == G_TYPE_DATE_TIME) { int year,month,day; sscanf((const char*)obj->stringval, "%02d/%02d/%04d", &day, &month, &year); GDateTime *date = g_date_time_new_local (year, month, day, 0, 0, 0); GRL_DEBUG ("Setting %s to %s", grl_metadata_key_get_name (assoc->grl_key), g_date_time_format (date, "%F %H:%M:%S")); grl_data_set_boxed (GRL_DATA (media), assoc->grl_key, date); if(date) g_date_time_unref (date); } else { GRL_DEBUG ("\tUnexpected data type: %s", g_type_name (_type)); } break; } g_free (strvalue); } xmlXPathFreeObject (obj); } g_free (str); mapping = mapping->next; } op->callback (op->source, op->operation_id, media, --op->count, op->user_data, NULL); if (op->count == 0) break; } finalize: g_clear_pointer (&xpath, xmlXPathFreeContext); g_clear_pointer (&doc, xmlFreeDoc); /* Signal the last element if it was not already signaled */ if (nb_items == 0 || g_bVideoNotFound) { op->callback (op->source, op->operation_id, NULL, 0, op->user_data, NULL); } else { //Continue the search if(op->count>0) { op->offset += nb_items; g_raitv_videos_search(op); } } }
dif_dive_t *dif_dive_set_datetime(dif_dive_t *dive, guint year, guint month, guint day, guint hour, guint minute, guint second) { dive->datetime = g_date_time_new_local(year, month, day, hour, minute, second); return dive; }
static void update_jobs_list_cb (cups_job_t *jobs, gint num_of_jobs, gpointer user_data) { GtkTreeSelection *selection; PpJobsDialog *dialog = (PpJobsDialog *) user_data; GtkListStore *store; GtkTreeView *treeview; GtkTreeIter select_iter; GtkTreeIter iter; GSettings *settings; gboolean select_iter_set = FALSE; gint i; gint select_index = 0; treeview = (GtkTreeView*) gtk_builder_get_object (dialog->builder, "job-treeview"); if (dialog->num_jobs > 0) cupsFreeJobs (dialog->num_jobs, dialog->jobs); dialog->num_jobs = num_of_jobs; dialog->jobs = jobs; store = gtk_list_store_new (JOB_N_COLUMNS, G_TYPE_INT, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING); if (dialog->current_job_id >= 0) { for (i = 0; i < dialog->num_jobs; i++) { select_index = i; if (dialog->jobs[i].id >= dialog->current_job_id) break; } } for (i = 0; i < dialog->num_jobs; i++) { GDesktopClockFormat value; GDateTime *time; struct tm *ts; gchar *time_string; gchar *state = NULL; ts = localtime (&(dialog->jobs[i].creation_time)); time = g_date_time_new_local (ts->tm_year, ts->tm_mon, ts->tm_mday, ts->tm_hour, ts->tm_min, ts->tm_sec); settings = g_settings_new (CLOCK_SCHEMA); value = g_settings_get_enum (settings, CLOCK_FORMAT_KEY); if (value == G_DESKTOP_CLOCK_FORMAT_24H) time_string = g_date_time_format (time, "%k:%M"); else time_string = g_date_time_format (time, "%l:%M %p"); g_date_time_unref (time); switch (dialog->jobs[i].state) { case IPP_JOB_PENDING: /* Translators: Job's state (job is waiting to be printed) */ state = g_strdup (C_("print job", "Pending")); break; case IPP_JOB_HELD: /* Translators: Job's state (job is held for printing) */ state = g_strdup (C_("print job", "Held")); break; case IPP_JOB_PROCESSING: /* Translators: Job's state (job is currently printing) */ state = g_strdup (C_("print job", "Processing")); break; case IPP_JOB_STOPPED: /* Translators: Job's state (job has been stopped) */ state = g_strdup (C_("print job", "Stopped")); break; case IPP_JOB_CANCELED: /* Translators: Job's state (job has been canceled) */ state = g_strdup (C_("print job", "Canceled")); break; case IPP_JOB_ABORTED: /* Translators: Job's state (job has aborted due to error) */ state = g_strdup (C_("print job", "Aborted")); break; case IPP_JOB_COMPLETED: /* Translators: Job's state (job has completed successfully) */ state = g_strdup (C_("print job", "Completed")); break; } gtk_list_store_append (store, &iter); gtk_list_store_set (store, &iter, JOB_ID_COLUMN, dialog->jobs[i].id, JOB_TITLE_COLUMN, dialog->jobs[i].title, JOB_STATE_COLUMN, state, JOB_CREATION_TIME_COLUMN, time_string, -1); if (i == select_index) { select_iter = iter; select_iter_set = TRUE; dialog->current_job_id = dialog->jobs[i].id; } g_free (time_string); g_free (state); } gtk_tree_view_set_model (treeview, GTK_TREE_MODEL (store)); if (select_iter_set && (selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview)))) { gtk_tree_selection_select_iter (selection, &select_iter); } g_object_unref (store); dialog->ref_count--; }
/** * gcal_date_selector_set_date: * @selector: * @day: (nullable): The day number. * @month: (nullable): The month number starting with 1 * @year: (nullable): The year number * * Set the value of the date shown **/ void gcal_date_selector_set_date (GcalDateSelector *selector, gint day, gint month, gint year) { GcalDateSelectorPrivate *priv; GDateTime *dt; gchar *label; g_return_if_fail (GCAL_IS_DATE_SELECTOR (selector)); priv = gcal_date_selector_get_instance_private (selector); day = CLAMP (day, 1, 31); month = CLAMP (month, 1, 12); /* since we're dealing only with the date, the tz shouldn't be a problem */ dt = g_date_time_new_local (year, month, day, 0, 0, 0); /** * When it fails to be instances, it's * because edit dialog is cleaning it's * data. Thus, we should stop here. */ if (dt == NULL) return; priv->day = day; priv->month = month; priv->year = year; month = CLAMP (month - 1, 0, 11); /* set calendar's date */ g_signal_handlers_block_by_func (priv->calendar, calendar_day_selected, selector); g_object_set (priv->calendar, "day", day, "month", month, "year", year, NULL); g_signal_handlers_unblock_by_func (priv->calendar, calendar_day_selected, selector); /* rebuild the date label */ label = g_date_time_format (dt, priv->mask); gtk_label_set_label (GTK_LABEL (priv->date_label), label); g_free (label); /* set date entries' text */ /* day entry */ label = g_strdup_printf ("%.2d", day); gtk_entry_set_text (GTK_ENTRY (priv->entries[DAY]), label); g_free (label); /* month entry */ label = g_strdup_printf ("%.2d", priv->month); gtk_entry_set_text (GTK_ENTRY (priv->entries[MONTH]), label); g_free (label); /* year entry */ label = g_strdup_printf ("%.4d", year); gtk_entry_set_text (GTK_ENTRY (priv->entries[YEAR]), label); /* emit the MODIFIED signal */ g_signal_emit (selector, signals[MODIFIED], 0); g_free (label); g_date_time_unref (dt); }
static void _hwp_hwp3_parser_parse_summary_info (HwpHWP3Parser *parser, HwpHWP3File *file, GError **error) { g_return_if_fail (HWP_IS_HWP3_FILE (file)); GString *string[9]; guint16 c; guint8 count = 0; HwpListenableInterface *iface; iface = HWP_LISTENABLE_GET_IFACE (parser->listenable); for (guint i = 0; i < 9; i++) { count = 0; string[i] = g_string_new (NULL); while (count < 112) { hwp_hwp3_parser_read_uint16 (parser, &c); count += 2; if (c != 0) { gchar *str = hwp_hnchar_to_utf8 (c); g_string_append (string[i], str); g_free (str); } else { hwp_hwp3_parser_skip (parser, 112 - count); break; } } } /* for */ if (iface->summary_info) { HwpSummaryInfo *info = hwp_summary_info_new (); info->title = g_string_free (string[0], FALSE); info->subject = g_string_free (string[1], FALSE); info->creator = g_string_free (string[2], FALSE); /* str format: "2001년 10월 11일 목요일, 20시 48분" */ gchar *s = g_string_free (string[3], FALSE); GRegex *regex; regex = g_regex_new ("^([0-9]{4})년 ([0-9]{1,2})월 ([0-9]{1,2})일 .요일, ([0-9]{1,2})시 ([0-9]{1,2})분", 0, 0, error); GMatchInfo *match_info; g_regex_match (regex, s, 0, &match_info); gint match_num = g_match_info_get_match_count (match_info); gchar *year = NULL; gchar *month = NULL; gchar *day = NULL; gchar *hour = NULL; gchar *minute = NULL; if (match_num == 6) { year = g_match_info_fetch (match_info, 1); month = g_match_info_fetch (match_info, 2); day = g_match_info_fetch (match_info, 3); hour = g_match_info_fetch (match_info, 4); minute = g_match_info_fetch (match_info, 5); GDateTime *datetime = g_date_time_new_local (atoi (year), atoi (month), atoi (day), atoi (hour), atoi (minute), 0.0); g_free (year); g_free (month); g_free (day); g_free (hour); g_free (minute); GTime time = g_date_time_to_unix (datetime); info->mod_date = time; } g_match_info_free (match_info); g_regex_unref (regex); iface->summary_info (parser->listenable, info, parser->user_data, error); } /* TODO */ /* 4 ~ 8 */ }
static gboolean parse_epg_dat_line (Request *req, gchar *line, GPtrArray *events) { gchar *duration_s, *start_time_s, *end_time_s, *date_s; gboolean start_in_between, end_in_between, englobing; gint year, month, day, hours, minutes, duration; GDateTime *start_date, *end_date; gint n_parsed; duration_s = cut_last_field_out (line); if (duration_s == NULL) goto no_duration; end_time_s = cut_last_field_out (line); if (end_time_s == NULL) goto no_end_time; start_time_s = cut_last_field_out (line); if (start_time_s == NULL) goto no_start_time; date_s = cut_last_field_out (line); if (date_s == NULL) goto no_date; n_parsed = sscanf (date_s, "%d/%d/%d", &day, &month, &year); if (n_parsed != 3) goto scanf_failed; n_parsed = sscanf (start_time_s, "%d:%d", &hours, &minutes); if (n_parsed != 2) goto scanf_failed; duration = atoi (duration_s); if (duration == 0) return TRUE; /* duration is always is seconds in Mex, minutes in the data files */ duration *= 60; start_date = g_date_time_new_local (year, month, day, hours, minutes, 0); end_date = g_date_time_add_seconds (start_date, duration); start_in_between = g_date_time_compare (start_date, req->start_date) >= 0 && g_date_time_compare (start_date, req->end_date) <= 0; end_in_between = g_date_time_compare (end_date, req->start_date) >= 0 && g_date_time_compare (end_date, req->end_date) <= 0; englobing = g_date_time_compare (start_date, req->start_date) <= 0 && g_date_time_compare (end_date, req->end_date) >= 0; if (start_in_between || end_in_between || englobing) { MexEpgEvent *event; MexProgram *program; event = mex_epg_event_new_with_date_time (start_date, duration); program = parse_program (line); if (program == NULL) goto program_failed; /* we add the duration here as parse_program don't do it and that we * need the duration in seconds instead of minutes */ duration_s = g_strdup_printf ("%d", duration); mex_program_set_metadata (program, MEX_CONTENT_METADATA_DURATION, duration_s); g_free (duration_s); mex_epg_event_set_program (event, program); g_object_unref (program); mex_epg_event_set_channel (event, req->channel); g_ptr_array_add (events, event); } return TRUE; program_failed: MEX_WARN (EPG, "could not create the program: %s", line); return FALSE; scanf_failed: MEX_WARN (EPG, "could not parse date or time: %s", line); return FALSE; no_date: MEX_WARN (EPG, "could not find the date: %s", line); return FALSE; no_start_time: MEX_WARN (EPG, "could not find the start time: %s", line); return FALSE; no_end_time: MEX_WARN (EPG, "could not find the end time: %s", line); return FALSE; no_duration: MEX_WARN (EPG, "could not find the duration: %s", line); return FALSE; }