[seahorse/wip/nielsdg/cleanup-pgp-more: 2/6] pgp: destroy Search dialog before showing the results



commit 8047fac9edd972cedb1b9cbc4681ca9358c43dd2
Author: Niels De Graef <nielsdegraef gmail com>
Date:   Tue Jan 29 08:09:28 2019 +0100

    pgp: destroy Search dialog before showing the results
    
    Otherwise, the new GtkDialog won't be run properly.

 pgp/seahorse-keyserver-search.c  | 28 ++++++++++------------------
 pgp/seahorse-keyserver-search.h  |  2 ++
 pgp/seahorse-keyserver-search.ui |  4 ++--
 pgp/seahorse-pgp-actions.c       | 28 ++++++++++++++++++++++++----
 4 files changed, 38 insertions(+), 24 deletions(-)
---
diff --git a/pgp/seahorse-keyserver-search.c b/pgp/seahorse-keyserver-search.c
index 3fba45af..ecdedcd6 100644
--- a/pgp/seahorse-keyserver-search.c
+++ b/pgp/seahorse-keyserver-search.c
@@ -43,7 +43,6 @@ struct _SeahorseKeyserverSearch {
        GtkWidget *search_entry;
        GtkWidget *key_server_list;
        GtkWidget *shared_keys_list;
-       GtkWidget *searchbutton;
 };
 
 G_DEFINE_TYPE (SeahorseKeyserverSearch, seahorse_keyserver_search, GTK_TYPE_DIALOG)
@@ -167,7 +166,7 @@ have_keyserver_selection (SeahorseKeyserverSearch *self)
 static void
 on_keyserver_search_control_changed (GtkWidget *widget, gpointer user_data)
 {
-       SeahorseKeyserverSearch *self = SEAHORSE_KEYSERVER_SEARCH (user_data);
+    SeahorseKeyserverSearch *self = SEAHORSE_KEYSERVER_SEARCH (user_data);
     gboolean enabled = TRUE;
 
     /* Need to have at least one key server selected ... */
@@ -183,7 +182,7 @@ on_keyserver_search_control_changed (GtkWidget *widget, gpointer user_data)
             enabled = FALSE;
     }
 
-    gtk_widget_set_sensitive (self->searchbutton, enabled);
+    gtk_dialog_set_response_sensitive (GTK_DIALOG (self), GTK_RESPONSE_ACCEPT, enabled);
 }
 
 /* Initial Selection -------------------------------------------------------- */
