diff options
author | Arx Cruz <arxcruz@src.gnome.org> | 2010-07-10 16:13:40 -0300 |
---|---|---|
committer | Arx Cruz <arxcruz@src.gnome.org> | 2010-07-12 11:08:26 -0300 |
commit | 10d038022014a8069495bd72ccf9ed47fdf9d14d (patch) | |
tree | 1534f086e8259514ad9117724eb262a34346b4f1 | |
parent | Update Czech translation by Marek Cernocky (diff) | |
download | zenity-10d038022014a8069495bd72ccf9ed47fdf9d14d.tar.gz zenity-10d038022014a8069495bd72ccf9ed47fdf9d14d.tar.bz2 zenity-10d038022014a8069495bd72ccf9ed47fdf9d14d.zip |
Add new password dialog
-rw-r--r-- | src/Makefile.am | 1 | ||||
-rw-r--r-- | src/main.c | 3 | ||||
-rw-r--r-- | src/option.c | 72 | ||||
-rw-r--r-- | src/option.h | 2 | ||||
-rw-r--r-- | src/password.c | 169 | ||||
-rw-r--r-- | src/zenity.h | 10 |
6 files changed, 256 insertions, 1 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index dbd672d0..03110fbc 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -17,6 +17,7 @@ zenity_SOURCES = \ text.c \ tree.c \ color.c \ + password.c \ util.c \ util.h \ zenity.h @@ -87,6 +87,9 @@ main (gint argc, gchar **argv) { case MODE_COLOR: zenity_colorselection (results->data, results->color_data); break; + case MODE_PASSWORD: + zenity_password_dialog (results->data, results->password_data); + break; case MODE_ABOUT: zenity_about (results->data); break; diff --git a/src/option.c b/src/option.c index 00467452..b9694fde 100644 --- a/src/option.c +++ b/src/option.c @@ -113,6 +113,10 @@ static gboolean zenity_colorsel_active; static gchar *zenity_colorsel_color; static gboolean zenity_colorsel_show_palette; +/* Password Dialog Options */ +static gboolean zenity_password_active; +static gboolean zenity_password_show_username; + /* Miscelaneus Options */ static gboolean zenity_misc_about; static gboolean zenity_misc_version; @@ -823,6 +827,30 @@ static GOptionEntry scale_options[] = { } }; +static GOptionEntry password_dialog_options[] = { + { + "password", + '\0', + G_OPTION_FLAG_IN_MAIN, + G_OPTION_ARG_NONE, + &zenity_password_active, + N_("Display password dialog"), + NULL + }, + { + "username", + '\0', + 0, + G_OPTION_ARG_NONE, + &zenity_password_show_username, + N_("Display the username option"), + NULL + }, + { + NULL + } +}; + static GOptionEntry color_selection_options[] = { { "color-selection", @@ -901,6 +929,7 @@ zenity_option_init (void) { results->tree_data = g_new0 (ZenityTreeData, 1); results->notification_data = g_new0 (ZenityNotificationData, 1); results->color_data = g_new0 (ZenityColorData, 1); + results->password_data = g_new0 (ZenityPasswordData, 1); } void @@ -938,7 +967,7 @@ zenity_option_free (void) { if (zenity_colorsel_color) g_free (zenity_colorsel_color); - + g_option_context_free (ctx); } @@ -1171,6 +1200,18 @@ zenity_color_pre_callback (GOptionContext *context, } static gboolean +zenity_password_pre_callback (GOptionContext *context, + GOptionGroup *group, + gpointer data, + GError **error) +{ + zenity_password_active = FALSE; + zenity_password_show_username = FALSE; + + return TRUE; +} + +static gboolean zenity_misc_pre_callback (GOptionContext *context, GOptionGroup *group, gpointer data, @@ -1560,6 +1601,24 @@ zenity_color_post_callback (GOptionContext *context, } static gboolean +zenity_password_post_callback (GOptionContext *context, + GOptionGroup *group, + gpointer data, + GError **error) +{ + zenity_option_set_dialog_mode (zenity_password_active, MODE_PASSWORD); + if (results->mode == MODE_PASSWORD) { + results->password_data->username = zenity_password_show_username; + } else { + if (zenity_password_show_username) + zenity_option_error (zenity_option_get_name(password_dialog_options, &zenity_password_show_username), + ERROR_SUPPORT); + } + + return TRUE; +} + +static gboolean zenity_misc_post_callback (GOptionContext *context, GOptionGroup *group, gpointer data, @@ -1733,6 +1792,17 @@ zenity_create_context (void) g_option_group_set_translation_domain (a_group, GETTEXT_PACKAGE); g_option_context_add_group(tmp_ctx, a_group); + /* Adds password dialog option entries */ + a_group = g_option_group_new("password", + N_("Password dialog options"), + N_("Show password dialog options"), NULL, NULL); + g_option_group_add_entries (a_group, password_dialog_options); + g_option_group_set_parse_hooks (a_group, + zenity_password_pre_callback, zenity_password_post_callback); + g_option_group_set_error_hook (a_group, zenity_option_error_callback); + g_option_group_set_translation_domain (a_group, GETTEXT_PACKAGE); + g_option_context_add_group(tmp_ctx, a_group); + /* Adds misc option entries */ a_group = g_option_group_new("misc", N_("Miscellaneous options"), diff --git a/src/option.h b/src/option.h index f52c3125..076b4c77 100644 --- a/src/option.h +++ b/src/option.h @@ -46,6 +46,7 @@ typedef enum { MODE_INFO, MODE_NOTIFICATION, MODE_COLOR, + MODE_PASSWORD, MODE_ABOUT, MODE_VERSION, MODE_LAST @@ -72,6 +73,7 @@ typedef struct { ZenityTreeData *tree_data; ZenityNotificationData *notification_data; ZenityColorData *color_data; + ZenityPasswordData *password_data; } ZenityParsingOptions; void zenity_option_error (gchar *string, 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 <arxcruz@gmail.com> + */ + +#include "config.h" +#include <string.h> +#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 (); +} diff --git a/src/zenity.h b/src/zenity.h index a4cff2b9..ecde3db6 100644 --- a/src/zenity.h +++ b/src/zenity.h @@ -131,6 +131,13 @@ typedef struct { gboolean show_palette; } ZenityColorData; +typedef struct { + gboolean username; + gchar *password; + GtkWidget *entry_username; + GtkWidget *entry_password; +} ZenityPasswordData; + void zenity_calendar (ZenityData *data, ZenityCalendarData *calendar_data); void zenity_msg (ZenityData *data, @@ -153,6 +160,9 @@ void zenity_scale (ZenityData *data, ZenityScaleData *scale_data); void zenity_about (ZenityData *data); +void zenity_password_dialog (ZenityData *data, + ZenityPasswordData *password_data); + G_END_DECLS #endif /* ZENITY_H */ |