pp-details-dialog: Modernize the UI

- Use modern widgets like AdwPreferencesPage/Group,
AdwEntryRow and AdwPropertyRow

- Set a minimum size for the window

- Add .error class to the printer name entry
when the name is invalid

- Restyle the printer name error message

- Add missing mnemonics
This commit is contained in:
Automeris naranja 2024-01-13 02:21:19 -03:00 committed by Matthijs Velsink
parent 0bbeba5124
commit 870b26ecdc
2 changed files with 133 additions and 197 deletions

View file

@ -42,13 +42,12 @@ struct _PpDetailsDialog {
AdwWindow parent_instance;
GtkBox *driver_buttons;
GtkBox *loading_box;
GtkSpinner *spinner_driver_search;
GtkLabel *printer_address_label;
GtkRevealer *print_name_hint_revealer;
GtkEntry *printer_location_entry;
GtkLabel *printer_model_label;
GtkStack *printer_model_stack;
GtkEntry *printer_name_entry;
GtkRevealer *printer_name_hint_revealer;
AdwEntryRow *printer_location_entry;
AdwActionRow *printer_model_label;
AdwEntryRow *printer_name_entry;
GtkButton *search_for_drivers_button;
gchar *printer_name;
@ -73,10 +72,12 @@ printer_name_changed (PpDetailsDialog *self)
if (printer_name_is_valid (name)){
/* Translators: This is the title of the dialog. %s is the printer name. */
title = g_strdup_printf (_("%s Details"), name);
gtk_revealer_set_reveal_child (self->print_name_hint_revealer, FALSE);
gtk_window_set_title (GTK_WINDOW (self), title);
gtk_revealer_set_reveal_child (self->printer_name_hint_revealer, FALSE);
gtk_widget_remove_css_class (GTK_WIDGET (self->printer_name_entry), "error");
} else {
gtk_revealer_set_reveal_child (self->print_name_hint_revealer, TRUE);
gtk_revealer_set_reveal_child (self->printer_name_hint_revealer, TRUE);
gtk_widget_add_css_class (GTK_WIDGET (self->printer_name_entry), "error");
}
}
@ -94,7 +95,7 @@ get_ppd_names_cb (PPDName **names,
{
if (names != NULL)
{
gtk_label_set_text (self->printer_model_label, names[0]->ppd_display_name);
adw_action_row_set_subtitle (self->printer_model_label, names[0]->ppd_display_name);
printer_set_ppd_async (printer_name,
names[0]->ppd_name,
self->cancellable,
@ -103,18 +104,18 @@ get_ppd_names_cb (PPDName **names,
}
else
{
gtk_label_set_text (self->printer_model_label, _("No suitable driver found"));
adw_action_row_set_subtitle (self->printer_model_label, _("No suitable driver found"));
gtk_widget_set_visible (GTK_WIDGET (self->spinner_driver_search), FALSE);
}
gtk_stack_set_visible_child (self->printer_model_stack, GTK_WIDGET (self->printer_model_label));
}
}
static void
search_for_drivers (PpDetailsDialog *self)
{
gtk_stack_set_visible_child (self->printer_model_stack, GTK_WIDGET (self->loading_box));
gtk_widget_set_visible (GTK_WIDGET (self->spinner_driver_search), TRUE);
gtk_widget_set_sensitive (GTK_WIDGET (self->search_for_drivers_button), FALSE);
adw_action_row_set_subtitle (self->printer_model_label, _("Searching for preferred drivers…"));
get_ppd_names_async (self->printer_name,
1,
@ -130,7 +131,7 @@ set_ppd_cb (const gchar *printer_name,
{
PpDetailsDialog *self = (PpDetailsDialog*) user_data;
gtk_label_set_text (GTK_LABEL (self->printer_model_label), self->ppd_file_name);
adw_action_row_set_subtitle (self->printer_model_label, self->ppd_file_name);
}
static void
@ -330,13 +331,12 @@ pp_details_dialog_class_init (PpDetailsDialogClass *klass)
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/control-center/printers/pp-details-dialog.ui");
gtk_widget_class_bind_template_child (widget_class, PpDetailsDialog, print_name_hint_revealer);
gtk_widget_class_bind_template_child (widget_class, PpDetailsDialog, printer_name_hint_revealer);
gtk_widget_class_bind_template_child (widget_class, PpDetailsDialog, driver_buttons);
gtk_widget_class_bind_template_child (widget_class, PpDetailsDialog, loading_box);
gtk_widget_class_bind_template_child (widget_class, PpDetailsDialog, spinner_driver_search);
gtk_widget_class_bind_template_child (widget_class, PpDetailsDialog, printer_address_label);
gtk_widget_class_bind_template_child (widget_class, PpDetailsDialog, printer_location_entry);
gtk_widget_class_bind_template_child (widget_class, PpDetailsDialog, printer_model_label);
gtk_widget_class_bind_template_child (widget_class, PpDetailsDialog, printer_model_stack);
gtk_widget_class_bind_template_child (widget_class, PpDetailsDialog, printer_name_entry);
gtk_widget_class_bind_template_child (widget_class, PpDetailsDialog, search_for_drivers_button);
@ -373,7 +373,7 @@ pp_details_dialog_new (gchar *printer_name,
gtk_editable_set_text (GTK_EDITABLE (self->printer_name_entry), printer_name);
gtk_editable_set_text (GTK_EDITABLE (self->printer_location_entry), printer_location);
gtk_label_set_text (GTK_LABEL (self->printer_model_label), printer_make_and_model);
adw_action_row_set_subtitle (self->printer_model_label, printer_make_and_model);
update_sensitivity (self, sensitive);

View file

@ -6,216 +6,152 @@
<property name="resizable">False</property>
<property name="modal">True</property>
<property name="destroy_with_parent">True</property>
<property name="width-request">360</property>
<property name="height-request">294</property>
<property name="default-width">360</property>
<property name="default-height">500</property>
<property name="content">
<object class="AdwToolbarView">
<child type="top">
<object class="AdwHeaderBar"/>
</child>
<property name="content">
<object class="GtkGrid">
<property name="margin-top">20</property>
<property name="margin-bottom">20</property>
<property name="margin-start">20</property>
<property name="margin-end">20</property>
<property name="halign">center</property>
<property name="row-spacing">10</property>
<property name="column-spacing">10</property>
<object class="AdwPreferencesPage">
<child>
<object class="GtkLabel">
<property name="label" translatable="yes">Name</property>
<property name="halign">end</property>
<property name="mnemonic_widget">printer_name_entry</property>
<layout>
<property name="column">0</property>
<property name="row">0</property>
</layout>
<style>
<class name="dim-label"/>
</style>
</object>
</child>
<child>
<object class="GtkEntry" id="printer_name_entry">
<property name="halign">fill</property>
<property name="width_request">320</property>
<signal name="changed" handler="printer_name_changed" object="PpDetailsDialog" swapped="yes"/>
<layout>
<property name="column">1</property>
<property name="row">0</property>
</layout>
</object>
</child>
<child>
<object class="GtkRevealer" id="print_name_hint_revealer">
<property name="visible">True</property>
<property name="can_focus">False</property>
<object class="AdwPreferencesGroup">
<child>
<object class="GtkLabel" id="print_name_hint_label">
<property name="visible">True</property>
<property name="label" translatable="yes">Printer names cannot contain SPACE, TAB, #, or /</property>
<property name="yalign">0</property>
<property name="xalign">0</property>
<style>
<class name="dim-label"/>
</style>
<attributes>
<attribute name="scale" value="0.83"/>
</attributes>
</object>
</child>
<layout>
<property name="column">1</property>
<property name="row">1</property>
</layout>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="label" translatable="yes">Location</property>
<property name="halign">end</property>
<property name="mnemonic_widget">printer_location_entry</property>
<layout>
<property name="column">0</property>
<property name="row">2</property>
</layout>
<style>
<class name="dim-label"/>
</style>
</object>
</child>
<child>
<object class="GtkEntry" id="printer_location_entry">
<property name="width_request">320</property>
<property name="halign">fill</property>
<layout>
<property name="column">1</property>
<property name="row">2</property>
</layout>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="label" translatable="yes">Address</property>
<property name="halign">end</property>
<property name="mnemonic_widget">printer_address_label</property>
<layout>
<property name="column">0</property>
<property name="row">3</property>
</layout>
<style>
<class name="dim-label"/>
</style>
</object>
</child>
<child>
<object class="GtkLabel" id="printer_address_label">
<property name="label">192.168.0.1</property>
<property name="halign">start</property>
<layout>
<property name="column">1</property>
<property name="row">3</property>
</layout>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="label" translatable="yes">Driver</property>
<property name="halign">end</property>
<property name="mnemonic_widget">printer_model_label</property>
<layout>
<property name="column">0</property>
<property name="row">4</property>
</layout>
<style>
<class name="dim-label"/>
</style>
</object>
</child>
<child>
<object class="GtkStack" id="printer_model_stack">
<property name="halign">start</property>
<layout>
<property name="column">1</property>
<property name="row">4</property>
</layout>
<child>
<object class="GtkLabel" id="printer_model_label">
<property name="halign">start</property>
<property name="label">HP Inkjet Delux 9000</property>
<property name="selectable">True</property>
<object class="AdwEntryRow" id="printer_name_entry">
<property name="title" translatable="yes">Name</property>
<signal name="changed" handler="printer_name_changed" object="PpDetailsDialog" swapped="yes"/>
</object>
</child>
<child>
<object class="GtkBox" id="loading_box">
<property name="halign">start</property>
<property name="spacing">5</property>
<child>
<object class="GtkSpinner">
<object class="AdwEntryRow" id="printer_location_entry">
<property name="title" translatable="yes">Location</property>
</object>
</child>
<child>
<object class="AdwActionRow">
<child type="prefix">
<object class="GtkBox">
<property name="orientation">vertical</property>
<property name="spacing">3</property>
<property name="halign">start</property>
<property name="valign">center</property>
<child>
<object class="GtkLabel">
<property name="label" translatable="yes">Address</property>
<property name="hexpand">True</property>
<property name="ellipsize">end</property>
<property name="halign">start</property>
<style>
<class name="subtitle"/>
</style>
</object>
</child>
<child>
<object class="GtkLabel" id="printer_address_label">
<property name="xalign">1</property>
<property name="ellipsize">start</property>
<property name="use-markup">true</property>
</object>
</child>
</object>
</child>
</object>
</child>
<child>
<object class="AdwActionRow" id="printer_model_label">
<property name="title" translatable="yes">Driver</property>
<child type="suffix">
<object class="GtkSpinner" id="spinner_driver_search">
<property name="visible">false</property>
<property name="spinning">True</property>
<property name="halign">start</property>
</object>
</child>
<style>
<class name="property"/>
</style>
</object>
</child>
<child>
<object class="GtkRevealer" id="printer_name_hint_revealer">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkLabel">
<property name="halign">start</property>
<property name="label" translatable="yes">Searching for preferred drivers…</property>
<object class="GtkBox">
<property name="visible">True</property>
<property name="orientation">horizontal</property>
<property name="spacing">6</property>
<property name="margin-top">12</property>
<property name="margin-bottom">12</property>
<child>
<object class="GtkImage">
<property name="icon-name">dialog-warning-symbolic</property>
<style>
<class name="error"/>
</style>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="label" translatable="yes">Printer names cannot contain SPACE, TAB, #, or /</property>
<property name="yalign">0</property>
<property name="xalign">0</property>
<style>
<class name="caption"/>
<class name="error"/>
</style>
</object>
</child>
</object>
</child>
</child>
</object>
</child>
</object>
</child>
<child>
<object class="GtkBox" id="driver_buttons">
<property name="orientation">vertical</property>
<property name="spacing">10</property>
<property name="halign">start</property>
<layout>
<property name="column">1</property>
<property name="row">5</property>
</layout>
<object class="AdwPreferencesGroup">
<child>
<object class="GtkButton" id="search_for_drivers_button">
<property name="label" translatable="yes">Search for Drivers</property>
<property name="halign">fill</property>
<signal name="clicked" handler="search_for_drivers" object="PpDetailsDialog" swapped="yes"/>
<object class="GtkBox" id="driver_buttons">
<property name="orientation">vertical</property>
<property name="spacing">6</property>
<child>
<object class="GtkButton" id="search_for_drivers_button">
<property name="label" translatable="yes">_Search for Drivers</property>
<property name="use-underline">True</property>
<property name="halign">fill</property>
<signal name="clicked" handler="search_for_drivers" object="PpDetailsDialog" swapped="yes"/>
</object>
</child>
<child>
<object class="GtkButton" id="select_from_database_button">
<property name="label" translatable="yes">S_elect from Database…</property>
<property name="use-underline">True</property>
<property name="halign">fill</property>
<signal name="clicked" handler="select_ppd_in_dialog" object="PpDetailsDialog" swapped="yes"/>
</object>
</child>
<child>
<object class="GtkButton" id="install_ppd_button">
<property name="label" translatable="yes">_Install PPD File…</property>
<property name="use-underline">True</property>
<property name="halign">fill</property>
<signal name="clicked" handler="select_ppd_manually" object="PpDetailsDialog" swapped="yes"/>
</object>
</child>
</object>
</child>
<child>
<object class="GtkButton" id="select_from_database_button">
<property name="label" translatable="yes">Select from Database…</property>
<property name="halign">fill</property>
<signal name="clicked" handler="select_ppd_in_dialog" object="PpDetailsDialog" swapped="yes"/>
</object>
</child>
<child>
<object class="GtkButton" id="install_ppd_button">
<property name="label" translatable="yes">Install PPD File…</property>
<property name="halign">fill</property>
<signal name="clicked" handler="select_ppd_manually" object="PpDetailsDialog" swapped="yes"/>
</object>
</child>
</object>
</child>
</object>
</property>
</object>
</property>
</template>
<object class="GtkSizeGroup">
<property name="mode">horizontal</property>
<widgets>
<widget name="search_for_drivers_button"/>
<widget name="select_from_database_button"/>
<widget name="install_ppd_button"/>
</widgets>
</object>
</interface>