author | brad <brad> | 2004-06-17 11:45:51 (UTC) |
---|---|---|
committer | brad <brad> | 2004-06-17 11:45:51 (UTC) |
commit | 9875d0391f21f4d7518dba946455d844f04c1668 (patch) (side-by-side diff) | |
tree | b53e0415e0f238e21cb8cc1a19175b9d4799bcaa /inputmethods/handwriting | |
parent | 4386dec4cc1b5ef3272b9aba352dfa6fba6a4e06 (diff) | |
download | opie-9875d0391f21f4d7518dba946455d844f04c1668.zip opie-9875d0391f21f4d7518dba946455d844f04c1668.tar.gz opie-9875d0391f21f4d7518dba946455d844f04c1668.tar.bz2 |
Fix inability to delete system characters.
It appears this has never previously worked correctly.
Reported by : A.Pearce@salford.ac.uk
-rw-r--r-- | inputmethods/handwriting/qimpenchar.cpp | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/inputmethods/handwriting/qimpenchar.cpp b/inputmethods/handwriting/qimpenchar.cpp index b83b2a4..96a0502 100644 --- a/inputmethods/handwriting/qimpenchar.cpp +++ b/inputmethods/handwriting/qimpenchar.cpp @@ -281,165 +281,179 @@ QIMPenCharSet::QIMPenCharSet() /*! Construct and load a characters set from file \a fn. */ QIMPenCharSet::QIMPenCharSet( const QString &fn ) { chars.setAutoDelete( TRUE ); desc = "Unnamed"; csTitle = "abc"; csType = Unknown; maxStrokes = 0; load( fn, System ); } const QString &QIMPenCharSet::filename( Domain d ) const { if ( d == System ) return sysFilename; else return userFilename; } void QIMPenCharSet::setFilename( const QString &fn, Domain d ) { if ( d == System ) sysFilename = fn; else if ( d == User ) userFilename = fn; } /*! Load a character set from file \a fn. */ bool QIMPenCharSet::load( const QString &fn, Domain d ) { setFilename( fn, d ); bool ok = FALSE; QFile file( fn ); if ( file.open( IO_ReadOnly ) ) { QDataStream ds( &file ); QString version; ds >> version; ds >> csTitle; ds >> desc; int major = version.mid( 4, 1 ).toInt(); int minor = version.mid( 6 ).toInt(); if ( major >= 1 && minor > 0 ) { ds >> (Q_INT8 &)csType; } else { if ( csTitle == "abc" ) csType = Lower; else if ( csTitle == "ABC" ) csType = Upper; else if ( csTitle == "123" ) csType = Numeric; else if ( fn == "Combining" ) csType = Combining; } while ( !ds.atEnd() ) { QIMPenChar *pc = new QIMPenChar; ds >> *pc; if ( d == User ) markDeleted( pc->character() ); // override system + if ( !pc->testFlag( QIMPenChar::Deleted ) ) addChar( pc ); } if ( file.status() == IO_Ok ) ok = TRUE; } setHidden ( false ); return ok; } /*! Save this character set. */ bool QIMPenCharSet::save( Domain d ) { if ( filename( d ).isEmpty() ) return FALSE; if ( hidden() ) return TRUE; bool ok = FALSE; QString fn = filename( d ); QString tmpFn = fn + ".new"; QFile file( tmpFn ); if ( file.open( IO_WriteOnly|IO_Raw ) ) { QByteArray buf; QDataStream ds( buf, IO_WriteOnly ); ds << QString( "QPT 1.1" ); ds << csTitle; ds << desc; ds << (Q_INT8)csType; QIMPenCharIterator ci( chars ); for ( ; ci.current(); ++ci ) { QIMPenChar *pc = ci.current(); +/* + * If the Domain is System and the Char is marked System - OR + * the domain is User, the Char is User and it's not deleted - OR + * the domain is User, the Char is System and it is deleted - AND + * the character is not an automated Combined Character + * + * This is required to ensure that we don't save user defined chars that have been deleted, but + * we *DO* save System chars that have been deleted. There is still the issue of deleted combined + * chars but I'm not sure how to tackle that yet + * + */ + if ( ( ( (d == System) && pc->testFlag( QIMPenChar::System ) ) || - ( (d == User) && !pc->testFlag( QIMPenChar::System ) ) ) && + ( (d == User) && !pc->testFlag( QIMPenChar::System ) && !pc->testFlag( QIMPenChar::Deleted ) ) || + ( (d == User) && pc->testFlag( QIMPenChar::System ) && pc->testFlag( QIMPenChar::Deleted ) ) ) && ( !pc->testFlag (QIMPenChar::Combined ) ) ) { ds << *pc; } } file.writeBlock( buf ); file.close(); if ( file.status() == IO_Ok ) ok = TRUE; } if ( ok ) { if ( ::rename( tmpFn.latin1(), fn.latin1() ) < 0 ) { owarn << "problem renaming file " <<tmpFn.latin1() << " to "<< fn.latin1() << ", errno: " << errno << oendl; // remove the tmp file, otherwise, it will just lay around... QFile::remove( tmpFn.latin1() ); ok = FALSE; } } return ok; } QIMPenChar *QIMPenCharSet::at( int i ) { return chars.at(i); } void QIMPenCharSet::markDeleted( uint ch ) { QIMPenCharIterator ci( chars ); for ( ; ci.current(); ++ci ) { QIMPenChar *pc = ci.current(); if ( pc->character() == ch && pc->testFlag( QIMPenChar::System ) ) pc->setFlag( QIMPenChar::Deleted ); } } /*! Find the best matches for \a ch in this character set. */ QIMPenCharMatchList QIMPenCharSet::match( QIMPenChar *ch ) { QIMPenCharMatchList matches; QIMPenCharIterator ci( chars ); for ( ; ci.current(); ++ci ) { QIMPenChar *tmplChar = ci.current(); if ( tmplChar->testFlag( QIMPenChar::Deleted ) ) { continue; } int err; if ( ch->penStrokes().count() <= tmplChar->penStrokes().count() ) { err = ch->match( tmplChar ); if ( err <= QIMPEN_MATCH_THRESHOLD ) { if (tmplChar->penStrokes().count() != ch->penStrokes().count()) err = QMIN(err*3, QIMPEN_MATCH_THRESHOLD); QIMPenCharMatchList::Iterator it; for ( it = matches.begin(); it != matches.end(); ++it ) { if ( (*it).penChar->character() == tmplChar->character() && (*it).penChar->penStrokes().count() == tmplChar->penStrokes().count() ) { if ( (*it).error > err ) (*it).error = err; |