int inputBox(const char * text, int height, int width, poptContext optCon, 
		int flags, char ** result) {
    newtComponent form, entry, okay, cancel, answer, tb;
    char * val;
    int rc = DLG_OKAY;
    int top;

    val = poptGetArg(optCon);
    tb = textbox(height - 3 - buttonHeight, width - 2,
			text, flags, &top);

    form = newtForm(NULL, NULL, 0);
    entry = newtEntry(1, top + 1, val, width - 2, &val, 
			NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT);

    newtFormAddComponents(form, tb, entry, NULL);

    addButtons(height, width, form, &okay, &cancel, flags);

    answer = newtRunForm(form);
    if (answer == cancel)
	rc = DLG_CANCEL;

    *result = val;

    return rc;
}
예제 #2
0
static int newtLicenseBox(const char* title, const char* text, int width, int height) {
	int ret = 1;

	newtCenteredWindow(width, height, title);

	newtComponent form = newtForm(NULL, NULL, 0);

	newtComponent textbox = newtTextbox(1, 1, width - 2, height - 7,
		NEWT_FLAG_WRAP|NEWT_FLAG_SCROLL);
	newtTextboxSetText(textbox, text);
	newtFormAddComponent(form, textbox);

	char choice;
	newtComponent checkbox = newtCheckbox(3, height - 3, _("I accept this license"),
		' ', " *", &choice);

	newtComponent btn = newtButton(width - 15, height - 4, _("OK"));

	newtFormAddComponents(form, checkbox, btn, NULL);

	newtComponent answer = newtRunForm(form);
	if (answer == btn && choice == '*')
		ret = 0;

	newtFormDestroy(form);
	newtPopWindow();

	return ret;
}
예제 #3
0
static int newtWinOkCancel(const char* title, const char* message, int width, int height,
		const char* btn_txt_ok, const char* btn_txt_cancel) {
	int ret = 1;

	unsigned int btn_width_ok = strlen(btn_txt_ok);
	unsigned int btn_width_cancel = strlen(btn_txt_cancel);

	// Maybe make the box wider to fix both buttons inside
	unsigned int min_width = btn_width_ok + btn_width_cancel + 5;
	if (width < min_width)
		width = min_width;

	unsigned int btn_pos_ok = (width / 3) - (btn_width_ok / 2) - 1;
	unsigned int btn_pos_cancel = (width * 2 / 3) - (btn_width_cancel / 2) - 1;

	// Move buttons a bit if they overlap
	while ((btn_pos_ok + btn_width_ok + 5) > btn_pos_cancel) {
		// Move the cancel button to the right if there is enough space left
		if ((btn_pos_cancel + btn_width_cancel + 2) < width) {
			++btn_pos_cancel;
			continue;
		}

		// Move the OK button to the left if possible
		if (btn_pos_ok > 1) {
			--btn_pos_ok;
			continue;
		}

		// If they still overlap, we cannot fix the situtation
		// and break. Should actually never get here, because we
		// adjust the width of the window earlier.
		break;
	}

	newtCenteredWindow(width, height, title);

	newtComponent form = newtForm(NULL, NULL, 0);

	newtComponent textbox = newtTextbox(1, 1, width - 2, height - 6, NEWT_FLAG_WRAP);
	newtTextboxSetText(textbox, message);
	newtFormAddComponent(form, textbox);

	newtComponent btn_ok = newtButton(btn_pos_ok, height - 4, btn_txt_ok);
	newtComponent btn_cancel = newtButton(btn_pos_cancel, height - 4, btn_txt_cancel);

	newtFormAddComponents(form, btn_ok, btn_cancel, NULL);

	newtComponent answer = newtRunForm(form);

	if (answer == btn_ok) {
		ret = 0;
	}

	newtFormDestroy(form);
	newtPopWindow();

	return ret;
}
예제 #4
0
// =======================================================
int CInterfaceNewt::askLogin(char *szLogin, char *szPasswd, WORD size)
{
  newtComponent editLoginText;
  newtComponent editPasswdText;
  newtComponent labelLoginText;
  newtComponent labelPasswdText;

  newtComponent form;
  newtComponent btnOk;
  newtComponent btnCancel;
  newtComponent temp;
 
  int nOk = 0; 
  
  while (!nOk)
    {
      newtCenteredWindow(65, 20, i18n("Password required"));
      
      labelLoginText = newtTextbox(1, 5, 60, 1, 0);
      newtTextboxSetText(labelLoginText, i18n("Enter your login"));
      editLoginText = newtEntry(1, 6, "", 55, NULL, NEWT_ENTRY_SCROLL);

      labelPasswdText = newtTextbox(1, 9, 60, 1, 0);
      newtTextboxSetText(labelPasswdText, i18n("Enter your password"));
      editPasswdText = newtEntry(1, 10, "", 55, NULL, NEWT_FLAG_HIDDEN);

      btnOk = newtButton(15, 14, i18n("Ok"));
      btnCancel = newtButton(40, 14, i18n("Cancel"));
      
      form = newtForm(NULL, NULL, 0);
      newtFormAddComponents(form, labelLoginText, editLoginText, 
         labelPasswdText, editPasswdText, btnOk, btnCancel, NULL);
      
      temp = newtRunForm(form);
      newtPopWindow();	
      if (temp == btnCancel)
	{	
	  newtFormDestroy(form);
	  RETURN_int(-1);
	}
      
      strncpy(szLogin, newtEntryGetValue(editLoginText), size-1);
      *(szLogin+size-1) = '\0';
      strncpy(szPasswd, newtEntryGetValue(editPasswdText), size-1);
      *(szPasswd+size-1) = '\0';
      
      if (!(*szLogin) || !(*szPasswd))
	msgBoxError(i18n("Text cannot be empty"));
      else
        nOk = 1;
      
      newtFormDestroy(form);
    }
  
  return 0;
}
예제 #5
0
// ============================================================================
unsigned int CExceptionsGUI::windowError(char *szTitle, char *szText, char *szButton, char *szCurPath)
{
  BEGIN;
  //char szTemp[] = "/tmp/image";

  unsigned int nRes;
  newtComponent btnOther;
  
  newtComponent formMain = newtForm(NULL, NULL, 0);
  if (szButton)
    btnOther = newtButton(30, 15, szButton);
  else
    btnOther = newtButton(30, 15, "(none)");
  newtComponent btnOk = newtButton(10, 15, i18n("Change"));
  newtComponent btnCancel = newtButton(50, 15, i18n("Cancel"));
  newtComponent editFilename = newtEntry(5, 10, szCurPath, 45, NULL, 0);
  newtComponent labelFilename = newtLabel(5, 9, i18n("Enter new filename"));

  newtComponent labelText = newtTextbox(1, 1, 60, 7, 0);
  newtTextboxSetText(labelText, szText);

  newtComponent widgetTemp;

  newtCenteredWindow(67, 20, szTitle);
  if (szButton)
    newtFormAddComponents(formMain, editFilename, btnOk, btnOther, btnCancel,
       labelFilename, labelText, NULL);
  else
    newtFormAddComponents(formMain, editFilename, btnOk, btnCancel,
       labelFilename, labelText, NULL);

  widgetTemp = newtRunForm(formMain);

  if (widgetTemp == btnCancel)
    nRes = ERR_QUIT;
  else if (szButton && widgetTemp == btnOther)
    nRes = ERR_CONT;
  else
    {
      strncpy(szNewString, newtEntryGetValue(editFilename), 1023);
      *(szNewString+1023) = '\0';

      while (szNewString[strlen(szNewString)-1] == '/')
        szNewString[strlen(szNewString)-1] = '\0';

      nRes = ERR_RETRY;
    }
  newtFormDestroy(formMain);
  newtPopWindow();
  RETURN_WORD(nRes);
}
int messageBox(const char * text, int height, int width, int type, int flags) {
    newtComponent form, yes, tb, answer;
    newtComponent no = NULL;
    int tFlag = (flags & FLAG_SCROLL_TEXT) ? NEWT_FLAG_SCROLL : 0;

    form = newtForm(NULL, NULL, 0);

    tb = newtTextbox(1, 1, width - 2, height - 3 - buttonHeight, 
			NEWT_FLAG_WRAP | tFlag);
    newtTextboxSetText(tb, text);

    newtFormAddComponent(form, tb);

    switch ( type ) {
    case MSGBOX_INFO:
	break;
    case MSGBOX_MSG:
	yes = makeButton((width - 8) / 2, height - 1 - buttonHeight, "Ok");
	newtFormAddComponent(form, yes);
	break;
    default:
	yes = makeButton((width - 16) / 3, height - 1 - buttonHeight, "Yes");
	no = makeButton(((width - 16) / 3) * 2 + 9, height - 1 - buttonHeight, 
			"No");
	newtFormAddComponents(form, yes, no, NULL);

	if (flags & FLAG_DEFAULT_NO)
	    newtFormSetCurrent(form, no);
    }

    if ( type != MSGBOX_INFO ) {
	newtRunForm(form);

	answer = newtFormGetCurrent(form);

	if (answer == no)
	    return DLG_CANCEL;
    }
    else {
	newtDrawForm(form);
	newtRefresh();
    }
	


    return DLG_OKAY;
}
/**
 * Ask the user how much compression they would like to use.
 * The choices are "None" (0), "Minimum" (1), "Average" (4), and "Maximum" (9).
 * @return The compression level (0-9) chosen, or -1 for "Exit".
 */
	int
	 which_compression_level() {

		/*@ char ************************************************************ */
		int output = none;


		/*@ newt ************************************************************ */

		newtComponent b1;
		newtComponent b2;
		newtComponent b3;
		newtComponent b4;
		newtComponent b5;
		newtComponent b_res;
		newtComponent myForm;

		newtDrawRootText(18, 0, WELCOME_STRING);
		newtPushHelpLine
			(_("   Please specify the level of compression that you want."));
		//  newtOpenWindow (23, 3, 34, 13, "How much compression?");
		newtCenteredWindow(34, 13, _("How much compression?"));
		b1 = newtButton(4, 1, _("Maximum"));
		b2 = newtButton(18, 1, _("Average"));
		b3 = newtButton(4, 5, _("Minimum"));
		b4 = newtButton(18, 5, _(" None  "));
		b5 = newtButton(4, 9, _("         Exit        "));
		myForm = newtForm(NULL, NULL, 0);
		newtFormAddComponents(myForm, b1, b3, b2, b4, b5, NULL);
		b_res = newtRunForm(myForm);
		newtFormDestroy(myForm);
		newtPopWindow();
		if (b_res == b1) {
			output = 9;
		} else if (b_res == b2) {
			output = 4;
		} else if (b_res == b3) {
			output = 1;
		} else if (b_res == b4) {
			output = 0;
		} else if (b_res == b5) {
			output = -1;
		}
		newtPopHelpLine();
		return (output);
	}
