* setup now uses "newt" instead of "curses" to draw its pretty screens.
authorArt Cancro <ajc@citadel.org>
Wed, 25 Jun 2003 15:40:57 +0000 (15:40 +0000)
committerArt Cancro <ajc@citadel.org>
Wed, 25 Jun 2003 15:40:57 +0000 (15:40 +0000)
  Changes were made to setup.c as well as all the autoconf stuff.

citadel/ChangeLog
citadel/Makefile.in
citadel/acconfig.h
citadel/configure.ac
citadel/setup.c

index 2813f2c277f68104979ce03521eb106333e5239c..a412411dc631c89080d389a5164e9696c830bac6 100644 (file)
@@ -1,4 +1,8 @@
  $Log$
+ Revision 607.7  2003/06/25 15:40:57  ajc
+ * setup now uses "newt" instead of "curses" to draw its pretty screens.
+   Changes were made to setup.c as well as all the autoconf stuff.
+
  Revision 607.6  2003/06/25 02:40:05  ajc
  * Per-user and global flags calling for validation need to be set in the
    vCard upload thingie, not in the wrapper function that emulates the
@@ -4785,3 +4789,4 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant <bryant@cs.usm.maine.edu>
 
 Fri Jul 10 1998 Art Cancro <ajc@uncensored.citadel.org>
        * Initial CVS import
+
index b04a12cba57e416f6d8696712117ec6e243f7812..fcfc6812c6567d367e52495bf26e2be01dfd93d9 100644 (file)
@@ -68,6 +68,7 @@ INSTALL_DATA=@INSTALL_DATA@
 RESOLV=@RESOLV@
 SHELL=/bin/sh
 SERVER_LDFLAGS=@SERVER_LDFLAGS@
+SETUP_LIBS=@SETUP_LIBS@
 YACC=@YACC@
 
 # End configuration section
@@ -140,7 +141,7 @@ citmail: citmail.o config.o
        $(CC) citmail.o config.o $(LDFLAGS) -o citmail $(LIBS)
 
 setup: setup.o tools.o
-       $(CC) setup.o tools.o $(LIBS) $(LDFLAGS) -o setup
+       $(CC) setup.o tools.o $(SETUP_LIBS) $(LDFLAGS) -o setup
 
 chkpwd: chkpwd.o auth.o config.o
        $(CC) chkpwd.o auth.o config.o $(LDFLAGS) -o chkpwd $(chkpwd_LIBS)
index 63e4752083b8ec2334bbf358c0377652c9f5ac74..a8a1d2b27088ab108a8076e1224126629e0b9044 100644 (file)
@@ -34,5 +34,8 @@
 /* define this if you have the libical calendaring library available */
 #undef HAVE_LIBICAL
 
+/* define this if you have the newt window library available */
+#undef HAVE_NEWT
+
 /* define this if you have the resolv.h header file. */
 #undef HAVE_RESOLV_H
