Пример #1
0
void
print_days_until_birthday (void)
{


  /*Calculate how many days there are between now and my
    birthday. (If you get something out of this glib-cookbook then
    feel free to send me a present after that many days go by. ;) */

  GTimeZone *tz;
  GDateTime *now;
  GDateTime *bday;
  GTimeSpan diff;

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

  bday = (GDateTime *)g_date_time_new(tz, g_date_time_get_year(now) + 1, 6, 25, 0, 0, 0);

  diff = g_date_time_difference(bday, now);
  
  g_print("There are %ld days until Jamil's birthday.\n",
	  diff / G_TIME_SPAN_DAY);
  
  g_date_time_unref(now);
  g_date_time_unref(bday);
  g_time_zone_unref(tz);

}
Пример #2
0
void
print_tomorrows_date (void)
{

  /* Figure out what tomorrow's date is and print it to stdio. */

  GTimeZone *tz;
  
  GDateTime *dt1;
  GDateTime *dt2;
  gchar *str;
  
  tz = (GTimeZone *)g_time_zone_new_local();

  dt1 = (GDateTime *)g_date_time_new_now(tz);
  dt2 = (GDateTime *)g_date_time_add_days(dt1, 1);
  str = (gchar *)g_date_time_format(dt2, "Tomorrow is %c.\n");
  g_print("%s\n", str);
  
  g_date_time_unref(dt1);
  g_date_time_unref(dt2);
  g_time_zone_unref(tz);
  g_free(str);

}
Пример #3
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::Local(int year, int month, int day, int hour, int minute, double seconds)
{
    auto gtz = g_time_zone_new_local();
    DateTime dt(gtz, year, month, day, hour, minute, seconds);
    g_time_zone_unref(gtz);
    return dt;
}
Пример #5
0
/**
 * time_edit_click:
 */