예제 #8
0
// =======================================================
int CInterfaceNewt::askText(char *szMessage, char *szTitle, char *szDestText, WORD size)
{
  newtComponent editText;
  newtComponent labelText;
  newtComponent form;
  newtComponent btnOk;
  newtComponent btnCancel;
  newtComponent temp;
  
  *szDestText = 0;
  
  while (!*szDestText)
    {
      newtCenteredWindow(65, 20, szTitle);
      
      labelText = newtTextbox(1, 1, 60, 7, 0/*NEWT_TEXTBOX_SCROLL*/);
      newtTextboxSetText(labelText, szMessage);
      
      editText = newtEntry(1, 9, "", 55, NULL, NEWT_ENTRY_SCROLL);
      btnOk = newtButton(15, 14, i18n("Ok"));
      btnCancel = newtButton(40, 14, i18n("Cancel"));
      
      form = newtForm(NULL, NULL, 0);
      newtFormAddComponents(form, labelText, editText, btnOk, btnCancel, NULL);
      
      temp = newtRunForm(form);
      newtPopWindow();	
      if (temp == btnCancel)
	{	
	  newtFormDestroy(form);
	  RETURN_int(-1);
	}
      
      strncpy(szDestText, newtEntryGetValue(editText), size-1);
      *(szDestText+size-1) = '\0';
      
      if (*szDestText == 0)
	msgBoxError(i18n("Text cannot be empty"));
      
      newtFormDestroy(form);
    }
  
  return 0;
}
예제 #9
0
파일: kickstart.c 프로젝트: bsanders/stacki
static char *newKickstartLocation(const char *origLocation) {
    const char *location;
    char *retval = NULL;
    newtComponent f, okay, cancel, answer, locationEntry;
    newtGrid grid, buttons;

    startNewt();

    locationEntry = newtEntry(-1, -1, NULL, 60, &location, NEWT_FLAG_SCROLL);
    newtEntrySet(locationEntry, origLocation, 1);

    /* button bar at the bottom of the window */
    buttons = newtButtonBar(_("OK"), &okay, _("Cancel"), &cancel, NULL);

    grid = newtCreateGrid(1, 3);

    newtGridSetField(grid, 0, 0, NEWT_GRID_COMPONENT,
                     newtTextboxReflowed(-1, -1, _("Unable to download the kickstart file.  Please modify the kickstart parameter below or press Cancel to proceed as an interactive installation."), 60, 0, 0, 0),
                     0, 0, 0, 0, NEWT_ANCHOR_LEFT, 0);
    newtGridSetField(grid, 0, 1, NEWT_GRID_COMPONENT, locationEntry,
                     0, 1, 0, 0, NEWT_ANCHOR_LEFT, 0);
    newtGridSetField(grid, 0, 2, NEWT_GRID_SUBGRID, buttons,
                     0, 1, 0, 0, 0, NEWT_GRID_FLAG_GROWX);

    f = newtForm(NULL, NULL, 0);
    newtGridAddComponentsToForm(grid, f, 1);
    newtGridWrappedWindow(grid, _("Error downloading kickstart file"));
    newtGridFree(grid, 1);

    /* run the form */
    answer = newtRunForm(f);

    if (answer != cancel)
        retval = strdup(location);

    newtFormDestroy(f);
    newtPopWindow();

    return retval;
}
예제 #10
0
// =======================================================
void CInterfaceNewt::askDescription(char *szDescription, DWORD dwMaxLen)
{
  newtComponent editDesc;
  newtComponent labelText;
  newtComponent form;
  newtComponent btnOk;
  
  memset(szDescription, 0, dwMaxLen);
  
  newtCenteredWindow(65, 18, i18n("Partition description"));
  
  labelText = newtLabel(1, 1, i18n("You can enter a description of the saved partition:"));
  editDesc = newtEntry(1, 3, "", 60, NULL, NEWT_ENTRY_SCROLL);
  btnOk = newtButton(27, 13, i18n("Ok"));
  
  form = newtForm(NULL, NULL, 0);
  newtFormAddComponents(form, labelText, editDesc, btnOk, NULL);
  
  newtRunForm(form);
  newtPopWindow();	
  
  strncpy(szDescription, newtEntryGetValue(editDesc), dwMaxLen);
  newtFormDestroy(form);
}
예제 #11
0
/* only supports up to 50 buttons and entries -- shucks! */
static int mynewtWinEntries(char * title, char * text, int suggestedWidth, int flexDown, 
			    int flexUp, int dataWidth, void (*callback_func)(char ** strings),
			    struct newtWinEntry * items, char * button1, ...) {
	newtComponent buttons[50], result, form, textw;
	newtGrid grid, buttonBar, subgrid;
	int numItems;
	int rc, i;
	int numButtons;
	char * buttonName;
	newtComponent entries[50];

	va_list args;
	
	textw = newtTextboxReflowed(-1, -1, text, suggestedWidth, flexDown,
				    flexUp, 0);
	
	for (numItems = 0; items[numItems].text; numItems++); 
	
	buttonName = button1, numButtons = 0;
	va_start(args, button1);
	while (buttonName) {
		buttons[numButtons] = newtButton(-1, -1, buttonName);
		numButtons++;
		buttonName = va_arg(args, char *);
	}
	
	va_end(args);
	
	buttonBar = newtCreateGrid(numButtons, 1);
	for (i = 0; i < numButtons; i++) {
		newtGridSetField(buttonBar, i, 0, NEWT_GRID_COMPONENT, 
				 buttons[i],
				 i ? 1 : 0, 0, 0, 0, 0, 0);
	}

	if (callback_func) {
		callback_real_function = callback_func;
		entries[numItems] = NULL;
	}
	else
		callback_real_function = NULL;
	
	subgrid = newtCreateGrid(2, numItems);
	for (i = 0; i < numItems; i++) {
		newtComponent entr = newtEntry(-1, -1, items[i].value ? 
					       *items[i].value : NULL, dataWidth,
					       (const char**)items[i].value, items[i].flags);

		newtGridSetField(subgrid, 0, i, NEWT_GRID_COMPONENT,
				 newtLabel(-1, -1, items[i].text),
				 0, 0, 0, 0, NEWT_ANCHOR_LEFT, 0);
		newtGridSetField(subgrid, 1, i, NEWT_GRID_COMPONENT,
				 entr,
				 1, 0, 0, 0, 0, 0);
		if (callback_func) {
			entries[i] = entr;
			newtComponentAddCallback(entr, default_callback, entries);
		}
	}
	
	
	grid = newtCreateGrid(1, 3);
	form = newtForm(NULL, 0, 0);
	newtGridSetField(grid, 0, 0, NEWT_GRID_COMPONENT, textw, 
			 0, 0, 0, 0, NEWT_ANCHOR_LEFT, 0);
	newtGridSetField(grid, 0, 1, NEWT_GRID_SUBGRID, subgrid, 
			 0, 1, 0, 0, 0, 0);
	newtGridSetField(grid, 0, 2, NEWT_GRID_SUBGRID, buttonBar, 
			 0, 1, 0, 0, 0, NEWT_GRID_FLAG_GROWX);
	newtGridAddComponentsToForm(grid, form, 1);
	newtGridWrappedWindow(grid, title);
	newtGridFree(grid, 1);
	
	result = newtRunForm(form);
	
	for (rc = 0; rc < numItems; rc++)
		*items[rc].value = strdup(*items[rc].value);
	
	for (rc = 0; result != buttons[rc] && rc < numButtons; rc++);
	if (rc == numButtons) 
		rc = 0; /* F12 */
	else 
		rc++;
	
	newtFormDestroy(form);
	newtPopWindow();
	
	return rc;
}
int checkList(const char * text, int height, int width, poptContext optCon,
		int useRadio, int flags, char *** selections) {
    newtComponent form, okay, tb, subform, answer;
    newtComponent sb = NULL, cancel = NULL;
    const char * arg;
    char * end;
    int listHeight;
    int numBoxes = 0;
    int allocedBoxes = 5;
    int i;
    int numSelected;
    int rc = DLG_OKAY;
    char buf[80], format[20];
    int maxWidth = 0;
    int top;
    struct {
	const char * text;
	const char * tag;
	newtComponent comp;
    } * cbInfo = malloc(allocedBoxes * sizeof(*cbInfo));
    char * cbStates = malloc(allocedBoxes * sizeof(cbStates));

    if (!(arg = poptGetArg(optCon))) return DLG_ERROR;
    listHeight = strtoul(arg, &end, 10);
    if (*end) return DLG_ERROR;

    while ((arg = poptGetArg(optCon))) {
	if (allocedBoxes == numBoxes) {
	    allocedBoxes += 5;
	    cbInfo = realloc(cbInfo, sizeof(*cbInfo) * allocedBoxes);
	    cbStates = realloc(cbStates, sizeof(*cbStates) * allocedBoxes);
	}

	cbInfo[numBoxes].tag = arg;
	if (!(arg = poptGetArg(optCon))) return DLG_ERROR;

	if (!(flags & FLAG_NOITEM)) {
	    cbInfo[numBoxes].text = arg;
	    if (!(arg = poptGetArg(optCon))) return DLG_ERROR;
	} else
	    cbInfo[numBoxes].text = "";

	if (!strcmp(arg, "1") || !strcasecmp(arg, "on") || 
		!strcasecmp(arg, "yes"))
	    cbStates[numBoxes] = '*';
	else
	    cbStates[numBoxes] = ' ';

	if (wstrlen(cbInfo[numBoxes].tag,-1) > (unsigned int)maxWidth)
	    maxWidth = wstrlen(cbInfo[numBoxes].tag,-1);

	numBoxes++;
    }

    form = newtForm(NULL, NULL, 0);

    tb = textbox(height - 3 - buttonHeight - listHeight, width - 2,
			text, flags, &top);

    if (listHeight < numBoxes) { 
	sb = newtVerticalScrollbar(width - 4, 
				   top + 1,
				   listHeight, NEWT_COLORSET_CHECKBOX,
				   NEWT_COLORSET_ACTCHECKBOX);
	newtFormAddComponent(form, sb);
    }
    subform = newtForm(sb, NULL, 0);
    newtFormSetBackground(subform, NEWT_COLORSET_CHECKBOX);

    sprintf(format, "%%-%ds  %%s", maxWidth);
    for (i = 0; i < numBoxes; i++) {
	sprintf(buf, format, cbInfo[i].tag, cbInfo[i].text);

	if (useRadio)
	    cbInfo[i].comp = newtRadiobutton(4, top + 1 + i, buf,
					cbStates[i] != ' ', 
					i ? cbInfo[i - 1].comp : NULL);
	else
	    cbInfo[i].comp = newtCheckbox(4, top + 1 + i, buf,
			      cbStates[i], NULL, cbStates + i);

	newtFormAddComponent(subform, cbInfo[i].comp);
    }

    newtFormSetHeight(subform, listHeight);
    newtFormSetWidth(subform, width - 10);

    newtFormAddComponents(form, tb, subform, NULL);

    addButtons(height, width, form, &okay, &cancel, flags);

    answer = newtRunForm(form);
    if (answer == cancel)
	rc = DLG_CANCEL;

    if (useRadio) {
	answer = newtRadioGetCurrent(cbInfo[0].comp);
	for (i = 0; i < numBoxes; i++) 
	    if (cbInfo[i].comp == answer) {
		*selections = malloc(sizeof(char *) * 2);
		(*selections)[0] = cbInfo[i].tag;
		(*selections)[1] = NULL;
		break;
	    }
    } else {
	numSelected = 0;
	for (i = 0; i < numBoxes; i++) {
	    if (cbStates[i] != ' ') numSelected++;
	}

	*selections = malloc(sizeof(char *) * (numSelected + 1));

	numSelected = 0;
	for (i = 0; i < numBoxes; i++) {
	    if (cbStates[i] != ' ') 
		(*selections)[numSelected++] = cbInfo[i].tag;
	}

	(*selections)[numSelected] = NULL;
    }

    return rc;
}
int listBox(const char * text, int height, int width, poptContext optCon,
		int flags, char ** result) {
    newtComponent form, okay, tb, answer, listBox;
    newtComponent cancel = NULL;
    const char * arg;
    char * end;
    int listHeight;
    int numItems = 0;
    int allocedItems = 5;
    int i, top;
    int rc = DLG_OKAY;
    char buf[80], format[20];
    int maxTagWidth = 0;
    int maxTextWidth = 0;
    int scrollFlag;
    struct {
	const char * text;
	const char * tag;
    } * itemInfo = malloc(allocedItems * sizeof(*itemInfo));

    if (!(arg = poptGetArg(optCon))) return DLG_ERROR;
    listHeight = strtoul(arg, &end, 10);
    if (*end) return DLG_ERROR;

    while ((arg = poptGetArg(optCon))) {
	if (allocedItems == numItems) {
	    allocedItems += 5;
	    itemInfo = realloc(itemInfo, sizeof(*itemInfo) * allocedItems);
	}

	itemInfo[numItems].tag = arg;
	if (!(arg = poptGetArg(optCon))) return DLG_ERROR;

	if (!(flags & FLAG_NOITEM)) {
	    itemInfo[numItems].text = arg;
	} else
	    itemInfo[numItems].text = "";

	if (wstrlen(itemInfo[numItems].text,-1) > (unsigned int)maxTextWidth)
	    maxTextWidth = wstrlen(itemInfo[numItems].text,-1);
	if (wstrlen(itemInfo[numItems].tag,-1) > (unsigned int)maxTagWidth)
	    maxTagWidth = wstrlen(itemInfo[numItems].tag,-1);

	numItems++;
    }

    form = newtForm(NULL, NULL, 0);

    tb = textbox(height - 4 - buttonHeight - listHeight, width - 2,
			text, flags, &top);

    if (listHeight >= numItems) {
	scrollFlag = 0;
	i = 0;
    } else {
	scrollFlag = NEWT_FLAG_SCROLL;
	i = 2;
    }

    listBox = newtListbox(3 + ((width - 10 - maxTagWidth - maxTextWidth - i) 
					/ 2),
			  top + 1, listHeight, 
			    NEWT_FLAG_RETURNEXIT | scrollFlag);

    sprintf(format, "%%-%ds  %%s", maxTagWidth);
    for (i = 0; i < numItems; i++) {
	sprintf(buf, format, itemInfo[i].tag, itemInfo[i].text);
	newtListboxAddEntry(listBox, buf, (void *) i);
    }

    newtFormAddComponents(form, tb, listBox, NULL);

    addButtons(height, width, form, &okay, &cancel, flags);

    answer = newtRunForm(form);
    if (answer == cancel)
	rc = DLG_CANCEL;

    i = (int) newtListboxGetCurrent(listBox);
    *result = itemInfo[i].tag;

    return rc;
}
예제 #14
0
int main(void) {
    newtComponent b1, b2, b3, b4;
    newtComponent answer, f, t;
    newtGrid grid, subgrid;
    char * flowedText;
    int textWidth, textHeight, rc;
    char * menuContents[] = { "One", "Two", "Three", "Four", "Five", NULL };
    char * entries[10];
    struct newtWinEntry autoEntries[] = {
	{ "An entry", entries + 0, 0 },
	{ "Another entry", entries + 1, 0 },
	{ "Third entry", entries + 2, 0 },
	{ "Fourth entry", entries + 3, 0 },
	{ NULL, NULL, 0 } };

    memset(entries, 0, sizeof(entries));

    newtInit();
    newtCls();

    b1 = newtCheckbox(-1, -1, "An pretty long checkbox for testing", ' ', NULL, NULL);
    b2 = newtButton(-1, -1, "Another Button");
    b3 = newtButton(-1, -1, "But, but");
    b4 = newtButton(-1, -1, "But what?");

    f = newtForm(NULL, NULL, 0);

    grid = newtCreateGrid(2, 2);
    newtGridSetField(grid, 0, 0, NEWT_GRID_COMPONENT, b1, 0, 0, 0, 0, 
			NEWT_ANCHOR_RIGHT, 0);
    newtGridSetField(grid, 0, 1, NEWT_GRID_COMPONENT, b2, 0, 0, 0, 0, 0, 0);
    newtGridSetField(grid, 1, 0, NEWT_GRID_COMPONENT, b3, 0, 0, 0, 0, 0, 0);
    newtGridSetField(grid, 1, 1, NEWT_GRID_COMPONENT, b4, 0, 0, 0, 0, 0, 0);


    newtFormAddComponents(f, b1, b2, b3, b4, NULL);

    newtGridWrappedWindow(grid, "first window");
    newtGridFree(grid, 1);

    answer = newtRunForm(f);
	
    newtFormDestroy(f);
    newtPopWindow();

    flowedText = newtReflowText("This is a quite a bit of text. It is 40 "
			  	"columns long, so some wrapping should be "
			  	"done. Did you know that the quick, brown "
			  	"fox jumped over the lazy dog?\n\n"
				"In other news, it's pretty important that we "
				"can properly force a line break.",
				40, 5, 5, &textWidth, &textHeight);
    t = newtTextbox(-1, -1, textWidth, textHeight, NEWT_FLAG_WRAP);
    newtTextboxSetText(t, flowedText);
    free(flowedText);

    
    b1 = newtButton(-1, -1, "Okay");
    b2 = newtButton(-1, -1, "Cancel");

    grid = newtCreateGrid(1, 2);
    subgrid = newtCreateGrid(2, 1);

    newtGridSetField(subgrid, 0, 0, NEWT_GRID_COMPONENT, b1, 0, 0, 0, 0, 0, 0);
    newtGridSetField(subgrid, 1, 0, NEWT_GRID_COMPONENT, b2, 0, 0, 0, 0, 0, 0);

    newtGridSetField(grid, 0, 0, NEWT_GRID_COMPONENT, t, 0, 0, 0, 1, 0, 0);
    newtGridSetField(grid, 0, 1, NEWT_GRID_SUBGRID, subgrid, 0, 0, 0, 0, 0,
			NEWT_GRID_FLAG_GROWX);
    newtGridWrappedWindow(grid, "another example");
    newtGridDestroy(grid, 1);

    f = newtForm(NULL, NULL, 0);
    newtFormAddComponents(f, b1, t, b2, NULL);
    answer = newtRunForm(f);

    newtPopWindow();
    newtFormDestroy(f);

    newtWinMessage("Simple", "Ok", "This is a simple message window");
    newtWinChoice("Simple", "Ok", "Cancel", "This is a simple choice window");

    textWidth = 0;
    rc = newtWinMenu("Test Menu", "This is a sample invovation of the "
		     "newtWinMenu() call. It may or may not have a scrollbar, "
		     "depending on the need for one.", 50, 5, 5, 3, 
		     menuContents, &textWidth, "Ok", "Cancel", NULL);

    rc = newtWinEntries("Text newtWinEntries()", "This is a sample invovation of "
		     "newtWinEntries() call. It lets you get a lot of input "
		     "quite easily.", 50, 5, 5, 20, autoEntries, "Ok", 
		     "Cancel", NULL);

    newtFinished();

    printf("rc = 0x%x item = %d\n", rc, textWidth);

    return 0;
}
예제 #15
0
파일: urls.c 프로젝트: atulyadavtech/kernel
int urlMainSetupPanel(struct iurlinfo * ui, urlprotocol protocol,
                      char * doSecondarySetup) {
    newtComponent form, okay, cancel, siteEntry, dirEntry;
    newtComponent answer, text;
    newtComponent cb = NULL;
    char * site, * dir;
    char * reflowedText = NULL;
    int width, height;
    newtGrid entryGrid, buttons, grid;
    char * chptr;
    char * buf = NULL;

    if (ui->address) {
        site = ui->address;
        dir = ui->prefix;
    } else {
        site = "";
        dir = "";
    }

    if (ui->login || ui->password || ui->proxy || ui->proxyPort)
        *doSecondarySetup = '*';
    else
        *doSecondarySetup = ' ';

    buttons = newtButtonBar(_("OK"), &okay, _("Back"), &cancel, NULL);
    
    switch (protocol) {
    case URL_METHOD_FTP:
        buf = sdupprintf(_(netServerPrompt), _("FTP"), getProductName());
        reflowedText = newtReflowText(buf, 47, 5, 5, &width, &height);
        free(buf);
        break;
    case URL_METHOD_HTTP:
        buf = sdupprintf(_(netServerPrompt), _("Web"), getProductName());
        reflowedText = newtReflowText(buf, 47, 5, 5, &width, &height);
        free(buf);
        break;

#ifdef ROCKS
    case URL_METHOD_HTTPS:
        buf = sdupprintf(_(netServerPrompt), "Secure Web", getProductName());
        reflowedText = newtReflowText(buf, 47, 5, 5, &width, &height);
        free(buf);
        break;
#endif /* ROCKS */
    }
    text = newtTextbox(-1, -1, width, height, NEWT_TEXTBOX_WRAP);
    newtTextboxSetText(text, reflowedText);
    free(reflowedText);

    siteEntry = newtEntry(22, 8, site, 24, (const char **) &site, 
                          NEWT_ENTRY_SCROLL);
    dirEntry = newtEntry(22, 9, dir, 24, (const char **) &dir, 
                         NEWT_ENTRY_SCROLL);

    entryGrid = newtCreateGrid(2, 2);
    newtGridSetField(entryGrid, 0, 0, NEWT_GRID_COMPONENT,
                     newtLabel(-1, -1, (protocol == URL_METHOD_FTP) ?
                                        _("FTP site name:") :
                                        _("Web site name:")),
                     0, 0, 1, 0, NEWT_ANCHOR_LEFT, 0);
    newtGridSetField(entryGrid, 0, 1, NEWT_GRID_COMPONENT,
                     newtLabel(-1, -1, 
                               sdupprintf(_("%s directory:"), 
                                          getProductName())),
                     0, 0, 1, 0, NEWT_ANCHOR_LEFT, 0);
    newtGridSetField(entryGrid, 1, 0, NEWT_GRID_COMPONENT, siteEntry,
                     0, 0, 0, 0, 0, 0);
    newtGridSetField(entryGrid, 1, 1, NEWT_GRID_COMPONENT, dirEntry,
                     0, 0, 0, 0, 0, 0);

    grid = newtCreateGrid(1, 4);
    newtGridSetField(grid, 0, 0, NEWT_GRID_COMPONENT, text,
                     0, 0, 0, 1, 0, 0);
    newtGridSetField(grid, 0, 1, NEWT_GRID_SUBGRID, entryGrid,
                     0, 0, 0, 1, 0, 0);

    if (protocol == URL_METHOD_FTP) {
        cb = newtCheckbox(3, 11, _("Use non-anonymous ftp"),
                          *doSecondarySetup, NULL, doSecondarySetup);
        newtGridSetField(grid, 0, 2, NEWT_GRID_COMPONENT, cb,
                         0, 0, 0, 1, NEWT_ANCHOR_LEFT, 0);
    }
        
    newtGridSetField(grid, 0, 3, NEWT_GRID_SUBGRID, buttons,
                     0, 0, 0, 0, 0, NEWT_GRID_FLAG_GROWX);

    newtGridWrappedWindow(grid, (protocol == URL_METHOD_FTP) ? _("FTP Setup") :
                          _("HTTP Setup"));

    form = newtForm(NULL, NULL, 0);
    newtGridAddComponentsToForm(grid, form, 1);    

    do {
        answer = newtRunForm(form);
        if (answer != cancel) {
            if (!strlen(site)) {
                newtWinMessage(_("Error"), _("OK"),
                               _("You must enter a server name."));
                continue;
            }
            if (!strlen(dir)) {
                newtWinMessage(_("Error"), _("OK"),
                               _("You must enter a directory."));
                continue;
            }

            if (!addrToIp(site)) {
                newtWinMessage(_("Unknown Host"), _("OK"),
                        _("%s is not a valid hostname."), site);
                continue;
            }
        }

        break;
    } while (1);
    
    if (answer == cancel) {
        newtFormDestroy(form);
        newtPopWindow();
        
        return LOADER_BACK;
    }

    if (ui->address) free(ui->address);
    ui->address = strdup(site);

    if (ui->prefix) free(ui->prefix);

    /* add a slash at the start of the dir if it is missing */
    if (*dir != '/') {
        if (asprintf(&(ui->prefix), "/%s", dir) == -1)
            ui->prefix = strdup(dir);
    } else {
        ui->prefix = strdup(dir);
    }

    /* Get rid of trailing /'s */
    chptr = ui->prefix + strlen(ui->prefix) - 1;
    while (chptr > ui->prefix && *chptr == '/') chptr--;
    chptr++;
    *chptr = '\0';

    if (*doSecondarySetup != '*') {
        if (ui->login)
            free(ui->login);
        if (ui->password)
            free(ui->password);
        if (ui->proxy)
            free(ui->proxy);
        if (ui->proxyPort)
            free(ui->proxyPort);
        ui->login = ui->password = ui->proxy = ui->proxyPort = NULL;
    }

    ui->protocol = protocol;

    newtFormDestroy(form);
    newtPopWindow();

    return 0;
}
예제 #16
0
static void
nmt_newt_dialog_g_log_handler (const char     *log_domain,
                               GLogLevelFlags  log_level,
                               const char     *message,
                               gpointer        user_data)
{
	const char *level_name;
	char *full_message;
	int screen_width, screen_height;
	newtComponent text, ok, form;
	newtGrid grid;

	g_assert (!(log_level & G_LOG_FLAG_RECURSION));

	if (log_level & G_LOG_LEVEL_DEBUG)
		return;

	switch (log_level & G_LOG_LEVEL_MASK) {
	case G_LOG_LEVEL_ERROR:
		level_name = "ERROR";
		break;
	case G_LOG_LEVEL_CRITICAL:
		level_name = "CRITICAL";
		break;
	case G_LOG_LEVEL_WARNING:
		level_name = "WARNING";
		break;
	case G_LOG_LEVEL_MESSAGE:
		level_name = "Message";
		break;
	default:
		level_name = NULL;
	}

	full_message = g_strdup_printf ("%s%s%s%s%s",
	                                log_domain ? log_domain : "",
	                                log_domain && level_name ? " " : "",
	                                level_name ? level_name : "",
	                                log_domain || level_name ? ": " : "",
	                                message);

	/* newtWinMessage() wraps the window too narrowly by default, so
	 * we don't want to use that. But we intentionally avoid using any
	 * NmtNewt classes, to avoid possible error recursion.
	 */

	newtGetScreenSize (&screen_width, &screen_height);
	text = newtTextboxReflowed (-1, -1, full_message, MAX (70, screen_width - 10), 0, 0, 0);
	g_free (full_message);

	ok = newtButton (-1, -1, "OK");

	grid = newtCreateGrid (1, 2);
	newtGridSetField (grid, 0, 0, NEWT_GRID_COMPONENT, text, 0, 0, 0, 0, 0, 0);
	newtGridSetField (grid, 0, 1, NEWT_GRID_COMPONENT, ok, 0, 1, 0, 0,
	                  NEWT_ANCHOR_RIGHT, 0);

	newtGridWrappedWindow (grid, (char *) (level_name ? level_name : ""));
	newtGridFree (grid, TRUE);

	form = newtForm (NULL, NULL, 0);
	newtFormAddComponents (form, text, ok, NULL);
	newtRunForm (form);
	newtFormDestroy (form);
	newtPopWindow ();
}
/**
 * Ask the user which backup media type they would like to use.
 * The choices are @p none (exit to shell), @c cdr, @c cdrw, @c dvd,
 * @c tape, @c cdstream, @c udev (only when @p g_text_mode is TRUE), @c nfs,
 * and @c iso.
 * @param restoring TRUE if we're restoring, FALSE if we're backing up.
 * @return The backup type chosen, or @c none if the user chose "Exit to shell".
 */
	t_bkptype which_backup_media_type(bool restoring) {

		/*@ char ************************************************************ */
		t_bkptype output;


		/*@ newt ************************************************************ */
		char *title_sz;
		char *minimsg_sz;
		static t_bkptype possible_bkptypes[] =
			{ none, cdr, cdrw, dvd, tape, cdstream, udev, nfs, iso };
		static char *possible_responses[] =
			{ "none", "cdr", "cdrw", "dvd", "tape", "cdstream", "udev",
			"nfs", "iso", NULL
		};
		char *outstr = NULL;
		t_bkptype backup_type;
		int i;
		size_t n = 0;

		newtComponent b1;
		newtComponent b2;
		newtComponent b3;
		newtComponent b4;
		newtComponent b5;
		newtComponent b6;
		newtComponent b7;
		newtComponent b8;
		newtComponent b_res;
		newtComponent myForm;

		if (g_text_mode) {
			for (backup_type = none; backup_type == none;) {
				printf(_("Backup type ("));
				for (i = 0; possible_responses[i]; i++) {
					printf("%c%s", (i == 0) ? '\0' : ' ',
						   possible_responses[i]);
				}
				printf(")\n--> ");
				(void) getline(&outstr, &n, stdin);
				strip_spaces(outstr);
				for (i = 0; possible_responses[i]; i++) {
					if (!strcmp(possible_responses[i], outstr)) {
						backup_type = possible_bkptypes[i];
					}
				}
			}
			paranoid_free(outstr);
			return (backup_type);
		}
		newtDrawRootText(18, 0, WELCOME_STRING);
		if (restoring) {
			asprintf(&title_sz,
					 _("Please choose the backup media from which you want to read data."));
			asprintf(&minimsg_sz, _("Read from:"));
		} else {
			asprintf(&title_sz,
					 _("Please choose the backup media to which you want to archive data."));
			asprintf(&minimsg_sz, _("Backup to:"));
		}
		newtPushHelpLine(title_sz);
		paranoid_free(title_sz);

		//  newtOpenWindow (23, 3, 34, 17, minimsg_sz);
		newtCenteredWindow(34, 17, minimsg_sz);
		paranoid_free(minimsg_sz);

		b1 = newtButton(1, 1, _("CD-R disks "));
		b2 = newtButton(17, 1, _("CD-RW disks"));
		b3 = newtButton(1, 9, _("Tape drive "));
		b4 = newtButton(17, 5, _("CD streamer"));
		b5 = newtButton(1, 5, _(" DVD disks "));
		b6 = newtButton(17, 9, _(" NFS mount "));
		b7 = newtButton(1, 13, _(" Hard disk "));
		b8 = newtButton(17, 13, _("    Exit   "));
		myForm = newtForm(NULL, NULL, 0);
		newtFormAddComponents(myForm, b1, b5, b3, b7, b2, b4, b6, b8,
							  NULL);
		b_res = newtRunForm(myForm);
		newtFormDestroy(myForm);
		newtPopWindow();
		if (b_res == b1) {
			output = cdr;
		} else if (b_res == b2) {
			output = cdrw;
		} else if (b_res == b3) {
			output = tape;
		} else if (b_res == b4) {
			output = cdstream;
		} else if (b_res == b5) {
			output = dvd;
		} else if (b_res == b6) {
			output = nfs;
		} else if (b_res == b7) {
			output = iso;
		} else {
			output = none;
		}
		newtPopHelpLine();
		return (output);
	}
