r332 - in trunk: . scripts

DONOTREPLY at icculus.org DONOTREPLY at icculus.org
Mon Jul 2 03:59:00 EDT 2007


Author: icculus
Date: 2007-07-02 03:58:52 -0400 (Mon, 02 Jul 2007)
New Revision: 332

Modified:
   trunk/docs.txt
   trunk/gui.h
   trunk/gui_gtkplus2.c
   trunk/gui_macosx.c
   trunk/gui_ncurses.c
   trunk/gui_stdio.c
   trunk/gui_www.c
   trunk/lua_glue.c
   trunk/scripts/mojosetup_mainline.lua
Log:
The promptyn* GUI interfaces now take a default (yes or no), so you can make
 sure people don't just click through a EULA without consciously choosing to,
 etc.


Modified: trunk/docs.txt
===================================================================
--- trunk/docs.txt	2007-07-02 07:54:42 UTC (rev 331)
+++ trunk/docs.txt	2007-07-02 07:58:52 UTC (rev 332)
@@ -779,24 +779,30 @@
     Write debug info to the installation log, if logging settings permit.
 
 
-  MojoSetup.msgbox(str)
+  MojoSetup.msgbox(title, str)
 
     Show (str) to the user with a GUI message box, and wait until they click
-    an "OK" button.
+    an "OK" button. (title) is the message box's title.
 
 
-  MojoSetup.promptyn(str)
+  MojoSetup.promptyn(title, str, defval)
 
     Show (str) to the user with a GUI message box, and wait until they click
     either a "YES" or "NO" button. Returns true if they clicked YES, false
-    if they clicked "NO".
+    if they clicked "NO". (title) is the message box's title.
+    (defval) is an optional boolean value: whether the default action should
+    be "YES" or "NO". If (defval) isn't specified, it defaults to false.
 
 
-  MojoSetup.promptynan(str)
+  MojoSetup.promptynan(title, str, defval)
 
     Show (str) to the user with a GUI message box, and wait until they click
     either a "YES", "NO", "ALWAYS" or "NEVER" button. Returns the string
-    "yes", "no", "always", or "never".
+    "yes", "no", "always", or "never". (title) is the message box's title.
+    (defval) is an optional boolean value: whether the default action should
+    be "YES" or "NO" ... "always" and "never" can not be the default, since
+    these tend to be destructive actions that the user should consciously
+    choose to do. If (defval) isn't specified, it defaults to false.
 
 
   MojoSetup.stackwalk()

Modified: trunk/gui.h
===================================================================
--- trunk/gui.h	2007-07-02 07:54:42 UTC (rev 331)
+++ trunk/gui.h	2007-07-02 07:58:52 UTC (rev 332)
@@ -69,8 +69,8 @@
     boolean (*init)(void);
     void (*deinit)(void);
     void (*msgbox)(const char *title, const char *text);
-    boolean (*promptyn)(const char *title, const char *text);
-    MojoGuiYNAN (*promptynan)(const char *title, const char *text);
+    boolean (*promptyn)(const char *title, const char *text, boolean def);
+    MojoGuiYNAN (*promptynan)(const char *title, const char *text, boolean def);
     boolean (*start)(const char *title, const char *splash);
     void (*stop)(void);
     int (*readme)(const char *name, const uint8 *data, size_t len,
@@ -109,9 +109,10 @@
 static boolean MojoGui_##module##_init(void); \
 static void MojoGui_##module##_deinit(void); \
 static void MojoGui_##module##_msgbox(const char *title, const char *text); \
-static boolean MojoGui_##module##_promptyn(const char *t1, const char *t2); \
+static boolean MojoGui_##module##_promptyn(const char *t1, const char *t2, \
+                                           boolean d); \
 static MojoGuiYNAN MojoGui_##module##_promptynan(const char *t1, \
-                                                 const char *t2); \
+                                                 const char *t2, boolean d); \
 static boolean MojoGui_##module##_start(const char *t, const char *s); \
 static void MojoGui_##module##_stop(void); \
 static int MojoGui_##module##_readme(const char *name, const uint8 *data, \

Modified: trunk/gui_gtkplus2.c
===================================================================
--- trunk/gui_gtkplus2.c	2007-07-02 07:54:42 UTC (rev 331)
+++ trunk/gui_gtkplus2.c	2007-07-02 07:58:52 UTC (rev 332)
@@ -94,7 +94,7 @@
         // !!! FIXME: language.
         char *title = entry->xstrdup(entry->_("Stop installation"));
         char *text = entry->xstrdup(entry->_("Are you sure you want to stop installation?"));
-        if (!MojoGui_gtkplus2_promptyn(title, text))
+        if (!MojoGui_gtkplus2_promptyn(title, text, false))
             click_value = CLICK_NONE;
         free(title);
         free(text);
@@ -215,8 +215,10 @@
 } // MojoGui_gtkplus2_msgbox
 
 