static void time_edit_click ( GtkWidget* widget, GdkEventButton *event, VikWaypoint *wp )
{
  if ( event->button == 3 ) {
    // On right click and when a time is available, allow a method to copy the displayed time as text
    if ( !gtk_button_get_image ( GTK_BUTTON(widget) ) ) {
      vu_copy_label_menu ( widget, event->button );
    }
    return;
  }
  else if ( event->button == 2 ) {
    return;
  }

  GTimeZone *gtz = g_time_zone_new_local ();
  time_t mytime = vik_datetime_edit_dialog ( GTK_WINDOW(gtk_widget_get_toplevel(widget)),
                                             _("Date/Time Edit"),
                                             wp->timestamp,
                                             gtz );
  g_time_zone_unref ( gtz );

  // Was the dialog cancelled?
  if ( mytime == 0 )
    return;

  // Otherwise use new value in the edit buffer
  edit_wp->timestamp = mytime;

  // Clear the previous 'Add' image as now a time is set
  if ( gtk_button_get_image ( GTK_BUTTON(widget) ) )
    gtk_button_set_image ( GTK_BUTTON(widget), NULL );

  update_time ( widget, edit_wp );
}
Пример #6
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);

}
Пример #7
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);
}
Пример #8
0
static VALUE
rg_s_local(G_GNUC_UNUSED VALUE self)
{
    GTimeZone *time_zone = NULL;
    time_zone = g_time_zone_new_local();
    return GTIMEZONE2RVAL(time_zone);
}
Пример #9
0
void
log_init(log_level_t filter)
{
    level_filter = filter;
    tz = g_time_zone_new_local();
    gchar *log_file = _get_log_file();
    logp = fopen(log_file, "a");
    free(log_file);
}
Пример #10
0
DateTime DateTime::Local(time_t t)
{
    auto gtz = g_time_zone_new_local();
    auto gdt = g_date_time_new_from_unix_local(t);
    DateTime dt(gtz, gdt);
    g_time_zone_unref(gtz);
    g_date_time_unref(gdt);
    return dt;
}
Пример #11
0
DateTime DateTime::NowLocal()
{
    auto gtz = g_time_zone_new_local();
    auto gdt = g_date_time_new_now(gtz);
    DateTime dt(gtz, gdt);
    g_time_zone_unref(gtz);
    g_date_time_unref(gdt);
    return dt;
}
Пример #12
0
void
log_init(log_level_t filter)
{
    level_filter = filter;
    tz = g_time_zone_new_local();
    gchar *log_file = _get_main_log_file();
    logp = fopen(log_file, "a");
    g_chmod(log_file, S_IRUSR | S_IWUSR);
    mainlogfile = g_string_new(log_file);
    free(log_file);
}
Пример #13
0
static gboolean
update_timezone (gpointer data)
{
	GnomeWallClock *self = data;

	if (self->priv->timezone != NULL)
		g_time_zone_unref (self->priv->timezone);
	self->priv->timezone = g_time_zone_new_local ();
	g_object_notify ((GObject*)self, "timezone");

	return update_clock (data);
}
Пример #14
0
void
print_dates_sorted (void)
{

  /* Choose five dates randomly from a time interval, sort them, and
     send to stdio. */

  GTimeZone *tz;
  GPtrArray *dates;
  GDateTime *dt;
  gchar *str;
  gint i;

  tz = (GTimeZone *)g_time_zone_new_local();
  
  dates = g_ptr_array_new();
  g_ptr_array_set_free_func(dates, (GDestroyNotify)g_date_time_unref);
  
  /*
   * Insert some random dates into the array.
   */
  for (i = 0; i < 5; i++) {
    dt = (GDateTime *)g_date_time_new(tz,
				      g_random_int_range(1900, 2020),
				      g_random_int_range(1, 12),
				      g_random_int_range(1, 28),
				      0, 0, 0);
    g_ptr_array_add(dates, dt);
  }

	/*
	 * Sort dates.  Remember that GPtrArray returns a pointer to the
	 * pointer type in sorting methods so they need to be dereferenced.
	 */
	g_ptr_array_sort(dates, gdt_sorter);

	/*
	 * Print out the dates
	 */
	g_print("Dates sorted in order:\n");
	for (i = 0; i < dates->len; i++) {
		dt = g_ptr_array_index(dates, i);
		str = g_date_time_format(dt, "%b %d, %Y");
		g_print("  %s\n", str);
		g_free(str);
	}

	g_ptr_array_unref(dates);
	g_time_zone_unref(tz);

}
gint
main (gint argc,
      gchar *argv[])
{

  // if final value remains 0 the test is passed otherwise return a -1: 
  gint retVal = 0;

  GTimeZone *tz = (GTimeZone *)g_time_zone_new_local();  
  //gint64 year, month, day;

  GDateTime *date00 = (GDateTime *)g_date_time_new(tz, 2015, 10, 1, 0, 0, 0);
  GDateTime *date01 = (GDateTime *)g_date_time_new(tz, 2015, 10, 1, 0, 0, 0);
  GDateTime *date02 = (GDateTime *)g_date_time_new(tz, 2015, 10, 1, 0, 0, 0);

  GDateTime *dt_1 =  str_to_gdatetime(tz, "20151001", "%4d%2d%2d");
  if (g_date_time_compare(date00, dt_1) != 0) {
    g_printf("%s was improperly parsed as a GDateTime!", "20151001");
    retVal = -1;
  }
  g_date_time_unref(dt_1);

  GDateTime *dt_2 = str_to_gdatetime(tz, "2015/10/01", "%d/%d/%d");
  if (g_date_time_compare(date01, dt_2) != 0) {
    g_printf("%s was improperly parsed as a GDateTime!", "2015/10/01");
    retVal = -1;
  }
  g_date_time_unref(dt_2);

  GDateTime *dt_3 = str_to_gdatetime(tz, "2015-10-01", "%d-%d-%d");
  if (g_date_time_compare(date02, dt_3) != 0) {
    g_printf("%s was improperly parsed as a GDateTime!", "2015-10-01");
    retVal = -1;
  }
  g_date_time_unref(dt_3);
  
  if (retVal == 0) {
    g_printf("All test strings were properly parsed as GDateTimes in check_str_to_gdatetime.");
  }

  // clean everything up:
  g_date_time_unref(date00);
  g_date_time_unref(date01);
  g_date_time_unref(date02);

  g_time_zone_unref(tz);

  return retVal;

}
Пример #16
0
static gboolean
is_new_record (OfficeRunner *run,
	       int          *new_pos)
{
	ORecord *o;
	guint i;
	gboolean new_record;
	GList *l;

#if 0
	GDateTime *dt;
	GTimeZone *tz;
	char *date;
#endif

	new_record = FALSE;

#if 0
	/* Unused */
	tz = g_time_zone_new_local ();
	dt = g_date_time_new_now (tz);
	date = g_date_time_format (dt, "%c");
	g_date_time_unref (dt);
	g_time_zone_unref (tz);
	g_free (date);
#endif
	o = new_orecord (run->elapsed);
	run->records = g_list_insert_sorted (run->records, o, (GCompareFunc) record_compare_func);
	g_debug ("Elapsed: %lf", o->time);
	for (l = run->records, i = GOLD; l != NULL; l = l->next, i++)
		g_debug ("\t%d = %lf", i, ((ORecord *) l->data)->time);

	*new_pos = 0;
	for (l = run->records, i = GOLD; i <= BRONZE; l = l->next, i++) {
		ORecord *o = l->data;
		if (run->elapsed == o->time && i <= BRONZE) {
			new_record = TRUE;
			*new_pos = i;
			break;
		}
	}

	if (new_record == FALSE)
		return FALSE;

	run->dirty_records = TRUE;

	return TRUE;
}
Пример #17
0
GSList *
chat_log_get_previous(const gchar * const login, const gchar * const recipient,
    GSList *history)
{
    GTimeZone *tz = g_time_zone_new_local();

    GDateTime *now = g_date_time_new_now_local();
    GDateTime *log_date = g_date_time_new(tz,
        g_date_time_get_year(session_started),
        g_date_time_get_month(session_started),
        g_date_time_get_day_of_month(session_started),
        g_date_time_get_hour(session_started),
        g_date_time_get_minute(session_started),
        g_date_time_get_second(session_started));

    // get data from all logs from the day the session was started to today
    while (g_date_time_compare(log_date, now) != 1) {
        char *filename = _get_log_filename(recipient, login, log_date, FALSE);

        FILE *logp = fopen(filename, "r");
        char *line;
        if (logp != NULL) {
            GString *gs_header = g_string_new("");
            g_string_append_printf(gs_header, "%d/%d/%d:",
                g_date_time_get_day_of_month(log_date),
                g_date_time_get_month(log_date),
                g_date_time_get_year(log_date));
            char *header = strdup(gs_header->str);
            history = g_slist_append(history, header);
            g_string_free(gs_header, TRUE);

            while ((line = prof_getline(logp)) != NULL) {
                history = g_slist_append(history, line);
            }

            fclose(logp);
        }

        free(filename);
        GDateTime *next = g_date_time_add_days(log_date, 1);
        g_date_time_unref(log_date);
        log_date = g_date_time_ref(next);
    }

    g_time_zone_unref(tz);

    return history;
}
Пример #18
0
/***********************************************************\
 * GLib's GTimeZone doesn't work with MSWindows, which in turn breaks
 * g_date_time_new_local, g_date_time_new_from_unix_local,
 * g_date_time_new_from_timeval_local, and gnc_g_date_time_to_local. The
 * following functions provide a work-around.
 */