/**
 * Pop up a list containing the filenames in @p source_file and the severity if they have changed since the
 * last backup. There can be no more than @p ARBITRARY_MAXIMUM files in @p source_file.
 * @param source_file The file containing a list of changed files.
 */
	void popup_changelist_from_file(char *source_file) {
		char *reason = NULL;
		newtComponent myForm;
		newtComponent bClose;
		newtComponent bSelect;
		newtComponent b_res;
		newtComponent fileListbox;
		newtComponent headerMsg;

		/*@ ???? ************************************************************ */
		void *curr_choice;
		void *keylist[ARBITRARY_MAXIMUM];

		/*@ int ************************************************************* */
		int i = 0;
		int currline = 0;
		int finished = FALSE;
		long lng = 0;

		/*@ buffers ********************************************************* */
		char *tmp;
		char *differ_sz;

		struct s_filelist *filelist;
		assert_string_is_neither_NULL_nor_zerolength(source_file);
		if (g_text_mode) {
			log_msg(2, "Text mode. Therefore, no popup list.");
			return;
		}
		log_msg(2, "Examining file %s", source_file);

		lng = count_lines_in_file(source_file);
		if (lng < 1) {
			log_msg(2, "No lines in file. Therefore, no popup list.");
			return;
		} else if (lng >= ARBITRARY_MAXIMUM) {
			log_msg(2, "Too many files differ for me to list.");
			return;
		}

		filelist = (struct s_filelist *) malloc(sizeof(struct s_filelist));
		fileListbox =
			newtListbox(2, 2, 12, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT);
		newtListboxClear(fileListbox);

		if (load_filelist_into_array(filelist, source_file)) {
			log_msg(2, "Can't open %s; therefore, cannot popup list",
					source_file);
			return;
		}
		log_msg(2, "%d files loaded into filelist array",
				filelist->entries);
		for (i = 0; i < filelist->entries; i++) {
			keylist[i] = (void *) i;
			newtListboxAppendEntry(fileListbox,
								   filelist_entry_to_string(&
															(filelist->
															 el[i])),
								   keylist[i]);
		}
		asprintf(&differ_sz,
				 _("  %d files differ. Hit 'Select' to pick a file. Hit 'Close' to quit the list."),
				 i);
		newtPushHelpLine(differ_sz);
		paranoid_free(differ_sz);

		bClose = newtCompactButton(10, 15, _(" Close  "));
		bSelect = newtCompactButton(30, 15, _(" Select "));
		asprintf(&tmp, "%-10s               %-20s", _("Priority"),
				 _("Filename"));
		headerMsg = newtLabel(2, 1, tmp);
		paranoid_free(tmp);

		newtOpenWindow(5, 4, 70, 16, _("Non-matching files"));
		myForm = newtForm(NULL, NULL, 0);
		newtFormAddComponents(myForm, headerMsg, fileListbox, bClose,
							  bSelect, NULL);
		while (!finished) {
			b_res = newtRunForm(myForm);
			if (b_res == bClose) {
				finished = TRUE;
			} else {
				curr_choice = newtListboxGetCurrent(fileListbox);
				for (i = 0;
					 i < filelist->entries && keylist[i] != curr_choice;
					 i++);
				if (i == filelist->entries && filelist->entries > 0) {
					log_to_screen(_("I don't know what that button does!"));
				} else {
					currline = i;
					if (filelist->entries > 0) {
						severity_of_difference(filelist->el[currline].
											   filename, reason);
						asprintf(&tmp, "%s --- %s",
								 filelist->el[currline].filename, reason);
						popup_and_OK(tmp);
						paranoid_free(tmp);
						paranoid_free(reason);
					}
				}
			}
		}
		newtFormDestroy(myForm);
		newtPopWindow();
		newtPopHelpLine();
	}
