From f96caa9a2ae83bda51f7e7b609ef4e6f61ab3c8e Mon Sep 17 00:00:00 2001 From: Martin Pitt Date: Thu, 10 Mar 2011 11:11:44 +0100 Subject: Add support for extra launcher dir Hardcoding a single extra launcher path is impractical for distributions, as multiple packages would collide on the name and wouldn't give any extra customization possibility for OEMs. Obsolete /usr/share/applications/indicator-session-extra.desktop and instead read /usr/share/indicators/session/applications/*.desktop https://launchpad.net/bugs/727823 --- src/session-service.c | 42 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/src/session-service.c b/src/session-service.c index 1d8cd3a..579b12f 100644 --- a/src/session-service.c +++ b/src/session-service.c @@ -55,6 +55,7 @@ with this program. If not, see . #define UP_INTERFACE "org.freedesktop.UPower" #define DESKTOP_FILE "/usr/share/applications/indicator-session-extra.desktop" +#define EXTRA_LAUNCHER_DIR "/usr/share/indicators/session/applications" #define GUEST_SESSION_LAUNCHER "/usr/share/gdm/guest-session/guest-session-launch" @@ -517,6 +518,19 @@ desktop_activate_cb (DbusmenuMenuitem * mi, guint timestamp, gpointer data) return; } +static void +add_extra_separator_once (DbusmenuMenuitem *menu) +{ + static gboolean added = FALSE; + + if (!added) { + DbusmenuMenuitem * separator = dbusmenu_menuitem_new(); + dbusmenu_menuitem_property_set(separator, DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_CLIENT_TYPES_SEPARATOR); + dbusmenu_menuitem_child_append(menu, separator); + added = TRUE; + } +} + /* Builds up the menu for us */ static void rebuild_items (DbusmenuMenuitem *root, @@ -529,6 +543,8 @@ rebuild_items (DbusmenuMenuitem *root, gboolean can_activate; gboolean can_lockscreen; GList *children; + GDir *extra_launchers_dir; + const gchar *extra_launcher_file; /* Make sure we have a valid GConf client, and build one if needed */ @@ -713,14 +729,34 @@ rebuild_items (DbusmenuMenuitem *root, update_menu_entries(restart_shutdown_logout_mi); + /* now add extra launchers */ + if (g_file_test(DESKTOP_FILE, G_FILE_TEST_EXISTS)) { GAppInfo * appinfo = G_APP_INFO(g_desktop_app_info_new_from_filename(DESKTOP_FILE)); if (appinfo != 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); + add_extra_separator_once (root); + DbusmenuMenuitem * desktop_mi = dbusmenu_menuitem_new(); + dbusmenu_menuitem_property_set(desktop_mi, DBUSMENU_MENUITEM_PROP_LABEL, g_app_info_get_name(appinfo)); + g_signal_connect(G_OBJECT(desktop_mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(desktop_activate_cb), appinfo); + dbusmenu_menuitem_child_append(root, desktop_mi); + } + } + + extra_launchers_dir = g_dir_open (EXTRA_LAUNCHER_DIR, 0, NULL); + if (extra_launchers_dir != NULL) { + for (;;) { + extra_launcher_file = g_dir_read_name (extra_launchers_dir); + if (extra_launcher_file == NULL) + break; + if (!g_str_has_suffix (extra_launcher_file, ".desktop")) + continue; + + gchar *full_path = g_build_filename (EXTRA_LAUNCHER_DIR, extra_launcher_file, NULL); + GAppInfo * appinfo = G_APP_INFO(g_desktop_app_info_new_from_filename (full_path)); + g_free (full_path); + add_extra_separator_once (root); DbusmenuMenuitem * desktop_mi = dbusmenu_menuitem_new(); dbusmenu_menuitem_property_set(desktop_mi, DBUSMENU_MENUITEM_PROP_LABEL, g_app_info_get_name(appinfo)); g_signal_connect(G_OBJECT(desktop_mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(desktop_activate_cb), appinfo); -- cgit v1.2.3 From 5f49c2d82c4f69d18531e73e6a7aae531a3f40d0 Mon Sep 17 00:00:00 2001 From: Martin Pitt Date: Thu, 10 Mar 2011 16:11:02 +0100 Subject: Drop support for indicator-session-extra.desktop --- src/session-service.c | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/src/session-service.c b/src/session-service.c index 579b12f..043bf20 100644 --- a/src/session-service.c +++ b/src/session-service.c @@ -54,7 +54,6 @@ with this program. If not, see . #define UP_OBJECT "/org/freedesktop/UPower" #define UP_INTERFACE "org.freedesktop.UPower" -#define DESKTOP_FILE "/usr/share/applications/indicator-session-extra.desktop" #define EXTRA_LAUNCHER_DIR "/usr/share/indicators/session/applications" #define GUEST_SESSION_LAUNCHER "/usr/share/gdm/guest-session/guest-session-launch" @@ -730,19 +729,6 @@ rebuild_items (DbusmenuMenuitem *root, update_menu_entries(restart_shutdown_logout_mi); /* now add extra launchers */ - - if (g_file_test(DESKTOP_FILE, G_FILE_TEST_EXISTS)) { - GAppInfo * appinfo = G_APP_INFO(g_desktop_app_info_new_from_filename(DESKTOP_FILE)); - - if (appinfo != NULL) { - add_extra_separator_once (root); - DbusmenuMenuitem * desktop_mi = dbusmenu_menuitem_new(); - dbusmenu_menuitem_property_set(desktop_mi, DBUSMENU_MENUITEM_PROP_LABEL, g_app_info_get_name(appinfo)); - g_signal_connect(G_OBJECT(desktop_mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(desktop_activate_cb), appinfo); - dbusmenu_menuitem_child_append(root, desktop_mi); - } - } - extra_launchers_dir = g_dir_open (EXTRA_LAUNCHER_DIR, 0, NULL); if (extra_launchers_dir != NULL) { for (;;) { -- cgit v1.2.3 From 2426a2119ad12042da1c0c77cf578b9ae0f3ff43 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 10 Mar 2011 14:54:59 -0600 Subject: Putting the appinfo's into a list so that we can sort them --- src/session-service.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/session-service.c b/src/session-service.c index 043bf20..c25939a 100644 --- a/src/session-service.c +++ b/src/session-service.c @@ -731,6 +731,8 @@ rebuild_items (DbusmenuMenuitem *root, /* now add extra launchers */ extra_launchers_dir = g_dir_open (EXTRA_LAUNCHER_DIR, 0, NULL); if (extra_launchers_dir != NULL) { + GList * launchers = NULL; + for (;;) { extra_launcher_file = g_dir_read_name (extra_launchers_dir); if (extra_launcher_file == NULL) @@ -742,12 +744,21 @@ rebuild_items (DbusmenuMenuitem *root, GAppInfo * appinfo = G_APP_INFO(g_desktop_app_info_new_from_filename (full_path)); g_free (full_path); + launchers = g_list_prepend(launchers, appinfo); + } + + GList * launcher = NULL; + for (launcher = launchers; launcher != NULL; launcher = g_list_next(launcher)) { + GAppInfo * appinfo = G_APP_INFO(launcher->data); + add_extra_separator_once (root); DbusmenuMenuitem * desktop_mi = dbusmenu_menuitem_new(); dbusmenu_menuitem_property_set(desktop_mi, DBUSMENU_MENUITEM_PROP_LABEL, g_app_info_get_name(appinfo)); g_signal_connect(G_OBJECT(desktop_mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(desktop_activate_cb), appinfo); dbusmenu_menuitem_child_append(root, desktop_mi); } + + g_list_free(launchers); } return; -- cgit v1.2.3 From 454b91173c9cf0b43993b4b9304b7d8449cd8640 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 10 Mar 2011 14:55:37 -0600 Subject: Closing the directory after we're done with it --- src/session-service.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/session-service.c b/src/session-service.c index c25939a..72f2139 100644 --- a/src/session-service.c +++ b/src/session-service.c @@ -746,6 +746,7 @@ rebuild_items (DbusmenuMenuitem *root, launchers = g_list_prepend(launchers, appinfo); } + g_dir_close(extra_launchers_dir); GList * launcher = NULL; for (launcher = launchers; launcher != NULL; launcher = g_list_next(launcher)) { -- cgit v1.2.3 From 80719b658bbd8f49c15b43e841370fc5ba509246 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 10 Mar 2011 14:56:45 -0600 Subject: Reducing the scope of some of our variables --- src/session-service.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/session-service.c b/src/session-service.c index 72f2139..28284ff 100644 --- a/src/session-service.c +++ b/src/session-service.c @@ -542,8 +542,6 @@ rebuild_items (DbusmenuMenuitem *root, gboolean can_activate; gboolean can_lockscreen; GList *children; - GDir *extra_launchers_dir; - const gchar *extra_launcher_file; /* Make sure we have a valid GConf client, and build one if needed */ @@ -729,11 +727,14 @@ rebuild_items (DbusmenuMenuitem *root, update_menu_entries(restart_shutdown_logout_mi); /* now add extra launchers */ + GDir *extra_launchers_dir; extra_launchers_dir = g_dir_open (EXTRA_LAUNCHER_DIR, 0, NULL); if (extra_launchers_dir != NULL) { GList * launchers = NULL; for (;;) { + const gchar *extra_launcher_file; + extra_launcher_file = g_dir_read_name (extra_launchers_dir); if (extra_launcher_file == NULL) break; -- cgit v1.2.3 From cb771e5da44cda7b8fc6ca07be44aa1d5048660b Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 10 Mar 2011 15:04:33 -0600 Subject: Sort the launchers --- src/session-service.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/session-service.c b/src/session-service.c index 28284ff..c76865d 100644 --- a/src/session-service.c +++ b/src/session-service.c @@ -517,6 +517,28 @@ desktop_activate_cb (DbusmenuMenuitem * mi, guint timestamp, gpointer data) return; } +/* Look at the GAppInfo structures and sort based on + the application names */ +static gint +sort_app_infos (gconstpointer a, gconstpointer b) +{ + GAppInfo * appa = G_APP_INFO(a); + GAppInfo * appb = G_APP_INFO(b); + + const gchar * namea = NULL; + const gchar * nameb = NULL; + + if (appa != NULL) { + namea = g_app_info_get_name(appa); + } + + if (appb != NULL) { + nameb = g_app_info_get_name(appb); + } + + return g_strcmp0(namea, nameb); +} + static void add_extra_separator_once (DbusmenuMenuitem *menu) { @@ -749,6 +771,8 @@ rebuild_items (DbusmenuMenuitem *root, } g_dir_close(extra_launchers_dir); + launchers = g_list_sort(launchers, sort_app_infos); + GList * launcher = NULL; for (launcher = launchers; launcher != NULL; launcher = g_list_next(launcher)) { GAppInfo * appinfo = G_APP_INFO(launcher->data); -- cgit v1.2.3 From 81022fc8b072cb04d3f2ebe8841c2f0b865870b7 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 10 Mar 2011 15:09:45 -0600 Subject: Add some cleanup and some comments --- src/session-service.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/session-service.c b/src/session-service.c index c76865d..123a12b 100644 --- a/src/session-service.c +++ b/src/session-service.c @@ -754,6 +754,7 @@ rebuild_items (DbusmenuMenuitem *root, if (extra_launchers_dir != NULL) { GList * launchers = NULL; + /* Find all the desktop files we want to use */ for (;;) { const gchar *extra_launcher_file; @@ -771,16 +772,24 @@ rebuild_items (DbusmenuMenuitem *root, } g_dir_close(extra_launchers_dir); + /* Sort the desktop files based on their names */ launchers = g_list_sort(launchers, sort_app_infos); + /* Turn each one into a separate menu item */ GList * launcher = NULL; for (launcher = launchers; launcher != NULL; launcher = g_list_next(launcher)) { GAppInfo * appinfo = G_APP_INFO(launcher->data); + /* Make sure we have a separator */ add_extra_separator_once (root); + + /* Build the item */ DbusmenuMenuitem * desktop_mi = dbusmenu_menuitem_new(); dbusmenu_menuitem_property_set(desktop_mi, DBUSMENU_MENUITEM_PROP_LABEL, g_app_info_get_name(appinfo)); g_signal_connect(G_OBJECT(desktop_mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(desktop_activate_cb), appinfo); + g_object_weak_ref(G_OBJECT(desktop_mi), (GWeakNotify)g_object_unref, appinfo); + + /* Put into the menu */ dbusmenu_menuitem_child_append(root, desktop_mi); } -- cgit v1.2.3 From 5cf62744287e975ba81a27f08ee9f273b1a426b2 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 10 Mar 2011 15:22:57 -0600 Subject: Embed the function so it's not one separator ever, but once per run --- src/session-service.c | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/src/session-service.c b/src/session-service.c index 123a12b..eb045c1 100644 --- a/src/session-service.c +++ b/src/session-service.c @@ -539,19 +539,6 @@ sort_app_infos (gconstpointer a, gconstpointer b) return g_strcmp0(namea, nameb); } -static void -add_extra_separator_once (DbusmenuMenuitem *menu) -{ - static gboolean added = FALSE; - - if (!added) { - DbusmenuMenuitem * separator = dbusmenu_menuitem_new(); - dbusmenu_menuitem_property_set(separator, DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_CLIENT_TYPES_SEPARATOR); - dbusmenu_menuitem_child_append(menu, separator); - added = TRUE; - } -} - /* Builds up the menu for us */ static void rebuild_items (DbusmenuMenuitem *root, @@ -777,11 +764,18 @@ rebuild_items (DbusmenuMenuitem *root, /* Turn each one into a separate menu item */ GList * launcher = NULL; + gboolean sepadded = FALSE; for (launcher = launchers; launcher != NULL; launcher = g_list_next(launcher)) { GAppInfo * appinfo = G_APP_INFO(launcher->data); /* Make sure we have a separator */ - add_extra_separator_once (root); + if (!sepadded) { + DbusmenuMenuitem * separator = dbusmenu_menuitem_new(); + dbusmenu_menuitem_property_set(separator, DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_CLIENT_TYPES_SEPARATOR); + dbusmenu_menuitem_child_append(root, separator); + g_object_unref(separator); + sepadded = TRUE; + } /* Build the item */ DbusmenuMenuitem * desktop_mi = dbusmenu_menuitem_new(); -- cgit v1.2.3 From ed671c80bf5729a6b1cddc6f92b48899a3e6ae94 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 10 Mar 2011 15:49:10 -0600 Subject: Add the --no-lock option to activate the session. --- src/session-service.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/session-service.c b/src/session-service.c index eb045c1..dc53f74 100644 --- a/src/session-service.c +++ b/src/session-service.c @@ -424,7 +424,7 @@ activate_guest_session (DbusmenuMenuitem * mi, guint timestamp, gpointer user_da g_warning("Unable to activate guest session, falling back to command line activation."); } - if (!g_spawn_command_line_async(GUEST_SESSION_LAUNCHER, &error)) { + if (!g_spawn_command_line_async(GUEST_SESSION_LAUNCHER " --no-lock", &error)) { g_warning("Unable to start guest session: %s", error->message); g_error_free(error); } -- cgit v1.2.3 From 7db402b6a67a54a39125d944441aa84c4b268963 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 10 Mar 2011 16:02:01 -0600 Subject: 0.2.15 --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index e12c744..724831f 100644 --- a/configure.ac +++ b/configure.ac @@ -4,7 +4,7 @@ AC_INIT(src/indicator-session.c) AC_PREREQ(2.53) AM_CONFIG_HEADER(config.h) -AM_INIT_AUTOMAKE(indicator-session, 0.2.14) +AM_INIT_AUTOMAKE(indicator-session, 0.2.15) AM_MAINTAINER_MODE -- cgit v1.2.3 From 6e0ddb7fa7839fc676ff90792afe386125b8e771 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 10 Mar 2011 16:10:22 -0600 Subject: releasing version 0.2.15-0ubuntu1~ppa1 --- debian/changelog | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/debian/changelog b/debian/changelog index 249e40b..9b9246e 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,4 +1,4 @@ -indicator-session (0.2.15-0ubuntu1~ppa1) UNRELEASED; urgency=low +indicator-session (0.2.15-0ubuntu1~ppa1) natty; urgency=low * New upstream release. ∘ Support adding arbitrary items to the end of the session @@ -6,7 +6,7 @@ indicator-session (0.2.15-0ubuntu1~ppa1) UNRELEASED; urgency=low ∘ Call guest session with --no-lock to ensure there is no double locking (LP: #636693) - -- Ted Gould Thu, 10 Mar 2011 16:07:19 -0600 + -- Ted Gould Thu, 10 Mar 2011 16:10:19 -0600 indicator-session (0.2.14-0ubuntu1) natty; urgency=low -- cgit v1.2.3