[gnome-software] Only enable the firmware 'Install' button when the device is in the right mode



commit 041f69a7bb3b1cf4ac2a50adc5395619e3ccc68c
Author: Richard Hughes <richard hughsie com>
Date:   Fri Aug 19 14:18:52 2016 +0100

    Only enable the firmware 'Install' button when the device is in the right mode
    
    This needs fwupd and appstream-glib from git master to work correctly.

 src/gs-page.c                 |   25 +++++++++++++++++++++++--
 src/plugins/gs-plugin-fwupd.c |    2 ++
 2 files changed, 25 insertions(+), 2 deletions(-)
---
diff --git a/src/gs-page.c b/src/gs-page.c
index d91cf26..19e5f42 100644
--- a/src/gs-page.c
+++ b/src/gs-page.c
@@ -46,11 +46,15 @@ typedef struct {
        GsPage          *page;
        GCancellable    *cancellable;
        SoupSession     *soup_session;
+       gulong           notify_quirk_id;
+       GtkWidget       *button_install;
 } GsPageHelper;
 
 static void
 gs_page_helper_free (GsPageHelper *helper)
 {
+       if (helper->notify_quirk_id > 0)
+               g_signal_handler_disconnect (helper->app, helper->notify_quirk_id);
        if (helper->app != NULL)
                g_object_unref (helper->app);
        if (helper->page != NULL)
@@ -346,6 +350,14 @@ gs_page_update_app_response_cb (GtkDialog *dialog,
 }
 
 static void
+gs_page_notify_quirk_cb (GsApp *app, GParamSpec *pspec, GsPageHelper *helper)
+{
+       gtk_widget_set_sensitive (helper->button_install,
+                                 !gs_app_has_quirk (helper->app,
+                                                    AS_APP_QUIRK_NEEDS_USER_ACTION));
+}
+
+static void
 gs_page_needs_user_action (GsPageHelper *helper, AsScreenshot *ss)
 {
        GtkWidget *content_area;
@@ -366,8 +378,17 @@ gs_page_needs_user_action (GsPageHelper *helper, AsScreenshot *ss)
        escaped = g_markup_escape_text (as_screenshot_get_caption (ss, NULL), -1);
        gtk_message_dialog_format_secondary_markup (GTK_MESSAGE_DIALOG (dialog),
                                                    "%s", escaped);
-       /* TRANSLATORS: this is button text to update the firware */
-       gtk_dialog_add_button (GTK_DIALOG (dialog), _("Install"), GTK_RESPONSE_OK);
+
+       /* this will be enabled when the device is in the right mode */
+       helper->button_install = gtk_dialog_add_button (GTK_DIALOG (dialog),
+                                                       /* TRANSLATORS: update the fw */
+                                                       _("Install"),
+                                                       GTK_RESPONSE_OK);
+       helper->notify_quirk_id =
+               g_signal_connect (helper->app, "notify::quirk",
+                                 G_CALLBACK (gs_page_notify_quirk_cb),
+                                 helper);
+       gtk_widget_set_sensitive (helper->button_install, FALSE);
 
        /* load screenshot */
        helper->soup_session = soup_session_new_with_options (SOUP_SESSION_USER_AGENT,
diff --git a/src/plugins/gs-plugin-fwupd.c b/src/plugins/gs-plugin-fwupd.c
index 84f8a90..d4d08e8 100644
--- a/src/plugins/gs-plugin-fwupd.c
+++ b/src/plugins/gs-plugin-fwupd.c
@@ -365,6 +365,8 @@ gs_plugin_fwupd_new_app_from_results (GsPlugin *plugin, FwupdResult *res)
        /* needs action */
        if (fwupd_result_has_device_flag (res, FU_DEVICE_FLAG_NEEDS_BOOTLOADER))
                gs_app_add_quirk (app, AS_APP_QUIRK_NEEDS_USER_ACTION);
+       else
+               gs_app_remove_quirk (app, AS_APP_QUIRK_NEEDS_USER_ACTION);
 #endif
 
        /* the same as we have already */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]