]> Pileus Git - ~andy/gtk/commitdiff
open-with: change the API to make it symmetric for GFile or content-type
authorCosimo Cecchi <cosimoc@gnome.org>
Tue, 16 Nov 2010 18:21:23 +0000 (19:21 +0100)
committerCosimo Cecchi <cosimoc@gnome.org>
Tue, 23 Nov 2010 15:51:39 +0000 (16:51 +0100)
It's much more convenient this way.

gtk/gtkopenwithdialog.c
gtk/gtkopenwithdialog.h
tests/testopenwith.c

index cdd4eb7edfe2aa537b984d4f5c0e2eda5c60614d..b096fdf935ed44b6386a81456ad61aec6269a544 100644 (file)
@@ -243,7 +243,7 @@ add_or_find_application (GtkOpenWithDialog *self)
 
   should_set_default =
     (self->priv->mode == GTK_OPEN_WITH_DIALOG_MODE_SELECT_DEFAULT) ||
-    (self->priv->mode == GTK_OPEN_WITH_DIALOG_MODE_OPEN_FILE &&
+    (self->priv->mode == GTK_OPEN_WITH_DIALOG_MODE_SELECT_ONE &&
      gtk_widget_get_visible (self->priv->checkbox) &&
      gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->priv->checkbox)));
   success = TRUE;
@@ -921,22 +921,41 @@ set_dialog_properties (GtkOpenWithDialog *self)
 
   description = g_content_type_get_description (self->priv->content_type);
 
-  if (self->priv->mode == GTK_OPEN_WITH_DIALOG_MODE_OPEN_FILE)
+  if (self->priv->mode == GTK_OPEN_WITH_DIALOG_MODE_SELECT_ONE)
     {
-      /* we have the GFile, its content type and its name and extension. */
-      gtk_window_set_title (GTK_WINDOW (self), _("Open With"));
+      if (self->priv->gfile != NULL)
+       gtk_window_set_title (GTK_WINDOW (self), _("Open With"));
+      else
+       gtk_window_set_title (GTK_WINDOW (self), _("Select Application"));
 
-      /* Translators: %s is a filename */
-      label = g_strdup_printf (_("Open %s with:"), emname);
+      if (emname != NULL)
+       {
+         /* Translators: %s is a filename */
+         label = g_strdup_printf (_("Open %s with:"), emname);
 
-      if (g_content_type_is_unknown (self->priv->content_type))
-       /* Translators: the %s is the extension of the file */
-       checkbox_text = g_strdup_printf (_("_Remember this application for %s documents"), 
-                                        extension);
+         if (g_content_type_is_unknown (self->priv->content_type))
+           /* Translators: the %s is the extension of the file */
+           checkbox_text = g_strdup_printf (_("_Remember this application for %s documents"), 
+                                            extension);
+         else
+           /* Translators: %s is a file type description */
+           checkbox_text = g_strdup_printf (_("_Remember this application for \"%s\" files"),
+                                            description);
+       }
       else
-       /* Translators: %s is a file type description */
-       checkbox_text = g_strdup_printf (_("_Remember this application for \"%s\" files"),
-                                        description);
+       {
+         /* we're in the content_type + SELECT_ONE case */
+
+         /* Translators: %s is a file type description */
+         label = g_strdup_printf (_("Select an application for \"%s\" files:"),
+                                  g_content_type_is_unknown (self->priv->content_type) ?
+                                  self->priv->content_type : description);
+
+         /* Translators: %s is a file type description */
+         checkbox_text = g_strdup_printf (_("_Remember this application for \"%s\" files"),
+                                          g_content_type_is_unknown (self->priv->content_type) ?
+                                          self->priv->content_type : description);
+       }
 
       gtk_button_set_label (GTK_BUTTON (self->priv->checkbox), checkbox_text);
       g_free (checkbox_text);
@@ -952,8 +971,8 @@ set_dialog_properties (GtkOpenWithDialog *self)
            /* Translators: first %s is a filename and second %s is a file extension */
            label = g_strdup_printf (_("Open %s and other %s document with:"),
                                     emname, extension);
-         else;
-           /* TODO: content type is unknown and no file provided?? */
+         else
+           label = g_strdup_printf (_("Open all \"%s\" files with:"), self->priv->content_type);
        }
       else
        {
@@ -1111,7 +1130,7 @@ gtk_open_with_dialog_class_init (GtkOpenWithDialogClass *klass)
                       P_("The dialog mode"),
                       P_("The operation mode for this dialog"),
                       GTK_TYPE_OPEN_WITH_DIALOG_MODE,
-                      GTK_OPEN_WITH_DIALOG_MODE_OPEN_FILE,
+                      GTK_OPEN_WITH_DIALOG_MODE_SELECT_ONE,
                       G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
                       G_PARAM_STATIC_STRINGS);
   properties[PROP_SHOW_OTHER_APPLICATIONS] =
