diff options
-rw-r--r-- | panels/printers/pp-details-dialog.c | 75 | ||||
-rw-r--r-- | panels/printers/pp-details-dialog.h | 14 | ||||
-rw-r--r-- | panels/printers/pp-details-dialog.ui | 1 | ||||
-rw-r--r-- | panels/printers/pp-printer-entry.c | 75 |
4 files changed, 65 insertions, 100 deletions
diff --git a/panels/printers/pp-details-dialog.c b/panels/printers/pp-details-dialog.c index dcfdf7922..524cb90d1 100644 --- a/panels/printers/pp-details-dialog.c +++ b/panels/printers/pp-details-dialog.c @@ -62,56 +62,6 @@ struct _PpDetailsDialog { G_DEFINE_TYPE (PpDetailsDialog, pp_details_dialog, GTK_TYPE_DIALOG) -enum -{ - PRINTER_RENAMED, - LAST_SIGNAL -}; - -static guint signals[LAST_SIGNAL] = { 0 }; - -static void -on_printer_rename_cb (GObject *source_object, - GAsyncResult *result, - gpointer user_data) -{ - pp_printer_rename_finish (PP_PRINTER (source_object), result, NULL); - - g_object_unref (source_object); -} - -static void -pp_details_dialog_response_cb (GtkDialog *dialog, - gint response_id, - gpointer user_data) -{ - PpDetailsDialog *self = (PpDetailsDialog*) dialog; - const gchar *new_name; - const gchar *new_location; - - new_location = gtk_entry_get_text (GTK_ENTRY (self->printer_location_entry)); - if (g_strcmp0 (self->printer_location, new_location) != 0) - { - printer_set_location (self->printer_name, new_location); - - self->printer_location = g_strdup (new_location); - } - - new_name = gtk_entry_get_text (GTK_ENTRY (self->printer_name_entry)); - if (g_strcmp0 (self->printer_name, new_name) != 0) - { - PpPrinter *printer = pp_printer_new (self->printer_name); - - g_signal_emit_by_name (self, "printer-renamed", new_name); - - pp_printer_rename_async (printer, - new_name, - NULL, - on_printer_rename_cb, - NULL); - } -} - static void printer_name_changed (GtkEditable *editable, gpointer user_data) @@ -120,7 +70,7 @@ printer_name_changed (GtkEditable *editable, const gchar *name; g_autofree gchar *title = NULL; - name = gtk_entry_get_text (GTK_ENTRY (self->printer_name_entry)); + name = pp_details_dialog_get_printer_name (self); /* Translators: This is the title of the dialog. %s is the printer name. */ title = g_strdup_printf (_("%s Details"), name); @@ -398,15 +348,6 @@ pp_details_dialog_class_init (PpDetailsDialogClass *klass) gtk_widget_class_bind_template_callback (widget_class, search_for_drivers); gtk_widget_class_bind_template_callback (widget_class, select_ppd_in_dialog); gtk_widget_class_bind_template_callback (widget_class, select_ppd_manually); - gtk_widget_class_bind_template_callback (widget_class, pp_details_dialog_response_cb); - - signals[PRINTER_RENAMED] = g_signal_new ("printer-renamed", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, - 0, - NULL, NULL, NULL, - G_TYPE_NONE, 1, - G_TYPE_STRING); } PpDetailsDialog * @@ -443,3 +384,17 @@ pp_details_dialog_new (gchar *printer_name, return self; } + +const gchar * +pp_details_dialog_get_printer_name (PpDetailsDialog *self) +{ + g_return_val_if_fail (PP_IS_DETAILS_DIALOG (self), NULL); + return gtk_entry_get_text (GTK_ENTRY (self->printer_name_entry)); +} + +const gchar * +pp_details_dialog_get_printer_location (PpDetailsDialog *self) +{ + g_return_val_if_fail (PP_IS_DETAILS_DIALOG (self), NULL); + return gtk_entry_get_text (GTK_ENTRY (self->printer_location_entry)); +} diff --git a/panels/printers/pp-details-dialog.h b/panels/printers/pp-details-dialog.h index 76ce553ef..8bb5a6500 100644 --- a/panels/printers/pp-details-dialog.h +++ b/panels/printers/pp-details-dialog.h @@ -28,10 +28,14 @@ G_BEGIN_DECLS #define PP_DETAILS_DIALOG_TYPE (pp_details_dialog_get_type ()) G_DECLARE_FINAL_TYPE (PpDetailsDialog, pp_details_dialog, PP, DETAILS_DIALOG, GtkDialog) -PpDetailsDialog *pp_details_dialog_new (gchar *printer_name, - gchar *printer_location, - gchar *printer_address, - gchar *printer_make_and_model, - gboolean sensitive); +PpDetailsDialog *pp_details_dialog_new (gchar *printer_name, + gchar *printer_location, + gchar *printer_address, + gchar *printer_make_and_model, + gboolean sensitive); + +const gchar *pp_details_dialog_get_printer_name (PpDetailsDialog *dialog); + +const gchar *pp_details_dialog_get_printer_location (PpDetailsDialog *dialog); G_END_DECLS diff --git a/panels/printers/pp-details-dialog.ui b/panels/printers/pp-details-dialog.ui index 71f56fff8..71683990b 100644 --- a/panels/printers/pp-details-dialog.ui +++ b/panels/printers/pp-details-dialog.ui @@ -10,7 +10,6 @@ <property name="destroy_with_parent">True</property> <property name="type_hint">dialog</property> <property name="use-header-bar">1</property> - <signal name="response" handler="pp_details_dialog_response_cb"/> <child internal-child="headerbar"> <object class="GtkHeaderBar"> <property name="visible">True</property> diff --git a/panels/printers/pp-printer-entry.c b/panels/printers/pp-printer-entry.c index 1f440c666..129fb7521 100644 --- a/panels/printers/pp-printer-entry.c +++ b/panels/printers/pp-printer-entry.c @@ -80,7 +80,6 @@ struct _PpPrinterEntry GtkLabel *error_status; /* Dialogs */ - PpDetailsDialog *pp_details_dialog; PpOptionsDialog *pp_options_dialog; PpJobsDialog *pp_jobs_dialog; @@ -404,44 +403,60 @@ supply_levels_draw_cb (GtkWidget *widget, } static void -printer_renamed_cb (PpDetailsDialog *dialog, - gchar *new_name, - gpointer user_data) -{ - PpPrinterEntry *self = user_data; - - g_signal_emit_by_name (self, "printer-renamed", new_name); -} - -static void -details_dialog_cb (GtkDialog *dialog, - gint response_id, - gpointer user_data) +on_printer_rename_cb (GObject *source_object, + GAsyncResult *result, + gpointer user_data) { PpPrinterEntry *self = user_data; + g_autofree gchar *printer_name = NULL; + + if (!pp_printer_rename_finish (PP_PRINTER (source_object), result, NULL)) + return; - g_clear_pointer ((GtkWidget **) &self->pp_details_dialog, gtk_widget_destroy); + g_object_get (PP_PRINTER (source_object), + "printer-name", &printer_name, + NULL); - g_signal_emit_by_name (self, "printer-changed"); + g_signal_emit_by_name (self, "printer-renamed", printer_name); } static void on_show_printer_details_dialog (GtkButton *button, PpPrinterEntry *self) { - self->pp_details_dialog = pp_details_dialog_new ( - self->printer_name, - self->printer_location, - self->printer_hostname, - self->printer_make_and_model, - self->is_authorized); + const gchar *new_name; + const gchar *new_location; + + PpDetailsDialog *dialog = pp_details_dialog_new (self->printer_name, + self->printer_location, + self->printer_hostname, + self->printer_make_and_model, + self->is_authorized); - gtk_window_set_transient_for (GTK_WINDOW (self->pp_details_dialog), + gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (self)))); - g_signal_connect (self->pp_details_dialog, "response", G_CALLBACK (details_dialog_cb), self); - g_signal_connect (self->pp_details_dialog, "printer-renamed", G_CALLBACK (printer_renamed_cb), self); - gtk_widget_show (GTK_WIDGET (self->pp_details_dialog)); + gtk_dialog_run (GTK_DIALOG (dialog)); + + new_location = pp_details_dialog_get_printer_location (dialog); + if (g_strcmp0 (self->printer_location, new_location) != 0) + printer_set_location (self->printer_name, new_location); + + new_name = pp_details_dialog_get_printer_name (dialog); + if (g_strcmp0 (self->printer_name, new_name) != 0) + { + PpPrinter *printer = pp_printer_new (self->printer_name); + + pp_printer_rename_async (printer, + new_name, + NULL, + on_printer_rename_cb, + self); + } + + g_signal_emit_by_name (self, "printer-changed"); + + gtk_widget_destroy (GTK_WIDGET (dialog)); } static void @@ -981,14 +996,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_details_dialog != NULL) - { - g_signal_handlers_disconnect_by_data (self->pp_details_dialog, self); - g_signal_connect (self->pp_details_dialog, "response", G_CALLBACK (details_dialog_free_cb), NULL); - } - - g_clear_pointer ((GtkWidget **) &self->pp_details_dialog, gtk_widget_destroy); - if (self->pp_options_dialog != NULL) pp_options_dialog_set_callback (self->pp_options_dialog, printer_options_dialog_free_cb, self->pp_options_dialog); |