diff options
-rw-r--r-- | src/actions.c | 12 | ||||
-rw-r--r-- | src/actions.h | 6 | ||||
-rw-r--r-- | src/backend-dbus/actions.c | 12 | ||||
-rw-r--r-- | src/service.c | 106 | ||||
-rw-r--r-- | src/utils.c | 110 | ||||
-rw-r--r-- | src/utils.h | 6 | ||||
-rw-r--r-- | tests/backend-mock-actions.c | 13 | ||||
-rw-r--r-- | tests/test-service.cc | 12 |
8 files changed, 178 insertions, 99 deletions
diff --git a/src/actions.c b/src/actions.c index 563f626..5c5c624 100644 --- a/src/actions.c +++ b/src/actions.c @@ -282,11 +282,19 @@ indicator_session_actions_power_off (IndicatorSessionActions * self) } void -indicator_session_actions_help (IndicatorSessionActions * self) +indicator_session_actions_desktop_help (IndicatorSessionActions * self) { g_return_if_fail (INDICATOR_IS_SESSION_ACTIONS (self)); - INDICATOR_SESSION_ACTIONS_GET_CLASS (self)->help (self); + INDICATOR_SESSION_ACTIONS_GET_CLASS (self)->desktop_help (self); +} + +void +indicator_session_actions_distro_help (IndicatorSessionActions * self) +{ + g_return_if_fail (INDICATOR_IS_SESSION_ACTIONS (self)); + + INDICATOR_SESSION_ACTIONS_GET_CLASS (self)->distro_help (self); } void diff --git a/src/actions.h b/src/actions.h index e31685e..be13dc7 100644 --- a/src/actions.h +++ b/src/actions.h @@ -75,7 +75,8 @@ struct _IndicatorSessionActionsClass void (*logout) (IndicatorSessionActions * self); void (*reboot) (IndicatorSessionActions * self); void (*power_off) (IndicatorSessionActions * self); - void (*help) (IndicatorSessionActions * self); + void (*desktop_help) (IndicatorSessionActions * self); + void (*distro_help) (IndicatorSessionActions * self); void (*about) (IndicatorSessionActions * self); void (*settings) (IndicatorSessionActions * self); void (*online_accounts) (IndicatorSessionActions * self); @@ -119,7 +120,8 @@ void indicator_session_actions_logout (IndicatorSession void indicator_session_actions_reboot (IndicatorSessionActions * self); void indicator_session_actions_power_off (IndicatorSessionActions * self); -void indicator_session_actions_help (IndicatorSessionActions * self); +void indicator_session_actions_desktop_help (IndicatorSessionActions * self); +void indicator_session_actions_distro_help (IndicatorSessionActions * self); void indicator_session_actions_about (IndicatorSessionActions * self); void indicator_session_actions_settings (IndicatorSessionActions * self); void indicator_session_actions_online_accounts (IndicatorSessionActions * self); diff --git a/src/backend-dbus/actions.c b/src/backend-dbus/actions.c index d2b7fbb..1836d94 100644 --- a/src/backend-dbus/actions.c +++ b/src/backend-dbus/actions.c @@ -914,7 +914,7 @@ my_power_off (IndicatorSessionActions * actions) ***/ static void -my_help (IndicatorSessionActions * self G_GNUC_UNUSED) +my_desktop_help (IndicatorSessionActions * self G_GNUC_UNUSED) { if (have_mate_program ("yelp")) run_outside_app ("yelp help:mate-user-guide"); @@ -922,6 +922,13 @@ my_help (IndicatorSessionActions * self G_GNUC_UNUSED) run_outside_app ("yelp"); } +static void +my_distro_help (IndicatorSessionActions * self G_GNUC_UNUSED) +{ + run_outside_app(g_strdup_printf("x-www-browser '%s'", get_distro_url())); +} + + static gboolean have_unity_control_center (void) { @@ -1164,7 +1171,8 @@ indicator_session_actions_dbus_class_init (IndicatorSessionActionsDbusClass * kl actions_class->power_off = my_power_off; actions_class->settings = my_settings; actions_class->online_accounts = my_online_accounts; - actions_class->help = my_help; + actions_class->desktop_help = my_desktop_help; + actions_class->distro_help = my_distro_help; actions_class->about = my_about; actions_class->switch_to_screensaver = my_switch_to_screensaver; actions_class->switch_to_greeter = my_switch_to_greeter; diff --git a/src/service.c b/src/service.c index 401bc56..c506e6f 100644 --- a/src/service.c +++ b/src/service.c @@ -336,94 +336,18 @@ get_current_real_name (IndicatorSessionService * self) return ""; } -/*** -**** -***/ - -static GHashTable* -get_os_release (void) -{ - static const char * const os_release = "/etc/os-release"; - GHashTable * hash; - GIOChannel * io; - - hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); - - if ((io = g_io_channel_new_file (os_release, "r", NULL))) - { - GString * key = g_string_new (NULL); - - for (;;) - { - GIOStatus status; - char * in; - GError * error; - gchar * val; - - /* read a line */ - status = g_io_channel_read_line_string (io, key, NULL, NULL); - if (status == G_IO_STATUS_EOF) - break; - - /* ignore blank lines & comments */ - if (!key->len || key->str[0]=='#') - continue; - - /* split into key=value */ - in = strchr(key->str, '='); - if (!in) - continue; - *in++ = '\0'; - - /* unmunge the value component */ - g_strstrip(in); /* eat linefeed */ - error = NULL; - val = g_shell_unquote (in, &error); - if (error != NULL) - { - g_warning("Unable to unquote \"%s\": %s", in, error->message); - val = g_strdup(in); - g_clear_error(&error); - } - - g_debug("from \"%s\": key [%s] val [%s]", os_release, key->str, val); - g_hash_table_insert (hash, g_strdup(key->str), val); /* hash owns val now */ - } - - g_string_free(key, TRUE); - g_io_channel_unref(io); - } - - return hash; -} - -static const char* -get_distro_name (void) -{ - static char * distro_name = NULL; - - if (distro_name == NULL) - { - GHashTable * os_release = get_os_release(); - gpointer value = g_hash_table_lookup(os_release, "NAME"); - if (value == NULL) - value = "Ubuntu"; /* fallback value */ - distro_name = g_strdup(value); - g_hash_table_destroy(os_release); - } - - return distro_name; -} - static GMenuModel * create_admin_section (void) { GMenu * menu; - gchar * help_label = g_strdup_printf(_("%s Help"), get_distro_name()); + gchar * desktop_help_label = g_strdup_printf(_("%s Desktop Help"), get_desktop_name()); + gchar * distro_help_label = g_strdup_printf(_("%s Help"), get_distro_name()); menu = g_menu_new (); g_menu_append (menu, _("About This Computer"), "indicator.about"); - g_menu_append (menu, help_label, "indicator.help"); - g_free (help_label); + g_menu_append (menu, desktop_help_label, "indicator.desktop_help"); + g_menu_append (menu, distro_help_label, "indicator.distro_help"); + g_free (desktop_help_label); + g_free (distro_help_label); return G_MENU_MODEL (menu); } @@ -890,11 +814,18 @@ on_online_accounts_activated (GSimpleAction * a G_GNUC_UNUSED, } static void -on_help_activated (GSimpleAction * a G_GNUC_UNUSED, - GVariant * param G_GNUC_UNUSED, - gpointer gself) +on_desktop_help_activated (GSimpleAction * a G_GNUC_UNUSED, + GVariant * param G_GNUC_UNUSED, + gpointer gself) +{ + indicator_session_actions_desktop_help (get_backend_actions(gself)); +} +static void +on_distro_help_activated (GSimpleAction * a G_GNUC_UNUSED, + GVariant * param G_GNUC_UNUSED, + gpointer gself) { - indicator_session_actions_help (get_backend_actions(gself)); + indicator_session_actions_distro_help (get_backend_actions(gself)); } static void @@ -988,7 +919,8 @@ init_gactions (IndicatorSessionService * self) GActionEntry entries[] = { { "about", on_about_activated }, - { "help", on_help_activated }, + { "desktop_help", on_desktop_help_activated }, + { "distro_help", on_distro_help_activated }, { "hibernate", on_hibernate_activated }, { "logout", on_logout_activated }, { "online-accounts", on_online_accounts_activated }, diff --git a/src/utils.c b/src/utils.c index 30ce341..4bc6d68 100644 --- a/src/utils.c +++ b/src/utils.c @@ -78,3 +78,113 @@ is_mate () } return FALSE; } + +GHashTable* +get_os_release (void) +{ + static const char * const os_release = "/etc/os-release"; + GHashTable * hash; + GIOChannel * io; + + hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); + + if ((io = g_io_channel_new_file (os_release, "r", NULL))) + { + GString * key = g_string_new (NULL); + + for (;;) + { + GIOStatus status; + char * in; + GError * error; + gchar * val; + + /* read a line */ + status = g_io_channel_read_line_string (io, key, NULL, NULL); + if (status == G_IO_STATUS_EOF) + break; + + /* ignore blank lines & comments */ + if (!key->len || key->str[0]=='#') + continue; + + /* split into key=value */ + in = strchr(key->str, '='); + if (!in) + continue; + *in++ = '\0'; + + /* unmunge the value component */ + g_strstrip(in); /* eat linefeed */ + error = NULL; + val = g_shell_unquote (in, &error); + if (error != NULL) + { + g_warning("Unable to unquote \"%s\": %s", in, error->message); + val = g_strdup(in); + g_clear_error(&error); + } + + g_debug("from \"%s\": key [%s] val [%s]", os_release, key->str, val); + g_hash_table_insert (hash, g_strdup(key->str), val); /* hash owns val now */ + } + + g_string_free(key, TRUE); + g_io_channel_unref(io); + } + + return hash; +} + +const char* +get_distro_name (void) +{ + static char * distro_name = NULL; + + if (distro_name == NULL) + { + GHashTable * os_release = get_os_release(); + gpointer value = g_hash_table_lookup(os_release, "NAME"); + if (value == NULL) + value = "GNU/Linux"; /* fallback value */ + distro_name = g_strdup(value); + g_hash_table_destroy(os_release); + } + + return distro_name; +} + +const char* +get_distro_url (void) +{ + static char * distro_url = NULL; + + if (distro_url == NULL) + { + GHashTable * os_release = get_os_release(); + gpointer value = g_hash_table_lookup(os_release, "HOME_URL"); + if (value == NULL) + value = "https://www.gnu.org"; /* fallback value */ + distro_url = g_strdup(value); + g_hash_table_destroy(os_release); + } + + return distro_url; +} + +const char* +get_desktop_name (void) +{ + static char * desktop_name = NULL; + const char * xdg_current_desktop; + + if (desktop_name == NULL) + { + xdg_current_desktop = g_getenv ("XDG_CURRENT_DESKTOP"); + if (xdg_current_desktop != NULL) { + desktop_name = g_strsplit (xdg_current_desktop, ":", 0)[0]; + } + } + + return desktop_name; +} diff --git a/src/utils.h b/src/utils.h index f431f85..bb9e750 100644 --- a/src/utils.h +++ b/src/utils.h @@ -18,9 +18,15 @@ #define __INDICATOR_SESSION_UTILS_H__ #include <glib.h> +#include <string.h> gboolean is_unity(); gboolean is_gnome(); gboolean is_mate(); +const char* get_distro_name(); +const char* get_distro_url(); +const char* get_desktop_name(); +GHashTable* get_os_release(); + #endif /* __INDICATOR_SESSION_UTILS_H__ */ diff --git a/tests/backend-mock-actions.c b/tests/backend-mock-actions.c index 25a606f..15a0bd9 100644 --- a/tests/backend-mock-actions.c +++ b/tests/backend-mock-actions.c @@ -124,9 +124,15 @@ my_switch_to_username (IndicatorSessionActions * self G_GNUC_UNUSED, } static void -my_help (IndicatorSessionActions * self G_GNUC_UNUSED) +my_desktop_help (IndicatorSessionActions * self G_GNUC_UNUSED) { - g_settings_set_string (mock_settings, "last-command", "help"); + g_settings_set_string (mock_settings, "last-command", "desktop_help"); +} + +static void +my_distro_help (IndicatorSessionActions * self G_GNUC_UNUSED) +{ + g_settings_set_string (mock_settings, "last-command", "distro_help"); } static void @@ -202,7 +208,8 @@ indicator_session_actions_mock_class_init (IndicatorSessionActionsMockClass * kl actions_class->power_off = my_power_off; actions_class->settings = my_settings; actions_class->online_accounts = my_online_accounts; - actions_class->help = my_help; + actions_class->desktop_help = my_desktop_help; + actions_class->distro_help = my_distro_help; actions_class->about = my_about; actions_class->switch_to_screensaver = my_switch_to_screensaver; actions_class->switch_to_greeter = my_switch_to_greeter; diff --git a/tests/test-service.cc b/tests/test-service.cc index 7dae887..ddb02d6 100644 --- a/tests/test-service.cc +++ b/tests/test-service.cc @@ -383,9 +383,14 @@ TEST_F (ServiceTest, About) test_simple_action ("about"); } -TEST_F (ServiceTest, Help) +TEST_F (ServiceTest, DesktopHelp) { - test_simple_action ("help"); + test_simple_action ("desktop_help"); +} + +TEST_F (ServiceTest, DistroHelp) +{ + test_simple_action ("distro_help"); } TEST_F (ServiceTest, Hibernate) @@ -693,7 +698,8 @@ TEST_F (ServiceTest, LockdownUserSwitchingAndLockScreen) TEST_F (ServiceTest, DefaultMenuItems) { ASSERT_TRUE (find_menu_item_for_action ("indicator.about", NULL, NULL)); - ASSERT_TRUE (find_menu_item_for_action ("indicator.help", NULL, NULL)); + ASSERT_TRUE (find_menu_item_for_action ("indicator.desktop_help", NULL, NULL)); + ASSERT_TRUE (find_menu_item_for_action ("indicator.distro_help", NULL, NULL)); ASSERT_TRUE (find_menu_item_for_action ("indicator.settings", NULL, NULL)); ASSERT_TRUE (find_menu_item_for_action ("indicator.switch-to-screensaver", NULL, NULL)); ASSERT_TRUE (find_menu_item_for_action ("indicator.switch-to-guest", NULL, NULL)); |