-rw-r--r-- | core/apps/embeddedkonsole/TEScreen.cpp | 4 | ||||
-rw-r--r-- | noncore/apps/checkbook/listedit.cpp | 2 | ||||
-rw-r--r-- | noncore/apps/opie-console/TEScreen.cpp | 4 | ||||
-rw-r--r-- | noncore/apps/opie-sheet/Excel.cpp | 2 | ||||
-rw-r--r-- | noncore/apps/tinykate/libkate/document/katedocument.cpp | 4 | ||||
-rw-r--r-- | noncore/comm/keypebble/krfbdecoder.cpp | 6 | ||||
-rw-r--r-- | noncore/games/sfcave/sfcave.cpp | 2 | ||||
-rw-r--r-- | noncore/settings/aqpkg/settingsimpl.cpp | 2 | ||||
-rw-r--r-- | noncore/settings/aqpkg/version.cpp | 2 |
9 files changed, 14 insertions, 14 deletions
diff --git a/core/apps/embeddedkonsole/TEScreen.cpp b/core/apps/embeddedkonsole/TEScreen.cpp index 8e69a88..1db34d2 100644 --- a/core/apps/embeddedkonsole/TEScreen.cpp +++ b/core/apps/embeddedkonsole/TEScreen.cpp @@ -949,288 +949,288 @@ void TEScreen::setBackColorToDefault() { cu_bg = DEFAULT_BACK_COLOR; effectiveRendition(); } /*! */ void TEScreen::setForeColorToDefault() { cu_fg = DEFAULT_FORE_COLOR; effectiveRendition(); } /* ------------------------------------------------------------------------- */ /* */ /* Marking & Selection */ /* */ /* ------------------------------------------------------------------------- */ void TEScreen::clearSelection() { sel_BR = -1; sel_TL = -1; sel_begin = -1; } void TEScreen::setSelBeginXY(const int x, const int y) { if (histCursor > hist.getLines()) { histCursor = hist.getLines(); } sel_begin = loc(x,y+histCursor) ; sel_BR = sel_begin; sel_TL = sel_begin; } void TEScreen::setSelExtentXY(const int x, const int y) { if (sel_begin == -1) return; if (histCursor > hist.getLines()) { histCursor = hist.getLines(); } int l = loc(x,y + histCursor); if (l < sel_begin) { sel_TL = l; sel_BR = sel_begin; } else { /* FIXME, HACK to correct for x too far to the right... */ if (( x == columns )|| (x == 0)) l--; sel_TL = sel_begin; sel_BR = l; } } QString TEScreen::getSelText(const BOOL preserve_line_breaks) { if (sel_begin == -1) return QString::null; // Selection got clear while selecting. int *m; // buffer to fill. int s, d; // source index, dest. index. int hist_BR = loc(0, hist.getLines()); int hY = sel_TL / columns; int hX = sel_TL % columns; int eol; // end of line s = sel_TL; // tracks copy in source. // allocate buffer for maximum // possible size... d = (sel_BR - sel_TL) / columns + 1; m = new int[d * (columns + 1) + 2]; d = 0; while (s <= sel_BR) { if (s < hist_BR) { // get lines from hist.history // buffer. eol = hist.getLineLen(hY); if ((hY == (sel_BR / columns)) && (eol >= (sel_BR % columns))) { eol = sel_BR % columns + 1; } while (hX < eol) { m[d++] = hist.getCell(hY, hX++).c; s++; } if (s <= sel_BR) { // The line break handling // It's different from the screen // image case! if (eol % columns == 0) { // That's either a completely filled // line or an empty line if (eol == 0) { m[d++] = '\n'; } else { // We have a full line. // FIXME: How can we handle newlines // at this position?! } } else if ((eol + 1) % columns == 0) { // FIXME: We don't know if this was a // space at the last position or a // short line!! m[d++] = ' '; } else { // We have a short line here. Put a // newline or a space into the // buffer. m[d++] = preserve_line_breaks ? '\n' : ' '; } } hY++; hX = 0; s = hY * columns; } else { // or from screen image. eol = (s / columns + 1) * columns - 1; if (eol < sel_BR) { while ((eol > s) && isspace(image[eol - hist_BR].c)) { eol--; } } else { eol = sel_BR; } while (s <= eol) { m[d++] = image[s++ - hist_BR].c; } if (eol < sel_BR) { // eol processing see below ... if ((eol + 1) % columns == 0) { if (image[eol - hist_BR].c == ' ') { m[d++] = ' '; } } else { m[d++] = ((preserve_line_breaks || ((eol % columns) == 0)) ? '\n' : ' '); } } s = (eol / columns + 1) * columns; } } QChar* qc = new QChar[d]; for (int i = 0; i < d; i++) { qc[i] = m[i]; } QString res(qc, d); - delete m; - delete qc; + delete [] m; + delete [] qc; return res; } /* above ... end of line processing for selection -- psilva cases: 1) (eol+1)%columns == 0 --> the whole line is filled. If the last char is a space, insert (preserve) space. otherwise leave the text alone, so that words that are broken by linewrap are preserved. FIXME: * this suppresses \n for command output that is sized to the exact column width of the screen. 2) eol%columns == 0 --> blank line. insert a \n unconditionally. Do it either you would because you are in preserve_line_break mode, or because it's an ASCII paragraph delimiter, so even when not preserving line_breaks, you want to preserve paragraph breaks. 3) else --> partially filled line insert a \n in preserve line break mode, else a space The space prevents concatenation of the last word of one line with the first of the next. */ void TEScreen::addHistLine() { assert(hasScroll() || histCursor == 0); // add to hist buffer // we have to take care about scrolling, too... if (hasScroll()){ ca dft; int end = columns - 1; while (end >= 0 && image[end] == dft) end -= 1; hist.addCells( image, end + 1); hist.addLine(); // adjust history cursor histCursor += ( hist.getLines() - 1 == histCursor); } if (!hasScroll()) histCursor = 0; //FIXME: a poor workaround } void TEScreen::setHistCursor(int cursor) { histCursor = cursor; //FIXME:rangecheck if (histCursor > hist.getLines()) { histCursor = hist.getLines(); } if (histCursor < 0) { histCursor = 0; } } void TEScreen::setHorzCursor(int cursor) { horzCursor = cursor; } int TEScreen::getHistCursor() { return histCursor; } int TEScreen::getHorzCursor() { return horzCursor; } int TEScreen::getHistLines() { return hist.getLines(); } void TEScreen::setScroll(bool on) { histCursor = 0; clearSelection(); hist.setScroll(on); } bool TEScreen::hasScroll() { return hist.hasScroll(); } diff --git a/noncore/apps/checkbook/listedit.cpp b/noncore/apps/checkbook/listedit.cpp index e40377b..b297d69 100644 --- a/noncore/apps/checkbook/listedit.cpp +++ b/noncore/apps/checkbook/listedit.cpp @@ -47,309 +47,309 @@ using namespace Opie::Core; // --- ListEdit --------------------------------------------------------------- ListEdit::ListEdit( QWidget *parent, const char *sName ) : QWidget(parent, sName), TableDef(sName) { // get font height int fh = fontMetrics().height(); // create layout QGridLayout *layout=new QGridLayout(this); layout->setSpacing( 2 ); layout->setMargin( 4 ); // type table _typeTable = new QListView( this ); ColumnDef *def=first(); while( def ) { _typeTable->addColumn( def->getName() ); def=next(); } connect( _typeTable, SIGNAL( clicked(QListViewItem*,const QPoint&,int) ), this, SLOT( slotClick(QListViewItem*,const QPoint&,int) ) ); layout->addMultiCellWidget(_typeTable, 0,4,0,4); _currentItem=NULL; // edit field _stack=new QWidgetStack( this ); _stack->setMaximumHeight(fh+5); layout->addMultiCellWidget(_stack, 5,5,0,2); _typeEdit = new QLineEdit( _stack ); _stack->raiseWidget(_typeEdit ); connect( _typeEdit, SIGNAL( textChanged(const QString&) ), this, SLOT( slotEditChanged(const QString&) ) ); // combo box _box=new QComboBox( _stack ); connect( _box, SIGNAL( activated(const QString&) ), this, SLOT( slotActivated(const QString&) ) ); // add button QPushButton *btn = new QPushButton( Opie::Core::OResource::loadPixmap( "new", Opie::Core::OResource::SmallIcon ), tr( "Add" ), this ); btn->setFixedHeight( AppLnk::smallIconSize()+4 ); connect( btn, SIGNAL( clicked() ), this, SLOT( slotAdd() ) ); layout->addWidget( btn, 5, 3 ); // delete button btn = new QPushButton( Opie::Core::OResource::loadPixmap( "trash", Opie::Core::OResource::SmallIcon ), tr( "Delete" ), this ); btn->setFixedHeight( AppLnk::smallIconSize()+4 ); connect( btn, SIGNAL( clicked() ), this, SLOT( slotDel() ) ); layout->addWidget( btn, 5, 4 ); } // --- ~ListEdit -------------------------------------------------------------- ListEdit::~ListEdit() { } // --- slotEditTypeChanged ---------------------------------------------------- void ListEdit::slotEditChanged(const QString &str) { if( !_currentItem || _currentColumn<0 ) return; _currentItem->setText(_currentColumn, str); } // --- slotAddType ------------------------------------------------------------ void ListEdit::slotAdd() { // construct new row QString args[8]; ColumnDef *pCol=this->first(); int i=0; while( pCol && i<8 ) { args[i++]=pCol->getNewValue(); pCol=this->next(); } _currentItem=new QListViewItem(_typeTable, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7] ); // fix uniques fixTypes(); // display col 0 of new value QPoint pnt; slotClick(_currentItem, pnt, 0); _typeTable->setSelected( _currentItem, true ); // make it selected _typeEdit->setCursorPosition(0); _typeEdit->setSelection(0, _typeEdit->text().length() ); } // --- slotDel ------------------------------------------------------------- void ListEdit::slotDel() { if( !_currentItem ) return; delete _currentItem; _currentItem=NULL; _typeEdit->setText(""); _stack->raiseWidget(_typeEdit); } // --- fixTypes ---------------------------------------------------------------- // Makes sure all entries have a unique name and empty entries are replaced // by a generic string. The first version performs the operation on a particular // column, whereas the 2nd does it for all unique columns. class ColMap { public: ColMap(QString sValue, QListViewItem *pEntry) { _sValue=sValue; _pEntry=pEntry; } QString &getValue() { return(_sValue); } QListViewItem *getItem() { return(_pEntry); } protected: QString _sValue; QListViewItem *_pEntry; }; class ColList : public QList<QString> { public: ColList() : QList<QString>() { } protected: int compareItems(QCollection::Item, QCollection::Item); }; int ColList::compareItems(QCollection::Item i1, QCollection::Item i2) { return( ((QString *)i1)->compare(*(QString *)i2) ); } void ListEdit::fixTypes(int iColumn) { // get column def ColumnDef *pDef=this->at(iColumn); // create map of entries if( !_typeTable->childCount() ) return; ColMap **colMap=new ColMap *[_typeTable->childCount()]; QListViewItem *cur=_typeTable->firstChild(); ColList lst; for(int i=0; i<_typeTable->childCount(); i++) { colMap[i]=new ColMap(cur->text(iColumn), cur); lst.append( &(colMap[i]->getValue()) ); cur=cur->nextSibling(); } // fix empty entries int i=0; for(QString *ptr=lst.first(); ptr; ptr=lst.next()) { *ptr=ptr->stripWhiteSpace(); if( ptr->isEmpty() ) { i++; if( i==1 ) *ptr=pDef->getNewValue(); else ptr->sprintf("%s %d", (const char *)pDef->getNewValue(), i); } } // fix dups lst.sort(); QString repl; for(uint iCur=0; iCur<lst.count()-1; iCur++) { QString *current=lst.at(iCur); for(uint iNext=iCur+1; iNext<lst.count(); iNext++ ) { if( *current!=*lst.at(iNext) ) continue; for(int i=2; ; i++) { repl.sprintf("%s %d", (const char *)*current, i); bool bDup=false; uint iChk=iNext+1; while( iChk<lst.count() ) { QString *chk=lst.at(iChk); if( !chk->startsWith(*current) ) break; if( *chk==repl ) { bDup=true; break; } iChk++; } if( !bDup ) { *lst.at(iNext)=repl; break; } } } } lst.sort(); // copy back clean up col map for(int i=0; i<_typeTable->childCount(); i++) { colMap[i]->getItem()->setText(iColumn, colMap[i]->getValue()); delete colMap[i]; } - delete colMap; + delete [] colMap; } void ListEdit::fixTypes() { int i; ColumnDef *pDef; for(pDef=this->first(), i=0; pDef; pDef=this->next(), i++) { if( pDef->hasFlag(ColumnDef::typeUnique) ) fixTypes(i); } _typeTable->sort(); } // --- storeInList ------------------------------------------------------------ void ListEdit::storeInList(QStringList &lst) { // delete old content lst.clear(); // add new one fixTypes(); QListViewItem *itm=_typeTable->firstChild(); while( itm ) { int i=0; QString sAdd; ColumnDef *pDef; for(pDef=this->first(), i=0; pDef; pDef=this->next(), i++) { if( i>=1 ) sAdd+=";"; sAdd += itm->text(i); } lst.append( sAdd ); itm=itm->nextSibling(); } } // --- slotClicked ------------------------------------------------------------ void ListEdit::slotClick(QListViewItem *itm, const QPoint &pnt, int col) { (void)pnt; // get rid of unused warning; // save values _currentItem=itm; _currentColumn=col; if( itm==NULL ) { _typeEdit->setText(""); _stack->raiseWidget(_typeEdit); return; } // display value if( _currentColumn<0 ) _currentColumn=0; ColumnDef *pDef=this->at(_currentColumn); if( pDef->isType(ColumnDef::typeString) ) { _typeEdit->setText( _currentItem->text(_currentColumn) ); _stack->raiseWidget(_typeEdit); } else if( pDef->isType(ColumnDef::typeList) ){ _box->clear(); _box->insertStringList( pDef->getValueList() ); QStringList::Iterator itr; int i=0; for(itr=pDef->getValueList().begin(); itr!=pDef->getValueList().end(); itr++) { if( (*itr)==_currentItem->text(_currentColumn) ) { _box->setCurrentItem(i); i=-1; break; } i++; } if( i>=0 ) { _box->insertItem( _currentItem->text(_currentColumn) ); _box->setCurrentItem(i); } _stack->raiseWidget(_box); } else { odebug << "Unsupported column type for column " << (const char *)pDef->getName() << "" << oendl; _typeEdit->setText(""); _stack->raiseWidget(_typeEdit); } } // --- addColumnDef ----------------------------------------------------------- void ListEdit::addColumnDef(ColumnDef *pDef) { _typeTable->addColumn( pDef->getName() ); _vColumns.append(pDef); } // --- addData ---------------------------------------------------------------- void ListEdit::addData(QStringList &lst) { // run through list QStringList::Iterator itr; for(itr=lst.begin(); itr!=lst.end(); itr++) { QStringList split=QStringList::split(";", *itr, true); QStringList::Iterator entry; QString args[8]; int i=0; for(entry=split.begin(); entry!=split.end() && i<8; entry++, i++) { args[i]= (*entry); } while(i<8) { args[i++]=""; } new QListViewItem(_typeTable, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7]); } } // --- slotActivated ---------------------------------------------------------- void ListEdit::slotActivated(const QString &str) { if( _currentItem==NULL || _currentColumn<0 ) return; _currentItem->setText(_currentColumn, str); } diff --git a/noncore/apps/opie-console/TEScreen.cpp b/noncore/apps/opie-console/TEScreen.cpp index 2675d31..8e91532 100644 --- a/noncore/apps/opie-console/TEScreen.cpp +++ b/noncore/apps/opie-console/TEScreen.cpp @@ -926,283 +926,283 @@ void TEScreen::setBackColor(int bgcolor) } /*! */ void TEScreen::setBackColorToDefault() { cu_bg = DEFAULT_BACK_COLOR; effectiveRendition(); } /*! */ void TEScreen::setForeColorToDefault() { cu_fg = DEFAULT_FORE_COLOR; effectiveRendition(); } /* ------------------------------------------------------------------------- */ /* */ /* Marking & Selection */ /* */ /* ------------------------------------------------------------------------- */ void TEScreen::clearSelection() { sel_BR = -1; sel_TL = -1; sel_begin = -1; } void TEScreen::setSelBeginXY(const int x, const int y) { sel_begin = loc(x,y+histCursor) ; sel_BR = sel_begin; sel_TL = sel_begin; } void TEScreen::setSelExtentXY(const int x, const int y) { if (sel_begin == -1) return; int l = loc(x,y + histCursor); if (l < sel_begin) { sel_TL = l; sel_BR = sel_begin; } else { /* FIXME, HACK to correct for x too far to the right... */ if (( x == columns )|| (x == 0)) l--; sel_TL = sel_begin; sel_BR = l; } } QString TEScreen::getSelText(const BOOL preserve_line_breaks) { if (sel_begin == -1) return QString::null; // Selection got clear while selecting. int *m; // buffer to fill. int s, d; // source index, dest. index. int hist_BR = loc(0, hist.getLines()); int hY = sel_TL / columns; int hX = sel_TL % columns; int eol; // end of line s = sel_TL; // tracks copy in source. // allocate buffer for maximum // possible size... d = (sel_BR - sel_TL) / columns + 1; m = new int[d * (columns + 1) + 2]; d = 0; while (s <= sel_BR) { if (s < hist_BR) { // get lines from hist.history // buffer. eol = hist.getLineLen(hY); if ((hY == (sel_BR / columns)) && (eol >= (sel_BR % columns))) { eol = sel_BR % columns + 1; } while (hX < eol) { m[d++] = hist.getCell(hY, hX++).c; s++; } if (s <= sel_BR) { // The line break handling // It's different from the screen // image case! if (eol % columns == 0) { // That's either a completely filled // line or an empty line if (eol == 0) { m[d++] = '\n'; } else { // We have a full line. // FIXME: How can we handle newlines // at this position?! } } else if ((eol + 1) % columns == 0) { // FIXME: We don't know if this was a // space at the last position or a // short line!! m[d++] = ' '; } else { // We have a short line here. Put a // newline or a space into the // buffer. m[d++] = preserve_line_breaks ? '\n' : ' '; } } hY++; hX = 0; s = hY * columns; } else { // or from screen image. eol = (s / columns + 1) * columns - 1; if (eol < sel_BR) { while ((eol > s) && isspace(image[eol - hist_BR].c)) { eol--; } } else { eol = sel_BR; } while (s <= eol) { m[d++] = image[s++ - hist_BR].c; } if (eol < sel_BR) { // eol processing see below ... if ((eol + 1) % columns == 0) { if (image[eol - hist_BR].c == ' ') { m[d++] = ' '; } } else { m[d++] = ((preserve_line_breaks || ((eol % columns) == 0)) ? '\n' : ' '); } } s = (eol / columns + 1) * columns; } } QChar* qc = new QChar[d]; for (int i = 0; i < d; i++) { qc[i] = m[i]; } QString res(qc, d); - delete m; - delete qc; + delete [] m; + delete [] qc; return res; } QString TEScreen::getHistory() { sel_begin = 0; sel_BR = sel_begin; sel_TL = sel_begin; setSelExtentXY(columns-1,lines-1); QString tmp=getSelText(true); while (tmp.at(tmp.length()-2).unicode()==10 && tmp.at(tmp.length()-1).unicode()==10) tmp.truncate(tmp.length()-1); return tmp; } /* above ... end of line processing for selection -- psilva cases: 1) (eol+1)%columns == 0 --> the whole line is filled. If the last char is a space, insert (preserve) space. otherwise leave the text alone, so that words that are broken by linewrap are preserved. FIXME: * this suppresses \n for command output that is sized to the exact column width of the screen. 2) eol%columns == 0 --> blank line. insert a \n unconditionally. Do it either you would because you are in preserve_line_break mode, or because it's an ASCII paragraph delimiter, so even when not preserving line_breaks, you want to preserve paragraph breaks. 3) else --> partially filled line insert a \n in preserve line break mode, else a space The space prevents concatenation of the last word of one line with the first of the next. */ void TEScreen::addHistLine() { assert(hasScroll() || histCursor == 0); // add to hist buffer // we have to take care about scrolling, too... if (hasScroll()) { ca dft; int end = columns-1; while (end >= 0 && image[end] == dft) end -= 1; hist.addCells(image,end+1); hist.addLine(); // adjust history cursor histCursor += (hist.getLines()-1 == histCursor); } if (!hasScroll()) histCursor = 0; //FIXME: a poor workaround } void TEScreen::setHistCursor(int cursor) { histCursor = cursor; //FIXME:rangecheck } int TEScreen::getHistCursor() { return histCursor; } int TEScreen::getHistLines() { return hist.getLines(); } void TEScreen::setScroll(bool on) { histCursor = 0; clearSelection(); hist.setScroll(on); } bool TEScreen::hasScroll() { return hist.hasScroll(); } diff --git a/noncore/apps/opie-sheet/Excel.cpp b/noncore/apps/opie-sheet/Excel.cpp index 338bc30..51fe707 100644 --- a/noncore/apps/opie-sheet/Excel.cpp +++ b/noncore/apps/opie-sheet/Excel.cpp @@ -149,385 +149,385 @@ double ExcelBook::Double4Byte(int b1, int b2, int b3, int b4) printf("Double4Byte: VALUE=%f\r\n",value); if ( (rk & 0x01) != 0) { value /= 100.0; }; return value; }; }; void ExcelBook::DetectEndian(void) { int end; long i = 0x44332211; unsigned char* a = (unsigned char*) &i; end = (*a != 0x11); if (end == 1) { endian = BIG_ENDIAN; printf("BIGENDIAN!\r\n"); } else { endian = LITTLE_ENDIAN; printf("LITTLEENDIAN!\r\n"); } }; double ExcelBook::Double8Byte(int b1, int b2, int b3, int b4, int b5, int b6, int b7, int b8) { int i; double d; unsigned char *ieee; ieee = (unsigned char *)&d; for (i = 0; i < 8; i++) ieee[i] = 0; if (endian == BIG_ENDIAN) { ieee[0] = ((int)b8) & 0xff;ieee[1] = ((int)b7) & 0xff; ieee[2] = ((int)b6) & 0xff;ieee[3] = ((int)b5) & 0xff; ieee[4] = ((int)b4) & 0xff;ieee[5] = ((int)b3) & 0xff; ieee[6] = ((int)b2) & 0xff;ieee[7] = ((int)b1) & 0xff; } else { ieee[0] = ((int)b1) & 0xff;ieee[1] = ((int)b2) & 0xff; ieee[2] = ((int)b3) & 0xff;ieee[3] = ((int)b4) & 0xff; ieee[4] = ((int)b5) & 0xff;ieee[5] = ((int)b6) & 0xff; ieee[6] = ((int)b7) & 0xff;ieee[7] = ((int)b8) & 0xff; } return d; }; bool ExcelBook::OpenFile(char *Filename) { printf("Opening excel file!\r\n"); File= fopen(Filename, "r"); Position=0; // first byte index in file XFRecords.resize(0); SharedStrings.resize(0); Names.resize(0); Sheets.resize(0); if(File==NULL) return false; printf("Opened excel file!\r\n"); return true; }; bool ExcelBook::CloseFile(void) { int w1; for(w1=0;w1<(int)XFRecords.count();w1++) { if(XFRecords[w1]!=NULL) {delete XFRecords[w1];XFRecords[w1]=NULL;}; }; for(w1=0;w1<(int)SharedStrings.count();w1++) { if(SharedStrings[w1]!=NULL) {delete SharedStrings[w1];SharedStrings[w1]=NULL;}; }; for(w1=0;w1<(int)Names.count();w1++) { if(Names[w1]!=NULL) {delete Names[w1];Names[w1]=NULL;}; }; for(w1=0;w1<(int)Sheets.count();w1++) { if(Sheets[w1]!=NULL) {delete Sheets[w1];Sheets[w1]=NULL;}; }; XFRecords.resize(0); SharedStrings.resize(0); Names.resize(0); Sheets.resize(0); fclose(File); printf("closed excel file!\r\n"); if(File==NULL) return true; return false; }; void ExcelBook::SeekPosition(int pos) { if(!feof(File)) { Position=pos; //printf("SeekPosition:Pos:%d\r\n",Position); fseek(File,pos,SEEK_SET); }; }; void ExcelBook::SeekSkip(int pos) { if(!feof(File)) { Position=Position+pos; //printf("SeekSkip:Pos:%d\r\n",Position); fseek(File, Position, SEEK_SET); }; }; int ExcelBook::FileEOF(void) { if(File!=NULL) return(feof(File)); else return 0; //EOF is defined in stdlib as -1 }; int ExcelBook::Get2Bytes(void) { int i1,i2; i1=0; i2=0; if (!feof(File)) { i1=fgetc(File); Position++; }; if (!feof(File)) { i2=fgetc(File); Position++; }; return Integer2Byte(i1,i2); }; char* ExcelBook::Read(int pos, int length) { int i; char *data; data= new char[length]; SeekPosition(pos); for(i=0; i<length; i++) { if(!feof(File)) data[i]=fgetc(File); }; Position= Position+length; return data; }; QString ExcelBook::ReadUnicodeChar(int pos, int length) { int i; QString data; int i1=' ',i2=' ',ii; SeekPosition(pos); for(i=0; i<length; i++) { if(!feof(File)) i1=fgetc(File); if(!feof(File)) i2=fgetc(File); ii=Integer2Byte(i1,i2); data.append(ii); Position+=2; }; return data; }; QString* ExcelBook::GetString(int num) { if(num>=0 && num<(int)SharedStrings.count()) { return SharedStrings[num]; }; return new QString(""); }; int ExcelBook::SeekBOF(void) { int opcode,version,streamtype,length,ret=0; char *data; while(!feof(File)) { opcode=Get2Bytes(); if(opcode==XL_BOF) { length=Get2Bytes(); data=Read(Position,length); version=Integer2Byte(data[0], data[1]); streamtype=Integer2Byte(data[2], data[3]); printf("SEEKBOF:opcode=XLBOF, %d ,version %d\r\n",Position,version); - delete data; data=NULL; + delete [] data; data=NULL; if (version==BIFF8) ret=8; else if(version==BIFF7) ret=7; printf("SEEKBOF:versionBIFF%d\r\n",ret); if(streamtype==WBKGLOBAL) return ret *2; else if(streamtype==WRKSHEET) return ret *1; return 1; }; }; return 0; }; ExcelBREC* ExcelBook::GetBREC(void) { ExcelBREC* rec; rec= new ExcelBREC; if(FileEOF()) return NULL; rec->data=NULL; rec->code=Get2Bytes(); rec->length=Get2Bytes(); rec->position=Position; SeekSkip(rec->length); return rec; }; ExcelBREC* ExcelBook::PeekBREC(void) { int oldpos; ExcelBREC* NextRec; oldpos=Position; NextRec=GetBREC(); SeekPosition(oldpos); return NextRec; }; char* ExcelBook::GetDataOfBREC(ExcelBREC* record) { if(record->data==NULL) { ConvertCharToArray(record,Read(record->position,record->length),record->length); }; return record->data;//new? }; void ExcelBook::ConvertCharToArray(ExcelBREC* record, char* chars, int length) { record->data=new char[length]; for(int w1=0;w1<=length-1;w1++) record->data[w1]=chars[w1]; }; bool ExcelSheet::InitCells() { int r; Cells.resize(rows * cols + cols+1); if(Cells.count()==0) return false; for(r=0;r < Cells.count();r++) { Cells[r]=NULL; }; return true; }; void ExcelSheet::Set(int row, int col, ExcelCell* cell) { if(cell!=NULL&&(row*cols+col)<Cells.count()) { Cells[row*cols+col]=cell; }; }; ExcelCell* ExcelSheet::Get(int row, int col) { ExcelCell* cell; cell=Cells[row*cols+col]; if(cell==NULL) return NULL; return cell; }; int ExcelBook::SheetHandleRecord(ExcelSheet* sheet, ExcelBREC* record) { char* data=NULL; switch (record->code) { case XL_DIMENSION: data = GetDataOfBREC(record); if (record->length == 10) { sheet->rows = Integer2Byte(data[2], data[3]); sheet->cols = Integer2Byte(data[6], data[7]); } else { sheet->rows = Integer4Byte(data[4], data[5], data[6], data[7]); sheet->cols = Integer2Byte(data[10], data[11]); } sheet->InitCells(); break; case XL_LABELSST: HandleLabelSST(sheet, record); break; case XL_RK: case XL_RK2: HandleRK(sheet, record); break; case XL_MULRK: HandleMulrk(sheet, record); break; case XL_ROW: break; case XL_NUMBER: HandleNumber(sheet, record); break; case XL_BOOLERR: break; case XL_CONTINUE: break; case XL_FORMULA: case XL_FORMULA2: HandleFormula(sheet, record); break; case XL_LABEL: break; case XL_NAME: HandleName(sheet, record); break; case XL_BOF: break; case XL_EOF: return 0; default: break; }; return 1; }; int ExcelBook::ReadSheet(ExcelSheet* sheet) { ExcelBREC* record; int oldpos; oldpos = Position; SeekPosition(sheet->position); record = GetBREC(); while (record!=NULL) { if (!SheetHandleRecord(sheet, record)) break; record=GetBREC(); }; SeekPosition(oldpos); return 1; }; ExcelSheet* ExcelBook::GetSheet(void) { ExcelSheet* sh=NULL; int type; type=SeekBOF(); Version=type; sh=new ExcelSheet; if(type) { sh->type=type; sh->position=Position; sh->name=QString(""); }; if(type==8||type==7) { ReadSheet(sh); }; return sh; }; void ExcelBook::ParseSheets(void) { int BOFs; ExcelBREC* r; BOFs=1; r=GetBREC(); while(BOFs) { r=GetBREC(); diff --git a/noncore/apps/tinykate/libkate/document/katedocument.cpp b/noncore/apps/tinykate/libkate/document/katedocument.cpp index 6dc4fd2..a70f3aa 100644 --- a/noncore/apps/tinykate/libkate/document/katedocument.cpp +++ b/noncore/apps/tinykate/libkate/document/katedocument.cpp @@ -2030,446 +2030,446 @@ void KateDocument::paintTextLine(QPainter &paint, int line, int y, int xStart, i do { xc = x; zc = z; if (z == len) break; ch = s[z];//textLine->getChar(z); if (ch == '\t') { x += m_tabWidth - (x % m_tabWidth); } else { a = &m_attribs[textLine->getAttr(z)]; if (a->bold && a->italic) x += myFontMetricsBI.width(ch); else if (a->bold) x += myFontMetricsBold.width(ch); else if (a->italic) x += myFontMetricsItalic.width(ch); else x += myFontMetrics.width(ch); } z++; } while (x <= xStart); // draw background xs = xStart; attr = textLine->getRawAttr(zc); while (x < xEnd) { nextAttr = textLine->getRawAttr(z); if ((nextAttr ^ attr) & taSelected) { if (attr & taSelected) paint.fillRect(xs - xStart, y, x - xs, fontHeight, colors[1]); else paint.fillRect(xs - xStart, y, x - xs, fontHeight, colors[0]); xs = x; attr = nextAttr; } if (z == len) break; ch = s[z];//textLine->getChar(z); if (ch == '\t') x += m_tabWidth - (x % m_tabWidth); else { a = &m_attribs[textLine->getAttr(z)]; if (a->bold && a->italic) x += myFontMetricsBI.width(ch); else if (a->bold) x += myFontMetricsBold.width(ch); else if (a->italic) x += myFontMetricsItalic.width(ch); else x += myFontMetrics.width(ch); } z++; } if (attr & taSelected) paint.fillRect(xs - xStart, y, xEnd - xs, fontHeight, colors[1]); else paint.fillRect(xs - xStart, y, xEnd - xs, fontHeight, colors[0]); len = z; //reduce length to visible length // draw text x = xc; z = zc; y += fontAscent;// -1; attr = -1; while (z < len) { ch = s[z];//textLine->getChar(z); if (ch == '\t') { if (z > zc) { //this should cause no copy at all QConstString str((QChar *) &s[zc], z - zc /*+1*/); QString s = str.string(); paint.drawText(x - xStart, y, s); if (a->bold && a->italic) x += myFontMetricsBI.width(s); else if (a->bold) x += myFontMetricsBold.width(s); else if (a->italic) x += myFontMetricsItalic.width(s); else x += myFontMetrics.width(s); } zc = z +1; if (showTabs) { nextAttr = textLine->getRawAttr(z); if (nextAttr != attr) { attr = nextAttr; a = &m_attribs[attr & taAttrMask]; if (attr & taSelected) paint.setPen(a->selCol); else paint.setPen(a->col); if (a->bold && a->italic) paint.setFont(myFontBI); else if (a->bold) paint.setFont(myFontBold); else if (a->italic) paint.setFont(myFontItalic); else paint.setFont(myFont); } // paint.drawLine(x - xStart, y -2, x - xStart, y); // paint.drawLine(x - xStart, y, x - xStart + 2, y); paint.drawPoint(x - xStart, y); paint.drawPoint(x - xStart +1, y); paint.drawPoint(x - xStart, y -1); } x += m_tabWidth - (x % m_tabWidth); } else { nextAttr = textLine->getRawAttr(z); if (nextAttr != attr) { if (z > zc) { QConstString str((QChar *) &s[zc], z - zc /*+1*/); QString s = str.string(); paint.drawText(x - xStart, y, s); if (a->bold && a->italic) x += myFontMetricsBI.width(s); else if (a->bold) x += myFontMetricsBold.width(s); else if (a->italic) x += myFontMetricsItalic.width(s); else x += myFontMetrics.width(s); zc = z; } attr = nextAttr; a = &m_attribs[attr & taAttrMask]; if (attr & taSelected) paint.setPen(a->selCol); else paint.setPen(a->col); if (a->bold && a->italic) paint.setFont(myFontBI); else if (a->bold) paint.setFont(myFontBold); else if (a->italic) paint.setFont(myFontItalic); else paint.setFont(myFont); } } z++; } if (z > zc) { QConstString str((QChar *) &s[zc], z - zc /*+1*/); paint.drawText(x - xStart, y, str.string()); } } // Applies the search context, and returns whether a match was found. If one is, // the length of the string matched is also returned. bool KateDocument::doSearch(SConfig &sc, const QString &searchFor) { int line, col; int searchEnd; int bufLen, tlen; QChar *t; TextLine::Ptr textLine; int pos, newPos; if (searchFor.isEmpty()) return false; bufLen = 0; t = 0L; line = sc.cursor.y; col = sc.cursor.x; if (!(sc.flags & KateView::sfBackward)) { //forward search if (sc.flags & KateView::sfSelected) { if (line < selectStart) { line = selectStart; col = 0; } searchEnd = selectEnd; } else searchEnd = lastLine(); while (line <= searchEnd) { textLine = getTextLine(line); tlen = textLine->length(); if (tlen > bufLen) { - delete t; + delete [] t; bufLen = (tlen + 255) & (~255); t = new QChar[bufLen]; } memcpy(t, textLine->getText(), tlen*sizeof(QChar)); if (sc.flags & KateView::sfSelected) { pos = 0; do { pos = textLine->findSelected(pos); newPos = textLine->findUnselected(pos); memset(&t[pos], 0, (newPos - pos)*sizeof(QChar)); pos = newPos; } while (pos < tlen); } QString text(t, tlen); if (sc.flags & KateView::sfWholeWords) { // Until the end of the line... while (col < tlen) { // ...find the next match. col = sc.search(text, col); if (col != -1) { // Is the match delimited correctly? if (((col == 0) || (!m_highlight->isInWord(t[col]))) && ((col + sc.matchedLength == tlen) || (!m_highlight->isInWord(t[col + sc.matchedLength])))) { goto found; } else { // Start again from the next character. col++; } } else { // No match. break; } } } else { // Non-whole-word search. col = sc.search(text, col); if (col != -1) goto found; } col = 0; line++; } } else { // backward search if (sc.flags & KateView::sfSelected) { if (line > selectEnd) { line = selectEnd; col = -1; } searchEnd = selectStart; } else searchEnd = 0; while (line >= searchEnd) { textLine = getTextLine(line); tlen = textLine->length(); if (tlen > bufLen) { - delete t; + delete [] t; bufLen = (tlen + 255) & (~255); t = new QChar[bufLen]; } memcpy(t, textLine->getText(), tlen*sizeof(QChar)); if (sc.flags & KateView::sfSelected) { pos = 0; do { pos = textLine->findSelected(pos); newPos = textLine->findUnselected(pos); memset(&t[pos], 0, (newPos - pos)*sizeof(QChar)); pos = newPos; } while (pos < tlen); } if (col < 0 || col > tlen) col = tlen; QString text(t, tlen); if (sc.flags & KateView::sfWholeWords) { // Until the beginning of the line... while (col >= 0) { // ...find the next match. col = sc.search(text, col); if (col != -1) { // Is the match delimited correctly? if (((col == 0) || (!m_highlight->isInWord(t[col]))) && ((col + sc.matchedLength == tlen) || (!m_highlight->isInWord(t[col + sc.matchedLength])))) { goto found; } else { // Start again from the previous character. col--; } } else { // No match. break; } } } else { // Non-whole-word search. col = sc.search(text, col); if (col != -1) goto found; } col = -1; line--; } } sc.flags |= KateView::sfWrapped; return false; found: if (sc.flags & KateView::sfWrapped) { if ((line > sc.startCursor.y || (line == sc.startCursor.y && col >= sc.startCursor.x)) ^ ((sc.flags & KateView::sfBackward) != 0)) return false; } sc.cursor.x = col; sc.cursor.y = line; return true; } void KateDocument::tagLine(int line) { if (tagStart > line) tagStart = line; if (tagEnd < line) tagEnd = line; } void KateDocument::insLine(int line) { KateView *view; if (selectStart >= line) selectStart++; if (selectEnd >= line) selectEnd++; if (tagStart >= line) tagStart++; if (tagEnd >= line) tagEnd++; newDocGeometry = true; for (view = views.first(); view != 0L; view = views.next() ) { view->insLine(line); } } void KateDocument::delLine(int line) { KateView *view; if (selectStart >= line && selectStart > 0) selectStart--; if (selectEnd >= line) selectEnd--; if (tagStart >= line && tagStart > 0) tagStart--; if (tagEnd >= line) tagEnd--; newDocGeometry = true; for (view = views.first(); view != 0L; view = views.next() ) { view->delLine(line); } } void KateDocument::optimizeSelection() { TextLine::Ptr textLine; while (selectStart <= selectEnd) { textLine = getTextLine(selectStart); if (textLine->isSelected() || textLine->numSelected() > 0) break; selectStart++; } while (selectEnd >= selectStart) { textLine = getTextLine(selectEnd); if (textLine->isSelected() || textLine->numSelected() > 0) break; selectEnd--; } if (selectStart > selectEnd) { selectStart = 0xffffff; selectEnd = 0; } } void KateDocument::doAction(KateAction *a) { switch (a->action) { case KateAction::replace: doReplace(a); break; case KateAction::wordWrap: doWordWrap(a); break; case KateAction::wordUnWrap: doWordUnWrap(a); break; case KateAction::newLine: doNewLine(a); break; case KateAction::delLine: doDelLine(a); break; case KateAction::insLine: doInsLine(a); break; case KateAction::killLine: doKillLine(a); break; /* case KateAction::doubleLine: break; case KateAction::removeLine: break;*/ } } void KateDocument::doReplace(KateAction *a) { TextLine::Ptr textLine; int l; //exchange current text with stored text in KateAction *a textLine = getTextLine(a->cursor.y); l = textLine->length() - a->cursor.x; if (l > a->len) l = a->len; QString oldText(&textLine->getText()[a->cursor.x], (l < 0) ? 0 : l); textLine->replace(a->cursor.x, a->len, a->text.unicode(), a->text.length()); a->len = a->text.length(); a->text = oldText; buffer->changeLine(a->cursor.y); tagLine(a->cursor.y); } void KateDocument::doWordWrap(KateAction *a) { TextLine::Ptr textLine; textLine = getTextLine(a->cursor.y - 1); a->len = textLine->length() - a->cursor.x; textLine->wrap(getTextLine(a->cursor.y),a->len); buffer->changeLine(a->cursor.y - 1); buffer->changeLine(a->cursor.y); tagLine(a->cursor.y - 1); tagLine(a->cursor.y); if (selectEnd == a->cursor.y - 1) selectEnd++; a->action = KateAction::wordUnWrap; } void KateDocument::doWordUnWrap(KateAction *a) { TextLine::Ptr textLine; textLine = getTextLine(a->cursor.y - 1); // textLine->setLength(a->len); textLine->unWrap(a->len, getTextLine(a->cursor.y),a->cursor.x); buffer->changeLine(a->cursor.y - 1); buffer->changeLine(a->cursor.y); diff --git a/noncore/comm/keypebble/krfbdecoder.cpp b/noncore/comm/keypebble/krfbdecoder.cpp index 837fcc5..27ae101 100644 --- a/noncore/comm/keypebble/krfbdecoder.cpp +++ b/noncore/comm/keypebble/krfbdecoder.cpp @@ -36,796 +36,796 @@ const int ServerInitLength = 24; const int UpdateHeaderLength = 4; const int RectHeaderLength = 12; const int RectChunkSize = 4; const int CopyRectPosLength = 4; const int ServerCutLenLength = 7; // // Client -> Server Message Identifiers // static CARD8 SetPixelFormatId = 0; //static CARD8 FixColourMapEntriesId = 1; // Not used static CARD8 SetEncodingsId = 2; static CARD8 UpdateRequestId = 3; static CARD8 KeyEventId = 4; static CARD8 PointerEventId = 5; static CARD8 ClientCutTextId = 6; // // Server -> Client Message Identifiers // static CARD8 UpdateId = 0; static CARD8 BellId = 2; static CARD8 ServerCutId = 3; // // Encoding identifiers // static CARD32 RawEncoding = Swap32IfLE( 0 ); static CARD32 CopyRectEncoding = Swap32IfLE(1 ); static CARD32 RreEncoding = Swap32IfLE( 2 ); static CARD32 CorreEncoding = Swap32IfLE( 4 ); static CARD32 HexTileEncoding = Swap32IfLE( 5 ); static struct { int keysym; int keycode; } keyMap[] = { { 0xff08, Qt::Key_Backspace }, { 0xff09, Qt::Key_Tab }, { 0xff0d, Qt::Key_Return }, { 0xff1b, Qt::Key_Escape }, { 0xff63, Qt::Key_Insert }, { 0xffff, Qt::Key_Delete }, { 0xff50, Qt::Key_Home }, { 0xff57, Qt::Key_End }, { 0xff55, Qt::Key_Prior }, { 0xff56, Qt::Key_Next }, { 0xff51, Qt::Key_Left }, { 0xff52, Qt::Key_Up }, { 0xff53, Qt::Key_Right }, { 0xff54, Qt::Key_Down }, { 0xffbe, Qt::Key_F1 }, { 0xffbf, Qt::Key_F2 }, { 0xffc0, Qt::Key_F3 }, { 0xffc1, Qt::Key_F4 }, { 0xffc2, Qt::Key_F5 }, { 0xffc3, Qt::Key_F6 }, { 0xffc4, Qt::Key_F7 }, { 0xffc5, Qt::Key_F8 }, { 0xffc6, Qt::Key_F9 }, { 0xffc7, Qt::Key_F10 }, { 0xffc8, Qt::Key_F11 }, { 0xffc9, Qt::Key_F12 }, { 0xffe1, Qt::Key_Shift }, { 0xffe2, Qt::Key_Shift }, { 0xffe3, Qt::Key_Control }, { 0xffe4, Qt::Key_Control }, { 0xffe7, Qt::Key_Meta }, { 0xffe8, Qt::Key_Meta }, { 0xffe9, Qt::Key_Alt }, { 0xffea, Qt::Key_Alt }, { 0, 0 } }; KRFBDecoder::KRFBDecoder( KRFBConnection *con ) : QObject( con, "RFB Decoder" ) { assert( con ); assert( con->state() == KRFBConnection::Connected ); this->con = con; this->buf = 0; this->info = 0; this->format = 0; this->buttonMask = 0; currentState = Idle; } KRFBDecoder::~KRFBDecoder() { if ( info ) delete info; if ( format ) delete format; } void KRFBDecoder::start() { sendClientInit(); } void KRFBDecoder::sendClientInit() { con->write( &( con->options()->shared ), 1 ); // Wait for server init owarn << "Waiting for server init" << oendl; static QString statusMsg = tr( "Waiting for server initialization..." ); emit status( statusMsg ); currentState = AwaitingServerInit; connect( con, SIGNAL( gotEnoughData() ), SLOT( gotServerInit() ) ); con->waitForData( ServerInitLength ); } void KRFBDecoder::gotServerInit() { owarn << "Got server init" << oendl; disconnect( con, SIGNAL( gotEnoughData() ), this, SLOT( gotServerInit() ) ); if ( info ) delete info; info = new KRFBServerInfo; CHECK_PTR( info ); con->read( &(info->width), 2 ); info->width = Swap16IfLE( info->width ); con->read( &info->height, 2 ); info->height = Swap16IfLE( info->height ); con->read( &(info->bpp), 1 ); con->read( &(info->depth), 1 ); con->read( &(info->bigEndian), 1 ); con->read( &(info->trueColor), 1 ); con->read( &(info->redMax), 2 ); info->redMax = Swap16IfLE( info->redMax ); con->read( &(info->greenMax), 2 ); info->greenMax = Swap16IfLE( info->greenMax ); con->read( &(info->blueMax), 2 ); info->blueMax = Swap16IfLE( info->blueMax ); con->read( &(info->redShift), 1 ); con->read( &(info->greenShift), 1 ); con->read( &(info->blueShift), 1 ); con->read( info->padding, 3 ); con->read( &(info->nameLength), 4 ); info->nameLength = Swap32IfLE( info->nameLength ); owarn << "Width = " << info->width << ", Height = " << info->height << "" << oendl; owarn << "Bpp = " << info->bpp << ", Depth = " << info->depth << ", Big = " << info->bigEndian << ", True = " << info->trueColor << oendl; owarn << "RedMax = " << info->redMax << ", GreenMax = " << info->greenMax << ", BlueMax = " << info->blueMax << oendl; owarn << "RedShift = " << info->redShift << ", GreenShift = " << info->greenShift << ", BlueShift = " << info-> blueShift << oendl; buf->resize( info->width/con->options()->scaleFactor, info->height /con->options()->scaleFactor); // Wait for desktop name owarn << "Waiting for desktop name" << oendl; static QString statusMsg = tr( "Waiting for desktop name..." ); emit status( statusMsg ); currentState = AwaitingDesktopName; connect( con, SIGNAL( gotEnoughData() ), SLOT( gotDesktopName() ) ); con->waitForData( info->nameLength ); } void KRFBDecoder::gotDesktopName() { assert( info ); assert( currentState == AwaitingDesktopName ); owarn << "Got desktop name" << oendl; disconnect( con, SIGNAL( gotEnoughData() ), this, SLOT( gotDesktopName() ) ); char *buf = new char[ info->nameLength + 1 ]; CHECK_PTR( buf ); con->read( buf, info->nameLength ); buf[ info->nameLength ] = '\0'; info->name = buf; owarn << "Desktop: " << info->name.latin1() << "" << oendl; - delete buf; + delete [] buf; // Get the format we'll really use and tell the server decidePixelFormat(); sendPixelFormat(); sendAllowedEncodings(); currentState = Idle; QString msg; msg = tr( "Connected to %1" ); msg = msg.arg( info->name ); emit status( msg ); sendUpdateRequest( false ); } void KRFBDecoder::decidePixelFormat() { assert( info ); if ( format ) delete format; format = new KRFBPixelFormat; CHECK_PTR( format ); // What depth do we want? // // We'll use the minimum of the remote and local depths, UNLESS an // eight bit session has been specifically requested by the user. int screenDepth = QPixmap::defaultDepth(); int bestDepth = ( screenDepth > info->depth ) ? info->depth : screenDepth; int chosenDepth; if ( con->options()->colors256 ) chosenDepth = 8; else chosenDepth = bestDepth; owarn << "Screen depth=" << screenDepth << ", server depth=" << info->depth << ", best depth=" << bestDepth << "eight bit " << con->options()->colors256 << ", chosenDepth=" << chosenDepth << oendl; format->depth = chosenDepth; // If we're using the servers native depth if ( chosenDepth == info->depth ) { // Use the servers native format format->bpp = info->bpp; // format->bigEndian = info->bigEndian; format->bigEndian = true; format->trueColor = info->trueColor; format->redMax = info->redMax; format->greenMax = info->greenMax; format->blueMax = info->blueMax; format->redShift = info->redShift; format->greenShift = info->greenShift; format->blueShift = info->blueShift; } else { if ( chosenDepth == 8 ) { format->bpp = 8; format->bigEndian = true; format->trueColor = true; format->redMax = 7; format->greenMax = 7; format->blueMax = 3; format->redShift = 0; format->greenShift = 3; format->blueShift = 6; } } format->redMax = Swap16IfLE( format->redMax ); format->greenMax = Swap16IfLE( format->greenMax ); format->blueMax = Swap16IfLE( format->blueMax ); } void KRFBDecoder::sendPixelFormat() { static char padding[3]; con->write( &SetPixelFormatId, 1 ); con->write( padding, 3 ); con->write( &(format->bpp), 1 ); con->write( &(format->depth), 1 ); con->write( &(format->bigEndian), 1 ); con->write( &(format->trueColor), 1 ); con->write( &(format->redMax), 2 ); con->write( &(format->greenMax), 2 ); con->write( &(format->blueMax), 2 ); con->write( &(format->redShift), 1 ); con->write( &(format->greenShift), 1 ); con->write( &(format->blueShift), 1 ); con->write( format->padding, 3 ); // Padding } void KRFBDecoder::sendAllowedEncodings() { static CARD8 padding[1]; con->write( &SetEncodingsId, 1 ); con->write( padding, 1 ); CARD16 noEncodings = con->options()->encodings(); noEncodings = Swap16IfLE( noEncodings ); con->write( &noEncodings, 2 ); if ( con->options()->corre ) con->write( &CorreEncoding, 4 ); if ( con->options()->hexTile ) con->write( &HexTileEncoding, 4 ); if ( con->options()->rre ) con->write( &RreEncoding, 4 ); if ( con->options()->copyrect ) con->write( &CopyRectEncoding, 4 ); // We always support this con->write( &RawEncoding, 4 ); } void KRFBDecoder::sendUpdateRequest( bool incremental ) { if ( currentState != Idle ) return; con->write( &UpdateRequestId, 1 ); con->write( &incremental, 1 ); static CARD16 x = 0, y = 0; static CARD16 w = Swap16IfLE( info->width ); static CARD16 h = Swap16IfLE( info->height ); con->write( &x, 2 ); con->write( &y, 2 ); con->write( &w, 2 ); con->write( &h, 2 ); // Now wait for the update currentState = AwaitingUpdate; connect( con, SIGNAL( gotEnoughData() ), SLOT( gotUpdateHeader() ) ); con->waitForData( UpdateHeaderLength ); } void KRFBDecoder::gotUpdateHeader() { assert( currentState == AwaitingUpdate ); // owarn << "Got update header" << oendl; disconnect( con, SIGNAL( gotEnoughData() ), this, SLOT( gotUpdateHeader() ) ); CARD8 msgType; con->read( &msgType, 1 ); if ( msgType != UpdateId ) { // We might have a bell or server cut if ( msgType == ServerCutId ) { oldState = currentState; gotServerCut(); } else if ( msgType == BellId ) { oldState = currentState; gotBell(); } else { int msg = msgType; QString protocolError = tr( "Protocol Error: Message Id %1 was " "found when expecting an update " "message." ).arg( msg ); currentState = Error; emit error( protocolError ); } return; } CARD8 padding; con->read( &padding, 1 ); con->read( &noRects, 2 ); noRects = Swap16IfLE( noRects ); // owarn << "Expecting " << noRects << " rects" << oendl; // Now wait for the data currentState = AwaitingRectHeader; connect( con, SIGNAL( gotEnoughData() ), SLOT( gotRectHeader() ) ); con->waitForData( RectHeaderLength ); } void KRFBDecoder::gotRectHeader() { assert( currentState == AwaitingRectHeader ); // owarn << "Got rect header" << oendl; disconnect( con, SIGNAL( gotEnoughData() ), this, SLOT( gotRectHeader() ) ); con->read( &x, 2 ); x = Swap16IfLE( x ); con->read( &y, 2 ); y = Swap16IfLE( y ); con->read( &w, 2 ); w = Swap16IfLE( w ); con->read( &h, 2 ); h = Swap16IfLE( h ); con->read( &encoding, 4 ); // CARD32 encodingLocal = Swap32IfLE( encoding ); // owarn << "Rect: x=" << x << ", y= " << y << ", w=" << w << ", h=" << h // << ", encoding= " << encodingLocal << oendl; // // Each encoding needs to be handled differently. Some require // waiting for more data, but others like a copyrect do not. // Our constants have already been byte swapped, so we use // the remote value as is. // if ( encoding == RawEncoding ) { // owarn << "Raw encoding" << oendl; handleRawRect(); } else if ( encoding == CopyRectEncoding ) { // owarn << "CopyRect encoding" << oendl; handleCopyRect(); } else if ( encoding == RreEncoding ) { owarn << "RRE encoding" << oendl; handleRRERect(); } else if ( encoding == CorreEncoding ) { owarn << "CoRRE encoding" << oendl; handleCoRRERect(); } else if ( encoding == HexTileEncoding ) { owarn << "HexTile encoding" << oendl; handleHexTileRect(); } else { int msg = Swap32IfLE( encoding ); QString protocolError = tr( "Protocol Error: An unknown encoding was " "used by the server %1" ).arg( msg ); currentState = Error; owarn << "Unknown encoding, " << msg << "" << oendl; emit error( protocolError ); return; } } // // Raw Encoding // void KRFBDecoder::handleRawRect() { // We need something a bit cleverer here to handle large // rectanges nicely. The chunking should be based on the // overall size (but has to be in complete lines). // owarn << "Handling a raw rect chunk" << oendl; // CARD32 lineCount = w * format->bpp / 8; if ( h > RectChunkSize ) { // if ( con->sock->size() / lineCount ) { // getRawRectChunk( con->sock->size() / lineCount ); // } // else { getRawRectChunk( RectChunkSize ); // } } else { getRawRectChunk( h ); } } void KRFBDecoder::getRawRectChunk( int lines ) { this->lines = lines; CARD32 count = lines * w * format->bpp / 8; // Wait for server init // owarn << "Waiting for raw rect chunk, " << count << "" << oendl; currentState = AwaitingRawRectChunk; connect( con, SIGNAL( gotEnoughData() ), SLOT( gotRawRectChunk() ) ); con->waitForData( count ); } void KRFBDecoder::gotRawRectChunk() { assert( currentState == AwaitingRawRectChunk ); disconnect( con, SIGNAL( gotEnoughData() ), this, SLOT( gotRawRectChunk() ) ); // owarn << "Got raw rect chunk" << oendl; // // Read the rect data and copy it to the buffer. // // TODO: Replace this! int count = lines * w * format->bpp / 8; char *hack = new char[ count ]; con->read( hack, count ); buf->drawRawRectChunk( hack, x, y, w, lines ); - delete hack; + delete [] hack; // /TODO: h = h - lines; y = y + lines; if ( h > 0 ) { handleRawRect(); } else { noRects--; // owarn << "There are " << noRects << " rects left" << oendl; if ( noRects ) { currentState = AwaitingRectHeader; connect( con, SIGNAL( gotEnoughData() ), SLOT( gotRectHeader() ) ); con->waitForData( RectHeaderLength ); } else { // we are now ready for the next update - no need to wait for the timer currentState = Idle; sendUpdateRequest (1); } } } // // Copy Rectangle Encoding // void KRFBDecoder::handleCopyRect() { currentState = AwaitingCopyRectPos; connect( con, SIGNAL( gotEnoughData() ), SLOT( gotCopyRectPos() ) ); con->waitForData( CopyRectPosLength ); } void KRFBDecoder::gotCopyRectPos() { disconnect( con, SIGNAL( gotEnoughData() ), this, SLOT( gotCopyRectPos() ) ); CARD16 srcX; CARD16 srcY; con->read( &srcX, 2 ); con->read( &srcY, 2 ); srcX = Swap16IfLE( srcX ); srcY = Swap16IfLE( srcY ); buf->copyRect( srcX, srcY, x, y, w, h ); noRects--; // owarn << "There are " << noRects << " rects left" << oendl; if ( noRects ) { currentState = AwaitingRectHeader; connect( con, SIGNAL( gotEnoughData() ), SLOT( gotRectHeader() ) ); con->waitForData( RectHeaderLength ); } else currentState = Idle; } void KRFBDecoder::handleRRERect() { owarn << "RRE not implemented" << oendl; } void KRFBDecoder::handleCoRRERect() { owarn << "CoRRE not implemented" << oendl; } void KRFBDecoder::handleHexTileRect() { owarn << "HexTile not implemented" << oendl; } void KRFBDecoder::sendMouseEvent( QMouseEvent *e ) { // Deal with the buttons if ( e->type() != QEvent::MouseMove ) { buttonMask = 0; if ( e->type() == QEvent::MouseButtonPress ) { if ( e->button() & LeftButton ) buttonMask |= 0x01; if ( e->button() & MidButton ) buttonMask |= 0x04; if ( e->button() & RightButton ) buttonMask |= 0x02; } else if ( e->type() == QEvent::MouseButtonRelease ) { if ( e->button() & LeftButton ) buttonMask &= 0x06; if ( e->button() & MidButton ) buttonMask |= 0x03; if ( e->button() & RightButton ) buttonMask |= 0x05; } } // HACK: Scaling CARD16 x = Swap16IfLE( e->x() * con->options()->scaleFactor ); CARD16 y = Swap16IfLE( e->y() * con->options()->scaleFactor ); con->write( &PointerEventId, 1 ); con->write( &buttonMask, 1 ); con->write( &x, 2 ); con->write( &y, 2 ); } void KRFBDecoder::sendCutEvent( const QString &unicode ) { // // Warning: There is a bug in the RFB protocol because there is no way to find // out the codepage in use on the remote machine. This could be fixed by requiring // the remote server to use utf8 etc. but for now we have to assume they're the // same. I've reported this problem to the ORL guys, but they apparantly have no // immediate plans to fix the issue. :-( (rich) // CARD8 padding[3]; QCString text = unicode.local8Bit(); CARD32 length = text.length(); length = Swap32IfLE( length ); con->write( &ClientCutTextId, 1 ); con->write( &padding, 3 ); con->write( &length, 4 ); con->write( text.data(), length ); } void KRFBDecoder::gotServerCut() { owarn << "Got server cut" << oendl; currentState = AwaitingServerCutLength; connect( con, SIGNAL( gotEnoughData() ), SLOT( gotServerCutLength() ) ); con->waitForData( ServerCutLenLength ); } void KRFBDecoder::gotServerCutLength() { assert( currentState = AwaitingServerCutLength ); disconnect( con, SIGNAL( gotEnoughData() ), this, SLOT( gotServerCutLength() ) ); CARD8 padding[3]; con->read( padding, 3 ); con->read( &serverCutTextLen, 4 ); serverCutTextLen = Swap32IfLE( serverCutTextLen ); currentState = AwaitingServerCutText; connect( con, SIGNAL( gotEnoughData() ), SLOT( gotServerCutText() ) ); con->waitForData( serverCutTextLen ); } void KRFBDecoder::gotServerCutText() { assert( currentState = AwaitingServerCutText ); disconnect( con, SIGNAL( gotEnoughData() ), this, SLOT( gotServerCutText() ) ); // // Warning: There is a bug in the RFB protocol because there is no way to find // out the codepage in use on the remote machine. This could be fixed by requiring // the remote server to use utf8 etc. but for now we have to assume they're the // same. I've reported this problem to the ORL guys, but they apparantly have no // immediate plans to fix the issue. :-( (rich) // char *cutbuf = new char[ serverCutTextLen + 1 ]; CHECK_PTR( cutbuf ); con->read( cutbuf, serverCutTextLen ); cutbuf[ serverCutTextLen ] = '\0'; /* For some reason QApplication::clipboard()->setText() segfaults when called * from within keypebble's mass of signals and slots owarn << "Server cut: " << cutbuf << "" << oendl; QString cutText( cutbuf ); // DANGER!! qApp->clipboard()->setText( cutText ); */ - delete cutbuf; + delete [] cutbuf; // Now wait for the update (again) if ( oldState == AwaitingUpdate ) { currentState = AwaitingUpdate; connect( con, SIGNAL( gotEnoughData() ), SLOT( gotUpdateHeader() ) ); con->waitForData( UpdateHeaderLength ); } else if ( oldState == Idle ) { currentState = Idle; } else { owarn << "Async handled in weird state" << oendl; currentState = oldState; }; } void KRFBDecoder::gotBell() { owarn << "Got server bell" << oendl; buf->soundBell(); // Now wait for the update (again) if ( oldState == AwaitingUpdate ) { currentState = AwaitingUpdate; connect( con, SIGNAL( gotEnoughData() ), SLOT( gotUpdateHeader() ) ); con->waitForData( UpdateHeaderLength ); } else if ( oldState == Idle ) { currentState = Idle; } else { owarn << "Async handled in weird state" << oendl; currentState = oldState; }; } void KRFBDecoder::sendKeyPressEvent( QKeyEvent *event ) { int key; key = toKeySym( event ); if ( key ) { key = Swap32IfLE( key ); CARD8 mask = true; CARD16 padding = 0; con->write( &KeyEventId, 1 ); con->write( &mask, 1 ); con->write( &padding, 2 ); con->write( &key, 4 ); } } void KRFBDecoder::sendKeyReleaseEvent( QKeyEvent *event ) { int key; key = toKeySym( event ); if ( key ) { key = Swap32IfLE( key ); CARD8 mask = false; CARD16 padding = 0; con->write( &KeyEventId, 1 ); con->write( &mask, 1 ); con->write( &padding, 2 ); con->write( &key, 4 ); } } // // The RFB protocol spec says 'For most ordinary keys, the 'keysym' // is the same as the corresponding ASCII value.', but doesn't // elaborate what the most ordinary keys are. The spec also lists // a set (possibly subset, it's unspecified) of mappings for // "other common keys" (backspace, tab, return, escape, etc). // int KRFBDecoder::toKeySym( QKeyEvent *k ) { // // Try and map these "other common keys" first. // if ((k->key() >= Qt::Key_Escape) && (k->key() <= Qt::Key_F12)) { for(int i = 0; keyMap[i].keycode != 0; i++) { if (k->key() == keyMap[i].keycode) { return keyMap[i].keysym; } } } // // If these keys aren't matched, return the ascii code and let the // server figure it out. We don't return k->key(), as the data in // key differs between input methods, and we don't want special cases. // return k->ascii(); } diff --git a/noncore/games/sfcave/sfcave.cpp b/noncore/games/sfcave/sfcave.cpp index a6c92a0..516dc93 100644 --- a/noncore/games/sfcave/sfcave.cpp +++ b/noncore/games/sfcave/sfcave.cpp @@ -809,385 +809,385 @@ void SFCave :: keyPressEvent( QKeyEvent *e ) { if ( state == STATE_MENU ) handleMenuKeys( e ); else { switch( e->key() ) { case Qt::Key_Up: case Qt::Key_F9: case Qt::Key_Space: if ( state == STATE_RUNNING ) { if ( !replay && !press ) { press = true; replayList.append( new int( nrFrames ) ); } } else if ( state == STATE_CRASHED ) { if ( e->key() == Key_Up ) state = STATE_NEWGAME; } break; case Qt::Key_M: case Qt::Key_Return: case Qt::Key_Enter: if ( state == STATE_CRASHED ) { state = STATE_MENU; currentMenuNr = 0; currentMenuOption[currentMenuNr] = 0; } break; case Qt::Key_Z: showScoreZones = !showScoreZones; break; default: e->ignore(); break; } } } void SFCave :: keyReleaseEvent( QKeyEvent *e ) { if ( state == STATE_MENU ) { } else { switch( e->key() ) { case Qt::Key_F9: case Qt::Key_Space: case Qt::Key_Up: if ( state == STATE_RUNNING ) { if ( !replay && press ) { press = false; replayList.append( new int( nrFrames ) ); } } break; case Qt::Key_E: showEyeCandy = !showEyeCandy; break; case Qt::Key_R: if ( state == STATE_CRASHED ) state = STATE_REPLAY; break; case Qt::Key_Down: if ( state == STATE_CRASHED ) state = STATE_NEWGAME; break; case Qt::Key_S: if ( state == STATE_CRASHED ) saveReplay(); break; case Qt::Key_L: if ( state == STATE_CRASHED ) loadReplay(); break; default: e->ignore(); break; } } } void SFCave :: saveScore() { #ifdef QWS Config cfg( "sfcave" ); cfg.setGroup( "settings" ); QString key = "highScore_"; cfg.writeEntry( key + gameTypes[currentGameType] + "_" + dificultyOption[currentGameDifficulty], highestScore[currentGameType][currentGameDifficulty] ); key += CURRENT_GAME_TYPE; cfg.writeEntry( key, highestScore[currentGameType] ); #endif } void SFCave :: saveReplay() { FILE *out; out = fopen( QFile::encodeName(replayFile).data(), "w" ); if ( !out ) { printf( "Couldn't write to %s\n", QFile::encodeName(replayFile).data() ); return; } // Build up string of values // Format is:: <landscape seed> <game type> <difficulty> <framenr> <framenr>....... QString val; val.sprintf( "%d %d %d ", currentSeed, currentGameType, currentGameDifficulty ); QListIterator<int> it( replayList ); while( it.current() ) { QString tmp; tmp.sprintf( "%d ", (*it.current()) ); val += tmp; ++it; } val += "\n"; QString line; line.sprintf( "%d\n", val.length() ); fwrite( (const char *)line, 1, line.length(), out ); fwrite( (const char *)val, 1, val.length(), out ); fclose( out ); printf( "Replay saved to %s\n", QFile::encodeName(replayFile).data() ); } void SFCave :: loadReplay() { FILE *in = fopen( QFile::encodeName(replayFile).data() , "r" ); if ( in == 0 ) { printf( "Couldn't load replay file!\n" ); return; } // Read next line - contains the size of the options char line[10+1]; fgets( line, 10, in ); int length = -1; sscanf( line, "%d", &length ); char *data = new char[length+1]; fread( data, 1, length, in ); // printf( "data - %s", data ); QString sep = " "; QStringList list = QStringList::split( sep, QString( data ) ); // print it out QStringList::Iterator it = list.begin(); currentSeed = (*it).toInt(); ++it; currentGameType = (*it).toInt(); ++it; currentGameDifficulty = (*it).toInt(); ++it; replayList.clear(); for ( ; it != list.end(); ++it ) { int v = (*it).toInt(); replayList.append( new int( v ) ); } - delete data; + delete [] data; fclose( in ); printf( "Replay loaded from %s\n", QFile::encodeName(replayFile).data() ); } //--------------- MENU CODE --------------------- void SFCave :: handleMenuKeys( QKeyEvent *e ) { switch( e->key() ) { case Qt::Key_Down: currentMenuOption[currentMenuNr] ++; if ( menuOptions[currentMenuNr][currentMenuOption[currentMenuNr]] == "" ) currentMenuOption[currentMenuNr] = 0; break; case Qt::Key_Up: currentMenuOption[currentMenuNr] --; if ( currentMenuOption[currentMenuNr] < 0 ) currentMenuOption[currentMenuNr] = nrMenuOptions[currentMenuNr]-1; break; case Qt::Key_Left: if ( currentMenuNr == MENU_OPTIONS_MENU ) { if ( currentMenuOption[currentMenuNr] == MENU_GAME_TYPE ) { currentGameType --; if ( currentGameType < 0 ) currentGameType = NR_GAME_TYPES - 1; } else if ( currentMenuOption[currentMenuNr] == MENU_GAME_DIFFICULTY ) { currentGameDifficulty --; if ( currentGameDifficulty < 0 ) currentGameDifficulty = NR_GAME_DIFFICULTIES - 1; } } break; case Qt::Key_Right: if ( currentMenuNr == MENU_OPTIONS_MENU ) { if ( currentMenuOption[currentMenuNr] == MENU_GAME_TYPE ) { currentGameType ++; if ( currentGameType == NR_GAME_TYPES ) currentGameType = 0; } else if ( currentMenuOption[currentMenuNr] == MENU_GAME_DIFFICULTY ) { currentGameDifficulty ++; if ( currentGameDifficulty == NR_GAME_DIFFICULTIES ) currentGameDifficulty = 0; } } break; case Qt::Key_Space: case Qt::Key_Return: case Qt::Key_Enter: dealWithMenuSelection(); break; } } void SFCave :: displayMenu() { offscreen->fill( Qt::black ); QPainter p( offscreen ); p.setPen( Qt::white ); QFont f( "Helvetica", 16 ); p.setFont( f ); QFontMetrics fm = p.fontMetrics(); QString text = "SFCave"; p.drawText( (sWidth/2) - (fm.width( text )/2), 60, text ); text = "Written by Andy Qua"; p.drawText( (sWidth/2) - (fm.width( text )/2), 85, text ); // Draw options int pos = 140; for ( int i = 0 ; menuOptions[currentMenuNr][i] != "" ; ++i, pos += 25 ) { if ( currentMenuOption[currentMenuNr] == i ) p.setPen( Qt::yellow ); else p.setPen( Qt::white ); QString text; if ( menuOptions[currentMenuNr][i].find( "%s" ) != -1 ) { QString val; if ( i == MENU_GAME_TYPE ) val = gameTypes[currentGameType]; else val = dificultyOption[currentGameDifficulty]; text.sprintf( (const char *)menuOptions[currentMenuNr][i], (const char *)val ); } else text = menuOptions[currentMenuNr][i]; p.drawText( (sWidth/2) - (fm.width( text )/2), pos, text ); } p.end(); bitBlt( this, 0, 0, offscreen, 0, 0, sWidth, sHeight, Qt::CopyROP, true ); } void SFCave :: dealWithMenuSelection() { switch( currentMenuNr ) { case MENU_MAIN_MENU: { switch( currentMenuOption[currentMenuNr] ) { case MENU_START_GAME: state = STATE_NEWGAME; break; case MENU_REPLAY: currentMenuNr = MENU_REPLAY_MENU; currentMenuOption[currentMenuNr] = 0; break; case MENU_OPTIONS: currentMenuNr = MENU_OPTIONS_MENU; currentMenuOption[currentMenuNr] = 0; break; case MENU_HELP: { // Display Help Menu HelpWindow *win = new HelpWindow( ); QPEApplication::showWidget( win ); break; } case MENU_QUIT: QApplication::exit(); break; } break; } case MENU_OPTIONS_MENU: { switch( currentMenuOption[currentMenuNr] ) { case MENU_GAME_TYPE: break; case MENU_GAME_DIFFICULTY: break; case MENU_CLEAR_HIGHSCORES: for ( int i = 0 ; i < 3 ; ++i ) highestScore[currentGameType][i] = 0; break; case MENU_BACK: currentMenuNr = MENU_MAIN_MENU; #ifdef QWS Config cfg( "sfcave" ); cfg.setGroup( "settings" ); cfg.writeEntry( "difficulty", currentGameDifficulty ); cfg.writeEntry( "gameType", currentGameType ); #endif break; } break; } case MENU_REPLAY_MENU: { switch( currentMenuOption[currentMenuNr] ) { case MENU_REPLAY_START: if ( currentSeed != 0 ) state = STATE_REPLAY; // Display No Replay break; diff --git a/noncore/settings/aqpkg/settingsimpl.cpp b/noncore/settings/aqpkg/settingsimpl.cpp index 7ffa1d6..0886e69 100644 --- a/noncore/settings/aqpkg/settingsimpl.cpp +++ b/noncore/settings/aqpkg/settingsimpl.cpp @@ -158,333 +158,333 @@ QWidget *SettingsImpl :: initDestinationTab() QWidget *container = new QWidget( sv->viewport() ); sv->addChild( container ); QGridLayout *layout = new QGridLayout( container ); layout->setSpacing( 2 ); layout->setMargin( 4 ); destinations = new QListBox( container ); destinations->setSizePolicy( QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ) ); connect( destinations, SIGNAL( highlighted(int) ), this, SLOT( editDestination(int) ) ); layout->addMultiCellWidget( destinations, 0, 0, 0, 1 ); QPushButton *btn = new QPushButton( Opie::Core::OResource::loadPixmap( "new", Opie::Core::OResource::SmallIcon ), tr( "New" ), container ); connect( btn, SIGNAL( clicked() ), this, SLOT( newDestination() ) ); layout->addWidget( btn, 1, 0 ); btn = new QPushButton( Opie::Core::OResource::loadPixmap( "trash", Opie::Core::OResource::SmallIcon ), tr( "Delete" ), container ); connect( btn, SIGNAL( clicked() ), this, SLOT( removeDestination() ) ); layout->addWidget( btn, 1, 1 ); QGroupBox *grpbox = new QGroupBox( 0, Qt::Vertical, tr( "Destination" ), container ); grpbox->layout()->setSpacing( 2 ); grpbox->layout()->setMargin( 4 ); layout->addMultiCellWidget( grpbox, 2, 2, 0, 1 ); QGridLayout *grplayout = new QGridLayout( grpbox->layout() ); QLabel *label = new QLabel( tr( "Name:" ), grpbox ); grplayout->addWidget( label, 0, 0 ); destinationname = new QLineEdit( grpbox ); grplayout->addWidget( destinationname, 0, 1 ); label = new QLabel( tr( "Location:" ), grpbox ); grplayout->addWidget( label, 1, 0 ); destinationurl = new QLineEdit( grpbox ); grplayout->addWidget( destinationurl, 1, 1 ); linkToRoot = new QCheckBox( tr( "Link to root" ), grpbox ); grplayout->addMultiCellWidget( linkToRoot, 2, 2, 0, 1 ); btn = new QPushButton( Opie::Core::OResource::loadPixmap( "edit", Opie::Core::OResource::SmallIcon ), tr( "Update" ), grpbox ); connect( btn, SIGNAL( clicked() ), this, SLOT( changeDestinationDetails() ) ); grplayout->addMultiCellWidget( btn, 3, 3, 0, 1 ); return control; } QWidget *SettingsImpl :: initProxyTab() { QWidget *control = new QWidget( this ); QVBoxLayout *vb = new QVBoxLayout( control ); QScrollView *sv = new QScrollView( control ); vb->addWidget( sv, 0, 0 ); sv->setResizePolicy( QScrollView::AutoOneFit ); sv->setFrameStyle( QFrame::NoFrame ); QWidget *container = new QWidget( sv->viewport() ); sv->addChild( container ); QGridLayout *layout = new QGridLayout( container ); layout->setSpacing( 2 ); layout->setMargin( 4 ); QGroupBox *grpbox = new QGroupBox( 0, Qt::Vertical, tr( "HTTP Proxy" ), container ); grpbox->layout()->setSpacing( 2 ); grpbox->layout()->setMargin( 4 ); layout->addMultiCellWidget( grpbox, 0, 0, 0, 1 ); QVBoxLayout *grplayout = new QVBoxLayout( grpbox->layout() ); txtHttpProxy = new QLineEdit( grpbox ); grplayout->addWidget( txtHttpProxy ); chkHttpProxyEnabled = new QCheckBox( tr( "Enabled" ), grpbox ); grplayout->addWidget( chkHttpProxyEnabled ); grpbox = new QGroupBox( 0, Qt::Vertical, tr( "FTP Proxy" ), container ); grpbox->layout()->setSpacing( 2 ); grpbox->layout()->setMargin( 4 ); layout->addMultiCellWidget( grpbox, 1, 1, 0, 1 ); grplayout = new QVBoxLayout( grpbox->layout() ); txtFtpProxy = new QLineEdit( grpbox ); grplayout->addWidget( txtFtpProxy ); chkFtpProxyEnabled = new QCheckBox( tr( "Enabled" ), grpbox ); grplayout->addWidget( chkFtpProxyEnabled ); QLabel *label = new QLabel( tr( "Username:" ), container ); layout->addWidget( label, 2, 0 ); txtUsername = new QLineEdit( container ); layout->addWidget( txtUsername, 2, 1 ); label = new QLabel( tr( "Password:" ), container ); layout->addWidget( label, 3, 0 ); txtPassword = new QLineEdit( container ); layout->addWidget( txtPassword, 3, 1 ); QPushButton *btn = new QPushButton( Opie::Core::OResource::loadPixmap( "edit", Opie::Core::OResource::SmallIcon ), tr( "Update" ), container ); connect( btn, SIGNAL( clicked() ), this, SLOT( proxyApplyChanges() ) ); layout->addMultiCellWidget( btn, 4, 4, 0, 1 ); return control; } void SettingsImpl :: setupData() { // add servers QString serverName; QListIterator<Server> it( dataMgr->getServerList() ); for ( ; it.current(); ++it ) { serverName = it.current()->getServerName(); if ( serverName == LOCAL_SERVER || serverName == LOCAL_IPKGS ) continue; servers->insertItem( serverName ); } // add destinations QListIterator<Destination> it2( dataMgr->getDestinationList() ); for ( ; it2.current(); ++it2 ) destinations->insertItem( it2.current()->getDestinationName() ); // setup proxy tab txtHttpProxy->setText( dataMgr->getHttpProxy() ); txtFtpProxy->setText( dataMgr->getFtpProxy() ); txtUsername->setText( dataMgr->getProxyUsername() ); txtPassword->setText( dataMgr->getProxyPassword() ); chkHttpProxyEnabled->setChecked( dataMgr->getHttpProxyEnabled() ); chkFtpProxyEnabled->setChecked( dataMgr->getFtpProxyEnabled() ); } //------------------ Servers tab ---------------------- void SettingsImpl :: editServer( int sel ) { currentSelectedServer = sel; Server *s = dataMgr->getServer( servers->currentText() ); if ( s ) { serverName = s->getServerName(); servername->setText( s->getServerName() ); serverurl->setText( s->getServerUrl() ); active->setChecked( s->isServerActive() ); } else { serverName = ""; servername->setText( "" ); serverurl->setText( "" ); active->setChecked( false ); } } void SettingsImpl :: newServer() { newserver = true; servername->setText( "" ); serverurl->setText( "" ); servername->setFocus(); active->setChecked( true ); } void SettingsImpl :: removeServer() { changed = true; Server *s = dataMgr->getServer( servers->currentText() ); if ( s ) { dataMgr->getServerList().removeRef( s ); servers->removeItem( currentSelectedServer ); } } void SettingsImpl :: changeServerDetails() { changed = true; QString newName = servername->text(); // Convert any spaces to underscores char *tmpStr = new char[newName.length() + 1]; for ( unsigned int i = 0 ; i < newName.length() ; ++i ) { if ( newName[i] == ' ' ) tmpStr[i] = '_'; else tmpStr[i] = newName[i].latin1(); } tmpStr[newName.length()] = '\0'; newName = tmpStr; - delete tmpStr; + delete [] tmpStr; if ( !newserver ) { Server *s = dataMgr->getServer( servers->currentText() ); if ( s ) { // Update url s->setServerUrl( serverurl->text() ); s->setActive( active->isChecked() ); // Check if server name has changed, if it has then we need to replace the key in the map if ( serverName != newName ) { // Update server name s->setServerName( newName ); } // Update list box servers->changeItem( newName, currentSelectedServer ); } } else { Server s( newName, serverurl->text() ); dataMgr->getServerList().append( new Server( newName, serverurl->text() ) ); dataMgr->getServerList().last()->setActive( active->isChecked() ); servers->insertItem( newName ); servers->setCurrentItem( servers->count() ); newserver = false; } } //------------------ Destinations tab ---------------------- void SettingsImpl :: editDestination( int sel ) { currentSelectedDestination = sel; Destination *d = dataMgr->getDestination( destinations->currentText() ); if ( d ) { destinationName = d->getDestinationName(); destinationname->setText( d->getDestinationName() ); destinationurl->setText( d->getDestinationPath() ); linkToRoot->setChecked( d->linkToRoot() ); } else { destinationName = ""; destinationname->setText( "" ); destinationurl->setText( "" ); linkToRoot->setChecked( false ); } } void SettingsImpl :: newDestination() { newdestination = true; destinationname->setText( "" ); destinationurl->setText( "" ); destinationname->setFocus(); linkToRoot->setChecked( true ); } void SettingsImpl :: removeDestination() { changed = true; Destination *d = dataMgr->getDestination( destinations->currentText() ); if ( d ) { dataMgr->getDestinationList().removeRef( d ); destinations->removeItem( currentSelectedDestination ); } } void SettingsImpl :: changeDestinationDetails() { changed = true; #ifdef QWS Config cfg( "aqpkg" ); cfg.setGroup( "destinations" ); #endif QString newName = destinationname->text(); if ( !newdestination ) { Destination *d = dataMgr->getDestination( destinations->currentText() ); if ( d ) { // Update url d->setDestinationPath( destinationurl->text() ); d->linkToRoot( linkToRoot->isChecked() ); // Check if server name has changed, if it has then we need to replace the key in the map if ( destinationName != newName ) { // Update server name d->setDestinationName( newName ); // Update list box destinations->changeItem( newName, currentSelectedDestination ); } #ifdef QWS QString key = newName; key += "_linkToRoot"; int val = d->linkToRoot(); cfg.writeEntry( key, val ); #endif } } else { dataMgr->getDestinationList().append( new Destination( newName, destinationurl->text() ) ); destinations->insertItem( newName ); destinations->setCurrentItem( destinations->count() ); newdestination = false; #ifdef QWS QString key = newName; key += "_linkToRoot"; cfg.writeEntry( key, true ); #endif } } //------------------ Proxy tab ---------------------- void SettingsImpl :: proxyApplyChanges() { changed = true; dataMgr->setHttpProxy( txtHttpProxy->text() ); dataMgr->setFtpProxy( txtFtpProxy->text() ); dataMgr->setProxyUsername( txtUsername->text() ); dataMgr->setProxyPassword( txtPassword->text() ); dataMgr->setHttpProxyEnabled( chkHttpProxyEnabled->isChecked() ); dataMgr->setFtpProxyEnabled( chkFtpProxyEnabled->isChecked() ); } diff --git a/noncore/settings/aqpkg/version.cpp b/noncore/settings/aqpkg/version.cpp index 59e6f3f..ce2de7b 100644 --- a/noncore/settings/aqpkg/version.cpp +++ b/noncore/settings/aqpkg/version.cpp @@ -1,219 +1,219 @@ /* * libdpkg - Debian packaging suite library routines * vercmp.c - comparison of version numbers * * Copyright (C) 1995 Ian Jackson <iwj10@cus.cam.ac.uk> * * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2, * or (at your option) any later version. * * This is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public * License along with dpkg; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include <stdio.h> #include <stdlib.h> #include <ctype.h> #include <string.h> #include <qobject.h> //# define _(Text) Text class versionrevision { public: versionrevision() { version = 0; } ~versionrevision() { if ( version ) - delete version; + delete [] version; } void setVersion( const char *str ) { version = new char[(strlen(str)+1)]; strcpy( version, str ); } unsigned long epoch; char *version; const char *revision; const char *familiar_revision; }; static int verrevcmp(const char *val, const char *ref) { int vc, rc; long vl, rl; const char *vp, *rp; if (!val) val= ""; if (!ref) ref= ""; for (;;) { vp= val; while (*vp && !isdigit(*vp)) vp++; rp= ref; while (*rp && !isdigit(*rp)) rp++; for (;;) { vc= val == vp ? 0 : *val++; rc= ref == rp ? 0 : *ref++; if (!rc && !vc) break; if (vc && !isalpha(vc)) vc += 256; /* assumes ASCII character set */ if (rc && !isalpha(rc)) rc += 256; if (vc != rc) return vc - rc; } val= vp; ref= rp; vl=0; if (isdigit(*vp)) vl= strtol(val,(char**)&val,10); rl=0; if (isdigit(*rp)) rl= strtol(ref,(char**)&ref,10); if (vl != rl) return vl - rl; if (!*val && !*ref) return 0; if (!*val) return -1; if (!*ref) return +1; } } int versioncompare(const struct versionrevision *version, const struct versionrevision *refversion) { int r; if (version->epoch > refversion->epoch) return 1; if (version->epoch < refversion->epoch) return -1; r= verrevcmp(version->version,refversion->version); if (r) return r; r= verrevcmp(version->revision,refversion->revision); if (r) return r; return verrevcmp(version->familiar_revision,refversion->familiar_revision); } int versionsatisfied3(const struct versionrevision *it, const struct versionrevision *ref, const char *op) { int r; r= versioncompare(it,ref); if (strcmp(op, "<=") == 0 || strcmp(op, "<") == 0) return r <= 0; if (strcmp(op, ">=") == 0 || strcmp(op, ">") == 0) return r >= 0; if (strcmp(op, "<<") == 0) return r < 0; if (strcmp(op, ">>") == 0) return r > 0; if (strcmp(op, "=") == 0) return r == 0; // fprintf(stderr, "unknown operator: %s", op); exit(1); } const char *parseversion(struct versionrevision *rversion, const char *string) { char *hyphen, *colon, *eepochcolon; unsigned long epoch; if ( !*string ) return QObject::tr( "Version string is empty." ); colon= strchr(string,':'); if (colon) { epoch= strtoul(string,&eepochcolon,10); if ( colon != eepochcolon ) return QObject::tr( "Epoch in version is not number." ); if ( !*++colon ) return QObject::tr( "Nothing after colon in version number." ); string= colon; rversion->epoch= epoch; } else { rversion->epoch= 0; } rversion->revision = ""; rversion->familiar_revision = ""; rversion->setVersion( string ); hyphen= strrchr(rversion->version,'-'); if (hyphen) { *hyphen++= 0; if (strncmp("fam", hyphen, 3) == 0) { rversion->familiar_revision=hyphen+3; hyphen= strrchr(rversion->version,'-'); if (hyphen) { *hyphen++= 0; rversion->revision = hyphen; } } else { rversion->revision = hyphen; } } /* fprintf(stderr,"Parsed version: %lu, %s, %s, %s\n", rversion->epoch, rversion->version, rversion->revision, rversion->familiar_revision); */ return 0; } int compareVersions( const char *v1, const char *v2 ) { const char *err; versionrevision ver, ref; err = parseversion(&ref, v1); if (err) { // fprintf(stderr, "Invalid version `%s': %s\n", v2, err); return -2; } err = parseversion(&ver, v2); if (err) { // fprintf(stderr, "Invalid version `%s': %s\n", v1, err); return -2; } if ( versionsatisfied3( &ver, &ref, "=" ) ) return 0; else if ( versionsatisfied3( &ver, &ref, "<" ) ) return -1; else return 1; } /* int main(int argc, char *argv[]) { const char *err; versionrevision ver, ref; if (argc < 4) { fprintf(stderr, "usage: %s: version op refversion\n", argv[0]); return 2; } err = parseversion(&ver, argv[1]); if (err) { fprintf(stderr, "Invalid version `%s': %s\n", argv[1], err); return 2; } err = parseversion(&ref, argv[3]); if (err) { fprintf(stderr, "Invalid version `%s': %s\n", argv[3], err); return 2; } printf( "Result: %d\n", versionsatisfied3(&ver, &ref, argv[2]) ); } */ |