app chooser dialog: Drop the priv pointer

This commit is contained in:
Matthias Clasen 2019-05-27 20:51:46 -04:00
parent e0a9952a56
commit dbdb137428

View File

@ -67,8 +67,6 @@ typedef struct _GtkAppChooserDialogPrivate GtkAppChooserDialogPrivate;
struct _GtkAppChooserDialog { struct _GtkAppChooserDialog {
GtkDialog parent; GtkDialog parent;
GtkAppChooserDialogPrivate *priv;
}; };
struct _GtkAppChooserDialogClass { struct _GtkAppChooserDialogClass {
@ -113,6 +111,7 @@ G_DEFINE_TYPE_WITH_CODE (GtkAppChooserDialog, gtk_app_chooser_dialog, GTK_TYPE_D
static void static void
add_or_find_application (GtkAppChooserDialog *self) add_or_find_application (GtkAppChooserDialog *self)
{ {
GtkAppChooserDialogPrivate *priv = gtk_app_chooser_dialog_get_instance_private (self);
GAppInfo *app; GAppInfo *app;
app = gtk_app_chooser_get_app_info (GTK_APP_CHOOSER (self)); app = gtk_app_chooser_get_app_info (GTK_APP_CHOOSER (self));
@ -120,9 +119,9 @@ add_or_find_application (GtkAppChooserDialog *self)
if (app) if (app)
{ {
/* we don't care about reporting errors here */ /* we don't care about reporting errors here */
if (self->priv->content_type) if (priv->content_type)
g_app_info_set_as_last_used_for_type (app, g_app_info_set_as_last_used_for_type (app,
self->priv->content_type, priv->content_type,
NULL); NULL);
g_object_unref (app); g_object_unref (app);
} }
@ -134,6 +133,7 @@ gtk_app_chooser_dialog_response (GtkDialog *dialog,
gpointer user_data) gpointer user_data)
{ {
GtkAppChooserDialog *self = GTK_APP_CHOOSER_DIALOG (dialog); GtkAppChooserDialog *self = GTK_APP_CHOOSER_DIALOG (dialog);
GtkAppChooserDialogPrivate *priv = gtk_app_chooser_dialog_get_instance_private (self);
switch (response_id) switch (response_id)
{ {
@ -142,7 +142,7 @@ gtk_app_chooser_dialog_response (GtkDialog *dialog,
break; break;
case GTK_RESPONSE_CANCEL: case GTK_RESPONSE_CANCEL:
case GTK_RESPONSE_DELETE_EVENT: case GTK_RESPONSE_DELETE_EVENT:
self->priv->dismissed = TRUE; priv->dismissed = TRUE;
default: default:
break; break;
} }
@ -184,6 +184,7 @@ get_extension (const char *basename)
static void static void
set_dialog_properties (GtkAppChooserDialog *self) set_dialog_properties (GtkAppChooserDialog *self)
{ {
GtkAppChooserDialogPrivate *priv = gtk_app_chooser_dialog_get_instance_private (self);
gchar *name; gchar *name;
gchar *extension; gchar *extension;
gchar *description; gchar *description;
@ -199,16 +200,16 @@ set_dialog_properties (GtkAppChooserDialog *self)
description = NULL; description = NULL;
unknown = TRUE; unknown = TRUE;
if (self->priv->gfile != NULL) if (priv->gfile != NULL)
{ {
name = g_file_get_basename (self->priv->gfile); name = g_file_get_basename (priv->gfile);
extension = get_extension (name); extension = get_extension (name);
} }
if (self->priv->content_type) if (priv->content_type)
{ {
description = g_content_type_get_description (self->priv->content_type); description = g_content_type_get_description (priv->content_type);
unknown = g_content_type_is_unknown (self->priv->content_type); unknown = g_content_type_is_unknown (priv->content_type);
} }
if (name != NULL) if (name != NULL)
@ -223,9 +224,9 @@ set_dialog_properties (GtkAppChooserDialog *self)
title = g_strdup (_("Select Application")); title = g_strdup (_("Select Application"));
/* Translators: %s is a file type description */ /* Translators: %s is a file type description */
subtitle = g_strdup_printf (_("Opening “%s” files."), subtitle = g_strdup_printf (_("Opening “%s” files."),
unknown ? self->priv->content_type : description); unknown ? priv->content_type : description);
string = g_strdup_printf (_("No applications found for “%s” files"), string = g_strdup_printf (_("No applications found for “%s” files"),
unknown ? self->priv->content_type : description); unknown ? priv->content_type : description);
} }
g_object_get (self, "use-header-bar", &use_header, NULL); g_object_get (self, "use-header-bar", &use_header, NULL);
@ -240,17 +241,17 @@ set_dialog_properties (GtkAppChooserDialog *self)
gtk_window_set_title (GTK_WINDOW (self), _("Select Application")); gtk_window_set_title (GTK_WINDOW (self), _("Select Application"));
} }
if (self->priv->heading != NULL) if (priv->heading != NULL)
{ {
gtk_label_set_markup (GTK_LABEL (self->priv->label), self->priv->heading); gtk_label_set_markup (GTK_LABEL (priv->label), priv->heading);
gtk_widget_show (self->priv->label); gtk_widget_show (priv->label);
} }
else else
{ {
gtk_widget_hide (self->priv->label); gtk_widget_hide (priv->label);
} }
gtk_app_chooser_widget_set_default_text (GTK_APP_CHOOSER_WIDGET (self->priv->app_chooser_widget), gtk_app_chooser_widget_set_default_text (GTK_APP_CHOOSER_WIDGET (priv->app_chooser_widget),
string); string);
g_free (title); g_free (title);
@ -266,15 +267,16 @@ show_more_button_clicked_cb (GtkButton *button,
gpointer user_data) gpointer user_data)
{ {
GtkAppChooserDialog *self = user_data; GtkAppChooserDialog *self = user_data;
GtkAppChooserDialogPrivate *priv = gtk_app_chooser_dialog_get_instance_private (self);
g_object_set (self->priv->app_chooser_widget, g_object_set (priv->app_chooser_widget,
"show-recommended", TRUE, "show-recommended", TRUE,
"show-fallback", TRUE, "show-fallback", TRUE,
"show-other", TRUE, "show-other", TRUE,
NULL); NULL);
gtk_widget_hide (self->priv->show_more_button); gtk_widget_hide (priv->show_more_button);
self->priv->show_more_clicked = TRUE; priv->show_more_clicked = TRUE;
} }
static void static void
@ -283,14 +285,15 @@ widget_notify_for_button_cb (GObject *source,
gpointer user_data) gpointer user_data)
{ {
GtkAppChooserDialog *self = user_data; GtkAppChooserDialog *self = user_data;
GtkAppChooserDialogPrivate *priv = gtk_app_chooser_dialog_get_instance_private (self);
GtkAppChooserWidget *widget = GTK_APP_CHOOSER_WIDGET (source); GtkAppChooserWidget *widget = GTK_APP_CHOOSER_WIDGET (source);
gboolean should_hide; gboolean should_hide;
should_hide = gtk_app_chooser_widget_get_show_other (widget) || should_hide = gtk_app_chooser_widget_get_show_other (widget) ||
self->priv->show_more_clicked; priv->show_more_clicked;
if (should_hide) if (should_hide)
gtk_widget_hide (self->priv->show_more_button); gtk_widget_hide (priv->show_more_button);
} }
static void static void
@ -298,13 +301,14 @@ forget_menu_item_activate_cb (GtkMenuItem *item,
gpointer user_data) gpointer user_data)
{ {
GtkAppChooserDialog *self = user_data; GtkAppChooserDialog *self = user_data;
GtkAppChooserDialogPrivate *priv = gtk_app_chooser_dialog_get_instance_private (self);
GAppInfo *info; GAppInfo *info;
info = gtk_app_chooser_get_app_info (GTK_APP_CHOOSER (self)); info = gtk_app_chooser_get_app_info (GTK_APP_CHOOSER (self));
if (info != NULL) if (info != NULL)
{ {
g_app_info_remove_supports_type (info, self->priv->content_type, NULL); g_app_info_remove_supports_type (info, priv->content_type, NULL);
gtk_app_chooser_refresh (GTK_APP_CHOOSER (self)); gtk_app_chooser_refresh (GTK_APP_CHOOSER (self));
@ -345,39 +349,39 @@ widget_populate_popup_cb (GtkAppChooserWidget *widget,
static void static void
construct_appchooser_widget (GtkAppChooserDialog *self) construct_appchooser_widget (GtkAppChooserDialog *self)
{ {
GtkAppChooserDialogPrivate *priv = gtk_app_chooser_dialog_get_instance_private (self);
GAppInfo *info; GAppInfo *info;
/* Need to build the appchooser widget after, because of the content-type construct-only property */ /* Need to build the appchooser widget after, because of the content-type construct-only property */
self->priv->app_chooser_widget = gtk_app_chooser_widget_new (self->priv->content_type); priv->app_chooser_widget = gtk_app_chooser_widget_new (priv->content_type);
gtk_widget_set_vexpand (self->priv->app_chooser_widget, TRUE); gtk_widget_set_vexpand (priv->app_chooser_widget, TRUE);
gtk_container_add (GTK_CONTAINER (self->priv->inner_box), self->priv->app_chooser_widget); gtk_container_add (GTK_CONTAINER (priv->inner_box), priv->app_chooser_widget);
g_signal_connect (priv->app_chooser_widget, "application-selected",
g_signal_connect (self->priv->app_chooser_widget, "application-selected",
G_CALLBACK (widget_application_selected_cb), self); G_CALLBACK (widget_application_selected_cb), self);
g_signal_connect (self->priv->app_chooser_widget, "application-activated", g_signal_connect (priv->app_chooser_widget, "application-activated",
G_CALLBACK (widget_application_activated_cb), self); G_CALLBACK (widget_application_activated_cb), self);
g_signal_connect (self->priv->app_chooser_widget, "notify::show-other", g_signal_connect (priv->app_chooser_widget, "notify::show-other",
G_CALLBACK (widget_notify_for_button_cb), self); G_CALLBACK (widget_notify_for_button_cb), self);
g_signal_connect (self->priv->app_chooser_widget, "populate-popup", g_signal_connect (priv->app_chooser_widget, "populate-popup",
G_CALLBACK (widget_populate_popup_cb), self); G_CALLBACK (widget_populate_popup_cb), self);
/* Add the custom button to the new appchooser */ /* Add the custom button to the new appchooser */
gtk_container_add (GTK_CONTAINER (self->priv->inner_box), gtk_container_add (GTK_CONTAINER (priv->inner_box),
self->priv->show_more_button); priv->show_more_button);
gtk_container_add (GTK_CONTAINER (self->priv->inner_box), gtk_container_add (GTK_CONTAINER (priv->inner_box),
self->priv->software_button); priv->software_button);
info = gtk_app_chooser_get_app_info (GTK_APP_CHOOSER (self->priv->app_chooser_widget)); info = gtk_app_chooser_get_app_info (GTK_APP_CHOOSER (priv->app_chooser_widget));
gtk_dialog_set_response_sensitive (GTK_DIALOG (self), GTK_RESPONSE_OK, info != NULL); gtk_dialog_set_response_sensitive (GTK_DIALOG (self), GTK_RESPONSE_OK, info != NULL);
if (info) if (info)
g_object_unref (info); g_object_unref (info);
_gtk_app_chooser_widget_set_search_entry (GTK_APP_CHOOSER_WIDGET (self->priv->app_chooser_widget), _gtk_app_chooser_widget_set_search_entry (GTK_APP_CHOOSER_WIDGET (priv->app_chooser_widget),
GTK_EDITABLE (self->priv->search_entry)); GTK_EDITABLE (priv->search_entry));
gtk_search_bar_set_key_capture_widget (GTK_SEARCH_BAR (self->priv->search_bar), gtk_search_bar_set_key_capture_widget (GTK_SEARCH_BAR (priv->search_bar),
GTK_WIDGET (self)); GTK_WIDGET (self));
} }
@ -385,17 +389,18 @@ static void
set_gfile_and_content_type (GtkAppChooserDialog *self, set_gfile_and_content_type (GtkAppChooserDialog *self,
GFile *file) GFile *file)
{ {
GtkAppChooserDialogPrivate *priv = gtk_app_chooser_dialog_get_instance_private (self);
GFileInfo *info; GFileInfo *info;
if (file == NULL) if (file == NULL)
return; return;
self->priv->gfile = g_object_ref (file); priv->gfile = g_object_ref (file);
info = g_file_query_info (self->priv->gfile, info = g_file_query_info (priv->gfile,
G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
0, NULL, NULL); 0, NULL, NULL);
self->priv->content_type = g_strdup (g_file_info_get_content_type (info)); priv->content_type = g_strdup (g_file_info_get_content_type (info));
g_object_unref (info); g_object_unref (info);
} }
@ -404,15 +409,18 @@ static GAppInfo *
gtk_app_chooser_dialog_get_app_info (GtkAppChooser *object) gtk_app_chooser_dialog_get_app_info (GtkAppChooser *object)
{ {
GtkAppChooserDialog *self = GTK_APP_CHOOSER_DIALOG (object); GtkAppChooserDialog *self = GTK_APP_CHOOSER_DIALOG (object);
return gtk_app_chooser_get_app_info (GTK_APP_CHOOSER (self->priv->app_chooser_widget)); GtkAppChooserDialogPrivate *priv = gtk_app_chooser_dialog_get_instance_private (self);
return gtk_app_chooser_get_app_info (GTK_APP_CHOOSER (priv->app_chooser_widget));
} }
static void static void
gtk_app_chooser_dialog_refresh (GtkAppChooser *object) gtk_app_chooser_dialog_refresh (GtkAppChooser *object)
{ {
GtkAppChooserDialog *self = GTK_APP_CHOOSER_DIALOG (object); GtkAppChooserDialog *self = GTK_APP_CHOOSER_DIALOG (object);
GtkAppChooserDialogPrivate *priv = gtk_app_chooser_dialog_get_instance_private (self);
gtk_app_chooser_refresh (GTK_APP_CHOOSER (self->priv->app_chooser_widget)); gtk_app_chooser_refresh (GTK_APP_CHOOSER (priv->app_chooser_widget));
} }
static void static void
@ -442,12 +450,13 @@ static void
software_button_clicked_cb (GtkButton *button, software_button_clicked_cb (GtkButton *button,
GtkAppChooserDialog *self) GtkAppChooserDialog *self)
{ {
GtkAppChooserDialogPrivate *priv = gtk_app_chooser_dialog_get_instance_private (self);
GSubprocess *process; GSubprocess *process;
GError *error = NULL; GError *error = NULL;
gchar *option; gchar *option;
if (self->priv->content_type) if (priv->content_type)
option = g_strconcat ("--search=", self->priv->content_type, NULL); option = g_strconcat ("--search=", priv->content_type, NULL);
else else
option = g_strdup ("--mode=overview"); option = g_strdup ("--mode=overview");
@ -467,13 +476,14 @@ software_button_clicked_cb (GtkButton *button,
static void static void
ensure_software_button (GtkAppChooserDialog *self) ensure_software_button (GtkAppChooserDialog *self)
{ {
GtkAppChooserDialogPrivate *priv = gtk_app_chooser_dialog_get_instance_private (self);
gchar *path; gchar *path;
path = g_find_program_in_path ("gnome-software"); path = g_find_program_in_path ("gnome-software");
if (path != NULL) if (path != NULL)
gtk_widget_show (self->priv->software_button); gtk_widget_show (priv->software_button);
else else
gtk_widget_hide (self->priv->software_button); gtk_widget_hide (priv->software_button);
g_free (path); g_free (path);
} }
@ -481,6 +491,7 @@ ensure_software_button (GtkAppChooserDialog *self)
static void static void
setup_search (GtkAppChooserDialog *self) setup_search (GtkAppChooserDialog *self)
{ {
GtkAppChooserDialogPrivate *priv = gtk_app_chooser_dialog_get_instance_private (self);
gboolean use_header; gboolean use_header;
g_object_get (self, "use-header-bar", &use_header, NULL); g_object_get (self, "use-header-bar", &use_header, NULL);
@ -501,12 +512,12 @@ setup_search (GtkAppChooserDialog *self)
header = gtk_dialog_get_header_bar (GTK_DIALOG (self)); header = gtk_dialog_get_header_bar (GTK_DIALOG (self));
gtk_header_bar_pack_end (GTK_HEADER_BAR (header), button); gtk_header_bar_pack_end (GTK_HEADER_BAR (header), button);
gtk_size_group_add_widget (self->priv->buttons, button); gtk_size_group_add_widget (priv->buttons, button);
g_object_bind_property (button, "active", g_object_bind_property (button, "active",
self->priv->search_bar, "search-mode-enabled", priv->search_bar, "search-mode-enabled",
G_BINDING_BIDIRECTIONAL); G_BINDING_BIDIRECTIONAL);
g_object_bind_property (self->priv->search_entry, "sensitive", g_object_bind_property (priv->search_entry, "sensitive",
button, "sensitive", button, "sensitive",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE); G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
} }
@ -530,10 +541,11 @@ static void
gtk_app_chooser_dialog_dispose (GObject *object) gtk_app_chooser_dialog_dispose (GObject *object)
{ {
GtkAppChooserDialog *self = GTK_APP_CHOOSER_DIALOG (object); GtkAppChooserDialog *self = GTK_APP_CHOOSER_DIALOG (object);
GtkAppChooserDialogPrivate *priv = gtk_app_chooser_dialog_get_instance_private (self);
g_clear_object (&self->priv->gfile); g_clear_object (&priv->gfile);
self->priv->dismissed = TRUE; priv->dismissed = TRUE;
G_OBJECT_CLASS (gtk_app_chooser_dialog_parent_class)->dispose (object); G_OBJECT_CLASS (gtk_app_chooser_dialog_parent_class)->dispose (object);
} }
@ -542,9 +554,10 @@ static void
gtk_app_chooser_dialog_finalize (GObject *object) gtk_app_chooser_dialog_finalize (GObject *object)
{ {
GtkAppChooserDialog *self = GTK_APP_CHOOSER_DIALOG (object); GtkAppChooserDialog *self = GTK_APP_CHOOSER_DIALOG (object);
GtkAppChooserDialogPrivate *priv = gtk_app_chooser_dialog_get_instance_private (self);
g_free (self->priv->content_type); g_free (priv->content_type);
g_free (self->priv->heading); g_free (priv->heading);
G_OBJECT_CLASS (gtk_app_chooser_dialog_parent_class)->finalize (object); G_OBJECT_CLASS (gtk_app_chooser_dialog_parent_class)->finalize (object);
} }
@ -556,6 +569,7 @@ gtk_app_chooser_dialog_set_property (GObject *object,
GParamSpec *pspec) GParamSpec *pspec)
{ {
GtkAppChooserDialog *self = GTK_APP_CHOOSER_DIALOG (object); GtkAppChooserDialog *self = GTK_APP_CHOOSER_DIALOG (object);
GtkAppChooserDialogPrivate *priv = gtk_app_chooser_dialog_get_instance_private (self);
switch (property_id) switch (property_id)
{ {
@ -564,8 +578,8 @@ gtk_app_chooser_dialog_set_property (GObject *object,
break; break;
case PROP_CONTENT_TYPE: case PROP_CONTENT_TYPE:
/* don't try to override a value previously set with the GFile */ /* don't try to override a value previously set with the GFile */
if (self->priv->content_type == NULL) if (priv->content_type == NULL)
self->priv->content_type = g_value_dup_string (value); priv->content_type = g_value_dup_string (value);
break; break;
case PROP_HEADING: case PROP_HEADING:
gtk_app_chooser_dialog_set_heading (self, g_value_get_string (value)); gtk_app_chooser_dialog_set_heading (self, g_value_get_string (value));
@ -583,18 +597,19 @@ gtk_app_chooser_dialog_get_property (GObject *object,
GParamSpec *pspec) GParamSpec *pspec)
{ {
GtkAppChooserDialog *self = GTK_APP_CHOOSER_DIALOG (object); GtkAppChooserDialog *self = GTK_APP_CHOOSER_DIALOG (object);
GtkAppChooserDialogPrivate *priv = gtk_app_chooser_dialog_get_instance_private (self);
switch (property_id) switch (property_id)
{ {
case PROP_GFILE: case PROP_GFILE:
if (self->priv->gfile != NULL) if (priv->gfile != NULL)
g_value_set_object (value, self->priv->gfile); g_value_set_object (value, priv->gfile);
break; break;
case PROP_CONTENT_TYPE: case PROP_CONTENT_TYPE:
g_value_set_string (value, self->priv->content_type); g_value_set_string (value, priv->content_type);
break; break;
case PROP_HEADING: case PROP_HEADING:
g_value_set_string (value, self->priv->heading); g_value_set_string (value, priv->heading);
break; break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@ -674,8 +689,6 @@ gtk_app_chooser_dialog_class_init (GtkAppChooserDialogClass *klass)
static void static void
gtk_app_chooser_dialog_init (GtkAppChooserDialog *self) gtk_app_chooser_dialog_init (GtkAppChooserDialog *self)
{ {
self->priv = gtk_app_chooser_dialog_get_instance_private (self);
gtk_widget_init_template (GTK_WIDGET (self)); gtk_widget_init_template (GTK_WIDGET (self));
gtk_dialog_set_use_header_bar_from_setting (GTK_DIALOG (self)); gtk_dialog_set_use_header_bar_from_setting (GTK_DIALOG (self));
@ -770,9 +783,11 @@ gtk_app_chooser_dialog_new_for_content_type (GtkWindow *parent,
GtkWidget * GtkWidget *
gtk_app_chooser_dialog_get_widget (GtkAppChooserDialog *self) gtk_app_chooser_dialog_get_widget (GtkAppChooserDialog *self)
{ {
GtkAppChooserDialogPrivate *priv = gtk_app_chooser_dialog_get_instance_private (self);
g_return_val_if_fail (GTK_IS_APP_CHOOSER_DIALOG (self), NULL); g_return_val_if_fail (GTK_IS_APP_CHOOSER_DIALOG (self), NULL);
return self->priv->app_chooser_widget; return priv->app_chooser_widget;
} }
/** /**
@ -787,21 +802,23 @@ void
gtk_app_chooser_dialog_set_heading (GtkAppChooserDialog *self, gtk_app_chooser_dialog_set_heading (GtkAppChooserDialog *self,
const gchar *heading) const gchar *heading)
{ {
GtkAppChooserDialogPrivate *priv = gtk_app_chooser_dialog_get_instance_private (self);
g_return_if_fail (GTK_IS_APP_CHOOSER_DIALOG (self)); g_return_if_fail (GTK_IS_APP_CHOOSER_DIALOG (self));
g_free (self->priv->heading); g_free (priv->heading);
self->priv->heading = g_strdup (heading); priv->heading = g_strdup (heading);
if (self->priv->label) if (priv->label)
{ {
if (self->priv->heading) if (priv->heading)
{ {
gtk_label_set_markup (GTK_LABEL (self->priv->label), self->priv->heading); gtk_label_set_markup (GTK_LABEL (priv->label), priv->heading);
gtk_widget_show (self->priv->label); gtk_widget_show (priv->label);
} }
else else
{ {
gtk_widget_hide (self->priv->label); gtk_widget_hide (priv->label);
} }
} }
@ -820,7 +837,9 @@ gtk_app_chooser_dialog_set_heading (GtkAppChooserDialog *self,
const gchar * const gchar *
gtk_app_chooser_dialog_get_heading (GtkAppChooserDialog *self) gtk_app_chooser_dialog_get_heading (GtkAppChooserDialog *self)
{ {
GtkAppChooserDialogPrivate *priv = gtk_app_chooser_dialog_get_instance_private (self);
g_return_val_if_fail (GTK_IS_APP_CHOOSER_DIALOG (self), NULL); g_return_val_if_fail (GTK_IS_APP_CHOOSER_DIALOG (self), NULL);
return self->priv->heading; return priv->heading;
} }