Ejemplo n.º 1
0
Archivo: ncce.c Proyecto: bmybbs/bmybbs
int
do_dict()
{
	newtComponent form, label, entry, text;
	struct newtExitStruct es;
	char *entryValue, *wordlist;
	newtCenteredWindow(70, 20, NULL);

	newtPushHelpLine("输入要查找的词,回车确定,上下键滚动,^C退出");
	label = newtLabel(2, 1, "请输入要查找的词");
	entry = newtEntry(2, 2, "", 40, &entryValue,
			  NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT);
	text = newtTextbox(2, 3, 66, 17, NEWT_FLAG_WRAP | NEWT_FLAG_SCROLL);
	newtTextboxSetText(text, "");
	form = newtForm(NULL, NULL, 0);
	newtFormAddHotKey(form, Ctrl('c'));
	newtFormAddHotKey(form, Ctrl('\r'));
	newtFormAddHotKey(form, Ctrl('\n'));
	newtFormAddComponents(form, label, entry, text, NULL);
	while (1) {
		newtFormRun(form, &es);
		if ((es.u.key == Ctrl('c')
		     || es.u.key == NEWT_KEY_F12)
		    && es.reason == NEWT_EXIT_HOTKEY)
			break;
		wordlist = search_dict(entryValue);
		newtTextboxSetText(text, wordlist);
	}
	newtFormDestroy(form);
	newtPopHelpLine();
	newtPopWindow();
	return 0;
}
Ejemplo n.º 2
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;
}
Ejemplo n.º 3
0
/*
  Create and show newt Window, but return form component instead of destroying,
  makes easy to add for example scale component.
*/
void *statuswindow_progress(int width, int height, char *title, char *text, ...)
{
    newtComponent t;
    char *buf = NULL;
    int size = 0;
    int i = 0;
    va_list args;

    va_start(args, text);

    do {
        size += 1000;
        if (buf)
            free(buf);
        buf = malloc(size);
        i = vsnprintf(buf, size, text, args);
    } while (i == size);

    va_end(args);

    newtCenteredWindow(width, height, title);

    t = newtTextbox(1, 1, width - 2, height - 2, NEWT_TEXTBOX_WRAP);
    newtTextboxSetText(t, buf);
    f_progress = newtForm(NULL, NULL, 0);

    free(buf);

    newtFormAddComponent(f_progress, t);

    newtDrawForm(f_progress);
    newtRefresh();

    return &f_progress;
}
static newtComponent textbox(int maxHeight, int width, const char * text,
			int flags, int * height) {
    newtComponent tb;
    int sFlag = (flags & FLAG_SCROLL_TEXT) ? NEWT_FLAG_SCROLL : 0;
    int i;
    char * buf, * dst;
    const char * src;

    dst = buf = alloca(strlen(text) + 1);
    src = text; 
    while (*src) {
	if (*src == '\\' && *(src + 1) == 'n') {
	    src += 2;
	    *dst++ = '\n';
	} else
	    *dst++ = *src++;
    }
    *dst++ = '\0';

    tb = newtTextbox(1, 0, width, maxHeight, NEWT_FLAG_WRAP | sFlag);
    newtTextboxSetText(tb, buf);

    i = newtTextboxGetNumLines(tb);
    if (i < maxHeight) {
	newtTextboxSetHeight(tb, i);
	maxHeight = i;
    }

    *height = maxHeight;

    return tb;
}
Ejemplo n.º 5
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;
}
Ejemplo n.º 6
0
void winStatus(int width, int height, char * title, char * text, ...) {
    newtComponent t, f;
    char * buf = NULL;
    va_list args;

    va_start(args, text);

    if (vasprintf(&buf, text, args) != -1) {
        newtCenteredWindow(width, height, title);

        t = newtTextbox(1, 1, width - 2, height - 2, NEWT_TEXTBOX_WRAP);
        newtTextboxSetText(t, buf);
        f = newtForm(NULL, NULL, 0);

        free(buf);

        newtFormAddComponent(f, t);

        newtDrawForm(f);
        newtRefresh();
        newtFormDestroy(f);
    }

    va_end(args);
}
Ejemplo n.º 7
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;
}
Ejemplo n.º 8
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);
}
Ejemplo n.º 9
0
newtComponent newtTextboxReflowed(int left, int top, char * text, int width,
                                  int flexDown, int flexUp, int flags) {
    newtComponent co;
    char * reflowedText;
    int actWidth, actHeight;

    reflowedText = newtReflowText(text, width, flexDown, flexUp,
                                  &actWidth, &actHeight);

    co = newtTextbox(left, top, actWidth, actHeight, NEWT_FLAG_WRAP);
    newtTextboxSetText(co, reflowedText);
    free(reflowedText);

    return co;
}
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;
}
Ejemplo n.º 11
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;
}
Ejemplo n.º 12
0
int ui__help_window(const char *text)
{
	struct newtExitStruct es;
	newtComponent tb, form = newt_form__new();
	int rc = -1;
	int max_len = 0, nr_lines = 0;
	const char *t;

	if (form == NULL)
		return -1;

	t = text;
	while (1) {
		const char *sep = strchr(t, '\n');
		int len;

		if (sep == NULL)
			sep = strchr(t, '\0');
		len = sep - t;
		if (max_len < len)
			max_len = len;
		++nr_lines;
		if (*sep == '\0')
			break;
		t = sep + 1;
	}

	tb = newtTextbox(0, 0, max_len, nr_lines, 0);
	if (tb == NULL)
		goto out_destroy_form;

	newtTextboxSetText(tb, text);
	newtFormAddComponent(form, tb);
	newtCenteredWindow(max_len, nr_lines, NULL);
	newtFormRun(form, &es);
	newtPopWindow();
	rc = 0;
out_destroy_form:
	newtFormDestroy(form);
	return rc;
}
Ejemplo n.º 13
0
void vwait_message_newt(const char *msg, va_list ap)
{
	int width, height;
	const char title[] = "Please wait...";
	newtComponent c, f;
	newtGrid grid;
	char * buf = NULL;
	char * flowed;
	int size = 0;
	int i = 0;
	
	do {
		size += 1000;
		if (buf) free(buf);
		buf = (char*)malloc(size);
		i = vsnprintf(buf, size, msg, ap);
	} while (i >= size || i == -1);

	flowed = newtReflowText(buf, 60, 5, 5, &width, &height);
	
	c = newtTextbox(-1, -1, width, height, NEWT_TEXTBOX_WRAP);
	newtTextboxSetText(c, flowed);

	grid = newtCreateGrid(1, 1);
	newtGridSetField(grid, 0, 0, NEWT_GRID_COMPONENT, c, 0, 0, 0, 0, 0, 0);
	newtGridWrappedWindow(grid, (char*)title);

	free(flowed);
	free(buf);

	f = newtForm(NULL, NULL, 0);
	newtFormAddComponent(f, c);

	newtDrawForm(f);
	newtRefresh();
	newtFormDestroy(f);
}
Ejemplo n.º 14
0
struct progressCBdata *winProgressBar(int width, int height, char *title, char *text, ...) {
    struct progressCBdata *data;
    char *buf = NULL;
    va_list args;
    int llen;
    newtComponent t, f, scale, label;

