summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLogan Rathbone <poprocks@gmail.com>2021-02-12 19:36:10 -0500
committerLogan Rathbone <poprocks@gmail.com>2021-02-12 19:36:10 -0500
commit5bcc3b18ca378e0ccf52a0890a7519505d8b5f08 (patch)
treedcda328dd06cdb8309e032776878b9769b825de0 /src
parent95a11a738cdd53e84e30358d2e55f080c63f10b5 (diff)
downloadzenity-5bcc3b18ca378e0ccf52a0890a7519505d8b5f08.tar.gz
password: use Builder for consistency with rest of app.
Diffstat (limited to 'src')
-rw-r--r--src/entry.c11
-rw-r--r--src/password.c100
-rw-r--r--src/zenity.ui72
3 files changed, 134 insertions, 49 deletions
diff --git a/src/entry.c b/src/entry.c
index 40cd909..6451e75 100644
--- a/src/entry.c
+++ b/src/entry.c
@@ -92,13 +92,10 @@ zenity_entry (ZenityData *data, ZenityEntryData *entry_data)
if (data->extra_label)
{
- int i = 0;
-
- while (data->extra_label[i] != NULL)
+ for (int i = 0; data->extra_label[i] != NULL; ++i)
{
gtk_dialog_add_button (GTK_DIALOG (dialog),
data->extra_label[i], i);
- i++;
}
}
@@ -109,7 +106,8 @@ zenity_entry (ZenityData *data, ZenityEntryData *entry_data)
gtk_button_set_label (GTK_BUTTON(button), data->ok_label);
}
- if (data->cancel_label) {
+ if (data->cancel_label)
+ {
button = GTK_WIDGET(gtk_builder_get_object (builder,
"zenity_entry_cancel_button"));
gtk_button_set_label (GTK_BUTTON(button), data->cancel_label);
@@ -117,9 +115,10 @@ zenity_entry (ZenityData *data, ZenityEntryData *entry_data)
text = gtk_builder_get_object (builder, "zenity_entry_text");
- if (entry_data->dialog_text)
+ if (entry_data->dialog_text) {
gtk_label_set_text_with_mnemonic (GTK_LABEL (text),
g_strcompress (entry_data->dialog_text));
+ }
vbox = gtk_builder_get_object (builder, "vbox4");
diff --git a/src/password.c b/src/password.c
index 8586619..172fe4f 100644
--- a/src/password.c
+++ b/src/password.c
@@ -39,17 +39,26 @@ static void zenity_password_dialog_response (GtkWidget *widget,
void
zenity_password_dialog (ZenityData *data, ZenityPasswordData *password_data)
{
+ GtkBuilder *builder;
GtkWidget *dialog;
- GtkWidget *image;
- GtkWidget *hbox;
- GtkWidget *vbox_labels;
- GtkWidget *vbox_entries;
+ GtkWidget *button;
+ GtkWidget *grid;
GtkWidget *label;
- char *title_text;
+ int pass_row = 0;
+ /* Set global */
zen_data = data;
- dialog = gtk_dialog_new ();
+ builder = zenity_util_load_ui_file ("zenity_password_dialog", NULL);
+
+ if (builder == NULL)
+ {
+ data->exit_code = zenity_util_return_exit_code (ZENITY_ERROR);
+ return;
+ }
+
+ dialog = GTK_WIDGET(gtk_builder_get_object (builder,
+ "zenity_password_dialog"));
if (data->extra_label)
{
@@ -60,61 +69,66 @@ zenity_password_dialog (ZenityData *data, ZenityPasswordData *password_data)
}
}
- 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);
+ if (data->ok_label)
+ {
+ button = GTK_WIDGET(gtk_builder_get_object (builder,
+ "zenity_password_ok_button"));
+ gtk_button_set_label (GTK_BUTTON(button), data->ok_label);
+ }
- image = gtk_image_new_from_icon_name ("dialog-password");
+ if (data->cancel_label)
+ {
+ button = GTK_WIDGET(gtk_builder_get_object (builder,
+ "zenity_password_cancel_button"));
+ gtk_button_set_label (GTK_BUTTON(button), data->cancel_label);
+ }
- gtk_dialog_set_default_response (GTK_DIALOG(dialog), GTK_RESPONSE_OK);
- hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 5);
- gtk_box_append (GTK_BOX(hbox), image);
+ 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");
- else
- title_text = _("Type your password");
-
- label = gtk_label_new (title_text);
-
- gtk_box_append (GTK_BOX(hbox), label);
- gtk_box_append (GTK_BOX(gtk_dialog_get_content_area (GTK_DIALOG(dialog))),
- hbox);
-
- 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_append (GTK_BOX(gtk_dialog_get_content_area (GTK_DIALOG(dialog))),
- hbox);
-
- gtk_box_append (GTK_BOX(hbox), vbox_labels);
- gtk_box_append (GTK_BOX (hbox), vbox_entries);
-
- if (password_data->username)
{
+ /* 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_box_append (GTK_BOX(vbox_labels), label);
+ 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_append (GTK_BOX(vbox_entries),
- password_data->entry_username);
+ gtk_grid_attach (GTK_GRID(grid), password_data->entry_username,
+ 1,
+ 0,
+ 1, 1);
+
+ ++pass_row;
}
label = gtk_label_new (_("Password:"));
- gtk_box_append (GTK_BOX(vbox_labels), label);
+ 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_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_box_append (GTK_BOX(vbox_entries), password_data->entry_password);
+ 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);
diff --git a/src/zenity.ui b/src/zenity.ui
index 96017f3..d7783f5 100644
--- a/src/zenity.ui
+++ b/src/zenity.ui
@@ -676,4 +676,76 @@
</object>
</child>
</object>
+
+
+
+
+
+
+
+ <object class="GtkDialog" id="zenity_password_dialog">
+ <property name="title" translatable="yes">Warning</property>
+ <property name="resizable">false</property>
+
+ <child internal-child="content_area">
+ <object class="GtkBox"> <!-- vbox -->
+ <property name="orientation">vertical</property>
+ <property name="spacing">14</property>
+ <property name="margin-start">12</property>
+ <property name="margin-end">12</property>
+ <property name="margin-bottom">12</property>
+ <property name="margin-top">12</property>
+ <child>
+ <object class="GtkBox">
+ <property name="orientation">horizontal</property>
+ <property name="spacing">12</property>
+ <child>
+ <object class="GtkImage" id="zenity_password_image">
+ <property name="icon_name">dialog-password</property>
+ <property name="icon_size">large</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkLabel" id="zenity_password_title">
+ <property name="label" translatable="yes">Type your password</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ <child>
+ <object class="GtkGrid" id="zenity_password_grid">
+ <property name="column-spacing">12</property>
+ <property name="row-spacing">6</property>
+ </object>
+ </child>
+ </object> <!-- !vbox -->
+ </child>
+ <action-widgets>
+ <action-widget response="ok" default="true">zenity_password_ok_button</action-widget>
+ <action-widget response="cancel">zenity_password_cancel_button</action-widget>
+ </action-widgets>
+ <child internal-child="action_area">
+ <object class="GtkBox">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <child>
+ <object class="GtkButton" id="zenity_password_ok_button">
+ <property name="use-underline">true</property>
+ <property name="label" translatable="yes">_OK</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkButton" id="zenity_password_cancel_button">
+ <property name="use-underline">true</property>
+ <property name="label" translatable="yes">_Cancel</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+
+
+
+
+
</interface>