/**
 * Ask the user to enter a value.
 * @param title The title of the dialog box.
 * @param b The blurb (e.g. what you want the user to enter).
 * @param output The string to put the user's answer in. It has to be freed by the caller
 * @return TRUE if the user pressed OK, FALSE if they pressed Cancel.
 */
	bool popup_and_get_string(char *title, char *b, char *output) {

		/*@ newt ************************************************************ */
		newtComponent myForm;
		newtComponent b_1;
		newtComponent b_2;
		newtComponent b_res;
		newtComponent text;
		newtComponent type_here;

		/*@ pointers ********************************************************* */
		char *entry_value = NULL;

		/*@ buffers ********************************************************** */
		char *blurb = NULL;
		size_t n = 0;
		bool ret = TRUE;

		assert_string_is_neither_NULL_nor_zerolength(title);
		assert(b != NULL);

		if (g_text_mode) {
			printf
				("---promptstring---1--- %s\r\n---promptstring---2--- %s\r\n---promptstring---Q---\r\n-->  ",
				 title, b);
			paranoid_free(output);
			(void) getline(&output, &n, stdin);
			if (output[strlen(output) - 1] == '\n')
				output[strlen(output) - 1] = '\0';
			return (ret);
		}
		asprintf(&blurb, b);
		text = newtTextboxReflowed(2, 1, blurb, 48, 5, 5, 0);

		type_here =
			newtEntry(2, newtTextboxGetNumLines(text) + 2,
					  output, 50,
					  &entry_value, NEWT_FLAG_RETURNEXIT
			);
		b_1 = newtButton(6, newtTextboxGetNumLines(text) + 4, _("  OK  "));
		b_2 = newtButton(18, newtTextboxGetNumLines(text) + 4, _("Cancel"));
		newtCenteredWindow(54, newtTextboxGetNumLines(text) + 9, title);
		myForm = newtForm(NULL, NULL, 0);
		newtFormAddComponents(myForm, text, type_here, b_1, b_2, NULL);
		/* BERLIOS: center_string is now broken replace it ! */
		//center_string(blurb, 80);
		newtPushHelpLine(blurb);
		paranoid_free(blurb);

		b_res = newtRunForm(myForm);
		newtPopHelpLine();
		if (b_res == b_2) {
			ret = FALSE;
		} else {
			// Copy entry_value before destroying the form
			// clearing potentially output before
			paranoid_alloc(output,entry_value);
		}
		newtFormDestroy(myForm);
		newtPopWindow();
		return(ret);
	}
