From 5b018bfff889c44eef34cc8aed95c36dbce25543 Mon Sep 17 00:00:00 2001 From: Luke Yelavich Date: Mon, 14 Feb 2011 18:10:24 +1100 Subject: Add accessible description support. --- src/indicator-datetime.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c index 1f61864..0d76a48 100644 --- a/src/indicator-datetime.c +++ b/src/indicator-datetime.c @@ -166,6 +166,7 @@ static void indicator_datetime_dispose (GObject *object); static void indicator_datetime_finalize (GObject *object); static GtkLabel * get_label (IndicatorObject * io); static GtkMenu * get_menu (IndicatorObject * io); +static const gchar * get_accessible_desc (IndicatorObject * io); static GVariant * bind_enum_set (const GValue * value, const GVariantType * type, gpointer user_data); static gboolean bind_enum_get (GValue * value, GVariant * variant, gpointer user_data); static gchar * generate_format_string (IndicatorDatetime * self); @@ -203,6 +204,7 @@ indicator_datetime_class_init (IndicatorDatetimeClass *klass) io_class->get_label = get_label; io_class->get_menu = get_menu; + io_class->get_accessible_desc = get_accessible_desc; g_object_class_install_property (object_class, PROP_TIME_FORMAT, @@ -621,6 +623,11 @@ update_label (IndicatorDatetime * io) if (ltime == NULL) { g_debug("Error getting local time"); gtk_label_set_label(self->priv->label, _("Error getting time")); + g_signal_emit(G_OBJECT(self), + INDICATOR_OBJECT_SIGNAL_ACCESSIBLE_DESC_UPDATE_ID, + 0, + (IndicatorObjectEntry *)indicator_object_get_entries(INDICATOR_OBJECT(self))->data, + TRUE); return NULL; } @@ -642,6 +649,12 @@ update_label (IndicatorDatetime * io) self->priv->idle_measure = g_idle_add(idle_measure, io); } + g_signal_emit(G_OBJECT(self), + INDICATOR_OBJECT_SIGNAL_ACCESSIBLE_DESC_UPDATE_ID, + 0, + (IndicatorObjectEntry *)indicator_object_get_entries(INDICATOR_OBJECT(self))->data, + TRUE); + return ltime; } @@ -1313,3 +1326,16 @@ get_menu (IndicatorObject * io) return GTK_MENU(self->priv->menu); } + +static const gchar * +get_accessible_desc (IndicatorObject * io) +{ + IndicatorDatetime * self = INDICATOR_DATETIME(io); + const gchar * name; + + if (self->priv->label != NULL) { + name = gtk_label_get_text(self->priv->label); + return name; + } + return NULL; +} -- cgit v1.2.3 From 09bfd842c5834c2e20731eec340210b8ef2158a0 Mon Sep 17 00:00:00 2001 From: karl-qdh Date: Tue, 15 Feb 2011 14:54:00 +0000 Subject: Added a partially working timezone menu items code, there are some difficulties in menu labels which aren't showing, and radio menu items. Also, it's incomplete as the time calculation is waiting until the labels work. --- data/com.canonical.indicator.datetime.gschema.xml | 8 + src/datetime-service.c | 254 +++++++++++++++++----- src/indicator-datetime.c | 8 + 3 files changed, 212 insertions(+), 58 deletions(-) diff --git a/data/com.canonical.indicator.datetime.gschema.xml b/data/com.canonical.indicator.datetime.gschema.xml index fe493f7..117f965 100644 --- a/data/com.canonical.indicator.datetime.gschema.xml +++ b/data/com.canonical.indicator.datetime.gschema.xml @@ -57,5 +57,13 @@ more information. + + [] + A List of locations + + Adds the list of locations the user has configured to display in the + indicator-datetime menu. + + diff --git a/src/datetime-service.c b/src/datetime-service.c index eb280dc..10f53df 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -52,8 +52,13 @@ with this program. If not, see . #include "datetime-interface.h" #include "dbus-shared.h" + +#define SETTINGS_INTERFACE "com.canonical.indicator.datetime" +#define SETTINGS_LOCATIONS "locations" + static void geo_create_client (GeoclueMaster * master, GeoclueMasterClient * client, gchar * path, GError * error, gpointer user_data); static gboolean update_appointment_menu_items (gpointer user_data); +static gboolean update_timezone_menu_items(gpointer user_data); static void setup_timer (void); static IndicatorService * service = NULL; @@ -61,30 +66,39 @@ static GMainLoop * mainloop = NULL; static DbusmenuServer * server = NULL; static DbusmenuMenuitem * root = NULL; static DatetimeInterface * dbus = NULL; -static gchar * current_timezone = NULL; /* Global Items */ static DbusmenuMenuitem * date = NULL; static DbusmenuMenuitem * calendar = NULL; static DbusmenuMenuitem * settings = NULL; -static DbusmenuMenuitem * tzchange = NULL; +static DbusmenuMenuitem * locations_separator = NULL; +static DbusmenuMenuitem * geo_location = NULL; +static DbusmenuMenuitem * current_location = NULL; +//static DbusmenuMenuitem * ecal_location = NULL; static DbusmenuMenuitem * add_appointment = NULL; -static DbusmenuMenuitem * add_location = NULL; static GList * appointments = NULL; -static ECal * ecal = NULL; -static const gchar * ecal_timezone = NULL; -static icaltimezone *tzone; +static GList * dconflocations = NULL; +GSettings *conf; + /* Geoclue trackers */ static GeoclueMasterClient * geo_master = NULL; static GeoclueAddress * geo_address = NULL; -static gchar * geo_timezone = NULL; + +/* Our 3 important timezones */ +static const gchar * ecal_timezone = NULL; +static gchar * current_timezone = NULL; +static gchar * geo_timezone = NULL; + +static ECal * ecal = NULL; +static icaltimezone * tzone; /* Check to see if our timezones are the same */ static void check_timezone_sync (void) { + gchar * label; gboolean in_sync = FALSE; - + if (geo_timezone == NULL) { in_sync = TRUE; } @@ -103,18 +117,64 @@ check_timezone_sync (void) { g_debug("Timezones are different"); } - if (tzchange != NULL) { + if (geo_location != NULL && current_location != NULL) { + g_debug("Got timezone %s", current_timezone); + g_debug("Got timezone %s", geo_timezone); + // Show neither current location nor geo location if both are the same + // however, we want to set their time and label accordingly if (in_sync) { - dbusmenu_menuitem_property_set_bool(tzchange, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE); + if (current_timezone == NULL && geo_timezone == NULL) { + dbusmenu_menuitem_property_set_bool(locations_separator, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE); + dbusmenu_menuitem_property_set_bool (current_location, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE); + dbusmenu_menuitem_property_set_bool (geo_location, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE); + update_timezone_menu_items(NULL); // Update the timezone menu items + return; + } + + dbusmenu_menuitem_property_set_bool (locations_separator, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE); + dbusmenu_menuitem_property_set_bool (current_location, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE); + dbusmenu_menuitem_property_set_bool (current_location, DBUSMENU_MENUITEM_PROP_ENABLED, TRUE); + dbusmenu_menuitem_property_set_bool (geo_location, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE); + dbusmenu_menuitem_property_set_bool (geo_location, DBUSMENU_MENUITEM_PROP_ENABLED, TRUE); + + if (current_timezone != NULL) { + label = current_timezone; + } else { + label = geo_timezone; + } + + if (label != NULL) { + // TODO work out the current location name in a nice way + dbusmenu_menuitem_property_set (current_location, TIMEZONE_MENUITEM_PROP_LABEL, label); + // TODO work out the current time at that location + dbusmenu_menuitem_property_set (current_location, TIMEZONE_MENUITEM_PROP_RIGHT, "+tzone"); + } else { + g_debug("Label for current location is null, this shouldn't happen"); + } + if (geo_timezone != NULL) { + // TODO work out the geo location name in a nice way + dbusmenu_menuitem_property_set (geo_location, TIMEZONE_MENUITEM_PROP_LABEL, geo_timezone); + // TODO work out the current time at that location + dbusmenu_menuitem_property_set (geo_location, TIMEZONE_MENUITEM_PROP_RIGHT, "+tzone"); + } } else { - gchar * label = g_strdup_printf(_("Change timezone to: %s"), geo_timezone); - - dbusmenu_menuitem_property_set(tzchange, DBUSMENU_MENUITEM_PROP_LABEL, label); - dbusmenu_menuitem_property_set_bool(tzchange, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE); - - g_free(label); + // TODO work out the geo location name in a nice way + dbusmenu_menuitem_property_set (geo_location, TIMEZONE_MENUITEM_PROP_LABEL, geo_timezone); + // TODO work out the current time at that location + dbusmenu_menuitem_property_set (geo_location, TIMEZONE_MENUITEM_PROP_RIGHT, "+tzone"); + dbusmenu_menuitem_property_set_bool(geo_location, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE); + + // TODO work out the current location name in a nice way + dbusmenu_menuitem_property_set (current_location, TIMEZONE_MENUITEM_PROP_LABEL, current_timezone); + // TODO work out the current time at that location + dbusmenu_menuitem_property_set (current_location, TIMEZONE_MENUITEM_PROP_RIGHT, "+tzone"); + dbusmenu_menuitem_property_set_bool(current_location, TIMEZONE_MENUITEM_PROP_RADIO, TRUE); + dbusmenu_menuitem_property_set_bool(current_location, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE); + dbusmenu_menuitem_property_set_bool(locations_separator, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE); } } + g_debug("Finished checking timezone sync"); + update_timezone_menu_items(NULL); // Update the timezone menu items return; } @@ -153,7 +213,7 @@ update_current_timezone (void) { return; } -/* See how our timezone setting went */ +/* See how our timezone setting went static void quick_set_tz_cb (OobsObject * obj, OobsResult result, gpointer user_data) { @@ -163,9 +223,9 @@ quick_set_tz_cb (OobsObject * obj, OobsResult result, gpointer user_data) g_warning("Unable to quick set timezone"); } return; -} +}*/ -/* Set the timezone to the Geoclue discovered one */ +/* Set the timezone to the Geoclue discovered one static void quick_set_tz (DbusmenuMenuitem * menuitem, guint timestamp, const gchar *command) { @@ -182,7 +242,7 @@ quick_set_tz (DbusmenuMenuitem * menuitem, guint timestamp, const gchar *command oobs_object_commit_async(obj, quick_set_tz_cb, NULL); return; -} +}*/ /* Updates the label in the date menuitem */ static gboolean @@ -237,8 +297,6 @@ check_for_calendar (gpointer user_data) 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(add_appointment, DBUSMENU_MENUITEM_PROP_ENABLED, TRUE); - dbusmenu_menuitem_property_set_bool(add_appointment, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE); GError *gerror = NULL; // TODO: In reality we should iterate sources of calendar, but getting the local one doens't lag for > a minute @@ -269,9 +327,20 @@ check_for_calendar (gpointer user_data) * this shouldn't automatically set the location and mess up all the appointments for the user. */ if (ecal) ecal_timezone = icaltimezone_get_tzid(tzone); - + + DbusmenuMenuitem * separator = dbusmenu_menuitem_new(); + dbusmenu_menuitem_property_set(separator, DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_CLIENT_TYPES_SEPARATOR); + dbusmenu_menuitem_child_add_position(root, separator, 3); + + add_appointment = dbusmenu_menuitem_new(); + dbusmenu_menuitem_property_set (add_appointment, DBUSMENU_MENUITEM_PROP_LABEL, _("Add Appointment")); + dbusmenu_menuitem_property_set_bool(add_appointment, DBUSMENU_MENUITEM_PROP_ENABLED, TRUE); + dbusmenu_menuitem_property_set_bool(add_appointment, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE); + g_signal_connect(G_OBJECT(add_appointment), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(activate_cb), "evolution -c calendar"); + dbusmenu_menuitem_child_add_position (root, add_appointment, 3); + update_appointment_menu_items(NULL); - g_signal_connect(root, DBUSMENU_MENUITEM_SIGNAL_ABOUT_TO_SHOW, G_CALLBACK(update_appointment_menu_items), NULL); + g_signal_connect(root, DBUSMENU_MENUITEM_SIGNAL_ABOUT_TO_SHOW, G_CALLBACK(update_appointment_menu_items), NULL); g_free(evo); } else { @@ -285,12 +354,60 @@ check_for_calendar (gpointer user_data) static gboolean update_timezone_menu_items(gpointer user_data) { - // Get the current location as specified by the user as a place name and time and add it, - // Get the location from geoclue as a place and time and add it, - // Get the evolution calendar timezone as a place and time and add it, - // Get the current timezone that the clock uses and select that - // Iterate over configured places and add any which aren't already listed - // Hook up each of these to setting the time/current timezone + g_debug("Updating timezone menu items"); + gchar ** locations = g_settings_get_strv(conf, SETTINGS_LOCATIONS); + if (locations == NULL) { + g_debug("No locations configured (NULL)"); + return FALSE; + } + guint len = g_strv_length(locations); + DbusmenuMenuitem *item; + gint i; + + /* Remove all of the previous locations */ + if (dconflocations != NULL) { + g_debug("Freeing old locations"); + while (appointments != NULL) { + DbusmenuMenuitem * litem = DBUSMENU_MENUITEM(dconflocations->data); + g_debug("Freeing old location: %p", litem); + // Remove all the existing menu items which are in appointments. + dconflocations = g_list_remove(dconflocations, litem); + dbusmenu_menuitem_child_delete(root, DBUSMENU_MENUITEM(litem)); + g_object_unref(G_OBJECT(litem)); + } + } + + // TODO: Remove items from the dconflocations at the end of the iteration + // Make sure if there are multiple locations, our current location is shown + if (len > 0) { + dbusmenu_menuitem_property_set_bool (locations_separator, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE); + dbusmenu_menuitem_property_set_bool (current_location, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE); + dbusmenu_menuitem_property_set_bool (current_location, DBUSMENU_MENUITEM_PROP_ENABLED, TRUE); + } else { + g_debug("No locations configured (Empty List)"); + return FALSE; + } + + for (i = 0; i < len; i++) { + // Iterate over configured places and add any which aren't already listed + if (g_strcmp0(locations[i], current_timezone) != 0 && + g_strcmp0(locations[i], geo_timezone) != 0) { + g_debug("Adding timezone in update_timezones %s", locations[i]); + item = dbusmenu_menuitem_new(); + dbusmenu_menuitem_property_set (item, DBUSMENU_MENUITEM_PROP_TYPE, TIMEZONE_MENUITEM_TYPE); + dbusmenu_menuitem_property_set (item, TIMEZONE_MENUITEM_PROP_LABEL, locations[i]); + dbusmenu_menuitem_property_set (item, TIMEZONE_MENUITEM_PROP_RIGHT, "+tzone"); + dbusmenu_menuitem_property_set_bool (item, TIMEZONE_MENUITEM_PROP_RADIO, FALSE); + dbusmenu_menuitem_property_set_bool (item, DBUSMENU_MENUITEM_PROP_ENABLED, TRUE); + dbusmenu_menuitem_property_set_bool (item, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE); + dbusmenu_menuitem_child_add_position (root, item, + dbusmenu_menuitem_get_position (locations_separator, root)+3); + //g_signal_connect(G_OBJECT(item), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(quick_set_tz), NULL); + dconflocations = g_list_append(dconflocations, item); + } + } + g_strfreev (locations); + // Get the evolution calendar timezone as a place and time and add it return FALSE; } @@ -355,6 +472,9 @@ update_appointment_menu_items (gpointer user_data) { // FIXME can we put a limit on the number of results? Or if not complete, or is event/todo? Or sort it by date? query = g_strdup_printf("(occur-in-time-range? (make-time\"%s\") (make-time\"%s\"))", is, ie); + + + // FIXME iterate the query for all sources, kill global ecal g_debug("Getting objects with query: %s", query); if (!e_cal_get_object_list_as_comp(ecal, query, &objects, &gerror)) { g_debug("Failed to get objects\n"); @@ -378,6 +498,8 @@ update_appointment_menu_items (gpointer user_data) { } } + // TODO Remove all highlights from the calendar widget + // Sort the list see above FIXME regarding queries objects = g_list_sort(objects, (GCompareFunc) compare_appointment_items); i = 0; @@ -386,6 +508,7 @@ update_appointment_menu_items (gpointer user_data) { ECalComponentText valuetext; ECalComponentDateTime datetime; icaltimezone *appointment_zone = NULL; + icaltimezone *current_zone = NULL; icalproperty_status status; gchar *summary, *cmd; char right[20]; @@ -433,10 +556,15 @@ update_appointment_menu_items (gpointer user_data) { continue; } + appointment_zone = icaltimezone_get_builtin_timezone_from_tzid(datetime.tzid); + current_zone = icaltimezone_get_builtin_timezone_from_tzid(current_timezone); if (!appointment_zone || datetime.value->is_date) { // If it's today put in the current timezone? - appointment_zone = tzone; + appointment_zone = current_zone; } - tmp_tm = icaltimetype_to_tm_with_zone (datetime.value, appointment_zone, tzone); + // TODO: Convert the timezone into a 3 letter abbreviation if it's different to current_timezone + // TODO: Add the appointment timezone to the list if it's not already there. + + tmp_tm = icaltimetype_to_tm_with_zone (datetime.value, appointment_zone, current_zone); g_debug("Generate time string"); // Get today @@ -450,11 +578,15 @@ update_appointment_menu_items (gpointer user_data) { strftime(right, 20, "%a %l:%M %P", &tmp_tm); g_debug("Appointment time: %s", right); + g_debug("Appointment timezone: %s", datetime.tzid); + g_debug("Appointment timezone: %s", icaltimezone_get_tzid(appointment_zone)); // These two should be the same + g_debug("Calendar timezone: %s", ecal_timezone); + dbusmenu_menuitem_property_set (item, APPOINTMENT_MENUITEM_PROP_RIGHT, right); e_cal_component_free_datetime (&datetime); - ad = is = isodate_from_time_t(mktime(&tmp_tm)); + ad = isodate_from_time_t(mktime(&tmp_tm)); // Now we pull out the URI for the calendar event and try to create a URI that'll work when we execute evolution // FIXME Because the URI stuff is really broken, we're going to open the calendar at todays date instead @@ -489,7 +621,7 @@ update_appointment_menu_items (gpointer user_data) { dbusmenu_menuitem_property_set_image (item, APPOINTMENT_MENUITEM_PROP_ICON, pixbuf); } - dbusmenu_menuitem_child_add_position (root, item, 4+i); + dbusmenu_menuitem_child_add_position (root, item, 3+i); appointments = g_list_append (appointments, item); // Keep track of the items here to make them east to remove g_debug("Adding appointment: %p", item); @@ -548,31 +680,32 @@ build_menus (DbusmenuMenuitem * root) g_idle_add(check_for_calendar, NULL); } - DbusmenuMenuitem * separator; - separator = dbusmenu_menuitem_new(); - dbusmenu_menuitem_property_set(separator, DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_CLIENT_TYPES_SEPARATOR); - dbusmenu_menuitem_child_append(root, separator); - - add_appointment = dbusmenu_menuitem_new(); - dbusmenu_menuitem_property_set (add_appointment, DBUSMENU_MENUITEM_PROP_LABEL, _("Add Appointment")); - dbusmenu_menuitem_property_set_bool(add_appointment, DBUSMENU_MENUITEM_PROP_ENABLED, FALSE); - dbusmenu_menuitem_property_set_bool(add_appointment, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE); - g_signal_connect(G_OBJECT(add_appointment), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(activate_cb), "evolution -c calendar"); - dbusmenu_menuitem_child_add_position (root, add_appointment, 4); + locations_separator = dbusmenu_menuitem_new(); + dbusmenu_menuitem_property_set(locations_separator, DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_CLIENT_TYPES_SEPARATOR); + dbusmenu_menuitem_property_set_bool (locations_separator, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE); + dbusmenu_menuitem_child_append(root, locations_separator); + + geo_location = dbusmenu_menuitem_new(); + dbusmenu_menuitem_property_set (geo_location, DBUSMENU_MENUITEM_PROP_TYPE, TIMEZONE_MENUITEM_TYPE); + dbusmenu_menuitem_property_set (geo_location, TIMEZONE_MENUITEM_PROP_LABEL, "Updating location information..."); + dbusmenu_menuitem_property_set_bool (geo_location, DBUSMENU_MENUITEM_PROP_ENABLED, FALSE); + dbusmenu_menuitem_property_set_bool (geo_location, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE); + //g_signal_connect(G_OBJECT(geo_location), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(quick_set_tz), NULL); + dbusmenu_menuitem_child_append(root, geo_location); + + current_location = dbusmenu_menuitem_new(); + dbusmenu_menuitem_property_set (current_location, DBUSMENU_MENUITEM_PROP_TYPE, TIMEZONE_MENUITEM_TYPE); + dbusmenu_menuitem_property_set (current_location, TIMEZONE_MENUITEM_PROP_LABEL, "Current Timezone"); + dbusmenu_menuitem_property_set_bool (current_location, DBUSMENU_MENUITEM_PROP_ENABLED, FALSE); + dbusmenu_menuitem_property_set_bool (current_location, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE); + //g_signal_connect(G_OBJECT(current_location), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(quick_set_tz), NULL); + dbusmenu_menuitem_child_append(root, current_location); - separator = dbusmenu_menuitem_new(); - dbusmenu_menuitem_property_set(separator, DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_CLIENT_TYPES_SEPARATOR); - dbusmenu_menuitem_child_append(root, separator); - - tzchange = dbusmenu_menuitem_new(); - dbusmenu_menuitem_property_set(tzchange, DBUSMENU_MENUITEM_PROP_LABEL, "Set specific timezone"); - dbusmenu_menuitem_property_set_bool(tzchange, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE); - g_signal_connect(G_OBJECT(tzchange), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(quick_set_tz), NULL); - dbusmenu_menuitem_child_append(root, tzchange); check_timezone_sync(); - - separator = dbusmenu_menuitem_new(); + //g_signal_connect(root, DBUSMENU_MENUITEM_SIGNAL_ABOUT_TO_SHOW, G_CALLBACK(update_timezone_menu_items), NULL); + + DbusmenuMenuitem * separator = dbusmenu_menuitem_new(); dbusmenu_menuitem_property_set(separator, DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_CLIENT_TYPES_SEPARATOR); dbusmenu_menuitem_child_append(root, separator); @@ -804,8 +937,9 @@ main (int argc, char ** argv) bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR); textdomain (GETTEXT_PACKAGE); - /* Cache the timezone */ - update_current_timezone(); + /* Set up GSettings */ + conf = g_settings_new(SETTINGS_INTERFACE); + // TODO Add a signal handler to catch gsettings changes and respond to them /* Building the base menu */ server = dbusmenu_server_new(MENU_OBJ); @@ -813,6 +947,9 @@ main (int argc, char ** argv) dbusmenu_server_set_root(server, root); build_menus(root); + + /* Cache the timezone */ + update_current_timezone(); /* Setup geoclue */ GeoclueMaster * master = geoclue_master_get_default(); @@ -830,6 +967,7 @@ main (int argc, char ** argv) mainloop = g_main_loop_new(NULL, FALSE); g_main_loop_run(mainloop); + g_object_unref(G_OBJECT(conf)); g_object_unref(G_OBJECT(master)); g_object_unref(G_OBJECT(dbus)); g_object_unref(G_OBJECT(service)); diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c index 1f61864..a9b77b9 100644 --- a/src/indicator-datetime.c +++ b/src/indicator-datetime.c @@ -1106,6 +1106,14 @@ indicator_prop_change_cb (DbusmenuMenuitem * mi, gchar * prop, gchar * value, in g_object_unref(resized_pixbuf); } } + } else if (!g_strcmp0(prop, TIMEZONE_MENUITEM_PROP_LABEL)) { + /* Set the main label */ + gtk_label_set_text(GTK_LABEL(mi_data->label), value); + } else if (!g_strcmp0(prop, TIMEZONE_MENUITEM_PROP_RIGHT)) { + /* Set the right label */ + gtk_label_set_text(GTK_LABEL(mi_data->right), value); + } else if (!g_strcmp0(prop, TIMEZONE_MENUITEM_PROP_RADIO)) { + //gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(mi_data->radio), value); } else { g_warning("Indicator Item property '%s' unknown", prop); } -- cgit v1.2.3 From d0f273eb94489f7c0e0c8b57c1d07c3f1a2f66a2 Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Tue, 15 Feb 2011 13:44:12 -0500 Subject: fix typo so timezone labels show up --- 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 a9b77b9..6c9ac55 100644 --- a/src/indicator-datetime.c +++ b/src/indicator-datetime.c @@ -1253,14 +1253,14 @@ new_timezone_item(DbusmenuMenuitem * newitem, gtk_widget_show(mi_data->radio); /* Label, probably a username, chat room or mailbox name */ - mi_data->label = gtk_label_new(dbusmenu_menuitem_property_get(newitem, APPOINTMENT_MENUITEM_PROP_LABEL)); + mi_data->label = gtk_label_new(dbusmenu_menuitem_property_get(newitem, TIMEZONE_MENUITEM_PROP_LABEL)); gtk_misc_set_alignment(GTK_MISC(mi_data->label), 0.0, 0.5); gtk_box_pack_start(GTK_BOX(hbox), mi_data->label, TRUE, TRUE, 0); gtk_widget_show(mi_data->label); /* 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)); + mi_data->right = gtk_label_new(dbusmenu_menuitem_property_get(newitem, TIMEZONE_MENUITEM_PROP_RIGHT)); gtk_size_group_add_widget(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); -- cgit v1.2.3 From 36b4e93794c845e5caac71556b9a05d7e474d35a Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Tue, 15 Feb 2011 14:41:43 -0500 Subject: use a GtkCheckMenuItem, not a GtkRadioButton, to render timezone items --- src/indicator-datetime.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c index 6c9ac55..2a309d2 100644 --- a/src/indicator-datetime.c +++ b/src/indicator-datetime.c @@ -105,7 +105,6 @@ enum { typedef struct _indicator_item_t indicator_item_t; struct _indicator_item_t { - GtkWidget * radio; GtkWidget * icon; GtkWidget * label; GtkWidget * right; @@ -176,7 +175,6 @@ static void update_time (IndicatorDatetime * self); static void receive_signal (GDBusProxy * proxy, gchar * sender_name, gchar * signal_name, GVariant * parameters, 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 GSList *location_group = NULL; /* Indicator Module Config */ INDICATOR_SET_VERSION @@ -1238,20 +1236,14 @@ new_timezone_item(DbusmenuMenuitem * newitem, // Menu item with a radio button and a right aligned time indicator_item_t * mi_data = g_new0(indicator_item_t, 1); - GtkMenuItem * gmi = GTK_MENU_ITEM(gtk_menu_item_new()); + GtkMenuItem * gmi = GTK_MENU_ITEM(gtk_check_menu_item_new()); + + gtk_check_menu_item_set_draw_as_radio(GTK_CHECK_MENU_ITEM(gmi), TRUE); + gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(gmi), + dbusmenu_menuitem_property_get_bool(newitem, TIMEZONE_MENUITEM_PROP_RADIO)); GtkWidget * hbox = gtk_hbox_new(FALSE, 4); - mi_data->radio = gtk_radio_button_new(location_group); - if (location_group == NULL) - location_group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(mi_data->radio)); - - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(mi_data->radio), - dbusmenu_menuitem_property_get_bool(newitem, TIMEZONE_MENUITEM_PROP_RADIO)); - - gtk_box_pack_start(GTK_BOX(hbox), mi_data->radio, FALSE, FALSE, 0); - gtk_widget_show(mi_data->radio); - /* Label, probably a username, chat room or mailbox name */ mi_data->label = gtk_label_new(dbusmenu_menuitem_property_get(newitem, TIMEZONE_MENUITEM_PROP_LABEL)); gtk_misc_set_alignment(GTK_MISC(mi_data->label), 0.0, 0.5); -- cgit v1.2.3 From 030ba7689c5dabac3a0d84bb55c8fcec7d87737b Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Tue, 15 Feb 2011 14:51:00 -0500 Subject: fix typo that prevented old locations from being deleted --- src/datetime-service.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/datetime-service.c b/src/datetime-service.c index 10f53df..0117be1 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -367,10 +367,10 @@ update_timezone_menu_items(gpointer user_data) { /* Remove all of the previous locations */ if (dconflocations != NULL) { g_debug("Freeing old locations"); - while (appointments != NULL) { + while (dconflocations != NULL) { DbusmenuMenuitem * litem = DBUSMENU_MENUITEM(dconflocations->data); g_debug("Freeing old location: %p", litem); - // Remove all the existing menu items which are in appointments. + // Remove all the existing menu items which are in dconflocations. dconflocations = g_list_remove(dconflocations, litem); dbusmenu_menuitem_child_delete(root, DBUSMENU_MENUITEM(litem)); g_object_unref(G_OBJECT(litem)); -- cgit v1.2.3 From f704c6178715e68128e324490660aea5014eb2f7 Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Tue, 15 Feb 2011 14:53:47 -0500 Subject: show current or geo location if we are going to use them --- src/datetime-service.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/datetime-service.c b/src/datetime-service.c index 0117be1..3c84551 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -148,6 +148,7 @@ check_timezone_sync (void) { dbusmenu_menuitem_property_set (current_location, TIMEZONE_MENUITEM_PROP_LABEL, label); // TODO work out the current time at that location dbusmenu_menuitem_property_set (current_location, TIMEZONE_MENUITEM_PROP_RIGHT, "+tzone"); + dbusmenu_menuitem_property_set_bool (current_location, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE); } else { g_debug("Label for current location is null, this shouldn't happen"); } @@ -156,6 +157,7 @@ check_timezone_sync (void) { dbusmenu_menuitem_property_set (geo_location, TIMEZONE_MENUITEM_PROP_LABEL, geo_timezone); // TODO work out the current time at that location dbusmenu_menuitem_property_set (geo_location, TIMEZONE_MENUITEM_PROP_RIGHT, "+tzone"); + dbusmenu_menuitem_property_set_bool (geo_location, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE); } } else { // TODO work out the geo location name in a nice way -- cgit v1.2.3 From 02f8926f9c00954625a57e8d5d650e2523b98154 Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Tue, 15 Feb 2011 15:06:33 -0500 Subject: add preference zones in order, after current timezone --- src/datetime-service.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/datetime-service.c b/src/datetime-service.c index 3c84551..2db6421 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -364,7 +364,7 @@ update_timezone_menu_items(gpointer user_data) { } guint len = g_strv_length(locations); DbusmenuMenuitem *item; - gint i; + gint i, offset; /* Remove all of the previous locations */ if (dconflocations != NULL) { @@ -390,6 +390,7 @@ update_timezone_menu_items(gpointer user_data) { return FALSE; } + offset = dbusmenu_menuitem_get_position (current_location, root)+1; for (i = 0; i < len; i++) { // Iterate over configured places and add any which aren't already listed if (g_strcmp0(locations[i], current_timezone) != 0 && @@ -402,8 +403,7 @@ update_timezone_menu_items(gpointer user_data) { dbusmenu_menuitem_property_set_bool (item, TIMEZONE_MENUITEM_PROP_RADIO, FALSE); dbusmenu_menuitem_property_set_bool (item, DBUSMENU_MENUITEM_PROP_ENABLED, TRUE); dbusmenu_menuitem_property_set_bool (item, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE); - dbusmenu_menuitem_child_add_position (root, item, - dbusmenu_menuitem_get_position (locations_separator, root)+3); + dbusmenu_menuitem_child_add_position (root, item, offset++); //g_signal_connect(G_OBJECT(item), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(quick_set_tz), NULL); dconflocations = g_list_append(dconflocations, item); } -- cgit v1.2.3 From 67264a791f282ac18eba02af4df73f71c9736886 Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Tue, 15 Feb 2011 15:10:49 -0500 Subject: start with current timezone selected --- src/datetime-service.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/datetime-service.c b/src/datetime-service.c index 2db6421..795403f 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -149,6 +149,7 @@ check_timezone_sync (void) { // TODO work out the current time at that location dbusmenu_menuitem_property_set (current_location, TIMEZONE_MENUITEM_PROP_RIGHT, "+tzone"); dbusmenu_menuitem_property_set_bool (current_location, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE); + dbusmenu_menuitem_property_set_bool(current_location, TIMEZONE_MENUITEM_PROP_RADIO, TRUE); } else { g_debug("Label for current location is null, this shouldn't happen"); } -- cgit v1.2.3 From 6bc13b2d4f6cab5a349a072d256dcb55418c6ef2 Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Tue, 15 Feb 2011 15:32:56 -0500 Subject: re-enable setting the timezone when clicking --- src/datetime-service.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/datetime-service.c b/src/datetime-service.c index 795403f..432657d 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -216,7 +216,7 @@ update_current_timezone (void) { return; } -/* See how our timezone setting went +/* See how our timezone setting went */ static void quick_set_tz_cb (OobsObject * obj, OobsResult result, gpointer user_data) { @@ -226,26 +226,27 @@ quick_set_tz_cb (OobsObject * obj, OobsResult result, gpointer user_data) g_warning("Unable to quick set timezone"); } return; -}*/ +} -/* Set the timezone to the Geoclue discovered one +/* Set the timezone to the Geoclue discovered one */ static void -quick_set_tz (DbusmenuMenuitem * menuitem, guint timestamp, const gchar *command) +quick_set_tz (DbusmenuMenuitem * menuitem, guint timestamp, gpointer user_data) { - g_debug("Quick setting timezone to: %s", geo_timezone); + const gchar * tz = dbusmenu_menuitem_property_get(menuitem, TIMEZONE_MENUITEM_PROP_LABEL); + g_debug("Quick setting timezone to: %s", tz); - g_return_if_fail(geo_timezone != NULL); + g_return_if_fail(tz != NULL); OobsObject * obj = oobs_time_config_get(); g_return_if_fail(obj != NULL); OobsTimeConfig * timeconfig = OOBS_TIME_CONFIG(obj); - oobs_time_config_set_timezone(timeconfig, geo_timezone); + oobs_time_config_set_timezone(timeconfig, tz); oobs_object_commit_async(obj, quick_set_tz_cb, NULL); return; -}*/ +} /* Updates the label in the date menuitem */ static gboolean @@ -405,7 +406,7 @@ update_timezone_menu_items(gpointer user_data) { dbusmenu_menuitem_property_set_bool (item, DBUSMENU_MENUITEM_PROP_ENABLED, TRUE); dbusmenu_menuitem_property_set_bool (item, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE); dbusmenu_menuitem_child_add_position (root, item, offset++); - //g_signal_connect(G_OBJECT(item), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(quick_set_tz), NULL); + g_signal_connect(G_OBJECT(item), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(quick_set_tz), NULL); dconflocations = g_list_append(dconflocations, item); } } @@ -694,7 +695,7 @@ build_menus (DbusmenuMenuitem * root) dbusmenu_menuitem_property_set (geo_location, TIMEZONE_MENUITEM_PROP_LABEL, "Updating location information..."); dbusmenu_menuitem_property_set_bool (geo_location, DBUSMENU_MENUITEM_PROP_ENABLED, FALSE); dbusmenu_menuitem_property_set_bool (geo_location, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE); - //g_signal_connect(G_OBJECT(geo_location), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(quick_set_tz), NULL); + g_signal_connect(G_OBJECT(geo_location), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(quick_set_tz), NULL); dbusmenu_menuitem_child_append(root, geo_location); current_location = dbusmenu_menuitem_new(); @@ -702,7 +703,7 @@ build_menus (DbusmenuMenuitem * root) dbusmenu_menuitem_property_set (current_location, TIMEZONE_MENUITEM_PROP_LABEL, "Current Timezone"); dbusmenu_menuitem_property_set_bool (current_location, DBUSMENU_MENUITEM_PROP_ENABLED, FALSE); dbusmenu_menuitem_property_set_bool (current_location, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE); - //g_signal_connect(G_OBJECT(current_location), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(quick_set_tz), NULL); + g_signal_connect(G_OBJECT(current_location), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(quick_set_tz), NULL); dbusmenu_menuitem_child_append(root, current_location); check_timezone_sync(); -- cgit v1.2.3 From fe51dffdecdaeca76ae8dd0c7e736cd7d56bf3a3 Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Tue, 15 Feb 2011 15:41:19 -0500 Subject: in prop_cb, value is a GVariant, not a string, which explains why we sometimes get bogus strings in the menu --- src/indicator-datetime.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c index 2a309d2..6d5afc0 100644 --- a/src/indicator-datetime.c +++ b/src/indicator-datetime.c @@ -1068,14 +1068,14 @@ generate_format_string (IndicatorDatetime * self) /* Whenever we have a property change on a DbusmenuMenuitem we need to be responsive to that. */ static void -indicator_prop_change_cb (DbusmenuMenuitem * mi, gchar * prop, gchar * value, indicator_item_t * mi_data) +indicator_prop_change_cb (DbusmenuMenuitem * mi, gchar * prop, GVariant *value, indicator_item_t * mi_data) { if (!g_strcmp0(prop, APPOINTMENT_MENUITEM_PROP_LABEL)) { /* Set the main label */ - gtk_label_set_text(GTK_LABEL(mi_data->label), value); + gtk_label_set_text(GTK_LABEL(mi_data->label), g_variant_get_string(value, NULL)); } else if (!g_strcmp0(prop, APPOINTMENT_MENUITEM_PROP_RIGHT)) { /* Set the right label */ - gtk_label_set_text(GTK_LABEL(mi_data->right), value); + gtk_label_set_text(GTK_LABEL(mi_data->right), g_variant_get_string(value, NULL)); } else if (!g_strcmp0(prop, APPOINTMENT_MENUITEM_PROP_ICON)) { /* We don't use the value here, which is probably less efficient, but it's easier to use the easy function. And since th value @@ -1106,12 +1106,12 @@ indicator_prop_change_cb (DbusmenuMenuitem * mi, gchar * prop, gchar * value, in } } else if (!g_strcmp0(prop, TIMEZONE_MENUITEM_PROP_LABEL)) { /* Set the main label */ - gtk_label_set_text(GTK_LABEL(mi_data->label), value); + gtk_label_set_text(GTK_LABEL(mi_data->label), g_variant_get_string(value, NULL)); } else if (!g_strcmp0(prop, TIMEZONE_MENUITEM_PROP_RIGHT)) { /* Set the right label */ - gtk_label_set_text(GTK_LABEL(mi_data->right), value); + gtk_label_set_text(GTK_LABEL(mi_data->right), g_variant_get_string(value, NULL)); } else if (!g_strcmp0(prop, TIMEZONE_MENUITEM_PROP_RADIO)) { - //gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(mi_data->radio), value); + //gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(mi_data->radio), g_variant_get_boolean(value)); } else { g_warning("Indicator Item property '%s' unknown", prop); } -- cgit v1.2.3 From 07e4b46e4a8ee9607919ad28af4f26fb036eb57e Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Tue, 15 Feb 2011 15:48:55 -0500 Subject: record which gmi goes with with dbusmenuitem and use that to properly watch radio-active property changes --- src/indicator-datetime.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c index 6d5afc0..f396665 100644 --- a/src/indicator-datetime.c +++ b/src/indicator-datetime.c @@ -105,6 +105,7 @@ enum { typedef struct _indicator_item_t indicator_item_t; struct _indicator_item_t { + GtkWidget * gmi; GtkWidget * icon; GtkWidget * label; GtkWidget * right; @@ -1111,7 +1112,7 @@ indicator_prop_change_cb (DbusmenuMenuitem * mi, gchar * prop, GVariant *value, /* Set the right label */ gtk_label_set_text(GTK_LABEL(mi_data->right), g_variant_get_string(value, NULL)); } else if (!g_strcmp0(prop, TIMEZONE_MENUITEM_PROP_RADIO)) { - //gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(mi_data->radio), g_variant_get_boolean(value)); + 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); } @@ -1133,7 +1134,7 @@ new_appointment_item (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, Dbu indicator_item_t * mi_data = g_new0(indicator_item_t, 1); - GtkMenuItem * gmi = GTK_MENU_ITEM(gtk_menu_item_new()); + mi_data->gmi = gtk_menu_item_new(); GtkWidget * hbox = gtk_hbox_new(FALSE, 4); @@ -1184,10 +1185,10 @@ new_appointment_item (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, Dbu gtk_box_pack_start(GTK_BOX(hbox), mi_data->right, FALSE, FALSE, 0); gtk_widget_show(mi_data->right); - gtk_container_add(GTK_CONTAINER(gmi), hbox); + gtk_container_add(GTK_CONTAINER(mi_data->gmi), hbox); gtk_widget_show(hbox); - dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), newitem, gmi, parent); + dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), newitem, GTK_MENU_ITEM(mi_data->gmi), parent); g_signal_connect(G_OBJECT(newitem), DBUSMENU_MENUITEM_SIGNAL_PROPERTY_CHANGED, G_CALLBACK(indicator_prop_change_cb), mi_data); g_signal_connect_swapped(G_OBJECT(newitem), "destroyed", G_CALLBACK(g_free), mi_data); @@ -1236,10 +1237,10 @@ new_timezone_item(DbusmenuMenuitem * newitem, // Menu item with a radio button and a right aligned time indicator_item_t * mi_data = g_new0(indicator_item_t, 1); - GtkMenuItem * gmi = GTK_MENU_ITEM(gtk_check_menu_item_new()); + mi_data->gmi = gtk_check_menu_item_new(); - gtk_check_menu_item_set_draw_as_radio(GTK_CHECK_MENU_ITEM(gmi), TRUE); - gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(gmi), + gtk_check_menu_item_set_draw_as_radio(GTK_CHECK_MENU_ITEM(mi_data->gmi), TRUE); + gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(mi_data->gmi), dbusmenu_menuitem_property_get_bool(newitem, TIMEZONE_MENUITEM_PROP_RADIO)); GtkWidget * hbox = gtk_hbox_new(FALSE, 4); @@ -1258,10 +1259,10 @@ new_timezone_item(DbusmenuMenuitem * newitem, gtk_box_pack_start(GTK_BOX(hbox), mi_data->right, FALSE, FALSE, 0); gtk_widget_show(mi_data->right); - gtk_container_add(GTK_CONTAINER(gmi), hbox); + gtk_container_add(GTK_CONTAINER(mi_data->gmi), hbox); gtk_widget_show(hbox); - dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), newitem, gmi, parent); + dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), newitem, GTK_MENU_ITEM(mi_data->gmi), parent); g_signal_connect(G_OBJECT(newitem), DBUSMENU_MENUITEM_SIGNAL_PROPERTY_CHANGED, G_CALLBACK(indicator_prop_change_cb), mi_data); g_signal_connect_swapped(G_OBJECT(newitem), "destroyed", G_CALLBACK(g_free), mi_data); -- cgit v1.2.3 From 02fcae957feca3cefd3c950c265fab03c5b1177c Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Tue, 15 Feb 2011 15:52:09 -0500 Subject: ignore timezone switches if nothing to do --- src/datetime-service.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/datetime-service.c b/src/datetime-service.c index 432657d..0894e83 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -233,10 +233,14 @@ static void quick_set_tz (DbusmenuMenuitem * menuitem, guint timestamp, gpointer user_data) { const gchar * tz = dbusmenu_menuitem_property_get(menuitem, TIMEZONE_MENUITEM_PROP_LABEL); + g_debug("Quick setting timezone to: %s", tz); g_return_if_fail(tz != NULL); + if (g_strcmp0(tz, current_timezone) == 0) + return; + OobsObject * obj = oobs_time_config_get(); g_return_if_fail(obj != NULL); -- cgit v1.2.3 From 9bb32e21e00cbccd6fc7676c3d75cf34f8f6087b Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Tue, 15 Feb 2011 16:19:03 -0500 Subject: make sure gmi-radio-active state is always in sync with the dbusmenu-radio-active state --- src/indicator-datetime.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c index f396665..13c39f8 100644 --- a/src/indicator-datetime.c +++ b/src/indicator-datetime.c @@ -1224,6 +1224,22 @@ new_calendar_item (DbusmenuMenuitem * newitem, return TRUE; } +static void +timezone_toggled_cb (GtkCheckMenuItem *checkmenuitem, DbusmenuMenuitem * dbusitem) +{ + /* Make sure that the displayed radio-active setting is always + consistent with the dbus menuitem */ + gtk_check_menu_item_set_active(checkmenuitem, + dbusmenu_menuitem_property_get_bool(dbusitem, TIMEZONE_MENUITEM_PROP_RADIO)); +} + +static void +timezone_destroyed_cb (DbusmenuMenuitem * dbusitem, indicator_item_t * mi_data) +{ + g_signal_handlers_disconnect_by_func(G_OBJECT(mi_data->gmi), G_CALLBACK(timezone_toggled_cb), dbusitem); + g_free(mi_data); +} + static gboolean new_timezone_item(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, @@ -1264,8 +1280,9 @@ new_timezone_item(DbusmenuMenuitem * newitem, dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), newitem, GTK_MENU_ITEM(mi_data->gmi), parent); + g_signal_connect(G_OBJECT(mi_data->gmi), "toggled", G_CALLBACK(timezone_toggled_cb), newitem); g_signal_connect(G_OBJECT(newitem), DBUSMENU_MENUITEM_SIGNAL_PROPERTY_CHANGED, G_CALLBACK(indicator_prop_change_cb), mi_data); - g_signal_connect_swapped(G_OBJECT(newitem), "destroyed", G_CALLBACK(g_free), mi_data); + g_signal_connect_swapped(G_OBJECT(newitem), "destroyed", G_CALLBACK(timezone_destroyed_cb), mi_data); return TRUE; } -- cgit v1.2.3 From 37fc0a3158e5ff5f8cf9096de49451379c2d11f1 Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Tue, 15 Feb 2011 16:42:13 -0500 Subject: whoops, don't connect destroyed signal as swapped --- 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 13c39f8..0f60428 100644 --- a/src/indicator-datetime.c +++ b/src/indicator-datetime.c @@ -1282,7 +1282,7 @@ new_timezone_item(DbusmenuMenuitem * newitem, g_signal_connect(G_OBJECT(mi_data->gmi), "toggled", G_CALLBACK(timezone_toggled_cb), newitem); g_signal_connect(G_OBJECT(newitem), DBUSMENU_MENUITEM_SIGNAL_PROPERTY_CHANGED, G_CALLBACK(indicator_prop_change_cb), mi_data); - g_signal_connect_swapped(G_OBJECT(newitem), "destroyed", G_CALLBACK(timezone_destroyed_cb), mi_data); + g_signal_connect(G_OBJECT(newitem), "destroyed", G_CALLBACK(timezone_destroyed_cb), mi_data); return TRUE; } -- cgit v1.2.3 From af5f67f6a005f3cfd23af998ef16cc8c507edba1 Mon Sep 17 00:00:00 2001 From: karl-qdh Date: Wed, 16 Feb 2011 13:19:53 +0000 Subject: Added ecal for all sources, untested as yet, need to merge in mterry's branch --- src/datetime-service.c | 64 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 45 insertions(+), 19 deletions(-) diff --git a/src/datetime-service.c b/src/datetime-service.c index 10f53df..e2313f8 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -90,9 +90,6 @@ static const gchar * ecal_timezone = NULL; static gchar * current_timezone = NULL; static gchar * geo_timezone = NULL; -static ECal * ecal = NULL; -static icaltimezone * tzone; - /* Check to see if our timezones are the same */ static void check_timezone_sync (void) { @@ -297,7 +294,7 @@ check_for_calendar (gpointer user_data) 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); - +/* GError *gerror = NULL; // TODO: In reality we should iterate sources of calendar, but getting the local one doens't lag for > a minute g_debug("Setting up ecal."); @@ -321,13 +318,13 @@ check_for_calendar (gpointer user_data) ecal = NULL; } - /* This timezone represents the timezone of the calendar, this might be different to the current UTC offset. + This timezone represents the timezone of the calendar, this might be different to the current UTC offset. * this means we'll have some geoclue interaction going on, and possibly the user will be involved in setting * their location manually, case in point: trains have satellite links which often geoclue to sweden, * this shouldn't automatically set the location and mess up all the appointments for the user. - */ + if (ecal) ecal_timezone = icaltimezone_get_tzid(tzone); - + */ DbusmenuMenuitem * separator = dbusmenu_menuitem_new(); dbusmenu_menuitem_property_set(separator, DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_CLIENT_TYPES_SEPARATOR); dbusmenu_menuitem_child_add_position(root, separator, 3); @@ -459,6 +456,7 @@ update_appointment_menu_items (gpointer user_data) { time_t t1, t2; gchar *query, *is, *ie, *ad; GList *objects = NULL, *l; + GList *allobjects = NULL; GError *gerror = NULL; gint i; gint width, height; @@ -470,20 +468,15 @@ update_appointment_menu_items (gpointer user_data) { is = isodate_from_time_t(t1); ie = isodate_from_time_t(t2); + gtk_icon_size_lookup(GTK_ICON_SIZE_MENU, &width, &height); + // FIXME can we put a limit on the number of results? Or if not complete, or is event/todo? Or sort it by date? query = g_strdup_printf("(occur-in-time-range? (make-time\"%s\") (make-time\"%s\"))", is, ie); - - // FIXME iterate the query for all sources, kill global ecal - g_debug("Getting objects with query: %s", query); - if (!e_cal_get_object_list_as_comp(ecal, query, &objects, &gerror)) { - g_debug("Failed to get objects\n"); - g_free(ecal); - ecal = NULL; + if (!e_cal_get_sources(&sources, E_CAL_SOURCE_TYPE_EVENT, &gerror)) { + g_debug("Failed to get ecal sources\n"); return FALSE; } - g_debug("Number of objects returned: %d", g_list_length(objects)); - gtk_icon_size_lookup(GTK_ICON_SIZE_MENU, &width, &height); /* Remove all of the previous appointments */ if (appointments != NULL) { @@ -500,10 +493,43 @@ update_appointment_menu_items (gpointer user_data) { // TODO Remove all highlights from the calendar widget + // iterate the query for all sources + for (g = e_source_list_peek_groups (sources); g; g = g->next) { + ESourceGroup *group = E_SOURCE_GROUP (g->data); + GSList *s; + + for (s = e_source_group_peek_sources (group); s; s = s->next) { + ESource *source = E_SOURCE (s->data); + ECal *ecal = e_cal_new(source, E_CAL_SOURCE_TYPE_EVENT); + + icaltimezone * tzone; + + if (!e_cal_open(ecal, FALSE, &gerror)) { + g_debug("Failed to get ecal sources %s", gerror->message); + return FALSE; + } + + g_debug("Getting objects with query: %s", query); + if (!e_cal_get_object_list_as_comp(ecal, query, &objects, &gerror)) { + g_debug("Failed to get objects\n"); + g_free(ecal); + return FALSE; + } + g_debug("Number of objects returned: %d", g_list_length(objects)); + + if (allobjects == NULL) { + allobjects = objects; + } else if (objects != NULL) { + allobjects = g_list_concat(allobjects, objects); + g_list_free(objects); + } + } + } + // Sort the list see above FIXME regarding queries - objects = g_list_sort(objects, (GCompareFunc) compare_appointment_items); + allobjects = g_list_sort(allobjects, (GCompareFunc) compare_appointment_items); i = 0; - for (l = objects; l; l = l->next) { + for (l = allobjects; l; l = l->next) { ECalComponent *ecalcomp = l->data; ECalComponentText valuetext; ECalComponentDateTime datetime; @@ -628,7 +654,7 @@ update_appointment_menu_items (gpointer user_data) { if (i == 4) break; // See above FIXME regarding query result limit i++; } - g_list_free(objects); + g_list_free(allobjects); g_debug("End of objects"); return TRUE; } -- cgit v1.2.3 From 3d413661f18e46c34802d8811c28e11020d01a8a Mon Sep 17 00:00:00 2001 From: karl-qdh Date: Wed, 16 Feb 2011 14:22:07 +0000 Subject: Removed unnoticed conflict and fixed some issues --- src/datetime-service.c | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/src/datetime-service.c b/src/datetime-service.c index 976e7e6..a33a561 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -78,10 +78,6 @@ static DbusmenuMenuitem * geo_location = NULL; static DbusmenuMenuitem * current_location = NULL; //static DbusmenuMenuitem * ecal_location = NULL; static DbusmenuMenuitem * add_appointment = NULL; -<<<<<<< TREE -======= -// static DbusmenuMenuitem * add_location = NULL; ->>>>>>> MERGE-SOURCE static GList * appointments = NULL; static GList * dconflocations = NULL; GSettings *conf; @@ -91,8 +87,7 @@ GSettings *conf; static GeoclueMasterClient * geo_master = NULL; static GeoclueAddress * geo_address = NULL; -/* Our 3 important timezones */ -static const gchar * ecal_timezone = NULL; +/* Our 2 important timezones */ static gchar * current_timezone = NULL; static gchar * geo_timezone = NULL; @@ -363,7 +358,7 @@ check_for_calendar (gpointer user_data) return FALSE; } -/* + static gboolean update_timezone_menu_items(gpointer user_data) { g_debug("Updating timezone menu items"); @@ -422,7 +417,7 @@ update_timezone_menu_items(gpointer user_data) { // Get the evolution calendar timezone as a place and time and add it return FALSE; } -*/ + // Compare function for g_list_sort of ECalComponent objects static gint @@ -466,16 +461,17 @@ compare_appointment_items (ECalComponent *a, */ static gboolean update_appointment_menu_items (gpointer user_data) { - if (!ecal) return FALSE; // FFR: we should take into account short term timers, for instance // tea timers, pomodoro timers etc... that people may add, this is hinted to in the spec. time_t t1, t2; gchar *query, *is, *ie, *ad; GList *objects = NULL, *l; GList *allobjects = NULL; + GSList *g; GError *gerror = NULL; gint i; gint width, height; + ESourceList * sources = NULL; time(&t1); time(&t2); @@ -485,14 +481,6 @@ update_appointment_menu_items (gpointer user_data) { ie = isodate_from_time_t(t2); gtk_icon_size_lookup(GTK_ICON_SIZE_MENU, &width, &height); - - // FIXME can we put a limit on the number of results? Or if not complete, or is event/todo? Or sort it by date? - query = g_strdup_printf("(occur-in-time-range? (make-time\"%s\") (make-time\"%s\"))", is, ie); - - if (!e_cal_get_sources(&sources, E_CAL_SOURCE_TYPE_EVENT, &gerror)) { - g_debug("Failed to get ecal sources\n"); - return FALSE; - } /* Remove all of the previous appointments */ if (appointments != NULL) { @@ -508,7 +496,15 @@ update_appointment_menu_items (gpointer user_data) { } // TODO Remove all highlights from the calendar widget + + // FIXME can we put a limit on the number of results? Or if not complete, or is event/todo? Or sort it by date? + query = g_strdup_printf("(occur-in-time-range? (make-time\"%s\") (make-time\"%s\"))", is, ie); + if (!e_cal_get_sources(&sources, E_CAL_SOURCE_TYPE_EVENT, &gerror)) { + g_debug("Failed to get ecal sources\n"); + return FALSE; + } + // iterate the query for all sources for (g = e_source_list_peek_groups (sources); g; g = g->next) { ESourceGroup *group = E_SOURCE_GROUP (g->data); @@ -518,7 +514,7 @@ update_appointment_menu_items (gpointer user_data) { ESource *source = E_SOURCE (s->data); ECal *ecal = e_cal_new(source, E_CAL_SOURCE_TYPE_EVENT); - icaltimezone * tzone; + //icaltimezone * tzone; if (!e_cal_open(ecal, FALSE, &gerror)) { g_debug("Failed to get ecal sources %s", gerror->message); @@ -622,7 +618,7 @@ update_appointment_menu_items (gpointer user_data) { g_debug("Appointment time: %s", right); g_debug("Appointment timezone: %s", datetime.tzid); g_debug("Appointment timezone: %s", icaltimezone_get_tzid(appointment_zone)); // These two should be the same - g_debug("Calendar timezone: %s", ecal_timezone); + //g_debug("Calendar timezone: %s", ecal_timezone); dbusmenu_menuitem_property_set (item, APPOINTMENT_MENUITEM_PROP_RIGHT, right); -- cgit v1.2.3 From bef945a68687702cbcf0cbc4227ac33297ad94b0 Mon Sep 17 00:00:00 2001 From: karl-qdh Date: Wed, 16 Feb 2011 14:31:25 +0000 Subject: Syncup --- src/datetime-service.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/datetime-service.c b/src/datetime-service.c index a33a561..0cba36b 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -636,15 +636,18 @@ update_appointment_menu_items (gpointer user_data) { g_debug("Command to Execute: %s", cmd); - ESource *source = e_cal_get_source (ecal); + // FIXME This is now more difficult to get right with more sources, as we need to keep track + // of which ecal or source goes with each ECalComponent :/ + + //ESource *source = e_cal_get_source (ecal); //e_source_get_color (source, &source_color); api has been changed - const gchar *color_spec = e_source_peek_color_spec(source); - GdkColor color; + const gchar *color_spec = NULL; //e_source_peek_color_spec(source); g_debug("Colour to use: %s", color_spec); // Draw the correct icon for the appointment type and then tint it using mask fill. // For now we'll create a circle if (color_spec != NULL) { + GdkColor color; gdk_color_parse (color_spec, &color); cairo_surface_t *cs = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height); -- cgit v1.2.3 From 942fb6b5ea7f36b7f9738fc8f1e2447ad915d1cb Mon Sep 17 00:00:00 2001 From: karl-qdh Date: Wed, 16 Feb 2011 14:47:12 +0000 Subject: Minor change to continue if getting source fails (auth required is returned by ecal) --- 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 0cba36b..6fef16d 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -518,7 +518,7 @@ update_appointment_menu_items (gpointer user_data) { if (!e_cal_open(ecal, FALSE, &gerror)) { g_debug("Failed to get ecal sources %s", gerror->message); - return FALSE; + continue; } g_debug("Getting objects with query: %s", query); -- cgit v1.2.3 From fafc296c3f87a4fbfd4576aa23f26de53f90d4a0 Mon Sep 17 00:00:00 2001 From: karl-qdh Date: Wed, 16 Feb 2011 15:21:05 +0000 Subject: Missing g_error_free --- src/datetime-service.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/datetime-service.c b/src/datetime-service.c index 6fef16d..1d09d15 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -518,6 +518,7 @@ update_appointment_menu_items (gpointer user_data) { if (!e_cal_open(ecal, FALSE, &gerror)) { g_debug("Failed to get ecal sources %s", gerror->message); + g_error_free(gerror); continue; } -- cgit v1.2.3 From 6bc3639dcf711c00b635d3beb4def0b08f1250a2 Mon Sep 17 00:00:00 2001 From: karl-qdh Date: Wed, 16 Feb 2011 15:38:52 +0000 Subject: Minor changes to objects freeing and NULLing the gerror --- 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 1d09d15..70a1ed5 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -515,10 +515,11 @@ update_appointment_menu_items (gpointer user_data) { ECal *ecal = e_cal_new(source, E_CAL_SOURCE_TYPE_EVENT); //icaltimezone * tzone; - + if (!e_cal_open(ecal, FALSE, &gerror)) { g_debug("Failed to get ecal sources %s", gerror->message); g_error_free(gerror); + gerror = NULL continue; } @@ -534,7 +535,7 @@ update_appointment_menu_items (gpointer user_data) { allobjects = objects; } else if (objects != NULL) { allobjects = g_list_concat(allobjects, objects); - g_list_free(objects); + e_cal_free_object_list(objects); } } } @@ -670,7 +671,7 @@ update_appointment_menu_items (gpointer user_data) { if (i == 4) break; // See above FIXME regarding query result limit i++; } - g_list_free(allobjects); + e_cal_free_object_list(allobjects); g_debug("End of objects"); return TRUE; } -- cgit v1.2.3 From 1676d621586bf6280cb2d37ac023c5588935c47c Mon Sep 17 00:00:00 2001 From: karl-qdh Date: Wed, 16 Feb 2011 16:21:02 +0000 Subject: Added authentication function, and another minor fix to the sources iteration --- configure.ac | 2 ++ src/datetime-service.c | 40 +++++++++++++++++++++++++++++++++++++--- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index b5b1781..6084b85 100644 --- a/configure.ac +++ b/configure.ac @@ -91,6 +91,7 @@ AS_IF([test "x$with_gtk" = x3], libecal-1.2 >= $ECAL_REQUIRED_VERSION libical >= $ICAL_REQUIRED_VERSION libedataserver-1.2 >= EDS_REQUIRED_VERSION + libedataserverui-1.2 >= EDS_REQUIRED_VERSION cairo >= CAIRO_REQUIRED_VERSION gdk-2.0 >= GDK_REQUIRED_VERSION) ], @@ -105,6 +106,7 @@ AS_IF([test "x$with_gtk" = x3], libecal-1.2 >= $ECAL_REQUIRED_VERSION libical >= $ICAL_REQUIRED_VERSION libedataserver-1.2 >= EDS_REQUIRED_VERSION + libedataserverui-1.2 >= EDS_REQUIRED_VERSION cairo >= CAIRO_REQUIRED_VERSION gdk-2.0 >= GDK_REQUIRED_VERSION) ], diff --git a/src/datetime-service.c b/src/datetime-service.c index 70a1ed5..cb383c1 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -42,6 +42,7 @@ with this program. If not, see . #include #include #include +#include // Other users of ecal seem to also include these, not sure why they should be included by the above #include #include @@ -418,6 +419,37 @@ update_timezone_menu_items(gpointer user_data) { return FALSE; } +// Authentication function taken from http://git.gnome.org/browse/evolution/tree/calendar/common/authentication.c +static gchar * +auth_func_cb (ECal *ecal, + const gchar *prompt, + const gchar *key, + gpointer user_data) +{ + gboolean remember; + gchar *password, *auth_domain; + ESource *source; + const gchar *component_name; + + source = e_cal_get_source (ecal); + auth_domain = e_source_get_duped_property (source, "auth-domain"); + component_name = auth_domain ? auth_domain : "Calendar"; + password = e_passwords_get_password (component_name, key); + + if (!password) + password = e_passwords_ask_password ( + _("Enter password"), + component_name, key, prompt, + E_PASSWORDS_REMEMBER_FOREVER | + E_PASSWORDS_SECRET | + E_PASSWORDS_ONLINE, + &remember, NULL); + + g_free (auth_domain); + + return password; +} + // Compare function for g_list_sort of ECalComponent objects static gint @@ -428,7 +460,9 @@ compare_appointment_items (ECalComponent *a, struct tm tm_a, tm_b; time_t t_a, t_b; gint retval = 0; - + + if (a == NULL || b == NULL) return retval; + ECalComponentVType vtype = e_cal_component_get_vtype (a); if (vtype == E_CAL_COMPONENT_EVENT) e_cal_component_get_dtstart (a, &datetime_a); @@ -513,13 +547,13 @@ update_appointment_menu_items (gpointer user_data) { for (s = e_source_group_peek_sources (group); s; s = s->next) { ESource *source = E_SOURCE (s->data); ECal *ecal = e_cal_new(source, E_CAL_SOURCE_TYPE_EVENT); - + e_cal_set_auth_func (ecal, (ECalAuthFunc) auth_func_cb, NULL); //icaltimezone * tzone; if (!e_cal_open(ecal, FALSE, &gerror)) { g_debug("Failed to get ecal sources %s", gerror->message); g_error_free(gerror); - gerror = NULL + gerror = NULL; continue; } -- cgit v1.2.3 From 4feb65c931038f4d6030bffaf44dadf7b10b1e20 Mon Sep 17 00:00:00 2001 From: karl-qdh Date: Wed, 16 Feb 2011 16:40:02 +0000 Subject: Added debugging to figure out a segfault on kenvandine's machine --- src/datetime-service.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/datetime-service.c b/src/datetime-service.c index cb383c1..ecebcce 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -575,6 +575,7 @@ update_appointment_menu_items (gpointer user_data) { } // Sort the list see above FIXME regarding queries + g_debug("Sorting objects list"); allobjects = g_list_sort(allobjects, (GCompareFunc) compare_appointment_items); i = 0; for (l = allobjects; l; l = l->next) { @@ -590,6 +591,7 @@ update_appointment_menu_items (gpointer user_data) { struct tm tmp_tm; DbusmenuMenuitem * item; + g_debug("Start Object"); ECalComponentVType vtype = e_cal_component_get_vtype (ecalcomp); // See above FIXME regarding query result @@ -608,7 +610,6 @@ update_appointment_menu_items (gpointer user_data) { dbusmenu_menuitem_property_set_bool (item, DBUSMENU_MENUITEM_PROP_ENABLED, TRUE); dbusmenu_menuitem_property_set_bool (item, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE); - g_debug("Start Object"); // Label text e_cal_component_get_summary (ecalcomp, &valuetext); summary = g_strdup (valuetext.value); -- cgit v1.2.3 From f6fa7241fd63bbbd451b57233f2f35a9525d5b36 Mon Sep 17 00:00:00 2001 From: karl-qdh Date: Wed, 16 Feb 2011 16:42:06 +0000 Subject: Probable cause of segfault identified, trying to get dates from types without dates most likely cause --- src/datetime-service.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/datetime-service.c b/src/datetime-service.c index ecebcce..9a74af2 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -464,6 +464,9 @@ compare_appointment_items (ECalComponent *a, if (a == NULL || b == NULL) return retval; ECalComponentVType vtype = e_cal_component_get_vtype (a); + + if (vtype != E_CAL_COMPONENT_EVENT && vtype != E_CAL_COMPONENT_TODO) return -1; + if (vtype == E_CAL_COMPONENT_EVENT) e_cal_component_get_dtstart (a, &datetime_a); else @@ -472,6 +475,8 @@ compare_appointment_items (ECalComponent *a, t_a = mktime(&tm_a); vtype = e_cal_component_get_vtype (b); + if (vtype != E_CAL_COMPONENT_EVENT && vtype != E_CAL_COMPONENT_TODO) return 1; + if (vtype == E_CAL_COMPONENT_EVENT) e_cal_component_get_dtstart (b, &datetime_b); else -- cgit v1.2.3 From d4584e52d361870001667964ba4755395538249e Mon Sep 17 00:00:00 2001 From: karl-qdh Date: Wed, 16 Feb 2011 16:44:08 +0000 Subject: Another probable cause of a segfault --- 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 9a74af2..2c0e34b 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -574,7 +574,7 @@ update_appointment_menu_items (gpointer user_data) { allobjects = objects; } else if (objects != NULL) { allobjects = g_list_concat(allobjects, objects); - e_cal_free_object_list(objects); + g_object_unref(objects); } } } -- cgit v1.2.3 From 2aea0129d09d224dee4df45c694c755137bbaf9a Mon Sep 17 00:00:00 2001 From: karl-qdh Date: Wed, 16 Feb 2011 16:49:14 +0000 Subject: The last free -> unref --- 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 2c0e34b..ce500c2 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -711,7 +711,7 @@ update_appointment_menu_items (gpointer user_data) { if (i == 4) break; // See above FIXME regarding query result limit i++; } - e_cal_free_object_list(allobjects); + g_object_unref(allobjects); g_debug("End of objects"); return TRUE; } -- cgit v1.2.3 From 336d4f32f5559d70740a42848e5483c9de447bce Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Wed, 16 Feb 2011 16:22:12 -0500 Subject: show current time in each timezone --- configure.ac | 5 + src/datetime-service.c | 21 ++-- src/dbus-shared.h | 3 +- src/indicator-datetime.c | 250 +++++++++++++++++++++++++++++++++++------------ 4 files changed, 203 insertions(+), 76 deletions(-) diff --git a/configure.ac b/configure.ac index 6084b85..081da56 100644 --- a/configure.ac +++ b/configure.ac @@ -64,15 +64,18 @@ EDS_REQUIRED_VERSION=2.30 ICAL_REQUIRED_VERSION=0.44 CAIRO_REQUIRED_VERSION=1.10 GDK_REQUIRED_VERSION=2.22 +GLIB_REQUIRED_VERSION=2.26 AS_IF([test "x$with_gtk" = x3], [PKG_CHECK_MODULES(INDICATOR, indicator3 >= $INDICATOR_REQUIRED_VERSION + glib-2.0 >= $GLIB_REQUIRED_VERSION dbusmenu-glib-0.4 >= $DBUSMENUGLIB_REQUIRED_VERSION dbusmenu-gtk3-0.4 >= $DBUSMENUGTK_REQUIRED_VERSION libido3-0.1 >= $INDICATOR_DISPLAY_OBJECTS) ], [test "x$with_gtk" = x2], [PKG_CHECK_MODULES(INDICATOR, indicator >= $INDICATOR_REQUIRED_VERSION + glib-2.0 >= $GLIB_REQUIRED_VERSION dbusmenu-glib-0.4 >= $DBUSMENUGLIB_REQUIRED_VERSION dbusmenu-gtk-0.4 >= $DBUSMENUGTK_REQUIRED_VERSION libido-0.1 >= $INDICATOR_DISPLAY_OBJECTS) @@ -82,6 +85,7 @@ AS_IF([test "x$with_gtk" = x3], AS_IF([test "x$with_gtk" = x3], [PKG_CHECK_MODULES(SERVICE, indicator >= $INDICATOR_REQUIRED_VERSION + glib-2.0 >= $GLIB_REQUIRED_VERSION dbusmenu-glib-0.4 >= $DBUSMENUGLIB_REQUIRED_VERSION dbusmenu-gtk3-0.4 >= $DBUSMENUGTK_REQUIRED_VERSION libido-0.1 >= $INDICATOR_DISPLAY_OBJECTS @@ -97,6 +101,7 @@ AS_IF([test "x$with_gtk" = x3], ], [test "x$with_gtk" = x2], [PKG_CHECK_MODULES(SERVICE, indicator >= $INDICATOR_REQUIRED_VERSION + glib-2.0 >= $GLIB_REQUIRED_VERSION dbusmenu-glib-0.4 >= $DBUSMENUGLIB_REQUIRED_VERSION dbusmenu-gtk-0.4 >= $DBUSMENUGTK_REQUIRED_VERSION libido-0.1 >= $INDICATOR_DISPLAY_OBJECTS diff --git a/src/datetime-service.c b/src/datetime-service.c index ce500c2..895bed0 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -144,9 +144,8 @@ check_timezone_sync (void) { if (label != NULL) { // TODO work out the current location name in a nice way - dbusmenu_menuitem_property_set (current_location, TIMEZONE_MENUITEM_PROP_LABEL, label); + dbusmenu_menuitem_property_set (current_location, TIMEZONE_MENUITEM_PROP_ZONE, label); // TODO work out the current time at that location - dbusmenu_menuitem_property_set (current_location, TIMEZONE_MENUITEM_PROP_RIGHT, "+tzone"); dbusmenu_menuitem_property_set_bool (current_location, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE); dbusmenu_menuitem_property_set_bool(current_location, TIMEZONE_MENUITEM_PROP_RADIO, TRUE); } else { @@ -154,22 +153,19 @@ check_timezone_sync (void) { } if (geo_timezone != NULL) { // TODO work out the geo location name in a nice way - dbusmenu_menuitem_property_set (geo_location, TIMEZONE_MENUITEM_PROP_LABEL, geo_timezone); + dbusmenu_menuitem_property_set (geo_location, TIMEZONE_MENUITEM_PROP_ZONE, geo_timezone); // TODO work out the current time at that location - dbusmenu_menuitem_property_set (geo_location, TIMEZONE_MENUITEM_PROP_RIGHT, "+tzone"); dbusmenu_menuitem_property_set_bool (geo_location, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE); } } else { // TODO work out the geo location name in a nice way - dbusmenu_menuitem_property_set (geo_location, TIMEZONE_MENUITEM_PROP_LABEL, geo_timezone); + dbusmenu_menuitem_property_set (geo_location, TIMEZONE_MENUITEM_PROP_ZONE, geo_timezone); // TODO work out the current time at that location - dbusmenu_menuitem_property_set (geo_location, TIMEZONE_MENUITEM_PROP_RIGHT, "+tzone"); dbusmenu_menuitem_property_set_bool(geo_location, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE); // TODO work out the current location name in a nice way - dbusmenu_menuitem_property_set (current_location, TIMEZONE_MENUITEM_PROP_LABEL, current_timezone); + dbusmenu_menuitem_property_set (current_location, TIMEZONE_MENUITEM_PROP_ZONE, current_timezone); // TODO work out the current time at that location - dbusmenu_menuitem_property_set (current_location, TIMEZONE_MENUITEM_PROP_RIGHT, "+tzone"); dbusmenu_menuitem_property_set_bool(current_location, TIMEZONE_MENUITEM_PROP_RADIO, TRUE); dbusmenu_menuitem_property_set_bool(current_location, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE); dbusmenu_menuitem_property_set_bool(locations_separator, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE); @@ -231,7 +227,7 @@ quick_set_tz_cb (OobsObject * obj, OobsResult result, gpointer user_data) static void quick_set_tz (DbusmenuMenuitem * menuitem, guint timestamp, gpointer user_data) { - const gchar * tz = dbusmenu_menuitem_property_get(menuitem, TIMEZONE_MENUITEM_PROP_LABEL); + const gchar * tz = dbusmenu_menuitem_property_get(menuitem, TIMEZONE_MENUITEM_PROP_ZONE); g_debug("Quick setting timezone to: %s", tz); @@ -404,8 +400,7 @@ update_timezone_menu_items(gpointer user_data) { g_debug("Adding timezone in update_timezones %s", locations[i]); item = dbusmenu_menuitem_new(); dbusmenu_menuitem_property_set (item, DBUSMENU_MENUITEM_PROP_TYPE, TIMEZONE_MENUITEM_TYPE); - dbusmenu_menuitem_property_set (item, TIMEZONE_MENUITEM_PROP_LABEL, locations[i]); - dbusmenu_menuitem_property_set (item, TIMEZONE_MENUITEM_PROP_RIGHT, "+tzone"); + dbusmenu_menuitem_property_set (item, TIMEZONE_MENUITEM_PROP_ZONE, locations[i]); dbusmenu_menuitem_property_set_bool (item, TIMEZONE_MENUITEM_PROP_RADIO, FALSE); dbusmenu_menuitem_property_set_bool (item, DBUSMENU_MENUITEM_PROP_ENABLED, TRUE); dbusmenu_menuitem_property_set_bool (item, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE); @@ -771,7 +766,7 @@ build_menus (DbusmenuMenuitem * root) geo_location = dbusmenu_menuitem_new(); dbusmenu_menuitem_property_set (geo_location, DBUSMENU_MENUITEM_PROP_TYPE, TIMEZONE_MENUITEM_TYPE); - dbusmenu_menuitem_property_set (geo_location, TIMEZONE_MENUITEM_PROP_LABEL, "Updating location information..."); + dbusmenu_menuitem_property_set (geo_location, TIMEZONE_MENUITEM_PROP_ZONE, ""); dbusmenu_menuitem_property_set_bool (geo_location, DBUSMENU_MENUITEM_PROP_ENABLED, FALSE); dbusmenu_menuitem_property_set_bool (geo_location, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE); g_signal_connect(G_OBJECT(geo_location), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(quick_set_tz), NULL); @@ -779,7 +774,7 @@ build_menus (DbusmenuMenuitem * root) current_location = dbusmenu_menuitem_new(); dbusmenu_menuitem_property_set (current_location, DBUSMENU_MENUITEM_PROP_TYPE, TIMEZONE_MENUITEM_TYPE); - dbusmenu_menuitem_property_set (current_location, TIMEZONE_MENUITEM_PROP_LABEL, "Current Timezone"); + dbusmenu_menuitem_property_set (current_location, TIMEZONE_MENUITEM_PROP_ZONE, ""); dbusmenu_menuitem_property_set_bool (current_location, DBUSMENU_MENUITEM_PROP_ENABLED, FALSE); dbusmenu_menuitem_property_set_bool (current_location, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE); g_signal_connect(G_OBJECT(current_location), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(quick_set_tz), NULL); diff --git a/src/dbus-shared.h b/src/dbus-shared.h index d13cb32..bad8354 100644 --- a/src/dbus-shared.h +++ b/src/dbus-shared.h @@ -35,6 +35,5 @@ with this program. If not, see . #define APPOINTMENT_MENUITEM_PROP_RIGHT "appointment-time" #define TIMEZONE_MENUITEM_TYPE "timezone-item" -#define TIMEZONE_MENUITEM_PROP_LABEL "timezone-label" +#define TIMEZONE_MENUITEM_PROP_ZONE "timezone-zone" #define TIMEZONE_MENUITEM_PROP_RADIO "timezone-radio" -#define TIMEZONE_MENUITEM_PROP_RIGHT "timezone-time" diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c index 0f60428..54b4507 100644 --- a/src/indicator-datetime.c +++ b/src/indicator-datetime.c @@ -89,6 +89,8 @@ struct _IndicatorDatetimePrivate { GDBusProxy * service_proxy; IdoCalendarMenuItem *ido_calendar; + GList * timezone_items; + GSettings * settings; }; @@ -105,6 +107,8 @@ enum { typedef struct _indicator_item_t indicator_item_t; struct _indicator_item_t { + IndicatorDatetime * self; + DbusmenuMenuitem * mi; GtkWidget * gmi; GtkWidget * icon; GtkWidget * label; @@ -168,14 +172,16 @@ static GtkLabel * get_label (IndicatorObject * io); static GtkMenu * get_menu (IndicatorObject * io); static GVariant * bind_enum_set (const GValue * value, const GVariantType * type, gpointer user_data); static gboolean bind_enum_get (GValue * value, GVariant * variant, gpointer user_data); -static gchar * generate_format_string (IndicatorDatetime * self); -static struct tm * update_label (IndicatorDatetime * io); +static gchar * generate_format_string_now (IndicatorDatetime * self); +static gchar * generate_format_string_at_time (IndicatorDatetime * self, GDateTime * time); +static void update_label (IndicatorDatetime * io, GDateTime ** datetime); static void guess_label_size (IndicatorDatetime * self); -static void setup_timer (IndicatorDatetime * self, struct tm * ltime); +static void setup_timer (IndicatorDatetime * self, GDateTime * datetime); static void update_time (IndicatorDatetime * self); static void receive_signal (GDBusProxy * proxy, gchar * sender_name, gchar * signal_name, GVariant * parameters, 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); /* Indicator Module Config */ INDICATOR_SET_VERSION @@ -262,7 +268,7 @@ indicator_datetime_init (IndicatorDatetime *self) self->priv->custom_string = g_strdup(DEFAULT_TIME_FORMAT); self->priv->custom_show_seconds = FALSE; - self->priv->time_string = generate_format_string(self); + self->priv->time_string = generate_format_string_now(self); self->priv->service_proxy = NULL; @@ -459,6 +465,13 @@ bind_enum_get (GValue * value, GVariant * variant, gpointer user_data) return TRUE; } +static void +timezone_update_all_labels (IndicatorDatetime * self) +{ + IndicatorDatetimePrivate *priv = INDICATOR_DATETIME_GET_PRIVATE(self); + g_list_foreach(priv->timezone_items, (GFunc)timezone_update_labels, NULL); +} + /* Sets a property on the object */ static void set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec) @@ -528,7 +541,7 @@ set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec } /* Get the new format string */ - gchar * newformat = generate_format_string(self); + gchar * newformat = generate_format_string_now(self); /* check to ensure the format really changed */ if (g_strcmp0(self->priv->time_string, newformat) == 0) { @@ -544,7 +557,8 @@ set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec self->priv->time_string = newformat; /* And update everything */ - update_label(self); + update_label(self, NULL); + timezone_update_all_labels(self); guess_label_size(self); return; @@ -602,54 +616,72 @@ idle_measure (gpointer data) return FALSE; } -/* Updates the label to be the current time. */ -static struct tm * -update_label (IndicatorDatetime * io) +static void +set_label_to_time_in_zone (IndicatorDatetime * self, GtkLabel * label, + GTimeZone * tz, const gchar * format, + GDateTime ** datetime) { - IndicatorDatetime * self = INDICATOR_DATETIME(io); - - if (self->priv->label == NULL) return NULL; - - gchar longstr[256]; - time_t t; - struct tm *ltime; - gboolean use_markup; + GDateTime * datetime_now; + if (tz == NULL) + datetime_now = g_date_time_new_now_local(); + else + datetime_now = g_date_time_new_now(tz); - t = time(NULL); - ltime = localtime(&t); - if (ltime == NULL) { - g_debug("Error getting local time"); - gtk_label_set_label(self->priv->label, _("Error getting time")); - return NULL; + gchar * timestr; + if (format == NULL) { + gchar * format_for_time = generate_format_string_at_time(self, datetime_now); + timestr = g_date_time_format(datetime_now, format_for_time); + g_free(format_for_time); + } + else { + timestr = g_date_time_format(datetime_now, format); } - strftime(longstr, 256, self->priv->time_string, ltime); - - gchar * utf8 = g_locale_to_utf8(longstr, -1, NULL, NULL, NULL); - - if (pango_parse_markup(utf8, -1, 0, NULL, NULL, NULL, NULL)) + gboolean use_markup = FALSE; + if (pango_parse_markup(timestr, -1, 0, NULL, NULL, NULL, NULL)) use_markup = TRUE; if (use_markup) - gtk_label_set_markup(self->priv->label, utf8); + gtk_label_set_markup(label, timestr); else - gtk_label_set_text(self->priv->label, utf8); + gtk_label_set_text(label, timestr); + + g_free(timestr); - g_free(utf8); + if (datetime) + *datetime = datetime_now; + else + g_date_time_unref(datetime_now); + + return; +} + +/* Updates the label to be the current time. */ +static void +update_label (IndicatorDatetime * io, GDateTime ** datetime) +{ + IndicatorDatetime * self = INDICATOR_DATETIME(io); + + if (self->priv->label == NULL) return; + + set_label_to_time_in_zone(self, self->priv->label, NULL, self->priv->time_string, datetime); if (self->priv->idle_measure == 0) { self->priv->idle_measure = g_idle_add(idle_measure, io); } - return ltime; + return; } /* Update the time right now. Usually the result of a timezone switch. */ static void update_time (IndicatorDatetime * self) { - struct tm * ltime = update_label(self); - setup_timer(self, ltime); + GDateTime * dt; + update_label(self, &dt); + timezone_update_all_labels(self); + setup_timer(self, dt); + g_date_time_unref(dt); return; } @@ -673,15 +705,20 @@ timer_func (gpointer user_data) { IndicatorDatetime * self = INDICATOR_DATETIME(user_data); self->priv->timer = 0; - struct tm * ltime = update_label(self); - setup_timer(self, ltime); + GDateTime * dt; + update_label(self, &dt); + timezone_update_all_labels(self); + setup_timer(self, dt); + g_date_time_unref(dt); return FALSE; } /* Configure the timer to run the next time through */ static void -setup_timer (IndicatorDatetime * self, struct tm * ltime) +setup_timer (IndicatorDatetime * self, GDateTime * datetime) { + gboolean unref = FALSE; + if (self->priv->timer != 0) { g_source_remove(self->priv->timer); self->priv->timer = 0; @@ -691,14 +728,18 @@ setup_timer (IndicatorDatetime * self, struct tm * ltime) (self->priv->time_mode == SETTINGS_TIME_CUSTOM && self->priv->custom_show_seconds)) { self->priv->timer = g_timeout_add_seconds(1, timer_func, self); } else { - if (ltime == NULL) { - time_t t; - t = time(NULL); - ltime = localtime(&t); + if (datetime == NULL) { + datetime = g_date_time_new_now_local(); + unref = TRUE; } /* Plus 2 so we're just after the minute, don't want to be early. */ - self->priv->timer = g_timeout_add_seconds(60 - ltime->tm_sec + 2, timer_func, self); + gint seconds = (gint)g_date_time_get_seconds(datetime); + self->priv->timer = g_timeout_add_seconds(60 - seconds + 2, timer_func, self); + + if (unref) { + g_date_time_unref(datetime); + } } return; @@ -925,7 +966,8 @@ style_changed (GtkWidget * widget, GtkStyle * oldstyle, gpointer data) g_debug("New style for time label"); IndicatorDatetime * self = INDICATOR_DATETIME(data); guess_label_size(self); - update_label(self); + update_label(self, NULL); + timezone_update_all_labels(self); return; } @@ -1000,12 +1042,8 @@ update_text_gravity (GtkWidget *widget, GdkScreen *previous_screen, gpointer dat /* Tries to figure out what our format string should be. Lots of translator comments in here. */ static gchar * -generate_format_string (IndicatorDatetime * self) +generate_format_string_full (IndicatorDatetime * self, gboolean show_day, gboolean show_date) { - if (self->priv->time_mode == SETTINGS_TIME_CUSTOM) { - return g_strdup(self->priv->custom_string); - } - gboolean twelvehour = TRUE; if (self->priv->time_mode == SETTINGS_TIME_LOCALE) { @@ -1038,20 +1076,20 @@ generate_format_string (IndicatorDatetime * self) /* If there's no date or day let's just leave now and not worry about the rest of this code */ - if (!self->priv->show_date && !self->priv->show_day) { + if (!show_date && !show_day) { return g_strdup(time_string); } const gchar * date_string = NULL; - if (self->priv->show_date && self->priv->show_day) { + if (show_date && show_day) { /* TRANSLATORS: This is a format string passed to strftime to represent the day of the week, the month and the day of the month. */ date_string = T_("%a %b %e"); - } else if (self->priv->show_date) { + } else if (show_date) { /* TRANSLATORS: This is a format string passed to strftime to represent the month and the day of the month. */ date_string = T_("%b %e"); - } else if (self->priv->show_day) { + } else if (show_day) { /* TRANSLATORS: This is a format string passed to strftime to represent the day of the week. */ date_string = T_("%a"); @@ -1066,6 +1104,83 @@ generate_format_string (IndicatorDatetime * self) return g_strdup_printf(T_("%s, %s"), date_string, time_string); } +static gchar * +generate_format_string_now (IndicatorDatetime * self) +{ + if (self->priv->time_mode == SETTINGS_TIME_CUSTOM) { + return g_strdup(self->priv->custom_string); + } + else { + return generate_format_string_full(self, + self->priv->show_day, + self->priv->show_date); + } +} + +static gchar * +generate_format_string_at_time (IndicatorDatetime * self, GDateTime * time) +{ + /* This is a bit less free-form than for the main "now" time label. */ + /* If it is today, just the time should be shown (e.g. “3:55 PM”) + If it is a different day this week, the day and time should be shown (e.g. “Wed 3:55 PM”) + If it is after this week, the day, date, and time should be shown (e.g. “Wed 21 Apr 3:55 PM”). + In addition, when presenting the times of upcoming events, the time should be followed by the timezone if it is different from the one the computer is currently set to. For example, “Wed 3:55 PM UTC−5”. */ + gboolean show_day = FALSE; + gboolean show_date = FALSE; + + GDateTime * now = g_date_time_new_now_local(); + + /* First, are we same day? */ + gint time_year, time_month, time_day; + gint now_year, now_month, now_day; + g_date_time_get_ymd(time, &time_year, &time_month, &time_day); + g_date_time_get_ymd(now, &now_year, &now_month, &now_day); + + if (time_year != now_year || + time_month != now_month || + time_day != now_day) { + /* OK, different days so we must at least show the day. */ + show_day = TRUE; + + /* Is it this week? */ + /* Here, we define "is this week" as yesterday, today, or the next five days */ + GDateTime * past = g_date_time_add_days(now, -1); + GDateTime * future = g_date_time_add_days(now, 5); + GDateTime * past_bound = g_date_time_new_local(g_date_time_get_year(past), + g_date_time_get_month(past), + g_date_time_get_day_of_month(past), + 0, 0, 0.0); + GDateTime * future_bound = g_date_time_new_local(g_date_time_get_year(future), + g_date_time_get_month(future), + g_date_time_get_day_of_month(future), + 23, 59, 59.9); + if (g_date_time_compare(time, past_bound) < 0 || + g_date_time_compare(time, future_bound) > 0) { + show_date = TRUE; + } + g_date_time_unref(past); + g_date_time_unref(future); + g_date_time_unref(past_bound); + g_date_time_unref(future_bound); + } + + return generate_format_string_full(self, show_day, show_date); +} + +static void +timezone_update_labels (indicator_item_t * mi_data) +{ + const gchar * zone_name = dbusmenu_menuitem_property_get(mi_data->mi, TIMEZONE_MENUITEM_PROP_ZONE); + + /* TODO: Make zone name a little more user friendly */ + gtk_label_set_text(GTK_LABEL(mi_data->label), zone_name); + + /* Show current time in that zone on the right */ + GTimeZone * tz = g_time_zone_new(zone_name); + set_label_to_time_in_zone(mi_data->self, GTK_LABEL(mi_data->right), tz, NULL, NULL); + g_time_zone_unref(tz); +} + /* Whenever we have a property change on a DbusmenuMenuitem we need to be responsive to that. */ static void @@ -1105,12 +1220,8 @@ indicator_prop_change_cb (DbusmenuMenuitem * mi, gchar * prop, GVariant *value, g_object_unref(resized_pixbuf); } } - } else if (!g_strcmp0(prop, TIMEZONE_MENUITEM_PROP_LABEL)) { - /* Set the main label */ - gtk_label_set_text(GTK_LABEL(mi_data->label), g_variant_get_string(value, NULL)); - } else if (!g_strcmp0(prop, TIMEZONE_MENUITEM_PROP_RIGHT)) { - /* Set the right label */ - gtk_label_set_text(GTK_LABEL(mi_data->right), g_variant_get_string(value, NULL)); + } else if (!g_strcmp0(prop, TIMEZONE_MENUITEM_PROP_ZONE)) { + 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 { @@ -1236,6 +1347,8 @@ timezone_toggled_cb (GtkCheckMenuItem *checkmenuitem, DbusmenuMenuitem * dbusite static void timezone_destroyed_cb (DbusmenuMenuitem * dbusitem, indicator_item_t * mi_data) { + IndicatorDatetimePrivate *priv = INDICATOR_DATETIME_GET_PRIVATE(mi_data->self); + priv->timezone_items = g_list_remove(priv->timezone_items, mi_data); g_signal_handlers_disconnect_by_func(G_OBJECT(mi_data->gmi), G_CALLBACK(timezone_toggled_cb), dbusitem); g_free(mi_data); } @@ -1250,9 +1363,22 @@ new_timezone_item(DbusmenuMenuitem * newitem, g_return_val_if_fail(DBUSMENU_IS_GTKCLIENT(client), 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); + IndicatorDatetimePrivate *priv = INDICATOR_DATETIME_GET_PRIVATE(self); + // Menu item with a radio button and a right aligned time indicator_item_t * mi_data = g_new0(indicator_item_t, 1); + priv->timezone_items = g_list_prepend(priv->timezone_items, mi_data); + + mi_data->self = self; + mi_data->mi = newitem; mi_data->gmi = gtk_check_menu_item_new(); gtk_check_menu_item_set_draw_as_radio(GTK_CHECK_MENU_ITEM(mi_data->gmi), TRUE); @@ -1262,19 +1388,21 @@ new_timezone_item(DbusmenuMenuitem * newitem, GtkWidget * hbox = gtk_hbox_new(FALSE, 4); /* Label, probably a username, chat room or mailbox name */ - mi_data->label = gtk_label_new(dbusmenu_menuitem_property_get(newitem, TIMEZONE_MENUITEM_PROP_LABEL)); + mi_data->label = gtk_label_new(""); gtk_misc_set_alignment(GTK_MISC(mi_data->label), 0.0, 0.5); gtk_box_pack_start(GTK_BOX(hbox), mi_data->label, TRUE, TRUE, 0); gtk_widget_show(mi_data->label); /* Usually either the time or the count on the individual item. */ - mi_data->right = gtk_label_new(dbusmenu_menuitem_property_get(newitem, TIMEZONE_MENUITEM_PROP_RIGHT)); + mi_data->right = gtk_label_new(""); gtk_size_group_add_widget(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); + timezone_update_labels(mi_data); + gtk_container_add(GTK_CONTAINER(mi_data->gmi), hbox); gtk_widget_show(hbox); @@ -1302,7 +1430,7 @@ get_label (IndicatorObject * io) g_signal_connect(G_OBJECT(self->priv->label), "style-set", G_CALLBACK(style_changed), self); g_signal_connect(G_OBJECT(self->priv->label), "screen-changed", G_CALLBACK(update_text_gravity), self); guess_label_size(self); - update_label(self); + update_label(self, NULL); gtk_widget_show(GTK_WIDGET(self->priv->label)); } -- cgit v1.2.3 From 4bc78d5d1b25f514828a0fb9652f65e529a4e7cf Mon Sep 17 00:00:00 2001 From: Luke Yelavich Date: Thu, 17 Feb 2011 11:05:35 +1100 Subject: Get the indicator entry data into a separate variable, adn and free it after we signal a change in the accessible description, to avoid a memory leak. --- 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 0d76a48..38050f9 100644 --- a/src/indicator-datetime.c +++ b/src/indicator-datetime.c @@ -610,6 +610,7 @@ static struct tm * update_label (IndicatorDatetime * io) { IndicatorDatetime * self = INDICATOR_DATETIME(io); + GList * entry = indicator_object_get_entries(INDICATOR_OBJECT(io)); if (self->priv->label == NULL) return NULL; @@ -623,11 +624,13 @@ update_label (IndicatorDatetime * io) if (ltime == NULL) { g_debug("Error getting local time"); gtk_label_set_label(self->priv->label, _("Error getting time")); + g_signal_emit(G_OBJECT(self), INDICATOR_OBJECT_SIGNAL_ACCESSIBLE_DESC_UPDATE_ID, 0, - (IndicatorObjectEntry *)indicator_object_get_entries(INDICATOR_OBJECT(self))->data, + entry->data, TRUE); + g_list_free(entry); return NULL; } @@ -652,8 +655,9 @@ update_label (IndicatorDatetime * io) g_signal_emit(G_OBJECT(self), INDICATOR_OBJECT_SIGNAL_ACCESSIBLE_DESC_UPDATE_ID, 0, - (IndicatorObjectEntry *)indicator_object_get_entries(INDICATOR_OBJECT(self))->data, + entry->data, TRUE); + g_list_free(entry); return ltime; } -- cgit v1.2.3 From 7d4571cce214fb4324bd3c8759c92feffe0b25c8 Mon Sep 17 00:00:00 2001 From: karl-qdh Date: Thu, 17 Feb 2011 14:49:55 +0000 Subject: Testing eds signal (FAIL) seems when evolution changes an entry no signal is emitted to eds clients --- 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 895bed0..c910770 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -546,6 +546,7 @@ update_appointment_menu_items (gpointer user_data) { for (s = e_source_group_peek_sources (group); s; s = s->next) { ESource *source = E_SOURCE (s->data); + g_signal_connect (G_OBJECT(source), "changed", G_CALLBACK (update_appointment_menu_items), NULL); ECal *ecal = e_cal_new(source, E_CAL_SOURCE_TYPE_EVENT); e_cal_set_auth_func (ecal, (ECalAuthFunc) auth_func_cb, NULL); //icaltimezone * tzone; @@ -781,7 +782,6 @@ build_menus (DbusmenuMenuitem * root) dbusmenu_menuitem_child_append(root, current_location); check_timezone_sync(); - //g_signal_connect(root, DBUSMENU_MENUITEM_SIGNAL_ABOUT_TO_SHOW, G_CALLBACK(update_timezone_menu_items), NULL); DbusmenuMenuitem * separator = dbusmenu_menuitem_new(); dbusmenu_menuitem_property_set(separator, DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_CLIENT_TYPES_SEPARATOR); -- cgit v1.2.3 From 7a70d5723bafdee6460f5080fa94449667eba8f4 Mon Sep 17 00:00:00 2001 From: karl-qdh Date: Thu, 17 Feb 2011 15:52:01 +0000 Subject: Rewrote auth_func at tedg's request. --- src/datetime-service.c | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/src/datetime-service.c b/src/datetime-service.c index c910770..347fecb 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -414,24 +414,19 @@ update_timezone_menu_items(gpointer user_data) { return FALSE; } -// Authentication function taken from http://git.gnome.org/browse/evolution/tree/calendar/common/authentication.c +// Authentication function static gchar * -auth_func_cb (ECal *ecal, - const gchar *prompt, - const gchar *key, - gpointer user_data) -{ - gboolean remember; - gchar *password, *auth_domain; - ESource *source; - const gchar *component_name; +auth_func (ECal *ecal, const gchar *prompt, const gchar *key, gpointer user_data) { + ESource *source = e_cal_get_source (ecal); + gchar *auth_domain = e_source_get_duped_property (source, "auth-domain"); - source = e_cal_get_source (ecal); - auth_domain = e_source_get_duped_property (source, "auth-domain"); - component_name = auth_domain ? auth_domain : "Calendar"; - password = e_passwords_get_password (component_name, key); + const gchar *component_name; + if (auth_domain) component_name = auth_domain; + else component_name = "Calendar"; + + gchar *password = e_passwords_get_password (component_name, key); - if (!password) + if (password == NULL) { password = e_passwords_ask_password ( _("Enter password"), component_name, key, prompt, @@ -439,7 +434,8 @@ auth_func_cb (ECal *ecal, E_PASSWORDS_SECRET | E_PASSWORDS_ONLINE, &remember, NULL); - + } + g_free (auth_domain); return password; @@ -548,7 +544,7 @@ update_appointment_menu_items (gpointer user_data) { ESource *source = E_SOURCE (s->data); g_signal_connect (G_OBJECT(source), "changed", G_CALLBACK (update_appointment_menu_items), NULL); ECal *ecal = e_cal_new(source, E_CAL_SOURCE_TYPE_EVENT); - e_cal_set_auth_func (ecal, (ECalAuthFunc) auth_func_cb, NULL); + e_cal_set_auth_func (ecal, (ECalAuthFunc) auth_func, NULL); //icaltimezone * tzone; if (!e_cal_open(ecal, FALSE, &gerror)) { -- cgit v1.2.3 From a764938d409a848154fbeb88a1370f0235d47405 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 17 Feb 2011 12:32:30 -0600 Subject: Encapsulating the updating of the description into a function --- src/indicator-datetime.c | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c index 38050f9..c7eb9d5 100644 --- a/src/indicator-datetime.c +++ b/src/indicator-datetime.c @@ -605,12 +605,31 @@ idle_measure (gpointer data) return FALSE; } +/* Updates the accessible description */ +static void +update_accessible_description (IndicatorDatetime * io) +{ + GList * entries = indicator_object_get_entries(INDICATOR_OBJECT(io)); + IndicatorObjectEntry * entry = (IndicatorObjectEntry *)entries->data; + + entry->accessible_desc = get_accessible_desc(INDICATOR_OBJECT(io)); + + g_signal_emit(G_OBJECT(io), + INDICATOR_OBJECT_SIGNAL_ACCESSIBLE_DESC_UPDATE_ID, + 0, + entry, + TRUE); + + g_list_free(entries); + + return; +} + /* Updates the label to be the current time. */ static struct tm * update_label (IndicatorDatetime * io) { IndicatorDatetime * self = INDICATOR_DATETIME(io); - GList * entry = indicator_object_get_entries(INDICATOR_OBJECT(io)); if (self->priv->label == NULL) return NULL; @@ -625,12 +644,8 @@ update_label (IndicatorDatetime * io) g_debug("Error getting local time"); gtk_label_set_label(self->priv->label, _("Error getting time")); - g_signal_emit(G_OBJECT(self), - INDICATOR_OBJECT_SIGNAL_ACCESSIBLE_DESC_UPDATE_ID, - 0, - entry->data, - TRUE); - g_list_free(entry); + update_accessible_description(io); + return NULL; } @@ -652,12 +667,7 @@ update_label (IndicatorDatetime * io) self->priv->idle_measure = g_idle_add(idle_measure, io); } - g_signal_emit(G_OBJECT(self), - INDICATOR_OBJECT_SIGNAL_ACCESSIBLE_DESC_UPDATE_ID, - 0, - entry->data, - TRUE); - g_list_free(entry); + update_accessible_description(io); return ltime; } -- cgit v1.2.3 From 8cb18a5036248b0f1fd9f35c437e7f2f11fb3d1a Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 17 Feb 2011 12:33:36 -0600 Subject: Bump to indicator 0.3.19 --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index b5b1781..9ec5914 100644 --- a/configure.ac +++ b/configure.ac @@ -51,7 +51,7 @@ AC_ARG_WITH([gtk], # Dependencies ########################### -INDICATOR_REQUIRED_VERSION=0.3.0 +INDICATOR_REQUIRED_VERSION=0.3.19 DBUSMENUGLIB_REQUIRED_VERSION=0.1.1 DBUSMENUGTK_REQUIRED_VERSION=0.3.94 GIO_REQUIRED_VERSION=2.25.11 -- cgit v1.2.3 From b72c7d76cbb91b353c3373f377bbc4ffc46898bd Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 17 Feb 2011 12:59:52 -0600 Subject: 0.1.94 --- configure.ac | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index a249775..d06aa6d 100644 --- a/configure.ac +++ b/configure.ac @@ -1,11 +1,11 @@ -AC_INIT(indicator-datetime, 0.1.93, ted@canonical.com) +AC_INIT(indicator-datetime, 0.1.94, ted@canonical.com) AC_COPYRIGHT([Copyright 2009,2010 Canonical]) AC_PREREQ(2.53) AM_CONFIG_HEADER(config.h) -AM_INIT_AUTOMAKE(indicator-datetime, 0.1.93) +AM_INIT_AUTOMAKE(indicator-datetime, 0.1.94) AM_MAINTAINER_MODE -- cgit v1.2.3 From e7e3df4f785e467a59308f7b99817cfbaeecab2c Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 17 Feb 2011 13:09:06 -0600 Subject: releasing version 0.1.94-0ubuntu1~ppa1 --- debian/changelog | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/debian/changelog b/debian/changelog index 82c35f3..ddd1a33 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,11 +1,11 @@ -indicator-datetime (0.1.94-0ubuntu1~ppa1) UNRELEASED; urgency=low +indicator-datetime (0.1.94-0ubuntu1~ppa1) natty; urgency=low * New upstream release. ∘ Timezone support ∘ Multiple calendar support ∘ Accessible description - -- Ted Gould Thu, 17 Feb 2011 13:07:48 -0600 + -- Ted Gould Thu, 17 Feb 2011 13:09:04 -0600 indicator-datetime (0.1.93-0ubuntu1) natty; urgency=low -- cgit v1.2.3