Esempio n. 1
0
void
ui_room_history(const char * const room_jid, const char * const nick,
    GTimeVal tv_stamp, const char * const message)
{
    ProfWin *window = wins_get_by_recipient(room_jid);

    GDateTime *time = g_date_time_new_from_timeval_utc(&tv_stamp);
    gchar *date_fmt = g_date_time_format(time, "%H:%M:%S");
    wprintw(window->win, "%s - ", date_fmt);
    g_date_time_unref(time);
    g_free(date_fmt);

    if (strncmp(message, "/me ", 4) == 0) {
        wprintw(window->win, "*%s ", nick);
        waddstr(window->win, message + 4);
        wprintw(window->win, "\n");
    } else {
        wprintw(window->win, "%s: ", nick);
        _win_show_message(window->win, message);
    }

    if (wins_is_current(window)) {
        wins_refresh_current();
    }
}
static void
create_date_format_menu (GtkBuilder *builder)
{
	GtkComboBoxText *combo_box;
	gchar *date_string;
	GDateTime *now;

	combo_box = GTK_COMBO_BOX_TEXT
		(gtk_builder_get_object (builder,
					 NEMO_FILE_MANAGEMENT_PROPERTIES_DATE_FORMAT_WIDGET));

	now = g_date_time_new_now_local ();

	date_string = g_date_time_format (now, "%c");
	gtk_combo_box_text_append_text (combo_box, date_string);
	g_free (date_string);

	date_string = g_date_time_format (now, "%Y-%m-%d %H:%M:%S");
	gtk_combo_box_text_append_text (combo_box, date_string);
	g_free (date_string);

	date_string = g_date_time_format (now, _("today at %-I:%M:%S %p"));
	gtk_combo_box_text_append_text (combo_box, date_string);
	g_free (date_string);

	g_date_time_unref (now);
}
Esempio n. 3
0
static char *
build_uri (AsyncExistenceJob *job)
{
  char *retval, *file_name;
  char *timestamp;
  GDateTime *d;

  d = g_date_time_new_now_local ();
  /* Translators: This is a strftime format string.
   * It is used to display the time in 24-hours format (eg, like
   * in France: 20:10) but using hyphens in place of colons. */
  timestamp = g_date_time_format (d, _("%Y-%m-%d %H-%M-%S"));
  g_date_time_unref (d);

  if (job->iteration == 0)
    {
      /* translators: this is the name of the file that gets made up
       * with the screenshot if the entire screen is taken */
      file_name = g_strdup_printf (_("Screenshot at %s.png"), timestamp);
    }
  else
    {
      /* translators: this is the name of the file that gets
       * made up with the screenshot if the entire screen is
       * taken */
      file_name = g_strdup_printf (_("Screenshot at %s - %d.png"), timestamp, job->iteration);
    }

  retval = g_build_filename (job->base_uris[job->type], file_name, NULL);
  g_free (file_name);
  g_free (timestamp);

  return retval;
}
Esempio n. 4
0
time64
gnc_mktime (struct tm* time)
{
     GDateTime *gdt;
     time64 secs;
     normalize_struct_tm (time);
     gdt = gnc_g_date_time_new_local (time->tm_year + 1900, time->tm_mon,
				      time->tm_mday, time->tm_hour,
				      time->tm_min, (gdouble)(time->tm_sec));
     if (gdt == NULL)
     {
         g_warning("Invalid time passed to gnc_mktime");
         return -1;
     }
     time->tm_mon = time->tm_mon > 0 ? time->tm_mon - 1 : 11;
     // Watch out: struct tm has wday=0..6 with Sunday=0, but GDateTime has wday=1..7 with Sunday=7.
     time->tm_wday = g_date_time_get_day_of_week (gdt) % 7;
     time->tm_yday = g_date_time_get_day_of_year (gdt);
     time->tm_isdst = g_date_time_is_daylight_savings (gdt);

#ifdef HAVE_STRUCT_TM_GMTOFF
     time->tm_gmtoff = g_date_time_get_utc_offset (gdt) / G_TIME_SPAN_SECOND;
#endif

     secs = g_date_time_to_unix (gdt);
     g_date_time_unref (gdt);
     return secs;
}
Esempio n. 5
0
void
p_contact_free(PContact contact)
{
    if (contact->jid != NULL) {
        free(contact->jid);
        contact->jid = NULL;
    }

    if (contact->name != NULL) {
        free(contact->name);
        contact->name = NULL;
    }

    if (contact->presence != NULL) {
        free(contact->presence);
        contact->presence = NULL;
    }

    if (contact->status != NULL) {
        free(contact->status);
        contact->status = NULL;
    }

    if (contact->subscription != NULL) {
        free(contact->subscription);
        contact->subscription = NULL;
    }

    if (contact->last_activity != NULL) {
        g_date_time_unref(contact->last_activity);
    }

    free(contact);
    contact = NULL;
}
Esempio n. 6
0
void
chat_log_close(void)
{
    g_hash_table_remove_all(logs);
    g_hash_table_remove_all(groupchat_logs);
    g_date_time_unref(session_started);
}
Esempio n. 7
0
char *
gnc_timespec_to_iso8601_buff (Timespec ts, char * buff)
{
    gchar *fmt1 = "%Y-%m-%d %H:%M", *fmt2 = "%s:%02d.%06d %s";
    GDateTime *gdt;
    gchar *time_base, *tz;

    g_return_val_if_fail (buff != NULL, NULL);
    gdt = gnc_g_date_time_new_from_timespec_local (ts);
    g_return_val_if_fail (gdt != NULL, NULL);
    time_base = g_date_time_format (gdt, fmt1);
#ifdef G_OS_WIN32
    tz = g_date_time_format (gdt, "%Z");
#else
    tz = g_date_time_format (gdt, "%z");
#endif
    snprintf (buff, MAX_DATE_LENGTH, fmt2, time_base,
	      g_date_time_get_second (gdt), g_date_time_get_microsecond (gdt),
	      tz);

    g_free (time_base);
    g_free (tz);
    g_date_time_unref (gdt);
    return buff + strlen (buff);

}
Esempio n. 8
0
void
print_is_leap_year (void)
{

  /* Print a message to stdio letting user know if the current year is
     a leap year. */

  GTimeZone *tz;  
  GDateTime *dt;
  GDateYear theYear;

  tz = (GTimeZone *)g_time_zone_new_local();  
  dt = (GDateTime *)g_date_time_new_now(tz);

  theYear = g_date_time_get_year(dt);

  if (g_date_is_leap_year(theYear)) {
    g_print("This year (%d) is a leap year.\n", theYear);
  } else {
    g_print("This year (%d) is not a leap year.\n", theYear);
  }

  g_date_time_unref(dt);
  g_time_zone_unref(tz);

}
Esempio n. 9
0
static void
_status_bar_draw(void)
{
    if (last_time) {
        g_date_time_unref(last_time);
    }
    last_time = g_date_time_new_now(tz);

    int bracket_attrs = theme_attrs(THEME_STATUS_BRACKET);
    int time_attrs = theme_attrs(THEME_STATUS_TIME);

    char *time_pref = prefs_get_string(PREF_TIME_STATUSBAR);
    if (g_strcmp0(time_pref, "off") != 0) {
        gchar *date_fmt = g_date_time_format(last_time, time_pref);
        assert(date_fmt != NULL);
        size_t len = strlen(date_fmt);
        wattron(status_bar, bracket_attrs);
        mvwaddch(status_bar, 0, 1, '[');
        wattroff(status_bar, bracket_attrs);
        wattron(status_bar, time_attrs);
        mvwprintw(status_bar, 0, 2, date_fmt);
        wattroff(status_bar, time_attrs);
        wattron(status_bar, bracket_attrs);
        mvwaddch(status_bar, 0, 2 + len, ']');
        wattroff(status_bar, bracket_attrs);
        g_free(date_fmt);
    }
    prefs_free_string(time_pref);

    _update_win_statuses();
    wnoutrefresh(status_bar);
    inp_put_back();
}
Esempio n. 10
0
static time_t
date_to_time_t (const xmlChar *str, const char * tzid)
{
    struct tm time = { 0 };
    GTimeZone *tz;
    GDateTime *dt;
    time_t rval;
    char *after;

    after = strptime ((const char*) str, "%Y-%m-%dT%T", &time);
    if (after == NULL) {
	g_warning ("Cannot parse date string \"%s\"", str);
	return 0;
    }

    if (*after == 'Z')
	tzid = "UTC";

    tz = g_time_zone_new (tzid);
    dt = g_date_time_new (tz,
			  time.tm_year + 1900,
			  time.tm_mon + 1,
			  time.tm_mday,
			  time.tm_hour,
			  time.tm_min,
			  time.tm_sec);

    rval = g_date_time_to_unix (dt);

    g_time_zone_unref (tz);
    g_date_time_unref (dt);

    return rval;
}
Esempio n. 11
0
void
chat_log_close(void)
{
    g_hash_table_destroy(logs);
    g_hash_table_destroy(groupchat_logs);
    g_date_time_unref(session_started);
}
Esempio n. 12
0
static void today_clicked (GtkWidget *cal)
{
  GDateTime *now = g_date_time_new_now_local ();
  gtk_calendar_select_month ( GTK_CALENDAR(cal), g_date_time_get_month(now)-1, g_date_time_get_year(now) );
  gtk_calendar_select_day ( GTK_CALENDAR(cal), g_date_time_get_day_of_month(now) );
  g_date_time_unref ( now );
}
Esempio n. 13
0
void
mex_content_set_last_used_metadatas (MexContent *content)
{
  guint count;
  gchar str[20], *nstr;
  const gchar *play_count;
  GDateTime *datetime;
  GTimeVal tv;

  play_count = mex_content_get_metadata (content,
                                         MEX_CONTENT_METADATA_PLAY_COUNT);
  if (play_count) {
    count = atoi (play_count);
    count++;
  } else
    count = 1;
  snprintf (str, sizeof (str), "%u", count);
  mex_content_set_metadata (content, MEX_CONTENT_METADATA_PLAY_COUNT, str);

  datetime = g_date_time_new_now_local ();
  if (datetime) {
    if (g_date_time_to_timeval (datetime, &tv)) {
      tv.tv_usec = 0;
      nstr = g_time_val_to_iso8601 (&tv);
      if (nstr) {
        mex_content_set_metadata (content,
                                  MEX_CONTENT_METADATA_LAST_PLAYED_DATE,
                                  nstr);
        g_free (nstr);
      }
    }
    g_date_time_unref (datetime);
  }
}
Esempio n. 14
0
gchar *tagsistant_get_timestamp()
{
	GDateTime *dt = g_date_time_new_now_local();
	gchar *stamp = g_date_time_format(dt, "%Y-%m-%d-%H-%M-%S-%s");
	g_date_time_unref(dt);
	return (stamp);
}
static void
time_converter(GBinding* bind,
               const GValue* from,
               GValue* to,
               gpointer udata)
{
    gchar* label = NULL;
    GDateTime* now_time;
    GDateTime* stream_started_time;
    GTimeSpan dif;

    if (g_value_get_pointer(from) != NULL)
    {
        now_time = g_date_time_new_now_utc();
        stream_started_time = (GDateTime*) g_value_get_pointer(from);

        dif = g_date_time_difference(now_time, stream_started_time);

        if (dif > G_TIME_SPAN_HOUR)
            label = g_strdup_printf("%2.1fh", (gdouble) dif / G_TIME_SPAN_HOUR);
        else
            label = g_strdup_printf("%ldm", dif / G_TIME_SPAN_MINUTE);

        g_date_time_unref(now_time);
    }

    g_value_take_string(to, label);
}
Esempio n. 16
0
void
create_status_bar(void)
{
    int i;
    int cols = getmaxx(stdscr);

    is_active[1] = TRUE;
    is_new[1] = FALSE;
    for (i = 2; i < 12; i++) {
        is_active[i] = FALSE;
        is_new[i] = FALSE;
    }
    remaining_active = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, NULL);
    remaining_new = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, NULL);
    current = 1;

    int bracket_attrs = theme_attrs(THEME_STATUS_BRACKET);

    int row = screen_statusbar_row();
    status_bar = newwin(1, cols, row, 0);
    wbkgd(status_bar, theme_attrs(THEME_STATUS_TEXT));
    wattron(status_bar, bracket_attrs);
    mvwprintw(status_bar, 0, cols - 34, _active);
    mvwprintw(status_bar, 0, cols - 34 + ((current - 1) * 3), bracket);
    wattroff(status_bar, bracket_attrs);

    tz = g_time_zone_new_local();

    if (last_time) {
        g_date_time_unref(last_time);
    }
    last_time = g_date_time_new_now(tz);

    _status_bar_draw();
}
DateTime DateTime::add_full(int year, int month, int day, int hour, int minute, double seconds) const
{
    auto gdt = g_date_time_add_full(get(), year, month, day, hour, minute, seconds);
    DateTime dt(m_tz.get(), gdt);
    g_date_time_unref(gdt);
    return dt;
}
Esempio n. 18
0
static void
_status_bar_resize(void)
{
    int rows, cols;
    getmaxyx(stdscr, rows, cols);

    mvwin(status_bar, rows-2, 0);
    wresize(status_bar, 1, cols);
    wbkgd(status_bar, COLOUR_STATUS_TEXT);
    werase(status_bar);
    wattron(status_bar, COLOUR_STATUS_BRACKET);
    mvwprintw(status_bar, 0, cols - 34, _active);
    mvwprintw(status_bar, 0, cols - 34 + ((current - 1) * 3), bracket);
    wattroff(status_bar, COLOUR_STATUS_BRACKET);

    _update_win_statuses();

    if (message != NULL)
        mvwprintw(status_bar, 0, 10, message);

    if (last_time != NULL)
        g_date_time_unref(last_time);
    last_time = g_date_time_new_now_local();
    dirty = TRUE;
}
Esempio n. 19
0
static void
_win_chat_print_incoming_message(ProfWin *window, GTimeVal *tv_stamp,
    const char * const from, const char * const message)
{
    if (tv_stamp == NULL) {
        win_print_time(window, '-');
    } else {
        GDateTime *time = g_date_time_new_from_timeval_utc(tv_stamp);
        gchar *date_fmt = g_date_time_format(time, "%H:%M:%S");
        wattron(window->win, COLOUR_TIME);
        wprintw(window->win, "%s - ", date_fmt);
        wattroff(window->win, COLOUR_TIME);
        g_date_time_unref(time);
        g_free(date_fmt);
    }

    if (strncmp(message, "/me ", 4) == 0) {
        wattron(window->win, COLOUR_THEM);
        wprintw(window->win, "*%s ", from);
        waddstr(window->win, message + 4);
        wprintw(window->win, "\n");
        wattroff(window->win, COLOUR_THEM);
    } else {
        wattron(window->win, COLOUR_THEM);
        wprintw(window->win, "%s: ", from);
        wattroff(window->win, COLOUR_THEM);
        waddstr(window->win, message);
        wprintw(window->win, "\n");
    }
}
Esempio n. 20
0
static void
_create_status_bar(void)
{
    int rows, cols, i;
    getmaxyx(stdscr, rows, cols);

    is_active[1] = TRUE;
    is_new[1] = FALSE;
    for (i = 2; i < 12; i++) {
        is_active[i] = FALSE;
        is_new[i] = FALSE;
    }
    remaining_active = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, NULL);
    remaining_new = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, NULL);
    current = 1;

    status_bar = newwin(1, cols, rows-2, 0);
    wbkgd(status_bar, COLOUR_STATUS_TEXT);
    wattron(status_bar, COLOUR_STATUS_BRACKET);
    mvwprintw(status_bar, 0, cols - 34, _active);
    mvwprintw(status_bar, 0, cols - 34 + ((current - 1) * 3), bracket);
    wattroff(status_bar, COLOUR_STATUS_BRACKET);

    if (last_time != NULL)
        g_date_time_unref(last_time);
    last_time = g_date_time_new_now_local();

    dirty = TRUE;
}
Esempio n. 21
0
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
}
Esempio n. 22
0
static gchar *cm_get_cookie_description_text(SoupCookie *cookie)
{
    gchar *expires;
    gchar *text;

    g_return_val_if_fail(cookie != NULL, NULL);

    if (cookie->expires != NULL)
    {
        time_t expiration_time = soup_date_to_time_t(cookie->expires);
        GDateTime* date = g_date_time_new_from_unix_local(expiration_time);
        expires = g_date_time_format(date, "%c");
        g_date_time_unref(date);
    }
    else
        expires = g_strdup(_("At the end of the session"));

    text = g_markup_printf_escaped(
               _("<b>Host</b>: %s\n<b>Name</b>: %s\n<b>Value</b>: %s\n<b>Path</b>: %s\n"
                 "<b>Secure</b>: %s\n<b>Expires</b>: %s"),
               cookie->domain,
               cookie->name,
               cookie->value,
               cookie->path,
               /* i18n: is this cookie secure (SSL)? yes/ no */
               cookie->secure ? _("Yes") : _("No"),
               expires);
    g_free(expires);

    return text;
}
static void
gst_timecodestamper_set_property (GObject * object, guint prop_id,
    const GValue * value, GParamSpec * pspec)
{
  GstTimeCodeStamper *timecodestamper = GST_TIME_CODE_STAMPER (object);

  switch (prop_id) {
    case PROP_OVERRIDE_EXISTING:
      timecodestamper->override_existing = g_value_get_boolean (value);
      break;
    case PROP_DROP_FRAME:
      timecodestamper->drop_frame = g_value_get_boolean (value);
      break;
    case PROP_SOURCE_CLOCK:
      if (timecodestamper->source_clock)
        gst_object_unref (timecodestamper->source_clock);
      timecodestamper->source_clock = g_value_dup_object (value);
      break;
    case PROP_DAILY_JAM:
      if (timecodestamper->current_tc->config.latest_daily_jam)
        g_date_time_unref (timecodestamper->current_tc->
            config.latest_daily_jam);
      timecodestamper->current_tc->config.latest_daily_jam =
          g_value_dup_boxed (value);
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
  }
}
Esempio n. 24
0
gboolean
nautilus_file_date_in_between (guint64    unix_file_time,
                               GDateTime *initial_date,
                               GDateTime *end_date)
{
    GDateTime *date;
    gboolean in_between;

    /* Silently ignore errors */
    if (unix_file_time == 0)
    {
        return FALSE;
    }

    date = g_date_time_new_from_unix_local (unix_file_time);

    /* For the end date, we want to make end_date inclusive,
     * for that the difference between the start of the day and the in_between
     * has to be more than -1 day
     */
    in_between = g_date_time_difference (date, initial_date) > 0 &&
                 g_date_time_difference (end_date, date) / G_TIME_SPAN_DAY > -1;

    g_date_time_unref (date);

    return in_between;
}
Esempio n. 25
0
gchar *
gl_util_boot_time_to_display (guint64 realtime_first,
                              guint64 realtime_last)
{
    gchar *time_first;
    gchar *time_last;
    gchar *time_display;
    GDateTime *now;
    GSettings *settings;
    GlUtilClockFormat clock_format;

    /* TODO: Monitor and propagate any GSettings changes. */
    settings = g_settings_new (DESKTOP_SCHEMA);
    clock_format = g_settings_get_enum (settings, CLOCK_FORMAT);

    g_object_unref (settings);

    now = g_date_time_new_now_local ();
    time_first = gl_util_timestamp_to_display (realtime_first,
                                               now, clock_format, FALSE);
    time_last = gl_util_timestamp_to_display (realtime_last,
                                              now, clock_format, FALSE);

    /* Transltors: the first string is the earliest timestamp of the boot,
     * and the second string is the newest timestamp. An example string might
     * be '08:10 - 08:30' */
    time_display = g_strdup_printf (_("%s – %s"), time_first, time_last);

    g_date_time_unref (now);
    g_free (time_first);
    g_free (time_last);

    return time_display;
}
static void
show_week_label (UmHistoryDialog *um)
{
        gchar *label, *from, *to;
        GDateTime *date;
        GTimeSpan span;

        span = g_date_time_difference (um->current_week, um->week);
        if (span == 0) {
                label = g_strdup (_("This Week"));
        }
        else if (span == G_TIME_SPAN_DAY * 7) {
                label = g_strdup (_("Last Week"));
        }
        else {
                date = g_date_time_add_days (um->week, 6);
                from = g_date_time_format (um->week, "%b %e");
                if (g_date_time_get_year (um->week) == g_date_time_get_year (um->current_week)) {
                        to = g_date_time_format (date, "%b %e");
                }
                else {
                        to = g_date_time_format (date, "%b %e, %Y");
                }

                label = g_strconcat (from, " - ", to, NULL);

                g_date_time_unref (date);
                g_free (from);
                g_free (to);
        }

        gtk_label_set_label (GTK_LABEL (get_widget (um, "week-label")), label);

        g_free (label);
}
Esempio n. 27
0
static void
log_handler (const gchar *log_domain, GLogLevelFlags log_level, const gchar *message, gpointer user)
{
    gsize       n_written;
    GError     *error = NULL;
    GIOChannel *channel = user;

#if GLIB_CHECK_VERSION(2, 26, 0)
    GTimeZone  *tz;
    GDateTime  *date_time;
    gchar      *new_message;

    tz = g_time_zone_new_local ();
    date_time = g_date_time_new_now (tz);

    new_message = g_strdup_printf ("[%s] %s\n", g_date_time_format (date_time, "%FT%H:%M:%S%z"), message);

    g_time_zone_unref (tz);
    g_date_time_unref (date_time);

    g_io_channel_write_chars (channel, new_message, strlen (new_message), &n_written, &error);
    g_assert_no_error (error);
    g_free (new_message);
#else
    g_io_channel_write_chars (channel, message, strlen (message), &n_written, &error);
    g_assert_no_error (error);
#endif

    g_io_channel_flush (channel, &error);
    g_assert_no_error (error);
}
Esempio n. 28
0
/**
 * Ends the clock and prints the elapsed time and then frees everything
 * @param my_clock is a clock_t * structure with begin already filled
 * @param message is a message that we want to include into the displayed
 *        result in order to know what was measured.
 */