예제 #20
0
static int newtChecklist(const char* title, const char* message,
		unsigned int width, unsigned int height, unsigned int num_entries,
		const char** entries, int* states) {
	int ret;
	const int list_height = 4;

	char cbstates[num_entries];

	for (unsigned int i = 0; i < num_entries; i++) {
		cbstates[i] = states[i] ? '*' : ' ';
	}

	newtCenteredWindow(width, height, title);

	newtComponent textbox = newtTextbox(1, 1, width - 2, height - 6 - list_height,
		NEWT_FLAG_WRAP);
	newtTextboxSetText(textbox, message);

	int top = newtTextboxGetNumLines(textbox) + 2;

	newtComponent form = newtForm(NULL, NULL, 0);

	newtComponent sb = NULL;
	if (list_height < num_entries) {
		sb = newtVerticalScrollbar(
			width - 4, top + 1, list_height,
			NEWT_COLORSET_CHECKBOX, NEWT_COLORSET_ACTCHECKBOX);

		newtFormAddComponent(form, sb);
	}

	newtComponent subform = newtForm(sb, NULL, 0);
	newtFormSetBackground(subform, NEWT_COLORSET_CHECKBOX);

	newtFormSetHeight(subform, list_height);
	newtFormSetWidth(subform, width - 10);

	for (unsigned int i = 0; i < num_entries; i++) {
		newtComponent cb = newtCheckbox(4, top + i, entries[i], cbstates[i],
			NULL, &cbstates[i]);

		newtFormAddComponent(subform, cb);
	}

	newtFormAddComponents(form, textbox, subform, NULL);

	newtComponent btn_okay   = newtButton((width - 18) / 3, height - 4, _("OK"));
	newtComponent btn_cancel = newtButton((width - 18) / 3 * 2 + 9, height - 4, _("Cancel"));
	newtFormAddComponents(form, btn_okay, btn_cancel, NULL);

	newtComponent answer = newtRunForm(form);

	if ((answer == NULL) || (answer == btn_cancel)) {
		ret = -1;
	} else {
		ret = 0;

		for (unsigned int i = 0; i < num_entries; i++) {
			states[i] = (cbstates[i] != ' ');

			if (states[i])
				ret++;
		}
	}

	newtFormDestroy(form);
	newtPopWindow();

	return ret;
}
/**
 * Pop up a dialog box with user-defined buttons.
 * @param p The text to put in the dialog box.
 * @param button1 The label on the first button.
 * @param button2 The label on the second button, or "" if you only want one button.
 * @return TRUE if @p button1 was pushed, FALSE otherwise.
 */
	bool popup_with_buttons(char *p, char *button1, char *button2) {

		/*@ buffers *********************************************************** */
		char *prompt;
		char *tmp = NULL;
		size_t n = 0;

		/*@ newt ************************************************************** */
		newtComponent myForm;
		newtComponent b_1;
		newtComponent b_2;
		newtComponent b_res;
		newtComponent text;

		assert_string_is_neither_NULL_nor_zerolength(p);
		assert(button1 != NULL);
		assert(button2 != NULL);
		if (g_text_mode) {
			if (strlen(button2) == 0) {
				printf("%s (%s) --> ", p, button1);
			} else {
				printf("%s (%s or %s) --> ", p, button1, button2);
			}
			for (asprintf(&tmp, " ");
				 strcmp(tmp, button1) && (strlen(button2) == 0
										  || strcmp(tmp, button2));) {
				printf("--> ");
				paranoid_free(tmp);
				(void) getline(&tmp, &n, stdin);
			}
			if (!strcmp(tmp, button1)) {
				paranoid_free(tmp);
				return (TRUE);
			} else {
				paranoid_free(tmp);
				return (FALSE);
			}
		}

		asprintf(&prompt, p);
		text = newtTextboxReflowed(1, 1, prompt, 40, 5, 5, 0);
		b_1 =
			newtButton(20 -
					   ((button2[0] !=
						 '\0') ? strlen(button1) +
						2 : strlen(button1) / 2),
					   newtTextboxGetNumLines(text) + 3, button1);
		if (button2[0] != '\0') {
			b_2 =
				newtButton(24, newtTextboxGetNumLines(text) + 3, button2);
		} else {
			b_2 = NULL;
		}
		//  newtOpenWindow (25, 5, 46, newtTextboxGetNumLines (text) + 7, "Alert");
		newtCenteredWindow(46, newtTextboxGetNumLines(text) + 7, _("Alert"));
		myForm = newtForm(NULL, NULL, 0);
		newtFormAddComponents(myForm, text, b_1, b_2, NULL);
		/* BERLIOS: center_string is now broken replace it ! */
		//center_string(prompt, 80);
		newtPushHelpLine(prompt);
		paranoid_free(prompt);
		b_res = newtRunForm(myForm);
		newtPopHelpLine();
		newtFormDestroy(myForm);
		newtPopWindow();
		if (b_res == b_1) {
			return (TRUE);
		} else {
			return (FALSE);
		}
	}
