/** * slice */ JSValueRef sliceForJSBuffer (JSContextRef ctx, JSObjectRef function, JSObjectRef object, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { BUFFER(buffer); MIN_SIZE(2); GET_NUMBER(0,index); GET_NUMBER(1,length); if (length > buffer->length) { JSStringRef string = JSStringCreateWithUTF8CString("length requested is greater than internal buffer length"); JSValueRef message = JSValueMakeString(ctx, string); JSStringRelease(string); *exception = JSObjectMakeError(ctx, 1, &message, 0); return JSValueMakeUndefined(ctx); } if ((int)index >= buffer->length || (int)index < 0) { JSStringRef string = JSStringCreateWithUTF8CString("index requested is invalid"); JSValueRef message = JSValueMakeString(ctx, string); JSStringRelease(string); *exception = JSObjectMakeError(ctx, 1, &message, 0); return JSValueMakeUndefined(ctx); } if (buffer->type!=JSBufferTypePointer) { JSStringRef string = JSStringCreateWithUTF8CString("cannot slice a non-pointer buffer"); JSValueRef message = JSValueMakeString(ctx, string); JSStringRelease(string); *exception = JSObjectMakeError(ctx, 1, &message, 0); return JSValueMakeUndefined(ctx); } throw ref new Exception(0, "JSBuffer's sliceForJSBuffer has not been implemented on Windows yet."); /*void *memory = malloc(length); void *start = &(buffer->buffer[(int)index]); memcpy(memory,start,length); JSBuffer *newbuffer = (JSBuffer *)malloc(sizeof(JSBuffer)); newbuffer->buffer = memory; newbuffer->length = length; newbuffer->type = JSBufferTypePointer; return MakeObjectForJSBuffer(ctx,newbuffer);*/ }
// Very simple menu with a heading and a scrolling banner as a footer char plat_Menu(char **menuItems, char height, char *scroller) { static char *prevScroller, *pScroller, *pEnd; int keyMask; char i, j, sx, sy, numMenuItems, timerInit = 0, maxLen = 0; // If the scroller message chages, cache the new one if(prevScroller != scroller) { prevScroller = scroller; pScroller = scroller; pEnd = scroller + strlen(scroller); } // Find the longest entry for(numMenuItems=0; menuItems[numMenuItems]; ++numMenuItems) { char len = strlen(menuItems[numMenuItems]); if(len > maxLen) maxLen = len; } // Centre on the screen sy = MAX_SIZE(0, (SCREEN_HEIGHT / 2) - (height / 2) - 1); sx = MAX_SIZE(0, (SCREEN_WIDTH / 2) - (maxLen / 2) - 1); maxLen = MIN_SIZE(SCREEN_WIDTH-2, maxLen); // Show the title textcolor(COLOR_GREEN); gotoxy(sx, sy); cprintf(" %.*s ",maxLen, menuItems[0]); // Leave a blank line textcolor(COLOR_BLACK); gotoxy(sx, ++sy); for(j=0; j<maxLen+2; ++j) cputc(' '); // Show all the menu items for(i=1; i<numMenuItems; ++i) { gotoxy(sx, sy+i); cprintf(" %.*s ",maxLen, menuItems[i]); } // Pad with blank lines to menu height for(;i<height;++i) { gotoxy(sx, sy+i); for(j=0; j<maxLen+2; ++j) cputc(' '); } // Select the first item i = 1; do { // Highlight the selected item gotoxy(sx, sy+i); textcolor(COLOR_WHITE); cprintf(">%.*s<",maxLen, menuItems[i]); textcolor(COLOR_BLACK); // Look for user input keyMask = plat_ReadKeys(0); if(keyMask & INPUT_MOTION) { // selection changes so de-highlight the selected item gotoxy(sx, sy+i); cprintf(" %.*s ",maxLen, menuItems[i]); // see if the selection goes up or down switch(keyMask & INPUT_MOTION) { case INPUT_UP: if(!--i) i = numMenuItems-1; break; case INPUT_DOWN: if(numMenuItems == ++i) i = 1; break; } } keyMask &= (INPUT_SELECT | INPUT_BACKUP); // Show the scroller gotoxy(sx,sy+height); textcolor(COLOR_CYAN); cprintf(" %.*s ",maxLen, pScroller); // Wrap the message if needed if((pEnd - pScroller) < maxLen-1) { gotoxy(sx+(pEnd-pScroller)+1,sy+height); cprintf(" %.*s ",maxLen-(pEnd - pScroller)-1, scroller); } // Only update the scrolling when needed if(plat_TimeExpired(SCROLL_SPEED, &timerInit)) { ++pScroller; if(!*pScroller) pScroller = scroller; } } while(keyMask != INPUT_SELECT && keyMask != INPUT_BACKUP); // if backing out of the menu, return 0 if(keyMask & INPUT_BACKUP) return 0; // return the selection return i; }
DialWidget::DialWidget( QWidget *parent, bool isnewaccount, const char *name ) : QWidget(parent, name) { const int GRIDROWS = 11; QGridLayout *tl = new QGridLayout(this, GRIDROWS, 4, 10, 10); tl->addRowSpacing(0, fontMetrics().lineSpacing() - 10); box = new QGroupBox(this); box->setTitle(i18n("Dial Setup")); tl->addMultiCellWidget(box, 0, GRIDROWS-1, 0, 3); connect_label = newLabel(i18n("Connection Name:"), this); tl->addWidget(connect_label, 1, 1); connectname_l = new QLineEdit(this); connectname_l->setMaxLength(ACCNAME_SIZE); FIXED_HEIGHT(connectname_l); MIN_WIDTH(connectname_l); tl->addWidget(connectname_l, 1, 2); KQuickHelp::add(connect_label, KQuickHelp::add(connectname_l, i18n("Type in a unique name for this connection"))); number_label = newLabel(i18n("Phone Number:"), this); tl->addWidget(number_label, 2, 1); number_l = new QLineEdit(this); number_l->setMaxLength(PHONENUMBER_SIZE); KQuickHelp::add(number_label, KQuickHelp::add(number_l, i18n("Specifies the phone number to dial. You\n" "can supply multiple numbers separated by\n" "a colon. When a number is busy or fails,\n" "<i>kppp</i>will try the next number and so on"))); FIXED_WIDTH(number_l); FIXED_HEIGHT(number_l); tl->addWidget(number_l, 2, 2); auth_l = newLabel(i18n("Authentication:"), this); tl->addWidget(auth_l, 4, 1); auth = new QComboBox(this); auth->insertItem(i18n("Script-based")); auth->insertItem(i18n("PAP")); auth->insertItem(i18n("Terminal-based")); auth->insertItem(i18n("CHAP")); MIN_WIDTH(auth); FIXED_HEIGHT(auth); tl->addWidget(auth, 4, 2); KQuickHelp::add(auth_l, KQuickHelp::add(auth, i18n("Specifies the method used to identify yourself to\n" "the PPP server. Most universities still use\n" "<b>Terminal</b>- or <b>Script</b>-based authtentication,\n" "while most ISP use <b>PAP</b> and/or <b>CHAP</b>. If\n" "unsure, contact your ISP.\n" "\n" "If you can choose between PAP and CHAP,\n" "choose CHAP, because it's much safer."))); store_password = newCheckBox(i18n("Store password"), this); store_password->setChecked(true); tl->addMultiCellWidget(store_password, 5, 5, 1, 2); KQuickHelp::add(store_password, i18n("When this is turned on, your ISP password\n" "will be saved in <i>kppp</i>'s config file, so\n" "you do not need to type it in everytime.\n" "\n" "<b><red>Warning:<black> your password will be stored as\n" "plain text in the config file, which is\n" "readable only to you. Make sure nobody\n" "gains access to this file!")); command_label = newLabel(i18n("Execute program\nupon connect:"), this); command_label->setAlignment(AlignVCenter); tl->addWidget(command_label, 6, 1); command = new QLineEdit(this); command->setMaxLength(COMMAND_SIZE); FIXED_HEIGHT(command); MIN_WIDTH(command); tl->addWidget(command, 6, 2); KQuickHelp::add(command_label, KQuickHelp::add(command, i18n("Allows you to run a program <b>after</b> a connection\n" "is established. When your program is called, all\n" "all preparations for an internet connection are\n" "finished.\n" "\n" "Very usefull for fetching mail and news"))); predisconnect_label = newLabel(i18n("Execute program\nbefore disconnect:"), this); predisconnect_label->setAlignment(AlignVCenter); tl->addWidget(predisconnect_label, 7, 1); predisconnect = new QLineEdit(this); predisconnect->setMaxLength(COMMAND_SIZE); FIXED_HEIGHT(predisconnect); MIN_WIDTH(predisconnect); tl->addWidget(predisconnect, 7, 2); KQuickHelp::add(predisconnect_label, KQuickHelp::add(predisconnect, i18n("Allows you to run a program <b>before</b> a connection\n" "is closed. The connection will stay open until\n" "the program exits."))); discommand_label = newLabel(i18n("Execute program\nupon disconnect:"), this); discommand_label->setAlignment(AlignVCenter); tl->addWidget(discommand_label, 8, 1); discommand = new QLineEdit(this); discommand->setMaxLength(COMMAND_SIZE); FIXED_HEIGHT(discommand); MIN_WIDTH(discommand); tl->addWidget(discommand, 8, 2); KQuickHelp::add(discommand_label, KQuickHelp::add(discommand, i18n("Allows you to run a program <b>after</b> a connection\n" "has been closed."))); pppd_label = newLabel(i18n("Edit pppd arguments:"), this); tl->addWidget(pppd_label, 9, 1); QHBoxLayout *l2 = new QHBoxLayout; tl->addLayout(l2, 9, 2); pppdargs = new QPushButton(i18n("Arguments"), this); connect(pppdargs, SIGNAL(clicked()), SLOT(pppdargsbutton())); MIN_SIZE(pppdargs); FIXED_HEIGHT(pppdargs); l2->addWidget(pppdargs); l2->addStretch(3); // Set defaults if editing an existing connection if(!isnewaccount) { connectname_l->setText(gpppdata.accname()); number_l->setText(gpppdata.phonenumber()); command->setText(gpppdata.command_on_connect()); discommand->setText(gpppdata.command_on_disconnect()); predisconnect->setText(gpppdata.command_before_disconnect()); auth->setCurrentItem(gpppdata.authMethod()); store_password->setChecked(gpppdata.storePassword()); } else { // select PAP as default auth->setCurrentItem(1); } tl->activate(); }