Ejemplo n.º 1
0
static void do_loop(int span, int looped)
{
	newtComponent form;
	newtComponent label;
	char s1[256];
	struct dahdi_maintinfo m;
	int res;
	struct newtExitStruct es;

	newtOpenWindow(20,12,40,4, s[span].desc);

	form = newtForm(NULL, NULL, 0);
	m.spanno = span;
	if (looped) {
		snprintf(s1, sizeof(s1), "Looping UP span %d...\n", span);
		m.command = DAHDI_MAINT_LOOPUP;
	} else {
		snprintf(s1, sizeof(s1), "Looping DOWN span %d...\n", span);
		m.command = DAHDI_MAINT_LOOPDOWN;
	}

	label = newtLabel(3,1,s1);
	newtFormAddComponent(form, label);
	newtPushHelpLine("Please wait...");

	newtFormSetTimer(form, 200);
	newtFormRun(form, &es);
	res = ioctl(ctl, DAHDI_MAINT, &m);
	newtFormDestroy(form);
	newtPopWindow();
	newtPopHelpLine();
}
static int manage_calls(char *host)
{
	newtComponent form;
	newtComponent quit;
	newtComponent hangup;
	newtComponent redirect;
	newtComponent channels;
	struct newtExitStruct es;
	char tmp[80];

	/* If there's one thing you learn from this code, it is this...
	   Never, ever fly Air France.  Their customer service is absolutely
	   the worst.  I've never heard the words "That's not my problem" as 
	   many times as I have from their staff -- It should, without doubt
	   be their corporate motto if it isn't already.  Don't bother giving 
	   them business because you're just a pain in their side and they
	   will be sure to let you know the first time you speak to them.
	   
	   If you ever want to make me happy just tell me that you, too, will
	   never fly Air France again either (in spite of their excellent
	   cuisine). */
	snprintf(tmp, sizeof(tmp), "Asterisk Manager at %s", host);
	newtCenteredWindow(74, 20, tmp);
	form = newtForm(NULL, NULL, 0);
	newtFormWatchFd(form, session.fd, NEWT_FD_READ);
	newtFormSetTimer(form, 100);
	quit = newtButton(62, 16, "Quit");
	redirect = newtButton(35, 16, "Redirect");
	hangup = newtButton(50, 16, "Hangup");
	channels = newtListbox(1,1,14, NEWT_FLAG_SCROLL);
	newtFormAddComponents(form, channels, redirect, hangup, quit, NULL);
	newtListboxSetWidth(channels, 72);
	
	show_doing("Getting Status", "Retrieving system status...");
	try_status();
	hide_doing();

	for(;;) {
		newtFormRun(form, &es);
		if (has_input(&session) || (es.reason == NEWT_EXIT_FDREADY)) {
			if (input_check(&session, NULL)) {
				show_message("Disconnected", "Disconnected from remote host");
				break;
			}
		} else if (es.reason == NEWT_EXIT_COMPONENT) {
			if (es.u.co == quit)
				break;
			if (es.u.co == hangup) {
				try_hangup(channels);
			} else if (es.u.co == redirect) {
				try_redirect(channels);
			}
		}
		rebuild_channels(channels);
	}
	newtFormDestroy(form);
	return 0;
}
static int show_doing(char *title, char *tmp)
{
	struct newtExitStruct es;
	newtComponent label;
	showform = newtForm(NULL, NULL, 0);
	newtCenteredWindow(70,4, title);
	label = newtLabel(3,1,tmp);
	newtFormAddComponents(showform,label, NULL);
	newtFormSetTimer(showform, 200);
	newtFormRun(showform, &es);
	return 0;
}
Ejemplo n.º 4
0
/* A "normal" newt program would call newtFormRun() to run newt's main loop
 * and process events. But we want to let GLib's main loop control the program
 * (eg, so libnm can process D-Bus notifications). So we call this function
 * to run a single iteration of newt's main loop (or rather, to run newt's
 * main loop for 1ms) whenever there are events for newt to process (redrawing
 * or keypresses).
 */
