diff --git a/src/Makefile.am b/src/Makefile.am index 95f0790..fb61e5c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -20,6 +20,7 @@ zenity_SOURCES = \ password.c \ util.c \ util.h \ + forms.c \ zenity.h zenity_CPPFLAGS = \ diff --git a/src/main.c b/src/main.c index 0517615..e667ee1 100644 --- a/src/main.c +++ b/src/main.c @@ -95,6 +95,9 @@ main (gint argc, gchar **argv) { case MODE_ABOUT: zenity_about (results->data); break; + case MODE_FORMS: + zenity_forms_dialog (results->data, results->forms_data); + break; case MODE_VERSION: g_print ("%s\n", VERSION); break; diff --git a/src/option.c b/src/option.c index 2d6d8a4..cd81209 100644 --- a/src/option.c +++ b/src/option.c @@ -120,10 +120,20 @@ static gboolean zenity_colorsel_show_palette; static gboolean zenity_password_active; static gboolean zenity_password_show_username; +/* Forms Dialog Options */ +static gboolean zenity_forms_active; +static gchar *zenity_forms_date_format; + /* Miscelaneus Options */ static gboolean zenity_misc_about; static gboolean zenity_misc_version; +static gboolean +zenity_forms_callback (const gchar *option_name, + const gchar *value, + gpointer data, + GError **error); + static GOptionEntry general_options[] = { { "title", @@ -842,6 +852,75 @@ static GOptionEntry scale_options[] = { } }; +static GOptionEntry forms_dialog_options[] = { + { + "forms", + '\0', + G_OPTION_FLAG_IN_MAIN, + G_OPTION_ARG_NONE, + &zenity_forms_active, + N_("Display forms dialog"), + NULL + }, + { + "add-entry", + '\0', + 0, + G_OPTION_ARG_CALLBACK, + zenity_forms_callback, + N_("Add a new Entry in forms dialog"), + N_("Field name") + }, + { + "add-password", + '\0', + 0, + G_OPTION_ARG_CALLBACK, + zenity_forms_callback, + N_("Add a new Password Entry in forms dialog"), + N_("Field name") + }, + { + "add-calendar", + '\0', + 0, + G_OPTION_ARG_CALLBACK, + zenity_forms_callback, + N_("Add a new Calendar in forms dialog"), + N_("Calendar field name") + }, + { + "text", + '\0', + G_OPTION_FLAG_NOALIAS, + G_OPTION_ARG_STRING, + &zenity_general_dialog_text, + N_("Set the dialog text"), + N_("TEXT") + }, + { + "separator", + '\0', + G_OPTION_FLAG_NOALIAS, + G_OPTION_ARG_STRING, + &zenity_general_separator, + N_("Set output separator character"), + N_("SEPARATOR") + }, + { + "date-format", + '\0', + 0, + G_OPTION_ARG_STRING, + &zenity_forms_date_format, + N_("Set the format for the returned date"), + N_("PATTERN") + }, + { + NULL + } +}; + static GOptionEntry password_dialog_options[] = { { "password", @@ -947,6 +1026,7 @@ zenity_option_init (void) { #endif results->color_data = g_new0 (ZenityColorData, 1); results->password_data = g_new0 (ZenityPasswordData, 1); + results->forms_data = g_new0 (ZenityFormsData, 1); } void @@ -964,6 +1044,9 @@ zenity_option_free (void) { if (zenity_calendar_date_format) g_free (zenity_calendar_date_format); + if (zenity_forms_date_format) + g_free (zenity_forms_date_format); + if (zenity_entry_entry_text) g_free (zenity_entry_entry_text); @@ -1014,6 +1097,27 @@ zenity_option_get_name (GOptionEntry *entries, gpointer arg_data) return NULL; } +/* Forms callback */ +static gboolean +zenity_forms_callback (const gchar *option_name, + const gchar *value, + gpointer data, + GError **error) +{ + ZenityFormsValue *forms_value = g_new0 (ZenityFormsValue, 1); + forms_value->option_value = g_strdup(value); + if (g_strcmp0(option_name, "--add-entry") == 0) + forms_value->type = ZENITY_FORMS_ENTRY; + else if (g_strcmp0(option_name, "--add-calendar") == 0) + forms_value->type = ZENITY_FORMS_CALENDAR; + else if (g_strcmp0(option_name, "--add-password") == 0) + forms_value->type = ZENITY_FORMS_PASSWORD; + + results->forms_data->list = g_slist_append(results->forms_data->list, forms_value); + + return TRUE; +} + /* Error callback */ static void zenity_option_error_callback (GOptionContext *context, @@ -1234,6 +1338,17 @@ zenity_password_pre_callback (GOptionContext *context, return TRUE; } +static gboolean +zenity_forms_pre_callback (GOptionContext *context, + GOptionGroup *group, + gpointer data, + GError **error) +{ + zenity_forms_active = FALSE; + zenity_forms_date_format = NULL; + return TRUE; +} + static gboolean zenity_misc_pre_callback (GOptionContext *context, GOptionGroup *group, @@ -1631,6 +1746,30 @@ zenity_color_post_callback (GOptionContext *context, return TRUE; } +static gboolean +zenity_forms_post_callback (GOptionContext *context, + GOptionGroup *group, + gpointer data, + GError **error) +{ + zenity_option_set_dialog_mode (zenity_forms_active, MODE_FORMS); + if (results->mode == MODE_FORMS) { + results->forms_data->dialog_text = zenity_general_dialog_text; + results->forms_data->separator = zenity_general_separator; + if (zenity_forms_date_format) + results->forms_data->date_format = zenity_forms_date_format; + else + results->forms_data->date_format = g_locale_to_utf8 (nl_langinfo (D_FMT), -1, NULL, NULL, NULL); + } else { + if (zenity_forms_date_format) + zenity_option_error (zenity_option_get_name (forms_dialog_options, &zenity_forms_date_format), + ERROR_SUPPORT); + } + + return TRUE; +} + + static gboolean zenity_password_post_callback (GOptionContext *context, GOptionGroup *group, @@ -1836,6 +1975,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 forms dialog option entries */ + a_group = g_option_group_new("forms", + N_("Forms dialog options"), + N_("Show forms dialog options"), NULL, NULL); + g_option_group_add_entries (a_group, forms_dialog_options); + g_option_group_set_parse_hooks (a_group, + zenity_forms_pre_callback, zenity_forms_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"), @@ -1899,7 +2049,7 @@ zenity_option_parse (gint argc, gchar **argv) zenity_option_error (zenity_option_get_name (calendar_options, &zenity_general_dialog_text), ERROR_SUPPORT); if (strcmp (zenity_general_separator, "|") != 0) - if (results->mode != MODE_LIST && results->mode != MODE_FILE) + if (results->mode != MODE_LIST && results->mode != MODE_FILE && results->mode != MODE_FORMS) zenity_option_error (zenity_option_get_name (list_options, &zenity_general_separator), ERROR_SUPPORT); if (zenity_general_multiple) diff --git a/src/option.h b/src/option.h index ac550b3..ddca9a9 100644 --- a/src/option.h +++ b/src/option.h @@ -49,6 +49,7 @@ typedef enum { #endif MODE_COLOR, MODE_PASSWORD, + MODE_FORMS, MODE_ABOUT, MODE_VERSION, MODE_LAST @@ -78,6 +79,7 @@ typedef struct { #endif ZenityColorData *color_data; ZenityPasswordData *password_data; + ZenityFormsData *forms_data; } ZenityParsingOptions; void zenity_option_error (gchar *string, diff --git a/src/zenity.h b/src/zenity.h index 6414140..e5c6f4c 100644 --- a/src/zenity.h +++ b/src/zenity.h @@ -135,6 +135,26 @@ typedef struct { gboolean show_palette; } ZenityColorData; +typedef struct { + GSList *list; + GSList *list_widgets; + gchar *dialog_text; + gchar *separator; + gchar *date_format; +} ZenityFormsData; + +typedef enum { + ZENITY_FORMS_ENTRY, + ZENITY_FORMS_PASSWORD, + ZENITY_FORMS_CALENDAR +} ZenityFormsType; + +typedef struct { + gchar *option_value; + ZenityFormsType type; + GtkWidget *forms_widget; +} ZenityFormsValue; + typedef struct { gboolean username; gchar *password; @@ -169,7 +189,8 @@ void zenity_about (ZenityData *data); void zenity_password_dialog (ZenityData *data, ZenityPasswordData *password_data); - +void zenity_forms_dialog (ZenityData *data, + ZenityFormsData *forms_data); G_END_DECLS #endif /* ZENITY_H */ diff --git a/src/zenity.ui b/src/zenity.ui index 5275a07..0255610 100644 --- a/src/zenity.ui +++ b/src/zenity.ui @@ -7,7 +7,6 @@ Calendar selection center dialog - True False @@ -129,7 +128,6 @@ Warning center dialog - True False @@ -213,7 +211,6 @@ Question center dialog - True False @@ -278,7 +275,6 @@ Add a new entry center dialog - True False @@ -377,7 +373,6 @@ 300 200 dialog - True False @@ -455,7 +450,6 @@ Progress center dialog - True False @@ -551,7 +545,6 @@ Error center dialog - True False @@ -643,7 +636,6 @@ 300 196 dialog - True False @@ -744,7 +736,6 @@ Information center dialog - True False @@ -827,7 +818,6 @@ 300 100 dialog - True False @@ -924,4 +914,96 @@ 1 + + 5 + normal + False + + + True + 2 + + + True + 0 + + + True + 12 + 12 + 6 + + + True + 2 + 10 + 6 + + + + + + + + + + + + + True + <b>Forms dialog</b> + True + + + + + 1 + + + + + True + end + + + gtk-cancel + True + True + True + True + + + False + False + 0 + + + + + gtk-ok + True + True + True + True + + + False + False + 1 + + + + + False + end + 0 + + + + + + cancelbutton12 + okbutton12 + +