]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkappchooserdialog.c
Place the search icon in the primary slot of the entry
[~andy/gtk] / gtk / gtkappchooserdialog.c
index 28c6bc0a50855343bd8d2821bd2e7aa2346c7f36..b63f0df72a9fd3001da45020bd6ec2257ca76c6a 100644 (file)
@@ -15,9 +15,7 @@
  * Library General Public License for more details.
  *
  * You should have received a copy of the GNU Library General Public
- * License along with the Gnome Library; see the file COPYING.LIB.  If not,
- * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  *
  * Authors: Dave Camp <dave@novell.com>
  *          Alexander Larsson <alexl@redhat.com>
@@ -77,8 +75,10 @@ struct _GtkAppChooserDialogPrivate {
   GtkWidget *show_more_button;
 
   GtkAppChooserOnline *online;
+  GCancellable *online_cancellable;
 
   gboolean show_more_clicked;
+  gboolean dismissed;
 };
 
 enum {
@@ -128,17 +128,26 @@ search_for_mimetype_ready_cb (GObject      *source,
 
   _gtk_app_chooser_online_search_for_mimetype_finish (online, res, &error);
 
-  if (error != NULL)
+  if (self->priv->dismissed)
+    goto out;
+
+  if (error != NULL &&
+      !g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
     {
       show_error_dialog (_("Failed to look for applications online"),
                          error->message, GTK_WINDOW (self));
-      g_error_free (error);
     }
   else
     {
+      gtk_widget_set_sensitive (self->priv->online_button, TRUE);
       gtk_app_chooser_refresh (GTK_APP_CHOOSER (self->priv->app_chooser_widget));
     }
 
+ out:
+  g_clear_object (&self->priv->online_cancellable);
+  g_clear_error (&error);
+  g_object_unref (self);
+
   gdk_threads_leave ();
 }
 
@@ -148,11 +157,15 @@ online_button_clicked_cb (GtkButton *b,
 {
   GtkAppChooserDialog *self = user_data;
 
+  self->priv->online_cancellable = g_cancellable_new ();
+  gtk_widget_set_sensitive (self->priv->online_button, FALSE);
+
   _gtk_app_chooser_online_search_for_mimetype_async (self->priv->online,
                                                     self->priv->content_type,
                                                     GTK_WINDOW (self),
+                                                     self->priv->online_cancellable,
                                                     search_for_mimetype_ready_cb,
-                                                    self);
+                                                    g_object_ref (self));
 }
 
 static void
@@ -166,12 +179,13 @@ app_chooser_online_get_default_ready_cb (GObject *source,
 
   self->priv->online = _gtk_app_chooser_online_get_default_finish (source, res);
 
-  if (self->priv->online != NULL)
+  if (self->priv->online != NULL &&
+      !self->priv->dismissed)
     {
       GtkWidget *action_area;
 
       action_area = gtk_dialog_get_action_area (GTK_DIALOG (self));
-      self->priv->online_button = gtk_button_new_with_label (_("Find applications online"));
+      self->priv->online_button = gtk_button_new_with_mnemonic (_("_Find applications online"));
       gtk_box_pack_start (GTK_BOX (action_area), self->priv->online_button,
                           FALSE, FALSE, 0);
       gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (action_area), self->priv->online_button,
@@ -186,13 +200,16 @@ app_chooser_online_get_default_ready_cb (GObject *source,
       gtk_widget_show (self->priv->online_button);
     }
 
+  g_object_unref (self);
+
   gdk_threads_leave ();
 }
 
 static void
 ensure_online_button (GtkAppChooserDialog *self)
 {
-  _gtk_app_chooser_online_get_default_async (app_chooser_online_get_default_ready_cb, self);
+  _gtk_app_chooser_online_get_default_async (app_chooser_online_get_default_ready_cb,
+                                             g_object_ref (self));
 }
 
 /* An application is valid if:
@@ -278,6 +295,16 @@ add_or_find_application (GtkAppChooserDialog *self)
     }
 }
 
+static void
+cancel_and_clear_cancellable (GtkAppChooserDialog *self)
+{                                                               
+  if (self->priv->online_cancellable != NULL)
+    {
+      g_cancellable_cancel (self->priv->online_cancellable);
+      g_clear_object (&self->priv->online_cancellable);
+    }
+}
+
 static void
 gtk_app_chooser_dialog_response (GtkDialog *dialog,
                                  gint       response_id,
@@ -290,6 +317,10 @@ gtk_app_chooser_dialog_response (GtkDialog *dialog,
     case GTK_RESPONSE_OK:
       add_or_find_application (self);
       break;
+    case GTK_RESPONSE_CANCEL:
+    case GTK_RESPONSE_DELETE_EVENT:
+      cancel_and_clear_cancellable (self);
+      self->priv->dismissed = TRUE;
     default :
       break;
     }
@@ -610,6 +641,7 @@ gtk_app_chooser_dialog_dispose (GObject *object)
   GtkAppChooserDialog *self = GTK_APP_CHOOSER_DIALOG (object);
   
   g_clear_object (&self->priv->gfile);
+  cancel_and_clear_cancellable (self);
   g_clear_object (&self->priv->online);
 
   G_OBJECT_CLASS (gtk_app_chooser_dialog_parent_class)->dispose (object);