-static boolean MojoGui_gtkplus2_promptyn(const char *title, const char *text)
+static boolean MojoGui_gtkplus2_promptyn(const char *title, const char *text,
+                                         boolean defval)
 {
+    // !!! FIXME: support defval.
     gint rc = do_msgbox(title, text, GTK_MESSAGE_QUESTION,
                         GTK_BUTTONS_YES_NO, NULL);
     return (rc == GTK_RESPONSE_YES);
@@ -240,8 +242,10 @@
 
 
 static MojoGuiYNAN MojoGui_gtkplus2_promptynan(const char *title,
-                                               const char *text)
+                                               const char *text,
+                                               boolean defval)
 {
+    // !!! FIXME: support defval.
     const gint rc = do_msgbox(title, text, GTK_MESSAGE_QUESTION,
                               GTK_BUTTONS_NONE, promptynanButtonCallback);
     switch (rc)

Modified: trunk/gui_macosx.c
===================================================================
--- trunk/gui_macosx.c	2007-07-02 07:54:42 UTC (rev 331)
+++ trunk/gui_macosx.c	2007-07-02 07:58:52 UTC (rev 332)
@@ -127,20 +127,22 @@
     } // if
 
     return retval;
-} // do_promptyn
+} // do_prompt
 
 
-static boolean MojoGui_macosx_promptyn(const char *title, const char *text)
+static boolean MojoGui_macosx_promptyn(const char *title, const char *text
+                                       boolean defval)
 {
-    return do_prompt(title, text, true, entry->_("Yes"), entry->_("No"));
+    return do_prompt(title, text, defval, entry->_("Yes"), entry->_("No"));
 } // MojoGui_macosx_promptyn
 
 
 static MojoGuiYNAN MojoGui_macosx_promptynan(const char *title,
-                                             const char *text)
+                                             const char *text,
+                                             boolean defval)
 {
     STUBBED("ynan");
-    return MojoGui_macosx_promptyn(title, text);  // !!! FIXME
+    return MojoGui_macosx_promptyn(title, text, defval);  // !!! FIXME
 } // MojoGui_macosx_promptynan
 
 

Modified: trunk/gui_ncurses.c
===================================================================
--- trunk/gui_ncurses.c	2007-07-02 07:54:42 UTC (rev 331)
+++ trunk/gui_ncurses.c	2007-07-02 07:58:52 UTC (rev 332)
@@ -640,13 +640,25 @@
 } // MojoGui_ncurses_msgbox
 
 
-static boolean MojoGui_ncurses_promptyn(const char *title, const char *text)
+static boolean MojoGui_ncurses_promptyn(const char *title, const char *text,
+                                        boolean defval)
 {
     char *localized_yes = entry->xstrdup(entry->_("Yes"));
     char *localized_no = entry->xstrdup(entry->_("No"));
     char *buttons[] = { localized_yes, localized_no };
     MojoBox *mojobox = makeBox(title, text, buttons, 2, false, true);
     int rc = 0;
+
+    // set the default to "no" instead of "yes"?
+    if (defval == false)
+    {
+        mojobox->hoverover = 1;
+        drawButton(mojobox, 0);
+        drawButton(mojobox, 1);
+        wrefresh(mojobox->buttons[0]);
+        wrefresh(mojobox->buttons[1]);
+    } // if
+
     while ((rc = upkeepBox(&mojobox, wgetch(mojobox->mainwin))) == -1) {}
     freeBox(mojobox, true);
     free(localized_yes);
@@ -656,7 +668,8 @@
 
 
 static MojoGuiYNAN MojoGui_ncurses_promptynan(const char *title,
-                                              const char *text)
+                                              const char *text,
+                                              boolean defval)
 {
     char *loc_yes = entry->xstrdup(entry->_("Yes"));
     char *loc_no = entry->xstrdup(entry->_("No"));
@@ -665,6 +678,17 @@
     char *buttons[] = { loc_yes, loc_always, loc_never, loc_no };
     MojoBox *mojobox = makeBox(title, text, buttons, 4, false, true);
     int rc = 0;
+
+    // set the default to "no" instead of "yes"?
+    if (defval == false)
+    {
+        mojobox->hoverover = 3;
+        drawButton(mojobox, 0);
+        drawButton(mojobox, 3);
+        wrefresh(mojobox->buttons[0]);
+        wrefresh(mojobox->buttons[3]);
+    } // if
+
     while ((rc = upkeepBox(&mojobox, wgetch(mojobox->mainwin))) == -1) {}
     freeBox(mojobox, true);
     free(loc_yes);

Modified: trunk/gui_stdio.c
===================================================================
--- trunk/gui_stdio.c	2007-07-02 07:54:42 UTC (rev 331)
+++ trunk/gui_stdio.c	2007-07-02 07:58:52 UTC (rev 332)
@@ -105,7 +105,8 @@
 } // MojoGui_stdio_msgbox
 
 
