From 21266a4e713b262de0a931e668723d78f7278535 Mon Sep 17 00:00:00 2001 From: Wu Xiaotian Date: Mon, 1 Jul 2019 18:15:34 +0800 Subject: launch lightdm-settings if installed --- capplets/accessibility/at-properties/main.c | 50 ++++++++++++++++------------- 1 file changed, 28 insertions(+), 22 deletions(-) (limited to 'capplets/accessibility/at-properties/main.c') diff --git a/capplets/accessibility/at-properties/main.c b/capplets/accessibility/at-properties/main.c index 44e07563..83bbe8f4 100644 --- a/capplets/accessibility/at-properties/main.c +++ b/capplets/accessibility/at-properties/main.c @@ -1,6 +1,7 @@ #include #include #include +#include #include "dm-util.h" #include @@ -24,6 +25,23 @@ enum { static gboolean initial_state; +static GDesktopAppInfo *get_desktop_app_info_from_dm (void) +{ + DMType dm_type; + GDesktopAppInfo *app_info = NULL; + + dm_type = dm_get_type(); + if (dm_type == DM_TYPE_MDM) { + app_info = g_desktop_app_info_new ("mdmsetup.desktop"); + } else if (dm_type == DM_TYPE_LIGHTDM) { + app_info = g_desktop_app_info_new ("lightdm-settings.desktop"); + if (app_info == NULL) { + app_info = g_desktop_app_info_new ("lightdm-gtk-greeter-settings.desktop"); + } + } + return app_info; +} + static GtkBuilder * create_builder (void) { @@ -34,8 +52,7 @@ create_builder (void) if (gtk_builder_add_from_resource (builder, "/org/mate/mcc/accessibility/at/at-enable-dialog.ui", &error)) { GObject *object; - gchar *prog = NULL; - DMType dm_type; + GDesktopAppInfo *app_info = NULL; object = gtk_builder_get_object (builder, "at_enable_image"); gtk_image_set_from_file (GTK_IMAGE (object), @@ -45,18 +62,13 @@ create_builder (void) "at_applications_image"); gtk_image_set_from_file (GTK_IMAGE (object), PIXMAPDIR "/at-support.png"); - - dm_type = dm_get_type(); - if (dm_type == DM_TYPE_MDM) { - prog = g_find_program_in_path ("mdmsetup"); - } else if (dm_type == DM_TYPE_LIGHTDM) { - prog = g_find_program_in_path ("lightdm-gtk-greeter-settings-pkexec"); - } - if (prog == NULL) { + app_info = get_desktop_app_info_from_dm (); + if (app_info == NULL) { object = gtk_builder_get_object (builder, "login_button"); gtk_widget_hide (GTK_WIDGET (object)); + } else { + g_object_unref (app_info); } - g_free (prog); } else { g_warning ("Could not load UI: %s", error->message); @@ -89,19 +101,13 @@ cb_mouse_preferences (GtkDialog *dialog, gint response_id) static void cb_login_preferences (GtkDialog *dialog, gint response_id) { - DMType dm_type; - gchar *prog = NULL; + GDesktopAppInfo *app_info = NULL; - dm_type = dm_get_type(); - if (dm_type == DM_TYPE_MDM) { - prog = g_find_program_in_path ("mdmsetup"); - } else if (dm_type == DM_TYPE_LIGHTDM) { - prog = g_find_program_in_path ("lightdm-gtk-greeter-settings-pkexec"); - } + app_info = get_desktop_app_info_from_dm (); - if (prog != NULL) { - g_spawn_command_line_async (prog, NULL); - g_free(prog); + if (app_info != NULL) { + g_app_info_launch (G_APP_INFO(app_info), NULL, NULL, NULL); + g_object_unref (app_info); } } -- cgit v1.2.1