    va_start(args, text);

    if (vasprintf(&buf, text, args) != -1) {
        va_end(args);
        newtCenteredWindow(width, height, title);
        t = newtTextbox(1, 1, width - 2, height - 2, NEWT_TEXTBOX_WRAP);
        newtTextboxSetText(t, buf);
        llen = strlen(buf);
        free(buf);
        label = newtLabel(llen + 1, 1, "-");
        f = newtForm(NULL, NULL, 0);
        newtFormAddComponent(f, t);
        scale = newtScale(3, 3, width - 6, 100);
        newtFormAddComponent(f, scale);
        newtDrawForm(f);
        newtRefresh();

        if ((data = malloc(sizeof(struct progressCBdata))) == NULL) {
            logMessage(ERROR, "%s: %d: %m", __func__, __LINE__);
            abort();
        }

        data->scale = scale;
        data->label = label;
        return data;
    }

    return NULL;
}
Ejemplo n.º 15
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;
}
Ejemplo n.º 16
0
int main(void) {
    newtComponent b1, b2, r1, r2, r3, e2, e3, l1, l2, l3, scale;
    newtComponent lb, t, rsf, answer, timeLabel;
    newtComponent cs[10];
    newtComponent f, chklist, e1;
    struct callbackInfo cbis[3];
    char results[10];
    char * enr2, * enr3, * scaleVal;
    void ** selectedList;
    int i, numsel;
    char buf[20];
    const char * spinner = "-\\|/\\|/";
    const char * spinState;
    struct newtExitStruct es;

    newtInit();
    newtCls();

    newtSetSuspendCallback(suspend, NULL);
    newtSetHelpCallback(helpCallback);

    newtDrawRootText(0, 0, "Newt test program");
    newtPushHelpLine(NULL);
    newtDrawRootText(-50, 0, "More root text");

    newtOpenWindow(2, 2, 30, 10, "first window");
    newtOpenWindow(10, 5, 65, 16, "window 2");

    f = newtForm(NULL, "This is some help text", 0);
    chklist = newtForm(NULL, NULL, 0);

    b1 = newtButton(3, 1, "Exit");
    b2 = newtButton(18, 1, "Update");
    r1 = newtRadiobutton(20, 10, "Choice 1", 0, NULL);
    r2 = newtRadiobutton(20, 11, "Chc 2", 1, r1);
    r3 = newtRadiobutton(20, 12, "Choice 3", 0, r2);
    rsf = newtForm(NULL, NULL, 0);
    newtFormAddComponents(rsf, r1, r2, r3, NULL);
    newtFormSetBackground(rsf, NEWT_COLORSET_CHECKBOX);

    for (i = 0; i < 10; i++) {
	sprintf(buf, "Check %d", i);
	cs[i] = newtCheckbox(3, 10 + i, buf, ' ', NULL, &results[i]);
	newtFormAddComponent(chklist, cs[i]);
    }

    l1 = newtLabel(3, 6, "Scale:");
    l2 = newtLabel(3, 7, "Scrolls:");
    l3 = newtLabel(3, 8, "Hidden:");
    e1 = newtEntry(12, 6, "", 20, &scaleVal, 0);
    e2 = newtEntry(12, 7, "Default", 20, &enr2, NEWT_FLAG_SCROLL);
/*    e3 = newtEntry(12, 8, NULL, 20, &enr3, NEWT_FLAG_HIDDEN); */
    e3 = newtEntry(12, 8, NULL, 20, &enr3, NEWT_FLAG_PASSWORD);

    cbis[0].state = &results[0];
    cbis[0].en = e1;
    newtComponentAddCallback(cs[0], disableCallback, &cbis[0]);

    scale = newtScale(3, 14, 32, 100);

    newtFormSetHeight(chklist, 3);

    newtFormAddComponents(f, b1, b2, l1, l2, l3, e1, e2, e3, chklist, NULL);
    newtFormAddComponents(f, rsf, scale, NULL);

    lb = newtListbox(45, 1, 6, NEWT_FLAG_MULTIPLE | NEWT_FLAG_BORDER |
				NEWT_FLAG_SCROLL | NEWT_FLAG_SHOWCURSOR);
    newtListboxAppendEntry(lb, "First", (void *) 1);
    newtListboxAppendEntry(lb, "Second", (void *) 2);
    newtListboxAppendEntry(lb, "Third", (void *) 3);
    newtListboxAppendEntry(lb, "Fourth", (void *) 4);
    newtListboxAppendEntry(lb, "Sixth", (void *) 6);
    newtListboxAppendEntry(lb, "Seventh", (void *) 7);
    newtListboxAppendEntry(lb, "Eighth", (void *) 8);
    newtListboxAppendEntry(lb, "Ninth", (void *) 9);
    newtListboxAppendEntry(lb, "Tenth", (void *) 10);

    newtListboxInsertEntry(lb, "Fifth", (void *) 5, (void *) 4);
    newtListboxInsertEntry(lb, "Eleventh", (void *) 11, (void *) 10);
    newtListboxDeleteEntry(lb, (void *) 11);

    spinState = spinner;
    timeLabel = newtLabel(45, 8, "Spinner: -");

    t = newtTextbox(45, 10, 17, 5, NEWT_FLAG_WRAP);
    newtTextboxSetText(t, "This is some text does it look okay?\nThis should be alone.\nThis shouldn't be printed");

    newtFormAddComponents(f, lb, timeLabel, t, NULL);
    newtRefresh();
    newtFormSetTimer(f, 200);

    do {
	newtFormRun(f, &es);

	if (es.reason == NEWT_EXIT_COMPONENT && es.u.co == b2) {
	    newtScaleSet(scale, atoi(scaleVal));
	    newtRefresh();
	    answer = NULL;
	} else if (es.reason == NEWT_EXIT_TIMER) {
	    spinState++;
	    if (!*spinState) spinState = spinner;
	    sprintf(buf, "Spinner: %c", *spinState);
	    newtLabelSetText(timeLabel, buf);
	}
    } while (es.reason != NEWT_EXIT_COMPONENT || es.u.co == b2);

    scaleVal = strdup(scaleVal);
    enr2 = strdup(enr2);
    enr3 = strdup(enr3);

    selectedList = newtListboxGetSelection(lb, &numsel);

    newtFormDestroy(f);

    newtPopWindow();
    newtPopWindow();
    newtFinished();

    printf("got string 1: %s\n", scaleVal);
    printf("got string 2: %s\n", enr2);
    printf("got string 3: %s\n", enr3);

    if(selectedList) {
	printf("\nSelected listbox items:\n");
	for(i = 0; i < numsel; i++)
	    puts(selectedList[i]);
    }

    return 0;
}
Ejemplo n.º 17
0
static void show_bits(int span, newtComponent bitbox, newtComponent inuse, newtComponent levels, newtComponent bpvcount,
						newtComponent alarms, newtComponent syncsrc, newtComponent irqmisses)
{
	DAHDI_PARAMS zp;
	int x;
	int res;
	char c;
	char tabits[80];
	char tbbits[80];
	char tcbits[80];
	char tdbits[80];
	char rabits[80];
	char rbbits[80];
	char rcbits[80];
	char rdbits[80];
	char tmp[1024];
	
	int use = 0;
	
	memset(tabits,0, sizeof(tabits));
	memset(tbbits,0, sizeof(tbbits));
	memset(rabits,0, sizeof(rabits));
	memset(rbbits,0, sizeof(rbbits));
	memset(tcbits,0, sizeof(tcbits));
	memset(tdbits,0, sizeof(tdbits));
	memset(rcbits,0, sizeof(rcbits));
	memset(rdbits,0, sizeof(rdbits));
	memset(tabits,32, span_max_chan_pos);
	memset(tbbits,32, span_max_chan_pos);
	memset(rabits,32, span_max_chan_pos);
	memset(rbbits,32, span_max_chan_pos);
	memset(tcbits,32, span_max_chan_pos);
	memset(tdbits,32, span_max_chan_pos);
	memset(rcbits,32, span_max_chan_pos);
	memset(rdbits,32, span_max_chan_pos);
	
	for (x=0;x<DAHDI_MAX_CHANNELS;x++) {
		memset(&zp, 0, sizeof(zp));
		zp.channo = x;
		res = ioctl(ctl, DAHDI_GET_PARAMS, &zp);
		if (!res) {
			if (zp.spanno == span) {
				if (zp.sigtype && (zp.rxbits > -1)) {
					if (zp.rxbits & DAHDI_ABIT)
						rabits[zp.chanpos - 1] = '1';
					else
						rabits[zp.chanpos - 1] = '0';
					if (zp.rxbits & DAHDI_BBIT)
						rbbits[zp.chanpos - 1] = '1';
					else
						rbbits[zp.chanpos - 1] = '0';

					if (zp.rxbits & DAHDI_CBIT)
						rcbits[zp.chanpos - 1] = '1';
					else
						rcbits[zp.chanpos - 1] = '0';
					if (zp.rxbits & DAHDI_DBIT)
						rdbits[zp.chanpos - 1] = '1';
					else
						rdbits[zp.chanpos - 1] = '0';

					if (zp.txbits & DAHDI_ABIT)
						tabits[zp.chanpos - 1] = '1';
					else
						tabits[zp.chanpos - 1] = '0';
					if (zp.txbits & DAHDI_BBIT)
						tbbits[zp.chanpos - 1] = '1';
					else
						tbbits[zp.chanpos - 1] = '0';
					if (zp.txbits & DAHDI_CBIT)
						tcbits[zp.chanpos - 1] = '1';
					else
						tcbits[zp.chanpos - 1] = '0';
					if (zp.txbits & DAHDI_DBIT)
						tdbits[zp.chanpos - 1] = '1';
					else
						tdbits[zp.chanpos - 1] = '0';
				} else {
					c = '-';
					if (!zp.sigtype)
						c = ' ';
					tabits[zp.chanpos - 1] = c;
					tbbits[zp.chanpos - 1] = c;
					tcbits[zp.chanpos - 1] = c;
					tdbits[zp.chanpos - 1] = c;
					rabits[zp.chanpos - 1] = c;
					rbbits[zp.chanpos - 1] = c;
					rcbits[zp.chanpos - 1] = c;
					rdbits[zp.chanpos - 1] = c;
				}
				if (zp.rxisoffhook)
					use++;
			}
		}
	}
	snprintf(tmp, sizeof(tmp), "%s\n%s\n%s\n%s\n\n%s\n%s\n%s\n%s", tabits, tbbits,tcbits,tdbits,rabits,rbbits,rcbits,rdbits);
	newtTextboxSetText(bitbox, tmp);	
	sprintf(tmp, "%3d/%3d/%3d", s[span].totalchans, s[span].numchans, use);
	newtTextboxSetText(inuse, tmp);
	sprintf(tmp, "%s/", dahdi_txlevelnames[s[span].txlevel]);
	strcat(tmp, dahdi_txlevelnames[s[span].rxlevel]);
	sprintf(tmp, "%3d/%3d", s[span].txlevel, s[span].rxlevel);
	newtTextboxSetText(levels, tmp);
	sprintf(tmp, "%7d", s[span].bpvcount);
	newtTextboxSetText(bpvcount, tmp);
	sprintf(tmp, "%7d", s[span].irqmisses);
	newtTextboxSetText(irqmisses, tmp);
	newtTextboxSetText(alarms, alarmstr(span));	
	if (s[span].syncsrc > 0)
		strcpy(tmp, s[s[span].syncsrc].desc);
	else
		strcpy(tmp, "Internally clocked");
	newtTextboxSetText(syncsrc, tmp);
	
	
}
Ejemplo n.º 18
0
int doMediaCheck(char *file, char *descr) {
    struct progressCBdata data;
    newtComponent t, f, scale, label;
    int rc;
    int dlen;
    int llen;
    char tmpstr[1024];

    if (access(file, R_OK) < 0) {
	newtWinMessage(_("Error"), _("OK"), _("Unable to find install image "
					      "%s"), file);
	return -1;
    }

    if (descr)
	snprintf(tmpstr, sizeof(tmpstr), _("Checking \"%s\"..."), descr);
    else
	snprintf(tmpstr, sizeof(tmpstr), _("Checking media now..."));

    dlen = strlen(tmpstr);
    if (dlen > 65)
	dlen = 65;

    newtCenteredWindow(dlen+8, 6, _("Media Check"));
    t = newtTextbox(1, 1, dlen+4, 3, NEWT_TEXTBOX_WRAP);

    newtTextboxSetText(t, tmpstr);
    llen = strlen(tmpstr);

    label = newtLabel(llen+1, 1, "-");
    f = newtForm(NULL, NULL, 0);
    newtFormAddComponent(f, t);
    scale = newtScale(3, 3, dlen, 100);
    newtFormAddComponent(f, scale);

    newtDrawForm(f);
    newtRefresh();

    data.scale = scale;
    data.label = label;

    rc = mediaCheckFile(file, progressCallback, &data);

    newtFormDestroy(f);
    newtPopWindow();

    if (rc == -1) {
	logMessage(WARNING, "mediacheck: %s (%s) has no checksum info", file, descr);
	newtWinMessage(_("Error"), _("OK"),
		       _("Unable to read the disc checksum from the "
			 "primary volume descriptor.  This probably "
			 "means the disc was created without adding the "
			 "checksum."));
    } else if (rc == 0) {
        logMessage(ERROR, "mediacheck: %s (%s) FAILED", file, descr);
        newtWinMessage(_("Error"), _("OK"),
                       _("The image which was just tested has errors. "
                         "This could be due to a "
                         "corrupt download or a bad disc.  "
                         "If applicable, please clean the disc "
                         "and try again.  If this test continues to fail you "
                         "should not continue the install."));
    } else if (rc > 0) {
        logMessage(INFO, "mediacheck: %s (%s) PASSED", file, descr);
        newtWinMessage(_("Success"), _("OK"),
                       _("The image which was just tested was successfully "
                         "verified.  It should be OK to install from this "
                         "media.  Note that not all media/drive errors can "
                         "be detected by the media check."));
    }


    return rc;
}
int gauge(const char * text, int height, int width, poptContext optCon, int fd, 
		int flags) {
    newtComponent form, scale, tb;
    int top;
    const char * arg;
    char * end;
    int val;
    FILE * f = fdopen(fd, "r");
    char buf[3000];
    char buf3[50];
    int i;

    setlinebuf(f);

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

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

    form = newtForm(NULL, NULL, 0);

    scale = newtScale(2, height - 2, width - 4, 100);
    newtScaleSet(scale, val);

    newtFormAddComponents(form, tb, scale, NULL);

    newtDrawForm(form);
    newtRefresh();

    while (fgets(buf, sizeof(buf) - 1, f)) {
	buf[strlen(buf) - 1] = '\0';

	if (!strcmp(buf, "XXX")) {
	    fgets(buf3, sizeof(buf3) - 1, f);
	    buf3[strlen(buf3) - 1] = '\0';
	    arg = buf3;

	    i = 0;
	    while (fgets(buf + i, sizeof(buf) - 1 - i, f)) {
		buf[strlen(buf) - 1] = '\0';
		if (!strcmp(buf + i, "XXX")) {
		    *(buf + i) = '\0';
		    break;
		}
		i = strlen(buf);
	    }

	    newtTextboxSetText(tb, buf);
 	} else {
	    arg = buf;
	}

	val = strtoul(buf, &end, 10);
	if (!*end) {
	    newtScaleSet(scale, val);
	    newtDrawForm(form);
	    newtRefresh();
	}
    }

    return DLG_OKAY;
}
Ejemplo n.º 20
0
/* This is a groovie dialog for showing network info.  Takes a keyvalue list,
 * a colour and a dhcp flag.  Shows the current settings, and rewrites them
 * if necessary.  DHCP flag sets wether to show the dhcp checkbox. */