-static boolean MojoGui_stdio_promptyn(const char *title, const char *text)
+static boolean MojoGui_stdio_promptyn(const char *title, const char *text,
+                                      boolean defval)
 {
     boolean retval = false;
     if (!feof(stdin))
@@ -116,6 +117,8 @@
         char buf[128];
         while (!getout)
         {
+            // !!! FIXME:
+            // We currently ignore defval and make you type out your choice.
             printf(entry->_("%s\n[y/n]: "), text);
             fflush(stdout);
             if (read_stdin(buf, sizeof (buf)) < 0)
@@ -133,7 +136,8 @@
 } // MojoGui_stdio_promptyn
 
 
-static MojoGuiYNAN MojoGui_stdio_promptynan(const char *title, const char *txt)
+static MojoGuiYNAN MojoGui_stdio_promptynan(const char *title, const char *txt,
+                                            boolean defval)
 {
     MojoGuiYNAN retval = MOJOGUI_NO;
     if (!feof(stdin))
@@ -146,6 +150,8 @@
         char buf[128];
         while (!getout)
         {
+            // !!! FIXME:
+            // We currently ignore defval and make you type out your choice.
             printf(entry->_("%s\n[y/n/Always/Never]: "), txt);
             fflush(stdout);
             if (read_stdin(buf, sizeof (buf)) < 0)

Modified: trunk/gui_www.c
===================================================================
--- trunk/gui_www.c	2007-07-02 07:54:42 UTC (rev 331)
+++ trunk/gui_www.c	2007-07-02 07:58:52 UTC (rev 332)
@@ -742,8 +742,12 @@
 } // MojoGui_www_msgbox
 
 
-static boolean MojoGui_www_promptyn(const char *title, const char *text)
+static boolean MojoGui_www_promptyn(const char *title, const char *text,
+                                    boolean defval)
 {
+    // !!! FIXME:
+    // We currently ignore defval
+
     int i, rc;
     char *htmltext = htmlescape(text);
     const char *buttons[] = { "no", "yes" };
@@ -764,8 +768,12 @@
 } // MojoGui_www_promptyn
 
 
-static MojoGuiYNAN MojoGui_www_promptynan(const char *title, const char *text)
+static MojoGuiYNAN MojoGui_www_promptynan(const char *title, const char *text,
+                                          boolean defval)
 {
+    // !!! FIXME:
+    // We currently ignore defval
+
     int i, rc;
     char *htmltext = htmlescape(text);
     const char *buttons[] = { "no", "yes", "always", "never" };

Modified: trunk/lua_glue.c
===================================================================
--- trunk/lua_glue.c	2007-07-02 07:54:42 UTC (rev 331)
+++ trunk/lua_glue.c	2007-07-02 07:58:52 UTC (rev 332)
@@ -556,7 +556,8 @@
     {
         const char *title = luaL_checkstring(L, 1);
         const char *text = luaL_checkstring(L, 2);
-        rc = GGui->promptyn(title, text);
+        const boolean defval = lua_toboolean(L, 3);
+        rc = GGui->promptyn(title, text, defval);
     } // if
 
     return retvalBoolean(L, rc);
@@ -570,7 +571,8 @@
     {
         const char *title = luaL_checkstring(L, 1);
         const char *text = luaL_checkstring(L, 2);
-        rc = GGui->promptynan(title, text);
+        const boolean defval = lua_toboolean(L, 3);
+        rc = GGui->promptynan(title, text, defval);
     } // if
 
     // Never localize these strings!

Modified: trunk/scripts/mojosetup_mainline.lua
===================================================================
--- trunk/scripts/mojosetup_mainline.lua	2007-07-02 07:54:42 UTC (rev 331)
+++ trunk/scripts/mojosetup_mainline.lua	2007-07-02 07:58:52 UTC (rev 332)
@@ -366,7 +366,7 @@
                 if not allowoverwrite then
                     -- !!! FIXME: language and formatting.
                     MojoSetup.loginfo("File '" .. dest .. "' already exists.")
-                    local ynan = MojoSetup.promptynan(_("Conflict!"), _("File already exists! Replace?"))
+                    local ynan = MojoSetup.promptynan(_("Conflict!"), _("File already exists! Replace?"), true)
                     if ynan == "always" then
                         MojoSetup.forceoverwrite = true
                         allowoverwrite = true
@@ -656,7 +656,7 @@
             stages[#stages+1] = function (thisstage, maxstage)
                 local retval = MojoSetup.gui.readme(desc,fname,thisstage,maxstage)
                 if retval == 1 then
-                    if not MojoSetup.promptyn(desc, _("Accept this license?")) then
+                    if not MojoSetup.promptyn(desc, _("Accept this license?"), false) then
                         MojoSetup.fatal(_("You must accept the license before you may install"))
                     end
                 end




More information about the mojosetup-commits mailing list