Allow GtkAppChooser classes to be instantiated with content-type=NULL.
Mostly for corner cases such as Glade that treats objects generically and needs to have an object that doesnt crash out of g_object_new().
This commit is contained in:
parent
0e608f1b1f
commit
c844a24ae6
@ -248,7 +248,7 @@ gtk_app_chooser_button_ensure_dialog_item (GtkAppChooserButton *self,
|
||||
{
|
||||
GtkTreeIter iter, iter2;
|
||||
|
||||
if (!self->priv->show_dialog_item)
|
||||
if (!self->priv->show_dialog_item || !self->priv->content_type)
|
||||
return;
|
||||
|
||||
if (prev_iter == NULL)
|
||||
@ -275,7 +275,8 @@ gtk_app_chooser_button_populate (GtkAppChooserButton *self)
|
||||
gboolean cycled_recommended;
|
||||
|
||||
#ifndef G_OS_WIN32
|
||||
recommended_apps = g_app_info_get_recommended_for_type (self->priv->content_type);
|
||||
if (self->priv->content_type)
|
||||
recommended_apps = g_app_info_get_recommended_for_type (self->priv->content_type);
|
||||
#endif
|
||||
cycled_recommended = FALSE;
|
||||
|
||||
@ -325,14 +326,6 @@ gtk_app_chooser_button_build_ui (GtkAppChooserButton *self)
|
||||
GtkCellRenderer *cell;
|
||||
GtkCellArea *area;
|
||||
|
||||
self->priv->store = gtk_list_store_new (NUM_COLUMNS,
|
||||
G_TYPE_APP_INFO,
|
||||
G_TYPE_STRING, /* name */
|
||||
G_TYPE_STRING, /* label */
|
||||
G_TYPE_ICON,
|
||||
G_TYPE_BOOLEAN, /* separator */
|
||||
G_TYPE_BOOLEAN); /* custom */
|
||||
|
||||
gtk_combo_box_set_model (GTK_COMBO_BOX (self),
|
||||
GTK_TREE_MODEL (self->priv->store));
|
||||
|
||||
@ -457,8 +450,6 @@ gtk_app_chooser_button_constructed (GObject *obj)
|
||||
if (G_OBJECT_CLASS (gtk_app_chooser_button_parent_class)->constructed != NULL)
|
||||
G_OBJECT_CLASS (gtk_app_chooser_button_parent_class)->constructed (obj);
|
||||
|
||||
g_assert (self->priv->content_type != NULL);
|
||||
|
||||
gtk_app_chooser_button_build_ui (self);
|
||||
}
|
||||
|
||||
@ -521,6 +512,8 @@ gtk_app_chooser_button_finalize (GObject *obj)
|
||||
g_free (self->priv->content_type);
|
||||
g_free (self->priv->heading);
|
||||
|
||||
g_object_unref (self->priv->store);
|
||||
|
||||
G_OBJECT_CLASS (gtk_app_chooser_button_parent_class)->finalize (obj);
|
||||
}
|
||||
|
||||
@ -605,6 +598,14 @@ gtk_app_chooser_button_init (GtkAppChooserButton *self)
|
||||
self->priv->custom_item_names =
|
||||
g_hash_table_new_full (g_str_hash, g_str_equal,
|
||||
g_free, NULL);
|
||||
|
||||
self->priv->store = gtk_list_store_new (NUM_COLUMNS,
|
||||
G_TYPE_APP_INFO,
|
||||
G_TYPE_STRING, /* name */
|
||||
G_TYPE_STRING, /* label */
|
||||
G_TYPE_ICON,
|
||||
G_TYPE_BOOLEAN, /* separator */
|
||||
G_TYPE_BOOLEAN); /* custom */
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
@ -142,10 +142,10 @@ online_button_clicked_cb (GtkButton *b,
|
||||
GtkAppChooserDialog *self = user_data;
|
||||
|
||||
_gtk_app_chooser_online_search_for_mimetype_async (self->priv->online,
|
||||
self->priv->content_type,
|
||||
GTK_WINDOW (self),
|
||||
search_for_mimetype_ready_cb,
|
||||
self);
|
||||
self->priv->content_type,
|
||||
GTK_WINDOW (self),
|
||||
search_for_mimetype_ready_cb,
|
||||
self);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -170,6 +170,10 @@ app_chooser_online_get_default_ready_cb (GObject *source,
|
||||
g_signal_connect (self->priv->online_button, "clicked",
|
||||
G_CALLBACK (online_button_clicked_cb), self);
|
||||
|
||||
|
||||
if (!self->priv->content_type)
|
||||
gtk_widget_set_sensitive (self->priv->online_button, FALSE);
|
||||
|
||||
gtk_widget_show (self->priv->online_button);
|
||||
}
|
||||
}
|
||||
@ -247,9 +251,10 @@ add_or_find_application (GtkAppChooserDialog *self)
|
||||
app = gtk_app_chooser_get_app_info (GTK_APP_CHOOSER (self));
|
||||
|
||||
/* we don't care about reporting errors here */
|
||||
g_app_info_set_as_last_used_for_type (app,
|
||||
self->priv->content_type,
|
||||
NULL);
|
||||
if (self->priv->content_type)
|
||||
g_app_info_set_as_last_used_for_type (app,
|
||||
self->priv->content_type,
|
||||
NULL);
|
||||
|
||||
g_object_unref (app);
|
||||
}
|
||||
@ -313,12 +318,14 @@ set_dialog_properties (GtkAppChooserDialog *self)
|
||||
gchar *description;
|
||||
gchar *default_text;
|
||||
gchar *string;
|
||||
gboolean unknown;
|
||||
PangoFontDescription *font_desc;
|
||||
|
||||
name = NULL;
|
||||
extension = NULL;
|
||||
label = NULL;
|
||||
description = NULL;
|
||||
unknown = TRUE;
|
||||
|
||||
if (self->priv->gfile != NULL)
|
||||
{
|
||||
@ -326,7 +333,12 @@ set_dialog_properties (GtkAppChooserDialog *self)
|
||||
extension = get_extension (name);
|
||||
}
|
||||
|
||||
description = g_content_type_get_description (self->priv->content_type);
|
||||
if (self->priv->content_type)
|
||||
{
|
||||
description = g_content_type_get_description (self->priv->content_type);
|
||||
unknown = g_content_type_is_unknown (self->priv->content_type);
|
||||
}
|
||||
|
||||
gtk_window_set_title (GTK_WINDOW (self), "");
|
||||
|
||||
if (name != NULL)
|
||||
@ -340,11 +352,9 @@ set_dialog_properties (GtkAppChooserDialog *self)
|
||||
{
|
||||
/* 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);
|
||||
unknown ? self->priv->content_type : description);
|
||||
string = g_strdup_printf (_("No applications available to open \"%s\" files"),
|
||||
g_content_type_is_unknown (self->priv->content_type) ?
|
||||
self->priv->content_type : description);
|
||||
unknown ? self->priv->content_type : description);
|
||||
}
|
||||
|
||||
font_desc = pango_font_description_new ();
|
||||
@ -575,9 +585,6 @@ gtk_app_chooser_dialog_constructed (GObject *object)
|
||||
{
|
||||
GtkAppChooserDialog *self = GTK_APP_CHOOSER_DIALOG (object);
|
||||
|
||||
g_assert (self->priv->content_type != NULL ||
|
||||
self->priv->gfile != NULL);
|
||||
|
||||
if (G_OBJECT_CLASS (gtk_app_chooser_dialog_parent_class)->constructed != NULL)
|
||||
G_OBJECT_CLASS (gtk_app_chooser_dialog_parent_class)->constructed (object);
|
||||
|
||||
|
@ -630,13 +630,15 @@ gtk_app_chooser_add_default (GtkAppChooserWidget *self,
|
||||
static void
|
||||
add_no_applications_label (GtkAppChooserWidget *self)
|
||||
{
|
||||
gchar *text = NULL, *desc;
|
||||
gchar *text = NULL, *desc = NULL;
|
||||
const gchar *string;
|
||||
GtkTreeIter iter;
|
||||
|
||||
if (self->priv->default_text == NULL)
|
||||
{
|
||||
desc = g_content_type_get_description (self->priv->content_type);
|
||||
if (self->priv->content_type)
|
||||
desc = g_content_type_get_description (self->priv->content_type);
|
||||
|
||||
string = text = g_strdup_printf (_("No applications available to open \"%s\""),
|
||||
desc);
|
||||
g_free (desc);
|
||||
@ -706,7 +708,7 @@ gtk_app_chooser_widget_real_add_items (GtkAppChooserWidget *self)
|
||||
if (self->priv->show_all)
|
||||
show_headings = FALSE;
|
||||
|
||||
if (self->priv->show_default)
|
||||
if (self->priv->show_default && self->priv->content_type)
|
||||
{
|
||||
default_app = g_app_info_get_default_for_type (self->priv->content_type, FALSE);
|
||||
|
||||
@ -719,9 +721,10 @@ gtk_app_chooser_widget_real_add_items (GtkAppChooserWidget *self)
|
||||
}
|
||||
|
||||
#ifndef G_OS_WIN32
|
||||
if (self->priv->show_recommended || self->priv->show_all)
|
||||
if ((self->priv->content_type && self->priv->show_recommended) || self->priv->show_all)
|
||||
{
|
||||
recommended_apps = g_app_info_get_recommended_for_type (self->priv->content_type);
|
||||
if (self->priv->content_type)
|
||||
recommended_apps = g_app_info_get_recommended_for_type (self->priv->content_type);
|
||||
|
||||
apps_added |= gtk_app_chooser_widget_add_section (self, _("Recommended Applications"),
|
||||
show_headings,
|
||||
@ -733,9 +736,10 @@ gtk_app_chooser_widget_real_add_items (GtkAppChooserWidget *self)
|
||||
g_list_copy (recommended_apps));
|
||||
}
|
||||
|
||||
if (self->priv->show_fallback || self->priv->show_all)
|
||||
if ((self->priv->content_type && self->priv->show_fallback) || self->priv->show_all)
|
||||
{
|
||||
fallback_apps = g_app_info_get_fallback_for_type (self->priv->content_type);
|
||||
if (self->priv->content_type)
|
||||
fallback_apps = g_app_info_get_fallback_for_type (self->priv->content_type);
|
||||
|
||||
apps_added |= gtk_app_chooser_widget_add_section (self, _("Related Applications"),
|
||||
show_headings,
|
||||
@ -953,8 +957,6 @@ gtk_app_chooser_widget_constructed (GObject *object)
|
||||
{
|
||||
GtkAppChooserWidget *self = GTK_APP_CHOOSER_WIDGET (object);
|
||||
|
||||
g_assert (self->priv->content_type != NULL);
|
||||
|
||||
if (G_OBJECT_CLASS (gtk_app_chooser_widget_parent_class)->constructed != NULL)
|
||||
G_OBJECT_CLASS (gtk_app_chooser_widget_parent_class)->constructed (object);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user