static GTimeZone*
gnc_g_time_zone_new_local (void)
{
#ifndef G_OS_WIN32
    return g_time_zone_new_local();
#else
    TIME_ZONE_INFORMATION tzinfo;
    gint64 dst = GetTimeZoneInformation (&tzinfo);
    gint bias = tzinfo.Bias + tzinfo.StandardBias;
    gint hours = -bias / 60; // 60 minutes per hour
    gint minutes = (bias < 0 ? -bias : bias) % 60;
    gchar *tzstr = g_strdup_printf ("%+03d:%02d", hours, minutes);
    GTimeZone *tz = g_time_zone_new(tzstr);
    g_free (tzstr);
    return tz;
#endif
}
static void
update_timestamp (IdoLocationMenuItem * self)
{
  GTimeZone * tz;
  GDateTime * date_time;

  tz = g_time_zone_new (self->priv->timezone);
  if (tz == NULL)
    tz = g_time_zone_new_local ();
  date_time = g_date_time_new_now (tz);

  ido_time_stamp_menu_item_set_date_time (IDO_TIME_STAMP_MENU_ITEM(self),
                                          date_time);

  g_date_time_unref (date_time);
  g_time_zone_unref (tz);
}
Пример #20
0
/**
 * tpwin_sync_time_to_tp:
 *
 */
