From f436da0a3f8cf7a01ccb0ae062d53e5be6cd5ff8 Mon Sep 17 00:00:00 2001 From: karl-qdh Date: Wed, 23 Mar 2011 10:24:35 +0000 Subject: changes for bug #649800 - requires dbusmenu to be released --- src/datetime-service.c | 24 ++++++++++++++++++++++++ src/indicator-datetime.c | 4 ++++ 2 files changed, 28 insertions(+) diff --git a/src/datetime-service.c b/src/datetime-service.c index bd9a9c9..129ec14 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -318,6 +318,27 @@ day_selected_double_click_cb (DbusmenuMenuitem * menuitem, gchar *name, GVariant return TRUE; } +static gboolean +close_menu_cb (DbusmenuMenuitem * menuitem, gchar *name, GVariant *variant) +{ + if (calendar == NULL) return FALSE; + start_time_appointments = 0; + // TODO create a variant which will be an array of 3 ints {y,m,d} + GVariant *date_variant; + time_t curtime; + struct tm *t1; + time(&curtime); + t1 = localtime(&curtime); + GVariant *date[3]; + date[0] = g_variant_new_uint32(t1->tm_year + 1900); + date[1] = g_variant_new_uint32(t1->tm_mon); + date[2] = g_variant_new_uint32(t1->tm_mday); + date_variant = g_variant_new_array(NULL, date, 3); + + dbusmenu_menuitem_property_set_variant (calendar, CALENDAR_MENUITEM_PROP_SET_DATE, date_variant); + return TRUE; +} + static guint ecaltimer = 0; static void @@ -1216,6 +1237,9 @@ main (int argc, char ** argv) build_menus(root); + // Connect to the close signal to reset the calendar date + g_signal_connect(root, "event::closed", G_CALLBACK(close_menu_cb), NULL); + /* Cache the timezone */ update_current_timezone(); diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c index 1cdcd3f..fb77974 100644 --- a/src/indicator-datetime.c +++ b/src/indicator-datetime.c @@ -1149,13 +1149,17 @@ indicator_prop_change_cb (DbusmenuMenuitem * mi, gchar * prop, GVariant *value, } else if (!g_strcmp0(prop, CALENDAR_MENUITEM_PROP_MARK)) { ido_calendar_menu_item_mark_day (IDO_CALENDAR_MENU_ITEM (mi_data), g_variant_get_int16(value)); + g_debug("Marked day: %d", g_variant_get_int16(value)); } else if (!g_strcmp0(prop, CALENDAR_MENUITEM_PROP_UNMARK)) { ido_calendar_menu_item_unmark_day (IDO_CALENDAR_MENU_ITEM (mi_data), g_variant_get_int16(value)); + g_debug("Unmarked day: %d", g_variant_get_int16(value)); } else if (!g_strcmp0(prop, CALENDAR_MENUITEM_PROP_CLEAR_MARKS)) { + g_debug("Cleared Marks"); ido_calendar_menu_item_clear_marks (IDO_CALENDAR_MENU_ITEM (mi_data)); } else if (!g_strcmp0(prop, CALENDAR_MENUITEM_PROP_SET_DATE)) { gsize size = 3; const gint * array = g_variant_get_fixed_array(value, &size, sizeof(gint)); + g_debug("Setting date y-m-d: %d-%d-%d", array[0], array[1], array[2]); ido_calendar_menu_item_set_date (IDO_CALENDAR_MENU_ITEM (mi_data), array[0], array[1], array[2]); } else { g_warning("Indicator Item property '%s' unknown", prop); -- cgit v1.2.3 From 736dde41f6046b8610e27568f394031c9b6f72fd Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Wed, 23 Mar 2011 15:24:28 -0500 Subject: cleanup locations dialog column usage --- src/datetime-prefs-locations.c | 58 ++++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 33 deletions(-) diff --git a/src/datetime-prefs-locations.c b/src/datetime-prefs-locations.c index 0c9a93c..5e93a56 100644 --- a/src/datetime-prefs-locations.c +++ b/src/datetime-prefs-locations.c @@ -35,6 +35,10 @@ with this program. If not, see . #define DATETIME_DIALOG_UI_FILE PKGDATADIR "/datetime-dialog.ui" +#define COL_NAME 0 +#define COL_TIME 1 +#define COL_ZONE 2 + static void handle_add (GtkWidget * button, GtkTreeView * tree) { @@ -84,7 +88,7 @@ handle_edit (GtkCellRendererText * renderer, gchar * path, gchar * new_text, GtkTreeIter iter; if (gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (store), &iter, path)) { - gtk_list_store_set (store, &iter, 0, new_text, -1); + gtk_list_store_set (store, &iter, COL_NAME, new_text, -1); } } @@ -92,28 +96,28 @@ static gboolean timezone_selected (GtkEntryCompletion * widget, GtkTreeModel * model, GtkTreeIter * iter, gpointer user_data) { - GValue zone_value = {0}, name_value = {0}; const gchar * zone, * name; - gtk_tree_model_get_value (model, iter, TIMEZONE_COMPLETION_ZONE, &zone_value); - zone = g_value_get_string (&zone_value); + gtk_tree_model_get (model, iter, + TIMEZONE_COMPLETION_ZONE, &zone, + TIMEZONE_COMPLETION_NAME, &name, + -1); - gtk_tree_model_get_value (model, iter, TIMEZONE_COMPLETION_NAME, &name_value); - name = g_value_get_string (&name_value); + g_debug("match selected: %s, %s", name, zone); if (zone == NULL || zone[0] == 0) { - GValue lon_value = {0}, lat_value = {0}; const gchar * strlon, * strlat; gdouble lon = 0.0, lat = 0.0; - gtk_tree_model_get_value (model, iter, TIMEZONE_COMPLETION_LONGITUDE, &lon_value); - strlon = g_value_get_string (&lon_value); + gtk_tree_model_get (model, iter, + TIMEZONE_COMPLETION_LONGITUDE, &strlon, + TIMEZONE_COMPLETION_LATITUDE, &strlat, + -1); + if (strlon != NULL && strlon[0] != 0) { lon = strtod(strlon, NULL); } - gtk_tree_model_get_value (model, iter, TIMEZONE_COMPLETION_LATITUDE, &lat_value); - strlat = g_value_get_string (&lat_value); if (strlat != NULL && strlat[0] != 0) { lat = strtod(strlat, NULL); } @@ -125,12 +129,9 @@ timezone_selected (GtkEntryCompletion * widget, GtkTreeModel * model, GtkListStore * store = GTK_LIST_STORE (g_object_get_data (G_OBJECT (widget), "store")); GtkTreeIter * store_iter = (GtkTreeIter *)g_object_get_data (G_OBJECT (widget), "store_iter"); if (store != NULL && store_iter != NULL) { - gtk_list_store_set (store, store_iter, 0, name, 2, zone, -1); + gtk_list_store_set (store, store_iter, COL_NAME, name, COL_ZONE, zone, -1); } - g_value_unset (&name_value); - g_value_unset (&zone_value); - return FALSE; // Do normal action too } @@ -169,11 +170,9 @@ update_times (TimezoneCompletion * completion) GtkTreeIter iter; if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter)) { do { - GValue zone_value = {0}; const gchar * strzone; - gtk_tree_model_get_value (GTK_TREE_MODEL (store), &iter, 2, &zone_value); - strzone = g_value_get_string (&zone_value); + gtk_tree_model_get (GTK_TREE_MODEL (store), &iter, COL_ZONE, &strzone, -1); if (strzone != NULL && strzone[0] != 0) { GTimeZone * tz = g_time_zone_new (strzone); @@ -181,15 +180,13 @@ update_times (TimezoneCompletion * completion) gchar * format = generate_format_string_at_time (now_tz); gchar * time_str = g_date_time_format (now_tz, format); - gtk_list_store_set (store, &iter, 1, time_str, -1); + gtk_list_store_set (store, &iter, COL_TIME, time_str, -1); g_free (time_str); g_free (format); g_date_time_unref (now_tz); g_time_zone_unref (tz); } - - g_value_unset (&zone_value); } while (gtk_tree_model_iter_next (GTK_TREE_MODEL (store), &iter)); } @@ -211,7 +208,7 @@ fill_from_settings (GObject * store, GSettings * conf) split_settings_location (*striter, &zone, &name); gtk_list_store_append (GTK_LIST_STORE (store), &iter); - gtk_list_store_set (GTK_LIST_STORE (store), &iter, 0, name, 2, zone, -1); + gtk_list_store_set (GTK_LIST_STORE (store), &iter, COL_NAME, name, COL_ZONE, zone, -1); g_free (zone); g_free (name); @@ -234,23 +231,18 @@ dialog_closed (GtkWidget * dlg, GObject * store) GtkTreeIter iter; if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter)) { do { - GValue zone_value = {0}, name_value = {0}; const gchar * strzone, * strname; - gtk_tree_model_get_value (GTK_TREE_MODEL (store), &iter, 0, &name_value); - gtk_tree_model_get_value (GTK_TREE_MODEL (store), &iter, 2, &zone_value); - - strzone = g_value_get_string (&zone_value); - strname = g_value_get_string (&name_value); + gtk_tree_model_get (GTK_TREE_MODEL (store), &iter, + COL_NAME, &strname, + COL_ZONE, &strzone, + -1); if (strzone != NULL && strzone[0] != 0 && strname != NULL && strname[0] != 0) { gchar * settings_string = g_strdup_printf("%s %s", strzone, strname); g_variant_builder_add (&builder, "s", settings_string); g_free (settings_string); } - - g_value_unset (&zone_value); - g_value_unset (&name_value); } while (gtk_tree_model_iter_next (GTK_TREE_MODEL (store), &iter)); } @@ -304,7 +296,7 @@ datetime_setup_locations_dialog (GtkWindow * parent, CcTimezoneMap * map) g_signal_connect (cell, "edited", G_CALLBACK (handle_edit), store); gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree), -1, _("Location"), cell, - "text", 0, NULL); + "text", COL_NAME, NULL); GtkTreeViewColumn * loc_col = gtk_tree_view_get_column (GTK_TREE_VIEW (tree), 0); gtk_tree_view_column_set_expand (loc_col, TRUE); g_object_set_data (G_OBJECT (completion), "name-cell", cell); @@ -312,7 +304,7 @@ datetime_setup_locations_dialog (GtkWindow * parent, CcTimezoneMap * map) cell = gtk_cell_renderer_text_new (); gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree), -1, _("Time"), cell, - "text", 1, NULL); + "text", COL_TIME, NULL); GtkTreeSelection * selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree)); gtk_tree_selection_set_mode (selection, GTK_SELECTION_MULTIPLE); -- cgit v1.2.3 From 64d76856cb691d998c070086d31ad51f18d68cdf Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Wed, 23 Mar 2011 16:03:29 -0500 Subject: sort locations by name, starting with prefixes --- src/timezone-completion.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/timezone-completion.c b/src/timezone-completion.c index aaf6bdc..2cd2340 100644 --- a/src/timezone-completion.c +++ b/src/timezone-completion.c @@ -87,6 +87,39 @@ save_and_use_model (TimezoneCompletion * completion, GtkTreeModel * model) g_signal_emit_by_name (priv->entry, "changed"); } +static gint +sort_zone (GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, + gpointer user_data) +{ + /* Anything that has text as a prefix goes first, in mostly sorted order. + Then everything else goes after, in mostly sorted order. */ + const gchar *casefolded_text = (const gchar *)user_data; + + const gchar *namea = NULL, *nameb = NULL; + gtk_tree_model_get (model, a, TIMEZONE_COMPLETION_NAME, &namea, -1); + gtk_tree_model_get (model, b, TIMEZONE_COMPLETION_NAME, &nameb, -1); + + gchar *casefolded_namea = NULL, *casefolded_nameb = NULL; + casefolded_namea = g_utf8_casefold (namea, -1); + casefolded_nameb = g_utf8_casefold (nameb, -1); + + gboolean amatches = FALSE, bmatches = FALSE; + amatches = strncmp (casefolded_text, casefolded_namea, strlen(casefolded_text)) == 0; + bmatches = strncmp (casefolded_text, casefolded_nameb, strlen(casefolded_text)) == 0; + + gint rv; + if (amatches && !bmatches) + rv = -1; + else if (bmatches && !amatches) + rv = 1; + else + rv = g_utf8_collate (casefolded_namea, casefolded_nameb); + + g_free (casefolded_namea); + g_free (casefolded_nameb); + return rv; +} + static void json_parse_ready (GObject *object, GAsyncResult *res, gpointer user_data) { @@ -179,6 +212,13 @@ json_parse_ready (GObject *object, GAsyncResult *res, gpointer user_data) TIMEZONE_COMPLETION_LONGITUDE, longitude, TIMEZONE_COMPLETION_LATITUDE, latitude, -1); + gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (store), + TIMEZONE_COMPLETION_NAME, sort_zone, + g_utf8_casefold(priv->request_text, -1), + g_free); + gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store), + TIMEZONE_COMPLETION_NAME, + GTK_SORT_ASCENDING); } prev_name = name; -- cgit v1.2.3 From 7df6b79140cf5184e95169682534af60e947d6bd Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Wed, 23 Mar 2011 16:05:07 -0500 Subject: cleanup another instance of GValue --- src/timezone-completion.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/src/timezone-completion.c b/src/timezone-completion.c index 2cd2340..a2fa643 100644 --- a/src/timezone-completion.c +++ b/src/timezone-completion.c @@ -380,16 +380,13 @@ static void data_func (GtkCellLayout *cell_layout, GtkCellRenderer *cell, GtkTreeModel *tree_model, GtkTreeIter *iter, gpointer user_data) { - GValue name_val = {0}, admin1_val = {0}, country_val = {0}; const gchar * name, * admin1, * country; - gtk_tree_model_get_value (GTK_TREE_MODEL (tree_model), iter, TIMEZONE_COMPLETION_NAME, &name_val); - gtk_tree_model_get_value (GTK_TREE_MODEL (tree_model), iter, TIMEZONE_COMPLETION_ADMIN1, &admin1_val); - gtk_tree_model_get_value (GTK_TREE_MODEL (tree_model), iter, TIMEZONE_COMPLETION_COUNTRY, &country_val); - - name = g_value_get_string (&name_val); - admin1 = g_value_get_string (&admin1_val); - country = g_value_get_string (&country_val); + gtk_tree_model_get (GTK_TREE_MODEL (tree_model), iter, + TIMEZONE_COMPLETION_NAME, &name, + TIMEZONE_COMPLETION_ADMIN1, &admin1, + TIMEZONE_COMPLETION_COUNTRY, &country, + -1); gchar * user_name; if (admin1 == NULL || admin1[0] == 0) { @@ -399,10 +396,6 @@ data_func (GtkCellLayout *cell_layout, GtkCellRenderer *cell, } g_object_set (G_OBJECT (cell), "markup", user_name, NULL); - - g_value_unset (&name_val); - g_value_unset (&admin1_val); - g_value_unset (&country_val); } static void -- cgit v1.2.3 From 44cde00066303e185b615cd1efb0d3bb1ffb0071 Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Wed, 23 Mar 2011 16:24:34 -0500 Subject: add bevel above location buttons --- data/datetime-dialog.ui | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/data/datetime-dialog.ui b/data/datetime-dialog.ui index 7545227..ead11d1 100644 --- a/data/datetime-dialog.ui +++ b/data/datetime-dialog.ui @@ -7,11 +7,6 @@ 86400 864000 - - 1.8446744073709552e+19 - 60 - 3600 - False Locations @@ -46,6 +41,17 @@ 0 + + + True + False + + + False + True + 1 + + True @@ -55,7 +61,6 @@ True True True - Add a Location… False @@ -76,7 +81,6 @@ True True True - Remove This Location False @@ -96,7 +100,7 @@ False True - 1 + 2 @@ -112,6 +116,11 @@ + + 1.8446744073709552e+19 + 60 + 3600 + False 5 -- cgit v1.2.3 From 2021a9554f85a9f78f1b65de30cb78572dab2752 Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Wed, 23 Mar 2011 16:37:20 -0500 Subject: add utc to relevant results --- src/timezone-completion.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/timezone-completion.c b/src/timezone-completion.c index a2fa643..c1ffb42 100644 --- a/src/timezone-completion.c +++ b/src/timezone-completion.c @@ -229,6 +229,20 @@ json_parse_ready (GObject *object, GAsyncResult *res, gpointer user_data) json_reader_end_element (reader); } + if (strlen (priv->request_text) < 4) { + gchar * lower_text = g_ascii_strdown (priv->request_text, -1); + if (g_strcmp0 (lower_text, "ut") == 0 || + g_strcmp0 (lower_text, "utc") == 0) { + GtkTreeIter iter; + gtk_list_store_append (store, &iter); + gtk_list_store_set (store, &iter, + TIMEZONE_COMPLETION_ZONE, "UTC", + TIMEZONE_COMPLETION_NAME, "UTC", + -1); + } + g_free (lower_text); + } + save_and_use_model (completion, GTK_TREE_MODEL (store)); g_object_unref (G_OBJECT (reader)); } @@ -372,6 +386,13 @@ get_initial_model (void) g_free (name); } + GtkTreeIter iter; + gtk_list_store_append (store, &iter); + gtk_list_store_set (store, &iter, + TIMEZONE_COMPLETION_ZONE, "UTC", + TIMEZONE_COMPLETION_NAME, "UTC", + -1); + tz_db_free (db); return store; } @@ -389,7 +410,9 @@ data_func (GtkCellLayout *cell_layout, GtkCellRenderer *cell, -1); gchar * user_name; - if (admin1 == NULL || admin1[0] == 0) { + if (country == NULL || country[0] == 0) { + user_name = g_strdup (name); + } else if (admin1 == NULL || admin1[0] == 0) { user_name = g_strdup_printf ("%s (%s)", name, country); } else { user_name = g_strdup_printf ("%s (%s, %s)", name, admin1, country); -- cgit v1.2.3 From f76208b252ab4eeec71b9ac305ff5dd8283571d5 Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Thu, 24 Mar 2011 07:25:30 -0500 Subject: drop debugging line and update times when user selects a zone --- src/datetime-prefs-locations.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/datetime-prefs-locations.c b/src/datetime-prefs-locations.c index 5e93a56..b8d9f8f 100644 --- a/src/datetime-prefs-locations.c +++ b/src/datetime-prefs-locations.c @@ -39,6 +39,8 @@ with this program. If not, see . #define COL_TIME 1 #define COL_ZONE 2 +static gboolean update_times (TimezoneCompletion * completion); + static void handle_add (GtkWidget * button, GtkTreeView * tree) { @@ -103,8 +105,6 @@ timezone_selected (GtkEntryCompletion * widget, GtkTreeModel * model, TIMEZONE_COMPLETION_NAME, &name, -1); - g_debug("match selected: %s, %s", name, zone); - if (zone == NULL || zone[0] == 0) { const gchar * strlon, * strlat; gdouble lon = 0.0, lat = 0.0; @@ -132,6 +132,8 @@ timezone_selected (GtkEntryCompletion * widget, GtkTreeModel * model, gtk_list_store_set (store, store_iter, COL_NAME, name, COL_ZONE, zone, -1); } + update_times (TIMEZONE_COMPLETION (widget)); + return FALSE; // Do normal action too } -- cgit v1.2.3 From cbc7a7cd54130c3f68565a6738e5471807f43df5 Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Thu, 24 Mar 2011 08:26:53 -0500 Subject: make map look insensitive if it is --- libmap/cc-timezone-map.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/libmap/cc-timezone-map.c b/libmap/cc-timezone-map.c index ec12c84..8e4a5b8 100644 --- a/libmap/cc-timezone-map.c +++ b/libmap/cc-timezone-map.c @@ -788,6 +788,13 @@ cc_timezone_map_draw (GtkWidget *widget, } if (!priv->location) { + /* Check if insensitive */ + if (gtk_widget_get_state (widget) == GTK_STATE_INSENSITIVE) { + cairo_set_source_rgba(cr, 1, 1, 1, 0.5); + cairo_rectangle(cr, 0, 0, alloc.width, alloc.height); + cairo_fill(cr); + } + return TRUE; } @@ -840,6 +847,13 @@ cc_timezone_map_draw (GtkWidget *widget, g_object_unref (pin); } + /* Check if insensitive */ + if (gtk_widget_get_state (widget) == GTK_STATE_INSENSITIVE) { + cairo_set_source_rgba(cr, 1, 1, 1, 0.5); + cairo_rectangle(cr, 0, 0, alloc.width, alloc.height); + cairo_fill(cr); + } + return TRUE; } -- cgit v1.2.3 From 4298b95bb97d341558b263bf15c02aa1575f6293 Mon Sep 17 00:00:00 2001 From: karl-qdh Date: Thu, 24 Mar 2011 13:41:43 +0000 Subject: Change timer to 999ms --- src/indicator-datetime.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c index 1cdcd3f..f789e2b 100644 --- a/src/indicator-datetime.c +++ b/src/indicator-datetime.c @@ -813,7 +813,7 @@ setup_timer (IndicatorDatetime * self, GDateTime * datetime) if (self->priv->show_seconds || (self->priv->time_mode == SETTINGS_TIME_CUSTOM && self->priv->custom_show_seconds)) { - self->priv->timer = g_timeout_add_full(G_PRIORITY_HIGH, 865, timer_func, self, NULL); + self->priv->timer = g_timeout_add_full(G_PRIORITY_HIGH, 999, timer_func, self, NULL); } else { if (datetime == NULL) { datetime = g_date_time_new_now_local(); -- cgit v1.2.3 From 594bff89b1c26340a1b0393cd17a45a48911fc9f Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Thu, 24 Mar 2011 13:14:40 -0500 Subject: update locations gsettings as soon as changes as made, not just when the dialog is closed --- src/datetime-prefs-locations.c | 74 ++++++++++++++++++++++++++++++++---------- 1 file changed, 57 insertions(+), 17 deletions(-) diff --git a/src/datetime-prefs-locations.c b/src/datetime-prefs-locations.c index b8d9f8f..5550450 100644 --- a/src/datetime-prefs-locations.c +++ b/src/datetime-prefs-locations.c @@ -39,7 +39,8 @@ with this program. If not, see . #define COL_TIME 1 #define COL_ZONE 2 -static gboolean update_times (TimezoneCompletion * completion); +static gboolean update_times (GtkWidget * dlg); +static void save_when_idle (GtkWidget * dlg); static void handle_add (GtkWidget * button, GtkTreeView * tree) @@ -96,7 +97,7 @@ handle_edit (GtkCellRendererText * renderer, gchar * path, gchar * new_text, static gboolean timezone_selected (GtkEntryCompletion * widget, GtkTreeModel * model, - GtkTreeIter * iter, gpointer user_data) + GtkTreeIter * iter, GtkWidget * dlg) { const gchar * zone, * name; @@ -132,7 +133,7 @@ timezone_selected (GtkEntryCompletion * widget, GtkTreeModel * model, gtk_list_store_set (store, store_iter, COL_NAME, name, COL_ZONE, zone, -1); } - update_times (TIMEZONE_COMPLETION (widget)); + update_times (dlg); return FALSE; // Do normal action too } @@ -155,9 +156,10 @@ handle_edit_started (GtkCellRendererText * renderer, GtkCellEditable * editable, } static gboolean -update_times (TimezoneCompletion * completion) +update_times (GtkWidget * dlg) { /* For each entry, check zone in column 2 and set column 1 to it's time */ + TimezoneCompletion * completion = TIMEZONE_COMPLETION (g_object_get_data (G_OBJECT (dlg), "completion")); GtkListStore * store = GTK_LIST_STORE (g_object_get_data (G_OBJECT (completion), "store")); GObject * cell = G_OBJECT (g_object_get_data (G_OBJECT (completion), "name-cell")); @@ -167,6 +169,8 @@ update_times (TimezoneCompletion * completion) return TRUE; } + g_signal_handlers_block_by_func (store, save_when_idle, dlg); + GDateTime * now = g_date_time_new_now_local (); GtkTreeIter iter; @@ -193,6 +197,9 @@ update_times (TimezoneCompletion * completion) } g_date_time_unref (now); + + g_signal_handlers_unblock_by_func (store, save_when_idle, dlg); + return TRUE; } @@ -220,13 +227,8 @@ fill_from_settings (GObject * store, GSettings * conf) } static void -dialog_closed (GtkWidget * dlg, GObject * store) +save_to_settings (GObject * store, GSettings * conf) { - /* Cleanup a tad */ - guint time_id = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (dlg), "time-id")); - g_source_remove (time_id); - - /* Now save to settings */ GVariantBuilder builder; g_variant_builder_init (&builder, G_VARIANT_TYPE_ARRAY); @@ -249,11 +251,45 @@ dialog_closed (GtkWidget * dlg, GObject * store) } GVariant * locations = g_variant_builder_end (&builder); + g_settings_set_strv (conf, SETTINGS_LOCATIONS_S, g_variant_get_strv (locations, NULL)); + g_variant_unref (locations); +} +static gboolean +save_now (GtkWidget *dlg) +{ GSettings * conf = G_SETTINGS (g_object_get_data (G_OBJECT (dlg), "conf")); - g_settings_set_strv (conf, SETTINGS_LOCATIONS_S, g_variant_get_strv (locations, NULL)); + GObject * completion = G_OBJECT (g_object_get_data (G_OBJECT (dlg), "completion")); + GObject * store = G_OBJECT (g_object_get_data (completion, "store")); - g_variant_unref (locations); + save_to_settings (store, conf); + + g_object_set_data (G_OBJECT (dlg), "save-id", GINT_TO_POINTER(0)); + + return FALSE; +} + +static void +save_when_idle (GtkWidget *dlg) +{ + guint save_id = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (dlg), "save-id")); + + if (save_id == 0) { + save_id = g_idle_add ((GSourceFunc)save_now, dlg); + g_object_set_data (G_OBJECT (dlg), "save-id", GINT_TO_POINTER(save_id)); + } +} + +static void +dialog_closed (GtkWidget * dlg, GObject * store) +{ + /* Cleanup a tad */ + guint time_id = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (dlg), "time-id")); + g_source_remove (time_id); + + guint save_id = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (dlg), "save-id")); + if (save_id > 0) + g_source_remove (save_id); } static void @@ -290,7 +326,7 @@ datetime_setup_locations_dialog (GtkWindow * parent, CcTimezoneMap * map) TimezoneCompletion * completion = timezone_completion_new (); g_object_set_data (G_OBJECT (completion), "tzmap", map); g_object_set_data (G_OBJECT (completion), "store", store); - g_signal_connect (completion, "match-selected", G_CALLBACK (timezone_selected), NULL); + g_signal_connect (completion, "match-selected", G_CALLBACK (timezone_selected), dlg); GtkCellRenderer * cell = gtk_cell_renderer_text_new (); g_object_set (cell, "editable", TRUE, NULL); @@ -317,15 +353,19 @@ datetime_setup_locations_dialog (GtkWindow * parent, CcTimezoneMap * map) g_signal_connect (WIG ("removeButton"), "clicked", G_CALLBACK (handle_remove), tree); fill_from_settings (store, conf); - - guint time_id = g_timeout_add_seconds (2, (GSourceFunc)update_times, completion); - update_times (completion); + 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); 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_object_set_data (G_OBJECT (dlg), "time-id", GINT_TO_POINTER(time_id)); g_signal_connect (dlg, "destroy", G_CALLBACK (dialog_closed), store); + guint time_id = g_timeout_add_seconds (2, (GSourceFunc)update_times, dlg); + g_object_set_data (G_OBJECT (dlg), "time-id", GINT_TO_POINTER(time_id)); + update_times (dlg); + gtk_window_set_transient_for (GTK_WINDOW (dlg), parent); #undef WIG -- cgit v1.2.3 From 0b0b94a49cd63bb1e1933cbe674c944c28ac24fb Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Thu, 24 Mar 2011 13:43:07 -0500 Subject: fix crash when emptying location list --- src/datetime-prefs-locations.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/datetime-prefs-locations.c b/src/datetime-prefs-locations.c index 5550450..d13f95a 100644 --- a/src/datetime-prefs-locations.c +++ b/src/datetime-prefs-locations.c @@ -229,6 +229,7 @@ fill_from_settings (GObject * store, GSettings * conf) static void save_to_settings (GObject * store, GSettings * conf) { + gboolean empty = TRUE; GVariantBuilder builder; g_variant_builder_init (&builder, G_VARIANT_TYPE_ARRAY); @@ -246,13 +247,21 @@ save_to_settings (GObject * store, GSettings * conf) gchar * settings_string = g_strdup_printf("%s %s", strzone, strname); g_variant_builder_add (&builder, "s", settings_string); g_free (settings_string); + empty = FALSE; } } while (gtk_tree_model_iter_next (GTK_TREE_MODEL (store), &iter)); } - GVariant * locations = g_variant_builder_end (&builder); - g_settings_set_strv (conf, SETTINGS_LOCATIONS_S, g_variant_get_strv (locations, NULL)); - g_variant_unref (locations); + if (empty) { + /* Empty list */ + g_variant_builder_clear (&builder); + g_settings_set_strv (conf, SETTINGS_LOCATIONS_S, NULL); + } + else { + GVariant * locations = g_variant_builder_end (&builder); + g_settings_set_strv (conf, SETTINGS_LOCATIONS_S, g_variant_get_strv (locations, NULL)); + g_variant_unref (locations); + } } static gboolean -- cgit v1.2.3 From acfa619b0301301a733e820cdda8d9335a15b45f Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Thu, 24 Mar 2011 13:54:25 -0500 Subject: show location separator even if no locations (since we always have the current location --- src/datetime-service.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/datetime-service.c b/src/datetime-service.c index 65df77e..b166f3c 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -437,11 +437,11 @@ update_timezone_menu_items(gpointer user_data) { gboolean show = g_settings_get_boolean (conf, SETTINGS_SHOW_LOCATIONS_S); - if (len > 0) { - dbusmenu_menuitem_property_set_bool (locations_separator, DBUSMENU_MENUITEM_PROP_VISIBLE, show); - dbusmenu_menuitem_property_set_bool (current_location, DBUSMENU_MENUITEM_PROP_VISIBLE, show); - dbusmenu_menuitem_property_set_bool (current_location, DBUSMENU_MENUITEM_PROP_ENABLED, TRUE); - } else { + dbusmenu_menuitem_property_set_bool (locations_separator, DBUSMENU_MENUITEM_PROP_VISIBLE, show); + dbusmenu_menuitem_property_set_bool (current_location, DBUSMENU_MENUITEM_PROP_VISIBLE, show); + dbusmenu_menuitem_property_set_bool (current_location, DBUSMENU_MENUITEM_PROP_ENABLED, TRUE); + + if (len == 0) { g_debug("No locations configured (Empty List)"); return FALSE; } -- cgit v1.2.3 From b86cc25455f38c4162ecd1fe6add20373c789980 Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Thu, 24 Mar 2011 16:22:52 -0400 Subject: fix memory leak that also prevented us noticing when the timezone got updated --- src/utils.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/utils.c b/src/utils.c index 537495b..d8851aa 100644 --- a/src/utils.c +++ b/src/utils.c @@ -233,6 +233,8 @@ generate_format_string_at_time (GDateTime * time) g_date_time_unref(future_bound); } + g_date_time_unref (now); + return generate_format_string_full(show_day, show_date); } -- cgit v1.2.3 From 47f806242850d509e1919780fa3eb2ec3598b356 Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Thu, 24 Mar 2011 16:54:00 -0400 Subject: don't access priv pointer if we've cancelled an async operation --- src/timezone-completion.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/timezone-completion.c b/src/timezone-completion.c index aaf6bdc..dddc003 100644 --- a/src/timezone-completion.c +++ b/src/timezone-completion.c @@ -99,14 +99,15 @@ json_parse_ready (GObject *object, GAsyncResult *res, gpointer user_data) json_parser_load_from_stream_finish (JSON_PARSER (object), res, &error); - if (priv->cancel && (error == NULL || error->code != G_IO_ERROR_CANCELLED)) { + if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED) && priv->cancel) { g_cancellable_reset (priv->cancel); } if (error != NULL) { + if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) + save_and_use_model (completion, priv->initial_model); g_warning ("Could not parse geoname JSON data: %s", error->message); g_error_free (error); - save_and_use_model (completion, priv->initial_model); return; } @@ -203,14 +204,15 @@ geonames_data_ready (GObject *object, GAsyncResult *res, gpointer user_data) stream = g_file_read_finish (G_FILE (object), res, &error); - if (priv->cancel && (error == NULL || error->code != G_IO_ERROR_CANCELLED)) { + if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED) && priv->cancel) { g_cancellable_reset (priv->cancel); } if (error != NULL) { + if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) + save_and_use_model (completion, priv->initial_model); g_warning ("Could not connect to geoname lookup server: %s", error->message); g_error_free (error); - save_and_use_model (completion, priv->initial_model); return; } -- cgit v1.2.3 From 37128f74bece1fea1d16503593546ce936568ae1 Mon Sep 17 00:00:00 2001 From: karl-qdh Date: Fri, 25 Mar 2011 16:09:17 +0000 Subject: Try splitting the function see if that works --- src/indicator-datetime.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c index 7b1164d..b47f1af 100644 --- a/src/indicator-datetime.c +++ b/src/indicator-datetime.c @@ -1144,10 +1144,17 @@ indicator_prop_change_cb (DbusmenuMenuitem * mi, gchar * prop, GVariant *value, timezone_update_labels(mi_data); } else if (!g_strcmp0(prop, TIMEZONE_MENUITEM_PROP_RADIO)) { gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(mi_data->gmi), g_variant_get_boolean(value)); - - // Properties for marking and unmarking the calendar - - } else if (!g_strcmp0(prop, CALENDAR_MENUITEM_PROP_MARK)) { + } else { + g_warning("Indicator Item property '%s' unknown", prop); + } + return; +} +// Properties for marking and unmarking the calendar +static void +calendar_prop_change_cb (DbusmenuMenuitem * mi, gchar * prop, GVariant *value, IdoCalendarMenuItem * mi_data) +{ + g_debug("Changing calendar property"); + if (!g_strcmp0(prop, CALENDAR_MENUITEM_PROP_MARK)) { ido_calendar_menu_item_mark_day (IDO_CALENDAR_MENU_ITEM (mi_data), g_variant_get_int16(value)); g_debug("Marked day: %d", g_variant_get_int16(value)); } else if (!g_strcmp0(prop, CALENDAR_MENUITEM_PROP_UNMARK)) { @@ -1332,7 +1339,7 @@ new_calendar_item (DbusmenuMenuitem * newitem, g_signal_connect_after(ido, "day-selected", G_CALLBACK(day_selected_cb), (gpointer)newitem); g_signal_connect_after(ido, "day-selected-double-click", G_CALLBACK(day_selected_double_click_cb), (gpointer)newitem); - g_signal_connect(G_OBJECT(newitem), DBUSMENU_MENUITEM_SIGNAL_PROPERTY_CHANGED, G_CALLBACK(indicator_prop_change_cb), ido); + g_signal_connect(G_OBJECT(newitem), DBUSMENU_MENUITEM_SIGNAL_PROPERTY_CHANGED, G_CALLBACK(calendar_prop_change_cb), ido); return TRUE; } -- cgit v1.2.3 From 6f4d5f0e8a120e35a10a8f4e2bc0b33438720e84 Mon Sep 17 00:00:00 2001 From: karl-qdh Date: Mon, 28 Mar 2011 11:22:03 +0100 Subject: Show calendar widget always --- src/datetime-service.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/datetime-service.c b/src/datetime-service.c index 65df77e..7e01f88 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -364,12 +364,13 @@ static gboolean check_for_calendar (gpointer user_data) { g_return_val_if_fail (calendar != NULL, FALSE); - + // Always enable the calendar even if it does nothing + dbusmenu_menuitem_property_set_bool(calendar, DBUSMENU_MENUITEM_PROP_ENABLED, TRUE); + dbusmenu_menuitem_property_set_bool(calendar, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE); + gchar *evo = g_find_program_in_path("evolution"); if (evo != NULL) { g_debug("Found the calendar application: %s", evo); - dbusmenu_menuitem_property_set_bool(calendar, DBUSMENU_MENUITEM_PROP_ENABLED, TRUE); - dbusmenu_menuitem_property_set_bool(calendar, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE); dbusmenu_menuitem_property_set_bool(date, DBUSMENU_MENUITEM_PROP_ENABLED, TRUE); g_signal_connect (G_OBJECT(date), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, -- cgit v1.2.3 From 09ad161fe9f61375d15abf38a6fefad6b23050e6 Mon Sep 17 00:00:00 2001 From: karl-qdh Date: Mon, 28 Mar 2011 11:54:16 +0100 Subject: Make switch statement more consistent might fix bug #743394 seems to be a weirdness in C related to; http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37231 --- src/indicator-datetime.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c index 1cdcd3f..28484f2 100644 --- a/src/indicator-datetime.c +++ b/src/indicator-datetime.c @@ -525,7 +525,7 @@ set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec } break; } - case PROP_SHOW_SECONDS: + case PROP_SHOW_SECONDS: { if (g_value_get_boolean(value) != self->priv->show_seconds) { self->priv->show_seconds = !self->priv->show_seconds; if (self->priv->time_mode != SETTINGS_TIME_CUSTOM) { @@ -534,7 +534,8 @@ set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec } } break; - case PROP_SHOW_DAY: + } + case PROP_SHOW_DAY: { if (g_value_get_boolean(value) != self->priv->show_day) { self->priv->show_day = !self->priv->show_day; if (self->priv->time_mode != SETTINGS_TIME_CUSTOM) { @@ -542,7 +543,8 @@ set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec } } break; - case PROP_SHOW_DATE: + } + case PROP_SHOW_DATE: { if (g_value_get_boolean(value) != self->priv->show_date) { self->priv->show_date = !self->priv->show_date; if (self->priv->time_mode != SETTINGS_TIME_CUSTOM) { @@ -550,6 +552,7 @@ set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec } } break; + } case PROP_CUSTOM_TIME_FORMAT: { const gchar * newstr = g_value_get_string(value); if (g_strcmp0(newstr, self->priv->custom_string) != 0) { @@ -585,11 +588,12 @@ set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec gtk_widget_set_visible (GTK_WIDGET (self->priv->ido_calendar), self->priv->show_calendar); } break; - } - default: + } + default: { G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); return; } + } if (!update) { return; -- cgit v1.2.3 From e4733095077a4bef45a1572492d5f593574c60f9 Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Mon, 28 Mar 2011 15:17:43 -0400 Subject: add missing a11y descriptions --- data/datetime-dialog.ui | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/data/datetime-dialog.ui b/data/datetime-dialog.ui index ead11d1..6bd7428 100644 --- a/data/datetime-dialog.ui +++ b/data/datetime-dialog.ui @@ -62,6 +62,11 @@ True True False + + + Add a Location… + + True @@ -82,6 +87,11 @@ True True False + + + Remove This Location + + True -- cgit v1.2.3 From 3f00f0b2b0790d6d8429d6d6812fcb78dcad9d7b Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Mon, 28 Mar 2011 15:21:46 -0400 Subject: Don't allow enter presses to leave non-timezone content in the model --- src/datetime-prefs-locations.c | 1 - src/datetime-prefs.c | 2 - src/timezone-completion.c | 109 ++++++++++++++++++++++++++++++++++++++++- 3 files changed, 107 insertions(+), 5 deletions(-) diff --git a/src/datetime-prefs-locations.c b/src/datetime-prefs-locations.c index d13f95a..9d0a97a 100644 --- a/src/datetime-prefs-locations.c +++ b/src/datetime-prefs-locations.c @@ -144,7 +144,6 @@ handle_edit_started (GtkCellRendererText * renderer, GtkCellEditable * editable, { if (GTK_IS_ENTRY (editable)) { GtkEntry *entry = GTK_ENTRY (editable); - gtk_entry_set_completion (entry, GTK_ENTRY_COMPLETION (completion)); timezone_completion_watch_entry (completion, entry); GtkListStore * store = GTK_LIST_STORE (g_object_get_data (G_OBJECT (completion), "store")); diff --git a/src/datetime-prefs.c b/src/datetime-prefs.c index fbc88f2..dfb94fe 100644 --- a/src/datetime-prefs.c +++ b/src/datetime-prefs.c @@ -604,8 +604,6 @@ create_dialog (void) /* And completion entry */ TimezoneCompletion * completion = timezone_completion_new (); - gtk_entry_set_completion (GTK_ENTRY (WIG ("timezoneEntry")), - GTK_ENTRY_COMPLETION (completion)); timezone_completion_watch_entry (completion, GTK_ENTRY (WIG ("timezoneEntry"))); g_signal_connect (completion, "match-selected", G_CALLBACK (timezone_selected), NULL); diff --git a/src/timezone-completion.c b/src/timezone-completion.c index c1ffb42..ab74219 100644 --- a/src/timezone-completion.c +++ b/src/timezone-completion.c @@ -24,6 +24,7 @@ with this program. If not, see . #include #include +#include #include #include "timezone-completion.h" #include "tz.h" @@ -41,6 +42,7 @@ struct _TimezoneCompletionPrivate GtkEntry * entry; guint queued_request; guint changed_id; + guint keypress_id; GCancellable * cancel; gchar * request_text; GHashTable * request_table; @@ -311,6 +313,7 @@ entry_changed (GtkEntry * entry, TimezoneCompletion * completion) if (priv->queued_request) { g_source_remove (priv->queued_request); + priv->queued_request = 0; } /* See if we've already got this one */ @@ -326,6 +329,94 @@ entry_changed (GtkEntry * entry, TimezoneCompletion * completion) gtk_entry_completion_complete (GTK_ENTRY_COMPLETION (completion)); } +static GtkWidget * +get_descendent (GtkWidget * parent, GType type) +{ + if (g_type_is_a (G_OBJECT_TYPE (parent), type)) + return parent; + + if (GTK_IS_CONTAINER (parent)) { + GList * children = gtk_container_get_children (GTK_CONTAINER (parent)); + GList * iter; + for (iter = children; iter; iter = iter->next) { + GtkWidget * found = get_descendent (GTK_WIDGET (iter->data), type); + if (found) { + g_list_free (children); + return found; + } + } + g_list_free (children); + } + + return NULL; +} + +/** + * The popup window and its GtkTreeView are private to our parent completion + * object. We can't get access to discover if there is a highlighted item or + * even if the window is showing right now. So this is a super hack to find + * it by looking through our toplevel's window group and finding a window with + * a GtkTreeView that points at our model. There should be only one ever, so + * we'll use the first one we find. + */ +static GtkTreeView * +find_popup_treeview (GtkWidget * widget, GtkTreeModel * model) +{ + GtkWidget * toplevel = gtk_widget_get_toplevel (widget); + if (!GTK_IS_WINDOW (toplevel)) + return NULL; + + GtkWindowGroup * group = gtk_window_get_group (GTK_WINDOW (toplevel)); + GList * windows = gtk_window_group_list_windows (group); + GList * iter; + for (iter = windows; iter; iter = iter->next) { + if (iter->data == toplevel) + continue; // Skip our own window, we don't have it + GtkWidget * view = get_descendent (GTK_WIDGET (iter->data), GTK_TYPE_TREE_VIEW); + if (view != NULL) { + GtkTreeModel * tree_model = gtk_tree_view_get_model (GTK_TREE_VIEW (view)); + if (GTK_IS_TREE_MODEL_FILTER (tree_model)) + tree_model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (tree_model)); + if (tree_model == model) { + g_list_free (windows); + return GTK_TREE_VIEW (view); + } + } + } + g_list_free (windows); + + return NULL; +} + +static gboolean +entry_keypress (GtkEntry * entry, GdkEventKey *event, TimezoneCompletion * completion) +{ + if (event->keyval == GDK_ISO_Enter || + event->keyval == GDK_KP_Enter || + event->keyval == GDK_Return) { + /* Make sure that user has a selection to choose, otherwise ignore */ + GtkTreeModel * model = gtk_entry_completion_get_model (GTK_ENTRY_COMPLETION (completion)); + GtkTreeView * view = find_popup_treeview (GTK_WIDGET (entry), model); + if (view == NULL) { + // Just beep if popup hasn't appeared yet. + gtk_widget_error_bell (GTK_WIDGET (entry)); + return TRUE; + } + + GtkTreeSelection * sel = gtk_tree_view_get_selection (view); + GtkTreeModel * sel_model = NULL; + if (!gtk_tree_selection_get_selected (sel, &sel_model, NULL)) { + // No selection, we should help them out and select first item in list + GtkTreeIter iter; + if (gtk_tree_model_get_iter_first (sel_model, &iter)) + gtk_tree_selection_select_iter (sel, &iter); + // And fall through to normal handler code + } + } + + return FALSE; +} + void timezone_completion_watch_entry (TimezoneCompletion * completion, GtkEntry * entry) { @@ -336,15 +427,22 @@ timezone_completion_watch_entry (TimezoneCompletion * completion, GtkEntry * ent priv->queued_request = 0; } if (priv->entry) { - g_source_remove (priv->changed_id); + g_signal_handler_disconnect (priv->entry, priv->changed_id); + g_signal_handler_disconnect (priv->entry, priv->keypress_id); g_object_remove_weak_pointer (G_OBJECT (priv->entry), (gpointer *)&priv->entry); + gtk_entry_set_completion (priv->entry, NULL); } guint id = g_signal_connect (entry, "changed", G_CALLBACK (entry_changed), completion); priv->changed_id = id; + id = g_signal_connect (entry, "key-press-event", G_CALLBACK (entry_keypress), completion); + priv->keypress_id = id; + priv->entry = entry; g_object_add_weak_pointer (G_OBJECT (entry), (gpointer *)&priv->entry); + + gtk_entry_set_completion (entry, GTK_ENTRY_COMPLETION (completion)); } static GtkListStore * @@ -466,10 +564,17 @@ timezone_completion_dispose (GObject * object) TimezoneCompletionPrivate * priv = TIMEZONE_COMPLETION_GET_PRIVATE (completion); if (priv->changed_id) { - g_source_remove (priv->changed_id); + if (priv->entry) + g_signal_handler_disconnect (priv->entry, priv->changed_id); priv->changed_id = 0; } + if (priv->keypress_id) { + if (priv->entry) + g_signal_handler_disconnect (priv->entry, priv->keypress_id); + priv->keypress_id = 0; + } + if (priv->entry != NULL) { g_object_remove_weak_pointer (G_OBJECT (priv->entry), (gpointer *)&priv->entry); } -- cgit v1.2.3 From 26fddf955899a2751b140a8c5a75f6861509b66e Mon Sep 17 00:00:00 2001 From: karl-qdh Date: Tue, 29 Mar 2011 14:23:29 +0100 Subject: Adding tedg's suggested change to the property sending, no change in signals being received by the other side. --- src/datetime-service.c | 20 ++++++++++++-------- src/indicator-datetime.c | 24 +++++++++++++++++++----- 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/src/datetime-service.c b/src/datetime-service.c index 17745fe..b0298ae 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -607,7 +607,7 @@ update_appointment_menu_items (gpointer user_data) int days[12]={31,28,31,30,31,30,31,31,30,31,30,31}; if ((this_year % 400 == 0) || (this_year % 100 > 0 && this_year % 4 == 0)) days[1] = 29; - int highlightdays = days[mon] - mday + 1; + int highlightdays = days[mon] - mday; t1 = curtime; // By default the current time is the appointment start time. if (start_time_appointments > 0) { @@ -627,10 +627,7 @@ update_appointment_menu_items (gpointer user_data) g_debug("Will highlight %d days from %s", highlightdays, ctime(&t1)); - t2 = t1 + (time_t) (highlightdays * 24 * 60 * 60); - - // Remove all highlights from the calendar widget - dbusmenu_menuitem_property_set (calendar, CALENDAR_MENUITEM_PROP_CLEAR_MARKS, NULL); + 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"); @@ -702,6 +699,11 @@ update_appointment_menu_items (gpointer user_data) } else { apt_output = SETTINGS_TIME_LOCALE; } + // Remove all highlights from the calendar widget + dbusmenu_menuitem_property_set (calendar, CALENDAR_MENUITEM_PROP_CLEAR_MARKS, NULL); + + GVariantBuilder markeddays; + g_variant_builder_init (&markeddays, G_VARIANT_TYPE_ARRAY); i = 0; for (l = sorted_comp_instances; l; l = l->next) { @@ -724,9 +726,8 @@ update_appointment_menu_items (gpointer user_data) const int dyear = due->tm_year; // Mark day - g_debug("Marking date %s", ctime(&ci->start)); - dbusmenu_menuitem_property_set_int (calendar, CALENDAR_MENUITEM_PROP_MARK, due->tm_mday); - + g_debug("Adding marked date %s, %d", ctime(&ci->start), dmday); + g_variant_builder_add (&markeddays, "i", dmday); // If the appointment time is less than the selected date, // don't create an appointment item for it. @@ -854,6 +855,9 @@ update_appointment_menu_items (gpointer user_data) } g_list_free(sorted_comp_instances); + GVariant * marks = g_variant_builder_end (&markeddays); + dbusmenu_menuitem_property_set_variant (calendar, CALENDAR_MENUITEM_PROP_MARK, marks); + updating_appointments = FALSE; g_debug("End of objects"); return TRUE; diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c index b47f1af..71b174c 100644 --- a/src/indicator-datetime.c +++ b/src/indicator-datetime.c @@ -1155,14 +1155,28 @@ calendar_prop_change_cb (DbusmenuMenuitem * mi, gchar * prop, GVariant *value, I { g_debug("Changing calendar property"); if (!g_strcmp0(prop, CALENDAR_MENUITEM_PROP_MARK)) { - ido_calendar_menu_item_mark_day (IDO_CALENDAR_MENU_ITEM (mi_data), g_variant_get_int16(value)); - g_debug("Marked day: %d", g_variant_get_int16(value)); + GVariantIter iter; + GVariant *day; + gchar *key; + + g_variant_iter_init (&iter, value); + while (g_variant_iter_loop (&iter, "{i}", &key, &day)) { + ido_calendar_menu_item_mark_day (IDO_CALENDAR_MENU_ITEM (mi_data), g_variant_get_int32(day)); + g_debug("Marked day: %d", g_variant_get_int32(day)); + } } else if (!g_strcmp0(prop, CALENDAR_MENUITEM_PROP_UNMARK)) { - ido_calendar_menu_item_unmark_day (IDO_CALENDAR_MENU_ITEM (mi_data), g_variant_get_int16(value)); - g_debug("Unmarked day: %d", g_variant_get_int16(value)); + GVariantIter iter; + GVariant *day; + gchar *key; + + g_variant_iter_init (&iter, value); + while (g_variant_iter_loop (&iter, "{i}", &key, &day)) { + ido_calendar_menu_item_unmark_day (IDO_CALENDAR_MENU_ITEM (mi_data), g_variant_get_int32(day)); + g_debug("Unmarked day: %d", g_variant_get_int32(day)); + } } else if (!g_strcmp0(prop, CALENDAR_MENUITEM_PROP_CLEAR_MARKS)) { - g_debug("Cleared Marks"); ido_calendar_menu_item_clear_marks (IDO_CALENDAR_MENU_ITEM (mi_data)); + g_debug("Cleared Marks"); } else if (!g_strcmp0(prop, CALENDAR_MENUITEM_PROP_SET_DATE)) { gsize size = 3; const gint * array = g_variant_get_fixed_array(value, &size, sizeof(gint)); -- cgit v1.2.3 From 18ea5194b357dbd14dd724eb32013af8031a50be Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Tue, 29 Mar 2011 11:17:52 -0400 Subject: treat locations dialog not as a modal dialog, but rather one that can be dismissed by interacting with the main dialog --- data/datetime-dialog.ui | 1 - src/datetime-prefs-locations.c | 4 +--- src/datetime-prefs-locations.h | 2 +- src/datetime-prefs.c | 20 ++++++++++++++++++-- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/data/datetime-dialog.ui b/data/datetime-dialog.ui index ead11d1..f150765 100644 --- a/data/datetime-dialog.ui +++ b/data/datetime-dialog.ui @@ -10,7 +10,6 @@ False Locations - True 300 200 True diff --git a/src/datetime-prefs-locations.c b/src/datetime-prefs-locations.c index d13f95a..5dd13e8 100644 --- a/src/datetime-prefs-locations.c +++ b/src/datetime-prefs-locations.c @@ -309,7 +309,7 @@ selection_changed (GtkTreeSelection * selection, GtkWidget * remove_button) } GtkWidget * -datetime_setup_locations_dialog (GtkWindow * parent, CcTimezoneMap * map) +datetime_setup_locations_dialog (CcTimezoneMap * map) { GError * error = NULL; GtkBuilder * builder = gtk_builder_new (); @@ -375,8 +375,6 @@ datetime_setup_locations_dialog (GtkWindow * parent, CcTimezoneMap * map) g_object_set_data (G_OBJECT (dlg), "time-id", GINT_TO_POINTER(time_id)); update_times (dlg); - gtk_window_set_transient_for (GTK_WINDOW (dlg), parent); - #undef WIG g_object_unref (conf); diff --git a/src/datetime-prefs-locations.h b/src/datetime-prefs-locations.h index 1760567..e312894 100644 --- a/src/datetime-prefs-locations.h +++ b/src/datetime-prefs-locations.h @@ -28,7 +28,7 @@ with this program. If not, see . G_BEGIN_DECLS -GtkWidget * datetime_setup_locations_dialog (GtkWindow * parent, CcTimezoneMap * map); +GtkWidget * datetime_setup_locations_dialog (CcTimezoneMap * map); G_END_DECLS diff --git a/src/datetime-prefs.c b/src/datetime-prefs.c index fbc88f2..5a6fd91 100644 --- a/src/datetime-prefs.c +++ b/src/datetime-prefs.c @@ -53,6 +53,7 @@ GtkWidget * date_spin = NULL; guint save_time_id = 0; gboolean user_edited_time = FALSE; gboolean changing_time = FALSE; +GtkWidget * loc_dlg = NULL; /* Turns the boolean property into a string gsettings */ static GVariant * @@ -494,11 +495,26 @@ setup_time_spinners (GtkWidget * time, GtkWidget * date) update_spinners (); } +static void +hide_locations () +{ + if (loc_dlg != NULL) + gtk_widget_destroy (loc_dlg); +} + static void show_locations (GtkWidget * button, GtkWidget * dlg) { - GtkWidget * locationsDlg = datetime_setup_locations_dialog (GTK_WINDOW (dlg), tzmap); - gtk_widget_show_all (locationsDlg); + if (loc_dlg == NULL) { + loc_dlg = datetime_setup_locations_dialog (tzmap); + gtk_window_set_transient_for (GTK_WINDOW (loc_dlg), GTK_WINDOW (dlg)); + g_signal_connect (loc_dlg, "destroy", G_CALLBACK (gtk_widget_destroyed), &loc_dlg); + g_signal_connect (dlg, "focus-in-event", G_CALLBACK (hide_locations), NULL); + gtk_widget_show_all (loc_dlg); + } + else { + gtk_window_present_with_time (GTK_WINDOW (loc_dlg), gtk_get_current_event_time ()); + } } static gboolean -- cgit v1.2.3 From 143f495ab94cb006954c036cf29079cbb49d584b Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Tue, 29 Mar 2011 12:14:40 -0400 Subject: use background color for insensitive map --- libmap/cc-timezone-map.c | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/libmap/cc-timezone-map.c b/libmap/cc-timezone-map.c index 8e4a5b8..7b7d704 100644 --- a/libmap/cc-timezone-map.c +++ b/libmap/cc-timezone-map.c @@ -766,13 +766,23 @@ cc_timezone_map_draw (GtkWidget *widget, gchar *file; GError *err = NULL; gdouble pointx, pointy; + gdouble alpha = 1.0; + GtkStyle *style; char buf[16]; gtk_widget_get_allocation (widget, &alloc); + style = gtk_widget_get_style (widget); + + /* Check if insensitive */ + if (gtk_widget_get_state (widget) == GTK_STATE_INSENSITIVE) + alpha = 0.5; + /* paint background */ - gdk_cairo_set_source_pixbuf (cr, priv->background, 0, 0); + gdk_cairo_set_source_color (cr, &style->bg[gtk_widget_get_state (widget)]); cairo_paint (cr); + gdk_cairo_set_source_pixbuf (cr, priv->background, 0, 0); + cairo_paint_with_alpha (cr, alpha); /* paint watermark */ if (priv->watermark) { @@ -788,13 +798,6 @@ cc_timezone_map_draw (GtkWidget *widget, } if (!priv->location) { - /* Check if insensitive */ - if (gtk_widget_get_state (widget) == GTK_STATE_INSENSITIVE) { - cairo_set_source_rgba(cr, 1, 1, 1, 0.5); - cairo_rectangle(cr, 0, 0, alloc.width, alloc.height); - cairo_fill(cr); - } - return TRUE; } @@ -820,7 +823,7 @@ cc_timezone_map_draw (GtkWidget *widget, alloc.height, GDK_INTERP_BILINEAR); gdk_cairo_set_source_pixbuf (cr, hilight, 0, 0); - cairo_paint (cr); + cairo_paint_with_alpha (cr, alpha); g_object_unref (hilight); g_object_unref (orig_hilight); } @@ -843,17 +846,10 @@ cc_timezone_map_draw (GtkWidget *widget, if (pin) { gdk_cairo_set_source_pixbuf (cr, pin, pointx - 8, pointy - 14); - cairo_paint (cr); + cairo_paint_with_alpha (cr, alpha); g_object_unref (pin); } - /* Check if insensitive */ - if (gtk_widget_get_state (widget) == GTK_STATE_INSENSITIVE) { - cairo_set_source_rgba(cr, 1, 1, 1, 0.5); - cairo_rectangle(cr, 0, 0, alloc.width, alloc.height); - cairo_fill(cr); - } - return TRUE; } -- cgit v1.2.3 From 37106c9e4c1d59285fdc0185ea2f55891d19c4cf Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Tue, 29 Mar 2011 15:18:55 -0400 Subject: don't call complete() unless we have an entry --- src/timezone-completion.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/timezone-completion.c b/src/timezone-completion.c index 2e1afc0..1c47bc0 100644 --- a/src/timezone-completion.c +++ b/src/timezone-completion.c @@ -79,12 +79,15 @@ save_and_use_model (TimezoneCompletion * completion, GtkTreeModel * model) gtk_entry_completion_set_match_func (GTK_ENTRY_COMPLETION (completion), match_func, NULL, NULL); gtk_entry_completion_set_model (GTK_ENTRY_COMPLETION (completion), model); - gtk_entry_completion_complete (GTK_ENTRY_COMPLETION (completion)); - /* By this time, the changed signal has come and gone. We didn't give a - model to use, so no popup appeared for user. Poke the entry again to show - popup in 300ms. */ - g_signal_emit_by_name (priv->entry, "changed"); + if (priv->entry != NULL) { + gtk_entry_completion_complete (GTK_ENTRY_COMPLETION (completion)); + + /* By this time, the changed signal has come and gone. We didn't give a + model to use, so no popup appeared for user. Poke the entry again to show + popup in 300ms. */ + g_signal_emit_by_name (priv->entry, "changed"); + } } static gint -- cgit v1.2.3 From 348285a8a64bedf936b5cc36a9e73519c2dde0d2 Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Tue, 29 Mar 2011 15:53:18 -0400 Subject: show error icon if user focuses out of location entry when it has an non-location value --- data/datetime-dialog.ui | 4 ++++ src/datetime-prefs-locations.c | 38 +++++++++++++++++++++++++++++++------- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/data/datetime-dialog.ui b/data/datetime-dialog.ui index 80b4fa6..8479482 100644 --- a/data/datetime-dialog.ui +++ b/data/datetime-dialog.ui @@ -123,6 +123,10 @@ + + + + diff --git a/src/datetime-prefs-locations.c b/src/datetime-prefs-locations.c index 6addac3..2862022 100644 --- a/src/datetime-prefs-locations.c +++ b/src/datetime-prefs-locations.c @@ -35,9 +35,11 @@ with this program. If not, see . #define DATETIME_DIALOG_UI_FILE PKGDATADIR "/datetime-dialog.ui" -#define COL_NAME 0 -#define COL_TIME 1 -#define COL_ZONE 2 +#define COL_NAME 0 +#define COL_TIME 1 +#define COL_ZONE 2 +#define COL_VISIBLE_NAME 3 +#define COL_ICON 4 static gboolean update_times (GtkWidget * dlg); static void save_when_idle (GtkWidget * dlg); @@ -90,8 +92,18 @@ handle_edit (GtkCellRendererText * renderer, gchar * path, gchar * new_text, { GtkTreeIter iter; + // Manual user edits are always wrong (unless they are undoing a previous + // edit), so we set the error icon here if needed. Common way to get to + // this code path is to lose entry focus. if (gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (store), &iter, path)) { - gtk_list_store_set (store, &iter, COL_NAME, new_text, -1); + const gchar * name; + gtk_tree_model_get (GTK_TREE_MODEL (store), &iter, COL_NAME, &name, -1); + gboolean correct = g_strcmp0 (name, new_text) == 0; + + gtk_list_store_set (store, &iter, + COL_VISIBLE_NAME, new_text, + COL_ICON, correct ? NULL : GTK_STOCK_DIALOG_ERROR, + -1); } } @@ -130,7 +142,11 @@ timezone_selected (GtkEntryCompletion * widget, GtkTreeModel * model, GtkListStore * store = GTK_LIST_STORE (g_object_get_data (G_OBJECT (widget), "store")); GtkTreeIter * store_iter = (GtkTreeIter *)g_object_get_data (G_OBJECT (widget), "store_iter"); if (store != NULL && store_iter != NULL) { - gtk_list_store_set (store, store_iter, COL_NAME, name, COL_ZONE, zone, -1); + gtk_list_store_set (store, store_iter, + COL_VISIBLE_NAME, name, + COL_ICON, NULL, + COL_NAME, name, + COL_ZONE, zone, -1); } update_times (dlg); @@ -216,7 +232,11 @@ fill_from_settings (GObject * store, GSettings * conf) split_settings_location (*striter, &zone, &name); gtk_list_store_append (GTK_LIST_STORE (store), &iter); - gtk_list_store_set (GTK_LIST_STORE (store), &iter, COL_NAME, name, COL_ZONE, zone, -1); + gtk_list_store_set (GTK_LIST_STORE (store), &iter, + COL_VISIBLE_NAME, name, + COL_ICON, NULL, + COL_NAME, name, + COL_ZONE, zone, -1); g_free (zone); g_free (name); @@ -342,11 +362,15 @@ datetime_setup_locations_dialog (CcTimezoneMap * map) g_signal_connect (cell, "edited", G_CALLBACK (handle_edit), store); gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree), -1, _("Location"), cell, - "text", COL_NAME, NULL); + "text", COL_VISIBLE_NAME, NULL); GtkTreeViewColumn * loc_col = gtk_tree_view_get_column (GTK_TREE_VIEW (tree), 0); gtk_tree_view_column_set_expand (loc_col, TRUE); g_object_set_data (G_OBJECT (completion), "name-cell", cell); + cell = gtk_cell_renderer_pixbuf_new (); + gtk_tree_view_column_pack_start (loc_col, cell, FALSE); + gtk_tree_view_column_add_attribute (loc_col, cell, "icon-name", COL_ICON); + cell = gtk_cell_renderer_text_new (); gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree), -1, _("Time"), cell, -- cgit v1.2.3 From 095bf2692ce36c1197349a629dde3c714c845384 Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Tue, 29 Mar 2011 17:22:14 -0300 Subject: remember user's preferred location name for main timezone --- data/com.canonical.indicator.datetime.gschema.xml | 7 +++ src/datetime-prefs.c | 62 ++++++++++++++++------- src/settings-shared.h | 1 + 3 files changed, 51 insertions(+), 19 deletions(-) diff --git a/data/com.canonical.indicator.datetime.gschema.xml b/data/com.canonical.indicator.datetime.gschema.xml index b33f34e..8ce75e6 100644 --- a/data/com.canonical.indicator.datetime.gschema.xml +++ b/data/com.canonical.indicator.datetime.gschema.xml @@ -100,5 +100,12 @@ indicator-datetime menu. + + '' + The name of the current timezone + + Some timezones can be known by many different cities or names. This setting describes how the current zone prefers to be named. Format is "TIMEZONE NAME" (e.g. "America/New_York Boston" to name the New_York zone Boston). + + diff --git a/src/datetime-prefs.c b/src/datetime-prefs.c index 4213ea9..b1335ca 100644 --- a/src/datetime-prefs.c +++ b/src/datetime-prefs.c @@ -184,10 +184,30 @@ ntp_query_answered (GObject *object, GAsyncResult *res, gpointer user_data) static void sync_entry (const gchar * location) { - gchar * name; - split_settings_location (location, NULL, &name); - gtk_entry_set_text (GTK_ENTRY (tz_entry), name); - g_free (name); + gchar * new_zone, * new_name; + gchar * old_zone, * old_name; + + split_settings_location (location, &new_zone, &new_name); + + GSettings * conf = g_settings_new (SETTINGS_INTERFACE); + gchar * tz_name = g_settings_get_string (conf, SETTINGS_TIMEZONE_NAME_S); + split_settings_location (tz_name, &old_zone, &old_name); + g_free (tz_name); + g_object_unref (conf); + + // new_name is always just a sanitized version of a timezone. + // old_name is potentially a saved "pretty" version of a timezone name from + // geonames. So we prefer to use it if available and the zones match. + + if (g_strcmp0 (old_zone, new_zone) == 0) + gtk_entry_set_text (GTK_ENTRY (tz_entry), old_name); + else + gtk_entry_set_text (GTK_ENTRY (tz_entry), new_name); + + g_free (new_zone); + g_free (old_zone); + g_free (new_name); + g_free (old_name); } static void @@ -521,36 +541,40 @@ static gboolean timezone_selected (GtkEntryCompletion * widget, GtkTreeModel * model, GtkTreeIter * iter, gpointer user_data) { - GValue value = {0}; - const gchar * strval; + const gchar * name, * zone; - gtk_tree_model_get_value (model, iter, TIMEZONE_COMPLETION_ZONE, &value); - strval = g_value_get_string (&value); + gtk_tree_model_get (model, iter, + TIMEZONE_COMPLETION_NAME, &name, + TIMEZONE_COMPLETION_ZONE, &zone, + -1); - if (strval != NULL && strval[0] != 0) { - cc_timezone_map_set_timezone (tzmap, strval); - } - else { - GValue lon_value = {0}, lat_value = {0}; + if (zone == NULL || zone[0] == 0) { const gchar * strlon, * strlat; gdouble lon = 0.0, lat = 0.0; - gtk_tree_model_get_value (model, iter, TIMEZONE_COMPLETION_LONGITUDE, &lon_value); - strlon = g_value_get_string (&lon_value); + gtk_tree_model_get (model, iter, + TIMEZONE_COMPLETION_LONGITUDE, &strlon, + TIMEZONE_COMPLETION_LATITUDE, &strlat, + -1); + if (strlon != NULL && strlon[0] != 0) { lon = strtod(strlon, NULL); } - gtk_tree_model_get_value (model, iter, TIMEZONE_COMPLETION_LATITUDE, &lat_value); - strlat = g_value_get_string (&lat_value); if (strlat != NULL && strlat[0] != 0) { lat = strtod(strlat, NULL); } - cc_timezone_map_set_coords (tzmap, lon, lat); + zone = cc_timezone_map_get_timezone_at_coords (tzmap, lon, lat); } - g_value_unset (&value); + GSettings * conf = g_settings_new (SETTINGS_INTERFACE); + gchar * tz_name = g_strdup_printf ("%s %s", zone, name); + g_settings_set_string (conf, SETTINGS_TIMEZONE_NAME_S, tz_name); + g_free (tz_name); + g_object_unref (conf); + + cc_timezone_map_set_timezone (tzmap, zone); return FALSE; // Do normal action too } diff --git a/src/settings-shared.h b/src/settings-shared.h index cdbb063..1ad4799 100644 --- a/src/settings-shared.h +++ b/src/settings-shared.h @@ -34,6 +34,7 @@ with this program. If not, see . #define SETTINGS_SHOW_EVENTS_S "show-events" #define SETTINGS_SHOW_LOCATIONS_S "show-locations" #define SETTINGS_LOCATIONS_S "locations" +#define SETTINGS_TIMEZONE_NAME_S "timezone-name" enum { SETTINGS_TIME_LOCALE = 0, -- cgit v1.2.3 From 851b7395730c2679403bc69013a9aea94584721d Mon Sep 17 00:00:00 2001 From: karl-qdh Date: Wed, 30 Mar 2011 12:49:01 +0100 Subject: Made marking work when you change month, still needs more work to get it to do it on startup properly. --- src/datetime-service.c | 6 ++---- src/indicator-datetime.c | 34 ++++++++++++++++++---------------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/datetime-service.c b/src/datetime-service.c index b0298ae..36a9a73 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -607,7 +607,7 @@ update_appointment_menu_items (gpointer user_data) int days[12]={31,28,31,30,31,30,31,31,30,31,30,31}; if ((this_year % 400 == 0) || (this_year % 100 > 0 && this_year % 4 == 0)) days[1] = 29; - int highlightdays = days[mon] - mday; + int highlightdays = days[mon] - mday + 1; t1 = curtime; // By default the current time is the appointment start time. if (start_time_appointments > 0) { @@ -621,7 +621,7 @@ update_appointment_menu_items (gpointer user_data) month_start.tm_mon = start_tm->tm_mon; month_start.tm_mday = 1; t1 = mktime(&month_start); - highlightdays = days[mon]; + highlightdays = days[start_month]; } } @@ -699,8 +699,6 @@ update_appointment_menu_items (gpointer user_data) } else { apt_output = SETTINGS_TIME_LOCALE; } - // Remove all highlights from the calendar widget - dbusmenu_menuitem_property_set (calendar, CALENDAR_MENUITEM_PROP_CLEAR_MARKS, NULL); GVariantBuilder markeddays; g_variant_builder_init (&markeddays, G_VARIANT_TYPE_ARRAY); diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c index 71b174c..ef3a857 100644 --- a/src/indicator-datetime.c +++ b/src/indicator-datetime.c @@ -1155,25 +1155,27 @@ calendar_prop_change_cb (DbusmenuMenuitem * mi, gchar * prop, GVariant *value, I { g_debug("Changing calendar property"); if (!g_strcmp0(prop, CALENDAR_MENUITEM_PROP_MARK)) { - GVariantIter iter; - GVariant *day; - gchar *key; - - g_variant_iter_init (&iter, value); - while (g_variant_iter_loop (&iter, "{i}", &key, &day)) { - ido_calendar_menu_item_mark_day (IDO_CALENDAR_MENU_ITEM (mi_data), g_variant_get_int32(day)); - g_debug("Marked day: %d", g_variant_get_int32(day)); + ido_calendar_menu_item_clear_marks (IDO_CALENDAR_MENU_ITEM (mi_data)); + g_debug("Marks: Cleared"); + GVariantIter *iter; + gint day; + + g_variant_get (value, "ai", &iter); + while (g_variant_iter_loop (iter, "i", &day)) { + ido_calendar_menu_item_mark_day (IDO_CALENDAR_MENU_ITEM (mi_data), day); + g_debug("Marks: Marked day: %d", day); } + g_variant_iter_free (iter); } else if (!g_strcmp0(prop, CALENDAR_MENUITEM_PROP_UNMARK)) { - GVariantIter iter; - GVariant *day; - gchar *key; - - g_variant_iter_init (&iter, value); - while (g_variant_iter_loop (&iter, "{i}", &key, &day)) { - ido_calendar_menu_item_unmark_day (IDO_CALENDAR_MENU_ITEM (mi_data), g_variant_get_int32(day)); - g_debug("Unmarked day: %d", g_variant_get_int32(day)); + GVariantIter *iter; + gint day; + + g_variant_get (value, "ai", &iter); + while (g_variant_iter_loop (iter, "i", &day)) { + g_debug("Unmarked day: %d", day); + ido_calendar_menu_item_unmark_day (IDO_CALENDAR_MENU_ITEM (mi_data), day); } + g_variant_iter_free (iter); } else if (!g_strcmp0(prop, CALENDAR_MENUITEM_PROP_CLEAR_MARKS)) { ido_calendar_menu_item_clear_marks (IDO_CALENDAR_MENU_ITEM (mi_data)); g_debug("Cleared Marks"); -- cgit v1.2.3 From af19585a970b79fdb5c566b1008d41830ced41c1 Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Wed, 30 Mar 2011 09:12:30 -0400 Subject: add tooltip to error icon --- src/datetime-prefs-locations.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/datetime-prefs-locations.c b/src/datetime-prefs-locations.c index 2862022..9c23a40 100644 --- a/src/datetime-prefs-locations.c +++ b/src/datetime-prefs-locations.c @@ -154,6 +154,27 @@ timezone_selected (GtkEntryCompletion * widget, GtkTreeModel * model, return FALSE; // Do normal action too } +static gboolean +query_tooltip (GtkTreeView * tree, gint x, gint y, gboolean keyboard_mode, + GtkTooltip * tooltip, GtkCellRenderer * cell) +{ + GtkTreeModel * model; + GtkTreeIter iter; + if (!gtk_tree_view_get_tooltip_context (tree, &x, &y, keyboard_mode, + &model, NULL, &iter)) + return FALSE; + + const gchar * icon; + gtk_tree_model_get (model, &iter, COL_ICON, &icon, -1); + if (icon == NULL) + return FALSE; + + GtkTreeViewColumn * col = gtk_tree_view_get_column (tree, 0); + gtk_tree_view_set_tooltip_cell (tree, tooltip, NULL, col, cell); + gtk_tooltip_set_text (tooltip, _("You need to complete this location for it to appear in the menu.")); + return TRUE; +} + static void handle_edit_started (GtkCellRendererText * renderer, GtkCellEditable * editable, gchar * path, TimezoneCompletion * completion) @@ -371,6 +392,9 @@ datetime_setup_locations_dialog (CcTimezoneMap * map) gtk_tree_view_column_pack_start (loc_col, cell, FALSE); gtk_tree_view_column_add_attribute (loc_col, cell, "icon-name", COL_ICON); + gtk_widget_set_has_tooltip (tree, TRUE); + g_signal_connect (tree, "query-tooltip", G_CALLBACK (query_tooltip), cell); + cell = gtk_cell_renderer_text_new (); gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree), -1, _("Time"), cell, -- cgit v1.2.3 From 642c67ed942d7ce49ab48303ba611b7f21d7e1d5 Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Wed, 30 Mar 2011 09:12:39 -0400 Subject: add error icon to main timezone entry --- src/datetime-prefs.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 46 insertions(+), 6 deletions(-) diff --git a/src/datetime-prefs.c b/src/datetime-prefs.c index b1335ca..4a32fd6 100644 --- a/src/datetime-prefs.c +++ b/src/datetime-prefs.c @@ -181,11 +181,12 @@ ntp_query_answered (GObject *object, GAsyncResult *res, gpointer user_data) g_variant_unref (answers); } -static void -sync_entry (const gchar * location) +static gchar * +get_zone_name (const gchar * location) { gchar * new_zone, * new_name; gchar * old_zone, * old_name; + gchar * rv; split_settings_location (location, &new_zone, &new_name); @@ -199,15 +200,31 @@ sync_entry (const gchar * location) // old_name is potentially a saved "pretty" version of a timezone name from // geonames. So we prefer to use it if available and the zones match. - if (g_strcmp0 (old_zone, new_zone) == 0) - gtk_entry_set_text (GTK_ENTRY (tz_entry), old_name); - else - gtk_entry_set_text (GTK_ENTRY (tz_entry), new_name); + if (g_strcmp0 (old_zone, new_zone) == 0) { + rv = old_name; + old_name = NULL; + } + else { + rv = new_name; + new_name = NULL; + } g_free (new_zone); g_free (old_zone); g_free (new_name); g_free (old_name); + + return rv; +} + +static void +sync_entry (const gchar * location) +{ + gchar * name = get_zone_name (location); + gtk_entry_set_text (GTK_ENTRY (tz_entry), name); + g_free (name); + + gtk_entry_set_icon_from_stock (GTK_ENTRY (tz_entry), GTK_ENTRY_ICON_SECONDARY, NULL); } static void @@ -579,6 +596,28 @@ timezone_selected (GtkEntryCompletion * widget, GtkTreeModel * model, return FALSE; // Do normal action too } +static gboolean +entry_focus_out (GtkEntry * entry, GdkEventFocus * event) +{ + // If the name left in the entry doesn't match the current timezone name, + // show an error icon. It's always an error for the user to manually type in + // a timezone. + TzLocation * location = cc_timezone_map_get_location (tzmap); + if (location == NULL) + return FALSE; + + gchar * name = get_zone_name (location->zone); + gboolean correct = (g_strcmp0 (gtk_entry_get_text (entry), name) == 0); + g_free (name); + + gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, + correct ? NULL : GTK_STOCK_DIALOG_ERROR); + gtk_entry_set_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY, + _("You need to choose a location to change the time zone.")); + gtk_entry_set_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY, FALSE); + return FALSE; +} + static gboolean key_pressed (GtkWidget * widget, GdkEventKey * event, gpointer user_data) { @@ -646,6 +685,7 @@ create_dialog (void) TimezoneCompletion * completion = timezone_completion_new (); timezone_completion_watch_entry (completion, GTK_ENTRY (WIG ("timezoneEntry"))); g_signal_connect (completion, "match-selected", G_CALLBACK (timezone_selected), NULL); + g_signal_connect (WIG ("timezoneEntry"), "focus-out-event", G_CALLBACK (entry_focus_out), NULL); /* Set up settings bindings */ g_settings_bind (conf, SETTINGS_SHOW_CLOCK_S, WIG ("showClockCheck"), -- cgit v1.2.3 From 019db0b50bfc677633e06cac7dfddf2c3a61cbf2 Mon Sep 17 00:00:00 2001 From: karl-qdh Date: Wed, 30 Mar 2011 15:02:28 +0100 Subject: Move start timer into an idle so we have a chance to actually create the menu items --- src/datetime-service.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/datetime-service.c b/src/datetime-service.c index 36a9a73..863bc9e 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -410,7 +410,7 @@ check_for_calendar (gpointer user_data) if (g_settings_get_boolean(conf, SETTINGS_SHOW_EVENTS_S)) { dbusmenu_menuitem_property_set_bool(add_appointment, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE); dbusmenu_menuitem_property_set_bool(events_separator, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE); - start_ecal_timer(); + g_idle_add(start_ecal_timer, NULL); } else { dbusmenu_menuitem_property_set_bool(add_appointment, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE); dbusmenu_menuitem_property_set_bool(events_separator, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE); -- cgit v1.2.3 From afdaa937487ff3db6077d851132ea7ae2353bf0f Mon Sep 17 00:00:00 2001 From: karl-qdh Date: Wed, 30 Mar 2011 15:57:26 +0100 Subject: Potential fix for suspend issue suggested by njpatel --- src/datetime-service.c | 8 +++++++- src/indicator-datetime.c | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/src/datetime-service.c b/src/datetime-service.c index 863bc9e..e284418 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -353,6 +353,12 @@ stop_ecal_timer(void) { if (ecaltimer != 0) g_source_remove(ecaltimer); } +static gboolean +idle_start_ecal_timer (gpointer data) +{ + start_ecal_timer(); + return FALSE; +} static void show_events_changed (void) @@ -410,7 +416,7 @@ check_for_calendar (gpointer user_data) if (g_settings_get_boolean(conf, SETTINGS_SHOW_EVENTS_S)) { dbusmenu_menuitem_property_set_bool(add_appointment, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE); dbusmenu_menuitem_property_set_bool(events_separator, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE); - g_idle_add(start_ecal_timer, NULL); + g_idle_add((GSourceFunc)idle_start_ecal_timer, NULL); } else { dbusmenu_menuitem_property_set_bool(add_appointment, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE); dbusmenu_menuitem_property_set_bool(events_separator, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE); diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c index ef3a857..e55bfa0 100644 --- a/src/indicator-datetime.c +++ b/src/indicator-datetime.c @@ -169,7 +169,9 @@ static void update_label (IndicatorDatetime * io, GDateTime ** static void guess_label_size (IndicatorDatetime * self); static void setup_timer (IndicatorDatetime * self, GDateTime * datetime); static void update_time (IndicatorDatetime * self); +static void session_active_change_cb (GDBusProxy * proxy, gchar * sender_name, gchar * signal_name, GVariant * parameters, gpointer user_data); static void receive_signal (GDBusProxy * proxy, gchar * sender_name, gchar * signal_name, GVariant * parameters, gpointer user_data); +static void system_proxy_cb (GObject * object, GAsyncResult * res, gpointer user_data); static void service_proxy_cb (GObject * object, GAsyncResult * res, gpointer user_data); static gint generate_strftime_bitmask (const char *time_str); static void timezone_update_labels (indicator_item_t * mi_data); @@ -352,8 +354,34 @@ indicator_datetime_init (IndicatorDatetime *self) service_proxy_cb, self); + g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM, + G_DBUS_PROXY_FLAGS_NONE, + NULL, + "org.freedesktop.ConsoleKit", + "/org/freedesktop/ConsoleKit/Manager", + "org.freedesktop.ConsoleKit.Manager", + NULL, system_proxy_cb, self); return; } +/* for hooking into console kit signal on wake from suspend */ +static void +system_proxy_cb (GObject * object, GAsyncResult * res, gpointer user_data) +{ + GError * error = NULL; + + IndicatorDatetime * self = INDICATOR_DATETIME(user_data); + g_return_if_fail(self != NULL); + + GDBusProxy * proxy = g_dbus_proxy_new_for_bus_finish(res, &error); + + if (error != NULL) { + g_warning("Could not grab DBus proxy for %s: %s", SERVICE_NAME, error->message); + g_error_free(error); + return; + } + g_signal_connect(proxy, "g-signal::ActiveChanged", G_CALLBACK(session_active_change_cb), self); + +} /* Callback from trying to create the proxy for the serivce, this could include starting the service. Sometime it'll fail and @@ -772,6 +800,16 @@ update_time (IndicatorDatetime * self) return; } +static void +session_active_change_cb (GDBusProxy * proxy, gchar * sender_name, gchar * signal_name, + GVariant * parameters, gpointer user_data) +{ + // Just returned from suspend + IndicatorDatetime * self = INDICATOR_DATETIME(user_data); + update_time(self); + return; +} + /* Receives all signals from the service, routed to the appropriate functions */ static void receive_signal (GDBusProxy * proxy, gchar * sender_name, gchar * signal_name, -- cgit v1.2.3 From f8923be6312878885431503e0ee372b1e11676ea Mon Sep 17 00:00:00 2001 From: karl-qdh Date: Wed, 30 Mar 2011 16:02:50 +0100 Subject: Might not like that signal notation --- src/indicator-datetime.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c index e55bfa0..addc2c2 100644 --- a/src/indicator-datetime.c +++ b/src/indicator-datetime.c @@ -379,7 +379,7 @@ system_proxy_cb (GObject * object, GAsyncResult * res, gpointer user_data) g_error_free(error); return; } - g_signal_connect(proxy, "g-signal::ActiveChanged", G_CALLBACK(session_active_change_cb), self); + g_signal_connect(proxy, "g-signal", G_CALLBACK(session_active_change_cb), self); } @@ -806,7 +806,9 @@ session_active_change_cb (GDBusProxy * proxy, gchar * sender_name, gchar * signa { // Just returned from suspend IndicatorDatetime * self = INDICATOR_DATETIME(user_data); - update_time(self); + if (g_strcmp0(signal_name, "ActiveChanged") == 0) { + update_time(self); + } return; } -- cgit v1.2.3 From fb7e5a07951216e5771614b92f4a49f57807b337 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 30 Mar 2011 10:29:58 -0500 Subject: Switching to one variable with all the marks in it --- src/datetime-service.c | 2 +- src/dbus-shared.h | 4 +--- src/indicator-datetime.c | 15 +-------------- 3 files changed, 3 insertions(+), 18 deletions(-) diff --git a/src/datetime-service.c b/src/datetime-service.c index e284418..ef67d85 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -860,7 +860,7 @@ update_appointment_menu_items (gpointer user_data) g_list_free(sorted_comp_instances); GVariant * marks = g_variant_builder_end (&markeddays); - dbusmenu_menuitem_property_set_variant (calendar, CALENDAR_MENUITEM_PROP_MARK, marks); + dbusmenu_menuitem_property_set_variant (calendar, CALENDAR_MENUITEM_PROP_MARKS, marks); updating_appointments = FALSE; g_debug("End of objects"); diff --git a/src/dbus-shared.h b/src/dbus-shared.h index 8b1a20b..51632f9 100644 --- a/src/dbus-shared.h +++ b/src/dbus-shared.h @@ -31,9 +31,7 @@ with this program. If not, see . // The following properties are not *really* properties, but are just // a way of accessing the calendar from the service -#define CALENDAR_MENUITEM_PROP_MARK "calendar-mark" -#define CALENDAR_MENUITEM_PROP_UNMARK "calendar-unmark" -#define CALENDAR_MENUITEM_PROP_CLEAR_MARKS "calendar-clear-marks" +#define CALENDAR_MENUITEM_PROP_MARKS "calendar-marks" #define CALENDAR_MENUITEM_PROP_SET_DATE "calendar-set-date" diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c index e55bfa0..b6b8885 100644 --- a/src/indicator-datetime.c +++ b/src/indicator-datetime.c @@ -1192,7 +1192,7 @@ static void calendar_prop_change_cb (DbusmenuMenuitem * mi, gchar * prop, GVariant *value, IdoCalendarMenuItem * mi_data) { g_debug("Changing calendar property"); - if (!g_strcmp0(prop, CALENDAR_MENUITEM_PROP_MARK)) { + if (!g_strcmp0(prop, CALENDAR_MENUITEM_PROP_MARKS)) { ido_calendar_menu_item_clear_marks (IDO_CALENDAR_MENU_ITEM (mi_data)); g_debug("Marks: Cleared"); GVariantIter *iter; @@ -1204,19 +1204,6 @@ calendar_prop_change_cb (DbusmenuMenuitem * mi, gchar * prop, GVariant *value, I g_debug("Marks: Marked day: %d", day); } g_variant_iter_free (iter); - } else if (!g_strcmp0(prop, CALENDAR_MENUITEM_PROP_UNMARK)) { - GVariantIter *iter; - gint day; - - g_variant_get (value, "ai", &iter); - while (g_variant_iter_loop (iter, "i", &day)) { - g_debug("Unmarked day: %d", day); - ido_calendar_menu_item_unmark_day (IDO_CALENDAR_MENU_ITEM (mi_data), day); - } - g_variant_iter_free (iter); - } else if (!g_strcmp0(prop, CALENDAR_MENUITEM_PROP_CLEAR_MARKS)) { - ido_calendar_menu_item_clear_marks (IDO_CALENDAR_MENU_ITEM (mi_data)); - g_debug("Cleared Marks"); } else if (!g_strcmp0(prop, CALENDAR_MENUITEM_PROP_SET_DATE)) { gsize size = 3; const gint * array = g_variant_get_fixed_array(value, &size, sizeof(gint)); -- cgit v1.2.3 From b7c7b708126be12a4c73f14a7017c8118f99e10e Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 30 Mar 2011 10:34:58 -0500 Subject: Some debugging info --- src/indicator-datetime.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c index b6b8885..707dd24 100644 --- a/src/indicator-datetime.c +++ b/src/indicator-datetime.c @@ -1191,7 +1191,7 @@ indicator_prop_change_cb (DbusmenuMenuitem * mi, gchar * prop, GVariant *value, static void calendar_prop_change_cb (DbusmenuMenuitem * mi, gchar * prop, GVariant *value, IdoCalendarMenuItem * mi_data) { - g_debug("Changing calendar property"); + g_debug("Changing calendar property: %s", prop); if (!g_strcmp0(prop, CALENDAR_MENUITEM_PROP_MARKS)) { ido_calendar_menu_item_clear_marks (IDO_CALENDAR_MENU_ITEM (mi_data)); g_debug("Marks: Cleared"); @@ -1350,6 +1350,7 @@ new_calendar_item (DbusmenuMenuitem * newitem, DbusmenuClient * client, gpointer user_data) { + g_debug("New calendar item"); g_return_val_if_fail(DBUSMENU_IS_MENUITEM(newitem), FALSE); g_return_val_if_fail(DBUSMENU_IS_GTKCLIENT(client), FALSE); /* Note: not checking parent, it's reasonable for it to be NULL */ -- cgit v1.2.3 From ce0945b155b33f862904fa4a8c05b8f4cd119ece Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 30 Mar 2011 10:43:05 -0500 Subject: Making sure to get the inital values of the calendar properties --- src/indicator-datetime.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c index 707dd24..1bd1916 100644 --- a/src/indicator-datetime.c +++ b/src/indicator-datetime.c @@ -1377,11 +1377,26 @@ new_calendar_item (DbusmenuMenuitem * newitem, gtk_widget_set_visible (GTK_WIDGET (self->priv->ido_calendar), self->priv->show_calendar); dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), newitem, GTK_MENU_ITEM(ido), parent); + g_signal_connect_after(ido, "month-changed", G_CALLBACK(month_changed_cb), (gpointer)newitem); g_signal_connect_after(ido, "day-selected", G_CALLBACK(day_selected_cb), (gpointer)newitem); g_signal_connect_after(ido, "day-selected-double-click", G_CALLBACK(day_selected_double_click_cb), (gpointer)newitem); g_signal_connect(G_OBJECT(newitem), DBUSMENU_MENUITEM_SIGNAL_PROPERTY_CHANGED, G_CALLBACK(calendar_prop_change_cb), ido); + + /* Run the current values through prop changed */ + GVariant * propval = NULL; + + propval = dbusmenu_menuitem_property_get_variant(newitem, CALENDAR_MENUITEM_PROP_MARKS); + if (propval != NULL) { + calendar_prop_change_cb(newitem, CALENDAR_MENUITEM_PROP_MARKS, propval, ido); + } + + propval = dbusmenu_menuitem_property_get_variant(newitem, CALENDAR_MENUITEM_PROP_SET_DATE); + if (propval != NULL) { + calendar_prop_change_cb(newitem, CALENDAR_MENUITEM_PROP_SET_DATE, propval, ido); + } + return TRUE; } -- cgit v1.2.3 From 8e1ab0d64a937669c7e9361e7e0942c4c8099358 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 30 Mar 2011 10:54:47 -0500 Subject: Making the right size group more real to remove an annoying error --- src/indicator-datetime.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c index 1bd1916..7b6695c 100644 --- a/src/indicator-datetime.c +++ b/src/indicator-datetime.c @@ -101,6 +101,8 @@ struct _IndicatorDatetimePrivate { GList * timezone_items; GSettings * settings; + + GtkSizeGroup * indicator_right_group; }; /* Enum for the properties so that they can be quickly @@ -182,8 +184,6 @@ INDICATOR_SET_TYPE(INDICATOR_DATETIME_TYPE) G_DEFINE_TYPE (IndicatorDatetime, indicator_datetime, INDICATOR_OBJECT_TYPE); -static GtkSizeGroup * indicator_right_group = NULL; - static void indicator_datetime_class_init (IndicatorDatetimeClass *klass) { @@ -341,6 +341,7 @@ indicator_datetime_init (IndicatorDatetime *self) } self->priv->sm = indicator_service_manager_new_version(SERVICE_NAME, SERVICE_VERSION); + self->priv->indicator_right_group = GTK_SIZE_GROUP(gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL)); self->priv->service_proxy_cancel = g_cancellable_new(); @@ -458,6 +459,11 @@ indicator_datetime_dispose (GObject *object) self->priv->service_proxy = NULL; } + if (self->priv->indicator_right_group != NULL) { + g_object_unref(G_OBJECT(self->priv->indicator_right_group)); + self->priv->indicator_right_group = NULL; + } + G_OBJECT_CLASS (indicator_datetime_parent_class)->dispose (object); return; } @@ -1226,7 +1232,9 @@ new_appointment_item (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, Dbu { g_return_val_if_fail(DBUSMENU_IS_MENUITEM(newitem), FALSE); g_return_val_if_fail(DBUSMENU_IS_GTKCLIENT(client), FALSE); + g_return_val_if_fail(IS_INDICATOR_DATETIME(user_data), FALSE); /* Note: not checking parent, it's reasonable for it to be NULL */ + IndicatorDatetime * self = INDICATOR_DATETIME(user_data); indicator_item_t * mi_data = g_new0(indicator_item_t, 1); @@ -1276,7 +1284,7 @@ new_appointment_item (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, Dbu /* Usually either the time or the count on the individual item. */ mi_data->right = gtk_label_new(dbusmenu_menuitem_property_get(newitem, APPOINTMENT_MENUITEM_PROP_RIGHT)); - gtk_size_group_add_widget(indicator_right_group, mi_data->right); + gtk_size_group_add_widget(self->priv->indicator_right_group, mi_data->right); gtk_misc_set_alignment(GTK_MISC(mi_data->right), 1.0, 0.5); gtk_box_pack_start(GTK_BOX(hbox), mi_data->right, FALSE, FALSE, 0); gtk_widget_show(mi_data->right); @@ -1426,15 +1434,10 @@ new_timezone_item(DbusmenuMenuitem * newitem, { g_return_val_if_fail(DBUSMENU_IS_MENUITEM(newitem), FALSE); g_return_val_if_fail(DBUSMENU_IS_GTKCLIENT(client), FALSE); + g_return_val_if_fail(IS_INDICATOR_DATETIME(user_data), FALSE); /* Note: not checking parent, it's reasonable for it to be NULL */ - - IndicatorObject *io = g_object_get_data (G_OBJECT (client), "indicator"); - if (io == NULL) { - g_warning ("found no indicator to attach the timezone to"); - return FALSE; - } - IndicatorDatetime *self = INDICATOR_DATETIME(io); + IndicatorDatetime * self = INDICATOR_DATETIME(user_data); IndicatorDatetimePrivate *priv = INDICATOR_DATETIME_GET_PRIVATE(self); // Menu item with a radio button and a right aligned time @@ -1461,7 +1464,7 @@ new_timezone_item(DbusmenuMenuitem * newitem, /* Usually either the time or the count on the individual item. */ mi_data->right = gtk_label_new(""); - gtk_size_group_add_widget(indicator_right_group, mi_data->right); + gtk_size_group_add_widget(self->priv->indicator_right_group, mi_data->right); gtk_misc_set_alignment(GTK_MISC(mi_data->right), 1.0, 0.5); gtk_box_pack_start(GTK_BOX(hbox), mi_data->right, FALSE, FALSE, 0); gtk_widget_show(mi_data->right); @@ -1518,9 +1521,9 @@ get_menu (IndicatorObject * io) DbusmenuGtkClient *client = dbusmenu_gtkmenu_get_client(self->priv->menu); g_object_set_data (G_OBJECT (client), "indicator", io); - dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(client), DBUSMENU_CALENDAR_MENUITEM_TYPE, new_calendar_item); - dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(client), APPOINTMENT_MENUITEM_TYPE, new_appointment_item); - dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(client), TIMEZONE_MENUITEM_TYPE, new_timezone_item); + dbusmenu_client_add_type_handler_full(DBUSMENU_CLIENT(client), DBUSMENU_CALENDAR_MENUITEM_TYPE, new_calendar_item, io, NULL); + dbusmenu_client_add_type_handler_full(DBUSMENU_CLIENT(client), APPOINTMENT_MENUITEM_TYPE, new_appointment_item, io, NULL); + dbusmenu_client_add_type_handler_full(DBUSMENU_CLIENT(client), TIMEZONE_MENUITEM_TYPE, new_timezone_item, io, NULL); return GTK_MENU(self->priv->menu); } -- cgit v1.2.3 From 073715557f637c7cd87c906718d99a3c682f7e5f Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 30 Mar 2011 10:57:02 -0500 Subject: Cleaning up debug output --- src/indicator-datetime.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c index 7b6695c..5d35c59 100644 --- a/src/indicator-datetime.c +++ b/src/indicator-datetime.c @@ -1200,14 +1200,14 @@ calendar_prop_change_cb (DbusmenuMenuitem * mi, gchar * prop, GVariant *value, I g_debug("Changing calendar property: %s", prop); if (!g_strcmp0(prop, CALENDAR_MENUITEM_PROP_MARKS)) { ido_calendar_menu_item_clear_marks (IDO_CALENDAR_MENU_ITEM (mi_data)); - g_debug("Marks: Cleared"); GVariantIter *iter; gint day; + g_debug("\tMarks: %s", g_variant_print(value, FALSE)); + g_variant_get (value, "ai", &iter); while (g_variant_iter_loop (iter, "i", &day)) { ido_calendar_menu_item_mark_day (IDO_CALENDAR_MENU_ITEM (mi_data), day); - g_debug("Marks: Marked day: %d", day); } g_variant_iter_free (iter); } else if (!g_strcmp0(prop, CALENDAR_MENUITEM_PROP_SET_DATE)) { -- cgit v1.2.3 From fbd5c581cc7f8ca4bc7386f6957b5c41e3d266cf Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 30 Mar 2011 10:58:17 -0500 Subject: Protecting against NULL values --- src/indicator-datetime.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c index 5d35c59..c96ec48 100644 --- a/src/indicator-datetime.c +++ b/src/indicator-datetime.c @@ -1200,21 +1200,28 @@ calendar_prop_change_cb (DbusmenuMenuitem * mi, gchar * prop, GVariant *value, I g_debug("Changing calendar property: %s", prop); if (!g_strcmp0(prop, CALENDAR_MENUITEM_PROP_MARKS)) { ido_calendar_menu_item_clear_marks (IDO_CALENDAR_MENU_ITEM (mi_data)); - GVariantIter *iter; - gint day; - g_debug("\tMarks: %s", g_variant_print(value, FALSE)); + if (value != NULL) { + GVariantIter *iter; + gint day; - g_variant_get (value, "ai", &iter); - while (g_variant_iter_loop (iter, "i", &day)) { - ido_calendar_menu_item_mark_day (IDO_CALENDAR_MENU_ITEM (mi_data), day); + g_debug("\tMarks: %s", g_variant_print(value, FALSE)); + + g_variant_get (value, "ai", &iter); + while (g_variant_iter_loop (iter, "i", &day)) { + ido_calendar_menu_item_mark_day (IDO_CALENDAR_MENU_ITEM (mi_data), day); + } + g_variant_iter_free (iter); + } else { + g_debug("\tMarks: "); } - g_variant_iter_free (iter); } else if (!g_strcmp0(prop, CALENDAR_MENUITEM_PROP_SET_DATE)) { - gsize size = 3; - const gint * array = g_variant_get_fixed_array(value, &size, sizeof(gint)); - g_debug("Setting date y-m-d: %d-%d-%d", array[0], array[1], array[2]); - ido_calendar_menu_item_set_date (IDO_CALENDAR_MENU_ITEM (mi_data), array[0], array[1], array[2]); + if (value != NULL) { + gsize size = 3; + const gint * array = g_variant_get_fixed_array(value, &size, sizeof(gint)); + g_debug("Setting date y-m-d: %d-%d-%d", array[0], array[1], array[2]); + ido_calendar_menu_item_set_date (IDO_CALENDAR_MENU_ITEM (mi_data), array[0], array[1], array[2]); + } } else { g_warning("Indicator Item property '%s' unknown", prop); } -- cgit v1.2.3 From 88d10f2b5102676f9498a700ef290b42953664f1 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 30 Mar 2011 11:03:51 -0500 Subject: Clear marks on month changes --- src/datetime-service.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/datetime-service.c b/src/datetime-service.c index ef67d85..6042e94 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -281,6 +281,11 @@ month_changed_cb (DbusmenuMenuitem * menuitem, gchar *name, GVariant *variant, g start_time_appointments = (time_t)g_variant_get_uint32(variant); g_debug("Received month changed with timestamp: %d -> %s",(int)start_time_appointments, ctime(&start_time_appointments)); + /* By default one of the first things we do is + clear the marks as we don't know the correct + ones yet and we don't want to confuse the + user. */ + dbusmenu_menuitem_property_remove(menuitem, CALENDAR_MENUITEM_PROP_MARKS); update_appointment_menu_items(NULL); return TRUE; } -- cgit v1.2.3 From 0e435a010c1350df7de029725ba9e721d543ccf5 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 30 Mar 2011 11:25:45 -0500 Subject: Update the appointments in the idle loop so we can get those signals returned promptly! --- src/datetime-service.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/datetime-service.c b/src/datetime-service.c index 6042e94..6820bb9 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -275,6 +275,13 @@ activate_cb (DbusmenuMenuitem * menuitem, guint timestamp, const gchar *command) } } +static gboolean +update_appointment_menu_items_idle (gpointer user_data) +{ + update_appointment_menu_items(user_data); + return FALSE; +} + static gboolean month_changed_cb (DbusmenuMenuitem * menuitem, gchar *name, GVariant *variant, guint timestamp) { @@ -286,7 +293,7 @@ month_changed_cb (DbusmenuMenuitem * menuitem, gchar *name, GVariant *variant, g ones yet and we don't want to confuse the user. */ dbusmenu_menuitem_property_remove(menuitem, CALENDAR_MENUITEM_PROP_MARKS); - update_appointment_menu_items(NULL); + g_idle_add(update_appointment_menu_items_idle, NULL); return TRUE; } @@ -296,7 +303,7 @@ day_selected_cb (DbusmenuMenuitem * menuitem, gchar *name, GVariant *variant, gu start_time_appointments = (time_t)g_variant_get_uint32(variant); g_debug("Received day-selected with timestamp: %d -> %s",(int)start_time_appointments, ctime(&start_time_appointments)); - update_appointment_menu_items(NULL); + g_idle_add(update_appointment_menu_items_idle, NULL); return TRUE; } -- cgit v1.2.3 From 6be8ddada1ca8b9901d7b9dccef39af47230bf32 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 30 Mar 2011 13:21:10 -0500 Subject: Moving the registration of the type handlers into the init so that they'll not execute more than once. --- src/indicator-datetime.c | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c index c96ec48..1e8b452 100644 --- a/src/indicator-datetime.c +++ b/src/indicator-datetime.c @@ -177,6 +177,9 @@ static void system_proxy_cb (GObject * object, GAsyncResult * res, gpointer use static void service_proxy_cb (GObject * object, GAsyncResult * res, gpointer user_data); static gint generate_strftime_bitmask (const char *time_str); static void timezone_update_labels (indicator_item_t * mi_data); +static gboolean new_calendar_item (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client, gpointer user_data); +static gboolean new_appointment_item (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client, gpointer user_data); +static gboolean new_timezone_item (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client, gpointer user_data); /* Indicator Module Config */ INDICATOR_SET_VERSION @@ -343,6 +346,13 @@ indicator_datetime_init (IndicatorDatetime *self) self->priv->sm = indicator_service_manager_new_version(SERVICE_NAME, SERVICE_VERSION); self->priv->indicator_right_group = GTK_SIZE_GROUP(gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL)); + self->priv->menu = dbusmenu_gtkmenu_new(SERVICE_NAME, MENU_OBJ); + + DbusmenuGtkClient *client = dbusmenu_gtkmenu_get_client(self->priv->menu); + dbusmenu_client_add_type_handler_full(DBUSMENU_CLIENT(client), DBUSMENU_CALENDAR_MENUITEM_TYPE, new_calendar_item, self, NULL); + dbusmenu_client_add_type_handler_full(DBUSMENU_CLIENT(client), APPOINTMENT_MENUITEM_TYPE, new_appointment_item, self, NULL); + dbusmenu_client_add_type_handler_full(DBUSMENU_CLIENT(client), TIMEZONE_MENUITEM_TYPE, new_timezone_item, self, NULL); + self->priv->service_proxy_cancel = g_cancellable_new(); g_dbus_proxy_new_for_bus (G_BUS_TYPE_SESSION, @@ -1368,15 +1378,10 @@ new_calendar_item (DbusmenuMenuitem * newitem, g_debug("New calendar item"); g_return_val_if_fail(DBUSMENU_IS_MENUITEM(newitem), FALSE); g_return_val_if_fail(DBUSMENU_IS_GTKCLIENT(client), FALSE); + g_return_val_if_fail(IS_INDICATOR_DATETIME(user_data), FALSE); /* Note: not checking parent, it's reasonable for it to be NULL */ - IndicatorObject *io = g_object_get_data (G_OBJECT (client), "indicator"); - if (io == NULL) { - g_warning ("found no indicator to attach the caledar to"); - return FALSE; - } - - IndicatorDatetime *self = INDICATOR_DATETIME(io); + IndicatorDatetime *self = INDICATOR_DATETIME(user_data); self->priv = INDICATOR_DATETIME_GET_PRIVATE(self); IdoCalendarMenuItem *ido = IDO_CALENDAR_MENU_ITEM (ido_calendar_menu_item_new ()); @@ -1521,17 +1526,6 @@ get_menu (IndicatorObject * io) { IndicatorDatetime * self = INDICATOR_DATETIME(io); - if (self->priv->menu == NULL) { - self->priv->menu = dbusmenu_gtkmenu_new(SERVICE_NAME, MENU_OBJ); - } - - DbusmenuGtkClient *client = dbusmenu_gtkmenu_get_client(self->priv->menu); - g_object_set_data (G_OBJECT (client), "indicator", io); - - dbusmenu_client_add_type_handler_full(DBUSMENU_CLIENT(client), DBUSMENU_CALENDAR_MENUITEM_TYPE, new_calendar_item, io, NULL); - dbusmenu_client_add_type_handler_full(DBUSMENU_CLIENT(client), APPOINTMENT_MENUITEM_TYPE, new_appointment_item, io, NULL); - dbusmenu_client_add_type_handler_full(DBUSMENU_CLIENT(client), TIMEZONE_MENUITEM_TYPE, new_timezone_item, io, NULL); - return GTK_MENU(self->priv->menu); } -- cgit v1.2.3 From b9355e5f0e32e04c93158e962e985f60abfbb35b Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 30 Mar 2011 13:23:49 -0500 Subject: Check for the signal name in the handler --- src/indicator-datetime.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c index 1e8b452..222844e 100644 --- a/src/indicator-datetime.c +++ b/src/indicator-datetime.c @@ -390,7 +390,7 @@ system_proxy_cb (GObject * object, GAsyncResult * res, gpointer user_data) g_error_free(error); return; } - g_signal_connect(proxy, "g-signal::ActiveChanged", G_CALLBACK(session_active_change_cb), self); + g_signal_connect(proxy, "g-signal", G_CALLBACK(session_active_change_cb), self); } @@ -820,9 +820,11 @@ static void session_active_change_cb (GDBusProxy * proxy, gchar * sender_name, gchar * signal_name, GVariant * parameters, gpointer user_data) { - // Just returned from suspend - IndicatorDatetime * self = INDICATOR_DATETIME(user_data); - update_time(self); + if (g_strcmp0(signal_name, "ActiveChanged") == 0) { + // Just returned from suspend + IndicatorDatetime * self = INDICATOR_DATETIME(user_data); + update_time(self); + } return; } -- cgit v1.2.3 From c0166121f74d4d0552f1241a8bc42f380cfbd662 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 30 Mar 2011 13:32:31 -0500 Subject: Protecting against the widgets being NULL at startup --- src/indicator-datetime.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c index 222844e..cafcf1f 100644 --- a/src/indicator-datetime.c +++ b/src/indicator-datetime.c @@ -556,7 +556,9 @@ set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec case PROP_SHOW_CLOCK: { if (g_value_get_boolean(value) != self->priv->show_clock) { self->priv->show_clock = g_value_get_boolean(value); - gtk_widget_set_visible (GTK_WIDGET (self->priv->label), self->priv->show_clock); + if (self->priv->label != NULL) { + gtk_widget_set_visible (GTK_WIDGET (self->priv->label), self->priv->show_clock); + } } break; } @@ -626,7 +628,9 @@ set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec case PROP_SHOW_CALENDAR: { if (g_value_get_boolean(value) != self->priv->show_calendar) { self->priv->show_calendar = g_value_get_boolean(value); - gtk_widget_set_visible (GTK_WIDGET (self->priv->ido_calendar), self->priv->show_calendar); + if (self->priv->ido_calendar != NULL) { + gtk_widget_set_visible (GTK_WIDGET (self->priv->ido_calendar), self->priv->show_calendar); + } } break; } -- cgit v1.2.3 From 49ffaa6c41cee3855f5101cdbe0220e225f59ac0 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 30 Mar 2011 14:44:28 -0500 Subject: Ensure that the marks get cleared on day changes that go across monthly boundries as well --- src/datetime-service.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/datetime-service.c b/src/datetime-service.c index 6820bb9..85139ed 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -300,10 +300,33 @@ month_changed_cb (DbusmenuMenuitem * menuitem, gchar *name, GVariant *variant, g static gboolean day_selected_cb (DbusmenuMenuitem * menuitem, gchar *name, GVariant *variant, guint timestamp) { - start_time_appointments = (time_t)g_variant_get_uint32(variant); - + time_t new_time = (time_t)g_variant_get_uint32(variant); + g_warn_if_fail(new_time != 0); + + if (start_time_appointments == 0 || new_time == 0) { + /* If we've got nothing, assume everyhting is going to + get repopulated, let's start with a clean slate */ + dbusmenu_menuitem_property_remove(menuitem, CALENDAR_MENUITEM_PROP_MARKS); + } else { + /* No check to see if we changed months. If we did we'll + want to clear the marks. Otherwise we're cool keeping + them around. */ + struct tm start_tm; + struct tm new_tm; + + localtime_r(&start_time_appointments, &start_tm); + localtime_r(&new_time, &new_tm); + + if (start_tm.tm_mon != new_tm.tm_mon) { + dbusmenu_menuitem_property_remove(menuitem, CALENDAR_MENUITEM_PROP_MARKS); + } + } + + start_time_appointments = new_time; + g_debug("Received day-selected with timestamp: %d -> %s",(int)start_time_appointments, ctime(&start_time_appointments)); g_idle_add(update_appointment_menu_items_idle, NULL); + return TRUE; } -- cgit v1.2.3 From cdf13963033711cd14d01e1a47958f861f6ff21d Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 30 Mar 2011 14:49:07 -0500 Subject: Disable the appointments on date or month change to make it show that they're being updated and aren't currently valid --- src/datetime-service.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/datetime-service.c b/src/datetime-service.c index 85139ed..91e9d81 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -293,6 +293,13 @@ month_changed_cb (DbusmenuMenuitem * menuitem, gchar *name, GVariant *variant, g ones yet and we don't want to confuse the user. */ dbusmenu_menuitem_property_remove(menuitem, CALENDAR_MENUITEM_PROP_MARKS); + + GList * appointment; + for (appointment = appointments; appointment != NULL; appointment = g_list_next(appointment)) { + DbusmenuMenuitem * mi = DBUSMENU_MENUITEM(appointment->data); + dbusmenu_menuitem_property_set_bool(mi, DBUSMENU_MENUITEM_PROP_ENABLED, FALSE); + } + g_idle_add(update_appointment_menu_items_idle, NULL); return TRUE; } @@ -322,6 +329,12 @@ day_selected_cb (DbusmenuMenuitem * menuitem, gchar *name, GVariant *variant, gu } } + GList * appointment; + for (appointment = appointments; appointment != NULL; appointment = g_list_next(appointment)) { + DbusmenuMenuitem * mi = DBUSMENU_MENUITEM(appointment->data); + dbusmenu_menuitem_property_set_bool(mi, DBUSMENU_MENUITEM_PROP_ENABLED, FALSE); + } + start_time_appointments = new_time; g_debug("Received day-selected with timestamp: %d -> %s",(int)start_time_appointments, ctime(&start_time_appointments)); -- cgit v1.2.3 From d331e3005e9c3d00709f146ccd2e32f6f2a2c82d Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 30 Mar 2011 15:10:41 -0500 Subject: Changing code to recycle the appointment menu items for a cleaner switching of days --- src/datetime-service.c | 55 +++++++++++++++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 21 deletions(-) diff --git a/src/datetime-service.c b/src/datetime-service.c index 91e9d81..fb3b89f 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -420,14 +420,13 @@ show_events_changed (void) dbusmenu_menuitem_property_set_bool(events_separator, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE); /* Remove all of the previous appointments */ if (appointments != NULL) { - g_debug("Freeing old appointments"); - while (appointments != NULL) { - DbusmenuMenuitem * litem = DBUSMENU_MENUITEM(appointments->data); - g_debug("Freeing old appointment: %p", litem); + g_debug("Hiding old appointments"); + GList * appointment; + for (appointment = appointments; appointment != NULL; appointment = g_list_next(appointment)) { + DbusmenuMenuitem * litem = DBUSMENU_MENUITEM(appointment->data); + g_debug("Hiding old appointment: %p", litem); // Remove all the existing menu items which are in appointments. - appointments = g_list_remove(appointments, litem); - dbusmenu_menuitem_child_delete(root, DBUSMENU_MENUITEM(litem)); - g_object_unref(G_OBJECT(litem)); + dbusmenu_menuitem_property_set_bool(DBUSMENU_MENUITEM(litem), DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE); } } stop_ecal_timer(); @@ -725,16 +724,15 @@ update_appointment_menu_items (gpointer user_data) comp_instances = NULL; g_debug("Components sorted"); - /* Remove all of the previous appointments */ + /* Hiding all of the previous appointments */ if (appointments != NULL) { - g_debug("Freeing old appointments"); - while (appointments != NULL) { - DbusmenuMenuitem * litem = DBUSMENU_MENUITEM(appointments->data); - g_debug("Freeing old appointment: %p", litem); + g_debug("Hiding old appointments"); + GList * appointment; + for (appointment = appointments; appointment != NULL; appointment = g_list_next(appointment)) { + DbusmenuMenuitem * litem = DBUSMENU_MENUITEM(appointment->data); + g_debug("Hiding old appointment: %p", litem); // Remove all the existing menu items which are in appointments. - appointments = g_list_remove(appointments, litem); - dbusmenu_menuitem_child_delete(root, DBUSMENU_MENUITEM(litem)); - g_object_unref(G_OBJECT(litem)); + dbusmenu_menuitem_property_set_bool(DBUSMENU_MENUITEM(litem), DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE); } } @@ -758,6 +756,7 @@ update_appointment_menu_items (gpointer user_data) g_variant_builder_init (&markeddays, G_VARIANT_TYPE_ARRAY); i = 0; + GList * cached_appointment = appointments; for (l = sorted_comp_instances; l; l = l->next) { struct comp_instance *ci = l->data; ECalComponent *ecalcomp = ci->comp; @@ -792,12 +791,28 @@ update_appointment_menu_items (gpointer user_data) if (i >= 5) continue; i++; - g_debug("Create menu item"); - - item = dbusmenu_menuitem_new(); - dbusmenu_menuitem_property_set (item, DBUSMENU_MENUITEM_PROP_TYPE, APPOINTMENT_MENUITEM_TYPE); + if (cached_appointment == NULL) { + g_debug("Create menu item"); + + item = dbusmenu_menuitem_new(); + dbusmenu_menuitem_property_set (item, DBUSMENU_MENUITEM_PROP_TYPE, APPOINTMENT_MENUITEM_TYPE); + + dbusmenu_menuitem_child_add_position (root, item, 2+i); + appointments = g_list_append (appointments, item); // Keep track of the items here to make them easy to remove + } else { + item = DBUSMENU_MENUITEM(cached_appointment->data); + cached_appointment = g_list_next(cached_appointment); + + /* Remove the icon as we might not replace it on error */ + dbusmenu_menuitem_property_remove(item, APPOINTMENT_MENUITEM_PROP_ICON); + + /* Remove the activate handler */ + g_signal_handlers_disconnect_matched(G_OBJECT(item), G_SIGNAL_MATCH_FUNC, 0, 0, NULL, G_CALLBACK(activate_cb), NULL); + } + dbusmenu_menuitem_property_set_bool (item, DBUSMENU_MENUITEM_PROP_ENABLED, TRUE); dbusmenu_menuitem_property_set_bool (item, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE); + // Label text e_cal_component_get_summary (ecalcomp, &valuetext); @@ -895,8 +910,6 @@ update_appointment_menu_items (gpointer user_data) cairo_surface_destroy (surface); cairo_destroy(cr); } - dbusmenu_menuitem_child_add_position (root, item, 2+i); - appointments = g_list_append (appointments, item); // Keep track of the items here to make them easy to remove g_debug("Adding appointment: %p", item); } -- cgit v1.2.3 From b690f64445e81b5ce09f5b1eb7b56defb64bbba4 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 30 Mar 2011 16:06:05 -0500 Subject: Setting the default _WITH_DAY to be 12_WITH_DAY --- src/datetime-service.c | 2 +- src/settings-shared.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/datetime-service.c b/src/datetime-service.c index fb3b89f..5172eea 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -654,7 +654,7 @@ update_appointment_menu_items (gpointer user_data) const int mday = today->tm_mday; const int mon = today->tm_mon; const int year = today->tm_year; - + struct tm *start_tm = NULL; int this_year = today->tm_year + 1900; int days[12]={31,28,31,30,31,30,31,31,30,31,30,31}; diff --git a/src/settings-shared.h b/src/settings-shared.h index cdbb063..47ee6ef 100644 --- a/src/settings-shared.h +++ b/src/settings-shared.h @@ -51,7 +51,7 @@ enum { #define DEFAULT_TIME_24_FORMAT N_("%H:%M") #define DEFAULT_TIME_FORMAT DEFAULT_TIME_12_FORMAT -#define DEFAULT_TIME_FORMAT_WITH_DAY DEFAULT_TIME_12_FORMAT +#define DEFAULT_TIME_FORMAT_WITH_DAY DEFAULT_TIME_12_FORMAT_WITH_DAY /* TRANSLATORS: A format string for the strftime function for a clock showing the day of the week and the time in 12-hour format without -- cgit v1.2.3 From e8d074ffc39904e5095623c8c865e32a1fffecc8 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 30 Mar 2011 16:50:04 -0500 Subject: Be a bit smarter about handling the the locale --- src/datetime-service.c | 11 +++++------ src/settings-shared.h | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/datetime-service.c b/src/datetime-service.c index 5172eea..9eb26e8 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -749,7 +749,11 @@ update_appointment_menu_items (gpointer user_data) } else if (g_strcmp0(time_format_str, "24-hour") == 0) { apt_output = SETTINGS_TIME_24_HOUR; } else { - apt_output = SETTINGS_TIME_LOCALE; + if (is_locale_12h()) { + apt_output = SETTINGS_TIME_12_HOUR; + } else { + apt_output = SETTINGS_TIME_24_HOUR; + } } GVariantBuilder markeddays; @@ -833,11 +837,6 @@ update_appointment_menu_items (gpointer user_data) strftime(right, 20, _(DEFAULT_TIME_24_FORMAT), due); else strftime(right, 20, _(DEFAULT_TIME_24_FORMAT_WITH_DAY), due); - } else { - if ((mday == dmday) && (mon == dmon) && (year == dyear)) - strftime(right, 20, _(DEFAULT_TIME_FORMAT), due); - else - strftime(right, 20, _(DEFAULT_TIME_FORMAT_WITH_DAY), due); } g_debug("Appointment time: %s, for date %s", right, asctime(due)); dbusmenu_menuitem_property_set (item, APPOINTMENT_MENUITEM_PROP_RIGHT, right); diff --git a/src/settings-shared.h b/src/settings-shared.h index 47ee6ef..8c36ae3 100644 --- a/src/settings-shared.h +++ b/src/settings-shared.h @@ -50,7 +50,7 @@ enum { a clock showing 24-hour time without seconds. */ #define DEFAULT_TIME_24_FORMAT N_("%H:%M") -#define DEFAULT_TIME_FORMAT DEFAULT_TIME_12_FORMAT +#define DEFAULT_TIME_FORMAT DEFAULT_TIME_12_FORMAT #define DEFAULT_TIME_FORMAT_WITH_DAY DEFAULT_TIME_12_FORMAT_WITH_DAY /* TRANSLATORS: A format string for the strftime function for -- cgit v1.2.3 From 99044a57ae60b55336f8db18734d89be707c23a5 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 30 Mar 2011 16:52:03 -0500 Subject: Removing a warning that will occur on the default GTK properties --- src/indicator-datetime.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c index 3f9344d..d85b3fd 100644 --- a/src/indicator-datetime.c +++ b/src/indicator-datetime.c @@ -1204,8 +1204,6 @@ indicator_prop_change_cb (DbusmenuMenuitem * mi, gchar * prop, GVariant *value, timezone_update_labels(mi_data); } else if (!g_strcmp0(prop, TIMEZONE_MENUITEM_PROP_RADIO)) { gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(mi_data->gmi), g_variant_get_boolean(value)); - } else { - g_warning("Indicator Item property '%s' unknown", prop); } return; } @@ -1238,8 +1236,6 @@ calendar_prop_change_cb (DbusmenuMenuitem * mi, gchar * prop, GVariant *value, I g_debug("Setting date y-m-d: %d-%d-%d", array[0], array[1], array[2]); ido_calendar_menu_item_set_date (IDO_CALENDAR_MENU_ITEM (mi_data), array[0], array[1], array[2]); } - } else { - g_warning("Indicator Item property '%s' unknown", prop); } return; } -- cgit v1.2.3 From 00aca04c636009c8fffe8bba01d42c269d85464b Mon Sep 17 00:00:00 2001 From: karl-qdh Date: Thu, 31 Mar 2011 11:35:35 +0100 Subject: Switched to using SystemIdleHintChanged from ActiveState, appears ConsoleKit might have changed recently. --- src/indicator-datetime.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c index ec08f92..a999f42 100644 --- a/src/indicator-datetime.c +++ b/src/indicator-datetime.c @@ -830,7 +830,7 @@ session_active_change_cb (GDBusProxy * proxy, gchar * sender_name, gchar * signa { // Just returned from suspend IndicatorDatetime * self = INDICATOR_DATETIME(user_data); - if (g_strcmp0(signal_name, "ActiveChanged") == 0) { + if (g_strcmp0(signal_name, "SystemIdleHintChanged") == 0 && g_variant_get_boolean(parameters) == FALSE) { update_time(self); } return; -- cgit v1.2.3 From dc9ee534b96c6bea117fd5baafa67146e173aeb8 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 31 Mar 2011 14:25:28 -0500 Subject: 0.2.1 --- configure.ac | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index ef49e53..d1de2be 100644 --- a/configure.ac +++ b/configure.ac @@ -1,11 +1,11 @@ -AC_INIT(indicator-datetime, 0.2.0, ted@canonical.com) +AC_INIT(indicator-datetime, 0.2.1, ted@canonical.com) AC_COPYRIGHT([Copyright 2009,2010 Canonical]) AC_PREREQ(2.53) AM_CONFIG_HEADER(config.h) -AM_INIT_AUTOMAKE(indicator-datetime, 0.2.0) +AM_INIT_AUTOMAKE(indicator-datetime, 0.2.1) AM_MAINTAINER_MODE -- cgit v1.2.3