static void
nmt_newt_form_iterate (NmtNewtForm *form)
{
	NmtNewtFormPrivate *priv = NMT_NEWT_FORM_GET_PRIVATE (form);
	NmtNewtWidget *focus;
	struct newtExitStruct es;

	if (priv->dirty) {
		nmt_newt_form_destroy (form);
		nmt_newt_form_build (form);
	}

	newtFormSetTimer (priv->form, 1);
	newtFormRun (priv->form, &es);

	if (   es.reason == NEWT_EXIT_HOTKEY
	    || es.reason == NEWT_EXIT_ERROR) {
		/* The user hit Esc or there was an error. */
		g_clear_object (&priv->focus);
		nmt_newt_form_quit (form);
		return;
	}

	if (es.reason == NEWT_EXIT_COMPONENT) {
		/* The user hit Return/Space on a component; update the form focus
		 * to point that that component, and activate it.
		 */
		focus = nmt_newt_widget_find_component (priv->content, es.u.co);
		if (focus) {
			nmt_newt_form_set_focus (form, focus);
			nmt_newt_widget_activated (focus);
		}
	} else {
		/* The 1ms timer ran out. Update focus but don't do anything else. */
		focus = nmt_newt_widget_find_component (priv->content,
		                                        newtFormGetCurrent (priv->form));
		if (focus)
			nmt_newt_form_set_focus (form, focus);
	}
}
Ejemplo n.º 5
0
static void show_spans(void)
{
	newtComponent form;
	newtComponent quit;
	newtComponent label;
	newtComponent sel;

	
	struct newtExitStruct es;
	
	
	quit = newtButton(50,14,"Quit");
	sel = newtButton(10,14,"Select");
	
	spans = newtListbox(5, 2, 10, NEWT_FLAG_SCROLL);
	newtListboxSetWidth(spans, 65);
	
	label = newtLabel(5,1,"Alarms          Span");
	
	newtCenteredWindow(72,18, "DAHDI Telephony Interfaces");
	form = newtForm(NULL, NULL, 0);
	
	newtFormSetTimer(form, 200);
	
	newtFormAddComponents(form, spans, sel, quit, label, NULL);

	newtComponentAddCallback(spans, sel_callback, NULL);

	newtFormAddHotKey(form, NEWT_KEY_F1);
	newtFormAddHotKey(form, NEWT_KEY_F10);
	
	for(;;) {
		/* Wait for user to select something */
		do {
			add_cards(spans);
			newtFormRun(form, &es);
		} while(es.reason == NEWT_EXIT_TIMER);

		switch(es.reason) {
		case NEWT_EXIT_COMPONENT:
			if (es.u.co == quit) {
				/* Quit if appropriate */
				newtFormDestroy(form);
				return;
			} else if (es.u.co == sel) {
				show_span(-1);
			}
			break;
		case NEWT_EXIT_HOTKEY:
			switch(es.u.key) {
			case NEWT_KEY_F1:
				show_span(-1);
				break;
			case NEWT_KEY_F10:
				newtFormDestroy(form);
				return;
			}
			break;
		default:
			break;
		}
	}
}
Ejemplo n.º 6
0
static void show_span(int span)
{
	newtComponent form;
	newtComponent back;
	newtComponent loop;
	newtComponent label;
	newtComponent bitbox;
	newtComponent inuse;
	newtComponent levels;
	newtComponent bpvcount;
	newtComponent alarms;
	newtComponent syncsrc;
	newtComponent irqmisses;
	
	char s1[] = "         1111111111222222222233";
	char s2[] = "1234567890123456789012345678901";
	int x;
	int looped = 0;
	struct newtExitStruct es;

	void *ss;
	char info2[256];

	if (span < 0) {
		/* Display info on a span */
		ss = newtListboxGetCurrent(spans);
		if (ss) {
			span = (long)(ss);
		}
	}

	snprintf(info2, sizeof(info2), "%-59s            F10=Back", s[span].desc);
	newtOpenWindow(10,2,60,20, s[span].desc);
	newtPushHelpLine(info2);

	back = newtButton(48,8,"Back");
	loop = newtButton(48,14,"Loop");
	form = newtForm(NULL, NULL, 0);

	newtFormAddComponents(form, back, loop, NULL);

	span_max_chan_pos = s[span].totalchans;
	for (x=0;x<DAHDI_MAX_CHANNELS;x++) {
		DAHDI_PARAMS zp;
		int res;
		memset(&zp, 0, sizeof(zp));
		zp.channo = x;
		res = ioctl(ctl, DAHDI_GET_PARAMS, &zp);
		if (!res && zp.spanno == span && zp.chanpos > span_max_chan_pos )
			span_max_chan_pos = zp.chanpos;
	}

	if (span_max_chan_pos > 32)
		span_max_chan_pos = 32;

	s1[span_max_chan_pos] = '\0';
	s2[span_max_chan_pos] = '\0';

	bitbox = newtTextbox(8,10,span_max_chan_pos,9,0);
	newtFormAddComponent(form, bitbox);

	label = newtLabel(8,8,s1);
	newtFormAddComponent(form, label);

	label = newtLabel(8,9,s2);
	newtFormAddComponent(form, label);

	newtFormAddHotKey(form, NEWT_KEY_F10);
	newtFormSetTimer(form, 200);

	label = newtLabel(4,10,"TxA");
	newtFormAddComponent(form, label);

	label = newtLabel(4,11,"TxB");
	newtFormAddComponent(form, label);

	label = newtLabel(4,12,"TxC");
	newtFormAddComponent(form, label);

	label = newtLabel(4,13,"TxD");
	newtFormAddComponent(form, label);

	label = newtLabel(4,15,"RxA");
	newtFormAddComponent(form, label);

	label = newtLabel(4,16,"RxB");
	newtFormAddComponent(form, label);

	label = newtLabel(4,17,"RxC");
	newtFormAddComponent(form, label);

	label = newtLabel(4,18,"RxD");
	newtFormAddComponent(form, label);
	
	
	label = newtLabel(4,7,"Total/Conf/Act: ");
	newtFormAddComponent(form, label);
	
	inuse = newtTextbox(24,7,12,1,0);
	newtFormAddComponent(form, inuse);

	label = newtLabel(4,6,"Tx/Rx Levels: ");
	newtFormAddComponent(form, label);

	levels = newtTextbox(24,6,30,1,0);
	newtFormAddComponent(form, levels);
	
	label = newtLabel(4,5,"Bipolar Viol: ");
	newtFormAddComponent(form, label);

	bpvcount = newtTextbox(24,5,30,1,0);
	newtFormAddComponent(form, bpvcount);
	
	label = newtLabel(4,4,"IRQ Misses: ");
	newtFormAddComponent(form, label);

	irqmisses = newtTextbox(24,4,30,1,0);
	newtFormAddComponent(form, irqmisses);

	label = newtLabel(4,3,"Sync Source: ");
	newtFormAddComponent(form, label);

	syncsrc = newtTextbox(24,3,30,1,0);
	newtFormAddComponent(form, syncsrc);

	label = newtLabel(4,2,"Current Alarms: ");
	newtFormAddComponent(form, label);

	alarms = newtTextbox(24,2,30,1,0);
	newtFormAddComponent(form, alarms);
	
	for(;;) {
		/* Wait for user to select something */
		do {
			add_cards(NULL);
			show_bits(span, bitbox, inuse, levels, bpvcount, alarms, syncsrc, irqmisses);
			newtFormRun(form, &es);
		} while(es.reason == NEWT_EXIT_TIMER);
		switch(es.reason) {
		case NEWT_EXIT_COMPONENT:
			if (es.u.co == loop) {
				looped = !looped;
				do_loop(span, looped);
				newtFormSetTimer(form, 200);
			}
			if (es.u.co == back) {
				goto out;
			}
			break;
		case NEWT_EXIT_HOTKEY:
			switch(es.u.key) {
#if 0
			case NEWT_KEY_F1:
				show_span(-1);
				break;
#endif				
			case NEWT_KEY_F10:
				goto out;
			}
			break;
		default:
			break;
		}
	}	

out:	
	newtFormDestroy(form);
	newtPopWindow();
	newtPopHelpLine();
	span_max_chan_pos = 0;
}
Ejemplo n.º 7
0
// return a malloc()ed path
char *filesel(char *dr)
{
	newtComponent	lb, b1, b2, b3, l1, l2, f;
	const char	*enr2, *enr3;
	char		*curv;
	char		curvv[PATH_MAX]; // stupid, but who cares...
	int		i, cnt;
	fde		*sel, *sela;
	char		cwd[PATH_MAX], cwdcd[PATH_MAX], *ret=NULL;
	struct		newtExitStruct es;
	struct		stat st;
	
	newtCenteredWindow(65, 15, i18n("Select path"));
	
	f = newtForm(NULL, NULL, 0);
	
	b1 = newtCompactButton(59, 14, i18n("Ok"));
	b3 = newtCompactButton(45, 14, i18n("Cancel"));
	
	l2 = newtEntry(1, 14, "", 25, &enr3, NEWT_FLAG_SCROLL);
	b2 = newtCompactButton(26, 14, i18n("Create dir"));
	
	lb = newtListbox(1, 2, 12, /*NEWT_FLAG_MULTIPLE |*/ /*NEWT_FLAG_BORDER | */
		NEWT_FLAG_RETURNEXIT |
		NEWT_FLAG_SCROLL | NEWT_FLAG_SHOWCURSOR);
	
	if(dr && strlen(dr) > 0) 
	{
		// let it show the file or dir at any case
		l1 = newtEntry(1, 0, dr, 60, &enr2, NEWT_FLAG_SCROLL | NEWT_FLAG_DISABLED);
		stat(dr,&st);
		if(S_ISDIR(st.st_mode)) 
		{
			dir_here(lb,dr);
			strcpy(cwd,dr);
		} else
		{
			dir_here(lb,dirname(dr));
			strcpy(cwd,dirname(dr));
		}
	}
	else
	{
		// if NULL, show the current dir
		l1 = newtEntry(1, 0, get_current_dir_name(), 60, &enr2, NEWT_FLAG_SCROLL | NEWT_FLAG_DISABLED);
		dir_here(lb,get_current_dir_name());
		strcpy(cwd,get_current_dir_name());
	}
	
	newtListboxSetWidth(lb,63);
	newtFormAddComponents(f, lb,l1, l2, b2, b1, b3, NULL);
	newtRefresh();
	newtFormSetTimer(f, 200);
	
	do
	{
		newtFormRun(f, &es);
		
		if (es.reason == es.NEWT_EXIT_COMPONENT && es.u.co == lb) 
		{
			sel=(fde*)newtListboxGetCurrent(lb);
			if (sel && S_ISDIR(sel->st.st_mode))
			{
				cnt=newtListboxItemCount(lb);
				// delete items there:
				for(i=0; i < cnt; i++) 
				{
					newtListboxGetEntry(lb, i, &curv, (void**)&sela);
					if(sela != sel) 
					{
						free(sela->name);
						free(sela);
					}
					else
					{
						strcpy(curvv, curv);
					}
				}
				
				newtListboxClear(lb);
				
				dir_here(lb,sel->name);
				if(strcmp(curvv,"..") == 0) set_lb_cursor(lb,cwdcd);
				strcpy(cwd,sel->name);
				strcpy(cwdcd,sel->name);
				newtEntrySet(l1, sel->name, 1);
				if(sel)
				{
						free(sel->name);
						free(sel);
				}
			} 
			if(sel && S_ISREG(sel->st.st_mode)) // is a directory
			{
				newtEntrySet(l1, sel->name, 1);
			}
		}
		else if (es.reason == es.NEWT_EXIT_COMPONENT && es.u.co == b2) 
		{
			if(strlen(enr3) > 0) 
			{
				strcpy(cwdcd,cwd);
				strcat(cwdcd,"/");
				strcat(cwdcd,enr3);
				if(mkdir(cwdcd,0755) == 0) 
				{
					newtListboxClear(lb);
					dir_here(lb,cwd);
					set_lb_cursor(lb,cwdcd);
					newtEntrySet(l2, "", 1);
				}
			}
		}
		else if (es.reason == es.NEWT_EXIT_COMPONENT && es.u.co == b1)
		{
			ret=strdup(enr2);
		}
	}
	while (es.reason != es.NEWT_EXIT_COMPONENT || es.u.co == lb || es.u.co == b2);
	
	newtFormDestroy(f);
	newtPopWindow();
	
	return ret;
}
Ejemplo n.º 8
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;
}