static void tpwin_sync_time_to_tp ( GtkWidget* widget, GdkEventButton *event, VikTrwLayerTpwin *tpwin )
{
  if ( !tpwin->cur_tp || tpwin->sync_to_tp_block )
    return;

  if ( event->button == 3 ) {
    // On right click and when a time is available, allow a method to copy the displayed time as text
    if ( !gtk_button_get_image ( GTK_BUTTON(widget) ) ) {
       vu_copy_label_menu ( widget, event->button );
    }
    return;
  }
  else if ( event->button == 2 ) {
    return;
  }

  if ( !tpwin->cur_tp || tpwin->sync_to_tp_block )
    return;

  if ( tpwin->cur_tp->has_timestamp )
    last_edit_time = tpwin->cur_tp->timestamp;
  else if ( last_edit_time == 0 )
    time ( &last_edit_time );

  GTimeZone *gtz = g_time_zone_new_local ();
  time_t mytime = vik_datetime_edit_dialog ( GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(&tpwin->parent))),
                                             _("Date/Time Edit"),
                                             last_edit_time,
                                             gtz );
  g_time_zone_unref ( gtz );

  // Was the dialog cancelled?
  if ( mytime == 0 )
    return;

  // Otherwise use the new value
  tpwin->cur_tp->timestamp = mytime;
  tpwin->cur_tp->has_timestamp = TRUE;
  // TODO: consider warning about unsorted times?

  // Clear the previous 'Add' image as now a time is set
  if ( gtk_button_get_image ( GTK_BUTTON(tpwin->time) ) )
    gtk_button_set_image ( GTK_BUTTON(tpwin->time), NULL );

  tpwin_update_times ( tpwin, tpwin->cur_tp );
}
Пример #21
0
/** 
 * Creates a GDate set to yesterday.
 * 
 * 
 * @return A GDate with year, month, and day set to yesterday.
 */
