summaryrefslogtreecommitdiff
path: root/src/password.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/password.c')
-rw-r--r--src/password.c209
1 files changed, 107 insertions, 102 deletions
diff --git a/src/password.c b/src/password.c
index a5490d3..69dd683 100644
--- a/src/password.c
+++ b/src/password.c
@@ -1,19 +1,22 @@
+/* vim: colorcolumn=80 ts=4 sw=4
+ */
/*
* password.c
*
- * Copyright (C) 2010 Arx Cruz
+ * Copyright © 2010 Arx Cruz
+ * Copyright © 2021-2023 Logan Rathbone
*
* This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
+ * modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
+ * Lesser General Public License for more details.
*
- * You should have received a copy of the GNU Library General Public
+ * You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 121 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
@@ -21,153 +24,155 @@
* Authors: Arx Cruz <arxcruz@gmail.com>
*/
-#include "config.h"
#include "util.h"
#include "zenity.h"
+
#include <string.h>
+#include <config.h>
+
static ZenityData *zen_data;
-static void zenity_password_dialog_response (
- GtkWidget *widget, int response, gpointer data);
+static void zenity_password_dialog_response (GtkWidget *widget, char *rstr, gpointer data);
void
-zenity_password_dialog (ZenityData *data, ZenityPasswordData *password_data) {
+zenity_password_dialog (ZenityData *data, ZenityPasswordData *password_data)
+{
+ GtkBuilder *builder;
GtkWidget *dialog;
- GtkWidget *image;
- GtkWidget *hbox;
- GtkWidget *vbox_labels;
- GtkWidget *vbox_entries;
+ GtkWidget *grid;
GtkWidget *label;
+ int pass_row = 0;
+ /* Set global */
zen_data = data;
- dialog = gtk_dialog_new ();
+ builder = zenity_util_load_ui_file ("zenity_password_dialog", "zenity_password_box", NULL);
- if (data->extra_label) {
- gint i = 0;
- while (data->extra_label[i] != NULL) {
- gtk_dialog_add_button (
- GTK_DIALOG (dialog), data->extra_label[i], i);
- i++;
- }
+ if (builder == NULL)
+ {
+ data->exit_code = zenity_util_return_exit_code (ZENITY_ERROR);
+ return;
}
- gtk_dialog_add_button (GTK_DIALOG (dialog),
- data->cancel_label != NULL ? data->cancel_label : _ ("_Cancel"),
- GTK_RESPONSE_CANCEL);
- gtk_dialog_add_button (GTK_DIALOG (dialog),
- data->ok_label != NULL ? data->ok_label : _ ("_OK"),
- GTK_RESPONSE_OK);
+ dialog = GTK_WIDGET(gtk_builder_get_object (builder,
+ "zenity_password_dialog"));
+
+ if (data->extra_label)
+ {
+ ZENITY_UTIL_ADD_EXTRA_LABELS (dialog)
+ }
- image =
- gtk_image_new_from_icon_name ("dialog-password", GTK_ICON_SIZE_DIALOG);
- gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
- hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 5);
- gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 12);
+ if (data->ok_label) {
+ ZENITY_UTIL_SETUP_OK_BUTTON_LABEL (dialog);
+ }
- /* Checks if username has been passed as a parameter */
- gchar *title_text = _ ("Type your password");
+ if (data->cancel_label)
+ {
+ ZENITY_UTIL_SETUP_CANCEL_BUTTON_LABEL (dialog);
+ }
+ grid = GTK_WIDGET(gtk_builder_get_object (builder,
+ "zenity_password_grid"));
+
+ /* Checks if username has been passed as a parameter */
if (password_data->username)
- title_text = _ ("Type your username and password");
-
- label = gtk_label_new (title_text);
-
- gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 12);
- gtk_box_pack_start (
- GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))),
- hbox,
- FALSE,
- TRUE,
- 5);
-
- vbox_labels = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5);
- vbox_entries = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5);
-
- hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 5);
- gtk_box_pack_start (
- GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))),
- hbox,
- FALSE,
- TRUE,
- 5);
-
- gtk_box_pack_start (GTK_BOX (hbox), vbox_labels, FALSE, TRUE, 12);
- gtk_box_pack_start (GTK_BOX (hbox), vbox_entries, TRUE, TRUE, 12);
-
- if (password_data->username) {
- label = gtk_label_new (_ ("Username:"));
- gtk_box_pack_start (GTK_BOX (vbox_labels), label, TRUE, FALSE, 12);
+ {
+ /* Change the password label to ask for both username and password */
+ label = GTK_WIDGET(gtk_builder_get_object (builder,
+ "zenity_password_title"));
+ gtk_label_set_text (GTK_LABEL(label),
+ _("Type your username and password"));
+
+ /* Add the username label and entry and increment the row for the
+ * password entry so it will be added below the username.
+ */
+ label = gtk_label_new (_("Username:"));
+ gtk_grid_attach (GTK_GRID(grid), label,
+ 0, /* col */
+ 0, /* row */
+ 1, 1); /* width/height by cell. */
+
password_data->entry_username = gtk_entry_new ();
- gtk_box_pack_start (GTK_BOX (vbox_entries),
- password_data->entry_username,
- TRUE,
- TRUE,
- 12);
+ gtk_grid_attach (GTK_GRID(grid), password_data->entry_username,
+ 1,
+ 0,
+ 1, 1);
+
+ ++pass_row;
}
- label = gtk_label_new (_ ("Password:"));
- gtk_box_pack_start (GTK_BOX (vbox_labels), label, TRUE, FALSE, 12);
+ label = gtk_label_new (_("Password:"));
+ gtk_grid_attach (GTK_GRID(grid), label,
+ 0, /* col */
+ pass_row, /* row */
+ 1, 1); /* width/height by cell. */
+
password_data->entry_password = gtk_entry_new ();
- gtk_entry_set_visibility (GTK_ENTRY (password_data->entry_password), FALSE);
- gtk_entry_set_activates_default (
- GTK_ENTRY (password_data->entry_password), TRUE);
- gtk_box_pack_start (
- GTK_BOX (vbox_entries), password_data->entry_password, TRUE, TRUE, 12);
+ gtk_entry_set_visibility (GTK_ENTRY(password_data->entry_password), FALSE);
+ gtk_entry_set_input_purpose (GTK_ENTRY(password_data->entry_password),
+ GTK_INPUT_PURPOSE_PASSWORD);
+ gtk_entry_set_activates_default (GTK_ENTRY(password_data->entry_password),
+ TRUE);
+ gtk_grid_attach (GTK_GRID(grid), password_data->entry_password,
+ 1,
+ pass_row,
+ 1, 1);
if (data->dialog_title)
- gtk_window_set_title (GTK_WINDOW (dialog), data->dialog_title);
+ gtk_window_set_title (GTK_WINDOW(dialog), data->dialog_title);
if (data->modal)
- gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
+ gtk_window_set_modal (GTK_WINDOW(dialog), TRUE);
+
+ g_signal_connect (dialog, "response", G_CALLBACK(zenity_password_dialog_response), password_data);
- g_signal_connect (G_OBJECT (dialog),
- "response",
- G_CALLBACK (zenity_password_dialog_response),
- password_data);
- gtk_widget_show_all (
- GTK_WIDGET (gtk_dialog_get_content_area (GTK_DIALOG (dialog))));
- zenity_util_show_dialog (dialog, data->attach);
+ zenity_util_show_dialog (dialog);
- if (data->timeout_delay > 0) {
+ if (data->timeout_delay > 0)
+ {
g_timeout_add_seconds (data->timeout_delay,
(GSourceFunc) zenity_util_timeout_handle,
dialog);
}
- gtk_main ();
+ zenity_util_gapp_main (GTK_WINDOW(dialog));
}
static void
-zenity_password_dialog_response (
- GtkWidget *widget, int response, gpointer data) {
- ZenityPasswordData *password_data = (ZenityPasswordData *) data;
- switch (response) {
- case GTK_RESPONSE_OK:
+zenity_password_dialog_response (GtkWidget *widget, char *rstr, gpointer data)
+{
+ ZenityPasswordData *password_data = data;
+ GtkEntryBuffer *user_buff, *pass_buff;
+ ZenityExitCode response = zenity_util_parse_dialog_response (rstr);
+
+ user_buff = gtk_entry_get_buffer (GTK_ENTRY(password_data->entry_username));
+ pass_buff = gtk_entry_get_buffer (GTK_ENTRY(password_data->entry_password));
+
+ switch (response)
+ {
+ case ZENITY_OK:
zenity_util_exit_code_with_data (ZENITY_OK, zen_data);
- if (password_data->username)
+ if (password_data->username) {
g_print ("%s|%s\n",
- gtk_entry_get_text (
- GTK_ENTRY (password_data->entry_username)),
- gtk_entry_get_text (
- GTK_ENTRY (password_data->entry_password)));
- else
+ gtk_entry_buffer_get_text (user_buff),
+ gtk_entry_buffer_get_text (pass_buff));
+ }
+ else {
g_print ("%s\n",
- gtk_entry_get_text (
- GTK_ENTRY (password_data->entry_password)));
+ gtk_entry_buffer_get_text (pass_buff));
+ }
break;
- case GTK_RESPONSE_CANCEL:
+ case ZENITY_CANCEL:
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_CANCEL);
break;
default:
if (zen_data->extra_label &&
- response < g_strv_length (zen_data->extra_label))
+ response < (int)g_strv_length (zen_data->extra_label))
printf ("%s\n", zen_data->extra_label[response]);
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC);
break;
}
-
- gtk_main_quit ();
+ zenity_util_gapp_quit (GTK_WINDOW(widget), zen_data);
}