[gnome-control-center] printers: Convert jobs dialog to use GtkTemplate



commit c0cd99d2a832d2dd5170274dfb82d3b9dc0eeca1
Author: Robert Ancell <robert ancell canonical com>
Date:   Wed Jul 4 15:34:05 2018 +1200

    printers: Convert jobs dialog to use GtkTemplate

 panels/printers/meson.build                        |   2 +-
 panels/printers/pp-jobs-dialog.c                   | 287 ++++++++-------------
 panels/printers/pp-jobs-dialog.h                   |  16 +-
 .../printers/{jobs-dialog.ui => pp-jobs-dialog.ui} |  61 ++---
 panels/printers/pp-printer-entry.c                 |  20 +-
 panels/printers/printers.gresource.xml             |   2 +-
 po/POTFILES.in                                     |   2 +-
 7 files changed, 153 insertions(+), 237 deletions(-)
---
diff --git a/panels/printers/meson.build b/panels/printers/meson.build
index fa1ae99d5..f887625db 100644
--- a/panels/printers/meson.build
+++ b/panels/printers/meson.build
@@ -40,10 +40,10 @@ sources = files(
 
 resource_data = files(
   'authentication-dialog.ui',
-  'jobs-dialog.ui',
   'new-printer-dialog.ui',
   'ppd-selection-dialog.ui',
   'pp-details-dialog.ui',
+  'pp-jobs-dialog.ui',
   'pp-options-dialog.ui',
   'printer-entry.ui',
   'printers.ui'
diff --git a/panels/printers/pp-jobs-dialog.c b/panels/printers/pp-jobs-dialog.c
index 3fb0fb20c..3e0805cfe 100644
--- a/panels/printers/pp-jobs-dialog.c
+++ b/panels/printers/pp-jobs-dialog.c
@@ -43,17 +43,26 @@
 #define CLOCK_SCHEMA "org.gnome.desktop.interface"
 #define CLOCK_FORMAT_KEY "clock-format"
 
-static void pp_jobs_dialog_hide (PpJobsDialog *self);
-
 struct _PpJobsDialog {
-  GtkBuilder *builder;
-
-  GtkWidget  *dialog;
-  GListStore *store;
-  GtkListBox *listbox;
-
-  UserResponseCallback user_callback;
-  gpointer             user_data;
+  GtkDialog   parent_instance;
+
+  GtkButton         *authenticate_button;
+  GtkMenuButton     *authenticate_jobs_button;
+  GtkLabel          *authenticate_jobs_label;
+  GtkInfoBar        *authentication_infobar;
+  GtkLabel          *authentication_label;
+  GtkEntry          *domain_entry;
+  GtkLabel          *domain_label;
+  GtkButton         *jobs_clear_all_button;
+  GtkListBox        *jobs_listbox;
+  GtkScrolledWindow *list_jobs_page;
+  GtkBox            *no_jobs_page;
+  GtkEntry          *password_entry;
+  GtkLabel          *password_label;
+  GtkStack          *stack;
+  GListStore        *store;
+  GtkEntry          *username_entry;
+  GtkLabel          *username_label;
 
   gchar *printer_name;
 
@@ -64,12 +73,14 @@ struct _PpJobsDialog {
   GCancellable *get_jobs_cancellable;
 };
 
+G_DEFINE_TYPE (PpJobsDialog, pp_jobs_dialog, GTK_TYPE_DIALOG)
+
 static gboolean
 is_info_required (PpJobsDialog *self,
                   const gchar  *info)
 {
-  gboolean   required = FALSE;
-  gint       i;
+  gboolean  required = FALSE;
+  gint      i;
 
   if (self != NULL && self->actual_auth_info_required != NULL)
     {
@@ -118,9 +129,9 @@ auth_popup_filled (PpJobsDialog *self)
   username_required = is_username_required (self);
   password_required = is_password_required (self);
 
-  domain_length = gtk_entry_get_text_length (GTK_ENTRY (gtk_builder_get_object (self->builder, 
"domain-entry")));
-  username_length = gtk_entry_get_text_length (GTK_ENTRY (gtk_builder_get_object (self->builder, 
"username-entry")));
-  password_length = gtk_entry_get_text_length (GTK_ENTRY (gtk_builder_get_object (self->builder, 
"password-entry")));
+  domain_length = gtk_entry_get_text_length (self->domain_entry);
+  username_length = gtk_entry_get_text_length (self->username_entry);
+  password_length = gtk_entry_get_text_length (self->password_entry);
 
   return (!domain_required || domain_length > 0) &&
          (!username_required || username_length > 0) &&
@@ -128,30 +139,21 @@ auth_popup_filled (PpJobsDialog *self)
 }
 
 static void
-auth_entries_changed (GtkEntry     *entry,
-                      PpJobsDialog *self)
+auth_entries_changed (PpJobsDialog *self)
 {
-  GtkWidget *widget;
-
-  widget = GTK_WIDGET (gtk_builder_get_object (self->builder, "authenticate-button"));
-  gtk_widget_set_sensitive (widget, auth_popup_filled (self));
+  gtk_widget_set_sensitive (GTK_WIDGET (self->authenticate_button), auth_popup_filled (self));
 }
 
 static void
-auth_entries_activated (GtkEntry     *entry,
-                        PpJobsDialog *self)
+auth_entries_activated (PpJobsDialog *self)
 {
-  GtkWidget *widget;
-
-  widget = GTK_WIDGET (gtk_builder_get_object (self->builder, "authenticate-button"));
   if (auth_popup_filled (self))
-    gtk_button_clicked (GTK_BUTTON (widget));
+    gtk_button_clicked (self->authenticate_button);
 }
 
 static void
 authenticate_popover_update (PpJobsDialog *self)
 {
-  GtkWidget *widget;
   gboolean   domain_required;
   gboolean   username_required;
   gboolean   password_required;
@@ -160,29 +162,22 @@ authenticate_popover_update (PpJobsDialog *self)
   username_required = is_username_required (self);
   password_required = is_password_required (self);
 
-  widget = GTK_WIDGET (gtk_builder_get_object (GTK_BUILDER (self->builder), "domain-label"));
-  gtk_widget_set_visible (widget, domain_required);
-  widget = GTK_WIDGET (gtk_builder_get_object (GTK_BUILDER (self->builder), "domain-entry"));
-  gtk_widget_set_visible (widget, domain_required);
+  gtk_widget_set_visible (GTK_WIDGET (self->domain_label), domain_required);
+  gtk_widget_set_visible (GTK_WIDGET (self->domain_entry), domain_required);
   if (domain_required)
-    gtk_entry_set_text (GTK_ENTRY (widget), "");
+    gtk_entry_set_text (self->domain_entry, "");
 
-  widget = GTK_WIDGET (gtk_builder_get_object (GTK_BUILDER (self->builder), "username-label"));
-  gtk_widget_set_visible (widget, username_required);
-  widget = GTK_WIDGET (gtk_builder_get_object (GTK_BUILDER (self->builder), "username-entry"));
-  gtk_widget_set_visible (widget, username_required);
+  gtk_widget_set_visible (GTK_WIDGET (self->username_label), username_required);
+  gtk_widget_set_visible (GTK_WIDGET (self->username_entry), username_required);
   if (username_required)
-    gtk_entry_set_text (GTK_ENTRY (widget), cupsUser ());
+    gtk_entry_set_text (self->username_entry, cupsUser ());
 
-  widget = GTK_WIDGET (gtk_builder_get_object (GTK_BUILDER (self->builder), "password-label"));
-  gtk_widget_set_visible (widget, password_required);
-  widget = GTK_WIDGET (gtk_builder_get_object (GTK_BUILDER (self->builder), "password-entry"));
-  gtk_widget_set_visible (widget, password_required);
+  gtk_widget_set_visible (GTK_WIDGET (self->password_label), password_required);
+  gtk_widget_set_visible (GTK_WIDGET (self->password_entry), password_required);
   if (password_required)
-    gtk_entry_set_text (GTK_ENTRY (widget), "");
+    gtk_entry_set_text (self->password_entry, "");
 
-  widget = GTK_WIDGET (gtk_builder_get_object (GTK_BUILDER (self->builder), "authenticate-button"));
-  gtk_widget_set_sensitive (widget, FALSE);
+  gtk_widget_set_sensitive (GTK_WIDGET (self->authenticate_button), FALSE);
 }
 
 static void
@@ -302,13 +297,8 @@ create_listbox_row (gpointer item,
 static void
 pop_up_authentication_popup (PpJobsDialog *self)
 {
-  GtkWidget *widget;
-
   if (self->actual_auth_info_required != NULL)
-    {
-      widget = GTK_WIDGET (gtk_builder_get_object (GTK_BUILDER (self->builder), "authenticate-jobs-button"));
-      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE);
-    }
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->authenticate_jobs_button), TRUE);
 }
 
 static void
@@ -318,10 +308,6 @@ update_jobs_list_cb (GObject      *source_object,
 {
   PpJobsDialog        *self = user_data;
   PpPrinter           *printer = PP_PRINTER (source_object);
-  GtkWidget           *clear_all_button;
-  GtkWidget           *infobar;
-  GtkWidget           *label;
-  GtkStack            *stack;
   g_autoptr(GError)    error = NULL;
   g_autoptr(GPtrArray) jobs;
   PpJob               *job;
@@ -331,9 +317,6 @@ update_jobs_list_cb (GObject      *source_object,
 
   g_list_store_remove_all (self->store);
 
-  stack = GTK_STACK (gtk_builder_get_object (GTK_BUILDER (self->builder), "stack"));
-  clear_all_button = GTK_WIDGET (gtk_builder_get_object (GTK_BUILDER (self->builder), 
"jobs-clear-all-button"));
-
   jobs = pp_printer_get_jobs_finish (printer, result, &error);
   if (error != NULL)
     {
@@ -347,13 +330,13 @@ update_jobs_list_cb (GObject      *source_object,
 
   if (jobs->len > 0)
     {
-      gtk_widget_set_sensitive (clear_all_button, TRUE);
-      gtk_stack_set_visible_child_name (stack, "list-jobs-page");
+      gtk_widget_set_sensitive (GTK_WIDGET (self->jobs_clear_all_button), TRUE);
+      gtk_stack_set_visible_child (self->stack, GTK_WIDGET (self->list_jobs_page));
     }
   else
     {
-      gtk_widget_set_sensitive (clear_all_button, FALSE);
-      gtk_stack_set_visible_child_name (stack, "no-jobs-page");
+      gtk_widget_set_sensitive (GTK_WIDGET (self->jobs_clear_all_button), FALSE);
+      gtk_stack_set_visible_child (self->stack, GTK_WIDGET (self->no_jobs_page));
     }
 
   for (i = 0; i < jobs->len; i++)
@@ -378,22 +361,19 @@ update_jobs_list_cb (GObject      *source_object,
         }
     }
 
-  infobar = GTK_WIDGET (gtk_builder_get_object (GTK_BUILDER (self->builder), "authentication-infobar"));
   if (num_of_auth_jobs > 0)
     {
       g_autofree gchar *text = NULL;
 
-      label = GTK_WIDGET (gtk_builder_get_object (GTK_BUILDER (self->builder), "authenticate-jobs-label"));
-
       /* Translators: This label shows how many jobs of this printer needs to be authenticated to be 
printed. */
       text = g_strdup_printf (ngettext ("%u Job Requires Authentication", "%u Jobs Require Authentication", 
num_of_auth_jobs), num_of_auth_jobs);
-      gtk_label_set_text (GTK_LABEL (label), text);
+      gtk_label_set_text (self->authenticate_jobs_label, text);
 
-      gtk_widget_show (infobar);
+      gtk_widget_show (GTK_WIDGET (self->authentication_infobar));
     }
   else
     {
-      gtk_widget_hide (infobar);
+      gtk_widget_hide (GTK_WIDGET (self->authentication_infobar));
     }
 
   authenticate_popover_update (self);
@@ -435,24 +415,8 @@ update_jobs_list (PpJobsDialog *self)
 }
 
 static void
-jobs_dialog_response_cb (GtkDialog *dialog,
-                         gint       response_id,
-                         gpointer   user_data)
-{
-  PpJobsDialog *self = (PpJobsDialog*) user_data;
-
-  pp_jobs_dialog_hide (self);
-
-  self->user_callback (GTK_DIALOG (self->dialog),
-                       response_id,
-                       self->user_data);
-}
-
-static void
-on_clear_all_button_clicked (GtkButton *button,
-                             gpointer   user_data)
+on_clear_all_button_clicked (PpJobsDialog *self)
 {
-  PpJobsDialog *self = user_data;
   guint num_items;
   guint i;
 
@@ -491,11 +455,8 @@ pp_job_authenticate_cb (GObject      *source_object,
 }
 
 static void
-authenticate_button_clicked (GtkWidget *button,
-                             gpointer   user_data)
+authenticate_button_clicked (PpJobsDialog *self)
 {
-  PpJobsDialog *self = user_data;
-  GtkWidget    *widget;
   PpJob        *job;
   gchar       **auth_info_required = NULL;
   gchar       **auth_info;
@@ -506,16 +467,11 @@ authenticate_button_clicked (GtkWidget *button,
   for (i = 0; self->actual_auth_info_required[i] != NULL; i++)
     {
       if (g_strcmp0 (self->actual_auth_info_required[i], "domain") == 0)
-        widget = GTK_WIDGET (gtk_builder_get_object (GTK_BUILDER (self->builder), "domain-entry"));
+        auth_info[i] = g_strdup (gtk_entry_get_text (GTK_ENTRY (self->domain_entry)));
       else if (g_strcmp0 (self->actual_auth_info_required[i], "username") == 0)
-        widget = GTK_WIDGET (gtk_builder_get_object (GTK_BUILDER (self->builder), "username-entry"));
+        auth_info[i] = g_strdup (gtk_entry_get_text (GTK_ENTRY (self->username_entry)));
       else if (g_strcmp0 (self->actual_auth_info_required[i], "password") == 0)
-        widget = GTK_WIDGET (gtk_builder_get_object (GTK_BUILDER (self->builder), "password-entry"));
-      else
-        widget = NULL;
-
-      if (widget != NULL)
-        auth_info[i] = g_strdup (gtk_entry_get_text (GTK_ENTRY (widget)));
+        auth_info[i] = g_strdup (gtk_entry_get_text (GTK_ENTRY (self->password_entry)));
     }
 
   num_items = g_list_model_get_n_items (G_LIST_MODEL (self->store));
@@ -548,84 +504,40 @@ key_press_event_cb (GtkWidget   *widget,
 }
 
 PpJobsDialog *
-pp_jobs_dialog_new (UserResponseCallback  user_callback,
-                    gpointer              user_data,
-                    gchar                *printer_name)
+pp_jobs_dialog_new (const gchar *printer_name)
 {
-  PpJobsDialog     *self;
-  GtkWidget        *widget;
-  g_autoptr(GError) error = NULL;
-  gchar            *objects[] = { "jobs-dialog", "authentication_popover", NULL };
+  PpJobsDialog *self;
   g_autofree gchar *text = NULL;
-  guint             builder_result;
   g_autofree gchar *title = NULL;
 
-  self = g_new0 (PpJobsDialog, 1);
-
-  self->builder = gtk_builder_new ();
+  self = g_object_new (PP_TYPE_JOBS_DIALOG,
+                       "use-header-bar", 1,
+                       NULL);
 
-  builder_result = gtk_builder_add_objects_from_resource (self->builder,
-                                                          
"/org/gnome/control-center/printers/jobs-dialog.ui",
-                                                          objects, &error);
-
-  if (builder_result == 0)
-    {
-      g_warning ("Could not load ui: %s", error->message);
-      return NULL;
-    }
-
-  self->dialog = (GtkWidget *) gtk_builder_get_object (self->builder, "jobs-dialog");
-  self->user_callback = user_callback;
-  self->user_data = user_data;
   self->printer_name = g_strdup (printer_name);
   self->actual_auth_info_required = NULL;
   self->jobs_filled = FALSE;
   self->pop_up_authentication_popup = FALSE;
 
   /* connect signals */
-  g_signal_connect (self->dialog, "delete-event", G_CALLBACK (gtk_widget_hide_on_delete), NULL);
-  g_signal_connect (self->dialog, "response", G_CALLBACK (jobs_dialog_response_cb), self);
-  g_signal_connect (self->dialog, "key-press-event", G_CALLBACK (key_press_event_cb), NULL);
-
-  widget = GTK_WIDGET (gtk_builder_get_object (self->builder, "jobs-clear-all-button"));
-  g_signal_connect (widget, "clicked", G_CALLBACK (on_clear_all_button_clicked), self);
-
-  widget = GTK_WIDGET (gtk_builder_get_object (self->builder, "authenticate-button"));
-  g_signal_connect (widget, "clicked", G_CALLBACK (authenticate_button_clicked), self);
-
-  widget = GTK_WIDGET (gtk_builder_get_object (self->builder, "domain-entry"));
-  g_signal_connect (widget, "changed", G_CALLBACK (auth_entries_changed), self);
-  g_signal_connect (widget, "activate", G_CALLBACK (auth_entries_activated), self);
-
-  widget = GTK_WIDGET (gtk_builder_get_object (self->builder, "username-entry"));
-  g_signal_connect (widget, "changed", G_CALLBACK (auth_entries_changed), self);
-  g_signal_connect (widget, "activate", G_CALLBACK (auth_entries_activated), self);
-
-  widget = GTK_WIDGET (gtk_builder_get_object (self->builder, "password-entry"));
-  g_signal_connect (widget, "changed", G_CALLBACK (auth_entries_changed), self);
-  g_signal_connect (widget, "activate", G_CALLBACK (auth_entries_activated), self);
+  g_signal_connect (self, "key-press-event", G_CALLBACK (key_press_event_cb), NULL);
 
   /* Translators: This is the printer name for which we are showing the active jobs */
   title = g_strdup_printf (C_("Printer jobs dialog title", "%s — Active Jobs"), printer_name);
-  gtk_window_set_title (GTK_WINDOW (self->dialog), title);
+  gtk_window_set_title (GTK_WINDOW (self), title);
 
   /* Translators: The printer needs authentication info to print. */
   text = g_strdup_printf (_("Enter credentials to print from %s."), printer_name);
-  widget = GTK_WIDGET (gtk_builder_get_object (GTK_BUILDER (self->builder), "authentication-label"));
-  gtk_label_set_text (GTK_LABEL (widget), text);
+  gtk_label_set_text (self->authentication_label, text);
 
-  self->listbox = GTK_LIST_BOX (gtk_builder_get_object (self->builder, "jobs-listbox"));
-  gtk_list_box_set_header_func (self->listbox,
+  gtk_list_box_set_header_func (self->jobs_listbox,
                                 cc_list_box_update_header_func, NULL, NULL);
   self->store = g_list_store_new (pp_job_get_type ());
-  gtk_list_box_bind_model (self->listbox, G_LIST_MODEL (self->store),
+  gtk_list_box_bind_model (self->jobs_listbox, G_LIST_MODEL (self->store),
                            create_listbox_row, NULL, NULL);
 
   update_jobs_list (self);
 
-  gtk_window_present (GTK_WINDOW (self->dialog));
-  gtk_widget_show_all (GTK_WIDGET (self->dialog));
-
   return self;
 }
 
@@ -636,43 +548,62 @@ pp_jobs_dialog_update (PpJobsDialog *self)
 }
 
 void
-pp_jobs_dialog_set_callback (PpJobsDialog         *self,
-                             UserResponseCallback  user_callback,
-                             gpointer              user_data)
+pp_jobs_dialog_authenticate_jobs (PpJobsDialog *self)
 {
-  g_return_if_fail (self != NULL);
+  if (self->jobs_filled)
+    pop_up_authentication_popup (self);
+  else
+    self->pop_up_authentication_popup = TRUE;
+}
 
-  self->user_callback = user_callback;
-  self->user_data = user_data;
+static void
+pp_jobs_dialog_init (PpJobsDialog *dialog)
+{
+  gtk_widget_init_template (GTK_WIDGET (dialog));
 }
 
-void
-pp_jobs_dialog_free (PpJobsDialog *self)
+static void
+pp_jobs_dialog_dispose (GObject *object)
 {
+  PpJobsDialog *self = PP_JOBS_DIALOG (object);
+
   g_cancellable_cancel (self->get_jobs_cancellable);
   g_clear_object (&self->get_jobs_cancellable);
+  g_clear_pointer (&self->actual_auth_info_required, g_strfreev);
+  g_clear_pointer (&self->printer_name, g_free);
 
-  gtk_widget_destroy (GTK_WIDGET (self->dialog));
-  self->dialog = NULL;
-
-  g_strfreev (self->actual_auth_info_required);
-
-  g_clear_object (&self->builder);
-  g_free (self->printer_name);
-  g_free (self);
+  G_OBJECT_CLASS (pp_jobs_dialog_parent_class)->dispose (object);
 }
 
 static void
-pp_jobs_dialog_hide (PpJobsDialog *self)
+pp_jobs_dialog_class_init (PpJobsDialogClass *klass)
 {
-  gtk_widget_hide (GTK_WIDGET (self->dialog));
-}
-
-void
-pp_jobs_dialog_authenticate_jobs (PpJobsDialog *self)
-{
-  if (self->jobs_filled)
-    pop_up_authentication_popup (self);
-  else
-    self->pop_up_authentication_popup = TRUE;
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+  GObjectClass   *object_class = G_OBJECT_CLASS (klass);
+
+  gtk_widget_class_set_template_from_resource (widget_class, 
"/org/gnome/control-center/printers/pp-jobs-dialog.ui");
+
+  gtk_widget_class_bind_template_child (widget_class, PpJobsDialog, authenticate_button);
+  gtk_widget_class_bind_template_child (widget_class, PpJobsDialog, authenticate_jobs_button);
+  gtk_widget_class_bind_template_child (widget_class, PpJobsDialog, authenticate_jobs_label);
+  gtk_widget_class_bind_template_child (widget_class, PpJobsDialog, authentication_infobar);
+  gtk_widget_class_bind_template_child (widget_class, PpJobsDialog, authentication_label);
+  gtk_widget_class_bind_template_child (widget_class, PpJobsDialog, domain_entry);
+  gtk_widget_class_bind_template_child (widget_class, PpJobsDialog, domain_label);
+  gtk_widget_class_bind_template_child (widget_class, PpJobsDialog, jobs_clear_all_button);
+  gtk_widget_class_bind_template_child (widget_class, PpJobsDialog, jobs_listbox);
+  gtk_widget_class_bind_template_child (widget_class, PpJobsDialog, list_jobs_page);
+  gtk_widget_class_bind_template_child (widget_class, PpJobsDialog, no_jobs_page);
+  gtk_widget_class_bind_template_child (widget_class, PpJobsDialog, password_entry);
+  gtk_widget_class_bind_template_child (widget_class, PpJobsDialog, password_label);
+  gtk_widget_class_bind_template_child (widget_class, PpJobsDialog, stack);
+  gtk_widget_class_bind_template_child (widget_class, PpJobsDialog, username_entry);
+  gtk_widget_class_bind_template_child (widget_class, PpJobsDialog, username_label);
+
+  gtk_widget_class_bind_template_callback (widget_class, authenticate_button_clicked);
+  gtk_widget_class_bind_template_callback (widget_class, on_clear_all_button_clicked);
+  gtk_widget_class_bind_template_callback (widget_class, auth_entries_activated);
+  gtk_widget_class_bind_template_callback (widget_class, auth_entries_changed);
+
+  object_class->dispose = pp_jobs_dialog_dispose;
 }
diff --git a/panels/printers/pp-jobs-dialog.h b/panels/printers/pp-jobs-dialog.h
index a1563caf0..c61354bc9 100644
--- a/panels/printers/pp-jobs-dialog.h
+++ b/panels/printers/pp-jobs-dialog.h
@@ -25,17 +25,11 @@
 
 G_BEGIN_DECLS
 
-typedef struct _PpJobsDialog PpJobsDialog;
+#define PP_TYPE_JOBS_DIALOG (pp_jobs_dialog_get_type ())
+G_DECLARE_FINAL_TYPE (PpJobsDialog, pp_jobs_dialog, PP, JOBS_DIALOG, GtkDialog)
 
-PpJobsDialog *pp_jobs_dialog_new               (UserResponseCallback  user_callback,
-                                                gpointer              user_data,
-                                                gchar                *printer_name);
-void          pp_jobs_dialog_update            (PpJobsDialog         *dialog);
-void          pp_jobs_dialog_set_callback      (PpJobsDialog         *dialog,
-                                                UserResponseCallback  user_callback,
-                                                gpointer              user_data);
-void          pp_jobs_dialog_free              (PpJobsDialog         *dialog);
-
-void          pp_jobs_dialog_authenticate_jobs (PpJobsDialog         *dialog);
+PpJobsDialog *pp_jobs_dialog_new               (const gchar  *printer_name);
+void          pp_jobs_dialog_update            (PpJobsDialog *dialog);
+void          pp_jobs_dialog_authenticate_jobs (PpJobsDialog *dialog);
 
 G_END_DECLS
diff --git a/panels/printers/jobs-dialog.ui b/panels/printers/pp-jobs-dialog.ui
similarity index 89%
rename from panels/printers/jobs-dialog.ui
rename to panels/printers/pp-jobs-dialog.ui
index ca2a1a0be..30bd14d50 100644
--- a/panels/printers/jobs-dialog.ui
+++ b/panels/printers/pp-jobs-dialog.ui
@@ -17,7 +17,7 @@
         <property name="orientation">vertical</property>
         <property name="spacing">20</property>
         <child>
-          <object class="GtkLabel" id="authentication-label">
+          <object class="GtkLabel" id="authentication_label">
             <property name="visible">True</property>
             <property name="can_focus">False</property>
             <property name="margin_top">5</property>
@@ -37,7 +37,7 @@
             <property name="row_spacing">10</property>
             <property name="column_spacing">15</property>
             <child>
-              <object class="GtkLabel" id="domain-label">
+              <object class="GtkLabel" id="domain_label">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
                 <property name="halign">start</property>
@@ -50,7 +50,7 @@
               </packing>
             </child>
             <child>
-              <object class="GtkLabel" id="username-label">
+              <object class="GtkLabel" id="username_label">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
                 <property name="halign">start</property>
@@ -63,7 +63,7 @@
               </packing>
             </child>
             <child>
-              <object class="GtkLabel" id="password-label">
+              <object class="GtkLabel" id="password_label">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
                 <property name="halign">start</property>
@@ -76,10 +76,12 @@
               </packing>
             </child>
             <child>
-              <object class="GtkEntry" id="domain-entry">
+              <object class="GtkEntry" id="domain_entry">
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
                 <property name="hexpand">True</property>
+                <signal name="changed" handler="auth_entries_changed" swapped="true"/>
+                <signal name="activate" handler="auth_entries_activated" swapped="true"/>
               </object>
               <packing>
                 <property name="left_attach">1</property>
@@ -87,10 +89,12 @@
               </packing>
             </child>
             <child>
-              <object class="GtkEntry" id="username-entry">
+              <object class="GtkEntry" id="username_entry">
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
                 <property name="hexpand">True</property>
+                <signal name="changed" handler="auth_entries_changed" swapped="true"/>
+                <signal name="activate" handler="auth_entries_activated" swapped="true"/>
               </object>
               <packing>
                 <property name="left_attach">1</property>
@@ -98,13 +102,15 @@
               </packing>
             </child>
             <child>
-              <object class="GtkEntry" id="password-entry">
+              <object class="GtkEntry" id="password_entry">
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
                 <property name="hexpand">True</property>
                 <property name="visibility">False</property>
                 <property name="invisible_char">*</property>
                 <property name="input_purpose">password</property>
+                <signal name="changed" handler="auth_entries_changed" swapped="true"/>
+                <signal name="activate" handler="auth_entries_activated" swapped="true"/>
               </object>
               <packing>
                 <property name="left_attach">1</property>
@@ -119,13 +125,14 @@
           </packing>
         </child>
         <child>
-          <object class="GtkButton" id="authenticate-button">
+          <object class="GtkButton" id="authenticate_button">
             <property name="label" translatable="yes" comments="Translators: This button authenticates all 
print jobs and send them for printing.">A_uthenticate</property>
             <property name="use_underline">True</property>
             <property name="visible">True</property>
             <property name="can_focus">True</property>
             <property name="receives_default">True</property>
             <property name="halign">end</property>
+            <signal name="clicked" handler="authenticate_button_clicked" swapped="yes"/>
           </object>
           <packing>
             <property name="expand">False</property>
@@ -138,12 +145,12 @@
   </object>
   <object class="GtkSizeGroup">
     <widgets>
-      <widget name="domain-label"/>
-      <widget name="username-label"/>
-      <widget name="password-label"/>
+      <widget name="domain_label"/>
+      <widget name="username_label"/>
+      <widget name="password_label"/>
     </widgets>
   </object>
-  <object class="GtkDialog" id="jobs-dialog">
+  <template class="PpJobsDialog" parent="GtkDialog">
     <property name="width_request">720</property>
     <property name="height_request">500</property>
     <property name="can_focus">False</property>
@@ -152,20 +159,20 @@
     <property name="modal">True</property>
     <property name="destroy_with_parent">True</property>
     <property name="type_hint">dialog</property>
-    <property name="use-header-bar">1</property>
     <child internal-child="headerbar">
-      <object class="GtkHeaderBar" id="dialog-header-bar">
+      <object class="GtkHeaderBar">
         <property name="visible">True</property>
         <property name="can_focus">False</property>
         <property name="show_close_button">True</property>
         <child>
-          <object class="GtkButton" id="jobs-clear-all-button">
+          <object class="GtkButton" id="jobs_clear_all_button">
             <property name="label" translatable="yes" comments="Translators: this action removes (purges) 
all the listed jobs from the list.">Clear All</property>
             <property name="visible">True</property>
             <property name="can_focus">True</property>
             <property name="receives_default">True</property>
             <property name="use_underline">True</property>
             <property name="valign">center</property>
+            <signal name="clicked" handler="on_clear_all_button_clicked" swapped="yes"/>
             <style>
               <class name="destructive-action"/>
             </style>
@@ -174,7 +181,7 @@
       </object>
     </child>
     <child internal-child="vbox">
-      <object class="GtkBox" id="dialog-vbox1">
+      <object class="GtkBox">
         <property name="can_focus">False</property>
         <property name="border_width">0</property>
         <style>
@@ -192,7 +199,7 @@
           </packing>
         </child>
         <child>
-          <object class="GtkInfoBar" id="authentication-infobar">
+          <object class="GtkInfoBar" id="authentication_infobar">
             <property name="visible">True</property>
             <property name="can_focus">False</property>
             <property name="border_width">0</property>
@@ -206,7 +213,7 @@
                 <property name="layout_style">end</property>
                 <property name="margin-end">2</property>
                 <child>
-                  <object class="GtkMenuButton" id="authenticate-jobs-button">
+                  <object class="GtkMenuButton" id="authenticate_jobs_button">
                     <property name="visible">True</property>
                     <property name="can_focus">True</property>
                     <property name="receives_default">False</property>
@@ -265,7 +272,7 @@
                 <property name="spacing">16</property>
                 <property name="margin-start">12</property>
                 <child>
-                  <object class="GtkLabel" id="authenticate-jobs-label">
+                  <object class="GtkLabel" id="authenticate_jobs_label">
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
                     <property name="halign">start</property>
@@ -300,14 +307,14 @@
             <property name="visible">True</property>
             <property name="can_focus">False</property>
             <child>
-              <object class="GtkScrolledWindow" id="scrolledwindow">
+              <object class="GtkScrolledWindow" id="list_jobs_page">
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
                 <property name="vexpand">True</property>
                 <property name="hscrollbar-policy">never</property>
                 <property name="shadow_type">none</property>
                 <child>
-                  <object class="GtkListBox" id="jobs-listbox">
+                  <object class="GtkListBox" id="jobs_listbox">
                     <property name="visible">True</property>
                     <property name="can-focus">True</property>
                     <property name="halign">fill</property>
@@ -319,19 +326,16 @@
                   </object>
                 </child>
               </object>
-              <packing>
-                <property name="name">list-jobs-page</property>
-              </packing>
             </child>
             <child>
-              <object class="GtkBox" id="no-jobs-dialog">
+              <object class="GtkBox" id="no_jobs_page">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
                 <property name="spacing">10</property>
                 <property name="orientation">vertical</property>
                 <property name="valign">center</property>
                 <child>
-                  <object class="GtkImage" id="no-printer-image">
+                  <object class="GtkImage">
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
                     <property name="valign">start</property>
@@ -348,7 +352,7 @@
                   </packing>
                 </child>
                 <child>
-                  <object class="GtkLabel" id="no-printer-label">
+                  <object class="GtkLabel">
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
                     <property name="label" translatable="yes" comments="Translators: this label describes 
the dialog empty state, with no jobs listed.">No Active Printer Jobs</property>
@@ -364,7 +368,6 @@
                 </child>
               </object>
               <packing>
-                <property name="name">no-jobs-page</property>
                 <property name="position">1</property>
               </packing>
             </child>
@@ -380,5 +383,5 @@
     <child>
       <placeholder/>
     </child>
-  </object>
+  </template>
 </interface>
diff --git a/panels/printers/pp-printer-entry.c b/panels/printers/pp-printer-entry.c
index 26cf24a8a..3e87fabad 100644
--- a/panels/printers/pp-printer-entry.c
+++ b/panels/printers/pp-printer-entry.c
@@ -638,29 +638,20 @@ jobs_dialog_response_cb (GtkDialog  *dialog,
 
   if (self->pp_jobs_dialog != NULL)
     {
-      pp_jobs_dialog_free (self->pp_jobs_dialog);
+      gtk_widget_destroy (GTK_WIDGET (self->pp_jobs_dialog));
       self->pp_jobs_dialog = NULL;
     }
 }
 
-static void
-printer_jobs_dialog_free_cb (GtkDialog *dialog,
-                             gint       response_id,
-                             gpointer   user_data)
-{
-  pp_jobs_dialog_free ((PpJobsDialog *) user_data);
-}
-
 void
 pp_printer_entry_show_jobs_dialog (PpPrinterEntry *self)
 {
   if (self->pp_jobs_dialog == NULL)
     {
-      self->pp_jobs_dialog = pp_jobs_dialog_new (
-        jobs_dialog_response_cb,
-        self,
-        self->printer_name);
+      self->pp_jobs_dialog = pp_jobs_dialog_new (self->printer_name);
+      g_signal_connect_object (self->pp_jobs_dialog, "response", G_CALLBACK (jobs_dialog_response_cb), self, 
0);
       gtk_window_set_transient_for (GTK_WINDOW (self->pp_jobs_dialog), GTK_WINDOW (gtk_widget_get_toplevel 
(GTK_WIDGET (self))));
+      gtk_window_present (GTK_WINDOW (self->pp_jobs_dialog));
     }
 }
 
@@ -976,9 +967,6 @@ pp_printer_entry_dispose (GObject *object)
   g_cancellable_cancel (self->get_jobs_cancellable);
   g_cancellable_cancel (self->check_clean_heads_cancellable);
 
-  if (self->pp_jobs_dialog != NULL)
-    pp_jobs_dialog_set_callback (self->pp_jobs_dialog, printer_jobs_dialog_free_cb, self->pp_jobs_dialog);
-
   g_clear_pointer (&self->printer_name, g_free);
   g_clear_pointer (&self->printer_location, g_free);
   g_clear_pointer (&self->printer_make_and_model, g_free);
diff --git a/panels/printers/printers.gresource.xml b/panels/printers/printers.gresource.xml
index 385ff710e..b9a7d4be1 100644
--- a/panels/printers/printers.gresource.xml
+++ b/panels/printers/printers.gresource.xml
@@ -2,11 +2,11 @@
 <gresources>
   <gresource prefix="/org/gnome/control-center/printers">
     <file preprocess="xml-stripblanks">authentication-dialog.ui</file>
-    <file preprocess="xml-stripblanks">jobs-dialog.ui</file>
     <file preprocess="xml-stripblanks">new-printer-dialog.ui</file>
     <file preprocess="xml-stripblanks">pp-options-dialog.ui</file>
     <file preprocess="xml-stripblanks">ppd-selection-dialog.ui</file>
     <file preprocess="xml-stripblanks">pp-details-dialog.ui</file>
+    <file preprocess="xml-stripblanks">pp-jobs-dialog.ui</file>
     <file preprocess="xml-stripblanks">printer-entry.ui</file>
     <file preprocess="xml-stripblanks">printers.ui</file>
   </gresource>
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 563bcdb33..4c7c4781a 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -155,7 +155,6 @@ panels/power/gnome-power-panel.desktop.in.in
 panels/printers/authentication-dialog.ui
 panels/printers/cc-printers-panel.c
 panels/printers/gnome-printers-panel.desktop.in.in
-panels/printers/jobs-dialog.ui
 panels/printers/new-printer-dialog.ui
 panels/printers/pp-details-dialog.c
 panels/printers/pp-details-dialog.ui
@@ -163,6 +162,7 @@ panels/printers/ppd-selection-dialog.ui
 panels/printers/pp-host.c
 panels/printers/pp-ipp-option-widget.c
 panels/printers/pp-jobs-dialog.c
+panels/printers/pp-jobs-dialog.ui
 panels/printers/pp-new-printer-dialog.c
 panels/printers/pp-options-dialog.c
 panels/printers/pp-options-dialog.ui


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]