From ee7a2230388832443237d4da51d0b5cdc3545b19 Mon Sep 17 00:00:00 2001 From: karl-qdh Date: Mon, 11 Apr 2011 13:08:12 +0100 Subject: Make selection change on remove item --- src/datetime-prefs-locations.c | 70 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 69 insertions(+), 1 deletion(-) diff --git a/src/datetime-prefs-locations.c b/src/datetime-prefs-locations.c index 9c23a40..af0e10d 100644 --- a/src/datetime-prefs-locations.c +++ b/src/datetime-prefs-locations.c @@ -77,13 +77,81 @@ handle_remove (GtkWidget * button, GtkTreeView * tree) gtk_tree_path_free (iter->data); } g_list_free (paths); - + + // Find the next item to select + GtkTreeIter *last_selected = g_list_nth_data(tree_iters, 0); + GtkTreePath *path = gtk_tree_model_get_path(GTK_TREE_MODEL (store), last_selected); + GtkTreeIter titer; + if (!gtk_tree_model_get_iter(GTK_TREE_MODEL (store), &titer, path)) { + g_debug("Failed to get last selected iter from path"); + last_selected = NULL; + } else { + if (!gtk_tree_model_iter_next(GTK_TREE_MODEL (store), &titer)) { + if (gtk_tree_path_prev(path)) { + if (!gtk_tree_model_get_iter(GTK_TREE_MODEL (store), &titer, path)) { + g_debug("Failed to get iter from path"); + last_selected = NULL; + } else { + last_selected = &titer; + } + } else { + g_debug("handle_remove: Failed to find another location to select (assume single selected)"); + last_selected = NULL; + } + } else { + g_debug("Got next item in model"); + last_selected = &titer; + } + } + + if (last_selected) { + gboolean clear = TRUE; + path = gtk_tree_model_get_path(GTK_TREE_MODEL (store), last_selected); + + // Step over the path to find an item which isn't in the delete list + if (g_list_length(tree_iters) > 1) { + for (iter = tree_iters; iter; iter = iter->next) { + GtkTreePath *ipath = gtk_tree_model_get_path(GTK_TREE_MODEL (store), (GtkTreeIter *)iter->data); + if (gtk_tree_path_compare(path, ipath) == 0) { + clear = FALSE; + break; + } + } + while (clear == FALSE) { + if (gtk_tree_path_prev(path)) { + clear = TRUE; + for (iter = tree_iters; iter; iter = iter->next) { + GtkTreePath *ipath = gtk_tree_model_get_path(GTK_TREE_MODEL (store), (GtkTreeIter *)iter->data); + if (gtk_tree_path_compare(path, ipath) == 0) { + clear = FALSE; + break; + } + } + if (clear) { + if (!gtk_tree_model_get_iter(GTK_TREE_MODEL (store), &titer, path)) { + g_debug("Failed to get iter from path"); + last_selected = NULL; + } else { + last_selected = &titer; + } + } + } else { + last_selected = NULL; + break; + } + } + } + } + /* Now delete each iterator */ for (iter = tree_iters; iter; iter = iter->next) { gtk_list_store_remove (store, (GtkTreeIter *)iter->data); g_free (iter->data); } g_list_free (tree_iters); + + if (last_selected) + gtk_tree_selection_select_iter(selection, last_selected); } static void -- cgit v1.2.3 From 9e768e9751cd1705146f245d61dedc5d9f6147d5 Mon Sep 17 00:00:00 2001 From: karl-qdh Date: Mon, 11 Apr 2011 14:40:57 +0100 Subject: Calendar reset, should work for mike --- src/datetime-service.c | 25 ------------------------- src/dbus-shared.h | 4 ---- src/indicator-datetime.c | 31 ++++++++++++++++++++++++------- 3 files changed, 24 insertions(+), 36 deletions(-) diff --git a/src/datetime-service.c b/src/datetime-service.c index d01f5dc..02538c4 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -366,28 +366,6 @@ 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; - g_debug("Resetting date on menu close"); - 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 @@ -1331,9 +1309,6 @@ 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/dbus-shared.h b/src/dbus-shared.h index 51632f9..9e3a781 100644 --- a/src/dbus-shared.h +++ b/src/dbus-shared.h @@ -29,11 +29,7 @@ with this program. If not, see . #define DBUSMENU_CALENDAR_MENUITEM_TYPE "x-canonical-calendar-item" -// The following properties are not *really* properties, but are just -// a way of accessing the calendar from the service #define CALENDAR_MENUITEM_PROP_MARKS "calendar-marks" -#define CALENDAR_MENUITEM_PROP_SET_DATE "calendar-set-date" - #define APPOINTMENT_MENUITEM_TYPE "appointment-item" #define APPOINTMENT_MENUITEM_PROP_LABEL "appointment-label" diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c index a999f42..7d1222e 100644 --- a/src/indicator-datetime.c +++ b/src/indicator-datetime.c @@ -268,6 +268,28 @@ indicator_datetime_class_init (IndicatorDatetimeClass *klass) return; } +static void +menu_visible_notfy_cb(GtkWidget * menu, gpointer user_data) +{ + IndicatorDatetime * self = INDICATOR_DATETIME(user_data); + int y,m,d; + time_t curtime; + + time(&curtime); + struct tm *today = localtime(&curtime); + int y = today->tm_year; + int m = today->tm_mon; + int d = today->tm_mday; + + // Set the calendar to todays date + ido_calendar_menu_item_set_date (IDO_CALENDAR_MENU_ITEM (mi_data), y, m, d); + + // Make sure the day-selected signal is sent so the menu updates - may duplicate + GVariant *variant = g_variant_new_uint32((guint)curtime); + guint timestamp = (guint)time(NULL); + dbusmenu_menuitem_handle_event(DBUSMENU_MENUITEM(item), "day-selected", variant, timestamp); +} + static void indicator_datetime_init (IndicatorDatetime *self) { @@ -348,6 +370,8 @@ indicator_datetime_init (IndicatorDatetime *self) self->priv->menu = dbusmenu_gtkmenu_new(SERVICE_NAME, MENU_OBJ); + g_signal_connect(self->priv->menu, "notify::visible", G_CALLBACK(menu_visible_notfy_cb), self); + 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); @@ -1233,13 +1257,6 @@ calendar_prop_change_cb (DbusmenuMenuitem * mi, gchar * prop, GVariant *value, I } else { g_debug("\tMarks: "); } - } else if (!g_strcmp0(prop, CALENDAR_MENUITEM_PROP_SET_DATE)) { - 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]); - } } return; } -- cgit v1.2.3 From 22a5e34ec75727861c77488aa62d606d64c95271 Mon Sep 17 00:00:00 2001 From: karl-qdh Date: Mon, 11 Apr 2011 14:45:47 +0100 Subject: Improve debug messages and only react when hiding --- src/indicator-datetime.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c index 7d1222e..a6d7ef2 100644 --- a/src/indicator-datetime.c +++ b/src/indicator-datetime.c @@ -272,6 +272,14 @@ static void menu_visible_notfy_cb(GtkWidget * menu, gpointer user_data) { IndicatorDatetime * self = INDICATOR_DATETIME(user_data); + g_debug("notify visible signal recieved"); + + // we should only react if we're currently visible + gboolean visible; + g_object_get(G_OBJECT(menu), "visible", &visible, NULL); + if (visible) return; + g_debug("notify visible menu hidden, resetting date"); + int y,m,d; time_t curtime; -- cgit v1.2.3 From 54a4bf27e26fbdbcd02618250dbabd2b880ca447 Mon Sep 17 00:00:00 2001 From: karl-qdh Date: Mon, 11 Apr 2011 14:56:07 +0100 Subject: syntax fail --- src/indicator-datetime.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c index a6d7ef2..a69e728 100644 --- a/src/indicator-datetime.c +++ b/src/indicator-datetime.c @@ -280,7 +280,6 @@ menu_visible_notfy_cb(GtkWidget * menu, gpointer user_data) if (visible) return; g_debug("notify visible menu hidden, resetting date"); - int y,m,d; time_t curtime; time(&curtime); @@ -290,12 +289,12 @@ menu_visible_notfy_cb(GtkWidget * menu, gpointer user_data) int d = today->tm_mday; // Set the calendar to todays date - ido_calendar_menu_item_set_date (IDO_CALENDAR_MENU_ITEM (mi_data), y, m, d); + ido_calendar_menu_item_set_date (IDO_CALENDAR_MENU_ITEM (self->priv->ido_calendar), y, m, d); // Make sure the day-selected signal is sent so the menu updates - may duplicate GVariant *variant = g_variant_new_uint32((guint)curtime); guint timestamp = (guint)time(NULL); - dbusmenu_menuitem_handle_event(DBUSMENU_MENUITEM(item), "day-selected", variant, timestamp); + dbusmenu_menuitem_handle_event(DBUSMENU_MENUITEM(self->priv->ido_calendar), "day-selected", variant, timestamp); } static void @@ -1443,11 +1442,6 @@ new_calendar_item (DbusmenuMenuitem * newitem, 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 ea0c8c5ef4d8c790304d6c4f3c791b3e56244027 Mon Sep 17 00:00:00 2001 From: karl-qdh Date: Mon, 11 Apr 2011 15:15:16 +0100 Subject: Fixed niggles --- src/indicator-datetime.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c index a69e728..b322cc6 100644 --- a/src/indicator-datetime.c +++ b/src/indicator-datetime.c @@ -269,7 +269,7 @@ indicator_datetime_class_init (IndicatorDatetimeClass *klass) } static void -menu_visible_notfy_cb(GtkWidget * menu, gpointer user_data) +menu_visible_notfy_cb(GtkWidget * menu, G_GNUC_UNUSED GParamSpec *pspec, gpointer user_data) { IndicatorDatetime * self = INDICATOR_DATETIME(user_data); g_debug("notify visible signal recieved"); @@ -289,12 +289,12 @@ menu_visible_notfy_cb(GtkWidget * menu, gpointer user_data) int d = today->tm_mday; // Set the calendar to todays date - ido_calendar_menu_item_set_date (IDO_CALENDAR_MENU_ITEM (self->priv->ido_calendar), y, m, d); + ido_calendar_menu_item_set_date (self->priv->ido_calendar, y+1900, m, d); // Make sure the day-selected signal is sent so the menu updates - may duplicate - GVariant *variant = g_variant_new_uint32((guint)curtime); + /*GVariant *variant = g_variant_new_uint32((guint)curtime); guint timestamp = (guint)time(NULL); - dbusmenu_menuitem_handle_event(DBUSMENU_MENUITEM(self->priv->ido_calendar), "day-selected", variant, timestamp); + dbusmenu_menuitem_handle_event(DBUSMENU_MENUITEM(self->priv->ido_calendar), "day-selected", variant, timestamp);*/ } static void -- cgit v1.2.3 From 0ecb2dd406a7981d197f57b33934b02fbf034b3d Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Wed, 13 Apr 2011 15:32:18 -0400 Subject: watch for resume in the service, not the indicator; update today's menu label after resume --- src/datetime-service.c | 43 +++++++++++++++++++++++++++++++++++++++++++ src/indicator-datetime.c | 40 ---------------------------------------- 2 files changed, 43 insertions(+), 40 deletions(-) diff --git a/src/datetime-service.c b/src/datetime-service.c index 08b352a..08ff9ad 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -1199,6 +1199,40 @@ setup_timer (void) return; } +static void +session_active_change_cb (GDBusProxy * proxy, gchar * sender_name, gchar * signal_name, + GVariant * parameters, gpointer user_data) +{ + // Just returned from suspend + if (g_strcmp0(signal_name, "SystemIdleHintChanged") == 0) { + gboolean idle = FALSE; + g_variant_get(parameters, "(b)", &idle); + if (!idle) { + datetime_interface_update(DATETIME_INTERFACE(user_data)); + update_datetime(NULL); + setup_timer(); + } + } + 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; + + GDBusProxy * proxy = g_dbus_proxy_new_for_bus_finish(res, &error); + + if (error != NULL) { + g_warning("Could not grab DBus proxy for ConsoleKit: %s", error->message); + g_error_free(error); + return; + } + + g_signal_connect(proxy, "g-signal", G_CALLBACK(session_active_change_cb), user_data); +} + /* Callback from getting the address */ static void geo_address_cb (GeoclueAddress * address, int timestamp, GHashTable * addy_data, GeoclueAccuracy * accuracy, GError * error, gpointer user_data) @@ -1433,6 +1467,15 @@ main (int argc, char ** argv) /* Setup the timer */ setup_timer(); + /* And watch for system resumes */ + 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, dbus); + mainloop = g_main_loop_new(NULL, FALSE); g_main_loop_run(mainloop); diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c index b322cc6..1c05ff0 100644 --- a/src/indicator-datetime.c +++ b/src/indicator-datetime.c @@ -171,9 +171,7 @@ 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); @@ -396,34 +394,8 @@ 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", 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 @@ -855,18 +827,6 @@ 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); - if (g_strcmp0(signal_name, "SystemIdleHintChanged") == 0 && g_variant_get_boolean(parameters) == FALSE) { - 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 b5bb58568b4ddd555c885b9f32fd9977b64c8b8a Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 14 Apr 2011 14:34:15 -0500 Subject: 0.2.3 --- configure.ac | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index 6c62342..1504c6a 100644 --- a/configure.ac +++ b/configure.ac @@ -1,11 +1,11 @@ -AC_INIT(indicator-datetime, 0.2.2, ted@canonical.com) +AC_INIT(indicator-datetime, 0.2.3, 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.2) +AM_INIT_AUTOMAKE(indicator-datetime, 0.2.3) AM_MAINTAINER_MODE -- cgit v1.2.3