@@ -1332,6 +1351,7 @@ gtk_open_with_dialog_new (GtkWindow *parent,
 GtkWidget *
 gtk_open_with_dialog_new_for_content_type (GtkWindow *parent,
                                           GtkDialogFlags flags,
+                                          GtkOpenWithDialogMode mode,
                                           const gchar *content_type)
 {
   GtkWidget *retval;
@@ -1340,7 +1360,7 @@ gtk_open_with_dialog_new_for_content_type (GtkWindow *parent,
 
   retval = g_object_new (GTK_TYPE_OPEN_WITH_DIALOG,
                         "content-type", content_type,
-                        "mode", GTK_OPEN_WITH_DIALOG_MODE_SELECT_DEFAULT,
+                        "mode", mode,
                         NULL);
 
   set_parent_and_flags (retval, parent, flags);
index d66160b64f6066bd5c5921ec8200a17f9295e893..6b202c79e59d03f944908974f3a95061bb423120 100644 (file)
@@ -73,11 +73,12 @@ GtkWidget * gtk_open_with_dialog_new (GtkWindow *parent,
                                      GFile *file);
 GtkWidget * gtk_open_with_dialog_new_for_content_type (GtkWindow *parent,
                                                       GtkDialogFlags flags,
+                                                      GtkOpenWithDialogMode mode,
                                                       const gchar *content_type);
 
 void gtk_open_with_dialog_set_show_other_applications (GtkOpenWithDialog *self,
                                                       gboolean show_other_applications);
-gboolean gtk_open_with_get_show_other_applications (GtkOpenWithDialog *self);
+gboolean gtk_open_with_dialog_get_show_other_applications (GtkOpenWithDialog *self);
 
 void gtk_open_with_dialog_set_show_set_as_default_button (GtkOpenWithDialog *self,
                                                          gboolean show_button);
index 6fefe6398053bb963a8e401ea54038597f9a11ba..57cfad3f193488ca2986bf7bb79fd4efe6999431 100644 (file)
@@ -26,7 +26,7 @@
 static GtkWidget *toplevel;
 static GFile *file;
 static GtkWidget *grid, *file_l, *open, *show_all, *show_set_as_default;
-static GtkWidget *radio_file, *radio_content_from_file, *radio_content, *dialog;
+static GtkWidget *radio_file, *radio_file_default, *radio_content, *radio_content_default, *dialog;
 
 static void
 dialog_response (GtkDialog *d,
@@ -55,46 +55,54 @@ display_dialog (GtkButton *b,
                gpointer user_data)
 {
   gboolean use_file = FALSE;
-  gboolean use_content = FALSE;
+  gboolean default_mode = FALSE;
   gchar *content_type = NULL;
 
-  if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (radio_content_from_file)))
+  if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (radio_file)))
     {
       use_file = TRUE;
-      use_content = TRUE;
+      default_mode = FALSE;
     }
-  else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (radio_file)))
+  else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (radio_file_default)))
     {
       use_file = TRUE;
-      use_content = FALSE;
+      default_mode = TRUE;
     }
   else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (radio_content)))
     {
-      GFileInfo *info;
-
       use_file = FALSE;
-      use_content = TRUE;
-
-      info = g_file_query_info (file,
-                               G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
-                               0, NULL, NULL);
-      content_type = g_strdup (g_file_info_get_content_type (info));
-
-      g_object_unref (info);
-    } 
+      default_mode = FALSE;
+    }
+  else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (radio_content_default)))
+    {
+      use_file = FALSE;
+      default_mode = TRUE;
+    }
 
   if (use_file)
     {
       dialog = gtk_open_with_dialog_new (GTK_WINDOW (toplevel),
-                                        0, use_content ?
+                                        0, default_mode ?
                                         GTK_OPEN_WITH_DIALOG_MODE_SELECT_DEFAULT :
-                                        GTK_OPEN_WITH_DIALOG_MODE_OPEN_FILE,
+                                        GTK_OPEN_WITH_DIALOG_MODE_SELECT_ONE,
                                         file);
     }
   else
     {
+      GFileInfo *info;
+
+      info = g_file_query_info (file,
+                               G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
+                               0, NULL, NULL);
+      content_type = g_strdup (g_file_info_get_content_type (info));
+
+      g_object_unref (info);
+
       dialog = gtk_open_with_dialog_new_for_content_type (GTK_WINDOW (toplevel),
-                                                         0, content_type);
+                                                         0, default_mode ?
+                                                         GTK_OPEN_WITH_DIALOG_MODE_SELECT_DEFAULT :
+                                                         GTK_OPEN_WITH_DIALOG_MODE_SELECT_ONE,
+                                                         content_type);
     }
 
   gtk_open_with_dialog_set_show_other_applications (GTK_OPEN_WITH_DIALOG (dialog),
@@ -189,22 +197,26 @@ main (int argc,
   g_signal_connect (file_l, "clicked",
                    G_CALLBACK (button_clicked), NULL);
 
-  radio_file = gtk_radio_button_new_with_label (NULL, "Use GFile");
-  radio_content_from_file = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (radio_file),
-                                                                        "Use content type and GFile");
+  radio_file = gtk_radio_button_new_with_label (NULL, "Use GFile and select one");
+  radio_file_default = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (radio_file),
+                                                                   "Use GFile and select default");
   radio_content = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (radio_file),
