From 6ea864111a1848be32afe946c855385ad6042487 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sun, 22 Apr 2012 09:51:54 -0500 Subject: indicator_datetime_panel's dispose() method needs to chain up to the superclass' dispose() method --- src/datetime-prefs.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/datetime-prefs.c b/src/datetime-prefs.c index 0e2e99c..615d601 100644 --- a/src/datetime-prefs.c +++ b/src/datetime-prefs.c @@ -829,6 +829,8 @@ indicator_datetime_panel_dispose (GObject * object) gtk_widget_destroy (priv->date_spin); priv->date_spin = NULL; } + + G_OBJECT_CLASS (indicator_datetime_panel_parent_class)->dispose (object); } static void -- cgit v1.2.3 From 51d32ea7bf60f234a68359a20b3fe74433e7ebcb Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sun, 22 Apr 2012 19:30:07 -0500 Subject: minor: silence two console warnings when the calendar app is disabled. --- src/datetime-service.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/datetime-service.c b/src/datetime-service.c index 8ecef1c..c2a4c27 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -579,8 +579,10 @@ check_for_calendar (gpointer user_data) g_signal_connect(calendar, "event::day-selected-double-click", G_CALLBACK(day_selected_double_click_cb), NULL); } else { g_debug("Unable to find calendar app."); - dbusmenu_menuitem_property_set_bool(add_appointment, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE); - dbusmenu_menuitem_property_set_bool(events_separator, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE); + if (add_appointment != NULL) + dbusmenu_menuitem_property_set_bool(add_appointment, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE); + if (events_separator != NULL) + dbusmenu_menuitem_property_set_bool(events_separator, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE); } if (g_settings_get_boolean(conf, SETTINGS_SHOW_CALENDAR_S)) { -- cgit v1.2.3 From 8c6f958633aca2dcd9999782939eafc7a32d7cb0 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 7 May 2012 16:48:29 -0700 Subject: require gtk3 --- configure.ac | 21 +++++---------------- src/datetime-service.c | 7 ------- src/indicator-datetime.c | 8 -------- 3 files changed, 5 insertions(+), 31 deletions(-) diff --git a/configure.ac b/configure.ac index 508fc9a..e4adc35 100644 --- a/configure.ac +++ b/configure.ac @@ -71,22 +71,11 @@ GLIB_REQUIRED_VERSION=2.29.19 GTK3_REQUIRED_VERSION=3.1.4 GCONF_REQUIRED_VERSION=2.31 -AS_IF([test "x$with_gtk" = x3], - [PKG_CHECK_MODULES(INDICATOR, indicator3-0.4 >= $INDICATOR_REQUIRED_VERSION - glib-2.0 >= $GLIB_REQUIRED_VERSION - dbusmenu-glib-0.4 >= $DBUSMENUGLIB_REQUIRED_VERSION - dbusmenu-gtk3-0.4 >= $DBUSMENUGTK_REQUIRED_VERSION - libido3-0.1 >= $INDICATOR_DISPLAY_OBJECTS) - ], - [test "x$with_gtk" = x2], - [PKG_CHECK_MODULES(INDICATOR, indicator-0.4 >= $INDICATOR_REQUIRED_VERSION - glib-2.0 >= $GLIB_REQUIRED_VERSION - dbusmenu-glib-0.4 >= $DBUSMENUGLIB_REQUIRED_VERSION - dbusmenu-gtk-0.4 >= $DBUSMENUGTK_REQUIRED_VERSION - libido-0.1 >= $INDICATOR_DISPLAY_OBJECTS) - ], - [AC_MSG_FAILURE([Value for --with-gtk was neither 2 nor 3])] -) +PKG_CHECK_MODULES(INDICATOR, indicator3-0.4 >= $INDICATOR_REQUIRED_VERSION + glib-2.0 >= $GLIB_REQUIRED_VERSION + dbusmenu-glib-0.4 >= $DBUSMENUGLIB_REQUIRED_VERSION + dbusmenu-gtk3-0.4 >= $DBUSMENUGTK_REQUIRED_VERSION + libido3-0.1 >= $INDICATOR_DISPLAY_OBJECTS) PKG_CHECK_MODULES(SERVICE, indicator3-0.4 >= $INDICATOR_REQUIRED_VERSION glib-2.0 >= $GLIB_REQUIRED_VERSION diff --git a/src/datetime-service.c b/src/datetime-service.c index c2a4c27..d264900 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -952,17 +952,10 @@ update_appointment_menu_items (gpointer user_data) if (color_spec != NULL) { g_debug("Creating a cairo surface: size, %d by %d", width, height); cairo_surface_t *surface = cairo_image_surface_create( CAIRO_FORMAT_ARGB32, width, height ); - cairo_t *cr = cairo_create(surface); -#if GTK_CHECK_VERSION(3,0,0) GdkRGBA rgba; if (gdk_rgba_parse (&rgba, color_spec)) gdk_cairo_set_source_rgba (cr, &rgba); -#else - GdkColor color; - if (gdk_color_parse (color_spec, &color)) - gdk_cairo_set_source_color (cr, &color); -#endif cairo_paint(cr); cairo_set_source_rgba(cr, 0,0,0,0.5); cairo_set_line_width(cr, 1); diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c index 77fdb40..9e34a65 100644 --- a/src/indicator-datetime.c +++ b/src/indicator-datetime.c @@ -1220,11 +1220,7 @@ new_appointment_item (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, Dbu mi_data->gmi = gtk_menu_item_new(); -#if GTK_CHECK_VERSION(3,0,0) GtkWidget * hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4); -#else - GtkWidget * hbox = gtk_hbox_new(FALSE, 4); -#endif /* Icon, probably someone's face or avatar on an IM */ mi_data->icon = gtk_image_new(); @@ -1435,11 +1431,7 @@ new_timezone_item(DbusmenuMenuitem * newitem, gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(mi_data->gmi), dbusmenu_menuitem_property_get_bool(newitem, TIMEZONE_MENUITEM_PROP_RADIO)); -#if GTK_CHECK_VERSION(3,0,0) GtkWidget * hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4); -#else - GtkWidget * hbox = gtk_hbox_new(FALSE, 4); -#endif /* Label, probably a username, chat room or mailbox name */ mi_data->label = gtk_label_new(""); -- cgit v1.2.3 From f07f4e1737450f58de2548e2570c17dc5bd1070f Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 8 May 2012 15:57:59 -0700 Subject: remove AC_ARG_WITH --- configure.ac | 25 +++++-------------------- 1 file changed, 5 insertions(+), 20 deletions(-) diff --git a/configure.ac b/configure.ac index e4adc35..e4c1c26 100644 --- a/configure.ac +++ b/configure.ac @@ -42,16 +42,6 @@ AC_PATH_PROG([GLIB_GENMARSHAL], [glib-genmarshal]) PKG_PROG_PKG_CONFIG -########################### -# GTK+ version option -########################### - -AC_ARG_WITH([gtk], - [AS_HELP_STRING([--with-gtk], - [Which version of gtk to use for the indicator @<:@default=3@:>@])], - [], - [with_gtk=3]) - ########################### # Dependencies ########################### @@ -112,7 +102,7 @@ if test x"$with_ccpanel" != x"no" ; then if test x${have_ccpanel} = xyes; then AC_DEFINE(HAVE_CCPANEL, 1, [Define to 1 to enable Control Center panel]) PKG_CHECK_MODULES(LIBMAP, gio-2.0 >= $GIO_REQUIRED_VERSION - gtk+-3.0 >= $GTK3_REQUIRED_VERSION) + gtk+-3.0 >= $GTK3_REQUIRED_VERSION) fi if test x${with_ccpanel} = xyes && test x${have_ccpanel} = xno; then AC_MSG_ERROR([Control Center panel configured but not found]) @@ -156,15 +146,10 @@ AS_IF([test "x$with_localinstall" = "xyes"], INDICATORDIR="${libdir}/indicators/2/" INDICATORICONSDIR="${datadir}/libindicate/icons/" ], - [AS_IF([test "x$with_gtk" = "x2"], - [ - INDICATORDIR=`$PKG_CONFIG --variable=indicatordir indicator-0.4` - INDICATORICONSDIR=`$PKG_CONFIG --variable=iconsdir indicator-0.4` - ], - [ - INDICATORDIR=`$PKG_CONFIG --variable=indicatordir indicator3-0.4` - INDICATORICONSDIR=`$PKG_CONFIG --variable=iconsdir indicator3-0.4` - ])]) + [ + INDICATORDIR=`$PKG_CONFIG --variable=indicatordir indicator3-0.4` + INDICATORICONSDIR=`$PKG_CONFIG --variable=iconsdir indicator3-0.4` + ]) AC_SUBST(INDICATORDIR) AC_SUBST(INDICATORICONSDIR) -- cgit v1.2.3 From fa15f08c01e6350437dbb7023b8947eb12ab4e30 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 17 May 2012 15:29:04 -0500 Subject: fix a bug that caused the location settings to re-saved every time update_times() was called (which is periodically every 2 seconds). --- src/datetime-prefs-locations.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/datetime-prefs-locations.c b/src/datetime-prefs-locations.c index 9f5b42c..0f21a5e 100644 --- a/src/datetime-prefs-locations.c +++ b/src/datetime-prefs-locations.c @@ -298,9 +298,13 @@ update_times (GtkWidget * dlg) GDateTime * now_tz = g_date_time_to_timezone (now, tz); gchar * format = generate_format_string_at_time (now_tz); gchar * time_str = g_date_time_format (now_tz, format); + gchar * old_time_str; - gtk_list_store_set (store, &iter, COL_TIME, time_str, -1); + gtk_tree_model_get (GTK_TREE_MODEL (store), &iter, COL_TIME, &old_time_str, -1); + if (g_strcmp0 (old_time_str, time_str)) + gtk_list_store_set (store, &iter, COL_TIME, time_str, -1); + g_free (old_time_str); g_free (time_str); g_free (format); g_date_time_unref (now_tz); -- cgit v1.2.3 From da61c2a69e259b029c39a6deb0f65217d90e73e4 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 17 May 2012 15:46:42 -0500 Subject: Add the "Time in auto-detected location" setting described in https://wiki.ubuntu.com/TimeAndDate --- data/com.canonical.indicator.datetime.gschema.xml | 7 +++++ data/datetime-dialog.ui | 19 ++++++++++++- src/datetime-prefs.c | 2 ++ src/datetime-service.c | 34 ++++++++++++++--------- src/settings-shared.h | 1 + 5 files changed, 49 insertions(+), 14 deletions(-) diff --git a/data/com.canonical.indicator.datetime.gschema.xml b/data/com.canonical.indicator.datetime.gschema.xml index 8ce75e6..4f831d5 100644 --- a/data/com.canonical.indicator.datetime.gschema.xml +++ b/data/com.canonical.indicator.datetime.gschema.xml @@ -85,6 +85,13 @@ Shows events from Evolution in indicator-datetime's menu. + + false + Show the auto-detected location in the indicator + + Shows your current location (determined from geoclue and /etc/timezone) in indicator-datetime's menu. + + false Show locations in the indicator diff --git a/data/datetime-dialog.ui b/data/datetime-dialog.ui index f3110ec..3b777fc 100644 --- a/data/datetime-dialog.ui +++ b/data/datetime-dialog.ui @@ -678,6 +678,23 @@ 3 + + + Time in _auto-detected location + True + True + False + False + True + 0 + True + + + False + True + 4 + + Time in _other locations @@ -719,7 +736,7 @@ True True - 5 + 6 diff --git a/src/datetime-prefs.c b/src/datetime-prefs.c index 611d9ef..d80a59f 100644 --- a/src/datetime-prefs.c +++ b/src/datetime-prefs.c @@ -733,6 +733,8 @@ indicator_datetime_panel_init (IndicatorDatetimePanel * self) "active", G_SETTINGS_BIND_DEFAULT); g_settings_bind (conf, SETTINGS_SHOW_EVENTS_S, WIG ("showEventsCheck"), "active", G_SETTINGS_BIND_DEFAULT); + g_settings_bind (conf, SETTINGS_SHOW_DETECTED_S, WIG ("showDetectedCheck"), + "active", G_SETTINGS_BIND_DEFAULT); g_settings_bind (conf, SETTINGS_SHOW_LOCATIONS_S, WIG ("showLocationsCheck"), "active", G_SETTINGS_BIND_DEFAULT); diff --git a/src/datetime-service.c b/src/datetime-service.c index d264900..5b3bf81 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -115,6 +115,7 @@ struct TimeLocation gint32 offset; gchar * zone; gchar * name; + gboolean visible; }; static void time_location_free (struct TimeLocation * loc) @@ -124,7 +125,7 @@ time_location_free (struct TimeLocation * loc) g_free (loc); } static struct TimeLocation* -time_location_new (const char * zone, const char * name, time_t now) +time_location_new (const char * zone, const char * name, gboolean visible, time_t now) { struct TimeLocation * loc = g_new (struct TimeLocation, 1); GTimeZone * tz = g_time_zone_new (zone); @@ -132,6 +133,7 @@ time_location_new (const char * zone, const char * name, time_t now) loc->offset = g_time_zone_get_offset (tz, interval); loc->zone = g_strdup (zone); loc->name = g_strdup (name); + loc->visible = visible; g_time_zone_unref (tz); g_debug ("%s zone '%s' name '%s' offset is %d", G_STRLOC, zone, name, (int)loc->offset); return loc; @@ -139,18 +141,18 @@ time_location_new (const char * zone, const char * name, time_t now) static int time_location_compare (const struct TimeLocation * a, const struct TimeLocation * b) { - int ret; - if (a->offset != b->offset) /* primary key s.t. we can sort by timezone order */ - ret = a->offset - b->offset; - else + int ret = a->offset - b->offset; /* primary key */ + if (!ret) ret = g_strcmp0 (a->name, b->name); /* secondary key */ + if (!ret) + ret = a->visible - b->visible; /* tertiary key */ g_debug ("%s comparing '%s' (%d) to '%s' (%d), returning %d", G_STRLOC, a->name, (int)a->offset, b->name, (int)b->offset, ret); return ret; } static GSList* -locations_add (GSList * locations, const char * zone, const char * name, time_t now) +locations_add (GSList * locations, const char * zone, const char * name, gboolean visible, time_t now) { - struct TimeLocation * loc = time_location_new (zone, name, now); + struct TimeLocation * loc = time_location_new (zone, name, visible, now); if (g_slist_find_custom (locations, loc, (GCompareFunc)time_location_compare) == NULL) { g_debug ("%s Adding zone '%s', name '%s'", G_STRLOC, zone, name); @@ -188,15 +190,17 @@ update_location_menu_items (void) /* maybe add geo_timezone */ if (geo_timezone != NULL) { + const gboolean visible = g_settings_get_boolean (conf, SETTINGS_SHOW_DETECTED_S); gchar * name = get_current_zone_name (geo_timezone); - locations = locations_add (locations, geo_timezone, name, now); + locations = locations_add (locations, geo_timezone, name, visible, now); g_free (name); } /* maybe add current_timezone */ if (current_timezone != NULL) { + const gboolean visible = g_settings_get_boolean (conf, SETTINGS_SHOW_DETECTED_S); gchar * name = get_current_zone_name (current_timezone); - locations = locations_add (locations, current_timezone, name, now); + locations = locations_add (locations, current_timezone, name, visible, now); g_free (name); } @@ -205,12 +209,13 @@ update_location_menu_items (void) if (user_locations != NULL) { gint i; const guint location_count = g_strv_length (user_locations); + const gboolean visible = g_settings_get_boolean (conf, SETTINGS_SHOW_LOCATIONS_S); g_debug ("%s Found %u user-specified locations", G_STRLOC, location_count); for (i=0; inext) { struct TimeLocation * loc = l->data; g_debug("%s Adding location: zone '%s', name '%s'", G_STRLOC, loc->zone, loc->name); @@ -234,17 +239,19 @@ update_location_menu_items (void) dbusmenu_menuitem_property_set (item, TIMEZONE_MENUITEM_PROP_ZONE, loc->zone); dbusmenu_menuitem_property_set_bool (item, TIMEZONE_MENUITEM_PROP_RADIO, FALSE); dbusmenu_menuitem_property_set_bool (item, DBUSMENU_MENUITEM_PROP_ENABLED, TRUE); - dbusmenu_menuitem_property_set_bool (item, DBUSMENU_MENUITEM_PROP_VISIBLE, show_locations); + dbusmenu_menuitem_property_set_bool (item, DBUSMENU_MENUITEM_PROP_VISIBLE, loc->visible); dbusmenu_menuitem_child_add_position (root, item, offset++); g_signal_connect(G_OBJECT(item), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(quick_set_tz), NULL); location_menu_items = g_slist_append (location_menu_items, item); + if (loc->visible) + have_visible_location = TRUE; time_location_free (loc); } g_slist_free (locations); locations = NULL; /* if there's at least one item being shown, show the separator too */ - dbusmenu_menuitem_property_set_bool (locations_separator, DBUSMENU_MENUITEM_PROP_VISIBLE, show_locations && (location_menu_items!=NULL)); + dbusmenu_menuitem_property_set_bool (locations_separator, DBUSMENU_MENUITEM_PROP_VISIBLE, have_visible_location); } /* Update the current timezone */ @@ -1090,6 +1097,7 @@ build_menus (DbusmenuMenuitem * root) update_location_menu_items(); g_signal_connect (conf, "changed::" SETTINGS_SHOW_LOCATIONS_S, G_CALLBACK (show_locations_changed), NULL); + g_signal_connect (conf, "changed::" SETTINGS_SHOW_DETECTED_S, G_CALLBACK (show_locations_changed), NULL); g_signal_connect (conf, "changed::" SETTINGS_LOCATIONS_S, G_CALLBACK (show_locations_changed), NULL); g_signal_connect (conf, "changed::" SETTINGS_SHOW_EVENTS_S, G_CALLBACK (show_events_changed), NULL); g_signal_connect (conf, "changed::" SETTINGS_TIME_FORMAT_S, G_CALLBACK (time_format_changed), NULL); diff --git a/src/settings-shared.h b/src/settings-shared.h index da66205..8c14f1e 100644 --- a/src/settings-shared.h +++ b/src/settings-shared.h @@ -33,6 +33,7 @@ with this program. If not, see . #define SETTINGS_SHOW_WEEK_NUMBERS_S "show-week-numbers" #define SETTINGS_SHOW_EVENTS_S "show-events" #define SETTINGS_SHOW_LOCATIONS_S "show-locations" +#define SETTINGS_SHOW_DETECTED_S "show-auto-detected-location" #define SETTINGS_LOCATIONS_S "locations" #define SETTINGS_TIMEZONE_NAME_S "timezone-name" -- cgit v1.2.3 From b51315028eb616e966ca761e50c6b1114680c364 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 17 May 2012 15:53:17 -0500 Subject: Modify the timezone location sorting to follow mpt's design at https://wiki.ubuntu.com/TimeAndDate - the auto-detected location, if enabled, is listed before user-specified locations - Locations in the indicator always mirror the Locations Dialog's ordering - Added sort-by-name and sort-by-time buttons in the Locations Dialog --- data/datetime-dialog.ui | 39 ++++++++++ src/datetime-prefs-locations.c | 170 +++++++++++++++++++++++++++++++++++++++-- src/datetime-service.c | 5 +- 3 files changed, 205 insertions(+), 9 deletions(-) diff --git a/data/datetime-dialog.ui b/data/datetime-dialog.ui index 3b777fc..2b4cf67 100644 --- a/data/datetime-dialog.ui +++ b/data/datetime-dialog.ui @@ -28,6 +28,8 @@ True True locationsStore + False + False True 0 @@ -54,6 +56,7 @@ True False + 4 True @@ -104,10 +107,46 @@ 1 + + + Sort by _Name + False + True + True + True + False + True + + + + False + False + 6 + 2 + + + + + Sort by _Time + False + True + True + True + False + True + + + + False + False + 3 + + False True + 4 2 diff --git a/src/datetime-prefs-locations.c b/src/datetime-prefs-locations.c index 9f5b42c..0bea7d9 100644 --- a/src/datetime-prefs-locations.c +++ b/src/datetime-prefs-locations.c @@ -44,6 +44,138 @@ with this program. If not, see . static gboolean update_times (GtkWidget * dlg); static void save_when_idle (GtkWidget * dlg); +/*** +**** Sorting +***/ + +/** + * A temporary struct used for sorting + */ +struct TimeLocation +{ + gchar * collated_name; + gint pos; + gint32 offset; +}; + +static struct TimeLocation* +time_location_new (const char * zone, const char * name, int pos, time_t now) +{ + struct TimeLocation * loc = g_new (struct TimeLocation, 1); + GTimeZone * tz = g_time_zone_new (zone); + const gint interval = g_time_zone_find_interval (tz, G_TIME_TYPE_UNIVERSAL, now); + loc->offset = g_time_zone_get_offset (tz, interval); + loc->collated_name = g_utf8_collate_key (name, -1); + loc->pos = pos; + g_time_zone_unref (tz); + return loc; +} + +static void +time_location_free (struct TimeLocation * loc) +{ + g_free (loc->collated_name); + g_free (loc); +} + +static GSList* +time_location_array_new_from_model (GtkTreeModel * model) +{ + int pos = 0; + GtkTreeIter iter; + GSList * list = NULL; + const time_t now = time (NULL); + + if (gtk_tree_model_get_iter_first (model, &iter)) do + { + gchar * zone = NULL; + gchar * name = NULL; + + gtk_tree_model_get (model, &iter, + COL_ZONE, &zone, + COL_VISIBLE_NAME, &name, + -1); + list = g_slist_prepend (list, time_location_new (zone, name, pos++, now)); + + g_free (name); + g_free (zone); + } + while (gtk_tree_model_iter_next (model, &iter)); + + return g_slist_reverse (list); +} + +static void +handle_sort(GtkWidget * button, GtkTreeView * tree_view, GCompareFunc compare) +{ + GtkTreeModel * model = gtk_tree_view_get_model (tree_view); + GSList * l; + GSList * list = g_slist_sort (time_location_array_new_from_model(model), compare); + + gint i; + gint * reorder = g_new (gint, g_slist_length(list)); + for (i=0, l=list; l!=NULL; l=l->next, i++) + reorder[i] = ((struct TimeLocation*)l->data)->pos; + gtk_list_store_reorder (GTK_LIST_STORE(model), reorder); + + g_free (reorder); + g_slist_free_full (list, (GDestroyNotify)time_location_free); +} + +static gint +time_location_compare_by_name (gconstpointer ga, gconstpointer gb) +{ + const struct TimeLocation * a = ga; + const struct TimeLocation * b = gb; + int ret = g_strcmp0 (a->collated_name, b->collated_name); /* primary key */ + if (!ret) + ret = a->offset - b->offset; /* secondary key */ + return ret; +} +static void +handle_sort_by_name (GtkWidget * button, GtkTreeView * tree_view) +{ + handle_sort (button, tree_view, time_location_compare_by_name); +} + +static gint +time_location_compare_by_time (gconstpointer ga, gconstpointer gb) +{ + const struct TimeLocation * a = ga; + const struct TimeLocation * b = gb; + int ret = a->offset - b->offset; /* primary key */ + if (!ret) + ret = g_strcmp0 (a->collated_name, b->collated_name); /* secondary key */ + return ret; +} +static void +handle_sort_by_time (GtkWidget * button, GtkTreeView * tree_view) +{ + handle_sort (button, tree_view, time_location_compare_by_time); +} + +static gboolean +time_location_list_test_sorted (GSList * list, GCompareFunc compare) +{ + GSList * l; + for (l=list; l!=NULL && l->next!=NULL; l=l->next) + if (compare(l->data, l->next->data) > 0) + return FALSE; + return TRUE; +} +static void +location_model_test_sorted (GtkTreeModel * model, gboolean * is_sorted_by_name, gboolean * is_sorted_by_time) +{ + GSList * list = time_location_array_new_from_model(model); + *is_sorted_by_name = time_location_list_test_sorted (list, time_location_compare_by_name); + *is_sorted_by_time = time_location_list_test_sorted (list, time_location_compare_by_time); + g_slist_free_full (list, (GDestroyNotify)time_location_free); +} + +/*** +**** +***/ + static void handle_add (GtkWidget * button, GtkTreeView * tree) { @@ -426,6 +558,26 @@ selection_changed (GtkTreeSelection * selection, GtkWidget * remove_button) gtk_widget_set_sensitive (remove_button, count > 0); } +static void +update_button_sensitivity (GtkWidget * dlg) +{ + GObject * odlg = G_OBJECT(dlg); + GObject * completion = g_object_get_data(odlg, "completion"); + GtkTreeModel * model = GTK_TREE_MODEL (g_object_get_data (completion, "store")); + gboolean is_sorted_by_name; + gboolean is_sorted_by_time; + location_model_test_sorted (model, &is_sorted_by_name, &is_sorted_by_time); + gtk_widget_set_sensitive (GTK_WIDGET(g_object_get_data(odlg, "sortByNameButton")), !is_sorted_by_name); + gtk_widget_set_sensitive (GTK_WIDGET(g_object_get_data(odlg, "sortByTimeButton")), !is_sorted_by_time); +} + +static void +model_changed (GtkWidget * dlg) +{ + update_button_sensitivity (dlg); + save_when_idle (dlg); +} + GtkWidget * datetime_setup_locations_dialog (CcTimezoneMap * map) { @@ -473,6 +625,7 @@ datetime_setup_locations_dialog (CcTimezoneMap * map) g_signal_connect (tree, "query-tooltip", G_CALLBACK (query_tooltip), cell); cell = gtk_cell_renderer_text_new (); + gtk_cell_renderer_set_alignment (cell, 1.0f, 0.5f); gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree), -1, _("Time"), cell, "text", COL_TIME, NULL); @@ -485,12 +638,19 @@ datetime_setup_locations_dialog (CcTimezoneMap * map) g_signal_connect (WIG ("addButton"), "clicked", G_CALLBACK (handle_add), tree); g_signal_connect (WIG ("removeButton"), "clicked", G_CALLBACK (handle_remove), tree); - fill_from_settings (store, conf); - g_signal_connect_swapped (store, "row-deleted", G_CALLBACK (save_when_idle), dlg); - g_signal_connect_swapped (store, "row-inserted", G_CALLBACK (save_when_idle), dlg); - g_signal_connect_swapped (store, "row-changed", G_CALLBACK (save_when_idle), dlg); - g_signal_connect_swapped (store, "rows-reordered", G_CALLBACK (save_when_idle), dlg); + GtkWidget * w = WIG ("sortByNameButton"); + g_signal_connect (w, "clicked", G_CALLBACK (handle_sort_by_name), tree); + g_object_set_data (G_OBJECT(dlg), "sortByNameButton", w); + + w = WIG ("sortByTimeButton"); + g_signal_connect (w, "clicked", G_CALLBACK (handle_sort_by_time), tree); + g_object_set_data (G_OBJECT(dlg), "sortByTimeButton", w); + fill_from_settings (store, conf); + g_signal_connect_swapped (store, "row-deleted", G_CALLBACK (model_changed), dlg); + g_signal_connect_swapped (store, "row-inserted", G_CALLBACK (model_changed), dlg); + g_signal_connect_swapped (store, "row-changed", G_CALLBACK (model_changed), dlg); + g_signal_connect_swapped (store, "rows-reordered", G_CALLBACK (model_changed), dlg); g_object_set_data_full (G_OBJECT (dlg), "conf", g_object_ref (conf), g_object_unref); g_object_set_data_full (G_OBJECT (dlg), "completion", completion, g_object_unref); g_signal_connect (dlg, "destroy", G_CALLBACK (dialog_closed), store); diff --git a/src/datetime-service.c b/src/datetime-service.c index 5b3bf81..0219cfb 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -156,7 +156,7 @@ locations_add (GSList * locations, const char * zone, const char * name, gboolea if (g_slist_find_custom (locations, loc, (GCompareFunc)time_location_compare) == NULL) { g_debug ("%s Adding zone '%s', name '%s'", G_STRLOC, zone, name); - locations = g_slist_prepend (locations, loc); + locations = g_slist_append (locations, loc); } else { g_debug("%s Skipping duplicate zone '%s' name '%s'", G_STRLOC, zone, name); time_location_free (loc); @@ -223,9 +223,6 @@ update_location_menu_items (void) user_locations = NULL; } - /* sort the list by timezone offset */ - locations = g_slist_sort (locations, (GCompareFunc)time_location_compare); - /* finally create menuitems for each location */ gint offset = dbusmenu_menuitem_get_position (locations_separator, root)+1; GSList * l; -- cgit v1.2.3 From 0ec41cb0237bc8c493d8c05c6af45ebfb9f36557 Mon Sep 17 00:00:00 2001 From: Bob Owen Date: Fri, 25 May 2012 21:42:25 +0100 Subject: * src/utils.c - generate_format_string_full - Changed space between date and time to Unicode en space. Added using UTF-8 hex encoding (0xE28082) to avoid the need to mess with CFLAGS to add std=c99. (LP: #749847) --- src/utils.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/utils.c b/src/utils.c index e6de92a..f5aecd6 100644 --- a/src/utils.c +++ b/src/utils.c @@ -243,9 +243,10 @@ generate_format_string_full (gboolean show_day, gboolean show_date) g_return_val_if_fail(date_string != NULL, g_strdup(time_string)); /* TRANSLATORS: This is a format string passed to strftime to combine the - date and the time. The value of "%s %s" would result in a string like - this in US English 12-hour time: 'Fri Jul 16 11:50 AM' */ - return g_strdup_printf(T_("%s %s"), date_string, time_string); + date and the time. The value of "%s\xE2\x80\x82%s" would result in a string like + this in US English 12-hour time: 'Fri Jul 16 11:50 AM'. + The space in between date and time is a Unicode en space (E28082 in UTF-8 hex). */ + return g_strdup_printf(T_("%s\xE2\x80\x82%s"), date_string, time_string); } gchar * -- cgit v1.2.3 From eb1b4aa7cb5d34223c8a0e461e36743c76fdb631 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 12 Jul 2012 12:59:44 -0500 Subject: cyphermox patch to support EDS 3.6's API --- src/datetime-service.c | 176 +++++++++++++++++++++++-------------------------- 1 file changed, 84 insertions(+), 92 deletions(-) diff --git a/src/datetime-service.c b/src/datetime-service.c index 0219cfb..86c677a 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -40,11 +40,9 @@ with this program. If not, see . #include #include -#include +#include #include -#include -#include -#include +#include // Other users of ecal seem to also include these, not sure why they should be included by the above #include #include @@ -600,27 +598,6 @@ check_for_calendar (gpointer user_data) return FALSE; } -// Authentication function -static gchar * -auth_func (ECal *ecal, - const gchar *prompt, - const gchar *key, - gpointer user_data) -{ - ESource *source = e_cal_get_source (ecal); - gchar *auth_domain = e_source_get_duped_property (source, "auth-domain"); - - const gchar *component_name; - if (auth_domain) component_name = auth_domain; - else component_name = "Calendar"; - - gchar *password = e_passwords_get_password (component_name, key); - - g_free (auth_domain); - - return password; -} - static gint compare_comp_instances (gconstpointer ga, gconstpointer gb) { @@ -655,23 +632,53 @@ comp_instance_free (struct comp_instance* ci) } static gboolean -populate_appointment_instances (ECalComponent * comp, +populate_appointment_instances (ECalClient * client, time_t start, time_t end, gpointer data) { - g_debug("Appending item %p", comp); - - ECalComponentVType vtype = e_cal_component_get_vtype (comp); - if (vtype != E_CAL_COMPONENT_EVENT && vtype != E_CAL_COMPONENT_TODO) return FALSE; - - icalproperty_status status; - e_cal_component_get_status (comp, &status); - if (status == ICAL_STATUS_COMPLETED || status == ICAL_STATUS_CANCELLED) return FALSE; + GSList *ecalcomps, *comp_item; - struct comp_instance *ci = comp_instance_new (comp, start, end, E_SOURCE(data)); - comp_instances = g_list_append (comp_instances, ci); - return TRUE; + if (e_cal_client_get_object_list_as_comps_sync (client, + NULL, + &ecalcomps, + NULL, NULL)) { + + for (comp_item = ecalcomps; comp_item; comp_item = g_slist_next(comp_item)) { + ECalComponent *comp = comp_item->data; + + g_debug("Appending item %p", e_cal_component_get_as_string(comp)); + + ECalComponentVType vtype = e_cal_component_get_vtype (comp); + if (vtype != E_CAL_COMPONENT_EVENT && vtype != E_CAL_COMPONENT_TODO) return FALSE; + + icalproperty_status status; + e_cal_component_get_status (comp, &status); + if (status == ICAL_STATUS_COMPLETED || status == ICAL_STATUS_CANCELLED) return FALSE; + + g_object_ref(comp); + + ECalComponentDateTime datetime; + icaltimezone *appointment_zone = NULL; + icaltimezone *current_zone = NULL; + + if (vtype == E_CAL_COMPONENT_EVENT) + e_cal_component_get_dtstart (comp, &datetime); + else + e_cal_component_get_due (comp, &datetime); + + appointment_zone = icaltimezone_get_builtin_timezone_from_tzid(datetime.tzid); + current_zone = icaltimezone_get_builtin_timezone_from_tzid(current_timezone); + if (!appointment_zone || datetime.value->is_date) { // If it's today put in the current timezone? + appointment_zone = current_zone; + } + + struct comp_instance *ci = comp_instance_new (comp, start, end, E_SOURCE(data)); + comp_instances = g_list_append (comp_instances, ci); + } + return TRUE; + } + return FALSE; } /* Populate the menu with todays, next 5 appointments. @@ -691,12 +698,12 @@ update_appointment_menu_items (gpointer user_data) updating_appointments = TRUE; time_t curtime = 0, t1 = 0, t2 = 0; - GList *l; - GSList *g; + GList *l, *s; GError *gerror = NULL; gint i; gint width = 0, height = 0; - ESourceList * sources = NULL; + ESourceRegistry * src_registry = NULL; + GList * sources = NULL; // Get today & work out query times time(&curtime); @@ -736,67 +743,52 @@ update_appointment_menu_items (gpointer user_data) highlightdays = highlightdays + 7; // Minimum of 7 days ahead t2 = t1 + (time_t) (highlightdays * 24 * 60 * 60); - if (!e_cal_get_sources(&sources, E_CAL_SOURCE_TYPE_EVENT, &gerror)) { - g_debug("Failed to get ecal sources\n"); - g_clear_error (&gerror); - return FALSE; - } - // clear any previous comp_instances g_list_free_full (comp_instances, (GDestroyNotify)comp_instance_free); comp_instances = NULL; - GSList *cal_list = gconf_client_get_list(gconf, "/apps/evolution/calendar/display/selected_calendars", GCONF_VALUE_STRING, &gerror); - if (gerror) { - g_debug("Failed to get evolution preference for enabled calendars"); - g_clear_error (&gerror); - cal_list = NULL; - } - + src_registry = e_source_registry_new_sync (NULL, &gerror); + if (!src_registry) { + g_debug("Failed to get access to source registry: %s\n", gerror->message); + return FALSE; + } + + sources = e_source_registry_list_sources(src_registry, E_SOURCE_EXTENSION_CALENDAR); + // Generate instances for all sources - for (g = e_source_list_peek_groups (sources); g; g = g->next) { - ESourceGroup *group = E_SOURCE_GROUP (g->data); - GSList *s; - - for (s = e_source_group_peek_sources (group); s; s = s->next) { - ESource *source = E_SOURCE (s->data); - g_signal_connect (G_OBJECT(source), "changed", G_CALLBACK (update_appointment_menu_items), NULL); - ECal *ecal = e_cal_new(source, E_CAL_SOURCE_TYPE_EVENT); - e_cal_set_auth_func (ecal, (ECalAuthFunc) auth_func, NULL); - - icaltimezone* current_zone = icaltimezone_get_builtin_timezone(current_timezone); - if (!current_zone) { - // current_timezone may be a TZID? - current_zone = icaltimezone_get_builtin_timezone_from_tzid(current_timezone); - } - if (current_zone && !e_cal_set_default_timezone(ecal, current_zone, &gerror)) { - g_debug("Failed to set ecal default timezone %s", gerror->message); - g_clear_error (&gerror); - g_object_unref(ecal); - continue; - } - - if (!e_cal_open(ecal, FALSE, &gerror)) { - g_debug("Failed to get ecal sources %s", gerror->message); - g_clear_error (&gerror); - g_object_unref(ecal); - continue; - } + for (s = g_list_first (sources); s; s = g_list_next (s)) { + + ESource *source = E_SOURCE (s->data); + g_signal_connect (G_OBJECT(source), "changed", G_CALLBACK (update_appointment_menu_items), NULL); + ECalClient *ecal = e_cal_client_new(source, E_CAL_CLIENT_SOURCE_TYPE_EVENTS, &gerror); + + icaltimezone* current_zone = icaltimezone_get_builtin_timezone(current_timezone); + if (!current_zone) { + // current_timezone may be a TZID? + current_zone = icaltimezone_get_builtin_timezone_from_tzid(current_timezone); + } - const gchar *ecal_uid = e_source_peek_uid(source); - g_debug("Checking ecal_uid is enabled: %s", ecal_uid); - const gboolean in_list = g_slist_find_custom (cal_list, ecal_uid, (GCompareFunc)g_strcmp0) != NULL; - if (!in_list) { + e_cal_client_set_default_timezone (ecal, current_zone); + + g_debug("Checking if source %s is enabled", e_source_get_uid(source)); + if (e_source_get_enabled (source)) { + g_debug("source is enabled, generating instances"); + + if (!e_client_open_sync (E_CLIENT (ecal), TRUE, NULL, &gerror)) { + g_debug("Failed to open source: %s", gerror->message); + g_clear_error (&gerror); g_object_unref(ecal); continue; } - g_debug("ecal_uid is enabled, generating instances"); - e_cal_generate_instances (ecal, t1, t2, (ECalRecurInstanceFn) populate_appointment_instances, source); - g_object_unref(ecal); - } - } - g_slist_free_full (cal_list, g_free); + e_cal_client_generate_instances (ecal, t1, t2, NULL, + (ECalRecurInstanceFn) populate_appointment_instances, + (gpointer) source, + NULL); + } + g_object_unref(ecal); + } + g_list_free_full (sources, g_object_unref); g_debug("Number of ECalComponents returned: %d", g_list_length(comp_instances)); GList *sorted_comp_instances = g_list_sort(comp_instances, compare_comp_instances); @@ -948,7 +940,7 @@ update_appointment_menu_items (gpointer user_data) G_CALLBACK(activate_cb), cmd, (GClosureNotify)g_free, 0); g_free (ad); - const gchar *color_spec = e_source_peek_color_spec(ci->source); + const gchar *color_spec = e_source_selectable_get_color (e_source_get_extension (ci->source, E_SOURCE_EXTENSION_CALENDAR)); g_debug("Colour to use: %s", color_spec); // Draw the correct icon for the appointment type and then tint it using mask fill. -- cgit v1.2.3 From e2e14906d2f574abf672862c2bf4dac1d044dd3c Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 12 Jul 2012 16:27:57 -0500 Subject: bump version to 12.10.0 --- NEWS | 15 +++++++++++++++ configure.ac | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index e69de29..b18731c 100644 --- a/NEWS +++ b/NEWS @@ -0,0 +1,15 @@ +12.10.0 + + - Support EDS 3.6's API (cyphermox) + + - Apply an 'en space' between the date and time strings. (LP #749847) + lp:~bobowen/indicator-datetime/fix-for-749847 + + - Sort locations as spec'ed by https://wiki.ubuntu.com/TimeAndDate (LP #833325) + lp:~charlesk/indicator-datetime/lp-833325 + + - Fix a bug that caused location settings to be re-saved each 2 seconds + lp:~charlesk/indicator-datetime/unnecessary-saves + + - Drop GTK+ 2 support + diff --git a/configure.ac b/configure.ac index e4c1c26..e8b3eb2 100644 --- a/configure.ac +++ b/configure.ac @@ -1,5 +1,5 @@ AC_INIT([indicator-datetime], - [0.3.94], + [12.10.0], [http://bugs.launchpad.net/indicator-datetime], [indicator-datetime], [http://launchpad.net/indicator-datetime]) -- cgit v1.2.3