aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTed Gould <ted@gould.cx>2011-04-12 22:32:18 -0500
committerTed Gould <ted@gould.cx>2011-04-12 22:32:18 -0500
commit6e96a11fa4adf17f5a439d8dd6a20f59eb679e42 (patch)
tree45598d4cf7f260eb4c90bea1753b6c21a8846688 /src
parentd4dc8fa632a432ec7255459122f577eddd6b8978 (diff)
parent8603d94b5950329aeb81bcf255fe7f4173eaf6c3 (diff)
downloadayatana-indicator-datetime-6e96a11fa4adf17f5a439d8dd6a20f59eb679e42.tar.gz
ayatana-indicator-datetime-6e96a11fa4adf17f5a439d8dd6a20f59eb679e42.tar.bz2
ayatana-indicator-datetime-6e96a11fa4adf17f5a439d8dd6a20f59eb679e42.zip
* Upstream Merge
* Use GTK directly for detecting when the menu appears and disappears to reset the date (LP: #649800) * Handle items being removed from the locations list by choosing another item in the list (LP: #740948)
Diffstat (limited to 'src')
-rw-r--r--src/datetime-prefs-locations.c70
-rw-r--r--src/datetime-service.c25
-rw-r--r--src/dbus-shared.h4
-rw-r--r--src/indicator-datetime.c43
4 files changed, 100 insertions, 42 deletions
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
diff --git a/src/datetime-service.c b/src/datetime-service.c
index df37b5e..08b352a 100644
--- a/src/datetime-service.c
+++ b/src/datetime-service.c
@@ -440,28 +440,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
@@ -1439,9 +1417,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 <http://www.gnu.org/licenses/>.
#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..b322cc6 100644
--- a/src/indicator-datetime.c
+++ b/src/indicator-datetime.c
@@ -269,6 +269,35 @@ indicator_datetime_class_init (IndicatorDatetimeClass *klass)
}
static void
+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");
+
+ // 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");
+
+ 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 (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);
+ guint timestamp = (guint)time(NULL);
+ dbusmenu_menuitem_handle_event(DBUSMENU_MENUITEM(self->priv->ido_calendar), "day-selected", variant, timestamp);*/
+}
+
+static void
indicator_datetime_init (IndicatorDatetime *self)
{
self->priv = INDICATOR_DATETIME_GET_PRIVATE(self);
@@ -348,6 +377,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 +1264,6 @@ calendar_prop_change_cb (DbusmenuMenuitem * mi, gchar * prop, GVariant *value, I
} else {
g_debug("\tMarks: <cleared>");
}
- } 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;
}
@@ -1418,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;
}