grub2: bring back build of aros-side grub2 tools
[AROS.git] / workbench / utilities / Installer / gui_zune.c
blob270602f846549703a4ac52dc39ef28020ae99199
1 /*
2 Copyright © 1995-2003, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 /* gui_zune.c -- here are all functions for the ZUNE gui */
8 #include "Installer.h"
9 #include "cleanup.h"
10 #include "execute.h"
11 #include "locale.h"
12 #include "texts.h"
13 #include "misc.h"
14 #include "gui.h"
15 #include "variables.h"
17 /* External variables */
18 extern BPTR inputfile;
19 extern char buffer[MAXARGSIZE];
20 extern char *filename;
21 extern InstallerPrefs preferences;
22 extern int error, grace_exit;
23 extern int doing_abort;
25 #include <exec/types.h>
26 #include <stdlib.h>
27 #include <stdio.h>
28 #include <string.h>
30 #include <proto/intuition.h>
31 #include <proto/muimaster.h>
32 #include <libraries/mui.h>
33 #ifdef __AROS__
34 #include <libraries/coolimages.h>
35 #else
36 #define HBar(x) MUI_MakeObject(MUIO_HBar,x)
37 #define CoolImageIDButton(label,imageid) SimpleButton(label)
38 #endif
40 Object *app;
41 Object *wnd;
42 Object *reqwnd, *helpwnd, *helptext;
43 Object *reqroot, *root;
44 Object *btproceed, *btabort, *btskip, *bthelp;
45 Object *intermediate = NULL;
47 enum
49 Push_NULL,
50 Push_Proceed,
51 Push_Abort,
52 Push_Skip,
53 Push_Help,
54 Push_About,
55 Push_Ok,
56 Push_Cancel,
57 Push_Last
61 /* ######################################################################## */
63 void AddContents(Object *obj)
65 DoMethod(root, MUIM_Group_InitChange);
66 if (intermediate != NULL)
68 DoMethod(root, OM_REMMEMBER, (IPTR)intermediate);
69 MUI_DisposeObject(intermediate);
70 intermediate = NULL;
72 DoMethod(root, OM_ADDMEMBER, (IPTR)obj);
73 DoMethod(root, MUIM_Group_ExitChange);
75 void DelContents(Object *obj)
77 DoMethod(root, MUIM_Group_InitChange);
78 DoMethod(root, OM_REMMEMBER, (IPTR)obj);
79 DoMethod(root, MUIM_Group_ExitChange);
80 MUI_DisposeObject(obj);
83 #define WaitCTRL(sigs) \
84 if (sigs) \
85 { \
86 sigs = Wait(sigs | SIGBREAKF_CTRL_C | SIGBREAKF_CTRL_D); \
87 if (sigs & SIGBREAKF_CTRL_C) break; \
88 if (sigs & SIGBREAKF_CTRL_D) break; \
91 #define disable_abort(val) set(btabort, MUIA_Disabled, val)
92 #define disable_skip(val) set(btskip, MUIA_Disabled, val)
93 #define disable_help(val) set(bthelp, MUIA_Disabled, val)
95 #define NeedPROMPT(pl) \
96 if ( GetPL(pl, _PROMPT).intval == 0 ) \
97 { \
98 error = SCRIPTERROR; \
99 traperr("Missing prompt!\n", NULL); \
102 #define NeedHELP(pl) \
103 if ( GetPL(pl, _HELP).intval == 0 ) \
105 error = SCRIPTERROR; \
106 traperr("Missing help!\n", NULL); \
109 #define TRANSSCRIPT() \
110 if ( preferences.transcriptstream != BNULL ) \
112 int len = 0; \
113 char *out; \
114 int m = GetPL(pl, _PROMPT).intval; \
115 for ( i = 0 ; i < m ; i ++ ) \
117 len += strlen(GetPL(pl, _PROMPT).arg[i]) + 2; \
119 out = malloc((len+2)*sizeof(char)); \
120 outofmem(out); \
121 out[0] = 0; \
122 for ( i = 0 ; i < m ; i ++ ) \
124 strcat(out,">"); \
125 strcat(out,GetPL(pl, _PROMPT).arg[i]); \
126 strcat(out,"\n"); \
128 Write(preferences.transcriptstream, out, len); \
129 free(out); \
133 * Ask user if he really wants to abort
135 void abort_install()
137 BOOL running = TRUE, quit = FALSE;
138 LONG sigs = 0;
139 Object *wc;
140 Object *btok, *btcancel;
142 wc = VGroup,
143 Child, TextObject,
144 GroupFrameT(_(MSG_MESSAGE)),
145 MUIA_Text_Contents, (IPTR)ASKQUIT_STRING,
146 End,
147 Child, HBar(TRUE),
148 Child, HGroup,
149 MUIA_Group_SameSize, TRUE,
150 Child, btok = CoolImageIDButton(_(MSG_OK), COOL_USEIMAGE_ID),
151 Child, btcancel = CoolImageIDButton(_(MSG_CANCEL), COOL_CANCELIMAGE_ID),
152 End,
153 End;
154 set(btok,MUIA_CycleChain,1);
155 set(btcancel,MUIA_CycleChain,1);
156 DoMethod(btok, MUIM_Notify, MUIA_Pressed, FALSE,(IPTR)app, 2, MUIM_Application_ReturnID, Push_Ok);
157 DoMethod(btcancel, MUIM_Notify, MUIA_Pressed, FALSE,(IPTR)app, 2, MUIM_Application_ReturnID, Push_Cancel);
158 DoMethod(reqroot, OM_ADDMEMBER, (IPTR)wc);
160 set(reqwnd, MUIA_Window_Open, TRUE);
161 while (running)
163 switch (DoMethod(app,MUIM_Application_NewInput,(IPTR)&sigs))
165 case Push_Cancel:
166 running = FALSE;
167 break;
168 case Push_Ok:
169 quit = TRUE;
170 running = FALSE;
171 break;
172 default:
173 break;
175 WaitCTRL(sigs);
177 set(reqwnd, MUIA_Window_Open, FALSE);
179 DoMethod(reqroot, OM_REMMEMBER, (IPTR)wc);
180 MUI_DisposeObject(wc);
182 if (quit)
184 error = USERABORT;
185 grace_exit = TRUE;
186 /* Execute trap(1) */
187 traperr( "User aborted!\n", NULL );
192 /* ######################################################################## */
195 const char GuiWinTitle[] ="AROS - Installer V43.3";
198 #define WINDOWWIDTH 400
199 #define WINDOWHEIGHT 300
201 void helpwin(char *title, char *text)
203 BOOL running = TRUE;
204 LONG sigs = 0;
206 set(helptext, MUIA_Text_Contents, text);
207 set(helpwnd, MUIA_Window_Title, title);
208 set(helpwnd, MUIA_Window_Open, TRUE);
209 while (running)
211 switch (DoMethod(app,MUIM_Application_NewInput,(IPTR)&sigs))
213 case MUIV_Application_ReturnID_Quit:
214 running = FALSE;
215 break;
216 default:
217 break;
219 WaitCTRL(sigs);
221 set(helpwnd, MUIA_Window_Open, FALSE);
225 void helpwinpl(char *title, struct ParameterList *pl, int what)
227 char *text;
229 text = collatestrings(GetPL(pl, what).intval, GetPL(pl, what).arg);
230 if ( text != NULL )
232 helpwin(title, text);
233 free(text);
239 * Initialize the GUI
241 void init_gui()
243 struct Screen *scr;
245 scr = LockPubScreen(NULL);
247 app = ApplicationObject,
248 MUIA_Application_Title, "AROS - Installer",
249 MUIA_Application_DoubleStart, TRUE,
251 SubWindow, wnd = WindowObject,
252 MUIA_Window_Title, GuiWinTitle,
253 MUIA_Window_Width, WINDOWWIDTH,
254 MUIA_Window_Height, WINDOWHEIGHT,
255 MUIA_Window_CloseGadget, FALSE,
256 MUIA_Window_NoMenus, TRUE,
257 MUIA_Window_ID, MAKE_ID('A','I','N','S'),
258 WindowContents, VGroup,
259 Child, root = VGroup, End,
260 Child, HBar(TRUE),
261 Child, HGroup,
262 MUIA_Group_SameSize, TRUE,
263 Child, btproceed = CoolImageIDButton("Proceed", COOL_USEIMAGE_ID),
264 Child, btabort = CoolImageIDButton("Abort", COOL_CANCELIMAGE_ID),
265 Child, btskip = CoolImageIDButton("Skip", COOL_WARNIMAGE_ID),
266 Child, bthelp = CoolImageIDButton("Help", COOL_INFOIMAGE_ID),
267 End,
268 End,
269 End,
270 SubWindow, helpwnd = WindowObject,
271 MUIA_Window_Width, WINDOWWIDTH,
272 MUIA_Window_Height, WINDOWHEIGHT,
273 MUIA_Window_CloseGadget, TRUE,
274 MUIA_Window_SizeGadget, FALSE,
275 MUIA_Window_NoMenus, TRUE,
276 WindowContents, VGroup,
277 Child, helptext = TextObject,
278 GroupFrame,
279 MUIA_Background, MUII_GroupBack,
280 MUIA_Text_Contents, (IPTR)NULL,
281 End,
282 Child, VSpace(1),
283 End,
284 End,
285 SubWindow, reqwnd = WindowObject,
286 MUIA_Window_Width, WINDOWWIDTH,
287 MUIA_Window_Height, WINDOWHEIGHT,
288 MUIA_Window_CloseGadget, FALSE,
289 MUIA_Window_SizeGadget, FALSE,
290 MUIA_Window_NoMenus, TRUE,
291 WindowContents, VGroup,
292 Child, reqroot = VGroup, End,
293 End,
294 End,
295 End;
296 if (app == NULL)
298 /* failed to initialize GUI */
299 #if DEBUG
300 printf("Failed to intialize Zune GUI\n");
301 #endif
302 exit(-1);
304 set(btproceed,MUIA_CycleChain,1);
305 set(btabort,MUIA_CycleChain,1);
306 set(btskip,MUIA_CycleChain,1);
307 set(bthelp,MUIA_CycleChain,1);
308 DoMethod(helpwnd, MUIM_Notify, MUIA_Window_CloseRequest, TRUE, (IPTR)app, 2,
309 MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);
311 DoMethod(btproceed, MUIM_Notify, MUIA_Pressed, FALSE,(IPTR)app, 2,
312 MUIM_Application_ReturnID, Push_Proceed);
313 DoMethod(btabort, MUIM_Notify, MUIA_Pressed, FALSE,(IPTR)app, 2,
314 MUIM_Application_ReturnID, Push_Abort);
315 DoMethod(btskip, MUIM_Notify, MUIA_Pressed, FALSE,(IPTR)app, 2,
316 MUIM_Application_ReturnID, Push_Skip);
317 DoMethod(bthelp, MUIM_Notify, MUIA_Pressed, FALSE,(IPTR)app, 2,
318 MUIM_Application_ReturnID, Push_Help);
319 set(wnd, MUIA_Window_Open, TRUE);
320 UnlockPubScreen(NULL, scr);
324 * Close GUI
326 void deinit_gui()
328 set(wnd, MUIA_Window_Open, FALSE);
329 MUI_DisposeObject(app);
334 * Show user that we are going to "(abort)" install
335 * Don't confuse NOVICE...
337 void show_abort(char *msg)
339 BOOL running = TRUE;
340 ULONG sigs = 0;
341 Object *wc;
343 if ( get_var_int("@user-level") > _NOVICE )
345 disable_abort(TRUE);
346 disable_skip(TRUE);
347 disable_help(TRUE);
349 wc = VGroup,
350 Child, TextObject,
351 GroupFrameT("Aborting Installation:"),
352 MUIA_Text_Contents, (IPTR)(msg),
353 End,
354 End;
356 if (wc)
358 AddContents(wc);
360 while (running)
362 switch (DoMethod(app,MUIM_Application_NewInput,(IPTR)&sigs))
364 case Push_Proceed:
365 running = FALSE;
366 break;
367 default:
368 break;
370 WaitCTRL(sigs);
373 DelContents(wc);
376 disable_abort(FALSE);
377 disable_skip(FALSE);
378 disable_help(FALSE);
385 * Show user how much we have completed yet
387 void show_complete(long int percent)
389 char *text;
391 text = malloc(strlen(GuiWinTitle) + 13);
392 if ( text == NULL )
394 end_alloc();
396 sprintf(text, "%s (Done %3ld%%)", GuiWinTitle, percent);
397 set(wnd, MUIA_Window_Title, text);
398 free(text);
403 * Show user that we "(exit)" the installation
405 void show_exit(char *msg)
407 BOOL running = TRUE;
408 ULONG sigs = 0;
409 Object *wc;
410 char *msg2;
412 msg2 = malloc((strlen(msg)+strlen(DONE_TEXT))*sizeof(char));
413 msg2[0] = 0;
414 strcat(msg2,msg);
415 strcat(msg2,DONE_TEXT);
416 disable_abort(TRUE);
417 disable_skip(TRUE);
418 disable_help(TRUE);
420 wc = VGroup,
421 Child, TextObject,
422 GroupFrameT("Aborting Installation:"),
423 MUIA_Text_Contents, (IPTR)(msg2),
424 End,
425 End;
427 if (wc)
429 AddContents(wc);
431 while (running)
433 switch (DoMethod(app,MUIM_Application_NewInput,(IPTR)&sigs))
435 case Push_Proceed:
436 running = FALSE;
437 break;
438 default:
439 break;
441 WaitCTRL(sigs);
444 DelContents(wc);
447 disable_abort(FALSE);
448 disable_skip(FALSE);
449 disable_help(FALSE);
454 * Show the line which caused the parse-error
456 void show_parseerror(char * msg, int errline)
462 * Tell user that some big task is to be done
463 * "Be patient..."
465 void show_working(char *msg)
467 if (intermediate != NULL)
469 DelContents(intermediate);
472 intermediate = VGroup,
473 Child, TextObject,
474 GroupFrameT(_(MSG_MESSAGE)),
475 MUIA_Text_Contents, (IPTR)(msg),
476 End,
477 End;
479 if (intermediate)
481 DoMethod(root, MUIM_Group_InitChange);
482 DoMethod(root, OM_ADDMEMBER, (IPTR)intermediate);
483 DoMethod(root, MUIM_Group_ExitChange);
489 * Display a "(message)" to the user
490 * Don't confuse NOVICE unless "(all)" users want to get this info
492 void show_message(char * msg, struct ParameterList * pl)
494 BOOL running = TRUE;
495 ULONG sigs = 0;
496 Object *wc;
498 if ( GetPL(pl, _ALL).used == 1 || get_var_int("@user-level") > _NOVICE )
500 disable_skip(TRUE);
501 if ( GetPL(pl, _HELP).used != 1 )
503 disable_help(TRUE);
506 wc = VGroup,
507 Child, TextObject,
508 GroupFrameT(_(MSG_MESSAGE)),
509 MUIA_Text_Contents, (IPTR)(msg),
510 End,
511 End;
513 if (wc)
515 AddContents(wc);
517 while (running)
519 switch (DoMethod(app,MUIM_Application_NewInput,(IPTR)&sigs))
521 case Push_Abort:
522 abort_install();
523 break;
524 case Push_Proceed:
525 running = FALSE;
526 break;
527 case Push_Help:
528 helpwinpl(HELP_ON_MESSAGE, pl, _HELP);
529 break;
530 default:
531 break;
533 WaitCTRL(sigs);
536 DelContents(wc);
539 disable_skip(FALSE);
540 disable_help(FALSE);
546 * Ask user for his user-level
548 void request_userlevel(char *msg)
550 BOOL running = TRUE;
551 ULONG sigs = 0;
552 Object *wc;
553 Object *btabout;
555 LONG usrlevel, logval;
556 char *welcome;
558 Object *levelmx;
559 char **mxlabels;
561 /* Ask for User Level */
562 usrlevel = preferences.defusrlevel;
563 disable_skip(TRUE);
565 if ( msg != NULL )
567 welcome = strdup(msg);
569 else
571 welcome = malloc(sizeof(char *)*(strlen(WELCOME_TEMPLATE)+strlen(get_var_arg("@app-name"))));
572 outofmem(welcome);
573 sprintf(welcome, WELCOME_TEMPLATE, get_var_arg("@app-name"));
575 mxlabels = malloc(4*sizeof(STRPTR));
576 mxlabels[0] = strdup(NOVICE_NAME);
577 mxlabels[1] = strdup(ADVANCED_NAME);
578 mxlabels[2] = strdup(EXPERT_NAME);
579 mxlabels[3] = NULL;
582 wc = VGroup,
583 Child, VGroup, GroupFrame,
584 Child, TextObject,
585 GroupFrame,
586 MUIA_Background, MUII_GroupBack,
587 MUIA_Text_Contents, (IPTR)(welcome),
588 End,
589 Child, levelmx = RadioObject,
590 GroupFrameT(USERLEVEL_REQUEST),
591 MUIA_Radio_Entries, (IPTR)(mxlabels),
592 End,
593 Child, btabout = CoolImageIDButton("About Installer" ,COOL_ASKIMAGE_ID),
594 End,
595 End;
597 if (wc)
599 set(levelmx, MUIA_Radio_Active, usrlevel);
600 DoMethod(btabout, MUIM_Notify, MUIA_Pressed, FALSE,(IPTR)app, 2, MUIM_Application_ReturnID, Push_About);
601 AddContents(wc);
603 while (running)
605 switch (DoMethod(app,MUIM_Application_NewInput,(IPTR)&sigs))
607 case Push_Abort:
608 abort_install();
609 break;
610 case Push_Proceed:
611 running = FALSE;
612 break;
613 case Push_Help:
614 helpwin(HELP_ON_USERLEVEL, USERLEVEL_HELP);
615 break;
616 case Push_About:
618 char *helptext;
620 /* TODO: help/about for Installer */
621 helptext = malloc(512 * sizeof(char));
622 sprintf(helptext, ABOUT_INSTALLER, INSTALLER_VERSION, INSTALLER_REVISION);
623 helpwin(ABOUT_ON_INSTALLER, helptext);
624 free(helptext);
626 break;
627 default:
628 break;
630 WaitCTRL(sigs);
632 GetAttr(MUIA_Radio_Active, levelmx, (IPTR *)&usrlevel);
633 set_variable("@user-level", NULL, usrlevel);
635 DelContents(wc);
637 free(welcome);
638 free(mxlabels[0]);
639 free(mxlabels[1]);
640 free(mxlabels[2]);
642 /* Ask for Logfile creation */
643 if ( usrlevel > 0 )
645 mxlabels[0] = strdup(LOG_FILE_TEXT);
646 mxlabels[1] = strdup(LOG_PRINT_TEXT);
647 mxlabels[2] = strdup(LOG_NOLOG_TEXT);
649 wc = VGroup,
650 Child, levelmx = RadioObject,
651 GroupFrameT(LOG_QUESTION),
652 MUIA_Radio_Entries, (IPTR)(mxlabels),
653 End,
654 End;
656 if (wc)
658 AddContents(wc);
660 running = TRUE;
661 while (running)
663 switch (DoMethod(app,MUIM_Application_NewInput,(IPTR)&sigs))
665 case Push_Abort:
666 abort_install();
667 break;
668 case Push_Proceed:
669 running = FALSE;
670 break;
671 case Push_Help:
673 char *helptext;
675 /* TODO: help for logfile-requester */
676 helptext = malloc(512 * sizeof(char));
677 sprintf(helptext, LOG_HELP, preferences.transcriptfile);
678 helpwin(HELP_ON_LOGFILES, helptext);
679 free(helptext);
681 break;
682 default:
683 break;
685 WaitCTRL(sigs);
687 GetAttr(MUIA_Radio_Active, levelmx, (IPTR *)&logval);
688 switch (logval)
690 case 0: /* Log to file */
691 /* TODO: Handle Logging output selection */
692 break;
693 case 1: /* Log to printer */
694 free(preferences.transcriptfile);
695 preferences.transcriptfile = strdup("PRT:");
696 break;
697 case 2: /* No Log */
698 free(preferences.transcriptfile);
699 preferences.transcriptfile = NULL;
700 break;
703 DelContents(wc);
705 free(mxlabels[0]);
706 free(mxlabels[1]);
707 free(mxlabels[2]);
709 if (!preferences.nopretend)
711 mxlabels[0] = strdup(NOPRETEND_TEXT);
712 mxlabels[1] = strdup(PRETEND_TEXT);
713 mxlabels[2] = NULL;
715 wc = VGroup,
716 Child, levelmx = RadioObject,
717 GroupFrameT(PRETEND_QUESTION),
718 MUIA_Radio_Entries, (IPTR)(mxlabels),
719 End,
720 End;
722 if (wc)
724 AddContents(wc);
726 running = TRUE;
727 while (running)
729 switch (DoMethod(app,MUIM_Application_NewInput,(IPTR)&sigs))
731 case Push_Abort:
732 abort_install();
733 break;
734 case Push_Proceed:
735 running = FALSE;
736 break;
737 case Push_Help:
738 helpwin(HELP_ON_PRETEND, PRETEND_HELP);
739 break;
740 default:
741 break;
743 WaitCTRL(sigs);
745 GetAttr(MUIA_Radio_Active, levelmx, (IPTR *)&logval);
746 switch (logval)
748 case 0: /* Really Install */
749 preferences.pretend = FALSE;
750 break;
751 case 1: /* Only pretend to install */
752 preferences.pretend = TRUE;
753 break;
756 DelContents(wc);
759 free(mxlabels[0]);
760 free(mxlabels[1]);
764 free(mxlabels);
765 disable_skip(FALSE);
770 * Ask user for a boolean
772 long int request_bool(struct ParameterList *pl)
774 long int retval;
775 char **mxlabels;
776 int i, m;
778 NeedPROMPT(pl);
779 NeedHELP(pl);
781 m = GetPL(pl, _PROMPT).intval;
783 retval = ( GetPL(pl, _DEFAULT).intval != 0 );
785 mxlabels = malloc(3*sizeof(STRPTR));
786 outofmem(mxlabels);
787 if ( GetPL(pl, _CHOICES).used == 1 )
789 if (GetPL(pl, _CHOICES).intval >= 2)
791 mxlabels[0] = strdup(GetPL(pl, _CHOICES).arg[0]);
792 mxlabels[1] = strdup(GetPL(pl, _CHOICES).arg[1]);
794 else if (GetPL(pl, _CHOICES).intval == 1)
796 mxlabels[0] = strdup(GetPL(pl, _CHOICES).arg[0]);
797 mxlabels[1] = strdup(_(MSG_NO));
799 else
801 mxlabels[0] = strdup(_(MSG_YES));
802 mxlabels[1] = strdup(_(MSG_NO));
805 else
807 mxlabels[0] = strdup(_(MSG_YES));
808 mxlabels[1] = strdup(_(MSG_NO));
810 mxlabels[2] = NULL;
812 TRANSSCRIPT();
814 if ( get_var_int("@user-level") > _NOVICE )
816 char *out;
817 BOOL running = TRUE;
818 Object *levelmx, *wc;
819 ULONG sigs = 0;
821 disable_skip(TRUE);
822 out = collatestrings(m, GetPL(pl, _PROMPT).arg);
824 wc = VGroup,
825 Child, VGroup, GroupFrame,
826 MUIA_Background, MUII_GroupBack,
827 Child, TextObject,
828 MUIA_Text_Contents, (IPTR)(out),
829 End,
830 Child, levelmx = RadioObject,
831 MUIA_Radio_Entries, (IPTR)(mxlabels),
832 End,
833 End,
834 End;
836 if (wc)
838 AddContents(wc);
840 while (running)
842 switch (DoMethod(app,MUIM_Application_NewInput,(IPTR)&sigs))
844 case Push_Abort:
845 abort_install();
846 break;
847 case Push_Proceed:
848 running = FALSE;
849 break;
850 case Push_Help:
851 if (GetPL(pl, _HELP).intval)
853 helpwinpl(HELP_ON_ASKNUMBER, pl, _HELP);
855 else
857 helpwin(HELP_ON_ASKNUMBER, get_var_arg("@asknumber-help"));
859 break;
860 default:
861 break;
863 WaitCTRL(sigs);
865 GetAttr(MUIA_Radio_Active, levelmx, &retval);
867 DelContents(wc);
869 free(out);
870 disable_skip(FALSE);
872 if ( preferences.transcriptstream != BNULL )
874 Write(preferences.transcriptstream, "Ask Question: Result was \"", 26);
875 Write(preferences.transcriptstream, mxlabels[retval], strlen(mxlabels[retval]));
876 Write(preferences.transcriptstream, "\".\n\n", 4);
878 free(mxlabels[0]);
879 free(mxlabels[1]);
880 free(mxlabels);
882 return retval;
887 * Ask user for a number
889 long int request_number(struct ParameterList *pl)
891 long int retval;
892 long int i, min, max;
893 char minmax[MAXARGSIZE];
895 retval = GetPL( pl, _DEFAULT ).intval;
896 if ( GetPL( pl, _RANGE ).used == 1 )
898 min = GetPL( pl, _RANGE ).intval;
899 max = GetPL( pl, _RANGE ).intval2;
900 /* Wrong order ? Change order */
901 if ( max < min )
903 i = min;
904 min = max;
905 max = i;
907 sprintf(minmax, "Range = [%ld, %ld]", min, max);
909 else
911 minmax[0] = 0;
912 #define INTMAX 32767
913 max = INTMAX;
914 min = ( retval < 0 ) ? retval : 0;
918 TRANSSCRIPT();
919 if ( get_var_int( "@user-level" ) > _NOVICE )
921 char *out;
922 BOOL running = TRUE;
923 Object *st, *wc;
924 ULONG sigs = 0;
926 disable_skip(TRUE);
927 out = collatestrings(GetPL(pl, _PROMPT).intval, GetPL(pl, _PROMPT).arg);
929 wc = VGroup,
930 Child, VGroup, GroupFrame,
931 MUIA_Background, MUII_GroupBack,
932 Child, TextObject,
933 MUIA_Text_Contents, (IPTR)(out),
934 End,
935 Child, st = StringObject,
936 StringFrame,
937 MUIA_String_Accept, (IPTR)"-0123456789",
938 MUIA_String_Integer, retval,
939 MUIA_String_AdvanceOnCR,TRUE,
940 MUIA_CycleChain, TRUE,
941 End,
942 Child, TextObject,
943 MUIA_Text_Contents, (IPTR)(minmax),
944 End,
945 End,
946 End;
948 if (wc)
950 AddContents(wc);
952 while (running)
954 switch (DoMethod(app,MUIM_Application_NewInput,(IPTR)&sigs))
956 case Push_Abort:
957 abort_install();
958 break;
959 case Push_Proceed:
960 GetAttr(MUIA_String_Integer, st, &retval);
961 if ( retval <= max && retval >= min)
963 running = FALSE;
965 break;
966 case Push_Help:
967 if (GetPL(pl, _HELP).intval)
969 helpwinpl(HELP_ON_ASKSTRING, pl, _HELP);
971 else
973 helpwin(HELP_ON_ASKNUMBER, get_var_arg("@asknumber-help"));
975 break;
976 default:
977 break;
979 WaitCTRL(sigs);
981 GetAttr(MUIA_String_Integer, st, &retval);
983 DelContents(wc);
985 free(out);
986 disable_skip(FALSE);
988 if ( preferences.transcriptstream != BNULL )
990 char tmpbuf[MAXARGSIZE];
991 Write(preferences.transcriptstream, "Ask Number: Result was \"", 24);
992 sprintf(tmpbuf, "%ld", retval);
993 Write(preferences.transcriptstream, tmpbuf, strlen(tmpbuf));
994 Write(preferences.transcriptstream, "\".\n\n", 4);
997 return retval;
1002 * Ask user for a string
1004 char *request_string(struct ParameterList *pl)
1006 char *retval, *string = NULL;
1007 int i;
1009 if ( GetPL(pl, _DEFAULT).used == 1 )
1011 string = strdup(GetPL(pl, _DEFAULT).arg[0]);
1013 else
1015 string = strdup(EMPTY_STRING);
1017 TRANSSCRIPT();
1018 if ( get_var_int( "@user-level" ) > _NOVICE )
1020 char *out;
1021 BOOL running = TRUE;
1022 Object *st, *wc;
1023 ULONG sigs = 0;
1025 disable_skip(TRUE);
1026 out = collatestrings(GetPL(pl, _PROMPT).intval, GetPL(pl, _PROMPT).arg);
1028 wc = VGroup,
1029 Child, VGroup, GroupFrame,
1030 MUIA_Background, MUII_GroupBack,
1031 Child, TextObject,
1032 MUIA_Text_Contents, (IPTR)(out),
1033 End,
1034 Child, st = StringObject,
1035 StringFrame,
1036 MUIA_String_Contents, (IPTR)string,
1037 MUIA_String_MaxLen, 128,
1038 MUIA_String_AdvanceOnCR,TRUE,
1039 MUIA_CycleChain, TRUE,
1040 End,
1041 End,
1042 End;
1044 if (wc)
1046 char *str = "";
1047 AddContents(wc);
1049 while (running)
1051 switch (DoMethod(app,MUIM_Application_NewInput,(IPTR)&sigs))
1053 case Push_Abort:
1054 abort_install();
1055 break;
1056 case Push_Proceed:
1057 running = FALSE;
1058 break;
1059 case Push_Help:
1060 if (GetPL(pl, _HELP).intval)
1062 helpwinpl(HELP_ON_ASKSTRING, pl, _HELP);
1064 else
1066 helpwin(HELP_ON_ASKNUMBER, get_var_arg("@asknumber-help"));
1068 break;
1069 default:
1070 break;
1072 WaitCTRL(sigs);
1074 free(string);
1075 get(st, MUIA_String_Contents, &str);
1076 string = strdup(str);
1078 DelContents(wc);
1080 free(out);
1081 disable_skip(FALSE);
1083 retval = addquotes(string);
1084 free(string);
1085 if ( preferences.transcriptstream != BNULL )
1087 Write(preferences.transcriptstream, "Ask String: Result was ", 23);
1088 Write(preferences.transcriptstream, retval, strlen(retval));
1089 Write(preferences.transcriptstream, ".\n\n", 3);
1092 return retval;
1096 * Ask user to choose one of N items
1098 long int request_choice(struct ParameterList *pl)
1100 long int retval;
1101 char **mxlabels = NULL;
1102 int i, max = 0;
1104 NeedPROMPT(pl);
1106 retval = GetPL(pl, _DEFAULT).intval;
1108 if ( GetPL(pl, _CHOICES).used == 1 )
1110 max = GetPL(pl, _CHOICES).intval;
1112 if ( max > 32 )
1114 error = SCRIPTERROR;
1115 traperr("More than 32 choices given!\n", NULL);
1118 mxlabels = malloc((max+1)*sizeof(STRPTR));
1119 outofmem(mxlabels);
1121 for ( i = 0 ; i < max ; i++ )
1123 mxlabels[i] = strdup(GetPL(pl, _CHOICES).arg[i]);
1125 mxlabels[i] = NULL;
1127 else
1129 error = SCRIPTERROR;
1130 traperr("No choices given!\n", NULL);
1133 TRANSSCRIPT();
1135 if ( get_var_int("@user-level") > _NOVICE )
1137 char *out;
1138 BOOL running = TRUE;
1139 Object *levelmx, *wc;
1140 ULONG sigs = 0;
1142 disable_skip(TRUE);
1143 out = collatestrings(GetPL(pl, _PROMPT).intval, GetPL(pl, _PROMPT).arg);
1145 wc = VGroup,
1146 Child, VGroup, GroupFrame,
1147 MUIA_Background, MUII_GroupBack,
1148 Child, TextObject,
1149 MUIA_Text_Contents, (IPTR)(out),
1150 End,
1151 Child, levelmx = RadioObject,
1152 MUIA_Radio_Entries, (IPTR)(mxlabels),
1153 End,
1154 End,
1155 End;
1157 if (wc)
1159 AddContents(wc);
1161 while (running)
1163 switch (DoMethod(app,MUIM_Application_NewInput,(IPTR)&sigs))
1165 case Push_Abort:
1166 abort_install();
1167 break;
1168 case Push_Proceed:
1169 running = FALSE;
1170 break;
1171 case Push_Help:
1172 if (GetPL(pl, _HELP).intval)
1174 helpwinpl(HELP_ON_ASKCHOICE, pl, _HELP);
1176 else
1178 helpwin(HELP_ON_ASKCHOICE, get_var_arg("@asknumber-help"));
1180 break;
1181 default:
1182 break;
1184 WaitCTRL(sigs);
1186 GetAttr(MUIA_Radio_Active, levelmx, &retval);
1188 DelContents(wc);
1190 free(out);
1191 disable_skip(FALSE);
1193 if ( preferences.transcriptstream != BNULL )
1195 Write(preferences.transcriptstream, "Ask Choice: Result was \"", 24);
1196 Write(preferences.transcriptstream, mxlabels[retval], strlen(mxlabels[retval]));
1197 Write(preferences.transcriptstream, "\".\n\n", 4);
1199 for ( i = 0 ; i < max ; i++ )
1201 free(mxlabels[i]);
1203 free(mxlabels);
1205 return retval;
1210 * Ask user for a directory
1212 char *request_dir(struct ParameterList *pl)
1214 char *retval, *string;
1216 if ( GetPL(pl, _DEFAULT).used == 0 )
1218 error = SCRIPTERROR;
1219 traperr("No default specified!", NULL);
1221 string = GetPL(pl, _DEFAULT).arg[0];
1223 /* TODO: write whole function request_dir() */
1225 retval = addquotes(string);
1227 return retval;
1232 * Ask user to insert a specific disk
1234 char *request_disk(struct ParameterList *pl)
1236 char *retval, *string;
1238 if ( GetPL(pl, _DEST).used == 0 )
1240 error = SCRIPTERROR;
1241 traperr("No dest specified!", NULL);
1243 string = GetPL(pl, _DEST).arg[0];
1245 /* TODO: write whole function request_disk() */
1247 retval = addquotes(string);
1249 return retval;
1254 * Ask user for a file
1256 char *request_file(struct ParameterList *pl)
1258 char *retval, *string;
1260 if ( GetPL(pl, _DEFAULT).used == 0 )
1262 error = SCRIPTERROR;
1263 traperr("No default specified!", NULL);
1265 string = GetPL(pl, _DEFAULT).arg[0];
1267 /* TODO: write whole function request_file() */
1269 retval = addquotes(string);
1271 return retval;
1276 * Ask user for a selection of multiple items (choose m of n items)
1278 long int request_options(struct ParameterList *pl)
1280 long int retval;
1281 char **mxlabels = NULL;
1282 int i, max = 0;
1283 Object *marks[33];
1284 Object *labels[33];
1285 long int val;
1286 BOOL j;
1288 NeedPROMPT(pl);
1290 retval = GetPL(pl, _DEFAULT).intval;
1292 if ( GetPL(pl, _CHOICES).used == 1 )
1294 max = GetPL(pl, _CHOICES).intval;
1296 if ( max > 32 )
1298 error = SCRIPTERROR;
1299 traperr("More than 32 choices given!\n", NULL);
1302 mxlabels = malloc((max+1)*sizeof(STRPTR));
1303 outofmem(mxlabels);
1305 for ( i = 0 ; i < max ; i++ )
1307 mxlabels[i] = strdup(GetPL(pl, _CHOICES).arg[i]);
1308 marks[i] = MUI_MakeObject(MUIO_Checkmark, (IPTR)mxlabels[i]);
1309 labels[i] = LLabel(mxlabels[i]);
1311 set(marks[i], MUIA_CycleChain, TRUE);
1312 if ( (retval & 1<<i) != 0 )
1313 set(marks[i], MUIA_Selected, TRUE);
1315 mxlabels[i] = NULL;
1317 else
1319 error = SCRIPTERROR;
1320 traperr("No choices given!\n", NULL);
1323 TRANSSCRIPT();
1325 if ( get_var_int("@user-level") > _NOVICE )
1327 char *out;
1328 BOOL running = TRUE;
1329 Object *levelmx, *wc;
1330 ULONG sigs = 0;
1332 disable_skip(TRUE);
1333 out = collatestrings(GetPL(pl, _PROMPT).intval, GetPL(pl, _PROMPT).arg);
1335 wc = VGroup,
1336 Child, VGroup, GroupFrame,
1337 MUIA_Background, MUII_GroupBack,
1338 Child, TextObject,
1339 MUIA_Text_Contents, (IPTR)(out),
1340 End,
1341 Child, levelmx = ColGroup(2),
1342 GroupFrame,
1343 MUIA_Background, MUII_GroupBack,
1344 End,
1345 End,
1346 End;
1348 if (wc)
1350 for ( i = 0 ; i < max ; i++ )
1352 DoMethod(levelmx, OM_ADDMEMBER, (IPTR)marks[i]);
1353 DoMethod(levelmx, OM_ADDMEMBER, (IPTR)labels[i]);
1355 AddContents(wc);
1357 while (running)
1359 switch (DoMethod(app,MUIM_Application_NewInput,(IPTR)&sigs))
1361 case Push_Abort:
1362 abort_install();
1363 break;
1364 case Push_Proceed:
1365 running = FALSE;
1366 break;
1367 case Push_Help:
1368 if (GetPL(pl, _HELP).intval)
1370 helpwinpl(HELP_ON_ASKCHOICE, pl, _HELP);
1372 else
1374 helpwin(HELP_ON_ASKCHOICE, get_var_arg("@asknumber-help"));
1376 break;
1377 default:
1378 break;
1380 WaitCTRL(sigs);
1382 retval = 0;
1383 for ( i = 0 ; i < max ; i++ )
1385 GetAttr(MUIA_Selected, marks[i], &val);
1386 if (val)
1388 retval |= 1<<i;
1392 DelContents(wc);
1394 free(out);
1395 disable_skip(FALSE);
1397 if ( preferences.transcriptstream != BNULL )
1399 Write(preferences.transcriptstream, "Ask Options: Result was \"", 24);
1400 j = FALSE;
1401 for ( i = 0 ; i < max ; i++ )
1403 if ( (retval & (1<<i)) != 0 )
1405 if ( j )
1407 Write(preferences.transcriptstream, "\", \"", 4);
1409 Write(preferences.transcriptstream, mxlabels[i], strlen(mxlabels[i]));
1410 j = TRUE;
1413 Write(preferences.transcriptstream, "\".\n\n", 4);
1415 for ( i = 0 ; i < max ; i++ )
1417 free(mxlabels[i]);
1419 free(mxlabels);
1421 return retval;
1426 * Ask user to confirm
1428 int request_confirm(struct ParameterList * pl)
1430 int retval = 1;
1431 BOOL running = TRUE;
1432 Object *wc;
1433 ULONG sigs = 0;
1434 char *out;
1436 NeedPROMPT(pl);
1437 NeedHELP(pl);
1439 if ( get_var_int("@user-level") >= GetPL(pl, _CONFIRM).intval )
1441 out = collatestrings(GetPL(pl, _PROMPT).intval, GetPL(pl, _PROMPT).arg);
1443 wc = VGroup,
1444 Child, TextObject,
1445 GroupFrame,
1446 MUIA_Background, MUII_GroupBack,
1447 MUIA_Text_Contents, (IPTR)(out),
1448 End,
1449 End;
1451 if (wc)
1453 AddContents(wc);
1455 while (running)
1457 switch (DoMethod(app,MUIM_Application_NewInput,(IPTR)&sigs))
1459 case Push_Abort:
1460 abort_install();
1461 break;
1462 case Push_Proceed:
1463 running = FALSE;
1464 break;
1465 case Push_Skip:
1466 retval = 0;
1467 running = FALSE;
1468 break;
1469 case Push_Help:
1470 helpwinpl(HELP_ON_CONFIRM, pl, _HELP);
1471 break;
1472 default:
1473 break;
1475 WaitCTRL(sigs);
1478 DelContents(wc);
1480 free(out);
1483 return retval;
1488 * Give a short summary on what was done
1490 void final_report()
1492 #ifdef DEBUG
1493 printf("Application has been installed in %s.\n", get_var_arg("@default-dest"));
1494 #endif /* DEBUG */
1498 void display_text(char * msg)
1500 BOOL running = TRUE;
1501 LONG sigs = 0;
1502 Object *wc;
1503 Object *btok;
1505 wc = VGroup,
1506 Child, TextObject,
1507 GroupFrameT(_(MSG_MESSAGE)),
1508 MUIA_Text_Contents, (IPTR)msg,
1509 End,
1510 Child, HBar(TRUE),
1511 Child, HGroup,
1512 Child, btok = CoolImageIDButton(_(MSG_OK), COOL_USEIMAGE_ID),
1513 End,
1514 End;
1515 set(btok,MUIA_CycleChain,1);
1516 DoMethod(btok, MUIM_Notify, MUIA_Pressed, FALSE,(IPTR)app, 2, MUIM_Application_ReturnID, Push_Ok);
1517 DoMethod(reqroot, OM_ADDMEMBER, (IPTR)wc);
1519 set(reqwnd, MUIA_Window_Open, TRUE);
1520 while (running)
1522 switch (DoMethod(app,MUIM_Application_NewInput,(IPTR)&sigs))
1524 case Push_Ok:
1525 running = FALSE;
1526 break;
1527 default:
1528 break;
1530 WaitCTRL(sigs);
1532 set(reqwnd, MUIA_Window_Open, FALSE);
1534 DoMethod(reqroot, OM_REMMEMBER, (IPTR)wc);
1535 MUI_DisposeObject(wc);