-                                                              "Use content type only");
+                                                              "Use content type and select one");
+  radio_content_default = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (radio_file),
+                                                                      "Use content type and select default");
 
   gtk_grid_attach (GTK_GRID (grid), radio_file,
                   0, 1, 1, 1);
-  gtk_grid_attach_next_to (GTK_GRID (grid), radio_content_from_file,
+  gtk_grid_attach_next_to (GTK_GRID (grid), radio_file_default,
                           radio_file, GTK_POS_BOTTOM, 1, 1);
   gtk_grid_attach_next_to (GTK_GRID (grid), radio_content,
-                          radio_content_from_file, GTK_POS_BOTTOM, 1, 1);
+                          radio_file_default, GTK_POS_BOTTOM, 1, 1);
+  gtk_grid_attach_next_to (GTK_GRID (grid), radio_content_default,
+                          radio_content, GTK_POS_BOTTOM, 1, 1);
 
   open = gtk_button_new_with_label ("Trigger Open With dialog");
   gtk_grid_attach_next_to (GTK_GRID (grid), open,
-                          radio_content, GTK_POS_BOTTOM, 1, 1);
+                          radio_content_default, GTK_POS_BOTTOM, 1, 1);
   gtk_widget_set_sensitive (open, FALSE);
   g_signal_connect (open, "clicked",
                    G_CALLBACK (display_dialog), NULL);