author | ar <ar> | 2004-05-31 15:26:50 (UTC) |
---|---|---|
committer | ar <ar> | 2004-05-31 15:26:50 (UTC) |
commit | 27dfc34d411dee76f09f5e516c60b0a64eb35948 (patch) (unidiff) | |
tree | b7f7259497630390e352a1257cac5dc59f5399a6 | |
parent | 27b09fe4f930b96e82cea9fb0eb1a9b87f7ec062 (diff) | |
download | opie-27dfc34d411dee76f09f5e516c60b0a64eb35948.zip opie-27dfc34d411dee76f09f5e516c60b0a64eb35948.tar.gz opie-27dfc34d411dee76f09f5e516c60b0a64eb35948.tar.bz2 |
- convert qWarning to owarn
20 files changed, 1037 insertions, 998 deletions
diff --git a/noncore/apps/opie-write/qrichtext_p.h b/noncore/apps/opie-write/qrichtext_p.h index e368edb..3778feb 100644 --- a/noncore/apps/opie-write/qrichtext_p.h +++ b/noncore/apps/opie-write/qrichtext_p.h | |||
@@ -1,282 +1,285 @@ | |||
1 | /**************************************************************************** | 1 | /**************************************************************************** |
2 | ** $Id$ | 2 | ** $Id$ |
3 | ** | 3 | ** |
4 | ** Definition of internal rich text classes | 4 | ** Definition of internal rich text classes |
5 | ** | 5 | ** |
6 | ** Created : 990124 | 6 | ** Created : 990124 |
7 | ** | 7 | ** |
8 | ** Copyright (C) 1999-2000 Trolltech AS. All rights reserved. | 8 | ** Copyright (C) 1999-2000 Trolltech AS. All rights reserved. |
9 | ** | 9 | ** |
10 | ** This file is part of the kernel module of the Qt GUI Toolkit. | 10 | ** This file is part of the kernel module of the Qt GUI Toolkit. |
11 | ** | 11 | ** |
12 | ** This file may be distributed under the terms of the Q Public License | 12 | ** This file may be distributed under the terms of the Q Public License |
13 | ** as defined by Trolltech AS of Norway and appearing in the file | 13 | ** as defined by Trolltech AS of Norway and appearing in the file |
14 | ** LICENSE.QPL included in the packaging of this file. | 14 | ** LICENSE.QPL included in the packaging of this file. |
15 | ** | 15 | ** |
16 | ** This file may be distributed and/or modified under the terms of the | 16 | ** This file may be distributed and/or modified under the terms of the |
17 | ** GNU General Public License version 2 as published by the Free Software | 17 | ** GNU General Public License version 2 as published by the Free Software |
18 | ** Foundation and appearing in the file LICENSE.GPL included in the | 18 | ** Foundation and appearing in the file LICENSE.GPL included in the |
19 | ** packaging of this file. | 19 | ** packaging of this file. |
20 | ** | 20 | ** |
21 | ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition | 21 | ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition |
22 | ** licenses may use this file in accordance with the Qt Commercial License | 22 | ** licenses may use this file in accordance with the Qt Commercial License |
23 | ** Agreement provided with the Software. | 23 | ** Agreement provided with the Software. |
24 | ** | 24 | ** |
25 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 25 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
26 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 26 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
27 | ** | 27 | ** |
28 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for | 28 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for |
29 | ** information about Qt Commercial License Agreements. | 29 | ** information about Qt Commercial License Agreements. |
30 | ** See http://www.trolltech.com/qpl/ for QPL licensing information. | 30 | ** See http://www.trolltech.com/qpl/ for QPL licensing information. |
31 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 31 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
32 | ** | 32 | ** |
33 | ** Contact info@trolltech.com if any conditions of this licensing are | 33 | ** Contact info@trolltech.com if any conditions of this licensing are |
34 | ** not clear to you. | 34 | ** not clear to you. |
35 | ** | 35 | ** |
36 | **********************************************************************/ | 36 | **********************************************************************/ |
37 | 37 | ||
38 | #ifndef QRICHTEXT_P_H | 38 | #ifndef QRICHTEXT_P_H |
39 | #define QRICHTEXT_P_H | 39 | #define QRICHTEXT_P_H |
40 | 40 | ||
41 | // | 41 | // |
42 | // W A R N I N G | 42 | // W A R N I N G |
43 | // ------------- | 43 | // ------------- |
44 | // | 44 | // |
45 | // This file is not part of the Qt API. It exists for the convenience | 45 | // This file is not part of the Qt API. It exists for the convenience |
46 | // of a number of Qt sources files. This header file may change from | 46 | // of a number of Qt sources files. This header file may change from |
47 | // version to version without notice, or even be removed. | 47 | // version to version without notice, or even be removed. |
48 | // | 48 | // |
49 | // We mean it. | 49 | // We mean it. |
50 | // | 50 | // |
51 | // | 51 | // |
52 | 52 | ||
53 | #include <opie2/odebug.h> | ||
54 | using namespace Opie::Core; | ||
55 | |||
53 | #ifndef QT_H | 56 | #ifndef QT_H |
54 | #include "qstring.h" | 57 | #include "qstring.h" |
55 | #include "qlist.h" | 58 | #include "qlist.h" |
56 | #include "qrect.h" | 59 | #include "qrect.h" |
57 | #include "qfontmetrics.h" | 60 | #include "qfontmetrics.h" |
58 | #include "qintdict.h" | 61 | #include "qintdict.h" |
59 | #include "qmap.h" | 62 | #include "qmap.h" |
60 | #include "qstringlist.h" | 63 | #include "qstringlist.h" |
61 | #include "qfont.h" | 64 | #include "qfont.h" |
62 | #include "qcolor.h" | 65 | #include "qcolor.h" |
63 | #include "qsize.h" | 66 | #include "qsize.h" |
64 | #include "qvaluelist.h" | 67 | #include "qvaluelist.h" |
65 | #include "qvaluestack.h" | 68 | #include "qvaluestack.h" |
66 | #include "qobject.h" | 69 | #include "qobject.h" |
67 | #include "qdict.h" | 70 | #include "qdict.h" |
68 | #include "qtextstream.h" | 71 | #include "qtextstream.h" |
69 | #include "qpixmap.h" | 72 | #include "qpixmap.h" |
70 | #include "qstylesheet.h" | 73 | #include "qstylesheet.h" |
71 | #include "qvector.h" | 74 | #include "qvector.h" |
72 | #include "qpainter.h" | 75 | #include "qpainter.h" |
73 | #include "qlayout.h" | 76 | #include "qlayout.h" |
74 | #include "qobject.h" | 77 | #include "qobject.h" |
75 | #include "qcomplextext_p.h" | 78 | #include "qcomplextext_p.h" |
76 | #include "qapplication.h" | 79 | #include "qapplication.h" |
77 | #include <limits.h> | 80 | #include <limits.h> |
78 | #endif // QT_H | 81 | #endif // QT_H |
79 | 82 | ||
80 | namespace Qt3 { | 83 | namespace Qt3 { |
81 | 84 | ||
82 | class QTextDocument; | 85 | class QTextDocument; |
83 | class QTextString; | 86 | class QTextString; |
84 | class QTextPreProcessor; | 87 | class QTextPreProcessor; |
85 | class QTextFormat; | 88 | class QTextFormat; |
86 | class QTextCursor; | 89 | class QTextCursor; |
87 | class QTextParagraph; | 90 | class QTextParagraph; |
88 | class QTextFormatter; | 91 | class QTextFormatter; |
89 | class QTextIndent; | 92 | class QTextIndent; |
90 | class QTextFormatCollection; | 93 | class QTextFormatCollection; |
91 | class QStyleSheetItem; | 94 | class QStyleSheetItem; |
92 | class QTextCustomItem; | 95 | class QTextCustomItem; |
93 | class QTextFlow; | 96 | class QTextFlow; |
94 | struct QBidiContext; | 97 | struct QBidiContext; |
95 | 98 | ||
96 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | 99 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
97 | 100 | ||
98 | class Q_EXPORT QTextStringChar | 101 | class Q_EXPORT QTextStringChar |
99 | { | 102 | { |
100 | friend class QTextString; | 103 | friend class QTextString; |
101 | 104 | ||
102 | public: | 105 | public: |
103 | // this is never called, initialize variables in QTextString::insert()!!! | 106 | // this is never called, initialize variables in QTextString::insert()!!! |
104 | QTextStringChar() : lineStart( 0 ), type( Regular ), startOfRun( 0 ) {d.format=0;} | 107 | QTextStringChar() : lineStart( 0 ), type( Regular ), startOfRun( 0 ) {d.format=0;} |
105 | ~QTextStringChar(); | 108 | ~QTextStringChar(); |
106 | 109 | ||
107 | QChar c; | 110 | QChar c; |
108 | enum Type { Regular=0, Custom=1, Anchor=2, CustomAnchor=3 }; | 111 | enum Type { Regular=0, Custom=1, Anchor=2, CustomAnchor=3 }; |
109 | uint lineStart : 1; | 112 | uint lineStart : 1; |
110 | uint rightToLeft : 1; | 113 | uint rightToLeft : 1; |
111 | uint hasCursor : 1; | 114 | uint hasCursor : 1; |
112 | uint canBreak : 1; | 115 | uint canBreak : 1; |
113 | Type type : 2; | 116 | Type type : 2; |
114 | uint startOfRun : 1; | 117 | uint startOfRun : 1; |
115 | 118 | ||
116 | int x; | 119 | int x; |
117 | int height() const; | 120 | int height() const; |
118 | int ascent() const; | 121 | int ascent() const; |
119 | int descent() const; | 122 | int descent() const; |
120 | bool isCustom() const { return (type & Custom) != 0; } | 123 | bool isCustom() const { return (type & Custom) != 0; } |
121 | QTextFormat *format() const; | 124 | QTextFormat *format() const; |
122 | QTextCustomItem *customItem() const; | 125 | QTextCustomItem *customItem() const; |
123 | void setFormat( QTextFormat *f ); | 126 | void setFormat( QTextFormat *f ); |
124 | void setCustomItem( QTextCustomItem *i ); | 127 | void setCustomItem( QTextCustomItem *i ); |
125 | struct CustomData | 128 | struct CustomData |
126 | { | 129 | { |
127 | QTextFormat *format; | 130 | QTextFormat *format; |
128 | QTextCustomItem *custom; | 131 | QTextCustomItem *custom; |
129 | QString anchorName; | 132 | QString anchorName; |
130 | QString anchorHref; | 133 | QString anchorHref; |
131 | }; | 134 | }; |
132 | 135 | ||
133 | void loseCustomItem(); | 136 | void loseCustomItem(); |
134 | 137 | ||
135 | union { | 138 | union { |
136 | QTextFormat* format; | 139 | QTextFormat* format; |
137 | CustomData* custom; | 140 | CustomData* custom; |
138 | } d; | 141 | } d; |
139 | 142 | ||
140 | bool isAnchor() const { return ( type & Anchor) != 0; } | 143 | bool isAnchor() const { return ( type & Anchor) != 0; } |
141 | QString anchorName() const; | 144 | QString anchorName() const; |
142 | QString anchorHref() const; | 145 | QString anchorHref() const; |
143 | void setAnchor( const QString& name, const QString& href ); | 146 | void setAnchor( const QString& name, const QString& href ); |
144 | 147 | ||
145 | private: | 148 | private: |
146 | QTextStringChar &operator=( const QTextStringChar & ) { | 149 | QTextStringChar &operator=( const QTextStringChar & ) { |
147 | //abort(); | 150 | //abort(); |
148 | return *this; | 151 | return *this; |
149 | } | 152 | } |
150 | friend class QComplexText; | 153 | friend class QComplexText; |
151 | friend class QTextParagraph; | 154 | friend class QTextParagraph; |
152 | }; | 155 | }; |
153 | 156 | ||
154 | #if defined(Q_TEMPLATEDLL) | 157 | #if defined(Q_TEMPLATEDLL) |
155 | // MOC_SKIP_BEGIN | 158 | // MOC_SKIP_BEGIN |
156 | Q_TEMPLATE_EXTERN template class Q_EXPORT QMemArray<QTextStringChar>; | 159 | Q_TEMPLATE_EXTERN template class Q_EXPORT QMemArray<QTextStringChar>; |
157 | // MOC_SKIP_END | 160 | // MOC_SKIP_END |
158 | #endif | 161 | #endif |
159 | 162 | ||
160 | class Q_EXPORT QTextString | 163 | class Q_EXPORT QTextString |
161 | { | 164 | { |
162 | public: | 165 | public: |
163 | 166 | ||
164 | QTextString(); | 167 | QTextString(); |
165 | QTextString( const QTextString &s ); | 168 | QTextString( const QTextString &s ); |
166 | virtual ~QTextString(); | 169 | virtual ~QTextString(); |
167 | 170 | ||
168 | static QString toString( const QMemArray<QTextStringChar> &data ); | 171 | static QString toString( const QMemArray<QTextStringChar> &data ); |
169 | QString toString() const; | 172 | QString toString() const; |
170 | 173 | ||
171 | QTextStringChar &at( int i ) const; | 174 | QTextStringChar &at( int i ) const; |
172 | int length() const; | 175 | int length() const; |
173 | 176 | ||
174 | int width( int idx ) const; | 177 | int width( int idx ) const; |
175 | 178 | ||
176 | void insert( int index, const QString &s, QTextFormat *f ); | 179 | void insert( int index, const QString &s, QTextFormat *f ); |
177 | void insert( int index, const QChar *unicode, int len, QTextFormat *f ); | 180 | void insert( int index, const QChar *unicode, int len, QTextFormat *f ); |
178 | void insert( int index, QTextStringChar *c, bool doAddRefFormat = FALSE ); | 181 | void insert( int index, QTextStringChar *c, bool doAddRefFormat = FALSE ); |
179 | void truncate( int index ); | 182 | void truncate( int index ); |
180 | void remove( int index, int len ); | 183 | void remove( int index, int len ); |
181 | void clear(); | 184 | void clear(); |
182 | 185 | ||
183 | void setFormat( int index, QTextFormat *f, bool useCollection ); | 186 | void setFormat( int index, QTextFormat *f, bool useCollection ); |
184 | 187 | ||
185 | void setBidi( bool b ) { bidi = b; } | 188 | void setBidi( bool b ) { bidi = b; } |
186 | bool isBidi() const; | 189 | bool isBidi() const; |
187 | bool isRightToLeft() const; | 190 | bool isRightToLeft() const; |
188 | QChar::Direction direction() const; | 191 | QChar::Direction direction() const; |
189 | void setDirection( QChar::Direction d ) { dir = d; bidiDirty = TRUE; } | 192 | void setDirection( QChar::Direction d ) { dir = d; bidiDirty = TRUE; } |
190 | 193 | ||
191 | QMemArray<QTextStringChar> subString( int start = 0, int len = 0xFFFFFF ) const; | 194 | QMemArray<QTextStringChar> subString( int start = 0, int len = 0xFFFFFF ) const; |
192 | QMemArray<QTextStringChar> rawData() const { return data; } | 195 | QMemArray<QTextStringChar> rawData() const { return data; } |
193 | 196 | ||
194 | void operator=( const QString &s ) { clear(); insert( 0, s, 0 ); } | 197 | void operator=( const QString &s ) { clear(); insert( 0, s, 0 ); } |
195 | void operator+=( const QString &s ) {insert( length(), s, 0 ); } | 198 | void operator+=( const QString &s ) {insert( length(), s, 0 ); } |
196 | void prepend( const QString &s ) { insert( 0, s, 0 ); } | 199 | void prepend( const QString &s ) { insert( 0, s, 0 ); } |
197 | 200 | ||
198 | private: | 201 | private: |
199 | void checkBidi() const; | 202 | void checkBidi() const; |
200 | 203 | ||
201 | QMemArray<QTextStringChar> data; | 204 | QMemArray<QTextStringChar> data; |
202 | uint bidiDirty : 1; | 205 | uint bidiDirty : 1; |
203 | uint bidi : 1; // true when the paragraph has right to left characters | 206 | uint bidi : 1; // true when the paragraph has right to left characters |
204 | uint rightToLeft : 1; | 207 | uint rightToLeft : 1; |
205 | uint dir : 5; | 208 | uint dir : 5; |
206 | }; | 209 | }; |
207 | 210 | ||
208 | inline bool QTextString::isBidi() const | 211 | inline bool QTextString::isBidi() const |
209 | { | 212 | { |
210 | if ( bidiDirty ) | 213 | if ( bidiDirty ) |
211 | checkBidi(); | 214 | checkBidi(); |
212 | return bidi; | 215 | return bidi; |
213 | } | 216 | } |
214 | 217 | ||
215 | inline bool QTextString::isRightToLeft() const | 218 | inline bool QTextString::isRightToLeft() const |
216 | { | 219 | { |
217 | if ( bidiDirty ) | 220 | if ( bidiDirty ) |
218 | checkBidi(); | 221 | checkBidi(); |
219 | return rightToLeft; | 222 | return rightToLeft; |
220 | } | 223 | } |
221 | 224 | ||
222 | inline QChar::Direction QTextString::direction() const | 225 | inline QChar::Direction QTextString::direction() const |
223 | { | 226 | { |
224 | return (QChar::Direction) dir; | 227 | return (QChar::Direction) dir; |
225 | } | 228 | } |
226 | 229 | ||
227 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | 230 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
228 | 231 | ||
229 | #if defined(Q_TEMPLATEDLL) | 232 | #if defined(Q_TEMPLATEDLL) |
230 | // MOC_SKIP_BEGIN | 233 | // MOC_SKIP_BEGIN |
231 | Q_TEMPLATE_EXTERN template class Q_EXPORT QValueStack<int>; | 234 | Q_TEMPLATE_EXTERN template class Q_EXPORT QValueStack<int>; |
232 | Q_TEMPLATE_EXTERN template class Q_EXPORT QValueStack<QTextParagraph*>; | 235 | Q_TEMPLATE_EXTERN template class Q_EXPORT QValueStack<QTextParagraph*>; |
233 | Q_TEMPLATE_EXTERN template class Q_EXPORT QValueStack<bool>; | 236 | Q_TEMPLATE_EXTERN template class Q_EXPORT QValueStack<bool>; |
234 | // MOC_SKIP_END | 237 | // MOC_SKIP_END |
235 | #endif | 238 | #endif |
236 | 239 | ||
237 | class Q_EXPORT QTextCursor | 240 | class Q_EXPORT QTextCursor |
238 | { | 241 | { |
239 | public: | 242 | public: |
240 | QTextCursor( QTextDocument *d = 0 ); | 243 | QTextCursor( QTextDocument *d = 0 ); |
241 | QTextCursor( const QTextCursor &c ); | 244 | QTextCursor( const QTextCursor &c ); |
242 | QTextCursor &operator=( const QTextCursor &c ); | 245 | QTextCursor &operator=( const QTextCursor &c ); |
243 | virtual ~QTextCursor() {} | 246 | virtual ~QTextCursor() {} |
244 | 247 | ||
245 | bool operator==( const QTextCursor &c ) const; | 248 | bool operator==( const QTextCursor &c ) const; |
246 | bool operator!=( const QTextCursor &c ) const { return !(*this == c); } | 249 | bool operator!=( const QTextCursor &c ) const { return !(*this == c); } |
247 | 250 | ||
248 | QTextParagraph *paragraph() const; | 251 | QTextParagraph *paragraph() const; |
249 | void setParagraph( QTextParagraph*p ) { gotoPosition(p, 0 ); } | 252 | void setParagraph( QTextParagraph*p ) { gotoPosition(p, 0 ); } |
250 | QTextDocument *document() const; | 253 | QTextDocument *document() const; |
251 | int index() const; | 254 | int index() const; |
252 | void setIndex( int index ) { gotoPosition(paragraph(), index ); } | 255 | void setIndex( int index ) { gotoPosition(paragraph(), index ); } |
253 | 256 | ||
254 | void gotoPosition( QTextParagraph* p, int index = 0); | 257 | void gotoPosition( QTextParagraph* p, int index = 0); |
255 | void gotoLeft(); | 258 | void gotoLeft(); |
256 | void gotoRight(); | 259 | void gotoRight(); |
257 | void gotoNextLetter(); | 260 | void gotoNextLetter(); |
258 | void gotoPreviousLetter(); | 261 | void gotoPreviousLetter(); |
259 | void gotoUp(); | 262 | void gotoUp(); |
260 | void gotoDown(); | 263 | void gotoDown(); |
261 | void gotoLineEnd(); | 264 | void gotoLineEnd(); |
262 | void gotoLineStart(); | 265 | void gotoLineStart(); |
263 | void gotoHome(); | 266 | void gotoHome(); |
264 | void gotoEnd(); | 267 | void gotoEnd(); |
265 | void gotoPageUp( int visibleHeight ); | 268 | void gotoPageUp( int visibleHeight ); |
266 | void gotoPageDown( int visibleHeight ); | 269 | void gotoPageDown( int visibleHeight ); |
267 | void gotoNextWord(); | 270 | void gotoNextWord(); |
268 | void gotoPreviousWord(); | 271 | void gotoPreviousWord(); |
269 | void gotoWordLeft(); | 272 | void gotoWordLeft(); |
270 | void gotoWordRight(); | 273 | void gotoWordRight(); |
271 | 274 | ||
272 | void insert( const QString &s, bool checkNewLine, QMemArray<QTextStringChar> *formatting = 0 ); | 275 | void insert( const QString &s, bool checkNewLine, QMemArray<QTextStringChar> *formatting = 0 ); |
273 | void splitAndInsertEmptyParagraph( bool ind = TRUE, bool updateIds = TRUE ); | 276 | void splitAndInsertEmptyParagraph( bool ind = TRUE, bool updateIds = TRUE ); |
274 | bool remove(); | 277 | bool remove(); |
275 | void indent(); | 278 | void indent(); |
276 | 279 | ||
277 | bool atParagStart(); | 280 | bool atParagStart(); |
278 | bool atParagEnd(); | 281 | bool atParagEnd(); |
279 | 282 | ||
280 | int x() const; // x in current paragraph | 283 | int x() const; // x in current paragraph |
281 | int y() const; // y in current paragraph | 284 | int y() const; // y in current paragraph |
282 | 285 | ||
@@ -323,786 +326,786 @@ private: | |||
323 | 326 | ||
324 | class Q_EXPORT QTextCommand | 327 | class Q_EXPORT QTextCommand |
325 | { | 328 | { |
326 | public: | 329 | public: |
327 | enum Commands { Invalid, Insert, Delete, Format, Style }; | 330 | enum Commands { Invalid, Insert, Delete, Format, Style }; |
328 | 331 | ||
329 | QTextCommand( QTextDocument *d ) : doc( d ), cursor( d ) {} | 332 | QTextCommand( QTextDocument *d ) : doc( d ), cursor( d ) {} |
330 | virtual ~QTextCommand(); | 333 | virtual ~QTextCommand(); |
331 | 334 | ||
332 | virtual Commands type() const; | 335 | virtual Commands type() const; |
333 | 336 | ||
334 | virtual QTextCursor *execute( QTextCursor *c ) = 0; | 337 | virtual QTextCursor *execute( QTextCursor *c ) = 0; |
335 | virtual QTextCursor *unexecute( QTextCursor *c ) = 0; | 338 | virtual QTextCursor *unexecute( QTextCursor *c ) = 0; |
336 | 339 | ||
337 | protected: | 340 | protected: |
338 | QTextDocument *doc; | 341 | QTextDocument *doc; |
339 | QTextCursor cursor; | 342 | QTextCursor cursor; |
340 | 343 | ||
341 | }; | 344 | }; |
342 | 345 | ||
343 | #if defined(Q_TEMPLATEDLL) | 346 | #if defined(Q_TEMPLATEDLL) |
344 | // MOC_SKIP_BEGIN | 347 | // MOC_SKIP_BEGIN |
345 | Q_TEMPLATE_EXTERN template class Q_EXPORT QPtrList<QTextCommand>; | 348 | Q_TEMPLATE_EXTERN template class Q_EXPORT QPtrList<QTextCommand>; |
346 | // MOC_SKIP_END | 349 | // MOC_SKIP_END |
347 | #endif | 350 | #endif |
348 | 351 | ||
349 | class Q_EXPORT QTextCommandHistory | 352 | class Q_EXPORT QTextCommandHistory |
350 | { | 353 | { |
351 | public: | 354 | public: |
352 | QTextCommandHistory( int s ) : current( -1 ), steps( s ) { history.setAutoDelete( TRUE ); } | 355 | QTextCommandHistory( int s ) : current( -1 ), steps( s ) { history.setAutoDelete( TRUE ); } |
353 | virtual ~QTextCommandHistory(); | 356 | virtual ~QTextCommandHistory(); |
354 | 357 | ||
355 | void clear() { history.clear(); current = -1; } | 358 | void clear() { history.clear(); current = -1; } |
356 | 359 | ||
357 | void addCommand( QTextCommand *cmd ); | 360 | void addCommand( QTextCommand *cmd ); |
358 | QTextCursor *undo( QTextCursor *c ); | 361 | QTextCursor *undo( QTextCursor *c ); |
359 | QTextCursor *redo( QTextCursor *c ); | 362 | QTextCursor *redo( QTextCursor *c ); |
360 | 363 | ||
361 | bool isUndoAvailable(); | 364 | bool isUndoAvailable(); |
362 | bool isRedoAvailable(); | 365 | bool isRedoAvailable(); |
363 | 366 | ||
364 | void setUndoDepth( int d ) { steps = d; } | 367 | void setUndoDepth( int d ) { steps = d; } |
365 | int undoDepth() const { return steps; } | 368 | int undoDepth() const { return steps; } |
366 | 369 | ||
367 | int historySize() const { return history.count(); } | 370 | int historySize() const { return history.count(); } |
368 | int currentPosition() const { return current; } | 371 | int currentPosition() const { return current; } |
369 | 372 | ||
370 | private: | 373 | private: |
371 | QPtrList<QTextCommand> history; | 374 | QPtrList<QTextCommand> history; |
372 | int current, steps; | 375 | int current, steps; |
373 | 376 | ||
374 | }; | 377 | }; |
375 | 378 | ||
376 | inline QTextCommandHistory::~QTextCommandHistory() | 379 | inline QTextCommandHistory::~QTextCommandHistory() |
377 | { | 380 | { |
378 | clear(); | 381 | clear(); |
379 | } | 382 | } |
380 | 383 | ||
381 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | 384 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
382 | 385 | ||
383 | class Q_EXPORT QTextCustomItem | 386 | class Q_EXPORT QTextCustomItem |
384 | { | 387 | { |
385 | public: | 388 | public: |
386 | QTextCustomItem( QTextDocument *p ) | 389 | QTextCustomItem( QTextDocument *p ) |
387 | : xpos(0), ypos(-1), width(-1), height(0), parent( p ) | 390 | : xpos(0), ypos(-1), width(-1), height(0), parent( p ) |
388 | {} | 391 | {} |
389 | virtual ~QTextCustomItem(); | 392 | virtual ~QTextCustomItem(); |
390 | virtual void draw(QPainter* p, int x, int y, int cx, int cy, int cw, int ch, const QColorGroup& cg, bool selected ) = 0; | 393 | virtual void draw(QPainter* p, int x, int y, int cx, int cy, int cw, int ch, const QColorGroup& cg, bool selected ) = 0; |
391 | 394 | ||
392 | virtual void adjustToPainter( QPainter* ); | 395 | virtual void adjustToPainter( QPainter* ); |
393 | 396 | ||
394 | enum Placement { PlaceInline = 0, PlaceLeft, PlaceRight }; | 397 | enum Placement { PlaceInline = 0, PlaceLeft, PlaceRight }; |
395 | virtual Placement placement() const; | 398 | virtual Placement placement() const; |
396 | bool placeInline() { return placement() == PlaceInline; } | 399 | bool placeInline() { return placement() == PlaceInline; } |
397 | 400 | ||
398 | virtual bool ownLine() const; | 401 | virtual bool ownLine() const; |
399 | virtual void resize( int nwidth ); | 402 | virtual void resize( int nwidth ); |
400 | virtual void invalidate(); | 403 | virtual void invalidate(); |
401 | virtual int ascent() const { return height; } | 404 | virtual int ascent() const { return height; } |
402 | 405 | ||
403 | virtual bool isNested() const; | 406 | virtual bool isNested() const; |
404 | virtual int minimumWidth() const; | 407 | virtual int minimumWidth() const; |
405 | 408 | ||
406 | virtual QString richText() const; | 409 | virtual QString richText() const; |
407 | 410 | ||
408 | int xpos; // used for floating items | 411 | int xpos; // used for floating items |
409 | int ypos; // used for floating items | 412 | int ypos; // used for floating items |
410 | int width; | 413 | int width; |
411 | int height; | 414 | int height; |
412 | 415 | ||
413 | QRect geometry() const { return QRect( xpos, ypos, width, height ); } | 416 | QRect geometry() const { return QRect( xpos, ypos, width, height ); } |
414 | 417 | ||
415 | virtual bool enter( QTextCursor *, QTextDocument *&doc, QTextParagraph *¶g, int &idx, int &ox, int &oy, bool atEnd = FALSE ); | 418 | virtual bool enter( QTextCursor *, QTextDocument *&doc, QTextParagraph *¶g, int &idx, int &ox, int &oy, bool atEnd = FALSE ); |
416 | virtual bool enterAt( QTextCursor *, QTextDocument *&doc, QTextParagraph *¶g, int &idx, int &ox, int &oy, const QPoint & ); | 419 | virtual bool enterAt( QTextCursor *, QTextDocument *&doc, QTextParagraph *¶g, int &idx, int &ox, int &oy, const QPoint & ); |
417 | virtual bool next( QTextCursor *, QTextDocument *&doc, QTextParagraph *¶g, int &idx, int &ox, int &oy ); | 420 | virtual bool next( QTextCursor *, QTextDocument *&doc, QTextParagraph *¶g, int &idx, int &ox, int &oy ); |
418 | virtual bool prev( QTextCursor *, QTextDocument *&doc, QTextParagraph *¶g, int &idx, int &ox, int &oy ); | 421 | virtual bool prev( QTextCursor *, QTextDocument *&doc, QTextParagraph *¶g, int &idx, int &ox, int &oy ); |
419 | virtual bool down( QTextCursor *, QTextDocument *&doc, QTextParagraph *¶g, int &idx, int &ox, int &oy ); | 422 | virtual bool down( QTextCursor *, QTextDocument *&doc, QTextParagraph *¶g, int &idx, int &ox, int &oy ); |
420 | virtual bool up( QTextCursor *, QTextDocument *&doc, QTextParagraph *¶g, int &idx, int &ox, int &oy ); | 423 | virtual bool up( QTextCursor *, QTextDocument *&doc, QTextParagraph *¶g, int &idx, int &ox, int &oy ); |
421 | 424 | ||
422 | void setParagraph( QTextParagraph *p ) { parag = p; } | 425 | void setParagraph( QTextParagraph *p ) { parag = p; } |
423 | QTextParagraph *paragraph() const { return parag; } | 426 | QTextParagraph *paragraph() const { return parag; } |
424 | 427 | ||
425 | QTextDocument *parent; | 428 | QTextDocument *parent; |
426 | QTextParagraph *parag; | 429 | QTextParagraph *parag; |
427 | 430 | ||
428 | virtual void pageBreak( int y, QTextFlow* flow ); | 431 | virtual void pageBreak( int y, QTextFlow* flow ); |
429 | }; | 432 | }; |
430 | 433 | ||
431 | #if defined(Q_TEMPLATEDLL) | 434 | #if defined(Q_TEMPLATEDLL) |
432 | // MOC_SKIP_BEGIN | 435 | // MOC_SKIP_BEGIN |
433 | Q_TEMPLATE_EXTERN template class Q_EXPORT QMap<QString, QString>; | 436 | Q_TEMPLATE_EXTERN template class Q_EXPORT QMap<QString, QString>; |
434 | // MOC_SKIP_END | 437 | // MOC_SKIP_END |
435 | #endif | 438 | #endif |
436 | 439 | ||
437 | class Q_EXPORT QTextImage : public QTextCustomItem | 440 | class Q_EXPORT QTextImage : public QTextCustomItem |
438 | { | 441 | { |
439 | public: | 442 | public: |
440 | QTextImage( QTextDocument *p, const QMap<QString, QString> &attr, const QString& context, | 443 | QTextImage( QTextDocument *p, const QMap<QString, QString> &attr, const QString& context, |
441 | QMimeSourceFactory &factory ); | 444 | QMimeSourceFactory &factory ); |
442 | virtual ~QTextImage(); | 445 | virtual ~QTextImage(); |
443 | 446 | ||
444 | Placement placement() const { return place; } | 447 | Placement placement() const { return place; } |
445 | void adjustToPainter( QPainter* ); | 448 | void adjustToPainter( QPainter* ); |
446 | int minimumWidth() const { return width; } | 449 | int minimumWidth() const { return width; } |
447 | 450 | ||
448 | QString richText() const; | 451 | QString richText() const; |
449 | 452 | ||
450 | void draw( QPainter* p, int x, int y, int cx, int cy, int cw, int ch, const QColorGroup& cg, bool selected ); | 453 | void draw( QPainter* p, int x, int y, int cx, int cy, int cw, int ch, const QColorGroup& cg, bool selected ); |
451 | 454 | ||
452 | private: | 455 | private: |
453 | QRegion* reg; | 456 | QRegion* reg; |
454 | QPixmap pm; | 457 | QPixmap pm; |
455 | Placement place; | 458 | Placement place; |
456 | int tmpwidth, tmpheight; | 459 | int tmpwidth, tmpheight; |
457 | QMap<QString, QString> attributes; | 460 | QMap<QString, QString> attributes; |
458 | QString imgId; | 461 | QString imgId; |
459 | 462 | ||
460 | }; | 463 | }; |
461 | 464 | ||
462 | class Q_EXPORT QTextHorizontalLine : public QTextCustomItem | 465 | class Q_EXPORT QTextHorizontalLine : public QTextCustomItem |
463 | { | 466 | { |
464 | public: | 467 | public: |
465 | QTextHorizontalLine( QTextDocument *p, const QMap<QString, QString> &attr, const QString& context, | 468 | QTextHorizontalLine( QTextDocument *p, const QMap<QString, QString> &attr, const QString& context, |
466 | QMimeSourceFactory &factory ); | 469 | QMimeSourceFactory &factory ); |
467 | virtual ~QTextHorizontalLine(); | 470 | virtual ~QTextHorizontalLine(); |
468 | 471 | ||
469 | void adjustToPainter( QPainter* ); | 472 | void adjustToPainter( QPainter* ); |
470 | void draw(QPainter* p, int x, int y, int cx, int cy, int cw, int ch, const QColorGroup& cg, bool selected ); | 473 | void draw(QPainter* p, int x, int y, int cx, int cy, int cw, int ch, const QColorGroup& cg, bool selected ); |
471 | QString richText() const; | 474 | QString richText() const; |
472 | 475 | ||
473 | bool ownLine() const { return TRUE; } | 476 | bool ownLine() const { return TRUE; } |
474 | 477 | ||
475 | private: | 478 | private: |
476 | int tmpheight; | 479 | int tmpheight; |
477 | QColor color; | 480 | QColor color; |
478 | 481 | ||
479 | }; | 482 | }; |
480 | 483 | ||
481 | #if defined(Q_TEMPLATEDLL) | 484 | #if defined(Q_TEMPLATEDLL) |
482 | // MOC_SKIP_BEGIN | 485 | // MOC_SKIP_BEGIN |
483 | Q_TEMPLATE_EXTERN template class Q_EXPORT QPtrList<QTextCustomItem>; | 486 | Q_TEMPLATE_EXTERN template class Q_EXPORT QPtrList<QTextCustomItem>; |
484 | // MOC_SKIP_END | 487 | // MOC_SKIP_END |
485 | #endif | 488 | #endif |
486 | 489 | ||
487 | class Q_EXPORT QTextFlow | 490 | class Q_EXPORT QTextFlow |
488 | { | 491 | { |
489 | friend class QTextDocument; | 492 | friend class QTextDocument; |
490 | friend class QTextTableCell; | 493 | friend class QTextTableCell; |
491 | 494 | ||
492 | public: | 495 | public: |
493 | QTextFlow(); | 496 | QTextFlow(); |
494 | virtual ~QTextFlow(); | 497 | virtual ~QTextFlow(); |
495 | 498 | ||
496 | virtual void setWidth( int width ); | 499 | virtual void setWidth( int width ); |
497 | int width() const; | 500 | int width() const; |
498 | 501 | ||
499 | virtual void setPageSize( int ps ); | 502 | virtual void setPageSize( int ps ); |
500 | int pageSize() const { return pagesize; } | 503 | int pageSize() const { return pagesize; } |
501 | 504 | ||
502 | virtual int adjustLMargin( int yp, int h, int margin, int space ); | 505 | virtual int adjustLMargin( int yp, int h, int margin, int space ); |
503 | virtual int adjustRMargin( int yp, int h, int margin, int space ); | 506 | virtual int adjustRMargin( int yp, int h, int margin, int space ); |
504 | 507 | ||
505 | virtual void registerFloatingItem( QTextCustomItem* item ); | 508 | virtual void registerFloatingItem( QTextCustomItem* item ); |
506 | virtual void unregisterFloatingItem( QTextCustomItem* item ); | 509 | virtual void unregisterFloatingItem( QTextCustomItem* item ); |
507 | virtual QRect boundingRect() const; | 510 | virtual QRect boundingRect() const; |
508 | virtual void drawFloatingItems(QPainter* p, int cx, int cy, int cw, int ch, const QColorGroup& cg, bool selected ); | 511 | virtual void drawFloatingItems(QPainter* p, int cx, int cy, int cw, int ch, const QColorGroup& cg, bool selected ); |
509 | 512 | ||
510 | virtual int adjustFlow( int y, int w, int h ); // adjusts y according to the defined pagesize. Returns the shift. | 513 | virtual int adjustFlow( int y, int w, int h ); // adjusts y according to the defined pagesize. Returns the shift. |
511 | 514 | ||
512 | virtual bool isEmpty(); | 515 | virtual bool isEmpty(); |
513 | 516 | ||
514 | void clear(); | 517 | void clear(); |
515 | 518 | ||
516 | private: | 519 | private: |
517 | int w; | 520 | int w; |
518 | int pagesize; | 521 | int pagesize; |
519 | 522 | ||
520 | QPtrList<QTextCustomItem> leftItems; | 523 | QPtrList<QTextCustomItem> leftItems; |
521 | QPtrList<QTextCustomItem> rightItems; | 524 | QPtrList<QTextCustomItem> rightItems; |
522 | 525 | ||
523 | }; | 526 | }; |
524 | 527 | ||
525 | inline int QTextFlow::width() const { return w; } | 528 | inline int QTextFlow::width() const { return w; } |
526 | 529 | ||
527 | class QTextTable; | 530 | class QTextTable; |
528 | 531 | ||
529 | class Q_EXPORT QTextTableCell : public QLayoutItem | 532 | class Q_EXPORT QTextTableCell : public QLayoutItem |
530 | { | 533 | { |
531 | friend class QTextTable; | 534 | friend class QTextTable; |
532 | 535 | ||
533 | public: | 536 | public: |
534 | QTextTableCell( QTextTable* table, | 537 | QTextTableCell( QTextTable* table, |
535 | int row, int column, | 538 | int row, int column, |
536 | const QMap<QString, QString> &attr, | 539 | const QMap<QString, QString> &attr, |
537 | const QStyleSheetItem* style, | 540 | const QStyleSheetItem* style, |
538 | const QTextFormat& fmt, const QString& context, | 541 | const QTextFormat& fmt, const QString& context, |
539 | QMimeSourceFactory &factory, QStyleSheet *sheet, const QString& doc ); | 542 | QMimeSourceFactory &factory, QStyleSheet *sheet, const QString& doc ); |
540 | virtual ~QTextTableCell(); | 543 | virtual ~QTextTableCell(); |
541 | 544 | ||
542 | QSize sizeHint() const ; | 545 | QSize sizeHint() const ; |
543 | QSize minimumSize() const ; | 546 | QSize minimumSize() const ; |
544 | QSize maximumSize() const ; | 547 | QSize maximumSize() const ; |
545 | QSizePolicy::ExpandData expanding() const; | 548 | QSizePolicy::ExpandData expanding() const; |
546 | bool isEmpty() const; | 549 | bool isEmpty() const; |
547 | void setGeometry( const QRect& ) ; | 550 | void setGeometry( const QRect& ) ; |
548 | QRect geometry() const; | 551 | QRect geometry() const; |
549 | 552 | ||
550 | bool hasHeightForWidth() const; | 553 | bool hasHeightForWidth() const; |
551 | int heightForWidth( int ) const; | 554 | int heightForWidth( int ) const; |
552 | 555 | ||
553 | void adjustToPainter( QPainter* ); | 556 | void adjustToPainter( QPainter* ); |
554 | 557 | ||
555 | int row() const { return row_; } | 558 | int row() const { return row_; } |
556 | int column() const { return col_; } | 559 | int column() const { return col_; } |
557 | int rowspan() const { return rowspan_; } | 560 | int rowspan() const { return rowspan_; } |
558 | int colspan() const { return colspan_; } | 561 | int colspan() const { return colspan_; } |
559 | int stretch() const { return stretch_; } | 562 | int stretch() const { return stretch_; } |
560 | 563 | ||
561 | QTextDocument* richText() const { return richtext; } | 564 | QTextDocument* richText() const { return richtext; } |
562 | QTextTable* table() const { return parent; } | 565 | QTextTable* table() const { return parent; } |
563 | 566 | ||
564 | void draw( QPainter* p, int x, int y, int cx, int cy, int cw, int ch, const QColorGroup& cg, bool selected ); | 567 | void draw( QPainter* p, int x, int y, int cx, int cy, int cw, int ch, const QColorGroup& cg, bool selected ); |
565 | 568 | ||
566 | QBrush *backGround() const { return background; } | 569 | QBrush *backGround() const { return background; } |
567 | virtual void invalidate(); | 570 | virtual void invalidate(); |
568 | 571 | ||
569 | int verticalAlignmentOffset() const; | 572 | int verticalAlignmentOffset() const; |
570 | int horizontalAlignmentOffset() const; | 573 | int horizontalAlignmentOffset() const; |
571 | 574 | ||
572 | private: | 575 | private: |
573 | QRect geom; | 576 | QRect geom; |
574 | QTextTable* parent; | 577 | QTextTable* parent; |
575 | QTextDocument* richtext; | 578 | QTextDocument* richtext; |
576 | int row_; | 579 | int row_; |
577 | int col_; | 580 | int col_; |
578 | int rowspan_; | 581 | int rowspan_; |
579 | int colspan_; | 582 | int colspan_; |
580 | int stretch_; | 583 | int stretch_; |
581 | int maxw; | 584 | int maxw; |
582 | int minw; | 585 | int minw; |
583 | bool hasFixedWidth; | 586 | bool hasFixedWidth; |
584 | QBrush *background; | 587 | QBrush *background; |
585 | int cached_width; | 588 | int cached_width; |
586 | int cached_sizehint; | 589 | int cached_sizehint; |
587 | QMap<QString, QString> attributes; | 590 | QMap<QString, QString> attributes; |
588 | int align; | 591 | int align; |
589 | }; | 592 | }; |
590 | 593 | ||
591 | #if defined(Q_TEMPLATEDLL) | 594 | #if defined(Q_TEMPLATEDLL) |
592 | // MOC_SKIP_BEGIN | 595 | // MOC_SKIP_BEGIN |
593 | Q_TEMPLATE_EXTERN template class Q_EXPORT QPtrList<QTextTableCell>; | 596 | Q_TEMPLATE_EXTERN template class Q_EXPORT QPtrList<QTextTableCell>; |
594 | Q_TEMPLATE_EXTERN template class Q_EXPORT QMap<QTextCursor*, int>; | 597 | Q_TEMPLATE_EXTERN template class Q_EXPORT QMap<QTextCursor*, int>; |
595 | // MOC_SKIP_END | 598 | // MOC_SKIP_END |
596 | #endif | 599 | #endif |
597 | 600 | ||
598 | class Q_EXPORT QTextTable: public QTextCustomItem | 601 | class Q_EXPORT QTextTable: public QTextCustomItem |
599 | { | 602 | { |
600 | friend class QTextTableCell; | 603 | friend class QTextTableCell; |
601 | 604 | ||
602 | public: | 605 | public: |
603 | QTextTable( QTextDocument *p, const QMap<QString, QString> &attr ); | 606 | QTextTable( QTextDocument *p, const QMap<QString, QString> &attr ); |
604 | virtual ~QTextTable(); | 607 | virtual ~QTextTable(); |
605 | 608 | ||
606 | void adjustToPainter( QPainter *p ); | 609 | void adjustToPainter( QPainter *p ); |
607 | void pageBreak( int y, QTextFlow* flow ); | 610 | void pageBreak( int y, QTextFlow* flow ); |
608 | void draw( QPainter* p, int x, int y, int cx, int cy, int cw, int ch, | 611 | void draw( QPainter* p, int x, int y, int cx, int cy, int cw, int ch, |
609 | const QColorGroup& cg, bool selected ); | 612 | const QColorGroup& cg, bool selected ); |
610 | 613 | ||
611 | bool noErase() const { return TRUE; } | 614 | bool noErase() const { return TRUE; } |
612 | bool ownLine() const { return TRUE; } | 615 | bool ownLine() const { return TRUE; } |
613 | Placement placement() const { return place; } | 616 | Placement placement() const { return place; } |
614 | bool isNested() const { return TRUE; } | 617 | bool isNested() const { return TRUE; } |
615 | void resize( int nwidth ); | 618 | void resize( int nwidth ); |
616 | virtual void invalidate(); | 619 | virtual void invalidate(); |
617 | 620 | ||
618 | virtual bool enter( QTextCursor *c, QTextDocument *&doc, QTextParagraph *¶g, int &idx, int &ox, int &oy, bool atEnd = FALSE ); | 621 | virtual bool enter( QTextCursor *c, QTextDocument *&doc, QTextParagraph *¶g, int &idx, int &ox, int &oy, bool atEnd = FALSE ); |
619 | virtual bool enterAt( QTextCursor *c, QTextDocument *&doc, QTextParagraph *¶g, int &idx, int &ox, int &oy, const QPoint &pos ); | 622 | virtual bool enterAt( QTextCursor *c, QTextDocument *&doc, QTextParagraph *¶g, int &idx, int &ox, int &oy, const QPoint &pos ); |
620 | virtual bool next( QTextCursor *c, QTextDocument *&doc, QTextParagraph *¶g, int &idx, int &ox, int &oy ); | 623 | virtual bool next( QTextCursor *c, QTextDocument *&doc, QTextParagraph *¶g, int &idx, int &ox, int &oy ); |
621 | virtual bool prev( QTextCursor *c, QTextDocument *&doc, QTextParagraph *¶g, int &idx, int &ox, int &oy ); | 624 | virtual bool prev( QTextCursor *c, QTextDocument *&doc, QTextParagraph *¶g, int &idx, int &ox, int &oy ); |
622 | virtual bool down( QTextCursor *c, QTextDocument *&doc, QTextParagraph *¶g, int &idx, int &ox, int &oy ); | 625 | virtual bool down( QTextCursor *c, QTextDocument *&doc, QTextParagraph *¶g, int &idx, int &ox, int &oy ); |
623 | virtual bool up( QTextCursor *c, QTextDocument *&doc, QTextParagraph *¶g, int &idx, int &ox, int &oy ); | 626 | virtual bool up( QTextCursor *c, QTextDocument *&doc, QTextParagraph *¶g, int &idx, int &ox, int &oy ); |
624 | 627 | ||
625 | QString richText() const; | 628 | QString richText() const; |
626 | 629 | ||
627 | int minimumWidth() const; | 630 | int minimumWidth() const; |
628 | 631 | ||
629 | QPtrList<QTextTableCell> tableCells() const { return cells; } | 632 | QPtrList<QTextTableCell> tableCells() const { return cells; } |
630 | 633 | ||
631 | bool isStretching() const { return stretch; } | 634 | bool isStretching() const { return stretch; } |
632 | 635 | ||
633 | private: | 636 | private: |
634 | void format( int w ); | 637 | void format( int w ); |
635 | void addCell( QTextTableCell* cell ); | 638 | void addCell( QTextTableCell* cell ); |
636 | 639 | ||
637 | private: | 640 | private: |
638 | QGridLayout* layout; | 641 | QGridLayout* layout; |
639 | QPtrList<QTextTableCell> cells; | 642 | QPtrList<QTextTableCell> cells; |
640 | int cachewidth; | 643 | int cachewidth; |
641 | int fixwidth; | 644 | int fixwidth; |
642 | int cellpadding; | 645 | int cellpadding; |
643 | int cellspacing; | 646 | int cellspacing; |
644 | int border; | 647 | int border; |
645 | int outerborder; | 648 | int outerborder; |
646 | int stretch; | 649 | int stretch; |
647 | int innerborder; | 650 | int innerborder; |
648 | int us_cp, us_ib, us_b, us_ob, us_cs; | 651 | int us_cp, us_ib, us_b, us_ob, us_cs; |
649 | QMap<QString, QString> attributes; | 652 | QMap<QString, QString> attributes; |
650 | QMap<QTextCursor*, int> currCell; | 653 | QMap<QTextCursor*, int> currCell; |
651 | Placement place; | 654 | Placement place; |
652 | void adjustCells( int y , int shift ); | 655 | void adjustCells( int y , int shift ); |
653 | int pageBreakFor; | 656 | int pageBreakFor; |
654 | }; | 657 | }; |
655 | 658 | ||
656 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | 659 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
657 | 660 | ||
658 | class QTextTableCell; | 661 | class QTextTableCell; |
659 | class QTextParagraph; | 662 | class QTextParagraph; |
660 | 663 | ||
661 | struct Q_EXPORT QTextDocumentSelection | 664 | struct Q_EXPORT QTextDocumentSelection |
662 | { | 665 | { |
663 | QTextCursor startCursor, endCursor; | 666 | QTextCursor startCursor, endCursor; |
664 | bool swapped; | 667 | bool swapped; |
665 | }; | 668 | }; |
666 | 669 | ||
667 | #if defined(Q_TEMPLATEDLL) | 670 | #if defined(Q_TEMPLATEDLL) |
668 | // MOC_SKIP_BEGIN | 671 | // MOC_SKIP_BEGIN |
669 | Q_TEMPLATE_EXTERN template class Q_EXPORT QMap<int, QColor>; | 672 | Q_TEMPLATE_EXTERN template class Q_EXPORT QMap<int, QColor>; |
670 | Q_TEMPLATE_EXTERN template class Q_EXPORT QMap<int, bool>; | 673 | Q_TEMPLATE_EXTERN template class Q_EXPORT QMap<int, bool>; |
671 | Q_TEMPLATE_EXTERN template class Q_EXPORT QMap<int, QTextDocumentSelection>; | 674 | Q_TEMPLATE_EXTERN template class Q_EXPORT QMap<int, QTextDocumentSelection>; |
672 | Q_TEMPLATE_EXTERN template class Q_EXPORT QPtrList<QTextDocument>; | 675 | Q_TEMPLATE_EXTERN template class Q_EXPORT QPtrList<QTextDocument>; |
673 | // MOC_SKIP_END | 676 | // MOC_SKIP_END |
674 | #endif | 677 | #endif |
675 | 678 | ||
676 | class Q_EXPORT QTextDocument : public QObject | 679 | class Q_EXPORT QTextDocument : public QObject |
677 | { | 680 | { |
678 | Q_OBJECT | 681 | Q_OBJECT |
679 | 682 | ||
680 | friend class QTextTableCell; | 683 | friend class QTextTableCell; |
681 | friend class QTextCursor; | 684 | friend class QTextCursor; |
682 | friend class QTextEdit; | 685 | friend class QTextEdit; |
683 | friend class QTextParagraph; | 686 | friend class QTextParagraph; |
684 | 687 | ||
685 | public: | 688 | public: |
686 | enum SelectionIds { | 689 | enum SelectionIds { |
687 | Standard = 0, | 690 | Standard = 0, |
688 | Temp = 32000 // This selection must not be drawn, it's used e.g. by undo/redo to | 691 | Temp = 32000 // This selection must not be drawn, it's used e.g. by undo/redo to |
689 | // remove multiple lines with removeSelectedText() | 692 | // remove multiple lines with removeSelectedText() |
690 | }; | 693 | }; |
691 | 694 | ||
692 | QTextDocument( QTextDocument *p ); | 695 | QTextDocument( QTextDocument *p ); |
693 | QTextDocument( QTextDocument *d, QTextFormatCollection *f ); | 696 | QTextDocument( QTextDocument *d, QTextFormatCollection *f ); |
694 | virtual ~QTextDocument(); | 697 | virtual ~QTextDocument(); |
695 | 698 | ||
696 | QTextDocument *parent() const { return par; } | 699 | QTextDocument *parent() const { return par; } |
697 | QTextParagraph *parentParagraph() const { return parentPar; } | 700 | QTextParagraph *parentParagraph() const { return parentPar; } |
698 | 701 | ||
699 | void setText( const QString &text, const QString &context ); | 702 | void setText( const QString &text, const QString &context ); |
700 | QMap<QString, QString> attributes() const { return attribs; } | 703 | QMap<QString, QString> attributes() const { return attribs; } |
701 | void setAttributes( const QMap<QString, QString> &attr ) { attribs = attr; } | 704 | void setAttributes( const QMap<QString, QString> &attr ) { attribs = attr; } |
702 | 705 | ||
703 | QString text() const; | 706 | QString text() const; |
704 | QString text( int parag ) const; | 707 | QString text( int parag ) const; |
705 | QString originalText() const; | 708 | QString originalText() const; |
706 | 709 | ||
707 | int x() const; | 710 | int x() const; |
708 | int y() const; | 711 | int y() const; |
709 | int width() const; | 712 | int width() const; |
710 | int widthUsed() const; | 713 | int widthUsed() const; |
711 | int visibleWidth() const; | 714 | int visibleWidth() const; |
712 | int height() const; | 715 | int height() const; |
713 | void setWidth( int w ); | 716 | void setWidth( int w ); |
714 | int minimumWidth() const; | 717 | int minimumWidth() const; |
715 | bool setMinimumWidth( int needed, int used = -1, QTextParagraph *parag = 0 ); | 718 | bool setMinimumWidth( int needed, int used = -1, QTextParagraph *parag = 0 ); |
716 | 719 | ||
717 | void setY( int y ); | 720 | void setY( int y ); |
718 | int leftMargin() const; | 721 | int leftMargin() const; |
719 | void setLeftMargin( int lm ); | 722 | void setLeftMargin( int lm ); |
720 | int rightMargin() const; | 723 | int rightMargin() const; |
721 | void setRightMargin( int rm ); | 724 | void setRightMargin( int rm ); |
722 | 725 | ||
723 | QTextParagraph *firstParagraph() const; | 726 | QTextParagraph *firstParagraph() const; |
724 | QTextParagraph *lastParagraph() const; | 727 | QTextParagraph *lastParagraph() const; |
725 | void setFirstParagraph( QTextParagraph *p ); | 728 | void setFirstParagraph( QTextParagraph *p ); |
726 | void setLastParagraph( QTextParagraph *p ); | 729 | void setLastParagraph( QTextParagraph *p ); |
727 | 730 | ||
728 | void invalidate(); | 731 | void invalidate(); |
729 | 732 | ||
730 | void setPreProcessor( QTextPreProcessor *sh ); | 733 | void setPreProcessor( QTextPreProcessor *sh ); |
731 | QTextPreProcessor *preProcessor() const; | 734 | QTextPreProcessor *preProcessor() const; |
732 | 735 | ||
733 | void setFormatter( QTextFormatter *f ); | 736 | void setFormatter( QTextFormatter *f ); |
734 | QTextFormatter *formatter() const; | 737 | QTextFormatter *formatter() const; |
735 | 738 | ||
736 | void setIndent( QTextIndent *i ); | 739 | void setIndent( QTextIndent *i ); |
737 | QTextIndent *indent() const; | 740 | QTextIndent *indent() const; |
738 | 741 | ||
739 | QColor selectionColor( int id ) const; | 742 | QColor selectionColor( int id ) const; |
740 | bool invertSelectionText( int id ) const; | 743 | bool invertSelectionText( int id ) const; |
741 | void setSelectionColor( int id, const QColor &c ); | 744 | void setSelectionColor( int id, const QColor &c ); |
742 | void setInvertSelectionText( int id, bool b ); | 745 | void setInvertSelectionText( int id, bool b ); |
743 | bool hasSelection( int id, bool visible = FALSE ) const; | 746 | bool hasSelection( int id, bool visible = FALSE ) const; |
744 | void setSelectionStart( int id, const QTextCursor &cursor ); | 747 | void setSelectionStart( int id, const QTextCursor &cursor ); |
745 | bool setSelectionEnd( int id, const QTextCursor &cursor ); | 748 | bool setSelectionEnd( int id, const QTextCursor &cursor ); |
746 | void selectAll( int id ); | 749 | void selectAll( int id ); |
747 | bool removeSelection( int id ); | 750 | bool removeSelection( int id ); |
748 | void selectionStart( int id, int ¶gId, int &index ); | 751 | void selectionStart( int id, int ¶gId, int &index ); |
749 | QTextCursor selectionStartCursor( int id ); | 752 | QTextCursor selectionStartCursor( int id ); |
750 | QTextCursor selectionEndCursor( int id ); | 753 | QTextCursor selectionEndCursor( int id ); |
751 | void selectionEnd( int id, int ¶gId, int &index ); | 754 | void selectionEnd( int id, int ¶gId, int &index ); |
752 | void setFormat( int id, QTextFormat *f, int flags ); | 755 | void setFormat( int id, QTextFormat *f, int flags ); |
753 | int numSelections() const { return nSelections; } | 756 | int numSelections() const { return nSelections; } |
754 | void addSelection( int id ); | 757 | void addSelection( int id ); |
755 | 758 | ||
756 | QString selectedText( int id, bool asRichText = FALSE ) const; | 759 | QString selectedText( int id, bool asRichText = FALSE ) const; |
757 | void removeSelectedText( int id, QTextCursor *cursor ); | 760 | void removeSelectedText( int id, QTextCursor *cursor ); |
758 | void indentSelection( int id ); | 761 | void indentSelection( int id ); |
759 | 762 | ||
760 | QTextParagraph *paragAt( int i ) const; | 763 | QTextParagraph *paragAt( int i ) const; |
761 | 764 | ||
762 | void addCommand( QTextCommand *cmd ); | 765 | void addCommand( QTextCommand *cmd ); |
763 | QTextCursor *undo( QTextCursor *c = 0 ); | 766 | QTextCursor *undo( QTextCursor *c = 0 ); |
764 | QTextCursor *redo( QTextCursor *c = 0 ); | 767 | QTextCursor *redo( QTextCursor *c = 0 ); |
765 | QTextCommandHistory *commands() const { return commandHistory; } | 768 | QTextCommandHistory *commands() const { return commandHistory; } |
766 | 769 | ||
767 | QTextFormatCollection *formatCollection() const; | 770 | QTextFormatCollection *formatCollection() const; |
768 | 771 | ||
769 | bool find( QTextCursor &cursor, const QString &expr, bool cs, bool wo, bool forward); | 772 | bool find( QTextCursor &cursor, const QString &expr, bool cs, bool wo, bool forward); |
770 | 773 | ||
771 | void setTextFormat( Qt::TextFormat f ); | 774 | void setTextFormat( Qt::TextFormat f ); |
772 | Qt::TextFormat textFormat() const; | 775 | Qt::TextFormat textFormat() const; |
773 | 776 | ||
774 | bool inSelection( int selId, const QPoint &pos ) const; | 777 | bool inSelection( int selId, const QPoint &pos ) const; |
775 | 778 | ||
776 | QStyleSheet *styleSheet() const { return sheet_; } | 779 | QStyleSheet *styleSheet() const { return sheet_; } |
777 | QMimeSourceFactory *mimeSourceFactory() const { return factory_; } | 780 | QMimeSourceFactory *mimeSourceFactory() const { return factory_; } |
778 | QString context() const { return contxt; } | 781 | QString context() const { return contxt; } |
779 | 782 | ||
780 | void setStyleSheet( QStyleSheet *s ); | 783 | void setStyleSheet( QStyleSheet *s ); |
781 | void setDefaultFormat( const QFont &font, const QColor &color ); | 784 | void setDefaultFormat( const QFont &font, const QColor &color ); |
782 | void setMimeSourceFactory( QMimeSourceFactory *f ) { if ( f ) factory_ = f; } | 785 | void setMimeSourceFactory( QMimeSourceFactory *f ) { if ( f ) factory_ = f; } |
783 | void setContext( const QString &c ) { if ( !c.isEmpty() ) contxt = c; } | 786 | void setContext( const QString &c ) { if ( !c.isEmpty() ) contxt = c; } |
784 | 787 | ||
785 | void setUnderlineLinks( bool b ); | 788 | void setUnderlineLinks( bool b ); |
786 | bool underlineLinks() const { return underlLinks; } | 789 | bool underlineLinks() const { return underlLinks; } |
787 | 790 | ||
788 | void setPaper( QBrush *brush ) { if ( backBrush ) delete backBrush; backBrush = brush; } | 791 | void setPaper( QBrush *brush ) { if ( backBrush ) delete backBrush; backBrush = brush; } |
789 | QBrush *paper() const { return backBrush; } | 792 | QBrush *paper() const { return backBrush; } |
790 | 793 | ||
791 | void doLayout( QPainter *p, int w ); | 794 | void doLayout( QPainter *p, int w ); |
792 | void draw( QPainter *p, const QRect& rect, const QColorGroup &cg, const QBrush *paper = 0 ); | 795 | void draw( QPainter *p, const QRect& rect, const QColorGroup &cg, const QBrush *paper = 0 ); |
793 | void drawParagraph( QPainter *p, QTextParagraph *parag, int cx, int cy, int cw, int ch, | 796 | void drawParagraph( QPainter *p, QTextParagraph *parag, int cx, int cy, int cw, int ch, |
794 | QPixmap *&doubleBuffer, const QColorGroup &cg, | 797 | QPixmap *&doubleBuffer, const QColorGroup &cg, |
795 | bool drawCursor, QTextCursor *cursor, bool resetChanged = TRUE ); | 798 | bool drawCursor, QTextCursor *cursor, bool resetChanged = TRUE ); |
796 | QTextParagraph *draw( QPainter *p, int cx, int cy, int cw, int ch, const QColorGroup &cg, | 799 | QTextParagraph *draw( QPainter *p, int cx, int cy, int cw, int ch, const QColorGroup &cg, |
797 | bool onlyChanged = FALSE, bool drawCursor = FALSE, QTextCursor *cursor = 0, | 800 | bool onlyChanged = FALSE, bool drawCursor = FALSE, QTextCursor *cursor = 0, |
798 | bool resetChanged = TRUE ); | 801 | bool resetChanged = TRUE ); |
799 | 802 | ||
800 | void registerCustomItem( QTextCustomItem *i, QTextParagraph *p ); | 803 | void registerCustomItem( QTextCustomItem *i, QTextParagraph *p ); |
801 | void unregisterCustomItem( QTextCustomItem *i, QTextParagraph *p ); | 804 | void unregisterCustomItem( QTextCustomItem *i, QTextParagraph *p ); |
802 | 805 | ||
803 | void setFlow( QTextFlow *f ); | 806 | void setFlow( QTextFlow *f ); |
804 | void takeFlow(); | 807 | void takeFlow(); |
805 | QTextFlow *flow() const { return flow_; } | 808 | QTextFlow *flow() const { return flow_; } |
806 | bool isPageBreakEnabled() const { return pages; } | 809 | bool isPageBreakEnabled() const { return pages; } |
807 | void setPageBreakEnabled( bool b ) { pages = b; } | 810 | void setPageBreakEnabled( bool b ) { pages = b; } |
808 | 811 | ||
809 | void setUseFormatCollection( bool b ) { useFC = b; } | 812 | void setUseFormatCollection( bool b ) { useFC = b; } |
810 | bool useFormatCollection() const { return useFC; } | 813 | bool useFormatCollection() const { return useFC; } |
811 | 814 | ||
812 | QTextTableCell *tableCell() const { return tc; } | 815 | QTextTableCell *tableCell() const { return tc; } |
813 | void setTableCell( QTextTableCell *c ) { tc = c; } | 816 | void setTableCell( QTextTableCell *c ) { tc = c; } |
814 | 817 | ||
815 | void setPlainText( const QString &text ); | 818 | void setPlainText( const QString &text ); |
816 | void setRichText( const QString &text, const QString &context ); | 819 | void setRichText( const QString &text, const QString &context ); |
817 | QString richText() const; | 820 | QString richText() const; |
818 | QString plainText() const; | 821 | QString plainText() const; |
819 | 822 | ||
820 | bool focusNextPrevChild( bool next ); | 823 | bool focusNextPrevChild( bool next ); |
821 | 824 | ||
822 | int alignment() const; | 825 | int alignment() const; |
823 | void setAlignment( int a ); | 826 | void setAlignment( int a ); |
824 | 827 | ||
825 | int *tabArray() const; | 828 | int *tabArray() const; |
826 | int tabStopWidth() const; | 829 | int tabStopWidth() const; |
827 | void setTabArray( int *a ); | 830 | void setTabArray( int *a ); |
828 | void setTabStops( int tw ); | 831 | void setTabStops( int tw ); |
829 | 832 | ||
830 | void setUndoDepth( int d ) { commandHistory->setUndoDepth( d ); } | 833 | void setUndoDepth( int d ) { commandHistory->setUndoDepth( d ); } |
831 | int undoDepth() const { return commandHistory->undoDepth(); } | 834 | int undoDepth() const { return commandHistory->undoDepth(); } |
832 | 835 | ||
833 | int length() const; | 836 | int length() const; |
834 | void clear( bool createEmptyParag = FALSE ); | 837 | void clear( bool createEmptyParag = FALSE ); |
835 | 838 | ||
836 | virtual QTextParagraph *createParagraph( QTextDocument *d, QTextParagraph *pr = 0, QTextParagraph *nx = 0, bool updateIds = TRUE ); | 839 | virtual QTextParagraph *createParagraph( QTextDocument *d, QTextParagraph *pr = 0, QTextParagraph *nx = 0, bool updateIds = TRUE ); |
837 | void insertChild( QObject *o ) { QObject::insertChild( o ); } | 840 | void insertChild( QObject *o ) { QObject::insertChild( o ); } |
838 | void removeChild( QObject *o ) { QObject::removeChild( o ); } | 841 | void removeChild( QObject *o ) { QObject::removeChild( o ); } |
839 | void insertChild( QTextDocument *d ) { childList.append( d ); } | 842 | void insertChild( QTextDocument *d ) { childList.append( d ); } |
840 | void removeChild( QTextDocument *d ) { childList.removeRef( d ); } | 843 | void removeChild( QTextDocument *d ) { childList.removeRef( d ); } |
841 | QPtrList<QTextDocument> children() const { return childList; } | 844 | QPtrList<QTextDocument> children() const { return childList; } |
842 | 845 | ||
843 | bool hasFocusParagraph() const; | 846 | bool hasFocusParagraph() const; |
844 | QString focusHref() const; | 847 | QString focusHref() const; |
845 | 848 | ||
846 | void invalidateOriginalText() { oTextValid = FALSE; oText = ""; } | 849 | void invalidateOriginalText() { oTextValid = FALSE; oText = ""; } |
847 | 850 | ||
848 | static QString section( QString str, const QString &sep, int start, int end = 0xffffffff ); | 851 | static QString section( QString str, const QString &sep, int start, int end = 0xffffffff ); |
849 | static bool endsWith( QString str, const QString &s); | 852 | static bool endsWith( QString str, const QString &s); |
850 | 853 | ||
851 | signals: | 854 | signals: |
852 | void minimumWidthChanged( int ); | 855 | void minimumWidthChanged( int ); |
853 | 856 | ||
854 | private: | 857 | private: |
855 | void init(); | 858 | void init(); |
856 | QPixmap *bufferPixmap( const QSize &s ); | 859 | QPixmap *bufferPixmap( const QSize &s ); |
857 | // HTML parser | 860 | // HTML parser |
858 | bool hasPrefix(const QChar* doc, int length, int pos, QChar c); | 861 | bool hasPrefix(const QChar* doc, int length, int pos, QChar c); |
859 | bool hasPrefix(const QChar* doc, int length, int pos, const QString& s); | 862 | bool hasPrefix(const QChar* doc, int length, int pos, const QString& s); |
860 | QTextCustomItem* parseTable( const QMap<QString, QString> &attr, const QTextFormat &fmt, | 863 | QTextCustomItem* parseTable( const QMap<QString, QString> &attr, const QTextFormat &fmt, |
861 | const QChar* doc, int length, int& pos, QTextParagraph *curpar ); | 864 | const QChar* doc, int length, int& pos, QTextParagraph *curpar ); |
862 | bool eatSpace(const QChar* doc, int length, int& pos, bool includeNbsp = FALSE ); | 865 | bool eatSpace(const QChar* doc, int length, int& pos, bool includeNbsp = FALSE ); |
863 | bool eat(const QChar* doc, int length, int& pos, QChar c); | 866 | bool eat(const QChar* doc, int length, int& pos, QChar c); |
864 | QString parseOpenTag(const QChar* doc, int length, int& pos, QMap<QString, QString> &attr, bool& emptyTag); | 867 | QString parseOpenTag(const QChar* doc, int length, int& pos, QMap<QString, QString> &attr, bool& emptyTag); |
865 | QString parseCloseTag( const QChar* doc, int length, int& pos ); | 868 | QString parseCloseTag( const QChar* doc, int length, int& pos ); |
866 | QChar parseHTMLSpecialChar(const QChar* doc, int length, int& pos); | 869 | QChar parseHTMLSpecialChar(const QChar* doc, int length, int& pos); |
867 | QString parseWord(const QChar* doc, int length, int& pos, bool lower = TRUE); | 870 | QString parseWord(const QChar* doc, int length, int& pos, bool lower = TRUE); |
868 | QChar parseChar(const QChar* doc, int length, int& pos, QStyleSheetItem::WhiteSpaceMode wsm ); | 871 | QChar parseChar(const QChar* doc, int length, int& pos, QStyleSheetItem::WhiteSpaceMode wsm ); |
869 | void setRichTextInternal( const QString &text, QTextCursor* cursor = 0 ); | 872 | void setRichTextInternal( const QString &text, QTextCursor* cursor = 0 ); |
870 | void setRichTextMarginsInternal( QPtrList< QPtrVector<QStyleSheetItem> >& styles, QTextParagraph* stylesPar ); | 873 | void setRichTextMarginsInternal( QPtrList< QPtrVector<QStyleSheetItem> >& styles, QTextParagraph* stylesPar ); |
871 | 874 | ||
872 | private: | 875 | private: |
873 | struct Q_EXPORT Focus { | 876 | struct Q_EXPORT Focus { |
874 | QTextParagraph *parag; | 877 | QTextParagraph *parag; |
875 | int start, len; | 878 | int start, len; |
876 | QString href; | 879 | QString href; |
877 | }; | 880 | }; |
878 | 881 | ||
879 | int cx, cy, cw, vw; | 882 | int cx, cy, cw, vw; |
880 | QTextParagraph *fParag, *lParag; | 883 | QTextParagraph *fParag, *lParag; |
881 | QTextPreProcessor *pProcessor; | 884 | QTextPreProcessor *pProcessor; |
882 | QMap<int, QColor> selectionColors; | 885 | QMap<int, QColor> selectionColors; |
883 | QMap<int, QTextDocumentSelection> selections; | 886 | QMap<int, QTextDocumentSelection> selections; |
884 | QMap<int, bool> selectionText; | 887 | QMap<int, bool> selectionText; |
885 | QTextCommandHistory *commandHistory; | 888 | QTextCommandHistory *commandHistory; |
886 | QTextFormatter *pFormatter; | 889 | QTextFormatter *pFormatter; |
887 | QTextIndent *indenter; | 890 | QTextIndent *indenter; |
888 | QTextFormatCollection *fCollection; | 891 | QTextFormatCollection *fCollection; |
889 | Qt::TextFormat txtFormat; | 892 | Qt::TextFormat txtFormat; |
890 | uint preferRichText : 1; | 893 | uint preferRichText : 1; |
891 | uint pages : 1; | 894 | uint pages : 1; |
892 | uint useFC : 1; | 895 | uint useFC : 1; |
893 | uint withoutDoubleBuffer : 1; | 896 | uint withoutDoubleBuffer : 1; |
894 | uint underlLinks : 1; | 897 | uint underlLinks : 1; |
895 | uint nextDoubleBuffered : 1; | 898 | uint nextDoubleBuffered : 1; |
896 | uint oTextValid : 1; | 899 | uint oTextValid : 1; |
897 | uint mightHaveCustomItems : 1; | 900 | uint mightHaveCustomItems : 1; |
898 | int align; | 901 | int align; |
899 | int nSelections; | 902 | int nSelections; |
900 | QTextFlow *flow_; | 903 | QTextFlow *flow_; |
901 | QTextDocument *par; | 904 | QTextDocument *par; |
902 | QTextParagraph *parentPar; | 905 | QTextParagraph *parentPar; |
903 | QTextTableCell *tc; | 906 | QTextTableCell *tc; |
904 | QBrush *backBrush; | 907 | QBrush *backBrush; |
905 | QPixmap *buf_pixmap; | 908 | QPixmap *buf_pixmap; |
906 | Focus focusIndicator; | 909 | Focus focusIndicator; |
907 | int minw; | 910 | int minw; |
908 | int wused; | 911 | int wused; |
909 | int leftmargin; | 912 | int leftmargin; |
910 | int rightmargin; | 913 | int rightmargin; |
911 | QTextParagraph *minwParag, *curParag; | 914 | QTextParagraph *minwParag, *curParag; |
912 | QStyleSheet* sheet_; | 915 | QStyleSheet* sheet_; |
913 | QMimeSourceFactory* factory_; | 916 | QMimeSourceFactory* factory_; |
914 | QString contxt; | 917 | QString contxt; |
915 | QMap<QString, QString> attribs; | 918 | QMap<QString, QString> attribs; |
916 | int *tArray; | 919 | int *tArray; |
917 | int tStopWidth; | 920 | int tStopWidth; |
918 | int uDepth; | 921 | int uDepth; |
919 | QString oText; | 922 | QString oText; |
920 | QPtrList<QTextDocument> childList; | 923 | QPtrList<QTextDocument> childList; |
921 | QColor linkColor; | 924 | QColor linkColor; |
922 | double scaleFontsFactor; | 925 | double scaleFontsFactor; |
923 | 926 | ||
924 | short list_tm,list_bm, list_lm, li_tm, li_bm, par_tm, par_bm; | 927 | short list_tm,list_bm, list_lm, li_tm, li_bm, par_tm, par_bm; |
925 | }; | 928 | }; |
926 | 929 | ||
927 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | 930 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
928 | 931 | ||
929 | 932 | ||
930 | class Q_EXPORT QTextDeleteCommand : public QTextCommand | 933 | class Q_EXPORT QTextDeleteCommand : public QTextCommand |
931 | { | 934 | { |
932 | public: | 935 | public: |
933 | QTextDeleteCommand( QTextDocument *d, int i, int idx, const QMemArray<QTextStringChar> &str, | 936 | QTextDeleteCommand( QTextDocument *d, int i, int idx, const QMemArray<QTextStringChar> &str, |
934 | const QByteArray& oldStyle ); | 937 | const QByteArray& oldStyle ); |
935 | QTextDeleteCommand( QTextParagraph *p, int idx, const QMemArray<QTextStringChar> &str ); | 938 | QTextDeleteCommand( QTextParagraph *p, int idx, const QMemArray<QTextStringChar> &str ); |
936 | virtual ~QTextDeleteCommand(); | 939 | virtual ~QTextDeleteCommand(); |
937 | 940 | ||
938 | Commands type() const { return Delete; } | 941 | Commands type() const { return Delete; } |
939 | QTextCursor *execute( QTextCursor *c ); | 942 | QTextCursor *execute( QTextCursor *c ); |
940 | QTextCursor *unexecute( QTextCursor *c ); | 943 | QTextCursor *unexecute( QTextCursor *c ); |
941 | 944 | ||
942 | protected: | 945 | protected: |
943 | int id, index; | 946 | int id, index; |
944 | QTextParagraph *parag; | 947 | QTextParagraph *parag; |
945 | QMemArray<QTextStringChar> text; | 948 | QMemArray<QTextStringChar> text; |
946 | QByteArray styleInformation; | 949 | QByteArray styleInformation; |
947 | 950 | ||
948 | }; | 951 | }; |
949 | 952 | ||
950 | class Q_EXPORT QTextInsertCommand : public QTextDeleteCommand | 953 | class Q_EXPORT QTextInsertCommand : public QTextDeleteCommand |
951 | { | 954 | { |
952 | public: | 955 | public: |
953 | QTextInsertCommand( QTextDocument *d, int i, int idx, const QMemArray<QTextStringChar> &str, | 956 | QTextInsertCommand( QTextDocument *d, int i, int idx, const QMemArray<QTextStringChar> &str, |
954 | const QByteArray& oldStyleInfo ) | 957 | const QByteArray& oldStyleInfo ) |
955 | : QTextDeleteCommand( d, i, idx, str, oldStyleInfo ) {} | 958 | : QTextDeleteCommand( d, i, idx, str, oldStyleInfo ) {} |
956 | QTextInsertCommand( QTextParagraph *p, int idx, const QMemArray<QTextStringChar> &str ) | 959 | QTextInsertCommand( QTextParagraph *p, int idx, const QMemArray<QTextStringChar> &str ) |
957 | : QTextDeleteCommand( p, idx, str ) {} | 960 | : QTextDeleteCommand( p, idx, str ) {} |
958 | virtual ~QTextInsertCommand() {} | 961 | virtual ~QTextInsertCommand() {} |
959 | 962 | ||
960 | Commands type() const { return Insert; } | 963 | Commands type() const { return Insert; } |
961 | QTextCursor *execute( QTextCursor *c ) { return QTextDeleteCommand::unexecute( c ); } | 964 | QTextCursor *execute( QTextCursor *c ) { return QTextDeleteCommand::unexecute( c ); } |
962 | QTextCursor *unexecute( QTextCursor *c ) { return QTextDeleteCommand::execute( c ); } | 965 | QTextCursor *unexecute( QTextCursor *c ) { return QTextDeleteCommand::execute( c ); } |
963 | 966 | ||
964 | }; | 967 | }; |
965 | 968 | ||
966 | class Q_EXPORT QTextFormatCommand : public QTextCommand | 969 | class Q_EXPORT QTextFormatCommand : public QTextCommand |
967 | { | 970 | { |
968 | public: | 971 | public: |
969 | QTextFormatCommand( QTextDocument *d, int sid, int sidx, int eid, int eidx, const QMemArray<QTextStringChar> &old, QTextFormat *f, int fl ); | 972 | QTextFormatCommand( QTextDocument *d, int sid, int sidx, int eid, int eidx, const QMemArray<QTextStringChar> &old, QTextFormat *f, int fl ); |
970 | virtual ~QTextFormatCommand(); | 973 | virtual ~QTextFormatCommand(); |
971 | 974 | ||
972 | Commands type() const { return Format; } | 975 | Commands type() const { return Format; } |
973 | QTextCursor *execute( QTextCursor *c ); | 976 | QTextCursor *execute( QTextCursor *c ); |
974 | QTextCursor *unexecute( QTextCursor *c ); | 977 | QTextCursor *unexecute( QTextCursor *c ); |
975 | 978 | ||
976 | protected: | 979 | protected: |
977 | int startId, startIndex, endId, endIndex; | 980 | int startId, startIndex, endId, endIndex; |
978 | QTextFormat *format; | 981 | QTextFormat *format; |
979 | QMemArray<QTextStringChar> oldFormats; | 982 | QMemArray<QTextStringChar> oldFormats; |
980 | int flags; | 983 | int flags; |
981 | 984 | ||
982 | }; | 985 | }; |
983 | 986 | ||
984 | class Q_EXPORT QTextStyleCommand : public QTextCommand | 987 | class Q_EXPORT QTextStyleCommand : public QTextCommand |
985 | { | 988 | { |
986 | public: | 989 | public: |
987 | QTextStyleCommand( QTextDocument *d, int fParag, int lParag, const QByteArray& beforeChange ); | 990 | QTextStyleCommand( QTextDocument *d, int fParag, int lParag, const QByteArray& beforeChange ); |
988 | virtual ~QTextStyleCommand() {} | 991 | virtual ~QTextStyleCommand() {} |
989 | 992 | ||
990 | Commands type() const { return Style; } | 993 | Commands type() const { return Style; } |
991 | QTextCursor *execute( QTextCursor *c ); | 994 | QTextCursor *execute( QTextCursor *c ); |
992 | QTextCursor *unexecute( QTextCursor *c ); | 995 | QTextCursor *unexecute( QTextCursor *c ); |
993 | 996 | ||
994 | static QByteArray readStyleInformation( QTextDocument* d, int fParag, int lParag ); | 997 | static QByteArray readStyleInformation( QTextDocument* d, int fParag, int lParag ); |
995 | static void writeStyleInformation( QTextDocument* d, int fParag, const QByteArray& style ); | 998 | static void writeStyleInformation( QTextDocument* d, int fParag, const QByteArray& style ); |
996 | 999 | ||
997 | private: | 1000 | private: |
998 | int firstParag, lastParag; | 1001 | int firstParag, lastParag; |
999 | QByteArray before; | 1002 | QByteArray before; |
1000 | QByteArray after; | 1003 | QByteArray after; |
1001 | }; | 1004 | }; |
1002 | 1005 | ||
1003 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | 1006 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1004 | 1007 | ||
1005 | struct Q_EXPORT QTextParagraphSelection | 1008 | struct Q_EXPORT QTextParagraphSelection |
1006 | { | 1009 | { |
1007 | int start, end; | 1010 | int start, end; |
1008 | }; | 1011 | }; |
1009 | 1012 | ||
1010 | struct Q_EXPORT QTextLineStart | 1013 | struct Q_EXPORT QTextLineStart |
1011 | { | 1014 | { |
1012 | QTextLineStart() : y( 0 ), baseLine( 0 ), h( 0 ) | 1015 | QTextLineStart() : y( 0 ), baseLine( 0 ), h( 0 ) |
1013 | #ifndef QT_NO_COMPLEXTEXT | 1016 | #ifndef QT_NO_COMPLEXTEXT |
1014 | , bidicontext( 0 ) | 1017 | , bidicontext( 0 ) |
1015 | #endif | 1018 | #endif |
1016 | { } | 1019 | { } |
1017 | QTextLineStart( ushort y_, ushort bl, ushort h_ ) : y( y_ ), baseLine( bl ), h( h_ ), | 1020 | QTextLineStart( ushort y_, ushort bl, ushort h_ ) : y( y_ ), baseLine( bl ), h( h_ ), |
1018 | w( 0 ) | 1021 | w( 0 ) |
1019 | #ifndef QT_NO_COMPLEXTEXT | 1022 | #ifndef QT_NO_COMPLEXTEXT |
1020 | , bidicontext( 0 ) | 1023 | , bidicontext( 0 ) |
1021 | #endif | 1024 | #endif |
1022 | { } | 1025 | { } |
1023 | #ifndef QT_NO_COMPLEXTEXT | 1026 | #ifndef QT_NO_COMPLEXTEXT |
1024 | QTextLineStart( QBidiContext *c, QBidiStatus s ) : y(0), baseLine(0), h(0), | 1027 | QTextLineStart( QBidiContext *c, QBidiStatus s ) : y(0), baseLine(0), h(0), |
1025 | status( s ), bidicontext( c ) { if ( bidicontext ) bidicontext->ref(); } | 1028 | status( s ), bidicontext( c ) { if ( bidicontext ) bidicontext->ref(); } |
1026 | #endif | 1029 | #endif |
1027 | 1030 | ||
1028 | virtual ~QTextLineStart() | 1031 | virtual ~QTextLineStart() |
1029 | { | 1032 | { |
1030 | #ifndef QT_NO_COMPLEXTEXT | 1033 | #ifndef QT_NO_COMPLEXTEXT |
1031 | if ( bidicontext && bidicontext->deref() ) | 1034 | if ( bidicontext && bidicontext->deref() ) |
1032 | delete bidicontext; | 1035 | delete bidicontext; |
1033 | #endif | 1036 | #endif |
1034 | } | 1037 | } |
1035 | 1038 | ||
1036 | #ifndef QT_NO_COMPLEXTEXT | 1039 | #ifndef QT_NO_COMPLEXTEXT |
1037 | void setContext( QBidiContext *c ) { | 1040 | void setContext( QBidiContext *c ) { |
1038 | if ( c == bidicontext ) | 1041 | if ( c == bidicontext ) |
1039 | return; | 1042 | return; |
1040 | if ( bidicontext && bidicontext->deref() ) | 1043 | if ( bidicontext && bidicontext->deref() ) |
1041 | delete bidicontext; | 1044 | delete bidicontext; |
1042 | bidicontext = c; | 1045 | bidicontext = c; |
1043 | if ( bidicontext ) | 1046 | if ( bidicontext ) |
1044 | bidicontext->ref(); | 1047 | bidicontext->ref(); |
1045 | } | 1048 | } |
1046 | QBidiContext *context() const { return bidicontext; } | 1049 | QBidiContext *context() const { return bidicontext; } |
1047 | #endif | 1050 | #endif |
1048 | 1051 | ||
1049 | public: | 1052 | public: |
1050 | ushort y, baseLine, h; | 1053 | ushort y, baseLine, h; |
1051 | #ifndef QT_NO_COMPLEXTEXT | 1054 | #ifndef QT_NO_COMPLEXTEXT |
1052 | QBidiStatus status; | 1055 | QBidiStatus status; |
1053 | #endif | 1056 | #endif |
1054 | int w; | 1057 | int w; |
1055 | 1058 | ||
1056 | private: | 1059 | private: |
1057 | #ifndef QT_NO_COMPLEXTEXT | 1060 | #ifndef QT_NO_COMPLEXTEXT |
1058 | QBidiContext *bidicontext; | 1061 | QBidiContext *bidicontext; |
1059 | #endif | 1062 | #endif |
1060 | }; | 1063 | }; |
1061 | 1064 | ||
1062 | #if defined(Q_TEMPLATEDLL) | 1065 | #if defined(Q_TEMPLATEDLL) |
1063 | // MOC_SKIP_BEGIN | 1066 | // MOC_SKIP_BEGIN |
1064 | Q_TEMPLATE_EXTERN template class Q_EXPORT QMap<int, QTextParagraphSelection>; | 1067 | Q_TEMPLATE_EXTERN template class Q_EXPORT QMap<int, QTextParagraphSelection>; |
1065 | Q_TEMPLATE_EXTERN template class Q_EXPORT QMap<int, QTextLineStart*>; | 1068 | Q_TEMPLATE_EXTERN template class Q_EXPORT QMap<int, QTextLineStart*>; |
1066 | // MOC_SKIP_END | 1069 | // MOC_SKIP_END |
1067 | #endif | 1070 | #endif |
1068 | 1071 | ||
1069 | class Q_EXPORT QTextParagraphData | 1072 | class Q_EXPORT QTextParagraphData |
1070 | { | 1073 | { |
1071 | public: | 1074 | public: |
1072 | QTextParagraphData() {} | 1075 | QTextParagraphData() {} |
1073 | virtual ~QTextParagraphData(); | 1076 | virtual ~QTextParagraphData(); |
1074 | virtual void join( QTextParagraphData * ); | 1077 | virtual void join( QTextParagraphData * ); |
1075 | }; | 1078 | }; |
1076 | 1079 | ||
1077 | class Q_EXPORT QTextParagraphPseudoDocument | 1080 | class Q_EXPORT QTextParagraphPseudoDocument |
1078 | { | 1081 | { |
1079 | public: | 1082 | public: |
1080 | QTextParagraphPseudoDocument(); | 1083 | QTextParagraphPseudoDocument(); |
1081 | ~QTextParagraphPseudoDocument(); | 1084 | ~QTextParagraphPseudoDocument(); |
1082 | QRect docRect; | 1085 | QRect docRect; |
1083 | QTextFormatter *pFormatter; | 1086 | QTextFormatter *pFormatter; |
1084 | QTextCommandHistory *commandHistory; | 1087 | QTextCommandHistory *commandHistory; |
1085 | int minw; | 1088 | int minw; |
1086 | int wused; | 1089 | int wused; |
1087 | }; | 1090 | }; |
1088 | 1091 | ||
1089 | //nase | 1092 | //nase |
1090 | class Q_EXPORT QTextParagraph | 1093 | class Q_EXPORT QTextParagraph |
1091 | { | 1094 | { |
1092 | friend class QTextDocument; | 1095 | friend class QTextDocument; |
1093 | friend class QTextCursor; | 1096 | friend class QTextCursor; |
1094 | 1097 | ||
1095 | public: | 1098 | public: |
1096 | QTextParagraph( QTextDocument *d, QTextParagraph *pr = 0, QTextParagraph *nx = 0, bool updateIds = TRUE ); | 1099 | QTextParagraph( QTextDocument *d, QTextParagraph *pr = 0, QTextParagraph *nx = 0, bool updateIds = TRUE ); |
1097 | virtual ~QTextParagraph(); | 1100 | virtual ~QTextParagraph(); |
1098 | 1101 | ||
1099 | QTextString *string() const; | 1102 | QTextString *string() const; |
1100 | QTextStringChar *at( int i ) const; // maybe remove later | 1103 | QTextStringChar *at( int i ) const; // maybe remove later |
1101 | int leftGap() const; | 1104 | int leftGap() const; |
1102 | int length() const; // maybe remove later | 1105 | int length() const; // maybe remove later |
1103 | 1106 | ||
1104 | void setListStyle( QStyleSheetItem::ListStyle ls ) { lstyle = ls; changed = TRUE; } | 1107 | void setListStyle( QStyleSheetItem::ListStyle ls ) { lstyle = ls; changed = TRUE; } |
1105 | QStyleSheetItem::ListStyle listStyle() const { return lstyle; } | 1108 | QStyleSheetItem::ListStyle listStyle() const { return lstyle; } |
1106 | void setListItem( bool li ) { litem = li; changed = TRUE; } | 1109 | void setListItem( bool li ) { litem = li; changed = TRUE; } |
1107 | bool isListItem() const { return litem; } | 1110 | bool isListItem() const { return litem; } |
1108 | void setListValue( int v ) { list_val = v; } | 1111 | void setListValue( int v ) { list_val = v; } |
@@ -1122,356 +1125,356 @@ public: | |||
1122 | void show(); | 1125 | void show(); |
1123 | void hide(); | 1126 | void hide(); |
1124 | bool isVisible() const { return visible; } | 1127 | bool isVisible() const { return visible; } |
1125 | 1128 | ||
1126 | QTextParagraph *prev() const; | 1129 | QTextParagraph *prev() const; |
1127 | QTextParagraph *next() const; | 1130 | QTextParagraph *next() const; |
1128 | void setPrev( QTextParagraph *s ); | 1131 | void setPrev( QTextParagraph *s ); |
1129 | void setNext( QTextParagraph *s ); | 1132 | void setNext( QTextParagraph *s ); |
1130 | 1133 | ||
1131 | void insert( int index, const QString &s ); | 1134 | void insert( int index, const QString &s ); |
1132 | void insert( int index, const QChar *unicode, int len ); | 1135 | void insert( int index, const QChar *unicode, int len ); |
1133 | void append( const QString &s, bool reallyAtEnd = FALSE ); | 1136 | void append( const QString &s, bool reallyAtEnd = FALSE ); |
1134 | void truncate( int index ); | 1137 | void truncate( int index ); |
1135 | void remove( int index, int len ); | 1138 | void remove( int index, int len ); |
1136 | void join( QTextParagraph *s ); | 1139 | void join( QTextParagraph *s ); |
1137 | 1140 | ||
1138 | void invalidate( int chr ); | 1141 | void invalidate( int chr ); |
1139 | 1142 | ||
1140 | void move( int &dy ); | 1143 | void move( int &dy ); |
1141 | void format( int start = -1, bool doMove = TRUE ); | 1144 | void format( int start = -1, bool doMove = TRUE ); |
1142 | 1145 | ||
1143 | bool isValid() const; | 1146 | bool isValid() const; |
1144 | bool hasChanged() const; | 1147 | bool hasChanged() const; |
1145 | void setChanged( bool b, bool recursive = FALSE ); | 1148 | void setChanged( bool b, bool recursive = FALSE ); |
1146 | 1149 | ||
1147 | int lineHeightOfChar( int i, int *bl = 0, int *y = 0 ) const; | 1150 | int lineHeightOfChar( int i, int *bl = 0, int *y = 0 ) const; |
1148 | QTextStringChar *lineStartOfChar( int i, int *index = 0, int *line = 0 ) const; | 1151 | QTextStringChar *lineStartOfChar( int i, int *index = 0, int *line = 0 ) const; |
1149 | int lines() const; | 1152 | int lines() const; |
1150 | QTextStringChar *lineStartOfLine( int line, int *index = 0 ) const; | 1153 | QTextStringChar *lineStartOfLine( int line, int *index = 0 ) const; |
1151 | int lineY( int l ) const; | 1154 | int lineY( int l ) const; |
1152 | int lineBaseLine( int l ) const; | 1155 | int lineBaseLine( int l ) const; |
1153 | int lineHeight( int l ) const; | 1156 | int lineHeight( int l ) const; |
1154 | void lineInfo( int l, int &y, int &h, int &bl ) const; | 1157 | void lineInfo( int l, int &y, int &h, int &bl ) const; |
1155 | 1158 | ||
1156 | void setSelection( int id, int start, int end ); | 1159 | void setSelection( int id, int start, int end ); |
1157 | void removeSelection( int id ); | 1160 | void removeSelection( int id ); |
1158 | int selectionStart( int id ) const; | 1161 | int selectionStart( int id ) const; |
1159 | int selectionEnd( int id ) const; | 1162 | int selectionEnd( int id ) const; |
1160 | bool hasSelection( int id ) const; | 1163 | bool hasSelection( int id ) const; |
1161 | bool hasAnySelection() const; | 1164 | bool hasAnySelection() const; |
1162 | bool fullSelected( int id ) const; | 1165 | bool fullSelected( int id ) const; |
1163 | 1166 | ||
1164 | void setEndState( int s ); | 1167 | void setEndState( int s ); |
1165 | int endState() const; | 1168 | int endState() const; |
1166 | 1169 | ||
1167 | void setParagId( int i ); | 1170 | void setParagId( int i ); |
1168 | int paragId() const; | 1171 | int paragId() const; |
1169 | 1172 | ||
1170 | bool firstPreProcess() const; | 1173 | bool firstPreProcess() const; |
1171 | void setFirstPreProcess( bool b ); | 1174 | void setFirstPreProcess( bool b ); |
1172 | 1175 | ||
1173 | void indent( int *oldIndent = 0, int *newIndent = 0 ); | 1176 | void indent( int *oldIndent = 0, int *newIndent = 0 ); |
1174 | 1177 | ||
1175 | void setExtraData( QTextParagraphData *data ); | 1178 | void setExtraData( QTextParagraphData *data ); |
1176 | QTextParagraphData *extraData() const; | 1179 | QTextParagraphData *extraData() const; |
1177 | 1180 | ||
1178 | QMap<int, QTextLineStart*> &lineStartList(); | 1181 | QMap<int, QTextLineStart*> &lineStartList(); |
1179 | 1182 | ||
1180 | void setFormat( int index, int len, QTextFormat *f, bool useCollection = TRUE, int flags = -1 ); | 1183 | void setFormat( int index, int len, QTextFormat *f, bool useCollection = TRUE, int flags = -1 ); |
1181 | 1184 | ||
1182 | void setAlignment( int a ); | 1185 | void setAlignment( int a ); |
1183 | int alignment() const; | 1186 | int alignment() const; |
1184 | 1187 | ||
1185 | virtual void paint( QPainter &painter, const QColorGroup &cg, QTextCursor *cursor = 0, bool drawSelections = FALSE, | 1188 | virtual void paint( QPainter &painter, const QColorGroup &cg, QTextCursor *cursor = 0, bool drawSelections = FALSE, |
1186 | int clipx = -1, int clipy = -1, int clipw = -1, int cliph = -1 ); | 1189 | int clipx = -1, int clipy = -1, int clipw = -1, int cliph = -1 ); |
1187 | 1190 | ||
1188 | virtual int topMargin() const; | 1191 | virtual int topMargin() const; |
1189 | virtual int bottomMargin() const; | 1192 | virtual int bottomMargin() const; |
1190 | virtual int leftMargin() const; | 1193 | virtual int leftMargin() const; |
1191 | virtual int firstLineMargin() const; | 1194 | virtual int firstLineMargin() const; |
1192 | virtual int rightMargin() const; | 1195 | virtual int rightMargin() const; |
1193 | virtual int lineSpacing() const; | 1196 | virtual int lineSpacing() const; |
1194 | 1197 | ||
1195 | void registerFloatingItem( QTextCustomItem *i ); | 1198 | void registerFloatingItem( QTextCustomItem *i ); |
1196 | void unregisterFloatingItem( QTextCustomItem *i ); | 1199 | void unregisterFloatingItem( QTextCustomItem *i ); |
1197 | 1200 | ||
1198 | void setFullWidth( bool b ) { fullWidth = b; } | 1201 | void setFullWidth( bool b ) { fullWidth = b; } |
1199 | bool isFullWidth() const { return fullWidth; } | 1202 | bool isFullWidth() const { return fullWidth; } |
1200 | 1203 | ||
1201 | QTextTableCell *tableCell() const; | 1204 | QTextTableCell *tableCell() const; |
1202 | 1205 | ||
1203 | QBrush *background() const; | 1206 | QBrush *background() const; |
1204 | 1207 | ||
1205 | int documentWidth() const; | 1208 | int documentWidth() const; |
1206 | int documentVisibleWidth() const; | 1209 | int documentVisibleWidth() const; |
1207 | int documentX() const; | 1210 | int documentX() const; |
1208 | int documentY() const; | 1211 | int documentY() const; |
1209 | QTextFormatCollection *formatCollection() const; | 1212 | QTextFormatCollection *formatCollection() const; |
1210 | QTextFormatter *formatter() const; | 1213 | QTextFormatter *formatter() const; |
1211 | 1214 | ||
1212 | virtual int nextTab( int i, int x ); | 1215 | virtual int nextTab( int i, int x ); |
1213 | int *tabArray() const; | 1216 | int *tabArray() const; |
1214 | void setTabArray( int *a ); | 1217 | void setTabArray( int *a ); |
1215 | void setTabStops( int tw ); | 1218 | void setTabStops( int tw ); |
1216 | 1219 | ||
1217 | void adjustToPainter( QPainter *p ); | 1220 | void adjustToPainter( QPainter *p ); |
1218 | 1221 | ||
1219 | void setNewLinesAllowed( bool b ); | 1222 | void setNewLinesAllowed( bool b ); |
1220 | bool isNewLinesAllowed() const; | 1223 | bool isNewLinesAllowed() const; |
1221 | 1224 | ||
1222 | QString richText() const; | 1225 | QString richText() const; |
1223 | 1226 | ||
1224 | void addCommand( QTextCommand *cmd ); | 1227 | void addCommand( QTextCommand *cmd ); |
1225 | QTextCursor *undo( QTextCursor *c = 0 ); | 1228 | QTextCursor *undo( QTextCursor *c = 0 ); |
1226 | QTextCursor *redo( QTextCursor *c = 0 ); | 1229 | QTextCursor *redo( QTextCursor *c = 0 ); |
1227 | QTextCommandHistory *commands() const; | 1230 | QTextCommandHistory *commands() const; |
1228 | virtual void copyParagData( QTextParagraph *parag ); | 1231 | virtual void copyParagData( QTextParagraph *parag ); |
1229 | 1232 | ||
1230 | void setBreakable( bool b ) { breakable = b; } | 1233 | void setBreakable( bool b ) { breakable = b; } |
1231 | bool isBreakable() const { return breakable; } | 1234 | bool isBreakable() const { return breakable; } |
1232 | 1235 | ||
1233 | void setBackgroundColor( const QColor &c ); | 1236 | void setBackgroundColor( const QColor &c ); |
1234 | QColor *backgroundColor() const { return bgcol; } | 1237 | QColor *backgroundColor() const { return bgcol; } |
1235 | void clearBackgroundColor(); | 1238 | void clearBackgroundColor(); |
1236 | 1239 | ||
1237 | void setMovedDown( bool b ) { movedDown = b; } | 1240 | void setMovedDown( bool b ) { movedDown = b; } |
1238 | bool wasMovedDown() const { return movedDown; } | 1241 | bool wasMovedDown() const { return movedDown; } |
1239 | 1242 | ||
1240 | void setDirection( QChar::Direction d ); | 1243 | void setDirection( QChar::Direction d ); |
1241 | QChar::Direction direction() const; | 1244 | QChar::Direction direction() const; |
1242 | 1245 | ||
1243 | void readStyleInformation( QDataStream& stream ); | 1246 | void readStyleInformation( QDataStream& stream ); |
1244 | void writeStyleInformation( QDataStream& stream ) const; | 1247 | void writeStyleInformation( QDataStream& stream ) const; |
1245 | 1248 | ||
1246 | protected: | 1249 | protected: |
1247 | virtual void drawLabel( QPainter* p, int x, int y, int w, int h, int base, const QColorGroup& cg ); | 1250 | virtual void drawLabel( QPainter* p, int x, int y, int w, int h, int base, const QColorGroup& cg ); |
1248 | virtual void drawString( QPainter &painter, const QString &str, int start, int len, int xstart, | 1251 | virtual void drawString( QPainter &painter, const QString &str, int start, int len, int xstart, |
1249 | int y, int baseLine, int w, int h, int selection, | 1252 | int y, int baseLine, int w, int h, int selection, |
1250 | QTextStringChar *formatChar, const QColorGroup& cg, | 1253 | QTextStringChar *formatChar, const QColorGroup& cg, |
1251 | bool rightToLeft ); | 1254 | bool rightToLeft ); |
1252 | 1255 | ||
1253 | private: | 1256 | private: |
1254 | QMap<int, QTextParagraphSelection> &selections() const; | 1257 | QMap<int, QTextParagraphSelection> &selections() const; |
1255 | QPtrList<QTextCustomItem> &floatingItems() const; | 1258 | QPtrList<QTextCustomItem> &floatingItems() const; |
1256 | QBrush backgroundBrush( const QColorGroup&cg ) { if ( bgcol ) return *bgcol; return cg.brush( QColorGroup::Base ); } | 1259 | QBrush backgroundBrush( const QColorGroup&cg ) { if ( bgcol ) return *bgcol; return cg.brush( QColorGroup::Base ); } |
1257 | void invalidateStyleCache(); | 1260 | void invalidateStyleCache(); |
1258 | 1261 | ||
1259 | QMap<int, QTextLineStart*> lineStarts; | 1262 | QMap<int, QTextLineStart*> lineStarts; |
1260 | int invalid; | 1263 | int invalid; |
1261 | QRect r; | 1264 | QRect r; |
1262 | QTextParagraph *p, *n; | 1265 | QTextParagraph *p, *n; |
1263 | void *docOrPseudo; | 1266 | void *docOrPseudo; |
1264 | uint changed : 1; | 1267 | uint changed : 1; |
1265 | uint firstFormat : 1; | 1268 | uint firstFormat : 1; |
1266 | uint firstPProcess : 1; | 1269 | uint firstPProcess : 1; |
1267 | uint needPreProcess : 1; | 1270 | uint needPreProcess : 1; |
1268 | uint fullWidth : 1; | 1271 | uint fullWidth : 1; |
1269 | uint lastInFrame : 1; | 1272 | uint lastInFrame : 1; |
1270 | uint visible : 1; | 1273 | uint visible : 1; |
1271 | uint breakable : 1; | 1274 | uint breakable : 1; |
1272 | uint movedDown : 1; | 1275 | uint movedDown : 1; |
1273 | uint mightHaveCustomItems : 1; | 1276 | uint mightHaveCustomItems : 1; |
1274 | uint hasdoc : 1; | 1277 | uint hasdoc : 1; |
1275 | uint litem : 1; // whether the paragraph is a list item | 1278 | uint litem : 1; // whether the paragraph is a list item |
1276 | uint rtext : 1; // whether the paragraph needs rich text margin | 1279 | uint rtext : 1; // whether the paragraph needs rich text margin |
1277 | int align : 4; | 1280 | int align : 4; |
1278 | int state, id; | 1281 | int state, id; |
1279 | QTextString *str; | 1282 | QTextString *str; |
1280 | QMap<int, QTextParagraphSelection> *mSelections; | 1283 | QMap<int, QTextParagraphSelection> *mSelections; |
1281 | QPtrList<QTextCustomItem> *mFloatingItems; | 1284 | QPtrList<QTextCustomItem> *mFloatingItems; |
1282 | QStyleSheetItem::ListStyle lstyle; | 1285 | QStyleSheetItem::ListStyle lstyle; |
1283 | short utm, ubm, ulm, urm, uflm, ulinespacing; | 1286 | short utm, ubm, ulm, urm, uflm, ulinespacing; |
1284 | int *tArray; | 1287 | int *tArray; |
1285 | short tabStopWidth; | 1288 | short tabStopWidth; |
1286 | QTextParagraphData *eData; | 1289 | QTextParagraphData *eData; |
1287 | short list_val; | 1290 | short list_val; |
1288 | QColor *bgcol; | 1291 | QColor *bgcol; |
1289 | ushort ldepth; | 1292 | ushort ldepth; |
1290 | 1293 | ||
1291 | }; | 1294 | }; |
1292 | 1295 | ||
1293 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | 1296 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1294 | 1297 | ||
1295 | class Q_EXPORT QTextFormatter | 1298 | class Q_EXPORT QTextFormatter |
1296 | { | 1299 | { |
1297 | public: | 1300 | public: |
1298 | QTextFormatter(); | 1301 | QTextFormatter(); |
1299 | virtual ~QTextFormatter(); | 1302 | virtual ~QTextFormatter(); |
1300 | 1303 | ||
1301 | virtual int format( QTextDocument *doc, QTextParagraph *parag, int start, const QMap<int, QTextLineStart*> &oldLineStarts ) = 0; | 1304 | virtual int format( QTextDocument *doc, QTextParagraph *parag, int start, const QMap<int, QTextLineStart*> &oldLineStarts ) = 0; |
1302 | virtual int formatVertically( QTextDocument* doc, QTextParagraph* parag ); | 1305 | virtual int formatVertically( QTextDocument* doc, QTextParagraph* parag ); |
1303 | 1306 | ||
1304 | bool isWrapEnabled( QTextParagraph *p ) const { if ( !wrapEnabled ) return FALSE; if ( p && !p->isBreakable() ) return FALSE; return TRUE;} | 1307 | bool isWrapEnabled( QTextParagraph *p ) const { if ( !wrapEnabled ) return FALSE; if ( p && !p->isBreakable() ) return FALSE; return TRUE;} |
1305 | int wrapAtColumn() const { return wrapColumn;} | 1308 | int wrapAtColumn() const { return wrapColumn;} |
1306 | virtual void setWrapEnabled( bool b ); | 1309 | virtual void setWrapEnabled( bool b ); |
1307 | virtual void setWrapAtColumn( int c ); | 1310 | virtual void setWrapAtColumn( int c ); |
1308 | virtual void setAllowBreakInWords( bool b ) { biw = b; } | 1311 | virtual void setAllowBreakInWords( bool b ) { biw = b; } |
1309 | bool allowBreakInWords() const { return biw; } | 1312 | bool allowBreakInWords() const { return biw; } |
1310 | 1313 | ||
1311 | int minimumWidth() const { return thisminw; } | 1314 | int minimumWidth() const { return thisminw; } |
1312 | int widthUsed() const { return thiswused; } | 1315 | int widthUsed() const { return thiswused; } |
1313 | 1316 | ||
1314 | static bool isBreakable( QTextString *string, int pos ); | 1317 | static bool isBreakable( QTextString *string, int pos ); |
1315 | 1318 | ||
1316 | protected: | 1319 | protected: |
1317 | virtual QTextLineStart *formatLine( QTextParagraph *parag, QTextString *string, QTextLineStart *line, QTextStringChar *start, | 1320 | virtual QTextLineStart *formatLine( QTextParagraph *parag, QTextString *string, QTextLineStart *line, QTextStringChar *start, |
1318 | QTextStringChar *last, int align = Qt3::AlignAuto, int space = 0 ); | 1321 | QTextStringChar *last, int align = Qt3::AlignAuto, int space = 0 ); |
1319 | #ifndef QT_NO_COMPLEXTEXT | 1322 | #ifndef QT_NO_COMPLEXTEXT |
1320 | virtual QTextLineStart *bidiReorderLine( QTextParagraph *parag, QTextString *string, QTextLineStart *line, QTextStringChar *start, | 1323 | virtual QTextLineStart *bidiReorderLine( QTextParagraph *parag, QTextString *string, QTextLineStart *line, QTextStringChar *start, |
1321 | QTextStringChar *last, int align, int space ); | 1324 | QTextStringChar *last, int align, int space ); |
1322 | #endif | 1325 | #endif |
1323 | void insertLineStart( QTextParagraph *parag, int index, QTextLineStart *ls ); | 1326 | void insertLineStart( QTextParagraph *parag, int index, QTextLineStart *ls ); |
1324 | 1327 | ||
1325 | int thisminw; | 1328 | int thisminw; |
1326 | int thiswused; | 1329 | int thiswused; |
1327 | 1330 | ||
1328 | private: | 1331 | private: |
1329 | bool wrapEnabled; | 1332 | bool wrapEnabled; |
1330 | int wrapColumn; | 1333 | int wrapColumn; |
1331 | bool biw; | 1334 | bool biw; |
1332 | 1335 | ||
1333 | #ifdef HAVE_THAI_BREAKS | 1336 | #ifdef HAVE_THAI_BREAKS |
1334 | static QCString *thaiCache; | 1337 | static QCString *thaiCache; |
1335 | static QTextString *cachedString; | 1338 | static QTextString *cachedString; |
1336 | static ThBreakIterator *thaiIt; | 1339 | static ThBreakIterator *thaiIt; |
1337 | #endif | 1340 | #endif |
1338 | }; | 1341 | }; |
1339 | 1342 | ||
1340 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | 1343 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1341 | 1344 | ||
1342 | class Q_EXPORT QTextFormatterBreakInWords : public QTextFormatter | 1345 | class Q_EXPORT QTextFormatterBreakInWords : public QTextFormatter |
1343 | { | 1346 | { |
1344 | public: | 1347 | public: |
1345 | QTextFormatterBreakInWords(); | 1348 | QTextFormatterBreakInWords(); |
1346 | virtual ~QTextFormatterBreakInWords() {} | 1349 | virtual ~QTextFormatterBreakInWords() {} |
1347 | 1350 | ||
1348 | int format( QTextDocument *doc, QTextParagraph *parag, int start, const QMap<int, QTextLineStart*> &oldLineStarts ); | 1351 | int format( QTextDocument *doc, QTextParagraph *parag, int start, const QMap<int, QTextLineStart*> &oldLineStarts ); |
1349 | 1352 | ||
1350 | }; | 1353 | }; |
1351 | 1354 | ||
1352 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | 1355 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1353 | 1356 | ||
1354 | class Q_EXPORT QTextFormatterBreakWords : public QTextFormatter | 1357 | class Q_EXPORT QTextFormatterBreakWords : public QTextFormatter |
1355 | { | 1358 | { |
1356 | public: | 1359 | public: |
1357 | QTextFormatterBreakWords(); | 1360 | QTextFormatterBreakWords(); |
1358 | virtual ~QTextFormatterBreakWords() {} | 1361 | virtual ~QTextFormatterBreakWords() {} |
1359 | 1362 | ||
1360 | int format( QTextDocument *doc, QTextParagraph *parag, int start, const QMap<int, QTextLineStart*> &oldLineStarts ); | 1363 | int format( QTextDocument *doc, QTextParagraph *parag, int start, const QMap<int, QTextLineStart*> &oldLineStarts ); |
1361 | 1364 | ||
1362 | }; | 1365 | }; |
1363 | 1366 | ||
1364 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | 1367 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1365 | 1368 | ||
1366 | class Q_EXPORT QTextIndent | 1369 | class Q_EXPORT QTextIndent |
1367 | { | 1370 | { |
1368 | public: | 1371 | public: |
1369 | QTextIndent(); | 1372 | QTextIndent(); |
1370 | virtual ~QTextIndent() {} | 1373 | virtual ~QTextIndent() {} |
1371 | 1374 | ||
1372 | virtual void indent( QTextDocument *doc, QTextParagraph *parag, int *oldIndent = 0, int *newIndent = 0 ) = 0; | 1375 | virtual void indent( QTextDocument *doc, QTextParagraph *parag, int *oldIndent = 0, int *newIndent = 0 ) = 0; |
1373 | 1376 | ||
1374 | }; | 1377 | }; |
1375 | 1378 | ||
1376 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | 1379 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1377 | 1380 | ||
1378 | class Q_EXPORT QTextPreProcessor | 1381 | class Q_EXPORT QTextPreProcessor |
1379 | { | 1382 | { |
1380 | public: | 1383 | public: |
1381 | enum Ids { | 1384 | enum Ids { |
1382 | Standard = 0 | 1385 | Standard = 0 |
1383 | }; | 1386 | }; |
1384 | 1387 | ||
1385 | QTextPreProcessor(); | 1388 | QTextPreProcessor(); |
1386 | virtual ~QTextPreProcessor() {} | 1389 | virtual ~QTextPreProcessor() {} |
1387 | 1390 | ||
1388 | virtual void process( QTextDocument *doc, QTextParagraph *, int, bool = TRUE ) = 0; | 1391 | virtual void process( QTextDocument *doc, QTextParagraph *, int, bool = TRUE ) = 0; |
1389 | virtual QTextFormat *format( int id ) = 0; | 1392 | virtual QTextFormat *format( int id ) = 0; |
1390 | 1393 | ||
1391 | }; | 1394 | }; |
1392 | 1395 | ||
1393 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | 1396 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1394 | 1397 | ||
1395 | class Q_EXPORT QTextFormat | 1398 | class Q_EXPORT QTextFormat |
1396 | { | 1399 | { |
1397 | friend class QTextFormatCollection; | 1400 | friend class QTextFormatCollection; |
1398 | friend class QTextDocument; | 1401 | friend class QTextDocument; |
1399 | 1402 | ||
1400 | public: | 1403 | public: |
1401 | enum Flags { | 1404 | enum Flags { |
1402 | NoFlags, | 1405 | NoFlags, |
1403 | Bold = 1, | 1406 | Bold = 1, |
1404 | Italic = 2, | 1407 | Italic = 2, |
1405 | Underline = 4, | 1408 | Underline = 4, |
1406 | Family = 8, | 1409 | Family = 8, |
1407 | Size = 16, | 1410 | Size = 16, |
1408 | Color = 32, | 1411 | Color = 32, |
1409 | Misspelled = 64, | 1412 | Misspelled = 64, |
1410 | VAlign = 128, | 1413 | VAlign = 128, |
1411 | StrikeOut= 256, | 1414 | StrikeOut= 256, |
1412 | Font = Bold | Italic | Underline | Family | Size | StrikeOut, | 1415 | Font = Bold | Italic | Underline | Family | Size | StrikeOut, |
1413 | Format = Font | Color | Misspelled | VAlign | 1416 | Format = Font | Color | Misspelled | VAlign |
1414 | }; | 1417 | }; |
1415 | 1418 | ||
1416 | enum VerticalAlignment { AlignNormal, AlignSuperScript, AlignSubScript }; | 1419 | enum VerticalAlignment { AlignNormal, AlignSuperScript, AlignSubScript }; |
1417 | 1420 | ||
1418 | QTextFormat(); | 1421 | QTextFormat(); |
1419 | virtual ~QTextFormat(); | 1422 | virtual ~QTextFormat(); |
1420 | 1423 | ||
1421 | QTextFormat( const QStyleSheetItem *s ); | 1424 | QTextFormat( const QStyleSheetItem *s ); |
1422 | QTextFormat( const QFont &f, const QColor &c, QTextFormatCollection *parent = 0 ); | 1425 | QTextFormat( const QFont &f, const QColor &c, QTextFormatCollection *parent = 0 ); |
1423 | QTextFormat( const QTextFormat &fm ); | 1426 | QTextFormat( const QTextFormat &fm ); |
1424 | QTextFormat makeTextFormat( const QStyleSheetItem *style, const QMap<QString,QString>& attr, double scaleFontsFactor ) const; | 1427 | QTextFormat makeTextFormat( const QStyleSheetItem *style, const QMap<QString,QString>& attr, double scaleFontsFactor ) const; |
1425 | QTextFormat& operator=( const QTextFormat &fm ); | 1428 | QTextFormat& operator=( const QTextFormat &fm ); |
1426 | QColor color() const; | 1429 | QColor color() const; |
1427 | QFont font() const; | 1430 | QFont font() const; |
1428 | bool isMisspelled() const; | 1431 | bool isMisspelled() const; |
1429 | VerticalAlignment vAlign() const; | 1432 | VerticalAlignment vAlign() const; |
1430 | int minLeftBearing() const; | 1433 | int minLeftBearing() const; |
1431 | int minRightBearing() const; | 1434 | int minRightBearing() const; |
1432 | int width( const QChar &c ) const; | 1435 | int width( const QChar &c ) const; |
1433 | int width( const QString &str, int pos ) const; | 1436 | int width( const QString &str, int pos ) const; |
1434 | int height() const; | 1437 | int height() const; |
1435 | int ascent() const; | 1438 | int ascent() const; |
1436 | int descent() const; | 1439 | int descent() const; |
1437 | int leading() const; | 1440 | int leading() const; |
1438 | bool useLinkColor() const; | 1441 | bool useLinkColor() const; |
1439 | 1442 | ||
1440 | void setBold( bool b ); | 1443 | void setBold( bool b ); |
1441 | void setItalic( bool b ); | 1444 | void setItalic( bool b ); |
1442 | void setUnderline( bool b ); | 1445 | void setUnderline( bool b ); |
1443 | void setStrikeOut( bool b ); | 1446 | void setStrikeOut( bool b ); |
1444 | void setFamily( const QString &f ); | 1447 | void setFamily( const QString &f ); |
1445 | void setPointSize( int s ); | 1448 | void setPointSize( int s ); |
1446 | void setFont( const QFont &f ); | 1449 | void setFont( const QFont &f ); |
1447 | void setColor( const QColor &c ); | 1450 | void setColor( const QColor &c ); |
1448 | void setMisspelled( bool b ); | 1451 | void setMisspelled( bool b ); |
1449 | void setVAlign( VerticalAlignment a ); | 1452 | void setVAlign( VerticalAlignment a ); |
1450 | 1453 | ||
1451 | bool operator==( const QTextFormat &f ) const; | 1454 | bool operator==( const QTextFormat &f ) const; |
1452 | QTextFormatCollection *parent() const; | 1455 | QTextFormatCollection *parent() const; |
1453 | QString key() const; | 1456 | QString key() const; |
1454 | 1457 | ||
1455 | static QString getKey( const QFont &f, const QColor &c, bool misspelled, VerticalAlignment vAlign ); | 1458 | static QString getKey( const QFont &f, const QColor &c, bool misspelled, VerticalAlignment vAlign ); |
1456 | 1459 | ||
1457 | void addRef(); | 1460 | void addRef(); |
1458 | void removeRef(); | 1461 | void removeRef(); |
1459 | 1462 | ||
1460 | QString makeFormatChangeTags( QTextFormat* defaultFormat, QTextFormat *f, const QString& oldAnchorHref, const QString& anchorHref ) const; | 1463 | QString makeFormatChangeTags( QTextFormat* defaultFormat, QTextFormat *f, const QString& oldAnchorHref, const QString& anchorHref ) const; |
1461 | QString makeFormatEndTags( QTextFormat* defaultFormat, const QString& anchorHref ) const; | 1464 | QString makeFormatEndTags( QTextFormat* defaultFormat, const QString& anchorHref ) const; |
1462 | 1465 | ||
1463 | static void setPainter( QPainter *p ); | 1466 | static void setPainter( QPainter *p ); |
1464 | static QPainter* painter(); | 1467 | static QPainter* painter(); |
1465 | 1468 | ||
1466 | bool fontSizesInPixels() { return usePixelSizes; } | 1469 | bool fontSizesInPixels() { return usePixelSizes; } |
1467 | 1470 | ||
1468 | protected: | 1471 | protected: |
1469 | virtual void generateKey(); | 1472 | virtual void generateKey(); |
1470 | 1473 | ||
1471 | private: | 1474 | private: |
1472 | void update(); | 1475 | void update(); |
1473 | 1476 | ||
1474 | private: | 1477 | private: |
1475 | QFont fn; | 1478 | QFont fn; |
1476 | QColor col; | 1479 | QColor col; |
1477 | QFontMetrics fm; | 1480 | QFontMetrics fm; |
@@ -1668,317 +1671,317 @@ inline void QTextDocument::setIndent( QTextIndent *i ) | |||
1668 | 1671 | ||
1669 | inline QTextIndent *QTextDocument::indent() const | 1672 | inline QTextIndent *QTextDocument::indent() const |
1670 | { | 1673 | { |
1671 | return indenter; | 1674 | return indenter; |
1672 | } | 1675 | } |
1673 | 1676 | ||
1674 | inline QColor QTextDocument::selectionColor( int id ) const | 1677 | inline QColor QTextDocument::selectionColor( int id ) const |
1675 | { | 1678 | { |
1676 | return selectionColors[ id ]; | 1679 | return selectionColors[ id ]; |
1677 | } | 1680 | } |
1678 | 1681 | ||
1679 | inline bool QTextDocument::invertSelectionText( int id ) const | 1682 | inline bool QTextDocument::invertSelectionText( int id ) const |
1680 | { | 1683 | { |
1681 | return selectionText[ id ]; | 1684 | return selectionText[ id ]; |
1682 | } | 1685 | } |
1683 | 1686 | ||
1684 | inline void QTextDocument::setSelectionColor( int id, const QColor &c ) | 1687 | inline void QTextDocument::setSelectionColor( int id, const QColor &c ) |
1685 | { | 1688 | { |
1686 | selectionColors[ id ] = c; | 1689 | selectionColors[ id ] = c; |
1687 | } | 1690 | } |
1688 | 1691 | ||
1689 | inline void QTextDocument::setInvertSelectionText( int id, bool b ) | 1692 | inline void QTextDocument::setInvertSelectionText( int id, bool b ) |
1690 | { | 1693 | { |
1691 | selectionText[ id ] = b; | 1694 | selectionText[ id ] = b; |
1692 | } | 1695 | } |
1693 | 1696 | ||
1694 | inline QTextFormatCollection *QTextDocument::formatCollection() const | 1697 | inline QTextFormatCollection *QTextDocument::formatCollection() const |
1695 | { | 1698 | { |
1696 | return fCollection; | 1699 | return fCollection; |
1697 | } | 1700 | } |
1698 | 1701 | ||
1699 | inline int QTextDocument::alignment() const | 1702 | inline int QTextDocument::alignment() const |
1700 | { | 1703 | { |
1701 | return align; | 1704 | return align; |
1702 | } | 1705 | } |
1703 | 1706 | ||
1704 | inline void QTextDocument::setAlignment( int a ) | 1707 | inline void QTextDocument::setAlignment( int a ) |
1705 | { | 1708 | { |
1706 | align = a; | 1709 | align = a; |
1707 | } | 1710 | } |
1708 | 1711 | ||
1709 | inline int *QTextDocument::tabArray() const | 1712 | inline int *QTextDocument::tabArray() const |
1710 | { | 1713 | { |
1711 | return tArray; | 1714 | return tArray; |
1712 | } | 1715 | } |
1713 | 1716 | ||
1714 | inline int QTextDocument::tabStopWidth() const | 1717 | inline int QTextDocument::tabStopWidth() const |
1715 | { | 1718 | { |
1716 | return tStopWidth; | 1719 | return tStopWidth; |
1717 | } | 1720 | } |
1718 | 1721 | ||
1719 | inline void QTextDocument::setTabArray( int *a ) | 1722 | inline void QTextDocument::setTabArray( int *a ) |
1720 | { | 1723 | { |
1721 | tArray = a; | 1724 | tArray = a; |
1722 | } | 1725 | } |
1723 | 1726 | ||
1724 | inline void QTextDocument::setTabStops( int tw ) | 1727 | inline void QTextDocument::setTabStops( int tw ) |
1725 | { | 1728 | { |
1726 | tStopWidth = tw; | 1729 | tStopWidth = tw; |
1727 | } | 1730 | } |
1728 | 1731 | ||
1729 | inline QString QTextDocument::originalText() const | 1732 | inline QString QTextDocument::originalText() const |
1730 | { | 1733 | { |
1731 | if ( oTextValid ) | 1734 | if ( oTextValid ) |
1732 | return oText; | 1735 | return oText; |
1733 | return text(); | 1736 | return text(); |
1734 | } | 1737 | } |
1735 | 1738 | ||
1736 | inline void QTextDocument::setFlow( QTextFlow *f ) | 1739 | inline void QTextDocument::setFlow( QTextFlow *f ) |
1737 | { | 1740 | { |
1738 | if ( flow_ ) | 1741 | if ( flow_ ) |
1739 | delete flow_; | 1742 | delete flow_; |
1740 | flow_ = f; | 1743 | flow_ = f; |
1741 | } | 1744 | } |
1742 | 1745 | ||
1743 | inline void QTextDocument::takeFlow() | 1746 | inline void QTextDocument::takeFlow() |
1744 | { | 1747 | { |
1745 | flow_ = 0; | 1748 | flow_ = 0; |
1746 | } | 1749 | } |
1747 | 1750 | ||
1748 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | 1751 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1749 | 1752 | ||
1750 | inline QColor QTextFormat::color() const | 1753 | inline QColor QTextFormat::color() const |
1751 | { | 1754 | { |
1752 | return col; | 1755 | return col; |
1753 | } | 1756 | } |
1754 | 1757 | ||
1755 | inline QFont QTextFormat::font() const | 1758 | inline QFont QTextFormat::font() const |
1756 | { | 1759 | { |
1757 | return fn; | 1760 | return fn; |
1758 | } | 1761 | } |
1759 | 1762 | ||
1760 | inline bool QTextFormat::isMisspelled() const | 1763 | inline bool QTextFormat::isMisspelled() const |
1761 | { | 1764 | { |
1762 | return missp; | 1765 | return missp; |
1763 | } | 1766 | } |
1764 | 1767 | ||
1765 | inline QTextFormat::VerticalAlignment QTextFormat::vAlign() const | 1768 | inline QTextFormat::VerticalAlignment QTextFormat::vAlign() const |
1766 | { | 1769 | { |
1767 | return ha; | 1770 | return ha; |
1768 | } | 1771 | } |
1769 | 1772 | ||
1770 | inline bool QTextFormat::operator==( const QTextFormat &f ) const | 1773 | inline bool QTextFormat::operator==( const QTextFormat &f ) const |
1771 | { | 1774 | { |
1772 | return k == f.k; | 1775 | return k == f.k; |
1773 | } | 1776 | } |
1774 | 1777 | ||
1775 | inline QTextFormatCollection *QTextFormat::parent() const | 1778 | inline QTextFormatCollection *QTextFormat::parent() const |
1776 | { | 1779 | { |
1777 | return collection; | 1780 | return collection; |
1778 | } | 1781 | } |
1779 | 1782 | ||
1780 | inline void QTextFormat::addRef() | 1783 | inline void QTextFormat::addRef() |
1781 | { | 1784 | { |
1782 | ref++; | 1785 | ref++; |
1783 | } | 1786 | } |
1784 | 1787 | ||
1785 | inline void QTextFormat::removeRef() | 1788 | inline void QTextFormat::removeRef() |
1786 | { | 1789 | { |
1787 | ref--; | 1790 | ref--; |
1788 | if ( !collection ) | 1791 | if ( !collection ) |
1789 | return; | 1792 | return; |
1790 | if ( this == collection->defFormat ) | 1793 | if ( this == collection->defFormat ) |
1791 | return; | 1794 | return; |
1792 | if ( ref == 0 ) | 1795 | if ( ref == 0 ) |
1793 | collection->remove( this ); | 1796 | collection->remove( this ); |
1794 | } | 1797 | } |
1795 | 1798 | ||
1796 | inline QString QTextFormat::key() const | 1799 | inline QString QTextFormat::key() const |
1797 | { | 1800 | { |
1798 | return k; | 1801 | return k; |
1799 | } | 1802 | } |
1800 | 1803 | ||
1801 | inline bool QTextFormat::useLinkColor() const | 1804 | inline bool QTextFormat::useLinkColor() const |
1802 | { | 1805 | { |
1803 | return linkColor; | 1806 | return linkColor; |
1804 | } | 1807 | } |
1805 | 1808 | ||
1806 | 1809 | ||
1807 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | 1810 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1808 | 1811 | ||
1809 | inline QTextStringChar &QTextString::at( int i ) const | 1812 | inline QTextStringChar &QTextString::at( int i ) const |
1810 | { | 1813 | { |
1811 | return data[ i ]; | 1814 | return data[ i ]; |
1812 | } | 1815 | } |
1813 | 1816 | ||
1814 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | 1817 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1815 | 1818 | ||
1816 | inline QTextStringChar *QTextParagraph::at( int i ) const | 1819 | inline QTextStringChar *QTextParagraph::at( int i ) const |
1817 | { | 1820 | { |
1818 | return &str->at( i ); | 1821 | return &str->at( i ); |
1819 | } | 1822 | } |
1820 | 1823 | ||
1821 | inline bool QTextParagraph::isValid() const | 1824 | inline bool QTextParagraph::isValid() const |
1822 | { | 1825 | { |
1823 | return invalid == -1; | 1826 | return invalid == -1; |
1824 | } | 1827 | } |
1825 | 1828 | ||
1826 | inline bool QTextParagraph::hasChanged() const | 1829 | inline bool QTextParagraph::hasChanged() const |
1827 | { | 1830 | { |
1828 | return changed; | 1831 | return changed; |
1829 | } | 1832 | } |
1830 | 1833 | ||
1831 | inline void QTextParagraph::setBackgroundColor( const QColor & c ) | 1834 | inline void QTextParagraph::setBackgroundColor( const QColor & c ) |
1832 | { | 1835 | { |
1833 | delete bgcol; | 1836 | delete bgcol; |
1834 | bgcol = new QColor( c ); | 1837 | bgcol = new QColor( c ); |
1835 | setChanged( TRUE ); | 1838 | setChanged( TRUE ); |
1836 | } | 1839 | } |
1837 | 1840 | ||
1838 | inline void QTextParagraph::clearBackgroundColor() | 1841 | inline void QTextParagraph::clearBackgroundColor() |
1839 | { | 1842 | { |
1840 | delete bgcol; bgcol = 0; setChanged( TRUE ); | 1843 | delete bgcol; bgcol = 0; setChanged( TRUE ); |
1841 | } | 1844 | } |
1842 | 1845 | ||
1843 | inline void QTextParagraph::append( const QString &s, bool reallyAtEnd ) | 1846 | inline void QTextParagraph::append( const QString &s, bool reallyAtEnd ) |
1844 | { | 1847 | { |
1845 | if ( reallyAtEnd ) | 1848 | if ( reallyAtEnd ) |
1846 | insert( str->length(), s ); | 1849 | insert( str->length(), s ); |
1847 | else | 1850 | else |
1848 | insert( QMAX( str->length() - 1, 0 ), s ); | 1851 | insert( QMAX( str->length() - 1, 0 ), s ); |
1849 | } | 1852 | } |
1850 | 1853 | ||
1851 | inline QTextParagraph *QTextParagraph::prev() const | 1854 | inline QTextParagraph *QTextParagraph::prev() const |
1852 | { | 1855 | { |
1853 | return p; | 1856 | return p; |
1854 | } | 1857 | } |
1855 | 1858 | ||
1856 | inline QTextParagraph *QTextParagraph::next() const | 1859 | inline QTextParagraph *QTextParagraph::next() const |
1857 | { | 1860 | { |
1858 | return n; | 1861 | return n; |
1859 | } | 1862 | } |
1860 | 1863 | ||
1861 | inline bool QTextParagraph::hasAnySelection() const | 1864 | inline bool QTextParagraph::hasAnySelection() const |
1862 | { | 1865 | { |
1863 | return mSelections ? !selections().isEmpty() : FALSE; | 1866 | return mSelections ? !selections().isEmpty() : FALSE; |
1864 | } | 1867 | } |
1865 | 1868 | ||
1866 | inline void QTextParagraph::setEndState( int s ) | 1869 | inline void QTextParagraph::setEndState( int s ) |
1867 | { | 1870 | { |
1868 | if ( s == state ) | 1871 | if ( s == state ) |
1869 | return; | 1872 | return; |
1870 | state = s; | 1873 | state = s; |
1871 | } | 1874 | } |
1872 | 1875 | ||
1873 | inline int QTextParagraph::endState() const | 1876 | inline int QTextParagraph::endState() const |
1874 | { | 1877 | { |
1875 | return state; | 1878 | return state; |
1876 | } | 1879 | } |
1877 | 1880 | ||
1878 | inline void QTextParagraph::setParagId( int i ) | 1881 | inline void QTextParagraph::setParagId( int i ) |
1879 | { | 1882 | { |
1880 | id = i; | 1883 | id = i; |
1881 | } | 1884 | } |
1882 | 1885 | ||
1883 | inline int QTextParagraph::paragId() const | 1886 | inline int QTextParagraph::paragId() const |
1884 | { | 1887 | { |
1885 | if ( id == -1 ) | 1888 | if ( id == -1 ) |
1886 | qWarning( "invalid parag id!!!!!!!! (%p)", (void*)this ); | 1889 | owarn << "invalid parag id!!!!!!!! (" << (void*)this << ")" << oendl; |
1887 | return id; | 1890 | return id; |
1888 | } | 1891 | } |
1889 | 1892 | ||
1890 | inline bool QTextParagraph::firstPreProcess() const | 1893 | inline bool QTextParagraph::firstPreProcess() const |
1891 | { | 1894 | { |
1892 | return firstPProcess; | 1895 | return firstPProcess; |
1893 | } | 1896 | } |
1894 | 1897 | ||
1895 | inline void QTextParagraph::setFirstPreProcess( bool b ) | 1898 | inline void QTextParagraph::setFirstPreProcess( bool b ) |
1896 | { | 1899 | { |
1897 | firstPProcess = b; | 1900 | firstPProcess = b; |
1898 | } | 1901 | } |
1899 | 1902 | ||
1900 | inline QMap<int, QTextLineStart*> &QTextParagraph::lineStartList() | 1903 | inline QMap<int, QTextLineStart*> &QTextParagraph::lineStartList() |
1901 | { | 1904 | { |
1902 | return lineStarts; | 1905 | return lineStarts; |
1903 | } | 1906 | } |
1904 | 1907 | ||
1905 | inline QTextString *QTextParagraph::string() const | 1908 | inline QTextString *QTextParagraph::string() const |
1906 | { | 1909 | { |
1907 | return str; | 1910 | return str; |
1908 | } | 1911 | } |
1909 | 1912 | ||
1910 | inline QTextDocument *QTextParagraph::document() const | 1913 | inline QTextDocument *QTextParagraph::document() const |
1911 | { | 1914 | { |
1912 | if ( hasdoc ) | 1915 | if ( hasdoc ) |
1913 | return (QTextDocument*) docOrPseudo; | 1916 | return (QTextDocument*) docOrPseudo; |
1914 | return 0; | 1917 | return 0; |
1915 | } | 1918 | } |
1916 | 1919 | ||
1917 | inline QTextParagraphPseudoDocument *QTextParagraph::pseudoDocument() const | 1920 | inline QTextParagraphPseudoDocument *QTextParagraph::pseudoDocument() const |
1918 | { | 1921 | { |
1919 | if ( hasdoc ) | 1922 | if ( hasdoc ) |
1920 | return 0; | 1923 | return 0; |
1921 | return (QTextParagraphPseudoDocument*) docOrPseudo; | 1924 | return (QTextParagraphPseudoDocument*) docOrPseudo; |
1922 | } | 1925 | } |
1923 | 1926 | ||
1924 | 1927 | ||
1925 | inline QTextTableCell *QTextParagraph::tableCell() const | 1928 | inline QTextTableCell *QTextParagraph::tableCell() const |
1926 | { | 1929 | { |
1927 | return hasdoc ? document()->tableCell () : 0; | 1930 | return hasdoc ? document()->tableCell () : 0; |
1928 | } | 1931 | } |
1929 | 1932 | ||
1930 | inline QTextCommandHistory *QTextParagraph::commands() const | 1933 | inline QTextCommandHistory *QTextParagraph::commands() const |
1931 | { | 1934 | { |
1932 | return hasdoc ? document()->commands() : pseudoDocument()->commandHistory; | 1935 | return hasdoc ? document()->commands() : pseudoDocument()->commandHistory; |
1933 | } | 1936 | } |
1934 | 1937 | ||
1935 | 1938 | ||
1936 | inline int QTextParagraph::alignment() const | 1939 | inline int QTextParagraph::alignment() const |
1937 | { | 1940 | { |
1938 | return align; | 1941 | return align; |
1939 | } | 1942 | } |
1940 | 1943 | ||
1941 | inline void QTextParagraph::registerFloatingItem( QTextCustomItem *i ) | 1944 | inline void QTextParagraph::registerFloatingItem( QTextCustomItem *i ) |
1942 | { | 1945 | { |
1943 | floatingItems().append( i ); | 1946 | floatingItems().append( i ); |
1944 | } | 1947 | } |
1945 | 1948 | ||
1946 | inline void QTextParagraph::unregisterFloatingItem( QTextCustomItem *i ) | 1949 | inline void QTextParagraph::unregisterFloatingItem( QTextCustomItem *i ) |
1947 | { | 1950 | { |
1948 | floatingItems().removeRef( i ); | 1951 | floatingItems().removeRef( i ); |
1949 | } | 1952 | } |
1950 | 1953 | ||
1951 | inline QBrush *QTextParagraph::background() const | 1954 | inline QBrush *QTextParagraph::background() const |
1952 | { | 1955 | { |
1953 | return tableCell() ? tableCell()->backGround() : 0; | 1956 | return tableCell() ? tableCell()->backGround() : 0; |
1954 | } | 1957 | } |
1955 | 1958 | ||
1956 | inline int QTextParagraph::documentWidth() const | 1959 | inline int QTextParagraph::documentWidth() const |
1957 | { | 1960 | { |
1958 | return hasdoc ? document()->width() : pseudoDocument()->docRect.width(); | 1961 | return hasdoc ? document()->width() : pseudoDocument()->docRect.width(); |
1959 | } | 1962 | } |
1960 | 1963 | ||
1961 | inline int QTextParagraph::documentVisibleWidth() const | 1964 | inline int QTextParagraph::documentVisibleWidth() const |
1962 | { | 1965 | { |
1963 | return hasdoc ? document()->visibleWidth() : pseudoDocument()->docRect.width(); | 1966 | return hasdoc ? document()->visibleWidth() : pseudoDocument()->docRect.width(); |
1964 | } | 1967 | } |
1965 | 1968 | ||
1966 | inline int QTextParagraph::documentX() const | 1969 | inline int QTextParagraph::documentX() const |
1967 | { | 1970 | { |
1968 | return hasdoc ? document()->x() : pseudoDocument()->docRect.x(); | 1971 | return hasdoc ? document()->x() : pseudoDocument()->docRect.x(); |
1969 | } | 1972 | } |
1970 | 1973 | ||
1971 | inline int QTextParagraph::documentY() const | 1974 | inline int QTextParagraph::documentY() const |
1972 | { | 1975 | { |
1973 | return hasdoc ? document()->y() : pseudoDocument()->docRect.y(); | 1976 | return hasdoc ? document()->y() : pseudoDocument()->docRect.y(); |
1974 | } | 1977 | } |
1975 | 1978 | ||
1976 | inline void QTextParagraph::setExtraData( QTextParagraphData *data ) | 1979 | inline void QTextParagraph::setExtraData( QTextParagraphData *data ) |
1977 | { | 1980 | { |
1978 | eData = data; | 1981 | eData = data; |
1979 | } | 1982 | } |
1980 | 1983 | ||
1981 | inline QTextParagraphData *QTextParagraph::extraData() const | 1984 | inline QTextParagraphData *QTextParagraph::extraData() const |
1982 | { | 1985 | { |
1983 | return eData; | 1986 | return eData; |
1984 | } | 1987 | } |
diff --git a/noncore/apps/tableviewer/browsekeyentry.cpp b/noncore/apps/tableviewer/browsekeyentry.cpp index 04e7902..bab9af6 100644 --- a/noncore/apps/tableviewer/browsekeyentry.cpp +++ b/noncore/apps/tableviewer/browsekeyentry.cpp | |||
@@ -1,242 +1,243 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 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 | 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 | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 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. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | #include "browsekeyentry.h" | 20 | #include "browsekeyentry.h" |
21 | 21 | ||
22 | /* OPIE */ | ||
23 | #include <opie2/odebug.h> | ||
24 | using namespace Opie::Core; | ||
25 | |||
26 | /* QT */ | ||
22 | #include <qtoolbutton.h> | 27 | #include <qtoolbutton.h> |
23 | #include <qwidgetstack.h> | 28 | #include <qwidgetstack.h> |
24 | #include <qlayout.h> | 29 | #include <qlayout.h> |
25 | #include <qlineedit.h> | 30 | #include <qlineedit.h> |
26 | #include <qpushbutton.h> | 31 | #include <qpushbutton.h> |
27 | #include <qpopupmenu.h> | 32 | #include <qpopupmenu.h> |
28 | #include <qhbox.h> | 33 | #include <qhbox.h> |
29 | #include <qdatetime.h> | 34 | #include <qdatetime.h> |
30 | 35 | ||
31 | //#include <iostream.h> | ||
32 | #include <qheader.h> | ||
33 | // For qWarning(const char *) | ||
34 | 36 | ||
35 | /*! | 37 | /*! |
36 | \class TVBrowseKeyEntry | 38 | \class TVBrowseKeyEntry |
37 | \brief a Widget used enter keys into the TVBrowseViewWidget | 39 | \brief a Widget used enter keys into the TVBrowseViewWidget |
38 | 40 | ||
39 | The TVBrowseKeyEntry Widget provides the facility to enter | 41 | The TVBrowseKeyEntry Widget provides the facility to enter |
40 | various key types to be search on in the table. The key can be changed | 42 | various key types to be search on in the table. The key can be changed |
41 | and the entry field will update to the correct sort of widget appropriately | 43 | and the entry field will update to the correct sort of widget appropriately |
42 | */ | 44 | */ |
43 | 45 | ||
44 | /*! | 46 | /*! |
45 | Constructs the widget | 47 | Constructs the widget |
46 | */ | 48 | */ |
47 | TVBrowseKeyEntry::TVBrowseKeyEntry(QWidget *parent, const char *name, WFlags f) | 49 | TVBrowseKeyEntry::TVBrowseKeyEntry(QWidget *parent, const char *name, WFlags f) |
48 | : QWidget(parent, name, f) | 50 | : QWidget(parent, name, f) |
49 | { | 51 | { |
50 | int stack_elem = 0; | 52 | int stack_elem = 0; |
51 | QHBoxLayout *h_layout = new QHBoxLayout(this); | 53 | QHBoxLayout *h_layout = new QHBoxLayout(this); |
52 | 54 | ||
53 | textKey = new QLineEdit(this, 0); | 55 | textKey = new QLineEdit(this, 0); |
54 | 56 | ||
55 | dateKey = new QHBox(this, 0); | 57 | dateKey = new QHBox(this, 0); |
56 | dayKey = new QLineEdit(dateKey, 0); | 58 | dayKey = new QLineEdit(dateKey, 0); |
57 | monthKey = new QLineEdit(dateKey, 0); | 59 | monthKey = new QLineEdit(dateKey, 0); |
58 | yearKey = new QLineEdit(dateKey, 0); | 60 | yearKey = new QLineEdit(dateKey, 0); |
59 | 61 | ||
60 | timeKey = new QHBox(this, 0); | 62 | timeKey = new QHBox(this, 0); |
61 | hourKey = new QLineEdit(timeKey, 0); | 63 | hourKey = new QLineEdit(timeKey, 0); |
62 | minuteKey = new QLineEdit(timeKey, 0); | 64 | minuteKey = new QLineEdit(timeKey, 0); |
63 | secondKey = new QLineEdit(timeKey, 0); | 65 | secondKey = new QLineEdit(timeKey, 0); |
64 | 66 | ||
65 | resetButton = new QPushButton(this, "reset"); | 67 | resetButton = new QPushButton(this, "reset"); |
66 | resetButton->setMinimumSize(QSize(50, 0)); | 68 | resetButton->setMinimumSize(QSize(50, 0)); |
67 | resetButton->setText(tr("Reset")); | 69 | resetButton->setText(tr("Reset")); |
68 | 70 | ||
69 | changeKeyButton = new QToolButton(this, "changekey"); | 71 | changeKeyButton = new QToolButton(this, "changekey"); |
70 | // TODO The icon stuff. | 72 | // TODO The icon stuff. |
71 | changeKeyButton->setText(tr("key")); | 73 | changeKeyButton->setText(tr("key")); |
72 | 74 | ||
73 | totalKeys = 0; | 75 | totalKeys = 0; |
74 | ts = 0; | 76 | ts = 0; |
75 | keyMenu = new QPopupMenu(this, "keymenu"); | 77 | keyMenu = new QPopupMenu(this, "keymenu"); |
76 | 78 | ||
77 | ws = new QWidgetStack(this, 0); | 79 | ws = new QWidgetStack(this, 0); |
78 | ws->addWidget(textKey, stack_elem++); | 80 | ws->addWidget(textKey, stack_elem++); |
79 | ws->addWidget(timeKey, stack_elem++); | 81 | ws->addWidget(timeKey, stack_elem++); |
80 | ws->addWidget(dateKey, stack_elem++); | 82 | ws->addWidget(dateKey, stack_elem++); |
81 | 83 | ||
82 | ws->raiseWidget(0); | 84 | ws->raiseWidget(0); |
83 | 85 | ||
84 | // TODO connect slots and signals.... | 86 | // TODO connect slots and signals.... |
85 | connect(changeKeyButton, SIGNAL(clicked()), | 87 | connect(changeKeyButton, SIGNAL(clicked()), |
86 | this, SLOT(changeKeyMenuSlot())); | 88 | this, SLOT(changeKeyMenuSlot())); |
87 | connect(resetButton, SIGNAL(clicked()), | 89 | connect(resetButton, SIGNAL(clicked()), |
88 | this, SLOT(resetKeySlot())); | 90 | this, SLOT(resetKeySlot())); |
89 | 91 | ||
90 | connect(textKey, SIGNAL(textChanged(const QString&)), | 92 | connect(textKey, SIGNAL(textChanged(const QString&)), |
91 | this, SLOT(searchOnText())); | 93 | this, SLOT(searchOnText())); |
92 | 94 | ||
93 | connect(dayKey, SIGNAL(textChanged(const QString&)), | 95 | connect(dayKey, SIGNAL(textChanged(const QString&)), |
94 | this, SLOT(searchOnText())); | 96 | this, SLOT(searchOnText())); |
95 | connect(monthKey, SIGNAL(textChanged(const QString&)), | 97 | connect(monthKey, SIGNAL(textChanged(const QString&)), |
96 | this, SLOT(searchOnText())); | 98 | this, SLOT(searchOnText())); |
97 | connect(yearKey, SIGNAL(textChanged(const QString&)), | 99 | connect(yearKey, SIGNAL(textChanged(const QString&)), |
98 | this, SLOT(searchOnText())); | 100 | this, SLOT(searchOnText())); |
99 | 101 | ||
100 | connect(secondKey, SIGNAL(textChanged(const QString&)), | 102 | connect(secondKey, SIGNAL(textChanged(const QString&)), |
101 | this, SLOT(searchOnText())); | 103 | this, SLOT(searchOnText())); |
102 | connect(minuteKey, SIGNAL(textChanged(const QString&)), | 104 | connect(minuteKey, SIGNAL(textChanged(const QString&)), |
103 | this, SLOT(searchOnText())); | 105 | this, SLOT(searchOnText())); |
104 | connect(hourKey, SIGNAL(textChanged(const QString&)), | 106 | connect(hourKey, SIGNAL(textChanged(const QString&)), |
105 | this, SLOT(searchOnText())); | 107 | this, SLOT(searchOnText())); |
106 | 108 | ||
107 | h_layout->addWidget(ws); | 109 | h_layout->addWidget(ws); |
108 | h_layout->addWidget(resetButton); | 110 | h_layout->addWidget(resetButton); |
109 | h_layout->addWidget(changeKeyButton); | 111 | h_layout->addWidget(changeKeyButton); |
110 | } | 112 | } |
111 | 113 | ||
112 | /*! | 114 | /*! |
113 | Destructs the widget | 115 | Destructs the widget |
114 | */ | 116 | */ |
115 | TVBrowseKeyEntry::~TVBrowseKeyEntry() | 117 | TVBrowseKeyEntry::~TVBrowseKeyEntry() |
116 | { | 118 | { |
117 | } | 119 | } |
118 | 120 | ||
119 | /*! | 121 | /*! |
120 | Changes which key the user intends to search on | 122 | Changes which key the user intends to search on |
121 | 123 | ||
122 | \param id_param the index of the key future searches should be base on | 124 | \param id_param the index of the key future searches should be base on |
123 | */ | 125 | */ |
124 | void TVBrowseKeyEntry::changeKeySlot(int id_param) | 126 | void TVBrowseKeyEntry::changeKeySlot(int id_param) |
125 | { | 127 | { |
126 | emit sortChanged(id_param); | 128 | emit sortChanged(id_param); |
127 | switch(ts->kRep->getKeyType(ts->current_column)) { | 129 | switch(ts->kRep->getKeyType(ts->current_column)) { |
128 | /* work out what to raise */ | 130 | /* work out what to raise */ |
129 | case kt_string: | 131 | case kt_string: |
130 | case kt_int: | 132 | case kt_int: |
131 | ws->raiseWidget(0); | 133 | ws->raiseWidget(0); |
132 | break; | 134 | break; |
133 | case kt_time: | 135 | case kt_time: |
134 | ws->raiseWidget(1); | 136 | ws->raiseWidget(1); |
135 | break; | 137 | break; |
136 | case kt_date: | 138 | case kt_date: |
137 | ws->raiseWidget(2); | 139 | ws->raiseWidget(2); |
138 | break; | 140 | break; |
139 | default: | 141 | default: |
140 | return; | 142 | return; |
141 | } | 143 | } |
142 | } | 144 | } |
143 | 145 | ||
144 | /*! | 146 | /*! |
145 | Opens the change key menu | 147 | Opens the change key menu |
146 | */ | 148 | */ |
147 | void TVBrowseKeyEntry::changeKeyMenuSlot() | 149 | void TVBrowseKeyEntry::changeKeyMenuSlot() |
148 | { | 150 | { |
149 | if(ts) | 151 | if(ts) |
150 | keyMenu->exec(changeKeyButton->mapToGlobal(QPoint(0,0))); | 152 | keyMenu->exec(changeKeyButton->mapToGlobal(QPoint(0,0))); |
151 | } | 153 | } |
152 | /*! | 154 | /*! |
153 | Blanks the key entry widget | 155 | Blanks the key entry widget |
154 | \TODO the actual implmentation | 156 | \TODO the actual implmentation |
155 | */ | 157 | */ |
156 | void TVBrowseKeyEntry::resetKeySlot() { | 158 | void TVBrowseKeyEntry::resetKeySlot() { |
157 | ; | 159 | ; |
158 | } | 160 | } |
159 | 161 | ||
160 | void TVBrowseKeyEntry::setTableState(TableState *t) { | 162 | void TVBrowseKeyEntry::setTableState(TableState *t) { |
161 | int i; | 163 | int i; |
162 | ts = t; | 164 | ts = t; |
163 | 165 | ||
164 | /* clear the old */ | 166 | /* clear the old */ |
165 | keyMenu->clear(); | 167 | keyMenu->clear(); |
166 | 168 | ||
167 | for (i = 0; i < t->kRep->getNumFields(); i++) { | 169 | for (i = 0; i < t->kRep->getNumFields(); i++) { |
168 | keyMenu->insertItem(ts->kRep->getKeyName(i), this, | 170 | keyMenu->insertItem(ts->kRep->getKeyName(i), this, |
169 | SLOT(changeKeySlot(int)), 0, i); | 171 | SLOT(changeKeySlot(int)), 0, i); |
170 | keyMenu->setItemParameter(i, i); | 172 | keyMenu->setItemParameter(i, i); |
171 | } | 173 | } |
172 | } | 174 | } |
173 | 175 | ||
174 | /*! | 176 | /*! |
175 | Searches on the current value of the key entry provided that the | 177 | Searches on the current value of the key entry provided that the |
176 | current key is of type text WARNING, TODO fix memory leaks | 178 | current key is of type text WARNING, TODO fix memory leaks |
177 | */ | 179 | */ |
178 | void TVBrowseKeyEntry::searchOnText() | 180 | void TVBrowseKeyEntry::searchOnText() |
179 | { | 181 | { |
180 | void *sendkey; | 182 | void *sendkey; |
181 | int tmp; | 183 | int tmp; |
182 | 184 | ||
183 | switch(ts->kRep->getKeyType(ts->current_column)) { | 185 | switch(ts->kRep->getKeyType(ts->current_column)) { |
184 | /* work out what to raise */ | 186 | /* work out what to raise */ |
185 | case kt_string: | 187 | case kt_string: |
186 | sendkey = (void *)new QString(textKey->text()); | 188 | sendkey = (void *)new QString(textKey->text()); |
187 | break; | 189 | break; |
188 | case kt_int: { | 190 | case kt_int: { |
189 | bool ok; | 191 | bool ok; |
190 | tmp = textKey->text().toInt(&ok); | 192 | tmp = textKey->text().toInt(&ok); |
191 | sendkey = &tmp; | 193 | sendkey = &tmp; |
192 | if (!ok) | 194 | if (!ok) |
193 | return; | 195 | return; |
194 | break; | 196 | break; |
195 | } | 197 | } |
196 | case kt_time: { | 198 | case kt_time: { |
197 | bool ok; | 199 | bool ok; |
198 | int s,m,h; | 200 | int s,m,h; |
199 | s = secondKey->text().toInt(&ok); | 201 | s = secondKey->text().toInt(&ok); |
200 | if (!ok) | 202 | if (!ok) |
201 | return; | 203 | return; |
202 | m = minuteKey->text().toInt(&ok); | 204 | m = minuteKey->text().toInt(&ok); |
203 | if (!ok) | 205 | if (!ok) |
204 | return; | 206 | return; |
205 | h = hourKey->text().toInt(&ok); | 207 | h = hourKey->text().toInt(&ok); |
206 | if (!ok) | 208 | if (!ok) |
207 | return; | 209 | return; |
208 | if(!QTime::isValid(h, m, s)) | 210 | if(!QTime::isValid(h, m, s)) |
209 | return; | 211 | return; |
210 | sendkey = (void *) new QTime(h, m, s); | 212 | sendkey = (void *) new QTime(h, m, s); |
211 | break; | 213 | break; |
212 | } | 214 | } |
213 | case kt_date: { | 215 | case kt_date: { |
214 | bool ok; | 216 | bool ok; |
215 | int d,m,y; | 217 | int d,m,y; |
216 | d = dayKey->text().toInt(&ok); | 218 | d = dayKey->text().toInt(&ok); |
217 | if (!ok) | 219 | if (!ok) |
218 | return; | 220 | return; |
219 | m = monthKey->text().toInt(&ok); | 221 | m = monthKey->text().toInt(&ok); |
220 | if (!ok) | 222 | if (!ok) |
221 | return; | 223 | return; |
222 | y = yearKey->text().toInt(&ok); | 224 | y = yearKey->text().toInt(&ok); |
223 | if (!ok) | 225 | if (!ok) |
224 | return; | 226 | return; |
225 | if(!QDate::isValid(y, m, d)) | 227 | if(!QDate::isValid(y, m, d)) |
226 | return; | 228 | return; |
227 | sendkey = (void *) new QDate(y, m, d); | 229 | sendkey = (void *) new QDate(y, m, d); |
228 | break; | 230 | break; |
229 | } | 231 | } |
230 | default: | 232 | default: |
231 | qWarning("TVBrowseKeyEntry::searchOnText() " | 233 | owarn << "TVBrowseKeyEntry::searchOnText() cannot work out data type" << oendl; |
232 | "cannot work out data type"); | ||
233 | return; | 234 | return; |
234 | } | 235 | } |
235 | emit searchOnKey(ts->current_column, sendkey); | 236 | emit searchOnKey(ts->current_column, sendkey); |
236 | } | 237 | } |
237 | 238 | ||
238 | /*! \fn void TVBrowseKeyEntry::searchOnKey(int currentKeyId, void *v) | 239 | /*! \fn void TVBrowseKeyEntry::searchOnKey(int currentKeyId, void *v) |
239 | 240 | ||
240 | This signal indicates that a search on key index currentKeyId should be | 241 | This signal indicates that a search on key index currentKeyId should be |
241 | done searching for the value v. | 242 | done searching for the value v. |
242 | */ | 243 | */ |
diff --git a/noncore/apps/tableviewer/db/common.cpp b/noncore/apps/tableviewer/db/common.cpp index b58af85..c35dbea 100644 --- a/noncore/apps/tableviewer/db/common.cpp +++ b/noncore/apps/tableviewer/db/common.cpp | |||
@@ -1,161 +1,161 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 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 | 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 | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 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. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | #include "common.h" | 20 | #include "common.h" |
21 | #include "datacache.h" | 21 | #include "datacache.h" |
22 | 22 | ||
23 | /* OPIE */ | 23 | /* OPIE */ |
24 | #include <opie2/odebug.h> | 24 | #include <opie2/odebug.h> |
25 | #include <qpe/timestring.h> | 25 | #include <qpe/timestring.h> |
26 | using namespace Opie::Core; | 26 | using namespace Opie::Core; |
27 | 27 | ||
28 | /* QT */ | 28 | /* QT */ |
29 | #include <qstring.h> | 29 | #include <qstring.h> |
30 | #include <qheader.h> | 30 | #include <qheader.h> |
31 | #include <qvector.h> | 31 | #include <qvector.h> |
32 | #include <qdatetime.h> | 32 | #include <qdatetime.h> |
33 | 33 | ||
34 | /* STD */ | 34 | /* STD */ |
35 | #include <assert.h> | 35 | #include <assert.h> |
36 | #include <stdlib.h> | 36 | #include <stdlib.h> |
37 | 37 | ||
38 | static const int del_flag = 0x1; | 38 | static const int del_flag = 0x1; |
39 | static const int new_flag = 0x2; | 39 | static const int new_flag = 0x2; |
40 | 40 | ||
41 | /* Helper function */ | 41 | /* Helper function */ |
42 | 42 | ||
43 | int parseNextNumber(QString *q) { | 43 | int parseNextNumber(QString *q) { |
44 | QChar c; | 44 | QChar c; |
45 | uint i; | 45 | uint i; |
46 | int result = 0; | 46 | int result = 0; |
47 | 47 | ||
48 | bool found_digits = FALSE; | 48 | bool found_digits = FALSE; |
49 | for(i = 0; i < q->length(); i++) { | 49 | for(i = 0; i < q->length(); i++) { |
50 | c = q->at(i); | 50 | c = q->at(i); |
51 | if (c.isDigit()) { | 51 | if (c.isDigit()) { |
52 | if (found_digits) | 52 | if (found_digits) |
53 | result *= 10; | 53 | result *= 10; |
54 | found_digits = TRUE; | 54 | found_digits = TRUE; |
55 | result += c.digitValue(); | 55 | result += c.digitValue(); |
56 | } else { | 56 | } else { |
57 | if (found_digits) | 57 | if (found_digits) |
58 | break; | 58 | break; |
59 | /* just skip this char */ | 59 | /* just skip this char */ |
60 | } | 60 | } |
61 | } | 61 | } |
62 | /* now truncate q */ | 62 | /* now truncate q */ |
63 | if (found_digits) | 63 | if (found_digits) |
64 | q->remove(0, i); | 64 | q->remove(0, i); |
65 | return result; | 65 | return result; |
66 | } | 66 | } |
67 | 67 | ||
68 | /*! | 68 | /*! |
69 | \class QStringVector | 69 | \class QStringVector |
70 | \brief A Vector of QStrings that can be sorted and searched | 70 | \brief A Vector of QStrings that can be sorted and searched |
71 | 71 | ||
72 | Implmented in order to allow reverse lookup on the string name | 72 | Implmented in order to allow reverse lookup on the string name |
73 | 73 | ||
74 | */ | 74 | */ |
75 | 75 | ||
76 | /*! | 76 | /*! |
77 | This function implements the compare function in order to allow the | 77 | This function implements the compare function in order to allow the |
78 | searching and sorting of the QStringVector to occur | 78 | searching and sorting of the QStringVector to occur |
79 | 79 | ||
80 | \returns an int which is either | 80 | \returns an int which is either |
81 | <UL> | 81 | <UL> |
82 | <LI> < 0 if the first string is smaller than the second,</LI> | 82 | <LI> < 0 if the first string is smaller than the second,</LI> |
83 | <LI> > 0 if the first string is bigger then the second,</LI> | 83 | <LI> > 0 if the first string is bigger then the second,</LI> |
84 | <LI> == 0 if the first string is equal to the second.</LI> | 84 | <LI> == 0 if the first string is equal to the second.</LI> |
85 | </UL> | 85 | </UL> |
86 | */ | 86 | */ |
87 | int QStringVector::compareItems(Item a, Item b) | 87 | int QStringVector::compareItems(Item a, Item b) |
88 | { | 88 | { |
89 | QString *qa = (QString *)a; | 89 | QString *qa = (QString *)a; |
90 | QString *qb = (QString *)b; | 90 | QString *qb = (QString *)b; |
91 | 91 | ||
92 | return QString::compare(*qa, *qb); | 92 | return QString::compare(*qa, *qb); |
93 | } | 93 | } |
94 | 94 | ||
95 | /*! | 95 | /*! |
96 | \class TVVariant | 96 | \class TVVariant |
97 | A way of abstracting void * and keeping information on | 97 | A way of abstracting void * and keeping information on |
98 | the keytypes and behaviours in one place | 98 | the keytypes and behaviours in one place |
99 | */ | 99 | */ |
100 | 100 | ||
101 | TVVariantPrivate::TVVariantPrivate() | 101 | TVVariantPrivate::TVVariantPrivate() |
102 | { | 102 | { |
103 | typ = TVVariant::Invalid; | 103 | typ = TVVariant::Invalid; |
104 | } | 104 | } |
105 | 105 | ||
106 | TVVariantPrivate::TVVariantPrivate( TVVariantPrivate *d) | 106 | TVVariantPrivate::TVVariantPrivate( TVVariantPrivate *d) |
107 | { | 107 | { |
108 | switch(d->typ) | 108 | switch(d->typ) |
109 | { | 109 | { |
110 | case TVVariant::Invalid: | 110 | case TVVariant::Invalid: |
111 | break; | 111 | break; |
112 | case TVVariant::String: | 112 | case TVVariant::String: |
113 | value.ptr = new QString(*((QString *)d->value.ptr)); | 113 | value.ptr = new QString(*((QString *)d->value.ptr)); |
114 | break; | 114 | break; |
115 | case TVVariant::Date: | 115 | case TVVariant::Date: |
116 | value.ptr = new QDate(*((QDate *)d->value.ptr)); | 116 | value.ptr = new QDate(*((QDate *)d->value.ptr)); |
117 | break; | 117 | break; |
118 | case TVVariant::Time: | 118 | case TVVariant::Time: |
119 | value.ptr = new QTime(*((QTime *)d->value.ptr)); | 119 | value.ptr = new QTime(*((QTime *)d->value.ptr)); |
120 | break; | 120 | break; |
121 | case TVVariant::Int: | 121 | case TVVariant::Int: |
122 | value.i = d->value.i; | 122 | value.i = d->value.i; |
123 | break; | 123 | break; |
124 | default: | 124 | default: |
125 | ASSERT( 0 ); | 125 | ASSERT( 0 ); |
126 | } | 126 | } |
127 | 127 | ||
128 | typ = d->typ; | 128 | typ = d->typ; |
129 | } | 129 | } |
130 | 130 | ||
131 | TVVariantPrivate::~TVVariantPrivate() | 131 | TVVariantPrivate::~TVVariantPrivate() |
132 | { | 132 | { |
133 | clear(); | 133 | clear(); |
134 | } | 134 | } |
135 | 135 | ||
136 | void TVVariantPrivate::clear() | 136 | void TVVariantPrivate::clear() |
137 | { | 137 | { |
138 | switch( typ ) | 138 | switch( typ ) |
139 | { | 139 | { |
140 | case TVVariant::String: | 140 | case TVVariant::String: |
141 | delete (QString *)value.ptr; | 141 | delete (QString *)value.ptr; |
142 | break; | 142 | break; |
143 | case TVVariant::Date: | 143 | case TVVariant::Date: |
144 | delete (QDate *)value.ptr; | 144 | delete (QDate *)value.ptr; |
145 | break; | 145 | break; |
146 | case TVVariant::Time: | 146 | case TVVariant::Time: |
147 | delete (QTime *)value.ptr; | 147 | delete (QTime *)value.ptr; |
148 | break; | 148 | break; |
149 | case TVVariant::Invalid: | 149 | case TVVariant::Invalid: |
150 | case TVVariant::Int: | 150 | case TVVariant::Int: |
151 | break; | 151 | break; |
152 | } | 152 | } |
153 | 153 | ||
154 | typ = TVVariant::Invalid; | 154 | typ = TVVariant::Invalid; |
155 | } | 155 | } |
156 | 156 | ||
157 | /*! | 157 | /*! |
158 | \class TVVariant | 158 | \class TVVariant |
159 | blah | 159 | blah |
160 | */ | 160 | */ |
161 | 161 | ||
@@ -259,1220 +259,1217 @@ const QString TVVariant::typeToName(KeyType typ) | |||
259 | case Time: | 259 | case Time: |
260 | return QString("Time"); | 260 | return QString("Time"); |
261 | case Int: | 261 | case Int: |
262 | return QString("Int"); | 262 | return QString("Int"); |
263 | case Invalid: | 263 | case Invalid: |
264 | default: | 264 | default: |
265 | return QString("Invalid"); | 265 | return QString("Invalid"); |
266 | } | 266 | } |
267 | return QString("Invalid"); | 267 | return QString("Invalid"); |
268 | } | 268 | } |
269 | 269 | ||
270 | TVVariant::KeyType TVVariant::nameToType(const QString &name) | 270 | TVVariant::KeyType TVVariant::nameToType(const QString &name) |
271 | { | 271 | { |
272 | if(!qstrcmp("String", name)) | 272 | if(!qstrcmp("String", name)) |
273 | return String; | 273 | return String; |
274 | if(!qstrcmp("Date", name)) | 274 | if(!qstrcmp("Date", name)) |
275 | return Date; | 275 | return Date; |
276 | if(!qstrcmp("Time", name)) | 276 | if(!qstrcmp("Time", name)) |
277 | return Time; | 277 | return Time; |
278 | if(!qstrcmp("Int", name)) | 278 | if(!qstrcmp("Int", name)) |
279 | return Int; | 279 | return Int; |
280 | 280 | ||
281 | return Invalid; | 281 | return Invalid; |
282 | } | 282 | } |
283 | 283 | ||
284 | void TVVariant::load(QDataStream &s ) | 284 | void TVVariant::load(QDataStream &s ) |
285 | { | 285 | { |
286 | KeyType t; | 286 | KeyType t; |
287 | s >> t; | 287 | s >> t; |
288 | 288 | ||
289 | d->typ = t; | 289 | d->typ = t; |
290 | switch(t) { | 290 | switch(t) { |
291 | case Invalid: | 291 | case Invalid: |
292 | d->typ = t; | 292 | d->typ = t; |
293 | break; | 293 | break; |
294 | case String: | 294 | case String: |
295 | { | 295 | { |
296 | QString *x = new QString; | 296 | QString *x = new QString; |
297 | s >> *x; | 297 | s >> *x; |
298 | d->value.ptr = x; | 298 | d->value.ptr = x; |
299 | } | 299 | } |
300 | break; | 300 | break; |
301 | case Time: | 301 | case Time: |
302 | { | 302 | { |
303 | QTime *x = new QTime; | 303 | QTime *x = new QTime; |
304 | s >> *x; | 304 | s >> *x; |
305 | d->value.ptr = x; | 305 | d->value.ptr = x; |
306 | } | 306 | } |
307 | break; | 307 | break; |
308 | case Date: | 308 | case Date: |
309 | { | 309 | { |
310 | QDate *x = new QDate; | 310 | QDate *x = new QDate; |
311 | s >> *x; | 311 | s >> *x; |
312 | d->value.ptr = x; | 312 | d->value.ptr = x; |
313 | } | 313 | } |
314 | break; | 314 | break; |
315 | case Int: | 315 | case Int: |
316 | { | 316 | { |
317 | int x; | 317 | int x; |
318 | s >> x; | 318 | s >> x; |
319 | d->value.i = x; | 319 | d->value.i = x; |
320 | } | 320 | } |
321 | break; | 321 | break; |
322 | default: | 322 | default: |
323 | ofatal << "Unrecognized data type" << oendl; | 323 | ofatal << "Unrecognized data type" << oendl; |
324 | } | 324 | } |
325 | } | 325 | } |
326 | 326 | ||
327 | void TVVariant::save( QDataStream &s ) const | 327 | void TVVariant::save( QDataStream &s ) const |
328 | { | 328 | { |
329 | s << type(); | 329 | s << type(); |
330 | 330 | ||
331 | switch( d->typ ) { | 331 | switch( d->typ ) { |
332 | case String: | 332 | case String: |
333 | s << *((QString *)d->value.ptr); | 333 | s << *((QString *)d->value.ptr); |
334 | break; | 334 | break; |
335 | case Date: | 335 | case Date: |
336 | s << *((QDate *)d->value.ptr); | 336 | s << *((QDate *)d->value.ptr); |
337 | break; | 337 | break; |
338 | case Time: | 338 | case Time: |
339 | s << *((QTime *)d->value.ptr); | 339 | s << *((QTime *)d->value.ptr); |
340 | break; | 340 | break; |
341 | case Int: | 341 | case Int: |
342 | s << d->value.i; | 342 | s << d->value.i; |
343 | break; | 343 | break; |
344 | case Invalid: | 344 | case Invalid: |
345 | break; | 345 | break; |
346 | } | 346 | } |
347 | } | 347 | } |
348 | 348 | ||
349 | QDataStream& operator>>(QDataStream& s, TVVariant& p) | 349 | QDataStream& operator>>(QDataStream& s, TVVariant& p) |
350 | { | 350 | { |
351 | p.load( s ); | 351 | p.load( s ); |
352 | return s; | 352 | return s; |
353 | } | 353 | } |
354 | 354 | ||
355 | QDataStream& operator<<(QDataStream &s, const TVVariant& p) | 355 | QDataStream& operator<<(QDataStream &s, const TVVariant& p) |
356 | { | 356 | { |
357 | p.save( s ); | 357 | p.save( s ); |
358 | return s; | 358 | return s; |
359 | } | 359 | } |
360 | 360 | ||
361 | QDataStream& operator>> (QDataStream &s, TVVariant::KeyType& p) | 361 | QDataStream& operator>> (QDataStream &s, TVVariant::KeyType& p) |
362 | { | 362 | { |
363 | Q_UINT8 u = 0; | 363 | Q_UINT8 u = 0; |
364 | s >> u; | 364 | s >> u; |
365 | p = (TVVariant::KeyType) u; | 365 | p = (TVVariant::KeyType) u; |
366 | 366 | ||
367 | return s; | 367 | return s; |
368 | } | 368 | } |
369 | 369 | ||
370 | QDataStream& operator<< (QDataStream& s, const TVVariant::KeyType& p) | 370 | QDataStream& operator<< (QDataStream& s, const TVVariant::KeyType& p) |
371 | { | 371 | { |
372 | s << (Q_UINT8)p; | 372 | s << (Q_UINT8)p; |
373 | return s; | 373 | return s; |
374 | } | 374 | } |
375 | 375 | ||
376 | const QString TVVariant::toString() const | 376 | const QString TVVariant::toString() const |
377 | { | 377 | { |
378 | switch(d->typ) { | 378 | switch(d->typ) { |
379 | case String: | 379 | case String: |
380 | return *((QString*)d->value.ptr); | 380 | return *((QString*)d->value.ptr); |
381 | case Date: | 381 | case Date: |
382 | return ((QDate*)d->value.ptr)->toString(); | 382 | return ((QDate*)d->value.ptr)->toString(); |
383 | case Time: | 383 | case Time: |
384 | return ((QTime*)d->value.ptr)->toString(); | 384 | return ((QTime*)d->value.ptr)->toString(); |
385 | case Int: | 385 | case Int: |
386 | return QString::number(d->value.i); | 386 | return QString::number(d->value.i); |
387 | case Invalid: | 387 | case Invalid: |
388 | default: | 388 | default: |
389 | return QString::null; | 389 | return QString::null; |
390 | } | 390 | } |
391 | return QString::null; | 391 | return QString::null; |
392 | } | 392 | } |
393 | 393 | ||
394 | // TODO DO, this properly, */ | 394 | // TODO DO, this properly, */ |
395 | int TVVariant::toInt() const | 395 | int TVVariant::toInt() const |
396 | { | 396 | { |
397 | if(d->typ == Int) | 397 | if(d->typ == Int) |
398 | return d->value.i; | 398 | return d->value.i; |
399 | 399 | ||
400 | if(d->typ == String) { | 400 | if(d->typ == String) { |
401 | QString tmpq(*(QString *)d->value.ptr); | 401 | QString tmpq(*(QString *)d->value.ptr); |
402 | return parseNextNumber(&tmpq); | 402 | return parseNextNumber(&tmpq); |
403 | } | 403 | } |
404 | 404 | ||
405 | return 0; | 405 | return 0; |
406 | } | 406 | } |
407 | 407 | ||
408 | const QDate TVVariant::toDate() const | 408 | const QDate TVVariant::toDate() const |
409 | { | 409 | { |
410 | if(d->typ == Date) | 410 | if(d->typ == Date) |
411 | return *((QDate *)d->value.ptr); | 411 | return *((QDate *)d->value.ptr); |
412 | 412 | ||
413 | if(d->typ == String) { | 413 | if(d->typ == String) { |
414 | QString q = toString(); | 414 | QString q = toString(); |
415 | 415 | ||
416 | /* date format is day mon d yyyy */ | 416 | /* date format is day mon d yyyy */ |
417 | /* ignore the first three letters, read the next | 417 | /* ignore the first three letters, read the next |
418 | three for month.. etc */ | 418 | three for month.. etc */ |
419 | 419 | ||
420 | int day = parseNextNumber(&q); | 420 | int day = parseNextNumber(&q); |
421 | int month = parseNextNumber(&q); | 421 | int month = parseNextNumber(&q); |
422 | int year = parseNextNumber(&q); | 422 | int year = parseNextNumber(&q); |
423 | if (!QDate::isValid(year, month, day)) | 423 | if (!QDate::isValid(year, month, day)) |
424 | return QDate(); | 424 | return QDate(); |
425 | return QDate(year, month, day); | 425 | return QDate(year, month, day); |
426 | } | 426 | } |
427 | 427 | ||
428 | 428 | ||
429 | return QDate(); | 429 | return QDate(); |
430 | } | 430 | } |
431 | 431 | ||
432 | const QTime TVVariant::toTime() const | 432 | const QTime TVVariant::toTime() const |
433 | { | 433 | { |
434 | if(d->typ == Time) | 434 | if(d->typ == Time) |
435 | return *((QTime *)d->value.ptr); | 435 | return *((QTime *)d->value.ptr); |
436 | 436 | ||
437 | if(d->typ == String) { | 437 | if(d->typ == String) { |
438 | QString q = toString(); | 438 | QString q = toString(); |
439 | int hour = parseNextNumber(&q); | 439 | int hour = parseNextNumber(&q); |
440 | int minute = parseNextNumber(&q); | 440 | int minute = parseNextNumber(&q); |
441 | int second = parseNextNumber(&q); | 441 | int second = parseNextNumber(&q); |
442 | int msecond = parseNextNumber(&q); | 442 | int msecond = parseNextNumber(&q); |
443 | if (!QTime::isValid(hour, minute, second, msecond)) | 443 | if (!QTime::isValid(hour, minute, second, msecond)) |
444 | return QTime(); | 444 | return QTime(); |
445 | return QTime(hour, minute, second, msecond); | 445 | return QTime(hour, minute, second, msecond); |
446 | } | 446 | } |
447 | 447 | ||
448 | return QTime(); | 448 | return QTime(); |
449 | } | 449 | } |
450 | 450 | ||
451 | #define TV_VARIANT_AS( f ) Q##f& TVVariant::as##f() { \ | 451 | #define TV_VARIANT_AS( f ) Q##f& TVVariant::as##f() { \ |
452 | if ( d->typ != f ) \ | 452 | if ( d->typ != f ) \ |
453 | *this = TVVariant( to##f() ); \ | 453 | *this = TVVariant( to##f() ); \ |
454 | else \ | 454 | else \ |
455 | detach(); \ | 455 | detach(); \ |
456 | return *((Q##f*)d->value.ptr); } | 456 | return *((Q##f*)d->value.ptr); } |
457 | 457 | ||
458 | TV_VARIANT_AS(String) | 458 | TV_VARIANT_AS(String) |
459 | TV_VARIANT_AS(Date) | 459 | TV_VARIANT_AS(Date) |
460 | TV_VARIANT_AS(Time) | 460 | TV_VARIANT_AS(Time) |
461 | 461 | ||
462 | #undef TV_VARIANT_AS | 462 | #undef TV_VARIANT_AS |
463 | 463 | ||
464 | int& TVVariant::asInt() | 464 | int& TVVariant::asInt() |
465 | { | 465 | { |
466 | detach(); | 466 | detach(); |
467 | if (d->typ != Int) { | 467 | if (d->typ != Int) { |
468 | d->value.i = toInt(); | 468 | d->value.i = toInt(); |
469 | d->typ = Int; | 469 | d->typ = Int; |
470 | } | 470 | } |
471 | return d->value.i; | 471 | return d->value.i; |
472 | } | 472 | } |
473 | 473 | ||
474 | /*! | 474 | /*! |
475 | valid cast is | 475 | valid cast is |
476 | anything to String | 476 | anything to String |
477 | same to same | 477 | same to same |
478 | */ | 478 | */ |
479 | bool TVVariant::canCast(KeyType t) const | 479 | bool TVVariant::canCast(KeyType t) const |
480 | { | 480 | { |
481 | if(d->typ == t) | 481 | if(d->typ == t) |
482 | return TRUE; | 482 | return TRUE; |
483 | 483 | ||
484 | if(t == String) | 484 | if(t == String) |
485 | return TRUE; | 485 | return TRUE; |
486 | 486 | ||
487 | if(t == Int) { | 487 | if(t == Int) { |
488 | if (d->typ == Date) | 488 | if (d->typ == Date) |
489 | return TRUE; | 489 | return TRUE; |
490 | if (d->typ == Time) | 490 | if (d->typ == Time) |
491 | return TRUE; | 491 | return TRUE; |
492 | if (d->typ == String) | 492 | if (d->typ == String) |
493 | return TRUE; | 493 | return TRUE; |
494 | } | 494 | } |
495 | 495 | ||
496 | return FALSE; | 496 | return FALSE; |
497 | } | 497 | } |
498 | 498 | ||
499 | bool TVVariant::operator==( const TVVariant &v ) const | 499 | bool TVVariant::operator==( const TVVariant &v ) const |
500 | { | 500 | { |
501 | switch(d->typ) { | 501 | switch(d->typ) { |
502 | case String: | 502 | case String: |
503 | return v.toString() == toString(); | 503 | return v.toString() == toString(); |
504 | case Date: | 504 | case Date: |
505 | return v.toDate() == toDate(); | 505 | return v.toDate() == toDate(); |
506 | case Time: | 506 | case Time: |
507 | return v.toTime() == toTime(); | 507 | return v.toTime() == toTime(); |
508 | case Int: | 508 | case Int: |
509 | return v.toInt() == toInt(); | 509 | return v.toInt() == toInt(); |
510 | case Invalid: | 510 | case Invalid: |
511 | break; | 511 | break; |
512 | } | 512 | } |
513 | 513 | ||
514 | return FALSE; | 514 | return FALSE; |
515 | } | 515 | } |
516 | 516 | ||
517 | bool TVVariant::operator!=( const TVVariant &v ) const | 517 | bool TVVariant::operator!=( const TVVariant &v ) const |
518 | { | 518 | { |
519 | return !( v == *this); | 519 | return !( v == *this); |
520 | } | 520 | } |
521 | 521 | ||
522 | bool TVVariant::operator<( const TVVariant &v ) const | 522 | bool TVVariant::operator<( const TVVariant &v ) const |
523 | { | 523 | { |
524 | switch(d->typ) { | 524 | switch(d->typ) { |
525 | case String: | 525 | case String: |
526 | return toString().lower() < v.toString().lower(); | 526 | return toString().lower() < v.toString().lower(); |
527 | case Date: | 527 | case Date: |
528 | return toDate() < v.toDate(); | 528 | return toDate() < v.toDate(); |
529 | case Time: | 529 | case Time: |
530 | return toTime() < v.toTime(); | 530 | return toTime() < v.toTime(); |
531 | case Int: | 531 | case Int: |
532 | return toInt() < v.toInt(); | 532 | return toInt() < v.toInt(); |
533 | case Invalid: | 533 | case Invalid: |
534 | default: | 534 | default: |
535 | break; | 535 | break; |
536 | } | 536 | } |
537 | return FALSE; | 537 | return FALSE; |
538 | } | 538 | } |
539 | 539 | ||
540 | bool TVVariant::operator>( const TVVariant &v ) const | 540 | bool TVVariant::operator>( const TVVariant &v ) const |
541 | { | 541 | { |
542 | switch(d->typ) { | 542 | switch(d->typ) { |
543 | case String: | 543 | case String: |
544 | return toString().lower() > v.toString().lower(); | 544 | return toString().lower() > v.toString().lower(); |
545 | case Date: | 545 | case Date: |
546 | return toDate() > v.toDate(); | 546 | return toDate() > v.toDate(); |
547 | case Time: | 547 | case Time: |
548 | return toTime() > v.toTime(); | 548 | return toTime() > v.toTime(); |
549 | case Int: | 549 | case Int: |
550 | return toInt() > v.toInt(); | 550 | return toInt() > v.toInt(); |
551 | case Invalid: | 551 | case Invalid: |
552 | default: | 552 | default: |
553 | break; | 553 | break; |
554 | } | 554 | } |
555 | return FALSE; | 555 | return FALSE; |
556 | } | 556 | } |
557 | 557 | ||
558 | /*! True if n is closer to this than o */ | 558 | /*! True if n is closer to this than o */ |
559 | bool TVVariant::closer(TVVariant n, TVVariant o) | 559 | bool TVVariant::closer(TVVariant n, TVVariant o) |
560 | { | 560 | { |
561 | /* Nothing is close to an invalid, so nothing can be closer */ | 561 | /* Nothing is close to an invalid, so nothing can be closer */ |
562 | if(d->typ == Invalid) | 562 | if(d->typ == Invalid) |
563 | return FALSE; | 563 | return FALSE; |
564 | 564 | ||
565 | /* can't be closer if of different type */ | 565 | /* can't be closer if of different type */ |
566 | if(n.type() != type()) | 566 | if(n.type() != type()) |
567 | return FALSE; | 567 | return FALSE; |
568 | 568 | ||
569 | /* if new shares type, and old doesn't, then new is closer */ | 569 | /* if new shares type, and old doesn't, then new is closer */ |
570 | if(o.type() != type()) | 570 | if(o.type() != type()) |
571 | return TRUE; | 571 | return TRUE; |
572 | 572 | ||
573 | switch(type()){ | 573 | switch(type()){ |
574 | case String: { | 574 | case String: { |
575 | /* case for strings is close is a substring.. closer is | 575 | /* case for strings is close is a substring.. closer is |
576 | * earlier alphabetically */ | 576 | * earlier alphabetically */ |
577 | QString qs1 = n.toString().lower(); | 577 | QString qs1 = n.toString().lower(); |
578 | QString qs2 = o.toString().lower(); | 578 | QString qs2 = o.toString().lower(); |
579 | QString qsv = toString().lower(); | 579 | QString qsv = toString().lower(); |
580 | 580 | ||
581 | if (!qs1.startsWith(qsv)) | 581 | if (!qs1.startsWith(qsv)) |
582 | return FALSE; | 582 | return FALSE; |
583 | 583 | ||
584 | /* contains sub-str, if later than is not closer */ | 584 | /* contains sub-str, if later than is not closer */ |
585 | if(QString::compare(qs1, qs2) > 0) | 585 | if(QString::compare(qs1, qs2) > 0) |
586 | return FALSE; | 586 | return FALSE; |
587 | return TRUE; | 587 | return TRUE; |
588 | } | 588 | } |
589 | case Int: { | 589 | case Int: { |
590 | /* case for int is smallest absolute difference */ | 590 | /* case for int is smallest absolute difference */ |
591 | int i1 = n.toInt(); | 591 | int i1 = n.toInt(); |
592 | int i2 = o.toInt(); | 592 | int i2 = o.toInt(); |
593 | int iv = toInt(); | 593 | int iv = toInt(); |
594 | 594 | ||
595 | int diff1 = (i1 - iv); | 595 | int diff1 = (i1 - iv); |
596 | if (diff1 < 0) | 596 | if (diff1 < 0) |
597 | diff1 = -diff1; | 597 | diff1 = -diff1; |
598 | int diff2 = (i2 - iv); | 598 | int diff2 = (i2 - iv); |
599 | if (diff2 < 0) | 599 | if (diff2 < 0) |
600 | diff2 = -diff2; | 600 | diff2 = -diff2; |
601 | 601 | ||
602 | if (diff1 < diff2) | 602 | if (diff1 < diff2) |
603 | return TRUE; | 603 | return TRUE; |
604 | return FALSE; | 604 | return FALSE; |
605 | } | 605 | } |
606 | case Date: { | 606 | case Date: { |
607 | QDate i1 = n.toDate(); | 607 | QDate i1 = n.toDate(); |
608 | QDate i2 = o.toDate(); | 608 | QDate i2 = o.toDate(); |
609 | QDate iv = toDate(); | 609 | QDate iv = toDate(); |
610 | 610 | ||
611 | /* definition of closer is the least difference in days */ | 611 | /* definition of closer is the least difference in days */ |
612 | int diff1 = i1.daysTo(iv); | 612 | int diff1 = i1.daysTo(iv); |
613 | if (diff1 < 0) | 613 | if (diff1 < 0) |
614 | diff1 = -diff1; | 614 | diff1 = -diff1; |
615 | int diff2 = i2.daysTo(iv); | 615 | int diff2 = i2.daysTo(iv); |
616 | if (diff2 < 0) | 616 | if (diff2 < 0) |
617 | diff2 = -diff2; | 617 | diff2 = -diff2; |
618 | 618 | ||
619 | if (diff1 < diff2) | 619 | if (diff1 < diff2) |
620 | return TRUE; | 620 | return TRUE; |
621 | return FALSE; | 621 | return FALSE; |
622 | } | 622 | } |
623 | case Time: { | 623 | case Time: { |
624 | QTime i1 = n.toTime(); | 624 | QTime i1 = n.toTime(); |
625 | QTime i2 = o.toTime(); | 625 | QTime i2 = o.toTime(); |
626 | QTime iv = toTime(); | 626 | QTime iv = toTime(); |
627 | 627 | ||
628 | /* definition of closer is the least difference in days */ | 628 | /* definition of closer is the least difference in days */ |
629 | int diff1 = i1.msecsTo(iv); | 629 | int diff1 = i1.msecsTo(iv); |
630 | if (diff1 < 0) | 630 | if (diff1 < 0) |
631 | diff1 = -diff1; | 631 | diff1 = -diff1; |
632 | int diff2 = i2.msecsTo(iv); | 632 | int diff2 = i2.msecsTo(iv); |
633 | if (diff2 < 0) | 633 | if (diff2 < 0) |
634 | diff2 = -diff2; | 634 | diff2 = -diff2; |
635 | if (diff1 < diff2) | 635 | if (diff1 < diff2) |
636 | return TRUE; | 636 | return TRUE; |
637 | return FALSE; | 637 | return FALSE; |
638 | } | 638 | } |
639 | default: | 639 | default: |
640 | /* don't know how to do 'closer' on this type, hence never closer | 640 | /* don't know how to do 'closer' on this type, hence never closer |
641 | * or even close */ | 641 | * or even close */ |
642 | break; | 642 | break; |
643 | } | 643 | } |
644 | return FALSE; | 644 | return FALSE; |
645 | } | 645 | } |
646 | 646 | ||
647 | /*! True if n is close to this */ | 647 | /*! True if n is close to this */ |
648 | bool TVVariant::close(TVVariant n) | 648 | bool TVVariant::close(TVVariant n) |
649 | { | 649 | { |
650 | /* Nothing is close to an invalid, so nothing can be closer */ | 650 | /* Nothing is close to an invalid, so nothing can be closer */ |
651 | if(type() == Invalid) | 651 | if(type() == Invalid) |
652 | return FALSE; | 652 | return FALSE; |
653 | 653 | ||
654 | /* can't be close if of different type */ | 654 | /* can't be close if of different type */ |
655 | if(n.type() != type()) | 655 | if(n.type() != type()) |
656 | return FALSE; | 656 | return FALSE; |
657 | 657 | ||
658 | switch(type()){ | 658 | switch(type()){ |
659 | case String: { | 659 | case String: { |
660 | /* case for strings is close is a substring.. closer is | 660 | /* case for strings is close is a substring.. closer is |
661 | * earlier alphabetically */ | 661 | * earlier alphabetically */ |
662 | QString qs1 = n.toString().lower(); | 662 | QString qs1 = n.toString().lower(); |
663 | QString qsv = toString().lower(); | 663 | QString qsv = toString().lower(); |
664 | 664 | ||
665 | if (!qs1.startsWith(qsv)) | 665 | if (!qs1.startsWith(qsv)) |
666 | return FALSE; | 666 | return FALSE; |
667 | return TRUE; | 667 | return TRUE; |
668 | } | 668 | } |
669 | case Int: | 669 | case Int: |
670 | case Date: | 670 | case Date: |
671 | case Time: | 671 | case Time: |
672 | return TRUE; | 672 | return TRUE; |
673 | default: | 673 | default: |
674 | /* don't know how to do 'closer' on this type, hence never closer | 674 | /* don't know how to do 'closer' on this type, hence never closer |
675 | * or even close */ | 675 | * or even close */ |
676 | break; | 676 | break; |
677 | } | 677 | } |
678 | return FALSE; | 678 | return FALSE; |
679 | } | 679 | } |
680 | 680 | ||
681 | /*! | 681 | /*! |
682 | \class Key | 682 | \class Key |
683 | \brief document me! | 683 | \brief document me! |
684 | 684 | ||
685 | document me! | 685 | document me! |
686 | */ | 686 | */ |
687 | 687 | ||
688 | Key::Key() : kname(), kexample(), kflags(0) { } | 688 | Key::Key() : kname(), kexample(), kflags(0) { } |
689 | 689 | ||
690 | Key::Key(QString name, TVVariant example, int flags) : | 690 | Key::Key(QString name, TVVariant example, int flags) : |
691 | kname(name), kexample(example), kflags(flags) { } | 691 | kname(name), kexample(example), kflags(flags) { } |
692 | 692 | ||
693 | Key::Key(const Key &other) | 693 | Key::Key(const Key &other) |
694 | { | 694 | { |
695 | kname = other.kname; | 695 | kname = other.kname; |
696 | kexample = other.kexample; | 696 | kexample = other.kexample; |
697 | kflags = other.kflags; | 697 | kflags = other.kflags; |
698 | } | 698 | } |
699 | 699 | ||
700 | Key& Key::operator=(const Key& key) | 700 | Key& Key::operator=(const Key& key) |
701 | { | 701 | { |
702 | kname = key.kname; | 702 | kname = key.kname; |
703 | kexample = key.kexample; | 703 | kexample = key.kexample; |
704 | kflags = key.kflags; | 704 | kflags = key.kflags; |
705 | return *this; | 705 | return *this; |
706 | } | 706 | } |
707 | 707 | ||
708 | QString Key::name() const | 708 | QString Key::name() const |
709 | { | 709 | { |
710 | return QString(kname); | 710 | return QString(kname); |
711 | } | 711 | } |
712 | 712 | ||
713 | TVVariant Key::example() const | 713 | TVVariant Key::example() const |
714 | { | 714 | { |
715 | return TVVariant(kexample); | 715 | return TVVariant(kexample); |
716 | } | 716 | } |
717 | 717 | ||
718 | TVVariant::KeyType Key::type() const | 718 | TVVariant::KeyType Key::type() const |
719 | { | 719 | { |
720 | return kexample.type(); | 720 | return kexample.type(); |
721 | } | 721 | } |
722 | 722 | ||
723 | void Key::setName(const QString &name) | 723 | void Key::setName(const QString &name) |
724 | { | 724 | { |
725 | kname = QString(name); | 725 | kname = QString(name); |
726 | } | 726 | } |
727 | 727 | ||
728 | void Key::setExample(const TVVariant &e) | 728 | void Key::setExample(const TVVariant &e) |
729 | { | 729 | { |
730 | kexample = TVVariant(e); | 730 | kexample = TVVariant(e); |
731 | } | 731 | } |
732 | 732 | ||
733 | int Key::flags() const | 733 | int Key::flags() const |
734 | { | 734 | { |
735 | return kflags; | 735 | return kflags; |
736 | } | 736 | } |
737 | 737 | ||
738 | void Key::setFlags(int fl) | 738 | void Key::setFlags(int fl) |
739 | { | 739 | { |
740 | kflags = fl; | 740 | kflags = fl; |
741 | } | 741 | } |
742 | 742 | ||
743 | bool Key::delFlag() const | 743 | bool Key::delFlag() const |
744 | { | 744 | { |
745 | if(kflags & del_flag) | 745 | if(kflags & del_flag) |
746 | return TRUE; | 746 | return TRUE; |
747 | return FALSE; | 747 | return FALSE; |
748 | } | 748 | } |
749 | 749 | ||
750 | bool Key::newFlag() const | 750 | bool Key::newFlag() const |
751 | { | 751 | { |
752 | if(kflags & new_flag) | 752 | if(kflags & new_flag) |
753 | return TRUE; | 753 | return TRUE; |
754 | return FALSE; | 754 | return FALSE; |
755 | } | 755 | } |
756 | 756 | ||
757 | void Key::setDelFlag(bool v) | 757 | void Key::setDelFlag(bool v) |
758 | { | 758 | { |
759 | if(delFlag() != v) | 759 | if(delFlag() != v) |
760 | kflags = kflags ^ del_flag; | 760 | kflags = kflags ^ del_flag; |
761 | } | 761 | } |
762 | 762 | ||
763 | void Key::setNewFlag(bool v) | 763 | void Key::setNewFlag(bool v) |
764 | { | 764 | { |
765 | if(newFlag() != v) | 765 | if(newFlag() != v) |
766 | kflags = kflags ^ new_flag; | 766 | kflags = kflags ^ new_flag; |
767 | } | 767 | } |
768 | 768 | ||
769 | /*! | 769 | /*! |
770 | \class KeyList | 770 | \class KeyList |
771 | \brief A represntation of keys used for a table. | 771 | \brief A represntation of keys used for a table. |
772 | 772 | ||
773 | The KeyList class is used to store the representation of keys used in table | 773 | The KeyList class is used to store the representation of keys used in table |
774 | headings by DBStore. It stores the names and types of the keys | 774 | headings by DBStore. It stores the names and types of the keys |
775 | */ | 775 | */ |
776 | 776 | ||
777 | /*! | 777 | /*! |
778 | Constructs a KeyList | 778 | Constructs a KeyList |
779 | */ | 779 | */ |
780 | KeyList::KeyList() : QIntDict<Key>(20) | 780 | KeyList::KeyList() : QIntDict<Key>(20) |
781 | { | 781 | { |
782 | setAutoDelete(TRUE); | 782 | setAutoDelete(TRUE); |
783 | } | 783 | } |
784 | 784 | ||
785 | /* Should be deep copy, but isn't */ | 785 | /* Should be deep copy, but isn't */ |
786 | KeyList::KeyList(const KeyList &k) : QIntDict<Key>(k) | 786 | KeyList::KeyList(const KeyList &k) : QIntDict<Key>(k) |
787 | { | 787 | { |
788 | KeyListIterator it(k); | 788 | KeyListIterator it(k); |
789 | while(it.current()) { | 789 | while(it.current()) { |
790 | replace(it.currentKey(), new Key(*it.current())); | 790 | replace(it.currentKey(), new Key(*it.current())); |
791 | ++it; | 791 | ++it; |
792 | } | 792 | } |
793 | 793 | ||
794 | setAutoDelete(TRUE); | 794 | setAutoDelete(TRUE); |
795 | } | 795 | } |
796 | 796 | ||
797 | /*! | 797 | /*! |
798 | Destroys a KeyList | 798 | Destroys a KeyList |
799 | */ | 799 | */ |
800 | KeyList::~KeyList() { | 800 | KeyList::~KeyList() { |
801 | } | 801 | } |
802 | 802 | ||
803 | /* Do a comparision base on Keys */ | 803 | /* Do a comparision base on Keys */ |
804 | bool KeyList::operator!=(const KeyList &other) | 804 | bool KeyList::operator!=(const KeyList &other) |
805 | { | 805 | { |
806 | KeyListIterator it(*this); | 806 | KeyListIterator it(*this); |
807 | 807 | ||
808 | if (other.getNumFields() != getNumFields()) | 808 | if (other.getNumFields() != getNumFields()) |
809 | return TRUE; | 809 | return TRUE; |
810 | 810 | ||
811 | while(it.current()) { | 811 | while(it.current()) { |
812 | //it.currentKey(), it.current(); | 812 | //it.currentKey(), it.current(); |
813 | if (other.getKeyName(it.currentKey()) != getKeyName(it.currentKey())) | 813 | if (other.getKeyName(it.currentKey()) != getKeyName(it.currentKey())) |
814 | return TRUE; | 814 | return TRUE; |
815 | if (other.getKeyType(it.currentKey()) != getKeyType(it.currentKey())) | 815 | if (other.getKeyType(it.currentKey()) != getKeyType(it.currentKey())) |
816 | return TRUE; | 816 | return TRUE; |
817 | ++it; | 817 | ++it; |
818 | } | 818 | } |
819 | return FALSE; | 819 | return FALSE; |
820 | } | 820 | } |
821 | 821 | ||
822 | /*! | 822 | /*! |
823 | Returns the number of keys stored in the KeyList | 823 | Returns the number of keys stored in the KeyList |
824 | */ | 824 | */ |
825 | int KeyList::getNumFields() const | 825 | int KeyList::getNumFields() const |
826 | { | 826 | { |
827 | return count(); | 827 | return count(); |
828 | } | 828 | } |
829 | 829 | ||
830 | /*! | 830 | /*! |
831 | Adds a new key to the KeyList | 831 | Adds a new key to the KeyList |
832 | 832 | ||
833 | \param name the name of the new key | 833 | \param name the name of the new key |
834 | \param type the type of the new key | 834 | \param type the type of the new key |
835 | */ | 835 | */ |
836 | int KeyList::addKey(QString name, TVVariant example) | 836 | int KeyList::addKey(QString name, TVVariant example) |
837 | { | 837 | { |
838 | int i = count(); | 838 | int i = count(); |
839 | while(find(i) && (i > -1)) | 839 | while(find(i) && (i > -1)) |
840 | i--; | 840 | i--; |
841 | replace(i, new Key(name, example, 0)); | 841 | replace(i, new Key(name, example, 0)); |
842 | return i; | 842 | return i; |
843 | } | 843 | } |
844 | 844 | ||
845 | int KeyList::addKey(QString name, TVVariant::KeyType type) | 845 | int KeyList::addKey(QString name, TVVariant::KeyType type) |
846 | { | 846 | { |
847 | /* generate a valid type for the example? */ | 847 | /* generate a valid type for the example? */ |
848 | TVVariant e = TVVariant("0"); | 848 | TVVariant e = TVVariant("0"); |
849 | switch(type) { | 849 | switch(type) { |
850 | case TVVariant::String: | 850 | case TVVariant::String: |
851 | return addKey(name, TVVariant("<undefined>").asString()); | 851 | return addKey(name, TVVariant("<undefined>").asString()); |
852 | break; | 852 | break; |
853 | case TVVariant::Date: | 853 | case TVVariant::Date: |
854 | return addKey(name, TVVariant(QDate::currentDate()).asDate()); | 854 | return addKey(name, TVVariant(QDate::currentDate()).asDate()); |
855 | break; | 855 | break; |
856 | case TVVariant::Time: | 856 | case TVVariant::Time: |
857 | return addKey(name, TVVariant(QTime(0,0,0)).toTime()); | 857 | return addKey(name, TVVariant(QTime(0,0,0)).toTime()); |
858 | break; | 858 | break; |
859 | case TVVariant::Int: | 859 | case TVVariant::Int: |
860 | return addKey(name, TVVariant(0).toInt()); | 860 | return addKey(name, TVVariant(0).toInt()); |
861 | break; | 861 | break; |
862 | default: | 862 | default: |
863 | qWarning(QObject::tr("KeyList::addKey() Cannot make default " | 863 | owarn << "KeyList::addKey() Cannot make default value for type " << type << ", Key not added." << oendl; |
864 | "value for type %1, Key not added.").arg(type)); | ||
865 | break; | 864 | break; |
866 | } | 865 | } |
867 | return -1; | 866 | return -1; |
868 | } | 867 | } |
869 | 868 | ||
870 | void KeyList::setKeyFlags(int i, int flag) | 869 | void KeyList::setKeyFlags(int i, int flag) |
871 | { | 870 | { |
872 | if(find(i)) | 871 | if(find(i)) |
873 | find(i)->setFlags(flag); | 872 | find(i)->setFlags(flag); |
874 | } | 873 | } |
875 | 874 | ||
876 | int KeyList::getKeyFlags(int i) const | 875 | int KeyList::getKeyFlags(int i) const |
877 | { | 876 | { |
878 | if(find(i)) | 877 | if(find(i)) |
879 | return find(i)->flags(); | 878 | return find(i)->flags(); |
880 | return 0; | 879 | return 0; |
881 | } | 880 | } |
882 | 881 | ||
883 | bool KeyList::checkNewFlag(int i) const | 882 | bool KeyList::checkNewFlag(int i) const |
884 | { | 883 | { |
885 | if (find(i)) | 884 | if (find(i)) |
886 | return find(i)->newFlag(); | 885 | return find(i)->newFlag(); |
887 | return false; | 886 | return false; |
888 | } | 887 | } |
889 | 888 | ||
890 | void KeyList::setNewFlag(int i, bool f) | 889 | void KeyList::setNewFlag(int i, bool f) |
891 | { | 890 | { |
892 | if(!find(i)) | 891 | if(!find(i)) |
893 | return; | 892 | return; |
894 | find(i)->setNewFlag(f); | 893 | find(i)->setNewFlag(f); |
895 | } | 894 | } |
896 | 895 | ||
897 | bool KeyList::checkDeleteFlag(int i) const | 896 | bool KeyList::checkDeleteFlag(int i) const |
898 | { | 897 | { |
899 | if (find(i)) | 898 | if (find(i)) |
900 | return find(i)->delFlag(); | 899 | return find(i)->delFlag(); |
901 | return false; | 900 | return false; |
902 | } | 901 | } |
903 | 902 | ||
904 | void KeyList::setDeleteFlag(int i, bool f) | 903 | void KeyList::setDeleteFlag(int i, bool f) |
905 | { | 904 | { |
906 | if(!find(i)) | 905 | if(!find(i)) |
907 | return; | 906 | return; |
908 | find(i)->setDelFlag(f); | 907 | find(i)->setDelFlag(f); |
909 | } | 908 | } |
910 | 909 | ||
911 | /*! | 910 | /*! |
912 | Returns the name of the key at index i | 911 | Returns the name of the key at index i |
913 | */ | 912 | */ |
914 | QString KeyList::getKeyName(int i) const | 913 | QString KeyList::getKeyName(int i) const |
915 | { | 914 | { |
916 | if (find (i)) | 915 | if (find (i)) |
917 | return find(i)->name(); | 916 | return find(i)->name(); |
918 | return QString(); | 917 | return QString(); |
919 | } | 918 | } |
920 | 919 | ||
921 | void KeyList::setKeyName(int i, const QString &n) | 920 | void KeyList::setKeyName(int i, const QString &n) |
922 | { | 921 | { |
923 | if(find(i)) | 922 | if(find(i)) |
924 | find(i)->setName(n); | 923 | find(i)->setName(n); |
925 | } | 924 | } |
926 | 925 | ||
927 | /*! | 926 | /*! |
928 | Returns the type of the key at index i | 927 | Returns the type of the key at index i |
929 | */ | 928 | */ |
930 | TVVariant::KeyType KeyList::getKeyType(int i) const | 929 | TVVariant::KeyType KeyList::getKeyType(int i) const |
931 | { | 930 | { |
932 | if(find(i)) | 931 | if(find(i)) |
933 | return find(i)->type(); | 932 | return find(i)->type(); |
934 | return TVVariant::Invalid; | 933 | return TVVariant::Invalid; |
935 | } | 934 | } |
936 | 935 | ||
937 | void KeyList::setKeyType(int i, TVVariant::KeyType t) | 936 | void KeyList::setKeyType(int i, TVVariant::KeyType t) |
938 | { | 937 | { |
939 | if(!find(i)) | 938 | if(!find(i)) |
940 | return; | 939 | return; |
941 | switch(t) { | 940 | switch(t) { |
942 | case TVVariant::String: | 941 | case TVVariant::String: |
943 | find(i)->setExample(TVVariant(QString("default"))); | 942 | find(i)->setExample(TVVariant(QString("default"))); |
944 | return; | 943 | return; |
945 | case TVVariant::Int: | 944 | case TVVariant::Int: |
946 | find(i)->setExample(TVVariant(int(0))); | 945 | find(i)->setExample(TVVariant(int(0))); |
947 | return; | 946 | return; |
948 | case TVVariant::Date: | 947 | case TVVariant::Date: |
949 | find(i)->setExample(TVVariant(QDate::currentDate())); | 948 | find(i)->setExample(TVVariant(QDate::currentDate())); |
950 | return; | 949 | return; |
951 | case TVVariant::Time: | 950 | case TVVariant::Time: |
952 | find(i)->setExample(TVVariant(QTime(0,0,0,0))); | 951 | find(i)->setExample(TVVariant(QTime(0,0,0,0))); |
953 | return; | 952 | return; |
954 | default: | 953 | default: |
955 | break; | 954 | break; |
956 | } | 955 | } |
957 | return; | 956 | return; |
958 | } | 957 | } |
959 | 958 | ||
960 | TVVariant KeyList::getKeyExample(int i) const | 959 | TVVariant KeyList::getKeyExample(int i) const |
961 | { | 960 | { |
962 | if(find(i)) | 961 | if(find(i)) |
963 | return find(i)->example(); | 962 | return find(i)->example(); |
964 | return TVVariant(); | 963 | return TVVariant(); |
965 | } | 964 | } |
966 | 965 | ||
967 | void KeyList::setKeyExample(int i, TVVariant example) | 966 | void KeyList::setKeyExample(int i, TVVariant example) |
968 | { | 967 | { |
969 | if(find(i)) | 968 | if(find(i)) |
970 | find(i)->setExample(example); | 969 | find(i)->setExample(example); |
971 | } | 970 | } |
972 | 971 | ||
973 | /*! | 972 | /*! |
974 | Returns the index of the key with name q | 973 | Returns the index of the key with name q |
975 | */ | 974 | */ |
976 | int KeyList::getKeyIndex(QString q) const | 975 | int KeyList::getKeyIndex(QString q) const |
977 | { | 976 | { |
978 | KeyListIterator it(*this); | 977 | KeyListIterator it(*this); |
979 | 978 | ||
980 | while(it.current()) { | 979 | while(it.current()) { |
981 | if(it.current()->name() == q) | 980 | if(it.current()->name() == q) |
982 | return it.currentKey(); | 981 | return it.currentKey(); |
983 | ++it; | 982 | ++it; |
984 | } | 983 | } |
985 | return -1; | 984 | return -1; |
986 | } | 985 | } |
987 | 986 | ||
988 | bool KeyList::validIndex(int i) const | 987 | bool KeyList::validIndex(int i) const |
989 | { | 988 | { |
990 | if(!find(i)) | 989 | if(!find(i)) |
991 | return FALSE; | 990 | return FALSE; |
992 | if(find(i)->delFlag()) | 991 | if(find(i)->delFlag()) |
993 | return FALSE; | 992 | return FALSE; |
994 | return TRUE; | 993 | return TRUE; |
995 | } | 994 | } |
996 | 995 | ||
997 | QDataStream &operator<<( QDataStream &s, const KeyList &k) | 996 | QDataStream &operator<<( QDataStream &s, const KeyList &k) |
998 | { | 997 | { |
999 | s << k.getNumFields(); | 998 | s << k.getNumFields(); |
1000 | 999 | ||
1001 | KeyListIterator it(k); | 1000 | KeyListIterator it(k); |
1002 | 1001 | ||
1003 | while(it.current()) { | 1002 | while(it.current()) { |
1004 | s << (Q_UINT16)it.currentKey(); | 1003 | s << (Q_UINT16)it.currentKey(); |
1005 | s << it.current()->name(); | 1004 | s << it.current()->name(); |
1006 | s << it.current()->example(); | 1005 | s << it.current()->example(); |
1007 | s << (Q_UINT16)it.current()->flags(); | 1006 | s << (Q_UINT16)it.current()->flags(); |
1008 | ++it; | 1007 | ++it; |
1009 | } | 1008 | } |
1010 | return s; | 1009 | return s; |
1011 | } | 1010 | } |
1012 | 1011 | ||
1013 | QDataStream &operator>>( QDataStream &s, KeyList &k) | 1012 | QDataStream &operator>>( QDataStream &s, KeyList &k) |
1014 | { | 1013 | { |
1015 | int i; | 1014 | int i; |
1016 | int size; | 1015 | int size; |
1017 | int index = 0; | 1016 | int index = 0; |
1018 | int flags = 0; | 1017 | int flags = 0; |
1019 | TVVariant type = TVVariant(); | 1018 | TVVariant type = TVVariant(); |
1020 | QString name; | 1019 | QString name; |
1021 | 1020 | ||
1022 | s >> size; | 1021 | s >> size; |
1023 | 1022 | ||
1024 | for (i=0; i < size; i++) { | 1023 | for (i=0; i < size; i++) { |
1025 | s >> (Q_UINT16 &)index; | 1024 | s >> (Q_UINT16 &)index; |
1026 | s >> name; | 1025 | s >> name; |
1027 | s >> type; | 1026 | s >> type; |
1028 | s >> (Q_UINT16 &)flags; | 1027 | s >> (Q_UINT16 &)flags; |
1029 | k.replace(index, new Key(name, type, flags)); | 1028 | k.replace(index, new Key(name, type, flags)); |
1030 | } | 1029 | } |
1031 | return s; | 1030 | return s; |
1032 | } | 1031 | } |
1033 | 1032 | ||
1034 | /*! | 1033 | /*! |
1035 | \class DataElem | 1034 | \class DataElem |
1036 | \brief A class representing a single row or element of a table in a DBStore | 1035 | \brief A class representing a single row or element of a table in a DBStore |
1037 | 1036 | ||
1038 | This class holds the data of a row in a table. | 1037 | This class holds the data of a row in a table. |
1039 | */ | 1038 | */ |
1040 | 1039 | ||
1041 | 1040 | ||
1042 | /*! | 1041 | /*! |
1043 | Constructs a DataElem. This function needs a container because the | 1042 | Constructs a DataElem. This function needs a container because the |
1044 | size, types of keys and primary key are all defined by the containing | 1043 | size, types of keys and primary key are all defined by the containing |
1045 | database | 1044 | database |
1046 | */ | 1045 | */ |
1047 | DataElem::DataElem(DBStore *c) : values(20) | 1046 | DataElem::DataElem(DBStore *c) : values(20) |
1048 | { | 1047 | { |
1049 | int size; | 1048 | int size; |
1050 | contained = c; | 1049 | contained = c; |
1051 | size = c->getNumFields(); | 1050 | size = c->getNumFields(); |
1052 | values.setAutoDelete(TRUE); | 1051 | values.setAutoDelete(TRUE); |
1053 | } | 1052 | } |
1054 | 1053 | ||
1055 | /*! | 1054 | /*! |
1056 | Destroys a DataElem and frees memory used by the DataElem | 1055 | Destroys a DataElem and frees memory used by the DataElem |
1057 | */ | 1056 | */ |
1058 | DataElem::~DataElem() { | 1057 | DataElem::~DataElem() { |
1059 | } | 1058 | } |
1060 | 1059 | ||
1061 | 1060 | ||
1062 | 1061 | ||
1063 | QDataStream &operator<<( QDataStream &s, const DataElem &d) | 1062 | QDataStream &operator<<( QDataStream &s, const DataElem &d) |
1064 | { | 1063 | { |
1065 | int size = d.getNumFields(); | 1064 | int size = d.getNumFields(); |
1066 | 1065 | ||
1067 | s << size; /* redundent data but makes streaming easier */ | 1066 | s << size; /* redundent data but makes streaming easier */ |
1068 | KeyList k = d.getKeys(); | 1067 | KeyList k = d.getKeys(); |
1069 | 1068 | ||
1070 | KeyListIterator it(k); | 1069 | KeyListIterator it(k); |
1071 | 1070 | ||
1072 | while(it.current()) { | 1071 | while(it.current()) { |
1073 | s << (Q_UINT16)it.currentKey(); | 1072 | s << (Q_UINT16)it.currentKey(); |
1074 | s << d.getField(it.currentKey()); | 1073 | s << d.getField(it.currentKey()); |
1075 | ++it; | 1074 | ++it; |
1076 | } | 1075 | } |
1077 | return s; | 1076 | return s; |
1078 | } | 1077 | } |
1079 | 1078 | ||
1080 | QDataStream &operator>>( QDataStream &s, DataElem &d) | 1079 | QDataStream &operator>>( QDataStream &s, DataElem &d) |
1081 | { | 1080 | { |
1082 | int i; | 1081 | int i; |
1083 | int size; | 1082 | int size; |
1084 | TVVariant t; | 1083 | TVVariant t; |
1085 | Q_UINT16 index = 0; | 1084 | Q_UINT16 index = 0; |
1086 | 1085 | ||
1087 | s >> size; /* redundent data but makes streaming easier */ | 1086 | s >> size; /* redundent data but makes streaming easier */ |
1088 | if (size != d.getNumFields()) { | 1087 | if (size != d.getNumFields()) { |
1089 | owarn << "DataSize mis-match" << oendl; | 1088 | owarn << "DataSize mis-match" << oendl; |
1090 | return s; /* sanity check failed.. don't load */ | 1089 | return s; /* sanity check failed.. don't load */ |
1091 | } | 1090 | } |
1092 | 1091 | ||
1093 | for(i = 0; i < size; i++) { | 1092 | for(i = 0; i < size; i++) { |
1094 | s >> index; | 1093 | s >> index; |
1095 | s >> t; | 1094 | s >> t; |
1096 | d.setField(index, t); | 1095 | d.setField(index, t); |
1097 | } | 1096 | } |
1098 | return s; | 1097 | return s; |
1099 | } | 1098 | } |
1100 | 1099 | ||
1101 | /*! Returns the number of possible (not valid) fields in the data element */ | 1100 | /*! Returns the number of possible (not valid) fields in the data element */ |
1102 | int DataElem::getNumFields() const | 1101 | int DataElem::getNumFields() const |
1103 | { | 1102 | { |
1104 | return contained->getNumFields(); | 1103 | return contained->getNumFields(); |
1105 | } | 1104 | } |
1106 | 1105 | ||
1107 | KeyList DataElem::getKeys() const | 1106 | KeyList DataElem::getKeys() const |
1108 | { | 1107 | { |
1109 | return *(contained->getKeys()); | 1108 | return *(contained->getKeys()); |
1110 | } | 1109 | } |
1111 | 1110 | ||
1112 | /*! | 1111 | /*! |
1113 | This function determines whether field index i of the element has been | 1112 | This function determines whether field index i of the element has been |
1114 | set yet. | 1113 | set yet. |
1115 | 1114 | ||
1116 | \return A boolean value that is TRUE if the specfied field of this | 1115 | \return A boolean value that is TRUE if the specfied field of this |
1117 | element has been set and FALSE if the field has not yet been set | 1116 | element has been set and FALSE if the field has not yet been set |
1118 | */ | 1117 | */ |
1119 | bool DataElem::hasValidValue(int i) const | 1118 | bool DataElem::hasValidValue(int i) const |
1120 | { | 1119 | { |
1121 | if(!values.find(i)) | 1120 | if(!values.find(i)) |
1122 | return FALSE; | 1121 | return FALSE; |
1123 | if(!contained->getKeys()->validIndex(i)) | 1122 | if(!contained->getKeys()->validIndex(i)) |
1124 | return FALSE; | 1123 | return FALSE; |
1125 | return values.find(i)->isValid(); | 1124 | return values.find(i)->isValid(); |
1126 | } | 1125 | } |
1127 | 1126 | ||
1128 | /*! | 1127 | /*! |
1129 | This function determines whether field name qs of the element has been | 1128 | This function determines whether field name qs of the element has been |
1130 | set yet. | 1129 | set yet. |
1131 | 1130 | ||
1132 | \return A boolean value that is TRUE if the specfied field of this | 1131 | \return A boolean value that is TRUE if the specfied field of this |
1133 | element has been set and FALSE if the field has not yet been set | 1132 | element has been set and FALSE if the field has not yet been set |
1134 | */ | 1133 | */ |
1135 | bool DataElem::hasValidValue(QString qs) const | 1134 | bool DataElem::hasValidValue(QString qs) const |
1136 | { | 1135 | { |
1137 | int i = contained->getKeyIndex(qs); | 1136 | int i = contained->getKeyIndex(qs); |
1138 | return hasValidValue(i); | 1137 | return hasValidValue(i); |
1139 | } | 1138 | } |
1140 | 1139 | ||
1141 | /*! returns the type of the field specified by index i */ | 1140 | /*! returns the type of the field specified by index i */ |
1142 | TVVariant::KeyType DataElem::getFieldType(int i) const | 1141 | TVVariant::KeyType DataElem::getFieldType(int i) const |
1143 | { | 1142 | { |
1144 | return contained->getKeyType(i); | 1143 | return contained->getKeyType(i); |
1145 | } | 1144 | } |
1146 | 1145 | ||
1147 | /*! returns the type of the field specified by name qs */ | 1146 | /*! returns the type of the field specified by name qs */ |
1148 | TVVariant::KeyType DataElem::getFieldType(QString qs) const | 1147 | TVVariant::KeyType DataElem::getFieldType(QString qs) const |
1149 | { | 1148 | { |
1150 | int i = contained->getKeyIndex(qs); | 1149 | int i = contained->getKeyIndex(qs); |
1151 | return contained->getKeyType(i); | 1150 | return contained->getKeyType(i); |
1152 | } | 1151 | } |
1153 | 1152 | ||
1154 | /*! | 1153 | /*! |
1155 | returns a pointer to the data stored in field index i for this | 1154 | returns a pointer to the data stored in field index i for this |
1156 | data element, (value may not be valid) | 1155 | data element, (value may not be valid) |
1157 | */ | 1156 | */ |
1158 | TVVariant DataElem::getField(int i) const | 1157 | TVVariant DataElem::getField(int i) const |
1159 | { | 1158 | { |
1160 | if(hasValidValue(i)) | 1159 | if(hasValidValue(i)) |
1161 | return TVVariant(*values.find(i)); | 1160 | return TVVariant(*values.find(i)); |
1162 | return TVVariant(); | 1161 | return TVVariant(); |
1163 | } | 1162 | } |
1164 | 1163 | ||
1165 | /*! | 1164 | /*! |
1166 | returns a pointer to the data stored in field name qs for this | 1165 | returns a pointer to the data stored in field name qs for this |
1167 | data element, (value may not be valid) | 1166 | data element, (value may not be valid) |
1168 | */ | 1167 | */ |
1169 | TVVariant DataElem::getField(QString qs) const | 1168 | TVVariant DataElem::getField(QString qs) const |
1170 | { | 1169 | { |
1171 | int i = contained->getKeyIndex(qs); | 1170 | int i = contained->getKeyIndex(qs); |
1172 | return getField(i); | 1171 | return getField(i); |
1173 | } | 1172 | } |
1174 | 1173 | ||
1175 | /*! | 1174 | /*! |
1176 | Sets the value of the elements field index i to the value represented in | 1175 | Sets the value of the elements field index i to the value represented in |
1177 | the QString q. | 1176 | the QString q. |
1178 | 1177 | ||
1179 | \param i index of the field to set | 1178 | \param i index of the field to set |
1180 | \param q a string that can be parsed to get the value to be set | 1179 | \param q a string that can be parsed to get the value to be set |
1181 | */ | 1180 | */ |
1182 | void DataElem::setField(int i, QString q) | 1181 | void DataElem::setField(int i, QString q) |
1183 | { | 1182 | { |
1184 | /* from the type of the field, parse q and store */ | 1183 | /* from the type of the field, parse q and store */ |
1185 | TVVariant::KeyType kt = contained->getKeyType(i); | 1184 | TVVariant::KeyType kt = contained->getKeyType(i); |
1186 | 1185 | ||
1187 | TVVariant t = TVVariant(q); | 1186 | TVVariant t = TVVariant(q); |
1188 | 1187 | ||
1189 | switch(kt) { | 1188 | switch(kt) { |
1190 | case TVVariant::Int: { | 1189 | case TVVariant::Int: { |
1191 | t.asInt(); | 1190 | t.asInt(); |
1192 | setField(i, t); | 1191 | setField(i, t); |
1193 | return; | 1192 | return; |
1194 | } | 1193 | } |
1195 | case TVVariant::String: { | 1194 | case TVVariant::String: { |
1196 | t.asString(); | 1195 | t.asString(); |
1197 | setField(i, t); | 1196 | setField(i, t); |
1198 | return; | 1197 | return; |
1199 | } | 1198 | } |
1200 | case TVVariant::Date: { | 1199 | case TVVariant::Date: { |
1201 | t.asDate(); | 1200 | t.asDate(); |
1202 | setField(i, t); | 1201 | setField(i, t); |
1203 | return; | 1202 | return; |
1204 | } | 1203 | } |
1205 | case TVVariant::Time: { | 1204 | case TVVariant::Time: { |
1206 | t.asTime(); | 1205 | t.asTime(); |
1207 | setField(i, t); | 1206 | setField(i, t); |
1208 | return; | 1207 | return; |
1209 | } | 1208 | } |
1210 | default: | 1209 | default: |
1211 | qWarning( | 1210 | owarn << "DataElem::setField(" << i << ", " << q << ") No valid type found" << oendl; |
1212 | QObject::tr("DataElem::setField(%1, %2) No valid type found").arg(i).arg(q) | ||
1213 | ); | ||
1214 | } | 1211 | } |
1215 | } | 1212 | } |
1216 | 1213 | ||
1217 | /*! | 1214 | /*! |
1218 | Sets the value of the elements field index i to the value at the pointer | 1215 | Sets the value of the elements field index i to the value at the pointer |
1219 | value. | 1216 | value. |
1220 | 1217 | ||
1221 | \param i index of the field to set | 1218 | \param i index of the field to set |
1222 | \param value a pointer to the (already allocated) value to set | 1219 | \param value a pointer to the (already allocated) value to set |
1223 | */ | 1220 | */ |
1224 | void DataElem::setField(int i, TVVariant value) | 1221 | void DataElem::setField(int i, TVVariant value) |
1225 | { | 1222 | { |
1226 | if (value.isValid()) { | 1223 | if (value.isValid()) { |
1227 | values.remove(i); | 1224 | values.remove(i); |
1228 | values.replace(i, new TVVariant(value)); | 1225 | values.replace(i, new TVVariant(value)); |
1229 | } | 1226 | } |
1230 | } | 1227 | } |
1231 | 1228 | ||
1232 | /*! | 1229 | /*! |
1233 | Sets the value of the elements field name qs to the value represented in | 1230 | Sets the value of the elements field name qs to the value represented in |
1234 | the QString q. | 1231 | the QString q. |
1235 | 1232 | ||
1236 | \param qs name of the field to set | 1233 | \param qs name of the field to set |
1237 | \param q a string that can be parsed to get the value to be set | 1234 | \param q a string that can be parsed to get the value to be set |
1238 | */ | 1235 | */ |
1239 | void DataElem::setField(QString qs, QString q) | 1236 | void DataElem::setField(QString qs, QString q) |
1240 | { | 1237 | { |
1241 | /* from the type of the field, parse q and store */ | 1238 | /* from the type of the field, parse q and store */ |
1242 | int i = contained->getKeyIndex(qs); | 1239 | int i = contained->getKeyIndex(qs); |
1243 | setField(i, qs); | 1240 | setField(i, qs); |
1244 | } | 1241 | } |
1245 | 1242 | ||
1246 | /*! | 1243 | /*! |
1247 | Sets the value of the elements field name qs to the value at the pointer | 1244 | Sets the value of the elements field name qs to the value at the pointer |
1248 | value. | 1245 | value. |
1249 | 1246 | ||
1250 | \param qs name of the field to set | 1247 | \param qs name of the field to set |
1251 | \param value a pointer to the (already allocated) value to set | 1248 | \param value a pointer to the (already allocated) value to set |
1252 | */ | 1249 | */ |
1253 | void DataElem::setField(QString qs, TVVariant value) | 1250 | void DataElem::setField(QString qs, TVVariant value) |
1254 | { | 1251 | { |
1255 | int i = contained->getKeyIndex(qs); | 1252 | int i = contained->getKeyIndex(qs); |
1256 | setField(i, value); | 1253 | setField(i, value); |
1257 | } | 1254 | } |
1258 | 1255 | ||
1259 | void DataElem::unsetField(int i) { | 1256 | void DataElem::unsetField(int i) { |
1260 | values.remove(i); | 1257 | values.remove(i); |
1261 | } | 1258 | } |
1262 | 1259 | ||
1263 | void DataElem::unsetField(QString qs) | 1260 | void DataElem::unsetField(QString qs) |
1264 | { | 1261 | { |
1265 | int i = contained->getKeyIndex(qs); | 1262 | int i = contained->getKeyIndex(qs); |
1266 | unsetField(i); | 1263 | unsetField(i); |
1267 | } | 1264 | } |
1268 | 1265 | ||
1269 | /*! | 1266 | /*! |
1270 | Converts the data element to a Rich Text QString | 1267 | Converts the data element to a Rich Text QString |
1271 | */ | 1268 | */ |
1272 | QString DataElem::toQString() const | 1269 | QString DataElem::toQString() const |
1273 | { | 1270 | { |
1274 | /* lets make an attempt at this function */ | 1271 | /* lets make an attempt at this function */ |
1275 | int i; | 1272 | int i; |
1276 | QString scratch = ""; | 1273 | QString scratch = ""; |
1277 | 1274 | ||
1278 | QIntDictIterator<TVVariant> it(values); | 1275 | QIntDictIterator<TVVariant> it(values); |
1279 | 1276 | ||
1280 | while (it.current()) { | 1277 | while (it.current()) { |
1281 | i = it.currentKey(); | 1278 | i = it.currentKey(); |
1282 | if(hasValidValue(i)) { | 1279 | if(hasValidValue(i)) { |
1283 | scratch += "<B>" + contained->getKeyName(i) + ":</B> "; | 1280 | scratch += "<B>" + contained->getKeyName(i) + ":</B> "; |
1284 | scratch += getField(i).toString(); | 1281 | scratch += getField(i).toString(); |
1285 | scratch += "<br>"; | 1282 | scratch += "<br>"; |
1286 | } | 1283 | } |
1287 | ++it; | 1284 | ++it; |
1288 | } | 1285 | } |
1289 | return scratch; | 1286 | return scratch; |
1290 | } | 1287 | } |
1291 | 1288 | ||
1292 | /*! formats individual fields to strings so can be displayed */ | 1289 | /*! formats individual fields to strings so can be displayed */ |
1293 | QString DataElem::toQString(int i) const | 1290 | QString DataElem::toQString(int i) const |
1294 | { | 1291 | { |
1295 | if(hasValidValue(i)) { | 1292 | if(hasValidValue(i)) { |
1296 | return getField(i).toString(); | 1293 | return getField(i).toString(); |
1297 | } | 1294 | } |
1298 | return ""; | 1295 | return ""; |
1299 | } | 1296 | } |
1300 | /*! formats individual fields to strings so can be sorted by QListView */ | 1297 | /*! formats individual fields to strings so can be sorted by QListView */ |
1301 | QString DataElem::toSortableQString(int i) const | 1298 | QString DataElem::toSortableQString(int i) const |
1302 | { | 1299 | { |
1303 | QString scratch = ""; | 1300 | QString scratch = ""; |
1304 | if(hasValidValue(i)) { | 1301 | if(hasValidValue(i)) { |
1305 | switch (contained->getKeyType(i)) { | 1302 | switch (contained->getKeyType(i)) { |
1306 | case TVVariant::String: { | 1303 | case TVVariant::String: { |
1307 | scratch += getField(i).toString(); | 1304 | scratch += getField(i).toString(); |
1308 | break; | 1305 | break; |
1309 | } | 1306 | } |
1310 | case TVVariant::Int: { | 1307 | case TVVariant::Int: { |
1311 | scratch.sprintf("%08d", getField(i).toInt()); | 1308 | scratch.sprintf("%08d", getField(i).toInt()); |
1312 | break; | 1309 | break; |
1313 | } | 1310 | } |
1314 | case TVVariant::Date: { | 1311 | case TVVariant::Date: { |
1315 | static QDate epochD(1800, 1, 1); | 1312 | static QDate epochD(1800, 1, 1); |
1316 | scratch.sprintf("%08d", | 1313 | scratch.sprintf("%08d", |
1317 | epochD.daysTo(getField(i).toDate())); | 1314 | epochD.daysTo(getField(i).toDate())); |
1318 | break; | 1315 | break; |
1319 | } | 1316 | } |
1320 | case TVVariant::Time: { | 1317 | case TVVariant::Time: { |
1321 | static QTime epochT(0, 0, 0); | 1318 | static QTime epochT(0, 0, 0); |
1322 | scratch.sprintf("%08d", | 1319 | scratch.sprintf("%08d", |
1323 | epochT.msecsTo(getField(i).toTime())); | 1320 | epochT.msecsTo(getField(i).toTime())); |
1324 | break; | 1321 | break; |
1325 | } | 1322 | } |
1326 | default: | 1323 | default: |
1327 | scratch += "Unknown type"; | 1324 | scratch += "Unknown type"; |
1328 | break; | 1325 | break; |
1329 | } | 1326 | } |
1330 | } | 1327 | } |
1331 | return scratch; | 1328 | return scratch; |
1332 | } | 1329 | } |
1333 | 1330 | ||
1334 | /* compare functions */ | 1331 | /* compare functions */ |
1335 | 1332 | ||
1336 | bool DataElem::lessThan(int i, TVVariant v) const | 1333 | bool DataElem::lessThan(int i, TVVariant v) const |
1337 | { | 1334 | { |
1338 | if (!hasValidValue(i)) return FALSE; | 1335 | if (!hasValidValue(i)) return FALSE; |
1339 | 1336 | ||
1340 | if (getField(i).type() != v.type()) | 1337 | if (getField(i).type() != v.type()) |
1341 | return FALSE; | 1338 | return FALSE; |
1342 | 1339 | ||
1343 | return (getField(i) < v); | 1340 | return (getField(i) < v); |
1344 | } | 1341 | } |
1345 | 1342 | ||
1346 | bool DataElem::moreThan(int i, TVVariant v) const | 1343 | bool DataElem::moreThan(int i, TVVariant v) const |
1347 | { | 1344 | { |
1348 | if (!hasValidValue(i)) return FALSE; | 1345 | if (!hasValidValue(i)) return FALSE; |
1349 | 1346 | ||
1350 | if (getField(i).type() != v.type()) | 1347 | if (getField(i).type() != v.type()) |
1351 | return FALSE; | 1348 | return FALSE; |
1352 | 1349 | ||
1353 | return (getField(i) > v); | 1350 | return (getField(i) > v); |
1354 | } | 1351 | } |
1355 | 1352 | ||
1356 | bool DataElem::equalTo(int i, TVVariant v) const | 1353 | bool DataElem::equalTo(int i, TVVariant v) const |
1357 | { | 1354 | { |
1358 | if (!hasValidValue(i)) return FALSE; | 1355 | if (!hasValidValue(i)) return FALSE; |
1359 | 1356 | ||
1360 | if (getField(i).type() != v.type()) | 1357 | if (getField(i).type() != v.type()) |
1361 | return FALSE; | 1358 | return FALSE; |
1362 | 1359 | ||
1363 | return (getField(i) == v); | 1360 | return (getField(i) == v); |
1364 | } | 1361 | } |
1365 | 1362 | ||
1366 | bool DataElem::contains(int i, TVVariant v) const | 1363 | bool DataElem::contains(int i, TVVariant v) const |
1367 | { | 1364 | { |
1368 | if (!hasValidValue(i)) return FALSE; | 1365 | if (!hasValidValue(i)) return FALSE; |
1369 | 1366 | ||
1370 | if (getField(i).type() != v.type()) | 1367 | if (getField(i).type() != v.type()) |
1371 | return FALSE; | 1368 | return FALSE; |
1372 | 1369 | ||
1373 | switch(getField(i).type()) { | 1370 | switch(getField(i).type()) { |
1374 | case TVVariant::String: { | 1371 | case TVVariant::String: { |
1375 | QString qs1 = getField(i).toString().lower(); | 1372 | QString qs1 = getField(i).toString().lower(); |
1376 | QString qs2 = v.toString().lower(); | 1373 | QString qs2 = v.toString().lower(); |
1377 | if (qs1.contains(qs2) > 0) return TRUE; | 1374 | if (qs1.contains(qs2) > 0) return TRUE; |
1378 | break; | 1375 | break; |
1379 | } | 1376 | } |
1380 | /* meaningless for ints */ | 1377 | /* meaningless for ints */ |
1381 | /* meaningless for time */ | 1378 | /* meaningless for time */ |
1382 | /* meaningless for dates */ | 1379 | /* meaningless for dates */ |
1383 | case TVVariant::Int: | 1380 | case TVVariant::Int: |
1384 | case TVVariant::Time: | 1381 | case TVVariant::Time: |
1385 | case TVVariant::Date: | 1382 | case TVVariant::Date: |
1386 | break; | 1383 | break; |
1387 | default: | 1384 | default: |
1388 | owarn << "Tried to compare unknown data type" << oendl; | 1385 | owarn << "Tried to compare unknown data type" << oendl; |
1389 | } | 1386 | } |
1390 | return FALSE; | 1387 | return FALSE; |
1391 | } | 1388 | } |
1392 | 1389 | ||
1393 | bool DataElem::startsWith(int i, TVVariant v) const | 1390 | bool DataElem::startsWith(int i, TVVariant v) const |
1394 | { | 1391 | { |
1395 | if (!hasValidValue(i)) return FALSE; | 1392 | if (!hasValidValue(i)) return FALSE; |
1396 | 1393 | ||
1397 | if (getField(i).type() != v.type()) | 1394 | if (getField(i).type() != v.type()) |
1398 | return FALSE; | 1395 | return FALSE; |
1399 | 1396 | ||
1400 | switch(getField(i).type()) { | 1397 | switch(getField(i).type()) { |
1401 | case TVVariant::String: { | 1398 | case TVVariant::String: { |
1402 | QString qs1 = getField(i).toString().lower(); | 1399 | QString qs1 = getField(i).toString().lower(); |
1403 | QString qs2 = v.toString().lower(); | 1400 | QString qs2 = v.toString().lower(); |
1404 | return qs1.startsWith(qs2); | 1401 | return qs1.startsWith(qs2); |
1405 | } | 1402 | } |
1406 | /* meaningless for ints */ | 1403 | /* meaningless for ints */ |
1407 | /* meaningless for time */ | 1404 | /* meaningless for time */ |
1408 | /* meaningless for dates */ | 1405 | /* meaningless for dates */ |
1409 | case TVVariant::Int: | 1406 | case TVVariant::Int: |
1410 | case TVVariant::Time: | 1407 | case TVVariant::Time: |
1411 | case TVVariant::Date: | 1408 | case TVVariant::Date: |
1412 | return FALSE; | 1409 | return FALSE; |
1413 | default: | 1410 | default: |
1414 | owarn << "Tried to compare unknown data type" << oendl; | 1411 | owarn << "Tried to compare unknown data type" << oendl; |
1415 | } | 1412 | } |
1416 | return FALSE; | 1413 | return FALSE; |
1417 | } | 1414 | } |
1418 | 1415 | ||
1419 | bool DataElem::endsWith(int i, TVVariant v) const | 1416 | bool DataElem::endsWith(int i, TVVariant v) const |
1420 | { | 1417 | { |
1421 | if (!hasValidValue(i)) return FALSE; | 1418 | if (!hasValidValue(i)) return FALSE; |
1422 | 1419 | ||
1423 | if (getField(i).type() != v.type()) | 1420 | if (getField(i).type() != v.type()) |
1424 | return FALSE; | 1421 | return FALSE; |
1425 | 1422 | ||
1426 | switch(getField(i).type()) { | 1423 | switch(getField(i).type()) { |
1427 | case TVVariant::String: { | 1424 | case TVVariant::String: { |
1428 | QString qs1 = getField(i).toString().lower(); | 1425 | QString qs1 = getField(i).toString().lower(); |
1429 | QString qs2 = v.toString().lower(); | 1426 | QString qs2 = v.toString().lower(); |
1430 | return qs1.startsWith(qs2); | 1427 | return qs1.startsWith(qs2); |
1431 | } | 1428 | } |
1432 | /* meaningless for ints */ | 1429 | /* meaningless for ints */ |
1433 | /* meaningless for time */ | 1430 | /* meaningless for time */ |
1434 | /* meaningless for dates */ | 1431 | /* meaningless for dates */ |
1435 | case TVVariant::Int: | 1432 | case TVVariant::Int: |
1436 | case TVVariant::Time: | 1433 | case TVVariant::Time: |
1437 | case TVVariant::Date: | 1434 | case TVVariant::Date: |
1438 | return FALSE; | 1435 | return FALSE; |
1439 | default: | 1436 | default: |
1440 | owarn << "Tried to compare unknown data type" << oendl; | 1437 | owarn << "Tried to compare unknown data type" << oendl; |
1441 | } | 1438 | } |
1442 | return FALSE; | 1439 | return FALSE; |
1443 | } | 1440 | } |
1444 | 1441 | ||
1445 | /*! | 1442 | /*! |
1446 | Determins which of the first to parameters are closer to the third, target | 1443 | Determins which of the first to parameters are closer to the third, target |
1447 | parameter. | 1444 | parameter. |
1448 | 1445 | ||
1449 | \return | 1446 | \return |
1450 | <UL> | 1447 | <UL> |
1451 | <LI>TRUE if the first element is a closer match to the target than the | 1448 | <LI>TRUE if the first element is a closer match to the target than the |
1452 | second element</LI> | 1449 | second element</LI> |
1453 | <LI>FALSE if the first element is not a closer match to the target than | 1450 | <LI>FALSE if the first element is not a closer match to the target than |
1454 | the second element</LI> | 1451 | the second element</LI> |
1455 | </UL> | 1452 | </UL> |
1456 | */ | 1453 | */ |
1457 | bool DataElem::closer(DataElem*d1, DataElem *d2, TVVariant target, int column) | 1454 | bool DataElem::closer(DataElem*d1, DataElem *d2, TVVariant target, int column) |
1458 | { | 1455 | { |
1459 | int type; | 1456 | int type; |
1460 | 1457 | ||
1461 | if(!d1) return FALSE; | 1458 | if(!d1) return FALSE; |
1462 | 1459 | ||
1463 | if (!d1->hasValidValue(column)) return FALSE; | 1460 | if (!d1->hasValidValue(column)) return FALSE; |
1464 | 1461 | ||
1465 | if(!target.isValid()) return FALSE; | 1462 | if(!target.isValid()) return FALSE; |
1466 | 1463 | ||
1467 | type = d1->getField(column).type(); | 1464 | type = d1->getField(column).type(); |
1468 | 1465 | ||
1469 | if(d2) { | 1466 | if(d2) { |
1470 | if (type != d2->getField(column).type()) { | 1467 | if (type != d2->getField(column).type()) { |
1471 | /* can't do compare */ | 1468 | /* can't do compare */ |
1472 | owarn << "Tried to compare two incompatable types" << oendl; | 1469 | owarn << "Tried to compare two incompatable types" << oendl; |
1473 | return FALSE; | 1470 | return FALSE; |
1474 | } | 1471 | } |
1475 | return target.closer(d1->getField(column), d2->getField(column)); | 1472 | return target.closer(d1->getField(column), d2->getField(column)); |
1476 | } | 1473 | } |
1477 | return target.close(d1->getField(column)); | 1474 | return target.close(d1->getField(column)); |
1478 | } | 1475 | } |
diff --git a/noncore/apps/tableviewer/db/datacache.cpp b/noncore/apps/tableviewer/db/datacache.cpp index 6380e1b..de57961 100644 --- a/noncore/apps/tableviewer/db/datacache.cpp +++ b/noncore/apps/tableviewer/db/datacache.cpp | |||
@@ -1,301 +1,301 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 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 | 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 | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 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. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | /* | 20 | /* |
21 | * This file is used to load the xml files that represent the database. | 21 | * This file is used to load the xml files that represent the database. |
22 | * The main requirment for said file is each data entry must contain a key, | 22 | * The main requirment for said file is each data entry must contain a key, |
23 | * otherwise any other data headings are allowed. | 23 | * otherwise any other data headings are allowed. |
24 | */ | 24 | */ |
25 | 25 | ||
26 | #include "datacache.h" | 26 | #include "datacache.h" |
27 | #include "xmlsource.h" | 27 | #include "xmlsource.h" |
28 | #include "csvsource.h" | 28 | #include "csvsource.h" |
29 | 29 | ||
30 | /* OPIE */ | 30 | /* OPIE */ |
31 | #include <opie2/odebug.h> | 31 | #include <opie2/odebug.h> |
32 | using namespace Opie::Core; | 32 | using namespace Opie::Core; |
33 | 33 | ||
34 | /* QT */ | 34 | /* QT */ |
35 | #include <qheader.h> | 35 | #include <qheader.h> |
36 | 36 | ||
37 | /* STD */ | 37 | /* STD */ |
38 | #include <stdlib.h> | 38 | #include <stdlib.h> |
39 | 39 | ||
40 | #define INIT_TABLE_SIZE 128 | 40 | #define INIT_TABLE_SIZE 128 |
41 | 41 | ||
42 | /*! | 42 | /*! |
43 | \class DBStore datastore.h | 43 | \class DBStore datastore.h |
44 | 44 | ||
45 | \brief The DBStore class is the class responsible for storing, sorting and | 45 | \brief The DBStore class is the class responsible for storing, sorting and |
46 | searching the data loaded by the application | 46 | searching the data loaded by the application |
47 | 47 | ||
48 | */ | 48 | */ |
49 | 49 | ||
50 | /*! | 50 | /*! |
51 | Constructs a DBStore item | 51 | Constructs a DBStore item |
52 | */ | 52 | */ |
53 | DBStore::DBStore() | 53 | DBStore::DBStore() |
54 | { | 54 | { |
55 | name = ""; | 55 | name = ""; |
56 | number_elems = 0; | 56 | number_elems = 0; |
57 | full = false; | 57 | full = false; |
58 | kRep = new KeyList(); | 58 | kRep = new KeyList(); |
59 | master_table.resize(INIT_TABLE_SIZE); | 59 | master_table.resize(INIT_TABLE_SIZE); |
60 | table_size = INIT_TABLE_SIZE; | 60 | table_size = INIT_TABLE_SIZE; |
61 | 61 | ||
62 | current_elem = 0; | 62 | current_elem = 0; |
63 | archive = 0; | 63 | archive = 0; |
64 | } | 64 | } |
65 | 65 | ||
66 | //TODO | 66 | //TODO |
67 | /*! | 67 | /*! |
68 | Reinitializes the table to empty (include a resize of the master table, | 68 | Reinitializes the table to empty (include a resize of the master table, |
69 | which should free some memory) | 69 | which should free some memory) |
70 | */ | 70 | */ |
71 | void DBStore::freeTable() | 71 | void DBStore::freeTable() |
72 | { | 72 | { |
73 | name = ""; | 73 | name = ""; |
74 | if(archive) { | 74 | if(archive) { |
75 | delete archive; | 75 | delete archive; |
76 | archive = 0; | 76 | archive = 0; |
77 | } | 77 | } |
78 | kRep->clear(); /* clear the current key list */ | 78 | kRep->clear(); /* clear the current key list */ |
79 | 79 | ||
80 | number_elems = 0; | 80 | number_elems = 0; |
81 | table_size = INIT_TABLE_SIZE; | 81 | table_size = INIT_TABLE_SIZE; |
82 | master_table.resize(table_size); | 82 | master_table.resize(table_size); |
83 | full = false; | 83 | full = false; |
84 | current_elem = 0; | 84 | current_elem = 0; |
85 | } | 85 | } |
86 | 86 | ||
87 | /*! | 87 | /*! |
88 | Removes all items from the DBStore and destroys the DBStore | 88 | Removes all items from the DBStore and destroys the DBStore |
89 | */ | 89 | */ |
90 | DBStore::~DBStore() | 90 | DBStore::~DBStore() |
91 | { | 91 | { |
92 | freeTable(); | 92 | freeTable(); |
93 | } | 93 | } |
94 | 94 | ||
95 | /*! | 95 | /*! |
96 | This function opens the given xml file, loads it and sets up the | 96 | This function opens the given xml file, loads it and sets up the |
97 | appropriate data structures. | 97 | appropriate data structures. |
98 | 98 | ||
99 | \param file_name A string representing the name of the file to be opened | 99 | \param file_name A string representing the name of the file to be opened |
100 | \return true if successful, false otherwise. | 100 | \return true if successful, false otherwise. |
101 | */ | 101 | */ |
102 | bool DBStore::openSource(QIODevice *inDev, const QString &source) { | 102 | bool DBStore::openSource(QIODevice *inDev, const QString &source) { |
103 | 103 | ||
104 | /* first check if db is already open, if contains data.. then clear */ | 104 | /* first check if db is already open, if contains data.. then clear */ |
105 | if(number_elems > 0) { | 105 | if(number_elems > 0) { |
106 | freeTable(); | 106 | freeTable(); |
107 | } | 107 | } |
108 | 108 | ||
109 | if (source == "text/x-xml-tableviewer") { | 109 | if (source == "text/x-xml-tableviewer") { |
110 | archive = new DBXml(this); | 110 | archive = new DBXml(this); |
111 | } else if (source == "text/csv") { | 111 | } else if (source == "text/csv") { |
112 | archive = new DBCsv(this); | 112 | archive = new DBCsv(this); |
113 | } else | 113 | } else |
114 | return false; | 114 | return false; |
115 | 115 | ||
116 | return (archive->openSource(inDev)); | 116 | return (archive->openSource(inDev)); |
117 | } | 117 | } |
118 | 118 | ||
119 | bool DBStore::saveSource(QIODevice *outDev, const QString &source) | 119 | bool DBStore::saveSource(QIODevice *outDev, const QString &source) |
120 | { | 120 | { |
121 | /* saving a new file */ | 121 | /* saving a new file */ |
122 | if(!archive) { | 122 | if(!archive) { |
123 | if (source == "text/x-xml-tableviewer") { | 123 | if (source == "text/x-xml-tableviewer") { |
124 | archive = new DBXml(this); | 124 | archive = new DBXml(this); |
125 | } else if (source == "text/x-xml-tableviewer") { | 125 | } else if (source == "text/x-xml-tableviewer") { |
126 | archive = new DBCsv(this); | 126 | archive = new DBCsv(this); |
127 | } else | 127 | } else |
128 | return false; | 128 | return false; |
129 | } | 129 | } |
130 | 130 | ||
131 | /* changing file type */ | 131 | /* changing file type */ |
132 | if(archive->type() != source) { | 132 | if(archive->type() != source) { |
133 | delete archive; | 133 | delete archive; |
134 | if (source == "text/x-xml-tableviewer") { | 134 | if (source == "text/x-xml-tableviewer") { |
135 | archive = new DBXml(this); | 135 | archive = new DBXml(this); |
136 | } else if (source == "text/x-xml-tableviewer") { | 136 | } else if (source == "text/x-xml-tableviewer") { |
137 | archive = new DBCsv(this); | 137 | archive = new DBCsv(this); |
138 | } else | 138 | } else |
139 | return false; | 139 | return false; |
140 | } | 140 | } |
141 | 141 | ||
142 | return (archive->saveSource(outDev)); | 142 | return (archive->saveSource(outDev)); |
143 | } | 143 | } |
144 | 144 | ||
145 | /*! | 145 | /*! |
146 | This function is used to add new elements to the database. If the database | 146 | This function is used to add new elements to the database. If the database |
147 | has already reached the maximum allowable size this function does not alter | 147 | has already reached the maximum allowable size this function does not alter |
148 | the database. | 148 | the database. |
149 | 149 | ||
150 | \param delm An already allocated and initialized data element to be added | 150 | \param delm An already allocated and initialized data element to be added |
151 | */ | 151 | */ |
152 | void DBStore::addItem(DataElem *delem) | 152 | void DBStore::addItem(DataElem *delem) |
153 | { | 153 | { |
154 | addItemInternal(delem); | 154 | addItemInternal(delem); |
155 | } | 155 | } |
156 | 156 | ||
157 | void DBStore::addItemInternal(DataElem *delem) | 157 | void DBStore::addItemInternal(DataElem *delem) |
158 | { | 158 | { |
159 | /* if already full, don't over fill, do a qWarning though */ | 159 | /* if already full, don't over fill, do a owarn though */ |
160 | if (full) { | 160 | if (full) { |
161 | owarn << "Attempted to add items to already full table" << oendl; | 161 | owarn << "Attempted to add items to already full table" << oendl; |
162 | return; | 162 | return; |
163 | } | 163 | } |
164 | 164 | ||
165 | master_table.insert(number_elems, delem); | 165 | master_table.insert(number_elems, delem); |
166 | 166 | ||
167 | current_elem = number_elems; | 167 | current_elem = number_elems; |
168 | number_elems++; | 168 | number_elems++; |
169 | 169 | ||
170 | if(number_elems >= table_size) { | 170 | if(number_elems >= table_size) { |
171 | /* filled current table, double if we can */ | 171 | /* filled current table, double if we can */ |
172 | table_size = table_size << 1; | 172 | table_size = table_size << 1; |
173 | 173 | ||
174 | /* check that the new table size is still valid, i.e. that we didn't | 174 | /* check that the new table size is still valid, i.e. that we didn't |
175 | just shift the 1 bit of the end of the int. */ | 175 | just shift the 1 bit of the end of the int. */ |
176 | if (!table_size) { | 176 | if (!table_size) { |
177 | full = true; | 177 | full = true; |
178 | /* no point in doing antying else. */ | 178 | /* no point in doing antying else. */ |
179 | return; | 179 | return; |
180 | } | 180 | } |
181 | master_table.resize(table_size); | 181 | master_table.resize(table_size); |
182 | } | 182 | } |
183 | } | 183 | } |
184 | 184 | ||
185 | void DBStore::removeItem(DataElem *r) | 185 | void DBStore::removeItem(DataElem *r) |
186 | { | 186 | { |
187 | int position = master_table.findRef(r); | 187 | int position = master_table.findRef(r); |
188 | if(position != -1) { | 188 | if(position != -1) { |
189 | /* there is at least one item, this is it */ | 189 | /* there is at least one item, this is it */ |
190 | /* replace this with the last element, decrease the element count */ | 190 | /* replace this with the last element, decrease the element count */ |
191 | master_table.insert(position, master_table.at(--number_elems)); | 191 | master_table.insert(position, master_table.at(--number_elems)); |
192 | master_table.remove(number_elems); | 192 | master_table.remove(number_elems); |
193 | delete r; | 193 | delete r; |
194 | } | 194 | } |
195 | } | 195 | } |
196 | 196 | ||
197 | /*! | 197 | /*! |
198 | Sets the name of the database | 198 | Sets the name of the database |
199 | 199 | ||
200 | \param n A string representing the new name of the database. | 200 | \param n A string representing the new name of the database. |
201 | */ | 201 | */ |
202 | void DBStore::setName(const QString &n) | 202 | void DBStore::setName(const QString &n) |
203 | { | 203 | { |
204 | name = n; | 204 | name = n; |
205 | } | 205 | } |
206 | 206 | ||
207 | /*! | 207 | /*! |
208 | Gets the name of the database | 208 | Gets the name of the database |
209 | 209 | ||
210 | \return A string representing the name of the database. | 210 | \return A string representing the name of the database. |
211 | */ | 211 | */ |
212 | QString DBStore::getName() | 212 | QString DBStore::getName() |
213 | { | 213 | { |
214 | return name; | 214 | return name; |
215 | } | 215 | } |
216 | 216 | ||
217 | /*! | 217 | /*! |
218 | Retrieves a pointer to the key representation of the database for | 218 | Retrieves a pointer to the key representation of the database for |
219 | other classes to use as reference. | 219 | other classes to use as reference. |
220 | 220 | ||
221 | \return a pointer to the databases key representaion | 221 | \return a pointer to the databases key representaion |
222 | */ | 222 | */ |
223 | KeyList *DBStore::getKeys() | 223 | KeyList *DBStore::getKeys() |
224 | { | 224 | { |
225 | return kRep; | 225 | return kRep; |
226 | } | 226 | } |
227 | 227 | ||
228 | /*! | 228 | /*! |
229 | sets the database's key representation the passed pointer | 229 | sets the database's key representation the passed pointer |
230 | \param a pointer to a key representaton | 230 | \param a pointer to a key representaton |
231 | */ | 231 | */ |
232 | void DBStore::setKeys(KeyList *k) | 232 | void DBStore::setKeys(KeyList *k) |
233 | { | 233 | { |
234 | kRep = k; | 234 | kRep = k; |
235 | } | 235 | } |
236 | 236 | ||
237 | /*! | 237 | /*! |
238 | Sets the current element to the first element of the database | 238 | Sets the current element to the first element of the database |
239 | */ | 239 | */ |
240 | void DBStore::first() | 240 | void DBStore::first() |
241 | { | 241 | { |
242 | current_elem = 0; | 242 | current_elem = 0; |
243 | } | 243 | } |
244 | 244 | ||
245 | /*! | 245 | /*! |
246 | Sets the current element to the last element of the database | 246 | Sets the current element to the last element of the database |
247 | */ | 247 | */ |
248 | void DBStore::last() | 248 | void DBStore::last() |
249 | { | 249 | { |
250 | current_elem = number_elems - 1; | 250 | current_elem = number_elems - 1; |
251 | } | 251 | } |
252 | 252 | ||
253 | /*! | 253 | /*! |
254 | Sets the current element to the next element of the database if | 254 | Sets the current element to the next element of the database if |
255 | there exists an element after the current one. | 255 | there exists an element after the current one. |
256 | */ | 256 | */ |
257 | bool DBStore::next() | 257 | bool DBStore::next() |
258 | { | 258 | { |
259 | unsigned int new_current_elem = current_elem + 1; | 259 | unsigned int new_current_elem = current_elem + 1; |
260 | if (current_elem < number_elems) | 260 | if (current_elem < number_elems) |
261 | /* was valid before inc (it is possible but unlikely that inc current | 261 | /* was valid before inc (it is possible but unlikely that inc current |
262 | elem will change it from invalid to valid) */ | 262 | elem will change it from invalid to valid) */ |
263 | if (new_current_elem < number_elems) { | 263 | if (new_current_elem < number_elems) { |
264 | /* is valid after inc */ | 264 | /* is valid after inc */ |
265 | current_elem = new_current_elem; | 265 | current_elem = new_current_elem; |
266 | return true; | 266 | return true; |
267 | } | 267 | } |
268 | return false; | 268 | return false; |
269 | } | 269 | } |
270 | 270 | ||
271 | /*! | 271 | /*! |
272 | Sets the current element to the previous element of the database if | 272 | Sets the current element to the previous element of the database if |
273 | there exists an element before the current one. | 273 | there exists an element before the current one. |
274 | */ | 274 | */ |
275 | bool DBStore::previous() | 275 | bool DBStore::previous() |
276 | { | 276 | { |
277 | unsigned int new_current_elem = current_elem -1; | 277 | unsigned int new_current_elem = current_elem -1; |
278 | if (current_elem < number_elems) | 278 | if (current_elem < number_elems) |
279 | /* was valid */ | 279 | /* was valid */ |
280 | if (new_current_elem < number_elems) { | 280 | if (new_current_elem < number_elems) { |
281 | /* still is (if was 0, then now -1, but as is unsigned will wrap | 281 | /* still is (if was 0, then now -1, but as is unsigned will wrap |
282 | and hence be invalid */ | 282 | and hence be invalid */ |
283 | current_elem = new_current_elem; | 283 | current_elem = new_current_elem; |
284 | return true; | 284 | return true; |
285 | } | 285 | } |
286 | return false; | 286 | return false; |
287 | } | 287 | } |
288 | 288 | ||
289 | /*! | 289 | /*! |
290 | Returns the current data element in the database. Which element is current | 290 | Returns the current data element in the database. Which element is current |
291 | is affected by newly added items, findItem, next, previous, first and | 291 | is affected by newly added items, findItem, next, previous, first and |
292 | last functions | 292 | last functions |
293 | 293 | ||
294 | \return a pointer to the current data element | 294 | \return a pointer to the current data element |
295 | */ | 295 | */ |
296 | DataElem *DBStore::getCurrentData() | 296 | DataElem *DBStore::getCurrentData() |
297 | { | 297 | { |
298 | if (current_elem >= number_elems) | 298 | if (current_elem >= number_elems) |
299 | return NULL; | 299 | return NULL; |
300 | return master_table[current_elem]; | 300 | return master_table[current_elem]; |
301 | } | 301 | } |
diff --git a/noncore/apps/tableviewer/db/datacache.h b/noncore/apps/tableviewer/db/datacache.h index c5dc637..e38050c 100644 --- a/noncore/apps/tableviewer/db/datacache.h +++ b/noncore/apps/tableviewer/db/datacache.h | |||
@@ -1,130 +1,136 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 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 | 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 | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 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. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | /* | 21 | /* |
22 | * This file is used to load the xml files that represent the database. | 22 | * This file is used to load the xml files that represent the database. |
23 | * The main requirment for said file is each data entry must contain a key, | 23 | * The main requirment for said file is each data entry must contain a key, |
24 | * otherwise any other data headings are allowed. | 24 | * otherwise any other data headings are allowed. |
25 | */ | 25 | */ |
26 | 26 | ||
27 | #ifndef __DATACACHE_H__ | 27 | #ifndef __DATACACHE_H__ |
28 | #define __DATACACHE_H__ | 28 | #define __DATACACHE_H__ |
29 | 29 | ||
30 | #include "common.h" | ||
31 | |||
32 | /* OPIE */ | ||
33 | #include <opie2/odebug.h> | ||
34 | using namespace Opie::Core; | ||
35 | |||
36 | /* QT */ | ||
30 | #include <qstring.h> | 37 | #include <qstring.h> |
31 | #include <qvector.h> | 38 | #include <qvector.h> |
32 | #include "common.h" | ||
33 | 39 | ||
34 | class DBStore; | 40 | class DBStore; |
35 | 41 | ||
36 | /*! Abstract class that defines how database stuff can be accessed */ | 42 | /*! Abstract class that defines how database stuff can be accessed */ |
37 | class DBAccess { | 43 | class DBAccess { |
38 | public: | 44 | public: |
39 | 45 | ||
40 | // DBAccess(DBStore *d) { dstore = d; } | 46 | // DBAccess(DBStore *d) { dstore = d; } |
41 | virtual ~DBAccess() {} | 47 | virtual ~DBAccess() {} |
42 | 48 | ||
43 | virtual QString type() { | 49 | virtual QString type() { |
44 | return QString(); | 50 | return QString(); |
45 | } | 51 | } |
46 | 52 | ||
47 | virtual bool openSource(QIODevice *) { | 53 | virtual bool openSource(QIODevice *) { |
48 | qWarning("DBAccess::openSource not yet implemented"); | 54 | owarn << "DBAccess::openSource not yet implemented" << oendl; |
49 | return false; | 55 | return false; |
50 | } | 56 | } |
51 | 57 | ||
52 | virtual bool saveSource(QIODevice *) { | 58 | virtual bool saveSource(QIODevice *) { |
53 | qWarning("DBAccess::saveSource(QString) not yet implemented"); | 59 | owarn << "DBAccess::saveSource(QString) not yet implemented" << oendl; |
54 | return false; | 60 | return false; |
55 | } | 61 | } |
56 | 62 | ||
57 | protected: | 63 | protected: |
58 | DBStore *dstore; | 64 | DBStore *dstore; |
59 | QString source_name; | 65 | QString source_name; |
60 | }; | 66 | }; |
61 | 67 | ||
62 | class DBStore { | 68 | class DBStore { |
63 | public: | 69 | public: |
64 | DBStore(); | 70 | DBStore(); |
65 | ~DBStore(); | 71 | ~DBStore(); |
66 | 72 | ||
67 | bool openSource(QIODevice *, const QString &source); | 73 | bool openSource(QIODevice *, const QString &source); |
68 | bool saveSource(QIODevice *, const QString &source); | 74 | bool saveSource(QIODevice *, const QString &source); |
69 | 75 | ||
70 | // Add an item | 76 | // Add an item |
71 | void addItem(DataElem *); | 77 | void addItem(DataElem *); |
72 | void addItemInternal(DataElem *); | 78 | void addItemInternal(DataElem *); |
73 | void removeItem(DataElem *); | 79 | void removeItem(DataElem *); |
74 | 80 | ||
75 | // Set the name of the database | 81 | // Set the name of the database |
76 | void setName(const QString &name); | 82 | void setName(const QString &name); |
77 | 83 | ||
78 | // Get the name of the database | 84 | // Get the name of the database |
79 | QString getName(); | 85 | QString getName(); |
80 | 86 | ||
81 | KeyList *getKeys(); | 87 | KeyList *getKeys(); |
82 | void setKeys(KeyList *); | 88 | void setKeys(KeyList *); |
83 | 89 | ||
84 | /*! gets the number of fields defined in the database */ | 90 | /*! gets the number of fields defined in the database */ |
85 | inline int getNumFields() { | 91 | inline int getNumFields() { |
86 | return kRep->getNumFields(); | 92 | return kRep->getNumFields(); |
87 | } | 93 | } |
88 | 94 | ||
89 | /*! gets the index of a key given its name */ | 95 | /*! gets the index of a key given its name */ |
90 | inline int getKeyIndex(QString qs) { | 96 | inline int getKeyIndex(QString qs) { |
91 | return kRep->getKeyIndex(qs); | 97 | return kRep->getKeyIndex(qs); |
92 | } | 98 | } |
93 | 99 | ||
94 | /*! gets the type of a key given its index */ | 100 | /*! gets the type of a key given its index */ |
95 | inline TVVariant::KeyType getKeyType(int i) { | 101 | inline TVVariant::KeyType getKeyType(int i) { |
96 | return kRep->getKeyType(i); | 102 | return kRep->getKeyType(i); |
97 | } | 103 | } |
98 | 104 | ||
99 | /*! gets the name of a key given its index */ | 105 | /*! gets the name of a key given its index */ |
100 | inline QString getKeyName(int i) { | 106 | inline QString getKeyName(int i) { |
101 | return kRep->getKeyName(i); | 107 | return kRep->getKeyName(i); |
102 | } | 108 | } |
103 | 109 | ||
104 | // Access functions.. iterator type stuff | 110 | // Access functions.. iterator type stuff |
105 | 111 | ||
106 | void first(); | 112 | void first(); |
107 | void last(); | 113 | void last(); |
108 | 114 | ||
109 | bool next(); | 115 | bool next(); |
110 | bool previous(); | 116 | bool previous(); |
111 | 117 | ||
112 | DataElem* getCurrentData(); | 118 | DataElem* getCurrentData(); |
113 | 119 | ||
114 | private: | 120 | private: |
115 | /* does the work of freeing used memory */ | 121 | /* does the work of freeing used memory */ |
116 | void freeTable(); | 122 | void freeTable(); |
117 | QString name; | 123 | QString name; |
118 | 124 | ||
119 | QVector<DataElem> master_table; | 125 | QVector<DataElem> master_table; |
120 | DBAccess *archive; | 126 | DBAccess *archive; |
121 | 127 | ||
122 | KeyList *kRep; | 128 | KeyList *kRep; |
123 | 129 | ||
124 | unsigned int number_elems; | 130 | unsigned int number_elems; |
125 | unsigned int table_size; /* should always be a power of 2 */ | 131 | unsigned int table_size; /* should always be a power of 2 */ |
126 | bool full; /* since because we are using an int for indexing there is | 132 | bool full; /* since because we are using an int for indexing there is |
127 | an upper limit on the number of items we can store. */ | 133 | an upper limit on the number of items we can store. */ |
128 | unsigned int current_elem; | 134 | unsigned int current_elem; |
129 | }; | 135 | }; |
130 | #endif | 136 | #endif |
diff --git a/noncore/apps/tableviewer/ui/browsekeyentry.cpp b/noncore/apps/tableviewer/ui/browsekeyentry.cpp index 42e24dd..6b78437 100644 --- a/noncore/apps/tableviewer/ui/browsekeyentry.cpp +++ b/noncore/apps/tableviewer/ui/browsekeyentry.cpp | |||
@@ -1,206 +1,205 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 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 | 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 | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 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. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | #include "browsekeyentry.h" | 20 | #include "browsekeyentry.h" |
21 | #include "commonwidgets.h" | 21 | #include "commonwidgets.h" |
22 | 22 | ||
23 | #include <opie2/odebug.h> | ||
24 | using namespace Opie::Core; | ||
25 | |||
23 | #include <qtoolbutton.h> | 26 | #include <qtoolbutton.h> |
24 | #include <qwidgetstack.h> | 27 | #include <qwidgetstack.h> |
25 | #include <qlayout.h> | 28 | #include <qlayout.h> |
26 | #include <qlineedit.h> | 29 | #include <qlineedit.h> |
27 | #include <qpushbutton.h> | 30 | #include <qpushbutton.h> |
28 | #include <qpopupmenu.h> | 31 | #include <qpopupmenu.h> |
29 | #include <qhbox.h> | 32 | #include <qhbox.h> |
30 | #include <qdatetime.h> | 33 | #include <qdatetime.h> |
31 | 34 | ||
32 | #include <qheader.h> | ||
33 | // For qWarning(const char *) | ||
34 | |||
35 | /*! | 35 | /*! |
36 | \class TVBrowseKeyEntry | 36 | \class TVBrowseKeyEntry |
37 | \brief a Widget used enter keys into the TVBrowseViewWidget | 37 | \brief a Widget used enter keys into the TVBrowseViewWidget |
38 | 38 | ||
39 | The TVBrowseKeyEntry Widget provides the facility to enter | 39 | The TVBrowseKeyEntry Widget provides the facility to enter |
40 | various key types to be search on in the table. The key can be changed | 40 | various key types to be search on in the table. The key can be changed |
41 | and the entry field will update to the correct sort of widget appropriately | 41 | and the entry field will update to the correct sort of widget appropriately |
42 | */ | 42 | */ |
43 | 43 | ||
44 | /*! | 44 | /*! |
45 | Constructs the widget | 45 | Constructs the widget |
46 | */ | 46 | */ |
47 | TVBrowseKeyEntry::TVBrowseKeyEntry(QWidget *parent, const char *name, WFlags f) | 47 | TVBrowseKeyEntry::TVBrowseKeyEntry(QWidget *parent, const char *name, WFlags f) |
48 | : QWidget(parent, name, f) | 48 | : QWidget(parent, name, f) |
49 | { | 49 | { |
50 | QHBoxLayout *h_layout = new QHBoxLayout(this); | 50 | QHBoxLayout *h_layout = new QHBoxLayout(this); |
51 | 51 | ||
52 | textKey = new QLineEdit(this, 0); | 52 | textKey = new QLineEdit(this, 0); |
53 | intKey = new IntEdit(this, 0); | 53 | intKey = new IntEdit(this, 0); |
54 | dateKey = new DateEdit(this, 0); | 54 | dateKey = new DateEdit(this, 0); |
55 | timeKey = new TimeEdit(this, 0); | 55 | timeKey = new TimeEdit(this, 0); |
56 | 56 | ||
57 | resetButton = new QPushButton(this, "reset"); | 57 | resetButton = new QPushButton(this, "reset"); |
58 | resetButton->setMinimumSize(QSize(50, 0)); | 58 | resetButton->setMinimumSize(QSize(50, 0)); |
59 | resetButton->setText(tr("Reset")); | 59 | resetButton->setText(tr("Reset")); |
60 | 60 | ||
61 | changeKeyButton = new QToolButton(this, "changekey"); | 61 | changeKeyButton = new QToolButton(this, "changekey"); |
62 | // TODO The icon stuff. | 62 | // TODO The icon stuff. |
63 | changeKeyButton->setText(tr("key")); | 63 | changeKeyButton->setText(tr("key")); |
64 | 64 | ||
65 | totalKeys = 0; | 65 | totalKeys = 0; |
66 | ts = 0; | 66 | ts = 0; |
67 | keyMenu = new QPopupMenu(this, "keymenu"); | 67 | keyMenu = new QPopupMenu(this, "keymenu"); |
68 | 68 | ||
69 | ws = new QWidgetStack(this, 0); | 69 | ws = new QWidgetStack(this, 0); |
70 | ws->addWidget(textKey, TVVariant::String); | 70 | ws->addWidget(textKey, TVVariant::String); |
71 | ws->addWidget(intKey, TVVariant::Int); | 71 | ws->addWidget(intKey, TVVariant::Int); |
72 | ws->addWidget(timeKey, TVVariant::Time); | 72 | ws->addWidget(timeKey, TVVariant::Time); |
73 | ws->addWidget(dateKey, TVVariant::Date); | 73 | ws->addWidget(dateKey, TVVariant::Date); |
74 | 74 | ||
75 | ws->raiseWidget(TVVariant::String); | 75 | ws->raiseWidget(TVVariant::String); |
76 | 76 | ||
77 | // TODO connect slots and signals.... | 77 | // TODO connect slots and signals.... |
78 | connect(changeKeyButton, SIGNAL(clicked()), | 78 | connect(changeKeyButton, SIGNAL(clicked()), |
79 | this, SLOT(changeKeyMenuSlot())); | 79 | this, SLOT(changeKeyMenuSlot())); |
80 | 80 | ||
81 | connect(resetButton, SIGNAL(clicked()), | 81 | connect(resetButton, SIGNAL(clicked()), |
82 | textKey, SLOT(clear())); | 82 | textKey, SLOT(clear())); |
83 | connect(resetButton, SIGNAL(clicked()), | 83 | connect(resetButton, SIGNAL(clicked()), |
84 | intKey, SLOT(clear())); | 84 | intKey, SLOT(clear())); |
85 | connect(resetButton, SIGNAL(clicked()), | 85 | connect(resetButton, SIGNAL(clicked()), |
86 | dateKey, SLOT(clear())); | 86 | dateKey, SLOT(clear())); |
87 | connect(resetButton, SIGNAL(clicked()), | 87 | connect(resetButton, SIGNAL(clicked()), |
88 | timeKey, SLOT(clear())); | 88 | timeKey, SLOT(clear())); |
89 | 89 | ||
90 | h_layout->addWidget(ws); | 90 | h_layout->addWidget(ws); |
91 | h_layout->addWidget(resetButton); | 91 | h_layout->addWidget(resetButton); |
92 | h_layout->addWidget(changeKeyButton); | 92 | h_layout->addWidget(changeKeyButton); |
93 | 93 | ||
94 | connect(textKey, SIGNAL(textChanged(const QString&)), | 94 | connect(textKey, SIGNAL(textChanged(const QString&)), |
95 | this, SLOT(searchOnText())); | 95 | this, SLOT(searchOnText())); |
96 | connect(intKey, SIGNAL(valueChanged(int)), | 96 | connect(intKey, SIGNAL(valueChanged(int)), |
97 | this, SLOT(searchOnText())); | 97 | this, SLOT(searchOnText())); |
98 | connect(dateKey, SIGNAL(valueChanged(const QDate&)), | 98 | connect(dateKey, SIGNAL(valueChanged(const QDate&)), |
99 | this, SLOT(searchOnText())); | 99 | this, SLOT(searchOnText())); |
100 | connect(timeKey, SIGNAL(valueChanged(const QTime&)), | 100 | connect(timeKey, SIGNAL(valueChanged(const QTime&)), |
101 | this, SLOT(searchOnText())); | 101 | this, SLOT(searchOnText())); |
102 | } | 102 | } |
103 | 103 | ||
104 | /*! | 104 | /*! |
105 | Destructs the widget | 105 | Destructs the widget |
106 | */ | 106 | */ |
107 | TVBrowseKeyEntry::~TVBrowseKeyEntry() | 107 | TVBrowseKeyEntry::~TVBrowseKeyEntry() |
108 | { | 108 | { |
109 | } | 109 | } |
110 | 110 | ||
111 | /*! | 111 | /*! |
112 | Changes which key the user intends to search on | 112 | Changes which key the user intends to search on |
113 | 113 | ||
114 | \param id_param the index of the key future searches should be base on | 114 | \param id_param the index of the key future searches should be base on |
115 | */ | 115 | */ |
116 | void TVBrowseKeyEntry::changeKeySlot(int id_param) | 116 | void TVBrowseKeyEntry::changeKeySlot(int id_param) |
117 | { | 117 | { |
118 | if(ts) { | 118 | if(ts) { |
119 | emit sortChanged(id_param); | 119 | emit sortChanged(id_param); |
120 | ws->raiseWidget(ts->kRep->getKeyType(ts->current_column)); | 120 | ws->raiseWidget(ts->kRep->getKeyType(ts->current_column)); |
121 | } | 121 | } |
122 | } | 122 | } |
123 | 123 | ||
124 | /*! | 124 | /*! |
125 | Opens the change key menu | 125 | Opens the change key menu |
126 | */ | 126 | */ |
127 | void TVBrowseKeyEntry::changeKeyMenuSlot() | 127 | void TVBrowseKeyEntry::changeKeyMenuSlot() |
128 | { | 128 | { |
129 | if(ts) | 129 | if(ts) |
130 | keyMenu->exec(changeKeyButton->mapToGlobal(QPoint(0,0))); | 130 | keyMenu->exec(changeKeyButton->mapToGlobal(QPoint(0,0))); |
131 | } | 131 | } |
132 | 132 | ||
133 | 133 | ||
134 | void TVBrowseKeyEntry::setTableState(TableState *t) { | 134 | void TVBrowseKeyEntry::setTableState(TableState *t) { |
135 | ts = t; | 135 | ts = t; |
136 | } | 136 | } |
137 | 137 | ||
138 | void TVBrowseKeyEntry::rebuildKeys() { | 138 | void TVBrowseKeyEntry::rebuildKeys() { |
139 | int i; | 139 | int i; |
140 | if (!ts) return; | 140 | if (!ts) return; |
141 | if (!ts->kRep) return; | 141 | if (!ts->kRep) return; |
142 | 142 | ||
143 | /* clear the old */ | 143 | /* clear the old */ |
144 | keyMenu->clear(); | 144 | keyMenu->clear(); |
145 | 145 | ||
146 | KeyListIterator it(*ts->kRep); | 146 | KeyListIterator it(*ts->kRep); |
147 | 147 | ||
148 | for (i = 0; i < ts->kRep->getNumFields(); i++) { | 148 | for (i = 0; i < ts->kRep->getNumFields(); i++) { |
149 | keyMenu->insertItem(it.current()->name(), this, | 149 | keyMenu->insertItem(it.current()->name(), this, |
150 | SLOT(changeKeySlot(int)), 0, i); | 150 | SLOT(changeKeySlot(int)), 0, i); |
151 | keyMenu->setItemParameter(i, it.currentKey()); | 151 | keyMenu->setItemParameter(i, it.currentKey()); |
152 | ++it; | 152 | ++it; |
153 | } | 153 | } |
154 | } | 154 | } |
155 | 155 | ||
156 | void TVBrowseKeyEntry::reset() | 156 | void TVBrowseKeyEntry::reset() |
157 | { | 157 | { |
158 | textKey->clear(); | 158 | textKey->clear(); |
159 | intKey->clear(); | 159 | intKey->clear(); |
160 | dateKey->clear(); | 160 | dateKey->clear(); |
161 | timeKey->clear(); | 161 | timeKey->clear(); |
162 | 162 | ||
163 | keyMenu->clear(); | 163 | keyMenu->clear(); |
164 | } | 164 | } |
165 | /*! | 165 | /*! |
166 | Searches on the current value of the key entry provided that the | 166 | Searches on the current value of the key entry provided that the |
167 | current key is of type text WARNING, TODO fix memory leaks | 167 | current key is of type text WARNING, TODO fix memory leaks |
168 | */ | 168 | */ |
169 | void TVBrowseKeyEntry::searchOnText() | 169 | void TVBrowseKeyEntry::searchOnText() |
170 | { | 170 | { |
171 | TVVariant sendkey; | 171 | TVVariant sendkey; |
172 | 172 | ||
173 | if (!ts) | 173 | if (!ts) |
174 | return; | 174 | return; |
175 | 175 | ||
176 | switch(ts->kRep->getKeyType(ts->current_column)) { | 176 | switch(ts->kRep->getKeyType(ts->current_column)) { |
177 | case TVVariant::String: | 177 | case TVVariant::String: |
178 | sendkey = TVVariant(QString(textKey->text())); | 178 | sendkey = TVVariant(QString(textKey->text())); |
179 | break; | 179 | break; |
180 | case TVVariant::Int: { | 180 | case TVVariant::Int: { |
181 | sendkey = TVVariant(intKey->value()); | 181 | sendkey = TVVariant(intKey->value()); |
182 | break; | 182 | break; |
183 | } | 183 | } |
184 | case TVVariant::Time: { | 184 | case TVVariant::Time: { |
185 | sendkey = TVVariant(QTime(timeKey->time())); | 185 | sendkey = TVVariant(QTime(timeKey->time())); |
186 | break; | 186 | break; |
187 | } | 187 | } |
188 | case TVVariant::Date: { | 188 | case TVVariant::Date: { |
189 | sendkey = TVVariant(QDate(dateKey->date())); | 189 | sendkey = TVVariant(QDate(dateKey->date())); |
190 | break; | 190 | break; |
191 | } | 191 | } |
192 | case TVVariant::Invalid: | 192 | case TVVariant::Invalid: |
193 | break; | 193 | break; |
194 | default: | 194 | default: |
195 | qWarning("TVBrowseKeyEntry::searchOnText() " | 195 | owarn << "TVBrowseKeyEntry::searchOnText() cannot work out data type" << oendl; |
196 | "cannot work out data type"); | ||
197 | return; | 196 | return; |
198 | } | 197 | } |
199 | emit searchOnKey(ts->current_column, sendkey); | 198 | emit searchOnKey(ts->current_column, sendkey); |
200 | } | 199 | } |
201 | 200 | ||
202 | /*! \fn void TVBrowseKeyEntry::searchOnKey(int currentKeyId, TVVariant) | 201 | /*! \fn void TVBrowseKeyEntry::searchOnKey(int currentKeyId, TVVariant) |
203 | 202 | ||
204 | This signal indicates that a search on key index currentKeyId should be | 203 | This signal indicates that a search on key index currentKeyId should be |
205 | done searching for the value v. | 204 | done searching for the value v. |
206 | */ | 205 | */ |
diff --git a/noncore/apps/tableviewer/ui/filterkeyentry.cpp b/noncore/apps/tableviewer/ui/filterkeyentry.cpp index d108fbd..4d74d6b 100644 --- a/noncore/apps/tableviewer/ui/filterkeyentry.cpp +++ b/noncore/apps/tableviewer/ui/filterkeyentry.cpp | |||
@@ -1,208 +1,212 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 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 | 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 | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 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. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | #include "filterkeyentry.h" | 20 | #include "filterkeyentry.h" |
21 | #include "commonwidgets.h" | 21 | #include "commonwidgets.h" |
22 | 22 | ||
23 | /* OPIE */ | ||
24 | #include <opie2/odebug.h> | ||
25 | using namespace Opie::Core; | ||
26 | |||
27 | /* QT */ | ||
23 | #include <qwidgetstack.h> | 28 | #include <qwidgetstack.h> |
24 | #include <qcombobox.h> | 29 | #include <qcombobox.h> |
25 | #include <qlayout.h> | 30 | #include <qlayout.h> |
26 | #include <qlineedit.h> | 31 | #include <qlineedit.h> |
27 | #include <qsizepolicy.h> | 32 | #include <qsizepolicy.h> |
28 | #include <qdatetime.h> | 33 | #include <qdatetime.h> |
29 | #include <qhbox.h> | 34 | #include <qhbox.h> |
30 | 35 | ||
31 | TVFilterKeyEntry::TVFilterKeyEntry(QWidget *parent, const char *name, WFlags f) | 36 | TVFilterKeyEntry::TVFilterKeyEntry(QWidget *parent, const char *name, WFlags f) |
32 | : QWidget(parent, name, f) | 37 | : QWidget(parent, name, f) |
33 | { | 38 | { |
34 | int stack_elem = 0; | 39 | int stack_elem = 0; |
35 | 40 | ||
36 | layout = new QHBoxLayout(this, 0); | 41 | layout = new QHBoxLayout(this, 0); |
37 | layout->setSpacing(0); | 42 | layout->setSpacing(0); |
38 | layout->setMargin(0); | 43 | layout->setMargin(0); |
39 | 44 | ||
40 | textEntry = new QHBox(this, 0); | 45 | textEntry = new QHBox(this, 0); |
41 | textEntry->setSpacing(0); | 46 | textEntry->setSpacing(0); |
42 | textEntry->setMargin(0); | 47 | textEntry->setMargin(0); |
43 | 48 | ||
44 | intEntry = new QHBox(this, 0); | 49 | intEntry = new QHBox(this, 0); |
45 | intEntry->setSpacing(0); | 50 | intEntry->setSpacing(0); |
46 | intEntry->setMargin(0); | 51 | intEntry->setMargin(0); |
47 | 52 | ||
48 | timeEntry = new QHBox(this, 0); | 53 | timeEntry = new QHBox(this, 0); |
49 | timeEntry->setSpacing(0); | 54 | timeEntry->setSpacing(0); |
50 | timeEntry->setMargin(0); | 55 | timeEntry->setMargin(0); |
51 | 56 | ||
52 | dateEntry = new QHBox(this, 0); | 57 | dateEntry = new QHBox(this, 0); |
53 | dateEntry->setSpacing(0); | 58 | dateEntry->setSpacing(0); |
54 | dateEntry->setMargin(0); | 59 | dateEntry->setMargin(0); |
55 | 60 | ||
56 | textCombo = new QComboBox(textEntry, 0); | 61 | textCombo = new QComboBox(textEntry, 0); |
57 | textKey = new QLineEdit(textEntry, 0); | 62 | textKey = new QLineEdit(textEntry, 0); |
58 | 63 | ||
59 | /* Build the text combo list */ | 64 | /* Build the text combo list */ |
60 | textCombo->insertItem("less than"); | 65 | textCombo->insertItem("less than"); |
61 | textCombo->insertItem("more than"); | 66 | textCombo->insertItem("more than"); |
62 | textCombo->insertItem("equal to"); | 67 | textCombo->insertItem("equal to"); |
63 | textCombo->insertItem("containing"); | 68 | textCombo->insertItem("containing"); |
64 | textCombo->insertItem("starting with"); | 69 | textCombo->insertItem("starting with"); |
65 | textCombo->insertItem("ending with"); | 70 | textCombo->insertItem("ending with"); |
66 | 71 | ||
67 | intCombo = new QComboBox(intEntry, 0); | 72 | intCombo = new QComboBox(intEntry, 0); |
68 | intKey = new IntEdit(intEntry, 0); | 73 | intKey = new IntEdit(intEntry, 0); |
69 | 74 | ||
70 | /* Build the int combo list */ | 75 | /* Build the int combo list */ |
71 | intCombo->insertItem("less than"); | 76 | intCombo->insertItem("less than"); |
72 | intCombo->insertItem("more than"); | 77 | intCombo->insertItem("more than"); |
73 | intCombo->insertItem("equal to"); | 78 | intCombo->insertItem("equal to"); |
74 | 79 | ||
75 | timeCombo = new QComboBox(timeEntry, 0); | 80 | timeCombo = new QComboBox(timeEntry, 0); |
76 | timeKey = new TimeEdit(timeEntry, 0); | 81 | timeKey = new TimeEdit(timeEntry, 0); |
77 | 82 | ||
78 | /* Build the time combo list */ | 83 | /* Build the time combo list */ |
79 | timeCombo->insertItem("less than"); | 84 | timeCombo->insertItem("less than"); |
80 | timeCombo->insertItem("more than"); | 85 | timeCombo->insertItem("more than"); |
81 | timeCombo->insertItem("equal to"); | 86 | timeCombo->insertItem("equal to"); |
82 | 87 | ||
83 | dateCombo = new QComboBox(dateEntry, 0); | 88 | dateCombo = new QComboBox(dateEntry, 0); |
84 | dateKey = new DateEdit(dateEntry, 0); | 89 | dateKey = new DateEdit(dateEntry, 0); |
85 | 90 | ||
86 | /* Build the date combo list */ | 91 | /* Build the date combo list */ |
87 | dateCombo->insertItem("less than"); | 92 | dateCombo->insertItem("less than"); |
88 | dateCombo->insertItem("more than"); | 93 | dateCombo->insertItem("more than"); |
89 | dateCombo->insertItem("equal to"); | 94 | dateCombo->insertItem("equal to"); |
90 | 95 | ||
91 | ts = 0; | 96 | ts = 0; |
92 | 97 | ||
93 | ws = new QWidgetStack(this, 0); | 98 | ws = new QWidgetStack(this, 0); |
94 | ws->setMargin(0); | 99 | ws->setMargin(0); |
95 | ws->addWidget(textEntry, TVVariant::String); | 100 | ws->addWidget(textEntry, TVVariant::String); |
96 | ws->addWidget(intEntry, TVVariant::Int); | 101 | ws->addWidget(intEntry, TVVariant::Int); |
97 | ws->addWidget(timeEntry, TVVariant::Time); | 102 | ws->addWidget(timeEntry, TVVariant::Time); |
98 | ws->addWidget(dateEntry, TVVariant::Date); | 103 | ws->addWidget(dateEntry, TVVariant::Date); |
99 | 104 | ||
100 | /* connect the signals down */ | 105 | /* connect the signals down */ |
101 | connect(textKey, SIGNAL(textChanged(const QString&)), | 106 | connect(textKey, SIGNAL(textChanged(const QString&)), |
102 | this, SIGNAL(valueChanged())); | 107 | this, SIGNAL(valueChanged())); |
103 | connect(intKey, SIGNAL(valueChanged(int)), | 108 | connect(intKey, SIGNAL(valueChanged(int)), |
104 | this, SIGNAL(valueChanged())); | 109 | this, SIGNAL(valueChanged())); |
105 | connect(dateKey, SIGNAL(valueChanged(const QDate&)), | 110 | connect(dateKey, SIGNAL(valueChanged(const QDate&)), |
106 | this, SIGNAL(valueChanged())); | 111 | this, SIGNAL(valueChanged())); |
107 | connect(timeKey, SIGNAL(valueChanged(const QTime&)), | 112 | connect(timeKey, SIGNAL(valueChanged(const QTime&)), |
108 | this, SIGNAL(valueChanged())); | 113 | this, SIGNAL(valueChanged())); |
109 | 114 | ||
110 | connect(intCombo, SIGNAL(activated(int)), this, SIGNAL(valueChanged())); | 115 | connect(intCombo, SIGNAL(activated(int)), this, SIGNAL(valueChanged())); |
111 | connect(textCombo, SIGNAL(activated(int)), this, SIGNAL(valueChanged())); | 116 | connect(textCombo, SIGNAL(activated(int)), this, SIGNAL(valueChanged())); |
112 | connect(timeCombo, SIGNAL(activated(int)), this, SIGNAL(valueChanged())); | 117 | connect(timeCombo, SIGNAL(activated(int)), this, SIGNAL(valueChanged())); |
113 | connect(dateCombo, SIGNAL(activated(int)), this, SIGNAL(valueChanged())); | 118 | connect(dateCombo, SIGNAL(activated(int)), this, SIGNAL(valueChanged())); |
114 | 119 | ||
115 | ws->raiseWidget(TVVariant::String); | 120 | ws->raiseWidget(TVVariant::String); |
116 | layout->addWidget(ws); | 121 | layout->addWidget(ws); |
117 | 122 | ||
118 | current_type = TVVariant::String; | 123 | current_type = TVVariant::String; |
119 | } | 124 | } |
120 | 125 | ||
121 | /*! | 126 | /*! |
122 | Destructs the widget | 127 | Destructs the widget |
123 | */ | 128 | */ |
124 | TVFilterKeyEntry::~TVFilterKeyEntry() | 129 | TVFilterKeyEntry::~TVFilterKeyEntry() |
125 | { | 130 | { |
126 | } | 131 | } |
127 | 132 | ||
128 | void TVFilterKeyEntry::setKey(int i) | 133 | void TVFilterKeyEntry::setKey(int i) |
129 | { | 134 | { |
130 | 135 | ||
131 | if (!ts) return; | 136 | if (!ts) return; |
132 | if (!ts->kRep) return; | 137 | if (!ts->kRep) return; |
133 | 138 | ||
134 | /* set up to raise appropriate widget set */ | 139 | /* set up to raise appropriate widget set */ |
135 | if (current_type != ts->kRep->getKeyType(i)) { | 140 | if (current_type != ts->kRep->getKeyType(i)) { |
136 | current_type = ts->kRep->getKeyType(i); | 141 | current_type = ts->kRep->getKeyType(i); |
137 | ws->raiseWidget(current_type); | 142 | ws->raiseWidget(current_type); |
138 | } | 143 | } |
139 | } | 144 | } |
140 | 145 | ||
141 | void TVFilterKeyEntry::setTableState(TableState *t) { | 146 | void TVFilterKeyEntry::setTableState(TableState *t) { |
142 | int i; | 147 | int i; |
143 | ts = t; | 148 | ts = t; |
144 | if(!t) return; | 149 | if(!t) return; |
145 | if (!t->kRep) | 150 | if (!t->kRep) |
146 | return; | 151 | return; |
147 | if (t->kRep->getNumFields() < 1) | 152 | if (t->kRep->getNumFields() < 1) |
148 | return; | 153 | return; |
149 | setKey(0); | 154 | setKey(0); |
150 | /* set up the the menu stuff.. */ | 155 | /* set up the the menu stuff.. */ |
151 | } | 156 | } |
152 | 157 | ||
153 | CmpType TVFilterKeyEntry::getCompareType() | 158 | CmpType TVFilterKeyEntry::getCompareType() |
154 | { | 159 | { |
155 | 160 | ||
156 | switch(current_type) { | 161 | switch(current_type) { |
157 | case TVVariant::String: { | 162 | case TVVariant::String: { |
158 | CmpType k = (CmpType) textCombo->currentItem(); | 163 | CmpType k = (CmpType) textCombo->currentItem(); |
159 | return k; | 164 | return k; |
160 | } | 165 | } |
161 | case TVVariant::Int: { | 166 | case TVVariant::Int: { |
162 | CmpType k = (CmpType) intCombo->currentItem(); | 167 | CmpType k = (CmpType) intCombo->currentItem(); |
163 | return k; | 168 | return k; |
164 | } | 169 | } |
165 | case TVVariant::Time: { | 170 | case TVVariant::Time: { |
166 | CmpType k = (CmpType) timeCombo->currentItem(); | 171 | CmpType k = (CmpType) timeCombo->currentItem(); |
167 | return k; | 172 | return k; |
168 | } | 173 | } |
169 | case TVVariant::Date: { | 174 | case TVVariant::Date: { |
170 | CmpType k = (CmpType) dateCombo->currentItem(); | 175 | CmpType k = (CmpType) dateCombo->currentItem(); |
171 | return k; | 176 | return k; |
172 | } | 177 | } |
173 | default: | 178 | default: |
174 | break; | 179 | break; |
175 | } | 180 | } |
176 | return ct_equal; | 181 | return ct_equal; |
177 | } | 182 | } |
178 | 183 | ||
179 | /* MUST return a valid pointer */ | 184 | /* MUST return a valid pointer */ |
180 | TVVariant TVFilterKeyEntry::getCompareValue() | 185 | TVVariant TVFilterKeyEntry::getCompareValue() |
181 | { | 186 | { |
182 | TVVariant sendkey; | 187 | TVVariant sendkey; |
183 | int tmp; | 188 | int tmp; |
184 | 189 | ||
185 | switch(current_type) { | 190 | switch(current_type) { |
186 | case TVVariant::String: | 191 | case TVVariant::String: |
187 | sendkey = TVVariant(QString(textKey->text())); | 192 | sendkey = TVVariant(QString(textKey->text())); |
188 | break; | 193 | break; |
189 | case TVVariant::Int: { | 194 | case TVVariant::Int: { |
190 | sendkey = TVVariant(intKey->value()); | 195 | sendkey = TVVariant(intKey->value()); |
191 | break; | 196 | break; |
192 | } | 197 | } |
193 | case TVVariant::Time: { | 198 | case TVVariant::Time: { |
194 | sendkey = TVVariant(QTime(timeKey->time())); | 199 | sendkey = TVVariant(QTime(timeKey->time())); |
195 | break; | 200 | break; |
196 | } | 201 | } |
197 | case TVVariant::Date: { | 202 | case TVVariant::Date: { |
198 | sendkey = TVVariant(QDate(dateKey->date())); | 203 | sendkey = TVVariant(QDate(dateKey->date())); |
199 | break; | 204 | break; |
200 | } | 205 | } |
201 | default: { | 206 | default: { |
202 | sendkey = TVVariant(0); | 207 | sendkey = TVVariant(0); |
203 | qWarning("TVFilterKeyEntry::getCompareValue() " | 208 | owarn << "TVFilterKeyEntry::getCompareValue() cannot work out data type" << oendl; |
204 | "cannot work out data type"); | ||
205 | } | 209 | } |
206 | } | 210 | } |
207 | return sendkey; | 211 | return sendkey; |
208 | } | 212 | } |
diff --git a/noncore/apps/tableviewer/ui/tvfilterview.cpp b/noncore/apps/tableviewer/ui/tvfilterview.cpp index 22f1fb7..198c8b5 100644 --- a/noncore/apps/tableviewer/ui/tvfilterview.cpp +++ b/noncore/apps/tableviewer/ui/tvfilterview.cpp | |||
@@ -1,306 +1,311 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 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 | 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 | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 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. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | #include "tvfilterview.h" | 20 | #include "tvfilterview.h" |
21 | |||
22 | /* OPIE */ | ||
23 | #include <opie2/odebug.h> | ||
24 | #include <qpe/qpeapplication.h> | ||
25 | using namespace Opie::Core; | ||
26 | |||
27 | /* QT */ | ||
21 | #include <qtoolbutton.h> | 28 | #include <qtoolbutton.h> |
22 | #include <qcombobox.h> | 29 | #include <qcombobox.h> |
23 | #include <qlistview.h> | 30 | #include <qlistview.h> |
24 | #include <qlayout.h> | 31 | #include <qlayout.h> |
25 | #include <qheader.h> | 32 | #include <qheader.h> |
26 | #include <qpushbutton.h> | 33 | #include <qpushbutton.h> |
27 | #include <qlabel.h> | 34 | #include <qlabel.h> |
28 | 35 | ||
29 | #include <qpe/qpeapplication.h> | ||
30 | 36 | ||
31 | TVFilterView::TVFilterView(TableState *t, QWidget* parent, | 37 | TVFilterView::TVFilterView(TableState *t, QWidget* parent, |
32 | const char *name, WFlags fl ) : QDialog(parent, name, TRUE, fl) | 38 | const char *name, WFlags fl ) : QDialog(parent, name, TRUE, fl) |
33 | { | 39 | { |
34 | if ( !name ) | 40 | if ( !name ) |
35 | setName( "Filter View" ); | 41 | setName( "Filter View" ); |
36 | 42 | ||
37 | QVBoxLayout *vlayout = new QVBoxLayout(this); | 43 | QVBoxLayout *vlayout = new QVBoxLayout(this); |
38 | 44 | ||
39 | display = new QListView(this, "display"); | 45 | display = new QListView(this, "display"); |
40 | display->addColumn("Key"); | 46 | display->addColumn("Key"); |
41 | display->addColumn("Constraint"); | 47 | display->addColumn("Constraint"); |
42 | display->addColumn("Value"); | 48 | display->addColumn("Value"); |
43 | display->header()->setClickEnabled(FALSE); | 49 | display->header()->setClickEnabled(FALSE); |
44 | display->header()->setResizeEnabled(FALSE); | 50 | display->header()->setResizeEnabled(FALSE); |
45 | 51 | ||
46 | vlayout->addWidget(display); | 52 | vlayout->addWidget(display); |
47 | 53 | ||
48 | QHBoxLayout *hlayout = new QHBoxLayout; | 54 | QHBoxLayout *hlayout = new QHBoxLayout; |
49 | hlayout->addItem(new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum)); | 55 | hlayout->addItem(new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum)); |
50 | 56 | ||
51 | newFilterButton = new QPushButton(this, "new Filter"); | 57 | newFilterButton = new QPushButton(this, "new Filter"); |
52 | newFilterButton->setMaximumSize(QSize(50, 32767)); | 58 | newFilterButton->setMaximumSize(QSize(50, 32767)); |
53 | newFilterButton->setText("New"); | 59 | newFilterButton->setText("New"); |
54 | hlayout->addWidget(newFilterButton); | 60 | hlayout->addWidget(newFilterButton); |
55 | 61 | ||
56 | deleteFilterButton = new QPushButton(this, "delete Filter"); | 62 | deleteFilterButton = new QPushButton(this, "delete Filter"); |
57 | deleteFilterButton->setMaximumSize(QSize(50, 32767)); | 63 | deleteFilterButton->setMaximumSize(QSize(50, 32767)); |
58 | deleteFilterButton->setText("Delete"); | 64 | deleteFilterButton->setText("Delete"); |
59 | hlayout->addWidget(deleteFilterButton); | 65 | hlayout->addWidget(deleteFilterButton); |
60 | 66 | ||
61 | clearFilterButton = new QPushButton(this, "delete Filter"); | 67 | clearFilterButton = new QPushButton(this, "delete Filter"); |
62 | clearFilterButton->setMaximumSize(QSize(60, 32767)); | 68 | clearFilterButton->setMaximumSize(QSize(60, 32767)); |
63 | clearFilterButton->setText("Clear All"); | 69 | clearFilterButton->setText("Clear All"); |
64 | hlayout->addWidget(clearFilterButton); | 70 | hlayout->addWidget(clearFilterButton); |
65 | 71 | ||
66 | vlayout->addLayout(hlayout); | 72 | vlayout->addLayout(hlayout); |
67 | 73 | ||
68 | QHBoxLayout *hlayout2 = new QHBoxLayout; | 74 | QHBoxLayout *hlayout2 = new QHBoxLayout; |
69 | 75 | ||
70 | keyNameCombo = new QComboBox(FALSE, this, "key name"); | 76 | keyNameCombo = new QComboBox(FALSE, this, "key name"); |
71 | keyNameCombo->setEnabled(FALSE); | 77 | keyNameCombo->setEnabled(FALSE); |
72 | hlayout2->addWidget(keyNameCombo); | 78 | hlayout2->addWidget(keyNameCombo); |
73 | 79 | ||
74 | QLabel *label = new QLabel(this); | 80 | QLabel *label = new QLabel(this); |
75 | label->setText("has value"); | 81 | label->setText("has value"); |
76 | hlayout2->addWidget(label); | 82 | hlayout2->addWidget(label); |
77 | 83 | ||
78 | keyEntry = new TVFilterKeyEntry(this, "key entry"); | 84 | keyEntry = new TVFilterKeyEntry(this, "key entry"); |
79 | keyEntry->setEnabled(FALSE); | 85 | keyEntry->setEnabled(FALSE); |
80 | 86 | ||
81 | vlayout->addLayout(hlayout2); | 87 | vlayout->addLayout(hlayout2); |
82 | vlayout->addWidget(keyEntry); | 88 | vlayout->addWidget(keyEntry); |
83 | 89 | ||
84 | connect(newFilterButton, SIGNAL( clicked() ), this, SLOT( newTerm() )); | 90 | connect(newFilterButton, SIGNAL( clicked() ), this, SLOT( newTerm() )); |
85 | connect(deleteFilterButton, SIGNAL( clicked() ), this, SLOT( deleteTerm())); | 91 | connect(deleteFilterButton, SIGNAL( clicked() ), this, SLOT( deleteTerm())); |
86 | connect(clearFilterButton, SIGNAL( clicked() ), this, SLOT( clearTerms())); | 92 | connect(clearFilterButton, SIGNAL( clicked() ), this, SLOT( clearTerms())); |
87 | 93 | ||
88 | connect(keyEntry, SIGNAL(valueChanged()), this, SLOT( updateTerm() )); | 94 | connect(keyEntry, SIGNAL(valueChanged()), this, SLOT( updateTerm() )); |
89 | connect(keyNameCombo, SIGNAL(activated(int)), this, SLOT( updateTerm() )); | 95 | connect(keyNameCombo, SIGNAL(activated(int)), this, SLOT( updateTerm() )); |
90 | 96 | ||
91 | connect(display, SIGNAL(selectionChanged(QListViewItem*)), this, | 97 | connect(display, SIGNAL(selectionChanged(QListViewItem*)), this, |
92 | SLOT(setTerm(QListViewItem*))); | 98 | SLOT(setTerm(QListViewItem*))); |
93 | 99 | ||
94 | ts = t; | 100 | ts = t; |
95 | current = 0; | 101 | current = 0; |
96 | terms.setAutoDelete(true); | 102 | terms.setAutoDelete(true); |
97 | do_filter = false; | 103 | do_filter = false; |
98 | 104 | ||
99 | #ifdef Q_WS_QWS | 105 | #ifdef Q_WS_QWS |
100 | QPEApplication::showDialog( this ); | 106 | QPEApplication::showDialog( this ); |
101 | #endif | 107 | #endif |
102 | } | 108 | } |
103 | 109 | ||
104 | /*! | 110 | /*! |
105 | Destroys the TVFilterView widget | 111 | Destroys the TVFilterView widget |
106 | */ | 112 | */ |
107 | TVFilterView::~TVFilterView() | 113 | TVFilterView::~TVFilterView() |
108 | { | 114 | { |
109 | } | 115 | } |
110 | 116 | ||
111 | void TVFilterView::rebuildData() | 117 | void TVFilterView::rebuildData() |
112 | { | 118 | { |
113 | } | 119 | } |
114 | 120 | ||
115 | void TVFilterView::reset() | 121 | void TVFilterView::reset() |
116 | { | 122 | { |
117 | keyNameCombo->clear(); | 123 | keyNameCombo->clear(); |
118 | keyIds.clear(); | 124 | keyIds.clear(); |
119 | } | 125 | } |
120 | 126 | ||
121 | void TVFilterView::rebuildKeys() | 127 | void TVFilterView::rebuildKeys() |
122 | { | 128 | { |
123 | int i; | 129 | int i; |
124 | 130 | ||
125 | if (!ts) return; | 131 | if (!ts) return; |
126 | if(!ts->kRep) return; | 132 | if(!ts->kRep) return; |
127 | keyEntry->setTableState(ts); | 133 | keyEntry->setTableState(ts); |
128 | 134 | ||
129 | /* set up the list of keys that can be compared on */ | 135 | /* set up the list of keys that can be compared on */ |
130 | keyNameCombo->clear(); | 136 | keyNameCombo->clear(); |
131 | KeyListIterator it(*ts->kRep); | 137 | KeyListIterator it(*ts->kRep); |
132 | 138 | ||
133 | i = 0; | 139 | i = 0; |
134 | while(it.current()) { | 140 | while(it.current()) { |
135 | if(ts->kRep->validIndex(it.currentKey())) { | 141 | if(ts->kRep->validIndex(it.currentKey())) { |
136 | keyNameCombo->insertItem(it.current()->name()); | 142 | keyNameCombo->insertItem(it.current()->name()); |
137 | keyIds.insert(i, it.currentKey()); | 143 | keyIds.insert(i, it.currentKey()); |
138 | ++i; | 144 | ++i; |
139 | } | 145 | } |
140 | ++it; | 146 | ++it; |
141 | } | 147 | } |
142 | } | 148 | } |
143 | 149 | ||
144 | bool TVFilterView::passesFilter(DataElem *d) { | 150 | bool TVFilterView::passesFilter(DataElem *d) { |
145 | if (!filterActive()) return true; | 151 | if (!filterActive()) return true; |
146 | 152 | ||
147 | 153 | ||
148 | FilterTerm *t; | 154 | FilterTerm *t; |
149 | 155 | ||
150 | for (t = terms.first(); t != 0; t = terms.next() ) { | 156 | for (t = terms.first(); t != 0; t = terms.next() ) { |
151 | /* check against filter */ | 157 | /* check against filter */ |
152 | switch(t->ct) { | 158 | switch(t->ct) { |
153 | case ct_less: | 159 | case ct_less: |
154 | if (!d->lessThan(t->keyIndex, t->value)) | 160 | if (!d->lessThan(t->keyIndex, t->value)) |
155 | return false; | 161 | return false; |
156 | break; | 162 | break; |
157 | case ct_more: | 163 | case ct_more: |
158 | if (!d->moreThan(t->keyIndex, t->value)) | 164 | if (!d->moreThan(t->keyIndex, t->value)) |
159 | return false; | 165 | return false; |
160 | break; | 166 | break; |
161 | case ct_equal: | 167 | case ct_equal: |
162 | if (!d->equalTo(t->keyIndex, t->value)) | 168 | if (!d->equalTo(t->keyIndex, t->value)) |
163 | return false; | 169 | return false; |
164 | break; | 170 | break; |
165 | case ct_contains: | 171 | case ct_contains: |
166 | if (!d->contains(t->keyIndex, t->value)) | 172 | if (!d->contains(t->keyIndex, t->value)) |
167 | return false; | 173 | return false; |
168 | break; | 174 | break; |
169 | case ct_startswith: | 175 | case ct_startswith: |
170 | if (!d->startsWith(t->keyIndex, t->value)) | 176 | if (!d->startsWith(t->keyIndex, t->value)) |
171 | return false; | 177 | return false; |
172 | break; | 178 | break; |
173 | case ct_endswith: | 179 | case ct_endswith: |
174 | if (!d->endsWith(t->keyIndex, t->value)) | 180 | if (!d->endsWith(t->keyIndex, t->value)) |
175 | return false; | 181 | return false; |
176 | break; | 182 | break; |
177 | default: | 183 | default: |
178 | qWarning("TVFilterView::passesFilter() " | 184 | owarn << "TVFilterView::passesFilter() unrecognized filter type" << oendl; |
179 | "unrecognized filter type"); | ||
180 | return false; | 185 | return false; |
181 | } | 186 | } |
182 | } | 187 | } |
183 | return true; | 188 | return true; |
184 | } | 189 | } |
185 | 190 | ||
186 | bool TVFilterView::filterActive() const | 191 | bool TVFilterView::filterActive() const |
187 | { | 192 | { |
188 | /* when button operated, also check the do_filter value | 193 | /* when button operated, also check the do_filter value |
189 | return do_filter; | 194 | return do_filter; |
190 | */ | 195 | */ |
191 | if (terms.isEmpty()) | 196 | if (terms.isEmpty()) |
192 | return false; | 197 | return false; |
193 | return true; | 198 | return true; |
194 | } | 199 | } |
195 | 200 | ||
196 | /* SLOTS */ | 201 | /* SLOTS */ |
197 | void TVFilterView::newTerm() | 202 | void TVFilterView::newTerm() |
198 | { | 203 | { |
199 | if (!ts) return; | 204 | if (!ts) return; |
200 | 205 | ||
201 | FilterTerm *term = new FilterTerm; | 206 | FilterTerm *term = new FilterTerm; |
202 | current = term; | 207 | current = term; |
203 | 208 | ||
204 | term->view = 0; | 209 | term->view = 0; |
205 | 210 | ||
206 | updateTerm(); | 211 | updateTerm(); |
207 | 212 | ||
208 | display->setSelected(term->view, true); | 213 | display->setSelected(term->view, true); |
209 | terms.append(term); | 214 | terms.append(term); |
210 | 215 | ||
211 | keyEntry->setEnabled(true); | 216 | keyEntry->setEnabled(true); |
212 | keyNameCombo->setEnabled(true); | 217 | keyNameCombo->setEnabled(true); |
213 | } | 218 | } |
214 | 219 | ||
215 | void TVFilterView::updateTerm() | 220 | void TVFilterView::updateTerm() |
216 | { | 221 | { |
217 | FilterTerm *term; | 222 | FilterTerm *term; |
218 | /* Read the widget values (keyname, compare type, value) | 223 | /* Read the widget values (keyname, compare type, value) |
219 | * and build the lists */ | 224 | * and build the lists */ |
220 | if (!ts) return; | 225 | if (!ts) return; |
221 | if (!current) return; | 226 | if (!current) return; |
222 | 227 | ||
223 | QString keyString; | 228 | QString keyString; |
224 | QString cmpString; | 229 | QString cmpString; |
225 | QString vString; | 230 | QString vString; |
226 | 231 | ||
227 | term = current; | 232 | term = current; |
228 | 233 | ||
229 | /* create new list item, set initial values, enable widgets */ | 234 | /* create new list item, set initial values, enable widgets */ |
230 | term->keyIndex = keyIds[keyNameCombo->currentItem()]; | 235 | term->keyIndex = keyIds[keyNameCombo->currentItem()]; |
231 | keyEntry->setKey(term->keyIndex); /* so the next two items make sense */ | 236 | keyEntry->setKey(term->keyIndex); /* so the next two items make sense */ |
232 | term->ct = keyEntry->getCompareType(), | 237 | term->ct = keyEntry->getCompareType(), |
233 | term->value = keyEntry->getCompareValue(); | 238 | term->value = keyEntry->getCompareValue(); |
234 | 239 | ||
235 | keyString = keyNameCombo->currentText(); | 240 | keyString = keyNameCombo->currentText(); |
236 | 241 | ||
237 | switch(term->ct) { | 242 | switch(term->ct) { |
238 | case ct_less: | 243 | case ct_less: |
239 | cmpString = " less than "; | 244 | cmpString = " less than "; |
240 | break; | 245 | break; |
241 | case ct_more: | 246 | case ct_more: |
242 | cmpString = " more than "; | 247 | cmpString = " more than "; |
243 | break; | 248 | break; |
244 | case ct_equal: | 249 | case ct_equal: |
245 | cmpString = " equal to "; | 250 | cmpString = " equal to "; |
246 | break; | 251 | break; |
247 | case ct_contains: | 252 | case ct_contains: |
248 | cmpString = " containing "; | 253 | cmpString = " containing "; |
249 | break; | 254 | break; |
250 | case ct_startswith: | 255 | case ct_startswith: |
251 | cmpString = " starting with "; | 256 | cmpString = " starting with "; |
252 | break; | 257 | break; |
253 | case ct_endswith: | 258 | case ct_endswith: |
254 | cmpString = " ending with "; | 259 | cmpString = " ending with "; |
255 | break; | 260 | break; |
256 | default: | 261 | default: |
257 | cmpString = " ERROR "; | 262 | cmpString = " ERROR "; |
258 | } | 263 | } |
259 | 264 | ||
260 | vString = term->value.toString(); | 265 | vString = term->value.toString(); |
261 | 266 | ||
262 | /* remove old view */ | 267 | /* remove old view */ |
263 | if (term->view) | 268 | if (term->view) |
264 | delete(term->view); | 269 | delete(term->view); |
265 | term->view = new QListViewItem(display, 0, keyString, cmpString, vString); | 270 | term->view = new QListViewItem(display, 0, keyString, cmpString, vString); |
266 | display->setSelected(term->view, true); | 271 | display->setSelected(term->view, true); |
267 | } | 272 | } |
268 | 273 | ||
269 | /* deletes current term */ | 274 | /* deletes current term */ |
270 | void TVFilterView::deleteTerm() | 275 | void TVFilterView::deleteTerm() |
271 | { | 276 | { |
272 | if(!current) return; | 277 | if(!current) return; |
273 | if (current->view) | 278 | if (current->view) |
274 | delete(current->view); | 279 | delete(current->view); |
275 | 280 | ||
276 | terms.removeRef(current); | 281 | terms.removeRef(current); |
277 | 282 | ||
278 | current = terms.first(); | 283 | current = terms.first(); |
279 | 284 | ||
280 | if(terms.isEmpty()) { | 285 | if(terms.isEmpty()) { |
281 | keyEntry->setEnabled(false); | 286 | keyEntry->setEnabled(false); |
282 | keyNameCombo->setEnabled(false); | 287 | keyNameCombo->setEnabled(false); |
283 | } | 288 | } |
284 | } | 289 | } |
285 | 290 | ||
286 | /* clears all terminations */ | 291 | /* clears all terminations */ |
287 | void TVFilterView::clearTerms() | 292 | void TVFilterView::clearTerms() |
288 | { | 293 | { |
289 | while(current) | 294 | while(current) |
290 | deleteTerm(); | 295 | deleteTerm(); |
291 | } | 296 | } |
292 | 297 | ||
293 | void TVFilterView::setTerm(QListViewItem *target) | 298 | void TVFilterView::setTerm(QListViewItem *target) |
294 | { | 299 | { |
295 | /* Iterate through the list to find item with view=target.. | 300 | /* Iterate through the list to find item with view=target.. |
296 | * set as current, delete */ | 301 | * set as current, delete */ |
297 | FilterTerm *term = current; | 302 | FilterTerm *term = current; |
298 | 303 | ||
299 | for (current = terms.first(); current != 0; current = terms.next() ) | 304 | for (current = terms.first(); current != 0; current = terms.next() ) |
300 | if (current->view == target) | 305 | if (current->view == target) |
301 | break; | 306 | break; |
302 | 307 | ||
303 | if (!current) { | 308 | if (!current) { |
304 | current = term; | 309 | current = term; |
305 | } | 310 | } |
306 | } | 311 | } |
diff --git a/noncore/apps/tinykate/libkate/kateconfig.cpp b/noncore/apps/tinykate/libkate/kateconfig.cpp index 782b629..4b8ce78 100644 --- a/noncore/apps/tinykate/libkate/kateconfig.cpp +++ b/noncore/apps/tinykate/libkate/kateconfig.cpp | |||
@@ -1,90 +1,91 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 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 | 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 | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 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. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #define QTOPIA_INTERNAL_LANGLIST | 21 | #define QTOPIA_INTERNAL_LANGLIST |
22 | #include "kateconfig.h" | 22 | #include "kateconfig.h" |
23 | 23 | ||
24 | /* OPIE */ | 24 | /* OPIE */ |
25 | #include <opie2/odebug.h> | 25 | #include <opie2/odebug.h> |
26 | #include <qpe/global.h> | 26 | #include <qpe/global.h> |
27 | using namespace Opie::Core; | ||
27 | 28 | ||
28 | /* QT */ | 29 | /* QT */ |
29 | #include <qdir.h> | 30 | #include <qdir.h> |
30 | #include <qmessagebox.h> | 31 | #include <qmessagebox.h> |
31 | #if QT_VERSION <= 230 && defined(QT_NO_CODECS) | 32 | #if QT_VERSION <= 230 && defined(QT_NO_CODECS) |
32 | #include <qtextcodec.h> | 33 | #include <qtextcodec.h> |
33 | #endif | 34 | #endif |
34 | #include <qtextstream.h> | 35 | #include <qtextstream.h> |
35 | 36 | ||
36 | /* STD */ | 37 | /* STD */ |
37 | #include <sys/stat.h> | 38 | #include <sys/stat.h> |
38 | #include <sys/types.h> | 39 | #include <sys/types.h> |
39 | #include <fcntl.h> | 40 | #include <fcntl.h> |
40 | #include <stdlib.h> | 41 | #include <stdlib.h> |
41 | #include <unistd.h> | 42 | #include <unistd.h> |
42 | 43 | ||
43 | 44 | ||
44 | /*! | 45 | /*! |
45 | \internal | 46 | \internal |
46 | */ | 47 | */ |
47 | QString KateConfig::configFilename(const QString& name, Domain d) | 48 | QString KateConfig::configFilename(const QString& name, Domain d) |
48 | { | 49 | { |
49 | switch (d) { | 50 | switch (d) { |
50 | case File: | 51 | case File: |
51 | return name; | 52 | return name; |
52 | case User: { | 53 | case User: { |
53 | QDir dir = (QString(getenv("HOME")) + "/Settings"); | 54 | QDir dir = (QString(getenv("HOME")) + "/Settings"); |
54 | if ( !dir.exists() ) | 55 | if ( !dir.exists() ) |
55 | mkdir(dir.path().local8Bit(),0700); | 56 | mkdir(dir.path().local8Bit(),0700); |
56 | return dir.path() + "/" + name + ".conf"; | 57 | return dir.path() + "/" + name + ".conf"; |
57 | } | 58 | } |
58 | } | 59 | } |
59 | return name; | 60 | return name; |
60 | } | 61 | } |
61 | 62 | ||
62 | /*! | 63 | /*! |
63 | \class KateConfig config.h | 64 | \class KateConfig config.h |
64 | \brief The KateConfig class provides for saving application cofniguration state. | 65 | \brief The KateConfig class provides for saving application cofniguration state. |
65 | 66 | ||
66 | You should keep a KateConfig in existence only while you do not want others | 67 | You should keep a KateConfig in existence only while you do not want others |
67 | to be able to change the state. There is no locking currently, but there | 68 | to be able to change the state. There is no locking currently, but there |
68 | may be in the future. | 69 | may be in the future. |
69 | */ | 70 | */ |
70 | 71 | ||
71 | /*! | 72 | /*! |
72 | \enum KateConfig::KateConfigGroup | 73 | \enum KateConfig::KateConfigGroup |
73 | \internal | 74 | \internal |
74 | */ | 75 | */ |
75 | 76 | ||
76 | /*! | 77 | /*! |
77 | \enum KateConfig::Domain | 78 | \enum KateConfig::Domain |
78 | 79 | ||
79 | \value File | 80 | \value File |
80 | \value User | 81 | \value User |
81 | 82 | ||
82 | See KateConfig for details. | 83 | See KateConfig for details. |
83 | */ | 84 | */ |
84 | 85 | ||
85 | /*! | 86 | /*! |
86 | Constructs a config that will load or create a configuration with the | 87 | Constructs a config that will load or create a configuration with the |
87 | given \a name in the given \a domain. | 88 | given \a name in the given \a domain. |
88 | 89 | ||
89 | You must call setGroup() before doing much else with the KateConfig. | 90 | You must call setGroup() before doing much else with the KateConfig. |
90 | 91 | ||
@@ -495,130 +496,129 @@ QValueList<int> KateConfig::readIntListEntry( const QString &key ) const | |||
495 | 496 | ||
496 | QStringList::Iterator l_it; | 497 | QStringList::Iterator l_it; |
497 | for( l_it = l.begin(); l_it != l.end(); ++l_it ) | 498 | for( l_it = l.begin(); l_it != l.end(); ++l_it ) |
498 | il.append( (*l_it).toInt() ); | 499 | il.append( (*l_it).toInt() ); |
499 | return il; | 500 | return il; |
500 | } | 501 | } |
501 | 502 | ||
502 | /*! | 503 | /*! |
503 | Removes all entries from the current group. | 504 | Removes all entries from the current group. |
504 | */ | 505 | */ |
505 | void KateConfig::clearGroup() | 506 | void KateConfig::clearGroup() |
506 | { | 507 | { |
507 | if ( git == groups.end() ) { | 508 | if ( git == groups.end() ) { |
508 | owarn << "no group set" << oendl; | 509 | owarn << "no group set" << oendl; |
509 | return; | 510 | return; |
510 | } | 511 | } |
511 | if ( !(*git).isEmpty() ) { | 512 | if ( !(*git).isEmpty() ) { |
512 | ( *git ).clear(); | 513 | ( *git ).clear(); |
513 | changed = TRUE; | 514 | changed = TRUE; |
514 | } | 515 | } |
515 | } | 516 | } |
516 | 517 | ||
517 | /*! | 518 | /*! |
518 | \internal | 519 | \internal |
519 | */ | 520 | */ |
520 | void KateConfig::write( const QString &fn ) | 521 | void KateConfig::write( const QString &fn ) |
521 | { | 522 | { |
522 | QString strNewFile; | 523 | QString strNewFile; |
523 | if ( !fn.isEmpty() ) | 524 | if ( !fn.isEmpty() ) |
524 | filename = fn; | 525 | filename = fn; |
525 | strNewFile = filename + ".new"; | 526 | strNewFile = filename + ".new"; |
526 | 527 | ||
527 | QFile f( strNewFile ); | 528 | QFile f( strNewFile ); |
528 | if ( !f.open( IO_WriteOnly|IO_Raw ) ) { | 529 | if ( !f.open( IO_WriteOnly|IO_Raw ) ) { |
529 | owarn << "could not open for writing `" << strNewFile << "'" << oendl; | 530 | owarn << "could not open for writing `" << strNewFile << "'" << oendl; |
530 | git = groups.end(); | 531 | git = groups.end(); |
531 | return; | 532 | return; |
532 | } | 533 | } |
533 | 534 | ||
534 | QString str; | 535 | QString str; |
535 | QCString cstr; | 536 | QCString cstr; |
536 | QMap< QString, KateConfigGroup >::Iterator g_it = groups.begin(); | 537 | QMap< QString, KateConfigGroup >::Iterator g_it = groups.begin(); |
537 | 538 | ||
538 | for ( ; g_it != groups.end(); ++g_it ) { | 539 | for ( ; g_it != groups.end(); ++g_it ) { |
539 | str += "[" + g_it.key() + "]\n"; | 540 | str += "[" + g_it.key() + "]\n"; |
540 | KateConfigGroup::Iterator e_it = ( *g_it ).begin(); | 541 | KateConfigGroup::Iterator e_it = ( *g_it ).begin(); |
541 | for ( ; e_it != ( *g_it ).end(); ++e_it ) | 542 | for ( ; e_it != ( *g_it ).end(); ++e_it ) |
542 | str += e_it.key() + " = " + *e_it + "\n"; | 543 | str += e_it.key() + " = " + *e_it + "\n"; |
543 | } | 544 | } |
544 | cstr = str.utf8(); | 545 | cstr = str.utf8(); |
545 | 546 | ||
546 | int total_length; | 547 | int total_length; |
547 | total_length = f.writeBlock( cstr.data(), cstr.length() ); | 548 | total_length = f.writeBlock( cstr.data(), cstr.length() ); |
548 | if ( total_length != int(cstr.length()) ) { | 549 | if ( total_length != int(cstr.length()) ) { |
549 | QMessageBox::critical( 0, QObject::tr("Out of Space"), | 550 | QMessageBox::critical( 0, QObject::tr("Out of Space"), |
550 | QObject::tr("There was a problem creating\nKateConfiguration Information \nfor this program.\n\nPlease free up some space and\ntry again.") ); | 551 | QObject::tr("There was a problem creating\nKateConfiguration Information \nfor this program.\n\nPlease free up some space and\ntry again.") ); |
551 | f.close(); | 552 | f.close(); |
552 | QFile::remove( strNewFile ); | 553 | QFile::remove( strNewFile ); |
553 | return; | 554 | return; |
554 | } | 555 | } |
555 | 556 | ||
556 | f.close(); | 557 | f.close(); |
557 | // now rename the file... | 558 | // now rename the file... |
558 | if ( rename( strNewFile, filename ) < 0 ) { | 559 | if ( rename( strNewFile, filename ) < 0 ) { |
559 | qWarning( "problem renaming the file %s to %s", strNewFile.latin1(), | 560 | owarn << "problem renaming the file " << strNewFile.latin1() << " to " << filename.latin1() << oendl; |
560 | filename.latin1() ); | ||
561 | QFile::remove( strNewFile ); | 561 | QFile::remove( strNewFile ); |
562 | } | 562 | } |
563 | } | 563 | } |
564 | 564 | ||
565 | /*! | 565 | /*! |
566 | Returns whether the KateConfig is in a valid state. | 566 | Returns whether the KateConfig is in a valid state. |
567 | */ | 567 | */ |
568 | bool KateConfig::isValid() const | 568 | bool KateConfig::isValid() const |
569 | { | 569 | { |
570 | return groups.end() != git; | 570 | return groups.end() != git; |
571 | } | 571 | } |
572 | 572 | ||
573 | /*! | 573 | /*! |
574 | \internal | 574 | \internal |
575 | */ | 575 | */ |
576 | void KateConfig::read() | 576 | void KateConfig::read() |
577 | { | 577 | { |
578 | changed = FALSE; | 578 | changed = FALSE; |
579 | 579 | ||
580 | if ( !QFileInfo( filename ).exists() ) { | 580 | if ( !QFileInfo( filename ).exists() ) { |
581 | git = groups.end(); | 581 | git = groups.end(); |
582 | return; | 582 | return; |
583 | } | 583 | } |
584 | 584 | ||
585 | QFile f( filename ); | 585 | QFile f( filename ); |
586 | if ( !f.open( IO_ReadOnly ) ) { | 586 | if ( !f.open( IO_ReadOnly ) ) { |
587 | git = groups.end(); | 587 | git = groups.end(); |
588 | return; | 588 | return; |
589 | } | 589 | } |
590 | 590 | ||
591 | QTextStream s( &f ); | 591 | QTextStream s( &f ); |
592 | #if QT_VERSION <= 230 && defined(QT_NO_CODECS) | 592 | #if QT_VERSION <= 230 && defined(QT_NO_CODECS) |
593 | // The below should work, but doesn't in Qt 2.3.0 | 593 | // The below should work, but doesn't in Qt 2.3.0 |
594 | s.setCodec( QTextCodec::codecForMib( 106 ) ); | 594 | s.setCodec( QTextCodec::codecForMib( 106 ) ); |
595 | #else | 595 | #else |
596 | s.setEncoding( QTextStream::UnicodeUTF8 ); | 596 | s.setEncoding( QTextStream::UnicodeUTF8 ); |
597 | #endif | 597 | #endif |
598 | 598 | ||
599 | QStringList list = QStringList::split('\n', s.read() ); | 599 | QStringList list = QStringList::split('\n', s.read() ); |
600 | f.close(); | 600 | f.close(); |
601 | 601 | ||
602 | for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { | 602 | for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { |
603 | if ( !parse( *it ) ) { | 603 | if ( !parse( *it ) ) { |
604 | git = groups.end(); | 604 | git = groups.end(); |
605 | return; | 605 | return; |
606 | } | 606 | } |
607 | } | 607 | } |
608 | } | 608 | } |
609 | 609 | ||
610 | /*! | 610 | /*! |
611 | \internal | 611 | \internal |
612 | */ | 612 | */ |
613 | bool KateConfig::parse( const QString &l ) | 613 | bool KateConfig::parse( const QString &l ) |
614 | { | 614 | { |
615 | QString line = l.stripWhiteSpace(); | 615 | QString line = l.stripWhiteSpace(); |
616 | 616 | ||
617 | if ( line [0] == QChar ( '#' )) | 617 | if ( line [0] == QChar ( '#' )) |
618 | return true; // ignore comments | 618 | return true; // ignore comments |
619 | 619 | ||
620 | if ( line[ 0 ] == QChar( '[' ) ) { | 620 | if ( line[ 0 ] == QChar( '[' ) ) { |
621 | QString gname = line; | 621 | QString gname = line; |
622 | gname = gname.remove( 0, 1 ); | 622 | gname = gname.remove( 0, 1 ); |
623 | if ( gname[ (int)gname.length() - 1 ] == QChar( ']' ) ) | 623 | if ( gname[ (int)gname.length() - 1 ] == QChar( ']' ) ) |
624 | gname = gname.remove( gname.length() - 1, 1 ); | 624 | gname = gname.remove( gname.length() - 1, 1 ); |
diff --git a/noncore/apps/zsafe/main.cpp b/noncore/apps/zsafe/main.cpp index 4fe319b..5f48f77 100644 --- a/noncore/apps/zsafe/main.cpp +++ b/noncore/apps/zsafe/main.cpp | |||
@@ -1,111 +1,116 @@ | |||
1 | /* | 1 | /* |
2 | ** Author: Carsten Schneider <CarstenSchneider@t-online.de> | 2 | ** Author: Carsten Schneider <CarstenSchneider@t-online.de> |
3 | ** | 3 | ** |
4 | ** $Id$ | 4 | ** $Id$ |
5 | ** | 5 | ** |
6 | ** Homepage: http://home.t-online.de/home/CarstenSchneider/zsafe/index.html | 6 | ** Homepage: http://home.t-online.de/home/CarstenSchneider/zsafe/index.html |
7 | */ | 7 | */ |
8 | 8 | ||
9 | 9 | ||
10 | #include "zsafe.h" | 10 | #include "zsafe.h" |
11 | |||
12 | /* OPIE */ | ||
13 | #include <opie2/odebug.h> | ||
14 | using namespace Opie::Core; | ||
15 | |||
16 | /* QT */ | ||
11 | #ifdef DESKTOP | 17 | #ifdef DESKTOP |
12 | #include <qapplication.h> | 18 | #include <qapplication.h> |
13 | #else | 19 | #else |
14 | #include <qpe/qpeapplication.h> | 20 | #include <qpe/qpeapplication.h> |
15 | #endif | 21 | #endif |
22 | |||
23 | /* STD */ | ||
16 | #include <stdio.h> | 24 | #include <stdio.h> |
17 | #include <signal.h> | 25 | #include <signal.h> |
18 | 26 | ||
19 | ZSafe *zs; | 27 | ZSafe *zs; |
20 | #ifdef DESKTOP | 28 | #ifdef DESKTOP |
21 | QApplication *appl; | 29 | QApplication *appl; |
22 | #else | 30 | #else |
23 | QPEApplication *appl; | 31 | QPEApplication *appl; |
24 | #endif | 32 | #endif |
25 | 33 | ||
26 | int DeskW; | 34 | int DeskW; |
27 | int DeskH; | 35 | int DeskH; |
28 | 36 | ||
29 | void suspend (int signum) | 37 | void suspend (int signum) |
30 | { | 38 | { |
31 | printf ("Suspend signal %d received\n", signum); | 39 | printf ("Suspend signal %d received\n", signum); |
32 | } | 40 | } |
33 | 41 | ||
34 | void resume (int signum) | 42 | void resume (int signum) |
35 | { | 43 | { |
36 | printf ("Resume signal %d received\n", signum); | 44 | printf ("Resume signal %d received\n", signum); |
37 | zs->resume(signum); | 45 | zs->resume(signum); |
38 | } | 46 | } |
39 | 47 | ||
40 | int main( int argc, char ** argv ) | 48 | int main( int argc, char ** argv ) |
41 | { | 49 | { |
42 | #ifndef WIN32 | 50 | #ifndef WIN32 |
43 | // install signal handler | 51 | // install signal handler |
44 | signal (SIGSTOP, suspend); | 52 | signal (SIGSTOP, suspend); |
45 | #endif | 53 | #endif |
46 | 54 | ||
47 | #ifdef DESKTOP | 55 | #ifdef DESKTOP |
48 | QApplication a( argc, argv ); | 56 | QApplication a( argc, argv ); |
49 | #else | 57 | #else |
50 | QPEApplication a( argc, argv ); | 58 | QPEApplication a( argc, argv ); |
51 | #endif | 59 | #endif |
52 | appl = &a; | 60 | appl = &a; |
53 | 61 | ||
54 | #ifdef DESKTOP | 62 | #ifdef DESKTOP |
55 | if (argc >= 3) | 63 | if (argc >= 3) |
56 | { | 64 | { |
57 | #ifndef WIN32 | 65 | #ifndef WIN32 |
58 | DeskW = atoi(argv[1]); | 66 | DeskW = atoi(argv[1]); |
59 | DeskH = atoi(argv[2]); | 67 | DeskH = atoi(argv[2]); |
60 | #else | 68 | #else |
61 | int w, h; | 69 | int w, h; |
62 | sscanf (argv[1], "%d", &w); | 70 | sscanf (argv[1], "%d", &w); |
63 | sscanf (argv[2], "%d", &h); | 71 | sscanf (argv[2], "%d", &h); |
64 | DeskW = w; | 72 | DeskW = w; |
65 | DeskH = h; | 73 | DeskH = h; |
66 | #endif | 74 | #endif |
67 | } | 75 | } |
68 | else | 76 | else |
69 | { | 77 | { |
70 | DeskW = 600; | 78 | DeskW = 600; |
71 | DeskH = 400; | 79 | DeskH = 400; |
72 | } | 80 | } |
73 | #else | 81 | #else |
74 | DeskW = a.desktop()->width(); | 82 | DeskW = a.desktop()->width(); |
75 | DeskH = a.desktop()->height(); | 83 | DeskH = a.desktop()->height(); |
76 | 84 | ||
77 | char buf[128]; | 85 | owarn << "Width: " << DeskW << " Height: " << DeskH << oendl; |
78 | sprintf (buf, "Width: %d Height: %d\n", DeskW, DeskH); | ||
79 | qWarning (buf); | ||
80 | 86 | ||
81 | #ifdef JPATCH_HDE | 87 | #ifdef JPATCH_HDE |
82 | // nothings | 88 | // nothings |
83 | #else | 89 | #else |
84 | if (DeskW > 240) | 90 | if (DeskW > 240) |
85 | { | 91 | { |
86 | DeskW -= 20; | 92 | DeskW -= 20; |
87 | DeskH += 25; | 93 | DeskH += 25; |
88 | sprintf (buf, "Changed width: %d Height: %d\n", DeskW, DeskH); | 94 | owarn << "Changed width: " << DeskW << " Height: " << DeskH << oendl; |
89 | qWarning (buf); | ||
90 | } | 95 | } |
91 | #endif | 96 | #endif |
92 | 97 | ||
93 | #endif | 98 | #endif |
94 | 99 | ||
95 | ZSafe mw; | 100 | ZSafe mw; |
96 | zs = &mw; | 101 | zs = &mw; |
97 | 102 | ||
98 | #ifndef WIN32 | 103 | #ifndef WIN32 |
99 | signal (SIGCONT, resume); | 104 | signal (SIGCONT, resume); |
100 | #endif | 105 | #endif |
101 | #ifdef DESKTOP | 106 | #ifdef DESKTOP |
102 | a.setMainWidget(&mw); | 107 | a.setMainWidget(&mw); |
103 | mw.show(); | 108 | mw.show(); |
104 | #else | 109 | #else |
105 | // a.showMainWidget( &mw ); | 110 | // a.showMainWidget( &mw ); |
106 | a.showMainDocumentWidget( &mw ); | 111 | a.showMainDocumentWidget( &mw ); |
107 | #endif | 112 | #endif |
108 | int ret = a.exec(); | 113 | int ret = a.exec(); |
109 | 114 | ||
110 | return ret; | 115 | return ret; |
111 | } | 116 | } |
diff --git a/noncore/apps/zsafe/zlistview.cpp b/noncore/apps/zsafe/zlistview.cpp index ba02a15..7d0b8c2 100644 --- a/noncore/apps/zsafe/zlistview.cpp +++ b/noncore/apps/zsafe/zlistview.cpp | |||
@@ -1,36 +1,39 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id$ | 2 | ** $Id$ |
3 | */ | 3 | */ |
4 | 4 | ||
5 | #include "zlistview.h" | 5 | #include "zlistview.h" |
6 | #include <stdio.h> | ||
7 | #include "zsafe.h" | 6 | #include "zsafe.h" |
8 | 7 | ||
8 | /* OPIE */ | ||
9 | //#include <opie2/odebug.h> | ||
10 | |||
11 | /* STD */ | ||
12 | #include <stdio.h> | ||
13 | |||
9 | ZListView::ZListView (ZSafe *zsafe, const char *id) : QListView(zsafe, id) | 14 | ZListView::ZListView (ZSafe *zsafe, const char *id) : QListView(zsafe, id) |
10 | { | 15 | { |
11 | zs = zsafe; | 16 | zs = zsafe; |
12 | } | 17 | } |
13 | 18 | ||
14 | ZListView::~ZListView() | 19 | ZListView::~ZListView() |
15 | { | 20 | { |
16 | } | 21 | } |
17 | 22 | ||
18 | void ZListView::keyPressEvent ( QKeyEvent *e ) | 23 | void ZListView::keyPressEvent ( QKeyEvent *e ) |
19 | { | 24 | { |
20 | /* | 25 | /* |
21 | char buf[64]; | 26 | owarn << "key: " << e->key() << oendl; |
22 | sprintf (buf, "key: %d\n", e->key()); | ||
23 | qWarning (buf); | ||
24 | */ | 27 | */ |
25 | 28 | ||
26 | switch (e->key()) | 29 | switch (e->key()) |
27 | { | 30 | { |
28 | case 32: // middle cursor key pressed | 31 | case 32: // middle cursor key pressed |
29 | zs->showInfo (zs->selectedItem); | 32 | zs->showInfo (zs->selectedItem); |
30 | break; | 33 | break; |
31 | default: | 34 | default: |
32 | QListView::keyPressEvent( e ); | 35 | QListView::keyPressEvent( e ); |
33 | } | 36 | } |
34 | 37 | ||
35 | } | 38 | } |
36 | 39 | ||
diff --git a/noncore/apps/zsafe/zsafe.cpp b/noncore/apps/zsafe/zsafe.cpp index 6ff05ac..ca3ff52 100644 --- a/noncore/apps/zsafe/zsafe.cpp +++ b/noncore/apps/zsafe/zsafe.cpp | |||
@@ -820,206 +820,206 @@ retype: | |||
820 | QMessageBox::critical( 0, tr("ZSafe"), | 820 | QMessageBox::critical( 0, tr("ZSafe"), |
821 | tr("Entry name must be different\nfrom the category name.") ); | 821 | tr("Entry name must be different\nfrom the category name.") ); |
822 | goto retype; // it's not a good programming style :-) | 822 | goto retype; // it's not a good programming style :-) |
823 | } | 823 | } |
824 | 824 | ||
825 | modified = true; | 825 | modified = true; |
826 | // add the new item | 826 | // add the new item |
827 | QListViewItem *i = new ShadedListItem (0, selectedItem); | 827 | QListViewItem *i = new ShadedListItem (0, selectedItem); |
828 | i->setOpen (TRUE); | 828 | i->setOpen (TRUE); |
829 | 829 | ||
830 | i->setText (0, tr (name)); | 830 | i->setText (0, tr (name)); |
831 | QString user = dialog->UsernameField->text(); | 831 | QString user = dialog->UsernameField->text(); |
832 | i->setText (1, tr (user)); | 832 | i->setText (1, tr (user)); |
833 | QString pwd = dialog->PasswordField->text(); | 833 | QString pwd = dialog->PasswordField->text(); |
834 | i->setText (2, tr (pwd)); | 834 | i->setText (2, tr (pwd)); |
835 | QString comment = dialog->CommentField->text(); | 835 | QString comment = dialog->CommentField->text(); |
836 | comment.replace (QRegExp("\n"), "<br>"); | 836 | comment.replace (QRegExp("\n"), "<br>"); |
837 | i->setText (3, tr (comment)); | 837 | i->setText (3, tr (comment)); |
838 | QString f5 = dialog->Field5->text(); | 838 | QString f5 = dialog->Field5->text(); |
839 | i->setText (4, tr (f5)); | 839 | i->setText (4, tr (f5)); |
840 | QString f6 = dialog->Field6->text(); | 840 | QString f6 = dialog->Field6->text(); |
841 | i->setText (5, tr (f6)); | 841 | i->setText (5, tr (f6)); |
842 | } | 842 | } |
843 | 843 | ||
844 | delete dialog; | 844 | delete dialog; |
845 | } | 845 | } |
846 | } | 846 | } |
847 | 847 | ||
848 | void ZSafe::findPwd() | 848 | void ZSafe::findPwd() |
849 | { | 849 | { |
850 | 850 | ||
851 | // open the 'Search' dialog | 851 | // open the 'Search' dialog |
852 | SearchDialog *dialog = new SearchDialog(this, tr("Search"), TRUE); | 852 | SearchDialog *dialog = new SearchDialog(this, tr("Search"), TRUE); |
853 | #ifdef WIN32 | 853 | #ifdef WIN32 |
854 | dialog->setCaption ("Qt " + tr("Search")); | 854 | dialog->setCaption ("Qt " + tr("Search")); |
855 | #endif | 855 | #endif |
856 | 856 | ||
857 | #ifdef DESKTOP | 857 | #ifdef DESKTOP |
858 | #endif | 858 | #endif |
859 | if (lastSearchedName) | 859 | if (lastSearchedName) |
860 | dialog->NameField->setText(lastSearchedName); | 860 | dialog->NameField->setText(lastSearchedName); |
861 | else | 861 | else |
862 | dialog->NameField->setText(""); | 862 | dialog->NameField->setText(""); |
863 | if (lastSearchedUsername) | 863 | if (lastSearchedUsername) |
864 | dialog->UsernameField->setText(lastSearchedUsername); | 864 | dialog->UsernameField->setText(lastSearchedUsername); |
865 | else | 865 | else |
866 | dialog->UsernameField->setText(""); | 866 | dialog->UsernameField->setText(""); |
867 | if (lastSearchedComment) | 867 | if (lastSearchedComment) |
868 | dialog->CommentField->setText(lastSearchedComment); | 868 | dialog->CommentField->setText(lastSearchedComment); |
869 | else | 869 | else |
870 | dialog->CommentField->setText(""); | 870 | dialog->CommentField->setText(""); |
871 | DialogCode result = (DialogCode) dialog->exec(); | 871 | DialogCode result = (DialogCode) dialog->exec(); |
872 | #ifdef DESKTOP | 872 | #ifdef DESKTOP |
873 | result = Accepted; | 873 | result = Accepted; |
874 | #endif | 874 | #endif |
875 | 875 | ||
876 | QString name; | 876 | QString name; |
877 | QString username; | 877 | QString username; |
878 | QString comment; | 878 | QString comment; |
879 | if (result == Accepted) | 879 | if (result == Accepted) |
880 | { | 880 | { |
881 | name = dialog->NameField->text(); | 881 | name = dialog->NameField->text(); |
882 | username = dialog->UsernameField->text(); | 882 | username = dialog->UsernameField->text(); |
883 | comment = dialog->CommentField->text(); | 883 | comment = dialog->CommentField->text(); |
884 | qWarning (name); | 884 | owarn << name << oendl; |
885 | } | 885 | } |
886 | else | 886 | else |
887 | { | 887 | { |
888 | delete dialog; | 888 | delete dialog; |
889 | return; | 889 | return; |
890 | } | 890 | } |
891 | 891 | ||
892 | if (!name.isEmpty() && name != lastSearchedName || | 892 | if (!name.isEmpty() && name != lastSearchedName || |
893 | lastSearchedName.isEmpty() && !name.isEmpty()) | 893 | lastSearchedName.isEmpty() && !name.isEmpty()) |
894 | { | 894 | { |
895 | // set search at the beginning if a new name is given | 895 | // set search at the beginning if a new name is given |
896 | lastSearchedCategory = NULL; | 896 | lastSearchedCategory = NULL; |
897 | lastSearchedItem = NULL; | 897 | lastSearchedItem = NULL; |
898 | } | 898 | } |
899 | lastSearchedName = name; | 899 | lastSearchedName = name; |
900 | if (!username.isEmpty() && username != lastSearchedUsername || | 900 | if (!username.isEmpty() && username != lastSearchedUsername || |
901 | lastSearchedUsername.isEmpty() && !username.isEmpty()) | 901 | lastSearchedUsername.isEmpty() && !username.isEmpty()) |
902 | { | 902 | { |
903 | // set search at the beginning if a new name is given | 903 | // set search at the beginning if a new name is given |
904 | lastSearchedCategory = NULL; | 904 | lastSearchedCategory = NULL; |
905 | lastSearchedItem = NULL; | 905 | lastSearchedItem = NULL; |
906 | } | 906 | } |
907 | lastSearchedUsername = username; | 907 | lastSearchedUsername = username; |
908 | if (!comment.isEmpty() && comment != lastSearchedComment || | 908 | if (!comment.isEmpty() && comment != lastSearchedComment || |
909 | lastSearchedComment.isEmpty() && !comment.isEmpty()) | 909 | lastSearchedComment.isEmpty() && !comment.isEmpty()) |
910 | { | 910 | { |
911 | // set search at the beginning if a new name is given | 911 | // set search at the beginning if a new name is given |
912 | lastSearchedCategory = NULL; | 912 | lastSearchedCategory = NULL; |
913 | lastSearchedItem = NULL; | 913 | lastSearchedItem = NULL; |
914 | } | 914 | } |
915 | lastSearchedComment = comment; | 915 | lastSearchedComment = comment; |
916 | 916 | ||
917 | ListView->clearSelection(); | 917 | ListView->clearSelection(); |
918 | 918 | ||
919 | bool found=FALSE; | 919 | bool found=FALSE; |
920 | // step through all categories | 920 | // step through all categories |
921 | QListViewItem *i; | 921 | QListViewItem *i; |
922 | if (lastSearchedCategory) | 922 | if (lastSearchedCategory) |
923 | i = lastSearchedCategory; | 923 | i = lastSearchedCategory; |
924 | else | 924 | else |
925 | i = ListView->firstChild(); | 925 | i = ListView->firstChild(); |
926 | for (; | 926 | for (; |
927 | i != NULL; | 927 | i != NULL; |
928 | i = i->nextSibling()) | 928 | i = i->nextSibling()) |
929 | { | 929 | { |
930 | qWarning (i->text(0)); | 930 | owarn << i->text(0) << oendl; |
931 | i->setSelected(FALSE); | 931 | i->setSelected(FALSE); |
932 | 932 | ||
933 | // step through all subitems | 933 | // step through all subitems |
934 | QListViewItem *si; | 934 | QListViewItem *si; |
935 | if (lastSearchedItem) | 935 | if (lastSearchedItem) |
936 | si = lastSearchedItem; | 936 | si = lastSearchedItem; |
937 | else | 937 | else |
938 | si = i->firstChild(); | 938 | si = i->firstChild(); |
939 | // for (si = i->firstChild(); | 939 | // for (si = i->firstChild(); |
940 | for (; | 940 | for (; |
941 | si != NULL; | 941 | si != NULL; |
942 | si = si->nextSibling()) | 942 | si = si->nextSibling()) |
943 | { | 943 | { |
944 | qWarning (si->text(0)); | 944 | owarn << si->text(0) << oendl; |
945 | if (si->isSelected()) | 945 | if (si->isSelected()) |
946 | si->setSelected(FALSE); | 946 | si->setSelected(FALSE); |
947 | // ListView->repaintItem(si); | 947 | // ListView->repaintItem(si); |
948 | 948 | ||
949 | bool n=TRUE; | 949 | bool n=TRUE; |
950 | bool u=TRUE; | 950 | bool u=TRUE; |
951 | bool c=TRUE; | 951 | bool c=TRUE; |
952 | if (!name.isEmpty()) | 952 | if (!name.isEmpty()) |
953 | n = (si->text(0)).contains (name, FALSE); | 953 | n = (si->text(0)).contains (name, FALSE); |
954 | if (!username.isEmpty()) | 954 | if (!username.isEmpty()) |
955 | u = (si->text(1)).contains (username, FALSE); | 955 | u = (si->text(1)).contains (username, FALSE); |
956 | if (!comment.isEmpty()) | 956 | if (!comment.isEmpty()) |
957 | c = (si->text(3)).contains (comment, FALSE); | 957 | c = (si->text(3)).contains (comment, FALSE); |
958 | 958 | ||
959 | if ((n && u && c ) && !found) | 959 | if ((n && u && c ) && !found) |
960 | { | 960 | { |
961 | qWarning ("Found"); | 961 | owarn << "Found" << oendl; |
962 | selectedItem = si; | 962 | selectedItem = si; |
963 | si->setSelected(TRUE); | 963 | si->setSelected(TRUE); |
964 | ListView->setCurrentItem(si); | 964 | ListView->setCurrentItem(si); |
965 | ListView->ensureItemVisible(si); | 965 | ListView->ensureItemVisible(si); |
966 | ListView->triggerUpdate(); | 966 | ListView->triggerUpdate(); |
967 | 967 | ||
968 | lastSearchedCategory = i; | 968 | lastSearchedCategory = i; |
969 | // set to the next item | 969 | // set to the next item |
970 | lastSearchedItem = si->nextSibling(); | 970 | lastSearchedItem = si->nextSibling(); |
971 | if (!lastSearchedItem) | 971 | if (!lastSearchedItem) |
972 | { | 972 | { |
973 | // no next item within category -> set next category | 973 | // no next item within category -> set next category |
974 | lastSearchedCategory = i->nextSibling(); | 974 | lastSearchedCategory = i->nextSibling(); |
975 | if (!lastSearchedCategory) | 975 | if (!lastSearchedCategory) |
976 | lastSearchedItem = NULL; // END | 976 | lastSearchedItem = NULL; // END |
977 | } | 977 | } |
978 | 978 | ||
979 | found = TRUE; | 979 | found = TRUE; |
980 | delete dialog; | 980 | delete dialog; |
981 | update(); | 981 | update(); |
982 | return; | 982 | return; |
983 | } | 983 | } |
984 | } | 984 | } |
985 | lastSearchedCategory = i->nextSibling(); | 985 | lastSearchedCategory = i->nextSibling(); |
986 | lastSearchedItem = NULL; | 986 | lastSearchedItem = NULL; |
987 | } | 987 | } |
988 | lastSearchedCategory = NULL; | 988 | lastSearchedCategory = NULL; |
989 | lastSearchedItem = NULL; | 989 | lastSearchedItem = NULL; |
990 | delete dialog; | 990 | delete dialog; |
991 | update(); | 991 | update(); |
992 | QMessageBox::information( this, tr("ZSafe"), | 992 | QMessageBox::information( this, tr("ZSafe"), |
993 | tr("Entry not found"), tr("&OK"), 0); | 993 | tr("Entry not found"), tr("&OK"), 0); |
994 | 994 | ||
995 | } | 995 | } |
996 | 996 | ||
997 | QString ZSafe::getFieldLabel (QListViewItem *_item, QString field, QString def) | 997 | QString ZSafe::getFieldLabel (QListViewItem *_item, QString field, QString def) |
998 | { | 998 | { |
999 | QString category; | 999 | QString category; |
1000 | if (_item) | 1000 | if (_item) |
1001 | { | 1001 | { |
1002 | if (isCategory(_item)) | 1002 | if (isCategory(_item)) |
1003 | { | 1003 | { |
1004 | category = _item->text(0); | 1004 | category = _item->text(0); |
1005 | } | 1005 | } |
1006 | else | 1006 | else |
1007 | { | 1007 | { |
1008 | QListViewItem *cat = _item->parent(); | 1008 | QListViewItem *cat = _item->parent(); |
1009 | category = cat->text(0); | 1009 | category = cat->text(0); |
1010 | } | 1010 | } |
1011 | } | 1011 | } |
1012 | else | 1012 | else |
1013 | { | 1013 | { |
1014 | return def; | 1014 | return def; |
1015 | } | 1015 | } |
1016 | 1016 | ||
1017 | QString app_key = APP_KEY; | 1017 | QString app_key = APP_KEY; |
1018 | #ifndef DESKTOP | 1018 | #ifndef DESKTOP |
1019 | #ifndef WIN32 | 1019 | #ifndef WIN32 |
1020 | conf->setGroup ("fieldDefs"); | 1020 | conf->setGroup ("fieldDefs"); |
1021 | #endif | 1021 | #endif |
1022 | #else | 1022 | #else |
1023 | #ifndef WIN32 | 1023 | #ifndef WIN32 |
1024 | app_key += "/fieldDefs/"; | 1024 | app_key += "/fieldDefs/"; |
1025 | #endif | 1025 | #endif |
@@ -1167,304 +1167,301 @@ void ZSafe::listViewSelected( QListViewItem *_item) | |||
1167 | ListView->setColumnText(2, getFieldLabel (selectedItem, "3", tr("Field 3"))); | 1167 | ListView->setColumnText(2, getFieldLabel (selectedItem, "3", tr("Field 3"))); |
1168 | ListView->setColumnText(3, getFieldLabel (selectedItem, "4", tr("Comment"))); | 1168 | ListView->setColumnText(3, getFieldLabel (selectedItem, "4", tr("Comment"))); |
1169 | ListView->setColumnText(4, getFieldLabel (selectedItem, "5", tr("Field 4"))); | 1169 | ListView->setColumnText(4, getFieldLabel (selectedItem, "5", tr("Field 4"))); |
1170 | ListView->setColumnText(5, getFieldLabel (selectedItem, "6", tr("Field 5"))); | 1170 | ListView->setColumnText(5, getFieldLabel (selectedItem, "6", tr("Field 5"))); |
1171 | #endif | 1171 | #endif |
1172 | #ifdef WIN32 | 1172 | #ifdef WIN32 |
1173 | // set the column text dependent on the selected item | 1173 | // set the column text dependent on the selected item |
1174 | ListView->setColumnText(0, getFieldLabel (selectedItem, "1", tr("Name"))); | 1174 | ListView->setColumnText(0, getFieldLabel (selectedItem, "1", tr("Name"))); |
1175 | ListView->setColumnText(1, getFieldLabel (selectedItem, "2", tr("Field 2"))); | 1175 | ListView->setColumnText(1, getFieldLabel (selectedItem, "2", tr("Field 2"))); |
1176 | ListView->setColumnText(2, getFieldLabel (selectedItem, "3", tr("Field 3"))); | 1176 | ListView->setColumnText(2, getFieldLabel (selectedItem, "3", tr("Field 3"))); |
1177 | ListView->setColumnText(3, getFieldLabel (selectedItem, "4", tr("Comment"))); | 1177 | ListView->setColumnText(3, getFieldLabel (selectedItem, "4", tr("Comment"))); |
1178 | ListView->setColumnText(4, getFieldLabel (selectedItem, "5", tr("Field 4"))); | 1178 | ListView->setColumnText(4, getFieldLabel (selectedItem, "5", tr("Field 4"))); |
1179 | ListView->setColumnText(5, getFieldLabel (selectedItem, "6", tr("Field 5"))); | 1179 | ListView->setColumnText(5, getFieldLabel (selectedItem, "6", tr("Field 5"))); |
1180 | #endif | 1180 | #endif |
1181 | 1181 | ||
1182 | } | 1182 | } |
1183 | 1183 | ||
1184 | bool ZSafe::isCategory(QListViewItem *_item) | 1184 | bool ZSafe::isCategory(QListViewItem *_item) |
1185 | { | 1185 | { |
1186 | if (_item == NULL) | 1186 | if (_item == NULL) |
1187 | return FALSE; | 1187 | return FALSE; |
1188 | 1188 | ||
1189 | QString categoryName = _item->text (0); | 1189 | QString categoryName = _item->text (0); |
1190 | if (categories.find (categoryName)) | 1190 | if (categories.find (categoryName)) |
1191 | return TRUE; | 1191 | return TRUE; |
1192 | else | 1192 | else |
1193 | return FALSE; | 1193 | return FALSE; |
1194 | } | 1194 | } |
1195 | 1195 | ||
1196 | void ZSafe::removeAsciiFile() | 1196 | void ZSafe::removeAsciiFile() |
1197 | { | 1197 | { |
1198 | // QString fn = filename + ".txt"; | 1198 | // QString fn = filename + ".txt"; |
1199 | // open the file dialog | 1199 | // open the file dialog |
1200 | #ifndef DESKTOP | 1200 | #ifndef DESKTOP |
1201 | #ifndef NO_OPIE | 1201 | #ifndef NO_OPIE |
1202 | QMap<QString, QStringList> mimeTypes; | 1202 | QMap<QString, QStringList> mimeTypes; |
1203 | mimeTypes.insert(tr("All"), QStringList() ); | 1203 | mimeTypes.insert(tr("All"), QStringList() ); |
1204 | mimeTypes.insert(tr("Text"), "text/*" ); | 1204 | mimeTypes.insert(tr("Text"), "text/*" ); |
1205 | QString fn = OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL, | 1205 | QString fn = OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL, |
1206 | QDir::homeDirPath() + "/Documents/application/zsafe", | 1206 | QDir::homeDirPath() + "/Documents/application/zsafe", |
1207 | QString::null, | 1207 | QString::null, |
1208 | mimeTypes, | 1208 | mimeTypes, |
1209 | this, | 1209 | this, |
1210 | tr ("Remove text file")); | 1210 | tr ("Remove text file")); |
1211 | #else | 1211 | #else |
1212 | QString fn = ScQtFileEdit::getOpenFileName(this, | 1212 | QString fn = ScQtFileEdit::getOpenFileName(this, |
1213 | tr ("Remove text file"), | 1213 | tr ("Remove text file"), |
1214 | QDir::homeDirPath() + "/Documents/application/zsafe", | 1214 | QDir::homeDirPath() + "/Documents/application/zsafe", |
1215 | "*.txt"); | 1215 | "*.txt"); |
1216 | #endif | 1216 | #endif |
1217 | #else | 1217 | #else |
1218 | QString fn = QFileDialog::getOpenFileName( | 1218 | QString fn = QFileDialog::getOpenFileName( |
1219 | QDir::homeDirPath() + "/Documents/application/zsafe", | 1219 | QDir::homeDirPath() + "/Documents/application/zsafe", |
1220 | "ZSafe (*.txt)", | 1220 | "ZSafe (*.txt)", |
1221 | this, | 1221 | this, |
1222 | "ZSafe File Dialog" | 1222 | "ZSafe File Dialog" |
1223 | "Choose a text file" ); | 1223 | "Choose a text file" ); |
1224 | #endif | 1224 | #endif |
1225 | 1225 | ||
1226 | if (fn && fn.length() > 0 ) | 1226 | if (fn && fn.length() > 0 ) |
1227 | { | 1227 | { |
1228 | QFile f( fn ); | 1228 | QFile f( fn ); |
1229 | if ( !f.remove() ) | 1229 | if ( !f.remove() ) |
1230 | { | 1230 | { |
1231 | qWarning( QString("Could not remove file %1").arg(fn), | 1231 | owarn << "Could not remove file " << fn << oendl; |
1232 | 2000 ); | ||
1233 | QMessageBox::critical( 0, tr("ZSafe"), | 1232 | QMessageBox::critical( 0, tr("ZSafe"), |
1234 | tr("Could not remove text file.") ); | 1233 | tr("Could not remove text file.") ); |
1235 | return; | 1234 | return; |
1236 | } | 1235 | } |
1237 | } | 1236 | } |
1238 | } | 1237 | } |
1239 | 1238 | ||
1240 | void ZSafe::writeAllEntries() | 1239 | void ZSafe::writeAllEntries() |
1241 | { | 1240 | { |
1242 | if (filename.isEmpty()) | 1241 | if (filename.isEmpty()) |
1243 | { | 1242 | { |
1244 | QMessageBox::critical( 0, tr("ZSafe"), | 1243 | QMessageBox::critical( 0, tr("ZSafe"), |
1245 | tr("No document defined.\nYou have to create a new document")); | 1244 | tr("No document defined.\nYou have to create a new document")); |
1246 | return; | 1245 | return; |
1247 | } | 1246 | } |
1248 | 1247 | ||
1249 | // open the file dialog | 1248 | // open the file dialog |
1250 | #ifndef DESKTOP | 1249 | #ifndef DESKTOP |
1251 | #ifndef NO_OPIE | 1250 | #ifndef NO_OPIE |
1252 | QMap<QString, QStringList> mimeTypes; | 1251 | QMap<QString, QStringList> mimeTypes; |
1253 | mimeTypes.insert(tr("All"), QStringList() ); | 1252 | mimeTypes.insert(tr("All"), QStringList() ); |
1254 | mimeTypes.insert(tr("Text"), "text/*" ); | 1253 | mimeTypes.insert(tr("Text"), "text/*" ); |
1255 | QString fn = OFileDialog::getSaveFileName( OFileSelector::EXTENDED_ALL, | 1254 | QString fn = OFileDialog::getSaveFileName( OFileSelector::EXTENDED_ALL, |
1256 | QDir::homeDirPath() + "/Documents/application/zsafe", | 1255 | QDir::homeDirPath() + "/Documents/application/zsafe", |
1257 | QString::null, | 1256 | QString::null, |
1258 | mimeTypes, | 1257 | mimeTypes, |
1259 | this, | 1258 | this, |
1260 | tr ("Export text file")); | 1259 | tr ("Export text file")); |
1261 | #else | 1260 | #else |
1262 | QString fn = ScQtFileEdit::getSaveAsFileName(this, | 1261 | QString fn = ScQtFileEdit::getSaveAsFileName(this, |
1263 | tr ("Export text file"), | 1262 | tr ("Export text file"), |
1264 | QDir::homeDirPath() + "/Documents/application/zsafe", | 1263 | QDir::homeDirPath() + "/Documents/application/zsafe", |
1265 | "*.txt"); | 1264 | "*.txt"); |
1266 | #endif | 1265 | #endif |
1267 | #else | 1266 | #else |
1268 | QString fn = QFileDialog::getSaveFileName( | 1267 | QString fn = QFileDialog::getSaveFileName( |
1269 | QDir::homeDirPath() + "/Documents/application/zsafe", | 1268 | QDir::homeDirPath() + "/Documents/application/zsafe", |
1270 | "ZSafe (*.txt)", | 1269 | "ZSafe (*.txt)", |
1271 | this, | 1270 | this, |
1272 | "ZSafe File Dialog" | 1271 | "ZSafe File Dialog" |
1273 | "Choose a text file" ); | 1272 | "Choose a text file" ); |
1274 | #endif | 1273 | #endif |
1275 | 1274 | ||
1276 | // open the new document | 1275 | // open the new document |
1277 | if (fn && fn.length() > 0 ) | 1276 | if (fn && fn.length() > 0 ) |
1278 | { | 1277 | { |
1279 | QFile f( fn ); | 1278 | QFile f( fn ); |
1280 | if ( !f.open( IO_WriteOnly ) ) { | 1279 | if ( !f.open( IO_WriteOnly ) ) { |
1281 | qWarning( QString("Could not write to file %1").arg(fn), | 1280 | owarn << "Could not write to file " << fn << oendl; |
1282 | 2000 ); | ||
1283 | QMessageBox::critical( 0, "ZSafe", | 1281 | QMessageBox::critical( 0, "ZSafe", |
1284 | QString("Could not export to text file.") ); | 1282 | QString("Could not export to text file.") ); |
1285 | return; | 1283 | return; |
1286 | } | 1284 | } |
1287 | QTextStream t( &f ); | 1285 | QTextStream t( &f ); |
1288 | 1286 | ||
1289 | QListViewItem *i; | 1287 | QListViewItem *i; |
1290 | // step through all categories | 1288 | // step through all categories |
1291 | for (i = ListView->firstChild(); | 1289 | for (i = ListView->firstChild(); |
1292 | i != NULL; | 1290 | i != NULL; |
1293 | i = i->nextSibling()) | 1291 | i = i->nextSibling()) |
1294 | { | 1292 | { |
1295 | // step through all subitems | 1293 | // step through all subitems |
1296 | QListViewItem *si; | 1294 | QListViewItem *si; |
1297 | for (si = i->firstChild(); | 1295 | for (si = i->firstChild(); |
1298 | si != NULL; | 1296 | si != NULL; |
1299 | si = si->nextSibling()) | 1297 | si = si->nextSibling()) |
1300 | { | 1298 | { |
1301 | QString oneEntry; | 1299 | QString oneEntry; |
1302 | oneEntry += "\""; | 1300 | oneEntry += "\""; |
1303 | oneEntry += i->text(0); | 1301 | oneEntry += i->text(0); |
1304 | oneEntry += "\";"; | 1302 | oneEntry += "\";"; |
1305 | oneEntry += "\""; | 1303 | oneEntry += "\""; |
1306 | oneEntry += si->text(0); | 1304 | oneEntry += si->text(0); |
1307 | oneEntry += "\";"; | 1305 | oneEntry += "\";"; |
1308 | oneEntry += "\""; | 1306 | oneEntry += "\""; |
1309 | oneEntry += si->text(1); | 1307 | oneEntry += si->text(1); |
1310 | oneEntry += "\";"; | 1308 | oneEntry += "\";"; |
1311 | oneEntry += "\""; | 1309 | oneEntry += "\""; |
1312 | oneEntry += si->text(2); | 1310 | oneEntry += si->text(2); |
1313 | oneEntry += "\";"; | 1311 | oneEntry += "\";"; |
1314 | oneEntry += "\""; | 1312 | oneEntry += "\""; |
1315 | QString comment = si->text(3); | 1313 | QString comment = si->text(3); |
1316 | comment.replace (QRegExp("\n"), "<br>"); | 1314 | comment.replace (QRegExp("\n"), "<br>"); |
1317 | oneEntry += comment; | 1315 | oneEntry += comment; |
1318 | oneEntry += "\";"; | 1316 | oneEntry += "\";"; |
1319 | oneEntry += "\""; | 1317 | oneEntry += "\""; |
1320 | oneEntry += si->text(4); | 1318 | oneEntry += si->text(4); |
1321 | oneEntry += "\";"; | 1319 | oneEntry += "\";"; |
1322 | oneEntry += "\""; | 1320 | oneEntry += "\""; |
1323 | oneEntry += si->text(5); | 1321 | oneEntry += si->text(5); |
1324 | oneEntry += "\""; | 1322 | oneEntry += "\""; |
1325 | // qWarning (oneEntry); | 1323 | // owarn << oneEntry << oendl; |
1326 | t << oneEntry << endl; | 1324 | t << oneEntry << endl; |
1327 | 1325 | ||
1328 | // qWarning (si->text(0)); | 1326 | // owarn << si->text(0) << oendl; |
1329 | } | 1327 | } |
1330 | } | 1328 | } |
1331 | f.close(); | 1329 | f.close(); |
1332 | } | 1330 | } |
1333 | } | 1331 | } |
1334 | 1332 | ||
1335 | void ZSafe::readAllEntries() | 1333 | void ZSafe::readAllEntries() |
1336 | { | 1334 | { |
1337 | if (filename.isEmpty()) | 1335 | if (filename.isEmpty()) |
1338 | { | 1336 | { |
1339 | QMessageBox::critical( 0, tr("ZSafe"), | 1337 | QMessageBox::critical( 0, tr("ZSafe"), |
1340 | tr("No document defined.\nYou have to create a new document")); | 1338 | tr("No document defined.\nYou have to create a new document")); |
1341 | return; | 1339 | return; |
1342 | } | 1340 | } |
1343 | 1341 | ||
1344 | // open the file dialog | 1342 | // open the file dialog |
1345 | #ifndef DESKTOP | 1343 | #ifndef DESKTOP |
1346 | #ifndef NO_OPIE | 1344 | #ifndef NO_OPIE |
1347 | QMap<QString, QStringList> mimeTypes; | 1345 | QMap<QString, QStringList> mimeTypes; |
1348 | mimeTypes.insert(tr("All"), QStringList() ); | 1346 | mimeTypes.insert(tr("All"), QStringList() ); |
1349 | mimeTypes.insert(tr("Text"), "text/*" ); | 1347 | mimeTypes.insert(tr("Text"), "text/*" ); |
1350 | QString fn = OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL, | 1348 | QString fn = OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL, |
1351 | QDir::homeDirPath() + "/Documents/application/zsafe", | 1349 | QDir::homeDirPath() + "/Documents/application/zsafe", |
1352 | QString::null, | 1350 | QString::null, |
1353 | mimeTypes, | 1351 | mimeTypes, |
1354 | this, | 1352 | this, |
1355 | tr ("Import text file")); | 1353 | tr ("Import text file")); |
1356 | #else | 1354 | #else |
1357 | QString fn = ScQtFileEdit::getOpenFileName(this, | 1355 | QString fn = ScQtFileEdit::getOpenFileName(this, |
1358 | tr ("Import text file"), | 1356 | tr ("Import text file"), |
1359 | QDir::homeDirPath() + "/Documents/application/zsafe", | 1357 | QDir::homeDirPath() + "/Documents/application/zsafe", |
1360 | "*.txt"); | 1358 | "*.txt"); |
1361 | #endif | 1359 | #endif |
1362 | #else | 1360 | #else |
1363 | QString fn = QFileDialog::getOpenFileName( | 1361 | QString fn = QFileDialog::getOpenFileName( |
1364 | QDir::homeDirPath() + "/Documents/application/zsafe", | 1362 | QDir::homeDirPath() + "/Documents/application/zsafe", |
1365 | "ZSafe (*.txt)", | 1363 | "ZSafe (*.txt)", |
1366 | this, | 1364 | this, |
1367 | "ZSafe File Dialog" | 1365 | "ZSafe File Dialog" |
1368 | "Choose a text file" ); | 1366 | "Choose a text file" ); |
1369 | #endif | 1367 | #endif |
1370 | 1368 | ||
1371 | if (fn && fn.length() > 0 ) | 1369 | if (fn && fn.length() > 0 ) |
1372 | { | 1370 | { |
1373 | QFile f( fn ); | 1371 | QFile f( fn ); |
1374 | if ( !f.open( IO_ReadOnly ) ) | 1372 | if ( !f.open( IO_ReadOnly ) ) |
1375 | { | 1373 | { |
1376 | qWarning( QString("Could not read file %1").arg(fn), | 1374 | owarn << "Could not read file " << fn << oendl; |
1377 | 2000 ); | ||
1378 | QMessageBox::critical( 0, "ZSafe", | 1375 | QMessageBox::critical( 0, "ZSafe", |
1379 | QString("Could not import text file.") ); | 1376 | QString("Could not import text file.") ); |
1380 | return; | 1377 | return; |
1381 | } | 1378 | } |
1382 | 1379 | ||
1383 | modified = true; | 1380 | modified = true; |
1384 | 1381 | ||
1385 | // clear the password list | 1382 | // clear the password list |
1386 | selectedItem = NULL; | 1383 | selectedItem = NULL; |
1387 | QListViewItem *i; | 1384 | QListViewItem *i; |
1388 | // step through all categories | 1385 | // step through all categories |
1389 | for (i = ListView->firstChild(); | 1386 | for (i = ListView->firstChild(); |
1390 | i != NULL; | 1387 | i != NULL; |
1391 | i = i->nextSibling()) | 1388 | i = i->nextSibling()) |
1392 | { | 1389 | { |
1393 | // step through all subitems | 1390 | // step through all subitems |
1394 | QListViewItem *si; | 1391 | QListViewItem *si; |
1395 | for (si = i->firstChild(); | 1392 | for (si = i->firstChild(); |
1396 | si != NULL; ) | 1393 | si != NULL; ) |
1397 | // si = si->nextSibling()) | 1394 | // si = si->nextSibling()) |
1398 | { | 1395 | { |
1399 | QListViewItem *_si = si; | 1396 | QListViewItem *_si = si; |
1400 | si = si->nextSibling(); | 1397 | si = si->nextSibling(); |
1401 | i->takeItem(_si); // remove from view list | 1398 | i->takeItem(_si); // remove from view list |
1402 | if (_si) delete _si; | 1399 | if (_si) delete _si; |
1403 | } | 1400 | } |
1404 | } | 1401 | } |
1405 | 1402 | ||
1406 | qWarning ("ReadAllEntries(): "); | 1403 | owarn << "ReadAllEntries(): " << oendl; |
1407 | 1404 | ||
1408 | QTextStream t(&f); | 1405 | QTextStream t(&f); |
1409 | while ( !t.eof() ) | 1406 | while ( !t.eof() ) |
1410 | { | 1407 | { |
1411 | QString s = t.readLine(); | 1408 | QString s = t.readLine(); |
1412 | s.replace (QRegExp("\";\""), "\"|\""); | 1409 | s.replace (QRegExp("\";\""), "\"|\""); |
1413 | // char buffer[1024]; | 1410 | // char buffer[1024]; |
1414 | #ifndef WIN32 | 1411 | #ifndef WIN32 |
1415 | char buffer[s.length()+1]; | 1412 | char buffer[s.length()+1]; |
1416 | #else | 1413 | #else |
1417 | char buffer[4048]; | 1414 | char buffer[4048]; |
1418 | #endif | 1415 | #endif |
1419 | 1416 | ||
1420 | 1417 | ||
1421 | /* modify QString -> QCString::utf8 */ | 1418 | /* modify QString -> QCString::utf8 */ |
1422 | 1419 | ||
1423 | strcpy (buffer, s.utf8()); | 1420 | strcpy (buffer, s.utf8()); |
1424 | 1421 | ||
1425 | QString name; | 1422 | QString name; |
1426 | QString user; | 1423 | QString user; |
1427 | QString password; | 1424 | QString password; |
1428 | QString comment; | 1425 | QString comment; |
1429 | QString field5=""; | 1426 | QString field5=""; |
1430 | QString field6=""; | 1427 | QString field6=""; |
1431 | 1428 | ||
1432 | // separete the entries | 1429 | // separete the entries |
1433 | char *i = strtok (buffer, "|"); | 1430 | char *i = strtok (buffer, "|"); |
1434 | QString category(QString::fromUtf8(&i[1])); | 1431 | QString category(QString::fromUtf8(&i[1])); |
1435 | category.truncate(category.length() -1); | 1432 | category.truncate(category.length() -1); |
1436 | 1433 | ||
1437 | int idx=0; | 1434 | int idx=0; |
1438 | while ((i = strtok (NULL, "|")) != NULL) | 1435 | while ((i = strtok (NULL, "|")) != NULL) |
1439 | { | 1436 | { |
1440 | switch (idx) | 1437 | switch (idx) |
1441 | { | 1438 | { |
1442 | case 0: | 1439 | case 0: |
1443 | name = QString::fromUtf8(&i[1]); | 1440 | name = QString::fromUtf8(&i[1]); |
1444 | name.truncate(name.length() -1); | 1441 | name.truncate(name.length() -1); |
1445 | // name | 1442 | // name |
1446 | break; | 1443 | break; |
1447 | case 1: | 1444 | case 1: |
1448 | // user | 1445 | // user |
1449 | user = QString::fromUtf8(&i[1]); | 1446 | user = QString::fromUtf8(&i[1]); |
1450 | user.truncate(user.length() -1); | 1447 | user.truncate(user.length() -1); |
1451 | break; | 1448 | break; |
1452 | case 2: | 1449 | case 2: |
1453 | // password | 1450 | // password |
1454 | password = QString::fromUtf8(&i[1]); | 1451 | password = QString::fromUtf8(&i[1]); |
1455 | password.truncate(password.length() -1); | 1452 | password.truncate(password.length() -1); |
1456 | break; | 1453 | break; |
1457 | case 3: | 1454 | case 3: |
1458 | // comment | 1455 | // comment |
1459 | comment = QString::fromUtf8(&i[1]); | 1456 | comment = QString::fromUtf8(&i[1]); |
1460 | comment.truncate(comment.length() -1); | 1457 | comment.truncate(comment.length() -1); |
1461 | break; | 1458 | break; |
1462 | case 4: | 1459 | case 4: |
1463 | // field5 | 1460 | // field5 |
1464 | field5 = QString::fromUtf8(&i[1]); | 1461 | field5 = QString::fromUtf8(&i[1]); |
1465 | field5.truncate(field5.length() -1); | 1462 | field5.truncate(field5.length() -1); |
1466 | break; | 1463 | break; |
1467 | case 5: | 1464 | case 5: |
1468 | // field6 | 1465 | // field6 |
1469 | field6 = QString::fromUtf8(&i[1]); | 1466 | field6 = QString::fromUtf8(&i[1]); |
1470 | field6.truncate(field6.length() -1); | 1467 | field6.truncate(field6.length() -1); |
@@ -1493,402 +1490,400 @@ void ZSafe::readAllEntries() | |||
1493 | else | 1490 | else |
1494 | { | 1491 | { |
1495 | QListViewItem *catI = new ShadedListItem( 1, ListView ); | 1492 | QListViewItem *catI = new ShadedListItem( 1, ListView ); |
1496 | // create and insert a new item | 1493 | // create and insert a new item |
1497 | QListViewItem * item = new ShadedListItem( 0, catI ); | 1494 | QListViewItem * item = new ShadedListItem( 0, catI ); |
1498 | item->setText( 0, tr( name ) ); | 1495 | item->setText( 0, tr( name ) ); |
1499 | item->setText( 1, tr( user ) ); | 1496 | item->setText( 1, tr( user ) ); |
1500 | item->setText( 2, tr( password ) ); | 1497 | item->setText( 2, tr( password ) ); |
1501 | item->setText( 3, tr( comment ) ); | 1498 | item->setText( 3, tr( comment ) ); |
1502 | item->setText( 4, tr( field5 ) ); | 1499 | item->setText( 4, tr( field5 ) ); |
1503 | item->setText( 5, tr( field6 ) ); | 1500 | item->setText( 5, tr( field6 ) ); |
1504 | 1501 | ||
1505 | catI->setOpen( TRUE ); | 1502 | catI->setOpen( TRUE ); |
1506 | 1503 | ||
1507 | Category *c1 = new Category(); | 1504 | Category *c1 = new Category(); |
1508 | c1->setCategoryName(category); | 1505 | c1->setCategoryName(category); |
1509 | 1506 | ||
1510 | QString icon; | 1507 | QString icon; |
1511 | QString fullIconPath; | 1508 | QString fullIconPath; |
1512 | QPixmap *pix; | 1509 | QPixmap *pix; |
1513 | // #ifndef WIN32 | 1510 | // #ifndef WIN32 |
1514 | icon = conf->readEntry(APP_KEY+category); | 1511 | icon = conf->readEntry(APP_KEY+category); |
1515 | // #endif | 1512 | // #endif |
1516 | bool isIconAv = false; | 1513 | bool isIconAv = false; |
1517 | if (!icon.isEmpty() && !icon.isNull()) | 1514 | if (!icon.isEmpty() && !icon.isNull()) |
1518 | { | 1515 | { |
1519 | // build the full path | 1516 | // build the full path |
1520 | fullIconPath = iconPath + icon; | 1517 | fullIconPath = iconPath + icon; |
1521 | pix = new QPixmap (fullIconPath); | 1518 | pix = new QPixmap (fullIconPath); |
1522 | if (pix) | 1519 | if (pix) |
1523 | { | 1520 | { |
1524 | QImage img = pix->convertToImage(); | 1521 | QImage img = pix->convertToImage(); |
1525 | pix->convertFromImage(img.smoothScale(14,14)); | 1522 | pix->convertFromImage(img.smoothScale(14,14)); |
1526 | c1->setIconName (icon); | 1523 | c1->setIconName (icon); |
1527 | c1->setIcon (*pix); | 1524 | c1->setIcon (*pix); |
1528 | isIconAv = true; | 1525 | isIconAv = true; |
1529 | } | 1526 | } |
1530 | } | 1527 | } |
1531 | if (!isIconAv) | 1528 | if (!isIconAv) |
1532 | { | 1529 | { |
1533 | c1->setIcon (*getPredefinedIcon(category)); | 1530 | c1->setIcon (*getPredefinedIcon(category)); |
1534 | } | 1531 | } |
1535 | c1->setListItem (catI); | 1532 | c1->setListItem (catI); |
1536 | c1->initListItem(); | 1533 | c1->initListItem(); |
1537 | categories.insert (c1->getCategoryName(), c1); | 1534 | categories.insert (c1->getCategoryName(), c1); |
1538 | } | 1535 | } |
1539 | 1536 | ||
1540 | } | 1537 | } |
1541 | f.close(); | 1538 | f.close(); |
1542 | 1539 | ||
1543 | } | 1540 | } |
1544 | else | 1541 | else |
1545 | { | 1542 | { |
1546 | } | 1543 | } |
1547 | 1544 | ||
1548 | } | 1545 | } |
1549 | 1546 | ||
1550 | #ifdef UNUSED | 1547 | #ifdef UNUSED |
1551 | void ZSafe::writeAllEntries() | 1548 | void ZSafe::writeAllEntries() |
1552 | { | 1549 | { |
1553 | // open the file for writing | 1550 | // open the file for writing |
1554 | QString fn = filename + ".txt"; | 1551 | QString fn = filename + ".txt"; |
1555 | QFile f( fn ); | 1552 | QFile f( fn ); |
1556 | if ( !f.open( IO_WriteOnly ) ) { | 1553 | if ( !f.open( IO_WriteOnly ) ) { |
1557 | qWarning( QString("Could not write to file %1").arg(fn), | 1554 | owarn << "Could not write to file " << fn << oendl; |
1558 | 2000 ); | ||
1559 | QMessageBox::critical( 0, tr("ZSafe"), | 1555 | QMessageBox::critical( 0, tr("ZSafe"), |
1560 | tr("Could not export to text file.") ); | 1556 | tr("Could not export to text file.") ); |
1561 | return; | 1557 | return; |
1562 | } | 1558 | } |
1563 | QTextStream t( &f ); | 1559 | QTextStream t( &f ); |
1564 | 1560 | ||
1565 | QListViewItem *i; | 1561 | QListViewItem *i; |
1566 | // step through all categories | 1562 | // step through all categories |
1567 | for (i = ListView->firstChild(); | 1563 | for (i = ListView->firstChild(); |
1568 | i != NULL; | 1564 | i != NULL; |
1569 | i = i->nextSibling()) | 1565 | i = i->nextSibling()) |
1570 | { | 1566 | { |
1571 | // step through all subitems | 1567 | // step through all subitems |
1572 | QListViewItem *si; | 1568 | QListViewItem *si; |
1573 | for (si = i->firstChild(); | 1569 | for (si = i->firstChild(); |
1574 | si != NULL; | 1570 | si != NULL; |
1575 | si = si->nextSibling()) | 1571 | si = si->nextSibling()) |
1576 | { | 1572 | { |
1577 | QString oneEntry; | 1573 | QString oneEntry; |
1578 | oneEntry += "\""; | 1574 | oneEntry += "\""; |
1579 | oneEntry += i->text(0); | 1575 | oneEntry += i->text(0); |
1580 | oneEntry += "\";"; | 1576 | oneEntry += "\";"; |
1581 | oneEntry += "\""; | 1577 | oneEntry += "\""; |
1582 | oneEntry += si->text(0); | 1578 | oneEntry += si->text(0); |
1583 | oneEntry += "\";"; | 1579 | oneEntry += "\";"; |
1584 | oneEntry += "\""; | 1580 | oneEntry += "\""; |
1585 | oneEntry += si->text(1); | 1581 | oneEntry += si->text(1); |
1586 | oneEntry += "\";"; | 1582 | oneEntry += "\";"; |
1587 | oneEntry += "\""; | 1583 | oneEntry += "\""; |
1588 | oneEntry += si->text(2); | 1584 | oneEntry += si->text(2); |
1589 | oneEntry += "\";"; | 1585 | oneEntry += "\";"; |
1590 | oneEntry += "\""; | 1586 | oneEntry += "\""; |
1591 | // oneEntry += si->text(3); | 1587 | // oneEntry += si->text(3); |
1592 | QString comment = si->text(3); | 1588 | QString comment = si->text(3); |
1593 | comment.replace (QRegExp("\n"), "<br>"); | 1589 | comment.replace (QRegExp("\n"), "<br>"); |
1594 | oneEntry += comment; | 1590 | oneEntry += comment; |
1595 | oneEntry += "\""; | 1591 | oneEntry += "\""; |
1596 | // qWarning (oneEntry); | 1592 | // owarn << oneEntry << oendl; |
1597 | t << oneEntry << endl; | 1593 | t << oneEntry << endl; |
1598 | 1594 | ||
1599 | // qWarning (si->text(0)); | 1595 | // owarn << si->text(0) << oendl; |
1600 | } | 1596 | } |
1601 | } | 1597 | } |
1602 | f.close(); | 1598 | f.close(); |
1603 | } | 1599 | } |
1604 | 1600 | ||
1605 | void ZSafe::readAllEntries() | 1601 | void ZSafe::readAllEntries() |
1606 | { | 1602 | { |
1607 | QString fn = filename + ".txt"; | 1603 | QString fn = filename + ".txt"; |
1608 | QFile f( fn ); | 1604 | QFile f( fn ); |
1609 | if ( !f.open( IO_ReadOnly ) ) | 1605 | if ( !f.open( IO_ReadOnly ) ) |
1610 | { | 1606 | { |
1611 | qWarning( QString("Could not read file %1").arg(fn), | 1607 | owarn << "Could not read file " << fn << oendl; |
1612 | 2000 ); | ||
1613 | QMessageBox::critical( 0, tr("ZSafe"), | 1608 | QMessageBox::critical( 0, tr("ZSafe"), |
1614 | tr("Could not import text file.") ); | 1609 | tr("Could not import text file.") ); |
1615 | return; | 1610 | return; |
1616 | } | 1611 | } |
1617 | 1612 | ||
1618 | modified = true; | 1613 | modified = true; |
1619 | 1614 | ||
1620 | // clear the password list | 1615 | // clear the password list |
1621 | selectedItem = NULL; | 1616 | selectedItem = NULL; |
1622 | QListViewItem *i; | 1617 | QListViewItem *i; |
1623 | // step through all categories | 1618 | // step through all categories |
1624 | for (i = ListView->firstChild(); | 1619 | for (i = ListView->firstChild(); |
1625 | i != NULL; | 1620 | i != NULL; |
1626 | i = i->nextSibling()) | 1621 | i = i->nextSibling()) |
1627 | { | 1622 | { |
1628 | // step through all subitems | 1623 | // step through all subitems |
1629 | QListViewItem *si; | 1624 | QListViewItem *si; |
1630 | for (si = i->firstChild(); | 1625 | for (si = i->firstChild(); |
1631 | si != NULL; ) | 1626 | si != NULL; ) |
1632 | // si = si->nextSibling()) | 1627 | // si = si->nextSibling()) |
1633 | { | 1628 | { |
1634 | QListViewItem *_si = si; | 1629 | QListViewItem *_si = si; |
1635 | si = si->nextSibling(); | 1630 | si = si->nextSibling(); |
1636 | i->takeItem(_si); // remove from view list | 1631 | i->takeItem(_si); // remove from view list |
1637 | if (_si) delete _si; | 1632 | if (_si) delete _si; |
1638 | } | 1633 | } |
1639 | } | 1634 | } |
1640 | 1635 | ||
1641 | qWarning ("ReadAllEntries(): "); | 1636 | owarn << "ReadAllEntries(): " << oendl; |
1642 | 1637 | ||
1643 | QTextStream t(&f); | 1638 | QTextStream t(&f); |
1644 | while ( !t.eof() ) | 1639 | while ( !t.eof() ) |
1645 | { | 1640 | { |
1646 | QString s = t.readLine(); | 1641 | QString s = t.readLine(); |
1647 | s.replace (QRegExp("\";\""), "\"|\""); | 1642 | s.replace (QRegExp("\";\""), "\"|\""); |
1648 | // char buffer[1024]; | 1643 | // char buffer[1024]; |
1649 | int len=s.length()+1; | 1644 | int len=s.length()+1; |
1650 | #ifdef WIN32 | 1645 | #ifdef WIN32 |
1651 | char buffer[512]; | 1646 | char buffer[512]; |
1652 | #else | 1647 | #else |
1653 | char buffer[len]; | 1648 | char buffer[len]; |
1654 | #endif | 1649 | #endif |
1655 | strcpy (buffer, s); | 1650 | strcpy (buffer, s); |
1656 | 1651 | ||
1657 | QString name; | 1652 | QString name; |
1658 | QString user; | 1653 | QString user; |
1659 | QString password; | 1654 | QString password; |
1660 | QString comment; | 1655 | QString comment; |
1661 | 1656 | ||
1662 | // separete the entries | 1657 | // separete the entries |
1663 | char *i = strtok (buffer, "|"); | 1658 | char *i = strtok (buffer, "|"); |
1664 | QString category(&i[1]); | 1659 | QString category(&i[1]); |
1665 | category.truncate(category.length() -1); | 1660 | category.truncate(category.length() -1); |
1666 | 1661 | ||
1667 | int idx=0; | 1662 | int idx=0; |
1668 | while (i = strtok (NULL, "|")) | 1663 | while (i = strtok (NULL, "|")) |
1669 | { | 1664 | { |
1670 | switch (idx) | 1665 | switch (idx) |
1671 | { | 1666 | { |
1672 | case 0: | 1667 | case 0: |
1673 | name = &i[1]; | 1668 | name = &i[1]; |
1674 | name.truncate(name.length() -1); | 1669 | name.truncate(name.length() -1); |
1675 | // name | 1670 | // name |
1676 | break; | 1671 | break; |
1677 | case 1: | 1672 | case 1: |
1678 | // user | 1673 | // user |
1679 | user = &i[1]; | 1674 | user = &i[1]; |
1680 | user.truncate(user.length() -1); | 1675 | user.truncate(user.length() -1); |
1681 | break; | 1676 | break; |
1682 | case 2: | 1677 | case 2: |
1683 | // password | 1678 | // password |
1684 | password = &i[1]; | 1679 | password = &i[1]; |
1685 | password.truncate(password.length() -1); | 1680 | password.truncate(password.length() -1); |
1686 | break; | 1681 | break; |
1687 | case 3: | 1682 | case 3: |
1688 | // comment | 1683 | // comment |
1689 | comment = &i[1]; | 1684 | comment = &i[1]; |
1690 | comment.truncate(comment.length() -1); | 1685 | comment.truncate(comment.length() -1); |
1691 | break; | 1686 | break; |
1692 | } | 1687 | } |
1693 | idx++; | 1688 | idx++; |
1694 | } | 1689 | } |
1695 | 1690 | ||
1696 | Category *cat= categories.find (category); | 1691 | Category *cat= categories.find (category); |
1697 | if (cat) | 1692 | if (cat) |
1698 | { | 1693 | { |
1699 | // use the existend item | 1694 | // use the existend item |
1700 | QListViewItem *catItem = cat->getListItem(); | 1695 | QListViewItem *catItem = cat->getListItem(); |
1701 | if (catItem) | 1696 | if (catItem) |
1702 | { | 1697 | { |
1703 | QListViewItem * item = new ShadedListItem( 0, catItem ); | 1698 | QListViewItem * item = new ShadedListItem( 0, catItem ); |
1704 | item->setText( 0, tr( name ) ); | 1699 | item->setText( 0, tr( name ) ); |
1705 | item->setText( 1, tr( user ) ); | 1700 | item->setText( 1, tr( user ) ); |
1706 | item->setText( 2, tr( password ) ); | 1701 | item->setText( 2, tr( password ) ); |
1707 | item->setText( 3, tr( comment ) ); | 1702 | item->setText( 3, tr( comment ) ); |
1708 | 1703 | ||
1709 | catItem->setOpen( TRUE ); | 1704 | catItem->setOpen( TRUE ); |
1710 | } | 1705 | } |
1711 | } | 1706 | } |
1712 | else | 1707 | else |
1713 | { | 1708 | { |
1714 | QListViewItem *catI = new ShadedListItem( 1, ListView ); | 1709 | QListViewItem *catI = new ShadedListItem( 1, ListView ); |
1715 | // create and insert a new item | 1710 | // create and insert a new item |
1716 | QListViewItem * item = new ShadedListItem( 0, catI ); | 1711 | QListViewItem * item = new ShadedListItem( 0, catI ); |
1717 | item->setText( 0, tr( name ) ); | 1712 | item->setText( 0, tr( name ) ); |
1718 | item->setText( 1, tr( user ) ); | 1713 | item->setText( 1, tr( user ) ); |
1719 | item->setText( 2, tr( password ) ); | 1714 | item->setText( 2, tr( password ) ); |
1720 | item->setText( 3, tr( comment ) ); | 1715 | item->setText( 3, tr( comment ) ); |
1721 | 1716 | ||
1722 | catI->setOpen( TRUE ); | 1717 | catI->setOpen( TRUE ); |
1723 | 1718 | ||
1724 | Category *c1 = new Category(); | 1719 | Category *c1 = new Category(); |
1725 | c1->setCategoryName(category); | 1720 | c1->setCategoryName(category); |
1726 | 1721 | ||
1727 | QString icon; | 1722 | QString icon; |
1728 | QString fullIconPath; | 1723 | QString fullIconPath; |
1729 | QPixmap *pix; | 1724 | QPixmap *pix; |
1730 | // #ifndef WIN32 | 1725 | // #ifndef WIN32 |
1731 | icon = conf->readEntry(APP_KEY+category); | 1726 | icon = conf->readEntry(APP_KEY+category); |
1732 | // #endif | 1727 | // #endif |
1733 | bool isIconAv = false; | 1728 | bool isIconAv = false; |
1734 | if (!icon.isEmpty() && !icon.isNull()) | 1729 | if (!icon.isEmpty() && !icon.isNull()) |
1735 | { | 1730 | { |
1736 | // build the full path | 1731 | // build the full path |
1737 | fullIconPath = iconPath + icon; | 1732 | fullIconPath = iconPath + icon; |
1738 | pix = new QPixmap (fullIconPath); | 1733 | pix = new QPixmap (fullIconPath); |
1739 | if (pix) | 1734 | if (pix) |
1740 | { | 1735 | { |
1741 | QImage img = pix->convertToImage(); | 1736 | QImage img = pix->convertToImage(); |
1742 | pix->convertFromImage(img.smoothScale(14,14)); | 1737 | pix->convertFromImage(img.smoothScale(14,14)); |
1743 | c1->setIconName (icon); | 1738 | c1->setIconName (icon); |
1744 | c1->setIcon (*pix); | 1739 | c1->setIcon (*pix); |
1745 | isIconAv = true; | 1740 | isIconAv = true; |
1746 | } | 1741 | } |
1747 | } | 1742 | } |
1748 | if (!isIconAv) | 1743 | if (!isIconAv) |
1749 | { | 1744 | { |
1750 | c1->setIcon (*getPredefinedIcon(category)); | 1745 | c1->setIcon (*getPredefinedIcon(category)); |
1751 | } | 1746 | } |
1752 | c1->setListItem (catI); | 1747 | c1->setListItem (catI); |
1753 | c1->initListItem(); | 1748 | c1->initListItem(); |
1754 | categories.insert (c1->getCategoryName(), c1); | 1749 | categories.insert (c1->getCategoryName(), c1); |
1755 | } | 1750 | } |
1756 | 1751 | ||
1757 | } | 1752 | } |
1758 | f.close(); | 1753 | f.close(); |
1759 | 1754 | ||
1760 | } | 1755 | } |
1761 | #endif // UNUSED | 1756 | #endif // UNUSED |
1762 | 1757 | ||
1763 | void ZSafe::resume(int) | 1758 | void ZSafe::resume(int) |
1764 | { | 1759 | { |
1765 | qWarning ("Resume"); | 1760 | owarn << "Resume" << oendl; |
1766 | // hide the main window | 1761 | // hide the main window |
1767 | 1762 | ||
1768 | infoForm->hide(); | 1763 | infoForm->hide(); |
1769 | // open zsafe again | 1764 | // open zsafe again |
1770 | m_password = ""; | 1765 | m_password = ""; |
1771 | selectedItem = NULL; | 1766 | selectedItem = NULL; |
1772 | 1767 | ||
1773 | // clear the password list | 1768 | // clear the password list |
1774 | QListViewItem *i; | 1769 | QListViewItem *i; |
1775 | // step through all categories | 1770 | // step through all categories |
1776 | for (i = ListView->firstChild(); | 1771 | for (i = ListView->firstChild(); |
1777 | i != NULL; | 1772 | i != NULL; |
1778 | i = i->nextSibling()) | 1773 | i = i->nextSibling()) |
1779 | { | 1774 | { |
1780 | // step through all subitems | 1775 | // step through all subitems |
1781 | QListViewItem *si; | 1776 | QListViewItem *si; |
1782 | for (si = i->firstChild(); | 1777 | for (si = i->firstChild(); |
1783 | si != NULL; ) | 1778 | si != NULL; ) |
1784 | { | 1779 | { |
1785 | QListViewItem *_si = si; | 1780 | QListViewItem *_si = si; |
1786 | si = si->nextSibling(); | 1781 | si = si->nextSibling(); |
1787 | i->takeItem(_si); // remove from view list | 1782 | i->takeItem(_si); // remove from view list |
1788 | if (_si) delete _si; | 1783 | if (_si) delete _si; |
1789 | } | 1784 | } |
1790 | } | 1785 | } |
1791 | 1786 | ||
1792 | // ask for password and read again | 1787 | // ask for password and read again |
1793 | openDocument(filename); | 1788 | openDocument(filename); |
1794 | } | 1789 | } |
1795 | 1790 | ||
1796 | //--------------------------------------------- | 1791 | //--------------------------------------------- |
1797 | 1792 | ||
1798 | 1793 | ||
1799 | bool ZSafe::openDocument(const char* _filename, const char* ) | 1794 | bool ZSafe::openDocument(const char* _filename, const char* ) |
1800 | { | 1795 | { |
1801 | int retval; | 1796 | int retval; |
1802 | char* entry[FIELD_SIZE]; | 1797 | char* entry[FIELD_SIZE]; |
1803 | // #ifndef WIN32 | 1798 | // #ifndef WIN32 |
1804 | int validationFlag = conf->readNumEntry(APP_KEY+"valzsafe", 1); | 1799 | int validationFlag = conf->readNumEntry(APP_KEY+"valzsafe", 1); |
1805 | // #else | 1800 | // #else |
1806 | // int validationFlag = 1; | 1801 | // int validationFlag = 1; |
1807 | // #endif | 1802 | // #endif |
1808 | 1803 | ||
1809 | int pwdOk = 0; | 1804 | int pwdOk = 0; |
1810 | int numberOfTries = 3; | 1805 | int numberOfTries = 3; |
1811 | for (int i=0; i < numberOfTries; i++) | 1806 | for (int i=0; i < numberOfTries; i++) |
1812 | { | 1807 | { |
1813 | QFile f(_filename); | 1808 | QFile f(_filename); |
1814 | if (f.exists()) | 1809 | if (f.exists()) |
1815 | { | 1810 | { |
1816 | // ask with a dialog for the password | 1811 | // ask with a dialog for the password |
1817 | if (m_password.isEmpty()) | 1812 | if (m_password.isEmpty()) |
1818 | getDocPassword(tr("Enter Password")); | 1813 | getDocPassword(tr("Enter Password")); |
1819 | if (m_password.isEmpty() && validationFlag == 0) | 1814 | if (m_password.isEmpty() && validationFlag == 0) |
1820 | { | 1815 | { |
1821 | qWarning ("Wrong password"); | 1816 | owarn << "Wrong password" << oendl; |
1822 | QMessageBox::critical( 0, tr("ZSafe"), | 1817 | QMessageBox::critical( 0, tr("ZSafe"), |
1823 | tr("Wrong password.\n\nZSafe will now exit.") ); | 1818 | tr("Wrong password.\n\nZSafe will now exit.") ); |
1824 | exitZs (1); | 1819 | exitZs (1); |
1825 | } | 1820 | } |
1826 | 1821 | ||
1827 | retval = loadInit(_filename, m_password); | 1822 | retval = loadInit(_filename, m_password); |
1828 | if (retval != PWERR_GOOD) | 1823 | if (retval != PWERR_GOOD) |
1829 | { | 1824 | { |
1830 | qWarning ("Error loading Document"); | 1825 | owarn << "Error loading Document" << oendl; |
1831 | return false; | 1826 | return false; |
1832 | } | 1827 | } |
1833 | } | 1828 | } |
1834 | else | 1829 | else |
1835 | { | 1830 | { |
1836 | #ifdef WIN32 | 1831 | #ifdef WIN32 |
1837 | this->setCaption("Qt ZSafe"); | 1832 | this->setCaption("Qt ZSafe"); |
1838 | #else | 1833 | #else |
1839 | this->setCaption("ZSafe"); | 1834 | this->setCaption("ZSafe"); |
1840 | #endif | 1835 | #endif |
1841 | filename = ""; | 1836 | filename = ""; |
1842 | return false; | 1837 | return false; |
1843 | } | 1838 | } |
1844 | 1839 | ||
1845 | 1840 | ||
1846 | // load the validation entry | 1841 | // load the validation entry |
1847 | if (validationFlag == 0) | 1842 | if (validationFlag == 0) |
1848 | { | 1843 | { |
1849 | pwdOk = 1; | 1844 | pwdOk = 1; |
1850 | break; | 1845 | break; |
1851 | } | 1846 | } |
1852 | 1847 | ||
1853 | retval = loadEntry(entry); | 1848 | retval = loadEntry(entry); |
1854 | if (retval == 1 && | 1849 | if (retval == 1 && |
1855 | !strcmp (entry[0], "ZSAFECATEGORY") && | 1850 | !strcmp (entry[0], "ZSAFECATEGORY") && |
1856 | !strcmp (entry[1], "name") && | 1851 | !strcmp (entry[1], "name") && |
1857 | !strcmp (entry[2], "username") && | 1852 | !strcmp (entry[2], "username") && |
1858 | !strcmp (entry[3], "password") && | 1853 | !strcmp (entry[3], "password") && |
1859 | !strcmp (entry[4], "comment") ) | 1854 | !strcmp (entry[4], "comment") ) |
1860 | { | 1855 | { |
1861 | for (int count = 0; count < FIELD_SIZE; count++) free(entry[count]); | 1856 | for (int count = 0; count < FIELD_SIZE; count++) free(entry[count]); |
1862 | pwdOk = 1; | 1857 | pwdOk = 1; |
1863 | break; | 1858 | break; |
1864 | } | 1859 | } |
1865 | else | 1860 | else |
1866 | // for (int count = 0; count < FIELD_SIZE; count++) free(entry[count]); | 1861 | // for (int count = 0; count < FIELD_SIZE; count++) free(entry[count]); |
1867 | fclose (fd); | 1862 | fclose (fd); |
1868 | m_password = ""; | 1863 | m_password = ""; |
1869 | 1864 | ||
1870 | if (i < numberOfTries - 1) | 1865 | if (i < numberOfTries - 1) |
1871 | { | 1866 | { |
1872 | switch( QMessageBox::warning( this, tr("ZSafe"), | 1867 | switch( QMessageBox::warning( this, tr("ZSafe"), |
1873 | tr("Wrong password.\nEnter again?"), | 1868 | tr("Wrong password.\nEnter again?"), |
1874 | tr("&Yes"), tr("&No."), | 1869 | tr("&Yes"), tr("&No."), |
1875 | 0 | 1870 | 0 |
1876 | ) ) | 1871 | ) ) |
1877 | { | 1872 | { |
1878 | case 1: // No | 1873 | case 1: // No |
1879 | exitZs (1); | 1874 | exitZs (1); |
1880 | break; | 1875 | break; |
1881 | case 0: // Yes | 1876 | case 0: // Yes |
1882 | continue; | 1877 | continue; |
1883 | } | 1878 | } |
1884 | } | 1879 | } |
1885 | } | 1880 | } |
1886 | if (pwdOk == 0) | 1881 | if (pwdOk == 0) |
1887 | { | 1882 | { |
1888 | // unset the document entry | 1883 | // unset the document entry |
1889 | conf->writeEntry(APP_KEY+"document", "INVALIDPWD"); | 1884 | conf->writeEntry(APP_KEY+"document", "INVALIDPWD"); |
1890 | if (conf) | 1885 | if (conf) |
1891 | delete conf; | 1886 | delete conf; |
1892 | 1887 | ||
1893 | exitZs (1); | 1888 | exitZs (1); |
1894 | } | 1889 | } |
@@ -2240,129 +2235,129 @@ bool ZSafe::saveDocument(const char* _filename, | |||
2240 | QListViewItem *i; | 2235 | QListViewItem *i; |
2241 | // step through all categories | 2236 | // step through all categories |
2242 | for (i = ListView->firstChild(); | 2237 | for (i = ListView->firstChild(); |
2243 | i != NULL; | 2238 | i != NULL; |
2244 | i = i->nextSibling()) | 2239 | i = i->nextSibling()) |
2245 | { | 2240 | { |
2246 | // step through all subitems | 2241 | // step through all subitems |
2247 | QListViewItem *si; | 2242 | QListViewItem *si; |
2248 | for (si = i->firstChild(); | 2243 | for (si = i->firstChild(); |
2249 | si != NULL; | 2244 | si != NULL; |
2250 | si = si->nextSibling()) | 2245 | si = si->nextSibling()) |
2251 | { | 2246 | { |
2252 | int j=0; | 2247 | int j=0; |
2253 | entry[j] = (char*)malloc(strlen(i->text(0).utf8())+1); | 2248 | entry[j] = (char*)malloc(strlen(i->text(0).utf8())+1); |
2254 | strcpy(entry[j++], i->text(0).utf8()); | 2249 | strcpy(entry[j++], i->text(0).utf8()); |
2255 | entry[j] = (char*)malloc(strlen(si->text(0).utf8())+1); | 2250 | entry[j] = (char*)malloc(strlen(si->text(0).utf8())+1); |
2256 | strcpy(entry[j++], si->text(0).utf8()); | 2251 | strcpy(entry[j++], si->text(0).utf8()); |
2257 | entry[j] = (char*)malloc(strlen(si->text(1).utf8())+1); | 2252 | entry[j] = (char*)malloc(strlen(si->text(1).utf8())+1); |
2258 | strcpy(entry[j++], si->text(1).utf8()); | 2253 | strcpy(entry[j++], si->text(1).utf8()); |
2259 | entry[j] = (char*)malloc(strlen(si->text(2).utf8())+1); | 2254 | entry[j] = (char*)malloc(strlen(si->text(2).utf8())+1); |
2260 | strcpy(entry[j++], si->text(2).utf8()); | 2255 | strcpy(entry[j++], si->text(2).utf8()); |
2261 | entry[j] = (char*)malloc(strlen(si->text(3).utf8())+1); | 2256 | entry[j] = (char*)malloc(strlen(si->text(3).utf8())+1); |
2262 | strcpy(entry[j++], si->text(3).utf8()); | 2257 | strcpy(entry[j++], si->text(3).utf8()); |
2263 | entry[j] = (char*)malloc(strlen(si->text(4).utf8())+1); | 2258 | entry[j] = (char*)malloc(strlen(si->text(4).utf8())+1); |
2264 | strcpy(entry[j++], si->text(4).utf8()); | 2259 | strcpy(entry[j++], si->text(4).utf8()); |
2265 | entry[j] = (char*)malloc(strlen(si->text(5).utf8())+1); | 2260 | entry[j] = (char*)malloc(strlen(si->text(5).utf8())+1); |
2266 | strcpy(entry[j++], si->text(5).utf8()); | 2261 | strcpy(entry[j++], si->text(5).utf8()); |
2267 | 2262 | ||
2268 | retval = saveEntry(entry); | 2263 | retval = saveEntry(entry); |
2269 | for (int z=0; z<j; z++) | 2264 | for (int z=0; z<j; z++) |
2270 | { | 2265 | { |
2271 | free(entry[z]); | 2266 | free(entry[z]); |
2272 | } | 2267 | } |
2273 | if (retval == PWERR_DATA) { | 2268 | if (retval == PWERR_DATA) { |
2274 | owarn << "1: Error writing file, contents not saved" << oendl; | 2269 | owarn << "1: Error writing file, contents not saved" << oendl; |
2275 | saveFinalize(); | 2270 | saveFinalize(); |
2276 | return false; | 2271 | return false; |
2277 | } | 2272 | } |
2278 | 2273 | ||
2279 | } | 2274 | } |
2280 | } | 2275 | } |
2281 | 2276 | ||
2282 | if (saveFinalize() == PWERR_DATA) { | 2277 | if (saveFinalize() == PWERR_DATA) { |
2283 | owarn << "2: Error writing file, contents not saved" << oendl; | 2278 | owarn << "2: Error writing file, contents not saved" << oendl; |
2284 | return false; | 2279 | return false; |
2285 | } else { | 2280 | } else { |
2286 | #ifndef DESKTOP | 2281 | #ifndef DESKTOP |
2287 | Global::statusMessage (tr("Password file saved.")); | 2282 | Global::statusMessage (tr("Password file saved.")); |
2288 | #endif | 2283 | #endif |
2289 | modified = false; | 2284 | modified = false; |
2290 | return true; | 2285 | return true; |
2291 | } | 2286 | } |
2292 | } | 2287 | } |
2293 | 2288 | ||
2294 | PasswordForm *newPwdDialog; | 2289 | PasswordForm *newPwdDialog; |
2295 | bool newPwdDialogResult = false; | 2290 | bool newPwdDialogResult = false; |
2296 | void ZSafe::setPasswordDialogDone() | 2291 | void ZSafe::setPasswordDialogDone() |
2297 | { | 2292 | { |
2298 | newPwdDialogResult = true; | 2293 | newPwdDialogResult = true; |
2299 | newPwdDialog->close(); | 2294 | newPwdDialog->close(); |
2300 | } | 2295 | } |
2301 | 2296 | ||
2302 | void ZSafe::getDocPassword(QString title) | 2297 | void ZSafe::getDocPassword(QString title) |
2303 | { | 2298 | { |
2304 | qWarning ("getDocPassword"); | 2299 | owarn << "getDocPassword" << oendl; |
2305 | // open the 'Password' dialog | 2300 | // open the 'Password' dialog |
2306 | PasswordForm *dialog = new PasswordForm(this, title, TRUE); | 2301 | PasswordForm *dialog = new PasswordForm(this, title, TRUE); |
2307 | newPwdDialog = dialog; | 2302 | newPwdDialog = dialog; |
2308 | newPwdDialogResult = false; | 2303 | newPwdDialogResult = false; |
2309 | 2304 | ||
2310 | connect( dialog->PasswordField, SIGNAL( returnPressed() ), | 2305 | connect( dialog->PasswordField, SIGNAL( returnPressed() ), |
2311 | this, SLOT( setPasswordDialogDone() ) ); | 2306 | this, SLOT( setPasswordDialogDone() ) ); |
2312 | 2307 | ||
2313 | // CS: !!! | 2308 | // CS: !!! |
2314 | // int pos = filename.findRev ('/'); | 2309 | // int pos = filename.findRev ('/'); |
2315 | QString ti = filename.right (filename.length() - filename.findRev ('/') - 1); | 2310 | QString ti = filename.right (filename.length() - filename.findRev ('/') - 1); |
2316 | #ifdef WIN32 | 2311 | #ifdef WIN32 |
2317 | dialog->setCaption("Qt " + ti); | 2312 | dialog->setCaption("Qt " + ti); |
2318 | #else | 2313 | #else |
2319 | dialog->setCaption(ti); | 2314 | dialog->setCaption(ti); |
2320 | #endif | 2315 | #endif |
2321 | // dialog->setCaption(title); | 2316 | // dialog->setCaption(title); |
2322 | 2317 | ||
2323 | dialog->PasswordField->setFocus(); | 2318 | dialog->PasswordField->setFocus(); |
2324 | DialogCode result = (DialogCode) dialog->exec(); | 2319 | DialogCode result = (DialogCode) dialog->exec(); |
2325 | #ifdef DESKTOP | 2320 | #ifdef DESKTOP |
2326 | result = Accepted; | 2321 | result = Accepted; |
2327 | #endif | 2322 | #endif |
2328 | 2323 | ||
2329 | QString password; | 2324 | QString password; |
2330 | if (result == Accepted || newPwdDialogResult) | 2325 | if (result == Accepted || newPwdDialogResult) |
2331 | { | 2326 | { |
2332 | m_password = dialog->PasswordField->text(); | 2327 | m_password = dialog->PasswordField->text(); |
2333 | } | 2328 | } |
2334 | else | 2329 | else |
2335 | { | 2330 | { |
2336 | exitZs (1); | 2331 | exitZs (1); |
2337 | } | 2332 | } |
2338 | } | 2333 | } |
2339 | 2334 | ||
2340 | int ZSafe::saveInit(const char *_filename, const char *password) | 2335 | int ZSafe::saveInit(const char *_filename, const char *password) |
2341 | { | 2336 | { |
2342 | char key[128]; | 2337 | char key[128]; |
2343 | unsigned int j = 0; | 2338 | unsigned int j = 0; |
2344 | unsigned int keylength; | 2339 | unsigned int keylength; |
2345 | // int val; | 2340 | // int val; |
2346 | int count2; | 2341 | int count2; |
2347 | Krc2* krc2 = new Krc2(); | 2342 | Krc2* krc2 = new Krc2(); |
2348 | 2343 | ||
2349 | /* first we should check the permissions of the filename */ | 2344 | /* first we should check the permissions of the filename */ |
2350 | /* | 2345 | /* |
2351 | if (QFile::exists(_filename)) { | 2346 | if (QFile::exists(_filename)) { |
2352 | val = checkFile(_filename); | 2347 | val = checkFile(_filename); |
2353 | if (val != PWERR_GOOD) | 2348 | if (val != PWERR_GOOD) |
2354 | return val; | 2349 | return val; |
2355 | } else | 2350 | } else |
2356 | { | 2351 | { |
2357 | val = creat (_filename, (S_IRUSR | S_IWUSR)); | 2352 | val = creat (_filename, (S_IRUSR | S_IWUSR)); |
2358 | if (val == -1) | 2353 | if (val == -1) |
2359 | return PWERR_OPEN; | 2354 | return PWERR_OPEN; |
2360 | else | 2355 | else |
2361 | close(val); | 2356 | close(val); |
2362 | } | 2357 | } |
2363 | */ | 2358 | */ |
2364 | QFileInfo f (_filename); | 2359 | QFileInfo f (_filename); |
2365 | save_buffer_length = f.size(); | 2360 | save_buffer_length = f.size(); |
2366 | save_buffer_length = ((save_buffer_length / 1024)+1) * 1024; | 2361 | save_buffer_length = ((save_buffer_length / 1024)+1) * 1024; |
2367 | 2362 | ||
2368 | fd = fopen (_filename, "wb"); | 2363 | fd = fopen (_filename, "wb"); |
@@ -2419,129 +2414,129 @@ int ZSafe::saveEntry(char *entry[FIELD_SIZE]) | |||
2419 | plaintext[bufferIndex] = buffer[count2 + 1] << 8; | 2414 | plaintext[bufferIndex] = buffer[count2 + 1] << 8; |
2420 | plaintext[bufferIndex] += buffer[count2] & 0xff; | 2415 | plaintext[bufferIndex] += buffer[count2] & 0xff; |
2421 | #endif | 2416 | #endif |
2422 | #ifdef WORDS_BIGENDIAN | 2417 | #ifdef WORDS_BIGENDIAN |
2423 | plaintext[bufferIndex] = buffer[count2] << 8; | 2418 | plaintext[bufferIndex] = buffer[count2] << 8; |
2424 | plaintext[bufferIndex] += buffer[count2 + 1] & 0xff; | 2419 | plaintext[bufferIndex] += buffer[count2 + 1] & 0xff; |
2425 | #endif | 2420 | #endif |
2426 | bufferIndex++; | 2421 | bufferIndex++; |
2427 | if (bufferIndex == 4) { | 2422 | if (bufferIndex == 4) { |
2428 | krc2->rc2_encrypt (plaintext); | 2423 | krc2->rc2_encrypt (plaintext); |
2429 | 2424 | ||
2430 | for (count3 = 0; count3 < 4; count3++) { | 2425 | for (count3 = 0; count3 < 4; count3++) { |
2431 | ciphertext[count3] = iv[count3] ^ plaintext[count3]; | 2426 | ciphertext[count3] = iv[count3] ^ plaintext[count3]; |
2432 | 2427 | ||
2433 | /* Now store the ciphertext as the iv */ | 2428 | /* Now store the ciphertext as the iv */ |
2434 | iv[count3] = plaintext[count3]; | 2429 | iv[count3] = plaintext[count3]; |
2435 | 2430 | ||
2436 | /* reset the buffer index */ | 2431 | /* reset the buffer index */ |
2437 | bufferIndex = 0; | 2432 | bufferIndex = 0; |
2438 | if (putc ((unsigned char) (ciphertext[count3] >> 8), fd) == EOF) return PWERR_DATA; | 2433 | if (putc ((unsigned char) (ciphertext[count3] >> 8), fd) == EOF) return PWERR_DATA; |
2439 | if (putc ((unsigned char) (ciphertext[count3] & 0xff), fd) == EOF) return PWERR_DATA; | 2434 | if (putc ((unsigned char) (ciphertext[count3] & 0xff), fd) == EOF) return PWERR_DATA; |
2440 | } /*for (count3 = 0; count3 < 5; count3++)*/ | 2435 | } /*for (count3 = 0; count3 < 5; count3++)*/ |
2441 | } /*if (bufferIndex == 5)*/ | 2436 | } /*if (bufferIndex == 5)*/ |
2442 | /* increment a short, not a byte */ | 2437 | /* increment a short, not a byte */ |
2443 | count2 += 2; | 2438 | count2 += 2; |
2444 | } /*while (count2 < strlen (buffer))*/ | 2439 | } /*while (count2 < strlen (buffer))*/ |
2445 | int ret = PWERR_GOOD; | 2440 | int ret = PWERR_GOOD; |
2446 | return ret; | 2441 | return ret; |
2447 | } | 2442 | } |
2448 | 2443 | ||
2449 | int ZSafe::saveFinalize(void) | 2444 | int ZSafe::saveFinalize(void) |
2450 | { | 2445 | { |
2451 | int count1, retval = PWERR_GOOD; | 2446 | int count1, retval = PWERR_GOOD; |
2452 | unsigned short ciphertext[4]; | 2447 | unsigned short ciphertext[4]; |
2453 | Krc2* krc2 = new Krc2(); | 2448 | Krc2* krc2 = new Krc2(); |
2454 | 2449 | ||
2455 | /* Tack on the PKCS 5 padding | 2450 | /* Tack on the PKCS 5 padding |
2456 | * How it works is we fill up the last n bytes with the value n | 2451 | * How it works is we fill up the last n bytes with the value n |
2457 | * | 2452 | * |
2458 | * So, if we have, say, 13 bytes, 8 of which are used, we have 5 left | 2453 | * So, if we have, say, 13 bytes, 8 of which are used, we have 5 left |
2459 | * over, leaving us 3 short, so we fill it in with 3's. | 2454 | * over, leaving us 3 short, so we fill it in with 3's. |
2460 | * | 2455 | * |
2461 | * If we come out even, we fill it with 8 8s | 2456 | * If we come out even, we fill it with 8 8s |
2462 | * | 2457 | * |
2463 | * um, except that in this instance we are using 4 shorts instead of 8 bytes. | 2458 | * um, except that in this instance we are using 4 shorts instead of 8 bytes. |
2464 | * so, half everything | 2459 | * so, half everything |
2465 | */ | 2460 | */ |
2466 | for (count1 = bufferIndex; count1 < 4; count1++) { | 2461 | for (count1 = bufferIndex; count1 < 4; count1++) { |
2467 | plaintext[count1] = (4 - bufferIndex); | 2462 | plaintext[count1] = (4 - bufferIndex); |
2468 | } | 2463 | } |
2469 | krc2->rc2_encrypt (plaintext); | 2464 | krc2->rc2_encrypt (plaintext); |
2470 | for (count1 = 0; count1 < 4; count1++) { | 2465 | for (count1 = 0; count1 < 4; count1++) { |
2471 | ciphertext[count1] = iv[count1] ^ plaintext[count1]; | 2466 | ciphertext[count1] = iv[count1] ^ plaintext[count1]; |
2472 | if (putc ((unsigned char) (ciphertext[count1] >> 8), fd) == EOF) retval = PWERR_DATA; | 2467 | if (putc ((unsigned char) (ciphertext[count1] >> 8), fd) == EOF) retval = PWERR_DATA; |
2473 | if (putc ((unsigned char) (ciphertext[count1] & 0xff), fd) == EOF) retval = PWERR_DATA; | 2468 | if (putc ((unsigned char) (ciphertext[count1] & 0xff), fd) == EOF) retval = PWERR_DATA; |
2474 | } | 2469 | } |
2475 | 2470 | ||
2476 | fclose (fd); | 2471 | fclose (fd); |
2477 | free(buffer); | 2472 | free(buffer); |
2478 | return retval; | 2473 | return retval; |
2479 | } | 2474 | } |
2480 | 2475 | ||
2481 | void ZSafe::quitMe () | 2476 | void ZSafe::quitMe () |
2482 | { | 2477 | { |
2483 | qWarning ("QUIT..."); | 2478 | owarn << "QUIT..." << oendl; |
2484 | 2479 | ||
2485 | if (modified) | 2480 | if (modified) |
2486 | { | 2481 | { |
2487 | switch( QMessageBox::information( this, tr("ZSafe"), | 2482 | switch( QMessageBox::information( this, tr("ZSafe"), |
2488 | tr("Do you want to save\nbefore exiting?"), | 2483 | tr("Do you want to save\nbefore exiting?"), |
2489 | tr("&Save"), | 2484 | tr("&Save"), |
2490 | tr("S&ave with\nnew\npassword"), | 2485 | tr("S&ave with\nnew\npassword"), |
2491 | tr("&Don't Save"), | 2486 | tr("&Don't Save"), |
2492 | 0 // Enter == button 0 | 2487 | 0 // Enter == button 0 |
2493 | ) ) | 2488 | ) ) |
2494 | { // Escape == button 2 | 2489 | { // Escape == button 2 |
2495 | case 0: // Save clicked, Alt-S or Enter pressed. | 2490 | case 0: // Save clicked, Alt-S or Enter pressed. |
2496 | // save | 2491 | // save |
2497 | modified = false; | 2492 | modified = false; |
2498 | saveDocument(filename, FALSE); | 2493 | saveDocument(filename, FALSE); |
2499 | exitZs (1); | 2494 | exitZs (1); |
2500 | break; | 2495 | break; |
2501 | case 1: // | 2496 | case 1: // |
2502 | // Save with new password | 2497 | // Save with new password |
2503 | modified = false; | 2498 | modified = false; |
2504 | saveDocument(filename, TRUE); | 2499 | saveDocument(filename, TRUE); |
2505 | exitZs (1); | 2500 | exitZs (1); |
2506 | break; | 2501 | break; |
2507 | case 2: // Don't Save clicked or Alt-D pressed | 2502 | case 2: // Don't Save clicked or Alt-D pressed |
2508 | // don't save but exitZs | 2503 | // don't save but exitZs |
2509 | exitZs (1); | 2504 | exitZs (1); |
2510 | break; | 2505 | break; |
2511 | } | 2506 | } |
2512 | } | 2507 | } |
2513 | exitZs (1); | 2508 | exitZs (1); |
2514 | 2509 | ||
2515 | } | 2510 | } |
2516 | 2511 | ||
2517 | void ZSafe::categoryFieldActivated( const QString& category) | 2512 | void ZSafe::categoryFieldActivated( const QString& category) |
2518 | { | 2513 | { |
2519 | if (categoryDialog) | 2514 | if (categoryDialog) |
2520 | setCategoryDialogFields(categoryDialog, category); | 2515 | setCategoryDialogFields(categoryDialog, category); |
2521 | } | 2516 | } |
2522 | 2517 | ||
2523 | void ZSafe::addCategory() | 2518 | void ZSafe::addCategory() |
2524 | { | 2519 | { |
2525 | if (filename.isEmpty()) | 2520 | if (filename.isEmpty()) |
2526 | { | 2521 | { |
2527 | QMessageBox::critical( 0, tr("ZSafe"), | 2522 | QMessageBox::critical( 0, tr("ZSafe"), |
2528 | tr("No document defined.\nYou have to create a new document")); | 2523 | tr("No document defined.\nYou have to create a new document")); |
2529 | return; | 2524 | return; |
2530 | } | 2525 | } |
2531 | else | 2526 | else |
2532 | { | 2527 | { |
2533 | // open the 'Category' dialog | 2528 | // open the 'Category' dialog |
2534 | bool initIcons = false; | 2529 | bool initIcons = false; |
2535 | // open the 'Category' dialog | 2530 | // open the 'Category' dialog |
2536 | CategoryDialog *dialog; | 2531 | CategoryDialog *dialog; |
2537 | if (categoryDialog) | 2532 | if (categoryDialog) |
2538 | { | 2533 | { |
2539 | dialog = categoryDialog; | 2534 | dialog = categoryDialog; |
2540 | } | 2535 | } |
2541 | else | 2536 | else |
2542 | { | 2537 | { |
2543 | categoryDialog = new CategoryDialog(this, tr("Category"), TRUE); | 2538 | categoryDialog = new CategoryDialog(this, tr("Category"), TRUE); |
2544 | #ifdef WIN32 | 2539 | #ifdef WIN32 |
2545 | categoryDialog->setCaption ("Qt " + tr("Category")); | 2540 | categoryDialog->setCaption ("Qt " + tr("Category")); |
2546 | #endif | 2541 | #endif |
2547 | dialog = categoryDialog; | 2542 | dialog = categoryDialog; |
@@ -2623,129 +2618,129 @@ void ZSafe::addCategory() | |||
2623 | setCategoryDialogFields(dialog, firstCategory); | 2618 | setCategoryDialogFields(dialog, firstCategory); |
2624 | 2619 | ||
2625 | // CategoryDialog *dialog = new CategoryDialog(this, "Category", TRUE); | 2620 | // CategoryDialog *dialog = new CategoryDialog(this, "Category", TRUE); |
2626 | 2621 | ||
2627 | if (initIcons) | 2622 | if (initIcons) |
2628 | { | 2623 | { |
2629 | Wait waitDialog(this, tr("Wait dialog")); | 2624 | Wait waitDialog(this, tr("Wait dialog")); |
2630 | waitDialog.waitLabel->setText(tr("Gathering icons...")); | 2625 | waitDialog.waitLabel->setText(tr("Gathering icons...")); |
2631 | waitDialog.show(); | 2626 | waitDialog.show(); |
2632 | qApp->processEvents(); | 2627 | qApp->processEvents(); |
2633 | 2628 | ||
2634 | #ifdef DESKTOP | 2629 | #ifdef DESKTOP |
2635 | QDir d(iconPath); | 2630 | QDir d(iconPath); |
2636 | #else | 2631 | #else |
2637 | QDir d(QPEApplication::qpeDir() + "/pics/"); | 2632 | QDir d(QPEApplication::qpeDir() + "/pics/"); |
2638 | #endif | 2633 | #endif |
2639 | d.setFilter( QDir::Files); | 2634 | d.setFilter( QDir::Files); |
2640 | 2635 | ||
2641 | const QFileInfoList *list = d.entryInfoList(); | 2636 | const QFileInfoList *list = d.entryInfoList(); |
2642 | QFileInfoListIterator it( *list ); // create list iterator | 2637 | QFileInfoListIterator it( *list ); // create list iterator |
2643 | QFileInfo *fi; // pointer for traversing | 2638 | QFileInfo *fi; // pointer for traversing |
2644 | 2639 | ||
2645 | dialog->IconField->insertItem("predefined"); | 2640 | dialog->IconField->insertItem("predefined"); |
2646 | while ( (fi=it.current()) ) { // for each file... | 2641 | while ( (fi=it.current()) ) { // for each file... |
2647 | QString fileName = fi->fileName(); | 2642 | QString fileName = fi->fileName(); |
2648 | if(fileName.right(4) == ".png"){ | 2643 | if(fileName.right(4) == ".png"){ |
2649 | fileName = fileName.mid(0,fileName.length()-4); | 2644 | fileName = fileName.mid(0,fileName.length()-4); |
2650 | #ifdef DESKTOP | 2645 | #ifdef DESKTOP |
2651 | QPixmap imageOfFile; | 2646 | QPixmap imageOfFile; |
2652 | imageOfFile.load(iconPath + fi->fileName()); | 2647 | imageOfFile.load(iconPath + fi->fileName()); |
2653 | #else | 2648 | #else |
2654 | QPixmap imageOfFile(Resource::loadPixmap(fileName)); | 2649 | QPixmap imageOfFile(Resource::loadPixmap(fileName)); |
2655 | #endif | 2650 | #endif |
2656 | QImage foo = imageOfFile.convertToImage(); | 2651 | QImage foo = imageOfFile.convertToImage(); |
2657 | foo = foo.smoothScale(16,16); | 2652 | foo = foo.smoothScale(16,16); |
2658 | imageOfFile.convertFromImage(foo); | 2653 | imageOfFile.convertFromImage(foo); |
2659 | dialog->IconField->insertItem(imageOfFile,fileName); | 2654 | dialog->IconField->insertItem(imageOfFile,fileName); |
2660 | } | 2655 | } |
2661 | ++it; | 2656 | ++it; |
2662 | } | 2657 | } |
2663 | waitDialog.hide(); | 2658 | waitDialog.hide(); |
2664 | } | 2659 | } |
2665 | 2660 | ||
2666 | #ifndef WIN32 | 2661 | #ifndef WIN32 |
2667 | dialog->show(); | 2662 | dialog->show(); |
2668 | #endif | 2663 | #endif |
2669 | #ifndef DESKTOP | 2664 | #ifndef DESKTOP |
2670 | // dialog->move (20, 100); | 2665 | // dialog->move (20, 100); |
2671 | #endif | 2666 | #endif |
2672 | DialogCode result = (DialogCode) dialog->exec(); | 2667 | DialogCode result = (DialogCode) dialog->exec(); |
2673 | #ifdef DESKTOP | 2668 | #ifdef DESKTOP |
2674 | result = Accepted; | 2669 | result = Accepted; |
2675 | #endif | 2670 | #endif |
2676 | 2671 | ||
2677 | QString category; | 2672 | QString category; |
2678 | QString icon; | 2673 | QString icon; |
2679 | QString fullIconPath; | 2674 | QString fullIconPath; |
2680 | QPixmap *pix; | 2675 | QPixmap *pix; |
2681 | if (result == Accepted) | 2676 | if (result == Accepted) |
2682 | { | 2677 | { |
2683 | modified = true; | 2678 | modified = true; |
2684 | category = dialog->CategoryField->currentText(); | 2679 | category = dialog->CategoryField->currentText(); |
2685 | icon = dialog->IconField->currentText()+".png"; | 2680 | icon = dialog->IconField->currentText()+".png"; |
2686 | 2681 | ||
2687 | qWarning (category); | 2682 | owarn << category << oendl; |
2688 | 2683 | ||
2689 | QListViewItem *li = new ShadedListItem( 1, ListView ); | 2684 | QListViewItem *li = new ShadedListItem( 1, ListView ); |
2690 | Category *c1 = new Category(); | 2685 | Category *c1 = new Category(); |
2691 | c1->setCategoryName(category); | 2686 | c1->setCategoryName(category); |
2692 | 2687 | ||
2693 | // if (!icon.isEmpty() && !icon.isNull()) | 2688 | // if (!icon.isEmpty() && !icon.isNull()) |
2694 | if (icon != "predefined.png") | 2689 | if (icon != "predefined.png") |
2695 | { | 2690 | { |
2696 | // build the full path | 2691 | // build the full path |
2697 | fullIconPath = iconPath + icon; | 2692 | fullIconPath = iconPath + icon; |
2698 | pix = new QPixmap (fullIconPath); | 2693 | pix = new QPixmap (fullIconPath); |
2699 | // pix->resize(14, 14); | 2694 | // pix->resize(14, 14); |
2700 | if (pix) | 2695 | if (pix) |
2701 | { | 2696 | { |
2702 | // save the full pixmap name into the config file | 2697 | // save the full pixmap name into the config file |
2703 | // #ifndef WIN32 | 2698 | // #ifndef WIN32 |
2704 | conf->writeEntry(APP_KEY+category, icon); | 2699 | conf->writeEntry(APP_KEY+category, icon); |
2705 | // #endif | 2700 | // #endif |
2706 | saveConf(); | 2701 | saveConf(); |
2707 | QImage img = pix->convertToImage(); | 2702 | QImage img = pix->convertToImage(); |
2708 | pix->convertFromImage(img.smoothScale(14,14)); | 2703 | pix->convertFromImage(img.smoothScale(14,14)); |
2709 | c1->setIcon (*pix); | 2704 | c1->setIcon (*pix); |
2710 | c1->setIconName(icon); | 2705 | c1->setIconName(icon); |
2711 | } | 2706 | } |
2712 | else | 2707 | else |
2713 | { | 2708 | { |
2714 | QPixmap folder( ( const char** ) general_data ); | 2709 | QPixmap folder( ( const char** ) general_data ); |
2715 | c1->setIcon (folder); | 2710 | c1->setIcon (folder); |
2716 | } | 2711 | } |
2717 | } | 2712 | } |
2718 | else | 2713 | else |
2719 | { | 2714 | { |
2720 | c1->setIcon (*getPredefinedIcon(category)); | 2715 | c1->setIcon (*getPredefinedIcon(category)); |
2721 | } | 2716 | } |
2722 | 2717 | ||
2723 | c1->setListItem (li); | 2718 | c1->setListItem (li); |
2724 | c1->initListItem(); | 2719 | c1->initListItem(); |
2725 | categories.insert (c1->getCategoryName(), c1); | 2720 | categories.insert (c1->getCategoryName(), c1); |
2726 | 2721 | ||
2727 | saveCategoryDialogFields(dialog); | 2722 | saveCategoryDialogFields(dialog); |
2728 | } | 2723 | } |
2729 | else | 2724 | else |
2730 | { | 2725 | { |
2731 | // delete dialog; | 2726 | // delete dialog; |
2732 | dialog->hide(); | 2727 | dialog->hide(); |
2733 | return; | 2728 | return; |
2734 | } | 2729 | } |
2735 | 2730 | ||
2736 | } | 2731 | } |
2737 | 2732 | ||
2738 | } | 2733 | } |
2739 | 2734 | ||
2740 | void ZSafe::delCategory() | 2735 | void ZSafe::delCategory() |
2741 | { | 2736 | { |
2742 | if (!selectedItem) | 2737 | if (!selectedItem) |
2743 | return; | 2738 | return; |
2744 | if (isCategory(selectedItem)) | 2739 | if (isCategory(selectedItem)) |
2745 | { | 2740 | { |
2746 | switch( QMessageBox::information( this, tr("ZSafe"), | 2741 | switch( QMessageBox::information( this, tr("ZSafe"), |
2747 | tr("Do you want to delete?"), | 2742 | tr("Do you want to delete?"), |
2748 | tr("&Delete"), tr("D&on't Delete"), | 2743 | tr("&Delete"), tr("D&on't Delete"), |
2749 | 0 // Enter == button 0 | 2744 | 0 // Enter == button 0 |
2750 | ) ) { // Escape == button 2 | 2745 | ) ) { // Escape == button 2 |
2751 | case 0: // Delete clicked, Alt-S or Enter pressed. | 2746 | case 0: // Delete clicked, Alt-S or Enter pressed. |
@@ -3131,129 +3126,129 @@ void ZSafe::editCategory() | |||
3131 | } | 3126 | } |
3132 | 3127 | ||
3133 | // dialog->show(); | 3128 | // dialog->show(); |
3134 | #ifndef DESKTOP | 3129 | #ifndef DESKTOP |
3135 | // dialog->move (20, 100); | 3130 | // dialog->move (20, 100); |
3136 | #endif | 3131 | #endif |
3137 | DialogCode result = (DialogCode) dialog->exec(); | 3132 | DialogCode result = (DialogCode) dialog->exec(); |
3138 | #ifdef DESKTOP | 3133 | #ifdef DESKTOP |
3139 | result = Accepted; | 3134 | result = Accepted; |
3140 | #endif | 3135 | #endif |
3141 | 3136 | ||
3142 | QString fullIconPath; | 3137 | QString fullIconPath; |
3143 | QPixmap *pix; | 3138 | QPixmap *pix; |
3144 | if (result == Accepted) | 3139 | if (result == Accepted) |
3145 | { | 3140 | { |
3146 | modified = true; | 3141 | modified = true; |
3147 | if (category != dialog->CategoryField->currentText()) | 3142 | if (category != dialog->CategoryField->currentText()) |
3148 | { | 3143 | { |
3149 | categories.remove (category); | 3144 | categories.remove (category); |
3150 | // #ifndef WIN32 | 3145 | // #ifndef WIN32 |
3151 | conf->removeEntry(category); | 3146 | conf->removeEntry(category); |
3152 | // #endif | 3147 | // #endif |
3153 | saveConf(); | 3148 | saveConf(); |
3154 | } | 3149 | } |
3155 | 3150 | ||
3156 | category = dialog->CategoryField->currentText(); | 3151 | category = dialog->CategoryField->currentText(); |
3157 | icon = dialog->IconField->currentText()+".png"; | 3152 | icon = dialog->IconField->currentText()+".png"; |
3158 | 3153 | ||
3159 | if (cat) | 3154 | if (cat) |
3160 | { | 3155 | { |
3161 | owarn << "Category found" << oendl; | 3156 | owarn << "Category found" << oendl; |
3162 | 3157 | ||
3163 | // if (!icon.isEmpty() && !icon.isNull()) | 3158 | // if (!icon.isEmpty() && !icon.isNull()) |
3164 | if (icon != "predefined.png") | 3159 | if (icon != "predefined.png") |
3165 | { | 3160 | { |
3166 | // build the full path | 3161 | // build the full path |
3167 | fullIconPath = iconPath + icon; | 3162 | fullIconPath = iconPath + icon; |
3168 | pix = new QPixmap (fullIconPath); | 3163 | pix = new QPixmap (fullIconPath); |
3169 | if (pix) | 3164 | if (pix) |
3170 | { | 3165 | { |
3171 | // save the full pixmap name into the config file | 3166 | // save the full pixmap name into the config file |
3172 | // #ifndef WIN32 | 3167 | // #ifndef WIN32 |
3173 | conf->writeEntry(APP_KEY+category, icon); | 3168 | conf->writeEntry(APP_KEY+category, icon); |
3174 | // #endif | 3169 | // #endif |
3175 | saveConf(); | 3170 | saveConf(); |
3176 | QImage img = pix->convertToImage(); | 3171 | QImage img = pix->convertToImage(); |
3177 | pix->convertFromImage(img.smoothScale(14,14)); | 3172 | pix->convertFromImage(img.smoothScale(14,14)); |
3178 | cat->setIconName (icon); | 3173 | cat->setIconName (icon); |
3179 | cat->setIcon (*pix); | 3174 | cat->setIcon (*pix); |
3180 | } | 3175 | } |
3181 | } | 3176 | } |
3182 | else | 3177 | else |
3183 | { | 3178 | { |
3184 | // #ifndef WIN32 | 3179 | // #ifndef WIN32 |
3185 | conf->removeEntry (category); | 3180 | conf->removeEntry (category); |
3186 | // #endif | 3181 | // #endif |
3187 | saveConf(); | 3182 | saveConf(); |
3188 | cat->setIcon (*getPredefinedIcon(category)); | 3183 | cat->setIcon (*getPredefinedIcon(category)); |
3189 | } | 3184 | } |
3190 | 3185 | ||
3191 | // change the category name of the selected category | 3186 | // change the category name of the selected category |
3192 | QListViewItem *catItem = cat->getListItem(); | 3187 | QListViewItem *catItem = cat->getListItem(); |
3193 | if (catItem) | 3188 | if (catItem) |
3194 | { | 3189 | { |
3195 | qWarning (category); | 3190 | owarn << category << oendl; |
3196 | catItem->setText( 0, tr( category ) ); | 3191 | catItem->setText( 0, tr( category ) ); |
3197 | cat->setCategoryName (tr(category)); | 3192 | cat->setCategoryName (tr(category)); |
3198 | 3193 | ||
3199 | cat->initListItem(); | 3194 | cat->initListItem(); |
3200 | categories.insert (category, cat); | 3195 | categories.insert (category, cat); |
3201 | } | 3196 | } |
3202 | } | 3197 | } |
3203 | saveCategoryDialogFields(dialog); | 3198 | saveCategoryDialogFields(dialog); |
3204 | } | 3199 | } |
3205 | else | 3200 | else |
3206 | { | 3201 | { |
3207 | // delete dialog; | 3202 | // delete dialog; |
3208 | dialog->hide(); | 3203 | dialog->hide(); |
3209 | return; | 3204 | return; |
3210 | } | 3205 | } |
3211 | 3206 | ||
3212 | } | 3207 | } |
3213 | } | 3208 | } |
3214 | 3209 | ||
3215 | void ZSafe::cutItem() | 3210 | void ZSafe::cutItem() |
3216 | { | 3211 | { |
3217 | if (!selectedItem) | 3212 | if (!selectedItem) |
3218 | return; | 3213 | return; |
3219 | if (!isCategory(selectedItem)) | 3214 | if (!isCategory(selectedItem)) |
3220 | { | 3215 | { |
3221 | IsCut = true; | 3216 | IsCut = true; |
3222 | copiedItem = selectedItem; | 3217 | copiedItem = selectedItem; |
3223 | } | 3218 | } |
3224 | } | 3219 | } |
3225 | 3220 | ||
3226 | void ZSafe::copyItem() | 3221 | void ZSafe::copyItem() |
3227 | { | 3222 | { |
3228 | if (!selectedItem) | 3223 | if (!selectedItem) |
3229 | return; | 3224 | return; |
3230 | if (!isCategory(selectedItem)) | 3225 | if (!isCategory(selectedItem)) |
3231 | { | 3226 | { |
3232 | IsCopy = true; | 3227 | IsCopy = true; |
3233 | copiedItem = selectedItem; | 3228 | copiedItem = selectedItem; |
3234 | } | 3229 | } |
3235 | } | 3230 | } |
3236 | 3231 | ||
3237 | // paste item into category | 3232 | // paste item into category |
3238 | void ZSafe::pasteItem() | 3233 | void ZSafe::pasteItem() |
3239 | { | 3234 | { |
3240 | if (!selectedItem) | 3235 | if (!selectedItem) |
3241 | return; | 3236 | return; |
3242 | if (isCategory(selectedItem)) | 3237 | if (isCategory(selectedItem)) |
3243 | { | 3238 | { |
3244 | modified = true; | 3239 | modified = true; |
3245 | if (IsCut) | 3240 | if (IsCut) |
3246 | { | 3241 | { |
3247 | if (copiedItem) | 3242 | if (copiedItem) |
3248 | { | 3243 | { |
3249 | // add the new item | 3244 | // add the new item |
3250 | QListViewItem *i = new ShadedListItem (0, selectedItem); | 3245 | QListViewItem *i = new ShadedListItem (0, selectedItem); |
3251 | // i->setOpen (TRUE); | 3246 | // i->setOpen (TRUE); |
3252 | i->setText (0, copiedItem->text(0)); | 3247 | i->setText (0, copiedItem->text(0)); |
3253 | i->setText (1, copiedItem->text(1)); | 3248 | i->setText (1, copiedItem->text(1)); |
3254 | i->setText (2, copiedItem->text(2)); | 3249 | i->setText (2, copiedItem->text(2)); |
3255 | i->setText (3, copiedItem->text(3)); | 3250 | i->setText (3, copiedItem->text(3)); |
3256 | i->setText (4, copiedItem->text(4)); | 3251 | i->setText (4, copiedItem->text(4)); |
3257 | i->setText (5, copiedItem->text(5)); | 3252 | i->setText (5, copiedItem->text(5)); |
3258 | selectedItem->setOpen( TRUE ); | 3253 | selectedItem->setOpen( TRUE ); |
3259 | 3254 | ||
@@ -3532,129 +3527,129 @@ void ZSafe::about() | |||
3532 | info += "<br>"; | 3527 | info += "<br>"; |
3533 | info += tr("Translations by Robert Ernst<br>"); | 3528 | info += tr("Translations by Robert Ernst<br>"); |
3534 | info += "robert.ernst@linux-solutions.at<br>"; | 3529 | info += "robert.ernst@linux-solutions.at<br>"; |
3535 | 3530 | ||
3536 | info += "<br><br>"; | 3531 | info += "<br><br>"; |
3537 | info += QString::fromUtf8("æ~W¥æ~\\¬èª~^/VGA Zaurus対å¿~\\ã~C~Qã~C~Cã~C~Aä½~\\æ ~H~P<br>"); | 3532 | info += QString::fromUtf8("æ~W¥æ~\\¬èª~^/VGA Zaurus対å¿~\\ã~C~Qã~C~Cã~C~Aä½~\\æ ~H~P<br>"); |
3538 | info += "HADECO R&D<br>"; | 3533 | info += "HADECO R&D<br>"; |
3539 | info += "r&d@hadeco.co.jp<br>"; | 3534 | info += "r&d@hadeco.co.jp<br>"; |
3540 | info += "http://www.hadeco.co.jp/r&d/<br>"; | 3535 | info += "http://www.hadeco.co.jp/r&d/<br>"; |
3541 | info += "<br></div>"; | 3536 | info += "<br></div>"; |
3542 | info += "</body></html>"; | 3537 | info += "</body></html>"; |
3543 | #else | 3538 | #else |
3544 | info = "<html><body><div align=""center"">"; | 3539 | info = "<html><body><div align=""center"">"; |
3545 | info += "<b>"; | 3540 | info += "<b>"; |
3546 | info += tr("Zaurus Password Manager<br>"); | 3541 | info += tr("Zaurus Password Manager<br>"); |
3547 | info += tr("ZSafe version 2.1.2<br>"); | 3542 | info += tr("ZSafe version 2.1.2<br>"); |
3548 | info += "</b>"; | 3543 | info += "</b>"; |
3549 | info += tr("by Carsten Schneider<br>"); | 3544 | info += tr("by Carsten Schneider<br>"); |
3550 | info += "zcarsten@gmx.net<br>"; | 3545 | info += "zcarsten@gmx.net<br>"; |
3551 | info += "http://z-soft.z-portal.info/zsafe"; | 3546 | info += "http://z-soft.z-portal.info/zsafe"; |
3552 | info += "<br>"; | 3547 | info += "<br>"; |
3553 | info += tr("Translations by Robert Ernst<br>"); | 3548 | info += tr("Translations by Robert Ernst<br>"); |
3554 | info += "robert.ernst@linux-solutions.at<br>"; | 3549 | info += "robert.ernst@linux-solutions.at<br>"; |
3555 | info += "<br></div>"; | 3550 | info += "<br></div>"; |
3556 | info += "</body></html>"; | 3551 | info += "</body></html>"; |
3557 | #endif | 3552 | #endif |
3558 | 3553 | ||
3559 | // QMessageBox::information( this, tr("ZSafe"), info, tr("&OK"), 0); | 3554 | // QMessageBox::information( this, tr("ZSafe"), info, tr("&OK"), 0); |
3560 | 3555 | ||
3561 | QMessageBox mb( this, tr("ZSafe")); | 3556 | QMessageBox mb( this, tr("ZSafe")); |
3562 | mb.setText (info); | 3557 | mb.setText (info); |
3563 | mb.setButtonText (QMessageBox::Ok, tr ("&OK")); | 3558 | mb.setButtonText (QMessageBox::Ok, tr ("&OK")); |
3564 | QPixmap zsafe_img((const char**) zsafe_xpm); | 3559 | QPixmap zsafe_img((const char**) zsafe_xpm); |
3565 | mb.setIconPixmap (zsafe_img); | 3560 | mb.setIconPixmap (zsafe_img); |
3566 | mb.exec(); | 3561 | mb.exec(); |
3567 | } | 3562 | } |
3568 | 3563 | ||
3569 | void ZSafe::setExpandFlag() | 3564 | void ZSafe::setExpandFlag() |
3570 | { | 3565 | { |
3571 | expandTree = !expandTree; | 3566 | expandTree = !expandTree; |
3572 | file->setItemChecked('o', expandTree); | 3567 | file->setItemChecked('o', expandTree); |
3573 | #ifndef DESKTOP | 3568 | #ifndef DESKTOP |
3574 | conf->setGroup ("zsafePrefs"); | 3569 | conf->setGroup ("zsafePrefs"); |
3575 | #endif | 3570 | #endif |
3576 | // #ifndef WIN32 | 3571 | // #ifndef WIN32 |
3577 | conf->writeEntry (APP_KEY+"expandTree", expandTree); | 3572 | conf->writeEntry (APP_KEY+"expandTree", expandTree); |
3578 | // #endif | 3573 | // #endif |
3579 | saveConf(); | 3574 | saveConf(); |
3580 | 3575 | ||
3581 | } | 3576 | } |
3582 | 3577 | ||
3583 | void ZSafe::paintEvent( QPaintEvent * ) | 3578 | void ZSafe::paintEvent( QPaintEvent * ) |
3584 | { | 3579 | { |
3585 | if (raiseFlag) | 3580 | if (raiseFlag) |
3586 | { | 3581 | { |
3587 | raiseFlag = false; | 3582 | raiseFlag = false; |
3588 | raiseTimer.start (1, true); | 3583 | raiseTimer.start (1, true); |
3589 | if (infoForm->isVisible()) | 3584 | if (infoForm->isVisible()) |
3590 | infoForm->raise(); | 3585 | infoForm->raise(); |
3591 | } | 3586 | } |
3592 | } | 3587 | } |
3593 | 3588 | ||
3594 | void ZSafe::resizeEvent ( QResizeEvent * ) | 3589 | void ZSafe::resizeEvent ( QResizeEvent * ) |
3595 | { | 3590 | { |
3596 | // qWarning ("resizeEvent"); | 3591 | // owarn << "resizeEvent" << oendl; |
3597 | #ifndef DESKTOP | 3592 | #ifndef DESKTOP |
3598 | DeskW = appl->desktop()->width(); | 3593 | DeskW = appl->desktop()->width(); |
3599 | DeskH = appl->desktop()->height(); | 3594 | DeskH = appl->desktop()->height(); |
3600 | #else | 3595 | #else |
3601 | DeskW = this->width(); | 3596 | DeskW = this->width(); |
3602 | DeskH = this->height(); | 3597 | DeskH = this->height(); |
3603 | #endif | 3598 | #endif |
3604 | 3599 | ||
3605 | if (New) | 3600 | if (New) |
3606 | New->setGeometry ( QRect( DeskW-84, 2, 20, 20 ) ); | 3601 | New->setGeometry ( QRect( DeskW-84, 2, 20, 20 ) ); |
3607 | if (Edit) | 3602 | if (Edit) |
3608 | Edit->setGeometry ( QRect( DeskW-64, 2, 20, 20 ) ); | 3603 | Edit->setGeometry ( QRect( DeskW-64, 2, 20, 20 ) ); |
3609 | if (Delete) | 3604 | if (Delete) |
3610 | Delete->setGeometry( QRect( DeskW-44, 2, 20, 20 ) ); | 3605 | Delete->setGeometry( QRect( DeskW-44, 2, 20, 20 ) ); |
3611 | if (Find) | 3606 | if (Find) |
3612 | Find->setGeometry ( QRect( DeskW-24, 2, 20, 20 ) ); | 3607 | Find->setGeometry ( QRect( DeskW-24, 2, 20, 20 ) ); |
3613 | } | 3608 | } |
3614 | 3609 | ||
3615 | void ZSafe::slotRaiseTimer() | 3610 | void ZSafe::slotRaiseTimer() |
3616 | { | 3611 | { |
3617 | if (infoForm->isVisible()) | 3612 | if (infoForm->isVisible()) |
3618 | infoForm->raise(); | 3613 | infoForm->raise(); |
3619 | raiseFlag = true; | 3614 | raiseFlag = true; |
3620 | } | 3615 | } |
3621 | 3616 | ||
3622 | QPixmap * ZSafe::getPredefinedIcon(QString category) | 3617 | QPixmap * ZSafe::getPredefinedIcon(QString category) |
3623 | { | 3618 | { |
3624 | QPixmap *pm; | 3619 | QPixmap *pm; |
3625 | if (category == "Bank cards") | 3620 | if (category == "Bank cards") |
3626 | pm = new QPixmap((const char**)bank_cards_data); | 3621 | pm = new QPixmap((const char**)bank_cards_data); |
3627 | else if (category == "Passwords") | 3622 | else if (category == "Passwords") |
3628 | pm = new QPixmap((const char**)passwords_data); | 3623 | pm = new QPixmap((const char**)passwords_data); |
3629 | else if (category == "Software") | 3624 | else if (category == "Software") |
3630 | pm = new QPixmap((const char**)software_data); | 3625 | pm = new QPixmap((const char**)software_data); |
3631 | else if (category == "General") | 3626 | else if (category == "General") |
3632 | pm = new QPixmap((const char**)general_data); | 3627 | pm = new QPixmap((const char**)general_data); |
3633 | else | 3628 | else |
3634 | pm = new QPixmap((const char**)general_data); | 3629 | pm = new QPixmap((const char**)general_data); |
3635 | return pm; | 3630 | return pm; |
3636 | } | 3631 | } |
3637 | 3632 | ||
3638 | void ZSafe::setDocument(const QString& fileref) | 3633 | void ZSafe::setDocument(const QString& fileref) |
3639 | { | 3634 | { |
3640 | #ifndef DESKTOP | 3635 | #ifndef DESKTOP |
3641 | // stop the timer to prevent loading of the default document | 3636 | // stop the timer to prevent loading of the default document |
3642 | docuTimer.stop(); | 3637 | docuTimer.stop(); |
3643 | 3638 | ||
3644 | DocLnk link(fileref); | 3639 | DocLnk link(fileref); |
3645 | if ( link.isValid() ) | 3640 | if ( link.isValid() ) |
3646 | { | 3641 | { |
3647 | // if (filename != link.file()) | 3642 | // if (filename != link.file()) |
3648 | // saveDocument(filename, FALSE); | 3643 | // saveDocument(filename, FALSE); |
3649 | filename = link.file(); | 3644 | filename = link.file(); |
3650 | } | 3645 | } |
3651 | else | 3646 | else |
3652 | { | 3647 | { |
3653 | // if (filename != fileref) | 3648 | // if (filename != fileref) |
3654 | // saveDocument(filename, FALSE); | 3649 | // saveDocument(filename, FALSE); |
3655 | filename = fileref; | 3650 | filename = fileref; |
3656 | } | 3651 | } |
3657 | // save the current filename to the config file | 3652 | // save the current filename to the config file |
3658 | conf->writeEntry(APP_KEY+"document", filename); | 3653 | conf->writeEntry(APP_KEY+"document", filename); |
3659 | saveConf(); | 3654 | saveConf(); |
3660 | QString ti = filename.right (filename.length() - filename.findRev ('/') - 1); | 3655 | QString ti = filename.right (filename.length() - filename.findRev ('/') - 1); |
diff --git a/noncore/comm/keypebble/krfbdecoder.cpp b/noncore/comm/keypebble/krfbdecoder.cpp index d61433f..837fcc5 100644 --- a/noncore/comm/keypebble/krfbdecoder.cpp +++ b/noncore/comm/keypebble/krfbdecoder.cpp | |||
@@ -1,835 +1,831 @@ | |||
1 | #include "krfbconnection.h" | 1 | #include "krfbconnection.h" |
2 | #include "krfbserverinfo.h" | 2 | #include "krfbserverinfo.h" |
3 | #include "krfbdecoder.h" | 3 | #include "krfbdecoder.h" |
4 | #include "krfbbuffer.h" | 4 | #include "krfbbuffer.h" |
5 | 5 | ||
6 | /* OPIE */ | 6 | /* OPIE */ |
7 | #include <opie2/odebug.h> | 7 | #include <opie2/odebug.h> |
8 | using namespace Opie::Core; | 8 | using namespace Opie::Core; |
9 | 9 | ||
10 | /* QT */ | 10 | /* QT */ |
11 | #include <qpixmap.h> | 11 | #include <qpixmap.h> |
12 | 12 | ||
13 | /* STD */ | 13 | /* STD */ |
14 | #include <assert.h> | 14 | #include <assert.h> |
15 | 15 | ||
16 | // | 16 | // |
17 | // Endian stuff | 17 | // Endian stuff |
18 | // | 18 | // |
19 | //#ifndef OPIE_NO_DEBUG | 19 | //#ifndef OPIE_NO_DEBUG |
20 | const int endianTest = 1; | 20 | const int endianTest = 1; |
21 | //#endif | 21 | //#endif |
22 | 22 | ||
23 | #define Swap16IfLE(s) \ | 23 | #define Swap16IfLE(s) \ |
24 | (*(char *)&endianTest ? ((((s) & 0xff) << 8) | (((s) >> 8) & 0xff)) : (s)) | 24 | (*(char *)&endianTest ? ((((s) & 0xff) << 8) | (((s) >> 8) & 0xff)) : (s)) |
25 | 25 | ||
26 | #define Swap32IfLE(l) \ | 26 | #define Swap32IfLE(l) \ |
27 | (*(char *)&endianTest ? ((((l) & 0xff000000) >> 24) | \ | 27 | (*(char *)&endianTest ? ((((l) & 0xff000000) >> 24) | \ |
28 | (((l) & 0x00ff0000) >> 8) | \ | 28 | (((l) & 0x00ff0000) >> 8) | \ |
29 | (((l) & 0x0000ff00) << 8) | \ | 29 | (((l) & 0x0000ff00) << 8) | \ |
30 | (((l) & 0x000000ff) << 24)) : (l)) | 30 | (((l) & 0x000000ff) << 24)) : (l)) |
31 | 31 | ||
32 | // | 32 | // |
33 | // The lengths of the messages we need to wait for | 33 | // The lengths of the messages we need to wait for |
34 | // | 34 | // |
35 | const int ServerInitLength = 24; | 35 | const int ServerInitLength = 24; |
36 | const int UpdateHeaderLength = 4; | 36 | const int UpdateHeaderLength = 4; |
37 | const int RectHeaderLength = 12; | 37 | const int RectHeaderLength = 12; |
38 | const int RectChunkSize = 4; | 38 | const int RectChunkSize = 4; |
39 | const int CopyRectPosLength = 4; | 39 | const int CopyRectPosLength = 4; |
40 | const int ServerCutLenLength = 7; | 40 | const int ServerCutLenLength = 7; |
41 | 41 | ||
42 | // | 42 | // |
43 | // Client -> Server Message Identifiers | 43 | // Client -> Server Message Identifiers |
44 | // | 44 | // |
45 | static CARD8 SetPixelFormatId = 0; | 45 | static CARD8 SetPixelFormatId = 0; |
46 | //static CARD8 FixColourMapEntriesId = 1; // Not used | 46 | //static CARD8 FixColourMapEntriesId = 1; // Not used |
47 | static CARD8 SetEncodingsId = 2; | 47 | static CARD8 SetEncodingsId = 2; |
48 | static CARD8 UpdateRequestId = 3; | 48 | static CARD8 UpdateRequestId = 3; |
49 | static CARD8 KeyEventId = 4; | 49 | static CARD8 KeyEventId = 4; |
50 | static CARD8 PointerEventId = 5; | 50 | static CARD8 PointerEventId = 5; |
51 | static CARD8 ClientCutTextId = 6; | 51 | static CARD8 ClientCutTextId = 6; |
52 | 52 | ||
53 | // | 53 | // |
54 | // Server -> Client Message Identifiers | 54 | // Server -> Client Message Identifiers |
55 | // | 55 | // |
56 | static CARD8 UpdateId = 0; | 56 | static CARD8 UpdateId = 0; |
57 | static CARD8 BellId = 2; | 57 | static CARD8 BellId = 2; |
58 | static CARD8 ServerCutId = 3; | 58 | static CARD8 ServerCutId = 3; |
59 | 59 | ||
60 | // | 60 | // |
61 | // Encoding identifiers | 61 | // Encoding identifiers |
62 | // | 62 | // |
63 | static CARD32 RawEncoding = Swap32IfLE( 0 ); | 63 | static CARD32 RawEncoding = Swap32IfLE( 0 ); |
64 | static CARD32 CopyRectEncoding = Swap32IfLE(1 ); | 64 | static CARD32 CopyRectEncoding = Swap32IfLE(1 ); |
65 | static CARD32 RreEncoding = Swap32IfLE( 2 ); | 65 | static CARD32 RreEncoding = Swap32IfLE( 2 ); |
66 | static CARD32 CorreEncoding = Swap32IfLE( 4 ); | 66 | static CARD32 CorreEncoding = Swap32IfLE( 4 ); |
67 | static CARD32 HexTileEncoding = Swap32IfLE( 5 ); | 67 | static CARD32 HexTileEncoding = Swap32IfLE( 5 ); |
68 | 68 | ||
69 | static struct { | 69 | static struct { |
70 | int keysym; | 70 | int keysym; |
71 | int keycode; | 71 | int keycode; |
72 | } keyMap[] = { | 72 | } keyMap[] = { |
73 | { 0xff08, Qt::Key_Backspace }, | 73 | { 0xff08, Qt::Key_Backspace }, |
74 | { 0xff09, Qt::Key_Tab }, | 74 | { 0xff09, Qt::Key_Tab }, |
75 | { 0xff0d, Qt::Key_Return }, | 75 | { 0xff0d, Qt::Key_Return }, |
76 | { 0xff1b, Qt::Key_Escape }, | 76 | { 0xff1b, Qt::Key_Escape }, |
77 | { 0xff63, Qt::Key_Insert }, | 77 | { 0xff63, Qt::Key_Insert }, |
78 | { 0xffff, Qt::Key_Delete }, | 78 | { 0xffff, Qt::Key_Delete }, |
79 | { 0xff50, Qt::Key_Home }, | 79 | { 0xff50, Qt::Key_Home }, |
80 | { 0xff57, Qt::Key_End }, | 80 | { 0xff57, Qt::Key_End }, |
81 | { 0xff55, Qt::Key_Prior }, | 81 | { 0xff55, Qt::Key_Prior }, |
82 | { 0xff56, Qt::Key_Next }, | 82 | { 0xff56, Qt::Key_Next }, |
83 | { 0xff51, Qt::Key_Left }, | 83 | { 0xff51, Qt::Key_Left }, |
84 | { 0xff52, Qt::Key_Up }, | 84 | { 0xff52, Qt::Key_Up }, |
85 | { 0xff53, Qt::Key_Right }, | 85 | { 0xff53, Qt::Key_Right }, |
86 | { 0xff54, Qt::Key_Down }, | 86 | { 0xff54, Qt::Key_Down }, |
87 | { 0xffbe, Qt::Key_F1 }, | 87 | { 0xffbe, Qt::Key_F1 }, |
88 | { 0xffbf, Qt::Key_F2 }, | 88 | { 0xffbf, Qt::Key_F2 }, |
89 | { 0xffc0, Qt::Key_F3 }, | 89 | { 0xffc0, Qt::Key_F3 }, |
90 | { 0xffc1, Qt::Key_F4 }, | 90 | { 0xffc1, Qt::Key_F4 }, |
91 | { 0xffc2, Qt::Key_F5 }, | 91 | { 0xffc2, Qt::Key_F5 }, |
92 | { 0xffc3, Qt::Key_F6 }, | 92 | { 0xffc3, Qt::Key_F6 }, |
93 | { 0xffc4, Qt::Key_F7 }, | 93 | { 0xffc4, Qt::Key_F7 }, |
94 | { 0xffc5, Qt::Key_F8 }, | 94 | { 0xffc5, Qt::Key_F8 }, |
95 | { 0xffc6, Qt::Key_F9 }, | 95 | { 0xffc6, Qt::Key_F9 }, |
96 | { 0xffc7, Qt::Key_F10 }, | 96 | { 0xffc7, Qt::Key_F10 }, |
97 | { 0xffc8, Qt::Key_F11 }, | 97 | { 0xffc8, Qt::Key_F11 }, |
98 | { 0xffc9, Qt::Key_F12 }, | 98 | { 0xffc9, Qt::Key_F12 }, |
99 | { 0xffe1, Qt::Key_Shift }, | 99 | { 0xffe1, Qt::Key_Shift }, |
100 | { 0xffe2, Qt::Key_Shift }, | 100 | { 0xffe2, Qt::Key_Shift }, |
101 | { 0xffe3, Qt::Key_Control }, | 101 | { 0xffe3, Qt::Key_Control }, |
102 | { 0xffe4, Qt::Key_Control }, | 102 | { 0xffe4, Qt::Key_Control }, |
103 | { 0xffe7, Qt::Key_Meta }, | 103 | { 0xffe7, Qt::Key_Meta }, |
104 | { 0xffe8, Qt::Key_Meta }, | 104 | { 0xffe8, Qt::Key_Meta }, |
105 | { 0xffe9, Qt::Key_Alt }, | 105 | { 0xffe9, Qt::Key_Alt }, |
106 | { 0xffea, Qt::Key_Alt }, | 106 | { 0xffea, Qt::Key_Alt }, |
107 | { 0, 0 } | 107 | { 0, 0 } |
108 | }; | 108 | }; |
109 | 109 | ||
110 | 110 | ||
111 | KRFBDecoder::KRFBDecoder( KRFBConnection *con ) | 111 | KRFBDecoder::KRFBDecoder( KRFBConnection *con ) |
112 | : QObject( con, "RFB Decoder" ) | 112 | : QObject( con, "RFB Decoder" ) |
113 | { | 113 | { |
114 | assert( con ); | 114 | assert( con ); |
115 | assert( con->state() == KRFBConnection::Connected ); | 115 | assert( con->state() == KRFBConnection::Connected ); |
116 | 116 | ||
117 | this->con = con; | 117 | this->con = con; |
118 | this->buf = 0; | 118 | this->buf = 0; |
119 | this->info = 0; | 119 | this->info = 0; |
120 | this->format = 0; | 120 | this->format = 0; |
121 | this->buttonMask = 0; | 121 | this->buttonMask = 0; |
122 | currentState = Idle; | 122 | currentState = Idle; |
123 | } | 123 | } |
124 | 124 | ||
125 | KRFBDecoder::~KRFBDecoder() | 125 | KRFBDecoder::~KRFBDecoder() |
126 | { | 126 | { |
127 | if ( info ) | 127 | if ( info ) |
128 | delete info; | 128 | delete info; |
129 | if ( format ) | 129 | if ( format ) |
130 | delete format; | 130 | delete format; |
131 | } | 131 | } |
132 | 132 | ||
133 | void KRFBDecoder::start() | 133 | void KRFBDecoder::start() |
134 | { | 134 | { |
135 | sendClientInit(); | 135 | sendClientInit(); |
136 | } | 136 | } |
137 | 137 | ||
138 | void KRFBDecoder::sendClientInit() | 138 | void KRFBDecoder::sendClientInit() |
139 | { | 139 | { |
140 | con->write( &( con->options()->shared ), 1 ); | 140 | con->write( &( con->options()->shared ), 1 ); |
141 | 141 | ||
142 | // Wait for server init | 142 | // Wait for server init |
143 | owarn << "Waiting for server init" << oendl; | 143 | owarn << "Waiting for server init" << oendl; |
144 | 144 | ||
145 | static QString statusMsg = tr( "Waiting for server initialization..." ); | 145 | static QString statusMsg = tr( "Waiting for server initialization..." ); |
146 | emit status( statusMsg ); | 146 | emit status( statusMsg ); |
147 | 147 | ||
148 | currentState = AwaitingServerInit; | 148 | currentState = AwaitingServerInit; |
149 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotServerInit() ) ); | 149 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotServerInit() ) ); |
150 | con->waitForData( ServerInitLength ); | 150 | con->waitForData( ServerInitLength ); |
151 | } | 151 | } |
152 | 152 | ||
153 | void KRFBDecoder::gotServerInit() | 153 | void KRFBDecoder::gotServerInit() |
154 | { | 154 | { |
155 | owarn << "Got server init" << oendl; | 155 | owarn << "Got server init" << oendl; |
156 | disconnect( con, SIGNAL( gotEnoughData() ), this, SLOT( gotServerInit() ) ); | 156 | disconnect( con, SIGNAL( gotEnoughData() ), this, SLOT( gotServerInit() ) ); |
157 | 157 | ||
158 | if ( info ) | 158 | if ( info ) |
159 | delete info; | 159 | delete info; |
160 | info = new KRFBServerInfo; | 160 | info = new KRFBServerInfo; |
161 | CHECK_PTR( info ); | 161 | CHECK_PTR( info ); |
162 | 162 | ||
163 | con->read( &(info->width), 2 ); | 163 | con->read( &(info->width), 2 ); |
164 | info->width = Swap16IfLE( info->width ); | 164 | info->width = Swap16IfLE( info->width ); |
165 | con->read( &info->height, 2 ); | 165 | con->read( &info->height, 2 ); |
166 | info->height = Swap16IfLE( info->height ); | 166 | info->height = Swap16IfLE( info->height ); |
167 | 167 | ||
168 | con->read( &(info->bpp), 1 ); | 168 | con->read( &(info->bpp), 1 ); |
169 | con->read( &(info->depth), 1 ); | 169 | con->read( &(info->depth), 1 ); |
170 | con->read( &(info->bigEndian), 1 ); | 170 | con->read( &(info->bigEndian), 1 ); |
171 | con->read( &(info->trueColor), 1 ); | 171 | con->read( &(info->trueColor), 1 ); |
172 | 172 | ||
173 | con->read( &(info->redMax), 2 ); | 173 | con->read( &(info->redMax), 2 ); |
174 | info->redMax = Swap16IfLE( info->redMax ); | 174 | info->redMax = Swap16IfLE( info->redMax ); |
175 | con->read( &(info->greenMax), 2 ); | 175 | con->read( &(info->greenMax), 2 ); |
176 | info->greenMax = Swap16IfLE( info->greenMax ); | 176 | info->greenMax = Swap16IfLE( info->greenMax ); |
177 | con->read( &(info->blueMax), 2 ); | 177 | con->read( &(info->blueMax), 2 ); |
178 | info->blueMax = Swap16IfLE( info->blueMax ); | 178 | info->blueMax = Swap16IfLE( info->blueMax ); |
179 | 179 | ||
180 | con->read( &(info->redShift), 1 ); | 180 | con->read( &(info->redShift), 1 ); |
181 | con->read( &(info->greenShift), 1 ); | 181 | con->read( &(info->greenShift), 1 ); |
182 | con->read( &(info->blueShift), 1 ); | 182 | con->read( &(info->blueShift), 1 ); |
183 | 183 | ||
184 | con->read( info->padding, 3 ); | 184 | con->read( info->padding, 3 ); |
185 | 185 | ||
186 | con->read( &(info->nameLength), 4 ); | 186 | con->read( &(info->nameLength), 4 ); |
187 | info->nameLength = Swap32IfLE( info->nameLength ); | 187 | info->nameLength = Swap32IfLE( info->nameLength ); |
188 | 188 | ||
189 | owarn << "Width = " << info->width << ", Height = " << info->height << "" << oendl; | 189 | owarn << "Width = " << info->width << ", Height = " << info->height << "" << oendl; |
190 | qWarning( "Bpp = %d, Depth = %d, Big = %d, True = %d", | 190 | owarn << "Bpp = " << info->bpp << ", Depth = " << info->depth << ", Big = " << info->bigEndian |
191 | info->bpp, info->depth, info->bigEndian, info->trueColor ); | 191 | << ", True = " << info->trueColor << oendl; |
192 | qWarning( "RedMax = %d, GreenMax = %d, BlueMax = %d", | 192 | owarn << "RedMax = " << info->redMax << ", GreenMax = " << info->greenMax << ", BlueMax = " << info->blueMax << oendl; |
193 | info->redMax, info->greenMax, info->blueMax ); | 193 | owarn << "RedShift = " << info->redShift << ", GreenShift = " << info->greenShift |
194 | qWarning( "RedShift = %d, GreenShift = %d, BlueShift = %d", | 194 | << ", BlueShift = " << info-> blueShift << oendl; |
195 | info->redShift, info->greenShift,info-> blueShift ); | ||
196 | 195 | ||
197 | buf->resize( info->width/con->options()->scaleFactor, info->height /con->options()->scaleFactor); | 196 | buf->resize( info->width/con->options()->scaleFactor, info->height /con->options()->scaleFactor); |
198 | 197 | ||
199 | // Wait for desktop name | 198 | // Wait for desktop name |
200 | owarn << "Waiting for desktop name" << oendl; | 199 | owarn << "Waiting for desktop name" << oendl; |
201 | 200 | ||
202 | static QString statusMsg = tr( "Waiting for desktop name..." ); | 201 | static QString statusMsg = tr( "Waiting for desktop name..." ); |
203 | emit status( statusMsg ); | 202 | emit status( statusMsg ); |
204 | 203 | ||
205 | currentState = AwaitingDesktopName; | 204 | currentState = AwaitingDesktopName; |
206 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotDesktopName() ) ); | 205 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotDesktopName() ) ); |
207 | con->waitForData( info->nameLength ); | 206 | con->waitForData( info->nameLength ); |
208 | } | 207 | } |
209 | 208 | ||
210 | void KRFBDecoder::gotDesktopName() | 209 | void KRFBDecoder::gotDesktopName() |
211 | { | 210 | { |
212 | assert( info ); | 211 | assert( info ); |
213 | assert( currentState == AwaitingDesktopName ); | 212 | assert( currentState == AwaitingDesktopName ); |
214 | 213 | ||
215 | owarn << "Got desktop name" << oendl; | 214 | owarn << "Got desktop name" << oendl; |
216 | 215 | ||
217 | disconnect( con, SIGNAL( gotEnoughData() ), | 216 | disconnect( con, SIGNAL( gotEnoughData() ), |
218 | this, SLOT( gotDesktopName() ) ); | 217 | this, SLOT( gotDesktopName() ) ); |
219 | 218 | ||
220 | char *buf = new char[ info->nameLength + 1 ]; | 219 | char *buf = new char[ info->nameLength + 1 ]; |
221 | CHECK_PTR( buf ); | 220 | CHECK_PTR( buf ); |
222 | 221 | ||
223 | con->read( buf, info->nameLength ); | 222 | con->read( buf, info->nameLength ); |
224 | buf[ info->nameLength ] = '\0'; | 223 | buf[ info->nameLength ] = '\0'; |
225 | info->name = buf; | 224 | info->name = buf; |
226 | 225 | ||
227 | owarn << "Desktop: " << info->name.latin1() << "" << oendl; | 226 | owarn << "Desktop: " << info->name.latin1() << "" << oendl; |
228 | 227 | ||
229 | delete buf; | 228 | delete buf; |
230 | 229 | ||
231 | // Get the format we'll really use and tell the server | 230 | // Get the format we'll really use and tell the server |
232 | decidePixelFormat(); | 231 | decidePixelFormat(); |
233 | sendPixelFormat(); | 232 | sendPixelFormat(); |
234 | sendAllowedEncodings(); | 233 | sendAllowedEncodings(); |
235 | currentState = Idle; | 234 | currentState = Idle; |
236 | 235 | ||
237 | QString msg; | 236 | QString msg; |
238 | msg = tr( "Connected to %1" ); | 237 | msg = tr( "Connected to %1" ); |
239 | msg = msg.arg( info->name ); | 238 | msg = msg.arg( info->name ); |
240 | emit status( msg ); | 239 | emit status( msg ); |
241 | 240 | ||
242 | sendUpdateRequest( false ); | 241 | sendUpdateRequest( false ); |
243 | } | 242 | } |
244 | 243 | ||
245 | void KRFBDecoder::decidePixelFormat() | 244 | void KRFBDecoder::decidePixelFormat() |
246 | { | 245 | { |
247 | assert( info ); | 246 | assert( info ); |
248 | 247 | ||
249 | if ( format ) | 248 | if ( format ) |
250 | delete format; | 249 | delete format; |
251 | format = new KRFBPixelFormat; | 250 | format = new KRFBPixelFormat; |
252 | CHECK_PTR( format ); | 251 | CHECK_PTR( format ); |
253 | 252 | ||
254 | // What depth do we want? | 253 | // What depth do we want? |
255 | // | 254 | // |
256 | // We'll use the minimum of the remote and local depths, UNLESS an | 255 | // We'll use the minimum of the remote and local depths, UNLESS an |
257 | // eight bit session has been specifically requested by the user. | 256 | // eight bit session has been specifically requested by the user. |
258 | int screenDepth = QPixmap::defaultDepth(); | 257 | int screenDepth = QPixmap::defaultDepth(); |
259 | int bestDepth = ( screenDepth > info->depth ) ? info->depth : screenDepth; | 258 | int bestDepth = ( screenDepth > info->depth ) ? info->depth : screenDepth; |
260 | int chosenDepth; | 259 | int chosenDepth; |
261 | 260 | ||
262 | if ( con->options()->colors256 ) | 261 | if ( con->options()->colors256 ) |
263 | chosenDepth = 8; | 262 | chosenDepth = 8; |
264 | else | 263 | else |
265 | chosenDepth = bestDepth; | 264 | chosenDepth = bestDepth; |
266 | 265 | ||
267 | qWarning( "Screen depth=%d, server depth=%d, best depth=%d, " \ | 266 | owarn << "Screen depth=" << screenDepth << ", server depth=" << info->depth |
268 | "eight bit %d, chosenDepth=%d", | 267 | << ", best depth=" << bestDepth << "eight bit " << con->options()->colors256 |
269 | screenDepth, | 268 | << ", chosenDepth=" << chosenDepth << oendl; |
270 | info->depth, | ||
271 | bestDepth, | ||
272 | con->options()->colors256, chosenDepth ); | ||
273 | 269 | ||
274 | format->depth = chosenDepth; | 270 | format->depth = chosenDepth; |
275 | 271 | ||
276 | // If we're using the servers native depth | 272 | // If we're using the servers native depth |
277 | if ( chosenDepth == info->depth ) { | 273 | if ( chosenDepth == info->depth ) { |
278 | // Use the servers native format | 274 | // Use the servers native format |
279 | format->bpp = info->bpp; | 275 | format->bpp = info->bpp; |
280 | // format->bigEndian = info->bigEndian; | 276 | // format->bigEndian = info->bigEndian; |
281 | format->bigEndian = true; | 277 | format->bigEndian = true; |
282 | format->trueColor = info->trueColor; | 278 | format->trueColor = info->trueColor; |
283 | format->redMax = info->redMax; | 279 | format->redMax = info->redMax; |
284 | format->greenMax = info->greenMax; | 280 | format->greenMax = info->greenMax; |
285 | format->blueMax = info->blueMax; | 281 | format->blueMax = info->blueMax; |
286 | format->redShift = info->redShift; | 282 | format->redShift = info->redShift; |
287 | format->greenShift = info->greenShift; | 283 | format->greenShift = info->greenShift; |
288 | format->blueShift = info->blueShift; | 284 | format->blueShift = info->blueShift; |
289 | } | 285 | } |
290 | else { | 286 | else { |
291 | if ( chosenDepth == 8 ) { | 287 | if ( chosenDepth == 8 ) { |
292 | format->bpp = 8; | 288 | format->bpp = 8; |
293 | format->bigEndian = true; | 289 | format->bigEndian = true; |
294 | format->trueColor = true; | 290 | format->trueColor = true; |
295 | format->redMax = 7; | 291 | format->redMax = 7; |
296 | format->greenMax = 7; | 292 | format->greenMax = 7; |
297 | format->blueMax = 3; | 293 | format->blueMax = 3; |
298 | format->redShift = 0; | 294 | format->redShift = 0; |
299 | format->greenShift = 3; | 295 | format->greenShift = 3; |
300 | format->blueShift = 6; | 296 | format->blueShift = 6; |
301 | } | 297 | } |
302 | } | 298 | } |
303 | 299 | ||
304 | format->redMax = Swap16IfLE( format->redMax ); | 300 | format->redMax = Swap16IfLE( format->redMax ); |
305 | format->greenMax = Swap16IfLE( format->greenMax ); | 301 | format->greenMax = Swap16IfLE( format->greenMax ); |
306 | format->blueMax = Swap16IfLE( format->blueMax ); | 302 | format->blueMax = Swap16IfLE( format->blueMax ); |
307 | } | 303 | } |
308 | 304 | ||
309 | void KRFBDecoder::sendPixelFormat() | 305 | void KRFBDecoder::sendPixelFormat() |
310 | { | 306 | { |
311 | static char padding[3]; | 307 | static char padding[3]; |
312 | con->write( &SetPixelFormatId, 1 ); | 308 | con->write( &SetPixelFormatId, 1 ); |
313 | con->write( padding, 3 ); | 309 | con->write( padding, 3 ); |
314 | 310 | ||
315 | con->write( &(format->bpp), 1 ); | 311 | con->write( &(format->bpp), 1 ); |
316 | con->write( &(format->depth), 1 ); | 312 | con->write( &(format->depth), 1 ); |
317 | con->write( &(format->bigEndian), 1 ); | 313 | con->write( &(format->bigEndian), 1 ); |
318 | con->write( &(format->trueColor), 1 ); | 314 | con->write( &(format->trueColor), 1 ); |
319 | 315 | ||
320 | con->write( &(format->redMax), 2 ); | 316 | con->write( &(format->redMax), 2 ); |
321 | con->write( &(format->greenMax), 2 ); | 317 | con->write( &(format->greenMax), 2 ); |
322 | con->write( &(format->blueMax), 2 ); | 318 | con->write( &(format->blueMax), 2 ); |
323 | 319 | ||
324 | con->write( &(format->redShift), 1 ); | 320 | con->write( &(format->redShift), 1 ); |
325 | con->write( &(format->greenShift), 1 ); | 321 | con->write( &(format->greenShift), 1 ); |
326 | con->write( &(format->blueShift), 1 ); | 322 | con->write( &(format->blueShift), 1 ); |
327 | con->write( format->padding, 3 ); // Padding | 323 | con->write( format->padding, 3 ); // Padding |
328 | } | 324 | } |
329 | 325 | ||
330 | void KRFBDecoder::sendAllowedEncodings() | 326 | void KRFBDecoder::sendAllowedEncodings() |
331 | { | 327 | { |
332 | static CARD8 padding[1]; | 328 | static CARD8 padding[1]; |
333 | con->write( &SetEncodingsId, 1 ); | 329 | con->write( &SetEncodingsId, 1 ); |
334 | con->write( padding, 1 ); | 330 | con->write( padding, 1 ); |
335 | 331 | ||
336 | CARD16 noEncodings = con->options()->encodings(); | 332 | CARD16 noEncodings = con->options()->encodings(); |
337 | noEncodings = Swap16IfLE( noEncodings ); | 333 | noEncodings = Swap16IfLE( noEncodings ); |
338 | con->write( &noEncodings, 2 ); | 334 | con->write( &noEncodings, 2 ); |
339 | 335 | ||
340 | if ( con->options()->corre ) | 336 | if ( con->options()->corre ) |
341 | con->write( &CorreEncoding, 4 ); | 337 | con->write( &CorreEncoding, 4 ); |
342 | if ( con->options()->hexTile ) | 338 | if ( con->options()->hexTile ) |
343 | con->write( &HexTileEncoding, 4 ); | 339 | con->write( &HexTileEncoding, 4 ); |
344 | if ( con->options()->rre ) | 340 | if ( con->options()->rre ) |
345 | con->write( &RreEncoding, 4 ); | 341 | con->write( &RreEncoding, 4 ); |
346 | if ( con->options()->copyrect ) | 342 | if ( con->options()->copyrect ) |
347 | con->write( &CopyRectEncoding, 4 ); | 343 | con->write( &CopyRectEncoding, 4 ); |
348 | // We always support this | 344 | // We always support this |
349 | con->write( &RawEncoding, 4 ); | 345 | con->write( &RawEncoding, 4 ); |
350 | } | 346 | } |
351 | 347 | ||
352 | void KRFBDecoder::sendUpdateRequest( bool incremental ) | 348 | void KRFBDecoder::sendUpdateRequest( bool incremental ) |
353 | { | 349 | { |
354 | if ( currentState != Idle ) | 350 | if ( currentState != Idle ) |
355 | return; | 351 | return; |
356 | 352 | ||
357 | con->write( &UpdateRequestId, 1 ); | 353 | con->write( &UpdateRequestId, 1 ); |
358 | con->write( &incremental, 1 ); | 354 | con->write( &incremental, 1 ); |
359 | 355 | ||
360 | static CARD16 x = 0, y = 0; | 356 | static CARD16 x = 0, y = 0; |
361 | static CARD16 w = Swap16IfLE( info->width ); | 357 | static CARD16 w = Swap16IfLE( info->width ); |
362 | static CARD16 h = Swap16IfLE( info->height ); | 358 | static CARD16 h = Swap16IfLE( info->height ); |
363 | 359 | ||
364 | con->write( &x, 2 ); | 360 | con->write( &x, 2 ); |
365 | con->write( &y, 2 ); | 361 | con->write( &y, 2 ); |
366 | con->write( &w, 2 ); | 362 | con->write( &w, 2 ); |
367 | con->write( &h, 2 ); | 363 | con->write( &h, 2 ); |
368 | 364 | ||
369 | // Now wait for the update | 365 | // Now wait for the update |
370 | currentState = AwaitingUpdate; | 366 | currentState = AwaitingUpdate; |
371 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotUpdateHeader() ) ); | 367 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotUpdateHeader() ) ); |
372 | con->waitForData( UpdateHeaderLength ); | 368 | con->waitForData( UpdateHeaderLength ); |
373 | } | 369 | } |
374 | 370 | ||
375 | void KRFBDecoder::gotUpdateHeader() | 371 | void KRFBDecoder::gotUpdateHeader() |
376 | { | 372 | { |
377 | assert( currentState == AwaitingUpdate ); | 373 | assert( currentState == AwaitingUpdate ); |
378 | 374 | ||
379 | // owarn << "Got update header" << oendl; | 375 | // owarn << "Got update header" << oendl; |
380 | 376 | ||
381 | disconnect( con, SIGNAL( gotEnoughData() ), | 377 | disconnect( con, SIGNAL( gotEnoughData() ), |
382 | this, SLOT( gotUpdateHeader() ) ); | 378 | this, SLOT( gotUpdateHeader() ) ); |
383 | 379 | ||
384 | CARD8 msgType; | 380 | CARD8 msgType; |
385 | con->read( &msgType, 1 ); | 381 | con->read( &msgType, 1 ); |
386 | 382 | ||
387 | if ( msgType != UpdateId ) { | 383 | if ( msgType != UpdateId ) { |
388 | // We might have a bell or server cut | 384 | // We might have a bell or server cut |
389 | if ( msgType == ServerCutId ) { | 385 | if ( msgType == ServerCutId ) { |
390 | oldState = currentState; | 386 | oldState = currentState; |
391 | gotServerCut(); | 387 | gotServerCut(); |
392 | } | 388 | } |
393 | else if ( msgType == BellId ) { | 389 | else if ( msgType == BellId ) { |
394 | oldState = currentState; | 390 | oldState = currentState; |
395 | gotBell(); | 391 | gotBell(); |
396 | } | 392 | } |
397 | else { | 393 | else { |
398 | int msg = msgType; | 394 | int msg = msgType; |
399 | QString protocolError = tr( "Protocol Error: Message Id %1 was " | 395 | QString protocolError = tr( "Protocol Error: Message Id %1 was " |
400 | "found when expecting an update " | 396 | "found when expecting an update " |
401 | "message." ).arg( msg ); | 397 | "message." ).arg( msg ); |
402 | currentState = Error; | 398 | currentState = Error; |
403 | emit error( protocolError ); | 399 | emit error( protocolError ); |
404 | } | 400 | } |
405 | return; | 401 | return; |
406 | } | 402 | } |
407 | 403 | ||
408 | CARD8 padding; | 404 | CARD8 padding; |
409 | con->read( &padding, 1 ); | 405 | con->read( &padding, 1 ); |
410 | 406 | ||
411 | con->read( &noRects, 2 ); | 407 | con->read( &noRects, 2 ); |
412 | noRects = Swap16IfLE( noRects ); | 408 | noRects = Swap16IfLE( noRects ); |
413 | 409 | ||
414 | // owarn << "Expecting " << noRects << " rects" << oendl; | 410 | // owarn << "Expecting " << noRects << " rects" << oendl; |
415 | 411 | ||
416 | // Now wait for the data | 412 | // Now wait for the data |
417 | currentState = AwaitingRectHeader; | 413 | currentState = AwaitingRectHeader; |
418 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotRectHeader() ) ); | 414 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotRectHeader() ) ); |
419 | con->waitForData( RectHeaderLength ); | 415 | con->waitForData( RectHeaderLength ); |
420 | } | 416 | } |
421 | 417 | ||
422 | void KRFBDecoder::gotRectHeader() | 418 | void KRFBDecoder::gotRectHeader() |
423 | { | 419 | { |
424 | assert( currentState == AwaitingRectHeader ); | 420 | assert( currentState == AwaitingRectHeader ); |
425 | 421 | ||
426 | // owarn << "Got rect header" << oendl; | 422 | // owarn << "Got rect header" << oendl; |
427 | 423 | ||
428 | disconnect( con, SIGNAL( gotEnoughData() ), | 424 | disconnect( con, SIGNAL( gotEnoughData() ), |
429 | this, SLOT( gotRectHeader() ) ); | 425 | this, SLOT( gotRectHeader() ) ); |
430 | 426 | ||
431 | con->read( &x, 2 ); | 427 | con->read( &x, 2 ); |
432 | x = Swap16IfLE( x ); | 428 | x = Swap16IfLE( x ); |
433 | con->read( &y, 2 ); | 429 | con->read( &y, 2 ); |
434 | y = Swap16IfLE( y ); | 430 | y = Swap16IfLE( y ); |
435 | 431 | ||
436 | con->read( &w, 2 ); | 432 | con->read( &w, 2 ); |
437 | w = Swap16IfLE( w ); | 433 | w = Swap16IfLE( w ); |
438 | con->read( &h, 2 ); | 434 | con->read( &h, 2 ); |
439 | h = Swap16IfLE( h ); | 435 | h = Swap16IfLE( h ); |
440 | 436 | ||
441 | con->read( &encoding, 4 ); | 437 | con->read( &encoding, 4 ); |
442 | 438 | ||
443 | // CARD32 encodingLocal = Swap32IfLE( encoding ); | 439 | // CARD32 encodingLocal = Swap32IfLE( encoding ); |
444 | // qWarning( "Rect: x=%d, y= %d, w=%d, h=%d, encoding=%ld", | 440 | // owarn << "Rect: x=" << x << ", y= " << y << ", w=" << w << ", h=" << h |
445 | // x, y, w, h, encodingLocal ); | 441 | // << ", encoding= " << encodingLocal << oendl; |
446 | 442 | ||
447 | // | 443 | // |
448 | // Each encoding needs to be handled differently. Some require | 444 | // Each encoding needs to be handled differently. Some require |
449 | // waiting for more data, but others like a copyrect do not. | 445 | // waiting for more data, but others like a copyrect do not. |
450 | // Our constants have already been byte swapped, so we use | 446 | // Our constants have already been byte swapped, so we use |
451 | // the remote value as is. | 447 | // the remote value as is. |
452 | // | 448 | // |
453 | if ( encoding == RawEncoding ) { | 449 | if ( encoding == RawEncoding ) { |
454 | // owarn << "Raw encoding" << oendl; | 450 | // owarn << "Raw encoding" << oendl; |
455 | handleRawRect(); | 451 | handleRawRect(); |
456 | } | 452 | } |
457 | else if ( encoding == CopyRectEncoding ) { | 453 | else if ( encoding == CopyRectEncoding ) { |
458 | // owarn << "CopyRect encoding" << oendl; | 454 | // owarn << "CopyRect encoding" << oendl; |
459 | handleCopyRect(); | 455 | handleCopyRect(); |
460 | } | 456 | } |
461 | else if ( encoding == RreEncoding ) { | 457 | else if ( encoding == RreEncoding ) { |
462 | owarn << "RRE encoding" << oendl; | 458 | owarn << "RRE encoding" << oendl; |
463 | handleRRERect(); | 459 | handleRRERect(); |
464 | } | 460 | } |
465 | else if ( encoding == CorreEncoding ) { | 461 | else if ( encoding == CorreEncoding ) { |
466 | owarn << "CoRRE encoding" << oendl; | 462 | owarn << "CoRRE encoding" << oendl; |
467 | handleCoRRERect(); | 463 | handleCoRRERect(); |
468 | } | 464 | } |
469 | else if ( encoding == HexTileEncoding ) { | 465 | else if ( encoding == HexTileEncoding ) { |
470 | owarn << "HexTile encoding" << oendl; | 466 | owarn << "HexTile encoding" << oendl; |
471 | handleHexTileRect(); | 467 | handleHexTileRect(); |
472 | } | 468 | } |
473 | else { | 469 | else { |
474 | int msg = Swap32IfLE( encoding ); | 470 | int msg = Swap32IfLE( encoding ); |
475 | QString protocolError = tr( "Protocol Error: An unknown encoding was " | 471 | QString protocolError = tr( "Protocol Error: An unknown encoding was " |
476 | "used by the server %1" ).arg( msg ); | 472 | "used by the server %1" ).arg( msg ); |
477 | currentState = Error; | 473 | currentState = Error; |
478 | owarn << "Unknown encoding, " << msg << "" << oendl; | 474 | owarn << "Unknown encoding, " << msg << "" << oendl; |
479 | emit error( protocolError ); | 475 | emit error( protocolError ); |
480 | return; | 476 | return; |
481 | } | 477 | } |
482 | } | 478 | } |
483 | 479 | ||
484 | // | 480 | // |
485 | // Raw Encoding | 481 | // Raw Encoding |
486 | // | 482 | // |
487 | 483 | ||
488 | void KRFBDecoder::handleRawRect() | 484 | void KRFBDecoder::handleRawRect() |
489 | { | 485 | { |
490 | // We need something a bit cleverer here to handle large | 486 | // We need something a bit cleverer here to handle large |
491 | // rectanges nicely. The chunking should be based on the | 487 | // rectanges nicely. The chunking should be based on the |
492 | // overall size (but has to be in complete lines). | 488 | // overall size (but has to be in complete lines). |
493 | 489 | ||
494 | // owarn << "Handling a raw rect chunk" << oendl; | 490 | // owarn << "Handling a raw rect chunk" << oendl; |
495 | 491 | ||
496 | // CARD32 lineCount = w * format->bpp / 8; | 492 | // CARD32 lineCount = w * format->bpp / 8; |
497 | 493 | ||
498 | if ( h > RectChunkSize ) { | 494 | if ( h > RectChunkSize ) { |
499 | // if ( con->sock->size() / lineCount ) { | 495 | // if ( con->sock->size() / lineCount ) { |
500 | // getRawRectChunk( con->sock->size() / lineCount ); | 496 | // getRawRectChunk( con->sock->size() / lineCount ); |
501 | // } | 497 | // } |
502 | // else { | 498 | // else { |
503 | getRawRectChunk( RectChunkSize ); | 499 | getRawRectChunk( RectChunkSize ); |
504 | // } | 500 | // } |
505 | } | 501 | } |
506 | else { | 502 | else { |
507 | getRawRectChunk( h ); | 503 | getRawRectChunk( h ); |
508 | } | 504 | } |
509 | } | 505 | } |
510 | 506 | ||
511 | void KRFBDecoder::getRawRectChunk( int lines ) | 507 | void KRFBDecoder::getRawRectChunk( int lines ) |
512 | { | 508 | { |
513 | this->lines = lines; | 509 | this->lines = lines; |
514 | CARD32 count = lines * w * format->bpp / 8; | 510 | CARD32 count = lines * w * format->bpp / 8; |
515 | 511 | ||
516 | // Wait for server init | 512 | // Wait for server init |
517 | // owarn << "Waiting for raw rect chunk, " << count << "" << oendl; | 513 | // owarn << "Waiting for raw rect chunk, " << count << "" << oendl; |
518 | 514 | ||
519 | currentState = AwaitingRawRectChunk; | 515 | currentState = AwaitingRawRectChunk; |
520 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotRawRectChunk() ) ); | 516 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotRawRectChunk() ) ); |
521 | con->waitForData( count ); | 517 | con->waitForData( count ); |
522 | } | 518 | } |
523 | 519 | ||
524 | void KRFBDecoder::gotRawRectChunk() | 520 | void KRFBDecoder::gotRawRectChunk() |
525 | { | 521 | { |
526 | assert( currentState == AwaitingRawRectChunk ); | 522 | assert( currentState == AwaitingRawRectChunk ); |
527 | 523 | ||
528 | disconnect( con, SIGNAL( gotEnoughData() ), | 524 | disconnect( con, SIGNAL( gotEnoughData() ), |
529 | this, SLOT( gotRawRectChunk() ) ); | 525 | this, SLOT( gotRawRectChunk() ) ); |
530 | 526 | ||
531 | // owarn << "Got raw rect chunk" << oendl; | 527 | // owarn << "Got raw rect chunk" << oendl; |
532 | 528 | ||
533 | // | 529 | // |
534 | // Read the rect data and copy it to the buffer. | 530 | // Read the rect data and copy it to the buffer. |
535 | // | 531 | // |
536 | 532 | ||
537 | // TODO: Replace this! | 533 | // TODO: Replace this! |
538 | int count = lines * w * format->bpp / 8; | 534 | int count = lines * w * format->bpp / 8; |
539 | char *hack = new char[ count ]; | 535 | char *hack = new char[ count ]; |
540 | con->read( hack, count ); | 536 | con->read( hack, count ); |
541 | buf->drawRawRectChunk( hack, x, y, w, lines ); | 537 | buf->drawRawRectChunk( hack, x, y, w, lines ); |
542 | delete hack; | 538 | delete hack; |
543 | // /TODO: | 539 | // /TODO: |
544 | 540 | ||
545 | h = h - lines; | 541 | h = h - lines; |
546 | y = y + lines; | 542 | y = y + lines; |
547 | 543 | ||
548 | if ( h > 0 ) { | 544 | if ( h > 0 ) { |
549 | handleRawRect(); | 545 | handleRawRect(); |
550 | } | 546 | } |
551 | else { | 547 | else { |
552 | noRects--; | 548 | noRects--; |
553 | 549 | ||
554 | // owarn << "There are " << noRects << " rects left" << oendl; | 550 | // owarn << "There are " << noRects << " rects left" << oendl; |
555 | 551 | ||
556 | if ( noRects ) { | 552 | if ( noRects ) { |
557 | currentState = AwaitingRectHeader; | 553 | currentState = AwaitingRectHeader; |
558 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotRectHeader() ) ); | 554 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotRectHeader() ) ); |
559 | con->waitForData( RectHeaderLength ); | 555 | con->waitForData( RectHeaderLength ); |
560 | } | 556 | } |
561 | else { | 557 | else { |
562 | // we are now ready for the next update - no need to wait for the timer | 558 | // we are now ready for the next update - no need to wait for the timer |
563 | currentState = Idle; | 559 | currentState = Idle; |
564 | sendUpdateRequest (1); | 560 | sendUpdateRequest (1); |
565 | } | 561 | } |
566 | } | 562 | } |
567 | } | 563 | } |
568 | 564 | ||
569 | // | 565 | // |
570 | // Copy Rectangle Encoding | 566 | // Copy Rectangle Encoding |
571 | // | 567 | // |
572 | 568 | ||
573 | void KRFBDecoder::handleCopyRect() | 569 | void KRFBDecoder::handleCopyRect() |
574 | { | 570 | { |
575 | currentState = AwaitingCopyRectPos; | 571 | currentState = AwaitingCopyRectPos; |
576 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotCopyRectPos() ) ); | 572 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotCopyRectPos() ) ); |
577 | con->waitForData( CopyRectPosLength ); | 573 | con->waitForData( CopyRectPosLength ); |
578 | } | 574 | } |
579 | 575 | ||
580 | void KRFBDecoder::gotCopyRectPos() | 576 | void KRFBDecoder::gotCopyRectPos() |
581 | { | 577 | { |
582 | disconnect( con, SIGNAL( gotEnoughData() ), | 578 | disconnect( con, SIGNAL( gotEnoughData() ), |
583 | this, SLOT( gotCopyRectPos() ) ); | 579 | this, SLOT( gotCopyRectPos() ) ); |
584 | 580 | ||
585 | CARD16 srcX; | 581 | CARD16 srcX; |
586 | CARD16 srcY; | 582 | CARD16 srcY; |
587 | 583 | ||
588 | con->read( &srcX, 2 ); | 584 | con->read( &srcX, 2 ); |
589 | con->read( &srcY, 2 ); | 585 | con->read( &srcY, 2 ); |
590 | 586 | ||
591 | srcX = Swap16IfLE( srcX ); | 587 | srcX = Swap16IfLE( srcX ); |
592 | srcY = Swap16IfLE( srcY ); | 588 | srcY = Swap16IfLE( srcY ); |
593 | 589 | ||
594 | buf->copyRect( srcX, srcY, x, y, w, h ); | 590 | buf->copyRect( srcX, srcY, x, y, w, h ); |
595 | 591 | ||
596 | noRects--; | 592 | noRects--; |
597 | 593 | ||
598 | // owarn << "There are " << noRects << " rects left" << oendl; | 594 | // owarn << "There are " << noRects << " rects left" << oendl; |
599 | 595 | ||
600 | if ( noRects ) { | 596 | if ( noRects ) { |
601 | currentState = AwaitingRectHeader; | 597 | currentState = AwaitingRectHeader; |
602 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotRectHeader() ) ); | 598 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotRectHeader() ) ); |
603 | con->waitForData( RectHeaderLength ); | 599 | con->waitForData( RectHeaderLength ); |
604 | } | 600 | } |
605 | else | 601 | else |
606 | currentState = Idle; | 602 | currentState = Idle; |
607 | } | 603 | } |
608 | 604 | ||
609 | void KRFBDecoder::handleRRERect() | 605 | void KRFBDecoder::handleRRERect() |
610 | { | 606 | { |
611 | owarn << "RRE not implemented" << oendl; | 607 | owarn << "RRE not implemented" << oendl; |
612 | } | 608 | } |
613 | 609 | ||
614 | void KRFBDecoder::handleCoRRERect() | 610 | void KRFBDecoder::handleCoRRERect() |
615 | { | 611 | { |
616 | owarn << "CoRRE not implemented" << oendl; | 612 | owarn << "CoRRE not implemented" << oendl; |
617 | } | 613 | } |
618 | 614 | ||
619 | void KRFBDecoder::handleHexTileRect() | 615 | void KRFBDecoder::handleHexTileRect() |
620 | { | 616 | { |
621 | owarn << "HexTile not implemented" << oendl; | 617 | owarn << "HexTile not implemented" << oendl; |
622 | } | 618 | } |
623 | 619 | ||
624 | void KRFBDecoder::sendMouseEvent( QMouseEvent *e ) | 620 | void KRFBDecoder::sendMouseEvent( QMouseEvent *e ) |
625 | { | 621 | { |
626 | // Deal with the buttons | 622 | // Deal with the buttons |
627 | if ( e->type() != QEvent::MouseMove ) { | 623 | if ( e->type() != QEvent::MouseMove ) { |
628 | buttonMask = 0; | 624 | buttonMask = 0; |
629 | if ( e->type() == QEvent::MouseButtonPress ) { | 625 | if ( e->type() == QEvent::MouseButtonPress ) { |
630 | if ( e->button() & LeftButton ) | 626 | if ( e->button() & LeftButton ) |
631 | buttonMask |= 0x01; | 627 | buttonMask |= 0x01; |
632 | if ( e->button() & MidButton ) | 628 | if ( e->button() & MidButton ) |
633 | buttonMask |= 0x04; | 629 | buttonMask |= 0x04; |
634 | if ( e->button() & RightButton ) | 630 | if ( e->button() & RightButton ) |
635 | buttonMask |= 0x02; | 631 | buttonMask |= 0x02; |
636 | } | 632 | } |
637 | else if ( e->type() == QEvent::MouseButtonRelease ) { | 633 | else if ( e->type() == QEvent::MouseButtonRelease ) { |
638 | if ( e->button() & LeftButton ) | 634 | if ( e->button() & LeftButton ) |
639 | buttonMask &= 0x06; | 635 | buttonMask &= 0x06; |
640 | if ( e->button() & MidButton ) | 636 | if ( e->button() & MidButton ) |
641 | buttonMask |= 0x03; | 637 | buttonMask |= 0x03; |
642 | if ( e->button() & RightButton ) | 638 | if ( e->button() & RightButton ) |
643 | buttonMask |= 0x05; | 639 | buttonMask |= 0x05; |
644 | } | 640 | } |
645 | } | 641 | } |
646 | 642 | ||
647 | // HACK: Scaling | 643 | // HACK: Scaling |
648 | CARD16 x = Swap16IfLE( e->x() * con->options()->scaleFactor ); | 644 | CARD16 x = Swap16IfLE( e->x() * con->options()->scaleFactor ); |
649 | CARD16 y = Swap16IfLE( e->y() *con->options()->scaleFactor ); | 645 | CARD16 y = Swap16IfLE( e->y() * con->options()->scaleFactor ); |
650 | 646 | ||
651 | con->write( &PointerEventId, 1 ); | 647 | con->write( &PointerEventId, 1 ); |
652 | con->write( &buttonMask, 1 ); | 648 | con->write( &buttonMask, 1 ); |
653 | con->write( &x, 2 ); | 649 | con->write( &x, 2 ); |
654 | con->write( &y, 2 ); | 650 | con->write( &y, 2 ); |
655 | } | 651 | } |
656 | 652 | ||
657 | 653 | ||
658 | void KRFBDecoder::sendCutEvent( const QString &unicode ) | 654 | void KRFBDecoder::sendCutEvent( const QString &unicode ) |
659 | { | 655 | { |
660 | // | 656 | // |
661 | // Warning: There is a bug in the RFB protocol because there is no way to find | 657 | // Warning: There is a bug in the RFB protocol because there is no way to find |
662 | // out the codepage in use on the remote machine. This could be fixed by requiring | 658 | // out the codepage in use on the remote machine. This could be fixed by requiring |
663 | // the remote server to use utf8 etc. but for now we have to assume they're the | 659 | // the remote server to use utf8 etc. but for now we have to assume they're the |
664 | // same. I've reported this problem to the ORL guys, but they apparantly have no | 660 | // same. I've reported this problem to the ORL guys, but they apparantly have no |
665 | // immediate plans to fix the issue. :-( (rich) | 661 | // immediate plans to fix the issue. :-( (rich) |
666 | // | 662 | // |
667 | 663 | ||
668 | CARD8 padding[3]; | 664 | CARD8 padding[3]; |
669 | QCString text = unicode.local8Bit(); | 665 | QCString text = unicode.local8Bit(); |
670 | CARD32 length = text.length(); | 666 | CARD32 length = text.length(); |
671 | length = Swap32IfLE( length ); | 667 | length = Swap32IfLE( length ); |
672 | 668 | ||
673 | con->write( &ClientCutTextId, 1 ); | 669 | con->write( &ClientCutTextId, 1 ); |
674 | con->write( &padding, 3 ); | 670 | con->write( &padding, 3 ); |
675 | con->write( &length, 4 ); | 671 | con->write( &length, 4 ); |
676 | con->write( text.data(), length ); | 672 | con->write( text.data(), length ); |
677 | } | 673 | } |
678 | 674 | ||
679 | void KRFBDecoder::gotServerCut() | 675 | void KRFBDecoder::gotServerCut() |
680 | { | 676 | { |
681 | owarn << "Got server cut" << oendl; | 677 | owarn << "Got server cut" << oendl; |
682 | 678 | ||
683 | currentState = AwaitingServerCutLength; | 679 | currentState = AwaitingServerCutLength; |
684 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotServerCutLength() ) ); | 680 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotServerCutLength() ) ); |
685 | con->waitForData( ServerCutLenLength ); | 681 | con->waitForData( ServerCutLenLength ); |
686 | } | 682 | } |
687 | 683 | ||
688 | void KRFBDecoder::gotServerCutLength() | 684 | void KRFBDecoder::gotServerCutLength() |
689 | { | 685 | { |
690 | assert( currentState = AwaitingServerCutLength ); | 686 | assert( currentState = AwaitingServerCutLength ); |
691 | disconnect( con, SIGNAL( gotEnoughData() ), | 687 | disconnect( con, SIGNAL( gotEnoughData() ), |
692 | this, SLOT( gotServerCutLength() ) ); | 688 | this, SLOT( gotServerCutLength() ) ); |
693 | 689 | ||
694 | CARD8 padding[3]; | 690 | CARD8 padding[3]; |
695 | con->read( padding, 3 ); | 691 | con->read( padding, 3 ); |
696 | 692 | ||
697 | con->read( &serverCutTextLen, 4 ); | 693 | con->read( &serverCutTextLen, 4 ); |
698 | serverCutTextLen = Swap32IfLE( serverCutTextLen ); | 694 | serverCutTextLen = Swap32IfLE( serverCutTextLen ); |
699 | 695 | ||
700 | currentState = AwaitingServerCutText; | 696 | currentState = AwaitingServerCutText; |
701 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotServerCutText() ) ); | 697 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotServerCutText() ) ); |
702 | con->waitForData( serverCutTextLen ); | 698 | con->waitForData( serverCutTextLen ); |
703 | } | 699 | } |
704 | 700 | ||
705 | void KRFBDecoder::gotServerCutText() | 701 | void KRFBDecoder::gotServerCutText() |
706 | { | 702 | { |
707 | assert( currentState = AwaitingServerCutText ); | 703 | assert( currentState = AwaitingServerCutText ); |
708 | 704 | ||
709 | disconnect( con, SIGNAL( gotEnoughData() ), | 705 | disconnect( con, SIGNAL( gotEnoughData() ), |
710 | this, SLOT( gotServerCutText() ) ); | 706 | this, SLOT( gotServerCutText() ) ); |
711 | 707 | ||
712 | 708 | ||
713 | // | 709 | // |
714 | // Warning: There is a bug in the RFB protocol because there is no way to find | 710 | // Warning: There is a bug in the RFB protocol because there is no way to find |
715 | // out the codepage in use on the remote machine. This could be fixed by requiring | 711 | // out the codepage in use on the remote machine. This could be fixed by requiring |
716 | // the remote server to use utf8 etc. but for now we have to assume they're the | 712 | // the remote server to use utf8 etc. but for now we have to assume they're the |
717 | // same. I've reported this problem to the ORL guys, but they apparantly have no | 713 | // same. I've reported this problem to the ORL guys, but they apparantly have no |
718 | // immediate plans to fix the issue. :-( (rich) | 714 | // immediate plans to fix the issue. :-( (rich) |
719 | // | 715 | // |
720 | 716 | ||
721 | char *cutbuf = new char[ serverCutTextLen + 1 ]; | 717 | char *cutbuf = new char[ serverCutTextLen + 1 ]; |
722 | CHECK_PTR( cutbuf ); | 718 | CHECK_PTR( cutbuf ); |
723 | 719 | ||
724 | con->read( cutbuf, serverCutTextLen ); | 720 | con->read( cutbuf, serverCutTextLen ); |
725 | cutbuf[ serverCutTextLen ] = '\0'; | 721 | cutbuf[ serverCutTextLen ] = '\0'; |
726 | 722 | ||
727 | /* For some reason QApplication::clipboard()->setText() segfaults when called | 723 | /* For some reason QApplication::clipboard()->setText() segfaults when called |
728 | * from within keypebble's mass of signals and slots | 724 | * from within keypebble's mass of signals and slots |
729 | owarn << "Server cut: " << cutbuf << "" << oendl; | 725 | owarn << "Server cut: " << cutbuf << "" << oendl; |
730 | 726 | ||
731 | QString cutText( cutbuf ); // DANGER!! | 727 | QString cutText( cutbuf ); // DANGER!! |
732 | qApp->clipboard()->setText( cutText ); | 728 | qApp->clipboard()->setText( cutText ); |
733 | */ | 729 | */ |
734 | 730 | ||
735 | delete cutbuf; | 731 | delete cutbuf; |
736 | // Now wait for the update (again) | 732 | // Now wait for the update (again) |
737 | if ( oldState == AwaitingUpdate ) { | 733 | if ( oldState == AwaitingUpdate ) { |
738 | currentState = AwaitingUpdate; | 734 | currentState = AwaitingUpdate; |
739 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotUpdateHeader() ) ); | 735 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotUpdateHeader() ) ); |
740 | con->waitForData( UpdateHeaderLength ); | 736 | con->waitForData( UpdateHeaderLength ); |
741 | } | 737 | } |
742 | else if ( oldState == Idle ) { | 738 | else if ( oldState == Idle ) { |
743 | currentState = Idle; | 739 | currentState = Idle; |
744 | } | 740 | } |
745 | else { | 741 | else { |
746 | owarn << "Async handled in weird state" << oendl; | 742 | owarn << "Async handled in weird state" << oendl; |
747 | currentState = oldState; | 743 | currentState = oldState; |
748 | }; | 744 | }; |
749 | } | 745 | } |
750 | 746 | ||
751 | void KRFBDecoder::gotBell() | 747 | void KRFBDecoder::gotBell() |
752 | { | 748 | { |
753 | owarn << "Got server bell" << oendl; | 749 | owarn << "Got server bell" << oendl; |
754 | buf->soundBell(); | 750 | buf->soundBell(); |
755 | 751 | ||
756 | // Now wait for the update (again) | 752 | // Now wait for the update (again) |
757 | if ( oldState == AwaitingUpdate ) { | 753 | if ( oldState == AwaitingUpdate ) { |
758 | currentState = AwaitingUpdate; | 754 | currentState = AwaitingUpdate; |
759 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotUpdateHeader() ) ); | 755 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotUpdateHeader() ) ); |
760 | con->waitForData( UpdateHeaderLength ); | 756 | con->waitForData( UpdateHeaderLength ); |
761 | } | 757 | } |
762 | else if ( oldState == Idle ) { | 758 | else if ( oldState == Idle ) { |
763 | currentState = Idle; | 759 | currentState = Idle; |
764 | } | 760 | } |
765 | else { | 761 | else { |
766 | owarn << "Async handled in weird state" << oendl; | 762 | owarn << "Async handled in weird state" << oendl; |
767 | currentState = oldState; | 763 | currentState = oldState; |
768 | }; | 764 | }; |
769 | } | 765 | } |
770 | 766 | ||
771 | void KRFBDecoder::sendKeyPressEvent( QKeyEvent *event ) | 767 | void KRFBDecoder::sendKeyPressEvent( QKeyEvent *event ) |
772 | { | 768 | { |
773 | int key; | 769 | int key; |
774 | key = toKeySym( event ); | 770 | key = toKeySym( event ); |
775 | if ( key ) { | 771 | if ( key ) { |
776 | key = Swap32IfLE( key ); | 772 | key = Swap32IfLE( key ); |
777 | 773 | ||
778 | CARD8 mask = true; | 774 | CARD8 mask = true; |
779 | 775 | ||
780 | CARD16 padding = 0; | 776 | CARD16 padding = 0; |
781 | con->write( &KeyEventId, 1 ); | 777 | con->write( &KeyEventId, 1 ); |
782 | con->write( &mask, 1 ); | 778 | con->write( &mask, 1 ); |
783 | con->write( &padding, 2 ); | 779 | con->write( &padding, 2 ); |
784 | con->write( &key, 4 ); | 780 | con->write( &key, 4 ); |
785 | } | 781 | } |
786 | } | 782 | } |
787 | 783 | ||
788 | void KRFBDecoder::sendKeyReleaseEvent( QKeyEvent *event ) | 784 | void KRFBDecoder::sendKeyReleaseEvent( QKeyEvent *event ) |
789 | { | 785 | { |
790 | int key; | 786 | int key; |
791 | key = toKeySym( event ); | 787 | key = toKeySym( event ); |
792 | if ( key ) { | 788 | if ( key ) { |
793 | key = Swap32IfLE( key ); | 789 | key = Swap32IfLE( key ); |
794 | 790 | ||
795 | CARD8 mask = false; | 791 | CARD8 mask = false; |
796 | 792 | ||
797 | CARD16 padding = 0; | 793 | CARD16 padding = 0; |
798 | con->write( &KeyEventId, 1 ); | 794 | con->write( &KeyEventId, 1 ); |
799 | con->write( &mask, 1 ); | 795 | con->write( &mask, 1 ); |
800 | con->write( &padding, 2 ); | 796 | con->write( &padding, 2 ); |
801 | con->write( &key, 4 ); | 797 | con->write( &key, 4 ); |
802 | } | 798 | } |
803 | } | 799 | } |
804 | 800 | ||
805 | 801 | ||
806 | 802 | ||
807 | 803 | ||
808 | // | 804 | // |
809 | // The RFB protocol spec says 'For most ordinary keys, the 'keysym' | 805 | // The RFB protocol spec says 'For most ordinary keys, the 'keysym' |
810 | // is the same as the corresponding ASCII value.', but doesn't | 806 | // is the same as the corresponding ASCII value.', but doesn't |
811 | // elaborate what the most ordinary keys are. The spec also lists | 807 | // elaborate what the most ordinary keys are. The spec also lists |
812 | // a set (possibly subset, it's unspecified) of mappings for | 808 | // a set (possibly subset, it's unspecified) of mappings for |
813 | // "other common keys" (backspace, tab, return, escape, etc). | 809 | // "other common keys" (backspace, tab, return, escape, etc). |
814 | // | 810 | // |
815 | int KRFBDecoder::toKeySym( QKeyEvent *k ) | 811 | int KRFBDecoder::toKeySym( QKeyEvent *k ) |
816 | { | 812 | { |
817 | 813 | ||
818 | // | 814 | // |
819 | // Try and map these "other common keys" first. | 815 | // Try and map these "other common keys" first. |
820 | // | 816 | // |
821 | if ((k->key() >= Qt::Key_Escape) && (k->key() <= Qt::Key_F12)) { | 817 | if ((k->key() >= Qt::Key_Escape) && (k->key() <= Qt::Key_F12)) { |
822 | for(int i = 0; keyMap[i].keycode != 0; i++) { | 818 | for(int i = 0; keyMap[i].keycode != 0; i++) { |
823 | if (k->key() == keyMap[i].keycode) { | 819 | if (k->key() == keyMap[i].keycode) { |
824 | return keyMap[i].keysym; | 820 | return keyMap[i].keysym; |
825 | } | 821 | } |
826 | } | 822 | } |
827 | } | 823 | } |
828 | 824 | ||
829 | // | 825 | // |
830 | // If these keys aren't matched, return the ascii code and let the | 826 | // If these keys aren't matched, return the ascii code and let the |
831 | // server figure it out. We don't return k->key(), as the data in | 827 | // server figure it out. We don't return k->key(), as the data in |
832 | // key differs between input methods, and we don't want special cases. | 828 | // key differs between input methods, and we don't want special cases. |
833 | // | 829 | // |
834 | return k->ascii(); | 830 | return k->ascii(); |
835 | } | 831 | } |
diff --git a/noncore/graphics/opie-eye/gui/iconview.cpp b/noncore/graphics/opie-eye/gui/iconview.cpp index 6c5f5ea..211314b 100644 --- a/noncore/graphics/opie-eye/gui/iconview.cpp +++ b/noncore/graphics/opie-eye/gui/iconview.cpp | |||
@@ -49,131 +49,131 @@ namespace { | |||
49 | QPixmap* pixmap()const; | 49 | QPixmap* pixmap()const; |
50 | QString path()const { return m_path; } | 50 | QString path()const { return m_path; } |
51 | bool isDir()const { return m_isDir; } | 51 | bool isDir()const { return m_isDir; } |
52 | void setText( const QString& ); | 52 | void setText( const QString& ); |
53 | bool textOnly()const{return m_textOnly;} | 53 | bool textOnly()const{return m_textOnly;} |
54 | void setTextOnly(bool how){m_textOnly=how;} | 54 | void setTextOnly(bool how){m_textOnly=how;} |
55 | /* just for starting recalc of item rect! */ | 55 | /* just for starting recalc of item rect! */ |
56 | virtual void setPixmap( const QPixmap & icon, bool recalc, bool redraw = TRUE ); | 56 | virtual void setPixmap( const QPixmap & icon, bool recalc, bool redraw = TRUE ); |
57 | /* just for starting recalc of item rect! */ | 57 | /* just for starting recalc of item rect! */ |
58 | virtual void setPixmap( const QPixmap & icon); | 58 | virtual void setPixmap( const QPixmap & icon); |
59 | 59 | ||
60 | protected: | 60 | protected: |
61 | mutable QPixmap* m_pix; | 61 | mutable QPixmap* m_pix; |
62 | 62 | ||
63 | private: | 63 | private: |
64 | QString m_path; | 64 | QString m_path; |
65 | bool m_isDir : 1; | 65 | bool m_isDir : 1; |
66 | bool m_noInfo :1; | 66 | bool m_noInfo :1; |
67 | bool m_textOnly:1; | 67 | bool m_textOnly:1; |
68 | bool m_NameOnly:1; | 68 | bool m_NameOnly:1; |
69 | bool m_Pixset:1; | 69 | bool m_Pixset:1; |
70 | }; | 70 | }; |
71 | class TextViewItem : public IconViewItem { | 71 | class TextViewItem : public IconViewItem { |
72 | TextViewItem( QIconView*, const QString& path, const QString& name, bool isDir = false ); | 72 | TextViewItem( QIconView*, const QString& path, const QString& name, bool isDir = false ); |
73 | QPixmap *pixmap()const; | 73 | QPixmap *pixmap()const; |
74 | void setText( const QString& ); | 74 | void setText( const QString& ); |
75 | }; | 75 | }; |
76 | class ThumbViewItem : public IconViewItem { | 76 | class ThumbViewItem : public IconViewItem { |
77 | ThumbViewItem( QIconView*, const QString& path, const QString& name, bool isDir = false ); | 77 | ThumbViewItem( QIconView*, const QString& path, const QString& name, bool isDir = false ); |
78 | QPixmap *pixmap()const; | 78 | QPixmap *pixmap()const; |
79 | void setText( const QString& ); | 79 | void setText( const QString& ); |
80 | }; | 80 | }; |
81 | 81 | ||
82 | 82 | ||
83 | /* | 83 | /* |
84 | * If we request an Image or String | 84 | * If we request an Image or String |
85 | * we add it to the map | 85 | * we add it to the map |
86 | */ | 86 | */ |
87 | static QMap<QString, IconViewItem*> g_stringInf; | 87 | static QMap<QString, IconViewItem*> g_stringInf; |
88 | static QMap<QString, IconViewItem*> g_stringPix; | 88 | static QMap<QString, IconViewItem*> g_stringPix; |
89 | 89 | ||
90 | IconViewItem::IconViewItem( QIconView* view,const QString& path, | 90 | IconViewItem::IconViewItem( QIconView* view,const QString& path, |
91 | const QString& name, bool isDir ) | 91 | const QString& name, bool isDir ) |
92 | : QIconViewItem( view, name ), m_path( path ), m_isDir( isDir ), | 92 | : QIconViewItem( view, name ), m_path( path ), m_isDir( isDir ), |
93 | m_noInfo( false ),m_textOnly(false),m_Pixset(false) | 93 | m_noInfo( false ),m_textOnly(false),m_Pixset(false) |
94 | { | 94 | { |
95 | if ( isDir && !_dirPix ) | 95 | if ( isDir && !_dirPix ) |
96 | _dirPix = new QPixmap( Resource::loadPixmap("advancedfm/FileBrowser")); | 96 | _dirPix = new QPixmap( Resource::loadPixmap("advancedfm/FileBrowser")); |
97 | else if ( !isDir && !_unkPix ) | 97 | else if ( !isDir && !_unkPix ) |
98 | _unkPix = new QPixmap( Resource::loadPixmap( "UnknownDocument" ) ); | 98 | _unkPix = new QPixmap( Resource::loadPixmap( "UnknownDocument" ) ); |
99 | } | 99 | } |
100 | 100 | ||
101 | inline void IconViewItem::setPixmap( const QPixmap & icon, bool recalc, bool redraw) | 101 | inline void IconViewItem::setPixmap( const QPixmap & icon, bool recalc, bool redraw) |
102 | { | 102 | { |
103 | m_Pixset = true; | 103 | m_Pixset = true; |
104 | calcRect(text()); | 104 | calcRect(text()); |
105 | } | 105 | } |
106 | inline void IconViewItem::setPixmap( const QPixmap & icon) | 106 | inline void IconViewItem::setPixmap( const QPixmap & icon) |
107 | { | 107 | { |
108 | m_Pixset = true; | 108 | m_Pixset = true; |
109 | calcRect(text()); | 109 | calcRect(text()); |
110 | } | 110 | } |
111 | 111 | ||
112 | inline QPixmap* IconViewItem::pixmap()const { | 112 | inline QPixmap* IconViewItem::pixmap()const { |
113 | // qWarning( "Name is " + m_path.right( 15 ) + " rect is %d %d %d %d | %d %d", | 113 | // owarn << "Name is " << m_path.right( 15 ) << " rect is " << rect().x() << " " << rect().y() |
114 | // rect().x(),rect().y(),rect().width(),rect().height(), | 114 | // << " " << rect().width() << " " << rect().height() << " | " << iconView()->contentsX() |
115 | // iconView()->contentsX(), iconView()->contentsY()); | 115 | // << " " << iconView()->contentsY() << oendl; |
116 | 116 | ||
117 | if (textOnly()&&!m_isDir) { | 117 | if (textOnly()&&!m_isDir) { |
118 | if (!_emptyPix) _emptyPix = new QPixmap(0,0,1); | 118 | if (!_emptyPix) _emptyPix = new QPixmap(0,0,1); |
119 | return _emptyPix; | 119 | return _emptyPix; |
120 | } | 120 | } |
121 | if ( m_isDir ) | 121 | if ( m_isDir ) |
122 | return _dirPix; | 122 | return _dirPix; |
123 | else{ | 123 | else{ |
124 | if (!m_noInfo && !g_stringInf.contains( m_path ) ) { | 124 | if (!m_noInfo && !g_stringInf.contains( m_path ) ) { |
125 | currentView()->dirLister()->imageInfo( m_path ); | 125 | currentView()->dirLister()->imageInfo( m_path ); |
126 | g_stringInf.insert( m_path, const_cast<IconViewItem*>(this)); | 126 | g_stringInf.insert( m_path, const_cast<IconViewItem*>(this)); |
127 | } | 127 | } |
128 | 128 | ||
129 | m_pix = PPixmapCache::self()->cachedImage( m_path, 64, 64 ); | 129 | m_pix = PPixmapCache::self()->cachedImage( m_path, 64, 64 ); |
130 | if (!m_pix && !g_stringPix.contains( m_path )) { | 130 | if (!m_pix && !g_stringPix.contains( m_path )) { |
131 | currentView()->dirLister()->thumbNail( m_path, 64, 64 ); | 131 | currentView()->dirLister()->thumbNail( m_path, 64, 64 ); |
132 | g_stringPix.insert( m_path, const_cast<IconViewItem*>(this)); | 132 | g_stringPix.insert( m_path, const_cast<IconViewItem*>(this)); |
133 | } | 133 | } |
134 | return m_pix ? m_pix : _unkPix; | 134 | return m_pix ? m_pix : _unkPix; |
135 | } | 135 | } |
136 | } | 136 | } |
137 | inline void IconViewItem::setText( const QString& str ) { | 137 | inline void IconViewItem::setText( const QString& str ) { |
138 | QString text = QIconViewItem::text()+"\n"+str; | 138 | QString text = QIconViewItem::text()+"\n"+str; |
139 | m_noInfo = true; | 139 | m_noInfo = true; |
140 | QIconViewItem::setText( text ); | 140 | QIconViewItem::setText( text ); |
141 | } | 141 | } |
142 | } | 142 | } |
143 | 143 | ||
144 | 144 | ||
145 | /* | 145 | /* |
146 | * Set up the GUI.. initialize the slave set up gui | 146 | * Set up the GUI.. initialize the slave set up gui |
147 | * and also load a dir | 147 | * and also load a dir |
148 | */ | 148 | */ |
149 | PIconView::PIconView( QWidget* wid, Opie::Core::OConfig* cfg ) | 149 | PIconView::PIconView( QWidget* wid, Opie::Core::OConfig* cfg ) |
150 | : QVBox( wid ), m_cfg( cfg ), m_updatet( false ) | 150 | : QVBox( wid ), m_cfg( cfg ), m_updatet( false ) |
151 | { | 151 | { |
152 | { | 152 | { |
153 | QCopEnvelope( "QPE/Application/opie-eye_slave", "refUp()" ); | 153 | QCopEnvelope( "QPE/Application/opie-eye_slave", "refUp()" ); |
154 | } | 154 | } |
155 | m_path = QDir::homeDirPath(); | 155 | m_path = QDir::homeDirPath(); |
156 | m_mode = 0; | 156 | m_mode = 0; |
157 | 157 | ||
158 | QHBox *hbox = new QHBox( this ); | 158 | QHBox *hbox = new QHBox( this ); |
159 | QLabel* lbl = new QLabel( hbox ); | 159 | QLabel* lbl = new QLabel( hbox ); |
160 | lbl->setText( tr("View as" ) ); | 160 | lbl->setText( tr("View as" ) ); |
161 | 161 | ||
162 | m_views = new QComboBox( hbox, "View As" ); | 162 | m_views = new QComboBox( hbox, "View As" ); |
163 | 163 | ||
164 | m_view= new QIconView( this ); | 164 | m_view= new QIconView( this ); |
165 | connect(m_view, SIGNAL(clicked(QIconViewItem*) ), | 165 | connect(m_view, SIGNAL(clicked(QIconViewItem*) ), |
166 | this, SLOT(slotClicked(QIconViewItem*)) ); | 166 | this, SLOT(slotClicked(QIconViewItem*)) ); |
167 | connect(m_view, SIGNAL(returnPressed(QIconViewItem*)), | 167 | connect(m_view, SIGNAL(returnPressed(QIconViewItem*)), |
168 | this, SLOT(slotClicked(QIconViewItem*)) ); | 168 | this, SLOT(slotClicked(QIconViewItem*)) ); |
169 | 169 | ||
170 | m_view->setArrangement( QIconView::LeftToRight ); | 170 | m_view->setArrangement( QIconView::LeftToRight ); |
171 | 171 | ||
172 | m_mode = m_cfg->readNumEntry("ListViewMode", 1); | 172 | m_mode = m_cfg->readNumEntry("ListViewMode", 1); |
173 | QString lastView = m_cfg->readEntry("LastView",""); | 173 | QString lastView = m_cfg->readEntry("LastView",""); |
174 | 174 | ||
175 | if (m_mode < 1 || m_mode>3) m_mode = 1; | 175 | if (m_mode < 1 || m_mode>3) m_mode = 1; |
176 | 176 | ||
177 | m_view->setItemTextPos( QIconView::Right ); | 177 | m_view->setItemTextPos( QIconView::Right ); |
178 | 178 | ||
179 | calculateGrid(); | 179 | calculateGrid(); |
diff --git a/noncore/graphics/opie-eye/gui/viewmodebutton.cpp b/noncore/graphics/opie-eye/gui/viewmodebutton.cpp index 36e5dcf..aa15d31 100644 --- a/noncore/graphics/opie-eye/gui/viewmodebutton.cpp +++ b/noncore/graphics/opie-eye/gui/viewmodebutton.cpp | |||
@@ -1,45 +1,48 @@ | |||
1 | #include "viewmodebutton.h" | 1 | #include "viewmodebutton.h" |
2 | 2 | ||
3 | /* OPIE */ | ||
3 | #include <opie2/odebug.h> | 4 | #include <opie2/odebug.h> |
5 | using namespace Opie::Core; | ||
4 | 6 | ||
7 | /* QT */ | ||
5 | #include <qtoolbar.h> | 8 | #include <qtoolbar.h> |
6 | #include <qpopupmenu.h> | 9 | #include <qpopupmenu.h> |
7 | 10 | ||
8 | ViewModeButton::ViewModeButton( QToolBar* bar,int def ) | 11 | ViewModeButton::ViewModeButton( QToolBar* bar,int def ) |
9 | : QToolButton( bar ) | 12 | : QToolButton( bar ) |
10 | { | 13 | { |
11 | slotChange( def ); | 14 | slotChange( def ); |
12 | QPopupMenu *pop= new QPopupMenu( this ); | 15 | QPopupMenu *pop= new QPopupMenu( this ); |
13 | pop->setCheckable( true ); | 16 | pop->setCheckable( true ); |
14 | pop->insertItem( tr("Thumbnail and Imageinfo"), 1 ); | 17 | pop->insertItem( tr("Thumbnail and Imageinfo"), 1 ); |
15 | pop->insertItem( tr("Thumbnail and Name" ), 2 ); | 18 | pop->insertItem( tr("Thumbnail and Name" ), 2 ); |
16 | pop->insertItem( tr("Name Only" ), 3 ); | 19 | pop->insertItem( tr("Name Only" ), 3 ); |
17 | connect(pop, SIGNAL(activated(int)), | 20 | connect(pop, SIGNAL(activated(int)), |
18 | this, SIGNAL(changeMode(int)) ); | 21 | this, SIGNAL(changeMode(int)) ); |
19 | connect(pop, SIGNAL(activated(int)), | 22 | connect(pop, SIGNAL(activated(int)), |
20 | this, SLOT(slotChange(int)) ); | 23 | this, SLOT(slotChange(int)) ); |
21 | 24 | ||
22 | 25 | ||
23 | setPopup( pop ); | 26 | setPopup( pop ); |
24 | } | 27 | } |
25 | 28 | ||
26 | ViewModeButton::~ViewModeButton() { | 29 | ViewModeButton::~ViewModeButton() { |
27 | } | 30 | } |
28 | 31 | ||
29 | void ViewModeButton::slotChange( int i ) { | 32 | void ViewModeButton::slotChange( int i ) { |
30 | QString name; | 33 | QString name; |
31 | switch( i ) { | 34 | switch( i ) { |
32 | case 1: | 35 | case 1: |
33 | name = "opie-eye/opie-eye-thumb"; | 36 | name = "opie-eye/opie-eye-thumb"; |
34 | break; | 37 | break; |
35 | case 2: | 38 | case 2: |
36 | name = "opie-eye/opie-eye-thumbonly"; | 39 | name = "opie-eye/opie-eye-thumbonly"; |
37 | break; | 40 | break; |
38 | case 3: | 41 | case 3: |
39 | name = "opie-eye/opie-eye-textview"; | 42 | name = "opie-eye/opie-eye-textview"; |
40 | break; | 43 | break; |
41 | } | 44 | } |
42 | 45 | ||
43 | qWarning("foo %d" +name, i ); | 46 | owarn << "foo " << name << oendl; |
44 | setIconSet( Resource::loadIconSet( name ) ); | 47 | setIconSet( Resource::loadIconSet( name ) ); |
45 | } | 48 | } |
diff --git a/noncore/net/opietooth/lib/device.cc b/noncore/net/opietooth/lib/device.cc index 04c50d9..f81066e 100644 --- a/noncore/net/opietooth/lib/device.cc +++ b/noncore/net/opietooth/lib/device.cc | |||
@@ -1,152 +1,157 @@ | |||
1 | 1 | ||
2 | #include <signal.h> | 2 | #include "device.h" |
3 | 3 | ||
4 | /* OPIE */ | ||
4 | #include <opie2/oprocess.h> | 5 | #include <opie2/oprocess.h> |
6 | #include <opie2/odebug.h> | ||
7 | using namespace Opie::Core; | ||
8 | |||
9 | /* STD */ | ||
10 | #include <signal.h> | ||
5 | 11 | ||
6 | #include "device.h" | ||
7 | 12 | ||
8 | using namespace OpieTooth; | 13 | using namespace OpieTooth; |
9 | 14 | ||
10 | using Opie::Core::OProcess; | 15 | using Opie::Core::OProcess; |
11 | namespace { | 16 | namespace { |
12 | int parsePid( const QCString& par ){ | 17 | int parsePid( const QCString& par ){ |
13 | int id=0; | 18 | int id=0; |
14 | QString string( par ); | 19 | QString string( par ); |
15 | QStringList list = QStringList::split( '\n', string ); | 20 | QStringList list = QStringList::split( '\n', string ); |
16 | for( QStringList::Iterator it = list.begin(); it != list.end(); ++it ){ | 21 | for( QStringList::Iterator it = list.begin(); it != list.end(); ++it ){ |
17 | qWarning("parsePID: %s", (*it).latin1() ); | 22 | owarn << "parsePID: " << (*it).latin1() << oendl; |
18 | if( !(*it).startsWith("CSR") ){ | 23 | if( !(*it).startsWith("CSR") ){ |
19 | id = (*it).toInt(); | 24 | id = (*it).toInt(); |
20 | break; | 25 | break; |
21 | } | 26 | } |
22 | } | 27 | } |
23 | return id; | 28 | return id; |
24 | } | 29 | } |
25 | } | 30 | } |
26 | 31 | ||
27 | Device::Device(const QString &device, const QString &mode, const QString &speed ) | 32 | Device::Device(const QString &device, const QString &mode, const QString &speed ) |
28 | : QObject(0, "device") { | 33 | : QObject(0, "device") { |
29 | 34 | ||
30 | qWarning("OpieTooth::Device create" ); | 35 | owarn << "OpieTooth::Device create" << oendl; |
31 | m_hci = 0; | 36 | m_hci = 0; |
32 | m_process = 0; | 37 | m_process = 0; |
33 | m_attached = false; | 38 | m_attached = false; |
34 | m_device = device; | 39 | m_device = device; |
35 | m_mode = mode; | 40 | m_mode = mode; |
36 | m_speed = speed; | 41 | m_speed = speed; |
37 | attach(); | 42 | attach(); |
38 | } | 43 | } |
39 | Device::~Device(){ | 44 | Device::~Device(){ |
40 | detach(); | 45 | detach(); |
41 | } | 46 | } |
42 | void Device::attach(){ | 47 | void Device::attach(){ |
43 | qWarning("attaching %s %s %s", m_device.latin1(), m_mode.latin1(), m_speed.latin1() ); | 48 | owarn << "attaching " << m_device.latin1() << " " << m_mode.latin1() << " " << m_speed.latin1() << oendl; |
44 | if(m_process == 0 ){ | 49 | if(m_process == 0 ){ |
45 | m_output.resize(0); | 50 | m_output.resize(0); |
46 | qWarning("new process to create" ); | 51 | owarn << "new process to create" << oendl; |
47 | m_process = new OProcess(); | 52 | m_process = new OProcess(); |
48 | *m_process << "hciattach"; | 53 | *m_process << "hciattach"; |
49 | *m_process << "-p"; | 54 | *m_process << "-p"; |
50 | *m_process << m_device << m_mode << m_speed; | 55 | *m_process << m_device << m_mode << m_speed; |
51 | connect(m_process, SIGNAL( processExited(Opie::Core::OProcess*) ), | 56 | connect(m_process, SIGNAL( processExited(Opie::Core::OProcess*) ), |
52 | this, SLOT( slotExited(Opie::Core::OProcess* ) ) ); | 57 | this, SLOT( slotExited(Opie::Core::OProcess* ) ) ); |
53 | connect(m_process, SIGNAL( receivedStdout(Opie::Core::OProcess*, char*, int) ), | 58 | connect(m_process, SIGNAL( receivedStdout(Opie::Core::OProcess*, char*, int) ), |
54 | this, SLOT(slotStdOut(Opie::Core::OProcess*,char*,int ) ) ); | 59 | this, SLOT(slotStdOut(Opie::Core::OProcess*,char*,int ) ) ); |
55 | connect(m_process, SIGNAL(receivedStderr(Opie::Core::OProcess*, char*, int ) ), | 60 | connect(m_process, SIGNAL(receivedStderr(Opie::Core::OProcess*, char*, int ) ), |
56 | this, SLOT(slotStdErr(Opie::Core::OProcess*,char*,int) ) ); | 61 | this, SLOT(slotStdErr(Opie::Core::OProcess*,char*,int) ) ); |
57 | if(!m_process->start(OProcess::NotifyOnExit, OProcess::AllOutput ) ){ | 62 | if(!m_process->start(OProcess::NotifyOnExit, OProcess::AllOutput ) ){ |
58 | qWarning("Could not start" ); | 63 | owarn << "Could not start" << oendl; |
59 | delete m_process; | 64 | delete m_process; |
60 | m_process = 0; | 65 | m_process = 0; |
61 | } | 66 | } |
62 | }; | 67 | }; |
63 | } | 68 | } |
64 | void Device::detach(){ | 69 | void Device::detach(){ |
65 | delete m_hci; | 70 | delete m_hci; |
66 | delete m_process; | 71 | delete m_process; |
67 | // kill the pid we got | 72 | // kill the pid we got |
68 | if(m_attached ){ | 73 | if(m_attached ){ |
69 | //kill the pid | 74 | //kill the pid |
70 | qWarning( "killing" ); | 75 | warn << "killing" << oendl; |
71 | kill(pid, 9); | 76 | kill(pid, 9); |
72 | } | 77 | } |
73 | qWarning("detached" ); | 78 | owarn << "detached" << oendl; |
74 | } | 79 | } |
75 | bool Device::isLoaded()const{ | 80 | bool Device::isLoaded()const{ |
76 | return m_attached; | 81 | return m_attached; |
77 | } | 82 | } |
78 | QString Device::devName()const { | 83 | QString Device::devName()const { |
79 | return QString::fromLatin1("hci0"); | 84 | return QString::fromLatin1("hci0"); |
80 | }; | 85 | }; |
81 | void Device::slotExited( OProcess* proc) | 86 | void Device::slotExited( OProcess* proc) |
82 | { | 87 | { |
83 | qWarning("prcess exited" ); | 88 | owarn << "prcess exited" << oendl; |
84 | if(proc== m_process ){ | 89 | if(proc== m_process ){ |
85 | qWarning("proc == m_process" ); | 90 | owarn << "proc == m_process" << oendl; |
86 | if( m_process->normalExit() ){ // normal exit | 91 | if( m_process->normalExit() ){ // normal exit |
87 | qWarning("normalExit" ); | 92 | owarn << "normalExit" << oendl; |
88 | int ret = m_process->exitStatus(); | 93 | int ret = m_process->exitStatus(); |
89 | if( ret == 0 ){ // attached | 94 | if( ret == 0 ){ // attached |
90 | qWarning("attached" ); | 95 | owarn << "attached" << oendl; |
91 | qWarning("Output: %s", m_output.data() ); | 96 | owarn << "Output: " << m_output.data() << oendl; |
92 | pid = parsePid( m_output ); | 97 | pid = parsePid( m_output ); |
93 | qWarning("Pid = %d", pid ); | 98 | owarn << "Pid = " << pid << oendl; |
94 | // now hciconfig hci0 up ( determine hciX FIXME) | 99 | // now hciconfig hci0 up ( determine hciX FIXME) |
95 | // and call hciconfig hci0 up | 100 | // and call hciconfig hci0 up |
96 | // FIXME hardcoded to hci0 now :( | 101 | // FIXME hardcoded to hci0 now :( |
97 | m_hci = new OProcess( ); | 102 | m_hci = new OProcess( ); |
98 | *m_hci << "hciconfig"; | 103 | *m_hci << "hciconfig"; |
99 | *m_hci << "hci0 up"; | 104 | *m_hci << "hci0 up"; |
100 | connect(m_hci, SIGNAL( processExited(Opie::Core::OProcess*) ), | 105 | connect(m_hci, SIGNAL( processExited(Opie::Core::OProcess*) ), |
101 | this, SLOT( slotExited(Opie::Core::OProcess* ) ) ); | 106 | this, SLOT( slotExited(Opie::Core::OProcess* ) ) ); |
102 | if(!m_hci->start() ){ | 107 | if(!m_hci->start() ){ |
103 | qWarning("could not start" ); | 108 | owarn << "could not start" << oendl; |
104 | m_attached = false; | 109 | m_attached = false; |
105 | emit device("hci0", false ); | 110 | emit device("hci0", false ); |
106 | } | 111 | } |
107 | }else{ | 112 | }else{ |
108 | qWarning("crass" ); | 113 | owarn << "crass" << oendl; |
109 | m_attached = false; | 114 | m_attached = false; |
110 | emit device("hci0", false ); | 115 | emit device("hci0", false ); |
111 | 116 | ||
112 | } | 117 | } |
113 | } | 118 | } |
114 | delete m_process; | 119 | delete m_process; |
115 | m_process = 0; | 120 | m_process = 0; |
116 | }else if(proc== m_hci ){ | 121 | }else if(proc== m_hci ){ |
117 | qWarning("M HCI exited" ); | 122 | owarn << "M HCI exited" << oendl; |
118 | if( m_hci->normalExit() ){ | 123 | if( m_hci->normalExit() ){ |
119 | qWarning("normal exit" ); | 124 | owarn << "normal exit" << oendl; |
120 | int ret = m_hci->exitStatus(); | 125 | int ret = m_hci->exitStatus(); |
121 | if( ret == 0 ){ | 126 | if( ret == 0 ){ |
122 | qWarning("attached really really attached" ); | 127 | owarn << "attached really really attached" << oendl; |
123 | m_attached = true; | 128 | m_attached = true; |
124 | emit device("hci0", true ); | 129 | emit device("hci0", true ); |
125 | }else{ | 130 | }else{ |
126 | qWarning( "failed" ); | 131 | owarn << "failed" << oendl; |
127 | emit device("hci0", false ); | 132 | emit device("hci0", false ); |
128 | m_attached = false; | 133 | m_attached = false; |
129 | } | 134 | } |
130 | }// normal exit | 135 | }// normal exit |
131 | delete m_hci; | 136 | delete m_hci; |
132 | m_hci = 0; | 137 | m_hci = 0; |
133 | } | 138 | } |
134 | } | 139 | } |
135 | void Device::slotStdOut(OProcess* proc, char* chars, int len) | 140 | void Device::slotStdOut(OProcess* proc, char* chars, int len) |
136 | { | 141 | { |
137 | qWarning("std out" ); | 142 | owarn << "std out" << oendl; |
138 | if( len <1 ){ | 143 | if( len <1 ){ |
139 | qWarning( "len < 1 " ); | 144 | owarn << "len < 1 " << oendl; |
140 | return; | 145 | return; |
141 | } | 146 | } |
142 | if(proc == m_process ){ | 147 | if(proc == m_process ){ |
143 | QCString string( chars, len+1 ); // \0 == +1 | 148 | QCString string( chars, len+1 ); // \0 == +1 |
144 | qWarning("output: %s", string.data() ); | 149 | owarn << "output: " << string.data() << oendl; |
145 | m_output.append( string.data() ); | 150 | m_output.append( string.data() ); |
146 | } | 151 | } |
147 | } | 152 | } |
148 | void Device::slotStdErr(OProcess* proc, char* chars, int len) | 153 | void Device::slotStdErr(OProcess* proc, char* chars, int len) |
149 | { | 154 | { |
150 | qWarning("std err" ); | 155 | owarn << "std err" << oendl; |
151 | slotStdOut( proc, chars, len ); | 156 | slotStdOut( proc, chars, len ); |
152 | } | 157 | } |
diff --git a/noncore/net/opietooth/lib/manager.cc b/noncore/net/opietooth/lib/manager.cc index 18e1df9..76d9127 100644 --- a/noncore/net/opietooth/lib/manager.cc +++ b/noncore/net/opietooth/lib/manager.cc | |||
@@ -1,335 +1,336 @@ | |||
1 | 1 | ||
2 | |||
3 | #include <opie2/oprocess.h> | ||
4 | |||
5 | #include "parser.h" | 2 | #include "parser.h" |
6 | #include "manager.h" | 3 | #include "manager.h" |
7 | 4 | ||
5 | #include <opie2/oprocess.h> | ||
6 | #include <opie2/odebug.h> | ||
7 | using namespace Opie::Core; | ||
8 | |||
8 | 9 | ||
9 | using namespace OpieTooth; | 10 | using namespace OpieTooth; |
10 | 11 | ||
11 | using Opie::Core::OProcess; | 12 | using Opie::Core::OProcess; |
12 | Manager::Manager( const QString& dev ) | 13 | Manager::Manager( const QString& dev ) |
13 | : QObject() | 14 | : QObject() |
14 | { | 15 | { |
15 | qWarning("created"); | 16 | owarn << "created" << oendl; |
16 | m_device = dev; | 17 | m_device = dev; |
17 | m_hcitool = 0; | 18 | m_hcitool = 0; |
18 | m_sdp = 0; | 19 | m_sdp = 0; |
19 | } | 20 | } |
20 | Manager::Manager( Device* /*dev*/ ) | 21 | Manager::Manager( Device* /*dev*/ ) |
21 | : QObject() | 22 | : QObject() |
22 | { | 23 | { |
23 | m_hcitool = 0; | 24 | m_hcitool = 0; |
24 | m_sdp = 0; | 25 | m_sdp = 0; |
25 | } | 26 | } |
26 | Manager::Manager() | 27 | Manager::Manager() |
27 | : QObject() | 28 | : QObject() |
28 | { | 29 | { |
29 | m_hcitool = 0; | 30 | m_hcitool = 0; |
30 | m_sdp = 0; | 31 | m_sdp = 0; |
31 | } | 32 | } |
32 | Manager::~Manager(){ | 33 | Manager::~Manager(){ |
33 | delete m_hcitool; | 34 | delete m_hcitool; |
34 | delete m_sdp; | 35 | delete m_sdp; |
35 | } | 36 | } |
36 | void Manager::setDevice( const QString& dev ){ | 37 | void Manager::setDevice( const QString& dev ){ |
37 | m_device = dev; | 38 | m_device = dev; |
38 | } | 39 | } |
39 | void Manager::setDevice( Device* /*dev*/ ){ | 40 | void Manager::setDevice( Device* /*dev*/ ){ |
40 | 41 | ||
41 | } | 42 | } |
42 | void Manager::isAvailable( const QString& device ){ | 43 | void Manager::isAvailable( const QString& device ){ |
43 | OProcess* l2ping = new OProcess(); | 44 | OProcess* l2ping = new OProcess(); |
44 | l2ping->setName( device.latin1() ); | 45 | l2ping->setName( device.latin1() ); |
45 | *l2ping << "l2ping" << "-c1" << device; | 46 | *l2ping << "l2ping" << "-c1" << device; |
46 | connect(l2ping, SIGNAL(processExited(Opie::Core::OProcess* ) ), | 47 | connect(l2ping, SIGNAL(processExited(Opie::Core::OProcess* ) ), |
47 | this, SLOT(slotProcessExited(Opie::Core::OProcess*) ) ); | 48 | this, SLOT(slotProcessExited(Opie::Core::OProcess*) ) ); |
48 | if (!l2ping->start() ) { | 49 | if (!l2ping->start() ) { |
49 | emit available( device, false ); | 50 | emit available( device, false ); |
50 | delete l2ping; | 51 | delete l2ping; |
51 | } | 52 | } |
52 | 53 | ||
53 | } | 54 | } |
54 | 55 | ||
55 | void Manager::isAvailable( Device* /*dev*/ ){ | 56 | void Manager::isAvailable( Device* /*dev*/ ){ |
56 | 57 | ||
57 | 58 | ||
58 | } | 59 | } |
59 | void Manager::searchDevices( const QString& device ){ | 60 | void Manager::searchDevices( const QString& device ){ |
60 | qWarning("search devices"); | 61 | owarn << "search devices" << oendl; |
61 | OProcess* hcitool = new OProcess(); | 62 | OProcess* hcitool = new OProcess(); |
62 | hcitool->setName( device.isEmpty() ? "hci0" : device.latin1() ); | 63 | hcitool->setName( device.isEmpty() ? "hci0" : device.latin1() ); |
63 | *hcitool << "hcitool" << "scan"; | 64 | *hcitool << "hcitool" << "scan"; |
64 | connect( hcitool, SIGNAL(processExited(Opie::Core::OProcess*) ) , | 65 | connect( hcitool, SIGNAL(processExited(Opie::Core::OProcess*) ) , |
65 | this, SLOT(slotHCIExited(Opie::Core::OProcess* ) ) ); | 66 | this, SLOT(slotHCIExited(Opie::Core::OProcess* ) ) ); |
66 | connect( hcitool, SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int ) ), | 67 | connect( hcitool, SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int ) ), |
67 | this, SLOT(slotHCIOut(Opie::Core::OProcess*, char*, int ) ) ); | 68 | this, SLOT(slotHCIOut(Opie::Core::OProcess*, char*, int ) ) ); |
68 | if (!hcitool->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) { | 69 | if (!hcitool->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) { |
69 | qWarning("could not start"); | 70 | owarn << "could not start" << oendl; |
70 | RemoteDevice::ValueList list; | 71 | RemoteDevice::ValueList list; |
71 | emit foundDevices( device, list ); | 72 | emit foundDevices( device, list ); |
72 | delete hcitool; | 73 | delete hcitool; |
73 | } | 74 | } |
74 | } | 75 | } |
75 | 76 | ||
76 | void Manager::searchDevices(Device* /*d*/ ){ | 77 | void Manager::searchDevices(Device* /*d*/ ){ |
77 | 78 | ||
78 | 79 | ||
79 | } | 80 | } |
80 | void Manager::addService(const QString& name ){ | 81 | void Manager::addService(const QString& name ){ |
81 | OProcess proc; | 82 | OProcess proc; |
82 | proc << "sdptool" << "add" << name; | 83 | proc << "sdptool" << "add" << name; |
83 | bool bo = true; | 84 | bool bo = true; |
84 | if (!proc.start(OProcess::DontCare ) ) | 85 | if (!proc.start(OProcess::DontCare ) ) |
85 | bo = false; | 86 | bo = false; |
86 | emit addedService( name, bo ); | 87 | emit addedService( name, bo ); |
87 | } | 88 | } |
88 | void Manager::addServices(const QStringList& list){ | 89 | void Manager::addServices(const QStringList& list){ |
89 | QStringList::ConstIterator it; | 90 | QStringList::ConstIterator it; |
90 | for (it = list.begin(); it != list.end(); ++it ) | 91 | for (it = list.begin(); it != list.end(); ++it ) |
91 | addService( (*it) ); | 92 | addService( (*it) ); |
92 | } | 93 | } |
93 | void Manager::removeService( const QString& name ){ | 94 | void Manager::removeService( const QString& name ){ |
94 | OProcess prc; | 95 | OProcess prc; |
95 | prc << "sdptool" << "del" << name; | 96 | prc << "sdptool" << "del" << name; |
96 | bool bo = true; | 97 | bool bo = true; |
97 | if (!prc.start(OProcess::DontCare ) ) | 98 | if (!prc.start(OProcess::DontCare ) ) |
98 | bo = false; | 99 | bo = false; |
99 | emit removedService( name, bo ); | 100 | emit removedService( name, bo ); |
100 | } | 101 | } |
101 | void Manager::removeServices( const QStringList& list){ | 102 | void Manager::removeServices( const QStringList& list){ |
102 | QStringList::ConstIterator it; | 103 | QStringList::ConstIterator it; |
103 | for (it = list.begin(); it != list.end(); ++it ) | 104 | for (it = list.begin(); it != list.end(); ++it ) |
104 | removeService( (*it) ); | 105 | removeService( (*it) ); |
105 | } | 106 | } |
106 | void Manager::searchServices( const QString& remDevice ){ | 107 | void Manager::searchServices( const QString& remDevice ){ |
107 | OProcess *m_sdp =new OProcess(); | 108 | OProcess *m_sdp =new OProcess(); |
108 | *m_sdp << "sdptool" << "browse" << remDevice; | 109 | *m_sdp << "sdptool" << "browse" << remDevice; |
109 | m_sdp->setName( remDevice.latin1() ); | 110 | m_sdp->setName( remDevice.latin1() ); |
110 | qWarning("search Services for %s", remDevice.latin1() ); | 111 | owarn << "search Services for " << remDevice.latin1() << oendl; |
111 | connect(m_sdp, SIGNAL(processExited(Opie::Core::OProcess*) ), | 112 | connect(m_sdp, SIGNAL(processExited(Opie::Core::OProcess*) ), |
112 | this, SLOT(slotSDPExited(Opie::Core::OProcess* ) ) ); | 113 | this, SLOT(slotSDPExited(Opie::Core::OProcess* ) ) ); |
113 | connect(m_sdp, SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int ) ), | 114 | connect(m_sdp, SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int ) ), |
114 | this, SLOT(slotSDPOut(Opie::Core::OProcess*, char*, int) ) ); | 115 | this, SLOT(slotSDPOut(Opie::Core::OProcess*, char*, int) ) ); |
115 | if (!m_sdp->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) { | 116 | if (!m_sdp->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) { |
116 | qWarning("could not start sdptool" ); | 117 | owarn << "could not start sdptool" << oendl; |
117 | delete m_sdp; | 118 | delete m_sdp; |
118 | Services::ValueList list; | 119 | Services::ValueList list; |
119 | emit foundServices( remDevice, list ); | 120 | emit foundServices( remDevice, list ); |
120 | } | 121 | } |
121 | } | 122 | } |
122 | void Manager::searchServices( const RemoteDevice& dev){ | 123 | void Manager::searchServices( const RemoteDevice& dev){ |
123 | searchServices( dev.mac() ); | 124 | searchServices( dev.mac() ); |
124 | } | 125 | } |
125 | QString Manager::toDevice( const QString& /*mac*/ ){ | 126 | QString Manager::toDevice( const QString& /*mac*/ ){ |
126 | return QString::null; | 127 | return QString::null; |
127 | } | 128 | } |
128 | QString Manager::toMac( const QString &/*device*/ ){ | 129 | QString Manager::toMac( const QString &/*device*/ ){ |
129 | return QString::null; | 130 | return QString::null; |
130 | } | 131 | } |
131 | void Manager::slotProcessExited(OProcess* proc ) { | 132 | void Manager::slotProcessExited(OProcess* proc ) { |
132 | bool conn= false; | 133 | bool conn= false; |
133 | if (proc->normalExit() && proc->exitStatus() == 0 ) | 134 | if (proc->normalExit() && proc->exitStatus() == 0 ) |
134 | conn = true; | 135 | conn = true; |
135 | 136 | ||
136 | QString name = QString::fromLatin1(proc->name() ); | 137 | QString name = QString::fromLatin1(proc->name() ); |
137 | emit available( name, conn ); | 138 | emit available( name, conn ); |
138 | delete proc; | 139 | delete proc; |
139 | } | 140 | } |
140 | void Manager::slotSDPOut(OProcess* proc, char* ch, int len) | 141 | void Manager::slotSDPOut(OProcess* proc, char* ch, int len) |
141 | { | 142 | { |
142 | QCString str(ch, len+1 ); | 143 | QCString str(ch, len+1 ); |
143 | qWarning("SDP:%s", str.data() ); | 144 | owarn << "SDP:" << str.data() << oendl; |
144 | QMap<QString, QString>::Iterator it; | 145 | QMap<QString, QString>::Iterator it; |
145 | it = m_out.find(proc->name() ); | 146 | it = m_out.find(proc->name() ); |
146 | QString string; | 147 | QString string; |
147 | if ( it != m_out.end() ) { | 148 | if ( it != m_out.end() ) { |
148 | string = it.data(); | 149 | string = it.data(); |
149 | } | 150 | } |
150 | string.append( str ); | 151 | string.append( str ); |
151 | m_out.replace( proc->name(), string ); | 152 | m_out.replace( proc->name(), string ); |
152 | 153 | ||
153 | } | 154 | } |
154 | void Manager::slotSDPExited( OProcess* proc) | 155 | void Manager::slotSDPExited( OProcess* proc) |
155 | { | 156 | { |
156 | qWarning("proc name %s", proc->name() ); | 157 | owarn << "proc name " << proc->name() << oendl; |
157 | Services::ValueList list; | 158 | Services::ValueList list; |
158 | if (proc->normalExit() ) { | 159 | if (proc->normalExit() ) { |
159 | QMap<QString, QString>::Iterator it = m_out.find( proc->name() ); | 160 | QMap<QString, QString>::Iterator it = m_out.find( proc->name() ); |
160 | if ( it != m_out.end() ) { | 161 | if ( it != m_out.end() ) { |
161 | qWarning("found process" ); | 162 | owarn << "found process" << oendl; |
162 | list = parseSDPOutput( it.data() ); | 163 | list = parseSDPOutput( it.data() ); |
163 | m_out.remove( it ); | 164 | m_out.remove( it ); |
164 | } | 165 | } |
165 | } | 166 | } |
166 | emit foundServices( proc->name(), list ); | 167 | emit foundServices( proc->name(), list ); |
167 | delete proc; | 168 | delete proc; |
168 | } | 169 | } |
169 | Services::ValueList Manager::parseSDPOutput( const QString& out ) { | 170 | Services::ValueList Manager::parseSDPOutput( const QString& out ) { |
170 | Services::ValueList list; | 171 | Services::ValueList list; |
171 | qWarning("parsing output" ); | 172 | owarn << "parsing output" << oendl; |
172 | Parser parser( out ); | 173 | Parser parser( out ); |
173 | list = parser.services(); | 174 | list = parser.services(); |
174 | return list; | 175 | return list; |
175 | } | 176 | } |
176 | 177 | ||
177 | void Manager::slotHCIExited(OProcess* proc ) { | 178 | void Manager::slotHCIExited(OProcess* proc ) { |
178 | qWarning("process exited"); | 179 | owarn << "process exited" << oendl; |
179 | RemoteDevice::ValueList list; | 180 | RemoteDevice::ValueList list; |
180 | if (proc->normalExit() ) { | 181 | if (proc->normalExit() ) { |
181 | qWarning("normalExit %s", proc->name() ); | 182 | owarn << "normalExit " << proc->name() << oendl; |
182 | QMap<QString, QString>::Iterator it = m_devices.find(proc->name() ); | 183 | QMap<QString, QString>::Iterator it = m_devices.find(proc->name() ); |
183 | if (it != m_devices.end() ) { | 184 | if (it != m_devices.end() ) { |
184 | qWarning("!= end ;)"); | 185 | owarn << "!= end ;)" << oendl; |
185 | list = parseHCIOutput( it.data() ); | 186 | list = parseHCIOutput( it.data() ); |
186 | m_devices.remove( it ); | 187 | m_devices.remove( it ); |
187 | } | 188 | } |
188 | } | 189 | } |
189 | emit foundDevices( proc->name(), list ); | 190 | emit foundDevices( proc->name(), list ); |
190 | delete proc; | 191 | delete proc; |
191 | } | 192 | } |
192 | void Manager::slotHCIOut(OProcess* proc, char* ch, int len) { | 193 | void Manager::slotHCIOut(OProcess* proc, char* ch, int len) { |
193 | QCString str( ch, len+1 ); | 194 | QCString str( ch, len+1 ); |
194 | qWarning("hci: %s", str.data() ); | 195 | owarn << "hci: " << str.data() oendl; |
195 | QMap<QString, QString>::Iterator it; | 196 | QMap<QString, QString>::Iterator it; |
196 | it = m_devices.find( proc->name() ); | 197 | it = m_devices.find( proc->name() ); |
197 | qWarning("proc->name %s", proc->name() ); | 198 | owarn << "proc->name " << proc->name() << oendl; |
198 | QString string; | 199 | QString string; |
199 | if (it != m_devices.end() ) { | 200 | if (it != m_devices.end() ) { |
200 | qWarning("slotHCIOut "); | 201 | owarn << "slotHCIOut " << oendl; |
201 | string = it.data(); | 202 | string = it.data(); |
202 | } | 203 | } |
203 | string.append( str ); | 204 | string.append( str ); |
204 | 205 | ||
205 | m_devices.replace( proc->name(), string ); | 206 | m_devices.replace( proc->name(), string ); |
206 | } | 207 | } |
207 | RemoteDevice::ValueList Manager::parseHCIOutput(const QString& output ) { | 208 | RemoteDevice::ValueList Manager::parseHCIOutput(const QString& output ) { |
208 | qWarning("parseHCI %s", output.latin1() ); | 209 | owarn << "parseHCI " << output.latin1() << oendl; |
209 | RemoteDevice::ValueList list; | 210 | RemoteDevice::ValueList list; |
210 | QStringList strList = QStringList::split('\n', output ); | 211 | QStringList strList = QStringList::split('\n', output ); |
211 | QStringList::Iterator it; | 212 | QStringList::Iterator it; |
212 | QString str; | 213 | QString str; |
213 | for ( it = strList.begin(); it != strList.end(); ++it ) { | 214 | for ( it = strList.begin(); it != strList.end(); ++it ) { |
214 | str = (*it).stripWhiteSpace(); | 215 | str = (*it).stripWhiteSpace(); |
215 | qWarning("OpieTooth %s", str.latin1() ); | 216 | owarn << "OpieTooth " << str.latin1() << oendl; |
216 | int pos = str.findRev(':' ); | 217 | int pos = str.findRev(':' ); |
217 | if ( pos > 0 ) { | 218 | if ( pos > 0 ) { |
218 | QString mac = str.left(17 ); | 219 | QString mac = str.left(17 ); |
219 | str.remove( 0, 17 ); | 220 | str.remove( 0, 17 ); |
220 | qWarning("mac %s", mac.latin1() ); | 221 | owarn << "mac " << mac.latin1() << oendl; |
221 | qWarning("rest:%s", str.latin1() ); | 222 | owarn << "rest: " << str.latin1() << oendl; |
222 | RemoteDevice rem( mac , str.stripWhiteSpace() ); | 223 | RemoteDevice rem( mac , str.stripWhiteSpace() ); |
223 | list.append( rem ); | 224 | list.append( rem ); |
224 | } | 225 | } |
225 | } | 226 | } |
226 | return list; | 227 | return list; |
227 | } | 228 | } |
228 | 229 | ||
229 | ////// hcitool cc and hcitool con | 230 | ////// hcitool cc and hcitool con |
230 | 231 | ||
231 | /** | 232 | /** |
232 | * Create it on the stack as don't care | 233 | * Create it on the stack as don't care |
233 | * so we don't need to care for it | 234 | * so we don't need to care for it |
234 | * cause hcitool gets reparented | 235 | * cause hcitool gets reparented |
235 | */ | 236 | */ |
236 | void Manager::connectTo( const QString& mac) { | 237 | void Manager::connectTo( const QString& mac) { |
237 | OProcess proc; | 238 | OProcess proc; |
238 | proc << "hcitool"; | 239 | proc << "hcitool"; |
239 | proc << "cc"; | 240 | proc << "cc"; |
240 | proc << mac; | 241 | proc << mac; |
241 | proc.start(OProcess::DontCare); // the lib does not care at this point | 242 | proc.start(OProcess::DontCare); // the lib does not care at this point |
242 | } | 243 | } |
243 | 244 | ||
244 | 245 | ||
245 | void Manager::searchConnections() { | 246 | void Manager::searchConnections() { |
246 | qWarning("searching connections?"); | 247 | owarn << "searching connections?" << oendl; |
247 | OProcess* proc = new OProcess(); | 248 | OProcess* proc = new OProcess(); |
248 | m_hcitoolCon = QString::null; | 249 | m_hcitoolCon = QString::null; |
249 | 250 | ||
250 | connect(proc, SIGNAL(processExited(Opie::Core::OProcess*) ), | 251 | connect(proc, SIGNAL(processExited(Opie::Core::OProcess*) ), |
251 | this, SLOT(slotConnectionExited( Opie::Core::OProcess*) ) ); | 252 | this, SLOT(slotConnectionExited( Opie::Core::OProcess*) ) ); |
252 | connect(proc, SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int) ), | 253 | connect(proc, SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int) ), |
253 | this, SLOT(slotConnectionOutput(Opie::Core::OProcess*, char*, int) ) ); | 254 | this, SLOT(slotConnectionOutput(Opie::Core::OProcess*, char*, int) ) ); |
254 | *proc << "hcitool"; | 255 | *proc << "hcitool"; |
255 | *proc << "con"; | 256 | *proc << "con"; |
256 | 257 | ||
257 | if (!proc->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) { | 258 | if (!proc->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) { |
258 | ConnectionState::ValueList list; | 259 | ConnectionState::ValueList list; |
259 | emit connections( list ); | 260 | emit connections( list ); |
260 | delete proc; | 261 | delete proc; |
261 | } | 262 | } |
262 | } | 263 | } |
263 | void Manager::slotConnectionExited( OProcess* proc ) { | 264 | void Manager::slotConnectionExited( OProcess* proc ) { |
264 | ConnectionState::ValueList list; | 265 | ConnectionState::ValueList list; |
265 | list = parseConnections( m_hcitoolCon ); | 266 | list = parseConnections( m_hcitoolCon ); |
266 | emit connections(list ); | 267 | emit connections(list ); |
267 | delete proc; | 268 | delete proc; |
268 | } | 269 | } |
269 | void Manager::slotConnectionOutput(OProcess* /*proc*/, char* cha, int len) { | 270 | void Manager::slotConnectionOutput(OProcess* /*proc*/, char* cha, int len) { |
270 | QCString str(cha, len ); | 271 | QCString str(cha, len ); |
271 | m_hcitoolCon.append( str ); | 272 | m_hcitoolCon.append( str ); |
272 | //delete proc; | 273 | //delete proc; |
273 | } | 274 | } |
274 | ConnectionState::ValueList Manager::parseConnections( const QString& out ) { | 275 | ConnectionState::ValueList Manager::parseConnections( const QString& out ) { |
275 | ConnectionState::ValueList list2; | 276 | ConnectionState::ValueList list2; |
276 | QStringList list = QStringList::split('\n', out ); | 277 | QStringList list = QStringList::split('\n', out ); |
277 | QStringList::Iterator it; | 278 | QStringList::Iterator it; |
278 | // remove the first line ( "Connections:") | 279 | // remove the first line ( "Connections:") |
279 | it = list.begin(); | 280 | it = list.begin(); |
280 | it = list.remove( it ); | 281 | it = list.remove( it ); |
281 | for (; it != list.end(); ++it ) { | 282 | for (; it != list.end(); ++it ) { |
282 | QString row = (*it).stripWhiteSpace(); | 283 | QString row = (*it).stripWhiteSpace(); |
283 | QStringList value = QStringList::split(' ', row ); | 284 | QStringList value = QStringList::split(' ', row ); |
284 | qWarning("0: %s", value[0].latin1() ); | 285 | owan << "0: %s" << value[0].latin1() << oendl; |
285 | qWarning("1: %s", value[1].latin1() ); | 286 | owan << "1: %s" << value[1].latin1() << oendl; |
286 | qWarning("2: %s", value[2].latin1() ); | 287 | owan << "2: %s" << value[2].latin1() << oendl; |
287 | qWarning("3: %s", value[3].latin1() ); | 288 | owan << "3: %s" << value[3].latin1() << oendl; |
288 | qWarning("4: %s", value[4].latin1() ); | 289 | owan << "4: %s" << value[4].latin1() << oendl; |
289 | qWarning("5: %s", value[5].latin1() ); | 290 | owan << "5: %s" << value[5].latin1() << oendl; |
290 | qWarning("6: %s", value[6].latin1() ); | 291 | owan << "6: %s" << value[6].latin1() << oendl; |
291 | qWarning("7: %s", value[7].latin1() ); | 292 | owan << "7: %s" << value[7].latin1() << oendl; |
292 | qWarning("8: %s", value[8].latin1() ); | 293 | owan << "8: %s" << value[8].latin1() << oendl; |
293 | ConnectionState con; | 294 | ConnectionState con; |
294 | con.setDirection( value[0] == QString::fromLatin1("<") ? Outgoing : Incoming ); | 295 | con.setDirection( value[0] == QString::fromLatin1("<") ? Outgoing : Incoming ); |
295 | con.setConnectionMode( value[1] ); | 296 | con.setConnectionMode( value[1] ); |
296 | con.setMac( value[2] ); | 297 | con.setMac( value[2] ); |
297 | con.setHandle( value[4].toInt() ); | 298 | con.setHandle( value[4].toInt() ); |
298 | con.setState( value[6].toInt() ); | 299 | con.setState( value[6].toInt() ); |
299 | con.setLinkMode( value[8] == QString::fromLatin1("MASTER") ? Master : Client ); | 300 | con.setLinkMode( value[8] == QString::fromLatin1("MASTER") ? Master : Client ); |
300 | list2.append( con ); | 301 | list2.append( con ); |
301 | } | 302 | } |
302 | return list2; | 303 | return list2; |
303 | } | 304 | } |
304 | 305 | ||
305 | void Manager::signalStrength( const QString &mac ) { | 306 | void Manager::signalStrength( const QString &mac ) { |
306 | 307 | ||
307 | OProcess* sig_proc = new OProcess(); | 308 | OProcess* sig_proc = new OProcess(); |
308 | 309 | ||
309 | connect(sig_proc, SIGNAL(processExited(Opie::Core::OProcess*) ), | 310 | connect(sig_proc, SIGNAL(processExited(Opie::Core::OProcess*) ), |
310 | this, SLOT(slotSignalStrengthExited( Opie::Core::OProcess*) ) ); | 311 | this, SLOT(slotSignalStrengthExited( Opie::Core::OProcess*) ) ); |
311 | connect(sig_proc, SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int) ), | 312 | connect(sig_proc, SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int) ), |
312 | this, SLOT(slotSignalStrengthOutput(Opie::Core::OProcess*, char*, int) ) ); | 313 | this, SLOT(slotSignalStrengthOutput(Opie::Core::OProcess*, char*, int) ) ); |
313 | *sig_proc << "hcitool"; | 314 | *sig_proc << "hcitool"; |
314 | *sig_proc << "lq"; | 315 | *sig_proc << "lq"; |
315 | *sig_proc << mac; | 316 | *sig_proc << mac; |
316 | 317 | ||
317 | sig_proc->setName( mac.latin1() ); | 318 | sig_proc->setName( mac.latin1() ); |
318 | 319 | ||
319 | if (!sig_proc->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) { | 320 | if (!sig_proc->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) { |
320 | emit signalStrength( mac, "-1" ); | 321 | emit signalStrength( mac, "-1" ); |
321 | delete sig_proc; | 322 | delete sig_proc; |
322 | } | 323 | } |
323 | } | 324 | } |
324 | 325 | ||
325 | void Manager::slotSignalStrengthOutput(OProcess* proc, char* cha, int len) { | 326 | void Manager::slotSignalStrengthOutput(OProcess* proc, char* cha, int len) { |
326 | QCString str(cha, len ); | 327 | QCString str(cha, len ); |
327 | QString temp = QString(str).stripWhiteSpace(); | 328 | QString temp = QString(str).stripWhiteSpace(); |
328 | QStringList value = QStringList::split(' ', temp ); | 329 | QStringList value = QStringList::split(' ', temp ); |
329 | emit signalStrength( proc->name(), value[2].latin1() ); | 330 | emit signalStrength( proc->name(), value[2].latin1() ); |
330 | } | 331 | } |
331 | 332 | ||
332 | 333 | ||
333 | void Manager::slotSignalStrengthExited( OProcess* proc ) { | 334 | void Manager::slotSignalStrengthExited( OProcess* proc ) { |
334 | delete proc; | 335 | delete proc; |
335 | } | 336 | } |
diff --git a/noncore/net/opietooth/lib/parser.cc b/noncore/net/opietooth/lib/parser.cc index 8baf284..7e95907 100644 --- a/noncore/net/opietooth/lib/parser.cc +++ b/noncore/net/opietooth/lib/parser.cc | |||
@@ -1,199 +1,205 @@ | |||
1 | 1 | ||
2 | #include "parser.h" | ||
3 | |||
4 | /* OPIE */ | ||
5 | #include <opie2/odebug.h> | ||
6 | using namespace Opie::Core; | ||
7 | |||
8 | /* QT */ | ||
2 | #include <qstringlist.h> | 9 | #include <qstringlist.h> |
3 | 10 | ||
4 | #include "parser.h" | ||
5 | 11 | ||
6 | using namespace OpieTooth; | 12 | using namespace OpieTooth; |
7 | 13 | ||
8 | namespace { | 14 | namespace { |
9 | 15 | ||
10 | 16 | ||
11 | // "Test Foo Bar" (0x3456) | 17 | // "Test Foo Bar" (0x3456) |
12 | // @param ret Test Foo Bar | 18 | // @param ret Test Foo Bar |
13 | // @eturn 13398 | 19 | // @eturn 13398 |
14 | // tactic find " ( | 20 | // tactic find " ( |
15 | int convert( const QString& line, QString& ret ) { | 21 | int convert( const QString& line, QString& ret ) { |
16 | // qWarning("called"); | 22 | // owarn << "called" << oendl; |
17 | ret = QString::null; | 23 | ret = QString::null; |
18 | int i = 0; | 24 | int i = 0; |
19 | int pos = line.findRev("\" ("); | 25 | int pos = line.findRev("\" ("); |
20 | if ( pos > 0 ) { // it shouldn't be at pos 0 | 26 | if ( pos > 0 ) { // it shouldn't be at pos 0 |
21 | ret = line.left(pos ).stripWhiteSpace(); | 27 | ret = line.left(pos ).stripWhiteSpace(); |
22 | // qWarning("ret: %s", ret.latin1() ); | 28 | // owarn << "ret: " << ret.latin1() << oendl; |
23 | ret = ret.replace(QRegExp("[\"]"), ""); | 29 | ret = ret.replace(QRegExp("[\"]"), ""); |
24 | //qWarning("ret: %s", ret.latin1() ); | 30 | //owarn << "ret: " << ret.latin1() << oendl; |
25 | QString dummy = line.mid(pos + 5 ); | 31 | QString dummy = line.mid(pos + 5 ); |
26 | //qWarning("dummy: %s", dummy.latin1() ); | 32 | //owarn << "dummy: " << dummy.latin1() << oendl; |
27 | dummy = dummy.replace(QRegExp("[)]"), ""); | 33 | dummy = dummy.replace(QRegExp("[)]"), ""); |
28 | //qWarning("dummy: %s", dummy.latin1() ); | 34 | //owarn << "dummy: " << dummy.latin1() << oendl; |
29 | // dummy = dummy.remove( dummy.length() -2, 1 ); // remove the ) | 35 | // dummy = dummy.remove( dummy.length() -2, 1 ); // remove the ) |
30 | bool ok; | 36 | bool ok; |
31 | i = dummy.toInt(&ok, 16 ); | 37 | i = dummy.toInt(&ok, 16 ); |
32 | //if (ok ) { | 38 | //if (ok ) { |
33 | // qWarning("converted %d", i); | 39 | // owarn << "converted " << i << oendl; |
34 | //}else qWarning("failed" ); | 40 | //}else owarn << "failed" << oendl; |
35 | //qWarning("exiting"); | 41 | //owarn << "exiting" << oendl; |
36 | return i; | 42 | return i; |
37 | } | 43 | } |
38 | //qWarning("output %d", i ); | 44 | //owarn << "output " << i << oendl; |
39 | return i; | 45 | return i; |
40 | } | 46 | } |
41 | 47 | ||
42 | }; | 48 | }; |
43 | 49 | ||
44 | 50 | ||
45 | Parser::Parser(const QString& output ) { | 51 | Parser::Parser(const QString& output ) { |
46 | parse( output ); | 52 | parse( output ); |
47 | } | 53 | } |
48 | void Parser::setText(const QString& output) { | 54 | void Parser::setText(const QString& output) { |
49 | parse( output ); | 55 | parse( output ); |
50 | } | 56 | } |
51 | Services::ValueList Parser::services() const { | 57 | Services::ValueList Parser::services() const { |
52 | return m_list; | 58 | return m_list; |
53 | } | 59 | } |
54 | void Parser::parse( const QString& string) { | 60 | void Parser::parse( const QString& string) { |
55 | m_list.clear(); | 61 | m_list.clear(); |
56 | m_complete = true; | 62 | m_complete = true; |
57 | QStringList list = QStringList::split('\n', string,TRUE ); | 63 | QStringList list = QStringList::split('\n', string,TRUE ); |
58 | QStringList::Iterator it; | 64 | QStringList::Iterator it; |
59 | for (it = list.begin(); it != list.end(); ++it ) { | 65 | for (it = list.begin(); it != list.end(); ++it ) { |
60 | //qWarning("line:%s:line", (*it).latin1() ); | 66 | //owarn << "line:" << (*it).latin1() << oendl; |
61 | if ( (*it).startsWith("Browsing") ) continue; | 67 | if ( (*it).startsWith("Browsing") ) continue; |
62 | 68 | ||
63 | if ( (*it).stripWhiteSpace().isEmpty() ) { // line is empty because a new Service begins | 69 | if ( (*it).stripWhiteSpace().isEmpty() ) { // line is empty because a new Service begins |
64 | qWarning("could add"); | 70 | owarn << "could add" << oendl; |
65 | // now see if complete and add | 71 | // now see if complete and add |
66 | if (m_complete ) { | 72 | if (m_complete ) { |
67 | if (!m_item.serviceName().isEmpty() ) | 73 | if (!m_item.serviceName().isEmpty() ) |
68 | m_list.append( m_item ); | 74 | m_list.append( m_item ); |
69 | Services serv; | 75 | Services serv; |
70 | m_item = serv; | 76 | m_item = serv; |
71 | m_complete = true; | 77 | m_complete = true; |
72 | continue; | 78 | continue; |
73 | } | 79 | } |
74 | } | 80 | } |
75 | if (parseName( (*it) ) ) ;//continue; | 81 | if (parseName( (*it) ) ) ;//continue; |
76 | if (parseRecHandle( (*it) ) ) ;//continue; | 82 | if (parseRecHandle( (*it) ) ) ;//continue; |
77 | if (parseClassId( (*it) ) ) ;//continue; | 83 | if (parseClassId( (*it) ) ) ;//continue; |
78 | if (parseProtocol( (*it) ) ) ;//continue; | 84 | if (parseProtocol( (*it) ) ) ;//continue; |
79 | if (parseProfile( (*it) ) ) ;//continue; | 85 | if (parseProfile( (*it) ) ) ;//continue; |
80 | } | 86 | } |
81 | // missed the last one | 87 | // missed the last one |
82 | if (m_complete) { | 88 | if (m_complete) { |
83 | // qWarning("adding"); | 89 | // owarn << "adding" << oendl; |
84 | if (!m_item.serviceName().isEmpty() ) | 90 | if (!m_item.serviceName().isEmpty() ) |
85 | m_list.append(m_item ); | 91 | m_list.append(m_item ); |
86 | } | 92 | } |
87 | QValueList<Services>::Iterator it2; | 93 | QValueList<Services>::Iterator it2; |
88 | 94 | ||
89 | if (m_list.isEmpty() ) | 95 | if (m_list.isEmpty() ) |
90 | qWarning("m_list is empty"); | 96 | owarn << "m_list is empty" << oendl; |
91 | for (it2 = m_list.begin(); it2 != m_list.end(); ++it2 ) { | 97 | for (it2 = m_list.begin(); it2 != m_list.end(); ++it2 ) { |
92 | qWarning("name %s", (*it2).serviceName().latin1() ); | 98 | owarn << "name " << (*it2).serviceName().latin1() << oendl; |
93 | } | 99 | } |
94 | } | 100 | } |
95 | bool Parser::parseName( const QString& str) { | 101 | bool Parser::parseName( const QString& str) { |
96 | if (str.startsWith("Service Name:") ) { | 102 | if (str.startsWith("Service Name:") ) { |
97 | m_item.setServiceName( str.mid(13).stripWhiteSpace() ); | 103 | m_item.setServiceName( str.mid(13).stripWhiteSpace() ); |
98 | qWarning(m_item.serviceName() ); | 104 | owarn << m_item.serviceName() << oendl; |
99 | return true; | 105 | return true; |
100 | } | 106 | } |
101 | return false; | 107 | return false; |
102 | } | 108 | } |
103 | bool Parser::parseRecHandle( const QString& str) { | 109 | bool Parser::parseRecHandle( const QString& str) { |
104 | if (str.startsWith("Service RecHandle:" ) ) { | 110 | if (str.startsWith("Service RecHandle:" ) ) { |
105 | QString out = str.mid(18 ).stripWhiteSpace(); | 111 | QString out = str.mid(18 ).stripWhiteSpace(); |
106 | qWarning("out %s", out.latin1() ); | 112 | owarn << "out " << out.latin1() << oendl; |
107 | int value = out.mid(2).toInt(&m_ok, 16 ); | 113 | int value = out.mid(2).toInt(&m_ok, 16 ); |
108 | if (m_ok && (value != -1) ) | 114 | if (m_ok && (value != -1) ) |
109 | m_complete = true; | 115 | m_complete = true; |
110 | else | 116 | else |
111 | m_complete = false; | 117 | m_complete = false; |
112 | qWarning("rec handle %d", value); | 118 | owarn << "rec handle " << value << oendl; |
113 | m_item.setRecHandle( value ); | 119 | m_item.setRecHandle( value ); |
114 | return true; | 120 | return true; |
115 | 121 | ||
116 | } | 122 | } |
117 | return false; | 123 | return false; |
118 | } | 124 | } |
119 | bool Parser::parseClassId( const QString& str) { | 125 | bool Parser::parseClassId( const QString& str) { |
120 | if (str.startsWith("Service Class ID List:") ) { | 126 | if (str.startsWith("Service Class ID List:") ) { |
121 | qWarning("found class id" ); | 127 | owarn << "found class id" << oendl; |
122 | qWarning("line:%s", str.latin1() ); | 128 | owarn << "line: " << str.latin1() << oendl; |
123 | m_classOver = true; | 129 | m_classOver = true; |
124 | return true; | 130 | return true; |
125 | }else if ( m_classOver && str.startsWith(" " ) ){ // ok now are the informations in place | 131 | }else if ( m_classOver && str.startsWith(" " ) ){ // ok now are the informations in place |
126 | qWarning("line with class id" ); | 132 | owarn << "line with class id" << oendl; |
127 | qWarning("%s",str.latin1() ); | 133 | owarn << str.latin1() << oendl; |
128 | 134 | ||
129 | // "Obex Object Push" (0x1105) | 135 | // "Obex Object Push" (0x1105) |
130 | // find backwards the " and the from 0 to pos and the mid pos+1 | 136 | // find backwards the " and the from 0 to pos and the mid pos+1 |
131 | // then stripWhiteSpace add name replace '"' with "" | 137 | // then stripWhiteSpace add name replace '"' with "" |
132 | // and then convert 0x1105 toInt() | 138 | // and then convert 0x1105 toInt() |
133 | QString classes; | 139 | QString classes; |
134 | int ids; | 140 | int ids; |
135 | ids = convert( str, classes ); | 141 | ids = convert( str, classes ); |
136 | qWarning("ids %d", ids ); | 142 | owarn << "ids " << ids << oendl; |
137 | m_item.insertClassId( ids, classes ); | 143 | m_item.insertClassId( ids, classes ); |
138 | 144 | ||
139 | return true; | 145 | return true; |
140 | }else{ | 146 | }else{ |
141 | qWarning("Else %d", m_classOver ); | 147 | owarn << "Else " << m_classOver << oendl; |
142 | m_classOver = false; | 148 | m_classOver = false; |
143 | } | 149 | } |
144 | return false; | 150 | return false; |
145 | } | 151 | } |
146 | bool Parser::parseProtocol( const QString& str) { | 152 | bool Parser::parseProtocol( const QString& str) { |
147 | if (str.startsWith("Protocol Descriptor List:") ) { | 153 | if (str.startsWith("Protocol Descriptor List:") ) { |
148 | m_protocolOver = true; | 154 | m_protocolOver = true; |
149 | m_protocolAdded = false; | 155 | m_protocolAdded = false; |
150 | return true; | 156 | return true; |
151 | 157 | ||
152 | }else if (m_protocolOver && str.startsWith(" ") ) { // "L2CAP" (0x0100) | 158 | }else if (m_protocolOver && str.startsWith(" ") ) { // "L2CAP" (0x0100) |
153 | qWarning("double protocol filter"); | 159 | owarn << "double protocol filter" << oendl; |
154 | 160 | ||
155 | if (!m_protocolAdded ) { // the protocol does neither supply a channel nor port so add it now | 161 | if (!m_protocolAdded ) { // the protocol does neither supply a channel nor port so add it now |
156 | Services::ProtocolDescriptor desc( m_protName, m_protId ); | 162 | Services::ProtocolDescriptor desc( m_protName, m_protId ); |
157 | m_item.insertProtocolDescriptor( desc ); | 163 | m_item.insertProtocolDescriptor( desc ); |
158 | } | 164 | } |
159 | m_protocolAdded = false; | 165 | m_protocolAdded = false; |
160 | { // the find function | 166 | { // the find function |
161 | m_protId = convert(str, m_protName ); | 167 | m_protId = convert(str, m_protName ); |
162 | } | 168 | } |
163 | return true; | 169 | return true; |
164 | }else if (m_protocolOver && str.startsWith(" ") ) { | 170 | }else if (m_protocolOver && str.startsWith(" ") ) { |
165 | qWarning("tripple protocol filter"); | 171 | owarn << "tripple protocol filter" << oendl; |
166 | m_protocolAdded = true; | 172 | m_protocolAdded = true; |
167 | QString dummy = str.stripWhiteSpace(); | 173 | QString dummy = str.stripWhiteSpace(); |
168 | int pos = dummy.findRev(':'); | 174 | int pos = dummy.findRev(':'); |
169 | if ( pos > -1 ) { | 175 | if ( pos > -1 ) { |
170 | int port = dummy.mid(pos+1 ).stripWhiteSpace().toInt(); | 176 | int port = dummy.mid(pos+1 ).stripWhiteSpace().toInt(); |
171 | Services::ProtocolDescriptor desc( m_protName, m_protId, port ); | 177 | Services::ProtocolDescriptor desc( m_protName, m_protId, port ); |
172 | m_item.insertProtocolDescriptor( desc ); | 178 | m_item.insertProtocolDescriptor( desc ); |
173 | } | 179 | } |
174 | return true; | 180 | return true; |
175 | }else if (m_protocolOver ) { | 181 | }else if (m_protocolOver ) { |
176 | m_protocolOver = false; | 182 | m_protocolOver = false; |
177 | } | 183 | } |
178 | return false; | 184 | return false; |
179 | } | 185 | } |
180 | bool Parser::parseProfile( const QString& str) { | 186 | bool Parser::parseProfile( const QString& str) { |
181 | if (str.startsWith("Profile Descriptor List:") ) { | 187 | if (str.startsWith("Profile Descriptor List:") ) { |
182 | m_profOver = true; | 188 | m_profOver = true; |
183 | }else if ( m_profOver && str.startsWith(" ") ) { | 189 | }else if ( m_profOver && str.startsWith(" ") ) { |
184 | m_profId = convert( str, m_profName ); | 190 | m_profId = convert( str, m_profName ); |
185 | }else if ( m_profOver && str.startsWith(" ") ) { | 191 | }else if ( m_profOver && str.startsWith(" ") ) { |
186 | // now find | 192 | // now find |
187 | int pos = str.findRev(':'); | 193 | int pos = str.findRev(':'); |
188 | if ( pos > 0 ) { | 194 | if ( pos > 0 ) { |
189 | int dummy = str.mid(pos+1 ).stripWhiteSpace().toInt(); | 195 | int dummy = str.mid(pos+1 ).stripWhiteSpace().toInt(); |
190 | qWarning("dummyInt:%d", dummy ); | 196 | owarn << "dummyInt: " << dummy << oendl; |
191 | Services::ProfileDescriptor desc( m_profName, m_profId, dummy ); | 197 | Services::ProfileDescriptor desc( m_profName, m_profId, dummy ); |
192 | m_item.insertProfileDescriptor(desc); | 198 | m_item.insertProfileDescriptor(desc); |
193 | } | 199 | } |
194 | }else | 200 | }else |
195 | m_profOver = false; | 201 | m_profOver = false; |
196 | 202 | ||
197 | 203 | ||
198 | return false; | 204 | return false; |
199 | } | 205 | } |
diff --git a/noncore/settings/mediummount/mediumglobal.cc b/noncore/settings/mediummount/mediumglobal.cc index ab0b3af..0c6cf12 100644 --- a/noncore/settings/mediummount/mediumglobal.cc +++ b/noncore/settings/mediummount/mediumglobal.cc | |||
@@ -1,78 +1,83 @@ | |||
1 | 1 | ||
2 | #include "mediumglobal.h" | ||
3 | |||
4 | /* OPIE */ | ||
5 | #include <opie2/odebug.h> | ||
6 | using namespace Opie::Core; | ||
7 | #include <qpe/config.h> | ||
2 | 8 | ||
9 | /* QT */ | ||
3 | #include <qlineedit.h> | 10 | #include <qlineedit.h> |
4 | #include <qcheckbox.h> | 11 | #include <qcheckbox.h> |
5 | #include <qlabel.h> | 12 | #include <qlabel.h> |
6 | #include <qabstractlayout.h> // spacer item | 13 | #include <qabstractlayout.h> // spacer item |
7 | #include <qlayout.h> | 14 | #include <qlayout.h> |
8 | #include <qframe.h> | 15 | #include <qframe.h> |
9 | #include <qgroupbox.h> | 16 | #include <qgroupbox.h> |
10 | #include <qwhatsthis.h> | 17 | #include <qwhatsthis.h> |
11 | 18 | ||
12 | #include <qpe/config.h> | ||
13 | 19 | ||
14 | #include "mediumglobal.h" | ||
15 | 20 | ||
16 | using namespace MediumMountSetting; | 21 | using namespace MediumMountSetting; |
17 | 22 | ||
18 | /* TRANSLATOR MediumMountSetting::MediumGlobalWidget */ | 23 | /* TRANSLATOR MediumMountSetting::MediumGlobalWidget */ |
19 | 24 | ||
20 | MediumGlobalWidget::MediumGlobalWidget(QWidget *wid, const char *name ) | 25 | MediumGlobalWidget::MediumGlobalWidget(QWidget *wid, const char *name ) |
21 | : QWidget( wid, name, WStyle_ContextHelp ) | 26 | : QWidget( wid, name, WStyle_ContextHelp ) |
22 | { | 27 | { |
23 | m_config = 0; | 28 | m_config = 0; |
24 | initGUI(); | 29 | initGUI(); |
25 | readConfig(); | 30 | readConfig(); |
26 | 31 | ||
27 | } | 32 | } |
28 | void MediumGlobalWidget::initGUI() | 33 | void MediumGlobalWidget::initGUI() |
29 | { | 34 | { |
30 | m_layout = new QVBoxLayout(this ); | 35 | m_layout = new QVBoxLayout(this ); |
31 | m_layout->setMargin( 4 ); | 36 | m_layout->setMargin( 4 ); |
32 | // m_layout->setSpacing( 10 ); | 37 | // m_layout->setSpacing( 10 ); |
33 | 38 | ||
34 | 39 | ||
35 | m_label = new QLabel( this ); | 40 | m_label = new QLabel( this ); |
36 | m_label->setTextFormat( Qt::RichText ); | 41 | m_label->setTextFormat( Qt::RichText ); |
37 | m_label->setText( tr("") ); | 42 | m_label->setText( tr("") ); |
38 | QWhatsThis::add( this, tr("If a medium gets inserted into this device Opie " | 43 | QWhatsThis::add( this, tr("If a medium gets inserted into this device Opie " |
39 | "tries to search the medium for Documents. On " | 44 | "tries to search the medium for Documents. On " |
40 | "large mediums this can take some time. You can choose " | 45 | "large mediums this can take some time. You can choose " |
41 | "if Opie should scan for Documents globally or on a " | 46 | "if Opie should scan for Documents globally or on a " |
42 | "per medium level. You're also able to reconfigure " | 47 | "per medium level. You're also able to reconfigure " |
43 | "each medium.") ); | 48 | "each medium.") ); |
44 | 49 | ||
45 | m_layout->addWidget( m_label ); | 50 | m_layout->addWidget( m_label ); |
46 | 51 | ||
47 | m_check = new QCheckBox( tr("Enable medium checking" ), this ); | 52 | m_check = new QCheckBox( tr("Enable medium checking" ), this ); |
48 | connect( m_check, SIGNAL(stateChanged(int) ), | 53 | connect( m_check, SIGNAL(stateChanged(int) ), |
49 | this, SLOT(slotEnableChecking() ) ); | 54 | this, SLOT(slotEnableChecking() ) ); |
50 | m_layout->addWidget(m_check ); | 55 | m_layout->addWidget(m_check ); |
51 | 56 | ||
52 | m_frame = new QFrame(this, "Frame" ); | 57 | m_frame = new QFrame(this, "Frame" ); |
53 | m_frame->setFrameShape( QFrame::Box ); | 58 | m_frame->setFrameShape( QFrame::Box ); |
54 | m_frame->setFrameShadow( QFrame::Sunken ); | 59 | m_frame->setFrameShadow( QFrame::Sunken ); |
55 | 60 | ||
56 | m_box = new QVBoxLayout( m_frame ); | 61 | m_box = new QVBoxLayout( m_frame ); |
57 | m_box->setMargin( 5 ); | 62 | m_box->setMargin( 5 ); |
58 | m_useglobal = new QCheckBox( tr("Use global settings"), m_frame ); | 63 | m_useglobal = new QCheckBox( tr("Use global settings"), m_frame ); |
59 | connect( m_useglobal, SIGNAL( stateChanged(int) ), | 64 | connect( m_useglobal, SIGNAL( stateChanged(int) ), |
60 | this, SLOT( slotGlobalChanged() ) ); | 65 | this, SLOT( slotGlobalChanged() ) ); |
61 | 66 | ||
62 | m_box->addWidget( m_useglobal ); | 67 | m_box->addWidget( m_useglobal ); |
63 | 68 | ||
64 | m_global = new QGroupBox( tr("Which media files"), m_frame ); | 69 | m_global = new QGroupBox( tr("Which media files"), m_frame ); |
65 | m_frameLay = new QGridLayout(m_global, 4, 3 ); | 70 | m_frameLay = new QGridLayout(m_global, 4, 3 ); |
66 | m_frameLay->setMargin( 10 ); | 71 | m_frameLay->setMargin( 10 ); |
67 | 72 | ||
68 | QSpacerItem *item2 = new QSpacerItem( 5, 8, | 73 | QSpacerItem *item2 = new QSpacerItem( 5, 8, |
69 | QSizePolicy::Fixed, | 74 | QSizePolicy::Fixed, |
70 | QSizePolicy::Fixed ); | 75 | QSizePolicy::Fixed ); |
71 | m_audio = new QCheckBox( tr("Audio"), m_global ); | 76 | m_audio = new QCheckBox( tr("Audio"), m_global ); |
72 | m_all = new QCheckBox( tr("All") , m_global ); | 77 | m_all = new QCheckBox( tr("All") , m_global ); |
73 | m_image = new QCheckBox( tr("Image"), m_global ); | 78 | m_image = new QCheckBox( tr("Image"), m_global ); |
74 | m_text = new QCheckBox( tr("Text") , m_global ); | 79 | m_text = new QCheckBox( tr("Text") , m_global ); |
75 | m_video = new QCheckBox( tr("Video"), m_global ); | 80 | m_video = new QCheckBox( tr("Video"), m_global ); |
76 | 81 | ||
77 | connect(m_all, SIGNAL(stateChanged(int) ), | 82 | connect(m_all, SIGNAL(stateChanged(int) ), |
78 | this, SLOT(slotAllChanged() ) ); | 83 | this, SLOT(slotAllChanged() ) ); |
@@ -91,95 +96,95 @@ void MediumGlobalWidget::initGUI() | |||
91 | 96 | ||
92 | m_box->addWidget( m_global ); | 97 | m_box->addWidget( m_global ); |
93 | 98 | ||
94 | 99 | ||
95 | m_layout->addWidget( m_frame ); | 100 | m_layout->addWidget( m_frame ); |
96 | 101 | ||
97 | QSpacerItem *item1 = new QSpacerItem( 1, 24, | 102 | QSpacerItem *item1 = new QSpacerItem( 1, 24, |
98 | QSizePolicy::Fixed, | 103 | QSizePolicy::Fixed, |
99 | QSizePolicy::Expanding ); | 104 | QSizePolicy::Expanding ); |
100 | m_layout->addItem( item1 ); | 105 | m_layout->addItem( item1 ); |
101 | } | 106 | } |
102 | void MediumGlobalWidget::readConfig() | 107 | void MediumGlobalWidget::readConfig() |
103 | { | 108 | { |
104 | if( m_config == 0 ) | 109 | if( m_config == 0 ) |
105 | m_config = new Config("medium" ); | 110 | m_config = new Config("medium" ); |
106 | 111 | ||
107 | m_config->setGroup("main"); | 112 | m_config->setGroup("main"); |
108 | m_useglobal->setChecked( m_config->readBoolEntry("global", false ) ); | 113 | m_useglobal->setChecked( m_config->readBoolEntry("global", false ) ); |
109 | m_check->setChecked( m_config->readBoolEntry("use", true ) ); | 114 | m_check->setChecked( m_config->readBoolEntry("use", true ) ); |
110 | 115 | ||
111 | m_config->setGroup("mimetypes" ); | 116 | m_config->setGroup("mimetypes" ); |
112 | m_all->setChecked ( m_config->readBoolEntry("all", false ) ); | 117 | m_all->setChecked ( m_config->readBoolEntry("all", false ) ); |
113 | m_audio->setChecked( m_config->readBoolEntry("audio", true ) ); | 118 | m_audio->setChecked( m_config->readBoolEntry("audio", true ) ); |
114 | m_video->setChecked( m_config->readBoolEntry("video", true ) ); | 119 | m_video->setChecked( m_config->readBoolEntry("video", true ) ); |
115 | m_text->setChecked ( m_config->readBoolEntry("text", true ) ); | 120 | m_text->setChecked ( m_config->readBoolEntry("text", true ) ); |
116 | m_image->setChecked( m_config->readBoolEntry("image", true ) ); | 121 | m_image->setChecked( m_config->readBoolEntry("image", true ) ); |
117 | 122 | ||
118 | slotAllChanged(); | 123 | slotAllChanged(); |
119 | slotEnableChecking(); | 124 | slotEnableChecking(); |
120 | slotGlobalChanged(); | 125 | slotGlobalChanged(); |
121 | if( m_all->isChecked() ){ | 126 | if( m_all->isChecked() ){ |
122 | m_video->setEnabled( false ); | 127 | m_video->setEnabled( false ); |
123 | m_text->setEnabled( false ); | 128 | m_text->setEnabled( false ); |
124 | m_audio->setEnabled( false ); | 129 | m_audio->setEnabled( false ); |
125 | m_image->setEnabled( false ); | 130 | m_image->setEnabled( false ); |
126 | 131 | ||
127 | } | 132 | } |
128 | } | 133 | } |
129 | void MediumGlobalWidget::writeConfig() | 134 | void MediumGlobalWidget::writeConfig() |
130 | { | 135 | { |
131 | m_config->setGroup( "main" ); | 136 | m_config->setGroup( "main" ); |
132 | m_config->writeEntry("global", m_useglobal->isChecked() ); | 137 | m_config->writeEntry("global", m_useglobal->isChecked() ); |
133 | m_config->writeEntry("use", m_check->isChecked() ); | 138 | m_config->writeEntry("use", m_check->isChecked() ); |
134 | 139 | ||
135 | m_config->setGroup("mimetypes" ); | 140 | m_config->setGroup("mimetypes" ); |
136 | 141 | ||
137 | m_config->writeEntry("all", m_all->isChecked() ); | 142 | m_config->writeEntry("all", m_all->isChecked() ); |
138 | m_config->writeEntry("audio", m_audio->isChecked() ); | 143 | m_config->writeEntry("audio", m_audio->isChecked() ); |
139 | m_config->writeEntry("video", m_video->isChecked() ); | 144 | m_config->writeEntry("video", m_video->isChecked() ); |
140 | m_config->writeEntry("text", m_text->isChecked() ); | 145 | m_config->writeEntry("text", m_text->isChecked() ); |
141 | m_config->writeEntry("image", m_image->isChecked() ); | 146 | m_config->writeEntry("image", m_image->isChecked() ); |
142 | } | 147 | } |
143 | MediumGlobalWidget::~MediumGlobalWidget() | 148 | MediumGlobalWidget::~MediumGlobalWidget() |
144 | { | 149 | { |
145 | delete m_config; | 150 | delete m_config; |
146 | } | 151 | } |
147 | void MediumGlobalWidget::slotGlobalChanged() | 152 | void MediumGlobalWidget::slotGlobalChanged() |
148 | { | 153 | { |
149 | int mode = GLOBAL_DISABLED; | 154 | int mode = GLOBAL_DISABLED; |
150 | bool enabled = false; | 155 | bool enabled = false; |
151 | if( ( enabled =m_useglobal->isChecked() ) ){ | 156 | if( ( enabled =m_useglobal->isChecked() ) ){ |
152 | mode = GLOBAL_ENABLED; | 157 | mode = GLOBAL_ENABLED; |
153 | }else | 158 | }else |
154 | mode = GLOBAL_DISABLED; | 159 | mode = GLOBAL_DISABLED; |
155 | qWarning("enabled = %d", enabled ); | 160 | owarn << "enabled = " << enabled << oendl; |
156 | m_all->setEnabled ( enabled ); | 161 | m_all->setEnabled ( enabled ); |
157 | m_audio->setEnabled( enabled ); | 162 | m_audio->setEnabled( enabled ); |
158 | m_image->setEnabled( enabled ); | 163 | m_image->setEnabled( enabled ); |
159 | m_text->setEnabled ( enabled ); | 164 | m_text->setEnabled ( enabled ); |
160 | m_video->setEnabled ( enabled ); | 165 | m_video->setEnabled ( enabled ); |
161 | slotAllChanged(); | 166 | slotAllChanged(); |
162 | 167 | ||
163 | emit globalStateChanged( mode ); | 168 | emit globalStateChanged( mode ); |
164 | } | 169 | } |
165 | void MediumGlobalWidget::slotEnableChecking() | 170 | void MediumGlobalWidget::slotEnableChecking() |
166 | { | 171 | { |
167 | int mode = ENABLE_CHECKS; | 172 | int mode = ENABLE_CHECKS; |
168 | bool enabled = false; | 173 | bool enabled = false; |
169 | if( ( enabled = m_check->isChecked() ) ){ | 174 | if( ( enabled = m_check->isChecked() ) ){ |
170 | mode = ENABLE_CHECKS; | 175 | mode = ENABLE_CHECKS; |
171 | }else{ | 176 | }else{ |
172 | mode = DISABLE_CHECKS; | 177 | mode = DISABLE_CHECKS; |
173 | } | 178 | } |
174 | m_frame->setEnabled( enabled ); | 179 | m_frame->setEnabled( enabled ); |
175 | slotGlobalChanged(); | 180 | slotGlobalChanged(); |
176 | emit enableStateChanged( mode ); | 181 | emit enableStateChanged( mode ); |
177 | } | 182 | } |
178 | void MediumGlobalWidget::slotAllChanged() | 183 | void MediumGlobalWidget::slotAllChanged() |
179 | { | 184 | { |
180 | bool enable = !m_all->isChecked(); | 185 | bool enable = !m_all->isChecked(); |
181 | m_audio->setEnabled( enable ); | 186 | m_audio->setEnabled( enable ); |
182 | m_text->setEnabled( enable ); | 187 | m_text->setEnabled( enable ); |
183 | m_video->setEnabled( enable ); | 188 | m_video->setEnabled( enable ); |
184 | m_image->setEnabled( enable ); | 189 | m_image->setEnabled( enable ); |
185 | } | 190 | } |
diff --git a/noncore/styles/theme/othemebase.h b/noncore/styles/theme/othemebase.h index e691692..5519798 100644 --- a/noncore/styles/theme/othemebase.h +++ b/noncore/styles/theme/othemebase.h | |||
@@ -1,739 +1,744 @@ | |||
1 | /* This file is part of the KDE libraries | 1 | /* This file is part of the KDE libraries |
2 | Copyright (C) 1999 Daniel M. Duley <mosfet@kde.org> | 2 | Copyright (C) 1999 Daniel M. Duley <mosfet@kde.org> |
3 | 3 | ||
4 | This library is free software; you can redistribute it and/or | 4 | This library is free software; you can redistribute it and/or |
5 | modify it under the terms of the GNU Library General Public | 5 | modify it under the terms of the GNU Library General Public |
6 | License version 2 as published by the Free Software Foundation. | 6 | License version 2 as published by the Free Software Foundation. |
7 | 7 | ||
8 | This library is distributed in the hope that it will be useful, | 8 | This library is distributed in the hope that it will be useful, |
9 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
11 | Library General Public License for more details. | 11 | Library General Public License for more details. |
12 | 12 | ||
13 | You should have received a copy of the GNU Library General Public License | 13 | You should have received a copy of the GNU Library General Public License |
14 | along with this library; see the file COPYING.LIB. If not, write to | 14 | along with this library; see the file COPYING.LIB. If not, write to |
15 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 15 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
16 | Boston, MA 02111-1307, USA. | 16 | Boston, MA 02111-1307, USA. |
17 | */ | 17 | */ |
18 | #ifndef __OTHEMEBASE_H | 18 | #ifndef __OTHEMEBASE_H |
19 | #define __OTHEMEBASE_H | 19 | #define __OTHEMEBASE_H |
20 | 20 | ||
21 | /* OPIE */ | ||
22 | #include <opie2/odebug.h> | ||
23 | using namespace Opie::Core; | ||
24 | |||
25 | /* QT */ | ||
21 | #include <qdatetime.h> | 26 | #include <qdatetime.h> |
22 | #include <qtimer.h> | 27 | #include <qtimer.h> |
23 | #include <qwindowsstyle.h> | 28 | #include <qwindowsstyle.h> |
24 | #include <qpixmap.h> | 29 | #include <qpixmap.h> |
25 | #include <qpe/config.h> | 30 | #include <qpe/config.h> |
26 | #include <qimage.h> | 31 | #include <qimage.h> |
27 | #include <qintcache.h> | 32 | #include <qintcache.h> |
28 | #include <qstring.h> | 33 | #include <qstring.h> |
29 | #include <qpalette.h> | 34 | #include <qpalette.h> |
30 | 35 | ||
31 | #define WIDGETS 54 | 36 | #define WIDGETS 54 |
32 | 37 | ||
33 | /** | 38 | /** |
34 | * This class adds simple time management to QPixmap for use in flushing | 39 | * This class adds simple time management to QPixmap for use in flushing |
35 | * OThemeCache. | 40 | * OThemeCache. |
36 | * | 41 | * |
37 | * @author Daniel M. Duley <mosfet@kde.org> | 42 | * @author Daniel M. Duley <mosfet@kde.org> |
38 | */ | 43 | */ |
39 | class OThemePixmap : public QPixmap | 44 | class OThemePixmap : public QPixmap |
40 | { | 45 | { |
41 | public: | 46 | public: |
42 | enum BorderType{Top = 0, Bottom, Left, Right, TopLeft, TopRight, BottomLeft, | 47 | enum BorderType{Top = 0, Bottom, Left, Right, TopLeft, TopRight, BottomLeft, |
43 | BottomRight}; | 48 | BottomRight}; |
44 | 49 | ||
45 | OThemePixmap( bool timer = true ); | 50 | OThemePixmap( bool timer = true ); |
46 | OThemePixmap( const OThemePixmap &p ); | 51 | OThemePixmap( const OThemePixmap &p ); |
47 | ~OThemePixmap(); | 52 | ~OThemePixmap(); |
48 | QPixmap* border( BorderType type ); | 53 | QPixmap* border( BorderType type ); |
49 | void setBorder( BorderType type, const QPixmap &p ); | 54 | void setBorder( BorderType type, const QPixmap &p ); |
50 | void updateAccessed(); | 55 | void updateAccessed(); |
51 | bool isOld(); | 56 | bool isOld(); |
52 | protected: | 57 | protected: |
53 | QTime *t; | 58 | QTime *t; |
54 | QPixmap *b[ 8 ]; | 59 | QPixmap *b[ 8 ]; |
55 | 60 | ||
56 | private: | 61 | private: |
57 | class OThemePixmapPrivate; | 62 | class OThemePixmapPrivate; |
58 | OThemePixmapPrivate *d; | 63 | OThemePixmapPrivate *d; |
59 | }; | 64 | }; |
60 | 65 | ||
61 | inline QPixmap* OThemePixmap::border( BorderType type ) | 66 | inline QPixmap* OThemePixmap::border( BorderType type ) |
62 | { | 67 | { |
63 | return ( b[ type ] ); | 68 | return ( b[ type ] ); |
64 | } | 69 | } |
65 | 70 | ||
66 | inline void OThemePixmap::setBorder( BorderType type, const QPixmap &p ) | 71 | inline void OThemePixmap::setBorder( BorderType type, const QPixmap &p ) |
67 | { | 72 | { |
68 | if ( b[ type ] ) { | 73 | if ( b[ type ] ) { |
69 | qWarning( "OThemePixmap: Overwriting existing border!" ); | 74 | owarn << "OThemePixmap: Overwriting existing border!" << oendl; |
70 | delete( b[ type ] ); | 75 | delete( b[ type ] ); |
71 | } | 76 | } |
72 | b[ type ] = new QPixmap( p ); | 77 | b[ type ] = new QPixmap( p ); |
73 | } | 78 | } |
74 | 79 | ||
75 | inline void OThemePixmap::updateAccessed() | 80 | inline void OThemePixmap::updateAccessed() |
76 | { | 81 | { |
77 | if (t) | 82 | if (t) |
78 | t->start(); | 83 | t->start(); |
79 | } | 84 | } |
80 | 85 | ||
81 | inline bool OThemePixmap::isOld() | 86 | inline bool OThemePixmap::isOld() |
82 | { | 87 | { |
83 | return ( t ? t->elapsed() >= 300000 : false ); | 88 | return ( t ? t->elapsed() >= 300000 : false ); |
84 | } | 89 | } |
85 | 90 | ||
86 | /** | 91 | /** |
87 | * A very simple pixmap cache for theme plugins. QPixmapCache is not used | 92 | * A very simple pixmap cache for theme plugins. QPixmapCache is not used |
88 | * since it uses QString keys which are not needed. All the information we | 93 | * since it uses QString keys which are not needed. All the information we |
89 | * need can be encoded in a numeric key. Using QIntCache instead allows us to | 94 | * need can be encoded in a numeric key. Using QIntCache instead allows us to |
90 | * skip the string operations. | 95 | * skip the string operations. |
91 | * | 96 | * |
92 | * This class is mostly just inline methods that do bit operations on a key | 97 | * This class is mostly just inline methods that do bit operations on a key |
93 | * composed of the widget ID, width and/or height, and then calls | 98 | * composed of the widget ID, width and/or height, and then calls |
94 | * QIntCache::find(). | 99 | * QIntCache::find(). |
95 | * | 100 | * |
96 | * One other thing to note is that full, horizontal, and vertically scaled | 101 | * One other thing to note is that full, horizontal, and vertically scaled |
97 | * pixmaps are not used interchangeably. For example, if you insert a fully | 102 | * pixmaps are not used interchangeably. For example, if you insert a fully |
98 | * scaled pixmap that is 32x32 then request a horizontally scaled pixmap with | 103 | * scaled pixmap that is 32x32 then request a horizontally scaled pixmap with |
99 | * a width of 32, they will not match. This is because a pixmap that has been | 104 | * a width of 32, they will not match. This is because a pixmap that has been |
100 | * inserted into the cache has already been scaled at some point and it is | 105 | * inserted into the cache has already been scaled at some point and it is |
101 | * very likely the vertical height was not originally 32. Thus the pixmap | 106 | * very likely the vertical height was not originally 32. Thus the pixmap |
102 | * will be wrong when drawn, even though the horizontal width matches. | 107 | * will be wrong when drawn, even though the horizontal width matches. |
103 | * | 108 | * |
104 | * @author Daniel M. Duley <mosfet@kde.org> | 109 | * @author Daniel M. Duley <mosfet@kde.org> |
105 | * | 110 | * |
106 | */ | 111 | */ |
107 | class OThemeCache : public QObject | 112 | class OThemeCache : public QObject |
108 | { | 113 | { |
109 | Q_OBJECT | 114 | Q_OBJECT |
110 | public: | 115 | public: |
111 | /** | 116 | /** |
112 | * The scale hints supported by the cache. Note that Tiled is not here | 117 | * The scale hints supported by the cache. Note that Tiled is not here |
113 | * since tiled pixmaps are kept only once in OThemeBase. | 118 | * since tiled pixmaps are kept only once in OThemeBase. |
114 | */ | 119 | */ |
115 | enum ScaleHint{FullScale, HorizontalScale, VerticalScale}; | 120 | enum ScaleHint{FullScale, HorizontalScale, VerticalScale}; |
116 | /** | 121 | /** |
117 | * The constructor. | 122 | * The constructor. |
118 | * | 123 | * |
119 | * @param maxSize The maximum size of the cache in kilobytes. | 124 | * @param maxSize The maximum size of the cache in kilobytes. |
120 | */ | 125 | */ |
121 | OThemeCache( int maxSize, QObject *parent = 0, const char *name = 0 ); | 126 | OThemeCache( int maxSize, QObject *parent = 0, const char *name = 0 ); |
122 | /** | 127 | /** |
123 | * Inserts a new pixmap into the cache. | 128 | * Inserts a new pixmap into the cache. |
124 | * | 129 | * |
125 | * @param pixmap The pixmap to insert. | 130 | * @param pixmap The pixmap to insert. |
126 | * @param scale The scaling type of the pixmap. | 131 | * @param scale The scaling type of the pixmap. |
127 | * @param widgetID The widget ID of the pixmap, usually from OThemeBase's | 132 | * @param widgetID The widget ID of the pixmap, usually from OThemeBase's |
128 | * WidgetType enum. | 133 | * WidgetType enum. |
129 | * | 134 | * |
130 | * @return True if the insert was successful, false otherwise. | 135 | * @return True if the insert was successful, false otherwise. |
131 | */ | 136 | */ |
132 | bool insert( OThemePixmap *pixmap, ScaleHint scale, int widgetID, | 137 | bool insert( OThemePixmap *pixmap, ScaleHint scale, int widgetID, |
133 | bool border = false, bool mask = false ); | 138 | bool border = false, bool mask = false ); |
134 | /** | 139 | /** |
135 | * Returns a fully scaled pixmap. | 140 | * Returns a fully scaled pixmap. |
136 | * | 141 | * |
137 | * @param w The pixmap width to search for. | 142 | * @param w The pixmap width to search for. |
138 | * @param h The pixmap height to search for. | 143 | * @param h The pixmap height to search for. |
139 | * @param widgetID The widget ID to search for. | 144 | * @param widgetID The widget ID to search for. |
140 | * | 145 | * |
141 | * @return True if a pixmap matching the width, height, and widget ID of | 146 | * @return True if a pixmap matching the width, height, and widget ID of |
142 | * the pixmap exists, NULL otherwise. | 147 | * the pixmap exists, NULL otherwise. |
143 | */ | 148 | */ |
144 | OThemePixmap* pixmap( int w, int h, int widgetID, bool border = false, | 149 | OThemePixmap* pixmap( int w, int h, int widgetID, bool border = false, |
145 | bool mask = false ); | 150 | bool mask = false ); |
146 | /** | 151 | /** |
147 | * Returns a horizontally scaled pixmap. | 152 | * Returns a horizontally scaled pixmap. |
148 | * | 153 | * |
149 | * @param w The pixmap width to search for. | 154 | * @param w The pixmap width to search for. |
150 | * @param widgetID The widget ID to search for. | 155 | * @param widgetID The widget ID to search for. |
151 | * | 156 | * |
152 | * @return True if a pixmap matching the width and widget ID of | 157 | * @return True if a pixmap matching the width and widget ID of |
153 | * the pixmap exists, NULL otherwise. | 158 | * the pixmap exists, NULL otherwise. |
154 | */ | 159 | */ |
155 | OThemePixmap* horizontalPixmap( int w, int widgetID ); | 160 | OThemePixmap* horizontalPixmap( int w, int widgetID ); |
156 | /** | 161 | /** |
157 | * Returns a vertically scaled pixmap. | 162 | * Returns a vertically scaled pixmap. |
158 | * | 163 | * |
159 | * @param h The pixmap height to search for. | 164 | * @param h The pixmap height to search for. |
160 | * @param widgetID The widget ID to search for. | 165 | * @param widgetID The widget ID to search for. |
161 | * | 166 | * |
162 | * @return True if a pixmap matching the height and widget ID of | 167 | * @return True if a pixmap matching the height and widget ID of |
163 | * the pixmap exists, NULL otherwise. | 168 | * the pixmap exists, NULL otherwise. |
164 | */ | 169 | */ |
165 | OThemePixmap* verticalPixmap( int h, int widgetID ); | 170 | OThemePixmap* verticalPixmap( int h, int widgetID ); |
166 | protected slots: | 171 | protected slots: |
167 | void flushTimeout(); | 172 | void flushTimeout(); |
168 | protected: | 173 | protected: |
169 | QIntCache<OThemePixmap> cache; | 174 | QIntCache<OThemePixmap> cache; |
170 | QTimer flushTimer; | 175 | QTimer flushTimer; |
171 | 176 | ||
172 | private: | 177 | private: |
173 | class OThemeCachePrivate; | 178 | class OThemeCachePrivate; |
174 | OThemeCachePrivate *d; | 179 | OThemeCachePrivate *d; |
175 | }; | 180 | }; |
176 | 181 | ||
177 | 182 | ||
178 | /** | 183 | /** |
179 | * This is a base class for KDE themed styles. It implements a cache, | 184 | * This is a base class for KDE themed styles. It implements a cache, |
180 | * configuration file parsing, pixmap scaling, gradients, and a lot | 185 | * configuration file parsing, pixmap scaling, gradients, and a lot |
181 | * of inline methods for accessing user specified parameters. | 186 | * of inline methods for accessing user specified parameters. |
182 | * | 187 | * |
183 | * Note that this class *does not* actually implement any themes. It just | 188 | * Note that this class *does not* actually implement any themes. It just |
184 | * provides the groundwork for doing so. The only reason to use this class | 189 | * provides the groundwork for doing so. The only reason to use this class |
185 | * directly is if you plan to reimplement all of the widgets. Otherwise, | 190 | * directly is if you plan to reimplement all of the widgets. Otherwise, |
186 | * refer to OThemeStyle for a fully themed style you can derive from. | 191 | * refer to OThemeStyle for a fully themed style you can derive from. |
187 | * | 192 | * |
188 | * @author Daniel M. Duley <mosfet@kde.org> | 193 | * @author Daniel M. Duley <mosfet@kde.org> |
189 | */ | 194 | */ |
190 | class OThemeBase: public QWindowsStyle | 195 | class OThemeBase: public QWindowsStyle |
191 | { | 196 | { |
192 | Q_OBJECT | 197 | Q_OBJECT |
193 | public: | 198 | public: |
194 | /** | 199 | /** |
195 | * Constructs a new OThemeBase object. | 200 | * Constructs a new OThemeBase object. |
196 | */ | 201 | */ |
197 | OThemeBase( const QString &configFile ); | 202 | OThemeBase( const QString &configFile ); |
198 | ~OThemeBase(); | 203 | ~OThemeBase(); |
199 | /** | 204 | /** |
200 | * Describes if a pixmap should be scaled fully, horizontally, vertically, | 205 | * Describes if a pixmap should be scaled fully, horizontally, vertically, |
201 | * or not at all and tiled. | 206 | * or not at all and tiled. |
202 | */ | 207 | */ |
203 | enum ScaleHint{FullScale, HorizontalScale, VerticalScale, TileScale}; | 208 | enum ScaleHint{FullScale, HorizontalScale, VerticalScale, TileScale}; |
204 | /** | 209 | /** |
205 | * The default arrow types. | 210 | * The default arrow types. |
206 | */ | 211 | */ |
207 | enum ArrowStyle{MotifArrow, LargeArrow, SmallArrow}; | 212 | enum ArrowStyle{MotifArrow, LargeArrow, SmallArrow}; |
208 | /** | 213 | /** |
209 | * The default frame shading styles. | 214 | * The default frame shading styles. |
210 | */ | 215 | */ |
211 | enum ShadeStyle{Motif, Windows, Next, KDE}; | 216 | enum ShadeStyle{Motif, Windows, Next, KDE}; |
212 | /** | 217 | /** |
213 | * The default scrollbar button layout. BottomLeft is like what Next | 218 | * The default scrollbar button layout. BottomLeft is like what Next |
214 | * uses, BottomRight is like Platinum, and Opposite it like Windows and | 219 | * uses, BottomRight is like Platinum, and Opposite it like Windows and |
215 | * Motif. | 220 | * Motif. |
216 | */ | 221 | */ |
217 | enum SButton{SBBottomLeft, SBBottomRight, SBOpposite}; | 222 | enum SButton{SBBottomLeft, SBBottomRight, SBOpposite}; |
218 | /** | 223 | /** |
219 | * The gradient types. Horizontal is left to right, Vertical is top to | 224 | * The gradient types. Horizontal is left to right, Vertical is top to |
220 | * bottom, and diagonal is upper-left to bottom-right. | 225 | * bottom, and diagonal is upper-left to bottom-right. |
221 | */ | 226 | */ |
222 | enum Gradient{GrNone, GrHorizontal, GrVertical, GrDiagonal, GrPyramid, | 227 | enum Gradient{GrNone, GrHorizontal, GrVertical, GrDiagonal, GrPyramid, |
223 | GrRectangle, GrElliptic, GrReverseBevel}; | 228 | GrRectangle, GrElliptic, GrReverseBevel}; |
224 | /** | 229 | /** |
225 | * This provides a list of widget types that OThemeBase recognizes. | 230 | * This provides a list of widget types that OThemeBase recognizes. |
226 | */ | 231 | */ |
227 | /* Internal note: The order here is important. Some widgets inherit | 232 | /* Internal note: The order here is important. Some widgets inherit |
228 | * properties. This is usually for when you have two settings for the | 233 | * properties. This is usually for when you have two settings for the |
229 | * same widget, ie: on(sunken), and off. The on settings will inherit | 234 | * same widget, ie: on(sunken), and off. The on settings will inherit |
230 | * the properties of the off one when nothing is specified in the config. | 235 | * the properties of the off one when nothing is specified in the config. |
231 | * | 236 | * |
232 | * In order to be able to handle this while still having everything in | 237 | * In order to be able to handle this while still having everything in |
233 | * one group that is easy to loop from we have the following order: | 238 | * one group that is easy to loop from we have the following order: |
234 | * unsunked(off) items, sunken(on)items, and then the ones that don't | 239 | * unsunked(off) items, sunken(on)items, and then the ones that don't |
235 | * matter. INHERIT_ITEMS define the number of widgets that have inheritence | 240 | * matter. INHERIT_ITEMS define the number of widgets that have inheritence |
236 | * so if 0 == PushButtonOff then INHERIT_ITEMS should == PushButtonOn | 241 | * so if 0 == PushButtonOff then INHERIT_ITEMS should == PushButtonOn |
237 | * and so on. WIDGETS define the total number of widgets. | 242 | * and so on. WIDGETS define the total number of widgets. |
238 | */ | 243 | */ |
239 | enum WidgetType{ | 244 | enum WidgetType{ |
240 | // Off (unsunken widgets) | 245 | // Off (unsunken widgets) |
241 | PushButton = 0, ComboBox, HScrollBarSlider, VScrollBarSlider, Bevel, | 246 | PushButton = 0, ComboBox, HScrollBarSlider, VScrollBarSlider, Bevel, |
242 | ToolButton, ScrollButton, HScrollDeco, VScrollDeco, | 247 | ToolButton, ScrollButton, HScrollDeco, VScrollDeco, |
243 | ComboDeco, MenuItem, InactiveTab, ArrowUp, ArrowDown, ArrowLeft, | 248 | ComboDeco, MenuItem, InactiveTab, ArrowUp, ArrowDown, ArrowLeft, |
244 | ArrowRight, | 249 | ArrowRight, |
245 | // On (sunken widgets) | 250 | // On (sunken widgets) |
246 | PushButtonDown, ComboBoxDown, HScrollBarSliderDown, | 251 | PushButtonDown, ComboBoxDown, HScrollBarSliderDown, |
247 | VScrollBarSliderDown, BevelDown, ToolButtonDown, ScrollButtonDown, | 252 | VScrollBarSliderDown, BevelDown, ToolButtonDown, ScrollButtonDown, |
248 | HScrollDecoDown, VScrollDecoDown, ComboDecoDown, MenuItemDown, | 253 | HScrollDecoDown, VScrollDecoDown, ComboDecoDown, MenuItemDown, |
249 | ActiveTab, SunkenArrowUp, SunkenArrowDown, SunkenArrowLeft, | 254 | ActiveTab, SunkenArrowUp, SunkenArrowDown, SunkenArrowLeft, |
250 | SunkenArrowRight, | 255 | SunkenArrowRight, |
251 | // Everything else (indicators must have separate settings) | 256 | // Everything else (indicators must have separate settings) |
252 | HScrollGroove, VScrollGroove, Slider, SliderGroove, IndicatorOn, | 257 | HScrollGroove, VScrollGroove, Slider, SliderGroove, IndicatorOn, |
253 | IndicatorOff, ExIndicatorOn, ExIndicatorOff, HBarHandle, VBarHandle, | 258 | IndicatorOff, ExIndicatorOn, ExIndicatorOff, HBarHandle, VBarHandle, |
254 | ToolBar, Splitter, CheckMark, MenuBar, DisArrowUp, DisArrowDown, | 259 | ToolBar, Splitter, CheckMark, MenuBar, DisArrowUp, DisArrowDown, |
255 | DisArrowLeft, DisArrowRight, ProgressBar, ProgressBg, MenuBarItem, | 260 | DisArrowLeft, DisArrowRight, ProgressBar, ProgressBg, MenuBarItem, |
256 | Background}; | 261 | Background}; |
257 | 262 | ||
258 | /** | 263 | /** |
259 | * The scaling type specified by the Config file. | 264 | * The scaling type specified by the Config file. |
260 | * | 265 | * |
261 | * @param widget A Widgets enum value. | 266 | * @param widget A Widgets enum value. |
262 | * | 267 | * |
263 | * @return A ScaleHint enum value. | 268 | * @return A ScaleHint enum value. |
264 | */ | 269 | */ |
265 | ScaleHint scaleHint( WidgetType widget ) const; | 270 | ScaleHint scaleHint( WidgetType widget ) const; |
266 | /** | 271 | /** |
267 | * The gradient type specified by the KConfig file. | 272 | * The gradient type specified by the KConfig file. |
268 | * | 273 | * |
269 | * @param widget A Widgets enum value. | 274 | * @param widget A Widgets enum value. |
270 | * | 275 | * |
271 | * @return A Gradient enum value. | 276 | * @return A Gradient enum value. |
272 | */ | 277 | */ |
273 | Gradient gradientHint( WidgetType widget ) const; | 278 | Gradient gradientHint( WidgetType widget ) const; |
274 | /** | 279 | /** |
275 | * The color group specified for a given widget. | 280 | * The color group specified for a given widget. |
276 | * If a color group is set in the theme configuration | 281 | * If a color group is set in the theme configuration |
277 | * that is used, otherwise defaultColor is returned. | 282 | * that is used, otherwise defaultColor is returned. |
278 | * | 283 | * |
279 | * @param defaultColor The colorGroup to set if one is available. | 284 | * @param defaultColor The colorGroup to set if one is available. |
280 | * | 285 | * |
281 | * @param widget The widget whose color group to retrieve. | 286 | * @param widget The widget whose color group to retrieve. |
282 | * | 287 | * |
283 | */ | 288 | */ |
284 | const QColorGroup* colorGroup( const QColorGroup &defaultGroup, | 289 | const QColorGroup* colorGroup( const QColorGroup &defaultGroup, |
285 | WidgetType widget ) const; | 290 | WidgetType widget ) const; |
286 | 291 | ||
287 | QBrush pixmapBrush( const QColorGroup &group, QColorGroup::ColorRole role, | 292 | QBrush pixmapBrush( const QColorGroup &group, QColorGroup::ColorRole role, |
288 | int w, int h, WidgetType widget ); | 293 | int w, int h, WidgetType widget ); |
289 | /** | 294 | /** |
290 | * True if the widget has a pixmap or gradient specified. | 295 | * True if the widget has a pixmap or gradient specified. |
291 | */ | 296 | */ |
292 | bool isPixmap( WidgetType widget ) const; | 297 | bool isPixmap( WidgetType widget ) const; |
293 | /** | 298 | /** |
294 | * True if the widget has a color group specified. | 299 | * True if the widget has a color group specified. |
295 | */ | 300 | */ |
296 | bool isColor( WidgetType widget ) const; | 301 | bool isColor( WidgetType widget ) const; |
297 | /** | 302 | /** |
298 | * True if the user specified a 3D focus rectangle | 303 | * True if the user specified a 3D focus rectangle |
299 | */ | 304 | */ |
300 | bool is3DFocus() const; | 305 | bool is3DFocus() const; |
301 | /** | 306 | /** |
302 | * If the user specified a 3D focus rectangle, they may also specify an | 307 | * If the user specified a 3D focus rectangle, they may also specify an |
303 | * offset from the default rectangle to use when drawing it. This returns | 308 | * offset from the default rectangle to use when drawing it. This returns |
304 | * the specified offset. | 309 | * the specified offset. |
305 | */ | 310 | */ |
306 | int focusOffset() const; | 311 | int focusOffset() const; |
307 | /** | 312 | /** |
308 | * The border width of the specified widget. | 313 | * The border width of the specified widget. |
309 | */ | 314 | */ |
310 | int borderWidth( WidgetType widget ) const; | 315 | int borderWidth( WidgetType widget ) const; |
311 | /** | 316 | /** |
312 | * Pixmap border width of the specified widget. | 317 | * Pixmap border width of the specified widget. |
313 | */ | 318 | */ |
314 | int pixBorderWidth( WidgetType widget ) const; | 319 | int pixBorderWidth( WidgetType widget ) const; |
315 | /** | 320 | /** |
316 | * Returns the border pixmap if enabled for the specified widget. This | 321 | * Returns the border pixmap if enabled for the specified widget. This |
317 | * will contain the originial pixmap, plus the edges separated in | 322 | * will contain the originial pixmap, plus the edges separated in |
318 | * OThemePixmap::border() if valid. If invalid it will return NULL. | 323 | * OThemePixmap::border() if valid. If invalid it will return NULL. |
319 | */ | 324 | */ |
320 | OThemePixmap* borderPixmap( WidgetType widget ); | 325 | OThemePixmap* borderPixmap( WidgetType widget ); |
321 | /** | 326 | /** |
322 | * The highlight width of the specified widget. | 327 | * The highlight width of the specified widget. |
323 | */ | 328 | */ |
324 | int highlightWidth( WidgetType widget ) const; | 329 | int highlightWidth( WidgetType widget ) const; |
325 | /** | 330 | /** |
326 | * The border plus highlight width of the widget. | 331 | * The border plus highlight width of the widget. |
327 | */ | 332 | */ |
328 | int decoWidth( WidgetType widget ) const; | 333 | int decoWidth( WidgetType widget ) const; |
329 | /** | 334 | /** |
330 | * The extent (width for vertical, height for horizontal) requested | 335 | * The extent (width for vertical, height for horizontal) requested |
331 | * for the scrollbars. | 336 | * for the scrollbars. |
332 | */ | 337 | */ |
333 | int getSBExtent() const; | 338 | int getSBExtent() const; |
334 | /** | 339 | /** |
335 | * The scrollbar button layout. | 340 | * The scrollbar button layout. |
336 | */ | 341 | */ |
337 | SButton scrollBarLayout() const; | 342 | SButton scrollBarLayout() const; |
338 | /** | 343 | /** |
339 | * The arrow type. | 344 | * The arrow type. |
340 | */ | 345 | */ |
341 | ArrowStyle arrowType() const; | 346 | ArrowStyle arrowType() const; |
342 | /** | 347 | /** |
343 | * The shading type. | 348 | * The shading type. |
344 | */ | 349 | */ |
345 | ShadeStyle shade() const; | 350 | ShadeStyle shade() const; |
346 | /** | 351 | /** |
347 | * The frame width. | 352 | * The frame width. |
348 | */ | 353 | */ |
349 | int frameWidth() const; | 354 | int frameWidth() const; |
350 | /** | 355 | /** |
351 | * The splitter width. | 356 | * The splitter width. |
352 | */ | 357 | */ |
353 | int splitWidth() const; | 358 | int splitWidth() const; |
354 | /** | 359 | /** |
355 | * The contrast for some bevel effects such as reverse gradient. | 360 | * The contrast for some bevel effects such as reverse gradient. |
356 | */ | 361 | */ |
357 | int bevelContrast( WidgetType widget ) const; | 362 | int bevelContrast( WidgetType widget ) const; |
358 | /** | 363 | /** |
359 | * The button text X shift. | 364 | * The button text X shift. |
360 | */ | 365 | */ |
361 | int buttonXShift() const; | 366 | int buttonXShift() const; |
362 | /** | 367 | /** |
363 | * The button text Y shift. | 368 | * The button text Y shift. |
364 | */ | 369 | */ |
365 | int buttonYShift() const; | 370 | int buttonYShift() const; |
366 | /** | 371 | /** |
367 | * Returns either the slider length of the slider pixmap if available, | 372 | * Returns either the slider length of the slider pixmap if available, |
368 | * otherwise the length specified in the config file. | 373 | * otherwise the length specified in the config file. |
369 | */ | 374 | */ |
370 | int sliderButtonLength() const; | 375 | int sliderButtonLength() const; |
371 | /** | 376 | /** |
372 | * True if rounded buttons are requested. | 377 | * True if rounded buttons are requested. |
373 | */ | 378 | */ |
374 | bool roundButton() const; | 379 | bool roundButton() const; |
375 | /** | 380 | /** |
376 | * True if rounded comboboxes are requested. | 381 | * True if rounded comboboxes are requested. |
377 | */ | 382 | */ |
378 | bool roundComboBox() const; | 383 | bool roundComboBox() const; |
379 | /** | 384 | /** |
380 | * True if rounded slider grooves are requested. | 385 | * True if rounded slider grooves are requested. |
381 | */ | 386 | */ |
382 | bool roundSlider() const; | 387 | bool roundSlider() const; |
383 | /** | 388 | /** |
384 | * True if a line should be drawn on the bottom of active tabs. | 389 | * True if a line should be drawn on the bottom of active tabs. |
385 | */ | 390 | */ |
386 | bool activeTabLine() const; | 391 | bool activeTabLine() const; |
387 | /** | 392 | /** |
388 | * True if a line should be drawn on the bottom of inactive tabs. | 393 | * True if a line should be drawn on the bottom of inactive tabs. |
389 | */ | 394 | */ |
390 | bool inactiveTabLine() const; | 395 | bool inactiveTabLine() const; |
391 | /** | 396 | /** |
392 | * Returns the current uncached pixmap for the given widget. This will | 397 | * Returns the current uncached pixmap for the given widget. This will |
393 | * usually be either the last scaled or gradient pixmap if those have | 398 | * usually be either the last scaled or gradient pixmap if those have |
394 | * been specified in the config file, the original pixmap if not, or NULL | 399 | * been specified in the config file, the original pixmap if not, or NULL |
395 | * if no pixmap has been specified. | 400 | * if no pixmap has been specified. |
396 | */ | 401 | */ |
397 | OThemePixmap* uncached( WidgetType widget ) const; | 402 | OThemePixmap* uncached( WidgetType widget ) const; |
398 | /** | 403 | /** |
399 | * Returns the pixmap for the given widget at the specified width and | 404 | * Returns the pixmap for the given widget at the specified width and |
400 | * height. This will return NULL if no pixmap or gradient is specified. | 405 | * height. This will return NULL if no pixmap or gradient is specified. |
401 | * It may also return a different sized pixmap if the scaling | 406 | * It may also return a different sized pixmap if the scaling |
402 | * is set to Tiled. When using this method, you should call it using | 407 | * is set to Tiled. When using this method, you should call it using |
403 | * the needed width and height then use QPainter::drawTiledPixmap to | 408 | * the needed width and height then use QPainter::drawTiledPixmap to |
404 | * paint it. Doing this, if the pixmap is scaled it will be the proper | 409 | * paint it. Doing this, if the pixmap is scaled it will be the proper |
405 | * size, otherwise it will be tiled. | 410 | * size, otherwise it will be tiled. |
406 | * | 411 | * |
407 | * @param w Requested width. | 412 | * @param w Requested width. |
408 | * @param h Requested height. | 413 | * @param h Requested height. |
409 | * @param widget Widget type. | 414 | * @param widget Widget type. |
410 | * @return The pixmap or NULL if one is not specified. | 415 | * @return The pixmap or NULL if one is not specified. |
411 | */ | 416 | */ |
412 | virtual OThemePixmap *scalePixmap( int w, int h, WidgetType widget ); | 417 | virtual OThemePixmap *scalePixmap( int w, int h, WidgetType widget ); |
413 | /** | 418 | /** |
414 | * This method reads a configuration file and applies it to the user's | 419 | * This method reads a configuration file and applies it to the user's |
415 | * kstylerc file. It does not signal applications to reload via the | 420 | * kstylerc file. It does not signal applications to reload via the |
416 | * KDEChangeGeneral atom, if you want to do this you must do so yourself. | 421 | * KDEChangeGeneral atom, if you want to do this you must do so yourself. |
417 | * See kcmdisplay's general.cpp for an example. | 422 | * See kcmdisplay's general.cpp for an example. |
418 | * | 423 | * |
419 | * @param file The configuration file to apply. | 424 | * @param file The configuration file to apply. |
420 | */ | 425 | */ |
421 | static void applyConfigFile( const QString &file ); | 426 | static void applyConfigFile( const QString &file ); |
422 | protected: | 427 | protected: |
423 | /** | 428 | /** |
424 | * Returns a QImage for the given widget if the widget is scaled, NULL | 429 | * Returns a QImage for the given widget if the widget is scaled, NULL |
425 | * otherwise. QImages of the original pixmap are stored for scaled | 430 | * otherwise. QImages of the original pixmap are stored for scaled |
426 | * widgets in order to facilitate fast and accurate smooth-scaling. This | 431 | * widgets in order to facilitate fast and accurate smooth-scaling. This |
427 | * also saves us a conversion from a pixmap to an image then back again. | 432 | * also saves us a conversion from a pixmap to an image then back again. |
428 | */ | 433 | */ |
429 | QImage* image( WidgetType widget ) const; | 434 | QImage* image( WidgetType widget ) const; |
430 | /** | 435 | /** |
431 | * Returns the gradient high color if one is specified, NULL otherwise. | 436 | * Returns the gradient high color if one is specified, NULL otherwise. |
432 | */ | 437 | */ |
433 | QColor* gradientHigh( WidgetType widget ) const; | 438 | QColor* gradientHigh( WidgetType widget ) const; |
434 | /** | 439 | /** |
435 | * Returns the gradient low color if one is specified, NULL otherwise. | 440 | * Returns the gradient low color if one is specified, NULL otherwise. |
436 | */ | 441 | */ |
437 | QColor* gradientLow( WidgetType widget ) const; | 442 | QColor* gradientLow( WidgetType widget ) const; |
438 | /** | 443 | /** |
439 | * Reads in all the configuration file entries supported. | 444 | * Reads in all the configuration file entries supported. |
440 | * | 445 | * |
441 | * @param colorStyle The style for the color groups. In KDE, colors were | 446 | * @param colorStyle The style for the color groups. In KDE, colors were |
442 | * calculated a little differently for Motif vs Windows styles. This | 447 | * calculated a little differently for Motif vs Windows styles. This |
443 | * is obsolete. | 448 | * is obsolete. |
444 | */ | 449 | */ |
445 | void readConfig( Qt::GUIStyle colorStyle = Qt::WindowsStyle ); | 450 | void readConfig( Qt::GUIStyle colorStyle = Qt::WindowsStyle ); |
446 | void readWidgetConfig( int i, Config *config, QString *pixnames, | 451 | void readWidgetConfig( int i, Config *config, QString *pixnames, |
447 | QString *brdnames, bool *loadArray ); | 452 | QString *brdnames, bool *loadArray ); |
448 | void copyWidgetConfig( int sourceID, int destID, QString *pixnames, | 453 | void copyWidgetConfig( int sourceID, int destID, QString *pixnames, |
449 | QString *brdnames ); | 454 | QString *brdnames ); |
450 | /** | 455 | /** |
451 | * Makes a full color group based on the given foreground and background | 456 | * Makes a full color group based on the given foreground and background |
452 | * colors. This is the same code used by KDE (kapp.cpp) in previous | 457 | * colors. This is the same code used by KDE (kapp.cpp) in previous |
453 | * versions. | 458 | * versions. |
454 | */ | 459 | */ |
455 | QColorGroup* makeColorGroup( QColor &fg, QColor &bg, | 460 | QColorGroup* makeColorGroup( QColor &fg, QColor &bg, |
456 | Qt::GUIStyle style = Qt::WindowsStyle ); | 461 | Qt::GUIStyle style = Qt::WindowsStyle ); |
457 | OThemePixmap* scale( int w, int h, WidgetType widget ); | 462 | OThemePixmap* scale( int w, int h, WidgetType widget ); |
458 | OThemePixmap* scaleBorder( int w, int h, WidgetType type ); | 463 | OThemePixmap* scaleBorder( int w, int h, WidgetType type ); |
459 | OThemePixmap* gradient( int w, int h, WidgetType widget ); | 464 | OThemePixmap* gradient( int w, int h, WidgetType widget ); |
460 | OThemePixmap* blend( WidgetType widget ); | 465 | OThemePixmap* blend( WidgetType widget ); |
461 | void generateBorderPix( int i ); | 466 | void generateBorderPix( int i ); |
462 | void applyResourceGroup( Config *config, int i, QString *copyfrom, QString *pixnames, QString *brdnames ); | 467 | void applyResourceGroup( Config *config, int i, QString *copyfrom, QString *pixnames, QString *brdnames ); |
463 | void applyMiscResourceGroup( Config *config ); | 468 | void applyMiscResourceGroup( Config *config ); |
464 | void readResourceGroup( int i, QString *copyfrom, QString *pixnames, QString *brdnames, | 469 | void readResourceGroup( int i, QString *copyfrom, QString *pixnames, QString *brdnames, |
465 | bool *loadArray ); | 470 | bool *loadArray ); |
466 | void readMiscResourceGroup(); | 471 | void readMiscResourceGroup(); |
467 | /** | 472 | /** |
468 | * Attempts to load a pixmap from the default OThemeBase locations. | 473 | * Attempts to load a pixmap from the default OThemeBase locations. |
469 | */ | 474 | */ |
470 | OThemePixmap* loadPixmap( QString &name ); | 475 | OThemePixmap* loadPixmap( QString &name ); |
471 | /** | 476 | /** |
472 | * Attempts to load a image from the default OThemeBase locations. | 477 | * Attempts to load a image from the default OThemeBase locations. |
473 | */ | 478 | */ |
474 | QImage* loadImage( QString &name ); | 479 | QImage* loadImage( QString &name ); |
475 | private: | 480 | private: |
476 | SButton sbPlacement; | 481 | SButton sbPlacement; |
477 | ArrowStyle arrowStyle; | 482 | ArrowStyle arrowStyle; |
478 | ShadeStyle shading; | 483 | ShadeStyle shading; |
479 | int defaultFrame; | 484 | int defaultFrame; |
480 | int btnXShift, btnYShift; | 485 | int btnXShift, btnYShift; |
481 | int sliderLen; | 486 | int sliderLen; |
482 | int splitterWidth; | 487 | int splitterWidth; |
483 | int focus3DOffset; | 488 | int focus3DOffset; |
484 | int sbExtent; | 489 | int sbExtent; |
485 | bool smallGroove; | 490 | bool smallGroove; |
486 | bool roundedButton, roundedCombo, roundedSlider; | 491 | bool roundedButton, roundedCombo, roundedSlider; |
487 | bool aTabLine, iTabLine; | 492 | bool aTabLine, iTabLine; |
488 | bool focus3D; | 493 | bool focus3D; |
489 | OThemeCache *cache; | 494 | OThemeCache *cache; |
490 | int cacheSize; | 495 | int cacheSize; |
491 | QString configFileName; | 496 | QString configFileName; |
492 | QString configFilePath; | 497 | QString configFilePath; |
493 | 498 | ||
494 | protected: | 499 | protected: |
495 | QColor fgcolor, bgcolor, selfgcolor, selbgcolor, winfgcolor, winbgcolor; | 500 | QColor fgcolor, bgcolor, selfgcolor, selbgcolor, winfgcolor, winbgcolor; |
496 | 501 | ||
497 | private: | 502 | private: |
498 | /** | 503 | /** |
499 | * The theme pixmaps. Many of these may be NULL if no pixmap is specified. | 504 | * The theme pixmaps. Many of these may be NULL if no pixmap is specified. |
500 | * There may also be duplicate pixmap pointers if more than one widget | 505 | * There may also be duplicate pixmap pointers if more than one widget |
501 | * uses the same tiled pixmap. If a pixmap is tiled, it is kept here and | 506 | * uses the same tiled pixmap. If a pixmap is tiled, it is kept here and |
502 | * this acts as a cache. Otherwise this will hold whatever the last scaled | 507 | * this acts as a cache. Otherwise this will hold whatever the last scaled |
503 | * pixmap was. | 508 | * pixmap was. |
504 | */ | 509 | */ |
505 | OThemePixmap *pixmaps[ WIDGETS ]; | 510 | OThemePixmap *pixmaps[ WIDGETS ]; |
506 | /** | 511 | /** |
507 | * The theme images. These are for scaled images and are kept in order | 512 | * The theme images. These are for scaled images and are kept in order |
508 | * to maintain fast smoothscaling. | 513 | * to maintain fast smoothscaling. |
509 | */ | 514 | */ |
510 | QImage *images[ WIDGETS ]; | 515 | QImage *images[ WIDGETS ]; |
511 | /** | 516 | /** |
512 | * The border widths | 517 | * The border widths |
513 | */ | 518 | */ |
514 | unsigned char borders[ WIDGETS ]; | 519 | unsigned char borders[ WIDGETS ]; |
515 | /** | 520 | /** |
516 | * The highlight widths | 521 | * The highlight widths |
517 | */ | 522 | */ |
518 | unsigned char highlights[ WIDGETS ]; | 523 | unsigned char highlights[ WIDGETS ]; |
519 | /** | 524 | /** |
520 | * The scale hints for pixmaps and gradients. | 525 | * The scale hints for pixmaps and gradients. |
521 | */ | 526 | */ |
522 | ScaleHint scaleHints[ WIDGETS ]; | 527 | ScaleHint scaleHints[ WIDGETS ]; |
523 | /** | 528 | /** |
524 | * All the color groups. | 529 | * All the color groups. |
525 | */ | 530 | */ |
526 | QColorGroup *colors[ WIDGETS ]; | 531 | QColorGroup *colors[ WIDGETS ]; |
527 | /** | 532 | /** |
528 | * Gradient low colors (or blend background). | 533 | * Gradient low colors (or blend background). |
529 | */ | 534 | */ |
530 | QColor *grLowColors[ WIDGETS ]; | 535 | QColor *grLowColors[ WIDGETS ]; |
531 | /** | 536 | /** |
532 | * Gradient high colors. | 537 | * Gradient high colors. |
533 | */ | 538 | */ |
534 | QColor *grHighColors[ WIDGETS ]; | 539 | QColor *grHighColors[ WIDGETS ]; |
535 | /** | 540 | /** |
536 | * Gradient types. | 541 | * Gradient types. |
537 | */ | 542 | */ |
538 | Gradient gradients[ WIDGETS ]; | 543 | Gradient gradients[ WIDGETS ]; |
539 | /** | 544 | /** |
540 | * Blend intensity factors | 545 | * Blend intensity factors |
541 | */ | 546 | */ |
542 | float blends[ WIDGETS ]; | 547 | float blends[ WIDGETS ]; |
543 | /** | 548 | /** |
544 | * Bevel contrasts | 549 | * Bevel contrasts |
545 | */ | 550 | */ |
546 | unsigned char bContrasts[ WIDGETS ]; | 551 | unsigned char bContrasts[ WIDGETS ]; |
547 | /** | 552 | /** |
548 | * Duplicate pixmap entries (used during destruction). | 553 | * Duplicate pixmap entries (used during destruction). |
549 | */ | 554 | */ |
550 | bool duplicate[ WIDGETS ]; | 555 | bool duplicate[ WIDGETS ]; |
551 | /** | 556 | /** |
552 | * Pixmapped border widths | 557 | * Pixmapped border widths |
553 | */ | 558 | */ |
554 | int pbWidth[ WIDGETS ]; | 559 | int pbWidth[ WIDGETS ]; |
555 | /** | 560 | /** |
556 | * Pixmapped borders | 561 | * Pixmapped borders |
557 | */ | 562 | */ |
558 | OThemePixmap *pbPixmaps[ WIDGETS ]; | 563 | OThemePixmap *pbPixmaps[ WIDGETS ]; |
559 | /** | 564 | /** |
560 | * Duplicate border pixmapped border entries | 565 | * Duplicate border pixmapped border entries |
561 | */ | 566 | */ |
562 | bool pbDuplicate[ WIDGETS ]; | 567 | bool pbDuplicate[ WIDGETS ]; |
563 | 568 | ||
564 | private: | 569 | private: |
565 | class OThemeBasePrivate; | 570 | class OThemeBasePrivate; |
566 | OThemeBasePrivate *d; | 571 | OThemeBasePrivate *d; |
567 | 572 | ||
568 | }; | 573 | }; |
569 | 574 | ||
570 | inline bool OThemeBase::isPixmap( WidgetType widget ) const | 575 | inline bool OThemeBase::isPixmap( WidgetType widget ) const |
571 | { | 576 | { |
572 | return ( pixmaps[ widget ] != NULL || gradients[ widget ] != GrNone ); | 577 | return ( pixmaps[ widget ] != NULL || gradients[ widget ] != GrNone ); |
573 | } | 578 | } |
574 | 579 | ||
575 | inline bool OThemeBase::isColor( WidgetType widget ) const | 580 | inline bool OThemeBase::isColor( WidgetType widget ) const |
576 | { | 581 | { |
577 | return ( colors[ widget ] != NULL ); | 582 | return ( colors[ widget ] != NULL ); |
578 | } | 583 | } |
579 | 584 | ||
580 | inline bool OThemeBase::is3DFocus() const | 585 | inline bool OThemeBase::is3DFocus() const |
581 | { | 586 | { |
582 | return ( focus3D ); | 587 | return ( focus3D ); |
583 | } | 588 | } |
584 | 589 | ||
585 | inline int OThemeBase::focusOffset() const | 590 | inline int OThemeBase::focusOffset() const |
586 | { | 591 | { |
587 | return ( focus3DOffset ); | 592 | return ( focus3DOffset ); |
588 | } | 593 | } |
589 | 594 | ||
590 | inline int OThemeBase::bevelContrast( WidgetType widget ) const | 595 | inline int OThemeBase::bevelContrast( WidgetType widget ) const |
591 | { | 596 | { |
592 | return ( bContrasts[ widget ] ); | 597 | return ( bContrasts[ widget ] ); |
593 | } | 598 | } |
594 | 599 | ||
595 | inline OThemeBase::ScaleHint OThemeBase::scaleHint( WidgetType widget ) const | 600 | inline OThemeBase::ScaleHint OThemeBase::scaleHint( WidgetType widget ) const |
596 | { | 601 | { |
597 | return ( ( widget < WIDGETS ) ? scaleHints[ widget ] : TileScale ); | 602 | return ( ( widget < WIDGETS ) ? scaleHints[ widget ] : TileScale ); |
598 | } | 603 | } |
599 | 604 | ||
600 | inline OThemeBase::Gradient OThemeBase::gradientHint( WidgetType widget ) const | 605 | inline OThemeBase::Gradient OThemeBase::gradientHint( WidgetType widget ) const |
601 | { | 606 | { |
602 | return ( ( widget < WIDGETS ) ? gradients[ widget ] : GrNone ); | 607 | return ( ( widget < WIDGETS ) ? gradients[ widget ] : GrNone ); |
603 | } | 608 | } |
604 | 609 | ||
605 | inline OThemePixmap* OThemeBase::uncached( WidgetType widget ) const | 610 | inline OThemePixmap* OThemeBase::uncached( WidgetType widget ) const |
606 | { | 611 | { |
607 | return ( pixmaps[ widget ] ); | 612 | return ( pixmaps[ widget ] ); |
608 | } | 613 | } |
609 | 614 | ||
610 | inline QBrush OThemeBase::pixmapBrush( const QColorGroup &group, | 615 | inline QBrush OThemeBase::pixmapBrush( const QColorGroup &group, |
611 | QColorGroup::ColorRole role, | 616 | QColorGroup::ColorRole role, |
612 | int w, int h, WidgetType widget ) | 617 | int w, int h, WidgetType widget ) |
613 | { | 618 | { |
614 | if ( pixmaps[ widget ] || images[ widget ] ) | 619 | if ( pixmaps[ widget ] || images[ widget ] ) |
615 | return ( QBrush( group.color( role ), *scalePixmap( w, h, widget ) ) ); | 620 | return ( QBrush( group.color( role ), *scalePixmap( w, h, widget ) ) ); |
616 | else | 621 | else |
617 | return ( group.color( role ) ); | 622 | return ( group.color( role ) ); |
618 | } | 623 | } |
619 | 624 | ||
620 | inline const QColorGroup* OThemeBase::colorGroup( const QColorGroup &defaultGroup, | 625 | inline const QColorGroup* OThemeBase::colorGroup( const QColorGroup &defaultGroup, |
621 | WidgetType widget ) const | 626 | WidgetType widget ) const |
622 | { | 627 | { |
623 | return ( ( colors[ widget ] ) ? colors[ widget ] : &defaultGroup ); | 628 | return ( ( colors[ widget ] ) ? colors[ widget ] : &defaultGroup ); |
624 | } | 629 | } |
625 | 630 | ||
626 | inline int OThemeBase::borderWidth( WidgetType widget ) const | 631 | inline int OThemeBase::borderWidth( WidgetType widget ) const |
627 | { | 632 | { |
628 | return ( pbWidth[ widget ] ? pbWidth[ widget ] : borders[ widget ] ); | 633 | return ( pbWidth[ widget ] ? pbWidth[ widget ] : borders[ widget ] ); |
629 | } | 634 | } |
630 | 635 | ||
631 | inline int OThemeBase::pixBorderWidth( WidgetType widget ) const | 636 | inline int OThemeBase::pixBorderWidth( WidgetType widget ) const |
632 | { | 637 | { |
633 | return ( pbWidth[ widget ] ); | 638 | return ( pbWidth[ widget ] ); |
634 | } | 639 | } |
635 | 640 | ||
636 | inline int OThemeBase::highlightWidth( WidgetType widget ) const | 641 | inline int OThemeBase::highlightWidth( WidgetType widget ) const |
637 | { | 642 | { |
638 | return ( pbWidth[ widget ] ? 0 : highlights[ widget ] ); | 643 | return ( pbWidth[ widget ] ? 0 : highlights[ widget ] ); |
639 | } | 644 | } |
640 | 645 | ||
641 | inline int OThemeBase::decoWidth( WidgetType widget ) const | 646 | inline int OThemeBase::decoWidth( WidgetType widget ) const |
642 | { | 647 | { |
643 | return ( pbWidth[ widget ] ? pbWidth[ widget ] : borders[ widget ] + highlights[ widget ] ); | 648 | return ( pbWidth[ widget ] ? pbWidth[ widget ] : borders[ widget ] + highlights[ widget ] ); |
644 | } | 649 | } |
645 | 650 | ||
646 | inline QColor* OThemeBase::gradientHigh( WidgetType widget ) const | 651 | inline QColor* OThemeBase::gradientHigh( WidgetType widget ) const |
647 | { | 652 | { |
648 | return ( grHighColors[ widget ] ); | 653 | return ( grHighColors[ widget ] ); |
649 | } | 654 | } |
650 | 655 | ||
651 | inline QColor* OThemeBase::gradientLow( WidgetType widget ) const | 656 | inline QColor* OThemeBase::gradientLow( WidgetType widget ) const |
652 | { | 657 | { |
653 | return ( grLowColors[ widget ] ); | 658 | return ( grLowColors[ widget ] ); |
654 | } | 659 | } |
655 | 660 | ||
656 | inline QImage* OThemeBase::image( WidgetType widget ) const | 661 | inline QImage* OThemeBase::image( WidgetType widget ) const |
657 | { | 662 | { |
658 | return ( images[ widget ] ); | 663 | return ( images[ widget ] ); |
659 | } | 664 | } |
660 | 665 | ||
661 | inline OThemeBase::SButton OThemeBase::scrollBarLayout() const | 666 | inline OThemeBase::SButton OThemeBase::scrollBarLayout() const |
662 | { | 667 | { |
663 | return ( sbPlacement ); | 668 | return ( sbPlacement ); |
664 | } | 669 | } |
665 | 670 | ||
666 | inline OThemeBase::ArrowStyle OThemeBase::arrowType() const | 671 | inline OThemeBase::ArrowStyle OThemeBase::arrowType() const |
667 | { | 672 | { |
668 | return ( arrowStyle ); | 673 | return ( arrowStyle ); |
669 | } | 674 | } |
670 | 675 | ||
671 | inline OThemeBase::ShadeStyle OThemeBase::shade() const | 676 | inline OThemeBase::ShadeStyle OThemeBase::shade() const |
672 | { | 677 | { |
673 | return ( shading ); | 678 | return ( shading ); |
674 | } | 679 | } |
675 | 680 | ||
676 | inline int OThemeBase::frameWidth() const | 681 | inline int OThemeBase::frameWidth() const |
677 | { | 682 | { |
678 | return ( defaultFrame ); | 683 | return ( defaultFrame ); |
679 | } | 684 | } |
680 | 685 | ||
681 | inline int OThemeBase::buttonXShift() const | 686 | inline int OThemeBase::buttonXShift() const |
682 | { | 687 | { |
683 | return ( btnXShift ); | 688 | return ( btnXShift ); |
684 | } | 689 | } |
685 | 690 | ||
686 | inline int OThemeBase::splitWidth() const | 691 | inline int OThemeBase::splitWidth() const |
687 | { | 692 | { |
688 | return ( splitterWidth ); | 693 | return ( splitterWidth ); |
689 | } | 694 | } |
690 | 695 | ||
691 | inline int OThemeBase::buttonYShift() const | 696 | inline int OThemeBase::buttonYShift() const |
692 | { | 697 | { |
693 | return ( btnYShift ); | 698 | return ( btnYShift ); |
694 | } | 699 | } |
695 | 700 | ||
696 | inline int OThemeBase::sliderButtonLength() const | 701 | inline int OThemeBase::sliderButtonLength() const |
697 | { | 702 | { |
698 | if ( isPixmap( Slider ) ) | 703 | if ( isPixmap( Slider ) ) |
699 | return ( uncached( Slider ) ->width() ); | 704 | return ( uncached( Slider ) ->width() ); |
700 | else | 705 | else |
701 | return ( sliderLen ); | 706 | return ( sliderLen ); |
702 | } | 707 | } |
703 | 708 | ||
704 | inline bool OThemeBase::roundButton() const | 709 | inline bool OThemeBase::roundButton() const |
705 | { | 710 | { |
706 | return ( roundedButton ); | 711 | return ( roundedButton ); |
707 | } | 712 | } |
708 | 713 | ||
709 | inline bool OThemeBase::roundComboBox() const | 714 | inline bool OThemeBase::roundComboBox() const |
710 | { | 715 | { |
711 | return ( roundedCombo ); | 716 | return ( roundedCombo ); |
712 | } | 717 | } |
713 | 718 | ||
714 | inline bool OThemeBase::roundSlider() const | 719 | inline bool OThemeBase::roundSlider() const |
715 | { | 720 | { |
716 | return ( roundedSlider ); | 721 | return ( roundedSlider ); |
717 | } | 722 | } |
718 | 723 | ||
719 | inline bool OThemeBase::activeTabLine() const | 724 | inline bool OThemeBase::activeTabLine() const |
720 | { | 725 | { |
721 | return ( aTabLine ); | 726 | return ( aTabLine ); |
722 | } | 727 | } |
723 | 728 | ||
724 | inline bool OThemeBase::inactiveTabLine() const | 729 | inline bool OThemeBase::inactiveTabLine() const |
725 | { | 730 | { |
726 | return ( iTabLine ); | 731 | return ( iTabLine ); |
727 | } | 732 | } |
728 | 733 | ||
729 | inline int OThemeBase::getSBExtent() const | 734 | inline int OThemeBase::getSBExtent() const |
730 | { | 735 | { |
731 | return ( sbExtent ); | 736 | return ( sbExtent ); |
732 | } | 737 | } |
733 | 738 | ||
734 | inline OThemePixmap* OThemeBase::borderPixmap( WidgetType widget ) | 739 | inline OThemePixmap* OThemeBase::borderPixmap( WidgetType widget ) |
735 | { | 740 | { |
736 | return ( pbPixmaps[ widget ] ); | 741 | return ( pbPixmaps[ widget ] ); |
737 | } | 742 | } |
738 | 743 | ||
739 | #endif | 744 | #endif |