open-with: change the API to make it symmetric for GFile or content-type

It's much more convenient this way.
This commit is contained in:
Cosimo Cecchi 2010-11-16 19:21:23 +01:00
parent 3a6b936573
commit df8ccfb800
3 changed files with 81 additions and 48 deletions

View 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"));
/* 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 (self->priv->gfile != NULL)
gtk_window_set_title (GTK_WINDOW (self), _("Open With"));
else
/* Translators: %s is a file type description */
checkbox_text = g_strdup_printf (_("_Remember this application for \"%s\" files"),
description);
gtk_window_set_title (GTK_WINDOW (self), _("Select Application"));
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);
else
/* Translators: %s is a file type description */
checkbox_text = g_strdup_printf (_("_Remember this application for \"%s\" files"),
description);
}
else
{
/* 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);

View 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);

View 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,25 +55,41 @@ 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;
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, default_mode ?
GTK_OPEN_WITH_DIALOG_MODE_SELECT_DEFAULT :
GTK_OPEN_WITH_DIALOG_MODE_SELECT_ONE,
file);
}
else
{
GFileInfo *info;
info = g_file_query_info (file,
G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
@ -81,20 +97,12 @@ display_dialog (GtkButton *b,
content_type = g_strdup (g_file_info_get_content_type (info));
g_object_unref (info);
}
if (use_file)
{
dialog = gtk_open_with_dialog_new (GTK_WINDOW (toplevel),
0, use_content ?
GTK_OPEN_WITH_DIALOG_MODE_SELECT_DEFAULT :
GTK_OPEN_WITH_DIALOG_MODE_OPEN_FILE,
file);
}
else
{
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);