int changeaddress(struct keyvalue *kv, char *colour, int typeflag,
	char *defaultdhcphostname)
{
	char *addressresult;
	char *netmaskresult;
	char *dhcphostnameresult;
	char *dhcpforcemturesult;
	struct newtExitStruct es;
	newtComponent header;
	newtComponent addresslabel;
	newtComponent netmasklabel;
	newtComponent dhcphostnamelabel;
	newtComponent dhcpforcemtulabel;
	newtComponent ok, cancel;	
	char message[1000];
	char temp[STRING_SIZE];
	char addressfield[STRING_SIZE];
	char netmaskfield[STRING_SIZE];
	char typefield[STRING_SIZE];
	char dhcphostnamefield[STRING_SIZE];
	char dhcpforcemtufield[STRING_SIZE];
	int error;
	int result = 0;
	char type[STRING_SIZE];
	int startstatictype = 0;
	int startdhcptype = 0;
	int startpppoetype = 0;
		
	/* Build some key strings. */
	sprintf(addressfield, "%s_ADDRESS", colour);
	sprintf(netmaskfield, "%s_NETMASK", colour);
	sprintf(typefield, "%s_TYPE", colour);
	sprintf(dhcphostnamefield, "%s_DHCP_HOSTNAME", colour);
	sprintf(dhcpforcemtufield, "%s_DHCP_FORCE_MTU", colour);
		
	sprintf(message, _("Interface - %s"), colour);
	newtCenteredWindow(44, (typeflag ? 18 : 12), message);
	
	networkform = newtForm(NULL, NULL, 0);

	sprintf(message, _("Enter the IP address information for the %s interface."), colour);
	header = newtTextboxReflowed(1, 1, message, 42, 0, 0, 0);
	newtFormAddComponent(networkform, header);

	/* See if we need a dhcp checkbox.  If we do, then we shift the contents
	 * of the window down two rows to make room. */
	if (typeflag)
	{
		strcpy(temp, "STATIC"); findkey(kv, typefield, temp);
		if (strcmp(temp, "STATIC") == 0) startstatictype = 1;
		if (strcmp(temp, "DHCP") == 0) startdhcptype = 1;
		if (strcmp(temp, "PPPOE") == 0) startpppoetype = 1;
		statictyperadio = newtRadiobutton(2, 4, _("Static"), startstatictype, NULL);
		dhcptyperadio = newtRadiobutton(2, 5, _("DHCP"), startdhcptype, statictyperadio);
		pppoetyperadio = newtRadiobutton(2, 6, _("PPP DIALUP (PPPoE, modem, ATM ...)"),
			startpppoetype, dhcptyperadio);
		newtFormAddComponents(networkform, statictyperadio, dhcptyperadio, 
			pppoetyperadio, NULL);
		newtComponentAddCallback(statictyperadio, networkdialogcallbacktype, NULL);
		newtComponentAddCallback(dhcptyperadio, networkdialogcallbacktype, NULL);
		newtComponentAddCallback(pppoetyperadio, networkdialogcallbacktype, NULL);
		dhcphostnamelabel = newtTextbox(2, 8, 18, 1, 0);
		newtTextboxSetText(dhcphostnamelabel, _("DHCP Hostname:"));
		dhcpforcemtulabel = newtTextbox(2, 9, 18, 1, 0);
		newtTextboxSetText(dhcpforcemtulabel, _("Force DHCP MTU:"));
		strcpy(temp, defaultdhcphostname);
		findkey(kv, dhcphostnamefield, temp);
		dhcphostnameentry = newtEntry(20, 8, temp, 20, &dhcphostnameresult, 0);
		strcpy(temp, "");
		findkey(kv, dhcpforcemtufield, temp);
		dhcpforcemtuentry = newtEntry(20, 9, temp, 20, &dhcpforcemturesult, 0);
		newtFormAddComponent(networkform, dhcphostnamelabel);
		newtFormAddComponent(networkform, dhcphostnameentry);
		newtFormAddComponent(networkform, dhcpforcemtulabel);
		newtFormAddComponent(networkform, dhcpforcemtuentry);
		if (startdhcptype == 0)
			{
				newtEntrySetFlags(dhcphostnameentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET);
				newtEntrySetFlags(dhcpforcemtuentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET);
			}
	}
	/* Address */
	addresslabel = newtTextbox(2, (typeflag ? 11 : 4) + 0, 18, 1, 0);
	newtTextboxSetText(addresslabel, _("IP address:"));
	strcpy(temp, "");
	findkey(kv, addressfield, temp);
	addressentry = newtEntry(20, (typeflag ? 11 : 4) + 0, temp, 20, &addressresult, 0);
	newtEntrySetFilter(addressentry, ip_input_filter, NULL);
	if (typeflag == 1 && startstatictype == 0)
		newtEntrySetFlags(addressentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET);
	newtFormAddComponent(networkform, addresslabel);
	newtFormAddComponent(networkform, addressentry);
	
	/* Netmask */
	netmasklabel = newtTextbox(2, (typeflag ? 11 : 4) + 1, 18, 1, 0);
	newtTextboxSetText(netmasklabel, _("Network mask:"));
	strcpy(temp, "255.255.255.0"); findkey(kv, netmaskfield, temp);
	netmaskentry = newtEntry(20, (typeflag ? 11 : 4) + 1, temp, 20, &netmaskresult, 0);
	newtEntrySetFilter(netmaskentry, ip_input_filter, NULL);
	if (typeflag == 1 && startstatictype == 0) 
		newtEntrySetFlags(netmaskentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET);

	newtFormAddComponent(networkform, netmasklabel);
	newtFormAddComponent(networkform, netmaskentry);

	/* Buttons. */
	ok = newtButton(8, (typeflag ? 14 : 7), _("OK"));
	cancel = newtButton(26, (typeflag ? 14 : 7), _("Cancel"));

	newtFormAddComponents(networkform, ok, cancel, NULL);

	newtRefresh();
	newtDrawForm(networkform);

	do
	{
		error = 0;
		newtFormRun(networkform, &es);
	
		if (es.u.co == ok)
		{
			/* OK was pressed; verify the contents of each entry. */
			strcpy(message, _("The following fields are invalid:"));
			strcat(message, "\n\n");
			
			strcpy(type, "STATIC");
			if (typeflag)
				gettype(type);
			if (strcmp(type, "STATIC") == 0)
			{		
				if (inet_addr(addressresult) == INADDR_NONE)
				{
					strcat(message, _("IP address"));
					strcat(message, "\n");
					error = 1;
				}
				if (inet_addr(netmaskresult) == INADDR_NONE)
				{
					strcat(message, _("Network mask"));
					strcat(message, "\n");
					error = 1;
				}
			}
			if (strcmp(type, "DHCP") == 0)
			{
				if (!strlen(dhcphostnameresult))
				{
					strcat(message, _("DHCP hostname"));
					strcat(message, "\n");
					error = 1;
				}
			}
			if (error)
				errorbox(message);
			else
			{
				/* No errors!  Set new values, depending on dhcp flag etc. */
				if (typeflag)
				{
					replacekeyvalue(kv, dhcphostnamefield, dhcphostnameresult);
					replacekeyvalue(kv, dhcpforcemtufield, dhcpforcemturesult);
					if (strcmp(type, "STATIC") != 0)
					{
						replacekeyvalue(kv, addressfield, "0.0.0.0");
						replacekeyvalue(kv, netmaskfield, "0.0.0.0");
					}
					else
					{
						replacekeyvalue(kv, addressfield, addressresult);
						replacekeyvalue(kv, netmaskfield, netmaskresult);
					}
					replacekeyvalue(kv, typefield, type);					
				}
				else
				{
					replacekeyvalue(kv, addressfield, addressresult);
					replacekeyvalue(kv, netmaskfield, netmaskresult);
				}
				
				setnetaddress(kv, colour);
				result = 1;
			}
		}
		/* Workaround for a bug that dhcp radiobutton also end the dialog at arm
		*/
		else {
			if (es.u.co != cancel) {
				error = 1;
			}
		}
	}
	while (error);

	newtFormDestroy(networkform);
	newtPopWindow();
		
	return result;
}
Ejemplo n.º 21
0
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;
}
Ejemplo n.º 22
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;
}
Ejemplo n.º 23
0
int handledhcp(void)
{
	char *results[MAX_BOXES];
	char enabledresult;
	char startenabled;
	struct newtExitStruct es;
	newtComponent header;
	newtComponent labels[MAX_BOXES];
	newtComponent ok, cancel;	
	char message[1000];
	char *labeltexts[MAX_BOXES] = {
		_("Start address:"),
		_("End address:"),
		_("Primary DNS:"),
		_("Secondary DNS:"),
		_("Default lease (mins):"),
		_("Max lease (mins):"),
		_("Domain name suffix:")
	};
	char *varnames[MAX_BOXES] = {
		"START_ADDR_GREEN",
		"END_ADDR_GREEN",
		"DNS1_GREEN",
		"DNS2_GREEN",
		"DEFAULT_LEASE_TIME_GREEN",
		"MAX_LEASE_TIME_GREEN",
		"DOMAIN_NAME_GREEN"
	};
	char defaults[MAX_BOXES][STRING_SIZE]; 
	int result;
	int c;
	char temp[STRING_SIZE];
	struct keyvalue *mainkv = initkeyvalues();
	struct keyvalue *dhcpkv = initkeyvalues();
	struct keyvalue *ethernetkv = initkeyvalues();
	int error;
	FILE *file;
	char greenaddress[STRING_SIZE];	
	char greennetaddress[STRING_SIZE];
	char greennetmask[STRING_SIZE];
	
 	memset(defaults, 0, sizeof(char) * STRING_SIZE * MAX_BOXES);
	
	if (!(readkeyvalues(dhcpkv, CONFIG_ROOT "/dhcp/settings")))
	{
		freekeyvalues(dhcpkv);
		freekeyvalues(ethernetkv);
		errorbox(_("Unable to open settings file"));
		return 0;
	}
	if (!(readkeyvalues(ethernetkv, CONFIG_ROOT "/ethernet/settings")))
	{
		freekeyvalues(dhcpkv);
		freekeyvalues(ethernetkv);
		errorbox(_("Unable to open settings file"));
		return 0;
	}
	if (!(readkeyvalues(mainkv, CONFIG_ROOT "/main/settings")))
	{
		freekeyvalues(dhcpkv);
		freekeyvalues(ethernetkv);
		freekeyvalues(mainkv);
		errorbox(_("Unable to open settings file"));
		return 0;
	}

	/* Set default values. */	
	findkey(ethernetkv, "GREEN_ADDRESS", defaults[PRIMARY_DNS]);
	findkey(mainkv, "DOMAINNAME", defaults[DOMAIN_NAME_SUFFIX]);
	strcpy(defaults[DEFAULT_LEASE_TIME], "60");
	strcpy(defaults[MAX_LEASE_TIME], "120");

	newtCenteredWindow(55, 18, _("DHCP server configuration"));

	dhcpform = newtForm(NULL, NULL, 0);

	header = newtTextboxReflowed(1, 1,
		_("Configure the DHCP server by entering the settings information."),
		52, 0, 0, 0);
	newtFormAddComponent(dhcpform, header);

	strcpy(temp, ""); findkey(dhcpkv, "ENABLE_GREEN", temp);
	if (strcmp(temp, "on") == 0)
		startenabled = '*';
	else
		startenabled = ' ';
	enabledcheckbox = newtCheckbox(2, TOP + 0, _("Enabled"), startenabled, " *", &enabledresult);
	newtFormAddComponent(dhcpform, enabledcheckbox);
	newtComponentAddCallback(enabledcheckbox, dhcpdialogcallbackdhcp, NULL);		

	for (c = 0; c < MAX_BOXES; c++)
	{
		labels[c] = newtTextbox(2, TOP + 2 + c, 33, 1, 0);
		newtTextboxSetText(labels[c], labeltexts[c]);
		newtFormAddComponent(dhcpform, labels[c]);				
		strcpy(temp, defaults[c]); findkey(dhcpkv, varnames[c], temp);
		entries[c] = newtEntry(34, TOP + 2 + c, temp, 18, &results[c], 0);
		newtFormAddComponent(dhcpform, entries[c]);		
		if (startenabled == ' ')
			newtEntrySetFlags(entries[c], NEWT_FLAG_DISABLED, NEWT_FLAGS_SET);			
		
	}
	
	ok = newtButton(10, c + 7, _("OK"));
	cancel = newtButton(34, c + 7, _("Cancel"));

	newtFormAddComponents(dhcpform, ok, cancel, NULL);
	
	do {
		error = 0;
		newtFormRun(dhcpform, &es);
	
		if (es.u.co == ok)
		{
			/* OK was pressed; verify the contents of each entry. */		
			if (enabledresult == '*')
			{
				strcpy(message, _("The following fields are invalid:\n\n"));
				if (inet_addr(results[START_ADDRESS]) == INADDR_NONE)
				{
					strcat(message, _("Start address"));
					strcat(message, "\n");
					error = 1;
				}
				if (inet_addr(results[END_ADDRESS]) == INADDR_NONE)
				{
					strcat(message, _("End address"));
					strcat(message, "\n");
					error = 1;
				}
				if (strlen(results[SECONDARY_DNS]))
				{
					if (inet_addr(results[PRIMARY_DNS]) == INADDR_NONE)
					{
						strcat(message, _("Primary DNS"));
						strcat(message, "\n");
						error = 1;
					}
				}
				if (strlen(results[SECONDARY_DNS]))
				{
					if (inet_addr(results[SECONDARY_DNS]) == INADDR_NONE)
					{
						strcat(message, _("Secondary DNS"));
						strcat(message, "\n");
						error = 1;
					}
				}
				if (!(atol(results[DEFAULT_LEASE_TIME])))
				{
					strcat(message, _("Default lease time"));
					strcat(message, "\n");
					error = 1;
				}
				if (!(atol(results[MAX_LEASE_TIME])))
				{
					strcat(message, _("Max. lease time"));
					strcat(message, "\n");
					error = 1;
				}
			}				
			
			if (error)
				errorbox(message);
			else
			{
				for (c = 0; c < MAX_BOXES; c++)
					replacekeyvalue(dhcpkv, varnames[c], results[c]);
				if (enabledresult == '*')
				{
					replacekeyvalue(dhcpkv, "ENABLE_GREEN", "on");
					fclose(fopen(CONFIG_ROOT "/dhcp/enable_green", "w"));
					chown(CONFIG_ROOT "/dhcp/enable_green", 99, 99);
					mysystem(NULL, "/usr/local/bin/dhcpctrl enable");
				}
				else
				{
					replacekeyvalue(dhcpkv, "ENABLE_GREEN", "off");
					unlink(CONFIG_ROOT "/dhcp/enable_green");
					mysystem(NULL, "/usr/local/bin/dhcpctrl disable");
				}
				replacekeyvalue(dhcpkv, "VALID", "yes");
				writekeyvalues(dhcpkv, CONFIG_ROOT "/dhcp/settings");
				
				findkey(ethernetkv, "GREEN_ADDRESS", greenaddress);				
				findkey(ethernetkv, "GREEN_NETADDRESS", greennetaddress);
				findkey(ethernetkv, "GREEN_NETMASK", greennetmask);
			
				file = fopen(CONFIG_ROOT "/dhcp/dhcpd.conf", "w");
				fprintf(file, "ddns-update-style none;\n");
				fprintf(file, "authoritative;\n");
				fprintf(file, "subnet %s netmask %s\n", greennetaddress, greennetmask);
				fprintf(file, "{\n");
				fprintf(file, "\toption subnet-mask %s;\n", greennetmask);
				fprintf(file, "\toption domain-name \"%s\";\n", results[DOMAIN_NAME_SUFFIX]);		
				fprintf(file, "\toption routers %s;\n", greenaddress);
				if (strlen(results[PRIMARY_DNS]))
				{
					fprintf(file, "\toption domain-name-servers ");
					fprintf(file, "%s", results[PRIMARY_DNS]);
					if (strlen(results[SECONDARY_DNS]))
						fprintf(file, ", %s", results[SECONDARY_DNS]);
					fprintf(file, ";\n");
				}
				
				fprintf(file, "\trange %s %s;\n",	results[START_ADDRESS], results[END_ADDRESS]);
				fprintf(file, "\tdefault-lease-time %d;\n", (int) atol(results[DEFAULT_LEASE_TIME]) * 60);
				fprintf(file, "\tmax-lease-time %d;\n",	(int) atol(results[MAX_LEASE_TIME]) * 60);
				fprintf(file, "}\n");
				fclose(file);
				chown(CONFIG_ROOT "/dhcp/dhcpd.conf", 99, 99);
				if (automode == 0)
					mysystem(NULL, "/usr/local/bin/dhcpctrl enable");
			}
			result = 1;
		}
		else
			result = 0;
	} while (error);
	
	newtFormDestroy(dhcpform);
	newtPopWindow();
	
	freekeyvalues(dhcpkv);
	freekeyvalues(ethernetkv);
	freekeyvalues(mainkv);
	
	return result;
}
Ejemplo n.º 24
0
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;
}
Ejemplo n.º 25
0
/* Small window to change IP and Netmask of some colour */
void changeaddress(char *colour, int *changed_flag)
{
    newtComponent networkform;
    newtComponent text;
    newtComponent ok, cancel;
    struct newtExitStruct exitstruct;
    char keyvalue[STRING_SIZE];
    char addresskey[STRING_SIZE];
    char netmaskkey[STRING_SIZE];
    char netaddresskey[STRING_SIZE];
    newtComponent addresslabel;
    newtComponent netmasklabel;
    newtComponent addressentry;
    newtComponent netmaskentry;
    const char *addressresult;
    const char *netmaskresult;
    char message[STRING_SIZE_LARGE];
    int error;
    int numLines;
    char *tmpstring;

    /* Build some key strings. */
    sprintf(addresskey, "%s_1_ADDRESS", colour);
    sprintf(netmaskkey, "%s_1_NETMASK", colour);
    sprintf(netaddresskey, "%s_1_NETADDRESS", colour);

    /* workaround gcc warning, there is really 1 %s there */
    tmpstring=strdup(gettext("TR_ENTER_THE_IP_ADDRESS_INFORMATION"));
    snprintf(message, STRING_SIZE, tmpstring, colour);
    free(tmpstring);
    text = newtTextboxReflowed(1, 1, message, 68, 0, 0, 0);
    numLines = newtTextboxGetNumLines(text);

    /* workaround gcc warning, there is really 1 %s there */
    tmpstring=strdup(gettext("TR_INTERFACE"));
    snprintf(message, STRING_SIZE, tmpstring, colour);
    free(tmpstring);
    newtCenteredWindow(72, 10 + numLines, message);
    networkform = newtForm(NULL, NULL, 0);
    newtFormAddComponent(networkform, text);

    /* Address */
    addresslabel = newtTextbox(2, 2 + numLines, 18, 1, 0);
    newtTextboxSetText(addresslabel, gettext("TR_IP_ADDRESS_PROMPT"));
    if (!strcmp(colour, "GREEN")) {
        /* green only for now */
        strcpy(keyvalue, DEFAULT_IP);
    }
    else {
        strcpy(keyvalue, "");
    }
    find_kv_default(eth_kv, addresskey, keyvalue);
    addressentry = newtEntry(20, 2 + numLines, keyvalue, 20, &addressresult, 0);
    newtEntrySetFilter(addressentry, filterip, NULL);
    newtFormAddComponent(networkform, addresslabel);
    newtFormAddComponent(networkform, addressentry);

    /* Netmask */
    netmasklabel = newtTextbox(2, 3 + numLines, 18, 1, 0);
    newtTextboxSetText(netmasklabel, gettext("TR_NETMASK_PROMPT"));
    strcpy(keyvalue, DEFAULT_NETMASK);
    find_kv_default(eth_kv, netmaskkey, keyvalue);
    netmaskentry = newtEntry(20, 3 + numLines, keyvalue, 20, &netmaskresult, 0);
    newtEntrySetFilter(netmaskentry, filterip, NULL);
    newtFormAddComponent(networkform, netmasklabel);
    newtFormAddComponent(networkform, netmaskentry);

    ok = newtButton(6, 5 + numLines, gettext("TR_OK"));
    /* In case of installer we need a valid address, no turning back */
    if (flag_is_state == setupchroot) {
        newtFormAddComponent(networkform, ok);
    }
    else {
        cancel = newtButton(26, 5 + numLines, gettext("TR_GO_BACK"));
        newtFormAddComponents(networkform, ok, cancel, NULL);
    }
    newtRefresh();
    newtDrawForm(networkform);

    do {
        error = 0;
        newtFormRun(networkform, &exitstruct);

        if (exitstruct.u.co == ok) {

            strcpy(message, gettext("TR_INVALID_FIELDS"));
            if (VALID_IP(addressresult) == FALSE) {
                strcat(message, gettext("TR_IP_ADDRESS_CR"));
                error = 1;
                newtFormSetCurrent(networkform, addressentry);
            }
            if (VALID_IP(netmaskresult) == FALSE) {
                strcat(message, gettext("TR_NETWORK_MASK_CR"));
                error = 1;
                newtFormSetCurrent(networkform, netmaskentry);
            }

            // TODO: additional network mask validation

            if (error) {
                errorbox(message);
            }
            else {
                /* all is well, calc netaddress and store everything */
                unsigned long int intaddress;
                unsigned long int intnetaddress;
                unsigned long int intnetmask;
                struct in_addr i_addr;
                char *netaddress;

                update_kv(&eth_kv, addresskey, (char *) addressresult);
                update_kv(&eth_kv, netmaskkey, (char *) netmaskresult);
                /* calculate netaddress */
                intaddress = inet_addr(addressresult);
                intnetmask = inet_addr(netmaskresult);
                intnetaddress = intaddress & intnetmask;
                i_addr.s_addr = intnetaddress;
                netaddress = inet_ntoa(i_addr);
                update_kv(&eth_kv, netaddresskey, (char *) netaddress);

                changed_config = 1;
                *changed_flag = 1;
            }
        }
    }
    while (error);

    newtFormDestroy(networkform);
    newtPopWindow();
}