00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "qimpencombining.h"
00022 #include "qimpenprofile.h"
00023
00024 #include <qpe/qpeapplication.h>
00025 #include <qpe/config.h>
00026 #include <qpe/global.h>
00027
00028
00029 QIMPenProfile::QIMPenProfile( const QString &fn )
00030 : filename( fn )
00031 {
00032 sets.setAutoDelete( true );
00033
00034 Config config( filename, Config::File );
00035 config.setGroup( "Handwriting" );
00036
00037 pname = config.readEntry( "Name" );
00038 pdesc = config.readEntry( "Description" );
00039
00040 tstyle = config.readBoolEntry( "CanSelectStyle", false );
00041
00042 wordMatch = config.readBoolEntry( "MatchWords", true );
00043
00044 config.setGroup( "Settings" );
00045
00046 pstyle = BothCases;
00047 QString s = config.readEntry( "Style", "BothCases" );
00048 if ( s == "ToggleCases" )
00049 pstyle = ToggleCases;
00050
00051 QString t = config.readEntry( "Mono", "Dual" );
00052 pmono = (QString::fromLatin1("Mono") == t );
00053
00054 msTimeout = config.readNumEntry( "MultiTimeout", 500 );
00055
00056
00057 Config usrConfig( userConfig() );
00058 usrConfig.setGroup( "Settings" );
00059 msTimeout = usrConfig.readNumEntry( "MultiTimeout", msTimeout );
00060
00061 if ( tstyle && usrConfig.hasKey( "Style" ) ) {
00062 pstyle = BothCases;
00063 QString s = usrConfig.readEntry( "Style", "BothCases" );
00064 if ( s == "ToggleCases" )
00065 pstyle = ToggleCases;
00066 }
00067 }
00068
00069 void QIMPenProfile::setStyle( Style s )
00070 {
00071 if ( tstyle && s != pstyle ) {
00072 pstyle = s;
00073 Config config( userConfig() );
00074 config.setGroup( "Settings" );
00075 QString s = pstyle == ToggleCases ? "ToggleCases" : "BothCases";
00076 config.writeEntry( "Style", s );
00077 }
00078 }
00079
00080 void QIMPenProfile::setMultiStrokeTimeout( int t )
00081 {
00082 if ( t != msTimeout ) {
00083 msTimeout = t;
00084 Config config( userConfig() );
00085 config.setGroup( "Settings" );
00086 config.writeEntry( "MultiTimeout", msTimeout );
00087 }
00088 }
00089
00090 QString QIMPenProfile::userConfig()
00091 {
00092 QString un = filename;
00093 int pos = un.findRev( '/' );
00094 if ( pos >= 0 )
00095 un = un.mid( pos + 1 );
00096 pos = un.find( '.' );
00097 if ( pos > 0 )
00098 un.truncate( pos );
00099
00100 un = "handwriting-" + un;
00101
00102 return un;
00103 }
00104
00105 void QIMPenProfile::loadData()
00106 {
00107 Config config( filename, Config::File );
00108 config.setGroup( "CharSets" );
00109
00110 QString baseDir = QPEApplication::qpeDir();
00111 baseDir += "/etc/";
00112
00113 QIMPenCombining *combining = 0;
00114 QString s = config.readEntry( "Combining" );
00115 if ( !s.isEmpty() ) {
00116 combining = new QIMPenCombining( baseDir + "qimpen/" + s );
00117 if ( combining->isEmpty() ) {
00118 delete combining;
00119 combining = 0;
00120 }
00121 }
00122
00123 QIMPenCharSet *cs = 0;
00124 s = config.readEntry( "Uppercase" );
00125 if ( !s.isEmpty() && !mono() ) {
00126 cs = new QIMPenCharSet( baseDir + "qimpen/" + s );
00127 cs->load( Global::applicationFileName("qimpen",s), QIMPenCharSet::User );
00128 if ( !cs->isEmpty() ) {
00129 if ( combining )
00130 combining->addCombined( cs );
00131 sets.append( cs );
00132 } else {
00133 delete cs;
00134 }
00135 }
00136
00137 s = config.readEntry( "Lowercase" );
00138 if ( !s.isEmpty() ) {
00139 if ( mono() ) {
00140 cs = new QIMPenCharSet ( baseDir + "qimpen/" + s );
00141 cs->load( Global::applicationFileName("qimpen",s), QIMPenCharSet::User );
00142 if ( !cs->isEmpty() ) {
00143 cs->setTitle( cs->title().upper() );
00144 cs->setType( QIMPenCharSet::Upper );
00145 cs->setDescription( "Hidden uppercase" );
00146 cs->setHidden ( true );
00147 QIMPenCharIterator it( cs->characters() );
00148 for ( ; it.current(); ++it ) {
00149 uint ch = it.current()->character();
00150 if ( ch >= 'a' && ch <= 'z' )
00151 it.current()->setCharacter( QChar(ch).upper() );
00152 }
00153 if ( combining )
00154 combining->addCombined( cs );
00155 sets.append( cs );
00156 } else {
00157 delete cs;
00158 }
00159 }
00160 cs = new QIMPenCharSet( baseDir + "qimpen/" + s );
00161 cs->load( Global::applicationFileName("qimpen",s), QIMPenCharSet::User );
00162 if ( !cs->isEmpty() ) {
00163 if ( combining )
00164 combining->addCombined( cs );
00165 sets.append( cs );
00166 } else {
00167 delete cs;
00168 }
00169 }
00170
00171 s = config.readEntry( "Numeric" );
00172 if ( !s.isEmpty() ) {
00173 cs = new QIMPenCharSet( baseDir + "qimpen/" + s );
00174 cs->load( Global::applicationFileName("qimpen",s), QIMPenCharSet::User );
00175 if ( !cs->isEmpty() ) {
00176 sets.append( cs );
00177 } else {
00178 delete cs;
00179 }
00180 }
00181
00182 s = config.readEntry( "Punctuation" );
00183 if ( !s.isEmpty() ) {
00184 cs = new QIMPenCharSet( baseDir + "qimpen/" + s );
00185 cs->load( Global::applicationFileName("qimpen",s), QIMPenCharSet::User );
00186 if ( !cs->isEmpty() ) {
00187 sets.append( cs );
00188 } else {
00189 delete cs;
00190 }
00191 }
00192
00193 s = config.readEntry( "Symbol" );
00194 if ( !s.isEmpty() ) {
00195 cs = new QIMPenCharSet( baseDir + "qimpen/" + s );
00196 cs->load( Global::applicationFileName("qimpen",s), QIMPenCharSet::User );
00197 if ( !cs->isEmpty() ) {
00198 sets.append( cs );
00199 } else {
00200 delete cs;
00201 }
00202 }
00203
00204 s = config.readEntry( "Shortcut" );
00205 if ( !s.isEmpty() ) {
00206 cs = new QIMPenCharSet( baseDir + "qimpen/" + s );
00207 cs->load( Global::applicationFileName("qimpen",s), QIMPenCharSet::User );
00208 if ( !cs->isEmpty() ) {
00209 sets.append( cs );
00210 } else {
00211 delete cs;
00212 }
00213 }
00214
00215 if ( combining )
00216 delete combining;
00217 }
00218
00219 QIMPenCharSet *QIMPenProfile::uppercase()
00220 {
00221 return find( QIMPenCharSet::Upper );
00222 }
00223
00224 QIMPenCharSet *QIMPenProfile::lowercase()
00225 {
00226 return find( QIMPenCharSet::Lower );
00227 }
00228
00229 QIMPenCharSet *QIMPenProfile::numeric()
00230 {
00231 return find( QIMPenCharSet::Numeric );
00232 }
00233
00234 QIMPenCharSet *QIMPenProfile::punctuation()
00235 {
00236 return find( QIMPenCharSet::Punctuation );
00237 }
00238
00239 QIMPenCharSet *QIMPenProfile::symbol()
00240 {
00241 return find( QIMPenCharSet::Symbol );
00242 }
00243
00244 QIMPenCharSet *QIMPenProfile::shortcut()
00245 {
00246 return find( QIMPenCharSet::Shortcut );
00247 }
00248
00249 QIMPenCharSetList &QIMPenProfile::charSets()
00250 {
00251 if ( sets.isEmpty() )
00252 loadData();
00253 return sets;
00254 }
00255
00256 QIMPenCharSet *QIMPenProfile::find( QIMPenCharSet::Type t )
00257 {
00258 if ( sets.isEmpty() )
00259 loadData();
00260 QIMPenCharSetIterator it( sets );
00261 for ( ; it.current(); ++it ) {
00262 if ( it.current()->type() == t )
00263 return it.current();
00264 }
00265
00266 return 0;
00267 }
00268
00269