@@ -338,6 +337,14 @@ refresh_shared_keys (SeahorseDiscovery *ssd,
 
 /* -------------------------------------------------------------------------- */
 
+gchar *
+seahorse_keyserver_search_get_search_text (SeahorseKeyserverSearch *self)
+{
+       g_return_val_if_fail (SEAHORSE_IS_KEYSERVER_SEARCH (self), NULL);
+
+       return g_strdup (gtk_entry_get_text (GTK_ENTRY (self->search_entry)));
+}
+
 /* Extracts data, stores it in settings and starts a search using the entered
  * search data. */
 static void
@@ -345,13 +352,6 @@ on_keyserver_search_ok_clicked (GtkButton *button, gpointer user_data)
 {
        SeahorseKeyserverSearch *self = SEAHORSE_KEYSERVER_SEARCH (user_data);
        KeyserverSelection *selection;
-       const gchar *search;
-       GtkWindow *parent;
-
-       /* Get search text and save it for next time */
-       search = gtk_entry_get_text (GTK_ENTRY (self->search_entry));
-       g_return_if_fail (search != NULL && search[0] != 0);
-       seahorse_app_settings_set_last_search_text (seahorse_app_settings_instance (), search);
 
        /* The keyservers to search, and save for next time */
        selection = get_keyserver_selection (self);
@@ -359,13 +359,6 @@ on_keyserver_search_ok_clicked (GtkButton *button, gpointer user_data)
        g_settings_set_strv (G_SETTINGS (seahorse_app_settings_instance ()), "last-search-servers",
                             selection->all ? NULL : (const gchar * const*)selection->uris->pdata);
 
-       /* Open the new result window; its transient parent is *our* transient
-        * parent (Seahorse's primary window), not ourselves, as *we* will
-        * disappear when "OK" is clicked.
-        */
-       parent = gtk_window_get_transient_for (GTK_WINDOW (self));
-       seahorse_keyserver_results_show (search, parent);
-
        free_keyserver_selection (selection);
 }
 
@@ -419,7 +412,6 @@ seahorse_keyserver_search_class_init (SeahorseKeyserverSearchClass *klass)
        gtk_widget_class_bind_template_child (widget_class, SeahorseKeyserverSearch, search_entry);
        gtk_widget_class_bind_template_child (widget_class, SeahorseKeyserverSearch, key_server_list);
        gtk_widget_class_bind_template_child (widget_class, SeahorseKeyserverSearch, shared_keys_list);
-       gtk_widget_class_bind_template_child (widget_class, SeahorseKeyserverSearch, searchbutton);
 
        gtk_widget_class_bind_template_callback (widget_class, on_keyserver_search_control_changed);
        gtk_widget_class_bind_template_callback (widget_class, on_keyserver_search_ok_clicked);
diff --git a/pgp/seahorse-keyserver-search.h b/pgp/seahorse-keyserver-search.h
index ba98d9f2..89990ac3 100644
--- a/pgp/seahorse-keyserver-search.h
+++ b/pgp/seahorse-keyserver-search.h
@@ -29,3 +29,5 @@ G_DECLARE_FINAL_TYPE (SeahorseKeyserverSearch, seahorse_keyserver_search,
                       GtkDialog)
 
 SeahorseKeyserverSearch *         seahorse_keyserver_search_new      (GtkWindow *parent);
+
+gchar *    seahorse_keyserver_search_get_search_text (SeahorseKeyserverSearch *self);
diff --git a/pgp/seahorse-keyserver-search.ui b/pgp/seahorse-keyserver-search.ui
index 275d94b5..f12d5d28 100644
--- a/pgp/seahorse-keyserver-search.ui
+++ b/pgp/seahorse-keyserver-search.ui
@@ -147,8 +147,8 @@
       </object>
     </child>
     <action-widgets>
-      <action-widget response="-6">cancelbutton</action-widget>
-      <action-widget response="-5" default="true">searchbutton</action-widget>
+      <action-widget response="cancel">cancelbutton</action-widget>
+      <action-widget response="accept" default="true">searchbutton</action-widget>
     </action-widgets>
   </template>
 </interface>
diff --git a/pgp/seahorse-pgp-actions.c b/pgp/seahorse-pgp-actions.c
index 1982044f..677595bb 100644
--- a/pgp/seahorse-pgp-actions.c
+++ b/pgp/seahorse-pgp-actions.c
@@ -30,6 +30,7 @@
 #include "seahorse-pgp-backend.h"
 #include "seahorse-pgp-actions.h"
 #include "seahorse-pgp-dialogs.h"
+#include "seahorse-keyserver-results.h"
 #include "seahorse-keyserver-search.h"
 #include "seahorse-keyserver-sync.h"
 
@@ -65,12 +66,31 @@ on_remote_find (GSimpleAction *action,
 {
   SeahorseActionGroup *actions = SEAHORSE_ACTION_GROUP (user_data);
   SeahorseCatalog *catalog = NULL;
-  g_autoptr(SeahorseKeyserverSearch) search = NULL;
+  g_autoptr(SeahorseKeyserverSearch) search_dialog = NULL;
+  gint response;
+  g_autofree gchar *search_text = NULL;
 
+  /* Make a new "Find remote keys" dialog */
   catalog = seahorse_action_group_get_catalog (actions);
-  search = seahorse_keyserver_search_new (GTK_WINDOW (catalog));
-  gtk_dialog_run (GTK_DIALOG (search));
-  gtk_widget_destroy (GTK_WIDGET (g_steal_pointer (&search)));
+  search_dialog = seahorse_keyserver_search_new (GTK_WINDOW (catalog));
+
+  /* Run it and get the search text */
+  response = gtk_dialog_run (GTK_DIALOG (search_dialog));
+  search_text = seahorse_keyserver_search_get_search_text (search_dialog);
+
+  /* We can safely destroy it */
+  gtk_widget_destroy (GTK_WIDGET (g_steal_pointer (&search_dialog)));
+
+  /* If the user pressed "Search", make it happen */
+  if (response == GTK_RESPONSE_ACCEPT) {
+    /* Get search text and save it for next time */
+    g_return_if_fail (search_text && *search_text);
+
+    seahorse_app_settings_set_last_search_text (seahorse_app_settings_instance (),
+                                                search_text);
+    seahorse_keyserver_results_show (search_text, GTK_WINDOW (catalog));
+  }
+
   g_clear_object (&catalog);
 }
 


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