GDate *yesterday(void)
{

  GTimeZone *tz = g_time_zone_new_local();
  GDateTime *now = g_date_time_new_now(tz);
  g_time_zone_unref(tz);
  gint year, month, day;
  GDateTime *temp_copy = g_date_time_add_days(now, -1);
  g_date_time_unref(now);
  g_date_time_get_ymd(temp_copy, &year, &month, &day);
  g_date_time_unref(temp_copy);

  // and now we can create yesterday:
  GDate *yest = g_date_new_dmy(day, month, year);

  return yest;
  
}
Пример #22
0
void
convert_str_to_gdatetime(void)
{

  GTimeZone *tz = (GTimeZone *)g_time_zone_new_local();  

  GDateTime *date00 = str_to_gdatetime(tz, "20151001", "%4d%2d%2d");
  GDateTime *date01 = str_to_gdatetime(tz, "2015/10/01", "%d/%d/%d");
  GDateTime *date02 = str_to_gdatetime(tz, "2015-10-01", "%d-%d-%d");

  g_print("%s", (gchar *)g_date_time_format(date00, "test00: %c.\n"));
  g_print("%s", (gchar *)g_date_time_format(date01, "test01: %c.\n"));
  g_print("%s", (gchar *)g_date_time_format(date02, "test02: %c.\n"));

  g_date_time_unref(date00);
  g_date_time_unref(date01);
  g_date_time_unref(date02);
  g_time_zone_unref(tz);

}
Пример #23
0
void
print_current_timezone (void)
{

  /* Print a string representation of the local time zone to stdio. */

  GTimeZone *tz;
  GDateTime *dt;

  tz = (GTimeZone *)g_time_zone_new_local();
  
  dt = (GDateTime *)g_date_time_new_now(tz);
  g_print("The current timezone is %s.\n",
	  g_date_time_get_timezone_abbreviation(dt));

  g_date_time_unref(dt);
  g_time_zone_unref(tz);


}
Пример #24
0
void
print_todays_date (void)
{

  /* Just figure out what the current date is and print it. */

  GTimeZone *tz;
  GDateTime *dt;
  gchar *str;
  
  tz = (GTimeZone *)g_time_zone_new_local();
    dt = (GDateTime *)g_date_time_new_now(tz);
  str = (gchar *)g_date_time_format(dt, "Today is %c.\n");
  g_printf("%s\n", str);
  
  /* You gotta unref and free up all those gThingys. */

  g_date_time_unref(dt);
  g_time_zone_unref(tz);
  g_free(str);
}
Пример #25
0
static void
gnome_wall_clock_init (GnomeWallClock *self)
{
	GFile *tz;

	self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GNOME_TYPE_WALL_CLOCK, GnomeWallClockPrivate);

	self->priv->timezone = g_time_zone_new_local ();

	self->priv->clock_string = NULL;
	
	tz = g_file_new_for_path ("/etc/localtime");
	self->priv->tz_monitor = g_file_monitor_file (tz, 0, NULL, NULL);
	g_object_unref (tz);
	
	g_signal_connect (self->priv->tz_monitor, "changed", G_CALLBACK (on_tz_changed), self);
	
	self->priv->desktop_settings = g_settings_new ("org.gnome.desktop.interface");
	g_signal_connect (self->priv->desktop_settings, "changed", G_CALLBACK (on_schema_change), self);

	update_clock (self);
}
Пример #26
0
void
print_yesterdays_date (void)
{

  /* Figure out what yesterday's date is and print it to stdio. */

  GTimeZone *tz;
  GDateTime *dt;
  GDateTime *dt2;
  gchar *str;

  tz = (GTimeZone *)g_time_zone_new_local();
  
  dt = (GDateTime *)g_date_time_new_now(tz);
  dt2 = (GDateTime *)g_date_time_add_days(dt, -1);
  str = (gchar *)g_date_time_format(dt2, "Yesterday was %c.\n");
  g_print("%s\n", str);
  
  g_date_time_unref(dt);
  g_date_time_unref(dt2);
  g_time_zone_unref(tz);
  g_free(str);

}
static gboolean
get_result_metas_cb (GcalShellSearchProvider  *search_provider,
                     GDBusMethodInvocation    *invocation,
                     gchar                   **results,
                     GcalShellSearchProvider2 *skel)
{
  GcalShellSearchProviderPrivate *priv;
  gint i;
  gchar *uuid, *desc;
  const gchar* location;

  g_autoptr(GTimeZone) tz;
  g_autoptr (GDateTime) datetime;
  g_autoptr (GDateTime) local_datetime;
  ECalComponentDateTime dtstart;
  gchar *start_date;

  ECalComponentText summary;
  GdkRGBA color;
  GVariantBuilder abuilder, builder;
  GVariant *icon_variant;
  GcalEventData *data;
  GdkPixbuf *gicon;

  priv = search_provider->priv;

  g_variant_builder_init (&abuilder, G_VARIANT_TYPE ("aa{sv}"));
  for (i = 0; i < g_strv_length (results); i++)
    {
      uuid = results[i];
      data = g_hash_table_lookup (priv->events, uuid);

      g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));
      g_variant_builder_add (&builder, "{sv}", "id", g_variant_new_string (uuid));

      e_cal_component_get_summary (data->event_component, &summary);
      g_variant_builder_add (&builder, "{sv}", "name", g_variant_new_string (summary.value));

      get_color_name_from_source (data->source, &color);
      gicon = get_circle_pixbuf_from_color (&color, 128);
      icon_variant = g_icon_serialize (G_ICON (gicon));
      g_variant_builder_add (&builder, "{sv}", "icon", icon_variant);
      g_object_unref (gicon);
      g_variant_unref (icon_variant);

      e_cal_component_get_dtstart (data->event_component, &dtstart);

      if (dtstart.tzid != NULL)
        tz = g_time_zone_new (dtstart.tzid);
      else if (dtstart.value->zone != NULL)
        tz = g_time_zone_new (icaltimezone_get_tzid ((icaltimezone*) dtstart.value->zone));
      else
        tz = g_time_zone_new_local ();

      datetime = g_date_time_new (tz,
                                  dtstart.value->year, dtstart.value->month, dtstart.value->day,
                                  dtstart.value->hour, dtstart.value->minute, dtstart.value->second);
      local_datetime = g_date_time_to_local (datetime);

      /* FIXME: respect 24h time format */
      start_date = g_date_time_format (local_datetime,
                                       (dtstart.value->is_date == 1) ? "%x" : "%c");
      e_cal_component_free_datetime (&dtstart);

      e_cal_component_get_location (data->event_component, &location);
      if (location != NULL)
        desc = g_strconcat (start_date, ". ", location, NULL);
      else
        desc = g_strdup (start_date);

      g_variant_builder_add (&builder, "{sv}", "description", g_variant_new_string (desc));
      g_free (start_date);
      g_free (desc);

      g_variant_builder_add_value (&abuilder, g_variant_builder_end (&builder));
    }
  g_dbus_method_invocation_return_value (invocation, g_variant_new ("(aa{sv})", &abuilder));

  return TRUE;
}
Пример #28
0
int main (int argc, char *argv[])
{
    GCContext    gc_context;
    GMainLoop   *mainLoop;
    GKeyFile    *keyFile;
    GThread     *displayThread;
    GThread     *inputControllerThread;
    GThread     *x11EventThread;
    int          i;

    
    GCConfig config = {
        .movie_path          = DEFAULT_MOVIE_PATH,
        .mask_path           = DEFAULT_MASK_PATH,
        .controller_path     = DEFAULT_CONTROLLER_PATH,
        .seconds_per_frame   = DEFAULT_SECONDS_PER_FRAME,
        .easing_factor       = DEFAULT_EASING_FACTOR,
        .frames_per_tick     = 0,
        .diameter_controller = 0,
        .diameter_rim        = 0,
        .ctr                 = 0,
        .fpr                 = 0,
        .number_of_frames    = 0,
        .fullscreen          = TRUE,
        .timeZone            = NULL,
    };

    Movie movie = {
        .planes             = NULL,
        .frame_offset       = 0,
        .fd_movie           = -1,
        .frame              = { .pitches = { FRAME_PITCH, 0, 0 } },
        .fd_mask            = -1,
        .mask               = { .pitches = { MASK_PITCH, 0, 0 } },
        .pre_load_surface   = VDP_INVALID_HANDLE,
        .play_direction     = DIRECTION_FORWARD,
        .ticks              = 0,
        .new_frame          = FALSE,
        .ease_to            = TRUE,
    };

    keyFile = g_key_file_new();
    if (argc > 1 && g_key_file_load_from_file(keyFile, argv[1], G_KEY_FILE_NONE, NULL)) {
        if (g_key_file_has_group(keyFile, "MAIN")) {
            if (g_key_file_has_key(keyFile, "MAIN", "utc_offset", NULL))
                config.timeZone = g_time_zone_new(g_key_file_get_string(keyFile, "MAIN", "utc_offset", NULL));
            if (g_key_file_has_key(keyFile, "MAIN", "ease_to_time", NULL))
                movie.ease_to = g_key_file_get_boolean(keyFile, "MAIN", "ease_to_time", NULL);
        }
 
        if (g_key_file_has_group(keyFile, "MOVIE")) {
           if (g_key_file_has_key(keyFile, "MOVIE", "file", NULL))
              config.movie_path = g_key_file_get_string(keyFile, "MOVIE", "file", NULL);
           if (g_key_file_has_key(keyFile, "MOVIE", "mask", NULL))
              config.mask_path = g_key_file_get_string(keyFile, "MOVIE", "mask", NULL);
           if (g_key_file_has_key(keyFile, "MOVIE", "seconds_per_frame", NULL))
              config.seconds_per_frame = (float)g_key_file_get_double(keyFile, "MOVIE", "seconds_per_frame", NULL);
           if (g_key_file_has_key(keyFile, "MOVIE", "easing_factor", NULL))
              config.easing_factor = (float)g_key_file_get_integer(keyFile, "MOVIE", "easing_factor", NULL);
        }
        
        if (g_key_file_has_group(keyFile, "CONTROLLER")) {
           if (g_key_file_has_key(keyFile, "CONTROLLER", "path", NULL))
              config.controller_path = g_key_file_get_string(keyFile, "CONTROLLER", "path", NULL);

           if (g_key_file_has_key(keyFile, "CONTROLLER", "diameter_controller", NULL))
              config.diameter_controller = (float)g_key_file_get_double(keyFile, "CONTROLLER", "diameter_controller", NULL);
           if (g_key_file_has_key(keyFile, "CONTROLLER", "diameter_rim", NULL))
              config.diameter_rim = (float)g_key_file_get_double(keyFile, "CONTROLLER", "diameter_rim", NULL);
           if (g_key_file_has_key(keyFile, "CONTROLLER", "ctr", NULL))
              config.ctr = (float)g_key_file_get_double(keyFile, "CONTROLLER", "ctr", NULL);
           if (g_key_file_has_key(keyFile, "CONTROLLER", "fpr", NULL))
              config.fpr = (float)g_key_file_get_double(keyFile, "CONTROLLER", "fpr", NULL);
           if (g_key_file_has_key(keyFile, "CONTROLLER", "frames_per_tick", NULL))
              config.frames_per_tick = (float)g_key_file_get_double(keyFile, "CONTROLLER", "frames_per_tick", NULL);
        }

        if (g_key_file_has_group(keyFile, "SCREEN")) {
           if (g_key_file_has_key(keyFile, "SCREEN", "fullscreen", NULL))
              config.fullscreen = g_key_file_get_boolean(keyFile, "SCREEN", "fullscreen", NULL);
        }
        g_key_file_free(keyFile);
    }

    if (!config.timeZone)
        config.timeZone = g_time_zone_new_local();

    if (!config.frames_per_tick && 
        !(config.frames_per_tick = frames_per_tick(config.diameter_controller,
                                                   config.diameter_rim,
                                                   config.ctr,
                                                   config.fpr)))
    {
        g_warning("No valid tick settings, using default frames per tick: %f", DEFAULT_FRAMES_PER_TICK);
        config.frames_per_tick = DEFAULT_FRAMES_PER_TICK;
    }

    config.movie_size = get_file_size(config.movie_path);
    config.number_of_frames = config.movie_size / FRAME_SIZE;
    
    mainLoop = g_main_loop_new(NULL, FALSE);

    gc_context.g_main_loop        = mainLoop;
    gc_context.g_main_context     = g_main_loop_get_context(mainLoop);
    gc_context.window_size.width  = MOVIE_WIDTH;
    gc_context.window_size.height = MOVIE_HEIGHT;
    gc_context.exit               = FALSE;
    gc_context.movie_context      = &movie;
    gc_context.config             = &config;


    g_message("movie file: %s",                           config.movie_path);
    g_message("movie size: %lu",                          config.movie_size);
    g_message("movie frames: %lu",                        config.number_of_frames);
    g_message("movie mask file: %s",                      config.mask_path);
    g_message("frames per minute: %f",                    get_frames_per_minute(&gc_context));
    g_message("frames per day:    %lu",                   get_frames_per_day(&gc_context));
    g_message("frames per tick:   %f",                    config.frames_per_tick);
    g_message("number of days:    %d",                    get_number_of_days(&gc_context));
    g_message("current day:       %d",                    get_current_day(&gc_context));

    if (movie.ease_to) {
        movie.ease_to_frame = get_frame_offset(&gc_context, GO_TO_RAND_DAY, DAY_OFFSET_NOW);
        g_message("ease to frame:    %lu", movie.ease_to_frame);
    }

    x11_init(&gc_context);
    vdpau_init(&gc_context);

    load_movie(&gc_context);
    load_mask(&gc_context);

    g_cond_init(&movie.tick_cond);
    g_mutex_init(&movie.tick_lock);
    g_mutex_init(&movie.frame_lock);

    displayThread = g_thread_new("Display thread", display_thread, (gpointer)&gc_context);
    inputControllerThread = g_thread_new("Input controller thread", input_controller_thread, (gpointer)&gc_context);
    x11EventThread = g_thread_new("X11 Event thread", x11_event_thread, (gpointer)&gc_context);

    g_main_loop_run(mainLoop);

    gc_context.exit = TRUE;
    g_thread_join(displayThread); 
    g_thread_join(inputControllerThread); 
    g_thread_join(x11EventThread); 
    g_cond_clear(&movie.tick_cond);
    g_mutex_clear(&movie.tick_lock);
    g_mutex_clear(&movie.frame_lock);
    g_time_zone_unref(config.timeZone);
}
int main() {

  // if final value remains 0 the test is passed otherwise return a -1: 
  gint retVal = 0;

  /************************************************/
  /* Create three time series for use in the tests: */
  /************************************************/

  // use the same time zone for all dates:
  GTimeZone *tz = (GTimeZone *)g_time_zone_new_local();
  
  //first time series:
  GSList* first_ts = NULL, *first_dates = NULL, *first_values = NULL;

  first_dates = g_slist_append(first_dates, g_date_time_new(tz, 2015, 10, 1, 1, 0, 0.0));
  first_dates = g_slist_append(first_dates, g_date_time_new(tz, 2015, 10, 1, 5, 0, 0.0));
  first_dates = g_slist_append(first_dates, g_date_time_new(tz, 2015, 10, 1, 6, 0, 0.0));

  // GSLists can only hold pointers to data so we need to init the
  // gfloats and then store their addresses in the GSList:
  gdouble p1 = 1.0;
  gdouble p2 = 1.0;
  gdouble p3 = 1.0;
  
  first_values = g_slist_append(first_values, &p1);
  first_values = g_slist_append(first_values, &p2);
  first_values = g_slist_append(first_values, &p3);

  first_ts = ts_gdt_double(first_dates, first_values);

  // second time series using different dates:
  GSList* second_ts = NULL, *second_dates = NULL, *second_values = NULL;

  second_dates = g_slist_append(second_dates, g_date_time_new(tz, 2015, 10, 1, 2, 0, 0.0));
  second_dates = g_slist_append(second_dates, g_date_time_new(tz, 2015, 10, 1, 5, 0, 0.0));
  second_dates = g_slist_append(second_dates, g_date_time_new(tz, 2015, 10, 1, 10, 0, 0.0));
  
  // GSLists can only hold pointers to data so we need to init the
  // gfloats and then store their addresses in the GSList:
  gdouble q1 = 1.0;
  gdouble q2 = 1.0;
  gdouble q3 = 1.0;
  
  second_values = g_slist_append(second_values, &q1);
  second_values = g_slist_append(second_values, &q2);
  second_values = g_slist_append(second_values, &q3);

  second_ts = ts_gdt_double(second_dates, second_values);

  // third time series using still different dates:
  GSList* third_ts = NULL, *third_dates = NULL, *third_values = NULL;

  third_dates = g_slist_append(third_dates, g_date_time_new(tz, 2015, 10, 1, 2, 0, 0.0));
  third_dates = g_slist_append(third_dates, g_date_time_new(tz, 2015, 10, 1, 5, 0, 0.0));
  third_dates = g_slist_append(third_dates, g_date_time_new(tz, 2015, 10, 1, 9, 0, 0.0));
  // GSLists can only hold pointers to data so we need to init the
  // gfloats and then store their addresses in the GSList:
  gdouble r1 = 1.0;
  gdouble r2 = 1.0;
  gdouble r3 = 1.0;
  
  third_values = g_slist_append(third_values, &r1);
  third_values = g_slist_append(third_values, &r2);
  third_values = g_slist_append(third_values, &r3);

  third_ts = ts_gdt_double(third_dates, third_values);

  // clean up that timezone that we used to create all the data:
  g_time_zone_unref(tz);
  
  /********************************************/
  /* Now let's look at our three time series: */
  /********************************************/
  g_printf("first ts: \n");
  ts_pretty_print(first_ts);
  g_printf("second ts: \n");
  ts_pretty_print(second_ts);
  g_printf("third ts: \n");
  ts_pretty_print(third_ts);
  
  /*******************************/
  /* Alignment test begins here: */
  /*******************************/

  // Put all the time series to be aligned into a single list:
  GSList *pre_aligned_list = NULL;
  pre_aligned_list = g_slist_append(pre_aligned_list, first_ts);
  pre_aligned_list = g_slist_append(pre_aligned_list, second_ts);
  pre_aligned_list = g_slist_append(pre_aligned_list, third_ts);

  // Alignment will create a new list of the same time series but they
  // all should now have the same domains:
  GSList *aligned_list = NULL, *iter_1 = NULL, *iter_2 = NULL, *iter_3 = NULL;

  // do the alignment:
  aligned_list = ts_align_hourly(pre_aligned_list);

  // now we do the check:
  GSList *al_first = (GSList *)g_slist_nth(aligned_list, 0)->data;
  GSList *al_second = (GSList *)g_slist_nth(aligned_list, 1)->data;
  GSList *al_third = (GSList *)g_slist_nth(aligned_list, 2)->data;

  // the resulting time series should all look like this:
  //date	first	second	third
  //2015-Oct-01	1	nan	nan
  //2015-Oct-02	nan	1	1
  //2015-Oct-03	nan	nan	nan
  //2015-Oct-04	nan	nan	nan
  //2015-Oct-05	1	1	1
  //2015-Oct-06	1	nan	nan
  //2015-Oct-07	nan	nan	nan
  //2015-Oct-08	nan	nan	nan
  //2015-Oct-09	nan	nan	1
  //2015-Oct-10	nan	1	nan

  // print out a table of the time series:
  g_printf("Date:\tfirst:\tsecond:\tthird:\n");
  for (iter_1 = al_first, iter_2 = al_second, iter_3 = al_third;	\
       iter_1 && iter_2 && iter_3;					\
       iter_1 = iter_1->next, iter_2 = iter_2->next, iter_3 = iter_3->next) {
    ts_datum_double *first_datum = iter_1->data;
    ts_datum_double *second_datum = iter_2->data;
    ts_datum_double *third_datum = iter_3->data;
    gchar *dt_str = (gchar *)g_date_time_format(first_datum->thedate, "%F %T");
    g_printf("%s\t%g\t%g\t%g\n",					\
	     dt_str, \
	     first_datum->thevalue,					\
	     second_datum->thevalue,					\
	     third_datum->thevalue);
    g_free(dt_str);
  }

  // clean up the lists that were used to create the pre_aligned time
  // series:
  g_slist_free_full(first_dates, g_date_time_free);
  g_slist_free(first_values);
  g_slist_free_full(second_dates, g_date_time_free);
  g_slist_free(second_values);
  g_slist_free_full(third_dates, g_date_time_free);
  g_slist_free(third_values);

  // clean up the lists that are in the pre_aligned list of time series:
  g_slist_free_full(first_ts, ts_datum_double_free);
  g_slist_free_full(second_ts, ts_datum_double_free);
  g_slist_free_full(third_ts, ts_datum_double_free);
  g_slist_free(pre_aligned_list);

  // clean up the lists that in the aligned list of time series:
  g_slist_free_full(al_first, ts_datum_double_free);
  g_slist_free_full(al_second, ts_datum_double_free);
  g_slist_free_full(al_third, ts_datum_double_free);
  g_slist_free(aligned_list);
  
  return retVal;

}