[zenity] Adding missed files and code for --forms option.



commit 9c32783a1442f95f77a6a997058baa8c720011c8
Author: Arx Cruz <arxcruz src gnome org>
Date:   Mon Jan 17 12:20:21 2011 -0200

    Adding missed files and code for --forms option.

 src/Makefile.am |    1 +
 src/main.c      |    3 +
 src/option.c    |  152 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 src/option.h    |    2 +
 src/zenity.h    |   23 ++++++++-
 src/zenity.ui   |  102 +++++++++++++++++++++++++++++++++----
 6 files changed, 271 insertions(+), 12 deletions(-)
---
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,
@@ -1235,6 +1339,17 @@ zenity_password_pre_callback (GOptionContext *context,
 }
 
 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,
 		          gpointer	  data,
@@ -1632,6 +1747,30 @@ zenity_color_post_callback (GOptionContext *context,
 }
 
 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,
                                gpointer        data,
@@ -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
@@ -136,6 +136,26 @@ typedef struct {
 } 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;
   GtkWidget *entry_username;
@@ -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 @@
     <property name="title" translatable="yes">Calendar selection</property>
     <property name="window_position">center</property>
     <property name="type_hint">dialog</property>
-    <property name="focus_on_map">True</property>
     <property name="has_separator">False</property>
     <signal name="destroy" handler="gtk_main_quit"/>
     <child internal-child="vbox">
@@ -129,7 +128,6 @@
     <property name="title" translatable="yes">Warning</property>
     <property name="window_position">center</property>
     <property name="type_hint">dialog</property>
-    <property name="focus_on_map">True</property>
     <property name="has_separator">False</property>
     <signal name="destroy" handler="gtk_main_quit"/>
     <child internal-child="vbox">
@@ -213,7 +211,6 @@
     <property name="title" translatable="yes">Question</property>
     <property name="window_position">center</property>
     <property name="type_hint">dialog</property>
-    <property name="focus_on_map">True</property>
     <property name="has_separator">False</property>
     <signal name="destroy" handler="gtk_main_quit"/>
     <child internal-child="vbox">
@@ -278,7 +275,6 @@
     <property name="title" translatable="yes">Add a new entry</property>
     <property name="window_position">center</property>
     <property name="type_hint">dialog</property>
-    <property name="focus_on_map">True</property>
     <property name="has_separator">False</property>
     <signal name="destroy" handler="gtk_main_quit"/>
     <child internal-child="vbox">
@@ -377,7 +373,6 @@
     <property name="default_width">300</property>
     <property name="default_height">200</property>
     <property name="type_hint">dialog</property>
-    <property name="focus_on_map">True</property>
     <property name="has_separator">False</property>
     <signal name="destroy" handler="gtk_main_quit"/>
     <child internal-child="vbox">
@@ -455,7 +450,6 @@
     <property name="title" translatable="yes">Progress</property>
     <property name="window_position">center</property>
     <property name="type_hint">dialog</property>
-    <property name="focus_on_map">True</property>
     <property name="has_separator">False</property>
     <signal name="destroy" handler="gtk_main_quit"/>
     <child internal-child="vbox">
@@ -551,7 +545,6 @@
     <property name="title" translatable="yes">Error</property>
     <property name="window_position">center</property>
     <property name="type_hint">dialog</property>
-    <property name="focus_on_map">True</property>
     <property name="has_separator">False</property>
     <signal name="destroy" handler="gtk_main_quit"/>
     <child internal-child="vbox">
@@ -643,7 +636,6 @@
     <property name="default_width">300</property>
     <property name="default_height">196</property>
     <property name="type_hint">dialog</property>
-    <property name="focus_on_map">True</property>
     <property name="has_separator">False</property>
     <signal name="destroy" handler="gtk_main_quit"/>
     <child internal-child="vbox">
@@ -744,7 +736,6 @@
     <property name="title" translatable="yes">Information</property>
     <property name="window_position">center</property>
     <property name="type_hint">dialog</property>
-    <property name="focus_on_map">True</property>
     <property name="has_separator">False</property>
     <signal name="destroy" handler="gtk_main_quit"/>
     <child internal-child="vbox">
@@ -827,7 +818,6 @@
     <property name="default_width">300</property>
     <property name="default_height">100</property>
     <property name="type_hint">dialog</property>
-    <property name="focus_on_map">True</property>
     <property name="has_separator">False</property>
     <signal name="destroy" handler="gtk_main_quit"/>
     <child internal-child="vbox">
@@ -924,4 +914,96 @@
     <property name="page_increment">1</property>
   </object>
   <object class="GtkTextBuffer" id="textbuffer1"/>
+  <object class="GtkDialog" id="zenity_forms_dialog">
+    <property name="border_width">5</property>
+    <property name="type_hint">normal</property>
+    <property name="has_separator">False</property>
+    <child internal-child="vbox">
+      <object class="GtkVBox" id="dialog-vbox12">
+        <property name="visible">True</property>
+        <property name="spacing">2</property>
+        <child>
+          <object class="GtkFrame" id="frame1">
+            <property name="visible">True</property>
+            <property name="label_xalign">0</property>
+            <child>
+              <object class="GtkAlignment" id="alignment1">
+                <property name="visible">True</property>
+                <property name="top_padding">12</property>
+                <property name="left_padding">12</property>
+                <property name="right_padding">6</property>
+                <child>
+                  <object class="GtkTable" id="zenity_forms_table">
+                    <property name="visible">True</property>
+                    <property name="n_columns">2</property>
+                    <property name="column_spacing">10</property>
+                    <property name="row_spacing">6</property>
+                    <child>
+                      <placeholder/>
+                    </child>
+                    <child>
+                      <placeholder/>
+                    </child>
+                  </object>
+                </child>
+              </object>
+            </child>
+            <child type="label">
+              <object class="GtkLabel" id="zenity_forms_text">
+                <property name="visible">True</property>
+                <property name="label" translatable="yes">&lt;b&gt;Forms dialog&lt;/b&gt;</property>
+                <property name="use_markup">True</property>
+              </object>
+            </child>
+          </object>
+          <packing>
+            <property name="position">1</property>
+          </packing>
+        </child>
+        <child internal-child="action_area">
+          <object class="GtkHButtonBox" id="dialog-action_area12">
+            <property name="visible">True</property>
+            <property name="layout_style">end</property>
+            <child>
+              <object class="GtkButton" id="cancelbutton12">
+                <property name="label">gtk-cancel</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="use_stock">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkButton" id="okbutton12">
+                <property name="label">gtk-ok</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="use_stock">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="pack_type">end</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+    <action-widgets>
+      <action-widget response="-6">cancelbutton12</action-widget>
+      <action-widget response="-5">okbutton12</action-widget>
+    </action-widgets>
+  </object>
 </interface>



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]