From 10d038022014a8069495bd72ccf9ed47fdf9d14d Mon Sep 17 00:00:00 2001 From: Arx Cruz Date: Sat, 10 Jul 2010 16:13:40 -0300 Subject: Add new password dialog --- src/password.c | 169 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 169 insertions(+) create mode 100644 src/password.c (limited to 'src/password.c') diff --git a/src/password.c b/src/password.c new file mode 100644 index 00000000..96aef7a2 --- /dev/null +++ b/src/password.c @@ -0,0 +1,169 @@ +/* + * password.c + * + * Copyright (C) 2010 Berislav Kovacki + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library 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. + * + * You should have received a copy of the GNU Library 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. + * + * Authors: Arx Cruz + */ + +#include "config.h" +#include +#include "zenity.h" +#include "util.h" + +static ZenityData *zen_data; + +static void zenity_password_dialog_response (GtkWidget *widget, int response, gpointer data); + +void zenity_password_dialog (ZenityData *data, ZenityPasswordData *password_data) +{ + GtkWidget *dialog; + GtkWidget *image; + GtkWidget *hbox; + GtkWidget *vbox_labels; + GtkWidget *vbox_entries; + GtkWidget *label; + GtkWidget *align; + + zen_data = data; + + dialog = gtk_dialog_new (); + + gtk_dialog_add_button(GTK_DIALOG(dialog), + GTK_STOCK_CANCEL, + GTK_RESPONSE_CANCEL); + gtk_dialog_add_button(GTK_DIALOG(dialog), + GTK_STOCK_OK, + GTK_RESPONSE_OK); + + image = gtk_image_new_from_stock(GTK_STOCK_DIALOG_AUTHENTICATION, + GTK_ICON_SIZE_DIALOG); + gtk_dialog_set_default_response(GTK_DIALOG(dialog), + GTK_RESPONSE_OK); + hbox = gtk_hbox_new(FALSE, 5); + gtk_box_pack_start(GTK_BOX(hbox), + image, + FALSE, + FALSE, + 12); + label = gtk_label_new(_("Type your password")); + gtk_box_pack_start(GTK_BOX(hbox), + label, + FALSE, + FALSE, + 12); + gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), + hbox, + FALSE, + TRUE, + 5); + + vbox_labels = gtk_vbox_new(FALSE, 5); + vbox_entries = gtk_vbox_new(FALSE, 5); + + hbox = gtk_hbox_new(FALSE, 5); + gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), + 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) { + align = gtk_alignment_new(0.0, 0.12, 0.0, 0.0); + label = gtk_label_new(_("Username:")); + gtk_container_add(GTK_CONTAINER(align), label); + gtk_box_pack_start(GTK_BOX(vbox_labels), + align, + TRUE, + FALSE, + 12); + password_data->entry_username = gtk_entry_new(); + gtk_box_pack_start(GTK_BOX(vbox_entries), + password_data->entry_username, + TRUE, + TRUE, + 12); + } + + align = gtk_alignment_new(0.0, 0.5, 0.0, 0.0); + label = gtk_label_new(_("Password:")); + gtk_container_add(GTK_CONTAINER(align), label); + + gtk_box_pack_start(GTK_BOX(vbox_labels), + align, + TRUE, + FALSE, + 12); + password_data->entry_password = gtk_entry_new(); + gtk_entry_set_visibility(GTK_ENTRY(password_data->entry_password), + FALSE); + gtk_box_pack_start(GTK_BOX(vbox_entries), + password_data->entry_password, + TRUE, + TRUE, + 12); + + if (data->dialog_title) + gtk_window_set_title (GTK_WINDOW (dialog), data->dialog_title); + + g_signal_connect (G_OBJECT (dialog), "response", + G_CALLBACK (zenity_password_dialog_response), + password_data); + gtk_widget_show_all(GTK_WIDGET(GTK_DIALOG(dialog)->vbox)); + zenity_util_show_dialog (dialog); + + if (data->timeout_delay > 0) { + g_timeout_add (data->timeout_delay * 1000, + (GSourceFunc) zenity_util_timeout_handle, + NULL); + } + gtk_main(); +} + +static void +zenity_password_dialog_response (GtkWidget *widget, int response, gpointer data) +{ + ZenityPasswordData *password_data = (ZenityPasswordData *) data; + switch (response) { + case GTK_RESPONSE_OK: + zen_data->exit_code = zenity_util_return_exit_code (ZENITY_OK); + g_print ("%s\n", gtk_entry_get_text (GTK_ENTRY(password_data->entry_password))); + break; + + case GTK_RESPONSE_CANCEL: + zen_data->exit_code = zenity_util_return_exit_code (ZENITY_CANCEL); + break; + + default: + zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC); + break; + } + + gtk_main_quit (); +} -- cgit From 79ea294e0a55190f2e4e3de895e3f9afc78ef4eb Mon Sep 17 00:00:00 2001 From: Arx Cruz Date: Mon, 12 Jul 2010 11:20:02 -0300 Subject: Just changing the copyright. --- src/password.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/password.c') diff --git a/src/password.c b/src/password.c index 96aef7a2..7aee3068 100644 --- a/src/password.c +++ b/src/password.c @@ -1,7 +1,7 @@ /* * password.c * - * Copyright (C) 2010 Berislav Kovacki + * Copyright (C) 2010 Arx Cruz * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public -- cgit From 7969d942c8c1d6fa4b5536d36080a5331db196d7 Mon Sep 17 00:00:00 2001 From: Arx Cruz Date: Mon, 12 Jul 2010 12:57:47 -0300 Subject: Change GTK_DIALOG(dialog)->vbox to gtk_dialog_get_content_area() in order to compile with GTK 3.0 --- src/password.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/password.c') diff --git a/src/password.c b/src/password.c index 7aee3068..00896eaf 100644 --- a/src/password.c +++ b/src/password.c @@ -67,7 +67,7 @@ void zenity_password_dialog (ZenityData *data, ZenityPasswordData *password_data FALSE, FALSE, 12); - gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), + gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), hbox, FALSE, TRUE, @@ -77,7 +77,7 @@ void zenity_password_dialog (ZenityData *data, ZenityPasswordData *password_data vbox_entries = gtk_vbox_new(FALSE, 5); hbox = gtk_hbox_new(FALSE, 5); - gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), + gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), hbox, FALSE, TRUE, @@ -135,7 +135,7 @@ void zenity_password_dialog (ZenityData *data, ZenityPasswordData *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(dialog)->vbox)); + gtk_widget_show_all(GTK_WIDGET(gtk_dialog_get_content_area(GTK_DIALOG(dialog)))); zenity_util_show_dialog (dialog); if (data->timeout_delay > 0) { -- cgit From 18ed4622acad91021976435f693fd560098432c5 Mon Sep 17 00:00:00 2001 From: Luis Medinas Date: Wed, 29 Sep 2010 12:26:52 +0100 Subject: Add default activation on entry. Fixes bgo#630884 - Zenity --password dialog doesn't have a default action --- src/password.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/password.c') diff --git a/src/password.c b/src/password.c index 00896eaf..3d9311ab 100644 --- a/src/password.c +++ b/src/password.c @@ -123,6 +123,8 @@ void zenity_password_dialog (ZenityData *data, ZenityPasswordData *password_data 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, -- cgit From 01bf7956d6bba165326c99ea42f498687119b618 Mon Sep 17 00:00:00 2001 From: Arx Cruz Date: Thu, 18 Nov 2010 14:54:36 -0200 Subject: Fix for bug 630885 --- src/password.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/password.c') diff --git a/src/password.c b/src/password.c index 3d9311ab..2de1a76b 100644 --- a/src/password.c +++ b/src/password.c @@ -155,7 +155,10 @@ zenity_password_dialog_response (GtkWidget *widget, int response, gpointer data) switch (response) { case GTK_RESPONSE_OK: zen_data->exit_code = zenity_util_return_exit_code (ZENITY_OK); - g_print ("%s\n", gtk_entry_get_text (GTK_ENTRY(password_data->entry_password))); + 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 + g_print ("%s\n", gtk_entry_get_text (GTK_ENTRY(password_data->entry_password))); break; case GTK_RESPONSE_CANCEL: -- cgit From b39ad33c35bb93c647e7f6f05d1310a0ce6895d5 Mon Sep 17 00:00:00 2001 From: Arx Cruz Date: Thu, 16 Jun 2011 11:07:58 -0300 Subject: Bug 651948 - zenity list does not return default value when timeout is over --- src/password.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/password.c') diff --git a/src/password.c b/src/password.c index 2de1a76b..219f5f9c 100644 --- a/src/password.c +++ b/src/password.c @@ -143,7 +143,7 @@ void zenity_password_dialog (ZenityData *data, ZenityPasswordData *password_data if (data->timeout_delay > 0) { g_timeout_add (data->timeout_delay * 1000, (GSourceFunc) zenity_util_timeout_handle, - NULL); + dialog); } gtk_main(); } -- cgit From d60e5eeeb379e5444ad218d7335b17eaa821b182 Mon Sep 17 00:00:00 2001 From: Arx Cruz Date: Fri, 17 Jun 2011 10:47:07 -0300 Subject: Now if you use --timeout option, the return code will be properly handled The default behavior will be done (ie. user click on ok button) The return code will be 5 --- src/password.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/password.c') diff --git a/src/password.c b/src/password.c index 219f5f9c..c49b6752 100644 --- a/src/password.c +++ b/src/password.c @@ -154,7 +154,7 @@ zenity_password_dialog_response (GtkWidget *widget, int response, gpointer data) ZenityPasswordData *password_data = (ZenityPasswordData *) data; switch (response) { case GTK_RESPONSE_OK: - zen_data->exit_code = zenity_util_return_exit_code (ZENITY_OK); + zenity_util_exit_code_with_data(ZENITY_OK, zen_data); 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 -- cgit From 6768a40e997697d05008aecdb41815e1dbae61c6 Mon Sep 17 00:00:00 2001 From: Arx Cruz Date: Tue, 26 Jul 2011 14:00:28 -0300 Subject: Fix for bug #611297 Now Zenity have --ok-label and --cancel-label in all dialogs. This patch doesn't break old zenity scripts. --- src/password.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/password.c') diff --git a/src/password.c b/src/password.c index c49b6752..b656d8fc 100644 --- a/src/password.c +++ b/src/password.c @@ -45,10 +45,10 @@ void zenity_password_dialog (ZenityData *data, ZenityPasswordData *password_data dialog = gtk_dialog_new (); gtk_dialog_add_button(GTK_DIALOG(dialog), - GTK_STOCK_CANCEL, + data->cancel_label != NULL ? data->cancel_label : GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL); gtk_dialog_add_button(GTK_DIALOG(dialog), - GTK_STOCK_OK, + data->ok_label != NULL ? data->ok_label : GTK_STOCK_OK, GTK_RESPONSE_OK); image = gtk_image_new_from_stock(GTK_STOCK_DIALOG_AUTHENTICATION, -- cgit From 0628bd3291aad936b6b553366600590cca360bfa Mon Sep 17 00:00:00 2001 From: Florian Müllner Date: Tue, 18 Sep 2012 18:33:07 +0200 Subject: util: Add an option to request dialogs being modal As WMs cannot open windows themselves, Mutter uses zenity to open "Force Quit" dialogs for unresponsive windows; as those are strongly tied to the corresponding window, it makes sense to make them modal (in particular when attaching them to their parent). https://bugzilla.gnome.org/show_bug.cgi?id=684322 --- src/password.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/password.c') diff --git a/src/password.c b/src/password.c index b656d8fc..1582f956 100644 --- a/src/password.c +++ b/src/password.c @@ -134,6 +134,9 @@ void zenity_password_dialog (ZenityData *data, ZenityPasswordData *password_data if (data->dialog_title) gtk_window_set_title (GTK_WINDOW (dialog), data->dialog_title); + if (data->modal) + gtk_window_set_modal (GTK_WINDOW (dialog), TRUE); + g_signal_connect (G_OBJECT (dialog), "response", G_CALLBACK (zenity_password_dialog_response), password_data); -- cgit From 009523d5da827392b027ac6da1a50f94314e3a35 Mon Sep 17 00:00:00 2001 From: Weitian Leung Date: Fri, 23 Aug 2013 09:15:07 +0800 Subject: added attach option for transient window --- src/password.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/password.c') diff --git a/src/password.c b/src/password.c index 1582f956..915ea3d9 100644 --- a/src/password.c +++ b/src/password.c @@ -141,7 +141,7 @@ void zenity_password_dialog (ZenityData *data, ZenityPasswordData *password_data 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); + zenity_util_show_dialog (dialog, data->attach); if (data->timeout_delay > 0) { g_timeout_add (data->timeout_delay * 1000, -- cgit From cdef9c8fa16fd3ab9c4790c328285de15a0dfcd0 Mon Sep 17 00:00:00 2001 From: Vinicius Silva Date: Mon, 25 Nov 2013 22:27:10 -0200 Subject: Fixing bug #712616 --- src/password.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/password.c') diff --git a/src/password.c b/src/password.c index 915ea3d9..84cca21e 100644 --- a/src/password.c +++ b/src/password.c @@ -61,7 +61,15 @@ void zenity_password_dialog (ZenityData *data, ZenityPasswordData *password_data FALSE, FALSE, 12); - label = gtk_label_new(_("Type your password")); + + /* Checks if username has been passed as a parameter */ + gchar *title_text = N_("Type your password"); + + if(password_data->username) + title_text = N_("Type your username and password"); + + label = gtk_label_new(title_text); + gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, -- cgit From 6ac663ea05f00aa42d2aa620968e26e525487201 Mon Sep 17 00:00:00 2001 From: Arx Cruz Date: Tue, 21 Oct 2014 16:05:31 +0200 Subject: Fixing remain g_timeout_add Finish switch g_timeout_add for g_timeout_add_seconds --- src/password.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/password.c') diff --git a/src/password.c b/src/password.c index 84cca21e..a6dceda2 100644 --- a/src/password.c +++ b/src/password.c @@ -152,9 +152,9 @@ void zenity_password_dialog (ZenityData *data, ZenityPasswordData *password_data zenity_util_show_dialog (dialog, data->attach); if (data->timeout_delay > 0) { - g_timeout_add (data->timeout_delay * 1000, - (GSourceFunc) zenity_util_timeout_handle, - dialog); + g_timeout_add_seconds (data->timeout_delay * 1000, + (GSourceFunc) zenity_util_timeout_handle, + dialog); } gtk_main(); } -- cgit From b44b2fb33dac0618e355f8cd5c46be0b3d13eadc Mon Sep 17 00:00:00 2001 From: Arx Cruz Date: Tue, 21 Oct 2014 16:32:14 +0200 Subject: Fixing g_timeout_add calls --- src/password.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/password.c') diff --git a/src/password.c b/src/password.c index a6dceda2..ff254fde 100644 --- a/src/password.c +++ b/src/password.c @@ -152,7 +152,7 @@ void zenity_password_dialog (ZenityData *data, ZenityPasswordData *password_data zenity_util_show_dialog (dialog, data->attach); if (data->timeout_delay > 0) { - g_timeout_add_seconds (data->timeout_delay * 1000, + g_timeout_add_seconds (data->timeout_delay, (GSourceFunc) zenity_util_timeout_handle, dialog); } -- cgit From 6fcbb80fd1b5268fbedcdb985ffa873a2e475840 Mon Sep 17 00:00:00 2001 From: Javier Jardón Date: Sun, 22 Mar 2015 04:57:05 +0000 Subject: Do not use an icon for Cancel/OK buttons GTK+ documentation recommends to not use an icons, but use "_OK"/"_Cancel" labels instead --- src/password.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/password.c') diff --git a/src/password.c b/src/password.c index ff254fde..6d85390b 100644 --- a/src/password.c +++ b/src/password.c @@ -45,10 +45,10 @@ void zenity_password_dialog (ZenityData *data, ZenityPasswordData *password_data dialog = gtk_dialog_new (); gtk_dialog_add_button(GTK_DIALOG(dialog), - data->cancel_label != NULL ? data->cancel_label : GTK_STOCK_CANCEL, + 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 : GTK_STOCK_OK, + data->ok_label != NULL ? data->ok_label : _("_OK"), GTK_RESPONSE_OK); image = gtk_image_new_from_stock(GTK_STOCK_DIALOG_AUTHENTICATION, -- cgit From c1cf0abc21133e4fa79f412f2e7b0d1a4b6954bd Mon Sep 17 00:00:00 2001 From: Javier Jardón Date: Sun, 22 Mar 2015 05:00:48 +0000 Subject: Do not use stock dialog --- src/password.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/password.c') diff --git a/src/password.c b/src/password.c index 6d85390b..be3bcf43 100644 --- a/src/password.c +++ b/src/password.c @@ -51,8 +51,8 @@ void zenity_password_dialog (ZenityData *data, ZenityPasswordData *password_data data->ok_label != NULL ? data->ok_label : _("_OK"), GTK_RESPONSE_OK); - image = gtk_image_new_from_stock(GTK_STOCK_DIALOG_AUTHENTICATION, - GTK_ICON_SIZE_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_hbox_new(FALSE, 5); -- cgit From 1f130a37fac4976687473b951908581612168bdc Mon Sep 17 00:00:00 2001 From: Javier Jardón Date: Sun, 22 Mar 2015 07:19:56 +0000 Subject: password: Use gtk_box instead gtk_[v|h]box --- src/password.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/password.c') diff --git a/src/password.c b/src/password.c index be3bcf43..32be61ea 100644 --- a/src/password.c +++ b/src/password.c @@ -55,7 +55,7 @@ void zenity_password_dialog (ZenityData *data, ZenityPasswordData *password_data GTK_ICON_SIZE_DIALOG); gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_OK); - hbox = gtk_hbox_new(FALSE, 5); + hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 5); gtk_box_pack_start(GTK_BOX(hbox), image, FALSE, @@ -81,10 +81,10 @@ void zenity_password_dialog (ZenityData *data, ZenityPasswordData *password_data TRUE, 5); - vbox_labels = gtk_vbox_new(FALSE, 5); - vbox_entries = gtk_vbox_new(FALSE, 5); + vbox_labels = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5); + vbox_entries = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5); - hbox = gtk_hbox_new(FALSE, 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, -- cgit From 7c4cd1fc426e4e30a25a390987b139fc1d32a0b3 Mon Sep 17 00:00:00 2001 From: Javier Jardón Date: Sun, 22 Mar 2015 07:25:59 +0000 Subject: src/password.c: Do not use deprecated GtkAlignment widget --- src/password.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'src/password.c') diff --git a/src/password.c b/src/password.c index 32be61ea..c5161002 100644 --- a/src/password.c +++ b/src/password.c @@ -38,7 +38,6 @@ void zenity_password_dialog (ZenityData *data, ZenityPasswordData *password_data GtkWidget *vbox_labels; GtkWidget *vbox_entries; GtkWidget *label; - GtkWidget *align; zen_data = data; @@ -103,11 +102,9 @@ void zenity_password_dialog (ZenityData *data, ZenityPasswordData *password_data 12); if(password_data->username) { - align = gtk_alignment_new(0.0, 0.12, 0.0, 0.0); label = gtk_label_new(_("Username:")); - gtk_container_add(GTK_CONTAINER(align), label); gtk_box_pack_start(GTK_BOX(vbox_labels), - align, + label, TRUE, FALSE, 12); @@ -119,12 +116,9 @@ void zenity_password_dialog (ZenityData *data, ZenityPasswordData *password_data 12); } - align = gtk_alignment_new(0.0, 0.5, 0.0, 0.0); label = gtk_label_new(_("Password:")); - gtk_container_add(GTK_CONTAINER(align), label); - gtk_box_pack_start(GTK_BOX(vbox_labels), - align, + label, TRUE, FALSE, 12); -- cgit From ba5ea0386de2a80a664fb28d3af7e8d395968314 Mon Sep 17 00:00:00 2001 From: Gama Anderson Date: Sat, 28 Feb 2015 20:06:09 +0100 Subject: ADD gchar **extra_label TO struct ZenityData this is done to keep the name of the extra buttons ADD general option "extra-button" with string array as argument This will upon consecutive calls save the name of buttons in an array of strings To all MODES, except notification.c and about.c ADD 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++; } } This add the extra buttons to the dialog. The response is the number of the button To all MODES response, except notification.c and about.c ADD default: if (response < g_strv_length(zen_data->extra_label)) printf("%s\n",zen_data->extra_label[response]); This will print the button name to stdout when they are pressed ADD question option "switch" This will suppress the standard "ok" and "cancel" button in question. This just wort in combination with --extra-button, otherwise error is raised. https://bugzilla.gnome.org/show_bug.cgi?id=118016 --- src/password.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/password.c') diff --git a/src/password.c b/src/password.c index ff254fde..23357467 100644 --- a/src/password.c +++ b/src/password.c @@ -44,6 +44,14 @@ void zenity_password_dialog (ZenityData *data, ZenityPasswordData *password_data dialog = gtk_dialog_new (); + 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++; + } + } + gtk_dialog_add_button(GTK_DIALOG(dialog), data->cancel_label != NULL ? data->cancel_label : GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL); @@ -177,6 +185,8 @@ zenity_password_dialog_response (GtkWidget *widget, int response, gpointer data) break; default: + if (response < 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; } -- cgit From d063797fdfa73e5bec96d9399ab1bf47173a62d4 Mon Sep 17 00:00:00 2001 From: Arx Cruz Date: Fri, 2 Oct 2015 14:35:06 +0200 Subject: Fixing GLib-CRITICAL messages --- src/password.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/password.c') diff --git a/src/password.c b/src/password.c index 1d17d913..d8f492f6 100644 --- a/src/password.c +++ b/src/password.c @@ -179,7 +179,7 @@ zenity_password_dialog_response (GtkWidget *widget, int response, gpointer data) break; default: - if (response < g_strv_length(zen_data->extra_label)) + if (zen_data->extra_label && response < 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; -- cgit From 4eddb202cafdcabc254aa941ad1348ff09372627 Mon Sep 17 00:00:00 2001 From: Arx Cruz Date: Fri, 7 Apr 2017 14:00:42 +0200 Subject: Fix style Fixing style in all zenity code, removing useless spaces, empty lines, all code in 80 columns, etc. --- src/password.c | 298 +++++++++++++++++++++++++++------------------------------ 1 file changed, 141 insertions(+), 157 deletions(-) (limited to 'src/password.c') diff --git a/src/password.c b/src/password.c index d8f492f6..44a2a204 100644 --- a/src/password.c +++ b/src/password.c @@ -22,168 +22,152 @@ */ #include "config.h" -#include -#include "zenity.h" #include "util.h" +#include "zenity.h" +#include static ZenityData *zen_data; -static void zenity_password_dialog_response (GtkWidget *widget, int response, gpointer data); - -void zenity_password_dialog (ZenityData *data, ZenityPasswordData *password_data) -{ - GtkWidget *dialog; - GtkWidget *image; - GtkWidget *hbox; - GtkWidget *vbox_labels; - GtkWidget *vbox_entries; - GtkWidget *label; - - zen_data = data; - - dialog = gtk_dialog_new (); - - 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++; - } - } - - 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); - - 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); - - /* Checks if username has been passed as a parameter */ - gchar *title_text = N_("Type your password"); - - if(password_data->username) - title_text = N_("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); - password_data->entry_username = gtk_entry_new(); - gtk_box_pack_start(GTK_BOX(vbox_entries), - password_data->entry_username, - TRUE, - TRUE, - 12); - } - - label = gtk_label_new(_("Password:")); - gtk_box_pack_start(GTK_BOX(vbox_labels), - label, - TRUE, - FALSE, - 12); - 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); - - if (data->dialog_title) - gtk_window_set_title (GTK_WINDOW (dialog), data->dialog_title); - - if (data->modal) - gtk_window_set_modal (GTK_WINDOW (dialog), TRUE); - - 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); - - if (data->timeout_delay > 0) { - g_timeout_add_seconds (data->timeout_delay, - (GSourceFunc) zenity_util_timeout_handle, - dialog); - } - gtk_main(); +static void zenity_password_dialog_response ( + GtkWidget *widget, int response, gpointer data); + +void +zenity_password_dialog (ZenityData *data, ZenityPasswordData *password_data) { + GtkWidget *dialog; + GtkWidget *image; + GtkWidget *hbox; + GtkWidget *vbox_labels; + GtkWidget *vbox_entries; + GtkWidget *label; + + zen_data = data; + + dialog = gtk_dialog_new (); + + 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++; + } + } + + 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); + + 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); + + /* Checks if username has been passed as a parameter */ + gchar *title_text = N_ ("Type your password"); + + if (password_data->username) + title_text = N_ ("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); + password_data->entry_username = gtk_entry_new (); + gtk_box_pack_start (GTK_BOX (vbox_entries), + password_data->entry_username, + TRUE, + TRUE, + 12); + } + + label = gtk_label_new (_ ("Password:")); + gtk_box_pack_start (GTK_BOX (vbox_labels), label, TRUE, FALSE, 12); + 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); + + if (data->dialog_title) + gtk_window_set_title (GTK_WINDOW (dialog), data->dialog_title); + + if (data->modal) + gtk_window_set_modal (GTK_WINDOW (dialog), TRUE); + + 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); + + if (data->timeout_delay > 0) { + g_timeout_add_seconds (data->timeout_delay, + (GSourceFunc) zenity_util_timeout_handle, + dialog); + } + gtk_main (); } static void -zenity_password_dialog_response (GtkWidget *widget, int response, gpointer data) -{ - ZenityPasswordData *password_data = (ZenityPasswordData *) data; - switch (response) { - case GTK_RESPONSE_OK: - zenity_util_exit_code_with_data(ZENITY_OK, zen_data); - 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 - g_print ("%s\n", gtk_entry_get_text (GTK_ENTRY(password_data->entry_password))); - break; - - case GTK_RESPONSE_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)) - printf("%s\n",zen_data->extra_label[response]); - zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC); - break; - } - - gtk_main_quit (); +zenity_password_dialog_response ( + GtkWidget *widget, int response, gpointer data) { + ZenityPasswordData *password_data = (ZenityPasswordData *) data; + switch (response) { + case GTK_RESPONSE_OK: + zenity_util_exit_code_with_data (ZENITY_OK, zen_data); + 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 + g_print ("%s\n", + gtk_entry_get_text ( + GTK_ENTRY (password_data->entry_password))); + break; + + case GTK_RESPONSE_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)) + printf ("%s\n", zen_data->extra_label[response]); + zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC); + break; + } + + gtk_main_quit (); } -- cgit