예제 #22
0
파일: urls.c 프로젝트: atulyadavtech/kernel
int urlSecondarySetupPanel(struct iurlinfo * ui, urlprotocol protocol) {
    newtComponent form, okay, cancel, answer, text, accountEntry = NULL;
    newtComponent passwordEntry = NULL, proxyEntry = NULL;
    newtComponent proxyPortEntry = NULL;
    char * account, * password, * proxy, * proxyPort;
    newtGrid buttons, entryGrid, grid;
    char * reflowedText = NULL;
    int width, height;

    if (protocol == URL_METHOD_FTP) {
        reflowedText = newtReflowText(
        _("If you are using non anonymous ftp, enter the account name and "
          "password you wish to use below."),
        47, 5, 5, &width, &height);
    } else {
        reflowedText = newtReflowText(
        _("If you are using a HTTP proxy server "
          "enter the name of the HTTP proxy server to use."),
        47, 5, 5, &width, &height);
    }
    text = newtTextbox(-1, -1, width, height, NEWT_TEXTBOX_WRAP);
    newtTextboxSetText(text, reflowedText);
    free(reflowedText);

    if (protocol == URL_METHOD_FTP) {
        accountEntry = newtEntry(-1, -1, NULL, 24, (const char **) &account, 
                                 NEWT_FLAG_SCROLL);
        passwordEntry = newtEntry(-1, -1, NULL, 24, (const char **) &password, 
                                  NEWT_FLAG_SCROLL | NEWT_FLAG_PASSWORD);
    }
    proxyEntry = newtEntry(-1, -1, ui->proxy, 24, (const char **) &proxy, 
                           NEWT_ENTRY_SCROLL);
    proxyPortEntry = newtEntry(-1, -1, ui->proxyPort, 6, 
                               (const char **) &proxyPort, NEWT_FLAG_SCROLL);

    entryGrid = newtCreateGrid(2, 4);
    if (protocol == URL_METHOD_FTP) {
        newtGridSetField(entryGrid, 0, 0, NEWT_GRID_COMPONENT,
                     newtLabel(-1, -1, _("Account name:")),
                     0, 0, 2, 0, NEWT_ANCHOR_LEFT, 0);
        newtGridSetField(entryGrid, 0, 1, NEWT_GRID_COMPONENT,
                     newtLabel(-1, -1, _("Password:"******"OK"), &okay, _("Back"), &cancel, NULL);

    grid = newtCreateGrid(1, 3);
    newtGridSetField(grid, 0, 0, NEWT_GRID_COMPONENT, text, 0, 0, 0, 0, 0, 0);
    newtGridSetField(grid, 0, 1, NEWT_GRID_SUBGRID, entryGrid, 
                     0, 1, 0, 0, 0, 0);
    newtGridSetField(grid, 0, 2, NEWT_GRID_SUBGRID, buttons, 
                     0, 1, 0, 0, 0, NEWT_GRID_FLAG_GROWX);

    if (protocol == URL_METHOD_FTP) {
        newtGridWrappedWindow(grid, _("Further FTP Setup"));
    } else {
        if (protocol == URL_METHOD_HTTP)
            newtGridWrappedWindow(grid, _("Further HTTP Setup"));
    }

    form = newtForm(NULL, NULL, 0);
    newtGridAddComponentsToForm(grid, form, 1);
    newtGridFree(grid, 1);

    answer = newtRunForm(form);
    if (answer == cancel) {
        newtFormDestroy(form);
        newtPopWindow();
        
        return LOADER_BACK;
    }
 
    if (protocol == URL_METHOD_FTP) {
        if (ui->login) free(ui->login);
        if (strlen(account))
            ui->login = strdup(account);
        else
            ui->login = NULL;
        
        if (ui->password) free(ui->password);
        if (strlen(password))
            ui->password = strdup(password);
        else
            ui->password = NULL;
    }
    
    newtFormDestroy(form);
    newtPopWindow();

    return 0;
}
예제 #23
0
void play_wav_file(char *filename)
{
   char *inwavbuf;
   short *current;
   short *audioend;
   short *audio;
   WAVE_HEADER *wav_info;
   int wavfd;
   int dspfd;
   struct stat input_fstat;
   size_t interval;

   newtComponent vu_1sec;
   newtComponent vu_total;
   newtComponent wav_length;
   newtComponent label_length;
   newtComponent mainwaveform;
   newtComponent label_1sec;
   newtComponent label_total;
   newtComponent rf_result;

   char labelstr_1sec[10] = "0";
   char labelstr_total[10] = "0";
   char labelstr_length[10] = "";
   short one_sec_max, total_max;

   wavfd = open(filename,O_RDONLY,0600);
   if (wavfd == -1)
   {
      printf("Error: open() %s\n",strerror(errno));
      exit(1);
   }

   if (fstat(wavfd,&input_fstat) != 0)
   {
      printf("Error: fstat() %s\n",strerror(errno));
      return;
   }

   if (input_fstat.st_size < sizeof(WAVE_HEADER))
   {
      printf("File is not large enough to hold a .wav file header even!\n");
      return;
   }


   inwavbuf = mmap(NULL,input_fstat.st_size,PROT_READ,MAP_SHARED,wavfd,0);
   if (inwavbuf == MAP_FAILED)
   {
      printf("Error: mmap() %s\n",strerror(errno));
      exit(1);
   }


   audio = (short *)validate_wav_header(inwavbuf,0);
   current = audio;

   if (current == NULL)
   {
      printf("This program didn't like the wav file\n");
      exit(1);
   }

   wav_info = (WAVE_HEADER *)inwavbuf;
   audioend =  (short *)((char *)audio + wav_info->nDataBytes);

   dspfd = open_dsp(wav_info);

   newtCls();

   newtDrawRootText(0, 0, filename);
   mainwaveform = newtForm(NULL, NULL,  NEWT_FLAG_NOF12);
   vu_1sec    =  newtScale(9,5,68,(long long)(SHRT_MAX));
   label_1sec =  newtLabel(1,5,labelstr_1sec);
   wav_length  =  newtScale(9,3,68,audioend - audio);
   label_length = newtLabel(1,3,labelstr_length);
   vu_total =  newtScale(9,8,68,(long long)(SHRT_MAX));
   label_total =  newtLabel(1,8,labelstr_total);
   
   newtFormAddComponent(mainwaveform,vu_1sec);
   newtFormAddComponent(mainwaveform,vu_total);
   newtFormAddComponent(mainwaveform,label_1sec);
   newtFormAddComponent(mainwaveform,label_total);

   one_sec_max = 0;
   total_max = 0;
   newtFormWatchFd(mainwaveform,dspfd,NEWT_FD_WRITE); 
   newtFormAddHotKey(mainwaveform,NEWT_KEY_ENTER);
   newtPushHelpLine("Hit Enter to end playing");
   newtCenteredWindow(78,10,"now playing .wav file");

   newtRefresh();

   /* presently every second */
   interval = (size_t )((double )wav_info->nSamplesPerSec * interval_s * 2);

   while ((current) < audioend)
   {
      short *endcurrent = current + interval;

      if (endcurrent > audioend)
      {
         endcurrent = audioend;
      }
         
      one_sec_max = get_peak_value(current,endcurrent);
      newtScaleSet(vu_1sec,one_sec_max);
      sprintf(labelstr_1sec,"%1.6f",((float )one_sec_max/ (float )SHRT_MAX));
      newtLabelSetText(label_1sec,labelstr_1sec);
      newtScaleSet(wav_length,current - audio);
      sprintf(labelstr_length,"%4.2f",
         ((double )(current - audio) / 88200));
      newtLabelSetText(label_length,labelstr_length);
      if (one_sec_max > total_max)
      {
         total_max = one_sec_max;
         sprintf(labelstr_total,"%1.6f",((float )total_max/ (float )SHRT_MAX));
         newtLabelSetText(label_total,labelstr_total);
         newtScaleSet(vu_total,total_max);
      }
      rf_result = newtRunForm(mainwaveform);
      if (play_buffer(dspfd,current,endcurrent) == -1)
      {
         current = audioend;
      }
      
      current = endcurrent;
      if (rf_result == NULL)
         current = audioend;

      newtRefresh();
   }

   newtFormDestroy(mainwaveform);

   munmap(inwavbuf,input_fstat.st_size);
   close(wavfd);               
   close(dspfd);
      
   return;
}