summaryrefslogtreecommitdiff
path: root/panels
diff options
context:
space:
mode:
Diffstat (limited to 'panels')
-rw-r--r--panels/printers/pp-details-dialog.c8
-rw-r--r--panels/printers/pp-new-printer-dialog.c22
-rw-r--r--panels/printers/pp-ppd-selection-dialog.c156
-rw-r--r--panels/printers/pp-ppd-selection-dialog.h5
-rw-r--r--panels/printers/ppd-selection-dialog.ui20
5 files changed, 92 insertions, 119 deletions
diff --git a/panels/printers/pp-details-dialog.c b/panels/printers/pp-details-dialog.c
index 8882a0f49..28b047234 100644
--- a/panels/printers/pp-details-dialog.c
+++ b/panels/printers/pp-details-dialog.c
@@ -174,7 +174,7 @@ ppd_selection_dialog_response_cb (GtkDialog *dialog,
}
}
- g_clear_object (&self->pp_ppd_selection_dialog);
+ gtk_widget_destroy (GTK_WIDGET (self->pp_ppd_selection_dialog));
self->pp_ppd_selection_dialog = NULL;
}
@@ -231,11 +231,15 @@ select_ppd_in_dialog (PpDetailsDialog *self)
}
self->pp_ppd_selection_dialog = pp_ppd_selection_dialog_new (
- GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (self))),
self->all_ppds_list,
manufacturer,
ppd_selection_dialog_response_cb,
self);
+
+ gtk_window_set_transient_for (GTK_WINDOW (self->pp_ppd_selection_dialog),
+ GTK_WINDOW (self));
+
+ gtk_dialog_run (GTK_DIALOG (self->pp_ppd_selection_dialog));
}
}
diff --git a/panels/printers/pp-new-printer-dialog.c b/panels/printers/pp-new-printer-dialog.c
index d26e5b7a7..4a62bf2f3 100644
--- a/panels/printers/pp-new-printer-dialog.c
+++ b/panels/printers/pp-new-printer-dialog.c
@@ -539,7 +539,6 @@ pp_new_printer_dialog_finalize (GObject *object)
g_clear_pointer (&self->list, ppd_list_free);
g_clear_object (&self->builder);
g_clear_pointer (&self->local_cups_devices, g_ptr_array_unref);
- g_clear_object (&self->ppd_selection_dialog);
g_clear_object (&self->new_device);
g_clear_object (&self->local_printer_icon);
g_clear_object (&self->remote_printer_icon);
@@ -1902,15 +1901,14 @@ ppd_selection_cb (GtkDialog *_dialog,
guint window_id = 0;
gint acquisition_method;
- if (response_id != GTK_RESPONSE_OK) {
+ if (response_id == GTK_RESPONSE_OK) {
+ ppd_name = pp_ppd_selection_dialog_get_ppd_name (self->ppd_selection_dialog);
+ ppd_display_name = pp_ppd_selection_dialog_get_ppd_display_name (self->ppd_selection_dialog);
+ }
+ else {
emit_response (self, GTK_RESPONSE_CANCEL);
- return;
}
- ppd_name = pp_ppd_selection_dialog_get_ppd_name (self->ppd_selection_dialog);
- ppd_display_name = pp_ppd_selection_dialog_get_ppd_display_name (self->ppd_selection_dialog);
- g_clear_object (&self->ppd_selection_dialog);
-
if (ppd_name)
{
g_object_set (self->new_device, "device-ppd", ppd_name, NULL);
@@ -1980,6 +1978,8 @@ ppd_selection_cb (GtkDialog *_dialog,
g_clear_object (&self->new_device);
}
+
+ gtk_widget_destroy (GTK_WIDGET (self->ppd_selection_dialog));
}
static void
@@ -2018,11 +2018,15 @@ new_printer_dialog_response_cb (PpNewPrinterDialog *self,
{
self->new_device = pp_print_device_copy (device);
self->ppd_selection_dialog =
- pp_ppd_selection_dialog_new (self->parent,
- self->list,
+ pp_ppd_selection_dialog_new (self->list,
NULL,
ppd_selection_cb,
self);
+
+ gtk_window_set_transient_for (GTK_WINDOW (self->ppd_selection_dialog),
+ GTK_WINDOW (self->parent));
+
+ gtk_dialog_run (GTK_DIALOG (self->ppd_selection_dialog));
}
else
{
diff --git a/panels/printers/pp-ppd-selection-dialog.c b/panels/printers/pp-ppd-selection-dialog.c
index f3ae05c7b..e7f110a38 100644
--- a/panels/printers/pp-ppd-selection-dialog.c
+++ b/panels/printers/pp-ppd-selection-dialog.c
@@ -49,10 +49,13 @@ enum
struct _PpPPDSelectionDialog {
- GObject parent_instance;
+ GtkDialog parent_instance;
- GtkBuilder *builder;
- GtkWidget *dialog;
+ GtkButton *ppd_selection_select_button;
+ GtkSpinner *ppd_spinner;
+ GtkLabel *progress_label;
+ GtkTreeView *ppd_selection_manufacturers_treeview;
+ GtkTreeView *ppd_selection_models_treeview;
UserResponseCallback user_callback;
gpointer user_data;
@@ -64,7 +67,7 @@ struct _PpPPDSelectionDialog {
PPDList *list;
};
-G_DEFINE_TYPE (PpPPDSelectionDialog, pp_ppd_selection_dialog, G_TYPE_OBJECT)
+G_DEFINE_TYPE (PpPPDSelectionDialog, pp_ppd_selection_dialog, GTK_TYPE_DIALOG)
static void
manufacturer_selection_changed_cb (PpPPDSelectionDialog *self)
@@ -77,12 +80,12 @@ manufacturer_selection_changed_cb (PpPPDSelectionDialog *self)
gchar *manufacturer_name = NULL;
gint i, index;
- treeview = GTK_TREE_VIEW (gtk_builder_get_object (self->builder, "ppd-selection-manufacturers-treeview"));
+ treeview = self->ppd_selection_manufacturers_treeview;
if (gtk_tree_selection_get_selected (gtk_tree_view_get_selection (treeview), &model, &iter))
{
gtk_tree_model_get (model, &iter,
- PPD_MANUFACTURERS_NAMES_COLUMN, &manufacturer_name,
- -1);
+ PPD_MANUFACTURERS_NAMES_COLUMN, &manufacturer_name,
+ -1);
}
if (manufacturer_name)
@@ -100,8 +103,7 @@ manufacturer_selection_changed_cb (PpPPDSelectionDialog *self)
if (index >= 0)
{
- models_treeview = (GtkTreeView*)
- gtk_builder_get_object (self->builder, "ppd-selection-models-treeview");
+ models_treeview = self->ppd_selection_models_treeview;
store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_STRING);
@@ -128,28 +130,27 @@ model_selection_changed_cb (PpPPDSelectionDialog *self)
GtkTreeView *treeview;
GtkTreeModel *model;
GtkTreeIter iter;
- GtkWidget *widget;
+ GtkButton *ppd_select_button;
gchar *model_name = NULL;
- treeview = GTK_TREE_VIEW (gtk_builder_get_object (self->builder, "ppd-selection-models-treeview"));
+ treeview = self->ppd_selection_models_treeview;
if (gtk_tree_selection_get_selected (gtk_tree_view_get_selection (treeview), &model, &iter))
{
gtk_tree_model_get (model, &iter,
PPD_NAMES_COLUMN, &model_name,
- -1);
+ -1);
}
- widget = (GtkWidget*)
- gtk_builder_get_object (self->builder, "ppd-selection-select-button");
+ ppd_select_button = self->ppd_selection_select_button;
if (model_name)
{
- gtk_widget_set_sensitive (widget, TRUE);
+ gtk_widget_set_sensitive (GTK_WIDGET (ppd_select_button), TRUE);
g_free (model_name);
}
else
{
- gtk_widget_set_sensitive (widget, FALSE);
+ gtk_widget_set_sensitive (GTK_WIDGET (ppd_select_button), FALSE);
}
}
@@ -162,20 +163,14 @@ fill_ppds_list (PpPPDSelectionDialog *self)
GtkTreeView *treeview;
GtkTreeIter iter;
GtkTreeIter *preselect_iter = NULL;
- GtkWidget *widget;
gint i;
- widget = (GtkWidget*)
- gtk_builder_get_object (self->builder, "ppd-spinner");
- gtk_widget_hide (widget);
- gtk_spinner_stop (GTK_SPINNER (widget));
+ gtk_widget_hide (GTK_WIDGET (self->ppd_spinner));
+ gtk_spinner_stop (self->ppd_spinner);
- widget = (GtkWidget*)
- gtk_builder_get_object (self->builder, "progress-label");
- gtk_widget_hide (widget);
+ gtk_widget_hide (GTK_WIDGET (self->progress_label));
- treeview = (GtkTreeView*)
- gtk_builder_get_object (self->builder, "ppd-selection-manufacturers-treeview");
+ treeview = self->ppd_selection_manufacturers_treeview;
if (self->list)
{
@@ -217,11 +212,9 @@ populate_dialog (PpPPDSelectionDialog *self)
GtkCellRenderer *renderer;
GtkTreeView *manufacturers_treeview;
GtkTreeView *models_treeview;
- GtkWidget *widget;
GtkWidget *header;
- manufacturers_treeview = (GtkTreeView*)
- gtk_builder_get_object (self->builder, "ppd-selection-manufacturers-treeview");
+ manufacturers_treeview = self->ppd_selection_manufacturers_treeview;
renderer = gtk_cell_renderer_text_new ();
gtk_cell_renderer_set_padding (renderer, 10, 0);
@@ -237,8 +230,7 @@ populate_dialog (PpPPDSelectionDialog *self)
gtk_tree_view_append_column (manufacturers_treeview, column);
- models_treeview = (GtkTreeView*)
- gtk_builder_get_object (self->builder, "ppd-selection-models-treeview");
+ models_treeview = self->ppd_selection_models_treeview;
renderer = gtk_cell_renderer_text_new ();
gtk_cell_renderer_set_padding (renderer, 10, 0);
@@ -261,13 +253,12 @@ populate_dialog (PpPPDSelectionDialog *self)
g_signal_connect_object (gtk_tree_view_get_selection (manufacturers_treeview),
"changed", G_CALLBACK (manufacturer_selection_changed_cb), self, G_CONNECT_SWAPPED);
- gtk_widget_show (self->dialog);
-
if (!self->list)
{
- widget = (GtkWidget*)
- gtk_builder_get_object (self->builder, "ppd-spinner");
- gtk_spinner_start (GTK_SPINNER (widget));
+ gtk_widget_show (GTK_WIDGET (self->ppd_spinner));
+ gtk_spinner_start (self->ppd_spinner);
+
+ gtk_widget_show (GTK_WIDGET (self->progress_label));
}
else
{
@@ -284,12 +275,9 @@ ppd_selection_dialog_response_cb (PpPPDSelectionDialog *self,
GtkTreeView *models_treeview;
GtkTreeIter iter;
- gtk_widget_hide (GTK_WIDGET (self->dialog));
-
if (response_id == GTK_RESPONSE_OK)
{
- models_treeview = (GtkTreeView*)
- gtk_builder_get_object (self->builder, "ppd-selection-models-treeview");
+ models_treeview = self->ppd_selection_models_treeview;
if (models_treeview)
{
@@ -302,52 +290,24 @@ ppd_selection_dialog_response_cb (PpPPDSelectionDialog *self,
gtk_tree_model_get (model, &iter,
PPD_NAMES_COLUMN, &self->ppd_name,
PPD_DISPLAY_NAMES_COLUMN, &self->ppd_display_name,
- -1);
+ -1);
}
}
}
}
- self->user_callback (GTK_DIALOG (self->dialog), response_id, self->user_data);
+ self->user_callback (GTK_DIALOG (self), response_id, self->user_data);
}
-static void
-pp_ppd_selection_dialog_finalize (GObject *object)
-{
- PpPPDSelectionDialog *self = PP_PPD_SELECTION_DIALOG (object);
-
- g_clear_object (&self->builder);
- g_clear_pointer (&self->dialog, gtk_widget_destroy);
-
- g_clear_pointer (&self->ppd_name, g_free);
- g_clear_pointer (&self->ppd_name, g_free);
- g_clear_pointer (&self->ppd_display_name, g_free);
-
- G_OBJECT_CLASS (pp_ppd_selection_dialog_parent_class)->finalize (object);
-}
-
-static void
-pp_ppd_selection_dialog_class_init (PpPPDSelectionDialogClass *klass)
-{
- GObjectClass *object_class;
-
- object_class = G_OBJECT_CLASS (klass);
- object_class->finalize = pp_ppd_selection_dialog_finalize;
-}
-
-
PpPPDSelectionDialog *
-pp_ppd_selection_dialog_new (GtkWindow *parent,
- PPDList *ppd_list,
+pp_ppd_selection_dialog_new (PPDList *ppd_list,
const gchar *manufacturer,
UserResponseCallback user_callback,
gpointer user_data)
{
PpPPDSelectionDialog *self;
- GtkWidget *widget;
- g_autoptr(GError) error = NULL;
- self = g_object_new (PP_TYPE_PPD_SELECTION_DIALOG, NULL);
+ self = g_object_new (pp_ppd_selection_dialog_get_type (), NULL);
self->user_callback = user_callback;
self->user_data = user_data;
@@ -356,42 +316,48 @@ pp_ppd_selection_dialog_new (GtkWindow *parent,
self->manufacturer = get_standard_manufacturers_name (manufacturer);
- gtk_window_set_transient_for (GTK_WINDOW (self->dialog), GTK_WINDOW (parent));
+ /* connect signal */
+ g_signal_connect_object (self, "response", G_CALLBACK (ppd_selection_dialog_response_cb), self, G_CONNECT_SWAPPED);
- widget = (GtkWidget*)
- gtk_builder_get_object (self->builder, "ppd-spinner");
- gtk_spinner_start (GTK_SPINNER (widget));
+ gtk_spinner_start (self->ppd_spinner);
populate_dialog (self);
- gtk_window_present (GTK_WINDOW (self->dialog));
-
- return PP_PPD_SELECTION_DIALOG (self);
+ return self;
}
static void
-pp_ppd_selection_dialog_init (PpPPDSelectionDialog *self)
+pp_ppd_selection_dialog_dispose (GObject *object)
{
- g_autoptr(GError) error = NULL;
- gchar *objects[] = { "ppd-selection-dialog", NULL };
- guint builder_result;
+ PpPPDSelectionDialog *self = PP_PPD_SELECTION_DIALOG (object);
- self->builder = gtk_builder_new ();
+ g_clear_pointer (&self->ppd_name, g_free);
+ g_clear_pointer (&self->ppd_display_name, g_free);
+ g_clear_pointer (&self->manufacturer, g_free);
- builder_result = gtk_builder_add_objects_from_resource (self->builder,
- "/org/gnome/control-center/printers/ppd-selection-dialog.ui",
- objects, &error);
+ G_OBJECT_CLASS (pp_ppd_selection_dialog_parent_class)->dispose (object);
+}
- if (builder_result == 0)
- {
- g_warning ("Could not load ui: %s", error->message);
- }
+void
+pp_ppd_selection_dialog_class_init (PpPPDSelectionDialogClass *klass)
+{
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
- self->dialog = (GtkWidget *) gtk_builder_get_object (self->builder, "ppd-selection-dialog");
+ gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/control-center/printers/ppd-selection-dialog.ui");
+ gtk_widget_class_bind_template_child (widget_class, PpPPDSelectionDialog, ppd_selection_select_button);
+ gtk_widget_class_bind_template_child (widget_class, PpPPDSelectionDialog, ppd_spinner);
+ gtk_widget_class_bind_template_child (widget_class, PpPPDSelectionDialog, progress_label);
+ gtk_widget_class_bind_template_child (widget_class, PpPPDSelectionDialog, ppd_selection_manufacturers_treeview);
+ gtk_widget_class_bind_template_child (widget_class, PpPPDSelectionDialog, ppd_selection_models_treeview);
- /* connect signals */
- g_signal_connect (self->dialog, "delete-event", G_CALLBACK (gtk_widget_hide_on_delete), NULL);
- g_signal_connect_object (self->dialog, "response", G_CALLBACK (ppd_selection_dialog_response_cb), self, G_CONNECT_SWAPPED);
+ object_class->dispose = pp_ppd_selection_dialog_dispose;
+}
+
+void
+pp_ppd_selection_dialog_init (PpPPDSelectionDialog *self)
+{
+ gtk_widget_init_template (GTK_WIDGET (self));
}
gchar *
diff --git a/panels/printers/pp-ppd-selection-dialog.h b/panels/printers/pp-ppd-selection-dialog.h
index 36c0342e1..5b4ee22c3 100644
--- a/panels/printers/pp-ppd-selection-dialog.h
+++ b/panels/printers/pp-ppd-selection-dialog.h
@@ -26,10 +26,9 @@
G_BEGIN_DECLS
#define PP_TYPE_PPD_SELECTION_DIALOG (pp_ppd_selection_dialog_get_type ())
-G_DECLARE_FINAL_TYPE (PpPPDSelectionDialog, pp_ppd_selection_dialog, PP, PPD_SELECTION_DIALOG, GObject)
+G_DECLARE_FINAL_TYPE (PpPPDSelectionDialog, pp_ppd_selection_dialog, PP, PPD_SELECTION_DIALOG, GtkDialog)
-PpPPDSelectionDialog *pp_ppd_selection_dialog_new (GtkWindow *parent,
- PPDList *ppd_list,
+PpPPDSelectionDialog *pp_ppd_selection_dialog_new (PPDList *ppd_list,
const gchar *manufacturer,
UserResponseCallback user_callback,
gpointer user_data);
diff --git a/panels/printers/ppd-selection-dialog.ui b/panels/printers/ppd-selection-dialog.ui
index b40a1b1ad..c89ce3563 100644
--- a/panels/printers/ppd-selection-dialog.ui
+++ b/panels/printers/ppd-selection-dialog.ui
@@ -2,7 +2,7 @@
<!-- Generated with glade 3.18.3 -->
<interface>
<requires lib="gtk+" version="3.12"/>
- <object class="GtkDialog" id="ppd-selection-dialog">
+ <template class="PpPPDSelectionDialog" parent="GtkDialog">
<property name="width_request">600</property>
<property name="height_request">400</property>
<property name="can_focus">False</property>
@@ -23,7 +23,7 @@
<property name="can_focus">False</property>
<property name="layout_style">end</property>
<child>
- <object class="GtkButton" id="ppd-selection-cancel-button">
+ <object class="GtkButton" id="ppd_selection_cancel_button">
<property name="label" translatable="yes">Cancel</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
@@ -36,7 +36,7 @@
</packing>
</child>
<child>
- <object class="GtkButton" id="ppd-selection-select-button">
+ <object class="GtkButton" id="ppd_selection_select_button">
<property name="label" translatable="yes">Select</property>
<property name="visible">True</property>
<property name="sensitive">False</property>
@@ -54,7 +54,7 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
- <object class="GtkSpinner" id="ppd-spinner">
+ <object class="GtkSpinner" id="ppd_spinner">
<property name="visible">True</property>
<property name="width_request">24</property>
<property name="height_request">24</property>
@@ -68,7 +68,7 @@
</packing>
</child>
<child>
- <object class="GtkLabel" id="progress-label">
+ <object class="GtkLabel" id="progress_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="no_show_all">True</property>
@@ -112,7 +112,7 @@
<property name="hscrollbar_policy">never</property>
<property name="shadow_type">in</property>
<child>
- <object class="GtkTreeView" id="ppd-selection-manufacturers-treeview">
+ <object class="GtkTreeView" id="ppd_selection_manufacturers_treeview">
<property name="visible">True</property>
<property name="can_focus">True</property>
<child internal-child="selection">
@@ -133,7 +133,7 @@
<property name="can_focus">True</property>
<property name="shadow_type">in</property>
<child>
- <object class="GtkTreeView" id="ppd-selection-models-treeview">
+ <object class="GtkTreeView" id="ppd_selection_models_treeview">
<property name="visible">True</property>
<property name="can_focus">True</property>
<child internal-child="selection">
@@ -158,8 +158,8 @@
</object>
</child>
<action-widgets>
- <action-widget response="-6">ppd-selection-cancel-button</action-widget>
- <action-widget response="-5">ppd-selection-select-button</action-widget>
+ <action-widget response="-6">ppd_selection_cancel_button</action-widget>
+ <action-widget response="-5">ppd_selection_select_button</action-widget>
</action-widgets>
- </object>
+ </template>
</interface>