void end_clock(a_clock_t *my_clock, gchar *message)
{
    GTimeSpan difference = 0;

    if (my_clock != NULL && my_clock->begin != NULL)
        {
            my_clock->end = g_date_time_new_now_local();
            difference = g_date_time_difference(my_clock->end, my_clock->begin);

            g_date_time_unref(my_clock->begin);
            g_date_time_unref(my_clock->end);
            free_variable(my_clock);

            print_debug(_("Elapsed time (%s): %d µs\n"), message, difference);
        }
}
Esempio n. 29
0
static void
mnb_statusbar_update_datetime (MnbStatusbar *self)
{
  MnbStatusbarPrivate *priv = self->priv;
  GDateTime *datetime = g_date_time_new_now_local ();
  gchar *time_str;
  GConfClient *client = gconf_client_get_default ();
  gboolean c24h = gconf_client_get_bool (client, MNB_24H_KEY, NULL);

  if (c24h)
    {

      /* translators: translate this to a suitable 24 hourt time
       * format for your locale showing only hours and minutes. For
       * available format specifiers see
       * http://www.opengroup.org/onlinepubs/007908799/xsh/strftime.html
       */
      time_str = g_date_time_format (datetime, _("%A %B %e, %Y - %H:%M"));
    }
  else
    {
      /* translators: translate this to a suitable default time format for
       * your locale showing only hours and minutes. For available format
       * specifiers see
       * http://www.opengroup.org/onlinepubs/007908799/xsh/strftime.html
       */
      time_str = g_date_time_format (datetime, _("%A %B %e, %Y - %l:%M %P"));
    }

  mx_button_set_label (MX_BUTTON (priv->datetime), time_str);

  g_date_time_unref (datetime);
  g_free (time_str);
}
Esempio n. 30
0
static void
schedule_wakeups_with_timeout_source (GoaAlarm *self)
{
  GDateTime *now;
  GSource   *source;
  GTimeSpan  time_span;
  guint      interval;

  self->priv->type = GOA_ALARM_TYPE_TIMEOUT;

  now = g_date_time_new_now_local ();
  time_span = g_date_time_difference (self->priv->time, now);
  g_date_time_unref (now);

  time_span =
    CLAMP (time_span, 1000 *G_TIME_SPAN_MILLISECOND,
           G_MAXUINT *G_TIME_SPAN_MILLISECOND);
  interval = (guint) time_span / G_TIME_SPAN_MILLISECOND;

  /* We poll every 10 seconds or so because we want to catch time skew
   */
  interval = MIN (interval, MAX_TIMEOUT_INTERVAL);

  source = g_timeout_source_new (interval);

  self->priv->scheduled_wakeup_source = source;
  g_source_set_callback (self->priv->scheduled_wakeup_source,
                         (GSourceFunc)
                         on_timeout_source_ready,
                         self, (GDestroyNotify) clear_wakeup_source_pointer);

  g_source_attach (self->priv->scheduled_wakeup_source, self->priv->context);
  g_source_unref (source);
}