[gtk+] Allow GtkAppChooser classes to be instantiated with content-type=NULL.
- From: Tristan Van Berkom <tvb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] Allow GtkAppChooser classes to be instantiated with content-type=NULL.
- Date: Tue, 1 Mar 2011 22:46:13 +0000 (UTC)
commit c844a24ae6209b916e8aaa0559f1c45643a255d2
Author: Tristan Van Berkom <tristan van berkom gmail com>
Date: Tue Mar 1 19:41:15 2011 +0900
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().
gtk/gtkappchooserbutton.c | 25 +++++++++++++------------
gtk/gtkappchooserdialog.c | 37 ++++++++++++++++++++++---------------
gtk/gtkappchooserwidget.c | 20 +++++++++++---------
3 files changed, 46 insertions(+), 36 deletions(-)
---
diff --git a/gtk/gtkappchooserbutton.c b/gtk/gtkappchooserbutton.c
index 34cc573..706ce13 100644
--- a/gtk/gtkappchooserbutton.c
+++ b/gtk/gtkappchooserbutton.c
@@ -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
diff --git a/gtk/gtkappchooserdialog.c b/gtk/gtkappchooserdialog.c
index 181515d..35d1d1f 100644
--- a/gtk/gtkappchooserdialog.c
+++ b/gtk/gtkappchooserdialog.c
@@ -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);
diff --git a/gtk/gtkappchooserwidget.c b/gtk/gtkappchooserwidget.c
index 2b276e7..2251971 100644
--- a/gtk/gtkappchooserwidget.c
+++ b/gtk/gtkappchooserwidget.c
@@ -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);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]