diff options
Diffstat (limited to 'mdk-stage1/newt-frontend.c')
| -rw-r--r-- | mdk-stage1/newt-frontend.c | 156 |
1 files changed, 73 insertions, 83 deletions
diff --git a/mdk-stage1/newt-frontend.c b/mdk-stage1/newt-frontend.c index 416d05ae6..c0489b58d 100644 --- a/mdk-stage1/newt-frontend.c +++ b/mdk-stage1/newt-frontend.c @@ -1,7 +1,7 @@ /* - * Guillaume Cottenceau (gc@mandrakesoft.com) + * Guillaume Cottenceau (gc) * - * Copyright 2000 MandrakeSoft + * Copyright 2000 Mandriva * * This software may be freely redistributed under the terms of the GNU * public license. @@ -24,6 +24,7 @@ * Each different frontend must implement all functions defined in frontend.h */ +#define _GNU_SOURCE #include <stdlib.h> #include <unistd.h> @@ -31,21 +32,29 @@ #include <stdio.h> #include <stdarg.h> #include <sys/time.h> -#include "stage1.h" -#include "log.h" -#include "newt.h" +#include <newt.h> -#include "frontend.h" +#include <probing.h> +#include "frontend.h" -void init_frontend(void) +void init_frontend(char * welcome_msg) { + int i; + for (i=0; i<38; i++) printf("\n"); newtInit(); newtCls(); - - newtDrawRootText(0, 0, "Welcome to " DISTRIB_NAME " (" VERSION ") " __DATE__ " " __TIME__); - - newtPushHelpLine(" <Alt-F1> for here, <Alt-F3> to see the logs, <Alt-F4> for kernel msg"); + + if (welcome_msg[0]) { + char *msg; + int cols, rows; + newtGetScreenSize(&cols, &rows); + asprintf(&msg, " %-*s", cols - 1, welcome_msg); + newtDrawRootText(0, 0, msg); + free(msg); + newtPushHelpLine(" <Alt-F1> for here, <Alt-F3> to see the logs, <Alt-F4> for kernel msg"); + } + newtRefresh(); } @@ -55,58 +64,48 @@ void finish_frontend(void) } -void error_message(char *msg, ...) +void verror_message(char *msg, va_list ap) { - va_list args; - va_start(args, msg); - va_end(args); - newtWinMessagev("Error", "Ok", msg, args); - unset_param(MODE_AUTOMATIC); + newtWinMessagev("Error", "Ok", msg, ap); } -void info_message(char *msg, ...) +void vinfo_message(char *msg, va_list ap) { - va_list args; - va_start(args, msg); - va_end(args); - if (!IS_AUTOMATIC) - newtWinMessagev("Notice", "Ok", msg, args); - else - vlog_message(msg, args); + newtWinMessagev("Notice", "Ok", msg, ap); } -void wait_message(char *msg, ...) +void vwait_message(char *msg, va_list ap) { - int width = 8; - int height = 3; + int width, height; char * title = "Please wait..."; newtComponent c, f; + newtGrid grid; char * buf = NULL; + char * flowed; int size = 0; int i = 0; - va_list args; - - va_start(args, msg); do { size += 1000; if (buf) free(buf); buf = malloc(size); - i = vsnprintf(buf, size, msg, args); - width += i; - } while (i == size); - - va_end(args); + i = vsnprintf(buf, size, msg, ap); + } while (i >= size || i == -1); + + flowed = newtReflowText(buf, 60, 5, 5, &width, &height); - newtCenteredWindow(width, height, title); + c = newtTextbox(-1, -1, width, height, NEWT_TEXTBOX_WRAP); + newtTextboxSetText(c, flowed); - c = newtTextbox(1, 1, width - 2, height - 2, NEWT_TEXTBOX_WRAP); - newtTextboxSetText(c, buf); - f = newtForm(NULL, NULL, 0); + grid = newtCreateGrid(1, 1); + newtGridSetField(grid, 0, 0, NEWT_GRID_COMPONENT, c, 0, 0, 0, 0, 0, 0); + newtGridWrappedWindow(grid, title); + free(flowed); free(buf); + f = newtForm(NULL, NULL, 0); newtFormAddComponent(f, c); newtDrawForm(f); @@ -125,7 +124,7 @@ static int size_progress; static int actually_drawn; static char * msg_progress; -void init_progression(char *msg, int size) +void init_progression_raw(char *msg, int size) { size_progress = size; if (size) { @@ -144,7 +143,7 @@ void init_progression(char *msg, int size) } } -void update_progression(int current_size) +void update_progression_raw(int current_size) { if (size_progress) { if (current_size <= size_progress) @@ -167,7 +166,7 @@ void update_progression(int current_size) } } -void end_progression(void) +void end_progression_raw(void) { if (size_progress) { newtPopWindow(); @@ -178,52 +177,39 @@ void end_progression(void) } -enum return_type ask_from_list_comments(char *msg, char ** elems, char ** elems_comments, char ** choice) +enum return_type ask_from_list_index(char *msg, char ** elems, char ** elems_comments, int * answer) { - char * items[50]; - int answer = 0, rc; - char ** sav_elems = elems; - int i; + char * items[50000]; + int rc; - i = 0; - while (elems && *elems) { - items[i] = malloc(sizeof(char) * (strlen(*elems) + strlen(*elems_comments) + 4)); - strcpy(items[i], *elems); - strcat(items[i], " ("); - strcat(items[i], *elems_comments); - strcat(items[i], ")"); - i++; - elems++; - elems_comments++; + if (elems_comments) { + int i; + + i = 0; + while (elems && *elems) { + int j = (*elems_comments) ? strlen(*elems_comments) : 0; + items[i] = malloc(sizeof(char) * (strlen(*elems) + j + 4)); + strcpy(items[i], *elems); + if (*elems_comments) { + strcat(items[i], " ("); + strcat(items[i], *elems_comments); + strcat(items[i], ")"); + } + elems_comments++; + i++; + elems++; + } + items[i] = NULL; } - items[i] = NULL; - rc = newtWinMenu("Please choose...", msg, 52, 5, 5, 7, items, &answer, "Ok", "Cancel", NULL); + rc = newtWinMenu("Please choose...", msg, 52, 5, 5, 7, elems_comments ? items : elems, answer, "Ok", "Cancel", NULL); if (rc == 2) return RETURN_BACK; - *choice = strdup(sav_elems[answer]); - return RETURN_OK; } - -enum return_type ask_from_list(char *msg, char ** elems, char ** choice) -{ - int answer = 0, rc; - - rc = newtWinMenu("Please choose...", msg, 52, 5, 5, 7, elems, &answer, "Ok", "Cancel", NULL); - - if (rc == 2) - return RETURN_BACK; - - *choice = strdup(elems[answer]); - - return RETURN_OK; -} - - enum return_type ask_yes_no(char *msg) { int rc; @@ -240,7 +226,7 @@ enum return_type ask_yes_no(char *msg) static void (*callback_real_function)(char ** strings) = NULL; -static void default_callback(newtComponent co, void * data) +static void default_callback(newtComponent co __attribute__ ((unused)), void * data) { newtComponent * entries = data; char * strings[50], ** ptr; @@ -313,7 +299,7 @@ static int mynewtWinEntries(char * title, char * text, int suggestedWidth, int f for (i = 0; i < numItems; i++) { newtComponent entr = newtEntry(-1, -1, items[i].value ? *items[i].value : NULL, dataWidth, - items[i].value, items[i].flags); + (const char**)items[i].value, items[i].flags); newtGridSetField(subgrid, 0, i, NEWT_GRID_COMPONENT, newtLabel(-1, -1, items[i].text), @@ -367,7 +353,7 @@ enum return_type ask_from_entries(char *msg, char ** questions, char *** answers while (questions && *questions) { entries[i].text = *questions; - entries[i].flags = NEWT_FLAG_SCROLL; + entries[i].flags = NEWT_FLAG_SCROLL | (!strcmp(*questions, "Password") ? NEWT_FLAG_PASSWORD : 0); i++; questions++; } @@ -375,7 +361,7 @@ enum return_type ask_from_entries(char *msg, char ** questions, char *** answers entries[i].value = NULL; if (*answers == NULL) - *answers = (char **) malloc(sizeof(char *) * i); + *answers = (char **) calloc(1, sizeof(char *) * i); else already_answers = *answers; @@ -388,7 +374,7 @@ enum return_type ask_from_entries(char *msg, char ** questions, char *** answers *(entries[j].value) = NULL; } - rc = mynewtWinEntries("Please fill entries...", msg, 52, 5, 5, entry_size, callback_func, entries, "Ok", "Cancel", NULL); + rc = mynewtWinEntries("Please fill in entries...", msg, 52, 5, 5, entry_size, callback_func, entries, "Ok", "Cancel", NULL); if (rc == 3) return RETURN_BACK; @@ -397,3 +383,7 @@ enum return_type ask_from_entries(char *msg, char ** questions, char *** answers return RETURN_OK; } + + +void suspend_to_console(void) { newtSuspend(); } +void resume_from_suspend(void) { newtResume(); } |
