Commit 6f3ed908 authored by Felipe Borges's avatar Felipe Borges 👣

printers: Allow dismissing authentication in "Add New Printer" dialog

Introduce a "go-back" button allowing to get back to the list of
printers when the user is exposed to the authentication form in
the "Add New Printer" dialog.

This is a redesign based on the newest mockups available at
https://wiki.gnome.org/Design/SystemSettings/Printers#Guidelines

https://bugzilla.gnome.org/show_bug.cgi?id=760783
parent 58c2cff7
......@@ -37,17 +37,44 @@
<property name="visible">True</property>
<property name="show-close-button">False</property>
<child>
<object class="GtkButton" id="new-printer-cancel-button">
<property name="label" translatable="yes">_Cancel</property>
<object class="GtkStack" id="headerbar-topleft-buttons">
<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>
<child>
<object class="GtkButton" id="new-printer-cancel-button">
<property name="label" translatable="yes">_Cancel</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_underline">True</property>
</object>
<packing>
<property name="name">addprinter-page</property>
</packing>
</child>
<child>
<object class="GtkButton" id="go-back-button">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="halign">start</property>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="icon-name">go-previous-symbolic</property>
</object>
</child>
</object>
<packing>
<property name="name">authentication-page</property>
</packing>
</child>
</object>
</child>
<child>
<object class="GtkStack" id="headerbar-topright-buttons">
<property name="visible">True</property>
<property name="valign">center</property>
<child>
<object class="GtkButton" id="new-printer-add-button">
<property name="label" translatable="yes">_Add</property>
......
......@@ -267,6 +267,8 @@ get_authenticated_samba_devices_cb (GObject *source_object,
GError *error = NULL;
GList *iter;
g_object_ref (samba);
result = pp_samba_get_devices_finish (samba, res, &error);
g_object_unref (source_object);
......@@ -291,8 +293,6 @@ get_authenticated_samba_devices_cb (GObject *source_object,
if (!cancelled)
{
remove_device_from_list (dialog,
data->server_name);
if (result->devices != NULL)
{
......@@ -344,6 +344,9 @@ go_to_page (PpNewPrinterDialog *dialog,
stack = GTK_STACK (WID ("headerbar-topright-buttons"));
gtk_stack_set_visible_child_name (stack, page);
stack = GTK_STACK (WID ("headerbar-topleft-buttons"));
gtk_stack_set_visible_child_name (stack, page);
}
static gchar *
......@@ -361,6 +364,7 @@ on_authenticate (GtkWidget *button,
{
PpNewPrinterDialog *dialog = PP_NEW_PRINTER_DIALOG (user_data);
PpNewPrinterDialogPrivate *priv = dialog->priv;
gchar *hostname = NULL;
gchar *username = NULL;
gchar *password = NULL;
......@@ -379,6 +383,9 @@ on_authenticate (GtkWidget *button,
gtk_header_bar_set_title (GTK_HEADER_BAR (WID ("headerbar")), _("Add Printer"));
go_to_page (dialog, ADDPRINTER_PAGE);
g_object_get (PP_HOST (priv->samba_host), "hostname", &hostname, NULL);
remove_device_from_list (dialog, hostname);
}
static void
......@@ -435,6 +442,23 @@ auth_entries_changed (GtkEditable *editable,
g_clear_pointer (&password, g_free);
}
static void
on_go_back_button_clicked (GtkButton *button,
gpointer user_data)
{
PpNewPrinterDialog *dialog = PP_NEW_PRINTER_DIALOG (user_data);
PpNewPrinterDialogPrivate *priv = dialog->priv;
pp_samba_set_auth_info (priv->samba_host, NULL, NULL);
g_clear_object (&priv->samba_host);
go_to_page (dialog, ADDPRINTER_PAGE);
gtk_header_bar_set_title (GTK_HEADER_BAR (WID ("headerbar")), _("Add Printer"));
gtk_widget_set_sensitive (WID ("new-printer-add-button"), FALSE);
gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (priv->treeview));
}
static void
authenticate_samba_server (GtkButton *button,
gpointer user_data)
......@@ -535,6 +559,7 @@ pp_new_printer_dialog_init (PpNewPrinterDialog *dialog)
/* Authentication form widgets */
g_signal_connect (WID ("username-entry"), "changed", G_CALLBACK (auth_entries_changed), dialog);
g_signal_connect (WID ("password-entry"), "changed", G_CALLBACK (auth_entries_changed), dialog);
g_signal_connect (WID ("go-back-button"), "clicked", G_CALLBACK (on_go_back_button_clicked), dialog);
/* Set junctions */
widget = WID ("scrolledwindow1");
......
......@@ -88,7 +88,6 @@ typedef struct
PpSamba *samba;
PpDevicesList *devices;
GMainContext *context;
gboolean waiting;
gboolean auth_if_needed;
gboolean hostname_set;
gboolean cancelled;
......@@ -111,8 +110,6 @@ get_auth_info (gpointer user_data)
SMBData *data = (SMBData *) user_data;
PpSamba *samba = PP_SAMBA (data->samba);
samba->priv->waiting = TRUE;
g_signal_emit_by_name (samba, "authentication-required");
return FALSE;
......@@ -125,17 +122,17 @@ pp_samba_set_auth_info (PpSamba *samba,
{
PpSambaPrivate *priv = samba->priv;
g_free (priv->username);
if ((username != NULL) && (username[0] != '\0'))
{
g_free (priv->username);
priv->username = g_strdup (username);
}
priv->username = g_strdup (username);
else
priv->username = NULL;
g_free (priv->password);
if ((password != NULL) && (password[0] != '\0'))
{
g_free (priv->password);
priv->password = g_strdup (password);
}
priv->password = g_strdup (password);
else
priv->password = NULL;
priv->waiting = FALSE;
}
......@@ -174,6 +171,8 @@ auth_fn (SMBCCTX *smb_context,
g_source_attach (source, data->context);
g_source_unref (source);
samba->priv->waiting = TRUE;
/*
* smbclient needs to get authentication data
* from this synchronous callback so we are blocking
......@@ -184,11 +183,32 @@ auth_fn (SMBCCTX *smb_context,
g_usleep (POLL_DELAY);
}
if (g_strcmp0 (username, samba->priv->username) != 0)
g_strlcpy (username, samba->priv->username, unmaxlen);
/* Samba tries to call the auth_fn again if we just set the values
* to NULL when we want to cancel the authentication
*/
if (samba->priv->username == NULL && samba->priv->password == NULL)
data->cancelled = TRUE;
if (samba->priv->username != NULL)
{
if (g_strcmp0 (username, samba->priv->username) != 0)
g_strlcpy (username, samba->priv->username, unmaxlen);
}
else
{
username[0] = '\0';
}
if (samba->priv->password != NULL)
{
if (g_strcmp0 (password, samba->priv->password) != 0)
g_strlcpy (password, samba->priv->password, pwmaxlen);
}
else
{
password[0] = '\0';
}
if (g_strcmp0 (password, samba->priv->password) != 0)
g_strlcpy (password, samba->priv->password, pwmaxlen);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment