summaryrefslogtreecommitdiff
path: root/inputmethods/handwriting/qimpenprofile.cpp
Unidiff
Diffstat (limited to 'inputmethods/handwriting/qimpenprofile.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--inputmethods/handwriting/qimpenprofile.cpp245
1 files changed, 245 insertions, 0 deletions
diff --git a/inputmethods/handwriting/qimpenprofile.cpp b/inputmethods/handwriting/qimpenprofile.cpp
new file mode 100644
index 0000000..4b5bb83
--- a/dev/null
+++ b/inputmethods/handwriting/qimpenprofile.cpp
@@ -0,0 +1,245 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include "qimpencombining.h"
22#include "qimpenprofile.h"
23
24#include <qpe/qpeapplication.h>
25#include <qpe/config.h>
26#include <qpe/global.h>
27
28
29QIMPenProfile::QIMPenProfile( const QString &fn )
30 : filename( fn )
31{
32 sets.setAutoDelete( true );
33
34 Config config( filename, Config::File );
35 config.setGroup( "Handwriting" );
36
37 pname = config.readEntry( "Name" );
38 pdesc = config.readEntry( "Description" );
39
40 tstyle = config.readBoolEntry( "CanSelectStyle", false );
41
42 wordMatch = config.readBoolEntry( "MatchWords", true );
43
44 config.setGroup( "Settings" );
45
46 pstyle = BothCases;
47 QString s = config.readEntry( "Style", "BothCases" );
48 if ( s == "ToggleCases" )
49 pstyle = ToggleCases;
50
51 msTimeout = config.readNumEntry( "MultiTimeout", 500 );
52
53 // Read user configuration
54 Config usrConfig( userConfig() );
55 usrConfig.setGroup( "Settings" );
56 msTimeout = usrConfig.readNumEntry( "MultiTimeout", msTimeout );
57
58 if ( tstyle && usrConfig.hasKey( "Style" ) ) {
59 pstyle = BothCases;
60 QString s = usrConfig.readEntry( "Style", "BothCases" );
61 if ( s == "ToggleCases" )
62 pstyle = ToggleCases;
63 }
64}
65
66void QIMPenProfile::setStyle( Style s )
67{
68 if ( tstyle && s != pstyle ) {
69 pstyle = s;
70 Config config( userConfig() );
71 config.setGroup( "Settings" );
72 QString s = pstyle == ToggleCases ? "ToggleCases" : "BothCases";
73 config.writeEntry( "Style", s );
74 }
75}
76
77void QIMPenProfile::setMultiStrokeTimeout( int t )
78{
79 if ( t != msTimeout ) {
80 msTimeout = t;
81 Config config( userConfig() );
82 config.setGroup( "Settings" );
83 config.writeEntry( "MultiTimeout", msTimeout );
84 }
85}
86
87QString QIMPenProfile::userConfig()
88{
89 QString un = filename;
90 int pos = un.findRev( '/' );
91 if ( pos >= 0 )
92 un = un.mid( pos + 1 );
93 pos = un.find( '.' );
94 if ( pos > 0 )
95 un.truncate( pos );
96
97 un = "handwriting-" + un;
98
99 return un;
100}
101
102void QIMPenProfile::loadData()
103{
104 Config config( filename, Config::File );
105 config.setGroup( "CharSets" );
106
107 QString baseDir = QPEApplication::qpeDir();
108 baseDir += "/etc/";
109 // accents
110 QIMPenCombining *combining = 0;
111 QString s = config.readEntry( "Combining" );
112 if ( !s.isEmpty() ) {
113 combining = new QIMPenCombining( baseDir + "qimpen/" + s );
114 if ( combining->isEmpty() ) {
115 delete combining;
116 combining = 0;
117 }
118 }
119 // uppercase latin1
120 QIMPenCharSet *cs = 0;
121 s = config.readEntry( "Uppercase" );
122 if ( !s.isEmpty() ) {
123 cs = new QIMPenCharSet( baseDir + "qimpen/" + s );
124 cs->load( Global::applicationFileName("qimpen",s), QIMPenCharSet::User );
125 if ( !cs->isEmpty() ) {
126 if ( combining )
127 combining->addCombined( cs );
128 sets.append( cs );
129 } else {
130 delete cs;
131 }
132 }
133 // lowercase latin1
134 s = config.readEntry( "Lowercase" );
135 if ( !s.isEmpty() ) {
136 cs = new QIMPenCharSet( baseDir + "qimpen/" + s );
137 cs->load( Global::applicationFileName("qimpen",s), QIMPenCharSet::User );
138 if ( !cs->isEmpty() ) {
139 if ( combining )
140 combining->addCombined( cs );
141 sets.append( cs );
142 } else {
143 delete cs;
144 }
145 }
146 // numeric (may comtain punctuation and symbols)
147 s = config.readEntry( "Numeric" );
148 if ( !s.isEmpty() ) {
149 cs = new QIMPenCharSet( baseDir + "qimpen/" + s );
150 cs->load( Global::applicationFileName("qimpen",s), QIMPenCharSet::User );
151 if ( !cs->isEmpty() ) {
152 sets.append( cs );
153 } else {
154 delete cs;
155 }
156 }
157 // punctuation
158 s = config.readEntry( "Punctuation" );
159 if ( !s.isEmpty() ) {
160 cs = new QIMPenCharSet( baseDir + "qimpen/" + s );
161 cs->load( Global::applicationFileName("qimpen",s), QIMPenCharSet::User );
162 if ( !cs->isEmpty() ) {
163 sets.append( cs );
164 } else {
165 delete cs;
166 }
167 }
168 // symbol
169 s = config.readEntry( "Symbol" );
170 if ( !s.isEmpty() ) {
171 cs = new QIMPenCharSet( baseDir + "qimpen/" + s );
172 cs->load( Global::applicationFileName("qimpen",s), QIMPenCharSet::User );
173 if ( !cs->isEmpty() ) {
174 sets.append( cs );
175 } else {
176 delete cs;
177 }
178 }
179 // shortcut
180 s = config.readEntry( "Shortcut" );
181 if ( !s.isEmpty() ) {
182 cs = new QIMPenCharSet( baseDir + "qimpen/" + s );
183 cs->load( Global::applicationFileName("qimpen",s), QIMPenCharSet::User );
184 if ( !cs->isEmpty() ) {
185 sets.append( cs );
186 } else {
187 delete cs;
188 }
189 }
190
191 if ( combining )
192 delete combining;
193}
194
195QIMPenCharSet *QIMPenProfile::uppercase()
196{
197 return find( QIMPenCharSet::Upper );
198}
199
200QIMPenCharSet *QIMPenProfile::lowercase()
201{
202 return find( QIMPenCharSet::Lower );
203}
204
205QIMPenCharSet *QIMPenProfile::numeric()
206{
207 return find( QIMPenCharSet::Numeric );
208}
209
210QIMPenCharSet *QIMPenProfile::punctuation()
211{
212 return find( QIMPenCharSet::Punctuation );
213}
214
215QIMPenCharSet *QIMPenProfile::symbol()
216{
217 return find( QIMPenCharSet::Symbol );
218}
219
220QIMPenCharSet *QIMPenProfile::shortcut()
221{
222 return find( QIMPenCharSet::Shortcut );
223}
224
225QIMPenCharSetList &QIMPenProfile::charSets()
226{
227 if ( sets.isEmpty() )
228 loadData();
229 return sets;
230}
231
232QIMPenCharSet *QIMPenProfile::find( QIMPenCharSet::Type t )
233{
234 if ( sets.isEmpty() )
235 loadData();
236 QIMPenCharSetIterator it( sets );
237 for ( ; it.current(); ++it ) {
238 if ( it.current()->type() == t )
239 return it.current();
240 }
241
242 return 0;
243}
244
245