/* www_process(): * * The program's signal dispatcher function. Is called whenever a signal arrives. */ PROCESS_THREAD(www_process, ev, data) { static struct ctk_widget *w; static unsigned char i; #if WWW_CONF_WITH_WGET static char *argptr; #endif /* WWW_CONF_WITH_WGET */ w = (struct ctk_widget *)data; PROCESS_BEGIN(); /* Create the main window. */ memset(webpage, 0, sizeof(webpage)); ctk_window_new(&mainwindow, WWW_CONF_WEBPAGE_WIDTH, WWW_CONF_WEBPAGE_HEIGHT+5, "Web browser"); make_window(); #ifdef WWW_CONF_HOMEPAGE strncpy(editurl, WWW_CONF_HOMEPAGE, sizeof(editurl)); #endif /* WWW_CONF_HOMEPAGE */ CTK_WIDGET_FOCUS(&mainwindow, &urlentry); #if WWW_CONF_WITH_WGET /* Create download dialog.*/ ctk_dialog_new(&wgetdialog, 38, 7); CTK_WIDGET_ADD(&wgetdialog, &wgetlabel1); CTK_WIDGET_ADD(&wgetdialog, &wgetlabel2); CTK_WIDGET_ADD(&wgetdialog, &wgetnobutton); CTK_WIDGET_ADD(&wgetdialog, &wgetyesbutton); #endif /* WWW_CONF_WITH_WGET */ ctk_window_open(&mainwindow); while(1) { PROCESS_WAIT_EVENT(); if(ev == tcpip_event) { webclient_appcall(data); } else if(ev == ctk_signal_widget_activate) { if(w == (struct ctk_widget *)&backbutton) { firsty = 0; start_loading(); --history_last; if(history_last > WWW_CONF_HISTORY_SIZE) { history_last = WWW_CONF_HISTORY_SIZE - 1; } memcpy(url, history[(int)history_last], WWW_CONF_MAX_URLLEN); open_url(); CTK_WIDGET_FOCUS(&mainwindow, &backbutton); } else if(w == (struct ctk_widget *)&downbutton) { firsty = pagey + WWW_CONF_WEBPAGE_HEIGHT - 4; start_loading(); open_url(); CTK_WIDGET_FOCUS(&mainwindow, &downbutton); } else if(w == (struct ctk_widget *)&gobutton || w == (struct ctk_widget *)&urlentry) { start_loading(); firsty = 0; log_back(); memcpy(url, editurl, WWW_CONF_MAX_URLLEN); petsciiconv_toascii(url, WWW_CONF_MAX_URLLEN); open_url(); CTK_WIDGET_FOCUS(&mainwindow, &gobutton); } else if(w == (struct ctk_widget *)&stopbutton) { loading = 0; webclient_close(); #if WWW_CONF_WITH_WGET } else if(w == (struct ctk_widget *)&wgetnobutton) { ctk_dialog_close(); } else if(w == (struct ctk_widget *)&wgetyesbutton) { ctk_dialog_close(); quit(); argptr = arg_alloc((char)WWW_CONF_MAX_URLLEN); if(argptr != NULL) { strncpy(argptr, url, WWW_CONF_MAX_URLLEN); } program_handler_load("wget.prg", argptr); #endif /* WWW_CONF_WITH_WGET */ #if WWW_CONF_FORMS } else { /* Check form buttons */ for(i = 0; i < pagewidgetptr; ++i) { if(&pagewidgets[i] == w) { formsubmit(&pagewidgetattribs[i].form); /* show_statustext(pagewidgetattribs[i].form.formaction);*/ /* PRINTF(("Formaction %s formname %s inputname %s\n", pagewidgetattribs[i].form.formaction, pagewidgetattribs[i].form.formname, pagewidgetattribs[i].form.inputname));*/ break; } } #endif /* WWW_CONF_FORMS */ } } else if(ev == ctk_signal_hyperlink_activate) { firsty = 0; log_back(); open_link(w->widget.hyperlink.url); CTK_WIDGET_FOCUS(&mainwindow, &stopbutton); /* ctk_window_open(&mainwindow);*/ } else if(ev == ctk_signal_hyperlink_hover) { if(CTK_WIDGET_TYPE((struct ctk_widget *)data) == CTK_WIDGET_HYPERLINK) { strncpy(statustexturl, w->widget.hyperlink.url, sizeof(statustexturl)); petsciiconv_topetscii(statustexturl, sizeof(statustexturl)); show_statustext(statustexturl); } } else if(ev == resolv_event_found) { /* Either found a hostname, or not. */ if((char *)data != NULL && resolv_lookup((char *)data) != NULL) { open_url(); } else { show_statustext("Host not found."); } } else if(ev == ctk_signal_window_close || ev == PROCESS_EVENT_EXIT) { quit(); } } PROCESS_END(); }
/*-----------------------------------------------------------------------------------*/ static void * add_pagewidget(char *text, unsigned char len, unsigned char type, unsigned char border) { register struct ctk_widget *lptr; register char *wptr; static unsigned char maxwidth; static void *dataptr; if(!loading) { return NULL; } if(len + border == 0) { return NULL; } maxwidth = WWW_CONF_WEBPAGE_WIDTH - (1 + 2 * border); /* If the text of the link is too long so that it does not fit into the width of the current window, counting from the current x coordinate, we first try to jump to the next line. */ if(len + x > maxwidth) { htmlparser_newline(); if(!loading) { return NULL; } } /* If the text of the link still is too long, we just chop it off! XXX: this is not really the right thing to do, we should probably either make a link into a multiline link, or add multiple buttons. But this will do for now. */ if(len > maxwidth) { text[maxwidth] = 0; len = maxwidth; } dataptr = NULL; if(firsty == pagey) { wptr = webpageptr; /* To save memory, we'll copy the widget text to the web page drawing area and reference it from there. */ wptr[0] = 0; wptr += border; memcpy(wptr, text, len); wptr[len] = 0; wptr[len + border] = ' '; if(pagewidgetptr < WWW_CONF_MAX_NUMPAGEWIDGETS) { dataptr = &pagewidgetattribs[pagewidgetptr]; lptr = &pagewidgets[pagewidgetptr]; switch(type) { case CTK_WIDGET_HYPERLINK: CTK_HYPERLINK_NEW((struct ctk_hyperlink *)lptr, x, y + 3, len, wptr, dataptr); break; case CTK_WIDGET_BUTTON: CTK_BUTTON_NEW((struct ctk_button *)lptr, x, y + 3, len, wptr); ((struct formattribs *)dataptr)->inputvalue = wptr; break; case CTK_WIDGET_TEXTENTRY: CTK_TEXTENTRY_NEW((struct ctk_textentry *)lptr, x, y + 3, len, 1, wptr, len); ((struct formattribs *)dataptr)->inputvalue = wptr; break; } CTK_WIDGET_SET_FLAG(lptr, CTK_WIDGET_FLAG_MONOSPACE); CTK_WIDGET_ADD(&mainwindow, lptr); ++pagewidgetptr; } } /* Increase the x coordinate with the length of the link text plus the extra space behind it and the CTK button markers. */ len = len + 1 + 2 * border; x += len; if(firsty == pagey) { webpageptr += len; } if(x == WWW_CONF_WEBPAGE_WIDTH) { htmlparser_newline(); } return dataptr; }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(cgterm_process, ev, data) { u16_t *ipaddr; char *cptr; PROCESS_POLLHANDLER(pollhandler()); PROCESS_BEGIN(); ctk_window_new(&window, 38, 5, "C/G term"); CTK_WIDGET_ADD(&window, &hostlabel); CTK_WIDGET_ADD(&window, &hostentry); CTK_WIDGET_ADD(&window, &portlabel); CTK_WIDGET_ADD(&window, &portentry); CTK_WIDGET_ADD(&window, &connectbutton); CTK_WIDGET_ADD(&window, &switchbutton); CTK_WIDGET_ADD(&window, &helplabel); ctk_window_open(&window); while(1) { PROCESS_WAIT_EVENT(); if(ev == tcpip_event) { appcall(data); } else if(ev == ctk_signal_widget_activate) { if(data == &switchbutton) { textmode(); } else if(data == &connectbutton) { serverport = 0; for(cptr = port; *cptr != ' ' && *cptr != 0; ++cptr) { if(*cptr < '0' || *cptr > '9') { continue; } serverport = 10 * serverport + *cptr - '0'; } ipaddr = serveraddr; if(uiplib_ipaddrconv(host, (u8_t *)serveraddr) == 0) { ipaddr = resolv_lookup(host); if(ipaddr == NULL) { resolv_query(host); } else { uip_ipaddr_copy(serveraddr, ipaddr); } } if(ipaddr != NULL) { conn = connect(serveraddr, serverport); if(conn != NULL) { memset((char *)0x0400, 0x20, 40*25); memset((char *)0xd800, 0x01, 40*25); textmode(); } } } } else if(ev == resolv_event_found) { ipaddr = resolv_lookup(host); if(ipaddr != NULL) { uip_ipaddr_copy(serveraddr, ipaddr); conn = connect(serveraddr, serverport); if(conn != NULL) { memset((char *)0x0400, 0x20, 40*25); memset((char *)0xd800, 0x01, 40*25); textmode(); } } } else if(ev == PROCESS_EVENT_EXIT || ev == ctk_signal_window_close) { break; } } ctk_window_close(&window); PROCESS_END(); }
/*-----------------------------------------------------------------------------------*/ EK_EVENTHANDLER(configedit_eventhandler, ev, data) { EK_EVENTHANDLER_ARGS(ev, data); if(ev == EK_EVENT_INIT) { /* Create window. */ ctk_window_new(&window, 32, 18, "Config editor"); CTK_WIDGET_ADD(&window, &cfslabel); CTK_WIDGET_ADD(&window, &cfstextentry); CTK_TEXTENTRY_CLEAR(&cfstextentry); CTK_WIDGET_ADD(&window, &themelabel); CTK_WIDGET_ADD(&window, &themetextentry); CTK_TEXTENTRY_CLEAR(&themetextentry); CTK_WIDGET_ADD(&window, &driverlabel); CTK_WIDGET_ADD(&window, &drivertextentry); CTK_TEXTENTRY_CLEAR(&drivertextentry); CTK_WIDGET_ADD(&window, &screensaverlabel); CTK_WIDGET_ADD(&window, &screensavertextentry); CTK_TEXTENTRY_CLEAR(&screensavertextentry); CTK_WIDGET_ADD(&window, &ipaddrlabel); CTK_WIDGET_ADD(&window, &ipaddrtextentry); CTK_TEXTENTRY_CLEAR(&ipaddrtextentry); CTK_WIDGET_ADD(&window, &netmasklabel); CTK_WIDGET_ADD(&window, &netmasktextentry); CTK_TEXTENTRY_CLEAR(&netmasktextentry); CTK_WIDGET_ADD(&window, &gatewaylabel); CTK_WIDGET_ADD(&window, &gatewaytextentry); CTK_TEXTENTRY_CLEAR(&gatewaytextentry); CTK_WIDGET_ADD(&window, &dnsserverlabel); CTK_WIDGET_ADD(&window, &dnsservertextentry); CTK_TEXTENTRY_CLEAR(&dnsservertextentry); CTK_WIDGET_ADD(&window, &savebutton); CTK_WIDGET_ADD(&window, &cancelbutton); CTK_WIDGET_FOCUS(&window, &cfstextentry); /* Fill the configuration strings with values from the current configuration */ initscript(); ctk_window_open(&window); } else if(ev == ctk_signal_button_activate) { if(data == (ek_data_t)&savebutton) { savescript(); quit_services(); ctk_window_close(&window); configedit_quit(); program_handler_load("config.prg", NULL); } else if(data == (ek_data_t)&cancelbutton) { ctk_window_close(&window); configedit_quit(); } } else if(ev == ctk_signal_window_close || ev == EK_EVENT_REQUEST_EXIT) { ctk_window_close(&window); configedit_quit(); } }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(ftp_process, ev, data) { u16_t ipaddr[2], *ipaddrptr; PROCESS_BEGIN(); ftpc_init(); memset(statustext, 0, sizeof(statustext)); memset(remotefiles, 0, sizeof(remotefiles)); memset(localfiles, 0, sizeof(localfiles)); memset(leftptr, 0, sizeof(leftptr)); memset(midptr, 0, sizeof(midptr)); memset(rightptr, 0, sizeof(rightptr)); ptrstate = PTRSTATE_REMOTEFILES; localptr = remoteptr = 0; connection = NULL; ctk_window_new(&window, 3 + FILES_WIDTH * 2, 3 + FILES_HEIGHT, "FTP Client"); CTK_WIDGET_ADD(&window, &localtextlabel); CTK_WIDGET_ADD(&window, &remotetextlabel); CTK_WIDGET_ADD(&window, &leftptrlabel); CTK_WIDGET_ADD(&window, &localfileslabel); CTK_WIDGET_ADD(&window, &midptrlabel); CTK_WIDGET_ADD(&window, &remotefileslabel); CTK_WIDGET_ADD(&window, &rightptrlabel); CTK_WIDGET_ADD(&window, &reloadbutton); CTK_WIDGET_ADD(&window, &connectionbutton); CTK_WIDGET_ADD(&window, &quitbutton); CTK_WIDGET_ADD(&window, &statuslabel); CTK_WIDGET_FOCUS(&window, &connectionbutton); ctk_window_open(&window); showptr(); start_loaddir(); while(1) { PROCESS_WAIT_EVENT(); if(ev == PROCESS_EVENT_CONTINUE) { if(cfs_readdir(&dir, &dirent) == 0 && localfileptr < FILES_HEIGHT) { strncpy(&localfiles[localfileptr * FILES_WIDTH], dirent.name, FILES_WIDTH); CTK_WIDGET_REDRAW(&localfileslabel); ++localfileptr; process_post(&ftp_process, PROCESS_EVENT_CONTINUE, NULL); } else{ cfs_closedir(&dir); } } else if(ev == PROCESS_EVENT_EXIT) { quit(); } else if(ev == tcpip_event) { ftpc_appcall(data); #if UIP_UDP } else if(ev == resolv_event_found) { /* Either found a hostname, or not. */ if((char *)data != NULL && (ipaddrptr = resolv_lookup((char *)data)) != NULL) { connection = ftpc_connect(ipaddrptr, HTONS(21)); show_statustext("Connecting to ", hostname); } else { show_statustext("Host not found: ", hostname); } #endif /* UIP_UDP */ } else if( #if CTK_CONF_WINDOWCLOSE ev == ctk_signal_window_close && #endif /* CTK_CONF_WINDOWCLOSE */ data == (process_data_t)&window) { quit(); } else if(ev == ctk_signal_widget_activate) { if((struct ctk_button *)data == &quitbutton) { quit(); } else if((struct ctk_button *)data == &cancelbutton) { ctk_dialog_close(); } else if((struct ctk_button *)data == &downloadbutton) { ctk_dialog_close(); close_file(); fd = cfs_open(localfilename, CFS_WRITE); if(fd != -1) { show_statustext("Downloading ", remotefilename); ftpc_get(connection, remotefilename); } else { show_statustext("Could not create ", localfilename); } } else if((struct ctk_button *)data == &reloadbutton) { start_loaddir(); } else if((struct ctk_button *)data == &connectionbutton) { make_connectionwindow(); ctk_dialog_open(&connectionwindow); } else if((struct ctk_button *)data == &closebutton) { ctk_dialog_close(); } else if((struct ctk_button *)data == &anonymousbutton) { strcpy(username, "ftp"); strcpy(password, "contiki@ftp"); CTK_WIDGET_REDRAW(&userentry); CTK_WIDGET_REDRAW(&passwordentry); } else if((struct ctk_button *)data == &closeconnectionbutton) { ctk_dialog_close(); ftpc_close(connection); } else if((struct ctk_button *)data == &connectbutton) { ctk_dialog_close(); #if UIP_UDP if(uiplib_ipaddrconv(hostname, (unsigned char *)ipaddr) == 0) { ipaddrptr = resolv_lookup(hostname); if(ipaddrptr == NULL) { resolv_query(hostname); show_statustext("Resolving host ", hostname); break; } connection = ftpc_connect(ipaddrptr, HTONS(21)); show_statustext("Connecting to ", hostname); } else { connection = ftpc_connect(ipaddr, HTONS(21)); show_statustext("Connecting to ", hostname); } #else /* UIP_UDP */ uiplib_ipaddrconv(hostname, (unsigned char *)ipaddr); connection = ftpc_connect(ipaddr, HTONS(21)); show_statustext("Connecting to ", hostname); #endif /* UIP_UDP */ } /* if((struct ctk_button *)data == &closebutton) { ftpc_close(connection); }*/ } else if(ev == ctk_signal_keypress) { /* if((ctk_arch_key_t)data == ' ') { if(ptrstate == PTRSTATE_LOCALFILES) { ptrstate = PTRSTATE_REMOTEFILES; } else { ptrstate = PTRSTATE_LOCALFILES; } } else */ if((ctk_arch_key_t)(size_t)data == CH_CURS_UP) { clearptr(); if(ptrstate == PTRSTATE_LOCALFILES) { if(localptr > 0) { --localptr; } } else { if(remoteptr > 0) { --remoteptr; } } } else if((ctk_arch_key_t)(size_t)data == CH_CURS_DOWN) { clearptr(); if(ptrstate == PTRSTATE_LOCALFILES) { if(localptr < FILES_HEIGHT - 1) { ++localptr; } } else { if(remoteptr < FILES_HEIGHT - 1) { ++remoteptr; } } } else if((ctk_arch_key_t)(size_t)data == CH_ENTER) { if(ptrstate == PTRSTATE_LOCALFILES) { strncpy(localfilename, &localfiles[localptr * FILES_WIDTH], FILES_WIDTH); strncpy(remotefilename, &localfiles[localptr * FILES_WIDTH], FILES_WIDTH); make_uploaddialog(); ctk_dialog_open(&dialog); } else { strncpy(localfilename, &remotefiles[remoteptr * FILES_WIDTH], FILES_WIDTH); strncpy(remotefilename, &remotefiles[remoteptr * FILES_WIDTH], FILES_WIDTH); ftpc_cwd(connection, remotefilename); /* make_downloaddialog(); ctk_dialog_open(&dialog);*/ } } else if((ctk_arch_key_t)(size_t)data == 'u') { ftpc_cdup(connection); } showptr(); } } PROCESS_END(); }
/*-----------------------------------------------------------------------------------*/ PROCESS_THREAD(program_handler_process, ev, data) { #ifdef WITH_LOADER_ARCH unsigned char err; struct dsc *dsc; #endif /* WITH_LOADER_ARCH */ unsigned char i; struct dsc **dscp; PROCESS_BEGIN(); /* Create the menus */ ctk_menu_add(&contikimenu); #if WITH_LOADER_ARCH runmenuitem = ctk_menuitem_add(&contikimenu, "Run program..."); make_windows(); #endif /* WITH_LOADER_ARCH */ #if QUIT_MENU quitmenuitem = ctk_menuitem_add(&contikimenu, "Quit"); #endif /* QUIT_MENU */ displayname = NULL; #if CTK_CONF_SCREENSAVER program_handler_screensaver[0] = 0; #endif /* CTK_CONF_SCREENSAVER */ while(1) { PROCESS_WAIT_EVENT(); if(ev == ctk_signal_button_activate) { #ifdef WITH_LOADER_ARCH if(data == (process_data_t)&loadbutton) { ctk_window_close(&runwindow); program_handler_load(name, NULL); } else if(data == (process_data_t)&errorokbutton) { ctk_dialog_close(); } #endif /* WITH_LOADER_ARCH */ #if QUIT_MENU if(data == (process_data_t)&quityesbutton) { ctk_draw_init(); exit(EXIT_SUCCESS); } else if(data == (process_data_t)&quitnobutton) { ctk_dialog_close(); } #endif /* QUIT_MENU */ dscp = &contikidsc[0]; for(i = 0; i < CTK_MAXMENUITEMS; ++i) { if(*dscp != NULL #if CTK_CONF_ICONS && data == (process_data_t)(*dscp)->icon #endif /* CTK_CONF_ICONS */ ) { RUN((*dscp)->prgname, (*dscp)->process, NULL); break; } ++dscp; } } else if(ev == ctk_signal_menu_activate) { if((struct ctk_menu *)data == &contikimenu) { #if WITH_LOADER_ARCH dsc = contikidsc[contikimenu.active]; if(dsc != NULL) { RUN(dsc->prgname, dsc->process, NULL); } else if(contikimenu.active == runmenuitem) { make_windows(); ctk_window_close(&runwindow); ctk_window_open(&runwindow); CTK_WIDGET_FOCUS(&runwindow, &nameentry); } #else /* WITH_LOADER_ARCH */ if(contikidsc[contikimenu.active] != NULL) { RUN(contikidsc[contikimenu.active]->prgname, contikidsc[contikimenu.active]->process, NULL); } #endif /* WITH_LOADER_ARCH */ #if QUIT_MENU if(contikimenu.active == quitmenuitem) { ctk_dialog_new(&quitdialog, 24, 5); CTK_WIDGET_ADD(&quitdialog, &quitdialoglabel); CTK_WIDGET_ADD(&quitdialog, &quityesbutton); CTK_WIDGET_ADD(&quitdialog, &quitnobutton); CTK_WIDGET_FOCUS(&quitdialog, &quitnobutton); ctk_dialog_open(&quitdialog); } #endif /* QUIT_MENU */ } #if CTK_CONF_SCREENSAVER } else if(ev == ctk_signal_screensaver_start) { #if WITH_LOADER_ARCH if(program_handler_screensaver[0] != 0) { program_handler_load(program_handler_screensaver, NULL); } #endif /* WITH_LOADER_ARCH */ #endif /* CTK_CONF_SCREENSAVER */ } else if(ev == LOADER_EVENT_DISPLAY_NAME) { #if WITH_LOADER_ARCH if(displayname == NULL) { make_windows(); ctk_label_set_text(&loadingname, ((struct pnarg *)data)->name); ctk_dialog_open(&loadingdialog); process_post(&program_handler_process, LOADER_EVENT_LOAD, data); displayname = data; } else { /* Try again. */ process_post(&program_handler_process, LOADER_EVENT_DISPLAY_NAME, data); } #endif /* WITH_LOADER_ARCH */ } else if(ev == LOADER_EVENT_LOAD) { #if WITH_LOADER_ARCH if(displayname == data) { ctk_dialog_close(); displayname = NULL; log_message("Loading ", ((struct pnarg *)data)->name); err = LOADER_LOAD(((struct pnarg *)data)->name, ((struct pnarg *)data)->arg); if(err != LOADER_OK) { make_windows(); errorfilename[0] = '"'; strncpy(errorfilename + 1, ((struct pnarg *)data)->name, sizeof(errorfilename) - 2); errorfilename[1 + strlen(((struct pnarg *)data)->name)] = '"'; ctk_label_set_text(&errortype, (char *)errormsgs[err]); ctk_dialog_open(&errordialog); log_message((char *)errormsgs[err], errorfilename); } pnarg_free(data); } else { /* Try again. */ process_post(&program_handler_process, LOADER_EVENT_DISPLAY_NAME, data); } #endif /* WITH_LOADEER_ARCH */ } } PROCESS_END(); }
/* www_process(): * * The program's signal dispatcher function. Is called whenever a signal arrives. */ PROCESS_THREAD(www_process, ev, data) { static struct ctk_widget *w; static unsigned char i; #if WWW_CONF_WITH_WGET static char *argptr; #endif /* WWW_CONF_WITH_WGET */ w = (struct ctk_widget *)data; PROCESS_BEGIN(); /* Create the main window. */ memset(webpage, 0, sizeof(webpage)); ctk_window_new(&mainwindow, WWW_CONF_WEBPAGE_WIDTH, WWW_CONF_WEBPAGE_HEIGHT+5, "Web browser"); make_window(); #ifdef WWW_CONF_HOMEPAGE strncpy(editurl, WWW_CONF_HOMEPAGE, sizeof(editurl)); #endif /* WWW_CONF_HOMEPAGE */ CTK_WIDGET_FOCUS(&mainwindow, &urlentry); #if WWW_CONF_WITH_WGET || defined(WWW_CONF_WGET_EXEC) #if CTK_CONF_WINDOWS /* Create download dialog.*/ ctk_dialog_new(&wgetdialog, 38, 7); CTK_WIDGET_ADD(&wgetdialog, &wgetlabel1); CTK_WIDGET_ADD(&wgetdialog, &wgetlabel2); CTK_WIDGET_ADD(&wgetdialog, &wgetnobutton); CTK_WIDGET_ADD(&wgetdialog, &wgetyesbutton); #endif /* CTK_CONF_WINDOWS */ #endif /* WWW_CONF_WITH_WGET || WWW_CONF_WGET_EXEC */ ctk_window_open(&mainwindow); while(1) { PROCESS_WAIT_EVENT(); if(ev == tcpip_event) { webclient_appcall(data); } else if(ev == ctk_signal_widget_activate) { if(w == (struct ctk_widget *)&gobutton || w == (struct ctk_widget *)&urlentry) { start_loading(); firsty = 0; #if WWW_CONF_HISTORY_SIZE > 0 log_back(); #endif /* WWW_CONF_HISTORY_SIZE > 0 */ memcpy(url, editurl, WWW_CONF_MAX_URLLEN); petsciiconv_toascii(url, WWW_CONF_MAX_URLLEN); open_url(); CTK_WIDGET_FOCUS(&mainwindow, &gobutton); #if WWW_CONF_HISTORY_SIZE > 0 } else if(w == (struct ctk_widget *)&backbutton) { firsty = 0; start_loading(); --history_last; if(history_last > WWW_CONF_HISTORY_SIZE) { history_last = WWW_CONF_HISTORY_SIZE - 1; } memcpy(url, history[(int)history_last], WWW_CONF_MAX_URLLEN); open_url(); CTK_WIDGET_FOCUS(&mainwindow, &backbutton); #endif /* WWW_CONF_HISTORY_SIZE > 0 */ } else if(w == (struct ctk_widget *)&downbutton) { firsty = pagey + WWW_CONF_WEBPAGE_HEIGHT - 4; start_loading(); open_url(); CTK_WIDGET_FOCUS(&mainwindow, &downbutton); } else if(w == (struct ctk_widget *)&stopbutton) { loading = 0; webclient_close(); #if WWW_CONF_WITH_WGET || defined(WWW_CONF_WGET_EXEC) } else if(w == (struct ctk_widget *)&wgetnobutton) { #if CTK_CONF_WINDOWS ctk_dialog_close(); #else /* CTK_CONF_WINDOWS */ clear_page(); #endif /* CTK_CONF_WINDOWS */ } else if(w == (struct ctk_widget *)&wgetyesbutton) { #if CTK_CONF_WINDOWS ctk_dialog_close(); #else /* CTK_CONF_WINDOWS */ clear_page(); #endif /* CTK_CONF_WINDOWS */ #if WWW_CONF_WITH_WGET quit(); argptr = arg_alloc((char)WWW_CONF_MAX_URLLEN); if(argptr != NULL) { strncpy(argptr, url, WWW_CONF_MAX_URLLEN); } program_handler_load("wget.prg", argptr); #else /* WWW_CONF_WITH_WGET */ petsciiconv_topetscii(url, sizeof(url)); /* Clear screen */ ctk_restore(); WWW_CONF_WGET_EXEC(url); redraw_window(); show_statustext("Cannot exec wget"); #endif /* WWW_CONF_WITH_WGET */ #endif /* WWW_CONF_WITH_WGET || WWW_CONF_WGET_EXEC */ #if WWW_CONF_FORMS } else { /* Assume form widget. */ struct inputattrib *input = (struct inputattrib *) (((char *)w) - offsetof(struct inputattrib, widget)); formsubmit(input->formptr); #endif /* WWW_CONF_FORMS */ } } else if(ev == ctk_signal_hyperlink_activate) { firsty = 0; #if WWW_CONF_HISTORY_SIZE > 0 log_back(); #endif /* WWW_CONF_HISTORY_SIZE > 0 */ set_link(w->widget.hyperlink.url); show_url(); open_url(); start_loading(); CTK_WIDGET_FOCUS(&mainwindow, &stopbutton); } else if(ev == ctk_signal_hyperlink_hover) { if(CTK_WIDGET_TYPE((struct ctk_widget *)data) == CTK_WIDGET_HYPERLINK) { strncpy(statustexturl, w->widget.hyperlink.url, sizeof(statustexturl)); petsciiconv_topetscii(statustexturl, sizeof(statustexturl)); show_statustext(statustexturl); } #if UIP_UDP } else if(ev == resolv_event_found) { /* Either found a hostname, or not. */ if((char *)data != NULL && resolv_lookup((char *)data, NULL) == RESOLV_STATUS_CACHED) { open_url(); } else { show_statustext("Host not found"); } #endif /* UIP_UDP */ } else if(ev == ctk_signal_window_close || ev == PROCESS_EVENT_EXIT) { quit(); } }
/*---------------------------------------------------------------------------*/ EK_EVENTHANDLER(eventhandler, ev, data) { ctk_arch_key_t c; u16_t *ipaddr; if(ev == EK_EVENT_INIT) { /* ctk_textedit_init(&lineedit);*/ CTK_TEXTENTRY_CLEAR(&lineedit); memset(log, 0, sizeof(log)); ctk_window_new(&window, LOG_WIDTH, LOG_HEIGHT + 1, "IRC"); CTK_WIDGET_ADD(&window, &loglabel); /* ctk_textedit_add(&window, &lineedit); */ CTK_WIDGET_ADD(&window, &lineedit); CTK_WIDGET_FOCUS(&window, &lineedit); ctk_window_new(&setupwindow, SETUPWINDOW_WIDTH, SETUPWINDOW_HEIGHT, "IRC setup"); CTK_WIDGET_ADD(&setupwindow, &serverlabel); CTK_WIDGET_ADD(&setupwindow, &serverentry); CTK_WIDGET_ADD(&setupwindow, &nicklabel); CTK_WIDGET_ADD(&setupwindow, &nickentry); CTK_WIDGET_ADD(&setupwindow, &connectbutton); CTK_WIDGET_ADD(&setupwindow, &quitbutton); CTK_WIDGET_FOCUS(&setupwindow, &serverentry); ctk_window_open(&setupwindow); } else if(ev == EK_EVENT_REQUEST_EXIT) { quit(); } else if(ev == ctk_signal_window_close) { quit(); } else if(ev == tcpip_event) { ircc_appcall(data); } else if(ev == ctk_signal_widget_activate) { if(data == (ek_data_t)&lineedit) { parse_line(); } else if(data == (ek_data_t)&quitbutton) { quit(); } else if(data == (ek_data_t)&connectbutton) { ctk_window_close(&setupwindow); ctk_window_open(&window); ipaddr = serveraddr; if(uiplib_ipaddrconv(server, (u8_t *)serveraddr) == 0) { ipaddr = resolv_lookup(server); if(ipaddr == NULL) { resolv_query(server); } else { uip_ipaddr_copy(serveraddr, ipaddr); } } if(ipaddr != NULL) { ircc_connect(&s, server, serveraddr, nick); } } } else if(ev == resolv_event_found) { ipaddr = resolv_lookup(server); if(ipaddr == NULL) { ircc_text_output(&s, server, "hostname not found"); } else { uip_ipaddr_copy(serveraddr, ipaddr); ircc_connect(&s, server, serveraddr, nick); } } else if(ev == ctk_signal_keypress) { c = (ctk_arch_key_t)data; if(c == CH_ENTER) { parse_line(); } else { /* ctk_textedit_eventhandler(&lineedit, ev, data);*/ CTK_WIDGET_FOCUS(&window, &lineedit); } } }