index d4b29124cc5695286340c4e39a5a9450a1fc3293..c331e5a4a998f90d455ba18f4108109b68bad4b6 100644 (file)
@@ -32,6 +32,7 @@ AC_ARG_WITH(ncurses, [  --without-ncurses       don't use ncurses])
 
 AC_ARG_WITH(with_zlib, [  --with-zlib             use zlib compression if present])
 AC_ARG_WITH(with_libical, [  --with-libical          use libical calendaring library])
+AC_ARG_WITH(with_newt, [  --with-newt          use newt window library])
 
 if test "x$with_db" != xno -a "x$with_db" != xyes -a "$with_db"; then
        db_dir="$with_db"
@@ -354,6 +355,25 @@ fi
 
 
 
+
+dnl Checks for the newt window library.
+if test "x$with_newt" != xno ; then
+       AC_CHECK_HEADERS(newt.h,
+               [AC_CHECK_LIB(newt, newtInit,
+                       [ok_newt=yes],,
+       )])
+fi
+
+if test "x$ok_newt" = xyes ; then
+       SETUP_LIBS="-lnewt $SETUP_LIBS"
+       AC_DEFINE(HAVE_NEWT)
+fi
+
+
+
+
+
+
 dnl Checks for the libical calendaring library.
 if test "x$with_libical" != xno ; then
        AC_CHECK_HEADERS(ical.h,
@@ -392,6 +412,7 @@ fi
 
 
 
+
 dnl Checks for header files.
 AC_HEADER_DIRENT
 AC_HEADER_STDC
@@ -541,6 +562,7 @@ AC_SUBST(chkpwd_LIBS)
 AC_SUBST(TARGETS)
 AC_SUBST(DATABASE)
 AC_SUBST(SERVER_LDFLAGS)
+AC_SUBST(SETUP_LIBS)
 AC_CONFIG_HEADER(sysdep.h)
 AC_CONFIG_FILES([Makefile weekly])
 AC_OUTPUT
index 159a6284e2dad601c29158d93143aad04583c083..c2c789fb7349d4da349753ea89c3fd8a14374439 100644 (file)
 #include "config.h"
 #include "tools.h"
 
-#ifndef DISABLE_CURSES
-#if defined(HAVE_CURSES_H) || defined(HAVE_NCURSES_H)
-#ifdef HAVE_NCURSES_H
-#include <ncurses.h>
-#else
-#include <curses.h>
-#endif
-#endif
+#ifdef HAVE_NEWT
+#include <newt.h>
 #endif
 
+
 #define MAXSETUP 3     /* How many setup questions to ask */
 
 #define UI_TEXT                0       /* Default setup type -- text only */
-#define UI_DIALOG      1       /* Use the 'dialog' program (REMOVED) */
-#define UI_CURSES      2       /* Use curses */
 #define UI_SILENT      3       /* Silent running, for use in scripts */
+#define UI_NEWT                4       /* Use the "newt" window library */
 
 #define SERVICE_NAME   "citadel"
 #define PROTO_NAME     "tcp"
@@ -204,81 +198,15 @@ void start_the_service(void) {
 
 void cleanup(int exitcode)
 {
-#if defined(HAVE_CURSES_H) && !defined(DISABLE_CURSES)
-       if (setup_type == UI_CURSES) {
-               clear();
-               refresh();
-               endwin();
-       }
+#ifdef HAVE_NEWT
+       newtCls();
+       newtRefresh();
+       newtFinished();
 #endif
-
        exit(exitcode);
 }
 
 
-/* Gets a line from the terminal */
-/* Where on the screen to start */
-/* Pointer to string buffer */
-/* Maximum length - if negative, no-show */
-#if defined(HAVE_CURSES_H) && !defined(DISABLE_CURSES)
-void getlin(int yp, int xp, char *string, int lim) {
-       int a, b;
-       char flag;
-
-       flag = 0;
-       if (lim < 0) {
-               lim = (0 - lim);
-               flag = 1;
-       }
-       move(yp, xp);
-       standout();
-       for (a = 0; a < lim; ++a)
-               addch('-');
-       refresh();
-       move(yp, xp);
-       for (a = 0; a < lim; ++a)
-               addch(' ');
-       move(yp, xp);
-       printw("%s", string);
-      GLA:move(yp, xp + strlen(string));
-       refresh();
-       a = getch();
-       if (a == 127)
-               a = 8;
-       a = (a & 127);
-       if (a == 10)
-               a = 13;
-       if ((a == 8) && (strlen(string) == 0))
-               goto GLA;
-       if ((a != 13) && (a != 8) && (strlen(string) == lim))
-               goto GLA;
-       if ((a == 8) && (string[0] != 0)) {
-               string[strlen(string) - 1] = 0;
-               move(yp, xp + strlen(string));
-               addch(' ');
-               goto GLA;
-       }
-       if ((a == 13) || (a == 10)) {
-               standend();
-               move(yp, xp);
-               for (a = 0; a < lim; ++a)
-                       addch(' ');
-               mvprintw(yp, xp, "%s", string);
-               refresh();
-               return;
-       }
-       b = strlen(string);
-       string[b] = a;
-       string[b + 1] = 0;
-       if (flag == 0)
-               addch(a);
-       if (flag == 1)
-               addch('*');
-       goto GLA;
-}
-#endif
-
-
 
 void title(char *text)
 {
@@ -288,35 +216,25 @@ void title(char *text)
 }
 
 
-void hit_any_key(void)
-{
-       char junk[5];
-
-#if defined(HAVE_CURSES_H) && !defined(DISABLE_CURSES)
-       if (setup_type == UI_CURSES) {
-               mvprintw(20, 0, "Press any key to continue... ");
-               refresh();
-               getch();
-               return;
-       }
-#endif
-       if (setup_type == UI_TEXT) {
-               printf("Press return to continue...");
-               fgets(junk, 5, stdin);
-       }
-}
 
 int yesno(char *question)
 {
+#ifdef HAVE_NEWT
+       newtComponent form = NULL;
+       newtComponent yesbutton = NULL;
+       newtComponent nobutton = NULL;
+#endif
+
        int answer = 0;
-       char buf[4096];
+       int i = 0;
+       char buf[SIZ];
 
        switch (setup_type) {
 
        case UI_TEXT:
                do {
                        printf("%s\nYes/No --> ", question);
-                       fgets(buf, 4096, stdin);
+                       fgets(buf, sizeof buf, stdin);
                        answer = tolower(buf[0]);
                        if (answer == 'y')
                                answer = 1;
@@ -325,24 +243,27 @@ int yesno(char *question)
                } while ((answer < 0) || (answer > 1));
                break;
 
-#if defined(HAVE_CURSES_H) && !defined(DISABLE_CURSES)
-       case UI_CURSES:
-               do {
-                       clear();
-                       standout();
-                       mvprintw(1, 20, "Question");
-                       standend();
-                       mvprintw(10, 0, "%-80s", question);
-                       mvprintw(20, 0, "%80s", "");
-                       mvprintw(20, 0, "Yes/No -> ");
-                       refresh();
-                       answer = getch();
-                       answer = tolower(answer);
-                       if (answer == 'y')
-                               answer = 1;
-                       else if (answer == 'n')
-                               answer = 0;
-               } while ((answer < 0) || (answer > 1));
+#ifdef HAVE_NEWT
+       case UI_NEWT:
+               newtCenteredWindow(76, 10, "Question");
+               form = newtForm(NULL, NULL, 0);
+               for (i=0; i<num_tokens(question, '\n'); ++i) {
+                       extract_token(buf, question, i, '\n');
+                       newtFormAddComponent(form, newtLabel(1, 1+i, buf));
+               }
+               yesbutton = newtButton(10, 5, "Yes");
+               nobutton = newtButton(60, 5, "No");
+               newtFormAddComponent(form, yesbutton);
+               newtFormAddComponent(form, nobutton);
+               if (newtRunForm(form) == yesbutton) {
+                       answer = 1;
+               }
+               else {
+                       answer = 0;
+               }
+               newtPopWindow();
+               newtFormDestroy(form);  
+
                break;
 #endif
 
@@ -353,26 +274,33 @@ int yesno(char *question)
 
 void important_message(char *title, char *msgtext)
 {
+#ifdef HAVE_NEWT
+       newtComponent form = NULL;
+#endif
+       char buf[SIZ];
+       int i = 0;
 
        switch (setup_type) {
 
        case UI_TEXT:
                printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
                printf("       %s \n\n%s\n\n", title, msgtext);
-               hit_any_key();
+               printf("Press return to continue...");
+               fgets(buf, sizeof buf, stdin);
                break;
 
-#if defined(HAVE_CURSES_H) && !defined(DISABLE_CURSES)
-       case UI_CURSES:
-               clear();
-               move(1, 20);
-               standout();
-               printw("  Important Message  ");
-               standend();
-               move(3, 0);
-               printw("%s", msgtext);
-               refresh();
-               hit_any_key();
+#ifdef HAVE_NEWT
+       case UI_NEWT:
+               newtCenteredWindow(76, 10, title);
+               form = newtForm(NULL, NULL, 0);
+               for (i=0; i<num_tokens(msgtext, '\n'); ++i) {
+                       extract_token(buf, msgtext, i, '\n');
+                       newtFormAddComponent(form, newtLabel(1, 1+i, buf));
+               }
+               newtFormAddComponent(form, newtButton(35, 5, "OK"));
+               newtRunForm(form);
+               newtPopWindow();
+               newtFormDestroy(form);  
                break;
 #endif
 
@@ -391,8 +319,18 @@ void display_error(char *error_message)
 
 void progress(char *text, long int curr, long int cmax)
 {
-       static long dots_printed;
-       long a;
+#ifdef HAVE_NEWT
+
+       /* These variables are static because progress() gets called
+        * multiple times during the course of whatever operation is
+        * being performed.  This makes setup non-threadsafe, but who
+        * cares?
+        */
+       static newtComponent form = NULL;
+       static newtComponent scale = NULL;
+#endif
+       static long dots_printed = 0L;
+       long a = 0;
 
        switch (setup_type) {
 
@@ -418,32 +356,24 @@ void progress(char *text, long int curr, long int cmax)
                }
                break;
 
-#if defined(HAVE_CURSES_H) && !defined(DISABLE_CURSES)
-       case UI_CURSES:
+#ifdef HAVE_NEWT
+       case UI_NEWT:
                if (curr == 0) {
-                       clear();
-                       move(5, 20);
-                       printw("%s\n", text);
-                       move(10, 1);
-                       printf("..........................");
-                       printf("..........................");
-                       printf("..........................\r");
-                       refresh();
-                       dots_printed = 0;
-               } else if (curr == cmax) {
-                       clear();
-                       refresh();
-               } else {
-                       a = (curr * 100) / cmax;
-                       a = a * 78;
-                       a = a / 100;
-                       move(10, 1);
-                       dots_printed = 0;
-                       while (dots_printed < a) {
-                               printw("*");
-                               ++dots_printed;
-                       }
-                       refresh();
+                       newtCenteredWindow(76, 8, text);
+                       form = newtForm(NULL, NULL, 0);
+                       scale = newtScale(1, 3, 74, cmax);
+                       newtFormAddComponent(form, scale);
+                       newtDrawForm(form);
+                       newtRefresh();
+               }
+               if ((curr > 0) && (curr <= cmax)) {
+                       newtScaleSet(scale, curr);
+                       newtRefresh();
+               }
+               if (curr == cmax) {
+                       newtFormDestroy(form);  
+                       newtPopWindow();
+                       newtRefresh();
                }
                break;
 #endif
@@ -543,9 +473,14 @@ void check_inittab_entry(void)
 
 void set_str_val(int msgpos, char str[])
 {
-       char buf[4096];
+#ifdef HAVE_NEWT
+       newtComponent form;
+       char *result;
+#endif
+       char buf[SIZ];
        char tempfile[PATH_MAX];
        char setupmsg[SIZ];
+       int i;
 
        strcpy(tempfile, tmpnam(NULL));
        strcpy(setupmsg, "");
@@ -556,23 +491,28 @@ void set_str_val(int msgpos, char str[])
                printf("\n%s\n", setup_text[msgpos]);
                printf("This is currently set to:\n%s\n", str);
                printf("Enter new value or press return to leave unchanged:\n");
-               fgets(buf, 4096, stdin);
+               fgets(buf, sizeof buf, stdin);
                buf[strlen(buf) - 1] = 0;
                if (strlen(buf) != 0)
                        strcpy(str, buf);
                break;
-#if defined(HAVE_CURSES_H) && !defined(DISABLE_CURSES)
-       case UI_CURSES:
-               clear();
-               move(1, ((80 - strlen(setup_titles[msgpos])) / 2));
-               standout();
-               printw("%s", setup_titles[msgpos]);
-               standend();
-               move(3, 0);
-               printw("%s", setup_text[msgpos]);
-               refresh();
-               getlin(20, 0, str, 80);
-               break;
+#ifdef HAVE_NEWT
+       case UI_NEWT:
+
+               newtCenteredWindow(76, 10, setup_titles[msgpos]);
+               form = newtForm(NULL, NULL, 0);
+               for (i=0; i<num_tokens(setup_text[msgpos], '\n'); ++i) {
+                       extract_token(buf, setup_text[msgpos], i, '\n');
+                       newtFormAddComponent(form, newtLabel(1, 1+i, buf));
+               }
+               newtFormAddComponent(form, newtEntry(1, 8, str, 74, &result,
+                                       NEWT_FLAG_RETURNEXIT));
+               newtRunForm(form);
+               strcpy(str, result);
+
+               newtPopWindow();
+               newtFormDestroy(form);  
+
 #endif
        }
 }
@@ -678,8 +618,11 @@ void write_config_to_disk(void)
 int discover_ui(void)
 {
 
-#if defined(HAVE_CURSES_H) && !defined(DISABLE_CURSES)
-       return UI_CURSES;
+#ifdef HAVE_NEWT
+       newtInit();
+       newtCls();
+       newtDrawRootText(0, 0, "Citadel/UX Setup");
+       return UI_NEWT;
 #endif
        return UI_TEXT;
 }
@@ -726,14 +669,6 @@ int main(int argc, char *argv[])
        if (setup_type < 0) {
                setup_type = discover_ui();
        }
-#if defined(HAVE_CURSES_H) && !defined(DISABLE_CURSES)
-       if (setup_type == UI_CURSES) {
-               initscr();
-               raw();
-               noecho();
-       }
-#endif
-
        if (info_only == 1) {
                important_message("Citadel/UX Setup", CITADEL);
                cleanup(0);