removable-media: Move other combo box definition into GtkBuilder file

This commit is contained in:
Robert Ancell 2019-09-26 10:38:39 +12:00
parent 2546d02b3d
commit 84b6257d36
2 changed files with 30 additions and 50 deletions

View file

@ -76,6 +76,7 @@ struct _CcRemovableMediaPanel
GtkWidget *media_dialog; GtkWidget *media_dialog;
GtkWidget *media_other_type_combobox; GtkWidget *media_other_type_combobox;
GtkListStore *media_other_type_list_store;
GtkWidget *media_other_action_label; GtkWidget *media_other_action_label;
GtkWidget *media_other_action_container; GtkWidget *media_other_action_container;
}; };
@ -334,43 +335,30 @@ prepare_combo_box (CcRemovableMediaPanel *self,
} }
static void static void
other_type_combo_box_changed (GtkComboBox *combo_box, on_other_type_combo_box_changed (CcRemovableMediaPanel *self)
CcRemovableMediaPanel *self)
{ {
GtkTreeIter iter; GtkTreeIter iter;
GtkTreeModel *model;
g_autofree gchar *x_content_type = NULL; g_autofree gchar *x_content_type = NULL;
GtkWidget *action_container;
GtkWidget *action_label;
if (!gtk_combo_box_get_active_iter (combo_box, &iter)) { if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (self->media_other_type_combobox), &iter)) {
return; return;
} }
model = gtk_combo_box_get_model (combo_box); gtk_tree_model_get (GTK_TREE_MODEL (self->media_other_type_list_store), &iter,
if (model == NULL) {
return;
}
gtk_tree_model_get (model, &iter,
1, &x_content_type, 1, &x_content_type,
-1); -1);
action_container = self->media_other_action_container;
if (self->other_application_combo != NULL) { if (self->other_application_combo != NULL) {
gtk_widget_destroy (self->other_application_combo); gtk_widget_destroy (self->other_application_combo);
} }
self->other_application_combo = gtk_app_chooser_button_new (x_content_type); self->other_application_combo = gtk_app_chooser_button_new (x_content_type);
ellipsize_cell_layout (GTK_CELL_LAYOUT (self->other_application_combo)); ellipsize_cell_layout (GTK_CELL_LAYOUT (self->other_application_combo));
gtk_box_pack_start (GTK_BOX (action_container), self->other_application_combo, TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (self->media_other_action_container), self->other_application_combo, TRUE, TRUE, 0);
prepare_combo_box (self, self->other_application_combo, NULL); prepare_combo_box (self, self->other_application_combo, NULL);
gtk_widget_show (self->other_application_combo); gtk_widget_show (self->other_application_combo);
action_label = self->media_other_action_label; gtk_label_set_mnemonic_widget (GTK_LABEL (self->media_other_action_label), self->other_application_combo);
gtk_label_set_mnemonic_widget (GTK_LABEL (action_label), self->other_application_combo);
} }
static void static void
@ -390,10 +378,6 @@ static void
on_extra_options_button_clicked (GtkWidget *button, on_extra_options_button_clicked (GtkWidget *button,
CcRemovableMediaPanel *self) CcRemovableMediaPanel *self)
{ {
GtkWidget *combo_box;
combo_box = self->media_other_type_combobox;
gtk_window_set_transient_for (GTK_WINDOW (self->media_dialog), gtk_window_set_transient_for (GTK_WINDOW (self->media_dialog),
GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (self)))); GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (self))));
gtk_window_set_modal (GTK_WINDOW (self->media_dialog), TRUE); gtk_window_set_modal (GTK_WINDOW (self->media_dialog), TRUE);
@ -407,7 +391,7 @@ on_extra_options_button_clicked (GtkWidget *button,
G_CALLBACK (gtk_widget_hide_on_delete), G_CALLBACK (gtk_widget_hide_on_delete),
NULL); NULL);
/* update other_application_combo */ /* update other_application_combo */
other_type_combo_box_changed (GTK_COMBO_BOX (combo_box), self); on_other_type_combo_box_changed (self);
gtk_window_present (GTK_WINDOW (self->media_dialog)); gtk_window_present (GTK_WINDOW (self->media_dialog));
} }
@ -419,10 +403,7 @@ info_panel_setup_media (CcRemovableMediaPanel *self)
{ {
guint n; guint n;
GList *l, *content_types; GList *l, *content_types;
GtkWidget *other_type_combo_box;
GtkWidget *extras_button; GtkWidget *extras_button;
GtkListStore *other_type_list_store;
GtkCellRenderer *renderer;
GtkTreeIter iter; GtkTreeIter iter;
struct { struct {
@ -466,13 +447,7 @@ info_panel_setup_media (CcRemovableMediaPanel *self)
defs[n].heading); defs[n].heading);
} }
other_type_combo_box = self->media_other_type_combobox; gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (self->media_other_type_list_store),
other_type_list_store = gtk_list_store_new (2,
G_TYPE_STRING,
G_TYPE_STRING);
gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (other_type_list_store),
1, GTK_SORT_ASCENDING); 1, GTK_SORT_ASCENDING);
@ -508,9 +483,9 @@ info_panel_setup_media (CcRemovableMediaPanel *self)
description = g_content_type_get_description (content_type); description = g_content_type_get_description (content_type);
} }
gtk_list_store_append (other_type_list_store, &iter); gtk_list_store_append (self->media_other_type_list_store, &iter);
gtk_list_store_set (other_type_list_store, &iter, gtk_list_store_set (self->media_other_type_list_store, &iter,
0, description, 0, description,
1, content_type, 1, content_type,
-1); -1);
@ -520,21 +495,7 @@ info_panel_setup_media (CcRemovableMediaPanel *self)
g_list_free_full (content_types, g_free); g_list_free_full (content_types, g_free);
gtk_combo_box_set_model (GTK_COMBO_BOX (other_type_combo_box), gtk_combo_box_set_active (GTK_COMBO_BOX (self->media_other_type_combobox), 0);
GTK_TREE_MODEL (other_type_list_store));
renderer = gtk_cell_renderer_text_new ();
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (other_type_combo_box), renderer, TRUE);
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (other_type_combo_box), renderer,
"text", 0,
NULL);
g_signal_connect (other_type_combo_box,
"changed",
G_CALLBACK (other_type_combo_box_changed),
self);
gtk_combo_box_set_active (GTK_COMBO_BOX (other_type_combo_box), 0);
extras_button = self->extra_options_button; extras_button = self->extra_options_button;
g_signal_connect (extras_button, g_signal_connect (extras_button,
@ -599,8 +560,11 @@ cc_removable_media_panel_class_init (CcRemovableMediaPanelClass *klass)
gtk_widget_class_bind_template_child (widget_class, CcRemovableMediaPanel, media_dialog); gtk_widget_class_bind_template_child (widget_class, CcRemovableMediaPanel, media_dialog);
gtk_widget_class_bind_template_child (widget_class, CcRemovableMediaPanel, media_other_type_combobox); gtk_widget_class_bind_template_child (widget_class, CcRemovableMediaPanel, media_other_type_combobox);
gtk_widget_class_bind_template_child (widget_class, CcRemovableMediaPanel, media_other_type_list_store);
gtk_widget_class_bind_template_child (widget_class, CcRemovableMediaPanel, media_other_action_label); gtk_widget_class_bind_template_child (widget_class, CcRemovableMediaPanel, media_other_action_label);
gtk_widget_class_bind_template_child (widget_class, CcRemovableMediaPanel, media_other_action_container); gtk_widget_class_bind_template_child (widget_class, CcRemovableMediaPanel, media_other_action_container);
gtk_widget_class_bind_template_callback (widget_class, on_other_type_combo_box_changed);
} }
static void static void

View file

@ -364,6 +364,14 @@
<object class="GtkComboBox" id="media_other_type_combobox"> <object class="GtkComboBox" id="media_other_type_combobox">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="model">media_other_type_list_store</property>
<signal name="changed" handler="on_other_type_combo_box_changed" object="CcRemovableMediaPanel" swapped="yes"/>
<child>
<object class="GtkCellRendererText"/>
<attributes>
<attribute name="text">0</attribute>
</attributes>
</child>
</object> </object>
<packing> <packing>
<property name="left_attach">1</property> <property name="left_attach">1</property>
@ -438,4 +446,12 @@
</object> </object>
</child> </child>
</object> </object>
<object class="GtkListStore" id="media_other_type_list_store">
<columns>
<!-- column-name description -->
<column type="gchararray"/>
<!-- column-name content-type -->
<column type="gchararray"/>
</columns>
</object>
</interface> </interface>