24 files changed, 2 insertions, 99 deletions
diff --git a/noncore/apps/tinykate/libkate/document/katedocument.cpp b/noncore/apps/tinykate/libkate/document/katedocument.cpp index 6807544..f05e21a 100644 --- a/noncore/apps/tinykate/libkate/document/katedocument.cpp +++ b/noncore/apps/tinykate/libkate/document/katedocument.cpp | |||
@@ -1,836 +1,834 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | katedocument.cpp - description | 2 | katedocument.cpp - description |
3 | ------------------- | 3 | ------------------- |
4 | begin : Mon Jan 15 2001 | 4 | begin : Mon Jan 15 2001 |
5 | copyright : (C) 2001 by Christoph "Crossfire" Cullmann | 5 | copyright : (C) 2001 by Christoph "Crossfire" Cullmann |
6 | (C) 2002 by Joseph Wenninger | 6 | (C) 2002 by Joseph Wenninger |
7 | email : crossfire@babylon2k.de | 7 | email : crossfire@babylon2k.de |
8 | jowenn@kde.org | 8 | jowenn@kde.org |
9 | 9 | ||
10 | ***************************************************************************/ | 10 | ***************************************************************************/ |
11 | 11 | ||
12 | /*************************************************************************** | 12 | /*************************************************************************** |
13 | * * | 13 | * * |
14 | * This program is free software; you can redistribute it and/or modify * | 14 | * This program is free software; you can redistribute it and/or modify * |
15 | * it under the terms of the GNU General Public License as published by * | 15 | * it under the terms of the GNU General Public License as published by * |
16 | * the Free Software Foundation; either version 2 of the License, or * | 16 | * the Free Software Foundation; either version 2 of the License, or * |
17 | * (at your option) any later version. * | 17 | * (at your option) any later version. * |
18 | * * | 18 | * * |
19 | ***************************************************************************/ | 19 | ***************************************************************************/ |
20 | 20 | ||
21 | /* | 21 | /* |
22 | Copyright (C) 1998, 1999 Jochen Wilhelmy | 22 | Copyright (C) 1998, 1999 Jochen Wilhelmy |
23 | digisnap@cs.tu-berlin.de | 23 | digisnap@cs.tu-berlin.de |
24 | 24 | ||
25 | This library is free software; you can redistribute it and/or | 25 | This library is free software; you can redistribute it and/or |
26 | modify it under the terms of the GNU Library General Public | 26 | modify it under the terms of the GNU Library General Public |
27 | License as published by the Free Software Foundation; either | 27 | License as published by the Free Software Foundation; either |
28 | version 2 of the License, or (at your option) any later version. | 28 | version 2 of the License, or (at your option) any later version. |
29 | 29 | ||
30 | This library is distributed in the hope that it will be useful, | 30 | This library is distributed in the hope that it will be useful, |
31 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 31 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
32 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 32 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
33 | Library General Public License for more details. | 33 | Library General Public License for more details. |
34 | 34 | ||
35 | You should have received a copy of the GNU Library General Public License | 35 | You should have received a copy of the GNU Library General Public License |
36 | along with this library; see the file COPYING.LIB. If not, write to | 36 | along with this library; see the file COPYING.LIB. If not, write to |
37 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 37 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
38 | Boston, MA 02111-1307, USA. | 38 | Boston, MA 02111-1307, USA. |
39 | */ | 39 | */ |
40 | 40 | ||
41 | #include "katedocument.h" | 41 | #include "katedocument.h" |
42 | 42 | ||
43 | 43 | ||
44 | #include <qfileinfo.h> | 44 | #include <qfileinfo.h> |
45 | #include <qdatetime.h> | 45 | #include <qdatetime.h> |
46 | 46 | ||
47 | #include <kmessagebox.h> | 47 | #include <kmessagebox.h> |
48 | #include <klocale.h> | ||
49 | #include <qpe/config.h> | 48 | #include <qpe/config.h> |
50 | #include <qstring.h> | 49 | #include <qstring.h> |
51 | 50 | ||
52 | #include <sys/time.h> | 51 | #include <sys/time.h> |
53 | #include <unistd.h> | 52 | #include <unistd.h> |
54 | 53 | ||
55 | #include <stdio.h> | 54 | #include <stdio.h> |
56 | 55 | ||
57 | #include <qtimer.h> | 56 | #include <qtimer.h> |
58 | #include <qobject.h> | 57 | #include <qobject.h> |
59 | #include <qapplication.h> | 58 | #include <qapplication.h> |
60 | #include <qclipboard.h> | 59 | #include <qclipboard.h> |
61 | #include <qfont.h> | 60 | #include <qfont.h> |
62 | #include <qpainter.h> | 61 | #include <qpainter.h> |
63 | #include <qfile.h> | 62 | #include <qfile.h> |
64 | #include <qtextstream.h> | 63 | #include <qtextstream.h> |
65 | #include <qtextcodec.h> | 64 | #include <qtextcodec.h> |
66 | #include <kglobal.h> | 65 | #include <kglobal.h> |
67 | 66 | ||
68 | #include <klocale.h> | ||
69 | //#include <kcharsets.h> | 67 | //#include <kcharsets.h> |
70 | #include <kdebug.h> | 68 | #include <kdebug.h> |
71 | //#include <kinstance.h> | 69 | //#include <kinstance.h> |
72 | 70 | ||
73 | #include <kglobalsettings.h> | 71 | #include <kglobalsettings.h> |
74 | //#include <kaction.h> | 72 | //#include <kaction.h> |
75 | //#include <kstdaction.h> | 73 | //#include <kstdaction.h> |
76 | 74 | ||
77 | #include "../view/kateview.h" | 75 | #include "../view/kateview.h" |
78 | #include "katebuffer.h" | 76 | #include "katebuffer.h" |
79 | #include "katetextline.h" | 77 | #include "katetextline.h" |
80 | 78 | ||
81 | #include "katecmd.h" | 79 | #include "katecmd.h" |
82 | 80 | ||
83 | KateAction::KateAction(Action a, PointStruc &cursor, int len, const QString &text) | 81 | KateAction::KateAction(Action a, PointStruc &cursor, int len, const QString &text) |
84 | : action(a), cursor(cursor), len(len), text(text) { | 82 | : action(a), cursor(cursor), len(len), text(text) { |
85 | } | 83 | } |
86 | 84 | ||
87 | KateActionGroup::KateActionGroup(PointStruc &aStart, int type) | 85 | KateActionGroup::KateActionGroup(PointStruc &aStart, int type) |
88 | : start(aStart), action(0L), undoType(type) { | 86 | : start(aStart), action(0L), undoType(type) { |
89 | } | 87 | } |
90 | 88 | ||
91 | KateActionGroup::~KateActionGroup() { | 89 | KateActionGroup::~KateActionGroup() { |
92 | KateAction *current, *next; | 90 | KateAction *current, *next; |
93 | 91 | ||
94 | current = action; | 92 | current = action; |
95 | while (current) { | 93 | while (current) { |
96 | next = current->next; | 94 | next = current->next; |
97 | delete current; | 95 | delete current; |
98 | current = next; | 96 | current = next; |
99 | } | 97 | } |
100 | } | 98 | } |
101 | 99 | ||
102 | void KateActionGroup::insertAction(KateAction *a) { | 100 | void KateActionGroup::insertAction(KateAction *a) { |
103 | a->next = action; | 101 | a->next = action; |
104 | action = a; | 102 | action = a; |
105 | } | 103 | } |
106 | 104 | ||
107 | const char * KateActionGroup::typeName(int type) | 105 | const char * KateActionGroup::typeName(int type) |
108 | { | 106 | { |
109 | // return a short text description of the given undo group type suitable for a menu | 107 | // return a short text description of the given undo group type suitable for a menu |
110 | // not the lack of i18n's, the caller is expected to handle translation | 108 | // not the lack of i18n's, the caller is expected to handle translation |
111 | switch (type) { | 109 | switch (type) { |
112 | case ugPaste : return "Paste Text"; | 110 | case ugPaste : return "Paste Text"; |
113 | case ugDelBlock : return "Selection Overwrite"; | 111 | case ugDelBlock : return "Selection Overwrite"; |
114 | case ugIndent : return "Indent"; | 112 | case ugIndent : return "Indent"; |
115 | case ugUnindent : return "Unindent"; | 113 | case ugUnindent : return "Unindent"; |
116 | case ugComment : return "Comment"; | 114 | case ugComment : return "Comment"; |
117 | case ugUncomment : return "Uncomment"; | 115 | case ugUncomment : return "Uncomment"; |
118 | case ugReplace : return "Text Replace"; | 116 | case ugReplace : return "Text Replace"; |
119 | case ugSpell : return "Spell Check"; | 117 | case ugSpell : return "Spell Check"; |
120 | case ugInsChar : return "Typing"; | 118 | case ugInsChar : return "Typing"; |
121 | case ugDelChar : return "Delete Text"; | 119 | case ugDelChar : return "Delete Text"; |
122 | case ugInsLine : return "New Line"; | 120 | case ugInsLine : return "New Line"; |
123 | case ugDelLine : return "Delete Line"; | 121 | case ugDelLine : return "Delete Line"; |
124 | } | 122 | } |
125 | return ""; | 123 | return ""; |
126 | } | 124 | } |
127 | 125 | ||
128 | const int KateDocument::maxAttribs = 32; | 126 | const int KateDocument::maxAttribs = 32; |
129 | 127 | ||
130 | QStringList KateDocument::searchForList = QStringList(); | 128 | QStringList KateDocument::searchForList = QStringList(); |
131 | QStringList KateDocument::replaceWithList = QStringList(); | 129 | QStringList KateDocument::replaceWithList = QStringList(); |
132 | 130 | ||
133 | uint KateDocument::uniqueID = 0; | 131 | uint KateDocument::uniqueID = 0; |
134 | 132 | ||
135 | QPtrDict<KateDocument::KateDocPrivate>* KateDocument::d_ptr = 0; | 133 | QPtrDict<KateDocument::KateDocPrivate>* KateDocument::d_ptr = 0; |
136 | 134 | ||
137 | 135 | ||
138 | KateDocument::KateDocument(bool bSingleViewMode, bool bBrowserView, | 136 | KateDocument::KateDocument(bool bSingleViewMode, bool bBrowserView, |
139 | QWidget *parentWidget, const char *widgetName, | 137 | QWidget *parentWidget, const char *widgetName, |
140 | QObject *, const char *) | 138 | QObject *, const char *) |
141 | : Kate::Document (), | 139 | : Kate::Document (), |
142 | myFont(KGlobalSettings::generalFont()), myFontBold(KGlobalSettings::generalFont()), myFontItalic(KGlobalSettings::generalFont()), myFontBI(KGlobalSettings::generalFont()), | 140 | myFont(KGlobalSettings::generalFont()), myFontBold(KGlobalSettings::generalFont()), myFontItalic(KGlobalSettings::generalFont()), myFontBI(KGlobalSettings::generalFont()), |
143 | myFontMetrics (myFont), myFontMetricsBold (myFontBold), myFontMetricsItalic (myFontItalic), myFontMetricsBI (myFontBI), | 141 | myFontMetrics (myFont), myFontMetricsBold (myFontBold), myFontMetricsItalic (myFontItalic), myFontMetricsBI (myFontBI), |
144 | hlManager(HlManager::self ()) | 142 | hlManager(HlManager::self ()) |
145 | { | 143 | { |
146 | 144 | ||
147 | d(this)->hlSetByUser = false; | 145 | d(this)->hlSetByUser = false; |
148 | PreHighlightedTill=0; | 146 | PreHighlightedTill=0; |
149 | RequestPreHighlightTill=0; | 147 | RequestPreHighlightTill=0; |
150 | 148 | ||
151 | m_bSingleViewMode=bSingleViewMode; | 149 | m_bSingleViewMode=bSingleViewMode; |
152 | m_bBrowserView = bBrowserView; | 150 | m_bBrowserView = bBrowserView; |
153 | 151 | ||
154 | m_url = QString::null; | 152 | m_url = QString::null; |
155 | 153 | ||
156 | // NOTE: QFont::CharSet doesn't provide all the charsets KDE supports | 154 | // NOTE: QFont::CharSet doesn't provide all the charsets KDE supports |
157 | // (esp. it doesn't distinguish between UTF-8 and iso10646-1) | 155 | // (esp. it doesn't distinguish between UTF-8 and iso10646-1) |
158 | 156 | ||
159 | myEncoding = QString::fromLatin1(QTextCodec::codecForLocale()->name()); | 157 | myEncoding = QString::fromLatin1(QTextCodec::codecForLocale()->name()); |
160 | 158 | ||
161 | maxLength = -1; | 159 | maxLength = -1; |
162 | 160 | ||
163 | setFont (KGlobalSettings::generalFont()); | 161 | setFont (KGlobalSettings::generalFont()); |
164 | 162 | ||
165 | myDocID = uniqueID; | 163 | myDocID = uniqueID; |
166 | uniqueID++; | 164 | uniqueID++; |
167 | 165 | ||
168 | myDocName = QString (""); | 166 | myDocName = QString (""); |
169 | fileInfo = new QFileInfo (); | 167 | fileInfo = new QFileInfo (); |
170 | 168 | ||
171 | myCmd = new KateCmd (this); | 169 | myCmd = new KateCmd (this); |
172 | 170 | ||
173 | connect(this,SIGNAL(modifiedChanged ()),this,SLOT(slotModChanged ())); | 171 | connect(this,SIGNAL(modifiedChanged ()),this,SLOT(slotModChanged ())); |
174 | 172 | ||
175 | buffer = new KWBuffer; | 173 | buffer = new KWBuffer; |
176 | connect(buffer, SIGNAL(linesChanged(int)), this, SLOT(slotBufferChanged())); | 174 | connect(buffer, SIGNAL(linesChanged(int)), this, SLOT(slotBufferChanged())); |
177 | // connect(buffer, SIGNAL(textChanged()), this, SIGNAL(textChanged())); | 175 | // connect(buffer, SIGNAL(textChanged()), this, SIGNAL(textChanged())); |
178 | connect(buffer, SIGNAL(needHighlight(long,long)),this,SLOT(slotBufferHighlight(long,long))); | 176 | connect(buffer, SIGNAL(needHighlight(long,long)),this,SLOT(slotBufferHighlight(long,long))); |
179 | 177 | ||
180 | colors[0] = KGlobalSettings::baseColor(); | 178 | colors[0] = KGlobalSettings::baseColor(); |
181 | colors[1] = KGlobalSettings::highlightColor(); | 179 | colors[1] = KGlobalSettings::highlightColor(); |
182 | 180 | ||
183 | m_attribs = new Attribute[maxAttribs]; | 181 | m_attribs = new Attribute[maxAttribs]; |
184 | 182 | ||
185 | m_highlight = 0L; | 183 | m_highlight = 0L; |
186 | tabChars = 8; | 184 | tabChars = 8; |
187 | 185 | ||
188 | m_singleSelection = false; | 186 | m_singleSelection = false; |
189 | 187 | ||
190 | newDocGeometry = false; | 188 | newDocGeometry = false; |
191 | readOnly = false; | 189 | readOnly = false; |
192 | newDoc = false; | 190 | newDoc = false; |
193 | 191 | ||
194 | modified = false; | 192 | modified = false; |
195 | 193 | ||
196 | undoList.setAutoDelete(true); | 194 | undoList.setAutoDelete(true); |
197 | undoState = 0; | 195 | undoState = 0; |
198 | undoSteps = 50; | 196 | undoSteps = 50; |
199 | 197 | ||
200 | pseudoModal = 0L; | 198 | pseudoModal = 0L; |
201 | clear(); | 199 | clear(); |
202 | 200 | ||
203 | setHighlight(0); //calls updateFontData() | 201 | setHighlight(0); //calls updateFontData() |
204 | // if the user changes the highlight with the dialog, notify the doc | 202 | // if the user changes the highlight with the dialog, notify the doc |
205 | connect(hlManager,SIGNAL(changed()),SLOT(hlChanged())); | 203 | connect(hlManager,SIGNAL(changed()),SLOT(hlChanged())); |
206 | 204 | ||
207 | newDocGeometry = false; | 205 | newDocGeometry = false; |
208 | 206 | ||
209 | readConfig(); | 207 | readConfig(); |
210 | 208 | ||
211 | setReadOnly(false); | 209 | setReadOnly(false); |
212 | } | 210 | } |
213 | 211 | ||
214 | void KateDocument::setDontChangeHlOnSave() | 212 | void KateDocument::setDontChangeHlOnSave() |
215 | { | 213 | { |
216 | d(this)->hlSetByUser = true; | 214 | d(this)->hlSetByUser = true; |
217 | } | 215 | } |
218 | 216 | ||
219 | void KateDocument::setFont (QFont font) | 217 | void KateDocument::setFont (QFont font) |
220 | { | 218 | { |
221 | kdDebug()<<"Kate:: setFont"<<endl; | 219 | kdDebug()<<"Kate:: setFont"<<endl; |
222 | int oldwidth=myFontMetrics.width('W'); //Quick & Dirty Hack (by JoWenn) //Remove in KDE 3.0 | 220 | int oldwidth=myFontMetrics.width('W'); //Quick & Dirty Hack (by JoWenn) //Remove in KDE 3.0 |
223 | myFont = font; | 221 | myFont = font; |
224 | myFontBold = QFont (font); | 222 | myFontBold = QFont (font); |
225 | myFontBold.setBold (true); | 223 | myFontBold.setBold (true); |
226 | 224 | ||
227 | myFontItalic = QFont (font); | 225 | myFontItalic = QFont (font); |
228 | myFontItalic.setItalic (true); | 226 | myFontItalic.setItalic (true); |
229 | 227 | ||
230 | myFontBI = QFont (font); | 228 | myFontBI = QFont (font); |
231 | myFontBI.setBold (true); | 229 | myFontBI.setBold (true); |
232 | myFontBI.setItalic (true); | 230 | myFontBI.setItalic (true); |
233 | 231 | ||
234 | myFontMetrics = CachedFontMetrics (myFont); | 232 | myFontMetrics = CachedFontMetrics (myFont); |
235 | myFontMetricsBold = CachedFontMetrics (myFontBold); | 233 | myFontMetricsBold = CachedFontMetrics (myFontBold); |
236 | myFontMetricsItalic = CachedFontMetrics (myFontItalic); | 234 | myFontMetricsItalic = CachedFontMetrics (myFontItalic); |
237 | myFontMetricsBI = CachedFontMetrics (myFontBI); | 235 | myFontMetricsBI = CachedFontMetrics (myFontBI); |
238 | int newwidth=myFontMetrics.width('W'); //Quick & Dirty Hack (by JoWenn) //Remove in KDE 3.0 | 236 | int newwidth=myFontMetrics.width('W'); //Quick & Dirty Hack (by JoWenn) //Remove in KDE 3.0 |
239 | maxLength=maxLength*(float)newwidth/(float)oldwidth; //Quick & Dirty Hack (by JoWenn) //Remove in KDE 3.0 | 237 | maxLength=maxLength*(float)newwidth/(float)oldwidth; //Quick & Dirty Hack (by JoWenn) //Remove in KDE 3.0 |
240 | 238 | ||
241 | updateFontData(); | 239 | updateFontData(); |
242 | updateViews(); //Quick & Dirty Hack (by JoWenn) //Remove in KDE 3.0 | 240 | updateViews(); //Quick & Dirty Hack (by JoWenn) //Remove in KDE 3.0 |
243 | 241 | ||
244 | } | 242 | } |
245 | 243 | ||
246 | long KateDocument::needPreHighlight(long till) | 244 | long KateDocument::needPreHighlight(long till) |
247 | { | 245 | { |
248 | int max=numLines()-1; | 246 | int max=numLines()-1; |
249 | if (till>max) | 247 | if (till>max) |
250 | { | 248 | { |
251 | till=max; | 249 | till=max; |
252 | } | 250 | } |
253 | if (PreHighlightedTill>=till) return -1; | 251 | if (PreHighlightedTill>=till) return -1; |
254 | 252 | ||
255 | long tmp=RequestPreHighlightTill; | 253 | long tmp=RequestPreHighlightTill; |
256 | if (RequestPreHighlightTill<till) | 254 | if (RequestPreHighlightTill<till) |
257 | { | 255 | { |
258 | RequestPreHighlightTill=till; | 256 | RequestPreHighlightTill=till; |
259 | if (tmp<=PreHighlightedTill) QTimer::singleShot(10,this,SLOT(doPreHighlight())); | 257 | if (tmp<=PreHighlightedTill) QTimer::singleShot(10,this,SLOT(doPreHighlight())); |
260 | } | 258 | } |
261 | return RequestPreHighlightTill; | 259 | return RequestPreHighlightTill; |
262 | } | 260 | } |
263 | 261 | ||
264 | void KateDocument::doPreHighlight() | 262 | void KateDocument::doPreHighlight() |
265 | { | 263 | { |
266 | int from = PreHighlightedTill; | 264 | int from = PreHighlightedTill; |
267 | int till = PreHighlightedTill+200; | 265 | int till = PreHighlightedTill+200; |
268 | int max = numLines()-1; | 266 | int max = numLines()-1; |
269 | if (till > max) | 267 | if (till > max) |
270 | { | 268 | { |
271 | till = max; | 269 | till = max; |
272 | } | 270 | } |
273 | PreHighlightedTill = till; | 271 | PreHighlightedTill = till; |
274 | updateLines(from,till); | 272 | updateLines(from,till); |
275 | emit preHighlightChanged(PreHighlightedTill); | 273 | emit preHighlightChanged(PreHighlightedTill); |
276 | if (PreHighlightedTill<RequestPreHighlightTill) | 274 | if (PreHighlightedTill<RequestPreHighlightTill) |
277 | QTimer::singleShot(10,this,SLOT(doPreHighlight())); | 275 | QTimer::singleShot(10,this,SLOT(doPreHighlight())); |
278 | } | 276 | } |
279 | 277 | ||
280 | KateDocument::~KateDocument() | 278 | KateDocument::~KateDocument() |
281 | { | 279 | { |
282 | m_highlight->release(); | 280 | m_highlight->release(); |
283 | writeConfig(); | 281 | writeConfig(); |
284 | 282 | ||
285 | if ( !m_bSingleViewMode ) | 283 | if ( !m_bSingleViewMode ) |
286 | { | 284 | { |
287 | m_views.setAutoDelete( true ); | 285 | m_views.setAutoDelete( true ); |
288 | m_views.clear(); | 286 | m_views.clear(); |
289 | m_views.setAutoDelete( false ); | 287 | m_views.setAutoDelete( false ); |
290 | } | 288 | } |
291 | delete_d(this); | 289 | delete_d(this); |
292 | } | 290 | } |
293 | 291 | ||
294 | void KateDocument::openURL(const QString &filename) | 292 | void KateDocument::openURL(const QString &filename) |
295 | { | 293 | { |
296 | 294 | ||
297 | m_file=filename; | 295 | m_file=filename; |
298 | fileInfo->setFile (m_file); | 296 | fileInfo->setFile (m_file); |
299 | setMTime(); | 297 | setMTime(); |
300 | 298 | ||
301 | if (!fileInfo->exists() || !fileInfo->isReadable()) | 299 | if (!fileInfo->exists() || !fileInfo->isReadable()) |
302 | { | 300 | { |
303 | qDebug("File doesn't exit or couldn't be read"); | 301 | qDebug("File doesn't exit or couldn't be read"); |
304 | return ; | 302 | return ; |
305 | } | 303 | } |
306 | 304 | ||
307 | buffer->clear(); | 305 | buffer->clear(); |
308 | #warning fixme | 306 | #warning fixme |
309 | // buffer->insertFile(0, m_file, KGlobal::charsets()->codecForName(myEncoding)); | 307 | // buffer->insertFile(0, m_file, KGlobal::charsets()->codecForName(myEncoding)); |
310 | qDebug("Telling buffer to open file"); | 308 | qDebug("Telling buffer to open file"); |
311 | buffer->insertFile(0, m_file, QTextCodec::codecForLocale()); | 309 | buffer->insertFile(0, m_file, QTextCodec::codecForLocale()); |
312 | 310 | ||
313 | setMTime(); | 311 | setMTime(); |
314 | 312 | ||
315 | if (myWordWrap) | 313 | if (myWordWrap) |
316 | wrapText (myWordWrapAt); | 314 | wrapText (myWordWrapAt); |
317 | 315 | ||
318 | int hl = hlManager->wildcardFind( m_file ); | 316 | int hl = hlManager->wildcardFind( m_file ); |
319 | 317 | ||
320 | setHighlight(hl); | 318 | setHighlight(hl); |
321 | 319 | ||
322 | updateLines(); | 320 | updateLines(); |
323 | updateViews(); | 321 | updateViews(); |
324 | 322 | ||
325 | emit fileNameChanged(); | 323 | emit fileNameChanged(); |
326 | 324 | ||
327 | return ; | 325 | return ; |
328 | } | 326 | } |
329 | 327 | ||
330 | bool KateDocument::saveFile() | 328 | bool KateDocument::saveFile() |
331 | { | 329 | { |
332 | 330 | ||
333 | QFile f( m_file ); | 331 | QFile f( m_file ); |
334 | if ( !f.open( IO_WriteOnly ) ) | 332 | if ( !f.open( IO_WriteOnly ) ) |
335 | return false; // Error | 333 | return false; // Error |
336 | 334 | ||
337 | QTextStream stream(&f); | 335 | QTextStream stream(&f); |
338 | 336 | ||
339 | stream.setEncoding(QTextStream::RawUnicode); // disable Unicode headers | 337 | stream.setEncoding(QTextStream::RawUnicode); // disable Unicode headers |
340 | #warning fixme | 338 | #warning fixme |
341 | // stream.setCodec(KGlobal::charsets()->codecForName(myEncoding)); | 339 | // stream.setCodec(KGlobal::charsets()->codecForName(myEncoding)); |
342 | stream.setCodec(QTextCodec::codecForLocale()); // this line sets the mapper to the correct codec | 340 | stream.setCodec(QTextCodec::codecForLocale()); // this line sets the mapper to the correct codec |
343 | 341 | ||
344 | int maxLine = numLines(); | 342 | int maxLine = numLines(); |
345 | int line = 0; | 343 | int line = 0; |
346 | while(true) | 344 | while(true) |
347 | { | 345 | { |
348 | stream << getTextLine(line)->getString(); | 346 | stream << getTextLine(line)->getString(); |
349 | line++; | 347 | line++; |
350 | if (line >= maxLine) break; | 348 | if (line >= maxLine) break; |
351 | 349 | ||
352 | if (eolMode == KateDocument::eolUnix) stream << "\n"; | 350 | if (eolMode == KateDocument::eolUnix) stream << "\n"; |
353 | else if (eolMode == KateDocument::eolDos) stream << "\r\n"; | 351 | else if (eolMode == KateDocument::eolDos) stream << "\r\n"; |
354 | else if (eolMode == KateDocument::eolMacintosh) stream << '\r'; | 352 | else if (eolMode == KateDocument::eolMacintosh) stream << '\r'; |
355 | }; | 353 | }; |
356 | f.close(); | 354 | f.close(); |
357 | 355 | ||
358 | fileInfo->setFile (m_file); | 356 | fileInfo->setFile (m_file); |
359 | setMTime(); | 357 | setMTime(); |
360 | 358 | ||
361 | if (!(d(this)->hlSetByUser)) | 359 | if (!(d(this)->hlSetByUser)) |
362 | { | 360 | { |
363 | int hl = hlManager->wildcardFind( m_file ); | 361 | int hl = hlManager->wildcardFind( m_file ); |
364 | 362 | ||
365 | setHighlight(hl); | 363 | setHighlight(hl); |
366 | } | 364 | } |
367 | emit fileNameChanged (); | 365 | emit fileNameChanged (); |
368 | 366 | ||
369 | return (f.status() == IO_Ok); | 367 | return (f.status() == IO_Ok); |
370 | } | 368 | } |
371 | 369 | ||
372 | KTextEditor::View *KateDocument::createView( QWidget *parent, const char *name ) | 370 | KTextEditor::View *KateDocument::createView( QWidget *parent, const char *name ) |
373 | { | 371 | { |
374 | return new KateView( this, parent, name); | 372 | return new KateView( this, parent, name); |
375 | } | 373 | } |
376 | 374 | ||
377 | QString KateDocument::textLine( int line ) const | 375 | QString KateDocument::textLine( int line ) const |
378 | { | 376 | { |
379 | TextLine::Ptr l = getTextLine( line ); | 377 | TextLine::Ptr l = getTextLine( line ); |
380 | if ( !l ) | 378 | if ( !l ) |
381 | return QString(); | 379 | return QString(); |
382 | 380 | ||
383 | return l->getString(); | 381 | return l->getString(); |
384 | } | 382 | } |
385 | 383 | ||
386 | void KateDocument::replaceLine(const QString& s,int line) | 384 | void KateDocument::replaceLine(const QString& s,int line) |
387 | { | 385 | { |
388 | remove_Line(line,false); | 386 | remove_Line(line,false); |
389 | insert_Line(s,line,true); | 387 | insert_Line(s,line,true); |
390 | } | 388 | } |
391 | 389 | ||
392 | void KateDocument::insertLine( const QString &str, int l ) { | 390 | void KateDocument::insertLine( const QString &str, int l ) { |
393 | insert_Line(str,l,true); | 391 | insert_Line(str,l,true); |
394 | } | 392 | } |
395 | 393 | ||
396 | void KateDocument::insert_Line(const QString& s,int line, bool update) | 394 | void KateDocument::insert_Line(const QString& s,int line, bool update) |
397 | { | 395 | { |
398 | kdDebug(13020)<<"KateDocument::insertLine "<<s<<QString(" %1").arg(line)<<endl; | 396 | kdDebug(13020)<<"KateDocument::insertLine "<<s<<QString(" %1").arg(line)<<endl; |
399 | TextLine::Ptr TL=new TextLine(); | 397 | TextLine::Ptr TL=new TextLine(); |
400 | TL->append(s.unicode(),s.length()); | 398 | TL->append(s.unicode(),s.length()); |
401 | buffer->insertLine(line,TL); | 399 | buffer->insertLine(line,TL); |
402 | if (update) | 400 | if (update) |
403 | { | 401 | { |
404 | newDocGeometry=true; | 402 | newDocGeometry=true; |
405 | updateLines(line); | 403 | updateLines(line); |
406 | updateViews(); | 404 | updateViews(); |
407 | } | 405 | } |
408 | } | 406 | } |
409 | 407 | ||
410 | void KateDocument::insertAt( const QString &s, int line, int col, bool ) | 408 | void KateDocument::insertAt( const QString &s, int line, int col, bool ) |
411 | { | 409 | { |
412 | VConfig c; | 410 | VConfig c; |
413 | c.view = 0; // ### FIXME | 411 | c.view = 0; // ### FIXME |
414 | c.cursor.x = col; | 412 | c.cursor.x = col; |
415 | c.cursor.y = line; | 413 | c.cursor.y = line; |
416 | c.cXPos = 0; // ### FIXME | 414 | c.cXPos = 0; // ### FIXME |
417 | c.flags = 0; // ### FIXME | 415 | c.flags = 0; // ### FIXME |
418 | insert( c, s ); | 416 | insert( c, s ); |
419 | } | 417 | } |
420 | 418 | ||
421 | void KateDocument::removeLine( int line ) { | 419 | void KateDocument::removeLine( int line ) { |
422 | remove_Line(line,true); | 420 | remove_Line(line,true); |
423 | } | 421 | } |
424 | 422 | ||
425 | void KateDocument::remove_Line(int line,bool update) | 423 | void KateDocument::remove_Line(int line,bool update) |
426 | { | 424 | { |
427 | kdDebug(13020)<<"KateDocument::removeLine "<<QString("%1").arg(line)<<endl; | 425 | kdDebug(13020)<<"KateDocument::removeLine "<<QString("%1").arg(line)<<endl; |
428 | buffer->removeLine(line); | 426 | buffer->removeLine(line); |
429 | // newDocGeometry=true; | 427 | // newDocGeometry=true; |
430 | // if line==0) | 428 | // if line==0) |
431 | if (update) | 429 | if (update) |
432 | { | 430 | { |
433 | updateLines(line); | 431 | updateLines(line); |
434 | updateViews(); | 432 | updateViews(); |
435 | } | 433 | } |
436 | } | 434 | } |
437 | 435 | ||
438 | int KateDocument::length() const | 436 | int KateDocument::length() const |
439 | { | 437 | { |
440 | return text().length(); | 438 | return text().length(); |
441 | } | 439 | } |
442 | 440 | ||
443 | void KateDocument::setSelection( int , int , int , int ) | 441 | void KateDocument::setSelection( int , int , int , int ) |
444 | { | 442 | { |
445 | } | 443 | } |
446 | 444 | ||
447 | bool KateDocument::hasSelection() const | 445 | bool KateDocument::hasSelection() const |
448 | { | 446 | { |
449 | return (selectEnd >= selectStart); | 447 | return (selectEnd >= selectStart); |
450 | } | 448 | } |
451 | 449 | ||
452 | QString KateDocument::selection() const | 450 | QString KateDocument::selection() const |
453 | { | 451 | { |
454 | uint flags = 0; | 452 | uint flags = 0; |
455 | TextLine::Ptr textLine; | 453 | TextLine::Ptr textLine; |
456 | int len, z, start, end, i; | 454 | int len, z, start, end, i; |
457 | 455 | ||
458 | len = 1; | 456 | len = 1; |
459 | if (!(flags & KateView::cfVerticalSelect)) { | 457 | if (!(flags & KateView::cfVerticalSelect)) { |
460 | for (z = selectStart; z <= selectEnd; z++) { | 458 | for (z = selectStart; z <= selectEnd; z++) { |
461 | textLine = getTextLine(z); | 459 | textLine = getTextLine(z); |
462 | len += textLine->numSelected(); | 460 | len += textLine->numSelected(); |
463 | if (textLine->isSelected()) len++; | 461 | if (textLine->isSelected()) len++; |
464 | } | 462 | } |
465 | QString s; | 463 | QString s; |
466 | len = 0; | 464 | len = 0; |
467 | for (z = selectStart; z <= selectEnd; z++) { | 465 | for (z = selectStart; z <= selectEnd; z++) { |
468 | textLine = getTextLine(z); | 466 | textLine = getTextLine(z); |
469 | end = 0; | 467 | end = 0; |
470 | do { | 468 | do { |
471 | start = textLine->findUnselected(end); | 469 | start = textLine->findUnselected(end); |
472 | end = textLine->findSelected(start); | 470 | end = textLine->findSelected(start); |
473 | for (i = start; i < end; i++) { | 471 | for (i = start; i < end; i++) { |
474 | s[len] = textLine->getChar(i); | 472 | s[len] = textLine->getChar(i); |
475 | len++; | 473 | len++; |
476 | } | 474 | } |
477 | } while (start < end); | 475 | } while (start < end); |
478 | if (textLine->isSelected()) { | 476 | if (textLine->isSelected()) { |
479 | s[len] = '\n'; | 477 | s[len] = '\n'; |
480 | len++; | 478 | len++; |
481 | } | 479 | } |
482 | } | 480 | } |
483 | // s[len] = '\0'; | 481 | // s[len] = '\0'; |
484 | return s; | 482 | return s; |
485 | } else { | 483 | } else { |
486 | for (z = selectStart; z <= selectEnd; z++) { | 484 | for (z = selectStart; z <= selectEnd; z++) { |
487 | textLine = getTextLine(z); | 485 | textLine = getTextLine(z); |
488 | len += textLine->numSelected() + 1; | 486 | len += textLine->numSelected() + 1; |
489 | } | 487 | } |
490 | QString s; | 488 | QString s; |
491 | len = 0; | 489 | len = 0; |
492 | for (z = selectStart; z <= selectEnd; z++) { | 490 | for (z = selectStart; z <= selectEnd; z++) { |
493 | textLine = getTextLine(z); | 491 | textLine = getTextLine(z); |
494 | end = 0; | 492 | end = 0; |
495 | do { | 493 | do { |
496 | start = textLine->findUnselected(end); | 494 | start = textLine->findUnselected(end); |
497 | end = textLine->findSelected(start); | 495 | end = textLine->findSelected(start); |
498 | for (i = start; i < end; i++) { | 496 | for (i = start; i < end; i++) { |
499 | s[len] = textLine->getChar(i); | 497 | s[len] = textLine->getChar(i); |
500 | len++; | 498 | len++; |
501 | } | 499 | } |
502 | } while (start < end); | 500 | } while (start < end); |
503 | s[len] = '\n'; | 501 | s[len] = '\n'; |
504 | len++; | 502 | len++; |
505 | } | 503 | } |
506 | // s[len] = '\0'; // the final \0 is not counted in length() | 504 | // s[len] = '\0'; // the final \0 is not counted in length() |
507 | return s; | 505 | return s; |
508 | } | 506 | } |
509 | } | 507 | } |
510 | 508 | ||
511 | int KateDocument::numLines() const | 509 | int KateDocument::numLines() const |
512 | { | 510 | { |
513 | return buffer->count(); | 511 | return buffer->count(); |
514 | } | 512 | } |
515 | 513 | ||
516 | 514 | ||
517 | TextLine::Ptr KateDocument::getTextLine(int line) const | 515 | TextLine::Ptr KateDocument::getTextLine(int line) const |
518 | { | 516 | { |
519 | // This is a hack to get this stuff working. | 517 | // This is a hack to get this stuff working. |
520 | return buffer->line(line); | 518 | return buffer->line(line); |
521 | } | 519 | } |
522 | 520 | ||
523 | int KateDocument::textLength(int line) { | 521 | int KateDocument::textLength(int line) { |
524 | TextLine::Ptr textLine = getTextLine(line); | 522 | TextLine::Ptr textLine = getTextLine(line); |
525 | if (!textLine) return 0; | 523 | if (!textLine) return 0; |
526 | return textLine->length(); | 524 | return textLine->length(); |
527 | } | 525 | } |
528 | 526 | ||
529 | void KateDocument::setTabWidth(int chars) { | 527 | void KateDocument::setTabWidth(int chars) { |
530 | if (tabChars == chars) return; | 528 | if (tabChars == chars) return; |
531 | if (chars < 1) chars = 1; | 529 | if (chars < 1) chars = 1; |
532 | if (chars > 16) chars = 16; | 530 | if (chars > 16) chars = 16; |
533 | tabChars = chars; | 531 | tabChars = chars; |
534 | updateFontData(); | 532 | updateFontData(); |
535 | 533 | ||
536 | maxLength = -1; | 534 | maxLength = -1; |
537 | for (int i=0; i < buffer->count(); i++) | 535 | for (int i=0; i < buffer->count(); i++) |
538 | { | 536 | { |
539 | TextLine::Ptr textLine = buffer->line(i); | 537 | TextLine::Ptr textLine = buffer->line(i); |
540 | int len = textWidth(textLine,textLine->length()); | 538 | int len = textWidth(textLine,textLine->length()); |
541 | if (len > maxLength) { | 539 | if (len > maxLength) { |
542 | maxLength = len; | 540 | maxLength = len; |
543 | longestLine = textLine; | 541 | longestLine = textLine; |
544 | } | 542 | } |
545 | } | 543 | } |
546 | } | 544 | } |
547 | 545 | ||
548 | void KateDocument::setReadOnly(bool m) { | 546 | void KateDocument::setReadOnly(bool m) { |
549 | KTextEditor::View *view; | 547 | KTextEditor::View *view; |
550 | 548 | ||
551 | if (m != readOnly) { | 549 | if (m != readOnly) { |
552 | readOnly = m; | 550 | readOnly = m; |
553 | // if (readOnly) recordReset(); | 551 | // if (readOnly) recordReset(); |
554 | for (view = m_views.first(); view != 0L; view = m_views.next() ) { | 552 | for (view = m_views.first(); view != 0L; view = m_views.next() ) { |
555 | emit static_cast<KateView *>( view )->newStatus(); | 553 | emit static_cast<KateView *>( view )->newStatus(); |
556 | } | 554 | } |
557 | } | 555 | } |
558 | } | 556 | } |
559 | 557 | ||
560 | bool KateDocument::isReadOnly() const { | 558 | bool KateDocument::isReadOnly() const { |
561 | return readOnly; | 559 | return readOnly; |
562 | } | 560 | } |
563 | 561 | ||
564 | void KateDocument::setNewDoc( bool m ) | 562 | void KateDocument::setNewDoc( bool m ) |
565 | { | 563 | { |
566 | // KTextEditor::View *view; | 564 | // KTextEditor::View *view; |
567 | 565 | ||
568 | if ( m != newDoc ) | 566 | if ( m != newDoc ) |
569 | { | 567 | { |
570 | newDoc = m; | 568 | newDoc = m; |
571 | //// if (readOnly) recordReset(); | 569 | //// if (readOnly) recordReset(); |
572 | // for (view = m_views.first(); view != 0L; view = m_views.next() ) { | 570 | // for (view = m_views.first(); view != 0L; view = m_views.next() ) { |
573 | // emit static_cast<KateView *>( view )->newStatus(); | 571 | // emit static_cast<KateView *>( view )->newStatus(); |
574 | // } | 572 | // } |
575 | } | 573 | } |
576 | } | 574 | } |
577 | 575 | ||
578 | bool KateDocument::isNewDoc() const { | 576 | bool KateDocument::isNewDoc() const { |
579 | return newDoc; | 577 | return newDoc; |
580 | } | 578 | } |
581 | 579 | ||
582 | void KateDocument::setModified(bool m) { | 580 | void KateDocument::setModified(bool m) { |
583 | KTextEditor::View *view; | 581 | KTextEditor::View *view; |
584 | 582 | ||
585 | if (m != modified) { | 583 | if (m != modified) { |
586 | modified = m; | 584 | modified = m; |
587 | for (view = m_views.first(); view != 0L; view = m_views.next() ) { | 585 | for (view = m_views.first(); view != 0L; view = m_views.next() ) { |
588 | emit static_cast<KateView *>( view )->newStatus(); | 586 | emit static_cast<KateView *>( view )->newStatus(); |
589 | } | 587 | } |
590 | emit modifiedChanged (); | 588 | emit modifiedChanged (); |
591 | } | 589 | } |
592 | } | 590 | } |
593 | 591 | ||
594 | bool KateDocument::isModified() const { | 592 | bool KateDocument::isModified() const { |
595 | return modified; | 593 | return modified; |
596 | } | 594 | } |
597 | 595 | ||
598 | void KateDocument::readConfig() | 596 | void KateDocument::readConfig() |
599 | { | 597 | { |
600 | KateConfig *config = KGlobal::config(); | 598 | KateConfig *config = KGlobal::config(); |
601 | config->setGroup("Kate Document"); | 599 | config->setGroup("Kate Document"); |
602 | 600 | ||
603 | myWordWrap = config->readBoolEntry("Word Wrap On", false); | 601 | myWordWrap = config->readBoolEntry("Word Wrap On", false); |
604 | myWordWrapAt = config->readNumEntry("Word Wrap At", 80); | 602 | myWordWrapAt = config->readNumEntry("Word Wrap At", 80); |
605 | if (myWordWrap) | 603 | if (myWordWrap) |
606 | wrapText (myWordWrapAt); | 604 | wrapText (myWordWrapAt); |
607 | 605 | ||
608 | setTabWidth(config->readNumEntry("TabWidth", 8)); | 606 | setTabWidth(config->readNumEntry("TabWidth", 8)); |
609 | setUndoSteps(config->readNumEntry("UndoSteps", 50)); | 607 | setUndoSteps(config->readNumEntry("UndoSteps", 50)); |
610 | m_singleSelection = config->readBoolEntry("SingleSelection", false); | 608 | m_singleSelection = config->readBoolEntry("SingleSelection", false); |
611 | myEncoding = config->readEntry("Encoding", QString::fromLatin1(QTextCodec::codecForLocale()->name())); | 609 | myEncoding = config->readEntry("Encoding", QString::fromLatin1(QTextCodec::codecForLocale()->name())); |
612 | setFont (config->readFontEntry("Font", myFont)); | 610 | setFont (config->readFontEntry("Font", myFont)); |
613 | 611 | ||
614 | colors[0] = config->readColorEntry("Color Background", colors[0]); | 612 | colors[0] = config->readColorEntry("Color Background", colors[0]); |
615 | colors[1] = config->readColorEntry("Color Selected", colors[1]); | 613 | colors[1] = config->readColorEntry("Color Selected", colors[1]); |
616 | 614 | ||
617 | // config->sync(); | 615 | // config->sync(); |
618 | } | 616 | } |
619 | 617 | ||
620 | void KateDocument::writeConfig() | 618 | void KateDocument::writeConfig() |
621 | { | 619 | { |
622 | KateConfig *config = KGlobal::config(); | 620 | KateConfig *config = KGlobal::config(); |
623 | config->setGroup("Kate Document"); | 621 | config->setGroup("Kate Document"); |
624 | config->writeEntry("Word Wrap On", myWordWrap); | 622 | config->writeEntry("Word Wrap On", myWordWrap); |
625 | config->writeEntry("Word Wrap At", myWordWrapAt); | 623 | config->writeEntry("Word Wrap At", myWordWrapAt); |
626 | config->writeEntry("TabWidth", tabChars); | 624 | config->writeEntry("TabWidth", tabChars); |
627 | config->writeEntry("UndoSteps", undoSteps); | 625 | config->writeEntry("UndoSteps", undoSteps); |
628 | config->writeEntry("SingleSelection", m_singleSelection); | 626 | config->writeEntry("SingleSelection", m_singleSelection); |
629 | config->writeEntry("Encoding", myEncoding); | 627 | config->writeEntry("Encoding", myEncoding); |
630 | config->writeEntry("Font", myFont); | 628 | config->writeEntry("Font", myFont); |
631 | config->writeEntry("Color Background", colors[0]); | 629 | config->writeEntry("Color Background", colors[0]); |
632 | config->writeEntry("Color Selected", colors[1]); | 630 | config->writeEntry("Color Selected", colors[1]); |
633 | // config->sync(); | 631 | // config->sync(); |
634 | } | 632 | } |
635 | 633 | ||
636 | void KateDocument::readSessionConfig(KateConfig *config) | 634 | void KateDocument::readSessionConfig(KateConfig *config) |
637 | { | 635 | { |
638 | m_url = config->readEntry("URL"); // ### doesn't this break the encoding? (Simon) | 636 | m_url = config->readEntry("URL"); // ### doesn't this break the encoding? (Simon) |
639 | setHighlight(hlManager->nameFind(config->readEntry("Highlight"))); | 637 | setHighlight(hlManager->nameFind(config->readEntry("Highlight"))); |
640 | // anders: restore bookmarks if possible | 638 | // anders: restore bookmarks if possible |
641 | QValueList<int> l = config->readIntListEntry("Bookmarks"); | 639 | QValueList<int> l = config->readIntListEntry("Bookmarks"); |
642 | if ( l.count() ) { | 640 | if ( l.count() ) { |
643 | for (uint i=0; i < l.count(); i++) { | 641 | for (uint i=0; i < l.count(); i++) { |
644 | if ( numLines() < l[i] ) break; | 642 | if ( numLines() < l[i] ) break; |
645 | getTextLine( l[i] )->addMark( Bookmark ); | 643 | getTextLine( l[i] )->addMark( Bookmark ); |
646 | } | 644 | } |
647 | } | 645 | } |
648 | } | 646 | } |
649 | 647 | ||
650 | void KateDocument::writeSessionConfig(KateConfig *config) | 648 | void KateDocument::writeSessionConfig(KateConfig *config) |
651 | { | 649 | { |
652 | #if 0 | 650 | #if 0 |
653 | config->writeEntry("URL", m_url); // ### encoding?? (Simon) | 651 | config->writeEntry("URL", m_url); // ### encoding?? (Simon) |
654 | config->writeEntry("Highlight", m_highlight->name()); | 652 | config->writeEntry("Highlight", m_highlight->name()); |
655 | // anders: save bookmarks | 653 | // anders: save bookmarks |
656 | QList<Kate::Mark> l = marks(); | 654 | QList<Kate::Mark> l = marks(); |
657 | QValueList<int> ml; | 655 | QValueList<int> ml; |
658 | for (uint i=0; i < l.count(); i++) { | 656 | for (uint i=0; i < l.count(); i++) { |
659 | if ( l.at(i)->type == 1) // only save bookmarks | 657 | if ( l.at(i)->type == 1) // only save bookmarks |
660 | ml << l.at(i)->line; | 658 | ml << l.at(i)->line; |
661 | } | 659 | } |
662 | if ( ml.count() ) | 660 | if ( ml.count() ) |
663 | config->writeEntry("Bookmarks", ml); | 661 | config->writeEntry("Bookmarks", ml); |
664 | #endif | 662 | #endif |
665 | } | 663 | } |
666 | 664 | ||
667 | 665 | ||
668 | void KateDocument::setHighlight(int n) { | 666 | void KateDocument::setHighlight(int n) { |
669 | Highlight *h; | 667 | Highlight *h; |
670 | 668 | ||
671 | // hlNumber = n; | 669 | // hlNumber = n; |
672 | 670 | ||
673 | h = hlManager->getHl(n); | 671 | h = hlManager->getHl(n); |
674 | if (h == m_highlight) { | 672 | if (h == m_highlight) { |
675 | updateLines(); | 673 | updateLines(); |
676 | } else { | 674 | } else { |
677 | if (m_highlight != 0L) m_highlight->release(); | 675 | if (m_highlight != 0L) m_highlight->release(); |
678 | h->use(); | 676 | h->use(); |
679 | m_highlight = h; | 677 | m_highlight = h; |
680 | makeAttribs(); | 678 | makeAttribs(); |
681 | } | 679 | } |
682 | PreHighlightedTill=0; | 680 | PreHighlightedTill=0; |
683 | RequestPreHighlightTill=0; | 681 | RequestPreHighlightTill=0; |
684 | emit(highlightChanged()); | 682 | emit(highlightChanged()); |
685 | } | 683 | } |
686 | 684 | ||
687 | void KateDocument::makeAttribs() { | 685 | void KateDocument::makeAttribs() { |
688 | qDebug("KateDocument::makeAttribs()"); | 686 | qDebug("KateDocument::makeAttribs()"); |
689 | m_numAttribs = hlManager->makeAttribs(m_highlight, m_attribs, maxAttribs); | 687 | m_numAttribs = hlManager->makeAttribs(m_highlight, m_attribs, maxAttribs); |
690 | updateFontData(); | 688 | updateFontData(); |
691 | updateLines(); | 689 | updateLines(); |
692 | } | 690 | } |
693 | 691 | ||
694 | void KateDocument::updateFontData() { | 692 | void KateDocument::updateFontData() { |
695 | int maxAscent, maxDescent; | 693 | int maxAscent, maxDescent; |
696 | int tabWidth; | 694 | int tabWidth; |
697 | KateView *view; | 695 | KateView *view; |
698 | 696 | ||
699 | maxAscent = myFontMetrics.ascent(); | 697 | maxAscent = myFontMetrics.ascent(); |
700 | maxDescent = myFontMetrics.descent(); | 698 | maxDescent = myFontMetrics.descent(); |
701 | tabWidth = myFontMetrics.width(' '); | 699 | tabWidth = myFontMetrics.width(' '); |
702 | 700 | ||
703 | fontHeight = maxAscent + maxDescent + 1; | 701 | fontHeight = maxAscent + maxDescent + 1; |
704 | fontAscent = maxAscent; | 702 | fontAscent = maxAscent; |
705 | m_tabWidth = tabChars*tabWidth; | 703 | m_tabWidth = tabChars*tabWidth; |
706 | 704 | ||
707 | for (view = views.first(); view != 0L; view = views.next() ) { | 705 | for (view = views.first(); view != 0L; view = views.next() ) { |
708 | view->myViewInternal->drawBuffer->resize(view->width(),fontHeight); | 706 | view->myViewInternal->drawBuffer->resize(view->width(),fontHeight); |
709 | view->tagAll(); | 707 | view->tagAll(); |
710 | view->updateCursor(); | 708 | view->updateCursor(); |
711 | } | 709 | } |
712 | } | 710 | } |
713 | 711 | ||
714 | void KateDocument::hlChanged() { //slot | 712 | void KateDocument::hlChanged() { //slot |
715 | makeAttribs(); | 713 | makeAttribs(); |
716 | updateViews(); | 714 | updateViews(); |
717 | } | 715 | } |
718 | 716 | ||
719 | 717 | ||
720 | void KateDocument::addView(KTextEditor::View *view) { | 718 | void KateDocument::addView(KTextEditor::View *view) { |
721 | views.append( static_cast<KateView *>( view ) ); | 719 | views.append( static_cast<KateView *>( view ) ); |
722 | KTextEditor::Document::addView( view ); | 720 | KTextEditor::Document::addView( view ); |
723 | connect( static_cast<KateView *>( view ), SIGNAL( destroyed() ), this, SLOT( slotViewDestroyed() ) ); | 721 | connect( static_cast<KateView *>( view ), SIGNAL( destroyed() ), this, SLOT( slotViewDestroyed() ) ); |
724 | } | 722 | } |
725 | 723 | ||
726 | void KateDocument::removeView(KTextEditor::View *view) { | 724 | void KateDocument::removeView(KTextEditor::View *view) { |
727 | // if (undoView == view) recordReset(); | 725 | // if (undoView == view) recordReset(); |
728 | disconnect( static_cast<KateView *>( view ), SIGNAL( destroyed() ), this, SLOT( slotViewDestroyed() ) ); | 726 | disconnect( static_cast<KateView *>( view ), SIGNAL( destroyed() ), this, SLOT( slotViewDestroyed() ) ); |
729 | views.removeRef( static_cast<KateView *>( view ) ); | 727 | views.removeRef( static_cast<KateView *>( view ) ); |
730 | KTextEditor::Document::removeView( view ); | 728 | KTextEditor::Document::removeView( view ); |
731 | } | 729 | } |
732 | 730 | ||
733 | void KateDocument::slotViewDestroyed() | 731 | void KateDocument::slotViewDestroyed() |
734 | { | 732 | { |
735 | views.removeRef( static_cast<const KateView *>( sender() ) ); | 733 | views.removeRef( static_cast<const KateView *>( sender() ) ); |
736 | } | 734 | } |
737 | 735 | ||
738 | bool KateDocument::ownedView(KateView *view) { | 736 | bool KateDocument::ownedView(KateView *view) { |
739 | // do we own the given view? | 737 | // do we own the given view? |
740 | return (views.containsRef(view) > 0); | 738 | return (views.containsRef(view) > 0); |
741 | } | 739 | } |
742 | 740 | ||
743 | bool KateDocument::isLastView(int numViews) { | 741 | bool KateDocument::isLastView(int numViews) { |
744 | return ((int) views.count() == numViews); | 742 | return ((int) views.count() == numViews); |
745 | } | 743 | } |
746 | 744 | ||
747 | int KateDocument::textWidth(const TextLine::Ptr &textLine, int cursorX) { | 745 | int KateDocument::textWidth(const TextLine::Ptr &textLine, int cursorX) { |
748 | int x; | 746 | int x; |
749 | int z; | 747 | int z; |
750 | QChar ch; | 748 | QChar ch; |
751 | Attribute *a; | 749 | Attribute *a; |
752 | 750 | ||
753 | x = 0; | 751 | x = 0; |
754 | for (z = 0; z < cursorX; z++) { | 752 | for (z = 0; z < cursorX; z++) { |
755 | ch = textLine->getChar(z); | 753 | ch = textLine->getChar(z); |
756 | a = &m_attribs[textLine->getAttr(z)]; | 754 | a = &m_attribs[textLine->getAttr(z)]; |
757 | 755 | ||
758 | if (ch == '\t') | 756 | if (ch == '\t') |
759 | x += m_tabWidth - (x % m_tabWidth); | 757 | x += m_tabWidth - (x % m_tabWidth); |
760 | else if (a->bold && a->italic) | 758 | else if (a->bold && a->italic) |
761 | x += myFontMetricsBI.width(ch); | 759 | x += myFontMetricsBI.width(ch); |
762 | else if (a->bold) | 760 | else if (a->bold) |
763 | x += myFontMetricsBold.width(ch); | 761 | x += myFontMetricsBold.width(ch); |
764 | else if (a->italic) | 762 | else if (a->italic) |
765 | x += myFontMetricsItalic.width(ch); | 763 | x += myFontMetricsItalic.width(ch); |
766 | else | 764 | else |
767 | x += myFontMetrics.width(ch); | 765 | x += myFontMetrics.width(ch); |
768 | } | 766 | } |
769 | return x; | 767 | return x; |
770 | } | 768 | } |
771 | 769 | ||
772 | int KateDocument::textWidth(PointStruc &cursor) { | 770 | int KateDocument::textWidth(PointStruc &cursor) { |
773 | if (cursor.x < 0) | 771 | if (cursor.x < 0) |
774 | cursor.x = 0; | 772 | cursor.x = 0; |
775 | if (cursor.y < 0) | 773 | if (cursor.y < 0) |
776 | cursor.y = 0; | 774 | cursor.y = 0; |
777 | if (cursor.y >= numLines()) | 775 | if (cursor.y >= numLines()) |
778 | cursor.y = lastLine(); | 776 | cursor.y = lastLine(); |
779 | return textWidth(getTextLine(cursor.y),cursor.x); | 777 | return textWidth(getTextLine(cursor.y),cursor.x); |
780 | } | 778 | } |
781 | 779 | ||
782 | int KateDocument::textWidth(bool wrapCursor, PointStruc &cursor, int xPos) { | 780 | int KateDocument::textWidth(bool wrapCursor, PointStruc &cursor, int xPos) { |
783 | int len; | 781 | int len; |
784 | int x, oldX; | 782 | int x, oldX; |
785 | int z; | 783 | int z; |
786 | QChar ch; | 784 | QChar ch; |
787 | Attribute *a; | 785 | Attribute *a; |
788 | 786 | ||
789 | if (cursor.y < 0) cursor.y = 0; | 787 | if (cursor.y < 0) cursor.y = 0; |
790 | if (cursor.y > lastLine()) cursor.y = lastLine(); | 788 | if (cursor.y > lastLine()) cursor.y = lastLine(); |
791 | TextLine::Ptr textLine = getTextLine(cursor.y); | 789 | TextLine::Ptr textLine = getTextLine(cursor.y); |
792 | len = textLine->length(); | 790 | len = textLine->length(); |
793 | 791 | ||
794 | x = oldX = z = 0; | 792 | x = oldX = z = 0; |
795 | while (x < xPos && (!wrapCursor || z < len)) { | 793 | while (x < xPos && (!wrapCursor || z < len)) { |
796 | oldX = x; | 794 | oldX = x; |
797 | ch = textLine->getChar(z); | 795 | ch = textLine->getChar(z); |
798 | a = &m_attribs[textLine->getAttr(z)]; | 796 | a = &m_attribs[textLine->getAttr(z)]; |
799 | 797 | ||
800 | if (ch == '\t') | 798 | if (ch == '\t') |
801 | x += m_tabWidth - (x % m_tabWidth); | 799 | x += m_tabWidth - (x % m_tabWidth); |
802 | else if (a->bold && a->italic) | 800 | else if (a->bold && a->italic) |
803 | x += myFontMetricsBI.width(ch); | 801 | x += myFontMetricsBI.width(ch); |
804 | else if (a->bold) | 802 | else if (a->bold) |
805 | x += myFontMetricsBold.width(ch); | 803 | x += myFontMetricsBold.width(ch); |
806 | else if (a->italic) | 804 | else if (a->italic) |
807 | x += myFontMetricsItalic.width(ch); | 805 | x += myFontMetricsItalic.width(ch); |
808 | else | 806 | else |
809 | x += myFontMetrics.width(ch); | 807 | x += myFontMetrics.width(ch); |
810 | 808 | ||
811 | z++; | 809 | z++; |
812 | } | 810 | } |
813 | if (xPos - oldX < x - xPos && z > 0) { | 811 | if (xPos - oldX < x - xPos && z > 0) { |
814 | z--; | 812 | z--; |
815 | x = oldX; | 813 | x = oldX; |
816 | } | 814 | } |
817 | cursor.x = z; | 815 | cursor.x = z; |
818 | return x; | 816 | return x; |
819 | } | 817 | } |
820 | 818 | ||
821 | 819 | ||
822 | int KateDocument::textPos(const TextLine::Ptr &textLine, int xPos) { | 820 | int KateDocument::textPos(const TextLine::Ptr &textLine, int xPos) { |
823 | int x, oldX; | 821 | int x, oldX; |
824 | int z; | 822 | int z; |
825 | QChar ch; | 823 | QChar ch; |
826 | Attribute *a; | 824 | Attribute *a; |
827 | 825 | ||
828 | x = oldX = z = 0; | 826 | x = oldX = z = 0; |
829 | while (x < xPos) { // && z < len) { | 827 | while (x < xPos) { // && z < len) { |
830 | oldX = x; | 828 | oldX = x; |
831 | ch = textLine->getChar(z); | 829 | ch = textLine->getChar(z); |
832 | a = &m_attribs[textLine->getAttr(z)]; | 830 | a = &m_attribs[textLine->getAttr(z)]; |
833 | 831 | ||
834 | if (ch == '\t') | 832 | if (ch == '\t') |
835 | x += m_tabWidth - (x % m_tabWidth); | 833 | x += m_tabWidth - (x % m_tabWidth); |
836 | else if (a->bold && a->italic) | 834 | else if (a->bold && a->italic) |
diff --git a/noncore/apps/tinykate/libkate/kateconfig.cpp b/noncore/apps/tinykate/libkate/kateconfig.cpp index 06ac49f..96f91fb 100644 --- a/noncore/apps/tinykate/libkate/kateconfig.cpp +++ b/noncore/apps/tinykate/libkate/kateconfig.cpp | |||
@@ -1,634 +1,632 @@ | |||
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 | #include <qdir.h> | 21 | #include <qdir.h> |
22 | #include <qfile.h> | ||
23 | #include <qfileinfo.h> | ||
24 | #include <qmessagebox.h> | 22 | #include <qmessagebox.h> |
25 | #if QT_VERSION <= 230 && defined(QT_NO_CODECS) | 23 | #if QT_VERSION <= 230 && defined(QT_NO_CODECS) |
26 | #include <qtextcodec.h> | 24 | #include <qtextcodec.h> |
27 | #endif | 25 | #endif |
28 | #include <qtextstream.h> | 26 | #include <qtextstream.h> |
29 | 27 | ||
30 | #include <sys/stat.h> | 28 | #include <sys/stat.h> |
31 | #include <sys/types.h> | 29 | #include <sys/types.h> |
32 | #include <fcntl.h> | 30 | #include <fcntl.h> |
33 | #include <stdlib.h> | 31 | #include <stdlib.h> |
34 | #include <unistd.h> | 32 | #include <unistd.h> |
35 | 33 | ||
36 | #define QTOPIA_INTERNAL_LANGLIST | 34 | #define QTOPIA_INTERNAL_LANGLIST |
37 | #include "kateconfig.h" | 35 | #include "kateconfig.h" |
38 | #include <qpe/global.h> | 36 | #include <qpe/global.h> |
39 | 37 | ||
40 | 38 | ||
41 | /*! | 39 | /*! |
42 | \internal | 40 | \internal |
43 | */ | 41 | */ |
44 | QString KateConfig::configFilename(const QString& name, Domain d) | 42 | QString KateConfig::configFilename(const QString& name, Domain d) |
45 | { | 43 | { |
46 | switch (d) { | 44 | switch (d) { |
47 | case File: | 45 | case File: |
48 | return name; | 46 | return name; |
49 | case User: { | 47 | case User: { |
50 | QDir dir = (QString(getenv("HOME")) + "/Settings"); | 48 | QDir dir = (QString(getenv("HOME")) + "/Settings"); |
51 | if ( !dir.exists() ) | 49 | if ( !dir.exists() ) |
52 | mkdir(dir.path().local8Bit(),0700); | 50 | mkdir(dir.path().local8Bit(),0700); |
53 | return dir.path() + "/" + name + ".conf"; | 51 | return dir.path() + "/" + name + ".conf"; |
54 | } | 52 | } |
55 | } | 53 | } |
56 | return name; | 54 | return name; |
57 | } | 55 | } |
58 | 56 | ||
59 | /*! | 57 | /*! |
60 | \class KateConfig config.h | 58 | \class KateConfig config.h |
61 | \brief The KateConfig class provides for saving application cofniguration state. | 59 | \brief The KateConfig class provides for saving application cofniguration state. |
62 | 60 | ||
63 | You should keep a KateConfig in existence only while you do not want others | 61 | You should keep a KateConfig in existence only while you do not want others |
64 | to be able to change the state. There is no locking currently, but there | 62 | to be able to change the state. There is no locking currently, but there |
65 | may be in the future. | 63 | may be in the future. |
66 | */ | 64 | */ |
67 | 65 | ||
68 | /*! | 66 | /*! |
69 | \enum KateConfig::KateConfigGroup | 67 | \enum KateConfig::KateConfigGroup |
70 | \internal | 68 | \internal |
71 | */ | 69 | */ |
72 | 70 | ||
73 | /*! | 71 | /*! |
74 | \enum KateConfig::Domain | 72 | \enum KateConfig::Domain |
75 | 73 | ||
76 | \value File | 74 | \value File |
77 | \value User | 75 | \value User |
78 | 76 | ||
79 | See KateConfig for details. | 77 | See KateConfig for details. |
80 | */ | 78 | */ |
81 | 79 | ||
82 | /*! | 80 | /*! |
83 | Constructs a config that will load or create a configuration with the | 81 | Constructs a config that will load or create a configuration with the |
84 | given \a name in the given \a domain. | 82 | given \a name in the given \a domain. |
85 | 83 | ||
86 | You must call setGroup() before doing much else with the KateConfig. | 84 | You must call setGroup() before doing much else with the KateConfig. |
87 | 85 | ||
88 | In the default Domain, \e User, | 86 | In the default Domain, \e User, |
89 | the configuration is user-specific. \a name should not contain "/" in | 87 | the configuration is user-specific. \a name should not contain "/" in |
90 | this case, and in general should be the name of the C++ class that is | 88 | this case, and in general should be the name of the C++ class that is |
91 | primarily responsible for maintaining the configuration. | 89 | primarily responsible for maintaining the configuration. |
92 | 90 | ||
93 | In the File Domain, \a name is an absolute filename. | 91 | In the File Domain, \a name is an absolute filename. |
94 | */ | 92 | */ |
95 | KateConfig::KateConfig( const QString &name, Domain domain ) | 93 | KateConfig::KateConfig( const QString &name, Domain domain ) |
96 | : filename( configFilename(name,domain) ) | 94 | : filename( configFilename(name,domain) ) |
97 | { | 95 | { |
98 | qWarning("KateConfig constructor\n"); | 96 | qWarning("KateConfig constructor\n"); |
99 | git = groups.end(); | 97 | git = groups.end(); |
100 | read(); | 98 | read(); |
101 | QStringList l = Global::languageList(); | 99 | QStringList l = Global::languageList(); |
102 | lang = l[0]; | 100 | lang = l[0]; |
103 | glang = l[1]; | 101 | glang = l[1]; |
104 | } | 102 | } |
105 | 103 | ||
106 | 104 | ||
107 | // Sharp ROM compatibility | 105 | // Sharp ROM compatibility |
108 | KateConfig::KateConfig ( const QString &name, bool what ) | 106 | KateConfig::KateConfig ( const QString &name, bool what ) |
109 | : filename( configFilename(name,what ? User : File) ) | 107 | : filename( configFilename(name,what ? User : File) ) |
110 | { | 108 | { |
111 | git = groups.end(); | 109 | git = groups.end(); |
112 | read(); | 110 | read(); |
113 | QStringList l = Global::languageList(); | 111 | QStringList l = Global::languageList(); |
114 | lang = l[0]; | 112 | lang = l[0]; |
115 | glang = l[1]; | 113 | glang = l[1]; |
116 | } | 114 | } |
117 | 115 | ||
118 | /*! | 116 | /*! |
119 | Writes any changes to disk and destroys the in-memory object. | 117 | Writes any changes to disk and destroys the in-memory object. |
120 | */ | 118 | */ |
121 | KateConfig::~KateConfig() | 119 | KateConfig::~KateConfig() |
122 | { | 120 | { |
123 | qWarning("KateConfig destructor\n"); | 121 | qWarning("KateConfig destructor\n"); |
124 | if ( changed ) | 122 | if ( changed ) |
125 | write(); | 123 | write(); |
126 | } | 124 | } |
127 | 125 | ||
128 | /*! | 126 | /*! |
129 | Returns whether the current group has an entry called \a key. | 127 | Returns whether the current group has an entry called \a key. |
130 | */ | 128 | */ |
131 | bool KateConfig::hasKey( const QString &key ) const | 129 | bool KateConfig::hasKey( const QString &key ) const |
132 | { | 130 | { |
133 | if ( groups.end() == git ) | 131 | if ( groups.end() == git ) |
134 | return FALSE; | 132 | return FALSE; |
135 | KateConfigGroup::ConstIterator it = ( *git ).find( key ); | 133 | KateConfigGroup::ConstIterator it = ( *git ).find( key ); |
136 | return it != ( *git ).end(); | 134 | return it != ( *git ).end(); |
137 | } | 135 | } |
138 | 136 | ||
139 | /*! | 137 | /*! |
140 | Sets the current group for subsequent reading and writing of | 138 | Sets the current group for subsequent reading and writing of |
141 | entries to \a gname. Grouping allows the application to partition the namespace. | 139 | entries to \a gname. Grouping allows the application to partition the namespace. |
142 | 140 | ||
143 | This function must be called prior to any reading or writing | 141 | This function must be called prior to any reading or writing |
144 | of entries. | 142 | of entries. |
145 | 143 | ||
146 | The \a gname must not be empty. | 144 | The \a gname must not be empty. |
147 | */ | 145 | */ |
148 | void KateConfig::setGroup( const QString &gname ) | 146 | void KateConfig::setGroup( const QString &gname ) |
149 | { | 147 | { |
150 | QMap< QString, KateConfigGroup>::Iterator it = groups.find( gname ); | 148 | QMap< QString, KateConfigGroup>::Iterator it = groups.find( gname ); |
151 | if ( it == groups.end() ) { | 149 | if ( it == groups.end() ) { |
152 | git = groups.insert( gname, KateConfigGroup() ); | 150 | git = groups.insert( gname, KateConfigGroup() ); |
153 | changed = TRUE; | 151 | changed = TRUE; |
154 | return; | 152 | return; |
155 | } | 153 | } |
156 | git = it; | 154 | git = it; |
157 | } | 155 | } |
158 | 156 | ||
159 | /*! | 157 | /*! |
160 | Writes a (\a key, \a value) entry to the current group. | 158 | Writes a (\a key, \a value) entry to the current group. |
161 | 159 | ||
162 | \sa readEntry() | 160 | \sa readEntry() |
163 | */ | 161 | */ |
164 | void KateConfig::writeEntry( const QString &key, const char* value ) | 162 | void KateConfig::writeEntry( const QString &key, const char* value ) |
165 | { | 163 | { |
166 | writeEntry(key,QString(value)); | 164 | writeEntry(key,QString(value)); |
167 | } | 165 | } |
168 | 166 | ||
169 | /*! | 167 | /*! |
170 | Writes a (\a key, \a value) entry to the current group. | 168 | Writes a (\a key, \a value) entry to the current group. |
171 | 169 | ||
172 | \sa readEntry() | 170 | \sa readEntry() |
173 | */ | 171 | */ |
174 | void KateConfig::writeEntry( const QString &key, const QString &value ) | 172 | void KateConfig::writeEntry( const QString &key, const QString &value ) |
175 | { | 173 | { |
176 | if ( git == groups.end() ) { | 174 | if ( git == groups.end() ) { |
177 | qWarning( "no group set" ); | 175 | qWarning( "no group set" ); |
178 | return; | 176 | return; |
179 | } | 177 | } |
180 | if ( (*git)[key] != value ) { | 178 | if ( (*git)[key] != value ) { |
181 | ( *git ).insert( key, value ); | 179 | ( *git ).insert( key, value ); |
182 | changed = TRUE; | 180 | changed = TRUE; |
183 | } | 181 | } |
184 | } | 182 | } |
185 | 183 | ||
186 | /* | 184 | /* |
187 | Note that the degree of protection offered by the encryption here is | 185 | Note that the degree of protection offered by the encryption here is |
188 | only sufficient to avoid the most casual observation of the configuration | 186 | only sufficient to avoid the most casual observation of the configuration |
189 | files. People with access to the files can write down the contents and | 187 | files. People with access to the files can write down the contents and |
190 | decrypt it using this source code. | 188 | decrypt it using this source code. |
191 | 189 | ||
192 | Conceivably, and at some burden to the user, this encryption could | 190 | Conceivably, and at some burden to the user, this encryption could |
193 | be improved. | 191 | be improved. |
194 | */ | 192 | */ |
195 | static QString encipher(const QString& plain) | 193 | static QString encipher(const QString& plain) |
196 | { | 194 | { |
197 | // mainly, we make it long | 195 | // mainly, we make it long |
198 | QString cipher; | 196 | QString cipher; |
199 | int mix=28730492; | 197 | int mix=28730492; |
200 | for (int i=0; i<(int)plain.length(); i++) { | 198 | for (int i=0; i<(int)plain.length(); i++) { |
201 | int u = plain[i].unicode(); | 199 | int u = plain[i].unicode(); |
202 | int c = u ^ mix; | 200 | int c = u ^ mix; |
203 | QString x = QString::number(c,36); | 201 | QString x = QString::number(c,36); |
204 | cipher.append(QChar('a'+x.length())); | 202 | cipher.append(QChar('a'+x.length())); |
205 | cipher.append(x); | 203 | cipher.append(x); |
206 | mix *= u; | 204 | mix *= u; |
207 | } | 205 | } |
208 | return cipher; | 206 | return cipher; |
209 | } | 207 | } |
210 | 208 | ||
211 | static QString decipher(const QString& cipher) | 209 | static QString decipher(const QString& cipher) |
212 | { | 210 | { |
213 | QString plain; | 211 | QString plain; |
214 | int mix=28730492; | 212 | int mix=28730492; |
215 | for (int i=0; i<(int)cipher.length();) { | 213 | for (int i=0; i<(int)cipher.length();) { |
216 | int l = cipher[i].unicode()-'a'; | 214 | int l = cipher[i].unicode()-'a'; |
217 | QString x = cipher.mid(i+1,l); i+=l+1; | 215 | QString x = cipher.mid(i+1,l); i+=l+1; |
218 | int u = x.toInt(0,36) ^ mix; | 216 | int u = x.toInt(0,36) ^ mix; |
219 | plain.append(QChar(u)); | 217 | plain.append(QChar(u)); |
220 | mix *= u; | 218 | mix *= u; |
221 | } | 219 | } |
222 | return plain; | 220 | return plain; |
223 | } | 221 | } |
224 | 222 | ||
225 | /*! | 223 | /*! |
226 | Writes an encrypted (\a key, \a value) entry to the current group. | 224 | Writes an encrypted (\a key, \a value) entry to the current group. |
227 | 225 | ||
228 | Note that the degree of protection offered by the encryption is | 226 | Note that the degree of protection offered by the encryption is |
229 | only sufficient to avoid the most casual observation of the configuration | 227 | only sufficient to avoid the most casual observation of the configuration |
230 | files. | 228 | files. |
231 | 229 | ||
232 | \sa readEntry() | 230 | \sa readEntry() |
233 | */ | 231 | */ |
234 | void KateConfig::writeEntryCrypt( const QString &key, const QString &value ) | 232 | void KateConfig::writeEntryCrypt( const QString &key, const QString &value ) |
235 | { | 233 | { |
236 | if ( git == groups.end() ) { | 234 | if ( git == groups.end() ) { |
237 | qWarning( "no group set" ); | 235 | qWarning( "no group set" ); |
238 | return; | 236 | return; |
239 | } | 237 | } |
240 | QString evalue = encipher(value); | 238 | QString evalue = encipher(value); |
241 | if ( (*git)[key] != evalue ) { | 239 | if ( (*git)[key] != evalue ) { |
242 | ( *git ).insert( key, evalue ); | 240 | ( *git ).insert( key, evalue ); |
243 | changed = TRUE; | 241 | changed = TRUE; |
244 | } | 242 | } |
245 | } | 243 | } |
246 | 244 | ||
247 | /*! | 245 | /*! |
248 | Writes a (\a key, \a num) entry to the current group. | 246 | Writes a (\a key, \a num) entry to the current group. |
249 | 247 | ||
250 | \sa readNumEntry() | 248 | \sa readNumEntry() |
251 | */ | 249 | */ |
252 | void KateConfig::writeEntry( const QString &key, int num ) | 250 | void KateConfig::writeEntry( const QString &key, int num ) |
253 | { | 251 | { |
254 | QString s; | 252 | QString s; |
255 | s.setNum( num ); | 253 | s.setNum( num ); |
256 | writeEntry( key, s ); | 254 | writeEntry( key, s ); |
257 | } | 255 | } |
258 | 256 | ||
259 | void KateConfig::writeEntry( const QString &key, unsigned int num ) | 257 | void KateConfig::writeEntry( const QString &key, unsigned int num ) |
260 | { | 258 | { |
261 | QString s; | 259 | QString s; |
262 | s.setNum( num ); | 260 | s.setNum( num ); |
263 | writeEntry( key, s ); | 261 | writeEntry( key, s ); |
264 | } | 262 | } |
265 | 263 | ||
266 | #ifdef Q_HAS_BOOL_TYPE | 264 | #ifdef Q_HAS_BOOL_TYPE |
267 | /*! | 265 | /*! |
268 | Writes a (\a key, \a b) entry to the current group. This is equivalent | 266 | Writes a (\a key, \a b) entry to the current group. This is equivalent |
269 | to writing a 0 or 1 as an integer entry. | 267 | to writing a 0 or 1 as an integer entry. |
270 | 268 | ||
271 | \sa readBoolEntry() | 269 | \sa readBoolEntry() |
272 | */ | 270 | */ |
273 | void KateConfig::writeEntry( const QString &key, bool b ) | 271 | void KateConfig::writeEntry( const QString &key, bool b ) |
274 | { | 272 | { |
275 | QString s; | 273 | QString s; |
276 | s.setNum( ( int )b ); | 274 | s.setNum( ( int )b ); |
277 | writeEntry( key, s ); | 275 | writeEntry( key, s ); |
278 | } | 276 | } |
279 | #endif | 277 | #endif |
280 | 278 | ||
281 | /*! | 279 | /*! |
282 | Writes a (\a key, \a lst) entry to the current group. The list | 280 | Writes a (\a key, \a lst) entry to the current group. The list |
283 | is separated by \a sep, so the strings must not contain that character. | 281 | is separated by \a sep, so the strings must not contain that character. |
284 | 282 | ||
285 | \sa readListEntry() | 283 | \sa readListEntry() |
286 | */ | 284 | */ |
287 | void KateConfig::writeEntry( const QString &key, const QStringList &lst, const QChar &sep ) | 285 | void KateConfig::writeEntry( const QString &key, const QStringList &lst, const QChar &sep ) |
288 | { | 286 | { |
289 | QString s; | 287 | QString s; |
290 | QStringList::ConstIterator it = lst.begin(); | 288 | QStringList::ConstIterator it = lst.begin(); |
291 | for ( ; it != lst.end(); ++it ) | 289 | for ( ; it != lst.end(); ++it ) |
292 | s += *it + sep; | 290 | s += *it + sep; |
293 | writeEntry( key, s ); | 291 | writeEntry( key, s ); |
294 | } | 292 | } |
295 | 293 | ||
296 | void KateConfig::writeEntry( const QString &key, const QColor &val ) | 294 | void KateConfig::writeEntry( const QString &key, const QColor &val ) |
297 | { | 295 | { |
298 | QStringList l; | 296 | QStringList l; |
299 | l.append( QString().setNum(val.red()) ); | 297 | l.append( QString().setNum(val.red()) ); |
300 | l.append( QString().setNum(val.green()) ); | 298 | l.append( QString().setNum(val.green()) ); |
301 | l.append( QString().setNum(val.blue()) ); | 299 | l.append( QString().setNum(val.blue()) ); |
302 | 300 | ||
303 | writeEntry( key, l, QChar(',') ); | 301 | writeEntry( key, l, QChar(',') ); |
304 | } | 302 | } |
305 | 303 | ||
306 | void KateConfig::writeEntry( const QString &key, const QFont &val ) | 304 | void KateConfig::writeEntry( const QString &key, const QFont &val ) |
307 | { | 305 | { |
308 | QStringList l; | 306 | QStringList l; |
309 | l.append( val.family() ); | 307 | l.append( val.family() ); |
310 | l.append( QString().setNum(val.pointSize()) ); | 308 | l.append( QString().setNum(val.pointSize()) ); |
311 | l.append( QString().setNum(val.weight()) ); | 309 | l.append( QString().setNum(val.weight()) ); |
312 | l.append( QString().setNum((int)val.italic()) ); | 310 | l.append( QString().setNum((int)val.italic()) ); |
313 | l.append( QString().setNum((int)val.charSet()) ); | 311 | l.append( QString().setNum((int)val.charSet()) ); |
314 | 312 | ||
315 | writeEntry( key, l, QChar(',') ); | 313 | writeEntry( key, l, QChar(',') ); |
316 | } | 314 | } |
317 | 315 | ||
318 | /*! | 316 | /*! |
319 | Removes the \a key entry from the current group. Does nothing if | 317 | Removes the \a key entry from the current group. Does nothing if |
320 | there is no such entry. | 318 | there is no such entry. |
321 | */ | 319 | */ |
322 | 320 | ||
323 | void KateConfig::removeEntry( const QString &key ) | 321 | void KateConfig::removeEntry( const QString &key ) |
324 | { | 322 | { |
325 | if ( git == groups.end() ) { | 323 | if ( git == groups.end() ) { |
326 | qWarning( "no group set" ); | 324 | qWarning( "no group set" ); |
327 | return; | 325 | return; |
328 | } | 326 | } |
329 | ( *git ).remove( key ); | 327 | ( *git ).remove( key ); |
330 | changed = TRUE; | 328 | changed = TRUE; |
331 | } | 329 | } |
332 | 330 | ||
333 | /*! | 331 | /*! |
334 | \fn bool KateConfig::operator == ( const KateConfig & other ) const | 332 | \fn bool KateConfig::operator == ( const KateConfig & other ) const |
335 | 333 | ||
336 | Tests for equality with \a other. KateConfig objects are equal if they refer to the same filename. | 334 | Tests for equality with \a other. KateConfig objects are equal if they refer to the same filename. |
337 | */ | 335 | */ |
338 | 336 | ||
339 | /*! | 337 | /*! |
340 | \fn bool KateConfig::operator != ( const KateConfig & other ) const | 338 | \fn bool KateConfig::operator != ( const KateConfig & other ) const |
341 | 339 | ||
342 | Tests for inequality with \a other. KateConfig objects are equal if they refer to the same filename. | 340 | Tests for inequality with \a other. KateConfig objects are equal if they refer to the same filename. |
343 | */ | 341 | */ |
344 | 342 | ||
345 | /*! | 343 | /*! |
346 | \fn QString KateConfig::readEntry( const QString &key, const QString &deflt ) const | 344 | \fn QString KateConfig::readEntry( const QString &key, const QString &deflt ) const |
347 | 345 | ||
348 | Reads a string entry stored with \a key, defaulting to \a deflt if there is no entry. | 346 | Reads a string entry stored with \a key, defaulting to \a deflt if there is no entry. |
349 | */ | 347 | */ |
350 | 348 | ||
351 | /*! | 349 | /*! |
352 | \internal | 350 | \internal |
353 | For compatibility, non-const version. | 351 | For compatibility, non-const version. |
354 | */ | 352 | */ |
355 | QString KateConfig::readEntry( const QString &key, const QString &deflt ) | 353 | QString KateConfig::readEntry( const QString &key, const QString &deflt ) |
356 | { | 354 | { |
357 | QString res = readEntryDirect( key+"["+lang+"]" ); | 355 | QString res = readEntryDirect( key+"["+lang+"]" ); |
358 | if ( !res.isNull() ) | 356 | if ( !res.isNull() ) |
359 | return res; | 357 | return res; |
360 | if ( !glang.isEmpty() ) { | 358 | if ( !glang.isEmpty() ) { |
361 | res = readEntryDirect( key+"["+glang+"]" ); | 359 | res = readEntryDirect( key+"["+glang+"]" ); |
362 | if ( !res.isNull() ) | 360 | if ( !res.isNull() ) |
363 | return res; | 361 | return res; |
364 | } | 362 | } |
365 | return readEntryDirect( key, deflt ); | 363 | return readEntryDirect( key, deflt ); |
366 | } | 364 | } |
367 | 365 | ||
368 | /*! | 366 | /*! |
369 | \fn QString KateConfig::readEntryCrypt( const QString &key, const QString &deflt ) const | 367 | \fn QString KateConfig::readEntryCrypt( const QString &key, const QString &deflt ) const |
370 | 368 | ||
371 | Reads an encrypted string entry stored with \a key, defaulting to \a deflt if there is no entry. | 369 | Reads an encrypted string entry stored with \a key, defaulting to \a deflt if there is no entry. |
372 | */ | 370 | */ |
373 | 371 | ||
374 | /*! | 372 | /*! |
375 | \internal | 373 | \internal |
376 | For compatibility, non-const version. | 374 | For compatibility, non-const version. |
377 | */ | 375 | */ |
378 | QString KateConfig::readEntryCrypt( const QString &key, const QString &deflt ) | 376 | QString KateConfig::readEntryCrypt( const QString &key, const QString &deflt ) |
379 | { | 377 | { |
380 | QString res = readEntryDirect( key+"["+lang+"]" ); | 378 | QString res = readEntryDirect( key+"["+lang+"]" ); |
381 | if ( res.isNull() && glang.isEmpty() ) | 379 | if ( res.isNull() && glang.isEmpty() ) |
382 | res = readEntryDirect( key+"["+glang+"]" ); | 380 | res = readEntryDirect( key+"["+glang+"]" ); |
383 | if ( res.isNull() ) | 381 | if ( res.isNull() ) |
384 | res = readEntryDirect( key, QString::null ); | 382 | res = readEntryDirect( key, QString::null ); |
385 | if ( res.isNull() ) | 383 | if ( res.isNull() ) |
386 | return deflt; | 384 | return deflt; |
387 | return decipher(res); | 385 | return decipher(res); |
388 | } | 386 | } |
389 | 387 | ||
390 | /*! | 388 | /*! |
391 | \fn QString KateConfig::readEntryDirect( const QString &key, const QString &deflt ) const | 389 | \fn QString KateConfig::readEntryDirect( const QString &key, const QString &deflt ) const |
392 | \internal | 390 | \internal |
393 | */ | 391 | */ |
394 | 392 | ||
395 | /*! | 393 | /*! |
396 | \internal | 394 | \internal |
397 | For compatibility, non-const version. | 395 | For compatibility, non-const version. |
398 | */ | 396 | */ |
399 | QString KateConfig::readEntryDirect( const QString &key, const QString &deflt ) | 397 | QString KateConfig::readEntryDirect( const QString &key, const QString &deflt ) |
400 | { | 398 | { |
401 | if ( git == groups.end() ) { | 399 | if ( git == groups.end() ) { |
402 | //qWarning( "no group set" ); | 400 | //qWarning( "no group set" ); |
403 | return deflt; | 401 | return deflt; |
404 | } | 402 | } |
405 | KateConfigGroup::ConstIterator it = ( *git ).find( key ); | 403 | KateConfigGroup::ConstIterator it = ( *git ).find( key ); |
406 | if ( it != ( *git ).end() ) | 404 | if ( it != ( *git ).end() ) |
407 | return *it; | 405 | return *it; |
408 | else | 406 | else |
409 | return deflt; | 407 | return deflt; |
410 | } | 408 | } |
411 | 409 | ||
412 | /*! | 410 | /*! |
413 | \fn int KateConfig::readNumEntry( const QString &key, int deflt ) const | 411 | \fn int KateConfig::readNumEntry( const QString &key, int deflt ) const |
414 | Reads a numeric entry stored with \a key, defaulting to \a deflt if there is no entry. | 412 | Reads a numeric entry stored with \a key, defaulting to \a deflt if there is no entry. |
415 | */ | 413 | */ |
416 | 414 | ||
417 | /*! | 415 | /*! |
418 | \internal | 416 | \internal |
419 | For compatibility, non-const version. | 417 | For compatibility, non-const version. |
420 | */ | 418 | */ |
421 | int KateConfig::readNumEntry( const QString &key, int deflt ) | 419 | int KateConfig::readNumEntry( const QString &key, int deflt ) |
422 | { | 420 | { |
423 | QString s = readEntry( key ); | 421 | QString s = readEntry( key ); |
424 | if ( s.isEmpty() ) | 422 | if ( s.isEmpty() ) |
425 | return deflt; | 423 | return deflt; |
426 | else | 424 | else |
427 | return s.toInt(); | 425 | return s.toInt(); |
428 | } | 426 | } |
429 | 427 | ||
430 | /*! | 428 | /*! |
431 | \fn bool KateConfig::readBoolEntry( const QString &key, bool deflt ) const | 429 | \fn bool KateConfig::readBoolEntry( const QString &key, bool deflt ) const |
432 | Reads a bool entry stored with \a key, defaulting to \a deflt if there is no entry. | 430 | Reads a bool entry stored with \a key, defaulting to \a deflt if there is no entry. |
433 | */ | 431 | */ |
434 | 432 | ||
435 | /*! | 433 | /*! |
436 | \internal | 434 | \internal |
437 | For compatibility, non-const version. | 435 | For compatibility, non-const version. |
438 | */ | 436 | */ |
439 | bool KateConfig::readBoolEntry( const QString &key, bool deflt ) | 437 | bool KateConfig::readBoolEntry( const QString &key, bool deflt ) |
440 | { | 438 | { |
441 | QString s = readEntry( key ); | 439 | QString s = readEntry( key ); |
442 | if ( s.isEmpty() ) | 440 | if ( s.isEmpty() ) |
443 | return deflt; | 441 | return deflt; |
444 | else | 442 | else |
445 | return (bool)s.toInt(); | 443 | return (bool)s.toInt(); |
446 | } | 444 | } |
447 | 445 | ||
448 | /*! | 446 | /*! |
449 | \fn QStringList KateConfig::readListEntry( const QString &key, const QChar &sep ) const | 447 | \fn QStringList KateConfig::readListEntry( const QString &key, const QChar &sep ) const |
450 | Reads a string list entry stored with \a key, and with \a sep as the separator. | 448 | Reads a string list entry stored with \a key, and with \a sep as the separator. |
451 | */ | 449 | */ |
452 | 450 | ||
453 | /*! | 451 | /*! |
454 | \internal | 452 | \internal |
455 | For compatibility, non-const version. | 453 | For compatibility, non-const version. |
456 | */ | 454 | */ |
457 | QStringList KateConfig::readListEntry( const QString &key, const QChar &sep ) | 455 | QStringList KateConfig::readListEntry( const QString &key, const QChar &sep ) |
458 | { | 456 | { |
459 | QString s = readEntry( key ); | 457 | QString s = readEntry( key ); |
460 | if ( s.isEmpty() ) | 458 | if ( s.isEmpty() ) |
461 | return QStringList(); | 459 | return QStringList(); |
462 | else | 460 | else |
463 | return QStringList::split( sep, s ); | 461 | return QStringList::split( sep, s ); |
464 | } | 462 | } |
465 | 463 | ||
466 | QColor KateConfig::readColorEntry( const QString &key, const QColor &def ) const | 464 | QColor KateConfig::readColorEntry( const QString &key, const QColor &def ) const |
467 | { | 465 | { |
468 | QStringList list = readListEntry(key, QChar(',')); | 466 | QStringList list = readListEntry(key, QChar(',')); |
469 | if( list.count() != 3 ) | 467 | if( list.count() != 3 ) |
470 | return def; | 468 | return def; |
471 | 469 | ||
472 | return QColor(list[0].toInt(), list[1].toInt(), list[2].toInt()); | 470 | return QColor(list[0].toInt(), list[1].toInt(), list[2].toInt()); |
473 | } | 471 | } |
474 | 472 | ||
475 | QFont KateConfig::readFontEntry( const QString &key, const QFont &def ) const | 473 | QFont KateConfig::readFontEntry( const QString &key, const QFont &def ) const |
476 | { | 474 | { |
477 | QStringList list = readListEntry(key, QChar(',')); | 475 | QStringList list = readListEntry(key, QChar(',')); |
478 | if( list.count() != 5 ) | 476 | if( list.count() != 5 ) |
479 | return def; | 477 | return def; |
480 | 478 | ||
481 | return QFont(list[0], list[1].toInt(), list[2].toInt(), (bool)list[3].toInt(), (QFont::CharSet)list[4].toInt()); | 479 | return QFont(list[0], list[1].toInt(), list[2].toInt(), (bool)list[3].toInt(), (QFont::CharSet)list[4].toInt()); |
482 | } | 480 | } |
483 | 481 | ||
484 | QValueList<int> KateConfig::readIntListEntry( const QString &key ) const | 482 | QValueList<int> KateConfig::readIntListEntry( const QString &key ) const |
485 | { | 483 | { |
486 | QString s = readEntry( key ); | 484 | QString s = readEntry( key ); |
487 | QValueList<int> il; | 485 | QValueList<int> il; |
488 | if ( s.isEmpty() ) | 486 | if ( s.isEmpty() ) |
489 | return il; | 487 | return il; |
490 | 488 | ||
491 | QStringList l = QStringList::split( QChar(','), s ); | 489 | QStringList l = QStringList::split( QChar(','), s ); |
492 | 490 | ||
493 | QStringList::Iterator l_it; | 491 | QStringList::Iterator l_it; |
494 | for( l_it = l.begin(); l_it != l.end(); ++l_it ) | 492 | for( l_it = l.begin(); l_it != l.end(); ++l_it ) |
495 | il.append( (*l_it).toInt() ); | 493 | il.append( (*l_it).toInt() ); |
496 | return il; | 494 | return il; |
497 | } | 495 | } |
498 | 496 | ||
499 | /*! | 497 | /*! |
500 | Removes all entries from the current group. | 498 | Removes all entries from the current group. |
501 | */ | 499 | */ |
502 | void KateConfig::clearGroup() | 500 | void KateConfig::clearGroup() |
503 | { | 501 | { |
504 | if ( git == groups.end() ) { | 502 | if ( git == groups.end() ) { |
505 | qWarning( "no group set" ); | 503 | qWarning( "no group set" ); |
506 | return; | 504 | return; |
507 | } | 505 | } |
508 | if ( !(*git).isEmpty() ) { | 506 | if ( !(*git).isEmpty() ) { |
509 | ( *git ).clear(); | 507 | ( *git ).clear(); |
510 | changed = TRUE; | 508 | changed = TRUE; |
511 | } | 509 | } |
512 | } | 510 | } |
513 | 511 | ||
514 | /*! | 512 | /*! |
515 | \internal | 513 | \internal |
516 | */ | 514 | */ |
517 | void KateConfig::write( const QString &fn ) | 515 | void KateConfig::write( const QString &fn ) |
518 | { | 516 | { |
519 | QString strNewFile; | 517 | QString strNewFile; |
520 | if ( !fn.isEmpty() ) | 518 | if ( !fn.isEmpty() ) |
521 | filename = fn; | 519 | filename = fn; |
522 | strNewFile = filename + ".new"; | 520 | strNewFile = filename + ".new"; |
523 | 521 | ||
524 | QFile f( strNewFile ); | 522 | QFile f( strNewFile ); |
525 | if ( !f.open( IO_WriteOnly|IO_Raw ) ) { | 523 | if ( !f.open( IO_WriteOnly|IO_Raw ) ) { |
526 | qWarning( "could not open for writing `%s'", strNewFile.latin1() ); | 524 | qWarning( "could not open for writing `%s'", strNewFile.latin1() ); |
527 | git = groups.end(); | 525 | git = groups.end(); |
528 | return; | 526 | return; |
529 | } | 527 | } |
530 | 528 | ||
531 | QString str; | 529 | QString str; |
532 | QCString cstr; | 530 | QCString cstr; |
533 | QMap< QString, KateConfigGroup >::Iterator g_it = groups.begin(); | 531 | QMap< QString, KateConfigGroup >::Iterator g_it = groups.begin(); |
534 | 532 | ||
535 | for ( ; g_it != groups.end(); ++g_it ) { | 533 | for ( ; g_it != groups.end(); ++g_it ) { |
536 | str += "[" + g_it.key() + "]\n"; | 534 | str += "[" + g_it.key() + "]\n"; |
537 | KateConfigGroup::Iterator e_it = ( *g_it ).begin(); | 535 | KateConfigGroup::Iterator e_it = ( *g_it ).begin(); |
538 | for ( ; e_it != ( *g_it ).end(); ++e_it ) | 536 | for ( ; e_it != ( *g_it ).end(); ++e_it ) |
539 | str += e_it.key() + " = " + *e_it + "\n"; | 537 | str += e_it.key() + " = " + *e_it + "\n"; |
540 | } | 538 | } |
541 | cstr = str.utf8(); | 539 | cstr = str.utf8(); |
542 | 540 | ||
543 | int total_length; | 541 | int total_length; |
544 | total_length = f.writeBlock( cstr.data(), cstr.length() ); | 542 | total_length = f.writeBlock( cstr.data(), cstr.length() ); |
545 | if ( total_length != int(cstr.length()) ) { | 543 | if ( total_length != int(cstr.length()) ) { |
546 | QMessageBox::critical( 0, QObject::tr("Out of Space"), | 544 | QMessageBox::critical( 0, QObject::tr("Out of Space"), |
547 | QObject::tr("There was a problem creating\nKateConfiguration Information \nfor this program.\n\nPlease free up some space and\ntry again.") ); | 545 | QObject::tr("There was a problem creating\nKateConfiguration Information \nfor this program.\n\nPlease free up some space and\ntry again.") ); |
548 | f.close(); | 546 | f.close(); |
549 | QFile::remove( strNewFile ); | 547 | QFile::remove( strNewFile ); |
550 | return; | 548 | return; |
551 | } | 549 | } |
552 | 550 | ||
553 | f.close(); | 551 | f.close(); |
554 | // now rename the file... | 552 | // now rename the file... |
555 | if ( rename( strNewFile, filename ) < 0 ) { | 553 | if ( rename( strNewFile, filename ) < 0 ) { |
556 | qWarning( "problem renaming the file %s to %s", strNewFile.latin1(), | 554 | qWarning( "problem renaming the file %s to %s", strNewFile.latin1(), |
557 | filename.latin1() ); | 555 | filename.latin1() ); |
558 | QFile::remove( strNewFile ); | 556 | QFile::remove( strNewFile ); |
559 | } | 557 | } |
560 | } | 558 | } |
561 | 559 | ||
562 | /*! | 560 | /*! |
563 | Returns whether the KateConfig is in a valid state. | 561 | Returns whether the KateConfig is in a valid state. |
564 | */ | 562 | */ |
565 | bool KateConfig::isValid() const | 563 | bool KateConfig::isValid() const |
566 | { | 564 | { |
567 | return groups.end() != git; | 565 | return groups.end() != git; |
568 | } | 566 | } |
569 | 567 | ||
570 | /*! | 568 | /*! |
571 | \internal | 569 | \internal |
572 | */ | 570 | */ |
573 | void KateConfig::read() | 571 | void KateConfig::read() |
574 | { | 572 | { |
575 | changed = FALSE; | 573 | changed = FALSE; |
576 | 574 | ||
577 | if ( !QFileInfo( filename ).exists() ) { | 575 | if ( !QFileInfo( filename ).exists() ) { |
578 | git = groups.end(); | 576 | git = groups.end(); |
579 | return; | 577 | return; |
580 | } | 578 | } |
581 | 579 | ||
582 | QFile f( filename ); | 580 | QFile f( filename ); |
583 | if ( !f.open( IO_ReadOnly ) ) { | 581 | if ( !f.open( IO_ReadOnly ) ) { |
584 | git = groups.end(); | 582 | git = groups.end(); |
585 | return; | 583 | return; |
586 | } | 584 | } |
587 | 585 | ||
588 | QTextStream s( &f ); | 586 | QTextStream s( &f ); |
589 | #if QT_VERSION <= 230 && defined(QT_NO_CODECS) | 587 | #if QT_VERSION <= 230 && defined(QT_NO_CODECS) |
590 | // The below should work, but doesn't in Qt 2.3.0 | 588 | // The below should work, but doesn't in Qt 2.3.0 |
591 | s.setCodec( QTextCodec::codecForMib( 106 ) ); | 589 | s.setCodec( QTextCodec::codecForMib( 106 ) ); |
592 | #else | 590 | #else |
593 | s.setEncoding( QTextStream::UnicodeUTF8 ); | 591 | s.setEncoding( QTextStream::UnicodeUTF8 ); |
594 | #endif | 592 | #endif |
595 | 593 | ||
596 | QStringList list = QStringList::split('\n', s.read() ); | 594 | QStringList list = QStringList::split('\n', s.read() ); |
597 | f.close(); | 595 | f.close(); |
598 | 596 | ||
599 | for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { | 597 | for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { |
600 | if ( !parse( *it ) ) { | 598 | if ( !parse( *it ) ) { |
601 | git = groups.end(); | 599 | git = groups.end(); |
602 | return; | 600 | return; |
603 | } | 601 | } |
604 | } | 602 | } |
605 | } | 603 | } |
606 | 604 | ||
607 | /*! | 605 | /*! |
608 | \internal | 606 | \internal |
609 | */ | 607 | */ |
610 | bool KateConfig::parse( const QString &l ) | 608 | bool KateConfig::parse( const QString &l ) |
611 | { | 609 | { |
612 | QString line = l.stripWhiteSpace(); | 610 | QString line = l.stripWhiteSpace(); |
613 | 611 | ||
614 | if ( line [0] == QChar ( '#' )) | 612 | if ( line [0] == QChar ( '#' )) |
615 | return true; // ignore comments | 613 | return true; // ignore comments |
616 | 614 | ||
617 | if ( line[ 0 ] == QChar( '[' ) ) { | 615 | if ( line[ 0 ] == QChar( '[' ) ) { |
618 | QString gname = line; | 616 | QString gname = line; |
619 | gname = gname.remove( 0, 1 ); | 617 | gname = gname.remove( 0, 1 ); |
620 | if ( gname[ (int)gname.length() - 1 ] == QChar( ']' ) ) | 618 | if ( gname[ (int)gname.length() - 1 ] == QChar( ']' ) ) |
621 | gname = gname.remove( gname.length() - 1, 1 ); | 619 | gname = gname.remove( gname.length() - 1, 1 ); |
622 | git = groups.insert( gname, KateConfigGroup() ); | 620 | git = groups.insert( gname, KateConfigGroup() ); |
623 | } else if ( !line.isEmpty() ) { | 621 | } else if ( !line.isEmpty() ) { |
624 | if ( git == groups.end() ) | 622 | if ( git == groups.end() ) |
625 | return FALSE; | 623 | return FALSE; |
626 | int eq = line.find( '=' ); | 624 | int eq = line.find( '=' ); |
627 | if ( eq == -1 ) | 625 | if ( eq == -1 ) |
628 | return FALSE; | 626 | return FALSE; |
629 | QString key = line.left(eq).stripWhiteSpace(); | 627 | QString key = line.left(eq).stripWhiteSpace(); |
630 | QString value = line.mid(eq+1).stripWhiteSpace(); | 628 | QString value = line.mid(eq+1).stripWhiteSpace(); |
631 | ( *git ).insert( key, value ); | 629 | ( *git ).insert( key, value ); |
632 | } | 630 | } |
633 | return TRUE; | 631 | return TRUE; |
634 | } | 632 | } |
diff --git a/noncore/apps/tinykate/libkate/view/kateview.cpp b/noncore/apps/tinykate/libkate/view/kateview.cpp index 794fbdb..423634b 100644 --- a/noncore/apps/tinykate/libkate/view/kateview.cpp +++ b/noncore/apps/tinykate/libkate/view/kateview.cpp | |||
@@ -1,852 +1,845 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | kateview.cpp - description | 2 | kateview.cpp - description |
3 | ------------------- | 3 | ------------------- |
4 | begin : Mon Jan 15 2001 | 4 | begin : Mon Jan 15 2001 |
5 | copyright : (C) 2001 by Christoph "Crossfire" Cullmann | 5 | copyright : (C) 2001 by Christoph "Crossfire" Cullmann |
6 | (C) 2002 by Joseph Wenninger | 6 | (C) 2002 by Joseph Wenninger |
7 | email : crossfire@babylon2k.de | 7 | email : crossfire@babylon2k.de |
8 | jowenn@kde.org | 8 | jowenn@kde.org |
9 | ***************************************************************************/ | 9 | ***************************************************************************/ |
10 | 10 | ||
11 | /*************************************************************************** | 11 | /*************************************************************************** |
12 | * * | 12 | * * |
13 | * This program is free software; you can redistribute it and/or modify * | 13 | * This program is free software; you can redistribute it and/or modify * |
14 | * it under the terms of the GNU General Public License as published by * | 14 | * it under the terms of the GNU General Public License as published by * |
15 | * the Free Software Foundation; either version 2 of the License, or * | 15 | * the Free Software Foundation; either version 2 of the License, or * |
16 | * (at your option) any later version. * | 16 | * (at your option) any later version. * |
17 | * * | 17 | * * |
18 | ***************************************************************************/ | 18 | ***************************************************************************/ |
19 | 19 | ||
20 | /* | 20 | /* |
21 | Copyright (C) 1998, 1999 Jochen Wilhelmy | 21 | Copyright (C) 1998, 1999 Jochen Wilhelmy |
22 | digisnap@cs.tu-berlin.de | 22 | digisnap@cs.tu-berlin.de |
23 | 23 | ||
24 | This library is free software; you can redistribute it and/or | 24 | This library is free software; you can redistribute it and/or |
25 | modify it under the terms of the GNU Library General Public | 25 | modify it under the terms of the GNU Library General Public |
26 | License as published by the Free Software Foundation; either | 26 | License as published by the Free Software Foundation; either |
27 | version 2 of the License, or (at your option) any later version. | 27 | version 2 of the License, or (at your option) any later version. |
28 | 28 | ||
29 | This library is distributed in the hope that it will be useful, | 29 | This library is distributed in the hope that it will be useful, |
30 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 30 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
31 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 31 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
32 | Library General Public License for more details. | 32 | Library General Public License for more details. |
33 | 33 | ||
34 | You should have received a copy of the GNU Library General Public License | 34 | You should have received a copy of the GNU Library General Public License |
35 | along with this library; see the file COPYING.LIB. If not, write to | 35 | along with this library; see the file COPYING.LIB. If not, write to |
36 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 36 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
37 | Boston, MA 02111-1307, USA. | 37 | Boston, MA 02111-1307, USA. |
38 | */ | 38 | */ |
39 | 39 | ||
40 | 40 | ||
41 | 41 | ||
42 | #include "kateview.h" | 42 | #include "kateview.h" |
43 | 43 | ||
44 | #include "../document/katedocument.h" | 44 | #include "../document/katedocument.h" |
45 | #include "../document/katecmd.h" | 45 | #include "../document/katecmd.h" |
46 | #include "../document/katehighlight.h" | 46 | #include "../document/katehighlight.h" |
47 | #include "kateviewdialog.h" | ||
48 | #include "../document/katedialogs.h" | 47 | #include "../document/katedialogs.h" |
48 | #include "kateviewdialog.h" | ||
49 | #include <kateconfig.h> | 49 | #include <kateconfig.h> |
50 | 50 | ||
51 | #include <qfocusdata.h> | ||
52 | #include <kdebug.h> | ||
53 | #include <kapplication.h> | 51 | #include <kapplication.h> |
54 | #include <qscrollbar.h> | 52 | #include <qscrollbar.h> |
55 | #include <qiodevice.h> | ||
56 | #include <qpopupmenu.h> | 53 | #include <qpopupmenu.h> |
57 | #include <kpopupmenu.h> | 54 | #include <kpopupmenu.h> |
58 | #include <qkeycode.h> | 55 | #include <qkeycode.h> |
59 | #include <qintdict.h> | 56 | #include <qintdict.h> |
60 | #include <qfont.h> | 57 | #include <qfont.h> |
61 | #include <qpainter.h> | 58 | #include <qpainter.h> |
62 | #include <qpixmap.h> | 59 | #include <qpixmap.h> |
63 | #include <qfileinfo.h> | 60 | #include <qfileinfo.h> |
64 | #include <qfile.h> | 61 | #include <qfile.h> |
65 | #include <qevent.h> | 62 | #include <qevent.h> |
66 | #include <qdir.h> | 63 | #include <qdir.h> |
67 | #include <qvbox.h> | 64 | #include <qvbox.h> |
68 | #include <qprintdialog.h> | 65 | #include <qprintdialog.h> |
69 | #include <qpaintdevicemetrics.h> | 66 | #include <qpaintdevicemetrics.h> |
70 | #include <qiodevice.h> | ||
71 | #include <qbuffer.h> | 67 | #include <qbuffer.h> |
72 | #include <qfocusdata.h> | ||
73 | #include <klocale.h> | 68 | #include <klocale.h> |
74 | #include <kglobal.h> | 69 | #include <kglobal.h> |
75 | #include <kdebug.h> | ||
76 | #include <kmessagebox.h> | 70 | #include <kmessagebox.h> |
77 | #include <qregexp.h> | 71 | #include <qregexp.h> |
78 | #include <kdialogbase.h> | 72 | #include <kdialogbase.h> |
79 | #include <klineeditdlg.h> | 73 | #include <klineeditdlg.h> |
80 | #include <qapplication.h> | 74 | #include <qapplication.h> |
81 | #include <kfiledialog.h> | 75 | #include <kfiledialog.h> |
82 | #include <kiconloader.h> | 76 | #include <kiconloader.h> |
83 | #include "../document/katetextline.h" | 77 | #include "../document/katetextline.h" |
84 | #include "kateviewdialog.h" | ||
85 | #include "kateundohistory.h" | 78 | #include "kateundohistory.h" |
86 | #include <qlayout.h> | 79 | #include <qlayout.h> |
87 | #include <qpe/qpeapplication.h> | 80 | #include <qpe/qpeapplication.h> |
88 | 81 | ||
89 | KateViewInternal::KateViewInternal(KateView *view, KateDocument *doc) : QWidget(view) | 82 | KateViewInternal::KateViewInternal(KateView *view, KateDocument *doc) : QWidget(view) |
90 | { | 83 | { |
91 | waitForPreHighlight=-1; | 84 | waitForPreHighlight=-1; |
92 | myView = view; | 85 | myView = view; |
93 | myDoc = doc; | 86 | myDoc = doc; |
94 | 87 | ||
95 | iconBorderWidth = 16; | 88 | iconBorderWidth = 16; |
96 | iconBorderHeight = 800; | 89 | iconBorderHeight = 800; |
97 | 90 | ||
98 | QWidget::setCursor(ibeamCursor); | 91 | QWidget::setCursor(ibeamCursor); |
99 | setBackgroundMode(NoBackground); | 92 | setBackgroundMode(NoBackground); |
100 | 93 | ||
101 | setFocusPolicy(StrongFocus); | 94 | setFocusPolicy(StrongFocus); |
102 | 95 | ||
103 | xScroll = new QScrollBar(QScrollBar::Horizontal,myView); | 96 | xScroll = new QScrollBar(QScrollBar::Horizontal,myView); |
104 | yScroll = new QScrollBar(QScrollBar::Vertical,myView); | 97 | yScroll = new QScrollBar(QScrollBar::Vertical,myView); |
105 | connect(xScroll,SIGNAL(valueChanged(int)),SLOT(changeXPos(int))); | 98 | connect(xScroll,SIGNAL(valueChanged(int)),SLOT(changeXPos(int))); |
106 | connect(yScroll,SIGNAL(valueChanged(int)),SLOT(changeYPos(int))); | 99 | connect(yScroll,SIGNAL(valueChanged(int)),SLOT(changeYPos(int))); |
107 | connect(yScroll,SIGNAL(valueChanged(int)),myView,SIGNAL(scrollValueChanged(int))); | 100 | connect(yScroll,SIGNAL(valueChanged(int)),myView,SIGNAL(scrollValueChanged(int))); |
108 | connect( doc, SIGNAL (preHighlightChanged(long)),this,SLOT(slotPreHighlightUpdate(long))); | 101 | connect( doc, SIGNAL (preHighlightChanged(long)),this,SLOT(slotPreHighlightUpdate(long))); |
109 | 102 | ||
110 | xPos = 0; | 103 | xPos = 0; |
111 | yPos = 0; | 104 | yPos = 0; |
112 | 105 | ||
113 | scrollTimer = 0; | 106 | scrollTimer = 0; |
114 | 107 | ||
115 | cursor.x = 0; | 108 | cursor.x = 0; |
116 | cursor.y = 0; | 109 | cursor.y = 0; |
117 | cursorOn = false; | 110 | cursorOn = false; |
118 | cursorTimer = 0; | 111 | cursorTimer = 0; |
119 | cXPos = 0; | 112 | cXPos = 0; |
120 | cOldXPos = 0; | 113 | cOldXPos = 0; |
121 | 114 | ||
122 | startLine = 0; | 115 | startLine = 0; |
123 | endLine = -1; | 116 | endLine = -1; |
124 | 117 | ||
125 | exposeCursor = false; | 118 | exposeCursor = false; |
126 | updateState = 0; | 119 | updateState = 0; |
127 | numLines = 0; | 120 | numLines = 0; |
128 | lineRanges = 0L; | 121 | lineRanges = 0L; |
129 | newXPos = -1; | 122 | newXPos = -1; |
130 | newYPos = -1; | 123 | newYPos = -1; |
131 | 124 | ||
132 | drawBuffer = new QPixmap (); | 125 | drawBuffer = new QPixmap (); |
133 | drawBuffer->setOptimization (QPixmap::BestOptim); | 126 | drawBuffer->setOptimization (QPixmap::BestOptim); |
134 | 127 | ||
135 | bm.sXPos = 0; | 128 | bm.sXPos = 0; |
136 | bm.eXPos = -1; | 129 | bm.eXPos = -1; |
137 | 130 | ||
138 | } | 131 | } |
139 | 132 | ||
140 | 133 | ||
141 | KateViewInternal::~KateViewInternal() | 134 | KateViewInternal::~KateViewInternal() |
142 | { | 135 | { |
143 | delete [] lineRanges; | 136 | delete [] lineRanges; |
144 | delete drawBuffer; | 137 | delete drawBuffer; |
145 | } | 138 | } |
146 | 139 | ||
147 | 140 | ||
148 | void KateViewInternal::slotPreHighlightUpdate(long line) | 141 | void KateViewInternal::slotPreHighlightUpdate(long line) |
149 | { | 142 | { |
150 | //kdDebug()<<QString("slotPreHighlightUpdate - Wait for: %1, line: %2").arg(waitForPreHighlight).arg(line)<<endl; | 143 | //kdDebug()<<QString("slotPreHighlightUpdate - Wait for: %1, line: %2").arg(waitForPreHighlight).arg(line)<<endl; |
151 | if (waitForPreHighlight!=-1) | 144 | if (waitForPreHighlight!=-1) |
152 | { | 145 | { |
153 | if (line>=waitForPreHighlight) | 146 | if (line>=waitForPreHighlight) |
154 | { | 147 | { |
155 | waitForPreHighlight=-1; | 148 | waitForPreHighlight=-1; |
156 | repaint(); | 149 | repaint(); |
157 | } | 150 | } |
158 | } | 151 | } |
159 | } | 152 | } |
160 | 153 | ||
161 | void KateViewInternal::doCursorCommand(VConfig &c, int cmdNum) { | 154 | void KateViewInternal::doCursorCommand(VConfig &c, int cmdNum) { |
162 | 155 | ||
163 | switch (cmdNum) { | 156 | switch (cmdNum) { |
164 | case KateView::cmLeft: | 157 | case KateView::cmLeft: |
165 | cursorLeft(c); | 158 | cursorLeft(c); |
166 | break; | 159 | break; |
167 | case KateView::cmRight: | 160 | case KateView::cmRight: |
168 | cursorRight(c); | 161 | cursorRight(c); |
169 | break; | 162 | break; |
170 | case KateView::cmWordLeft: | 163 | case KateView::cmWordLeft: |
171 | wordLeft(c); | 164 | wordLeft(c); |
172 | break; | 165 | break; |
173 | case KateView::cmWordRight: | 166 | case KateView::cmWordRight: |
174 | wordRight(c); | 167 | wordRight(c); |
175 | break; | 168 | break; |
176 | case KateView::cmHome: | 169 | case KateView::cmHome: |
177 | home(c); | 170 | home(c); |
178 | break; | 171 | break; |
179 | case KateView::cmEnd: | 172 | case KateView::cmEnd: |
180 | end(c); | 173 | end(c); |
181 | break; | 174 | break; |
182 | case KateView::cmUp: | 175 | case KateView::cmUp: |
183 | cursorUp(c); | 176 | cursorUp(c); |
184 | break; | 177 | break; |
185 | case KateView::cmDown: | 178 | case KateView::cmDown: |
186 | cursorDown(c); | 179 | cursorDown(c); |
187 | break; | 180 | break; |
188 | case KateView::cmScrollUp: | 181 | case KateView::cmScrollUp: |
189 | scrollUp(c); | 182 | scrollUp(c); |
190 | break; | 183 | break; |
191 | case KateView::cmScrollDown: | 184 | case KateView::cmScrollDown: |
192 | scrollDown(c); | 185 | scrollDown(c); |
193 | break; | 186 | break; |
194 | case KateView::cmTopOfView: | 187 | case KateView::cmTopOfView: |
195 | topOfView(c); | 188 | topOfView(c); |
196 | break; | 189 | break; |
197 | case KateView::cmBottomOfView: | 190 | case KateView::cmBottomOfView: |
198 | bottomOfView(c); | 191 | bottomOfView(c); |
199 | break; | 192 | break; |
200 | case KateView::cmPageUp: | 193 | case KateView::cmPageUp: |
201 | pageUp(c); | 194 | pageUp(c); |
202 | break; | 195 | break; |
203 | case KateView::cmPageDown: | 196 | case KateView::cmPageDown: |
204 | pageDown(c); | 197 | pageDown(c); |
205 | break; | 198 | break; |
206 | case KateView::cmTop: | 199 | case KateView::cmTop: |
207 | top_home(c); | 200 | top_home(c); |
208 | break; | 201 | break; |
209 | case KateView::cmBottom: | 202 | case KateView::cmBottom: |
210 | bottom_end(c); | 203 | bottom_end(c); |
211 | break; | 204 | break; |
212 | } | 205 | } |
213 | } | 206 | } |
214 | 207 | ||
215 | void KateViewInternal::doEditCommand(VConfig &c, int cmdNum) { | 208 | void KateViewInternal::doEditCommand(VConfig &c, int cmdNum) { |
216 | 209 | ||
217 | switch (cmdNum) { | 210 | switch (cmdNum) { |
218 | case KateView::cmCopy: | 211 | case KateView::cmCopy: |
219 | myDoc->copy(c.flags); | 212 | myDoc->copy(c.flags); |
220 | return; | 213 | return; |
221 | case KateView::cmSelectAll: | 214 | case KateView::cmSelectAll: |
222 | myDoc->selectAll(); | 215 | myDoc->selectAll(); |
223 | return; | 216 | return; |
224 | case KateView::cmDeselectAll: | 217 | case KateView::cmDeselectAll: |
225 | myDoc->deselectAll(); | 218 | myDoc->deselectAll(); |
226 | return; | 219 | return; |
227 | case KateView::cmInvertSelection: | 220 | case KateView::cmInvertSelection: |
228 | myDoc->invertSelection(); | 221 | myDoc->invertSelection(); |
229 | return; | 222 | return; |
230 | } | 223 | } |
231 | if (myView->isReadOnly()) return; | 224 | if (myView->isReadOnly()) return; |
232 | switch (cmdNum) { | 225 | switch (cmdNum) { |
233 | case KateView::cmReturn: | 226 | case KateView::cmReturn: |
234 | if (c.flags & KateView::cfDelOnInput) myDoc->delMarkedText(c); | 227 | if (c.flags & KateView::cfDelOnInput) myDoc->delMarkedText(c); |
235 | myDoc->newLine(c); | 228 | myDoc->newLine(c); |
236 | //emit returnPressed(); | 229 | //emit returnPressed(); |
237 | //e->ignore(); | 230 | //e->ignore(); |
238 | return; | 231 | return; |
239 | case KateView::cmDelete: | 232 | case KateView::cmDelete: |
240 | if ((c.flags & KateView::cfDelOnInput) && myDoc->hasMarkedText()) | 233 | if ((c.flags & KateView::cfDelOnInput) && myDoc->hasMarkedText()) |
241 | myDoc->delMarkedText(c); | 234 | myDoc->delMarkedText(c); |
242 | else myDoc->del(c); | 235 | else myDoc->del(c); |
243 | return; | 236 | return; |
244 | case KateView::cmBackspace: | 237 | case KateView::cmBackspace: |
245 | if ((c.flags & KateView::cfDelOnInput) && myDoc->hasMarkedText()) | 238 | if ((c.flags & KateView::cfDelOnInput) && myDoc->hasMarkedText()) |
246 | myDoc->delMarkedText(c); | 239 | myDoc->delMarkedText(c); |
247 | else myDoc->backspace(c); | 240 | else myDoc->backspace(c); |
248 | return; | 241 | return; |
249 | case KateView::cmKillLine: | 242 | case KateView::cmKillLine: |
250 | myDoc->killLine(c); | 243 | myDoc->killLine(c); |
251 | return; | 244 | return; |
252 | case KateView::cmCut: | 245 | case KateView::cmCut: |
253 | myDoc->cut(c); | 246 | myDoc->cut(c); |
254 | return; | 247 | return; |
255 | case KateView::cmPaste: | 248 | case KateView::cmPaste: |
256 | if (c.flags & KateView::cfDelOnInput) myDoc->delMarkedText(c); | 249 | if (c.flags & KateView::cfDelOnInput) myDoc->delMarkedText(c); |
257 | myDoc->paste(c); | 250 | myDoc->paste(c); |
258 | return; | 251 | return; |
259 | case KateView::cmUndo: | 252 | case KateView::cmUndo: |
260 | myDoc->undo(c); | 253 | myDoc->undo(c); |
261 | return; | 254 | return; |
262 | case KateView::cmRedo: | 255 | case KateView::cmRedo: |
263 | myDoc->redo(c); | 256 | myDoc->redo(c); |
264 | return; | 257 | return; |
265 | case KateView::cmIndent: | 258 | case KateView::cmIndent: |
266 | myDoc->indent(c); | 259 | myDoc->indent(c); |
267 | return; | 260 | return; |
268 | case KateView::cmUnindent: | 261 | case KateView::cmUnindent: |
269 | myDoc->unIndent(c); | 262 | myDoc->unIndent(c); |
270 | return; | 263 | return; |
271 | case KateView::cmCleanIndent: | 264 | case KateView::cmCleanIndent: |
272 | myDoc->cleanIndent(c); | 265 | myDoc->cleanIndent(c); |
273 | return; | 266 | return; |
274 | case KateView::cmComment: | 267 | case KateView::cmComment: |
275 | myDoc->comment(c); | 268 | myDoc->comment(c); |
276 | return; | 269 | return; |
277 | case KateView::cmUncomment: | 270 | case KateView::cmUncomment: |
278 | myDoc->unComment(c); | 271 | myDoc->unComment(c); |
279 | return; | 272 | return; |
280 | } | 273 | } |
281 | } | 274 | } |
282 | 275 | ||
283 | void KateViewInternal::cursorLeft(VConfig &c) { | 276 | void KateViewInternal::cursorLeft(VConfig &c) { |
284 | 277 | ||
285 | cursor.x--; | 278 | cursor.x--; |
286 | if (c.flags & KateView::cfWrapCursor && cursor.x < 0 && cursor.y > 0) { | 279 | if (c.flags & KateView::cfWrapCursor && cursor.x < 0 && cursor.y > 0) { |
287 | cursor.y--; | 280 | cursor.y--; |
288 | cursor.x = myDoc->textLength(cursor.y); | 281 | cursor.x = myDoc->textLength(cursor.y); |
289 | } | 282 | } |
290 | cOldXPos = cXPos = myDoc->textWidth(cursor); | 283 | cOldXPos = cXPos = myDoc->textWidth(cursor); |
291 | changeState(c); | 284 | changeState(c); |
292 | } | 285 | } |
293 | 286 | ||
294 | void KateViewInternal::cursorRight(VConfig &c) { | 287 | void KateViewInternal::cursorRight(VConfig &c) { |
295 | 288 | ||
296 | if (c.flags & KateView::cfWrapCursor) { | 289 | if (c.flags & KateView::cfWrapCursor) { |
297 | if (cursor.x >= myDoc->textLength(cursor.y)) { | 290 | if (cursor.x >= myDoc->textLength(cursor.y)) { |
298 | if (cursor.y == myDoc->lastLine()) return; | 291 | if (cursor.y == myDoc->lastLine()) return; |
299 | cursor.y++; | 292 | cursor.y++; |
300 | cursor.x = -1; | 293 | cursor.x = -1; |
301 | } | 294 | } |
302 | } | 295 | } |
303 | cursor.x++; | 296 | cursor.x++; |
304 | cOldXPos = cXPos = myDoc->textWidth(cursor); | 297 | cOldXPos = cXPos = myDoc->textWidth(cursor); |
305 | changeState(c); | 298 | changeState(c); |
306 | } | 299 | } |
307 | 300 | ||
308 | void KateViewInternal::wordLeft(VConfig &c) { | 301 | void KateViewInternal::wordLeft(VConfig &c) { |
309 | Highlight *highlight; | 302 | Highlight *highlight; |
310 | 303 | ||
311 | highlight = myDoc->highlight(); | 304 | highlight = myDoc->highlight(); |
312 | TextLine::Ptr textLine = myDoc->getTextLine(cursor.y); | 305 | TextLine::Ptr textLine = myDoc->getTextLine(cursor.y); |
313 | 306 | ||
314 | if (cursor.x > 0) { | 307 | if (cursor.x > 0) { |
315 | do { | 308 | do { |
316 | cursor.x--; | 309 | cursor.x--; |
317 | } while (cursor.x > 0 && !highlight->isInWord(textLine->getChar(cursor.x))); | 310 | } while (cursor.x > 0 && !highlight->isInWord(textLine->getChar(cursor.x))); |
318 | while (cursor.x > 0 && highlight->isInWord(textLine->getChar(cursor.x -1))) | 311 | while (cursor.x > 0 && highlight->isInWord(textLine->getChar(cursor.x -1))) |
319 | cursor.x--; | 312 | cursor.x--; |
320 | } else { | 313 | } else { |
321 | if (cursor.y > 0) { | 314 | if (cursor.y > 0) { |
322 | cursor.y--; | 315 | cursor.y--; |
323 | textLine = myDoc->getTextLine(cursor.y); | 316 | textLine = myDoc->getTextLine(cursor.y); |
324 | cursor.x = textLine->length(); | 317 | cursor.x = textLine->length(); |
325 | } | 318 | } |
326 | } | 319 | } |
327 | 320 | ||
328 | cOldXPos = cXPos = myDoc->textWidth(cursor); | 321 | cOldXPos = cXPos = myDoc->textWidth(cursor); |
329 | changeState(c); | 322 | changeState(c); |
330 | } | 323 | } |
331 | 324 | ||
332 | void KateViewInternal::wordRight(VConfig &c) { | 325 | void KateViewInternal::wordRight(VConfig &c) { |
333 | Highlight *highlight; | 326 | Highlight *highlight; |
334 | int len; | 327 | int len; |
335 | 328 | ||
336 | highlight = myDoc->highlight(); | 329 | highlight = myDoc->highlight(); |
337 | TextLine::Ptr textLine = myDoc->getTextLine(cursor.y); | 330 | TextLine::Ptr textLine = myDoc->getTextLine(cursor.y); |
338 | len = textLine->length(); | 331 | len = textLine->length(); |
339 | 332 | ||
340 | if (cursor.x < len) { | 333 | if (cursor.x < len) { |
341 | do { | 334 | do { |
342 | cursor.x++; | 335 | cursor.x++; |
343 | } while (cursor.x < len && highlight->isInWord(textLine->getChar(cursor.x))); | 336 | } while (cursor.x < len && highlight->isInWord(textLine->getChar(cursor.x))); |
344 | while (cursor.x < len && !highlight->isInWord(textLine->getChar(cursor.x))) | 337 | while (cursor.x < len && !highlight->isInWord(textLine->getChar(cursor.x))) |
345 | cursor.x++; | 338 | cursor.x++; |
346 | } else { | 339 | } else { |
347 | if (cursor.y < myDoc->lastLine()) { | 340 | if (cursor.y < myDoc->lastLine()) { |
348 | cursor.y++; | 341 | cursor.y++; |
349 | textLine = myDoc->getTextLine(cursor.y); | 342 | textLine = myDoc->getTextLine(cursor.y); |
350 | cursor.x = 0; | 343 | cursor.x = 0; |
351 | } | 344 | } |
352 | } | 345 | } |
353 | 346 | ||
354 | cOldXPos = cXPos = myDoc->textWidth(cursor); | 347 | cOldXPos = cXPos = myDoc->textWidth(cursor); |
355 | changeState(c); | 348 | changeState(c); |
356 | } | 349 | } |
357 | 350 | ||
358 | void KateViewInternal::home(VConfig &c) { | 351 | void KateViewInternal::home(VConfig &c) { |
359 | int lc; | 352 | int lc; |
360 | 353 | ||
361 | lc = (c.flags & KateView::cfSmartHome) ? myDoc->getTextLine(cursor.y)->firstChar() : 0; | 354 | lc = (c.flags & KateView::cfSmartHome) ? myDoc->getTextLine(cursor.y)->firstChar() : 0; |
362 | if (lc <= 0 || cursor.x == lc) { | 355 | if (lc <= 0 || cursor.x == lc) { |
363 | cursor.x = 0; | 356 | cursor.x = 0; |
364 | cOldXPos = cXPos = 0; | 357 | cOldXPos = cXPos = 0; |
365 | } else { | 358 | } else { |
366 | cursor.x = lc; | 359 | cursor.x = lc; |
367 | cOldXPos = cXPos = myDoc->textWidth(cursor); | 360 | cOldXPos = cXPos = myDoc->textWidth(cursor); |
368 | } | 361 | } |
369 | 362 | ||
370 | changeState(c); | 363 | changeState(c); |
371 | } | 364 | } |
372 | 365 | ||
373 | void KateViewInternal::end(VConfig &c) { | 366 | void KateViewInternal::end(VConfig &c) { |
374 | cursor.x = myDoc->textLength(cursor.y); | 367 | cursor.x = myDoc->textLength(cursor.y); |
375 | cOldXPos = cXPos = myDoc->textWidth(cursor); | 368 | cOldXPos = cXPos = myDoc->textWidth(cursor); |
376 | changeState(c); | 369 | changeState(c); |
377 | } | 370 | } |
378 | 371 | ||
379 | 372 | ||
380 | void KateViewInternal::cursorUp(VConfig &c) { | 373 | void KateViewInternal::cursorUp(VConfig &c) { |
381 | 374 | ||
382 | cursor.y--; | 375 | cursor.y--; |
383 | cXPos = myDoc->textWidth(c.flags & KateView::cfWrapCursor,cursor,cOldXPos); | 376 | cXPos = myDoc->textWidth(c.flags & KateView::cfWrapCursor,cursor,cOldXPos); |
384 | changeState(c); | 377 | changeState(c); |
385 | } | 378 | } |
386 | 379 | ||
387 | 380 | ||
388 | void KateViewInternal::cursorDown(VConfig &c) { | 381 | void KateViewInternal::cursorDown(VConfig &c) { |
389 | int x; | 382 | int x; |
390 | 383 | ||
391 | if (cursor.y == myDoc->lastLine()) { | 384 | if (cursor.y == myDoc->lastLine()) { |
392 | x = myDoc->textLength(cursor.y); | 385 | x = myDoc->textLength(cursor.y); |
393 | if (cursor.x >= x) return; | 386 | if (cursor.x >= x) return; |
394 | cursor.x = x; | 387 | cursor.x = x; |
395 | cXPos = myDoc->textWidth(cursor); | 388 | cXPos = myDoc->textWidth(cursor); |
396 | } else { | 389 | } else { |
397 | cursor.y++; | 390 | cursor.y++; |
398 | cXPos = myDoc->textWidth(c.flags & KateView::cfWrapCursor, cursor, cOldXPos); | 391 | cXPos = myDoc->textWidth(c.flags & KateView::cfWrapCursor, cursor, cOldXPos); |
399 | } | 392 | } |
400 | changeState(c); | 393 | changeState(c); |
401 | } | 394 | } |
402 | 395 | ||
403 | void KateViewInternal::scrollUp(VConfig &c) { | 396 | void KateViewInternal::scrollUp(VConfig &c) { |
404 | 397 | ||
405 | if (! yPos) return; | 398 | if (! yPos) return; |
406 | 399 | ||
407 | newYPos = yPos - myDoc->fontHeight; | 400 | newYPos = yPos - myDoc->fontHeight; |
408 | if (cursor.y == (yPos + height())/myDoc->fontHeight -1) { | 401 | if (cursor.y == (yPos + height())/myDoc->fontHeight -1) { |
409 | cursor.y--; | 402 | cursor.y--; |
410 | cXPos = myDoc->textWidth(c.flags & KateView::cfWrapCursor,cursor,cOldXPos); | 403 | cXPos = myDoc->textWidth(c.flags & KateView::cfWrapCursor,cursor,cOldXPos); |
411 | 404 | ||
412 | changeState(c); | 405 | changeState(c); |
413 | } | 406 | } |
414 | } | 407 | } |
415 | 408 | ||
416 | void KateViewInternal::scrollDown(VConfig &c) { | 409 | void KateViewInternal::scrollDown(VConfig &c) { |
417 | 410 | ||
418 | if (endLine >= myDoc->lastLine()) return; | 411 | if (endLine >= myDoc->lastLine()) return; |
419 | 412 | ||
420 | newYPos = yPos + myDoc->fontHeight; | 413 | newYPos = yPos + myDoc->fontHeight; |
421 | if (cursor.y == (yPos + myDoc->fontHeight -1)/myDoc->fontHeight) { | 414 | if (cursor.y == (yPos + myDoc->fontHeight -1)/myDoc->fontHeight) { |
422 | cursor.y++; | 415 | cursor.y++; |
423 | cXPos = myDoc->textWidth(c.flags & KateView::cfWrapCursor,cursor,cOldXPos); | 416 | cXPos = myDoc->textWidth(c.flags & KateView::cfWrapCursor,cursor,cOldXPos); |
424 | changeState(c); | 417 | changeState(c); |
425 | } | 418 | } |
426 | } | 419 | } |
427 | 420 | ||
428 | void KateViewInternal::topOfView(VConfig &c) { | 421 | void KateViewInternal::topOfView(VConfig &c) { |
429 | 422 | ||
430 | cursor.y = (yPos + myDoc->fontHeight -1)/myDoc->fontHeight; | 423 | cursor.y = (yPos + myDoc->fontHeight -1)/myDoc->fontHeight; |
431 | cursor.x = 0; | 424 | cursor.x = 0; |
432 | cOldXPos = cXPos = 0; | 425 | cOldXPos = cXPos = 0; |
433 | changeState(c); | 426 | changeState(c); |
434 | } | 427 | } |
435 | 428 | ||
436 | void KateViewInternal::bottomOfView(VConfig &c) { | 429 | void KateViewInternal::bottomOfView(VConfig &c) { |
437 | 430 | ||
438 | cursor.y = (yPos + height())/myDoc->fontHeight -1; | 431 | cursor.y = (yPos + height())/myDoc->fontHeight -1; |
439 | if (cursor.y < 0) cursor.y = 0; | 432 | if (cursor.y < 0) cursor.y = 0; |
440 | if (cursor.y > myDoc->lastLine()) cursor.y = myDoc->lastLine(); | 433 | if (cursor.y > myDoc->lastLine()) cursor.y = myDoc->lastLine(); |
441 | cursor.x = 0; | 434 | cursor.x = 0; |
442 | cOldXPos = cXPos = 0; | 435 | cOldXPos = cXPos = 0; |
443 | changeState(c); | 436 | changeState(c); |
444 | } | 437 | } |
445 | 438 | ||
446 | void KateViewInternal::pageUp(VConfig &c) { | 439 | void KateViewInternal::pageUp(VConfig &c) { |
447 | int lines = (endLine - startLine - 1); | 440 | int lines = (endLine - startLine - 1); |
448 | 441 | ||
449 | if (lines <= 0) lines = 1; | 442 | if (lines <= 0) lines = 1; |
450 | 443 | ||
451 | if (!(c.flags & KateView::cfPageUDMovesCursor) && yPos > 0) { | 444 | if (!(c.flags & KateView::cfPageUDMovesCursor) && yPos > 0) { |
452 | newYPos = yPos - lines * myDoc->fontHeight; | 445 | newYPos = yPos - lines * myDoc->fontHeight; |
453 | if (newYPos < 0) newYPos = 0; | 446 | if (newYPos < 0) newYPos = 0; |
454 | } | 447 | } |
455 | cursor.y -= lines; | 448 | cursor.y -= lines; |
456 | cXPos = myDoc->textWidth(c.flags & KateView::cfWrapCursor, cursor, cOldXPos); | 449 | cXPos = myDoc->textWidth(c.flags & KateView::cfWrapCursor, cursor, cOldXPos); |
457 | changeState(c); | 450 | changeState(c); |
458 | // cursorPageUp(c); | 451 | // cursorPageUp(c); |
459 | } | 452 | } |
460 | 453 | ||
461 | void KateViewInternal::pageDown(VConfig &c) { | 454 | void KateViewInternal::pageDown(VConfig &c) { |
462 | 455 | ||
463 | int lines = (endLine - startLine - 1); | 456 | int lines = (endLine - startLine - 1); |
464 | 457 | ||
465 | if (!(c.flags & KateView::cfPageUDMovesCursor) && endLine < myDoc->lastLine()) { | 458 | if (!(c.flags & KateView::cfPageUDMovesCursor) && endLine < myDoc->lastLine()) { |
466 | if (lines < myDoc->lastLine() - endLine) | 459 | if (lines < myDoc->lastLine() - endLine) |
467 | newYPos = yPos + lines * myDoc->fontHeight; | 460 | newYPos = yPos + lines * myDoc->fontHeight; |
468 | else | 461 | else |
469 | newYPos = yPos + (myDoc->lastLine() - endLine) * myDoc->fontHeight; | 462 | newYPos = yPos + (myDoc->lastLine() - endLine) * myDoc->fontHeight; |
470 | } | 463 | } |
471 | cursor.y += lines; | 464 | cursor.y += lines; |
472 | cXPos = myDoc->textWidth(c.flags & KateView::cfWrapCursor,cursor,cOldXPos); | 465 | cXPos = myDoc->textWidth(c.flags & KateView::cfWrapCursor,cursor,cOldXPos); |
473 | changeState(c); | 466 | changeState(c); |
474 | // cursorPageDown(c); | 467 | // cursorPageDown(c); |
475 | } | 468 | } |
476 | 469 | ||
477 | // go to the top, same X position | 470 | // go to the top, same X position |
478 | void KateViewInternal::top(VConfig &c) { | 471 | void KateViewInternal::top(VConfig &c) { |
479 | 472 | ||
480 | // cursor.x = 0; | 473 | // cursor.x = 0; |
481 | cursor.y = 0; | 474 | cursor.y = 0; |
482 | cXPos = myDoc->textWidth(c.flags & KateView::cfWrapCursor,cursor,cOldXPos); | 475 | cXPos = myDoc->textWidth(c.flags & KateView::cfWrapCursor,cursor,cOldXPos); |
483 | // cOldXPos = cXPos = 0; | 476 | // cOldXPos = cXPos = 0; |
484 | changeState(c); | 477 | changeState(c); |
485 | } | 478 | } |
486 | 479 | ||
487 | // go to the bottom, same X position | 480 | // go to the bottom, same X position |
488 | void KateViewInternal::bottom(VConfig &c) { | 481 | void KateViewInternal::bottom(VConfig &c) { |
489 | 482 | ||
490 | // cursor.x = 0; | 483 | // cursor.x = 0; |
491 | cursor.y = myDoc->lastLine(); | 484 | cursor.y = myDoc->lastLine(); |
492 | cXPos = myDoc->textWidth(c.flags & KateView::cfWrapCursor,cursor,cOldXPos); | 485 | cXPos = myDoc->textWidth(c.flags & KateView::cfWrapCursor,cursor,cOldXPos); |
493 | // cOldXPos = cXPos = 0; | 486 | // cOldXPos = cXPos = 0; |
494 | changeState(c); | 487 | changeState(c); |
495 | } | 488 | } |
496 | 489 | ||
497 | // go to the top left corner | 490 | // go to the top left corner |
498 | void KateViewInternal::top_home(VConfig &c) | 491 | void KateViewInternal::top_home(VConfig &c) |
499 | { | 492 | { |
500 | cursor.y = 0; | 493 | cursor.y = 0; |
501 | cursor.x = 0; | 494 | cursor.x = 0; |
502 | cOldXPos = cXPos = 0; | 495 | cOldXPos = cXPos = 0; |
503 | changeState(c); | 496 | changeState(c); |
504 | } | 497 | } |
505 | 498 | ||
506 | // go to the bottom right corner | 499 | // go to the bottom right corner |
507 | void KateViewInternal::bottom_end(VConfig &c) { | 500 | void KateViewInternal::bottom_end(VConfig &c) { |
508 | 501 | ||
509 | cursor.y = myDoc->lastLine(); | 502 | cursor.y = myDoc->lastLine(); |
510 | cursor.x = myDoc->textLength(cursor.y); | 503 | cursor.x = myDoc->textLength(cursor.y); |
511 | cOldXPos = cXPos = myDoc->textWidth(cursor); | 504 | cOldXPos = cXPos = myDoc->textWidth(cursor); |
512 | changeState(c); | 505 | changeState(c); |
513 | } | 506 | } |
514 | 507 | ||
515 | 508 | ||
516 | void KateViewInternal::changeXPos(int p) { | 509 | void KateViewInternal::changeXPos(int p) { |
517 | int dx; | 510 | int dx; |
518 | 511 | ||
519 | dx = xPos - p; | 512 | dx = xPos - p; |
520 | xPos = p; | 513 | xPos = p; |
521 | if (QABS(dx) < width()) scroll(dx, 0); else update(); | 514 | if (QABS(dx) < width()) scroll(dx, 0); else update(); |
522 | } | 515 | } |
523 | 516 | ||
524 | void KateViewInternal::changeYPos(int p) { | 517 | void KateViewInternal::changeYPos(int p) { |
525 | int dy; | 518 | int dy; |
526 | 519 | ||
527 | dy = yPos - p; | 520 | dy = yPos - p; |
528 | yPos = p; | 521 | yPos = p; |
529 | clearDirtyCache(height()); | 522 | clearDirtyCache(height()); |
530 | 523 | ||
531 | if (QABS(dy) < height()) | 524 | if (QABS(dy) < height()) |
532 | { | 525 | { |
533 | scroll(0, dy); | 526 | scroll(0, dy); |
534 | leftBorder->scroll(0, dy); | 527 | leftBorder->scroll(0, dy); |
535 | } | 528 | } |
536 | else | 529 | else |
537 | update(); | 530 | update(); |
538 | } | 531 | } |
539 | 532 | ||
540 | 533 | ||
541 | void KateViewInternal::getVConfig(VConfig &c) { | 534 | void KateViewInternal::getVConfig(VConfig &c) { |
542 | 535 | ||
543 | c.view = myView; | 536 | c.view = myView; |
544 | c.cursor = cursor; | 537 | c.cursor = cursor; |
545 | c.cXPos = cXPos; | 538 | c.cXPos = cXPos; |
546 | c.flags = myView->configFlags; | 539 | c.flags = myView->configFlags; |
547 | } | 540 | } |
548 | 541 | ||
549 | void KateViewInternal::changeState(VConfig &c) { | 542 | void KateViewInternal::changeState(VConfig &c) { |
550 | /* | 543 | /* |
551 | * we need to be sure to kill the selection on an attempted cursor | 544 | * we need to be sure to kill the selection on an attempted cursor |
552 | * movement even if the cursor doesn't physically move, | 545 | * movement even if the cursor doesn't physically move, |
553 | * but we need to be careful not to do some other things in this case, | 546 | * but we need to be careful not to do some other things in this case, |
554 | * like we don't want to expose the cursor | 547 | * like we don't want to expose the cursor |
555 | */ | 548 | */ |
556 | 549 | ||
557 | // if (cursor.x == c.cursor.x && cursor.y == c.cursor.y) return; | 550 | // if (cursor.x == c.cursor.x && cursor.y == c.cursor.y) return; |
558 | bool nullMove = (cursor.x == c.cursor.x && cursor.y == c.cursor.y); | 551 | bool nullMove = (cursor.x == c.cursor.x && cursor.y == c.cursor.y); |
559 | 552 | ||
560 | // if (cursor.y != c.cursor.y || c.flags & KateView::cfMark) myDoc->recordReset(); | 553 | // if (cursor.y != c.cursor.y || c.flags & KateView::cfMark) myDoc->recordReset(); |
561 | 554 | ||
562 | if (! nullMove) { | 555 | if (! nullMove) { |
563 | 556 | ||
564 | exposeCursor = true; | 557 | exposeCursor = true; |
565 | 558 | ||
566 | // mark old position of cursor as dirty | 559 | // mark old position of cursor as dirty |
567 | if (cursorOn) { | 560 | if (cursorOn) { |
568 | tagLines(c.cursor.y, c.cursor.y, c.cXPos -2, c.cXPos +3); | 561 | tagLines(c.cursor.y, c.cursor.y, c.cXPos -2, c.cXPos +3); |
569 | cursorOn = false; | 562 | cursorOn = false; |
570 | } | 563 | } |
571 | 564 | ||
572 | // mark old bracket mark position as dirty | 565 | // mark old bracket mark position as dirty |
573 | if (bm.sXPos < bm.eXPos) { | 566 | if (bm.sXPos < bm.eXPos) { |
574 | tagLines(bm.cursor.y, bm.cursor.y, bm.sXPos, bm.eXPos); | 567 | tagLines(bm.cursor.y, bm.cursor.y, bm.sXPos, bm.eXPos); |
575 | } | 568 | } |
576 | // make new bracket mark | 569 | // make new bracket mark |
577 | myDoc->newBracketMark(cursor, bm); | 570 | myDoc->newBracketMark(cursor, bm); |
578 | 571 | ||
579 | // remove trailing spaces when leaving a line | 572 | // remove trailing spaces when leaving a line |
580 | if (c.flags & KateView::cfRemoveSpaces && cursor.y != c.cursor.y) { | 573 | if (c.flags & KateView::cfRemoveSpaces && cursor.y != c.cursor.y) { |
581 | TextLine::Ptr textLine = myDoc->getTextLine(c.cursor.y); | 574 | TextLine::Ptr textLine = myDoc->getTextLine(c.cursor.y); |
582 | int newLen = textLine->lastChar(); | 575 | int newLen = textLine->lastChar(); |
583 | if (newLen != textLine->length()) { | 576 | if (newLen != textLine->length()) { |
584 | textLine->truncate(newLen); | 577 | textLine->truncate(newLen); |
585 | // if some spaces are removed, tag the line as dirty | 578 | // if some spaces are removed, tag the line as dirty |
586 | myDoc->tagLines(c.cursor.y, c.cursor.y); | 579 | myDoc->tagLines(c.cursor.y, c.cursor.y); |
587 | } | 580 | } |
588 | } | 581 | } |
589 | } | 582 | } |
590 | 583 | ||
591 | if (c.flags & KateView::cfMark) { | 584 | if (c.flags & KateView::cfMark) { |
592 | if (! nullMove) | 585 | if (! nullMove) |
593 | myDoc->selectTo(c, cursor, cXPos); | 586 | myDoc->selectTo(c, cursor, cXPos); |
594 | } else { | 587 | } else { |
595 | if (!(c.flags & KateView::cfPersistent)) | 588 | if (!(c.flags & KateView::cfPersistent)) |
596 | myDoc->deselectAll(); | 589 | myDoc->deselectAll(); |
597 | } | 590 | } |
598 | } | 591 | } |
599 | 592 | ||
600 | void KateViewInternal::insLine(int line) { | 593 | void KateViewInternal::insLine(int line) { |
601 | 594 | ||
602 | if (line <= cursor.y) { | 595 | if (line <= cursor.y) { |
603 | cursor.y++; | 596 | cursor.y++; |
604 | } | 597 | } |
605 | if (line < startLine) { | 598 | if (line < startLine) { |
606 | startLine++; | 599 | startLine++; |
607 | endLine++; | 600 | endLine++; |
608 | yPos += myDoc->fontHeight; | 601 | yPos += myDoc->fontHeight; |
609 | } else if (line <= endLine) { | 602 | } else if (line <= endLine) { |
610 | tagAll(); | 603 | tagAll(); |
611 | } | 604 | } |
612 | } | 605 | } |
613 | 606 | ||
614 | void KateViewInternal::delLine(int line) { | 607 | void KateViewInternal::delLine(int line) { |
615 | 608 | ||
616 | if (line <= cursor.y && cursor.y > 0) { | 609 | if (line <= cursor.y && cursor.y > 0) { |
617 | cursor.y--; | 610 | cursor.y--; |
618 | } | 611 | } |
619 | if (line < startLine) { | 612 | if (line < startLine) { |
620 | startLine--; | 613 | startLine--; |
621 | endLine--; | 614 | endLine--; |
622 | yPos -= myDoc->fontHeight; | 615 | yPos -= myDoc->fontHeight; |
623 | } else if (line <= endLine) { | 616 | } else if (line <= endLine) { |
624 | tagAll(); | 617 | tagAll(); |
625 | } | 618 | } |
626 | } | 619 | } |
627 | 620 | ||
628 | void KateViewInternal::updateCursor() { | 621 | void KateViewInternal::updateCursor() { |
629 | cOldXPos = cXPos = myDoc->textWidth(cursor); | 622 | cOldXPos = cXPos = myDoc->textWidth(cursor); |
630 | } | 623 | } |
631 | 624 | ||
632 | 625 | ||
633 | void KateViewInternal::updateCursor(PointStruc &newCursor) { | 626 | void KateViewInternal::updateCursor(PointStruc &newCursor) { |
634 | updateCursor(newCursor, myView->config()); | 627 | updateCursor(newCursor, myView->config()); |
635 | } | 628 | } |
636 | 629 | ||
637 | void KateViewInternal::updateCursor(PointStruc &newCursor, int flags) { | 630 | void KateViewInternal::updateCursor(PointStruc &newCursor, int flags) { |
638 | 631 | ||
639 | if (!(flags & KateView::cfPersistent)) myDoc->deselectAll(); | 632 | if (!(flags & KateView::cfPersistent)) myDoc->deselectAll(); |
640 | 633 | ||
641 | exposeCursor = true; | 634 | exposeCursor = true; |
642 | if (cursorOn) { | 635 | if (cursorOn) { |
643 | tagLines(cursor.y, cursor.y, cXPos -2, cXPos +3); | 636 | tagLines(cursor.y, cursor.y, cXPos -2, cXPos +3); |
644 | cursorOn = false; | 637 | cursorOn = false; |
645 | } | 638 | } |
646 | 639 | ||
647 | if (bm.sXPos < bm.eXPos) { | 640 | if (bm.sXPos < bm.eXPos) { |
648 | tagLines(bm.cursor.y, bm.cursor.y, bm.sXPos, bm.eXPos); | 641 | tagLines(bm.cursor.y, bm.cursor.y, bm.sXPos, bm.eXPos); |
649 | } | 642 | } |
650 | myDoc->newBracketMark(newCursor, bm); | 643 | myDoc->newBracketMark(newCursor, bm); |
651 | 644 | ||
652 | cursor = newCursor; | 645 | cursor = newCursor; |
653 | cOldXPos = cXPos = myDoc->textWidth(cursor); | 646 | cOldXPos = cXPos = myDoc->textWidth(cursor); |
654 | } | 647 | } |
655 | 648 | ||
656 | // init the line dirty cache | 649 | // init the line dirty cache |
657 | void KateViewInternal::clearDirtyCache(int height) { | 650 | void KateViewInternal::clearDirtyCache(int height) { |
658 | int lines, z; | 651 | int lines, z; |
659 | 652 | ||
660 | // calc start and end line of visible part | 653 | // calc start and end line of visible part |
661 | startLine = yPos/myDoc->fontHeight; | 654 | startLine = yPos/myDoc->fontHeight; |
662 | endLine = (yPos + height -1)/myDoc->fontHeight; | 655 | endLine = (yPos + height -1)/myDoc->fontHeight; |
663 | 656 | ||
664 | updateState = 0; | 657 | updateState = 0; |
665 | 658 | ||
666 | lines = endLine - startLine +1; | 659 | lines = endLine - startLine +1; |
667 | if (lines > numLines) { // resize the dirty cache | 660 | if (lines > numLines) { // resize the dirty cache |
668 | numLines = lines*2; | 661 | numLines = lines*2; |
669 | delete [] lineRanges; | 662 | delete [] lineRanges; |
670 | lineRanges = new LineRange[numLines]; | 663 | lineRanges = new LineRange[numLines]; |
671 | } | 664 | } |
672 | 665 | ||
673 | for (z = 0; z < lines; z++) { // clear all lines | 666 | for (z = 0; z < lines; z++) { // clear all lines |
674 | lineRanges[z].start = 0xffffff; | 667 | lineRanges[z].start = 0xffffff; |
675 | lineRanges[z].end = -2; | 668 | lineRanges[z].end = -2; |
676 | } | 669 | } |
677 | newXPos = newYPos = -1; | 670 | newXPos = newYPos = -1; |
678 | } | 671 | } |
679 | 672 | ||
680 | void KateViewInternal::tagLines(int start, int end, int x1, int x2) { | 673 | void KateViewInternal::tagLines(int start, int end, int x1, int x2) { |
681 | LineRange *r; | 674 | LineRange *r; |
682 | int z; | 675 | int z; |
683 | 676 | ||
684 | start -= startLine; | 677 | start -= startLine; |
685 | if (start < 0) start = 0; | 678 | if (start < 0) start = 0; |
686 | end -= startLine; | 679 | end -= startLine; |
687 | if (end > endLine - startLine) end = endLine - startLine; | 680 | if (end > endLine - startLine) end = endLine - startLine; |
688 | 681 | ||
689 | if (x1 <= 0) x1 = -2; | 682 | if (x1 <= 0) x1 = -2; |
690 | if (x1 < xPos-2) x1 = xPos-2; | 683 | if (x1 < xPos-2) x1 = xPos-2; |
691 | if (x2 > width() + xPos-2) x2 = width() + xPos-2; | 684 | if (x2 > width() + xPos-2) x2 = width() + xPos-2; |
692 | if (x1 >= x2) return; | 685 | if (x1 >= x2) return; |
693 | 686 | ||
694 | r = &lineRanges[start]; | 687 | r = &lineRanges[start]; |
695 | for (z = start; z <= end; z++) { | 688 | for (z = start; z <= end; z++) { |
696 | if (x1 < r->start) r->start = x1; | 689 | if (x1 < r->start) r->start = x1; |
697 | if (x2 > r->end) r->end = x2; | 690 | if (x2 > r->end) r->end = x2; |
698 | r++; | 691 | r++; |
699 | updateState |= 1; | 692 | updateState |= 1; |
700 | } | 693 | } |
701 | } | 694 | } |
702 | 695 | ||
703 | void KateViewInternal::tagAll() { | 696 | void KateViewInternal::tagAll() { |
704 | updateState = 3; | 697 | updateState = 3; |
705 | } | 698 | } |
706 | 699 | ||
707 | void KateViewInternal::setPos(int x, int y) { | 700 | void KateViewInternal::setPos(int x, int y) { |
708 | newXPos = x; | 701 | newXPos = x; |
709 | newYPos = y; | 702 | newYPos = y; |
710 | } | 703 | } |
711 | 704 | ||
712 | void KateViewInternal::center() { | 705 | void KateViewInternal::center() { |
713 | newXPos = 0; | 706 | newXPos = 0; |
714 | newYPos = cursor.y*myDoc->fontHeight - height()/2; | 707 | newYPos = cursor.y*myDoc->fontHeight - height()/2; |
715 | if (newYPos < 0) newYPos = 0; | 708 | if (newYPos < 0) newYPos = 0; |
716 | } | 709 | } |
717 | 710 | ||
718 | void KateViewInternal::updateView(int flags) { | 711 | void KateViewInternal::updateView(int flags) { |
719 | int fontHeight; | 712 | int fontHeight; |
720 | int oldXPos, oldYPos; | 713 | int oldXPos, oldYPos; |
721 | int w, h; | 714 | int w, h; |
722 | int z; | 715 | int z; |
723 | bool b; | 716 | bool b; |
724 | int xMax, yMax; | 717 | int xMax, yMax; |
725 | int cYPos; | 718 | int cYPos; |
726 | int cXPosMin, cXPosMax, cYPosMin, cYPosMax; | 719 | int cXPosMin, cXPosMax, cYPosMin, cYPosMax; |
727 | int dx, dy; | 720 | int dx, dy; |
728 | int pageScroll; | 721 | int pageScroll; |
729 | int scrollbarWidth = style().scrollBarExtent().width(); | 722 | int scrollbarWidth = style().scrollBarExtent().width(); |
730 | 723 | ||
731 | //debug("upView %d %d %d %d %d", exposeCursor, updateState, flags, newXPos, newYPos); | 724 | //debug("upView %d %d %d %d %d", exposeCursor, updateState, flags, newXPos, newYPos); |
732 | if (exposeCursor || flags & KateView::ufDocGeometry) { | 725 | if (exposeCursor || flags & KateView::ufDocGeometry) { |
733 | emit myView->newCurPos(); | 726 | emit myView->newCurPos(); |
734 | } else { | 727 | } else { |
735 | if (updateState == 0 && newXPos < 0 && newYPos < 0) return; | 728 | if (updateState == 0 && newXPos < 0 && newYPos < 0) return; |
736 | } | 729 | } |
737 | 730 | ||
738 | if (cursorTimer) { | 731 | if (cursorTimer) { |
739 | killTimer(cursorTimer); | 732 | killTimer(cursorTimer); |
740 | cursorTimer = startTimer(KApplication::cursorFlashTime() / 2); | 733 | cursorTimer = startTimer(KApplication::cursorFlashTime() / 2); |
741 | cursorOn = true; | 734 | cursorOn = true; |
742 | } | 735 | } |
743 | 736 | ||
744 | oldXPos = xPos; | 737 | oldXPos = xPos; |
745 | oldYPos = yPos; | 738 | oldYPos = yPos; |
746 | /* if (flags & ufPos) { | 739 | /* if (flags & ufPos) { |
747 | xPos = newXPos; | 740 | xPos = newXPos; |
748 | yPos = newYPos; | 741 | yPos = newYPos; |
749 | exposeCursor = true; | 742 | exposeCursor = true; |
750 | }*/ | 743 | }*/ |
751 | if (newXPos >= 0) xPos = newXPos; | 744 | if (newXPos >= 0) xPos = newXPos; |
752 | if (newYPos >= 0) yPos = newYPos; | 745 | if (newYPos >= 0) yPos = newYPos; |
753 | 746 | ||
754 | fontHeight = myDoc->fontHeight; | 747 | fontHeight = myDoc->fontHeight; |
755 | cYPos = cursor.y*fontHeight; | 748 | cYPos = cursor.y*fontHeight; |
756 | 749 | ||
757 | z = 0; | 750 | z = 0; |
758 | do { | 751 | do { |
759 | w = myView->width() - 4; | 752 | w = myView->width() - 4; |
760 | h = myView->height() - 4; | 753 | h = myView->height() - 4; |
761 | 754 | ||
762 | xMax = myDoc->textWidth() - w; | 755 | xMax = myDoc->textWidth() - w; |
763 | b = (xPos > 0 || xMax > 0); | 756 | b = (xPos > 0 || xMax > 0); |
764 | if (b) h -= scrollbarWidth; | 757 | if (b) h -= scrollbarWidth; |
765 | yMax = myDoc->textHeight() - h; | 758 | yMax = myDoc->textHeight() - h; |
766 | if (yPos > 0 || yMax > 0) { | 759 | if (yPos > 0 || yMax > 0) { |
767 | w -= scrollbarWidth; | 760 | w -= scrollbarWidth; |
768 | xMax += scrollbarWidth; | 761 | xMax += scrollbarWidth; |
769 | if (!b && xMax > 0) { | 762 | if (!b && xMax > 0) { |
770 | h -= scrollbarWidth; | 763 | h -= scrollbarWidth; |
771 | yMax += scrollbarWidth; | 764 | yMax += scrollbarWidth; |
772 | } | 765 | } |
773 | } | 766 | } |
774 | 767 | ||
775 | if (!exposeCursor) break; | 768 | if (!exposeCursor) break; |
776 | // if (flags & KateView::ufNoScroll) break; | 769 | // if (flags & KateView::ufNoScroll) break; |
777 | /* | 770 | /* |
778 | if (flags & KateView::ufCenter) { | 771 | if (flags & KateView::ufCenter) { |
779 | cXPosMin = xPos + w/3; | 772 | cXPosMin = xPos + w/3; |
780 | cXPosMax = xPos + (w*2)/3; | 773 | cXPosMax = xPos + (w*2)/3; |
781 | cYPosMin = yPos + h/3; | 774 | cYPosMin = yPos + h/3; |
782 | cYPosMax = yPos + ((h - fontHeight)*2)/3; | 775 | cYPosMax = yPos + ((h - fontHeight)*2)/3; |
783 | } else {*/ | 776 | } else {*/ |
784 | cXPosMin = xPos + 4; | 777 | cXPosMin = xPos + 4; |
785 | cXPosMax = xPos + w - 8; | 778 | cXPosMax = xPos + w - 8; |
786 | cYPosMin = yPos; | 779 | cYPosMin = yPos; |
787 | cYPosMax = yPos + (h - fontHeight); | 780 | cYPosMax = yPos + (h - fontHeight); |
788 | // } | 781 | // } |
789 | 782 | ||
790 | if (cXPos < cXPosMin) { | 783 | if (cXPos < cXPosMin) { |
791 | xPos -= cXPosMin - cXPos; | 784 | xPos -= cXPosMin - cXPos; |
792 | } | 785 | } |
793 | if (xPos < 0) xPos = 0; | 786 | if (xPos < 0) xPos = 0; |
794 | if (cXPos > cXPosMax) { | 787 | if (cXPos > cXPosMax) { |
795 | xPos += cXPos - cXPosMax; | 788 | xPos += cXPos - cXPosMax; |
796 | } | 789 | } |
797 | if (cYPos < cYPosMin) { | 790 | if (cYPos < cYPosMin) { |
798 | yPos -= cYPosMin - cYPos; | 791 | yPos -= cYPosMin - cYPos; |
799 | } | 792 | } |
800 | if (yPos < 0) yPos = 0; | 793 | if (yPos < 0) yPos = 0; |
801 | if (cYPos > cYPosMax) { | 794 | if (cYPos > cYPosMax) { |
802 | yPos += cYPos - cYPosMax; | 795 | yPos += cYPos - cYPosMax; |
803 | } | 796 | } |
804 | 797 | ||
805 | z++; | 798 | z++; |
806 | } while (z < 2); | 799 | } while (z < 2); |
807 | 800 | ||
808 | if (xMax < xPos) xMax = xPos; | 801 | if (xMax < xPos) xMax = xPos; |
809 | if (yMax < yPos) yMax = yPos; | 802 | if (yMax < yPos) yMax = yPos; |
810 | 803 | ||
811 | if (xMax > 0) { | 804 | if (xMax > 0) { |
812 | pageScroll = w - (w % fontHeight) - fontHeight; | 805 | pageScroll = w - (w % fontHeight) - fontHeight; |
813 | if (pageScroll <= 0) | 806 | if (pageScroll <= 0) |
814 | pageScroll = fontHeight; | 807 | pageScroll = fontHeight; |
815 | 808 | ||
816 | xScroll->blockSignals(true); | 809 | xScroll->blockSignals(true); |
817 | xScroll->setGeometry(2,h + 2,w,scrollbarWidth); | 810 | xScroll->setGeometry(2,h + 2,w,scrollbarWidth); |
818 | xScroll->setRange(0,xMax); | 811 | xScroll->setRange(0,xMax); |
819 | xScroll->setValue(xPos); | 812 | xScroll->setValue(xPos); |
820 | xScroll->setSteps(fontHeight,pageScroll); | 813 | xScroll->setSteps(fontHeight,pageScroll); |
821 | xScroll->blockSignals(false); | 814 | xScroll->blockSignals(false); |
822 | xScroll->show(); | 815 | xScroll->show(); |
823 | } else xScroll->hide(); | 816 | } else xScroll->hide(); |
824 | 817 | ||
825 | if (yMax > 0) { | 818 | if (yMax > 0) { |
826 | pageScroll = h - (h % fontHeight) - fontHeight; | 819 | pageScroll = h - (h % fontHeight) - fontHeight; |
827 | if (pageScroll <= 0) | 820 | if (pageScroll <= 0) |
828 | pageScroll = fontHeight; | 821 | pageScroll = fontHeight; |
829 | 822 | ||
830 | yScroll->blockSignals(true); | 823 | yScroll->blockSignals(true); |
831 | yScroll->setGeometry(w + 2,2,scrollbarWidth,h); | 824 | yScroll->setGeometry(w + 2,2,scrollbarWidth,h); |
832 | yScroll->setRange(0,yMax); | 825 | yScroll->setRange(0,yMax); |
833 | yScroll->setValue(yPos); | 826 | yScroll->setValue(yPos); |
834 | yScroll->setSteps(fontHeight,pageScroll); | 827 | yScroll->setSteps(fontHeight,pageScroll); |
835 | yScroll->blockSignals(false); | 828 | yScroll->blockSignals(false); |
836 | yScroll->show(); | 829 | yScroll->show(); |
837 | } else yScroll->hide(); | 830 | } else yScroll->hide(); |
838 | 831 | ||
839 | if (w != width() || h != height()) { | 832 | if (w != width() || h != height()) { |
840 | clearDirtyCache(h); | 833 | clearDirtyCache(h); |
841 | resize(w,h); | 834 | resize(w,h); |
842 | } else { | 835 | } else { |
843 | dx = oldXPos - xPos; | 836 | dx = oldXPos - xPos; |
844 | dy = oldYPos - yPos; | 837 | dy = oldYPos - yPos; |
845 | 838 | ||
846 | b = updateState == 3; | 839 | b = updateState == 3; |
847 | if (flags & KateView::ufUpdateOnScroll) { | 840 | if (flags & KateView::ufUpdateOnScroll) { |
848 | b |= dx || dy; | 841 | b |= dx || dy; |
849 | } else { | 842 | } else { |
850 | b |= QABS(dx)*3 > w*2 || QABS(dy)*3 > h*2; | 843 | b |= QABS(dx)*3 > w*2 || QABS(dy)*3 > h*2; |
851 | } | 844 | } |
852 | 845 | ||
diff --git a/noncore/apps/tinykate/libkate/view/kateviewdialog.cpp b/noncore/apps/tinykate/libkate/view/kateviewdialog.cpp index bd5b74f..a85fb87 100644 --- a/noncore/apps/tinykate/libkate/view/kateviewdialog.cpp +++ b/noncore/apps/tinykate/libkate/view/kateviewdialog.cpp | |||
@@ -1,573 +1,571 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | kateviewdialog.cpp - description | 2 | kateviewdialog.cpp - description |
3 | ------------------- | 3 | ------------------- |
4 | copyright : (C) 2001 by The Kate Team | 4 | copyright : (C) 2001 by The Kate Team |
5 | (C) 2002 by Joseph Wenninger | 5 | (C) 2002 by Joseph Wenninger |
6 | email : kwrite-devel@kde.org | 6 | email : kwrite-devel@kde.org |
7 | jowenn@kde.org | 7 | jowenn@kde.org |
8 | 8 | ||
9 | ***************************************************************************/ | 9 | ***************************************************************************/ |
10 | 10 | ||
11 | /*************************************************************************** | 11 | /*************************************************************************** |
12 | * * | 12 | * * |
13 | * This program is free software; you can redistribute it and/or modify * | 13 | * This program is free software; you can redistribute it and/or modify * |
14 | * it under the terms of the GNU General Public License as published by * | 14 | * it under the terms of the GNU General Public License as published by * |
15 | * the Free Software Foundation; either version 2 of the License, or * | 15 | * the Free Software Foundation; either version 2 of the License, or * |
16 | * (at your option) any later version. * | 16 | * (at your option) any later version. * |
17 | * * | 17 | * * |
18 | ***************************************************************************/ | 18 | ***************************************************************************/ |
19 | // Dialogs | 19 | // Dialogs |
20 | 20 | ||
21 | #include <stdio.h> | 21 | #include <stdio.h> |
22 | #include <stdlib.h> | 22 | #include <stdlib.h> |
23 | 23 | ||
24 | #include <qgrid.h> | 24 | #include <qgrid.h> |
25 | #include <qlabel.h> | 25 | #include <qlabel.h> |
26 | #include <qlayout.h> | 26 | #include <qlayout.h> |
27 | #include <qlistbox.h> | 27 | #include <qlistbox.h> |
28 | #include <qspinbox.h> | ||
29 | #include <qcombobox.h> | ||
30 | #include <qgroupbox.h> | 28 | #include <qgroupbox.h> |
31 | #include <qlineedit.h> | 29 | #include <qlineedit.h> |
32 | #include <qcheckbox.h> | 30 | #include <qcheckbox.h> |
33 | #include <qcollection.h> | 31 | #include <qcollection.h> |
34 | #include <qpushbutton.h> | 32 | #include <qpushbutton.h> |
35 | #include <qobjectlist.h> | 33 | #include <qobjectlist.h> |
36 | #include <qradiobutton.h> | 34 | #include <qradiobutton.h> |
37 | #include <qwhatsthis.h> | 35 | #include <qwhatsthis.h> |
38 | #include <qstringlist.h> | 36 | #include <qstringlist.h> |
39 | #include <klocale.h> | 37 | #include <klocale.h> |
40 | #include <kcolorbtn.h> | 38 | #include <kcolorbtn.h> |
41 | #include <qcombobox.h> | ||
42 | #include <kglobal.h> | 39 | #include <kglobal.h> |
43 | #include <qvbox.h> | 40 | #include <qvbox.h> |
44 | #include <qspinbox.h> | 41 | #include <qspinbox.h> |
42 | #include <qcombobox.h> | ||
45 | #include <kfontdialog.h> | 43 | #include <kfontdialog.h> |
46 | 44 | ||
47 | #include "../document/katedocument.h" | 45 | #include "../document/katedocument.h" |
48 | #include "kateviewdialog.h" | 46 | #include "kateviewdialog.h" |
49 | #include <opie2/ofontselector.h> | 47 | #include <opie2/ofontselector.h> |
50 | 48 | ||
51 | 49 | ||
52 | SearchDialog::SearchDialog( QWidget *parent, QStringList &searchFor, QStringList &replaceWith, int flags ) | 50 | SearchDialog::SearchDialog( QWidget *parent, QStringList &searchFor, QStringList &replaceWith, int flags ) |
53 | : KDialogBase( parent, 0L, true, i18n( "Find Text" ), Ok | Cancel, Ok ) | 51 | : KDialogBase( parent, 0L, true, i18n( "Find Text" ), Ok | Cancel, Ok ) |
54 | , m_replace( 0L ) | 52 | , m_replace( 0L ) |
55 | { | 53 | { |
56 | QWidget *page = new QWidget( this ); | 54 | QWidget *page = new QWidget( this ); |
57 | setMainWidget( page ); | 55 | setMainWidget( page ); |
58 | 56 | ||
59 | QVBoxLayout *topLayout = new QVBoxLayout( page, 0, spacingHint() ); | 57 | QVBoxLayout *topLayout = new QVBoxLayout( page, 0, spacingHint() ); |
60 | 58 | ||
61 | m_search = new QComboBox( true, page ); | 59 | m_search = new QComboBox( true, page ); |
62 | m_search->insertStringList( searchFor ); | 60 | m_search->insertStringList( searchFor ); |
63 | m_search->setMinimumWidth( m_search->sizeHint().width() ); | 61 | m_search->setMinimumWidth( m_search->sizeHint().width() ); |
64 | m_search->lineEdit()->selectAll(); | 62 | m_search->lineEdit()->selectAll(); |
65 | QLabel *label = new QLabel( m_search, i18n( "&Text To Find:" ), page ); | 63 | QLabel *label = new QLabel( m_search, i18n( "&Text To Find:" ), page ); |
66 | m_optRegExp = new QCheckBox( i18n( "Regular Expression" ), page ); | 64 | m_optRegExp = new QCheckBox( i18n( "Regular Expression" ), page ); |
67 | topLayout->addWidget( label ); | 65 | topLayout->addWidget( label ); |
68 | topLayout->addWidget( m_search ); | 66 | topLayout->addWidget( m_search ); |
69 | topLayout->addWidget( m_optRegExp ); | 67 | topLayout->addWidget( m_optRegExp ); |
70 | 68 | ||
71 | if( flags & KateView::sfReplace ) | 69 | if( flags & KateView::sfReplace ) |
72 | { | 70 | { |
73 | // make it a replace dialog | 71 | // make it a replace dialog |
74 | setCaption( i18n( "Replace Text" ) ); | 72 | setCaption( i18n( "Replace Text" ) ); |
75 | m_replace = new QComboBox( true, page ); | 73 | m_replace = new QComboBox( true, page ); |
76 | m_replace->insertStringList( replaceWith ); | 74 | m_replace->insertStringList( replaceWith ); |
77 | m_replace->setMinimumWidth( m_search->sizeHint().width() ); | 75 | m_replace->setMinimumWidth( m_search->sizeHint().width() ); |
78 | label = new QLabel( m_replace, i18n( "&Replace With:" ), page ); | 76 | label = new QLabel( m_replace, i18n( "&Replace With:" ), page ); |
79 | //m_optPlaceholders = new QCheckBox( i18n( "&Use Placeholders" ), page ); | 77 | //m_optPlaceholders = new QCheckBox( i18n( "&Use Placeholders" ), page ); |
80 | topLayout->addWidget( label ); | 78 | topLayout->addWidget( label ); |
81 | topLayout->addWidget( m_replace ); | 79 | topLayout->addWidget( m_replace ); |
82 | //topLayout->addWidget( m_optPlaceholders ); | 80 | //topLayout->addWidget( m_optPlaceholders ); |
83 | } | 81 | } |
84 | 82 | ||
85 | QGroupBox *group = new QGroupBox( i18n( "Options" ), page ); | 83 | QGroupBox *group = new QGroupBox( i18n( "Options" ), page ); |
86 | topLayout->addWidget( group, 10 ); | 84 | topLayout->addWidget( group, 10 ); |
87 | 85 | ||
88 | QGridLayout *gbox = new QGridLayout( group, 5, 2, spacingHint() ); | 86 | QGridLayout *gbox = new QGridLayout( group, 5, 2, spacingHint() ); |
89 | gbox->addRowSpacing( 0, fontMetrics().lineSpacing() ); | 87 | gbox->addRowSpacing( 0, fontMetrics().lineSpacing() ); |
90 | gbox->setRowStretch( 4, 10 ); | 88 | gbox->setRowStretch( 4, 10 ); |
91 | 89 | ||
92 | m_opt1 = new QCheckBox( i18n( "C&ase Sensitive" ), group ); | 90 | m_opt1 = new QCheckBox( i18n( "C&ase Sensitive" ), group ); |
93 | gbox->addWidget( m_opt1, 1, 0 ); | 91 | gbox->addWidget( m_opt1, 1, 0 ); |
94 | 92 | ||
95 | m_opt2 = new QCheckBox(i18n("&Whole Words Only" ), group ); | 93 | m_opt2 = new QCheckBox(i18n("&Whole Words Only" ), group ); |
96 | gbox->addWidget( m_opt2, 2, 0 ); | 94 | gbox->addWidget( m_opt2, 2, 0 ); |
97 | 95 | ||
98 | m_opt3 = new QCheckBox(i18n("&From Beginning" ), group ); | 96 | m_opt3 = new QCheckBox(i18n("&From Beginning" ), group ); |
99 | gbox->addWidget( m_opt3, 3, 0 ); | 97 | gbox->addWidget( m_opt3, 3, 0 ); |
100 | 98 | ||
101 | m_opt4 = new QCheckBox(i18n("Find &Backwards" ), group ); | 99 | m_opt4 = new QCheckBox(i18n("Find &Backwards" ), group ); |
102 | gbox->addWidget( m_opt4, 1, 1 ); | 100 | gbox->addWidget( m_opt4, 1, 1 ); |
103 | 101 | ||
104 | m_opt5 = new QCheckBox(i18n("&Selected Text" ), group ); | 102 | m_opt5 = new QCheckBox(i18n("&Selected Text" ), group ); |
105 | gbox->addWidget( m_opt5, 2, 1 ); | 103 | gbox->addWidget( m_opt5, 2, 1 ); |
106 | 104 | ||
107 | m_opt1->setChecked( flags & KateView::sfCaseSensitive ); | 105 | m_opt1->setChecked( flags & KateView::sfCaseSensitive ); |
108 | m_opt2->setChecked( flags & KateView::sfWholeWords ); | 106 | m_opt2->setChecked( flags & KateView::sfWholeWords ); |
109 | m_opt3->setChecked( flags & KateView::sfFromBeginning ); | 107 | m_opt3->setChecked( flags & KateView::sfFromBeginning ); |
110 | m_optRegExp->setChecked( flags & KateView::sfRegularExpression ); | 108 | m_optRegExp->setChecked( flags & KateView::sfRegularExpression ); |
111 | m_opt4->setChecked( flags & KateView::sfBackward ); | 109 | m_opt4->setChecked( flags & KateView::sfBackward ); |
112 | m_opt5->setChecked( flags & KateView::sfSelected ); | 110 | m_opt5->setChecked( flags & KateView::sfSelected ); |
113 | 111 | ||
114 | if( m_replace ) | 112 | if( m_replace ) |
115 | { | 113 | { |
116 | m_opt6 = new QCheckBox( i18n( "&Prompt On Replace" ), group ); | 114 | m_opt6 = new QCheckBox( i18n( "&Prompt On Replace" ), group ); |
117 | m_opt6->setChecked( flags & KateView::sfPrompt ); | 115 | m_opt6->setChecked( flags & KateView::sfPrompt ); |
118 | gbox->addWidget( m_opt6, 3, 1 ); | 116 | gbox->addWidget( m_opt6, 3, 1 ); |
119 | } | 117 | } |
120 | 118 | ||
121 | m_search->setFocus(); | 119 | m_search->setFocus(); |
122 | } | 120 | } |
123 | 121 | ||
124 | QString SearchDialog::getSearchFor() | 122 | QString SearchDialog::getSearchFor() |
125 | { | 123 | { |
126 | return m_search->currentText(); | 124 | return m_search->currentText(); |
127 | } | 125 | } |
128 | 126 | ||
129 | QString SearchDialog::getReplaceWith() | 127 | QString SearchDialog::getReplaceWith() |
130 | { | 128 | { |
131 | return m_replace->currentText(); | 129 | return m_replace->currentText(); |
132 | } | 130 | } |
133 | 131 | ||
134 | int SearchDialog::getFlags() | 132 | int SearchDialog::getFlags() |
135 | { | 133 | { |
136 | int flags = 0; | 134 | int flags = 0; |
137 | 135 | ||
138 | if( m_opt1->isChecked() ) flags |= KateView::sfCaseSensitive; | 136 | if( m_opt1->isChecked() ) flags |= KateView::sfCaseSensitive; |
139 | if( m_opt2->isChecked() ) flags |= KateView::sfWholeWords; | 137 | if( m_opt2->isChecked() ) flags |= KateView::sfWholeWords; |
140 | if( m_opt3->isChecked() ) flags |= KateView::sfFromBeginning; | 138 | if( m_opt3->isChecked() ) flags |= KateView::sfFromBeginning; |
141 | if( m_opt4->isChecked() ) flags |= KateView::sfBackward; | 139 | if( m_opt4->isChecked() ) flags |= KateView::sfBackward; |
142 | if( m_opt5->isChecked() ) flags |= KateView::sfSelected; | 140 | if( m_opt5->isChecked() ) flags |= KateView::sfSelected; |
143 | if( m_optRegExp->isChecked() ) flags |= KateView::sfRegularExpression; | 141 | if( m_optRegExp->isChecked() ) flags |= KateView::sfRegularExpression; |
144 | if( m_replace ) | 142 | if( m_replace ) |
145 | { | 143 | { |
146 | if( m_opt6->isChecked() ) | 144 | if( m_opt6->isChecked() ) |
147 | flags |= KateView::sfPrompt; | 145 | flags |= KateView::sfPrompt; |
148 | 146 | ||
149 | flags |= KateView::sfReplace; | 147 | flags |= KateView::sfReplace; |
150 | } | 148 | } |
151 | 149 | ||
152 | return flags; | 150 | return flags; |
153 | } | 151 | } |
154 | 152 | ||
155 | void SearchDialog::slotOk() | 153 | void SearchDialog::slotOk() |
156 | { | 154 | { |
157 | if ( !m_search->currentText().isEmpty() ) | 155 | if ( !m_search->currentText().isEmpty() ) |
158 | { | 156 | { |
159 | if ( !m_optRegExp->isChecked() ) | 157 | if ( !m_optRegExp->isChecked() ) |
160 | { | 158 | { |
161 | accept(); | 159 | accept(); |
162 | } | 160 | } |
163 | else | 161 | else |
164 | { | 162 | { |
165 | // Check for a valid regular expression. | 163 | // Check for a valid regular expression. |
166 | 164 | ||
167 | QRegExp regExp( m_search->currentText() ); | 165 | QRegExp regExp( m_search->currentText() ); |
168 | 166 | ||
169 | if ( regExp.isValid() ) | 167 | if ( regExp.isValid() ) |
170 | accept(); | 168 | accept(); |
171 | } | 169 | } |
172 | } | 170 | } |
173 | } | 171 | } |
174 | 172 | ||
175 | void SearchDialog::setSearchText( const QString &searchstr ) | 173 | void SearchDialog::setSearchText( const QString &searchstr ) |
176 | { | 174 | { |
177 | m_search->insertItem( searchstr, 0 ); | 175 | m_search->insertItem( searchstr, 0 ); |
178 | m_search->setCurrentItem( 0 ); | 176 | m_search->setCurrentItem( 0 ); |
179 | m_search->lineEdit()->selectAll(); | 177 | m_search->lineEdit()->selectAll(); |
180 | } | 178 | } |
181 | 179 | ||
182 | // this dialog is not modal | 180 | // this dialog is not modal |
183 | ReplacePrompt::ReplacePrompt( QWidget *parent ) | 181 | ReplacePrompt::ReplacePrompt( QWidget *parent ) |
184 | : KDialogBase(parent, 0L, false, i18n( "Replace Text" ), | 182 | : KDialogBase(parent, 0L, false, i18n( "Replace Text" ), |
185 | User3 | User2 | User1 | Close, User3, true, | 183 | User3 | User2 | User1 | Close, User3, true, |
186 | i18n("&All"), i18n("&No"), i18n("&Yes")) { | 184 | i18n("&All"), i18n("&No"), i18n("&Yes")) { |
187 | 185 | ||
188 | QWidget *page = new QWidget(this); | 186 | QWidget *page = new QWidget(this); |
189 | setMainWidget(page); | 187 | setMainWidget(page); |
190 | 188 | ||
191 | QBoxLayout *topLayout = new QVBoxLayout( page, 0, spacingHint() ); | 189 | QBoxLayout *topLayout = new QVBoxLayout( page, 0, spacingHint() ); |
192 | QLabel *label = new QLabel(i18n("Replace this occurence?"),page); | 190 | QLabel *label = new QLabel(i18n("Replace this occurence?"),page); |
193 | topLayout->addWidget(label ); | 191 | topLayout->addWidget(label ); |
194 | } | 192 | } |
195 | 193 | ||
196 | void ReplacePrompt::slotUser1( void ) { // All | 194 | void ReplacePrompt::slotUser1( void ) { // All |
197 | done(KateView::srAll); | 195 | done(KateView::srAll); |
198 | } | 196 | } |
199 | 197 | ||
200 | void ReplacePrompt::slotUser2( void ) { // No | 198 | void ReplacePrompt::slotUser2( void ) { // No |
201 | done(KateView::srNo); | 199 | done(KateView::srNo); |
202 | } | 200 | } |
203 | 201 | ||
204 | void ReplacePrompt::slotUser3( void ) { // Yes | 202 | void ReplacePrompt::slotUser3( void ) { // Yes |
205 | accept(); | 203 | accept(); |
206 | } | 204 | } |
207 | 205 | ||
208 | void ReplacePrompt::done(int r) { | 206 | void ReplacePrompt::done(int r) { |
209 | setResult(r); | 207 | setResult(r); |
210 | emit clicked(); | 208 | emit clicked(); |
211 | } | 209 | } |
212 | 210 | ||
213 | void ReplacePrompt::closeEvent(QCloseEvent *) { | 211 | void ReplacePrompt::closeEvent(QCloseEvent *) { |
214 | reject(); | 212 | reject(); |
215 | } | 213 | } |
216 | 214 | ||
217 | GotoLineDialog::GotoLineDialog(QWidget *parent, int line, int max) | 215 | GotoLineDialog::GotoLineDialog(QWidget *parent, int line, int max) |
218 | : KDialogBase(parent, 0L, true, i18n("Goto Line"), Ok | Cancel, Ok) { | 216 | : KDialogBase(parent, 0L, true, i18n("Goto Line"), Ok | Cancel, Ok) { |
219 | 217 | ||
220 | QWidget *page = new QWidget(this); | 218 | QWidget *page = new QWidget(this); |
221 | setMainWidget(page); | 219 | setMainWidget(page); |
222 | 220 | ||
223 | QVBoxLayout *topLayout = new QVBoxLayout( page, 0, spacingHint() ); | 221 | QVBoxLayout *topLayout = new QVBoxLayout( page, 0, spacingHint() ); |
224 | e1 = new QSpinBox(page); | 222 | e1 = new QSpinBox(page); |
225 | e1->setMinValue(1); | 223 | e1->setMinValue(1); |
226 | e1->setMaxValue(max); | 224 | e1->setMaxValue(max); |
227 | e1->setValue((int)line); | 225 | e1->setValue((int)line); |
228 | 226 | ||
229 | QLabel *label = new QLabel( e1,i18n("&Goto Line:"), page ); | 227 | QLabel *label = new QLabel( e1,i18n("&Goto Line:"), page ); |
230 | topLayout->addWidget(label); | 228 | topLayout->addWidget(label); |
231 | topLayout->addWidget(e1); | 229 | topLayout->addWidget(e1); |
232 | topLayout->addSpacing(spacingHint()); // A little bit extra space | 230 | topLayout->addSpacing(spacingHint()); // A little bit extra space |
233 | topLayout->addStretch(10); | 231 | topLayout->addStretch(10); |
234 | e1->setFocus(); | 232 | e1->setFocus(); |
235 | } | 233 | } |
236 | 234 | ||
237 | int GotoLineDialog::getLine() { | 235 | int GotoLineDialog::getLine() { |
238 | return e1->value(); | 236 | return e1->value(); |
239 | } | 237 | } |
240 | 238 | ||
241 | const int IndentConfigTab::flags[] = {KateView::cfAutoIndent, KateView::cfSpaceIndent, | 239 | const int IndentConfigTab::flags[] = {KateView::cfAutoIndent, KateView::cfSpaceIndent, |
242 | KateView::cfBackspaceIndents,KateView::cfTabIndents, KateView::cfKeepIndentProfile, KateView::cfKeepExtraSpaces}; | 240 | KateView::cfBackspaceIndents,KateView::cfTabIndents, KateView::cfKeepIndentProfile, KateView::cfKeepExtraSpaces}; |
243 | 241 | ||
244 | IndentConfigTab::IndentConfigTab(QWidget *parent, KateView *view) | 242 | IndentConfigTab::IndentConfigTab(QWidget *parent, KateView *view) |
245 | : QWidget(parent, 0L) | 243 | : QWidget(parent, 0L) |
246 | { | 244 | { |
247 | QVBoxLayout *layout = new QVBoxLayout(this, 0, KDialog::spacingHint() ); | 245 | QVBoxLayout *layout = new QVBoxLayout(this, 0, KDialog::spacingHint() ); |
248 | int configFlags = view->config(); | 246 | int configFlags = view->config(); |
249 | 247 | ||
250 | opt[0] = new QCheckBox(i18n("&Auto Indent"), this); | 248 | opt[0] = new QCheckBox(i18n("&Auto Indent"), this); |
251 | layout->addWidget(opt[0], 0, AlignLeft); | 249 | layout->addWidget(opt[0], 0, AlignLeft); |
252 | opt[0]->setChecked(configFlags & flags[0]); | 250 | opt[0]->setChecked(configFlags & flags[0]); |
253 | 251 | ||
254 | opt[1] = new QCheckBox(i18n("Indent With &Spaces"), this); | 252 | opt[1] = new QCheckBox(i18n("Indent With &Spaces"), this); |
255 | layout->addWidget(opt[1], 0, AlignLeft); | 253 | layout->addWidget(opt[1], 0, AlignLeft); |
256 | opt[1]->setChecked(configFlags & flags[1]); | 254 | opt[1]->setChecked(configFlags & flags[1]); |
257 | 255 | ||
258 | opt[2] = new QCheckBox(i18n("&Backspace Key Indents"), this); | 256 | opt[2] = new QCheckBox(i18n("&Backspace Key Indents"), this); |
259 | layout->addWidget(opt[2], 0, AlignLeft); | 257 | layout->addWidget(opt[2], 0, AlignLeft); |
260 | opt[2]->setChecked(configFlags & flags[2]); | 258 | opt[2]->setChecked(configFlags & flags[2]); |
261 | 259 | ||
262 | opt[3] = new QCheckBox(i18n("&Tab Key Indents"), this); | 260 | opt[3] = new QCheckBox(i18n("&Tab Key Indents"), this); |
263 | layout->addWidget(opt[3], 0, AlignLeft); | 261 | layout->addWidget(opt[3], 0, AlignLeft); |
264 | opt[3]->setChecked(configFlags & flags[3]); | 262 | opt[3]->setChecked(configFlags & flags[3]); |
265 | 263 | ||
266 | opt[4] = new QCheckBox(i18n("Keep Indent &Profile"), this); | 264 | opt[4] = new QCheckBox(i18n("Keep Indent &Profile"), this); |
267 | layout->addWidget(opt[4], 0, AlignLeft); | 265 | layout->addWidget(opt[4], 0, AlignLeft); |
268 | // opt[4]->setChecked(configFlags & flags[4]); | 266 | // opt[4]->setChecked(configFlags & flags[4]); |
269 | opt[4]->setChecked(true); | 267 | opt[4]->setChecked(true); |
270 | opt[4]->hide(); | 268 | opt[4]->hide(); |
271 | 269 | ||
272 | opt[5] = new QCheckBox(i18n("&Keep Extra Spaces"), this); | 270 | opt[5] = new QCheckBox(i18n("&Keep Extra Spaces"), this); |
273 | layout->addWidget(opt[5], 0, AlignLeft); | 271 | layout->addWidget(opt[5], 0, AlignLeft); |
274 | opt[5]->setChecked(configFlags & flags[5]); | 272 | opt[5]->setChecked(configFlags & flags[5]); |
275 | 273 | ||
276 | layout->addStretch(); | 274 | layout->addStretch(); |
277 | 275 | ||
278 | // What is this? help | 276 | // What is this? help |
279 | QWhatsThis::add(opt[0], i18n("When <b>Auto indent</b> is on, KateView will indent new lines to equal the indent on the previous line.<p>If the previous line is blank, the nearest line above with text is used")); | 277 | QWhatsThis::add(opt[0], i18n("When <b>Auto indent</b> is on, KateView will indent new lines to equal the indent on the previous line.<p>If the previous line is blank, the nearest line above with text is used")); |
280 | QWhatsThis::add(opt[1], i18n("Check this if you want to indent with spaces rather than tabs.<br>A Tab will be converted to <u>Tab-width</u> as set in the <b>edit</b> options")); | 278 | QWhatsThis::add(opt[1], i18n("Check this if you want to indent with spaces rather than tabs.<br>A Tab will be converted to <u>Tab-width</u> as set in the <b>edit</b> options")); |
281 | QWhatsThis::add(opt[2], i18n("This allows the <b>backspace</b> key to be used to indent.")); | 279 | QWhatsThis::add(opt[2], i18n("This allows the <b>backspace</b> key to be used to indent.")); |
282 | QWhatsThis::add(opt[3], i18n("This allows the <b>tab</b> key to be used to indent.")); | 280 | QWhatsThis::add(opt[3], i18n("This allows the <b>tab</b> key to be used to indent.")); |
283 | QWhatsThis::add(opt[4], i18n("This retains current indentation settings for future documents.")); | 281 | QWhatsThis::add(opt[4], i18n("This retains current indentation settings for future documents.")); |
284 | QWhatsThis::add(opt[5], i18n("Indentations of more than the selected number of spaces will not be shortened.")); | 282 | QWhatsThis::add(opt[5], i18n("Indentations of more than the selected number of spaces will not be shortened.")); |
285 | } | 283 | } |
286 | 284 | ||
287 | void IndentConfigTab::getData(KateView *view) { | 285 | void IndentConfigTab::getData(KateView *view) { |
288 | int configFlags, z; | 286 | int configFlags, z; |
289 | 287 | ||
290 | configFlags = view->config(); | 288 | configFlags = view->config(); |
291 | for (z = 0; z < numFlags; z++) { | 289 | for (z = 0; z < numFlags; z++) { |
292 | configFlags &= ~flags[z]; | 290 | configFlags &= ~flags[z]; |
293 | if (opt[z]->isChecked()) configFlags |= flags[z]; | 291 | if (opt[z]->isChecked()) configFlags |= flags[z]; |
294 | } | 292 | } |
295 | view->setConfig(configFlags); | 293 | view->setConfig(configFlags); |
296 | } | 294 | } |
297 | 295 | ||
298 | const int SelectConfigTab::flags[] = {KateView::cfPersistent, KateView::cfDelOnInput, | 296 | const int SelectConfigTab::flags[] = {KateView::cfPersistent, KateView::cfDelOnInput, |
299 | KateView::cfMouseAutoCopy, KateView::cfSingleSelection, KateView::cfVerticalSelect, KateView::cfXorSelect}; | 297 | KateView::cfMouseAutoCopy, KateView::cfSingleSelection, KateView::cfVerticalSelect, KateView::cfXorSelect}; |
300 | 298 | ||
301 | SelectConfigTab::SelectConfigTab(QWidget *parent, KateView *view) | 299 | SelectConfigTab::SelectConfigTab(QWidget *parent, KateView *view) |
302 | : QWidget(parent, 0L) | 300 | : QWidget(parent, 0L) |
303 | { | 301 | { |
304 | QVBoxLayout *layout = new QVBoxLayout(this, 0, KDialog::spacingHint() ); | 302 | QVBoxLayout *layout = new QVBoxLayout(this, 0, KDialog::spacingHint() ); |
305 | int configFlags = view->config(); | 303 | int configFlags = view->config(); |
306 | 304 | ||
307 | opt[0] = new QCheckBox(i18n("&Persistent Selections"), this); | 305 | opt[0] = new QCheckBox(i18n("&Persistent Selections"), this); |
308 | layout->addWidget(opt[0], 0, AlignLeft); | 306 | layout->addWidget(opt[0], 0, AlignLeft); |
309 | opt[0]->setChecked(configFlags & flags[0]); | 307 | opt[0]->setChecked(configFlags & flags[0]); |
310 | 308 | ||
311 | opt[1] = new QCheckBox(i18n("&Overwrite Selections"), this); | 309 | opt[1] = new QCheckBox(i18n("&Overwrite Selections"), this); |
312 | layout->addWidget(opt[1], 0, AlignLeft); | 310 | layout->addWidget(opt[1], 0, AlignLeft); |
313 | opt[1]->setChecked(configFlags & flags[1]); | 311 | opt[1]->setChecked(configFlags & flags[1]); |
314 | 312 | ||
315 | opt[2] = new QCheckBox(i18n("Mouse &Autocopy"), this); | 313 | opt[2] = new QCheckBox(i18n("Mouse &Autocopy"), this); |
316 | layout->addWidget(opt[2], 0, AlignLeft); | 314 | layout->addWidget(opt[2], 0, AlignLeft); |
317 | opt[2]->setChecked(configFlags & flags[2]); | 315 | opt[2]->setChecked(configFlags & flags[2]); |
318 | 316 | ||
319 | opt[3] = new QCheckBox(i18n("&X11-like Single Selection"), this); | 317 | opt[3] = new QCheckBox(i18n("&X11-like Single Selection"), this); |
320 | layout->addWidget(opt[3], 0, AlignLeft); | 318 | layout->addWidget(opt[3], 0, AlignLeft); |
321 | opt[3]->setChecked(configFlags & flags[3]); | 319 | opt[3]->setChecked(configFlags & flags[3]); |
322 | 320 | ||
323 | opt[4] = new QCheckBox(i18n("&Vertical Selections"), this); | 321 | opt[4] = new QCheckBox(i18n("&Vertical Selections"), this); |
324 | layout->addWidget(opt[4], 0, AlignLeft); | 322 | layout->addWidget(opt[4], 0, AlignLeft); |
325 | opt[4]->setChecked(configFlags & flags[4]); | 323 | opt[4]->setChecked(configFlags & flags[4]); |
326 | 324 | ||
327 | opt[5] = new QCheckBox(i18n("&Toggle Old"), this); | 325 | opt[5] = new QCheckBox(i18n("&Toggle Old"), this); |
328 | layout->addWidget(opt[5], 0, AlignLeft); | 326 | layout->addWidget(opt[5], 0, AlignLeft); |
329 | opt[5]->setChecked(configFlags & flags[5]); | 327 | opt[5]->setChecked(configFlags & flags[5]); |
330 | 328 | ||
331 | layout->addStretch(); | 329 | layout->addStretch(); |
332 | 330 | ||
333 | // What is this? help | 331 | // What is this? help |
334 | QWhatsThis::add(opt[0], i18n("Enabling this prevents key input or cursor movement by way of the arrow keys from causing the elimination of text selection.<p><b>Note:</b> If the Overwrite Selections option is activated then any typed character input or paste operation will replace the selected text.")); | 332 | QWhatsThis::add(opt[0], i18n("Enabling this prevents key input or cursor movement by way of the arrow keys from causing the elimination of text selection.<p><b>Note:</b> If the Overwrite Selections option is activated then any typed character input or paste operation will replace the selected text.")); |
335 | QWhatsThis::add(opt[1], i18n("When this is on, any keyed character input or paste operation will replace the selected text.")); | 333 | QWhatsThis::add(opt[1], i18n("When this is on, any keyed character input or paste operation will replace the selected text.")); |
336 | QWhatsThis::add(opt[2], i18n("When this is on, any text selected with the mouse will be automatically copied to the clipboard.")); | 334 | QWhatsThis::add(opt[2], i18n("When this is on, any text selected with the mouse will be automatically copied to the clipboard.")); |
337 | QWhatsThis::add(opt[3], i18n("Not implemented yet.")); | 335 | QWhatsThis::add(opt[3], i18n("Not implemented yet.")); |
338 | QWhatsThis::add(opt[4], i18n("Enabling this allows you to make vertical selections.")); | 336 | QWhatsThis::add(opt[4], i18n("Enabling this allows you to make vertical selections.")); |
339 | QWhatsThis::add(opt[5], i18n("Not yet implemented.")); | 337 | QWhatsThis::add(opt[5], i18n("Not yet implemented.")); |
340 | } | 338 | } |
341 | 339 | ||
342 | void SelectConfigTab::getData(KateView *view) { | 340 | void SelectConfigTab::getData(KateView *view) { |
343 | int configFlags, z; | 341 | int configFlags, z; |
344 | 342 | ||
345 | configFlags = view->config(); | 343 | configFlags = view->config(); |
346 | for (z = 0; z < numFlags; z++) { | 344 | for (z = 0; z < numFlags; z++) { |
347 | configFlags &= ~flags[z]; // clear flag | 345 | configFlags &= ~flags[z]; // clear flag |
348 | if (opt[z]->isChecked()) configFlags |= flags[z]; // set flag if checked | 346 | if (opt[z]->isChecked()) configFlags |= flags[z]; // set flag if checked |
349 | } | 347 | } |
350 | view->setConfig(configFlags); | 348 | view->setConfig(configFlags); |
351 | } | 349 | } |
352 | 350 | ||
353 | const int EditConfigTab::flags[] = {KateView::cfWordWrap, KateView::cfReplaceTabs, KateView::cfRemoveSpaces, | 351 | const int EditConfigTab::flags[] = {KateView::cfWordWrap, KateView::cfReplaceTabs, KateView::cfRemoveSpaces, |
354 | KateView::cfAutoBrackets, KateView::cfGroupUndo, KateView::cfShowTabs, KateView::cfSmartHome, | 352 | KateView::cfAutoBrackets, KateView::cfGroupUndo, KateView::cfShowTabs, KateView::cfSmartHome, |
355 | KateView::cfPageUDMovesCursor, KateView::cfWrapCursor}; | 353 | KateView::cfPageUDMovesCursor, KateView::cfWrapCursor}; |
356 | 354 | ||
357 | EditConfigTab::EditConfigTab(QWidget *parent, KateView *view) | 355 | EditConfigTab::EditConfigTab(QWidget *parent, KateView *view) |
358 | : QWidget(parent, 0L) { | 356 | : QWidget(parent, 0L) { |
359 | 357 | ||
360 | QHBoxLayout *mainLayout; | 358 | QHBoxLayout *mainLayout; |
361 | QVBoxLayout *cbLayout, *leLayout; | 359 | QVBoxLayout *cbLayout, *leLayout; |
362 | int configFlags; | 360 | int configFlags; |
363 | 361 | ||
364 | mainLayout = new QHBoxLayout(this, 0, KDialog::spacingHint() ); | 362 | mainLayout = new QHBoxLayout(this, 0, KDialog::spacingHint() ); |
365 | 363 | ||
366 | // checkboxes | 364 | // checkboxes |
367 | cbLayout = new QVBoxLayout( mainLayout ); | 365 | cbLayout = new QVBoxLayout( mainLayout ); |
368 | configFlags = view->config(); | 366 | configFlags = view->config(); |
369 | 367 | ||
370 | opt[0] = new QCheckBox(i18n("&Word wrap"), this); | 368 | opt[0] = new QCheckBox(i18n("&Word wrap"), this); |
371 | cbLayout->addWidget(opt[0], 0, AlignLeft); | 369 | cbLayout->addWidget(opt[0], 0, AlignLeft); |
372 | opt[0]->setChecked(view->doc()->wordWrap()); | 370 | opt[0]->setChecked(view->doc()->wordWrap()); |
373 | 371 | ||
374 | opt[1] = new QCheckBox(i18n("Replace &tabs with spaces"), this); | 372 | opt[1] = new QCheckBox(i18n("Replace &tabs with spaces"), this); |
375 | cbLayout->addWidget(opt[1], 0, AlignLeft); | 373 | cbLayout->addWidget(opt[1], 0, AlignLeft); |
376 | opt[1]->setChecked(configFlags & flags[1]); | 374 | opt[1]->setChecked(configFlags & flags[1]); |
377 | 375 | ||
378 | opt[2] = new QCheckBox(i18n("&Remove trailing spaces"), this); | 376 | opt[2] = new QCheckBox(i18n("&Remove trailing spaces"), this); |
379 | cbLayout->addWidget(opt[2], 0, AlignLeft); | 377 | cbLayout->addWidget(opt[2], 0, AlignLeft); |
380 | opt[2]->setChecked(configFlags & flags[2]); | 378 | opt[2]->setChecked(configFlags & flags[2]); |
381 | 379 | ||
382 | opt[3] = new QCheckBox(i18n("&Auto brackets"), this); | 380 | opt[3] = new QCheckBox(i18n("&Auto brackets"), this); |
383 | cbLayout->addWidget(opt[3], 0, AlignLeft); | 381 | cbLayout->addWidget(opt[3], 0, AlignLeft); |
384 | opt[3]->setChecked(configFlags & flags[3]); | 382 | opt[3]->setChecked(configFlags & flags[3]); |
385 | 383 | ||
386 | opt[4] = new QCheckBox(i18n("Group &undos"), this); | 384 | opt[4] = new QCheckBox(i18n("Group &undos"), this); |
387 | cbLayout->addWidget(opt[4], 0, AlignLeft); | 385 | cbLayout->addWidget(opt[4], 0, AlignLeft); |
388 | opt[4]->setChecked(configFlags & flags[4]); | 386 | opt[4]->setChecked(configFlags & flags[4]); |
389 | 387 | ||
390 | opt[5] = new QCheckBox(i18n("&Show tabs"), this); | 388 | opt[5] = new QCheckBox(i18n("&Show tabs"), this); |
391 | cbLayout->addWidget(opt[5], 0, AlignLeft); | 389 | cbLayout->addWidget(opt[5], 0, AlignLeft); |
392 | opt[5]->setChecked(configFlags & flags[5]); | 390 | opt[5]->setChecked(configFlags & flags[5]); |
393 | 391 | ||
394 | opt[6] = new QCheckBox(i18n("Smart &home"), this); | 392 | opt[6] = new QCheckBox(i18n("Smart &home"), this); |
395 | cbLayout->addWidget(opt[6], 0, AlignLeft); | 393 | cbLayout->addWidget(opt[6], 0, AlignLeft); |
396 | opt[6]->setChecked(configFlags & flags[6]); | 394 | opt[6]->setChecked(configFlags & flags[6]); |
397 | 395 | ||
398 | opt[7] = new QCheckBox(i18n("&Page up/down moves cursor"), this); | 396 | opt[7] = new QCheckBox(i18n("&Page up/down moves cursor"), this); |
399 | cbLayout->addWidget(opt[7], 0, AlignLeft); | 397 | cbLayout->addWidget(opt[7], 0, AlignLeft); |
400 | opt[7]->setChecked(configFlags & flags[7]); | 398 | opt[7]->setChecked(configFlags & flags[7]); |
401 | 399 | ||
402 | opt[8] = new QCheckBox(i18n("Wrap &cursor"), this); | 400 | opt[8] = new QCheckBox(i18n("Wrap &cursor"), this); |
403 | cbLayout->addWidget(opt[8], 0, AlignLeft); | 401 | cbLayout->addWidget(opt[8], 0, AlignLeft); |
404 | opt[8]->setChecked(configFlags & flags[8]); | 402 | opt[8]->setChecked(configFlags & flags[8]); |
405 | 403 | ||
406 | cbLayout->addStretch(); | 404 | cbLayout->addStretch(); |
407 | 405 | ||
408 | // edit lines | 406 | // edit lines |
409 | leLayout = new QVBoxLayout(); | 407 | leLayout = new QVBoxLayout(); |
410 | mainLayout->addLayout(leLayout,10); | 408 | mainLayout->addLayout(leLayout,10); |
411 | 409 | ||
412 | e1 = new QSpinBox(this); | 410 | e1 = new QSpinBox(this); |
413 | e1->setMinValue(20); | 411 | e1->setMinValue(20); |
414 | e1->setMaxValue( 200); | 412 | e1->setMaxValue( 200); |
415 | e1->setValue((int)(view->doc()->wordWrapAt())); | 413 | e1->setValue((int)(view->doc()->wordWrapAt())); |
416 | #warning fixme e1->setLabel(i18n("Wrap Words At:")); | 414 | #warning fixme e1->setLabel(i18n("Wrap Words At:")); |
417 | 415 | ||
418 | e2 = new QSpinBox(this); | 416 | e2 = new QSpinBox(this); |
419 | e2->setMinValue(1); | 417 | e2->setMinValue(1); |
420 | e2->setMaxValue(16); | 418 | e2->setMaxValue(16); |
421 | e2->setValue((int)view->tabWidth()); | 419 | e2->setValue((int)view->tabWidth()); |
422 | 420 | ||
423 | #warning fixme e2->setLabel(i18n("Tab/Indent Width:")); | 421 | #warning fixme e2->setLabel(i18n("Tab/Indent Width:")); |
424 | 422 | ||
425 | e3 = new QSpinBox(this); | 423 | e3 = new QSpinBox(this); |
426 | e3->setMinValue(5); | 424 | e3->setMinValue(5); |
427 | e3->setMaxValue( 30000); | 425 | e3->setMaxValue( 30000); |
428 | #warning fixme e3->setLabel(i18n("Undo steps:")); | 426 | #warning fixme e3->setLabel(i18n("Undo steps:")); |
429 | e3->setValue((int)view->undoSteps()); | 427 | e3->setValue((int)view->undoSteps()); |
430 | 428 | ||
431 | leLayout->addWidget(e1, 0, AlignLeft); | 429 | leLayout->addWidget(e1, 0, AlignLeft); |
432 | leLayout->addWidget(e2, 0, AlignLeft); | 430 | leLayout->addWidget(e2, 0, AlignLeft); |
433 | leLayout->addWidget(e3, 0, AlignLeft); | 431 | leLayout->addWidget(e3, 0, AlignLeft); |
434 | 432 | ||
435 | 433 | ||
436 | QVBox *box = new QVBox (this); | 434 | QVBox *box = new QVBox (this); |
437 | leLayout->addWidget (box, 0, AlignLeft); | 435 | leLayout->addWidget (box, 0, AlignLeft); |
438 | 436 | ||
439 | new QLabel (i18n("Encoding:"), box); | 437 | new QLabel (i18n("Encoding:"), box); |
440 | 438 | ||
441 | encoding = new QComboBox(box); | 439 | encoding = new QComboBox(box); |
442 | #warning fixme | 440 | #warning fixme |
443 | #if 0 | 441 | #if 0 |
444 | encoding->insertStringList (KGlobal::charsets()->availableEncodingNames()); | 442 | encoding->insertStringList (KGlobal::charsets()->availableEncodingNames()); |
445 | encoding->setCurrentItem (KGlobal::charsets()->availableEncodingNames().findIndex(view->doc()->encoding())); | 443 | encoding->setCurrentItem (KGlobal::charsets()->availableEncodingNames().findIndex(view->doc()->encoding())); |
446 | #endif | 444 | #endif |
447 | leLayout->addStretch(); | 445 | leLayout->addStretch(); |
448 | 446 | ||
449 | // What is this? help | 447 | // What is this? help |
450 | QWhatsThis::add(opt[0], i18n("Word wrap is a feature that causes the editor to automatically start a new line of text and move (wrap) the cursor to the beginning of that new line. KateView will automatically start a new line of text when the current line reaches the length specified by the Wrap Words At: option.<p><b>NOTE:<b> Word Wrap will not change existing lines or wrap them for easy reading as in some applications.")); | 448 | QWhatsThis::add(opt[0], i18n("Word wrap is a feature that causes the editor to automatically start a new line of text and move (wrap) the cursor to the beginning of that new line. KateView will automatically start a new line of text when the current line reaches the length specified by the Wrap Words At: option.<p><b>NOTE:<b> Word Wrap will not change existing lines or wrap them for easy reading as in some applications.")); |
451 | QWhatsThis::add(e1, i18n("If the Word Wrap option is selected this entry determines the length (in characters) at which the editor will automatically start a new line.")); | 449 | QWhatsThis::add(e1, i18n("If the Word Wrap option is selected this entry determines the length (in characters) at which the editor will automatically start a new line.")); |
452 | QWhatsThis::add(opt[1], i18n("KateView will replace any tabs with the number of spaces indicated in the Tab Width: entry.")); | 450 | QWhatsThis::add(opt[1], i18n("KateView will replace any tabs with the number of spaces indicated in the Tab Width: entry.")); |
453 | QWhatsThis::add(e2, i18n("If the Replace Tabs By Spaces option is selected this entry determines the number of spaces with which the editor will automatically replace tabs.")); | 451 | QWhatsThis::add(e2, i18n("If the Replace Tabs By Spaces option is selected this entry determines the number of spaces with which the editor will automatically replace tabs.")); |
454 | QWhatsThis::add(opt[2], i18n("KateView will automatically eliminate extra spaces at the ends of lines of text.")); | 452 | QWhatsThis::add(opt[2], i18n("KateView will automatically eliminate extra spaces at the ends of lines of text.")); |
455 | QWhatsThis::add(opt[3], i18n("When the user types a left bracket ([,(, or {) KateView automatically enters the right bracket (}, ), or ]) to the right of the cursor.")); | 453 | QWhatsThis::add(opt[3], i18n("When the user types a left bracket ([,(, or {) KateView automatically enters the right bracket (}, ), or ]) to the right of the cursor.")); |
456 | QWhatsThis::add(opt[4], i18n("Checking this will cause sequences of similar actions to be undone at once.")); | 454 | QWhatsThis::add(opt[4], i18n("Checking this will cause sequences of similar actions to be undone at once.")); |
457 | QWhatsThis::add(opt[5], i18n("The editor will display a symbol to indicate the presence of a tab in the text.")); | 455 | QWhatsThis::add(opt[5], i18n("The editor will display a symbol to indicate the presence of a tab in the text.")); |
458 | QWhatsThis::add(opt[6], i18n("Not yet implemented.")); | 456 | QWhatsThis::add(opt[6], i18n("Not yet implemented.")); |
459 | QWhatsThis::add(opt[7], i18n("If this is selected, the insertion cursor will be moved to the first/last line when pressing the page up/down buttons.<p>If not selected, it will remain at it's relative position in the visible text.")); | 457 | QWhatsThis::add(opt[7], i18n("If this is selected, the insertion cursor will be moved to the first/last line when pressing the page up/down buttons.<p>If not selected, it will remain at it's relative position in the visible text.")); |
460 | QWhatsThis::add(e3, i18n("Sets the number of undo/redo steps to record. More steps uses more memory.")); | 458 | QWhatsThis::add(e3, i18n("Sets the number of undo/redo steps to record. More steps uses more memory.")); |
461 | QWhatsThis::add(opt[8], i18n("When on, moving the insertion cursor using the <b>Left</b> and <b>Right</b> keys will go on to previous/next line at beginning/end of the line, similar to most editors.<p>When off, the insertion cursor cannot be moved left of the line start, but it can be moved off the line end, which can be very handy for programmers.")); | 459 | QWhatsThis::add(opt[8], i18n("When on, moving the insertion cursor using the <b>Left</b> and <b>Right</b> keys will go on to previous/next line at beginning/end of the line, similar to most editors.<p>When off, the insertion cursor cannot be moved left of the line start, but it can be moved off the line end, which can be very handy for programmers.")); |
462 | } | 460 | } |
463 | 461 | ||
464 | void EditConfigTab::getData(KateView *view) | 462 | void EditConfigTab::getData(KateView *view) |
465 | { | 463 | { |
466 | int configFlags, z; | 464 | int configFlags, z; |
467 | 465 | ||
468 | configFlags = view->config(); | 466 | configFlags = view->config(); |
469 | for (z = 1; z < numFlags; z++) { | 467 | for (z = 1; z < numFlags; z++) { |
470 | configFlags &= ~flags[z]; | 468 | configFlags &= ~flags[z]; |
471 | if (opt[z]->isChecked()) configFlags |= flags[z]; | 469 | if (opt[z]->isChecked()) configFlags |= flags[z]; |
472 | } | 470 | } |
473 | view->setConfig(configFlags); | 471 | view->setConfig(configFlags); |
474 | 472 | ||
475 | view->setEncoding (encoding->currentText()); | 473 | view->setEncoding (encoding->currentText()); |
476 | view->doc()->setWordWrapAt(e1->value()); | 474 | view->doc()->setWordWrapAt(e1->value()); |
477 | view->doc()->setWordWrap (opt[0]->isChecked()); | 475 | view->doc()->setWordWrap (opt[0]->isChecked()); |
478 | view->setTabWidth(e2->value()); | 476 | view->setTabWidth(e2->value()); |
479 | view->setUndoSteps(e3->value()); | 477 | view->setUndoSteps(e3->value()); |
480 | } | 478 | } |
481 | 479 | ||
482 | ColorConfig::ColorConfig( QWidget *parent, char *name ) | 480 | ColorConfig::ColorConfig( QWidget *parent, char *name ) |
483 | : QWidget( parent, name ) | 481 | : QWidget( parent, name ) |
484 | { | 482 | { |
485 | QGridLayout *glay = new QGridLayout( this, 6, 2, 0, KDialog::spacingHint()); | 483 | QGridLayout *glay = new QGridLayout( this, 6, 2, 0, KDialog::spacingHint()); |
486 | glay->setColStretch(1,1); | 484 | glay->setColStretch(1,1); |
487 | glay->setRowStretch(5,1); | 485 | glay->setRowStretch(5,1); |
488 | 486 | ||
489 | QLabel *label; | 487 | QLabel *label; |
490 | 488 | ||
491 | label = new QLabel( i18n("Background:"), this); | 489 | label = new QLabel( i18n("Background:"), this); |
492 | label->setAlignment( AlignRight|AlignVCenter ); | 490 | label->setAlignment( AlignRight|AlignVCenter ); |
493 | m_back = new KColorButton( this ); | 491 | m_back = new KColorButton( this ); |
494 | glay->addWidget( label, 0, 0 ); | 492 | glay->addWidget( label, 0, 0 ); |
495 | glay->addWidget( m_back, 0, 1 ); | 493 | glay->addWidget( m_back, 0, 1 ); |
496 | 494 | ||
497 | label = new QLabel( i18n("Selected:"), this); | 495 | label = new QLabel( i18n("Selected:"), this); |
498 | label->setAlignment( AlignRight|AlignVCenter ); | 496 | label->setAlignment( AlignRight|AlignVCenter ); |
499 | m_selected = new KColorButton( this ); | 497 | m_selected = new KColorButton( this ); |
500 | glay->addWidget( label, 2, 0 ); | 498 | glay->addWidget( label, 2, 0 ); |
501 | glay->addWidget( m_selected, 2, 1 ); | 499 | glay->addWidget( m_selected, 2, 1 ); |
502 | 500 | ||
503 | // QWhatsThis help | 501 | // QWhatsThis help |
504 | QWhatsThis::add(m_back, i18n("Sets the background color of the editing area")); | 502 | QWhatsThis::add(m_back, i18n("Sets the background color of the editing area")); |
505 | QWhatsThis::add(m_selected, i18n("Sets the background color of the selection. To set the text color for selected text, use the "<b>Configure Highlighting</b>" dialog.")); | 503 | QWhatsThis::add(m_selected, i18n("Sets the background color of the selection. To set the text color for selected text, use the "<b>Configure Highlighting</b>" dialog.")); |
506 | } | 504 | } |
507 | 505 | ||
508 | 506 | ||
509 | ColorConfig::~ColorConfig() | 507 | ColorConfig::~ColorConfig() |
510 | { | 508 | { |
511 | } | 509 | } |
512 | 510 | ||
513 | void ColorConfig::setColors(QColor *colors) | 511 | void ColorConfig::setColors(QColor *colors) |
514 | { | 512 | { |
515 | m_back->setColor( colors[0] ); | 513 | m_back->setColor( colors[0] ); |
516 | m_selected->setColor( colors[1] ); | 514 | m_selected->setColor( colors[1] ); |
517 | } | 515 | } |
518 | 516 | ||
519 | void ColorConfig::getColors(QColor *colors) | 517 | void ColorConfig::getColors(QColor *colors) |
520 | { | 518 | { |
521 | colors[0] = m_back->color(); | 519 | colors[0] = m_back->color(); |
522 | colors[1] = m_selected->color(); | 520 | colors[1] = m_selected->color(); |
523 | } | 521 | } |
524 | 522 | ||
525 | FontConfig::FontConfig( QWidget *parent, char *name ) | 523 | FontConfig::FontConfig( QWidget *parent, char *name ) |
526 | : QWidget( parent, name ) | 524 | : QWidget( parent, name ) |
527 | { | 525 | { |
528 | // sizemanagment | 526 | // sizemanagment |
529 | QGridLayout *grid = new QGridLayout( this, 1, 1 ); | 527 | QGridLayout *grid = new QGridLayout( this, 1, 1 ); |
530 | // QString familyStr = cfg. readEntry ( "FontFamily", "Helvetica" ); | 528 | // QString familyStr = cfg. readEntry ( "FontFamily", "Helvetica" ); |
531 | // QString styleStr = cfg. readEntry ( "FontStyle", "Regular" ); | 529 | // QString styleStr = cfg. readEntry ( "FontStyle", "Regular" ); |
532 | // int size = cfg. readNumEntry ( "FontSize", 10 ); | 530 | // int size = cfg. readNumEntry ( "FontSize", 10 ); |
533 | // OFontSelector *m_fontselect; | 531 | // OFontSelector *m_fontselect; |
534 | 532 | ||
535 | m_fontselect = new Opie::OFontSelector ( false, this, "FontTab" ); | 533 | m_fontselect = new Opie::OFontSelector ( false, this, "FontTab" ); |
536 | // m_fontselect-> setSelectedFont ( familyStr, styleStr, size ); | 534 | // m_fontselect-> setSelectedFont ( familyStr, styleStr, size ); |
537 | // QWhatsThis::add( m_fontselect, | 535 | // QWhatsThis::add( m_fontselect, |
538 | // tr( "Select the desired name, style and size of the default font applications will use." ) ); | 536 | // tr( "Select the desired name, style and size of the default font applications will use." ) ); |
539 | 537 | ||
540 | connect( m_fontselect, SIGNAL( fontSelected ( const QFont & )), | 538 | connect( m_fontselect, SIGNAL( fontSelected ( const QFont & )), |
541 | this, SLOT( slotFontSelected( const QFont & ))); | 539 | this, SLOT( slotFontSelected( const QFont & ))); |
542 | grid->addWidget( m_fontselect, 0, 0); | 540 | grid->addWidget( m_fontselect, 0, 0); |
543 | 541 | ||
544 | 542 | ||
545 | // #if 0 | 543 | // #if 0 |
546 | // m_fontchooser = new KFontChooser ( this ); | 544 | // m_fontchooser = new KFontChooser ( this ); |
547 | // m_fontchooser->enableColumn(KFontChooser::StyleList, false); | 545 | // m_fontchooser->enableColumn(KFontChooser::StyleList, false); |
548 | // grid->addWidget( m_fontchooser, 0, 0); | 546 | // grid->addWidget( m_fontchooser, 0, 0); |
549 | 547 | ||
550 | // connect (m_fontchooser, SIGNAL (fontSelected( const QFont & )), this, SLOT (slotFontSelected( const QFont & ))); | 548 | // connect (m_fontchooser, SIGNAL (fontSelected( const QFont & )), this, SLOT (slotFontSelected( const QFont & ))); |
551 | // #endif | 549 | // #endif |
552 | } | 550 | } |
553 | 551 | ||
554 | FontConfig::~FontConfig() | 552 | FontConfig::~FontConfig() |
555 | { | 553 | { |
556 | } | 554 | } |
557 | 555 | ||
558 | void FontConfig::setFont ( const QFont &font ) | 556 | void FontConfig::setFont ( const QFont &font ) |
559 | { | 557 | { |
560 | //#if 0 | 558 | //#if 0 |
561 | m_fontselect->setFont (font); | 559 | m_fontselect->setFont (font); |
562 | myFont = font; | 560 | myFont = font; |
563 | //#endif | 561 | //#endif |
564 | } | 562 | } |
565 | 563 | ||
566 | void FontConfig::slotFontSelected( const QFont &font ) | 564 | void FontConfig::slotFontSelected( const QFont &font ) |
567 | { | 565 | { |
568 | myFont = font; | 566 | myFont = font; |
569 | } | 567 | } |
570 | 568 | ||
571 | 569 | ||
572 | 570 | ||
573 | 571 | ||
diff --git a/noncore/apps/tinykate/tinykate.cpp b/noncore/apps/tinykate/tinykate.cpp index bbf80ce..19a0127 100644 --- a/noncore/apps/tinykate/tinykate.cpp +++ b/noncore/apps/tinykate/tinykate.cpp | |||
@@ -1,283 +1,278 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | tinykate.cpp | 2 | tinykate.cpp |
3 | Tiny KATE mainwindow | 3 | Tiny KATE mainwindow |
4 | ------------------- | 4 | ------------------- |
5 | begin : November 2002 | 5 | begin : November 2002 |
6 | copyright : (C) 2002 by Joseph Wenninger <jowenn@kde.org> | 6 | copyright : (C) 2002 by Joseph Wenninger <jowenn@kde.org> |
7 | ***************************************************************************/ | 7 | ***************************************************************************/ |
8 | 8 | ||
9 | /*************************************************************************** | 9 | /*************************************************************************** |
10 | * * | 10 | * * |
11 | * This program is free softwaSre; you can redistribute it and/or modify * | 11 | * This program is free softwaSre; you can redistribute it and/or modify * |
12 | * it under the terms of the GNU General Public License as published by * | 12 | * it under the terms of the GNU General Public License as published by * |
13 | * the Free Software Foundation. * | 13 | * the Free Software Foundation. * |
14 | * ONLY VERSION 2 OF THE LICENSE IS APPLICABLE * | 14 | * ONLY VERSION 2 OF THE LICENSE IS APPLICABLE * |
15 | * * | 15 | * * |
16 | ***************************************************************************/ | 16 | ***************************************************************************/ |
17 | #include <qwidget.h> | ||
18 | #include <qaction.h> | 17 | #include <qaction.h> |
19 | #include <qlayout.h> | ||
20 | #include <qtoolbutton.h> | 18 | #include <qtoolbutton.h> |
21 | #include <qmenubar.h> | 19 | #include <qmenubar.h> |
22 | #include <qpe/resource.h> | 20 | #include <qpe/resource.h> |
23 | #include <qpe/global.h> | ||
24 | #include <qpe/qpeapplication.h> | 21 | #include <qpe/qpeapplication.h> |
25 | 22 | ||
26 | #include <opie2/ofiledialog.h> | 23 | #include <opie2/ofiledialog.h> |
27 | 24 | ||
28 | #include "tinykate.h" | 25 | #include "tinykate.h" |
29 | 26 | ||
30 | #include <katedocument.h> | 27 | #include <katedocument.h> |
31 | #include <katehighlight.h> | ||
32 | #include <kateview.h> | ||
33 | #include <kglobal.h> | 28 | #include <kglobal.h> |
34 | 29 | ||
35 | TinyKate::TinyKate( QWidget *parent, const char *name, WFlags f) : | 30 | TinyKate::TinyKate( QWidget *parent, const char *name, WFlags f) : |
36 | QMainWindow( parent, name, f ) | 31 | QMainWindow( parent, name, f ) |
37 | { | 32 | { |
38 | shutDown=false; | 33 | shutDown=false; |
39 | nextUnnamed=0; | 34 | nextUnnamed=0; |
40 | currentView=0; | 35 | currentView=0; |
41 | viewCount=0; | 36 | viewCount=0; |
42 | setCaption(tr("TinyKATE")); | 37 | setCaption(tr("TinyKATE")); |
43 | KGlobal::setAppName("TinyKATE"); | 38 | KGlobal::setAppName("TinyKATE"); |
44 | 39 | ||
45 | QMenuBar *mb = new QMenuBar( this ); | 40 | QMenuBar *mb = new QMenuBar( this ); |
46 | mb->setMargin( 0 ); | 41 | mb->setMargin( 0 ); |
47 | 42 | ||
48 | tabwidget=new OTabWidget(this); | 43 | tabwidget=new OTabWidget(this); |
49 | setCentralWidget(tabwidget); | 44 | setCentralWidget(tabwidget); |
50 | connect(tabwidget,SIGNAL(currentChanged( QWidget *)),this,SLOT(slotCurrentChanged(QWidget *))); | 45 | connect(tabwidget,SIGNAL(currentChanged( QWidget *)),this,SLOT(slotCurrentChanged(QWidget *))); |
51 | 46 | ||
52 | //FILE ACTIONS | 47 | //FILE ACTIONS |
53 | QPopupMenu *popup = new QPopupMenu( this ); | 48 | QPopupMenu *popup = new QPopupMenu( this ); |
54 | 49 | ||
55 | // Action for creating a new document | 50 | // Action for creating a new document |
56 | QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, 0, this, 0 ); | 51 | QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, 0, this, 0 ); |
57 | a->addTo( popup ); | 52 | a->addTo( popup ); |
58 | connect(a, SIGNAL(activated()), this, SLOT(slotNew())); | 53 | connect(a, SIGNAL(activated()), this, SLOT(slotNew())); |
59 | 54 | ||
60 | // Action for opening an exisiting document | 55 | // Action for opening an exisiting document |
61 | a = new QAction( tr( "Open" ),Resource::loadPixmap( "fileopen" ) , QString::null, 0, this, 0 ); | 56 | a = new QAction( tr( "Open" ),Resource::loadPixmap( "fileopen" ) , QString::null, 0, this, 0 ); |
62 | a->addTo(popup); | 57 | a->addTo(popup); |
63 | connect(a, SIGNAL(activated()), this, SLOT(slotOpen())); | 58 | connect(a, SIGNAL(activated()), this, SLOT(slotOpen())); |
64 | 59 | ||
65 | 60 | ||
66 | // Action for saving document | 61 | // Action for saving document |
67 | a = new QAction( tr( "Save" ), Resource::loadPixmap( "save" ) , QString::null, 0, this, 0 ); | 62 | a = new QAction( tr( "Save" ), Resource::loadPixmap( "save" ) , QString::null, 0, this, 0 ); |
68 | a->addTo(popup); | 63 | a->addTo(popup); |
69 | connect(a, SIGNAL(activated()), this, SLOT(slotSave())); | 64 | connect(a, SIGNAL(activated()), this, SLOT(slotSave())); |
70 | 65 | ||
71 | // Action for saving document to a new name | 66 | // Action for saving document to a new name |
72 | a = new QAction( tr( "Save As" ),Resource::loadPixmap( "save" ) , QString::null, 0, this, 0 ); | 67 | a = new QAction( tr( "Save As" ),Resource::loadPixmap( "save" ) , QString::null, 0, this, 0 ); |
73 | a->addTo(popup); | 68 | a->addTo(popup); |
74 | connect(a, SIGNAL(activated()), this, SLOT(slotSaveAs())); | 69 | connect(a, SIGNAL(activated()), this, SLOT(slotSaveAs())); |
75 | 70 | ||
76 | // Action for closing the currently active document | 71 | // Action for closing the currently active document |
77 | a = new QAction( tr( "Close" ), Resource::loadPixmap( "quit_icon" ) , QString::null, 0, this, 0 ); | 72 | a = new QAction( tr( "Close" ), Resource::loadPixmap( "quit_icon" ) , QString::null, 0, this, 0 ); |
78 | a->addTo(popup); | 73 | a->addTo(popup); |
79 | connect(a, SIGNAL(activated()), this, SLOT(slotClose())); | 74 | connect(a, SIGNAL(activated()), this, SLOT(slotClose())); |
80 | 75 | ||
81 | 76 | ||
82 | mb->insertItem(tr("File"),popup); | 77 | mb->insertItem(tr("File"),popup); |
83 | 78 | ||
84 | //EDIT ACTIONS | 79 | //EDIT ACTIONS |
85 | 80 | ||
86 | // Action for cutting text | 81 | // Action for cutting text |
87 | editCut = new QToolButton( 0 ); | 82 | editCut = new QToolButton( 0 ); |
88 | editCut->setAutoRaise( true ); | 83 | editCut->setAutoRaise( true ); |
89 | editCut->setIconSet( Resource::loadPixmap( "cut" ) ); | 84 | editCut->setIconSet( Resource::loadPixmap( "cut" ) ); |
90 | 85 | ||
91 | // Action for Copying text | 86 | // Action for Copying text |
92 | editCopy = new QToolButton( 0 ); | 87 | editCopy = new QToolButton( 0 ); |
93 | editCopy->setAutoRaise( true ); | 88 | editCopy->setAutoRaise( true ); |
94 | editCopy->setIconSet( Resource::loadPixmap( "copy" ) ); | 89 | editCopy->setIconSet( Resource::loadPixmap( "copy" ) ); |
95 | 90 | ||
96 | // Action for pasting text | 91 | // Action for pasting text |
97 | editPaste = new QToolButton( 0 ); | 92 | editPaste = new QToolButton( 0 ); |
98 | editPaste->setAutoRaise( true ); | 93 | editPaste->setAutoRaise( true ); |
99 | editPaste->setIconSet( Resource::loadPixmap( "paste" ) ); | 94 | editPaste->setIconSet( Resource::loadPixmap( "paste" ) ); |
100 | 95 | ||
101 | // Action for finding / replacing text | 96 | // Action for finding / replacing text |
102 | editFindReplace = new QToolButton( 0 ); | 97 | editFindReplace = new QToolButton( 0 ); |
103 | editFindReplace->setAutoRaise( true ); | 98 | editFindReplace->setAutoRaise( true ); |
104 | editFindReplace->setIconSet( Resource::loadPixmap("find") ); | 99 | editFindReplace->setIconSet( Resource::loadPixmap("find") ); |
105 | 100 | ||
106 | // Action for undo | 101 | // Action for undo |
107 | editUndo = new QToolButton( 0 ); | 102 | editUndo = new QToolButton( 0 ); |
108 | editUndo->setAutoRaise( true ); | 103 | editUndo->setAutoRaise( true ); |
109 | editUndo->setIconSet( Resource::loadPixmap( "undo" ) ); | 104 | editUndo->setIconSet( Resource::loadPixmap( "undo" ) ); |
110 | 105 | ||
111 | // Action for redo | 106 | // Action for redo |
112 | editRedo = new QToolButton( 0 ); | 107 | editRedo = new QToolButton( 0 ); |
113 | editRedo->setAutoRaise( true ); | 108 | editRedo->setAutoRaise( true ); |
114 | editRedo->setIconSet( Resource::loadPixmap( "redo" ) ); | 109 | editRedo->setIconSet( Resource::loadPixmap( "redo" ) ); |
115 | 110 | ||
116 | //VIEW ACITONS | 111 | //VIEW ACITONS |
117 | popup = new QPopupMenu( this ); | 112 | popup = new QPopupMenu( this ); |
118 | 113 | ||
119 | viewIncFontSizes = new QAction( tr( "Font +" ), QString::null, 0, this, 0 ); | 114 | viewIncFontSizes = new QAction( tr( "Font +" ), QString::null, 0, this, 0 ); |
120 | viewIncFontSizes->addTo( popup ); | 115 | viewIncFontSizes->addTo( popup ); |
121 | 116 | ||
122 | viewDecFontSizes = new QAction( tr( "Font -" ), QString::null, 0, this, 0 ); | 117 | viewDecFontSizes = new QAction( tr( "Font -" ), QString::null, 0, this, 0 ); |
123 | viewDecFontSizes->addTo( popup ); | 118 | viewDecFontSizes->addTo( popup ); |
124 | 119 | ||
125 | mb->insertItem(tr("View"),popup); | 120 | mb->insertItem(tr("View"),popup); |
126 | 121 | ||
127 | popup = new QPopupMenu( this ); | 122 | popup = new QPopupMenu( this ); |
128 | mb->insertItem(tr("Utils"),popup); | 123 | mb->insertItem(tr("Utils"),popup); |
129 | 124 | ||
130 | 125 | ||
131 | mb->insertItem( editCut ); | 126 | mb->insertItem( editCut ); |
132 | mb->insertItem( editCopy ); | 127 | mb->insertItem( editCopy ); |
133 | mb->insertItem( editPaste ); | 128 | mb->insertItem( editPaste ); |
134 | mb->insertItem( editFindReplace ); | 129 | mb->insertItem( editFindReplace ); |
135 | mb->insertItem( editUndo ); | 130 | mb->insertItem( editUndo ); |
136 | mb->insertItem( editRedo ); | 131 | mb->insertItem( editRedo ); |
137 | 132 | ||
138 | 133 | ||
139 | //Highlight management | 134 | //Highlight management |
140 | hlmenu=new QPopupMenu(this); | 135 | hlmenu=new QPopupMenu(this); |
141 | HlManager *hlm=HlManager::self(); | 136 | HlManager *hlm=HlManager::self(); |
142 | for (int i=0;i<hlm->highlights();i++) | 137 | for (int i=0;i<hlm->highlights();i++) |
143 | { | 138 | { |
144 | hlmenu->insertItem(hlm->hlName(i),i); | 139 | hlmenu->insertItem(hlm->hlName(i),i); |
145 | } | 140 | } |
146 | popup->insertItem(tr("Highlighting"),hlmenu); | 141 | popup->insertItem(tr("Highlighting"),hlmenu); |
147 | 142 | ||
148 | 143 | ||
149 | utilSettings = new QAction( tr( "Settings" ), QString::null, 0, this, 0 ); | 144 | utilSettings = new QAction( tr( "Settings" ), QString::null, 0, this, 0 ); |
150 | utilSettings->addTo( popup); | 145 | utilSettings->addTo( popup); |
151 | 146 | ||
152 | if( qApp->argc() > 1) open(qApp->argv()[1]); | 147 | if( qApp->argc() > 1) open(qApp->argv()[1]); |
153 | else slotNew(); | 148 | else slotNew(); |
154 | 149 | ||
155 | } | 150 | } |
156 | 151 | ||
157 | TinyKate::~TinyKate( ) | 152 | TinyKate::~TinyKate( ) |
158 | { | 153 | { |
159 | qWarning("TinyKate destructor\n"); | 154 | qWarning("TinyKate destructor\n"); |
160 | 155 | ||
161 | shutDown=true; | 156 | shutDown=true; |
162 | while (currentView!=0) { | 157 | while (currentView!=0) { |
163 | slotClose(); | 158 | slotClose(); |
164 | } | 159 | } |
165 | 160 | ||
166 | if( KGlobal::config() != 0 ) { | 161 | if( KGlobal::config() != 0 ) { |
167 | qWarning("deleting KateConfig object..\n"); | 162 | qWarning("deleting KateConfig object..\n"); |
168 | delete KGlobal::config(); | 163 | delete KGlobal::config(); |
169 | } | 164 | } |
170 | } | 165 | } |
171 | 166 | ||
172 | void TinyKate::slotOpen( ) | 167 | void TinyKate::slotOpen( ) |
173 | { | 168 | { |
174 | QString filename = Opie::OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL, | 169 | QString filename = Opie::OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL, |
175 | QString::null); | 170 | QString::null); |
176 | if (!filename.isEmpty()) { | 171 | if (!filename.isEmpty()) { |
177 | open(filename); | 172 | open(filename); |
178 | } | 173 | } |
179 | } | 174 | } |
180 | 175 | ||
181 | void TinyKate::open(const QString & filename) | 176 | void TinyKate::open(const QString & filename) |
182 | { | 177 | { |
183 | KateDocument *kd= new KateDocument(false, false, this,0,this); | 178 | KateDocument *kd= new KateDocument(false, false, this,0,this); |
184 | KTextEditor::View *kv; | 179 | KTextEditor::View *kv; |
185 | QFileInfo fi(filename); | 180 | QFileInfo fi(filename); |
186 | QString filenamed = fi.fileName(); | 181 | QString filenamed = fi.fileName(); |
187 | tabwidget->addTab(kv=kd->createView(tabwidget,"bLAH"),"tinykate/tinykate", filenamed ); | 182 | tabwidget->addTab(kv=kd->createView(tabwidget,"bLAH"),"tinykate/tinykate", filenamed ); |
188 | qDebug(filename); | 183 | qDebug(filename); |
189 | 184 | ||
190 | kd->setDocName( filenamed); | 185 | kd->setDocName( filenamed); |
191 | kd->open( filename ); | 186 | kd->open( filename ); |
192 | viewCount++; | 187 | viewCount++; |
193 | } | 188 | } |
194 | 189 | ||
195 | void TinyKate::setDocument(const QString& fileref) | 190 | void TinyKate::setDocument(const QString& fileref) |
196 | { | 191 | { |
197 | open( fileref ); | 192 | open( fileref ); |
198 | } | 193 | } |
199 | 194 | ||
200 | void TinyKate::slotCurrentChanged( QWidget * view) | 195 | void TinyKate::slotCurrentChanged( QWidget * view) |
201 | { | 196 | { |
202 | if (currentView) { | 197 | if (currentView) { |
203 | 198 | ||
204 | disconnect(editCopy,SIGNAL(activated()),currentView,SLOT(copy())); | 199 | disconnect(editCopy,SIGNAL(activated()),currentView,SLOT(copy())); |
205 | disconnect(editCut,SIGNAL(activated()),currentView,SLOT(cut())); | 200 | disconnect(editCut,SIGNAL(activated()),currentView,SLOT(cut())); |
206 | disconnect(editPaste,SIGNAL(activated()),currentView,SLOT(paste())); | 201 | disconnect(editPaste,SIGNAL(activated()),currentView,SLOT(paste())); |
207 | disconnect(editUndo,SIGNAL(activated()),currentView,SLOT(undo())); | 202 | disconnect(editUndo,SIGNAL(activated()),currentView,SLOT(undo())); |
208 | disconnect(editRedo,SIGNAL(activated()),currentView,SLOT(redo())); | 203 | disconnect(editRedo,SIGNAL(activated()),currentView,SLOT(redo())); |
209 | disconnect(viewIncFontSizes,SIGNAL(activated()), currentView,SLOT(slotIncFontSizes())); | 204 | disconnect(viewIncFontSizes,SIGNAL(activated()), currentView,SLOT(slotIncFontSizes())); |
210 | disconnect(viewDecFontSizes,SIGNAL(activated()), currentView,SLOT(slotDecFontSizes())); | 205 | disconnect(viewDecFontSizes,SIGNAL(activated()), currentView,SLOT(slotDecFontSizes())); |
211 | disconnect(hlmenu,SIGNAL(activated(int)), currentView,SLOT(setHl(int))); | 206 | disconnect(hlmenu,SIGNAL(activated(int)), currentView,SLOT(setHl(int))); |
212 | disconnect(utilSettings,SIGNAL(activated()), currentView,SLOT(configDialog())); | 207 | disconnect(utilSettings,SIGNAL(activated()), currentView,SLOT(configDialog())); |
213 | } | 208 | } |
214 | 209 | ||
215 | currentView=(KTextEditor::View*)view; | 210 | currentView=(KTextEditor::View*)view; |
216 | 211 | ||
217 | connect(editCopy,SIGNAL(clicked()),currentView,SLOT(copy())); | 212 | connect(editCopy,SIGNAL(clicked()),currentView,SLOT(copy())); |
218 | connect(editCut,SIGNAL(clicked()),currentView,SLOT(cut())); | 213 | connect(editCut,SIGNAL(clicked()),currentView,SLOT(cut())); |
219 | connect(editPaste,SIGNAL(clicked()),currentView,SLOT(paste())); | 214 | connect(editPaste,SIGNAL(clicked()),currentView,SLOT(paste())); |
220 | connect(editUndo,SIGNAL(clicked()),currentView,SLOT(undo())); | 215 | connect(editUndo,SIGNAL(clicked()),currentView,SLOT(undo())); |
221 | connect(editRedo,SIGNAL(clicked()),currentView,SLOT(redo())); | 216 | connect(editRedo,SIGNAL(clicked()),currentView,SLOT(redo())); |
222 | connect(viewIncFontSizes,SIGNAL(activated()), currentView,SLOT(slotIncFontSizes())); | 217 | connect(viewIncFontSizes,SIGNAL(activated()), currentView,SLOT(slotIncFontSizes())); |
223 | connect(viewDecFontSizes,SIGNAL(activated()), currentView,SLOT(slotDecFontSizes())); | 218 | connect(viewDecFontSizes,SIGNAL(activated()), currentView,SLOT(slotDecFontSizes())); |
224 | connect(hlmenu,SIGNAL(activated(int)), currentView,SLOT(setHl(int))); | 219 | connect(hlmenu,SIGNAL(activated(int)), currentView,SLOT(setHl(int))); |
225 | connect(utilSettings,SIGNAL(activated()), currentView,SLOT(configDialog())); | 220 | connect(utilSettings,SIGNAL(activated()), currentView,SLOT(configDialog())); |
226 | 221 | ||
227 | } | 222 | } |
228 | 223 | ||
229 | void TinyKate::slotNew( ) | 224 | void TinyKate::slotNew( ) |
230 | { | 225 | { |
231 | KateDocument *kd= new KateDocument(false, false, this,0,this); | 226 | KateDocument *kd= new KateDocument(false, false, this,0,this); |
232 | KTextEditor::View *kv; | 227 | KTextEditor::View *kv; |
233 | tabwidget->addTab(kv=kd->createView(tabwidget,"BLAH"), | 228 | tabwidget->addTab(kv=kd->createView(tabwidget,"BLAH"), |
234 | "tinykate/tinykate", | 229 | "tinykate/tinykate", |
235 | tr("Unnamed %1").arg(nextUnnamed++)); | 230 | tr("Unnamed %1").arg(nextUnnamed++)); |
236 | viewCount++; | 231 | viewCount++; |
237 | } | 232 | } |
238 | 233 | ||
239 | void TinyKate::slotClose( ) | 234 | void TinyKate::slotClose( ) |
240 | { | 235 | { |
241 | if (currentView==0) return; | 236 | if (currentView==0) return; |
242 | KTextEditor::View *dv=currentView; | 237 | KTextEditor::View *dv=currentView; |
243 | currentView=0; | 238 | currentView=0; |
244 | tabwidget->removePage(dv); | 239 | tabwidget->removePage(dv); |
245 | delete dv->document(); | 240 | delete dv->document(); |
246 | viewCount--; | 241 | viewCount--; |
247 | if ((!viewCount) && (!shutDown)) slotNew(); | 242 | if ((!viewCount) && (!shutDown)) slotNew(); |
248 | } | 243 | } |
249 | 244 | ||
250 | void TinyKate::slotSave() { | 245 | void TinyKate::slotSave() { |
251 | // feel free to make this how you want | 246 | // feel free to make this how you want |
252 | if (currentView==0) return; | 247 | if (currentView==0) return; |
253 | 248 | ||
254 | // KateView *kv = (KateView*) currentView; | 249 | // KateView *kv = (KateView*) currentView; |
255 | KateDocument *kd = (KateDocument*) currentView->document(); | 250 | KateDocument *kd = (KateDocument*) currentView->document(); |
256 | // qDebug("saving file "+kd->docName()); | 251 | // qDebug("saving file "+kd->docName()); |
257 | if( kd->docName().isEmpty()) | 252 | if( kd->docName().isEmpty()) |
258 | slotSaveAs(); | 253 | slotSaveAs(); |
259 | else | 254 | else |
260 | kd->saveFile(); | 255 | kd->saveFile(); |
261 | // kv->save(); | 256 | // kv->save(); |
262 | // kd->saveFile(); | 257 | // kd->saveFile(); |
263 | } | 258 | } |
264 | 259 | ||
265 | void TinyKate::slotSaveAs() { | 260 | void TinyKate::slotSaveAs() { |
266 | if (currentView==0) return; | 261 | if (currentView==0) return; |
267 | KateDocument *kd = (KateDocument*) currentView->document(); | 262 | KateDocument *kd = (KateDocument*) currentView->document(); |
268 | 263 | ||
269 | QString filename= Opie::OFileDialog::getSaveFileName(OFileSelector::EXTENDED_ALL, | 264 | QString filename= Opie::OFileDialog::getSaveFileName(OFileSelector::EXTENDED_ALL, |
270 | QString::null); | 265 | QString::null); |
271 | if (!filename.isEmpty()) { | 266 | if (!filename.isEmpty()) { |
272 | qDebug("saving file "+filename); | 267 | qDebug("saving file "+filename); |
273 | QFileInfo fi(filename); | 268 | QFileInfo fi(filename); |
274 | QString filenamed = fi.fileName(); | 269 | QString filenamed = fi.fileName(); |
275 | kd->setDocFile( filename); | 270 | kd->setDocFile( filename); |
276 | kd->setDocName( filenamed); | 271 | kd->setDocName( filenamed); |
277 | kd->saveFile(); | 272 | kd->saveFile(); |
278 | // KTextEditor::View *dv = currentView; | 273 | // KTextEditor::View *dv = currentView; |
279 | // tabwidget->changeTab( dv, filenamed); | 274 | // tabwidget->changeTab( dv, filenamed); |
280 | // need to change tab label here | 275 | // need to change tab label here |
281 | } | 276 | } |
282 | 277 | ||
283 | } | 278 | } |
diff --git a/noncore/apps/zsafe/category.cpp b/noncore/apps/zsafe/category.cpp index ce1d614..15448f0 100644 --- a/noncore/apps/zsafe/category.cpp +++ b/noncore/apps/zsafe/category.cpp | |||
@@ -1,63 +1,62 @@ | |||
1 | /* C implementation of RC2 encryption algorithm, as described in RFC2268 */ | 1 | /* C implementation of RC2 encryption algorithm, as described in RFC2268 */ |
2 | /* By Matthew Palmer <mjp16@uow.edu.au> */ | 2 | /* By Matthew Palmer <mjp16@uow.edu.au> */ |
3 | /* $Id$ */ | 3 | /* $Id$ */ |
4 | 4 | ||
5 | #include "category.h" | 5 | #include "category.h" |
6 | #include <qlistview.h> | ||
7 | 6 | ||
8 | Category::Category() | 7 | Category::Category() |
9 | { | 8 | { |
10 | } | 9 | } |
11 | 10 | ||
12 | Category::~Category() | 11 | Category::~Category() |
13 | { | 12 | { |
14 | } | 13 | } |
15 | 14 | ||
16 | QString Category::getIconName() | 15 | QString Category::getIconName() |
17 | { | 16 | { |
18 | return iconName; | 17 | return iconName; |
19 | } | 18 | } |
20 | 19 | ||
21 | QString Category::getCategoryName() | 20 | QString Category::getCategoryName() |
22 | { | 21 | { |
23 | return categoryName; | 22 | return categoryName; |
24 | } | 23 | } |
25 | 24 | ||
26 | QListViewItem * Category::getListItem() | 25 | QListViewItem * Category::getListItem() |
27 | { | 26 | { |
28 | return listItem; | 27 | return listItem; |
29 | } | 28 | } |
30 | 29 | ||
31 | QPixmap Category::getIcon() | 30 | QPixmap Category::getIcon() |
32 | { | 31 | { |
33 | return icon; | 32 | return icon; |
34 | } | 33 | } |
35 | 34 | ||
36 | void Category::setIconName(QString name) | 35 | void Category::setIconName(QString name) |
37 | { | 36 | { |
38 | iconName = name; | 37 | iconName = name; |
39 | } | 38 | } |
40 | 39 | ||
41 | void Category::setCategoryName(QString name) | 40 | void Category::setCategoryName(QString name) |
42 | { | 41 | { |
43 | categoryName = name; | 42 | categoryName = name; |
44 | } | 43 | } |
45 | 44 | ||
46 | void Category::setListItem(QListViewItem *item) | 45 | void Category::setListItem(QListViewItem *item) |
47 | { | 46 | { |
48 | listItem = item; | 47 | listItem = item; |
49 | } | 48 | } |
50 | 49 | ||
51 | void Category::setIcon(QPixmap item) | 50 | void Category::setIcon(QPixmap item) |
52 | { | 51 | { |
53 | icon = item; | 52 | icon = item; |
54 | } | 53 | } |
55 | 54 | ||
56 | void Category::initListItem() | 55 | void Category::initListItem() |
57 | { | 56 | { |
58 | if (listItem) | 57 | if (listItem) |
59 | { | 58 | { |
60 | listItem->setText (0, categoryName); | 59 | listItem->setText (0, categoryName); |
61 | listItem->setPixmap (0, icon); | 60 | listItem->setPixmap (0, icon); |
62 | } | 61 | } |
63 | } | 62 | } |
diff --git a/noncore/apps/zsafe/main.cpp b/noncore/apps/zsafe/main.cpp index 7ff549b..4fe319b 100644 --- a/noncore/apps/zsafe/main.cpp +++ b/noncore/apps/zsafe/main.cpp | |||
@@ -1,112 +1,111 @@ | |||
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 | #ifdef DESKTOP | 11 | #ifdef DESKTOP |
12 | #include <qapplication.h> | 12 | #include <qapplication.h> |
13 | #else | 13 | #else |
14 | #include <qpe/qpeapplication.h> | 14 | #include <qpe/qpeapplication.h> |
15 | #endif | 15 | #endif |
16 | #include <stdio.h> | 16 | #include <stdio.h> |
17 | #include <signal.h> | 17 | #include <signal.h> |
18 | #include "qsettings.h" | ||
19 | 18 | ||
20 | ZSafe *zs; | 19 | ZSafe *zs; |
21 | #ifdef DESKTOP | 20 | #ifdef DESKTOP |
22 | QApplication *appl; | 21 | QApplication *appl; |
23 | #else | 22 | #else |
24 | QPEApplication *appl; | 23 | QPEApplication *appl; |
25 | #endif | 24 | #endif |
26 | 25 | ||
27 | int DeskW; | 26 | int DeskW; |
28 | int DeskH; | 27 | int DeskH; |
29 | 28 | ||
30 | void suspend (int signum) | 29 | void suspend (int signum) |
31 | { | 30 | { |
32 | printf ("Suspend signal %d received\n", signum); | 31 | printf ("Suspend signal %d received\n", signum); |
33 | } | 32 | } |
34 | 33 | ||
35 | void resume (int signum) | 34 | void resume (int signum) |
36 | { | 35 | { |
37 | printf ("Resume signal %d received\n", signum); | 36 | printf ("Resume signal %d received\n", signum); |
38 | zs->resume(signum); | 37 | zs->resume(signum); |
39 | } | 38 | } |
40 | 39 | ||
41 | int main( int argc, char ** argv ) | 40 | int main( int argc, char ** argv ) |
42 | { | 41 | { |
43 | #ifndef WIN32 | 42 | #ifndef WIN32 |
44 | // install signal handler | 43 | // install signal handler |
45 | signal (SIGSTOP, suspend); | 44 | signal (SIGSTOP, suspend); |
46 | #endif | 45 | #endif |
47 | 46 | ||
48 | #ifdef DESKTOP | 47 | #ifdef DESKTOP |
49 | QApplication a( argc, argv ); | 48 | QApplication a( argc, argv ); |
50 | #else | 49 | #else |
51 | QPEApplication a( argc, argv ); | 50 | QPEApplication a( argc, argv ); |
52 | #endif | 51 | #endif |
53 | appl = &a; | 52 | appl = &a; |
54 | 53 | ||
55 | #ifdef DESKTOP | 54 | #ifdef DESKTOP |
56 | if (argc >= 3) | 55 | if (argc >= 3) |
57 | { | 56 | { |
58 | #ifndef WIN32 | 57 | #ifndef WIN32 |
59 | DeskW = atoi(argv[1]); | 58 | DeskW = atoi(argv[1]); |
60 | DeskH = atoi(argv[2]); | 59 | DeskH = atoi(argv[2]); |
61 | #else | 60 | #else |
62 | int w, h; | 61 | int w, h; |
63 | sscanf (argv[1], "%d", &w); | 62 | sscanf (argv[1], "%d", &w); |
64 | sscanf (argv[2], "%d", &h); | 63 | sscanf (argv[2], "%d", &h); |
65 | DeskW = w; | 64 | DeskW = w; |
66 | DeskH = h; | 65 | DeskH = h; |
67 | #endif | 66 | #endif |
68 | } | 67 | } |
69 | else | 68 | else |
70 | { | 69 | { |
71 | DeskW = 600; | 70 | DeskW = 600; |
72 | DeskH = 400; | 71 | DeskH = 400; |
73 | } | 72 | } |
74 | #else | 73 | #else |
75 | DeskW = a.desktop()->width(); | 74 | DeskW = a.desktop()->width(); |
76 | DeskH = a.desktop()->height(); | 75 | DeskH = a.desktop()->height(); |
77 | 76 | ||
78 | char buf[128]; | 77 | char buf[128]; |
79 | sprintf (buf, "Width: %d Height: %d\n", DeskW, DeskH); | 78 | sprintf (buf, "Width: %d Height: %d\n", DeskW, DeskH); |
80 | qWarning (buf); | 79 | qWarning (buf); |
81 | 80 | ||
82 | #ifdef JPATCH_HDE | 81 | #ifdef JPATCH_HDE |
83 | // nothings | 82 | // nothings |
84 | #else | 83 | #else |
85 | if (DeskW > 240) | 84 | if (DeskW > 240) |
86 | { | 85 | { |
87 | DeskW -= 20; | 86 | DeskW -= 20; |
88 | DeskH += 25; | 87 | DeskH += 25; |
89 | sprintf (buf, "Changed width: %d Height: %d\n", DeskW, DeskH); | 88 | sprintf (buf, "Changed width: %d Height: %d\n", DeskW, DeskH); |
90 | qWarning (buf); | 89 | qWarning (buf); |
91 | } | 90 | } |
92 | #endif | 91 | #endif |
93 | 92 | ||
94 | #endif | 93 | #endif |
95 | 94 | ||
96 | ZSafe mw; | 95 | ZSafe mw; |
97 | zs = &mw; | 96 | zs = &mw; |
98 | 97 | ||
99 | #ifndef WIN32 | 98 | #ifndef WIN32 |
100 | signal (SIGCONT, resume); | 99 | signal (SIGCONT, resume); |
101 | #endif | 100 | #endif |
102 | #ifdef DESKTOP | 101 | #ifdef DESKTOP |
103 | a.setMainWidget(&mw); | 102 | a.setMainWidget(&mw); |
104 | mw.show(); | 103 | mw.show(); |
105 | #else | 104 | #else |
106 | // a.showMainWidget( &mw ); | 105 | // a.showMainWidget( &mw ); |
107 | a.showMainDocumentWidget( &mw ); | 106 | a.showMainDocumentWidget( &mw ); |
108 | #endif | 107 | #endif |
109 | int ret = a.exec(); | 108 | int ret = a.exec(); |
110 | 109 | ||
111 | return ret; | 110 | return ret; |
112 | } | 111 | } |
diff --git a/noncore/apps/zsafe/qsettings.cpp b/noncore/apps/zsafe/qsettings.cpp index 62a9947..ee55339 100755 --- a/noncore/apps/zsafe/qsettings.cpp +++ b/noncore/apps/zsafe/qsettings.cpp | |||
@@ -1,153 +1,152 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id$ | 2 | ** $Id$ |
3 | */ | 3 | */ |
4 | 4 | ||
5 | #include "qsettings.h" | 5 | #include "qsettings.h" |
6 | #include <qstringlist.h> | ||
7 | #include <stdio.h> | 6 | #include <stdio.h> |
8 | #include <qfile.h> | 7 | #include <qfile.h> |
9 | #include <qtextstream.h> | 8 | #include <qtextstream.h> |
10 | 9 | ||
11 | 10 | ||
12 | QSettings::QSettings(const QString &_fn) | 11 | QSettings::QSettings(const QString &_fn) |
13 | { | 12 | { |
14 | // read the prefs from the file | 13 | // read the prefs from the file |
15 | fn = _fn; | 14 | fn = _fn; |
16 | 15 | ||
17 | QFile f(_fn); | 16 | QFile f(_fn); |
18 | if ( f.open(IO_ReadOnly) ) { // file opened successfully | 17 | if ( f.open(IO_ReadOnly) ) { // file opened successfully |
19 | QTextStream t( &f ); // use a text stream | 18 | QTextStream t( &f ); // use a text stream |
20 | QString s; | 19 | QString s; |
21 | while ( !t.eof() ) { // until end of file... | 20 | while ( !t.eof() ) { // until end of file... |
22 | s = t.readLine(); // line of text excluding '\n' | 21 | s = t.readLine(); // line of text excluding '\n' |
23 | char buf[256]; | 22 | char buf[256]; |
24 | sprintf (buf, "%s", (const char *) s); | 23 | sprintf (buf, "%s", (const char *) s); |
25 | int pos = s.find (" = "); | 24 | int pos = s.find (" = "); |
26 | QString key = s.left (pos); | 25 | QString key = s.left (pos); |
27 | QString val = s.right (s.length() - pos - 3); | 26 | QString val = s.right (s.length() - pos - 3); |
28 | writeEntry (key, val); | 27 | writeEntry (key, val); |
29 | 28 | ||
30 | sprintf (buf, "%s|%s", (const char *)key, (const char *)val); | 29 | sprintf (buf, "%s|%s", (const char *)key, (const char *)val); |
31 | } | 30 | } |
32 | f.close(); | 31 | f.close(); |
33 | } | 32 | } |
34 | 33 | ||
35 | 34 | ||
36 | } | 35 | } |
37 | 36 | ||
38 | QSettings::~QSettings() | 37 | QSettings::~QSettings() |
39 | { | 38 | { |
40 | // write out the prefs to the file | 39 | // write out the prefs to the file |
41 | QAsciiDictIterator <QString> it( prefs ); // iterator for dict | 40 | QAsciiDictIterator <QString> it( prefs ); // iterator for dict |
42 | QFile f(fn); | 41 | QFile f(fn); |
43 | f.open(IO_WriteOnly); | 42 | f.open(IO_WriteOnly); |
44 | QTextStream ts( &f ); | 43 | QTextStream ts( &f ); |
45 | 44 | ||
46 | while ( it.current() ) | 45 | while ( it.current() ) |
47 | { | 46 | { |
48 | QString *key = new QString(it.currentKey()); | 47 | QString *key = new QString(it.currentKey()); |
49 | char buf[256]; | 48 | char buf[256]; |
50 | sprintf (buf, "%s", (const char *) *( it.current())); | 49 | sprintf (buf, "%s", (const char *) *( it.current())); |
51 | QString *val = new QString(buf); | 50 | QString *val = new QString(buf); |
52 | sprintf (buf, "%s %s", (const char *)*key, (const char *)*val); | 51 | sprintf (buf, "%s %s", (const char *)*key, (const char *)*val); |
53 | ts << *key << " = " << *val << endl; | 52 | ts << *key << " = " << *val << endl; |
54 | ++it; | 53 | ++it; |
55 | } | 54 | } |
56 | 55 | ||
57 | f.close(); | 56 | f.close(); |
58 | prefs.clear(); | 57 | prefs.clear(); |
59 | } | 58 | } |
60 | 59 | ||
61 | void QSettings::insertSearchPath (System sys, const QString &str) | 60 | void QSettings::insertSearchPath (System sys, const QString &str) |
62 | { | 61 | { |
63 | fn = str; | 62 | fn = str; |
64 | } | 63 | } |
65 | 64 | ||
66 | QString QSettings::readEntry (const QString &key, const QString &def) | 65 | QString QSettings::readEntry (const QString &key, const QString &def) |
67 | { | 66 | { |
68 | 67 | ||
69 | QString *s = prefs.find((const char *)key); | 68 | QString *s = prefs.find((const char *)key); |
70 | if (!s) | 69 | if (!s) |
71 | return def; | 70 | return def; |
72 | else | 71 | else |
73 | return *s; | 72 | return *s; |
74 | 73 | ||
75 | } | 74 | } |
76 | 75 | ||
77 | int QSettings::readNumEntry (const QString &key, int def) | 76 | int QSettings::readNumEntry (const QString &key, int def) |
78 | { | 77 | { |
79 | QString *s = prefs[key]; | 78 | QString *s = prefs[key]; |
80 | if (!s) return def; | 79 | if (!s) return def; |
81 | return s->toInt(); | 80 | return s->toInt(); |
82 | } | 81 | } |
83 | 82 | ||
84 | bool QSettings::readBoolEntry (const QString &key, bool def) | 83 | bool QSettings::readBoolEntry (const QString &key, bool def) |
85 | { | 84 | { |
86 | QString *s = prefs[key]; | 85 | QString *s = prefs[key]; |
87 | if (!s) return def; | 86 | if (!s) return def; |
88 | if (*s == "1") | 87 | if (*s == "1") |
89 | return true; | 88 | return true; |
90 | else | 89 | else |
91 | return false; | 90 | return false; |
92 | } | 91 | } |
93 | 92 | ||
94 | bool QSettings::writeEntry (const QString &key, int val) | 93 | bool QSettings::writeEntry (const QString &key, int val) |
95 | { | 94 | { |
96 | char buf[64]; | 95 | char buf[64]; |
97 | sprintf (buf, "%d", val); | 96 | sprintf (buf, "%d", val); |
98 | QString *v = new QString(buf); | 97 | QString *v = new QString(buf); |
99 | prefs.replace ((const char *)key, v); | 98 | prefs.replace ((const char *)key, v); |
100 | return true; | 99 | return true; |
101 | } | 100 | } |
102 | 101 | ||
103 | bool QSettings::writeEntry (const QString &key, bool val) | 102 | bool QSettings::writeEntry (const QString &key, bool val) |
104 | { | 103 | { |
105 | QString *v; | 104 | QString *v; |
106 | if (val) | 105 | if (val) |
107 | v = new QString("1"); | 106 | v = new QString("1"); |
108 | else | 107 | else |
109 | v = new QString("0"); | 108 | v = new QString("0"); |
110 | prefs.replace ((const char *)key, v); | 109 | prefs.replace ((const char *)key, v); |
111 | return true; | 110 | return true; |
112 | } | 111 | } |
113 | 112 | ||
114 | bool QSettings::writeEntry (const QString &key, const QString &val) | 113 | bool QSettings::writeEntry (const QString &key, const QString &val) |
115 | { | 114 | { |
116 | QString *v = new QString (val); | 115 | QString *v = new QString (val); |
117 | prefs.replace ((const char *)key, v); | 116 | prefs.replace ((const char *)key, v); |
118 | return true; | 117 | return true; |
119 | } | 118 | } |
120 | 119 | ||
121 | bool QSettings::writeEntry (const QString &key, const char *val) | 120 | bool QSettings::writeEntry (const QString &key, const char *val) |
122 | { | 121 | { |
123 | QString *v = new QString (val); | 122 | QString *v = new QString (val); |
124 | prefs.replace ((const char *)key, v); | 123 | prefs.replace ((const char *)key, v); |
125 | return true; | 124 | return true; |
126 | } | 125 | } |
127 | 126 | ||
128 | bool QSettings::removeEntry (const QString &key) | 127 | bool QSettings::removeEntry (const QString &key) |
129 | { | 128 | { |
130 | prefs.remove (key); | 129 | prefs.remove (key); |
131 | return true; | 130 | return true; |
132 | } | 131 | } |
133 | 132 | ||
134 | QStringList QSettings::entryList (const QString &key) const | 133 | QStringList QSettings::entryList (const QString &key) const |
135 | { | 134 | { |
136 | QAsciiDictIterator <QString> it( prefs ); // iterator for dict | 135 | QAsciiDictIterator <QString> it( prefs ); // iterator for dict |
137 | QStringList list; | 136 | QStringList list; |
138 | 137 | ||
139 | while ( it.current() ) | 138 | while ( it.current() ) |
140 | { | 139 | { |
141 | char buf[512]; | 140 | char buf[512]; |
142 | sprintf (buf, "%s", (const char *) *( it.current())); | 141 | sprintf (buf, "%s", (const char *) *( it.current())); |
143 | QString *val = new QString(buf); | 142 | QString *val = new QString(buf); |
144 | sprintf(buf, "%s -> %s\n", it.currentKey(), (const char *)*val ); | 143 | sprintf(buf, "%s -> %s\n", it.currentKey(), (const char *)*val ); |
145 | QString *cat = new QString(it.currentKey()); | 144 | QString *cat = new QString(it.currentKey()); |
146 | if (cat->contains("-field", FALSE)) | 145 | if (cat->contains("-field", FALSE)) |
147 | list.append (it.currentKey()); | 146 | list.append (it.currentKey()); |
148 | ++it; | 147 | ++it; |
149 | 148 | ||
150 | } | 149 | } |
151 | return list; | 150 | return list; |
152 | } | 151 | } |
153 | 152 | ||
diff --git a/noncore/apps/zsafe/scqtfiledlg.cpp b/noncore/apps/zsafe/scqtfiledlg.cpp index d6cea64..dd72fdf 100644 --- a/noncore/apps/zsafe/scqtfiledlg.cpp +++ b/noncore/apps/zsafe/scqtfiledlg.cpp | |||
@@ -1,261 +1,256 @@ | |||
1 | /**************************************************************************** | 1 | /**************************************************************************** |
2 | ** Form implementation generated from reading ui file 'scqtfiledlg.ui' | 2 | ** Form implementation generated from reading ui file 'scqtfiledlg.ui' |
3 | ** | 3 | ** |
4 | ** Created: Sun Jun 8 15:51:12 2003 | 4 | ** Created: Sun Jun 8 15:51:12 2003 |
5 | ** by: The User Interface Compiler (uic) | 5 | ** by: The User Interface Compiler (uic) |
6 | ** | 6 | ** |
7 | ** WARNING! All changes made in this file will be lost! | 7 | ** WARNING! All changes made in this file will be lost! |
8 | ****************************************************************************/ | 8 | ****************************************************************************/ |
9 | #include "scqtfiledlg.h" | 9 | #include "scqtfiledlg.h" |
10 | 10 | ||
11 | #include <qcombobox.h> | 11 | #include <qcombobox.h> |
12 | #include <qheader.h> | ||
13 | #include <qlineedit.h> | 12 | #include <qlineedit.h> |
14 | #include <qlistview.h> | 13 | #include <qlistview.h> |
15 | #include <qpushbutton.h> | ||
16 | #include <qtoolbutton.h> | 14 | #include <qtoolbutton.h> |
17 | #include <qlayout.h> | 15 | #include <qlayout.h> |
18 | #include <qvariant.h> | ||
19 | #include <qtooltip.h> | 16 | #include <qtooltip.h> |
20 | #include <qwhatsthis.h> | 17 | #include <qwhatsthis.h> |
21 | #include <qimage.h> | ||
22 | #include <qpixmap.h> | ||
23 | 18 | ||
24 | static const char* const image0_data[] = { | 19 | static const char* const image0_data[] = { |
25 | "24 16 3 1", | 20 | "24 16 3 1", |
26 | ". c None", | 21 | ". c None", |
27 | "# c #000040", | 22 | "# c #000040", |
28 | "a c #808080", | 23 | "a c #808080", |
29 | "........................", | 24 | "........................", |
30 | "........................", | 25 | "........................", |
31 | ".................####...", | 26 | ".................####...", |
32 | ".................####...", | 27 | ".................####...", |
33 | ".......##........#aa#...", | 28 | ".......##........#aa#...", |
34 | "......###........#aa#...", | 29 | "......###........#aa#...", |
35 | ".....####........#aa#...", | 30 | ".....####........#aa#...", |
36 | "....##############aa#...", | 31 | "....##############aa#...", |
37 | "...###aaaaaaaaaaaaaa#...", | 32 | "...###aaaaaaaaaaaaaa#...", |
38 | "..####aaaaaaaaaaaaaa#...", | 33 | "..####aaaaaaaaaaaaaa#...", |
39 | "...###aaaaaaaaaaaaaa#...", | 34 | "...###aaaaaaaaaaaaaa#...", |
40 | "....#################...", | 35 | "....#################...", |
41 | ".....####...............", | 36 | ".....####...............", |
42 | "......###...............", | 37 | "......###...............", |
43 | ".......##...............", | 38 | ".......##...............", |
44 | "........................"}; | 39 | "........................"}; |
45 | 40 | ||
46 | static const char* const image1_data[] = { | 41 | static const char* const image1_data[] = { |
47 | "24 16 4 1", | 42 | "24 16 4 1", |
48 | ". c None", | 43 | ". c None", |
49 | "a c #008080", | 44 | "a c #008080", |
50 | "b c #808080", | 45 | "b c #808080", |
51 | "# c #ff0000", | 46 | "# c #ff0000", |
52 | "........................", | 47 | "........................", |
53 | "........................", | 48 | "........................", |
54 | "...####..........####...", | 49 | "...####..........####...", |
55 | "...#####........#####...", | 50 | "...#####........#####...", |
56 | "....######.....#####a...", | 51 | "....######.....#####a...", |
57 | ".....######...#####ba...", | 52 | ".....######...#####ba...", |
58 | ".....aa###########bba...", | 53 | ".....aa###########bba...", |
59 | "....aaaaa#######aabba...", | 54 | "....aaaaa#######aabba...", |
60 | "...aaabbb######bbbbba...", | 55 | "...aaabbb######bbbbba...", |
61 | "..aaaabb########bbbba...", | 56 | "..aaaabb########bbbba...", |
62 | "...aaa############bba...", | 57 | "...aaa############bba...", |
63 | "....a######aaa#####aa...", | 58 | "....a######aaa#####aa...", |
64 | "....######.....######...", | 59 | "....######.....######...", |
65 | "...#####a........####...", | 60 | "...#####a........####...", |
66 | "...####aa.........###...", | 61 | "...####aa.........###...", |
67 | "........................"}; | 62 | "........................"}; |
68 | 63 | ||
69 | static const char* const image2_data[] = { | 64 | static const char* const image2_data[] = { |
70 | "17 15 4 1", | 65 | "17 15 4 1", |
71 | "# c #000000", | 66 | "# c #000000", |
72 | ". c #dcdcdc", | 67 | ". c #dcdcdc", |
73 | "a c #ffff00", | 68 | "a c #ffff00", |
74 | "b c #ffffff", | 69 | "b c #ffffff", |
75 | ".................", | 70 | ".................", |
76 | "............#....", | 71 | "............#....", |
77 | ".................", | 72 | ".................", |
78 | "............#....", | 73 | "............#....", |
79 | ".........#.....#.", | 74 | ".........#.....#.", |
80 | "....####..#.#.#..", | 75 | "....####..#.#.#..", |
81 | "...#abab#..#.#...", | 76 | "...#abab#..#.#...", |
82 | "..##########..#.#", | 77 | "..##########..#.#", |
83 | "..#babababab##...", | 78 | "..#babababab##...", |
84 | "..#ababababa#.#..", | 79 | "..#ababababa#.#..", |
85 | "..#babababab#..#.", | 80 | "..#babababab#..#.", |
86 | "..#ababababa#....", | 81 | "..#ababababa#....", |
87 | "..#babababab#....", | 82 | "..#babababab#....", |
88 | "..#ababababa#....", | 83 | "..#ababababa#....", |
89 | "..###########...."}; | 84 | "..###########...."}; |
90 | 85 | ||
91 | 86 | ||
92 | /* | 87 | /* |
93 | * Constructs a ScQtFileDlg which is a child of 'parent', with the | 88 | * Constructs a ScQtFileDlg which is a child of 'parent', with the |
94 | * name 'name' and widget flags set to 'f' | 89 | * name 'name' and widget flags set to 'f' |
95 | * | 90 | * |
96 | * The dialog will by default be modeless, unless you set 'modal' to | 91 | * The dialog will by default be modeless, unless you set 'modal' to |
97 | * TRUE to construct a modal dialog. | 92 | * TRUE to construct a modal dialog. |
98 | */ | 93 | */ |
99 | ScQtFileDlg::ScQtFileDlg( QWidget* parent, const char* name, bool modal, WFlags fl ) | 94 | ScQtFileDlg::ScQtFileDlg( QWidget* parent, const char* name, bool modal, WFlags fl ) |
100 | : QDialog( parent, name, modal, fl ) | 95 | : QDialog( parent, name, modal, fl ) |
101 | { | 96 | { |
102 | QPixmap image0( ( const char** ) image0_data ); | 97 | QPixmap image0( ( const char** ) image0_data ); |
103 | QPixmap image1( ( const char** ) image1_data ); | 98 | QPixmap image1( ( const char** ) image1_data ); |
104 | QPixmap image2( ( const char** ) image2_data ); | 99 | QPixmap image2( ( const char** ) image2_data ); |
105 | if ( !name ) | 100 | if ( !name ) |
106 | setName( "ScQtFileDlg" ); | 101 | setName( "ScQtFileDlg" ); |
107 | resize( 196, 279 ); | 102 | resize( 196, 279 ); |
108 | if (!name) | 103 | if (!name) |
109 | setCaption( tr( "FileDlg" ) ); | 104 | setCaption( tr( "FileDlg" ) ); |
110 | else | 105 | else |
111 | setCaption(name); | 106 | setCaption(name); |
112 | ScQtFileDlgLayout = new QVBoxLayout( this ); | 107 | ScQtFileDlgLayout = new QVBoxLayout( this ); |
113 | ScQtFileDlgLayout->setSpacing( 6 ); | 108 | ScQtFileDlgLayout->setSpacing( 6 ); |
114 | ScQtFileDlgLayout->setMargin( 11 ); | 109 | ScQtFileDlgLayout->setMargin( 11 ); |
115 | 110 | ||
116 | Layout5 = new QVBoxLayout; | 111 | Layout5 = new QVBoxLayout; |
117 | Layout5->setSpacing( 6 ); | 112 | Layout5->setSpacing( 6 ); |
118 | Layout5->setMargin( 0 ); | 113 | Layout5->setMargin( 0 ); |
119 | 114 | ||
120 | Layout4 = new QVBoxLayout; | 115 | Layout4 = new QVBoxLayout; |
121 | Layout4->setSpacing( 6 ); | 116 | Layout4->setSpacing( 6 ); |
122 | Layout4->setMargin( 0 ); | 117 | Layout4->setMargin( 0 ); |
123 | 118 | ||
124 | Layout3 = new QHBoxLayout; | 119 | Layout3 = new QHBoxLayout; |
125 | Layout3->setSpacing( 6 ); | 120 | Layout3->setSpacing( 6 ); |
126 | Layout3->setMargin( 0 ); | 121 | Layout3->setMargin( 0 ); |
127 | 122 | ||
128 | TypeComboBox = new QComboBox( FALSE, this, "TypeComboBox" ); | 123 | TypeComboBox = new QComboBox( FALSE, this, "TypeComboBox" ); |
129 | TypeComboBox->setEditable( TRUE ); | 124 | TypeComboBox->setEditable( TRUE ); |
130 | TypeComboBox->setInsertionPolicy( QComboBox::AtBottom ); | 125 | TypeComboBox->setInsertionPolicy( QComboBox::AtBottom ); |
131 | TypeComboBox->setAutoCompletion( FALSE ); | 126 | TypeComboBox->setAutoCompletion( FALSE ); |
132 | TypeComboBox->setDuplicatesEnabled( FALSE ); | 127 | TypeComboBox->setDuplicatesEnabled( FALSE ); |
133 | QToolTip::add( TypeComboBox, tr( "file type filter" ) ); | 128 | QToolTip::add( TypeComboBox, tr( "file type filter" ) ); |
134 | QWhatsThis::add( TypeComboBox, tr( "ComboBox FileTypeFilter\n" | 129 | QWhatsThis::add( TypeComboBox, tr( "ComboBox FileTypeFilter\n" |
135 | "\n" | 130 | "\n" |
136 | "edit or select the filter" ) ); | 131 | "edit or select the filter" ) ); |
137 | Layout3->addWidget( TypeComboBox ); | 132 | Layout3->addWidget( TypeComboBox ); |
138 | QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ); | 133 | QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ); |
139 | Layout3->addItem( spacer ); | 134 | Layout3->addItem( spacer ); |
140 | 135 | ||
141 | OkButton = new QToolButton( this, "OkButton" ); | 136 | OkButton = new QToolButton( this, "OkButton" ); |
142 | OkButton->setText( tr( "" ) ); | 137 | OkButton->setText( tr( "" ) ); |
143 | OkButton->setPixmap( image0 ); | 138 | OkButton->setPixmap( image0 ); |
144 | OkButton->setUsesBigPixmap( FALSE ); | 139 | OkButton->setUsesBigPixmap( FALSE ); |
145 | QToolTip::add( OkButton, tr( "confirms the selection and closes the form" ) ); | 140 | QToolTip::add( OkButton, tr( "confirms the selection and closes the form" ) ); |
146 | QWhatsThis::add( OkButton, tr( "OKButton" ) ); | 141 | QWhatsThis::add( OkButton, tr( "OKButton" ) ); |
147 | Layout3->addWidget( OkButton ); | 142 | Layout3->addWidget( OkButton ); |
148 | 143 | ||
149 | CancelButton = new QToolButton( this, "CancelButton" ); | 144 | CancelButton = new QToolButton( this, "CancelButton" ); |
150 | CancelButton->setText( tr( "" ) ); | 145 | CancelButton->setText( tr( "" ) ); |
151 | CancelButton->setPixmap( image1 ); | 146 | CancelButton->setPixmap( image1 ); |
152 | CancelButton->setUsesBigPixmap( FALSE ); | 147 | CancelButton->setUsesBigPixmap( FALSE ); |
153 | QToolTip::add( CancelButton, tr( "cancels the selection and closes the form" ) ); | 148 | QToolTip::add( CancelButton, tr( "cancels the selection and closes the form" ) ); |
154 | QWhatsThis::add( CancelButton, tr( "CancelButton" ) ); | 149 | QWhatsThis::add( CancelButton, tr( "CancelButton" ) ); |
155 | Layout3->addWidget( CancelButton ); | 150 | Layout3->addWidget( CancelButton ); |
156 | Layout4->addLayout( Layout3 ); | 151 | Layout4->addLayout( Layout3 ); |
157 | 152 | ||
158 | Layout3_2 = new QHBoxLayout; | 153 | Layout3_2 = new QHBoxLayout; |
159 | Layout3_2->setSpacing( 6 ); | 154 | Layout3_2->setSpacing( 6 ); |
160 | Layout3_2->setMargin( 0 ); | 155 | Layout3_2->setMargin( 0 ); |
161 | 156 | ||
162 | FNameLineEdit = new QLineEdit( this, "FNameLineEdit" ); | 157 | FNameLineEdit = new QLineEdit( this, "FNameLineEdit" ); |
163 | QToolTip::add( FNameLineEdit, tr( "shows the selected filename" ) ); | 158 | QToolTip::add( FNameLineEdit, tr( "shows the selected filename" ) ); |
164 | QWhatsThis::add( FNameLineEdit, tr( "Filename LineEdit\n" | 159 | QWhatsThis::add( FNameLineEdit, tr( "Filename LineEdit\n" |
165 | "\n" | 160 | "\n" |
166 | "shows the selected file\n" | 161 | "shows the selected file\n" |
167 | "and allows the direct filename\n" | 162 | "and allows the direct filename\n" |
168 | "edit" ) ); | 163 | "edit" ) ); |
169 | Layout3_2->addWidget( FNameLineEdit ); | 164 | Layout3_2->addWidget( FNameLineEdit ); |
170 | 165 | ||
171 | MkDirButton = new QToolButton( this, "MkDirButton" ); | 166 | MkDirButton = new QToolButton( this, "MkDirButton" ); |
172 | MkDirButton->setText( tr( "" ) ); | 167 | MkDirButton->setText( tr( "" ) ); |
173 | MkDirButton->setPixmap( image2 ); | 168 | MkDirButton->setPixmap( image2 ); |
174 | MkDirButton->setUsesBigPixmap( FALSE ); | 169 | MkDirButton->setUsesBigPixmap( FALSE ); |
175 | QToolTip::add( MkDirButton, tr( "confirms the selection and closes the form" ) ); | 170 | QToolTip::add( MkDirButton, tr( "confirms the selection and closes the form" ) ); |
176 | QWhatsThis::add( MkDirButton, tr( "OKButton" ) ); | 171 | QWhatsThis::add( MkDirButton, tr( "OKButton" ) ); |
177 | Layout3_2->addWidget( MkDirButton ); | 172 | Layout3_2->addWidget( MkDirButton ); |
178 | Layout4->addLayout( Layout3_2 ); | 173 | Layout4->addLayout( Layout3_2 ); |
179 | 174 | ||
180 | DirComboBox = new QComboBox( FALSE, this, "DirComboBox" ); | 175 | DirComboBox = new QComboBox( FALSE, this, "DirComboBox" ); |
181 | DirComboBox->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)7, (QSizePolicy::SizeType)0, DirComboBox->sizePolicy().hasHeightForWidth() ) ); | 176 | DirComboBox->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)7, (QSizePolicy::SizeType)0, DirComboBox->sizePolicy().hasHeightForWidth() ) ); |
182 | DirComboBox->setEditable( TRUE ); | 177 | DirComboBox->setEditable( TRUE ); |
183 | DirComboBox->setDuplicatesEnabled( FALSE ); | 178 | DirComboBox->setDuplicatesEnabled( FALSE ); |
184 | QWhatsThis::add( DirComboBox, tr( "ComboBox Directory \n" | 179 | QWhatsThis::add( DirComboBox, tr( "ComboBox Directory \n" |
185 | "edit or select the directories name" ) ); | 180 | "edit or select the directories name" ) ); |
186 | Layout4->addWidget( DirComboBox ); | 181 | Layout4->addWidget( DirComboBox ); |
187 | Layout5->addLayout( Layout4 ); | 182 | Layout5->addLayout( Layout4 ); |
188 | 183 | ||
189 | ListView = new QListView( this, "ListView" ); | 184 | ListView = new QListView( this, "ListView" ); |
190 | ListView->addColumn( tr( "Name" ) ); | 185 | ListView->addColumn( tr( "Name" ) ); |
191 | ListView->addColumn( tr( "size" ) ); | 186 | ListView->addColumn( tr( "size" ) ); |
192 | ListView->addColumn( tr( "type" ) ); | 187 | ListView->addColumn( tr( "type" ) ); |
193 | ListView->setRootIsDecorated( TRUE ); | 188 | ListView->setRootIsDecorated( TRUE ); |
194 | QToolTip::add( ListView, tr( "directory listview" ) ); | 189 | QToolTip::add( ListView, tr( "directory listview" ) ); |
195 | QWhatsThis::add( ListView, tr( "Directory ListView\n" | 190 | QWhatsThis::add( ListView, tr( "Directory ListView\n" |
196 | "\n" | 191 | "\n" |
197 | "shows the list of dirs and files" ) ); | 192 | "shows the list of dirs and files" ) ); |
198 | Layout5->addWidget( ListView ); | 193 | Layout5->addWidget( ListView ); |
199 | ScQtFileDlgLayout->addLayout( Layout5 ); | 194 | ScQtFileDlgLayout->addLayout( Layout5 ); |
200 | 195 | ||
201 | // signals and slots connections | 196 | // signals and slots connections |
202 | connect( OkButton, SIGNAL( clicked() ), this, SLOT( slotOK() ) ); | 197 | connect( OkButton, SIGNAL( clicked() ), this, SLOT( slotOK() ) ); |
203 | connect( DirComboBox, SIGNAL( activated(int) ), this, SLOT( slotDirComboBoxChanged( int ) ) ); | 198 | connect( DirComboBox, SIGNAL( activated(int) ), this, SLOT( slotDirComboBoxChanged( int ) ) ); |
204 | connect( TypeComboBox, SIGNAL( activated(int) ), this, SLOT( slotTypeComboBoxChanged( int ) ) ); | 199 | connect( TypeComboBox, SIGNAL( activated(int) ), this, SLOT( slotTypeComboBoxChanged( int ) ) ); |
205 | connect( CancelButton, SIGNAL( clicked() ), this, SLOT( slotCancel() ) ); | 200 | connect( CancelButton, SIGNAL( clicked() ), this, SLOT( slotCancel() ) ); |
206 | connect( ListView, SIGNAL( returnPressed(QListViewItem*) ), this, SLOT( slotSelectionChanged(QListViewItem *) ) ); | 201 | connect( ListView, SIGNAL( returnPressed(QListViewItem*) ), this, SLOT( slotSelectionChanged(QListViewItem *) ) ); |
207 | connect( ListView, SIGNAL( selectionChanged(QListViewItem*) ), this, SLOT( slotSelectionChanged(QListViewItem *) ) ); | 202 | connect( ListView, SIGNAL( selectionChanged(QListViewItem*) ), this, SLOT( slotSelectionChanged(QListViewItem *) ) ); |
208 | connect( ListView, SIGNAL( doubleClicked(QListViewItem*) ), this, SLOT( slotDoubleClicked(QListViewItem *) ) ); | 203 | connect( ListView, SIGNAL( doubleClicked(QListViewItem*) ), this, SLOT( slotDoubleClicked(QListViewItem *) ) ); |
209 | connect( FNameLineEdit, SIGNAL( textChanged(const QString&) ), this, SLOT( slotFileTextChanged( const QString & ) ) ); | 204 | connect( FNameLineEdit, SIGNAL( textChanged(const QString&) ), this, SLOT( slotFileTextChanged( const QString & ) ) ); |
210 | connect( FNameLineEdit, SIGNAL( returnPressed() ), this, SLOT( slotOK() ) ); | 205 | connect( FNameLineEdit, SIGNAL( returnPressed() ), this, SLOT( slotOK() ) ); |
211 | connect( MkDirButton, SIGNAL( clicked() ), this, SLOT( slotMkDir() ) ); | 206 | connect( MkDirButton, SIGNAL( clicked() ), this, SLOT( slotMkDir() ) ); |
212 | } | 207 | } |
213 | 208 | ||
214 | /* | 209 | /* |
215 | * Destroys the object and frees any allocated resources | 210 | * Destroys the object and frees any allocated resources |
216 | */ | 211 | */ |
217 | ScQtFileDlg::~ScQtFileDlg() | 212 | ScQtFileDlg::~ScQtFileDlg() |
218 | { | 213 | { |
219 | // no need to delete child widgets, Qt does it all for us | 214 | // no need to delete child widgets, Qt does it all for us |
220 | } | 215 | } |
221 | 216 | ||
222 | void ScQtFileDlg::slotCancel() | 217 | void ScQtFileDlg::slotCancel() |
223 | { | 218 | { |
224 | qWarning( "ScQtFileDlg::slotCancel(): Not implemented yet!" ); | 219 | qWarning( "ScQtFileDlg::slotCancel(): Not implemented yet!" ); |
225 | } | 220 | } |
226 | 221 | ||
227 | void ScQtFileDlg::slotDirComboBoxChanged( int ) | 222 | void ScQtFileDlg::slotDirComboBoxChanged( int ) |
228 | { | 223 | { |
229 | qWarning( "ScQtFileDlg::slotDirComboBoxChanged( int ): Not implemented yet!" ); | 224 | qWarning( "ScQtFileDlg::slotDirComboBoxChanged( int ): Not implemented yet!" ); |
230 | } | 225 | } |
231 | 226 | ||
232 | void ScQtFileDlg::slotDoubleClicked(QListViewItem *) | 227 | void ScQtFileDlg::slotDoubleClicked(QListViewItem *) |
233 | { | 228 | { |
234 | qWarning( "ScQtFileDlg::slotDoubleClicked(QListViewItem *): Not implemented yet!" ); | 229 | qWarning( "ScQtFileDlg::slotDoubleClicked(QListViewItem *): Not implemented yet!" ); |
235 | } | 230 | } |
236 | 231 | ||
237 | void ScQtFileDlg::slotFileTextChanged( const QString & ) | 232 | void ScQtFileDlg::slotFileTextChanged( const QString & ) |
238 | { | 233 | { |
239 | qWarning( "ScQtFileDlg::slotFileTextChanged( const QString & ): Not implemented yet!" ); | 234 | qWarning( "ScQtFileDlg::slotFileTextChanged( const QString & ): Not implemented yet!" ); |
240 | } | 235 | } |
241 | 236 | ||
242 | void ScQtFileDlg::slotMkDir() | 237 | void ScQtFileDlg::slotMkDir() |
243 | { | 238 | { |
244 | qWarning( "ScQtFileDlg::slotMkDir(): Not implemented yet!" ); | 239 | qWarning( "ScQtFileDlg::slotMkDir(): Not implemented yet!" ); |
245 | } | 240 | } |
246 | 241 | ||
247 | void ScQtFileDlg::slotOK() | 242 | void ScQtFileDlg::slotOK() |
248 | { | 243 | { |
249 | qWarning( "ScQtFileDlg::slotOK(): Not implemented yet!" ); | 244 | qWarning( "ScQtFileDlg::slotOK(): Not implemented yet!" ); |
250 | } | 245 | } |
251 | 246 | ||
252 | void ScQtFileDlg::slotSelectionChanged(QListViewItem *) | 247 | void ScQtFileDlg::slotSelectionChanged(QListViewItem *) |
253 | { | 248 | { |
254 | qWarning( "ScQtFileDlg::slotSelectionChanged(QListViewItem *): Not implemented yet!" ); | 249 | qWarning( "ScQtFileDlg::slotSelectionChanged(QListViewItem *): Not implemented yet!" ); |
255 | } | 250 | } |
256 | 251 | ||
257 | void ScQtFileDlg::slotTypeComboBoxChanged( int ) | 252 | void ScQtFileDlg::slotTypeComboBoxChanged( int ) |
258 | { | 253 | { |
259 | qWarning( "ScQtFileDlg::slotTypeComboBoxChanged( int ): Not implemented yet!" ); | 254 | qWarning( "ScQtFileDlg::slotTypeComboBoxChanged( int ): Not implemented yet!" ); |
260 | } | 255 | } |
261 | 256 | ||
diff --git a/noncore/apps/zsafe/scqtfileedit.cpp b/noncore/apps/zsafe/scqtfileedit.cpp index 7a3d906..08fc2b5 100644 --- a/noncore/apps/zsafe/scqtfileedit.cpp +++ b/noncore/apps/zsafe/scqtfileedit.cpp | |||
@@ -1,758 +1,754 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | scqtfileedit.cpp - description | 2 | scqtfileedit.cpp - description |
3 | ------------------- | 3 | ------------------- |
4 | begin : Mon Sep 3 2001 | 4 | begin : Mon Sep 3 2001 |
5 | copyright : (C) 2001 by Werner Schulte | 5 | copyright : (C) 2001 by Werner Schulte |
6 | email : sc@schulte-ac.de | 6 | email : sc@schulte-ac.de |
7 | ***************************************************************************/ | 7 | ***************************************************************************/ |
8 | 8 | ||
9 | /* $Id$ */ | 9 | /* $Id$ */ |
10 | 10 | ||
11 | /*************************************************************************** | 11 | /*************************************************************************** |
12 | * * | 12 | * * |
13 | * This program is free software; you can redistribute it and/or modify * | 13 | * This program is free software; you can redistribute it and/or modify * |
14 | * it under the terms of the GNU General Public License as published by * | 14 | * it under the terms of the GNU General Public License as published by * |
15 | * the Free Software Foundation; either version 2 of the License, or * | 15 | * the Free Software Foundation; either version 2 of the License, or * |
16 | * (at your option) any later version. * | 16 | * (at your option) any later version. * |
17 | * * | 17 | * * |
18 | ***************************************************************************/ | 18 | ***************************************************************************/ |
19 | #include <stdio.h> | 19 | #include <stdio.h> |
20 | #include <stdlib.h> | 20 | #include <stdlib.h> |
21 | 21 | ||
22 | #include "qdir.h" | ||
23 | #include "qdialog.h" | ||
24 | #include "qpixmap.h" | ||
25 | #include "qlistview.h" | ||
26 | #include "qlineedit.h" | 22 | #include "qlineedit.h" |
27 | #include "qtoolbutton.h" | 23 | #include "qtoolbutton.h" |
28 | 24 | ||
29 | #include "scqtfileedit.h" | 25 | #include "scqtfileedit.h" |
30 | 26 | ||
31 | #include <qpe/qpeapplication.h> | 27 | #include <qpe/qpeapplication.h> |
32 | 28 | ||
33 | // #define DEBUGFILEEDIT | 29 | // #define DEBUGFILEEDIT |
34 | 30 | ||
35 | /* XPM */ | 31 | /* XPM */ |
36 | static const char* const file_xpm[]={ | 32 | static const char* const file_xpm[]={ |
37 | "16 16 5 1", | 33 | "16 16 5 1", |
38 | ". c #7f7f7f", | 34 | ". c #7f7f7f", |
39 | "# c None", | 35 | "# c None", |
40 | "c c #000000", | 36 | "c c #000000", |
41 | "b c #bfbfbf", | 37 | "b c #bfbfbf", |
42 | "a c #ffffff", | 38 | "a c #ffffff", |
43 | "################", | 39 | "################", |
44 | "..........######", | 40 | "..........######", |
45 | ".aaaaaaaab.#####", | 41 | ".aaaaaaaab.#####", |
46 | ".aaaaaaaaba.####", | 42 | ".aaaaaaaaba.####", |
47 | ".aaaaaaaacccc###", | 43 | ".aaaaaaaacccc###", |
48 | ".aaaaaaaaaabc###", | 44 | ".aaaaaaaaaabc###", |
49 | ".aaaaaaaaaabc###", | 45 | ".aaaaaaaaaabc###", |
50 | ".aaaaaaaaaabc###", | 46 | ".aaaaaaaaaabc###", |
51 | ".aaaaaaaaaabc###", | 47 | ".aaaaaaaaaabc###", |
52 | ".aaaaaaaaaabc###", | 48 | ".aaaaaaaaaabc###", |
53 | ".aaaaaaaaaabc###", | 49 | ".aaaaaaaaaabc###", |
54 | ".aaaaaaaaaabc###", | 50 | ".aaaaaaaaaabc###", |
55 | ".aaaaaaaaaabc###", | 51 | ".aaaaaaaaaabc###", |
56 | ".aaaaaaaaaabc###", | 52 | ".aaaaaaaaaabc###", |
57 | ".bbbbbbbbbbbc###", | 53 | ".bbbbbbbbbbbc###", |
58 | "ccccccccccccc###"}; | 54 | "ccccccccccccc###"}; |
59 | 55 | ||
60 | /* XPM */ | 56 | /* XPM */ |
61 | static const char * const link_file_xpm[]={ | 57 | static const char * const link_file_xpm[]={ |
62 | "16 16 10 1", | 58 | "16 16 10 1", |
63 | "h c #808080", | 59 | "h c #808080", |
64 | "g c #a0a0a0", | 60 | "g c #a0a0a0", |
65 | "d c #c3c3c3", | 61 | "d c #c3c3c3", |
66 | ". c #7f7f7f", | 62 | ". c #7f7f7f", |
67 | "c c #000000", | 63 | "c c #000000", |
68 | "b c #bfbfbf", | 64 | "b c #bfbfbf", |
69 | "f c #303030", | 65 | "f c #303030", |
70 | "e c #585858", | 66 | "e c #585858", |
71 | "a c #ffffff", | 67 | "a c #ffffff", |
72 | "# c None", | 68 | "# c None", |
73 | "################", | 69 | "################", |
74 | "..........######", | 70 | "..........######", |
75 | ".aaaaaaaab.#####", | 71 | ".aaaaaaaab.#####", |
76 | ".aaaaaaaaba.####", | 72 | ".aaaaaaaaba.####", |
77 | ".aaaaaaaacccc###", | 73 | ".aaaaaaaacccc###", |
78 | ".aaaaaaaaaabc###", | 74 | ".aaaaaaaaaabc###", |
79 | ".aaaaaaaaaabc###", | 75 | ".aaaaaaaaaabc###", |
80 | ".aaaaaaaaaadc###", | 76 | ".aaaaaaaaaadc###", |
81 | ".aaaaaaaaaadc###", | 77 | ".aaaaaaaaaadc###", |
82 | ".aaaacccccccc###", | 78 | ".aaaacccccccc###", |
83 | ".aaaacaaaaaac###", | 79 | ".aaaacaaaaaac###", |
84 | ".aaaacaeaeaac###", | 80 | ".aaaacaeaeaac###", |
85 | ".aaaacaefcfac###", | 81 | ".aaaacaefcfac###", |
86 | ".aaaacaagchac###", | 82 | ".aaaacaagchac###", |
87 | ".ddddcaaahaac###", | 83 | ".ddddcaaahaac###", |
88 | "ccccccccccccc###"}; | 84 | "ccccccccccccc###"}; |
89 | 85 | ||
90 | /* XPM */ | 86 | /* XPM */ |
91 | static const char * const closed_xpm[]={ | 87 | static const char * const closed_xpm[]={ |
92 | "16 16 6 1", | 88 | "16 16 6 1", |
93 | ". c None", | 89 | ". c None", |
94 | "b c #ffff00", | 90 | "b c #ffff00", |
95 | "d c #000000", | 91 | "d c #000000", |
96 | "* c #999999", | 92 | "* c #999999", |
97 | "a c #cccccc", | 93 | "a c #cccccc", |
98 | "c c #ffffff", | 94 | "c c #ffffff", |
99 | "................", | 95 | "................", |
100 | "................", | 96 | "................", |
101 | "..*****.........", | 97 | "..*****.........", |
102 | ".*ababa*........", | 98 | ".*ababa*........", |
103 | "*abababa******..", | 99 | "*abababa******..", |
104 | "*cccccccccccc*d.", | 100 | "*cccccccccccc*d.", |
105 | "*cbababababab*d.", | 101 | "*cbababababab*d.", |
106 | "*cabababababa*d.", | 102 | "*cabababababa*d.", |
107 | "*cbababababab*d.", | 103 | "*cbababababab*d.", |
108 | "*cabababababa*d.", | 104 | "*cabababababa*d.", |
109 | "*cbababababab*d.", | 105 | "*cbababababab*d.", |
110 | "*cabababababa*d.", | 106 | "*cabababababa*d.", |
111 | "*cbababababab*d.", | 107 | "*cbababababab*d.", |
112 | "**************d.", | 108 | "**************d.", |
113 | ".dddddddddddddd.", | 109 | ".dddddddddddddd.", |
114 | "................"}; | 110 | "................"}; |
115 | 111 | ||
116 | /* XPM */ | 112 | /* XPM */ |
117 | static const char* const cdtoparent_xpm[]={ | 113 | static const char* const cdtoparent_xpm[]={ |
118 | "15 13 3 1", | 114 | "15 13 3 1", |
119 | ". c None", | 115 | ". c None", |
120 | "* c #000000", | 116 | "* c #000000", |
121 | "a c #ffff99", | 117 | "a c #ffff99", |
122 | "..*****........", | 118 | "..*****........", |
123 | ".*aaaaa*.......", | 119 | ".*aaaaa*.......", |
124 | "***************", | 120 | "***************", |
125 | "*aaaaaaaaaaaaa*", | 121 | "*aaaaaaaaaaaaa*", |
126 | "*aaaa*aaaaaaaa*", | 122 | "*aaaa*aaaaaaaa*", |
127 | "*aaa***aaaaaaa*", | 123 | "*aaa***aaaaaaa*", |
128 | "*aa*****aaaaaa*", | 124 | "*aa*****aaaaaa*", |
129 | "*aaaa*aaaaaaaa*", | 125 | "*aaaa*aaaaaaaa*", |
130 | "*aaaa*aaaaaaaa*", | 126 | "*aaaa*aaaaaaaa*", |
131 | "*aaaa******aaa*", | 127 | "*aaaa******aaa*", |
132 | "*aaaaaaaaaaaaa*", | 128 | "*aaaaaaaaaaaaa*", |
133 | "*aaaaaaaaaaaaa*", | 129 | "*aaaaaaaaaaaaa*", |
134 | "***************"}; | 130 | "***************"}; |
135 | 131 | ||
136 | ScQtFileEditDlg::ScQtFileEditDlg( QWidget *parent, const char *name, | 132 | ScQtFileEditDlg::ScQtFileEditDlg( QWidget *parent, const char *name, |
137 | const QString &path, const QString &filter ) | 133 | const QString &path, const QString &filter ) |
138 | : ScQtFileDlg( parent, name, TRUE ), QDir( path, filter ) | 134 | : ScQtFileDlg( parent, name, TRUE ), QDir( path, filter ) |
139 | { | 135 | { |
140 | // ListView->setRootIsDecorated ( TRUE ); | 136 | // ListView->setRootIsDecorated ( TRUE ); |
141 | 137 | ||
142 | #ifdef DEBUGFILEEDIT | 138 | #ifdef DEBUGFILEEDIT |
143 | printf ("\nScQtFileEditDlg:: constructor name=%s", name ); | 139 | printf ("\nScQtFileEditDlg:: constructor name=%s", name ); |
144 | printf ("\n path=%s", (const char *)path ); | 140 | printf ("\n path=%s", (const char *)path ); |
145 | printf ("\n filter=%s", (const char *)filter ); | 141 | printf ("\n filter=%s", (const char *)filter ); |
146 | printf ("\n parent=%p", parent ); | 142 | printf ("\n parent=%p", parent ); |
147 | fflush(stdout); | 143 | fflush(stdout); |
148 | #endif | 144 | #endif |
149 | 145 | ||
150 | bpath = path; | 146 | bpath = path; |
151 | bfilter = filter; | 147 | bfilter = filter; |
152 | exflag = false; | 148 | exflag = false; |
153 | 149 | ||
154 | ListView->setAllColumnsShowFocus( TRUE ); | 150 | ListView->setAllColumnsShowFocus( TRUE ); |
155 | ListView->setColumnAlignment( 1, Qt::AlignRight ); | 151 | ListView->setColumnAlignment( 1, Qt::AlignRight ); |
156 | 152 | ||
157 | fileIcon = new QPixmap( (const char **)file_xpm); | 153 | fileIcon = new QPixmap( (const char **)file_xpm); |
158 | dirIcon = new QPixmap( (const char **)closed_xpm); | 154 | dirIcon = new QPixmap( (const char **)closed_xpm); |
159 | linkIcon = new QPixmap( (const char **)link_file_xpm); | 155 | linkIcon = new QPixmap( (const char **)link_file_xpm); |
160 | cdToParentIcon = new QPixmap( (const char **)cdtoparent_xpm); | 156 | cdToParentIcon = new QPixmap( (const char **)cdtoparent_xpm); |
161 | 157 | ||
162 | #ifdef QWS | 158 | #ifdef QWS |
163 | QPEApplication::execDialog( this ); | 159 | QPEApplication::execDialog( this ); |
164 | #endif | 160 | #endif |
165 | 161 | ||
166 | mkdirflag = false; | 162 | mkdirflag = false; |
167 | MkDirButton->setEnabled( false ); | 163 | MkDirButton->setEnabled( false ); |
168 | 164 | ||
169 | initDirCombo( bpath ); | 165 | initDirCombo( bpath ); |
170 | initTypeCombo( bfilter ); | 166 | initTypeCombo( bfilter ); |
171 | 167 | ||
172 | dirstr = tr("dir"); | 168 | dirstr = tr("dir"); |
173 | filestr = tr("file"); | 169 | filestr = tr("file"); |
174 | linkstr = tr("link"); | 170 | linkstr = tr("link"); |
175 | 171 | ||
176 | rFlag = false; | 172 | rFlag = false; |
177 | 173 | ||
178 | showTimer.stop(); | 174 | showTimer.stop(); |
179 | connect( &showTimer, SIGNAL(timeout()), SLOT( slotShowDir() ) ); | 175 | connect( &showTimer, SIGNAL(timeout()), SLOT( slotShowDir() ) ); |
180 | 176 | ||
181 | fmode = QDir::All; | 177 | fmode = QDir::All; |
182 | fnfilter = false; | 178 | fnfilter = false; |
183 | fsorting = false; | 179 | fsorting = false; |
184 | 180 | ||
185 | } | 181 | } |
186 | 182 | ||
187 | ScQtFileEditDlg::~ScQtFileEditDlg() | 183 | ScQtFileEditDlg::~ScQtFileEditDlg() |
188 | { | 184 | { |
189 | #ifdef DEBUGFILEEDIT | 185 | #ifdef DEBUGFILEEDIT |
190 | printf ("\nScQtFileEditDlg::destructor called" ); | 186 | printf ("\nScQtFileEditDlg::destructor called" ); |
191 | fflush(stdout); | 187 | fflush(stdout); |
192 | #endif | 188 | #endif |
193 | 189 | ||
194 | if ( fileIcon != NULL ) | 190 | if ( fileIcon != NULL ) |
195 | { | 191 | { |
196 | delete fileIcon; | 192 | delete fileIcon; |
197 | fileIcon = NULL; | 193 | fileIcon = NULL; |
198 | } | 194 | } |
199 | if ( dirIcon != NULL ) | 195 | if ( dirIcon != NULL ) |
200 | { | 196 | { |
201 | delete dirIcon; | 197 | delete dirIcon; |
202 | dirIcon = NULL; | 198 | dirIcon = NULL; |
203 | } | 199 | } |
204 | if ( linkIcon != NULL ) | 200 | if ( linkIcon != NULL ) |
205 | { | 201 | { |
206 | delete linkIcon; | 202 | delete linkIcon; |
207 | linkIcon = NULL; | 203 | linkIcon = NULL; |
208 | } | 204 | } |
209 | if ( cdToParentIcon != NULL ) | 205 | if ( cdToParentIcon != NULL ) |
210 | { | 206 | { |
211 | delete cdToParentIcon; | 207 | delete cdToParentIcon; |
212 | cdToParentIcon = NULL; | 208 | cdToParentIcon = NULL; |
213 | } | 209 | } |
214 | } | 210 | } |
215 | 211 | ||
216 | void ScQtFileEditDlg::readIt( ) | 212 | void ScQtFileEditDlg::readIt( ) |
217 | { | 213 | { |
218 | qfil = readDir( bpath, bfilter ); | 214 | qfil = readDir( bpath, bfilter ); |
219 | slotShowDir( ); | 215 | slotShowDir( ); |
220 | } | 216 | } |
221 | 217 | ||
222 | void ScQtFileEditDlg::setAutoExtension( bool ex ) | 218 | void ScQtFileEditDlg::setAutoExtension( bool ex ) |
223 | { | 219 | { |
224 | exflag = ex; | 220 | exflag = ex; |
225 | } | 221 | } |
226 | 222 | ||
227 | 223 | ||
228 | int ScQtFileEditDlg::checkComboEntryExists( QComboBox *com, const QString &str ) | 224 | int ScQtFileEditDlg::checkComboEntryExists( QComboBox *com, const QString &str ) |
229 | { | 225 | { |
230 | int i; | 226 | int i; |
231 | 227 | ||
232 | if ( com ) | 228 | if ( com ) |
233 | { | 229 | { |
234 | for ( i = 0; i < com->count(); i++ ) | 230 | for ( i = 0; i < com->count(); i++ ) |
235 | { | 231 | { |
236 | if ( com->text( i ) == str ) | 232 | if ( com->text( i ) == str ) |
237 | { | 233 | { |
238 | com->setCurrentItem( i ); | 234 | com->setCurrentItem( i ); |
239 | return( 1 ); | 235 | return( 1 ); |
240 | } | 236 | } |
241 | } | 237 | } |
242 | } | 238 | } |
243 | 239 | ||
244 | return( 0 ); | 240 | return( 0 ); |
245 | } | 241 | } |
246 | 242 | ||
247 | 243 | ||
248 | void ScQtFileEditDlg::initDirCombo( const QString &str ) | 244 | void ScQtFileEditDlg::initDirCombo( const QString &str ) |
249 | { | 245 | { |
250 | DirComboBox->clear(); | 246 | DirComboBox->clear(); |
251 | DirComboBox->insertItem( "/" ); | 247 | DirComboBox->insertItem( "/" ); |
252 | if ( str.isEmpty() ) | 248 | if ( str.isEmpty() ) |
253 | return; | 249 | return; |
254 | DirComboBox->insertItem( str, -1 ); | 250 | DirComboBox->insertItem( str, -1 ); |
255 | } | 251 | } |
256 | 252 | ||
257 | void ScQtFileEditDlg::initTypeCombo( const QString &str ) | 253 | void ScQtFileEditDlg::initTypeCombo( const QString &str ) |
258 | { | 254 | { |
259 | TypeComboBox->clear(); | 255 | TypeComboBox->clear(); |
260 | TypeComboBox->insertItem( "*" ); | 256 | TypeComboBox->insertItem( "*" ); |
261 | if ( str.isEmpty() ) | 257 | if ( str.isEmpty() ) |
262 | return; | 258 | return; |
263 | TypeComboBox->insertItem( str, -1 ); | 259 | TypeComboBox->insertItem( str, -1 ); |
264 | } | 260 | } |
265 | 261 | ||
266 | void ScQtFileEditDlg::insDirCombo( const QString &str ) | 262 | void ScQtFileEditDlg::insDirCombo( const QString &str ) |
267 | { | 263 | { |
268 | if ( str.isEmpty() ) | 264 | if ( str.isEmpty() ) |
269 | return; | 265 | return; |
270 | 266 | ||
271 | if ( !checkComboEntryExists( DirComboBox, str ) ) | 267 | if ( !checkComboEntryExists( DirComboBox, str ) ) |
272 | { | 268 | { |
273 | if ( DirComboBox->count() >= MAXDIRCOMBOCOUNT ) | 269 | if ( DirComboBox->count() >= MAXDIRCOMBOCOUNT ) |
274 | { | 270 | { |
275 | // 2. Item loeschen (das erste ist "/") | 271 | // 2. Item loeschen (das erste ist "/") |
276 | DirComboBox->removeItem( 1 ); | 272 | DirComboBox->removeItem( 1 ); |
277 | } | 273 | } |
278 | // neues Item anhaengen | 274 | // neues Item anhaengen |
279 | DirComboBox->insertItem( str, -1 ); | 275 | DirComboBox->insertItem( str, -1 ); |
280 | DirComboBox->setCurrentItem( DirComboBox->count() - 1 ); | 276 | DirComboBox->setCurrentItem( DirComboBox->count() - 1 ); |
281 | } | 277 | } |
282 | } | 278 | } |
283 | 279 | ||
284 | void ScQtFileEditDlg::insTypeCombo( const QString &str ) | 280 | void ScQtFileEditDlg::insTypeCombo( const QString &str ) |
285 | { | 281 | { |
286 | if ( str.isEmpty() ) | 282 | if ( str.isEmpty() ) |
287 | return; | 283 | return; |
288 | 284 | ||
289 | if ( !checkComboEntryExists( TypeComboBox, str ) ) | 285 | if ( !checkComboEntryExists( TypeComboBox, str ) ) |
290 | { | 286 | { |
291 | if ( TypeComboBox->count() >= MAXTYPECOMBOCOUNT ) | 287 | if ( TypeComboBox->count() >= MAXTYPECOMBOCOUNT ) |
292 | { | 288 | { |
293 | // 2. Item loeschen (das erste ist "/") | 289 | // 2. Item loeschen (das erste ist "/") |
294 | TypeComboBox->removeItem( 1 ); | 290 | TypeComboBox->removeItem( 1 ); |
295 | } | 291 | } |
296 | // neues Item anhaengen | 292 | // neues Item anhaengen |
297 | TypeComboBox->insertItem( str, -1 ); | 293 | TypeComboBox->insertItem( str, -1 ); |
298 | TypeComboBox->setCurrentItem( TypeComboBox->count() - 1 ); | 294 | TypeComboBox->setCurrentItem( TypeComboBox->count() - 1 ); |
299 | } | 295 | } |
300 | } | 296 | } |
301 | 297 | ||
302 | 298 | ||
303 | const QFileInfoList *ScQtFileEditDlg::readDir( const QString &path, const QString &filter ) | 299 | const QFileInfoList *ScQtFileEditDlg::readDir( const QString &path, const QString &filter ) |
304 | { | 300 | { |
305 | static QString qpath, qfilter; | 301 | static QString qpath, qfilter; |
306 | 302 | ||
307 | #ifdef DEBUGFILEEDIT | 303 | #ifdef DEBUGFILEEDIT |
308 | printf ("\nScQtFileEditDlg::readDir called, path = %s", (const char *)path ); | 304 | printf ("\nScQtFileEditDlg::readDir called, path = %s", (const char *)path ); |
309 | printf ("\n filter = %s", (const char *)filter ); | 305 | printf ("\n filter = %s", (const char *)filter ); |
310 | fflush(stdout); | 306 | fflush(stdout); |
311 | #endif | 307 | #endif |
312 | 308 | ||
313 | rFlag = true; | 309 | rFlag = true; |
314 | 310 | ||
315 | if ( path.isEmpty() ) | 311 | if ( path.isEmpty() ) |
316 | qpath = "/"; | 312 | qpath = "/"; |
317 | else | 313 | else |
318 | qpath = path; | 314 | qpath = path; |
319 | 315 | ||
320 | if ( filter.isEmpty() ) | 316 | if ( filter.isEmpty() ) |
321 | qfilter = "*"; | 317 | qfilter = "*"; |
322 | else | 318 | else |
323 | qfilter = filter; | 319 | qfilter = filter; |
324 | 320 | ||
325 | insDirCombo( qpath ); | 321 | insDirCombo( qpath ); |
326 | insTypeCombo( qfilter ); | 322 | insTypeCombo( qfilter ); |
327 | 323 | ||
328 | setFilter( fmode ); | 324 | setFilter( fmode ); |
329 | if ( fsorting ) | 325 | if ( fsorting ) |
330 | setSorting( QDir::DirsFirst | QDir::Name ); | 326 | setSorting( QDir::DirsFirst | QDir::Name ); |
331 | if ( fnfilter ) | 327 | if ( fnfilter ) |
332 | setNameFilter( qfilter ); | 328 | setNameFilter( qfilter ); |
333 | setPath( qpath ); | 329 | setPath( qpath ); |
334 | 330 | ||
335 | const QFileInfoList *dirlist = entryInfoList(); | 331 | const QFileInfoList *dirlist = entryInfoList(); |
336 | 332 | ||
337 | if ( !dirlist ) | 333 | if ( !dirlist ) |
338 | { | 334 | { |
339 | rFlag = false; | 335 | rFlag = false; |
340 | return( 0 ); | 336 | return( 0 ); |
341 | } | 337 | } |
342 | 338 | ||
343 | rFlag = false; | 339 | rFlag = false; |
344 | 340 | ||
345 | return( dirlist ); | 341 | return( dirlist ); |
346 | } | 342 | } |
347 | 343 | ||
348 | QString ScQtFileEditDlg::getResult( ) | 344 | QString ScQtFileEditDlg::getResult( ) |
349 | { | 345 | { |
350 | static QString qstr; | 346 | static QString qstr; |
351 | 347 | ||
352 | #ifdef DEBUGFILEEDIT | 348 | #ifdef DEBUGFILEEDIT |
353 | printf ("\nScQtFileEditDlg::getResult called" ); | 349 | printf ("\nScQtFileEditDlg::getResult called" ); |
354 | fflush(stdout); | 350 | fflush(stdout); |
355 | #endif | 351 | #endif |
356 | 352 | ||
357 | qstr = bpath + "/"; | 353 | qstr = bpath + "/"; |
358 | qstr = qstr + filename; | 354 | qstr = qstr + filename; |
359 | bpath = cleanDirPath( qstr ); | 355 | bpath = cleanDirPath( qstr ); |
360 | 356 | ||
361 | return( bpath ); | 357 | return( bpath ); |
362 | } | 358 | } |
363 | 359 | ||
364 | QString ScQtFileEditDlg::getFileName( ) | 360 | QString ScQtFileEditDlg::getFileName( ) |
365 | { | 361 | { |
366 | int a; | 362 | int a; |
367 | static QString qstr; | 363 | static QString qstr; |
368 | 364 | ||
369 | #ifdef DEBUGFILEEDIT | 365 | #ifdef DEBUGFILEEDIT |
370 | printf ("\nScQtFileEditDlg::getFileName called" ); | 366 | printf ("\nScQtFileEditDlg::getFileName called" ); |
371 | fflush(stdout); | 367 | fflush(stdout); |
372 | #endif | 368 | #endif |
373 | 369 | ||
374 | a = bpath.findRev( "/", -1, TRUE ); | 370 | a = bpath.findRev( "/", -1, TRUE ); |
375 | if (a == -1) | 371 | if (a == -1) |
376 | qstr = bpath; // Nicht gefunden | 372 | qstr = bpath; // Nicht gefunden |
377 | else | 373 | else |
378 | qstr = bpath.right( bpath.length() - a - 1 ); | 374 | qstr = bpath.right( bpath.length() - a - 1 ); |
379 | 375 | ||
380 | return( qstr ); | 376 | return( qstr ); |
381 | } | 377 | } |
382 | 378 | ||
383 | // Ab hier die Slots ----------------------------------- | 379 | // Ab hier die Slots ----------------------------------- |
384 | 380 | ||
385 | void ScQtFileEditDlg::slotShowDir() | 381 | void ScQtFileEditDlg::slotShowDir() |
386 | { | 382 | { |
387 | static QListViewItem *qlvitem; | 383 | static QListViewItem *qlvitem; |
388 | static QString ftypestr, fsizestr; | 384 | static QString ftypestr, fsizestr; |
389 | static QFileInfo *fi; // pointer for traversing | 385 | static QFileInfo *fi; // pointer for traversing |
390 | 386 | ||
391 | if ( !qfil ) // pointer war Null | 387 | if ( !qfil ) // pointer war Null |
392 | return; | 388 | return; |
393 | 389 | ||
394 | ListView->clear(); // ersma loeschen | 390 | ListView->clear(); // ersma loeschen |
395 | QFileInfoListIterator it( *qfil ); // create list iterator | 391 | QFileInfoListIterator it( *qfil ); // create list iterator |
396 | if ( !it ) // pointer war Null | 392 | if ( !it ) // pointer war Null |
397 | return; | 393 | return; |
398 | 394 | ||
399 | while ( (fi=it.current()) ) | 395 | while ( (fi=it.current()) ) |
400 | { // for each file... | 396 | { // for each file... |
401 | if ( !fi ) // current war 0 | 397 | if ( !fi ) // current war 0 |
402 | return; | 398 | return; |
403 | 399 | ||
404 | if ( !fi->fileName().isNull() ) | 400 | if ( !fi->fileName().isNull() ) |
405 | { | 401 | { |
406 | if ( fi->isDir() == TRUE ) | 402 | if ( fi->isDir() == TRUE ) |
407 | { | 403 | { |
408 | ftypestr = dirstr; | 404 | ftypestr = dirstr; |
409 | fsizestr = "" ; | 405 | fsizestr = "" ; |
410 | } | 406 | } |
411 | else if ( fi->isSymLink() == TRUE ) | 407 | else if ( fi->isSymLink() == TRUE ) |
412 | { | 408 | { |
413 | ftypestr = linkstr; | 409 | ftypestr = linkstr; |
414 | fsizestr = "" ; | 410 | fsizestr = "" ; |
415 | } | 411 | } |
416 | else if ( fi->isFile() == TRUE ) | 412 | else if ( fi->isFile() == TRUE ) |
417 | { | 413 | { |
418 | ftypestr = filestr; | 414 | ftypestr = filestr; |
419 | fsizestr.sprintf( "%d", fi->size() ); | 415 | fsizestr.sprintf( "%d", fi->size() ); |
420 | } | 416 | } |
421 | else | 417 | else |
422 | { | 418 | { |
423 | printf( "something else\n" ); | 419 | printf( "something else\n" ); |
424 | fflush(stdout); | 420 | fflush(stdout); |
425 | } | 421 | } |
426 | 422 | ||
427 | if ( !(fi->fileName() == "." ) ) // der wird ausgespart | 423 | if ( !(fi->fileName() == "." ) ) // der wird ausgespart |
428 | { | 424 | { |
429 | qlvitem = new QListViewItem ( ListView, fi->fileName(), fsizestr, ftypestr ); | 425 | qlvitem = new QListViewItem ( ListView, fi->fileName(), fsizestr, ftypestr ); |
430 | if ( fi->fileName() == ".." ) | 426 | if ( fi->fileName() == ".." ) |
431 | qlvitem->setPixmap( 0, *cdToParentIcon ); | 427 | qlvitem->setPixmap( 0, *cdToParentIcon ); |
432 | else if ( fi->isDir() == TRUE ) | 428 | else if ( fi->isDir() == TRUE ) |
433 | qlvitem->setPixmap( 0, *dirIcon ); | 429 | qlvitem->setPixmap( 0, *dirIcon ); |
434 | else if ( fi->isSymLink() == TRUE ) | 430 | else if ( fi->isSymLink() == TRUE ) |
435 | qlvitem->setPixmap( 0, *linkIcon ); | 431 | qlvitem->setPixmap( 0, *linkIcon ); |
436 | else if ( fi->isFile() == TRUE ) | 432 | else if ( fi->isFile() == TRUE ) |
437 | qlvitem->setPixmap( 0, *fileIcon ); | 433 | qlvitem->setPixmap( 0, *fileIcon ); |
438 | } | 434 | } |
439 | } | 435 | } |
440 | ++it; // goto next list element | 436 | ++it; // goto next list element |
441 | } | 437 | } |
442 | } | 438 | } |
443 | 439 | ||
444 | void ScQtFileEditDlg::slotDirComboBoxChanged( int item ) | 440 | void ScQtFileEditDlg::slotDirComboBoxChanged( int item ) |
445 | { | 441 | { |
446 | if ( !rFlag ) | 442 | if ( !rFlag ) |
447 | { | 443 | { |
448 | bpath = DirComboBox->currentText( ); | 444 | bpath = DirComboBox->currentText( ); |
449 | qfil = readDir( bpath, bfilter ); | 445 | qfil = readDir( bpath, bfilter ); |
450 | slotShowDir( ); | 446 | slotShowDir( ); |
451 | } | 447 | } |
452 | } | 448 | } |
453 | 449 | ||
454 | void ScQtFileEditDlg::slotTypeComboBoxChanged( int item ) | 450 | void ScQtFileEditDlg::slotTypeComboBoxChanged( int item ) |
455 | { | 451 | { |
456 | if ( !rFlag ) | 452 | if ( !rFlag ) |
457 | { | 453 | { |
458 | bfilter = TypeComboBox->currentText( ); | 454 | bfilter = TypeComboBox->currentText( ); |
459 | qfil = readDir( bpath, bfilter ); | 455 | qfil = readDir( bpath, bfilter ); |
460 | slotShowDir( ); | 456 | slotShowDir( ); |
461 | } | 457 | } |
462 | } | 458 | } |
463 | 459 | ||
464 | void ScQtFileEditDlg::slotFileTextChanged( const QString &txt ) | 460 | void ScQtFileEditDlg::slotFileTextChanged( const QString &txt ) |
465 | { | 461 | { |
466 | filename = txt; | 462 | filename = txt; |
467 | } | 463 | } |
468 | 464 | ||
469 | void ScQtFileEditDlg::slotSelectionChanged( QListViewItem *item ) | 465 | void ScQtFileEditDlg::slotSelectionChanged( QListViewItem *item ) |
470 | { | 466 | { |
471 | static QString qstr, rstr; | 467 | static QString qstr, rstr; |
472 | 468 | ||
473 | #ifdef DEBUGFILEEDIT | 469 | #ifdef DEBUGFILEEDIT |
474 | printf ("\nScQtFileEditDlg::slotSelectionChanged called" ); | 470 | printf ("\nScQtFileEditDlg::slotSelectionChanged called" ); |
475 | fflush(stdout); | 471 | fflush(stdout); |
476 | #endif | 472 | #endif |
477 | if ( item ) | 473 | if ( item ) |
478 | { | 474 | { |
479 | if ( !item->text(2) ) | 475 | if ( !item->text(2) ) |
480 | return; | 476 | return; |
481 | 477 | ||
482 | if ( item->text(2) == dirstr ) | 478 | if ( item->text(2) == dirstr ) |
483 | { | 479 | { |
484 | if ( !rFlag ) | 480 | if ( !rFlag ) |
485 | { | 481 | { |
486 | rstr = bpath; | 482 | rstr = bpath; |
487 | qstr = bpath + "/"; | 483 | qstr = bpath + "/"; |
488 | qstr = qstr + item->text(0); | 484 | qstr = qstr + item->text(0); |
489 | bpath = cleanDirPath( qstr ); | 485 | bpath = cleanDirPath( qstr ); |
490 | qfil = readDir( bpath, bfilter ); | 486 | qfil = readDir( bpath, bfilter ); |
491 | if ( qfil == 0 ) | 487 | if ( qfil == 0 ) |
492 | { | 488 | { |
493 | bpath = rstr; | 489 | bpath = rstr; |
494 | // Nochmal lesen, um die ComboBoxen zu setzten | 490 | // Nochmal lesen, um die ComboBoxen zu setzten |
495 | qfil = readDir( bpath, bfilter ); | 491 | qfil = readDir( bpath, bfilter ); |
496 | } | 492 | } |
497 | showTimer.start( 10, true ); | 493 | showTimer.start( 10, true ); |
498 | } | 494 | } |
499 | } | 495 | } |
500 | else if ( item->text(2) == filestr ) | 496 | else if ( item->text(2) == filestr ) |
501 | { | 497 | { |
502 | FNameLineEdit->setText( item->text(0) ); | 498 | FNameLineEdit->setText( item->text(0) ); |
503 | filename = item->text(0); | 499 | filename = item->text(0); |
504 | } | 500 | } |
505 | } | 501 | } |
506 | } | 502 | } |
507 | 503 | ||
508 | 504 | ||
509 | void ScQtFileEditDlg::slotMkDir( ) | 505 | void ScQtFileEditDlg::slotMkDir( ) |
510 | { | 506 | { |
511 | QString qstr; | 507 | QString qstr; |
512 | 508 | ||
513 | if ( !FNameLineEdit->text().isEmpty() ) | 509 | if ( !FNameLineEdit->text().isEmpty() ) |
514 | { | 510 | { |
515 | qstr = bpath + "/"; | 511 | qstr = bpath + "/"; |
516 | qstr = qstr + FNameLineEdit->text(); | 512 | qstr = qstr + FNameLineEdit->text(); |
517 | mkdir( qstr, true ); | 513 | mkdir( qstr, true ); |
518 | qfil = readDir( bpath, bfilter ); | 514 | qfil = readDir( bpath, bfilter ); |
519 | FNameLineEdit->setText( "" ); | 515 | FNameLineEdit->setText( "" ); |
520 | slotShowDir( ); | 516 | slotShowDir( ); |
521 | } | 517 | } |
522 | } | 518 | } |
523 | 519 | ||
524 | void ScQtFileEditDlg::slotDoubleClicked( QListViewItem *item ) | 520 | void ScQtFileEditDlg::slotDoubleClicked( QListViewItem *item ) |
525 | { | 521 | { |
526 | static QString qstr, rstr; | 522 | static QString qstr, rstr; |
527 | 523 | ||
528 | #ifdef DEBUGFILEEDIT | 524 | #ifdef DEBUGFILEEDIT |
529 | printf ("\nScQtFileEditDlg::slotDoubleClicked called" ); | 525 | printf ("\nScQtFileEditDlg::slotDoubleClicked called" ); |
530 | fflush(stdout); | 526 | fflush(stdout); |
531 | #endif | 527 | #endif |
532 | 528 | ||
533 | if ( item ) | 529 | if ( item ) |
534 | { | 530 | { |
535 | if ( item->text(2) == dirstr ) | 531 | if ( item->text(2) == dirstr ) |
536 | { | 532 | { |
537 | if ( !rFlag ) | 533 | if ( !rFlag ) |
538 | { | 534 | { |
539 | rstr = bpath; | 535 | rstr = bpath; |
540 | qstr = bpath + "/"; | 536 | qstr = bpath + "/"; |
541 | qstr = qstr + item->text(0); | 537 | qstr = qstr + item->text(0); |
542 | bpath = cleanDirPath( qstr ); | 538 | bpath = cleanDirPath( qstr ); |
543 | qfil = readDir( bpath, bfilter ); | 539 | qfil = readDir( bpath, bfilter ); |
544 | if ( qfil == 0 ) | 540 | if ( qfil == 0 ) |
545 | { | 541 | { |
546 | bpath = rstr; | 542 | bpath = rstr; |
547 | // Nochmal lesen, um die ComboBoxen zu setzten | 543 | // Nochmal lesen, um die ComboBoxen zu setzten |
548 | qfil = readDir( bpath, bfilter ); | 544 | qfil = readDir( bpath, bfilter ); |
549 | } | 545 | } |
550 | showTimer.start( 10, TRUE ); | 546 | showTimer.start( 10, TRUE ); |
551 | } | 547 | } |
552 | } | 548 | } |
553 | } | 549 | } |
554 | } | 550 | } |
555 | 551 | ||
556 | void ScQtFileEditDlg::autoExtension( ) | 552 | void ScQtFileEditDlg::autoExtension( ) |
557 | { | 553 | { |
558 | QString qstr; | 554 | QString qstr; |
559 | int len; | 555 | int len; |
560 | 556 | ||
561 | if ( exflag ) | 557 | if ( exflag ) |
562 | { | 558 | { |
563 | qstr = TypeComboBox->currentText( ); | 559 | qstr = TypeComboBox->currentText( ); |
564 | if ( qstr != "*" ) | 560 | if ( qstr != "*" ) |
565 | { | 561 | { |
566 | len = qstr.findRev( ".", -1 ); | 562 | len = qstr.findRev( ".", -1 ); |
567 | if ( len >= 0 ) | 563 | if ( len >= 0 ) |
568 | { | 564 | { |
569 | qstr = qstr.right( qstr.length() - len ); | 565 | qstr = qstr.right( qstr.length() - len ); |
570 | len = filename.findRev( qstr, -1 ); | 566 | len = filename.findRev( qstr, -1 ); |
571 | if ( len < 0 ) | 567 | if ( len < 0 ) |
572 | filename = filename + qstr; | 568 | filename = filename + qstr; |
573 | } | 569 | } |
574 | } | 570 | } |
575 | } | 571 | } |
576 | } | 572 | } |
577 | 573 | ||
578 | void ScQtFileEditDlg::setMode( int mode ) | 574 | void ScQtFileEditDlg::setMode( int mode ) |
579 | { | 575 | { |
580 | fmode = mode; | 576 | fmode = mode; |
581 | } | 577 | } |
582 | 578 | ||
583 | void ScQtFileEditDlg::setNFilter( bool ff ) | 579 | void ScQtFileEditDlg::setNFilter( bool ff ) |
584 | { | 580 | { |
585 | fnfilter = ff; | 581 | fnfilter = ff; |
586 | } | 582 | } |
587 | 583 | ||
588 | void ScQtFileEditDlg::setFSorting( bool ff ) | 584 | void ScQtFileEditDlg::setFSorting( bool ff ) |
589 | { | 585 | { |
590 | fsorting = ff; | 586 | fsorting = ff; |
591 | } | 587 | } |
592 | 588 | ||
593 | void ScQtFileEditDlg::allowMkDir( bool mkdir ) | 589 | void ScQtFileEditDlg::allowMkDir( bool mkdir ) |
594 | { | 590 | { |
595 | mkdirflag = mkdir; | 591 | mkdirflag = mkdir; |
596 | MkDirButton->setEnabled( mkdir ); | 592 | MkDirButton->setEnabled( mkdir ); |
597 | } | 593 | } |
598 | 594 | ||
599 | 595 | ||
600 | void ScQtFileEditDlg::slotOK( ) | 596 | void ScQtFileEditDlg::slotOK( ) |
601 | { | 597 | { |
602 | #ifdef DEBUGFILEEDIT | 598 | #ifdef DEBUGFILEEDIT |
603 | printf ("\nScQtFileEditDlg::slotOK called" ); | 599 | printf ("\nScQtFileEditDlg::slotOK called" ); |
604 | fflush(stdout); | 600 | fflush(stdout); |
605 | #endif | 601 | #endif |
606 | autoExtension(); | 602 | autoExtension(); |
607 | 603 | ||
608 | accept(); | 604 | accept(); |
609 | } | 605 | } |
610 | 606 | ||
611 | void ScQtFileEditDlg::slotCancel( ) | 607 | void ScQtFileEditDlg::slotCancel( ) |
612 | { | 608 | { |
613 | 609 | ||
614 | #ifdef DEBUGFILEEDIT | 610 | #ifdef DEBUGFILEEDIT |
615 | printf ("\nScQtFileEditDlg::slotCancel called" ); | 611 | printf ("\nScQtFileEditDlg::slotCancel called" ); |
616 | fflush(stdout); | 612 | fflush(stdout); |
617 | #endif | 613 | #endif |
618 | 614 | ||
619 | reject(); | 615 | reject(); |
620 | } | 616 | } |
621 | 617 | ||
622 | 618 | ||
623 | /************************************************************************** | 619 | /************************************************************************** |
624 | ***************************************************************************/ | 620 | ***************************************************************************/ |
625 | ScQtFileEdit::ScQtFileEdit( QWidget *parent, const char *name ) | 621 | ScQtFileEdit::ScQtFileEdit( QWidget *parent, const char *name ) |
626 | { | 622 | { |
627 | #ifdef DEBUGFILEEDIT | 623 | #ifdef DEBUGFILEEDIT |
628 | printf ("\nScQtFileEdit constructor called"); | 624 | printf ("\nScQtFileEdit constructor called"); |
629 | fflush(stdout); | 625 | fflush(stdout); |
630 | #endif | 626 | #endif |
631 | } | 627 | } |
632 | 628 | ||
633 | ScQtFileEdit::~ScQtFileEdit() | 629 | ScQtFileEdit::~ScQtFileEdit() |
634 | { | 630 | { |
635 | #ifdef DEBUGFILEEDIT | 631 | #ifdef DEBUGFILEEDIT |
636 | printf ("\nScQtFileEdit destructor called"); | 632 | printf ("\nScQtFileEdit destructor called"); |
637 | fflush(stdout); | 633 | fflush(stdout); |
638 | #endif | 634 | #endif |
639 | } | 635 | } |
640 | 636 | ||
641 | QString ScQtFileEdit::getOpenFileName( QWidget *parent, const char *name, | 637 | QString ScQtFileEdit::getOpenFileName( QWidget *parent, const char *name, |
642 | const QString &path, const QString &filter ) | 638 | const QString &path, const QString &filter ) |
643 | { | 639 | { |
644 | static ScQtFileEditDlg *fd; | 640 | static ScQtFileEditDlg *fd; |
645 | static QString fname; | 641 | static QString fname; |
646 | 642 | ||
647 | #ifdef DEBUGFILEEDIT | 643 | #ifdef DEBUGFILEEDIT |
648 | printf ("\nScQtFileEdit::getOpenFileName name=%s", name ); | 644 | printf ("\nScQtFileEdit::getOpenFileName name=%s", name ); |
649 | printf ("\n path=%s", (const char *)path ); | 645 | printf ("\n path=%s", (const char *)path ); |
650 | printf ("\n filter=%s", (const char *)filter ); | 646 | printf ("\n filter=%s", (const char *)filter ); |
651 | fflush(stdout); | 647 | fflush(stdout); |
652 | #endif | 648 | #endif |
653 | 649 | ||
654 | fd = new ScQtFileEditDlg( parent, name, path, filter ); | 650 | fd = new ScQtFileEditDlg( parent, name, path, filter ); |
655 | fd->setAutoExtension( false ); | 651 | fd->setAutoExtension( false ); |
656 | fd->setMode( QDir::All|QDir::System ); | 652 | fd->setMode( QDir::All|QDir::System ); |
657 | fd->setNFilter( true ); | 653 | fd->setNFilter( true ); |
658 | fd->setFSorting( true ); | 654 | fd->setFSorting( true ); |
659 | fd->readIt(); | 655 | fd->readIt(); |
660 | fd->exec(); | 656 | fd->exec(); |
661 | 657 | ||
662 | if ( fd->result() == QDialog::Accepted ) | 658 | if ( fd->result() == QDialog::Accepted ) |
663 | fname = fd->getResult(); | 659 | fname = fd->getResult(); |
664 | else | 660 | else |
665 | fname = ""; | 661 | fname = ""; |
666 | 662 | ||
667 | delete fd; | 663 | delete fd; |
668 | return( fname ); | 664 | return( fname ); |
669 | } | 665 | } |
670 | 666 | ||
671 | QString ScQtFileEdit::getSaveAsFileName( QWidget *parent, const char *name, | 667 | QString ScQtFileEdit::getSaveAsFileName( QWidget *parent, const char *name, |
672 | const QString &path, const QString &filter ) | 668 | const QString &path, const QString &filter ) |
673 | { | 669 | { |
674 | static ScQtFileEditDlg *fd; | 670 | static ScQtFileEditDlg *fd; |
675 | static QString fname; | 671 | static QString fname; |
676 | 672 | ||
677 | #ifdef DEBUGFILEEDIT | 673 | #ifdef DEBUGFILEEDIT |
678 | printf ("\nScQtFileEdit::getSaveAsFileName name=%s", name ); | 674 | printf ("\nScQtFileEdit::getSaveAsFileName name=%s", name ); |
679 | printf ("\n path=%s", (const char *)path ); | 675 | printf ("\n path=%s", (const char *)path ); |
680 | printf ("\n filter=%s", (const char *)filter ); | 676 | printf ("\n filter=%s", (const char *)filter ); |
681 | fflush(stdout); | 677 | fflush(stdout); |
682 | #endif | 678 | #endif |
683 | 679 | ||
684 | fd = new ScQtFileEditDlg( parent, name, path, filter ); | 680 | fd = new ScQtFileEditDlg( parent, name, path, filter ); |
685 | fd->allowMkDir( true ); // CS: | 681 | fd->allowMkDir( true ); // CS: |
686 | fd->setAutoExtension( true ); | 682 | fd->setAutoExtension( true ); |
687 | fd->setNFilter( true ); | 683 | fd->setNFilter( true ); |
688 | fd->setFSorting( true ); | 684 | fd->setFSorting( true ); |
689 | fd->readIt(); | 685 | fd->readIt(); |
690 | fd->exec(); | 686 | fd->exec(); |
691 | 687 | ||
692 | if ( fd->result() == QDialog::Accepted ) | 688 | if ( fd->result() == QDialog::Accepted ) |
693 | fname = fd->getResult(); | 689 | fname = fd->getResult(); |
694 | else | 690 | else |
695 | fname = ""; | 691 | fname = ""; |
696 | 692 | ||
697 | delete fd; | 693 | delete fd; |
698 | return( fname ); | 694 | return( fname ); |
699 | } | 695 | } |
700 | 696 | ||
701 | QString ScQtFileEdit::getDirName( QWidget *parent, const char *name, | 697 | QString ScQtFileEdit::getDirName( QWidget *parent, const char *name, |
702 | const QString &path ) | 698 | const QString &path ) |
703 | { | 699 | { |
704 | static ScQtFileEditDlg *fd; | 700 | static ScQtFileEditDlg *fd; |
705 | static QString fname; | 701 | static QString fname; |
706 | 702 | ||
707 | #ifdef DEBUGFILEEDIT | 703 | #ifdef DEBUGFILEEDIT |
708 | printf ("\nScQtFileEdit::getDirName name=%s", name ); | 704 | printf ("\nScQtFileEdit::getDirName name=%s", name ); |
709 | printf ("\n path=%s", (const char *)path ); | 705 | printf ("\n path=%s", (const char *)path ); |
710 | fflush(stdout); | 706 | fflush(stdout); |
711 | #endif | 707 | #endif |
712 | 708 | ||
713 | fd = new ScQtFileEditDlg( parent, name, path ); | 709 | fd = new ScQtFileEditDlg( parent, name, path ); |
714 | fd->setMode( QDir::Dirs ); | 710 | fd->setMode( QDir::Dirs ); |
715 | fd->setNFilter( false ); | 711 | fd->setNFilter( false ); |
716 | fd->setFSorting( true ); | 712 | fd->setFSorting( true ); |
717 | fd->readIt(); | 713 | fd->readIt(); |
718 | fd->exec(); | 714 | fd->exec(); |
719 | 715 | ||
720 | if ( fd->result() == QDialog::Accepted ) | 716 | if ( fd->result() == QDialog::Accepted ) |
721 | fname = fd->getResult(); | 717 | fname = fd->getResult(); |
722 | else | 718 | else |
723 | fname = ""; | 719 | fname = ""; |
724 | 720 | ||
725 | delete fd; | 721 | delete fd; |
726 | return( fname ); | 722 | return( fname ); |
727 | } | 723 | } |
728 | 724 | ||
729 | QString ScQtFileEdit::mkDir( QWidget *parent, const char *name, | 725 | QString ScQtFileEdit::mkDir( QWidget *parent, const char *name, |
730 | const QString &path, const QString &filter ) | 726 | const QString &path, const QString &filter ) |
731 | { | 727 | { |
732 | static ScQtFileEditDlg *fd; | 728 | static ScQtFileEditDlg *fd; |
733 | static QString fname; | 729 | static QString fname; |
734 | 730 | ||
735 | #ifdef DEBUGFILEEDIT | 731 | #ifdef DEBUGFILEEDIT |
736 | printf ("\nScQtFileEdit::mkDir name=%s", name ); | 732 | printf ("\nScQtFileEdit::mkDir name=%s", name ); |
737 | printf ("\n basepath=%s", (const char *)path ); | 733 | printf ("\n basepath=%s", (const char *)path ); |
738 | printf ("\n filter=%s", (const char *)filter ); | 734 | printf ("\n filter=%s", (const char *)filter ); |
739 | fflush(stdout); | 735 | fflush(stdout); |
740 | #endif | 736 | #endif |
741 | 737 | ||
742 | fd = new ScQtFileEditDlg( parent, name, path, filter ); | 738 | fd = new ScQtFileEditDlg( parent, name, path, filter ); |
743 | fd->setAutoExtension( true ); | 739 | fd->setAutoExtension( true ); |
744 | fd->allowMkDir( true ); | 740 | fd->allowMkDir( true ); |
745 | fd->setNFilter( false ); | 741 | fd->setNFilter( false ); |
746 | fd->setFSorting( true ); | 742 | fd->setFSorting( true ); |
747 | fd->readIt(); | 743 | fd->readIt(); |
748 | fd->exec(); | 744 | fd->exec(); |
749 | 745 | ||
750 | if ( fd->result() == QDialog::Accepted ) | 746 | if ( fd->result() == QDialog::Accepted ) |
751 | fname = fd->getResult(); | 747 | fname = fd->getResult(); |
752 | else | 748 | else |
753 | fname = ""; | 749 | fname = ""; |
754 | 750 | ||
755 | delete fd; | 751 | delete fd; |
756 | return( fname ); | 752 | return( fname ); |
757 | } | 753 | } |
758 | 754 | ||
diff --git a/noncore/apps/zsafe/zlistview.cpp b/noncore/apps/zsafe/zlistview.cpp index 23bbc4e..ba02a15 100644 --- a/noncore/apps/zsafe/zlistview.cpp +++ b/noncore/apps/zsafe/zlistview.cpp | |||
@@ -1,38 +1,36 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id$ | 2 | ** $Id$ |
3 | */ | 3 | */ |
4 | 4 | ||
5 | #include "zlistview.h" | 5 | #include "zlistview.h" |
6 | #include <qlistview.h> | ||
7 | #include <qevent.h> | ||
8 | #include <stdio.h> | 6 | #include <stdio.h> |
9 | #include "zsafe.h" | 7 | #include "zsafe.h" |
10 | 8 | ||
11 | ZListView::ZListView (ZSafe *zsafe, const char *id) : QListView(zsafe, id) | 9 | ZListView::ZListView (ZSafe *zsafe, const char *id) : QListView(zsafe, id) |
12 | { | 10 | { |
13 | zs = zsafe; | 11 | zs = zsafe; |
14 | } | 12 | } |
15 | 13 | ||
16 | ZListView::~ZListView() | 14 | ZListView::~ZListView() |
17 | { | 15 | { |
18 | } | 16 | } |
19 | 17 | ||
20 | void ZListView::keyPressEvent ( QKeyEvent *e ) | 18 | void ZListView::keyPressEvent ( QKeyEvent *e ) |
21 | { | 19 | { |
22 | /* | 20 | /* |
23 | char buf[64]; | 21 | char buf[64]; |
24 | sprintf (buf, "key: %d\n", e->key()); | 22 | sprintf (buf, "key: %d\n", e->key()); |
25 | qWarning (buf); | 23 | qWarning (buf); |
26 | */ | 24 | */ |
27 | 25 | ||
28 | switch (e->key()) | 26 | switch (e->key()) |
29 | { | 27 | { |
30 | case 32: // middle cursor key pressed | 28 | case 32: // middle cursor key pressed |
31 | zs->showInfo (zs->selectedItem); | 29 | zs->showInfo (zs->selectedItem); |
32 | break; | 30 | break; |
33 | default: | 31 | default: |
34 | QListView::keyPressEvent( e ); | 32 | QListView::keyPressEvent( e ); |
35 | } | 33 | } |
36 | 34 | ||
37 | } | 35 | } |
38 | 36 | ||
diff --git a/noncore/apps/zsafe/zsafe.cpp b/noncore/apps/zsafe/zsafe.cpp index f43a206..a3e805e 100644 --- a/noncore/apps/zsafe/zsafe.cpp +++ b/noncore/apps/zsafe/zsafe.cpp | |||
@@ -1,850 +1,849 @@ | |||
1 | /**************************************************************************** | 1 | /**************************************************************************** |
2 | ** | 2 | ** |
3 | ** Created: Sat Apr 6 17:57:45 2002 | 3 | ** Created: Sat Apr 6 17:57:45 2002 |
4 | ** | 4 | ** |
5 | ** Author: Carsten Schneider <CarstenSchneider@t-online.de> | 5 | ** Author: Carsten Schneider <CarstenSchneider@t-online.de> |
6 | ** | 6 | ** |
7 | ** $Id$ | 7 | ** $Id$ |
8 | ** | 8 | ** |
9 | ** Homepage: http://home.t-online.de/home/CarstenSchneider/zsafe/index.html | 9 | ** Homepage: http://home.t-online.de/home/CarstenSchneider/zsafe/index.html |
10 | ** | 10 | ** |
11 | ** Compile Flags: | 11 | ** Compile Flags: |
12 | ** Zaurus arm : -DNO_OPIE | 12 | ** Zaurus arm : -DNO_OPIE |
13 | ** Zaurus Opie arm: none | 13 | ** Zaurus Opie arm: none |
14 | ** Linux Desktop : -DDESKTOP | 14 | ** Linux Desktop : -DDESKTOP |
15 | ** Windows Desktop: -DDESKTOP -DWIN32 | 15 | ** Windows Desktop: -DDESKTOP -DWIN32 |
16 | ** | 16 | ** |
17 | ** for japanese version additional use: -DJPATCH_HDE | 17 | ** for japanese version additional use: -DJPATCH_HDE |
18 | ** | 18 | ** |
19 | ****************************************************************************/ | 19 | ****************************************************************************/ |
20 | #include "zsafe.h" | 20 | #include "zsafe.h" |
21 | #include "newdialog.h" | 21 | #include "newdialog.h" |
22 | #include "searchdialog.h" | 22 | #include "searchdialog.h" |
23 | #include "categorydialog.h" | 23 | #include "categorydialog.h" |
24 | #include "passworddialog.h" | 24 | #include "passworddialog.h" |
25 | #include "infoform.h" | 25 | #include "infoform.h" |
26 | #include "zlistview.h" | 26 | #include "zlistview.h" |
27 | #include "shadedlistitem.h" | 27 | #include "shadedlistitem.h" |
28 | 28 | ||
29 | #ifndef DESKTOP | 29 | #ifndef DESKTOP |
30 | #ifndef NO_OPIE | 30 | #ifndef NO_OPIE |
31 | #include <opie2/ofiledialog.h> | 31 | #include <opie2/ofiledialog.h> |
32 | 32 | ||
33 | using Opie::OFileDialog; | 33 | using Opie::OFileDialog; |
34 | using Opie::OFileSelector; | 34 | using Opie::OFileSelector; |
35 | #else | 35 | #else |
36 | #include "scqtfileedit.h" | 36 | #include "scqtfileedit.h" |
37 | #endif | 37 | #endif |
38 | #endif | 38 | #endif |
39 | 39 | ||
40 | #include <qclipboard.h> | 40 | #include <qclipboard.h> |
41 | 41 | ||
42 | #include <stdio.h> | 42 | #include <stdio.h> |
43 | 43 | ||
44 | #include <sys/types.h> | 44 | #include <sys/types.h> |
45 | #include <sys/stat.h> | 45 | #include <sys/stat.h> |
46 | #include <fcntl.h> | 46 | #include <fcntl.h> |
47 | #include <stdlib.h> | 47 | #include <stdlib.h> |
48 | #ifndef WIN32 | 48 | #ifndef WIN32 |
49 | #include <unistd.h> | 49 | #include <unistd.h> |
50 | #endif | 50 | #endif |
51 | #include <string.h> | 51 | #include <string.h> |
52 | #include <errno.h> | 52 | #include <errno.h> |
53 | 53 | ||
54 | #include <qmenubar.h> | 54 | #include <qmenubar.h> |
55 | #include <qpopupmenu.h> | 55 | #include <qpopupmenu.h> |
56 | 56 | ||
57 | #ifdef DESKTOP | 57 | #ifdef DESKTOP |
58 | #include <qfiledialog.h> | 58 | #include <qfiledialog.h> |
59 | #ifndef WIN32 | 59 | #ifndef WIN32 |
60 | #include <qsettings.h> | 60 | #include <qsettings.h> |
61 | #else | 61 | #else |
62 | #include "qsettings.h" | 62 | #include "qsettings.h" |
63 | #endif | 63 | #endif |
64 | #include <qapplication.h> | 64 | #include <qapplication.h> |
65 | #else | 65 | #else |
66 | #include <qfile.h> | 66 | #include <qfile.h> |
67 | #include <qpe/fileselector.h> | 67 | #include <qpe/fileselector.h> |
68 | #include <qpe/global.h> | 68 | #include <qpe/global.h> |
69 | #include <qpe/qpeapplication.h> | 69 | #include <qpe/qpeapplication.h> |
70 | #include <qpe/resource.h> | 70 | #include <qpe/resource.h> |
71 | #include <qpe/config.h> | 71 | #include <qpe/config.h> |
72 | #endif | 72 | #endif |
73 | 73 | ||
74 | #include <qtimer.h> | 74 | #include <qtimer.h> |
75 | #include <qlayout.h> | 75 | #include <qlayout.h> |
76 | #include <qmessagebox.h> | 76 | #include <qmessagebox.h> |
77 | #include <qfile.h> | 77 | #include <qfile.h> |
78 | #include <qtextstream.h> | 78 | #include <qtextstream.h> |
79 | #include <qheader.h> | 79 | #include <qheader.h> |
80 | #include <qlistview.h> | 80 | #include <qlistview.h> |
81 | #include <qtoolbutton.h> | 81 | #include <qtoolbutton.h> |
82 | #include <qlayout.h> | ||
83 | #include <qvariant.h> | 82 | #include <qvariant.h> |
84 | #include <qtooltip.h> | 83 | #include <qtooltip.h> |
85 | #include <qwhatsthis.h> | 84 | #include <qwhatsthis.h> |
86 | #include <qimage.h> | 85 | #include <qimage.h> |
87 | #include <qpixmap.h> | 86 | #include <qpixmap.h> |
88 | #include <qlineedit.h> | 87 | #include <qlineedit.h> |
89 | #include <qmultilineedit.h> | 88 | #include <qmultilineedit.h> |
90 | #include <qregexp.h> | 89 | #include <qregexp.h> |
91 | #include <qdir.h> | 90 | #include <qdir.h> |
92 | #include <qtextbrowser.h> | 91 | #include <qtextbrowser.h> |
93 | #include <qlabel.h> | 92 | #include <qlabel.h> |
94 | #include <qcombobox.h> | 93 | #include <qcombobox.h> |
95 | 94 | ||
96 | #include "krc2.h" | 95 | #include "krc2.h" |
97 | 96 | ||
98 | #include "wait.h" | 97 | #include "wait.h" |
99 | 98 | ||
100 | extern int DeskW, DeskH; | 99 | extern int DeskW, DeskH; |
101 | #ifdef DESKTOP | 100 | #ifdef DESKTOP |
102 | extern QApplication *appl; | 101 | extern QApplication *appl; |
103 | #else | 102 | #else |
104 | extern QPEApplication *appl; | 103 | extern QPEApplication *appl; |
105 | #endif | 104 | #endif |
106 | 105 | ||
107 | #ifdef JPATCH_HDE | 106 | #ifdef JPATCH_HDE |
108 | #define tr(arg) arg | 107 | #define tr(arg) arg |
109 | #endif | 108 | #endif |
110 | 109 | ||
111 | 110 | ||
112 | #ifdef DESKTOP | 111 | #ifdef DESKTOP |
113 | #ifndef WIN32 | 112 | #ifndef WIN32 |
114 | const QString APP_KEY="/.zsafe/"; | 113 | const QString APP_KEY="/.zsafe/"; |
115 | #else | 114 | #else |
116 | const QString APP_KEY=""; | 115 | const QString APP_KEY=""; |
117 | #endif | 116 | #endif |
118 | #else | 117 | #else |
119 | const QString APP_KEY=""; | 118 | const QString APP_KEY=""; |
120 | #endif | 119 | #endif |
121 | 120 | ||
122 | // include xmp images | 121 | // include xmp images |
123 | #include "pics/zsafe/copy.xpm" | 122 | #include "pics/zsafe/copy.xpm" |
124 | #include "pics/zsafe/cut.xpm" | 123 | #include "pics/zsafe/cut.xpm" |
125 | #include "pics/zsafe/edit.xpm" | 124 | #include "pics/zsafe/edit.xpm" |
126 | #include "pics/zsafe/editdelete.xpm" | 125 | #include "pics/zsafe/editdelete.xpm" |
127 | #include "pics/zsafe/find.xpm" | 126 | #include "pics/zsafe/find.xpm" |
128 | #include "pics/zsafe/folder_open.xpm" | 127 | #include "pics/zsafe/folder_open.xpm" |
129 | #include "pics/zsafe/help_icon.xpm" | 128 | #include "pics/zsafe/help_icon.xpm" |
130 | #include "pics/zsafe/new.xpm" | 129 | #include "pics/zsafe/new.xpm" |
131 | #include "pics/zsafe/paste.xpm" | 130 | #include "pics/zsafe/paste.xpm" |
132 | #include "pics/zsafe/quit_icon.xpm" | 131 | #include "pics/zsafe/quit_icon.xpm" |
133 | #include "pics/zsafe/save.xpm" | 132 | #include "pics/zsafe/save.xpm" |
134 | #include "pics/zsafe/trash.xpm" | 133 | #include "pics/zsafe/trash.xpm" |
135 | #include "pics/zsafe/expand.xpm" | 134 | #include "pics/zsafe/expand.xpm" |
136 | #include "pics/zsafe/export.xpm" | 135 | #include "pics/zsafe/export.xpm" |
137 | #include "pics/zsafe/import.xpm" | 136 | #include "pics/zsafe/import.xpm" |
138 | #include "pics/zsafe/zsafe.xpm" | 137 | #include "pics/zsafe/zsafe.xpm" |
139 | 138 | ||
140 | static const char* const bank_cards_data[] = { | 139 | static const char* const bank_cards_data[] = { |
141 | "14 14 16 1", | 140 | "14 14 16 1", |
142 | ". c None", | 141 | ". c None", |
143 | "# c #000000", | 142 | "# c #000000", |
144 | "b c #0000de", | 143 | "b c #0000de", |
145 | "a c #0000e6", | 144 | "a c #0000e6", |
146 | "j c #41de83", | 145 | "j c #41de83", |
147 | "k c #4acecd", | 146 | "k c #4acecd", |
148 | "h c #4aced5", | 147 | "h c #4aced5", |
149 | "g c #5a40cd", | 148 | "g c #5a40cd", |
150 | "d c #5a44d5", | 149 | "d c #5a44d5", |
151 | "l c #9440d5", | 150 | "l c #9440d5", |
152 | "m c #b4ce4a", | 151 | "m c #b4ce4a", |
153 | "n c #cd4883", | 152 | "n c #cd4883", |
154 | "e c #d5ae10", | 153 | "e c #d5ae10", |
155 | "f c #de3ce6", | 154 | "f c #de3ce6", |
156 | "i c #e640e6", | 155 | "i c #e640e6", |
157 | "c c #ffffff", | 156 | "c c #ffffff", |
158 | "..............", | 157 | "..............", |
159 | ".###########..", | 158 | ".###########..", |
160 | ".#ababababa#..", | 159 | ".#ababababa#..", |
161 | ".#babbbabbb#..", | 160 | ".#babbbabbb#..", |
162 | ".#ccccccccc#..", | 161 | ".#ccccccccc#..", |
163 | ".#cdcefcghc#..", | 162 | ".#cdcefcghc#..", |
164 | ".#ccccccccc#..", | 163 | ".#ccccccccc#..", |
165 | ".#cicjkclic#..", | 164 | ".#cicjkclic#..", |
166 | ".#ccccccccc#..", | 165 | ".#ccccccccc#..", |
167 | ".#cmchlcnec#..", | 166 | ".#cmchlcnec#..", |
168 | ".#ccccccccc#..", | 167 | ".#ccccccccc#..", |
169 | ".###########..", | 168 | ".###########..", |
170 | "..............", | 169 | "..............", |
171 | ".............."}; | 170 | ".............."}; |
172 | 171 | ||
173 | 172 | ||
174 | static const char* const passwords_data[] = { | 173 | static const char* const passwords_data[] = { |
175 | "16 16 20 1", | 174 | "16 16 20 1", |
176 | ". c None", | 175 | ". c None", |
177 | "# c #000000", | 176 | "# c #000000", |
178 | "r c #000083", | 177 | "r c #000083", |
179 | "p c #0000c5", | 178 | "p c #0000c5", |
180 | "q c #0000ff", | 179 | "q c #0000ff", |
181 | "n c #008100", | 180 | "n c #008100", |
182 | "l c #00c200", | 181 | "l c #00c200", |
183 | "m c #00ff00", | 182 | "m c #00ff00", |
184 | "j c #838100", | 183 | "j c #838100", |
185 | "a c #c55900", | 184 | "a c #c55900", |
186 | "h c #c5c200", | 185 | "h c #c5c200", |
187 | "o c #c5c2ff", | 186 | "o c #c5c2ff", |
188 | "k c #c5ffc5", | 187 | "k c #c5ffc5", |
189 | "f c #ff0000", | 188 | "f c #ff0000", |
190 | "d c #ff8100", | 189 | "d c #ff8100", |
191 | "b c #ffaa5a", | 190 | "b c #ffaa5a", |
192 | "e c #ffc2c5", | 191 | "e c #ffc2c5", |
193 | "c c #ffdeac", | 192 | "c c #ffdeac", |
194 | "i c #ffff00", | 193 | "i c #ffff00", |
195 | "g c #ffffc5", | 194 | "g c #ffffc5", |
196 | "............###.", | 195 | "............###.", |
197 | "...........#abb#", | 196 | "...........#abb#", |
198 | "..........#cbab#", | 197 | "..........#cbab#", |
199 | ".........#cbdd#.", | 198 | ".........#cbdd#.", |
200 | "######..#cbdd#..", | 199 | "######..#cbdd#..", |
201 | "#eeff#..#add#...", | 200 | "#eeff#..#add#...", |
202 | "#eeff#######....", | 201 | "#eeff#######....", |
203 | "#ccdbdd#........", | 202 | "#ccdbdd#........", |
204 | "#dddbdd###......", | 203 | "#dddbdd###......", |
205 | "#gghihhjj#......", | 204 | "#gghihhjj#......", |
206 | "#hhhihhjj###....", | 205 | "#hhhihhjj###....", |
207 | "#kklmllnnnn#....", | 206 | "#kklmllnnnn#....", |
208 | "#lllmllnnnn#....", | 207 | "#lllmllnnnn#....", |
209 | "#oopqpprprr#....", | 208 | "#oopqpprprr#....", |
210 | "#oopqpprprr#....", | 209 | "#oopqpprprr#....", |
211 | "############...."}; | 210 | "############...."}; |
212 | 211 | ||
213 | static const char* const software_data[] = { | 212 | static const char* const software_data[] = { |
214 | "16 16 5 1", | 213 | "16 16 5 1", |
215 | ". c None", | 214 | ". c None", |
216 | "# c #000000", | 215 | "# c #000000", |
217 | "b c #838183", | 216 | "b c #838183", |
218 | "c c #c5ffff", | 217 | "c c #c5ffff", |
219 | "a c #ffffff", | 218 | "a c #ffffff", |
220 | "................", | 219 | "................", |
221 | ".##############.", | 220 | ".##############.", |
222 | "#aaaaaaaaaaaaaa#", | 221 | "#aaaaaaaaaaaaaa#", |
223 | "#abbbbbbbbbbbbb#", | 222 | "#abbbbbbbbbbbbb#", |
224 | "#ab##########ab#", | 223 | "#ab##########ab#", |
225 | "#ab#c########ab#", | 224 | "#ab#c########ab#", |
226 | "#ab#c#c######ab#", | 225 | "#ab#c#c######ab#", |
227 | "#ab##########ab#", | 226 | "#ab##########ab#", |
228 | "#ab##########ab#", | 227 | "#ab##########ab#", |
229 | "#ab##########ab#", | 228 | "#ab##########ab#", |
230 | "#ab##########ab#", | 229 | "#ab##########ab#", |
231 | "#ab##########ab#", | 230 | "#ab##########ab#", |
232 | "#aaaaaaaaaaaaab#", | 231 | "#aaaaaaaaaaaaab#", |
233 | "#bbbbbbbbbbbbbb#", | 232 | "#bbbbbbbbbbbbbb#", |
234 | ".##############.", | 233 | ".##############.", |
235 | "................"}; | 234 | "................"}; |
236 | 235 | ||
237 | static const char* const general_data[] = { | 236 | static const char* const general_data[] = { |
238 | "14 14 98 2", | 237 | "14 14 98 2", |
239 | "Qt c None", | 238 | "Qt c None", |
240 | ".k c #000000", | 239 | ".k c #000000", |
241 | "#x c #080808", | 240 | "#x c #080808", |
242 | "#F c #101008", | 241 | "#F c #101008", |
243 | "#q c #101010", | 242 | "#q c #101010", |
244 | "#i c #101410", | 243 | "#i c #101410", |
245 | "## c #101810", | 244 | "## c #101810", |
246 | ".m c #181818", | 245 | ".m c #181818", |
247 | ".3 c #181c18", | 246 | ".3 c #181c18", |
248 | ".I c #182018", | 247 | ".I c #182018", |
249 | ".T c #202420", | 248 | ".T c #202420", |
250 | "#D c #202820", | 249 | "#D c #202820", |
251 | "#y c #292c29", | 250 | "#y c #292c29", |
252 | ".c c #293029", | 251 | ".c c #293029", |
253 | ".d c #313031", | 252 | ".d c #313031", |
254 | "#E c #313429", | 253 | "#E c #313429", |
255 | "#r c #313831", | 254 | "#r c #313831", |
256 | ".j c #393c31", | 255 | ".j c #393c31", |
257 | "#j c #394039", | 256 | "#j c #394039", |
258 | "#C c #414841", | 257 | "#C c #414841", |
259 | ".w c #4a554a", | 258 | ".w c #4a554a", |
260 | ".a c #4a594a", | 259 | ".a c #4a594a", |
261 | ".# c #525052", | 260 | ".# c #525052", |
262 | ".l c #52594a", | 261 | ".l c #52594a", |
263 | "#f c #525952", | 262 | "#f c #525952", |
264 | "#v c #525d52", | 263 | "#v c #525d52", |
265 | ".O c #5a4c4a", | 264 | ".O c #5a4c4a", |
266 | ".9 c #5a595a", | 265 | ".9 c #5a595a", |
267 | ".A c #5a5d52", | 266 | ".A c #5a5d52", |
268 | ".B c #624c52", | 267 | ".B c #624c52", |
269 | ".0 c #625552", | 268 | ".0 c #625552", |
270 | "#o c #626562", | 269 | "#o c #626562", |
271 | ".R c #626962", | 270 | ".R c #626962", |
272 | "#. c #626d5a", | 271 | "#. c #626d5a", |
273 | "#p c #626d62", | 272 | "#p c #626d62", |
274 | ".2 c #627162", | 273 | ".2 c #627162", |
275 | "#h c #6a6d62", | 274 | "#h c #6a6d62", |
276 | "#z c #6a7562", | 275 | "#z c #6a7562", |
277 | "#w c #6a756a", | 276 | "#w c #6a756a", |
278 | ".C c #73656a", | 277 | ".C c #73656a", |
279 | ".P c #73696a", | 278 | ".P c #73696a", |
280 | "#a c #737d6a", | 279 | "#a c #737d6a", |
281 | ".U c #738573", | 280 | ".U c #738573", |
282 | ".E c #7b817b", | 281 | ".E c #7b817b", |
283 | "#B c #7b857b", | 282 | "#B c #7b857b", |
284 | "#s c #7b897b", | 283 | "#s c #7b897b", |
285 | "#n c #7b917b", | 284 | "#n c #7b917b", |
286 | ".b c #838d83", | 285 | ".b c #838d83", |
287 | ".7 c #839583", | 286 | ".7 c #839583", |
288 | ".n c #8b7d7b", | 287 | ".n c #8b7d7b", |
289 | "#g c #8b8583", | 288 | "#g c #8b8583", |
290 | ".g c #8b858b", | 289 | ".g c #8b858b", |
291 | ".r c #8b898b", | 290 | ".r c #8b898b", |
292 | ".s c #8b8d8b", | 291 | ".s c #8b8d8b", |
293 | ".i c #8b9183", | 292 | ".i c #8b9183", |
294 | ".8 c #8b918b", | 293 | ".8 c #8b918b", |
295 | "#A c #8b9d8b", | 294 | "#A c #8b9d8b", |
296 | ".S c #8ba183", | 295 | ".S c #8ba183", |
297 | ".Z c #94918b", | 296 | ".Z c #94918b", |
298 | ".N c #949994", | 297 | ".N c #949994", |
299 | ".F c #949d94", | 298 | ".F c #949d94", |
300 | ".x c #94a18b", | 299 | ".x c #94a18b", |
301 | ".v c #94a194", | 300 | ".v c #94a194", |
302 | ".Y c #94aa94", | 301 | ".Y c #94aa94", |
303 | ".h c #9c999c", | 302 | ".h c #9c999c", |
304 | ".Q c #9ca19c", | 303 | ".Q c #9ca19c", |
305 | "#u c #9ca59c", | 304 | "#u c #9ca59c", |
306 | ".H c #9caa9c", | 305 | ".H c #9caa9c", |
307 | "#e c #9cb29c", | 306 | "#e c #9cb29c", |
308 | "#m c #a4b29c", | 307 | "#m c #a4b29c", |
309 | "#t c #a4b2a4", | 308 | "#t c #a4b2a4", |
310 | ".M c #a4b69c", | 309 | ".M c #a4b69c", |
311 | "#l c #a4b6a4", | 310 | "#l c #a4b6a4", |
312 | ".z c #a4baa4", | 311 | ".z c #a4baa4", |
313 | ".f c #aca5ac", | 312 | ".f c #aca5ac", |
314 | ".q c #acaaac", | 313 | ".q c #acaaac", |
315 | "#d c #acbeac", | 314 | "#d c #acbeac", |
316 | ".6 c #acc2ac", | 315 | ".6 c #acc2ac", |
317 | ".o c #b4b2b4", | 316 | ".o c #b4b2b4", |
318 | ".t c #b4beb4", | 317 | ".t c #b4beb4", |
319 | "#k c #b4c2ac", | 318 | "#k c #b4c2ac", |
320 | ".5 c #b4cab4", | 319 | ".5 c #b4cab4", |
321 | ".D c #bdb6bd", | 320 | ".D c #bdb6bd", |
322 | ".G c #bdc6b4", | 321 | ".G c #bdc6b4", |
323 | "#c c #bdceb4", | 322 | "#c c #bdceb4", |
324 | ".X c #bdd2bd", | 323 | ".X c #bdd2bd", |
325 | ".4 c #bdd6bd", | 324 | ".4 c #bdd6bd", |
326 | ".1 c #c5bec5", | 325 | ".1 c #c5bec5", |
327 | ".e c #c5c2c5", | 326 | ".e c #c5c2c5", |
328 | ".u c #c5cac5", | 327 | ".u c #c5cac5", |
329 | "#b c #c5d6c5", | 328 | "#b c #c5d6c5", |
330 | ".J c #c5dec5", | 329 | ".J c #c5dec5", |
331 | ".p c #cdcacd", | 330 | ".p c #cdcacd", |
332 | ".W c #cddecd", | 331 | ".W c #cddecd", |
333 | ".L c #cde2cd", | 332 | ".L c #cde2cd", |
334 | ".K c #d5eacd", | 333 | ".K c #d5eacd", |
335 | ".V c #d5ead5", | 334 | ".V c #d5ead5", |
336 | ".y c #d5eed5", | 335 | ".y c #d5eed5", |
337 | "QtQtQtQtQtQtQtQtQtQtQtQtQtQt", | 336 | "QtQtQtQtQtQtQtQtQtQtQtQtQtQt", |
338 | "QtQtQt.#.a.b.cQtQtQtQtQtQtQt", | 337 | "QtQtQt.#.a.b.cQtQtQtQtQtQtQt", |
339 | "QtQt.d.e.f.g.h.i.c.j.dQt.kQt", | 338 | "QtQt.d.e.f.g.h.i.c.j.dQt.kQt", |
340 | ".a.l.m.n.o.p.q.r.s.t.u.v.wQt", | 339 | ".a.l.m.n.o.p.q.r.s.t.u.v.wQt", |
341 | ".x.y.z.A.B.C.D.p.q.E.F.G.H.I", | 340 | ".x.y.z.A.B.C.D.p.q.E.F.G.H.I", |
342 | ".I.J.K.L.M.N.O.P.o.p.Q.R.S.T", | 341 | ".I.J.K.L.M.N.O.P.o.p.Q.R.S.T", |
343 | "Qt.U.V.L.W.X.Y.Z.0.P.1.s.2.3", | 342 | "Qt.U.V.L.W.X.Y.Z.0.P.1.s.2.3", |
344 | "Qt.3.X.W.4.X.5.6.7.8.9.s#.##", | 343 | "Qt.3.X.W.4.X.5.6.7.8.9.s#.##", |
345 | "QtQt#a.X#b#c.5.6#d#e#f#g#h#i", | 344 | "QtQt#a.X#b#c.5.6#d#e#f#g#h#i", |
346 | "QtQtQt#j.7#k.6#d#l#m#n#o#p#q", | 345 | "QtQtQt#j.7#k.6#d#l#m#n#o#p#q", |
347 | "QtQtQtQt.k#r#s#m#t.H#u#v#w#x", | 346 | "QtQtQtQt.k#r#s#m#t.H#u#v#w#x", |
348 | "QtQtQtQtQtQt.k#y#z.v#A#B#C#x", | 347 | "QtQtQtQtQtQt.k#y#z.v#A#B#C#x", |
349 | "QtQtQtQtQtQtQtQt.k#D.w#s#E.k", | 348 | "QtQtQtQtQtQtQtQt.k#D.w#s#E.k", |
350 | "QtQtQtQtQtQtQtQtQtQtQt#x#FQt"}; | 349 | "QtQtQtQtQtQtQtQtQtQtQt#x#FQt"}; |
351 | 350 | ||
352 | // exit ZSafe and clear the clipboard for security reasons | 351 | // exit ZSafe and clear the clipboard for security reasons |
353 | void ZSafe::exitZs (int ec) | 352 | void ZSafe::exitZs (int ec) |
354 | { | 353 | { |
355 | QClipboard *cb = QApplication::clipboard(); | 354 | QClipboard *cb = QApplication::clipboard(); |
356 | cb->clear(); | 355 | cb->clear(); |
357 | 356 | ||
358 | exit (ec); | 357 | exit (ec); |
359 | } | 358 | } |
360 | 359 | ||
361 | 360 | ||
362 | // save the configuration into the file | 361 | // save the configuration into the file |
363 | void ZSafe::saveConf () | 362 | void ZSafe::saveConf () |
364 | { | 363 | { |
365 | if (conf) | 364 | if (conf) |
366 | { | 365 | { |
367 | delete conf; | 366 | delete conf; |
368 | 367 | ||
369 | #ifdef DESKTOP | 368 | #ifdef DESKTOP |
370 | #ifndef WIN32 | 369 | #ifndef WIN32 |
371 | conf = new QSettings (); | 370 | conf = new QSettings (); |
372 | conf->insertSearchPath (QSettings::Unix, QDir::homeDirPath()); | 371 | conf->insertSearchPath (QSettings::Unix, QDir::homeDirPath()); |
373 | #else | 372 | #else |
374 | conf = new QSettings (cfgFile); | 373 | conf = new QSettings (cfgFile); |
375 | conf->insertSearchPath (QSettings::Unix, cfgFile); | 374 | conf->insertSearchPath (QSettings::Unix, cfgFile); |
376 | #endif | 375 | #endif |
377 | #else | 376 | #else |
378 | conf = new Config (cfgFile, Config::File); | 377 | conf = new Config (cfgFile, Config::File); |
379 | conf->setGroup ("zsafe"); | 378 | conf->setGroup ("zsafe"); |
380 | #endif | 379 | #endif |
381 | } | 380 | } |
382 | } | 381 | } |
383 | 382 | ||
384 | 383 | ||
385 | /* | 384 | /* |
386 | * Constructs a ZSafe which is a child of 'parent', with the | 385 | * Constructs a ZSafe which is a child of 'parent', with the |
387 | * name 'name' and widget flags set to 'f' | 386 | * name 'name' and widget flags set to 'f' |
388 | * | 387 | * |
389 | * The dialog will by default be modeless, unless you set 'modal' to | 388 | * The dialog will by default be modeless, unless you set 'modal' to |
390 | * TRUE to construct a modal dialog. | 389 | * TRUE to construct a modal dialog. |
391 | */ | 390 | */ |
392 | ZSafe::ZSafe( QWidget* parent, const char* name, bool modal, WFlags fl ) | 391 | ZSafe::ZSafe( QWidget* parent, const char* name, bool modal, WFlags fl ) |
393 | : QDialog( parent, name, modal, fl ), | 392 | : QDialog( parent, name, modal, fl ), |
394 | Edit(0l), Delete(0l), Find(0l), New(0l), ListView(0l) | 393 | Edit(0l), Delete(0l), Find(0l), New(0l), ListView(0l) |
395 | { | 394 | { |
396 | IsCut = false; | 395 | IsCut = false; |
397 | IsCopy = false; | 396 | IsCopy = false; |
398 | modified = false; | 397 | modified = false; |
399 | 398 | ||
400 | // set the config file | 399 | // set the config file |
401 | cfgFile=QDir::homeDirPath(); | 400 | cfgFile=QDir::homeDirPath(); |
402 | cfgFile += "/.zsafe.cfg"; | 401 | cfgFile += "/.zsafe.cfg"; |
403 | // set the icon path | 402 | // set the icon path |
404 | #ifdef NO_OPIE | 403 | #ifdef NO_OPIE |
405 | QString qpedir ((const char *)getenv("QPEDIR")); | 404 | QString qpedir ((const char *)getenv("QPEDIR")); |
406 | #else | 405 | #else |
407 | QString qpedir ((const char *)getenv("OPIEDIR")); | 406 | QString qpedir ((const char *)getenv("OPIEDIR")); |
408 | #endif | 407 | #endif |
409 | 408 | ||
410 | #ifdef DESKTOP | 409 | #ifdef DESKTOP |
411 | iconPath = QDir::homeDirPath() + "/pics/"; | 410 | iconPath = QDir::homeDirPath() + "/pics/"; |
412 | #else | 411 | #else |
413 | if (qpedir.isEmpty()) | 412 | if (qpedir.isEmpty()) |
414 | iconPath = "/home/QtPalmtop/pics/"; | 413 | iconPath = "/home/QtPalmtop/pics/"; |
415 | else | 414 | else |
416 | iconPath = qpedir + "/pics/"; | 415 | iconPath = qpedir + "/pics/"; |
417 | #endif | 416 | #endif |
418 | 417 | ||
419 | // create a zsafe configuration object | 418 | // create a zsafe configuration object |
420 | #ifdef DESKTOP | 419 | #ifdef DESKTOP |
421 | #ifndef WIN32 | 420 | #ifndef WIN32 |
422 | conf = new QSettings (); | 421 | conf = new QSettings (); |
423 | conf->insertSearchPath (QSettings::Unix, QDir::homeDirPath()); | 422 | conf->insertSearchPath (QSettings::Unix, QDir::homeDirPath()); |
424 | #else | 423 | #else |
425 | conf = new QSettings (cfgFile); | 424 | conf = new QSettings (cfgFile); |
426 | conf->insertSearchPath (QSettings::Unix, cfgFile); | 425 | conf->insertSearchPath (QSettings::Unix, cfgFile); |
427 | #endif | 426 | #endif |
428 | #else | 427 | #else |
429 | conf = new Config (cfgFile, Config::File); | 428 | conf = new Config (cfgFile, Config::File); |
430 | conf->setGroup ("zsafePrefs"); | 429 | conf->setGroup ("zsafePrefs"); |
431 | #endif | 430 | #endif |
432 | #ifdef DESKTOP | 431 | #ifdef DESKTOP |
433 | // #ifndef WIN32 | 432 | // #ifndef WIN32 |
434 | expandTree = conf->readBoolEntry(APP_KEY+"expandTree", false); | 433 | expandTree = conf->readBoolEntry(APP_KEY+"expandTree", false); |
435 | // #endif | 434 | // #endif |
436 | #else | 435 | #else |
437 | expandTree = conf->readNumEntry(APP_KEY+"expandTree", 0); | 436 | expandTree = conf->readNumEntry(APP_KEY+"expandTree", 0); |
438 | #endif | 437 | #endif |
439 | #ifndef DESKTOP | 438 | #ifndef DESKTOP |
440 | conf->setGroup ("zsafe"); | 439 | conf->setGroup ("zsafe"); |
441 | #endif | 440 | #endif |
442 | 441 | ||
443 | QPixmap copy_img((const char**) copy_xpm); | 442 | QPixmap copy_img((const char**) copy_xpm); |
444 | QPixmap cut_img((const char**) cut_xpm); | 443 | QPixmap cut_img((const char**) cut_xpm); |
445 | QPixmap edit_img((const char**) edit_xpm); | 444 | QPixmap edit_img((const char**) edit_xpm); |
446 | QPixmap editdelete_img((const char**) editdelete_xpm); | 445 | QPixmap editdelete_img((const char**) editdelete_xpm); |
447 | QPixmap find_img((const char**) find_xpm); | 446 | QPixmap find_img((const char**) find_xpm); |
448 | QPixmap folder_open_img((const char**) folder_open_xpm); | 447 | QPixmap folder_open_img((const char**) folder_open_xpm); |
449 | QPixmap help_icon_img((const char**) help_icon_xpm); | 448 | QPixmap help_icon_img((const char**) help_icon_xpm); |
450 | QPixmap new_img((const char**) new_xpm); | 449 | QPixmap new_img((const char**) new_xpm); |
451 | QPixmap paste_img((const char**) paste_xpm); | 450 | QPixmap paste_img((const char**) paste_xpm); |
452 | QPixmap quit_icon_img((const char**) quit_icon_xpm); | 451 | QPixmap quit_icon_img((const char**) quit_icon_xpm); |
453 | QPixmap save_img((const char**) save_xpm); | 452 | QPixmap save_img((const char**) save_xpm); |
454 | QPixmap trash_img((const char**) trash_xpm); | 453 | QPixmap trash_img((const char**) trash_xpm); |
455 | QPixmap expand_img((const char**) expand_xpm); | 454 | QPixmap expand_img((const char**) expand_xpm); |
456 | QPixmap export_img((const char**) export_xpm); | 455 | QPixmap export_img((const char**) export_xpm); |
457 | QPixmap import_img((const char**) import_xpm); | 456 | QPixmap import_img((const char**) import_xpm); |
458 | 457 | ||
459 | QPixmap bank_cards( ( const char** ) bank_cards_data ); | 458 | QPixmap bank_cards( ( const char** ) bank_cards_data ); |
460 | QPixmap passwords( ( const char** ) passwords_data ); | 459 | QPixmap passwords( ( const char** ) passwords_data ); |
461 | QPixmap software( ( const char** ) software_data ); | 460 | QPixmap software( ( const char** ) software_data ); |
462 | QPixmap general( ( const char** ) general_data ); | 461 | QPixmap general( ( const char** ) general_data ); |
463 | if ( !name ) | 462 | if ( !name ) |
464 | setName( "ZSafe" ); | 463 | setName( "ZSafe" ); |
465 | 464 | ||
466 | #ifdef DESKTOP | 465 | #ifdef DESKTOP |
467 | #ifdef WIN32 | 466 | #ifdef WIN32 |
468 | setGeometry(100, 150, DeskW, DeskH-30 ); | 467 | setGeometry(100, 150, DeskW, DeskH-30 ); |
469 | #else | 468 | #else |
470 | resize( DeskW, DeskH-30 ); | 469 | resize( DeskW, DeskH-30 ); |
471 | #endif | 470 | #endif |
472 | 471 | ||
473 | #else | 472 | #else |
474 | 473 | ||
475 | #ifdef JPATCH_HDE | 474 | #ifdef JPATCH_HDE |
476 | int DeskS; | 475 | int DeskS; |
477 | if(DeskW > DeskH) | 476 | if(DeskW > DeskH) |
478 | { | 477 | { |
479 | DeskS = DeskW; | 478 | DeskS = DeskW; |
480 | } | 479 | } |
481 | else | 480 | else |
482 | { | 481 | { |
483 | DeskS = DeskH; | 482 | DeskS = DeskH; |
484 | } | 483 | } |
485 | resize( DeskW, DeskH ); | 484 | resize( DeskW, DeskH ); |
486 | setMinimumSize( QSize( DeskS, DeskS ) ); | 485 | setMinimumSize( QSize( DeskS, DeskS ) ); |
487 | setMaximumSize( QSize( DeskS, DeskS ) ); | 486 | setMaximumSize( QSize( DeskS, DeskS ) ); |
488 | #else | 487 | #else |
489 | resize( DeskW, DeskH-30 ); | 488 | resize( DeskW, DeskH-30 ); |
490 | #endif | 489 | #endif |
491 | 490 | ||
492 | #endif | 491 | #endif |
493 | // setCaption( tr( "ZSafe" ) ); | 492 | // setCaption( tr( "ZSafe" ) ); |
494 | 493 | ||
495 | filename = conf->readEntry(APP_KEY+"document"); | 494 | filename = conf->readEntry(APP_KEY+"document"); |
496 | if (filename.isEmpty() || filename.isNull()) | 495 | if (filename.isEmpty() || filename.isNull()) |
497 | { | 496 | { |
498 | 497 | ||
499 | // check if the directory application exists, if not | 498 | // check if the directory application exists, if not |
500 | // create it | 499 | // create it |
501 | // #ifndef WIN32 | 500 | // #ifndef WIN32 |
502 | // QString d1("Documents/application"); | 501 | // QString d1("Documents/application"); |
503 | // #else | 502 | // #else |
504 | QString d1(QDir::homeDirPath() + "/Documents/application"); | 503 | QString d1(QDir::homeDirPath() + "/Documents/application"); |
505 | // #endif | 504 | // #endif |
506 | QDir pd1(d1); | 505 | QDir pd1(d1); |
507 | if (!pd1.exists()) | 506 | if (!pd1.exists()) |
508 | { | 507 | { |
509 | QDir pd1("Documents"); | 508 | QDir pd1("Documents"); |
510 | if (!pd1.mkdir("application", FALSE)) | 509 | if (!pd1.mkdir("application", FALSE)) |
511 | { | 510 | { |
512 | QMessageBox::critical( 0, tr("ZSafe"), | 511 | QMessageBox::critical( 0, tr("ZSafe"), |
513 | #ifdef JPATCH_HDE | 512 | #ifdef JPATCH_HDE |
514 | tr("Can't create directory\n.../Documents/application\n\nZSafe will now exit.")); | 513 | tr("Can't create directory\n.../Documents/application\n\nZSafe will now exit.")); |
515 | #else | 514 | #else |
516 | tr("Can't create directory\n%1\n\nZSafe will now exit.").arg(d1)); | 515 | tr("Can't create directory\n%1\n\nZSafe will now exit.").arg(d1)); |
517 | #endif | 516 | #endif |
518 | exitZs (1); | 517 | exitZs (1); |
519 | } | 518 | } |
520 | } | 519 | } |
521 | QString d2(QDir::homeDirPath() + "/Documents/application/zsafe"); | 520 | QString d2(QDir::homeDirPath() + "/Documents/application/zsafe"); |
522 | QDir pd2(d2); | 521 | QDir pd2(d2); |
523 | if (!pd2.exists()) | 522 | if (!pd2.exists()) |
524 | { | 523 | { |
525 | QDir pd2(QDir::homeDirPath() + "Documents/application"); | 524 | QDir pd2(QDir::homeDirPath() + "Documents/application"); |
526 | if (!pd2.mkdir("zsafe", FALSE)) | 525 | if (!pd2.mkdir("zsafe", FALSE)) |
527 | { | 526 | { |
528 | QMessageBox::critical( 0, tr("ZSafe"), | 527 | QMessageBox::critical( 0, tr("ZSafe"), |
529 | #ifdef JPATCH_HDE | 528 | #ifdef JPATCH_HDE |
530 | tr("Can't create directory\n...//Documents/application/zsafe\n\nZSafe will now exit.")); | 529 | tr("Can't create directory\n...//Documents/application/zsafe\n\nZSafe will now exit.")); |
531 | #else | 530 | #else |
532 | tr("Can't create directory\n%1\n\nZSafe will now exit.").arg(d2)); | 531 | tr("Can't create directory\n%1\n\nZSafe will now exit.").arg(d2)); |
533 | #endif | 532 | #endif |
534 | exitZs (1); | 533 | exitZs (1); |
535 | } | 534 | } |
536 | } | 535 | } |
537 | 536 | ||
538 | 537 | ||
539 | // set the default filename | 538 | // set the default filename |
540 | filename=d2 + "/passwords.zsf"; | 539 | filename=d2 + "/passwords.zsf"; |
541 | 540 | ||
542 | // save the current filename to the config file | 541 | // save the current filename to the config file |
543 | conf->writeEntry(APP_KEY+"document", filename); | 542 | conf->writeEntry(APP_KEY+"document", filename); |
544 | saveConf(); | 543 | saveConf(); |
545 | } | 544 | } |
546 | 545 | ||
547 | //if (filename == "INVALIDPWD") | 546 | //if (filename == "INVALIDPWD") |
548 | //filename = ""; | 547 | //filename = ""; |
549 | 548 | ||
550 | QString ti = filename.right (filename.length() - filename.findRev ('/') - 1); | 549 | QString ti = filename.right (filename.length() - filename.findRev ('/') - 1); |
551 | #ifdef WIN32 | 550 | #ifdef WIN32 |
552 | this->setCaption("Qt ZSafe: " + ti); | 551 | this->setCaption("Qt ZSafe: " + ti); |
553 | #else | 552 | #else |
554 | this->setCaption("ZSafe: " + ti); | 553 | this->setCaption("ZSafe: " + ti); |
555 | #endif | 554 | #endif |
556 | 555 | ||
557 | selectedItem = NULL; | 556 | selectedItem = NULL; |
558 | lastSearchedCategory = NULL; | 557 | lastSearchedCategory = NULL; |
559 | lastSearchedItem = NULL; | 558 | lastSearchedItem = NULL; |
560 | lastSearchedName = ""; | 559 | lastSearchedName = ""; |
561 | lastSearchedUsername = ""; | 560 | lastSearchedUsername = ""; |
562 | lastSearchedComment = ""; | 561 | lastSearchedComment = ""; |
563 | 562 | ||
564 | infoForm = new InfoForm(); | 563 | infoForm = new InfoForm(); |
565 | categoryDialog = NULL; | 564 | categoryDialog = NULL; |
566 | 565 | ||
567 | // add a menu bar | 566 | // add a menu bar |
568 | QMenuBar *menu = new QMenuBar( this ); | 567 | QMenuBar *menu = new QMenuBar( this ); |
569 | 568 | ||
570 | // add file menu | 569 | // add file menu |
571 | // QPopupMenu *file = new QPopupMenu( this ); | 570 | // QPopupMenu *file = new QPopupMenu( this ); |
572 | file = new QPopupMenu( this ); | 571 | file = new QPopupMenu( this ); |
573 | 572 | ||
574 | // #ifdef DESKTOP | 573 | // #ifdef DESKTOP |
575 | file->insertItem( new_img, tr("&New document"), this, SLOT(newDocument()) ); | 574 | file->insertItem( new_img, tr("&New document"), this, SLOT(newDocument()) ); |
576 | file->insertItem( folder_open_img, tr("&Open document"), this, SLOT(loadDocument()) ); | 575 | file->insertItem( folder_open_img, tr("&Open document"), this, SLOT(loadDocument()) ); |
577 | file->insertItem( save_img, tr("&Save document as .."), this, SLOT(saveDocumentAs()) ); | 576 | file->insertItem( save_img, tr("&Save document as .."), this, SLOT(saveDocumentAs()) ); |
578 | file->insertSeparator(); | 577 | file->insertSeparator(); |
579 | // #endif | 578 | // #endif |
580 | 579 | ||
581 | file->insertItem( save_img, tr("&Save document"), this, SLOT(saveDocumentWithoutPwd()) ); | 580 | file->insertItem( save_img, tr("&Save document"), this, SLOT(saveDocumentWithoutPwd()) ); |
582 | file->insertItem( save_img, tr("S&ave document with new Password"), this, | 581 | file->insertItem( save_img, tr("S&ave document with new Password"), this, |
583 | SLOT(saveDocumentWithPwd()) ); | 582 | SLOT(saveDocumentWithPwd()) ); |
584 | file->insertSeparator(); | 583 | file->insertSeparator(); |
585 | file->insertItem( export_img, tr("&Export text file"), this, SLOT(writeAllEntries()) ); | 584 | file->insertItem( export_img, tr("&Export text file"), this, SLOT(writeAllEntries()) ); |
586 | file->insertItem( import_img, tr("&Import text file"), this, SLOT(readAllEntries()) ); | 585 | file->insertItem( import_img, tr("&Import text file"), this, SLOT(readAllEntries()) ); |
587 | file->insertItem( trash_img, tr("&Remove text file"), this, SLOT(removeAsciiFile()) ); | 586 | file->insertItem( trash_img, tr("&Remove text file"), this, SLOT(removeAsciiFile()) ); |
588 | file->insertSeparator(); | 587 | file->insertSeparator(); |
589 | file->insertItem( expand_img, tr("&Open entries expanded"), this, | 588 | file->insertItem( expand_img, tr("&Open entries expanded"), this, |
590 | SLOT(setExpandFlag()), 0, 'o'); | 589 | SLOT(setExpandFlag()), 0, 'o'); |
591 | file->setItemChecked('o', expandTree); | 590 | file->setItemChecked('o', expandTree); |
592 | file->insertSeparator(); | 591 | file->insertSeparator(); |
593 | file->insertItem( quit_icon_img, tr("E&xit"), this, SLOT(quitMe()) ); | 592 | file->insertItem( quit_icon_img, tr("E&xit"), this, SLOT(quitMe()) ); |
594 | menu->insertItem( tr("&File"), file ); | 593 | menu->insertItem( tr("&File"), file ); |
595 | 594 | ||
596 | QPopupMenu *cat = new QPopupMenu( this ); | 595 | QPopupMenu *cat = new QPopupMenu( this ); |
597 | cat->insertItem( new_img, tr("&New"), this, SLOT(addCategory()) ); | 596 | cat->insertItem( new_img, tr("&New"), this, SLOT(addCategory()) ); |
598 | cat->insertItem( edit_img, tr("&Edit"), this, SLOT(editCategory()) ); | 597 | cat->insertItem( edit_img, tr("&Edit"), this, SLOT(editCategory()) ); |
599 | cat->insertItem( trash_img, tr("&Delete"), this, SLOT(delCategory()) ); | 598 | cat->insertItem( trash_img, tr("&Delete"), this, SLOT(delCategory()) ); |
600 | menu->insertItem( tr("&Category"), cat ); | 599 | menu->insertItem( tr("&Category"), cat ); |
601 | 600 | ||
602 | QPopupMenu *it = new QPopupMenu( this ); | 601 | QPopupMenu *it = new QPopupMenu( this ); |
603 | it->insertItem( cut_img, tr("&Cut"), this, SLOT(cutItem()) ); | 602 | it->insertItem( cut_img, tr("&Cut"), this, SLOT(cutItem()) ); |
604 | it->insertItem( copy_img, tr("C&opy"), this, SLOT(copyItem()) ); | 603 | it->insertItem( copy_img, tr("C&opy"), this, SLOT(copyItem()) ); |
605 | it->insertItem( paste_img, tr("&Paste"), this, SLOT(pasteItem()) ); | 604 | it->insertItem( paste_img, tr("&Paste"), this, SLOT(pasteItem()) ); |
606 | it->insertSeparator(); | 605 | it->insertSeparator(); |
607 | it->insertItem( new_img, tr("&New"), this, SLOT(newPwd()) ); | 606 | it->insertItem( new_img, tr("&New"), this, SLOT(newPwd()) ); |
608 | it->insertItem( edit_img, tr("&Edit"), this, SLOT(editPwd()) ); | 607 | it->insertItem( edit_img, tr("&Edit"), this, SLOT(editPwd()) ); |
609 | it->insertItem( trash_img, tr("&Delete"), this, SLOT(deletePwd()) ); | 608 | it->insertItem( trash_img, tr("&Delete"), this, SLOT(deletePwd()) ); |
610 | it->insertItem( find_img, tr("&Search"), this, SLOT(findPwd()) ); | 609 | it->insertItem( find_img, tr("&Search"), this, SLOT(findPwd()) ); |
611 | menu->insertItem( tr("&Entry"), it ); | 610 | menu->insertItem( tr("&Entry"), it ); |
612 | 611 | ||
613 | QPopupMenu *help = new QPopupMenu( this ); | 612 | QPopupMenu *help = new QPopupMenu( this ); |
614 | help->insertItem( help_icon_img, tr("&About"), this, SLOT(about()) ); | 613 | help->insertItem( help_icon_img, tr("&About"), this, SLOT(about()) ); |
615 | menu->insertItem( tr("&Help"), help ); | 614 | menu->insertItem( tr("&Help"), help ); |
616 | 615 | ||
617 | // toolbar icons | 616 | // toolbar icons |
618 | 617 | ||
619 | New = new QToolButton( menu, "New" ); | 618 | New = new QToolButton( menu, "New" ); |
620 | New->setGeometry( QRect( DeskW-84, 2, 20, 20 ) ); | 619 | New->setGeometry( QRect( DeskW-84, 2, 20, 20 ) ); |
621 | New->setMouseTracking( TRUE ); | 620 | New->setMouseTracking( TRUE ); |
622 | New->setText( tr( "" ) ); | 621 | New->setText( tr( "" ) ); |
623 | New->setPixmap( new_img ); | 622 | New->setPixmap( new_img ); |
624 | QToolTip::add( New, tr( "New entry" ) ); | 623 | QToolTip::add( New, tr( "New entry" ) ); |
625 | 624 | ||
626 | Edit = new QToolButton( menu, "Edit" ); | 625 | Edit = new QToolButton( menu, "Edit" ); |
627 | Edit->setGeometry( QRect( DeskW-64, 2, 20, 20 ) ); | 626 | Edit->setGeometry( QRect( DeskW-64, 2, 20, 20 ) ); |
628 | Edit->setText( tr( "" ) ); | 627 | Edit->setText( tr( "" ) ); |
629 | Edit->setPixmap( edit_img ); | 628 | Edit->setPixmap( edit_img ); |
630 | QToolTip::add( Edit, tr( "Edit category or entry" ) ); | 629 | QToolTip::add( Edit, tr( "Edit category or entry" ) ); |
631 | 630 | ||
632 | Delete = new QToolButton( menu, "Delete" ); | 631 | Delete = new QToolButton( menu, "Delete" ); |
633 | Delete->setGeometry( QRect( DeskW-44, 2, 20, 20 ) ); | 632 | Delete->setGeometry( QRect( DeskW-44, 2, 20, 20 ) ); |
634 | Delete->setText( tr( "" ) ); | 633 | Delete->setText( tr( "" ) ); |
635 | Delete->setPixmap( trash_img ); | 634 | Delete->setPixmap( trash_img ); |
636 | QToolTip::add( Delete, tr( "Delete category or entry" ) ); | 635 | QToolTip::add( Delete, tr( "Delete category or entry" ) ); |
637 | 636 | ||
638 | Find = new QToolButton( menu, "Find" ); | 637 | Find = new QToolButton( menu, "Find" ); |
639 | Find->setGeometry( QRect( DeskW-24, 2, 20, 20 ) ); | 638 | Find->setGeometry( QRect( DeskW-24, 2, 20, 20 ) ); |
640 | Find->setText( tr( "" ) ); | 639 | Find->setText( tr( "" ) ); |
641 | Find->setPixmap( find_img ); | 640 | Find->setPixmap( find_img ); |
642 | QToolTip::add( Find, tr( "Find entry" ) ); | 641 | QToolTip::add( Find, tr( "Find entry" ) ); |
643 | 642 | ||
644 | /* | 643 | /* |
645 | QBoxLayout * h = new QHBoxLayout( this ); | 644 | QBoxLayout * h = new QHBoxLayout( this ); |
646 | h->addWidget (menu); | 645 | h->addWidget (menu); |
647 | h->addWidget (New); | 646 | h->addWidget (New); |
648 | h->addWidget (Edit); | 647 | h->addWidget (Edit); |
649 | h->addWidget (Delete); | 648 | h->addWidget (Delete); |
650 | h->addWidget (Find); | 649 | h->addWidget (Find); |
651 | */ | 650 | */ |
652 | 651 | ||
653 | ListView = new ZListView( this, "ListView" ); | 652 | ListView = new ZListView( this, "ListView" ); |
654 | ListView->addColumn( tr( "Name" ) ); | 653 | ListView->addColumn( tr( "Name" ) ); |
655 | ListView->addColumn( tr( "Field 2" ) ); | 654 | ListView->addColumn( tr( "Field 2" ) ); |
656 | ListView->addColumn( tr( "Field 3" ) ); | 655 | ListView->addColumn( tr( "Field 3" ) ); |
657 | ListView->addColumn( tr( "Comment" ) ); | 656 | ListView->addColumn( tr( "Comment" ) ); |
658 | ListView->addColumn( tr( "Field 4" ) ); | 657 | ListView->addColumn( tr( "Field 4" ) ); |
659 | ListView->addColumn( tr( "Field 5" ) ); | 658 | ListView->addColumn( tr( "Field 5" ) ); |
660 | ListView->setAllColumnsShowFocus(TRUE); | 659 | ListView->setAllColumnsShowFocus(TRUE); |
661 | 660 | ||
662 | #ifdef DESKTOP | 661 | #ifdef DESKTOP |
663 | ListView->setResizePolicy(QScrollView::AutoOneFit); | 662 | ListView->setResizePolicy(QScrollView::AutoOneFit); |
664 | // ListView->setGeometry( QRect( 0, 22, this->width(), this->height() - 30 ) ); | 663 | // ListView->setGeometry( QRect( 0, 22, this->width(), this->height() - 30 ) ); |
665 | #else | 664 | #else |
666 | ListView->setResizePolicy(QScrollView::AutoOneFit); | 665 | ListView->setResizePolicy(QScrollView::AutoOneFit); |
667 | // ListView->setGeometry( QRect( 0, 22, | 666 | // ListView->setGeometry( QRect( 0, 22, |
668 | // this->width(), this->height() - 30 ) ); | 667 | // this->width(), this->height() - 30 ) ); |
669 | // ListView->setMaximumSize( QSize( 440, 290 ) ); | 668 | // ListView->setMaximumSize( QSize( 440, 290 ) ); |
670 | #endif | 669 | #endif |
671 | ListView->setVScrollBarMode( QListView::Auto ); | 670 | ListView->setVScrollBarMode( QListView::Auto ); |
672 | 671 | ||
673 | QBoxLayout * l = new QVBoxLayout( this ); | 672 | QBoxLayout * l = new QVBoxLayout( this ); |
674 | l->addWidget (menu); | 673 | l->addWidget (menu); |
675 | l->addWidget (ListView); | 674 | l->addWidget (ListView); |
676 | 675 | ||
677 | #ifndef DESKTOP | 676 | #ifndef DESKTOP |
678 | // start a timer (100 ms) to load the default document | 677 | // start a timer (100 ms) to load the default document |
679 | docuTimer.start( 100, true ); | 678 | docuTimer.start( 100, true ); |
680 | connect( &docuTimer, SIGNAL(timeout()), SLOT( slotLoadDocu() ) ); | 679 | connect( &docuTimer, SIGNAL(timeout()), SLOT( slotLoadDocu() ) ); |
681 | raiseFlag = true; | 680 | raiseFlag = true; |
682 | connect( &raiseTimer, SIGNAL(timeout()), SLOT( slotRaiseTimer() ) ); | 681 | connect( &raiseTimer, SIGNAL(timeout()), SLOT( slotRaiseTimer() ) ); |
683 | #else | 682 | #else |
684 | // open the default document | 683 | // open the default document |
685 | openDocument(filename); | 684 | openDocument(filename); |
686 | #endif | 685 | #endif |
687 | 686 | ||
688 | // signals and slots connections for QTollButton | 687 | // signals and slots connections for QTollButton |
689 | connect( New, SIGNAL( clicked() ), this, SLOT( newPwd() ) ); | 688 | connect( New, SIGNAL( clicked() ), this, SLOT( newPwd() ) ); |
690 | connect( Edit, SIGNAL( clicked() ), this, SLOT( editPwd() ) ); | 689 | connect( Edit, SIGNAL( clicked() ), this, SLOT( editPwd() ) ); |
691 | connect( Delete, SIGNAL( clicked() ), this, SLOT( deletePwd() ) ); | 690 | connect( Delete, SIGNAL( clicked() ), this, SLOT( deletePwd() ) ); |
692 | connect( Find, SIGNAL( clicked() ), this, SLOT( findPwd() ) ); | 691 | connect( Find, SIGNAL( clicked() ), this, SLOT( findPwd() ) ); |
693 | // signals and slots connections for QListView | 692 | // signals and slots connections for QListView |
694 | connect( ListView, SIGNAL( selectionChanged( QListViewItem* ) ), | 693 | connect( ListView, SIGNAL( selectionChanged( QListViewItem* ) ), |
695 | this, SLOT( listViewSelected( QListViewItem* ) ) ); | 694 | this, SLOT( listViewSelected( QListViewItem* ) ) ); |
696 | connect( ListView, SIGNAL( doubleClicked( QListViewItem* ) ), | 695 | connect( ListView, SIGNAL( doubleClicked( QListViewItem* ) ), |
697 | this, SLOT( showInfo( QListViewItem* ) ) ); | 696 | this, SLOT( showInfo( QListViewItem* ) ) ); |
698 | connect( ListView, SIGNAL( returnPressed( QListViewItem* ) ), | 697 | connect( ListView, SIGNAL( returnPressed( QListViewItem* ) ), |
699 | this, SLOT( showInfo( QListViewItem* ) ) ); | 698 | this, SLOT( showInfo( QListViewItem* ) ) ); |
700 | 699 | ||
701 | } | 700 | } |
702 | 701 | ||
703 | const QColor *ZSafe::evenRowColor = &Qt::white; | 702 | const QColor *ZSafe::evenRowColor = &Qt::white; |
704 | // const QColor *ZSafe::oddRowColor = &Qt::lightGray; | 703 | // const QColor *ZSafe::oddRowColor = &Qt::lightGray; |
705 | const QColor *ZSafe::oddRowColor = new QColor(216,240,255); | 704 | const QColor *ZSafe::oddRowColor = new QColor(216,240,255); |
706 | 705 | ||
707 | /* | 706 | /* |
708 | * Destroys the object and frees any allocated resources | 707 | * Destroys the object and frees any allocated resources |
709 | */ | 708 | */ |
710 | ZSafe::~ZSafe() | 709 | ZSafe::~ZSafe() |
711 | { | 710 | { |
712 | // no need to delete child widgets, Qt does it all for us | 711 | // no need to delete child widgets, Qt does it all for us |
713 | quitMe(); | 712 | quitMe(); |
714 | } | 713 | } |
715 | 714 | ||
716 | // load the default document | 715 | // load the default document |
717 | void ZSafe::slotLoadDocu() | 716 | void ZSafe::slotLoadDocu() |
718 | { | 717 | { |
719 | openDocument (filename); | 718 | openDocument (filename); |
720 | } | 719 | } |
721 | 720 | ||
722 | void ZSafe::deletePwd() | 721 | void ZSafe::deletePwd() |
723 | { | 722 | { |
724 | 723 | ||
725 | if (!selectedItem) | 724 | if (!selectedItem) |
726 | return; | 725 | return; |
727 | if (!isCategory(selectedItem)) | 726 | if (!isCategory(selectedItem)) |
728 | { | 727 | { |
729 | switch( QMessageBox::information( this, tr("ZSafe"), | 728 | switch( QMessageBox::information( this, tr("ZSafe"), |
730 | tr("Do you want to delete?"), | 729 | tr("Do you want to delete?"), |
731 | tr("&Delete"), tr("D&on't Delete"), | 730 | tr("&Delete"), tr("D&on't Delete"), |
732 | 0 // Enter == button 0 | 731 | 0 // Enter == button 0 |
733 | ) ) { // Escape == button 2 | 732 | ) ) { // Escape == button 2 |
734 | case 0: // Delete clicked, Alt-S or Enter pressed. | 733 | case 0: // Delete clicked, Alt-S or Enter pressed. |
735 | // Delete | 734 | // Delete |
736 | modified = true; | 735 | modified = true; |
737 | selectedItem->parent()->takeItem(selectedItem); | 736 | selectedItem->parent()->takeItem(selectedItem); |
738 | selectedItem = NULL; | 737 | selectedItem = NULL; |
739 | break; | 738 | break; |
740 | case 1: // Don't delete | 739 | case 1: // Don't delete |
741 | break; | 740 | break; |
742 | } | 741 | } |
743 | } | 742 | } |
744 | else | 743 | else |
745 | { | 744 | { |
746 | delCategory(); | 745 | delCategory(); |
747 | } | 746 | } |
748 | } | 747 | } |
749 | 748 | ||
750 | void ZSafe::editPwd() | 749 | void ZSafe::editPwd() |
751 | { | 750 | { |
752 | if (!selectedItem) | 751 | if (!selectedItem) |
753 | return; | 752 | return; |
754 | if (!isCategory(selectedItem)) | 753 | if (!isCategory(selectedItem)) |
755 | { | 754 | { |
756 | // open the 'New Entry' dialog | 755 | // open the 'New Entry' dialog |
757 | NewDialog *dialog = new NewDialog(this, tr("Edit Entry"), TRUE); | 756 | NewDialog *dialog = new NewDialog(this, tr("Edit Entry"), TRUE); |
758 | #ifdef WIN32 | 757 | #ifdef WIN32 |
759 | dialog->setCaption ("Qt " + tr("Edit Entry")); | 758 | dialog->setCaption ("Qt " + tr("Edit Entry")); |
760 | dialog->setGeometry(200, 250, 220, 310 ); | 759 | dialog->setGeometry(200, 250, 220, 310 ); |
761 | #endif | 760 | #endif |
762 | 761 | ||
763 | // set the labels | 762 | // set the labels |
764 | dialog->Name->setText(getFieldLabel (selectedItem, "1", tr("Name"))); | 763 | dialog->Name->setText(getFieldLabel (selectedItem, "1", tr("Name"))); |
765 | dialog->Username->setText(getFieldLabel (selectedItem, "2", tr("Username"))); | 764 | dialog->Username->setText(getFieldLabel (selectedItem, "2", tr("Username"))); |
766 | dialog->Password->setText(getFieldLabel (selectedItem, "3", tr("Password"))); | 765 | dialog->Password->setText(getFieldLabel (selectedItem, "3", tr("Password"))); |
767 | dialog->Comment->setText(getFieldLabel (selectedItem, "4", tr("Comment"))); | 766 | dialog->Comment->setText(getFieldLabel (selectedItem, "4", tr("Comment"))); |
768 | dialog->Field5Label->setText(getFieldLabel (selectedItem,"5", tr("Field 4"))); | 767 | dialog->Field5Label->setText(getFieldLabel (selectedItem,"5", tr("Field 4"))); |
769 | dialog->Field6Label->setText(getFieldLabel (selectedItem,"6", tr("Field 5"))); | 768 | dialog->Field6Label->setText(getFieldLabel (selectedItem,"6", tr("Field 5"))); |
770 | 769 | ||
771 | // set the fields | 770 | // set the fields |
772 | dialog->NameField->setText(selectedItem->text (0)); | 771 | dialog->NameField->setText(selectedItem->text (0)); |
773 | dialog->UsernameField->setText(selectedItem->text (1)); | 772 | dialog->UsernameField->setText(selectedItem->text (1)); |
774 | dialog->PasswordField->setText(selectedItem->text (2)); | 773 | dialog->PasswordField->setText(selectedItem->text (2)); |
775 | QString comment = selectedItem->text (3); | 774 | QString comment = selectedItem->text (3); |
776 | comment.replace (QRegExp("<br>"), "\n"); | 775 | comment.replace (QRegExp("<br>"), "\n"); |
777 | dialog->Field5->setText(selectedItem->text (4)); | 776 | dialog->Field5->setText(selectedItem->text (4)); |
778 | dialog->Field6->setText(selectedItem->text (5)); | 777 | dialog->Field6->setText(selectedItem->text (5)); |
779 | dialog->CommentField->insertLine(comment); | 778 | dialog->CommentField->insertLine(comment); |
780 | dialog->CommentField->setCursorPosition(0,0); | 779 | dialog->CommentField->setCursorPosition(0,0); |
781 | 780 | ||
782 | DialogCode result = (DialogCode) QPEApplication::execDialog( dialog ); | 781 | DialogCode result = (DialogCode) QPEApplication::execDialog( dialog ); |
783 | 782 | ||
784 | #ifdef DESKTOP | 783 | #ifdef DESKTOP |
785 | result = Accepted; | 784 | result = Accepted; |
786 | #endif | 785 | #endif |
787 | if (result == Accepted) | 786 | if (result == Accepted) |
788 | { | 787 | { |
789 | modified = true; | 788 | modified = true; |
790 | // edit the selected item | 789 | // edit the selected item |
791 | QString name = dialog->NameField->text(); | 790 | QString name = dialog->NameField->text(); |
792 | selectedItem->setText (0, tr (name)); | 791 | selectedItem->setText (0, tr (name)); |
793 | QString user = dialog->UsernameField->text(); | 792 | QString user = dialog->UsernameField->text(); |
794 | selectedItem->setText (1, tr (user)); | 793 | selectedItem->setText (1, tr (user)); |
795 | QString pwd = dialog->PasswordField->text(); | 794 | QString pwd = dialog->PasswordField->text(); |
796 | selectedItem->setText (2, tr (pwd)); | 795 | selectedItem->setText (2, tr (pwd)); |
797 | QString comment = dialog->CommentField->text(); | 796 | QString comment = dialog->CommentField->text(); |
798 | comment.replace (QRegExp("\n"), "<br>"); | 797 | comment.replace (QRegExp("\n"), "<br>"); |
799 | selectedItem->setText (3, tr (comment)); | 798 | selectedItem->setText (3, tr (comment)); |
800 | QString f5 = dialog->Field5->text(); | 799 | QString f5 = dialog->Field5->text(); |
801 | selectedItem->setText (4, tr (f5)); | 800 | selectedItem->setText (4, tr (f5)); |
802 | QString f6 = dialog->Field6->text(); | 801 | QString f6 = dialog->Field6->text(); |
803 | selectedItem->setText (5, tr (f6)); | 802 | selectedItem->setText (5, tr (f6)); |
804 | } | 803 | } |
805 | 804 | ||
806 | delete dialog; | 805 | delete dialog; |
807 | } | 806 | } |
808 | else | 807 | else |
809 | { | 808 | { |
810 | editCategory(); | 809 | editCategory(); |
811 | } | 810 | } |
812 | } | 811 | } |
813 | 812 | ||
814 | void ZSafe::newPwd() | 813 | void ZSafe::newPwd() |
815 | { | 814 | { |
816 | if (!selectedItem) | 815 | if (!selectedItem) |
817 | return; | 816 | return; |
818 | 817 | ||
819 | if (!isCategory(selectedItem)) | 818 | if (!isCategory(selectedItem)) |
820 | selectedItem = selectedItem->parent(); | 819 | selectedItem = selectedItem->parent(); |
821 | 820 | ||
822 | if (isCategory(selectedItem)) | 821 | if (isCategory(selectedItem)) |
823 | { | 822 | { |
824 | QString cat = selectedItem->text(0); | 823 | QString cat = selectedItem->text(0); |
825 | 824 | ||
826 | // open the 'New Entry' dialog | 825 | // open the 'New Entry' dialog |
827 | NewDialog *dialog = new NewDialog(this, tr("New Entry"), TRUE); | 826 | NewDialog *dialog = new NewDialog(this, tr("New Entry"), TRUE); |
828 | #ifdef WIN32 | 827 | #ifdef WIN32 |
829 | dialog->setCaption ("Qt " + tr("New Entry")); | 828 | dialog->setCaption ("Qt " + tr("New Entry")); |
830 | dialog->setGeometry(200, 250, 220, 310 ); | 829 | dialog->setGeometry(200, 250, 220, 310 ); |
831 | #endif | 830 | #endif |
832 | // set the labels | 831 | // set the labels |
833 | dialog->Name->setText(getFieldLabel (selectedItem, "1", tr("Name"))); | 832 | dialog->Name->setText(getFieldLabel (selectedItem, "1", tr("Name"))); |
834 | dialog->Username->setText(getFieldLabel (selectedItem, "2", tr("Username"))); | 833 | dialog->Username->setText(getFieldLabel (selectedItem, "2", tr("Username"))); |
835 | dialog->Password->setText(getFieldLabel (selectedItem, "3", tr("Password"))); | 834 | dialog->Password->setText(getFieldLabel (selectedItem, "3", tr("Password"))); |
836 | dialog->Comment->setText(getFieldLabel (selectedItem, "4", tr("Comment"))); | 835 | dialog->Comment->setText(getFieldLabel (selectedItem, "4", tr("Comment"))); |
837 | dialog->Field5Label->setText(getFieldLabel (selectedItem,"5", tr("Field 4"))); | 836 | dialog->Field5Label->setText(getFieldLabel (selectedItem,"5", tr("Field 4"))); |
838 | dialog->Field6Label->setText(getFieldLabel (selectedItem,"6", tr("Field 5"))); | 837 | dialog->Field6Label->setText(getFieldLabel (selectedItem,"6", tr("Field 5"))); |
839 | retype: | 838 | retype: |
840 | 839 | ||
841 | DialogCode result = (DialogCode) QPEApplication::execDialog( dialog ); | 840 | DialogCode result = (DialogCode) QPEApplication::execDialog( dialog ); |
842 | #ifdef DESKTOP | 841 | #ifdef DESKTOP |
843 | result = Accepted; | 842 | result = Accepted; |
844 | #endif | 843 | #endif |
845 | 844 | ||
846 | if (result == Accepted) | 845 | if (result == Accepted) |
847 | { | 846 | { |
848 | 847 | ||
849 | QString name = dialog->NameField->text(); | 848 | QString name = dialog->NameField->text(); |
850 | if (cat == name) | 849 | if (cat == name) |
diff --git a/noncore/comm/keypebble/krfbbuffer.cpp b/noncore/comm/keypebble/krfbbuffer.cpp index f1cb929..92918d4 100644 --- a/noncore/comm/keypebble/krfbbuffer.cpp +++ b/noncore/comm/keypebble/krfbbuffer.cpp | |||
@@ -1,203 +1,200 @@ | |||
1 | #include <assert.h> | 1 | #include <assert.h> |
2 | #include <qpixmap.h> | ||
3 | #include <qbrush.h> | ||
4 | #include <qimage.h> | 2 | #include <qimage.h> |
5 | #include <qpainter.h> | 3 | #include <qpainter.h> |
6 | #include <qapplication.h> | 4 | #include <qapplication.h> |
7 | #include "krfbdecoder.h" | 5 | #include "krfbdecoder.h" |
8 | #include "krfbbuffer.h" | 6 | #include "krfbbuffer.h" |
9 | #include "krfbconnection.h" | 7 | #include "krfbconnection.h" |
10 | #include "krfbserver.h" | ||
11 | #include "krfbserverinfo.h" | 8 | #include "krfbserverinfo.h" |
12 | 9 | ||
13 | // | 10 | // |
14 | // Endian stuff | 11 | // Endian stuff |
15 | // | 12 | // |
16 | #ifndef KDE_USE_FINAL | 13 | #ifndef KDE_USE_FINAL |
17 | const int endianTest = 1; | 14 | const int endianTest = 1; |
18 | #endif | 15 | #endif |
19 | 16 | ||
20 | #define Swap16IfLE(s) \ | 17 | #define Swap16IfLE(s) \ |
21 | (*(char *)&endianTest ? ((((s) & 0xff) << 8) | (((s) >> 8) & 0xff)) : (s)) | 18 | (*(char *)&endianTest ? ((((s) & 0xff) << 8) | (((s) >> 8) & 0xff)) : (s)) |
22 | 19 | ||
23 | #define Swap32IfLE(l) \ | 20 | #define Swap32IfLE(l) \ |
24 | (*(char *)&endianTest ? ((((l) & 0xff000000) >> 24) | \ | 21 | (*(char *)&endianTest ? ((((l) & 0xff000000) >> 24) | \ |
25 | (((l) & 0x00ff0000) >> 8) | \ | 22 | (((l) & 0x00ff0000) >> 8) | \ |
26 | (((l) & 0x0000ff00) << 8) | \ | 23 | (((l) & 0x0000ff00) << 8) | \ |
27 | (((l) & 0x000000ff) << 24)) : (l)) | 24 | (((l) & 0x000000ff) << 24)) : (l)) |
28 | 25 | ||
29 | KRFBBuffer::KRFBBuffer( KRFBDecoder *decoder, | 26 | KRFBBuffer::KRFBBuffer( KRFBDecoder *decoder, |
30 | QObject *parent, const char *name ) | 27 | QObject *parent, const char *name ) |
31 | : QObject( parent, name ) | 28 | : QObject( parent, name ) |
32 | { | 29 | { |
33 | assert( decoder ); | 30 | assert( decoder ); |
34 | this->decoder = decoder; | 31 | this->decoder = decoder; |
35 | pix = new QPixmap(); | 32 | pix = new QPixmap(); |
36 | } | 33 | } |
37 | 34 | ||
38 | KRFBBuffer::~KRFBBuffer() | 35 | KRFBBuffer::~KRFBBuffer() |
39 | { | 36 | { |
40 | delete pix; | 37 | delete pix; |
41 | } | 38 | } |
42 | 39 | ||
43 | void KRFBBuffer::resize( int w, int h ) | 40 | void KRFBBuffer::resize( int w, int h ) |
44 | { | 41 | { |
45 | qWarning( "Resizing buffer" ); | 42 | qWarning( "Resizing buffer" ); |
46 | 43 | ||
47 | pix->resize( w, h ); | 44 | pix->resize( w, h ); |
48 | 45 | ||
49 | QPalette pal = qApp->palette(); | 46 | QPalette pal = qApp->palette(); |
50 | pix->fill( pal.active().base() ); | 47 | pix->fill( pal.active().base() ); |
51 | 48 | ||
52 | emit sizeChanged( w, h ); | 49 | emit sizeChanged( w, h ); |
53 | } | 50 | } |
54 | 51 | ||
55 | void KRFBBuffer::soundBell() | 52 | void KRFBBuffer::soundBell() |
56 | { | 53 | { |
57 | emit bell(); | 54 | emit bell(); |
58 | } | 55 | } |
59 | 56 | ||
60 | void KRFBBuffer::mouseEvent( QMouseEvent *e ) | 57 | void KRFBBuffer::mouseEvent( QMouseEvent *e ) |
61 | { | 58 | { |
62 | decoder->sendMouseEvent( e ); | 59 | decoder->sendMouseEvent( e ); |
63 | } | 60 | } |
64 | 61 | ||
65 | void KRFBBuffer::keyPressEvent( QKeyEvent *e ) | 62 | void KRFBBuffer::keyPressEvent( QKeyEvent *e ) |
66 | { | 63 | { |
67 | qWarning( "Buffer got a key" ); | 64 | qWarning( "Buffer got a key" ); |
68 | 65 | ||
69 | decoder->sendKeyPressEvent( e ); | 66 | decoder->sendKeyPressEvent( e ); |
70 | } | 67 | } |
71 | 68 | ||
72 | void KRFBBuffer::keyReleaseEvent( QKeyEvent *e ) | 69 | void KRFBBuffer::keyReleaseEvent( QKeyEvent *e ) |
73 | { | 70 | { |
74 | decoder->sendKeyReleaseEvent( e ); | 71 | decoder->sendKeyReleaseEvent( e ); |
75 | } | 72 | } |
76 | 73 | ||
77 | void KRFBBuffer::copyRect( int srcX, int srcY, | 74 | void KRFBBuffer::copyRect( int srcX, int srcY, |
78 | int destX, int destY, int w, int h ) | 75 | int destX, int destY, int w, int h ) |
79 | { | 76 | { |
80 | // qWarning( "Got copy rect" ); | 77 | // qWarning( "Got copy rect" ); |
81 | bitBlt( pix, destX, destY, pix, srcX, srcY, w, h, CopyROP ); | 78 | bitBlt( pix, destX, destY, pix, srcX, srcY, w, h, CopyROP ); |
82 | 79 | ||
83 | emit updated( destX, destY, w, h ); | 80 | emit updated( destX, destY, w, h ); |
84 | } | 81 | } |
85 | 82 | ||
86 | void KRFBBuffer::drawRawRectChunk( void *data, | 83 | void KRFBBuffer::drawRawRectChunk( void *data, |
87 | int x, int y, int w, int h ) | 84 | int x, int y, int w, int h ) |
88 | { | 85 | { |
89 | QImage img( w, h, 32 ); | 86 | QImage img( w, h, 32 ); |
90 | 87 | ||
91 | int scaleFactor=decoder->con->options()->scaleFactor; | 88 | int scaleFactor=decoder->con->options()->scaleFactor; |
92 | int redMax = Swap16IfLE( decoder->format->redMax ); | 89 | int redMax = Swap16IfLE( decoder->format->redMax ); |
93 | int greenMax = Swap16IfLE( decoder->format->greenMax ); | 90 | int greenMax = Swap16IfLE( decoder->format->greenMax ); |
94 | int blueMax = Swap16IfLE( decoder->format->blueMax ); | 91 | int blueMax = Swap16IfLE( decoder->format->blueMax ); |
95 | 92 | ||
96 | QPainter p( pix ); | 93 | QPainter p( pix ); |
97 | 94 | ||
98 | if ( decoder->format->bpp == 8 ) { | 95 | if ( decoder->format->bpp == 8 ) { |
99 | uchar *d = (unsigned char *) data; | 96 | uchar *d = (unsigned char *) data; |
100 | 97 | ||
101 | uint r,g,b; | 98 | uint r,g,b; |
102 | 99 | ||
103 | 100 | ||
104 | for ( int j = 0; j < h; j++) { | 101 | for ( int j = 0; j < h; j++) { |
105 | for ( int i = 0; i < w ; i++ ) { | 102 | for ( int i = 0; i < w ; i++ ) { |
106 | r = d[ j * w + i ]; | 103 | r = d[ j * w + i ]; |
107 | r = r >> decoder->format->redShift; | 104 | r = r >> decoder->format->redShift; |
108 | r = r & redMax; | 105 | r = r & redMax; |
109 | 106 | ||
110 | g = d[ j * w + i ]; | 107 | g = d[ j * w + i ]; |
111 | g = g >> decoder->format->greenShift; | 108 | g = g >> decoder->format->greenShift; |
112 | g = g & greenMax; | 109 | g = g & greenMax; |
113 | 110 | ||
114 | b = d[ j * w + i ]; | 111 | b = d[ j * w + i ]; |
115 | b = b >> decoder->format->blueShift; | 112 | b = b >> decoder->format->blueShift; |
116 | b = b & blueMax; | 113 | b = b & blueMax; |
117 | 114 | ||
118 | r = ( r * 255 ) / redMax; | 115 | r = ( r * 255 ) / redMax; |
119 | g = ( g * 255 ) / greenMax; | 116 | g = ( g * 255 ) / greenMax; |
120 | b = ( b * 255 ) / blueMax; | 117 | b = ( b * 255 ) / blueMax; |
121 | 118 | ||
122 | uint *p = ( uint * ) img.scanLine( j ) + i; | 119 | uint *p = ( uint * ) img.scanLine( j ) + i; |
123 | *p = qRgb( r,g,b ); | 120 | *p = qRgb( r,g,b ); |
124 | } | 121 | } |
125 | } | 122 | } |
126 | } | 123 | } |
127 | else if ( decoder->format->bpp == 32 ) { | 124 | else if ( decoder->format->bpp == 32 ) { |
128 | ulong *d = (ulong *) data; | 125 | ulong *d = (ulong *) data; |
129 | 126 | ||
130 | ulong r,g,b; | 127 | ulong r,g,b; |
131 | 128 | ||
132 | for ( int j = 0; j < h; j++ ) { | 129 | for ( int j = 0; j < h; j++ ) { |
133 | for ( int i = 0; i < w ; i++ ) { | 130 | for ( int i = 0; i < w ; i++ ) { |
134 | ulong pixel = d[ j * w + i ]; | 131 | ulong pixel = d[ j * w + i ]; |
135 | pixel = Swap32IfLE( pixel ); | 132 | pixel = Swap32IfLE( pixel ); |
136 | 133 | ||
137 | r = pixel; | 134 | r = pixel; |
138 | r = r >> decoder->format->redShift; | 135 | r = r >> decoder->format->redShift; |
139 | r = r & redMax; | 136 | r = r & redMax; |
140 | 137 | ||
141 | g = pixel; | 138 | g = pixel; |
142 | g = g >> decoder->format->greenShift; | 139 | g = g >> decoder->format->greenShift; |
143 | g = g & greenMax; | 140 | g = g & greenMax; |
144 | 141 | ||
145 | b = pixel; | 142 | b = pixel; |
146 | b = b >> decoder->format->blueShift; | 143 | b = b >> decoder->format->blueShift; |
147 | b = b & blueMax; | 144 | b = b & blueMax; |
148 | 145 | ||
149 | r = ( r * 255 ) / redMax; | 146 | r = ( r * 255 ) / redMax; |
150 | g = ( g * 255 ) / greenMax; | 147 | g = ( g * 255 ) / greenMax; |
151 | b = ( b * 255 ) / blueMax; | 148 | b = ( b * 255 ) / blueMax; |
152 | 149 | ||
153 | uint *p = ( uint * ) img.scanLine( j ) + i; | 150 | uint *p = ( uint * ) img.scanLine( j ) + i; |
154 | *p = qRgb( r,g,b ); | 151 | *p = qRgb( r,g,b ); |
155 | } | 152 | } |
156 | } | 153 | } |
157 | } else if (decoder->format->bpp == 16 ) { | 154 | } else if (decoder->format->bpp == 16 ) { |
158 | 155 | ||
159 | CARD16 *d = (CARD16 *) data; | 156 | CARD16 *d = (CARD16 *) data; |
160 | 157 | ||
161 | uint r,g,b; | 158 | uint r,g,b; |
162 | 159 | ||
163 | for ( int j = 0; j < h; j++ ) { | 160 | for ( int j = 0; j < h; j++ ) { |
164 | for ( int i = 0; i < w ; i++ ) { | 161 | for ( int i = 0; i < w ; i++ ) { |
165 | CARD16 pixel = d[ j * w + i ]; | 162 | CARD16 pixel = d[ j * w + i ]; |
166 | pixel = Swap16IfLE( pixel ); | 163 | pixel = Swap16IfLE( pixel ); |
167 | 164 | ||
168 | r = pixel; | 165 | r = pixel; |
169 | r = r >> decoder->format->redShift; | 166 | r = r >> decoder->format->redShift; |
170 | r = r & redMax; | 167 | r = r & redMax; |
171 | 168 | ||
172 | g = pixel; | 169 | g = pixel; |
173 | g = g >> decoder->format->greenShift; | 170 | g = g >> decoder->format->greenShift; |
174 | g = g & greenMax; | 171 | g = g & greenMax; |
175 | 172 | ||
176 | b = pixel; | 173 | b = pixel; |
177 | b = b >> decoder->format->blueShift; | 174 | b = b >> decoder->format->blueShift; |
178 | b = b & blueMax; | 175 | b = b & blueMax; |
179 | 176 | ||
180 | r = ( r * 255 ) / redMax; | 177 | r = ( r * 255 ) / redMax; |
181 | g = ( g * 255 ) / greenMax; | 178 | g = ( g * 255 ) / greenMax; |
182 | b = ( b * 255 ) / blueMax; | 179 | b = ( b * 255 ) / blueMax; |
183 | 180 | ||
184 | ulong *p = ( ulong * ) img.scanLine( j ) + i; | 181 | ulong *p = ( ulong * ) img.scanLine( j ) + i; |
185 | *p = qRgb( r,g,b ); | 182 | *p = qRgb( r,g,b ); |
186 | } | 183 | } |
187 | } | 184 | } |
188 | } | 185 | } |
189 | else { | 186 | else { |
190 | p.setBrush( QBrush( Qt::black ) ); | 187 | p.setBrush( QBrush( Qt::black ) ); |
191 | p.drawRect( x, y, w, h ); | 188 | p.drawRect( x, y, w, h ); |
192 | } | 189 | } |
193 | 190 | ||
194 | if (scaleFactor > 1) { | 191 | if (scaleFactor > 1) { |
195 | p.drawImage( x/scaleFactor, y/scaleFactor, img.smoothScale(w/scaleFactor,h/scaleFactor) ); | 192 | p.drawImage( x/scaleFactor, y/scaleFactor, img.smoothScale(w/scaleFactor,h/scaleFactor) ); |
196 | emit updated( x/scaleFactor, y/scaleFactor, w/scaleFactor, h/scaleFactor ); | 193 | emit updated( x/scaleFactor, y/scaleFactor, w/scaleFactor, h/scaleFactor ); |
197 | } | 194 | } |
198 | else { | 195 | else { |
199 | p.drawImage( x, y, img); | 196 | p.drawImage( x, y, img); |
200 | emit updated( x, y, w, h ); | 197 | emit updated( x, y, w, h ); |
201 | } | 198 | } |
202 | } | 199 | } |
203 | 200 | ||
diff --git a/noncore/comm/keypebble/krfbcanvas.cpp b/noncore/comm/keypebble/krfbcanvas.cpp index bc71c90..75cba68 100644 --- a/noncore/comm/keypebble/krfbcanvas.cpp +++ b/noncore/comm/keypebble/krfbcanvas.cpp | |||
@@ -1,209 +1,200 @@ | |||
1 | #include "krfbconnection.h" | 1 | #include "krfbconnection.h" |
2 | #include "krfbcanvas.h" | 2 | #include "krfbcanvas.h" |
3 | #include "krfbserver.h" | ||
4 | #include "krfbbuffer.h" | 3 | #include "krfbbuffer.h" |
5 | 4 | ||
6 | #include <qpe/config.h> | ||
7 | #include <qpe/qpeapplication.h> | 5 | #include <qpe/qpeapplication.h> |
8 | 6 | ||
9 | #include <qapplication.h> | ||
10 | #include <qclipboard.h> | 7 | #include <qclipboard.h> |
11 | #include <qaction.h> | ||
12 | #include <qpixmap.h> | ||
13 | #include <qpoint.h> | ||
14 | #include <qapplication.h> | ||
15 | #include <qmainwindow.h> | ||
16 | #include <qiconset.h> | ||
17 | 8 | ||
18 | KRFBCanvas::KRFBCanvas( QWidget *parent, const char *name ) | 9 | KRFBCanvas::KRFBCanvas( QWidget *parent, const char *name ) |
19 | : QScrollView( parent, name ) | 10 | : QScrollView( parent, name ) |
20 | { | 11 | { |
21 | connection_ = new KRFBConnection(); | 12 | connection_ = new KRFBConnection(); |
22 | connect( connection_, SIGNAL( loggedIn() ), | 13 | connect( connection_, SIGNAL( loggedIn() ), |
23 | this, SLOT( loggedIn() ) ); | 14 | this, SLOT( loggedIn() ) ); |
24 | 15 | ||
25 | loggedIn_ = false; | 16 | loggedIn_ = false; |
26 | 17 | ||
27 | //QPEApplication::setStylusOperation(viewport(), QPEApplication::RightOnHold); | 18 | //QPEApplication::setStylusOperation(viewport(), QPEApplication::RightOnHold); |
28 | 19 | ||
29 | viewport()->setFocusPolicy( QWidget::StrongFocus ); | 20 | viewport()->setFocusPolicy( QWidget::StrongFocus ); |
30 | viewport()->setFocus(); | 21 | viewport()->setFocus(); |
31 | 22 | ||
32 | nextRightClick=0; | 23 | nextRightClick=0; |
33 | nextDoubleClick=0; | 24 | nextDoubleClick=0; |
34 | } | 25 | } |
35 | 26 | ||
36 | KRFBCanvas::~KRFBCanvas() | 27 | KRFBCanvas::~KRFBCanvas() |
37 | { | 28 | { |
38 | } | 29 | } |
39 | 30 | ||
40 | 31 | ||
41 | void KRFBCanvas::openConnection(KRFBServer server) | 32 | void KRFBCanvas::openConnection(KRFBServer server) |
42 | { | 33 | { |
43 | 34 | ||
44 | 35 | ||
45 | QCString host = server.hostname.latin1(); | 36 | QCString host = server.hostname.latin1(); |
46 | password=server.password; | 37 | password=server.password; |
47 | connection_->connectTo( server); | 38 | connection_->connectTo( server); |
48 | } | 39 | } |
49 | 40 | ||
50 | 41 | ||
51 | void KRFBCanvas::openURL( const QUrl &url ) | 42 | void KRFBCanvas::openURL( const QUrl &url ) |
52 | { | 43 | { |
53 | if ( loggedIn_ ) { | 44 | if ( loggedIn_ ) { |
54 | qWarning( "openURL invoked when logged in\n" ); | 45 | qWarning( "openURL invoked when logged in\n" ); |
55 | return; | 46 | return; |
56 | } | 47 | } |
57 | 48 | ||
58 | QCString host = url.host().latin1(); | 49 | QCString host = url.host().latin1(); |
59 | int display = url.port(); | 50 | int display = url.port(); |
60 | 51 | ||
61 | // connection_->connectTo( host, display ); | 52 | // connection_->connectTo( host, display ); |
62 | } | 53 | } |
63 | 54 | ||
64 | void KRFBCanvas::closeConnection() | 55 | void KRFBCanvas::closeConnection() |
65 | { | 56 | { |
66 | loggedIn_ = false; | 57 | loggedIn_ = false; |
67 | connection_->disconnect(); | 58 | connection_->disconnect(); |
68 | 59 | ||
69 | viewport()->setMouseTracking( false ); | 60 | viewport()->setMouseTracking( false ); |
70 | viewport()->setBackgroundMode( PaletteDark ); | 61 | viewport()->setBackgroundMode( PaletteDark ); |
71 | setBackgroundMode( PaletteDark ); | 62 | setBackgroundMode( PaletteDark ); |
72 | update(); | 63 | update(); |
73 | } | 64 | } |
74 | 65 | ||
75 | 66 | ||
76 | void KRFBCanvas::bell() | 67 | void KRFBCanvas::bell() |
77 | { | 68 | { |
78 | if ( connection_->options()->deIconify ) { | 69 | if ( connection_->options()->deIconify ) { |
79 | topLevelWidget()->raise(); | 70 | topLevelWidget()->raise(); |
80 | topLevelWidget()->show(); | 71 | topLevelWidget()->show(); |
81 | } | 72 | } |
82 | } | 73 | } |
83 | 74 | ||
84 | void KRFBCanvas::loggedIn() | 75 | void KRFBCanvas::loggedIn() |
85 | { | 76 | { |
86 | qWarning( "Ok, we're logged in" ); | 77 | qWarning( "Ok, we're logged in" ); |
87 | 78 | ||
88 | // | 79 | // |
89 | // Get ready for action | 80 | // Get ready for action |
90 | // | 81 | // |
91 | loggedIn_ = true; | 82 | loggedIn_ = true; |
92 | viewport()->setMouseTracking( true ); | 83 | viewport()->setMouseTracking( true ); |
93 | viewport()->setBackgroundMode( NoBackground ); | 84 | viewport()->setBackgroundMode( NoBackground ); |
94 | setBackgroundMode( NoBackground ); | 85 | setBackgroundMode( NoBackground ); |
95 | 86 | ||
96 | // Start using the buffer | 87 | // Start using the buffer |
97 | connect( connection_->buffer(), SIGNAL( sizeChanged( int, int ) ), | 88 | connect( connection_->buffer(), SIGNAL( sizeChanged( int, int ) ), |
98 | this, SLOT( resizeContents(int,int) ) ); | 89 | this, SLOT( resizeContents(int,int) ) ); |
99 | connect( connection_->buffer(), SIGNAL( updated( int, int, int, int ) ), | 90 | connect( connection_->buffer(), SIGNAL( updated( int, int, int, int ) ), |
100 | this, SLOT( viewportUpdate(int,int,int,int) ) ); | 91 | this, SLOT( viewportUpdate(int,int,int,int) ) ); |
101 | connect( connection_->buffer(), SIGNAL( bell() ), | 92 | connect( connection_->buffer(), SIGNAL( bell() ), |
102 | this, SLOT( bell() ) ); | 93 | this, SLOT( bell() ) ); |
103 | connect( qApp->clipboard(), SIGNAL( dataChanged() ), | 94 | connect( qApp->clipboard(), SIGNAL( dataChanged() ), |
104 | this, SLOT( clipboardChanged() ) ); | 95 | this, SLOT( clipboardChanged() ) ); |
105 | } | 96 | } |
106 | 97 | ||
107 | void KRFBCanvas::viewportPaintEvent( QPaintEvent *e ) | 98 | void KRFBCanvas::viewportPaintEvent( QPaintEvent *e ) |
108 | { | 99 | { |
109 | QRect r = e->rect(); | 100 | QRect r = e->rect(); |
110 | 101 | ||
111 | if ( loggedIn_ ) { | 102 | if ( loggedIn_ ) { |
112 | QPixmap p; | 103 | QPixmap p; |
113 | 104 | ||
114 | bitBlt( viewport(), r.x(), r.y(), | 105 | bitBlt( viewport(), r.x(), r.y(), |
115 | connection_->buffer()->pixmap(), | 106 | connection_->buffer()->pixmap(), |
116 | r.x() + contentsX(), r.y() + contentsY(), | 107 | r.x() + contentsX(), r.y() + contentsY(), |
117 | r.width(), r.height() ); | 108 | r.width(), r.height() ); |
118 | } | 109 | } |
119 | else { | 110 | else { |
120 | QScrollView::viewportPaintEvent( e ); | 111 | QScrollView::viewportPaintEvent( e ); |
121 | } | 112 | } |
122 | } | 113 | } |
123 | 114 | ||
124 | void KRFBCanvas::viewportUpdate( int x, int y, int w, int h ) | 115 | void KRFBCanvas::viewportUpdate( int x, int y, int w, int h ) |
125 | { | 116 | { |
126 | updateContents( x, y, w, h ); | 117 | updateContents( x, y, w, h ); |
127 | } | 118 | } |
128 | 119 | ||
129 | void KRFBCanvas::contentsMousePressEvent( QMouseEvent *e ) | 120 | void KRFBCanvas::contentsMousePressEvent( QMouseEvent *e ) |
130 | { | 121 | { |
131 | 122 | ||
132 | if (nextDoubleClick) { | 123 | if (nextDoubleClick) { |
133 | connection_->buffer()->mouseEvent( &QMouseEvent(QEvent::MouseButtonPress, e->pos(),LeftButton,LeftButton)); | 124 | connection_->buffer()->mouseEvent( &QMouseEvent(QEvent::MouseButtonPress, e->pos(),LeftButton,LeftButton)); |
134 | connection_->buffer()->mouseEvent( &QMouseEvent(QEvent::MouseButtonRelease, e->pos(),LeftButton,0)); | 125 | connection_->buffer()->mouseEvent( &QMouseEvent(QEvent::MouseButtonRelease, e->pos(),LeftButton,0)); |
135 | connection_->buffer()->mouseEvent( &QMouseEvent(QEvent::MouseButtonRelease, e->pos(),LeftButton,0)); | 126 | connection_->buffer()->mouseEvent( &QMouseEvent(QEvent::MouseButtonRelease, e->pos(),LeftButton,0)); |
136 | connection_->buffer()->mouseEvent( &QMouseEvent(QEvent::MouseButtonPress, e->pos(),NoButton,NoButton)); | 127 | connection_->buffer()->mouseEvent( &QMouseEvent(QEvent::MouseButtonPress, e->pos(),NoButton,NoButton)); |
137 | connection_->buffer()->mouseEvent( &QMouseEvent(QEvent::MouseButtonRelease, e->pos(),NoButton,0)); | 128 | connection_->buffer()->mouseEvent( &QMouseEvent(QEvent::MouseButtonRelease, e->pos(),NoButton,0)); |
138 | } if (nextRightClick) { | 129 | } if (nextRightClick) { |
139 | connection_->buffer()->mouseEvent( &QMouseEvent(QEvent::MouseButtonPress, e->pos(),RightButton,RightButton)); | 130 | connection_->buffer()->mouseEvent( &QMouseEvent(QEvent::MouseButtonPress, e->pos(),RightButton,RightButton)); |
140 | connection_->buffer()->mouseEvent( &QMouseEvent(QEvent::MouseButtonRelease, e->pos(),RightButton,0)); | 131 | connection_->buffer()->mouseEvent( &QMouseEvent(QEvent::MouseButtonRelease, e->pos(),RightButton,0)); |
141 | connection_->buffer()->mouseEvent( &QMouseEvent(QEvent::MouseButtonPress, e->pos(),NoButton,NoButton)); | 132 | connection_->buffer()->mouseEvent( &QMouseEvent(QEvent::MouseButtonPress, e->pos(),NoButton,NoButton)); |
142 | connection_->buffer()->mouseEvent( &QMouseEvent(QEvent::MouseButtonRelease, e->pos(),NoButton,0)); | 133 | connection_->buffer()->mouseEvent( &QMouseEvent(QEvent::MouseButtonRelease, e->pos(),NoButton,0)); |
143 | } else if ( loggedIn_ ) | 134 | } else if ( loggedIn_ ) |
144 | connection_->buffer()->mouseEvent( e ); | 135 | connection_->buffer()->mouseEvent( e ); |
145 | 136 | ||
146 | } | 137 | } |
147 | 138 | ||
148 | void KRFBCanvas::contentsMouseReleaseEvent( QMouseEvent *e ) | 139 | void KRFBCanvas::contentsMouseReleaseEvent( QMouseEvent *e ) |
149 | { | 140 | { |
150 | if ( loggedIn_ && !nextRightClick && !nextDoubleClick) { | 141 | if ( loggedIn_ && !nextRightClick && !nextDoubleClick) { |
151 | connection_->buffer()->mouseEvent( e ); | 142 | connection_->buffer()->mouseEvent( e ); |
152 | } | 143 | } |
153 | 144 | ||
154 | nextRightClick=0; | 145 | nextRightClick=0; |
155 | nextDoubleClick=0; | 146 | nextDoubleClick=0; |
156 | } | 147 | } |
157 | 148 | ||
158 | void KRFBCanvas::contentsMouseMoveEvent( QMouseEvent *e ) | 149 | void KRFBCanvas::contentsMouseMoveEvent( QMouseEvent *e ) |
159 | { | 150 | { |
160 | if ( loggedIn_ ) | 151 | if ( loggedIn_ ) |
161 | connection_->buffer()->mouseEvent( e ); | 152 | connection_->buffer()->mouseEvent( e ); |
162 | } | 153 | } |
163 | 154 | ||
164 | void KRFBCanvas::keyPressEvent( QKeyEvent *e ) | 155 | void KRFBCanvas::keyPressEvent( QKeyEvent *e ) |
165 | { | 156 | { |
166 | if ( loggedIn_ ) | 157 | if ( loggedIn_ ) |
167 | connection_->buffer()->keyPressEvent( e ); | 158 | connection_->buffer()->keyPressEvent( e ); |
168 | } | 159 | } |
169 | 160 | ||
170 | void KRFBCanvas::keyReleaseEvent( QKeyEvent *e ) | 161 | void KRFBCanvas::keyReleaseEvent( QKeyEvent *e ) |
171 | { | 162 | { |
172 | if ( loggedIn_ ) | 163 | if ( loggedIn_ ) |
173 | connection_->buffer()->keyReleaseEvent( e ); | 164 | connection_->buffer()->keyReleaseEvent( e ); |
174 | } | 165 | } |
175 | 166 | ||
176 | void KRFBCanvas::refresh() | 167 | void KRFBCanvas::refresh() |
177 | { | 168 | { |
178 | if ( loggedIn_ ) | 169 | if ( loggedIn_ ) |
179 | connection_->refresh(); | 170 | connection_->refresh(); |
180 | } | 171 | } |
181 | 172 | ||
182 | void KRFBCanvas::clipboardChanged() | 173 | void KRFBCanvas::clipboardChanged() |
183 | { | 174 | { |
184 | if ( loggedIn_ ) { | 175 | if ( loggedIn_ ) { |
185 | connection_->sendCutText( qApp->clipboard()->text() ); | 176 | connection_->sendCutText( qApp->clipboard()->text() ); |
186 | } | 177 | } |
187 | } | 178 | } |
188 | void KRFBCanvas::sendCtlAltDel( void) | 179 | void KRFBCanvas::sendCtlAltDel( void) |
189 | { | 180 | { |
190 | 181 | ||
191 | if ( loggedIn_ ) { | 182 | if ( loggedIn_ ) { |
192 | connection_->buffer()->keyPressEvent( &QKeyEvent(QEvent::KeyPress,Qt::Key_Control, 0,0)); | 183 | connection_->buffer()->keyPressEvent( &QKeyEvent(QEvent::KeyPress,Qt::Key_Control, 0,0)); |
193 | connection_->buffer()->keyPressEvent( &QKeyEvent(QEvent::KeyPress,Qt::Key_Alt, 0,0)); | 184 | connection_->buffer()->keyPressEvent( &QKeyEvent(QEvent::KeyPress,Qt::Key_Alt, 0,0)); |
194 | connection_->buffer()->keyPressEvent( &QKeyEvent(QEvent::KeyPress,Qt::Key_Delete, 0,0)); | 185 | connection_->buffer()->keyPressEvent( &QKeyEvent(QEvent::KeyPress,Qt::Key_Delete, 0,0)); |
195 | connection_->buffer()->keyPressEvent( &QKeyEvent(QEvent::KeyRelease,Qt::Key_Control, 0,0)); | 186 | connection_->buffer()->keyPressEvent( &QKeyEvent(QEvent::KeyRelease,Qt::Key_Control, 0,0)); |
196 | connection_->buffer()->keyPressEvent( &QKeyEvent(QEvent::KeyRelease,Qt::Key_Alt, 0,0)); | 187 | connection_->buffer()->keyPressEvent( &QKeyEvent(QEvent::KeyRelease,Qt::Key_Alt, 0,0)); |
197 | connection_->buffer()->keyPressEvent( &QKeyEvent(QEvent::KeyRelease,Qt::Key_Delete, 0,0)); | 188 | connection_->buffer()->keyPressEvent( &QKeyEvent(QEvent::KeyRelease,Qt::Key_Delete, 0,0)); |
198 | } | 189 | } |
199 | } | 190 | } |
200 | 191 | ||
201 | void KRFBCanvas::markDoubleClick( void) | 192 | void KRFBCanvas::markDoubleClick( void) |
202 | { | 193 | { |
203 | nextRightClick=1; | 194 | nextRightClick=1; |
204 | } | 195 | } |
205 | 196 | ||
206 | void KRFBCanvas::markRightClick( void) | 197 | void KRFBCanvas::markRightClick( void) |
207 | { | 198 | { |
208 | nextRightClick=1; | 199 | nextRightClick=1; |
209 | } | 200 | } |
diff --git a/noncore/comm/keypebble/krfbconnection.cpp b/noncore/comm/keypebble/krfbconnection.cpp index 389c836..e6c33c6 100644 --- a/noncore/comm/keypebble/krfbconnection.cpp +++ b/noncore/comm/keypebble/krfbconnection.cpp | |||
@@ -1,234 +1,233 @@ | |||
1 | #include <assert.h> | 1 | #include <assert.h> |
2 | #include <qsocket.h> | 2 | #include <qsocket.h> |
3 | #include <qtimer.h> | 3 | #include <qtimer.h> |
4 | #include <string.h> | 4 | #include <string.h> |
5 | 5 | ||
6 | #include "krfbconnection.h" | 6 | #include "krfbconnection.h" |
7 | #include "krfblogin.h" | 7 | #include "krfblogin.h" |
8 | #include "krfbserver.h" | ||
9 | #include "krfbdecoder.h" | 8 | #include "krfbdecoder.h" |
10 | #include "krfbbuffer.h" | 9 | #include "krfbbuffer.h" |
11 | 10 | ||
12 | KRFBConnection::KRFBConnection( QObject *parent ) | 11 | KRFBConnection::KRFBConnection( QObject *parent ) |
13 | : QObject( parent, "KRFBConnection" ) | 12 | : QObject( parent, "KRFBConnection" ) |
14 | { | 13 | { |
15 | portBase_ = 5900; | 14 | portBase_ = 5900; |
16 | currentState_ = Disconnected; | 15 | currentState_ = Disconnected; |
17 | sock = 0; | 16 | sock = 0; |
18 | minData_ = 0; | 17 | minData_ = 0; |
19 | options_ = new KRFBServer(); | 18 | options_ = new KRFBServer(); |
20 | updater = 0; | 19 | updater = 0; |
21 | decoder_ = 0; | 20 | decoder_ = 0; |
22 | buffer_ = 0; | 21 | buffer_ = 0; |
23 | } | 22 | } |
24 | 23 | ||
25 | KRFBConnection::~KRFBConnection() | 24 | KRFBConnection::~KRFBConnection() |
26 | { | 25 | { |
27 | if ( ( currentState_ != Disconnected ) && ( currentState_ != Disconnecting ) && sock ) { | 26 | if ( ( currentState_ != Disconnected ) && ( currentState_ != Disconnecting ) && sock ) { |
28 | disconnectDone(); | 27 | disconnectDone(); |
29 | } | 28 | } |
30 | delete options_; | 29 | delete options_; |
31 | } | 30 | } |
32 | 31 | ||
33 | void KRFBConnection::connectTo( KRFBServer server) | 32 | void KRFBConnection::connectTo( KRFBServer server) |
34 | { | 33 | { |
35 | if ( currentState_ != Disconnected ) | 34 | if ( currentState_ != Disconnected ) |
36 | disconnect(); | 35 | disconnect(); |
37 | 36 | ||
38 | (*options_)=server; | 37 | (*options_)=server; |
39 | 38 | ||
40 | sock = new QSocket( this, "rfbSocket" ); | 39 | sock = new QSocket( this, "rfbSocket" ); |
41 | CHECK_PTR( sock ); | 40 | CHECK_PTR( sock ); |
42 | 41 | ||
43 | // Connect to something to notice connection or error | 42 | // Connect to something to notice connection or error |
44 | connect( sock, SIGNAL( error( int ) ), SLOT( gotSocketError( int ) ) ); | 43 | connect( sock, SIGNAL( error( int ) ), SLOT( gotSocketError( int ) ) ); |
45 | connect( sock, SIGNAL( connected() ), SLOT( gotSocketConnection() ) ); | 44 | connect( sock, SIGNAL( connected() ), SLOT( gotSocketConnection() ) ); |
46 | 45 | ||
47 | qWarning( "Connecting..." ); | 46 | qWarning( "Connecting..." ); |
48 | 47 | ||
49 | currentState_ = Connecting; | 48 | currentState_ = Connecting; |
50 | sock->connectToHost( options_->hostname.latin1(), portBase_ + options_->display ); | 49 | sock->connectToHost( options_->hostname.latin1(), portBase_ + options_->display ); |
51 | } | 50 | } |
52 | 51 | ||
53 | void KRFBConnection::disconnect() | 52 | void KRFBConnection::disconnect() |
54 | { | 53 | { |
55 | qWarning( "Disconnecting from server" ); | 54 | qWarning( "Disconnecting from server" ); |
56 | 55 | ||
57 | if ( ( currentState_ != Disconnected ) | 56 | if ( ( currentState_ != Disconnected ) |
58 | && ( currentState_ != Disconnecting ) | 57 | && ( currentState_ != Disconnecting ) |
59 | && sock ) { | 58 | && sock ) { |
60 | currentState_ = Disconnecting; | 59 | currentState_ = Disconnecting; |
61 | 60 | ||
62 | connect( sock, SIGNAL( delayedCloseFinished() ), SLOT( disconnectDone() ) ); | 61 | connect( sock, SIGNAL( delayedCloseFinished() ), SLOT( disconnectDone() ) ); |
63 | sock->close(); | 62 | sock->close(); |
64 | 63 | ||
65 | if ( sock->state() != QSocket::Closing ) | 64 | if ( sock->state() != QSocket::Closing ) |
66 | disconnectDone(); | 65 | disconnectDone(); |
67 | } | 66 | } |
68 | } | 67 | } |
69 | 68 | ||
70 | void KRFBConnection::disconnectDone() | 69 | void KRFBConnection::disconnectDone() |
71 | { | 70 | { |
72 | currentState_ = Disconnected; | 71 | currentState_ = Disconnected; |
73 | delete sock; | 72 | delete sock; |
74 | sock = 0; | 73 | sock = 0; |
75 | minData_ = 0; | 74 | minData_ = 0; |
76 | delete updater; | 75 | delete updater; |
77 | delete decoder_; | 76 | delete decoder_; |
78 | delete buffer_; | 77 | delete buffer_; |
79 | emit disconnected(); | 78 | emit disconnected(); |
80 | } | 79 | } |
81 | 80 | ||
82 | void KRFBConnection::gotSocketConnection() | 81 | void KRFBConnection::gotSocketConnection() |
83 | { | 82 | { |
84 | currentState_ = LoggingIn; | 83 | currentState_ = LoggingIn; |
85 | 84 | ||
86 | qWarning( "Connected, logging in..." ); | 85 | qWarning( "Connected, logging in..." ); |
87 | 86 | ||
88 | static QString statusMsg = tr( "Connected" ); | 87 | static QString statusMsg = tr( "Connected" ); |
89 | emit statusChanged( statusMsg ); | 88 | emit statusChanged( statusMsg ); |
90 | 89 | ||
91 | // Do some login stuff | 90 | // Do some login stuff |
92 | login = new KRFBLogin( this ); | 91 | login = new KRFBLogin( this ); |
93 | } | 92 | } |
94 | 93 | ||
95 | void KRFBConnection::gotRFBConnection() | 94 | void KRFBConnection::gotRFBConnection() |
96 | { | 95 | { |
97 | qWarning( "Logged into server" ); | 96 | qWarning( "Logged into server" ); |
98 | 97 | ||
99 | currentState_ = Connected; | 98 | currentState_ = Connected; |
100 | emit connected(); | 99 | emit connected(); |
101 | 100 | ||
102 | // Create the decoder and start doing stuff | 101 | // Create the decoder and start doing stuff |
103 | decoder_ = new KRFBDecoder( this ); | 102 | decoder_ = new KRFBDecoder( this ); |
104 | CHECK_PTR( decoder_ ); | 103 | CHECK_PTR( decoder_ ); |
105 | 104 | ||
106 | buffer_ = new KRFBBuffer( decoder_, this, "RFB Buffer" ); | 105 | buffer_ = new KRFBBuffer( decoder_, this, "RFB Buffer" ); |
107 | CHECK_PTR( buffer_ ); | 106 | CHECK_PTR( buffer_ ); |
108 | decoder_->setBuffer( buffer_ ); | 107 | decoder_->setBuffer( buffer_ ); |
109 | 108 | ||
110 | connect( decoder_, SIGNAL( status( const QString & ) ), | 109 | connect( decoder_, SIGNAL( status( const QString & ) ), |
111 | this, SIGNAL( statusChanged( const QString & ) ) ); | 110 | this, SIGNAL( statusChanged( const QString & ) ) ); |
112 | emit loggedIn(); | 111 | emit loggedIn(); |
113 | 112 | ||
114 | decoder_->start(); | 113 | decoder_->start(); |
115 | 114 | ||
116 | updater = new QTimer; | 115 | updater = new QTimer; |
117 | connect( updater, SIGNAL( timeout() ), SLOT( updateTimer() ) ); | 116 | connect( updater, SIGNAL( timeout() ), SLOT( updateTimer() ) ); |
118 | updater->start( options_->updateRate ); | 117 | updater->start( options_->updateRate ); |
119 | } | 118 | } |
120 | 119 | ||
121 | void KRFBConnection::gotSocketError( int err ) | 120 | void KRFBConnection::gotSocketError( int err ) |
122 | { | 121 | { |
123 | currentState_ = Error; | 122 | currentState_ = Error; |
124 | 123 | ||
125 | // Do some error handling stuff | 124 | // Do some error handling stuff |
126 | qWarning( "KRFBConnection: Socket error %d", err ); | 125 | qWarning( "KRFBConnection: Socket error %d", err ); |
127 | 126 | ||
128 | static QString refused = tr( "Connection Refused" ); | 127 | static QString refused = tr( "Connection Refused" ); |
129 | static QString host = tr( "Host not found" ); | 128 | static QString host = tr( "Host not found" ); |
130 | static QString read = tr( "Read Error: QSocket reported an error reading\n" | 129 | static QString read = tr( "Read Error: QSocket reported an error reading\n" |
131 | "data, the remote host has probably dropped the\n" | 130 | "data, the remote host has probably dropped the\n" |
132 | "connection." ); | 131 | "connection." ); |
133 | static QString confused = tr( "QSocket reported an invalid error code" ); | 132 | static QString confused = tr( "QSocket reported an invalid error code" ); |
134 | 133 | ||
135 | QString msg; | 134 | QString msg; |
136 | switch ( err ) { | 135 | switch ( err ) { |
137 | case QSocket::ErrConnectionRefused: | 136 | case QSocket::ErrConnectionRefused: |
138 | msg = refused; | 137 | msg = refused; |
139 | break; | 138 | break; |
140 | case QSocket::ErrHostNotFound: | 139 | case QSocket::ErrHostNotFound: |
141 | msg = host; | 140 | msg = host; |
142 | break; | 141 | break; |
143 | case QSocket::ErrSocketRead: | 142 | case QSocket::ErrSocketRead: |
144 | msg = read; | 143 | msg = read; |
145 | break; | 144 | break; |
146 | default: | 145 | default: |
147 | msg = confused; | 146 | msg = confused; |
148 | }; | 147 | }; |
149 | 148 | ||
150 | QObject::disconnect( sock, SIGNAL( readyRead() ), this, SLOT( gotMoreData() ) ); | 149 | QObject::disconnect( sock, SIGNAL( readyRead() ), this, SLOT( gotMoreData() ) ); |
151 | delete sock; | 150 | delete sock; |
152 | sock = 0; | 151 | sock = 0; |
153 | currentState_ = Disconnected; | 152 | currentState_ = Disconnected; |
154 | 153 | ||
155 | emit error( msg ); | 154 | emit error( msg ); |
156 | } | 155 | } |
157 | 156 | ||
158 | void KRFBConnection::gotMoreData() | 157 | void KRFBConnection::gotMoreData() |
159 | { | 158 | { |
160 | assert( minData_ > 0 ); | 159 | assert( minData_ > 0 ); |
161 | 160 | ||
162 | if ( sock->size() >= minData_ ) { | 161 | if ( sock->size() >= minData_ ) { |
163 | minData_ = 0; | 162 | minData_ = 0; |
164 | QObject::disconnect( sock, SIGNAL( readyRead() ), this, SLOT( gotMoreData() ) ); | 163 | QObject::disconnect( sock, SIGNAL( readyRead() ), this, SLOT( gotMoreData() ) ); |
165 | emit gotEnoughData(); | 164 | emit gotEnoughData(); |
166 | } | 165 | } |
167 | } | 166 | } |
168 | 167 | ||
169 | void KRFBConnection::waitForData( unsigned int sz ) | 168 | void KRFBConnection::waitForData( unsigned int sz ) |
170 | { | 169 | { |
171 | assert( minData_ == 0 ); | 170 | assert( minData_ == 0 ); |
172 | assert( sz > 0 ); | 171 | assert( sz > 0 ); |
173 | assert( currentState_ != Error ); | 172 | assert( currentState_ != Error ); |
174 | 173 | ||
175 | if ( sock->size() >= sz ) { | 174 | if ( sock->size() >= sz ) { |
176 | // qWarning( "No need to wait for data" ); | 175 | // qWarning( "No need to wait for data" ); |
177 | emit gotEnoughData(); | 176 | emit gotEnoughData(); |
178 | } | 177 | } |
179 | else { | 178 | else { |
180 | // qWarning( "Waiting for %u bytes", sz ); | 179 | // qWarning( "Waiting for %u bytes", sz ); |
181 | minData_ = sz; | 180 | minData_ = sz; |
182 | connect( sock, SIGNAL( readyRead() ), SLOT( gotMoreData() ) ); | 181 | connect( sock, SIGNAL( readyRead() ), SLOT( gotMoreData() ) ); |
183 | } | 182 | } |
184 | } | 183 | } |
185 | 184 | ||
186 | int KRFBConnection::read( void *buf, int sz ) | 185 | int KRFBConnection::read( void *buf, int sz ) |
187 | { | 186 | { |
188 | return sock->readBlock( (char *) buf, sz ); | 187 | return sock->readBlock( (char *) buf, sz ); |
189 | } | 188 | } |
190 | 189 | ||
191 | int KRFBConnection::write( void *buf, int sz ) | 190 | int KRFBConnection::write( void *buf, int sz ) |
192 | { | 191 | { |
193 | return sock->writeBlock( (const char *) buf, sz ); | 192 | return sock->writeBlock( (const char *) buf, sz ); |
194 | } | 193 | } |
195 | 194 | ||
196 | KRFBConnection::State KRFBConnection::state() const | 195 | KRFBConnection::State KRFBConnection::state() const |
197 | { | 196 | { |
198 | return currentState_; | 197 | return currentState_; |
199 | } | 198 | } |
200 | 199 | ||
201 | void KRFBConnection::setPortBase( int base ) | 200 | void KRFBConnection::setPortBase( int base ) |
202 | { | 201 | { |
203 | portBase_ = base; | 202 | portBase_ = base; |
204 | } | 203 | } |
205 | 204 | ||
206 | int KRFBConnection::portBase() const | 205 | int KRFBConnection::portBase() const |
207 | { | 206 | { |
208 | return portBase_; | 207 | return portBase_; |
209 | } | 208 | } |
210 | 209 | ||
211 | void KRFBConnection::updateTimer() | 210 | void KRFBConnection::updateTimer() |
212 | { | 211 | { |
213 | decoder_->sendUpdateRequest( true ); | 212 | decoder_->sendUpdateRequest( true ); |
214 | } | 213 | } |
215 | 214 | ||
216 | void KRFBConnection::refresh() | 215 | void KRFBConnection::refresh() |
217 | { | 216 | { |
218 | decoder_->sendUpdateRequest( false ); | 217 | decoder_->sendUpdateRequest( false ); |
219 | } | 218 | } |
220 | 219 | ||
221 | void KRFBConnection::sendCutText( const QString &text ) | 220 | void KRFBConnection::sendCutText( const QString &text ) |
222 | { | 221 | { |
223 | decoder_->sendCutEvent( text ); | 222 | decoder_->sendCutEvent( text ); |
224 | } | 223 | } |
225 | 224 | ||
226 | const QUrl &KRFBConnection::url() | 225 | const QUrl &KRFBConnection::url() |
227 | { | 226 | { |
228 | url_.setProtocol( "vnc" ); | 227 | url_.setProtocol( "vnc" ); |
229 | url_.setPort( display() ); | 228 | url_.setPort( display() ); |
230 | url_.setHost( host() ); | 229 | url_.setHost( host() ); |
231 | url_.setPath( "/" ); | 230 | url_.setPath( "/" ); |
232 | 231 | ||
233 | return url_; | 232 | return url_; |
234 | } | 233 | } |
diff --git a/noncore/comm/keypebble/krfbdecoder.cpp b/noncore/comm/keypebble/krfbdecoder.cpp index c43aed5..2c9ad71 100644 --- a/noncore/comm/keypebble/krfbdecoder.cpp +++ b/noncore/comm/keypebble/krfbdecoder.cpp | |||
@@ -1,781 +1,775 @@ | |||
1 | #include "krfbconnection.h" | 1 | #include "krfbconnection.h" |
2 | #include "krfbserver.h" | ||
3 | #include "krfbserverinfo.h" | 2 | #include "krfbserverinfo.h" |
4 | #include "krfbdecoder.h" | 3 | #include "krfbdecoder.h" |
5 | #include "krfbbuffer.h" | 4 | #include "krfbbuffer.h" |
6 | 5 | ||
7 | #include <qpe/qpeapplication.h> | ||
8 | 6 | ||
9 | #include <qpixmap.h> | 7 | #include <qpixmap.h> |
10 | #include <qsocket.h> | ||
11 | #include <qevent.h> | ||
12 | #include <qstring.h> | ||
13 | #include <qclipboard.h> | ||
14 | 8 | ||
15 | #include <assert.h> | 9 | #include <assert.h> |
16 | 10 | ||
17 | // | 11 | // |
18 | // Endian stuff | 12 | // Endian stuff |
19 | // | 13 | // |
20 | #ifndef KDE_USE_FINAL | 14 | #ifndef KDE_USE_FINAL |
21 | const int endianTest = 1; | 15 | const int endianTest = 1; |
22 | #endif | 16 | #endif |
23 | 17 | ||
24 | #define Swap16IfLE(s) \ | 18 | #define Swap16IfLE(s) \ |
25 | (*(char *)&endianTest ? ((((s) & 0xff) << 8) | (((s) >> 8) & 0xff)) : (s)) | 19 | (*(char *)&endianTest ? ((((s) & 0xff) << 8) | (((s) >> 8) & 0xff)) : (s)) |
26 | 20 | ||
27 | #define Swap32IfLE(l) \ | 21 | #define Swap32IfLE(l) \ |
28 | (*(char *)&endianTest ? ((((l) & 0xff000000) >> 24) | \ | 22 | (*(char *)&endianTest ? ((((l) & 0xff000000) >> 24) | \ |
29 | (((l) & 0x00ff0000) >> 8) | \ | 23 | (((l) & 0x00ff0000) >> 8) | \ |
30 | (((l) & 0x0000ff00) << 8) | \ | 24 | (((l) & 0x0000ff00) << 8) | \ |
31 | (((l) & 0x000000ff) << 24)) : (l)) | 25 | (((l) & 0x000000ff) << 24)) : (l)) |
32 | 26 | ||
33 | // | 27 | // |
34 | // The lengths of the messages we need to wait for | 28 | // The lengths of the messages we need to wait for |
35 | // | 29 | // |
36 | const int ServerInitLength = 24; | 30 | const int ServerInitLength = 24; |
37 | const int UpdateHeaderLength = 4; | 31 | const int UpdateHeaderLength = 4; |
38 | const int RectHeaderLength = 12; | 32 | const int RectHeaderLength = 12; |
39 | const int RectChunkSize = 4; | 33 | const int RectChunkSize = 4; |
40 | const int CopyRectPosLength = 4; | 34 | const int CopyRectPosLength = 4; |
41 | const int ServerCutLenLength = 7; | 35 | const int ServerCutLenLength = 7; |
42 | 36 | ||
43 | // | 37 | // |
44 | // Client -> Server Message Identifiers | 38 | // Client -> Server Message Identifiers |
45 | // | 39 | // |
46 | static CARD8 SetPixelFormatId = 0; | 40 | static CARD8 SetPixelFormatId = 0; |
47 | //static CARD8 FixColourMapEntriesId = 1; // Not used | 41 | //static CARD8 FixColourMapEntriesId = 1; // Not used |
48 | static CARD8 SetEncodingsId = 2; | 42 | static CARD8 SetEncodingsId = 2; |
49 | static CARD8 UpdateRequestId = 3; | 43 | static CARD8 UpdateRequestId = 3; |
50 | static CARD8 KeyEventId = 4; | 44 | static CARD8 KeyEventId = 4; |
51 | static CARD8 PointerEventId = 5; | 45 | static CARD8 PointerEventId = 5; |
52 | static CARD8 ClientCutTextId = 6; | 46 | static CARD8 ClientCutTextId = 6; |
53 | 47 | ||
54 | // | 48 | // |
55 | // Server -> Client Message Identifiers | 49 | // Server -> Client Message Identifiers |
56 | // | 50 | // |
57 | static CARD8 UpdateId = 0; | 51 | static CARD8 UpdateId = 0; |
58 | static CARD8 BellId = 2; | 52 | static CARD8 BellId = 2; |
59 | static CARD8 ServerCutId = 3; | 53 | static CARD8 ServerCutId = 3; |
60 | 54 | ||
61 | // | 55 | // |
62 | // Encoding identifiers | 56 | // Encoding identifiers |
63 | // | 57 | // |
64 | static CARD32 RawEncoding = Swap32IfLE( 0 ); | 58 | static CARD32 RawEncoding = Swap32IfLE( 0 ); |
65 | static CARD32 CopyRectEncoding = Swap32IfLE(1 ); | 59 | static CARD32 CopyRectEncoding = Swap32IfLE(1 ); |
66 | static CARD32 RreEncoding = Swap32IfLE( 2 ); | 60 | static CARD32 RreEncoding = Swap32IfLE( 2 ); |
67 | static CARD32 CorreEncoding = Swap32IfLE( 4 ); | 61 | static CARD32 CorreEncoding = Swap32IfLE( 4 ); |
68 | static CARD32 HexTileEncoding = Swap32IfLE( 5 ); | 62 | static CARD32 HexTileEncoding = Swap32IfLE( 5 ); |
69 | 63 | ||
70 | static struct { | 64 | static struct { |
71 | int keysym; | 65 | int keysym; |
72 | int keycode; | 66 | int keycode; |
73 | } keyMap[] = { | 67 | } keyMap[] = { |
74 | { 0xff08, Qt::Key_Backspace }, | 68 | { 0xff08, Qt::Key_Backspace }, |
75 | { 0xff09, Qt::Key_Tab }, | 69 | { 0xff09, Qt::Key_Tab }, |
76 | { 0xff0d, Qt::Key_Return }, | 70 | { 0xff0d, Qt::Key_Return }, |
77 | { 0xff1b, Qt::Key_Escape }, | 71 | { 0xff1b, Qt::Key_Escape }, |
78 | { 0xff63, Qt::Key_Insert }, | 72 | { 0xff63, Qt::Key_Insert }, |
79 | { 0xffff, Qt::Key_Delete }, | 73 | { 0xffff, Qt::Key_Delete }, |
80 | { 0xff50, Qt::Key_Home }, | 74 | { 0xff50, Qt::Key_Home }, |
81 | { 0xff57, Qt::Key_End }, | 75 | { 0xff57, Qt::Key_End }, |
82 | { 0xff55, Qt::Key_Prior }, | 76 | { 0xff55, Qt::Key_Prior }, |
83 | { 0xff56, Qt::Key_Next }, | 77 | { 0xff56, Qt::Key_Next }, |
84 | { 0xff51, Qt::Key_Left }, | 78 | { 0xff51, Qt::Key_Left }, |
85 | { 0xff52, Qt::Key_Up }, | 79 | { 0xff52, Qt::Key_Up }, |
86 | { 0xff53, Qt::Key_Right }, | 80 | { 0xff53, Qt::Key_Right }, |
87 | { 0xff54, Qt::Key_Down }, | 81 | { 0xff54, Qt::Key_Down }, |
88 | { 0xffbe, Qt::Key_F1 }, | 82 | { 0xffbe, Qt::Key_F1 }, |
89 | { 0xffbf, Qt::Key_F2 }, | 83 | { 0xffbf, Qt::Key_F2 }, |
90 | { 0xffc0, Qt::Key_F3 }, | 84 | { 0xffc0, Qt::Key_F3 }, |
91 | { 0xffc1, Qt::Key_F4 }, | 85 | { 0xffc1, Qt::Key_F4 }, |
92 | { 0xffc2, Qt::Key_F5 }, | 86 | { 0xffc2, Qt::Key_F5 }, |
93 | { 0xffc3, Qt::Key_F6 }, | 87 | { 0xffc3, Qt::Key_F6 }, |
94 | { 0xffc4, Qt::Key_F7 }, | 88 | { 0xffc4, Qt::Key_F7 }, |
95 | { 0xffc5, Qt::Key_F8 }, | 89 | { 0xffc5, Qt::Key_F8 }, |
96 | { 0xffc6, Qt::Key_F9 }, | 90 | { 0xffc6, Qt::Key_F9 }, |
97 | { 0xffc7, Qt::Key_F10 }, | 91 | { 0xffc7, Qt::Key_F10 }, |
98 | { 0xffc8, Qt::Key_F11 }, | 92 | { 0xffc8, Qt::Key_F11 }, |
99 | { 0xffc9, Qt::Key_F12 }, | 93 | { 0xffc9, Qt::Key_F12 }, |
100 | { 0xffe1, Qt::Key_Shift }, | 94 | { 0xffe1, Qt::Key_Shift }, |
101 | { 0xffe2, Qt::Key_Shift }, | 95 | { 0xffe2, Qt::Key_Shift }, |
102 | { 0xffe3, Qt::Key_Control }, | 96 | { 0xffe3, Qt::Key_Control }, |
103 | { 0xffe4, Qt::Key_Control }, | 97 | { 0xffe4, Qt::Key_Control }, |
104 | { 0xffe7, Qt::Key_Meta }, | 98 | { 0xffe7, Qt::Key_Meta }, |
105 | { 0xffe8, Qt::Key_Meta }, | 99 | { 0xffe8, Qt::Key_Meta }, |
106 | { 0xffe9, Qt::Key_Alt }, | 100 | { 0xffe9, Qt::Key_Alt }, |
107 | { 0xffea, Qt::Key_Alt }, | 101 | { 0xffea, Qt::Key_Alt }, |
108 | { 0, 0 } | 102 | { 0, 0 } |
109 | }; | 103 | }; |
110 | 104 | ||
111 | 105 | ||
112 | KRFBDecoder::KRFBDecoder( KRFBConnection *con ) | 106 | KRFBDecoder::KRFBDecoder( KRFBConnection *con ) |
113 | : QObject( con, "RFB Decoder" ) | 107 | : QObject( con, "RFB Decoder" ) |
114 | { | 108 | { |
115 | assert( con ); | 109 | assert( con ); |
116 | assert( con->state() == KRFBConnection::Connected ); | 110 | assert( con->state() == KRFBConnection::Connected ); |
117 | 111 | ||
118 | this->con = con; | 112 | this->con = con; |
119 | this->buf = 0; | 113 | this->buf = 0; |
120 | this->info = 0; | 114 | this->info = 0; |
121 | this->format = 0; | 115 | this->format = 0; |
122 | this->buttonMask = 0; | 116 | this->buttonMask = 0; |
123 | currentState = Idle; | 117 | currentState = Idle; |
124 | } | 118 | } |
125 | 119 | ||
126 | KRFBDecoder::~KRFBDecoder() | 120 | KRFBDecoder::~KRFBDecoder() |
127 | { | 121 | { |
128 | if ( info ) | 122 | if ( info ) |
129 | delete info; | 123 | delete info; |
130 | if ( format ) | 124 | if ( format ) |
131 | delete format; | 125 | delete format; |
132 | } | 126 | } |
133 | 127 | ||
134 | void KRFBDecoder::start() | 128 | void KRFBDecoder::start() |
135 | { | 129 | { |
136 | sendClientInit(); | 130 | sendClientInit(); |
137 | } | 131 | } |
138 | 132 | ||
139 | void KRFBDecoder::sendClientInit() | 133 | void KRFBDecoder::sendClientInit() |
140 | { | 134 | { |
141 | con->write( &( con->options()->shared ), 1 ); | 135 | con->write( &( con->options()->shared ), 1 ); |
142 | 136 | ||
143 | // Wait for server init | 137 | // Wait for server init |
144 | qWarning( "Waiting for server init" ); | 138 | qWarning( "Waiting for server init" ); |
145 | 139 | ||
146 | static QString statusMsg = tr( "Waiting for server initialization..." ); | 140 | static QString statusMsg = tr( "Waiting for server initialization..." ); |
147 | emit status( statusMsg ); | 141 | emit status( statusMsg ); |
148 | 142 | ||
149 | currentState = AwaitingServerInit; | 143 | currentState = AwaitingServerInit; |
150 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotServerInit() ) ); | 144 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotServerInit() ) ); |
151 | con->waitForData( ServerInitLength ); | 145 | con->waitForData( ServerInitLength ); |
152 | } | 146 | } |
153 | 147 | ||
154 | void KRFBDecoder::gotServerInit() | 148 | void KRFBDecoder::gotServerInit() |
155 | { | 149 | { |
156 | qWarning( "Got server init" ); | 150 | qWarning( "Got server init" ); |
157 | disconnect( con, SIGNAL( gotEnoughData() ), this, SLOT( gotServerInit() ) ); | 151 | disconnect( con, SIGNAL( gotEnoughData() ), this, SLOT( gotServerInit() ) ); |
158 | 152 | ||
159 | if ( info ) | 153 | if ( info ) |
160 | delete info; | 154 | delete info; |
161 | info = new KRFBServerInfo; | 155 | info = new KRFBServerInfo; |
162 | CHECK_PTR( info ); | 156 | CHECK_PTR( info ); |
163 | 157 | ||
164 | con->read( &(info->width), 2 ); | 158 | con->read( &(info->width), 2 ); |
165 | info->width = Swap16IfLE( info->width ); | 159 | info->width = Swap16IfLE( info->width ); |
166 | con->read( &info->height, 2 ); | 160 | con->read( &info->height, 2 ); |
167 | info->height = Swap16IfLE( info->height ); | 161 | info->height = Swap16IfLE( info->height ); |
168 | 162 | ||
169 | con->read( &(info->bpp), 1 ); | 163 | con->read( &(info->bpp), 1 ); |
170 | con->read( &(info->depth), 1 ); | 164 | con->read( &(info->depth), 1 ); |
171 | con->read( &(info->bigEndian), 1 ); | 165 | con->read( &(info->bigEndian), 1 ); |
172 | con->read( &(info->trueColor), 1 ); | 166 | con->read( &(info->trueColor), 1 ); |
173 | 167 | ||
174 | con->read( &(info->redMax), 2 ); | 168 | con->read( &(info->redMax), 2 ); |
175 | info->redMax = Swap16IfLE( info->redMax ); | 169 | info->redMax = Swap16IfLE( info->redMax ); |
176 | con->read( &(info->greenMax), 2 ); | 170 | con->read( &(info->greenMax), 2 ); |
177 | info->greenMax = Swap16IfLE( info->greenMax ); | 171 | info->greenMax = Swap16IfLE( info->greenMax ); |
178 | con->read( &(info->blueMax), 2 ); | 172 | con->read( &(info->blueMax), 2 ); |
179 | info->blueMax = Swap16IfLE( info->blueMax ); | 173 | info->blueMax = Swap16IfLE( info->blueMax ); |
180 | 174 | ||
181 | con->read( &(info->redShift), 1 ); | 175 | con->read( &(info->redShift), 1 ); |
182 | con->read( &(info->greenShift), 1 ); | 176 | con->read( &(info->greenShift), 1 ); |
183 | con->read( &(info->blueShift), 1 ); | 177 | con->read( &(info->blueShift), 1 ); |
184 | 178 | ||
185 | con->read( info->padding, 3 ); | 179 | con->read( info->padding, 3 ); |
186 | 180 | ||
187 | con->read( &(info->nameLength), 4 ); | 181 | con->read( &(info->nameLength), 4 ); |
188 | info->nameLength = Swap32IfLE( info->nameLength ); | 182 | info->nameLength = Swap32IfLE( info->nameLength ); |
189 | 183 | ||
190 | qWarning( "Width = %d, Height = %d", info->width, info->height ); | 184 | qWarning( "Width = %d, Height = %d", info->width, info->height ); |
191 | qWarning( "Bpp = %d, Depth = %d, Big = %d, True = %d", | 185 | qWarning( "Bpp = %d, Depth = %d, Big = %d, True = %d", |
192 | info->bpp, info->depth, info->bigEndian, info->trueColor ); | 186 | info->bpp, info->depth, info->bigEndian, info->trueColor ); |
193 | qWarning( "RedMax = %d, GreenMax = %d, BlueMax = %d", | 187 | qWarning( "RedMax = %d, GreenMax = %d, BlueMax = %d", |
194 | info->redMax, info->greenMax, info->blueMax ); | 188 | info->redMax, info->greenMax, info->blueMax ); |
195 | qWarning( "RedShift = %d, GreenShift = %d, BlueShift = %d", | 189 | qWarning( "RedShift = %d, GreenShift = %d, BlueShift = %d", |
196 | info->redShift, info->greenShift,info-> blueShift ); | 190 | info->redShift, info->greenShift,info-> blueShift ); |
197 | 191 | ||
198 | buf->resize( info->width/con->options()->scaleFactor, info->height /con->options()->scaleFactor); | 192 | buf->resize( info->width/con->options()->scaleFactor, info->height /con->options()->scaleFactor); |
199 | 193 | ||
200 | // Wait for desktop name | 194 | // Wait for desktop name |
201 | qWarning( "Waiting for desktop name" ); | 195 | qWarning( "Waiting for desktop name" ); |
202 | 196 | ||
203 | static QString statusMsg = tr( "Waiting for desktop name..." ); | 197 | static QString statusMsg = tr( "Waiting for desktop name..." ); |
204 | emit status( statusMsg ); | 198 | emit status( statusMsg ); |
205 | 199 | ||
206 | currentState = AwaitingDesktopName; | 200 | currentState = AwaitingDesktopName; |
207 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotDesktopName() ) ); | 201 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotDesktopName() ) ); |
208 | con->waitForData( info->nameLength ); | 202 | con->waitForData( info->nameLength ); |
209 | } | 203 | } |
210 | 204 | ||
211 | void KRFBDecoder::gotDesktopName() | 205 | void KRFBDecoder::gotDesktopName() |
212 | { | 206 | { |
213 | assert( info ); | 207 | assert( info ); |
214 | assert( currentState == AwaitingDesktopName ); | 208 | assert( currentState == AwaitingDesktopName ); |
215 | 209 | ||
216 | qWarning( "Got desktop name" ); | 210 | qWarning( "Got desktop name" ); |
217 | 211 | ||
218 | disconnect( con, SIGNAL( gotEnoughData() ), | 212 | disconnect( con, SIGNAL( gotEnoughData() ), |
219 | this, SLOT( gotDesktopName() ) ); | 213 | this, SLOT( gotDesktopName() ) ); |
220 | 214 | ||
221 | char *buf = new char[ info->nameLength + 1 ]; | 215 | char *buf = new char[ info->nameLength + 1 ]; |
222 | CHECK_PTR( buf ); | 216 | CHECK_PTR( buf ); |
223 | 217 | ||
224 | con->read( buf, info->nameLength ); | 218 | con->read( buf, info->nameLength ); |
225 | buf[ info->nameLength ] = '\0'; | 219 | buf[ info->nameLength ] = '\0'; |
226 | info->name = buf; | 220 | info->name = buf; |
227 | 221 | ||
228 | qWarning( "Desktop: %s", info->name.latin1() ); | 222 | qWarning( "Desktop: %s", info->name.latin1() ); |
229 | 223 | ||
230 | delete buf; | 224 | delete buf; |
231 | 225 | ||
232 | // Get the format we'll really use and tell the server | 226 | // Get the format we'll really use and tell the server |
233 | decidePixelFormat(); | 227 | decidePixelFormat(); |
234 | sendPixelFormat(); | 228 | sendPixelFormat(); |
235 | sendAllowedEncodings(); | 229 | sendAllowedEncodings(); |
236 | currentState = Idle; | 230 | currentState = Idle; |
237 | 231 | ||
238 | QString msg; | 232 | QString msg; |
239 | msg = tr( "Connected to %1" ); | 233 | msg = tr( "Connected to %1" ); |
240 | msg = msg.arg( info->name ); | 234 | msg = msg.arg( info->name ); |
241 | emit status( msg ); | 235 | emit status( msg ); |
242 | 236 | ||
243 | sendUpdateRequest( false ); | 237 | sendUpdateRequest( false ); |
244 | } | 238 | } |
245 | 239 | ||
246 | void KRFBDecoder::decidePixelFormat() | 240 | void KRFBDecoder::decidePixelFormat() |
247 | { | 241 | { |
248 | assert( info ); | 242 | assert( info ); |
249 | 243 | ||
250 | if ( format ) | 244 | if ( format ) |
251 | delete format; | 245 | delete format; |
252 | format = new KRFBPixelFormat; | 246 | format = new KRFBPixelFormat; |
253 | CHECK_PTR( format ); | 247 | CHECK_PTR( format ); |
254 | 248 | ||
255 | // What depth do we want? | 249 | // What depth do we want? |
256 | // | 250 | // |
257 | // We'll use the minimum of the remote and local depths, UNLESS an | 251 | // We'll use the minimum of the remote and local depths, UNLESS an |
258 | // eight bit session has been specifically requested by the user. | 252 | // eight bit session has been specifically requested by the user. |
259 | int screenDepth = QPixmap::defaultDepth(); | 253 | int screenDepth = QPixmap::defaultDepth(); |
260 | int bestDepth = ( screenDepth > info->depth ) ? info->depth : screenDepth; | 254 | int bestDepth = ( screenDepth > info->depth ) ? info->depth : screenDepth; |
261 | int chosenDepth; | 255 | int chosenDepth; |
262 | 256 | ||
263 | if ( con->options()->colors256 ) | 257 | if ( con->options()->colors256 ) |
264 | chosenDepth = 8; | 258 | chosenDepth = 8; |
265 | else | 259 | else |
266 | chosenDepth = bestDepth; | 260 | chosenDepth = bestDepth; |
267 | 261 | ||
268 | qWarning( "Screen depth=%d, server depth=%d, best depth=%d, " \ | 262 | qWarning( "Screen depth=%d, server depth=%d, best depth=%d, " \ |
269 | "eight bit %d, chosenDepth=%d", | 263 | "eight bit %d, chosenDepth=%d", |
270 | screenDepth, | 264 | screenDepth, |
271 | info->depth, | 265 | info->depth, |
272 | bestDepth, | 266 | bestDepth, |
273 | con->options()->colors256, chosenDepth ); | 267 | con->options()->colors256, chosenDepth ); |
274 | 268 | ||
275 | format->depth = chosenDepth; | 269 | format->depth = chosenDepth; |
276 | 270 | ||
277 | // If we're using the servers native depth | 271 | // If we're using the servers native depth |
278 | if ( chosenDepth == info->depth ) { | 272 | if ( chosenDepth == info->depth ) { |
279 | // Use the servers native format | 273 | // Use the servers native format |
280 | format->bpp = info->bpp; | 274 | format->bpp = info->bpp; |
281 | // format->bigEndian = info->bigEndian; | 275 | // format->bigEndian = info->bigEndian; |
282 | format->bigEndian = true; | 276 | format->bigEndian = true; |
283 | format->trueColor = info->trueColor; | 277 | format->trueColor = info->trueColor; |
284 | format->redMax = info->redMax; | 278 | format->redMax = info->redMax; |
285 | format->greenMax = info->greenMax; | 279 | format->greenMax = info->greenMax; |
286 | format->blueMax = info->blueMax; | 280 | format->blueMax = info->blueMax; |
287 | format->redShift = info->redShift; | 281 | format->redShift = info->redShift; |
288 | format->greenShift = info->greenShift; | 282 | format->greenShift = info->greenShift; |
289 | format->blueShift = info->blueShift; | 283 | format->blueShift = info->blueShift; |
290 | } | 284 | } |
291 | else { | 285 | else { |
292 | if ( chosenDepth == 8 ) { | 286 | if ( chosenDepth == 8 ) { |
293 | format->bpp = 8; | 287 | format->bpp = 8; |
294 | format->bigEndian = true; | 288 | format->bigEndian = true; |
295 | format->trueColor = true; | 289 | format->trueColor = true; |
296 | format->redMax = 7; | 290 | format->redMax = 7; |
297 | format->greenMax = 7; | 291 | format->greenMax = 7; |
298 | format->blueMax = 3; | 292 | format->blueMax = 3; |
299 | format->redShift = 0; | 293 | format->redShift = 0; |
300 | format->greenShift = 3; | 294 | format->greenShift = 3; |
301 | format->blueShift = 6; | 295 | format->blueShift = 6; |
302 | } | 296 | } |
303 | } | 297 | } |
304 | 298 | ||
305 | format->redMax = Swap16IfLE( format->redMax ); | 299 | format->redMax = Swap16IfLE( format->redMax ); |
306 | format->greenMax = Swap16IfLE( format->greenMax ); | 300 | format->greenMax = Swap16IfLE( format->greenMax ); |
307 | format->blueMax = Swap16IfLE( format->blueMax ); | 301 | format->blueMax = Swap16IfLE( format->blueMax ); |
308 | } | 302 | } |
309 | 303 | ||
310 | void KRFBDecoder::sendPixelFormat() | 304 | void KRFBDecoder::sendPixelFormat() |
311 | { | 305 | { |
312 | static char padding[3]; | 306 | static char padding[3]; |
313 | con->write( &SetPixelFormatId, 1 ); | 307 | con->write( &SetPixelFormatId, 1 ); |
314 | con->write( padding, 3 ); | 308 | con->write( padding, 3 ); |
315 | 309 | ||
316 | con->write( &(format->bpp), 1 ); | 310 | con->write( &(format->bpp), 1 ); |
317 | con->write( &(format->depth), 1 ); | 311 | con->write( &(format->depth), 1 ); |
318 | con->write( &(format->bigEndian), 1 ); | 312 | con->write( &(format->bigEndian), 1 ); |
319 | con->write( &(format->trueColor), 1 ); | 313 | con->write( &(format->trueColor), 1 ); |
320 | 314 | ||
321 | con->write( &(format->redMax), 2 ); | 315 | con->write( &(format->redMax), 2 ); |
322 | con->write( &(format->greenMax), 2 ); | 316 | con->write( &(format->greenMax), 2 ); |
323 | con->write( &(format->blueMax), 2 ); | 317 | con->write( &(format->blueMax), 2 ); |
324 | 318 | ||
325 | con->write( &(format->redShift), 1 ); | 319 | con->write( &(format->redShift), 1 ); |
326 | con->write( &(format->greenShift), 1 ); | 320 | con->write( &(format->greenShift), 1 ); |
327 | con->write( &(format->blueShift), 1 ); | 321 | con->write( &(format->blueShift), 1 ); |
328 | con->write( format->padding, 3 ); // Padding | 322 | con->write( format->padding, 3 ); // Padding |
329 | } | 323 | } |
330 | 324 | ||
331 | void KRFBDecoder::sendAllowedEncodings() | 325 | void KRFBDecoder::sendAllowedEncodings() |
332 | { | 326 | { |
333 | static CARD8 padding[1]; | 327 | static CARD8 padding[1]; |
334 | con->write( &SetEncodingsId, 1 ); | 328 | con->write( &SetEncodingsId, 1 ); |
335 | con->write( padding, 1 ); | 329 | con->write( padding, 1 ); |
336 | 330 | ||
337 | CARD16 noEncodings = con->options()->encodings(); | 331 | CARD16 noEncodings = con->options()->encodings(); |
338 | noEncodings = Swap16IfLE( noEncodings ); | 332 | noEncodings = Swap16IfLE( noEncodings ); |
339 | con->write( &noEncodings, 2 ); | 333 | con->write( &noEncodings, 2 ); |
340 | 334 | ||
341 | if ( con->options()->corre ) | 335 | if ( con->options()->corre ) |
342 | con->write( &CorreEncoding, 4 ); | 336 | con->write( &CorreEncoding, 4 ); |
343 | if ( con->options()->hexTile ) | 337 | if ( con->options()->hexTile ) |
344 | con->write( &HexTileEncoding, 4 ); | 338 | con->write( &HexTileEncoding, 4 ); |
345 | if ( con->options()->rre ) | 339 | if ( con->options()->rre ) |
346 | con->write( &RreEncoding, 4 ); | 340 | con->write( &RreEncoding, 4 ); |
347 | if ( con->options()->copyrect ) | 341 | if ( con->options()->copyrect ) |
348 | con->write( &CopyRectEncoding, 4 ); | 342 | con->write( &CopyRectEncoding, 4 ); |
349 | // We always support this | 343 | // We always support this |
350 | con->write( &RawEncoding, 4 ); | 344 | con->write( &RawEncoding, 4 ); |
351 | } | 345 | } |
352 | 346 | ||
353 | void KRFBDecoder::sendUpdateRequest( bool incremental ) | 347 | void KRFBDecoder::sendUpdateRequest( bool incremental ) |
354 | { | 348 | { |
355 | if ( currentState != Idle ) | 349 | if ( currentState != Idle ) |
356 | return; | 350 | return; |
357 | 351 | ||
358 | con->write( &UpdateRequestId, 1 ); | 352 | con->write( &UpdateRequestId, 1 ); |
359 | con->write( &incremental, 1 ); | 353 | con->write( &incremental, 1 ); |
360 | 354 | ||
361 | static CARD16 x = 0, y = 0; | 355 | static CARD16 x = 0, y = 0; |
362 | static CARD16 w = Swap16IfLE( info->width ); | 356 | static CARD16 w = Swap16IfLE( info->width ); |
363 | static CARD16 h = Swap16IfLE( info->height ); | 357 | static CARD16 h = Swap16IfLE( info->height ); |
364 | 358 | ||
365 | con->write( &x, 2 ); | 359 | con->write( &x, 2 ); |
366 | con->write( &y, 2 ); | 360 | con->write( &y, 2 ); |
367 | con->write( &w, 2 ); | 361 | con->write( &w, 2 ); |
368 | con->write( &h, 2 ); | 362 | con->write( &h, 2 ); |
369 | 363 | ||
370 | // Now wait for the update | 364 | // Now wait for the update |
371 | currentState = AwaitingUpdate; | 365 | currentState = AwaitingUpdate; |
372 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotUpdateHeader() ) ); | 366 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotUpdateHeader() ) ); |
373 | con->waitForData( UpdateHeaderLength ); | 367 | con->waitForData( UpdateHeaderLength ); |
374 | } | 368 | } |
375 | 369 | ||
376 | void KRFBDecoder::gotUpdateHeader() | 370 | void KRFBDecoder::gotUpdateHeader() |
377 | { | 371 | { |
378 | assert( currentState == AwaitingUpdate ); | 372 | assert( currentState == AwaitingUpdate ); |
379 | 373 | ||
380 | // qWarning( "Got update header" ); | 374 | // qWarning( "Got update header" ); |
381 | 375 | ||
382 | disconnect( con, SIGNAL( gotEnoughData() ), | 376 | disconnect( con, SIGNAL( gotEnoughData() ), |
383 | this, SLOT( gotUpdateHeader() ) ); | 377 | this, SLOT( gotUpdateHeader() ) ); |
384 | 378 | ||
385 | CARD8 msgType; | 379 | CARD8 msgType; |
386 | con->read( &msgType, 1 ); | 380 | con->read( &msgType, 1 ); |
387 | 381 | ||
388 | if ( msgType != UpdateId ) { | 382 | if ( msgType != UpdateId ) { |
389 | // We might have a bell or server cut | 383 | // We might have a bell or server cut |
390 | if ( msgType == ServerCutId ) { | 384 | if ( msgType == ServerCutId ) { |
391 | oldState = currentState; | 385 | oldState = currentState; |
392 | gotServerCut(); | 386 | gotServerCut(); |
393 | } | 387 | } |
394 | else if ( msgType == BellId ) { | 388 | else if ( msgType == BellId ) { |
395 | oldState = currentState; | 389 | oldState = currentState; |
396 | gotBell(); | 390 | gotBell(); |
397 | } | 391 | } |
398 | else { | 392 | else { |
399 | int msg = msgType; | 393 | int msg = msgType; |
400 | QString protocolError = tr( "Protocol Error: Message Id %1 was " | 394 | QString protocolError = tr( "Protocol Error: Message Id %1 was " |
401 | "found when expecting an update " | 395 | "found when expecting an update " |
402 | "message." ).arg( msg ); | 396 | "message." ).arg( msg ); |
403 | currentState = Error; | 397 | currentState = Error; |
404 | emit error( protocolError ); | 398 | emit error( protocolError ); |
405 | } | 399 | } |
406 | return; | 400 | return; |
407 | } | 401 | } |
408 | 402 | ||
409 | CARD8 padding; | 403 | CARD8 padding; |
410 | con->read( &padding, 1 ); | 404 | con->read( &padding, 1 ); |
411 | 405 | ||
412 | con->read( &noRects, 2 ); | 406 | con->read( &noRects, 2 ); |
413 | noRects = Swap16IfLE( noRects ); | 407 | noRects = Swap16IfLE( noRects ); |
414 | 408 | ||
415 | // qWarning( "Expecting %d rects", noRects ); | 409 | // qWarning( "Expecting %d rects", noRects ); |
416 | 410 | ||
417 | // Now wait for the data | 411 | // Now wait for the data |
418 | currentState = AwaitingRectHeader; | 412 | currentState = AwaitingRectHeader; |
419 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotRectHeader() ) ); | 413 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotRectHeader() ) ); |
420 | con->waitForData( RectHeaderLength ); | 414 | con->waitForData( RectHeaderLength ); |
421 | } | 415 | } |
422 | 416 | ||
423 | void KRFBDecoder::gotRectHeader() | 417 | void KRFBDecoder::gotRectHeader() |
424 | { | 418 | { |
425 | assert( currentState == AwaitingRectHeader ); | 419 | assert( currentState == AwaitingRectHeader ); |
426 | 420 | ||
427 | // qWarning( "Got rect header" ); | 421 | // qWarning( "Got rect header" ); |
428 | 422 | ||
429 | disconnect( con, SIGNAL( gotEnoughData() ), | 423 | disconnect( con, SIGNAL( gotEnoughData() ), |
430 | this, SLOT( gotRectHeader() ) ); | 424 | this, SLOT( gotRectHeader() ) ); |
431 | 425 | ||
432 | con->read( &x, 2 ); | 426 | con->read( &x, 2 ); |
433 | x = Swap16IfLE( x ); | 427 | x = Swap16IfLE( x ); |
434 | con->read( &y, 2 ); | 428 | con->read( &y, 2 ); |
435 | y = Swap16IfLE( y ); | 429 | y = Swap16IfLE( y ); |
436 | 430 | ||
437 | con->read( &w, 2 ); | 431 | con->read( &w, 2 ); |
438 | w = Swap16IfLE( w ); | 432 | w = Swap16IfLE( w ); |
439 | con->read( &h, 2 ); | 433 | con->read( &h, 2 ); |
440 | h = Swap16IfLE( h ); | 434 | h = Swap16IfLE( h ); |
441 | 435 | ||
442 | con->read( &encoding, 4 ); | 436 | con->read( &encoding, 4 ); |
443 | 437 | ||
444 | // CARD32 encodingLocal = Swap32IfLE( encoding ); | 438 | // CARD32 encodingLocal = Swap32IfLE( encoding ); |
445 | // qWarning( "Rect: x=%d, y= %d, w=%d, h=%d, encoding=%ld", | 439 | // qWarning( "Rect: x=%d, y= %d, w=%d, h=%d, encoding=%ld", |
446 | // x, y, w, h, encodingLocal ); | 440 | // x, y, w, h, encodingLocal ); |
447 | 441 | ||
448 | // | 442 | // |
449 | // Each encoding needs to be handled differently. Some require | 443 | // Each encoding needs to be handled differently. Some require |
450 | // waiting for more data, but others like a copyrect do not. | 444 | // waiting for more data, but others like a copyrect do not. |
451 | // Our constants have already been byte swapped, so we use | 445 | // Our constants have already been byte swapped, so we use |
452 | // the remote value as is. | 446 | // the remote value as is. |
453 | // | 447 | // |
454 | if ( encoding == RawEncoding ) { | 448 | if ( encoding == RawEncoding ) { |
455 | // qWarning( "Raw encoding" ); | 449 | // qWarning( "Raw encoding" ); |
456 | handleRawRect(); | 450 | handleRawRect(); |
457 | } | 451 | } |
458 | else if ( encoding == CopyRectEncoding ) { | 452 | else if ( encoding == CopyRectEncoding ) { |
459 | // qWarning( "CopyRect encoding" ); | 453 | // qWarning( "CopyRect encoding" ); |
460 | handleCopyRect(); | 454 | handleCopyRect(); |
461 | } | 455 | } |
462 | else if ( encoding == RreEncoding ) { | 456 | else if ( encoding == RreEncoding ) { |
463 | qWarning( "RRE encoding" ); | 457 | qWarning( "RRE encoding" ); |
464 | handleRRERect(); | 458 | handleRRERect(); |
465 | } | 459 | } |
466 | else if ( encoding == CorreEncoding ) { | 460 | else if ( encoding == CorreEncoding ) { |
467 | qWarning( "CoRRE encoding" ); | 461 | qWarning( "CoRRE encoding" ); |
468 | handleCoRRERect(); | 462 | handleCoRRERect(); |
469 | } | 463 | } |
470 | else if ( encoding == HexTileEncoding ) { | 464 | else if ( encoding == HexTileEncoding ) { |
471 | qWarning( "HexTile encoding" ); | 465 | qWarning( "HexTile encoding" ); |
472 | handleHexTileRect(); | 466 | handleHexTileRect(); |
473 | } | 467 | } |
474 | else { | 468 | else { |
475 | int msg = Swap32IfLE( encoding ); | 469 | int msg = Swap32IfLE( encoding ); |
476 | QString protocolError = tr( "Protocol Error: An unknown encoding was " | 470 | QString protocolError = tr( "Protocol Error: An unknown encoding was " |
477 | "used by the server %1" ).arg( msg ); | 471 | "used by the server %1" ).arg( msg ); |
478 | currentState = Error; | 472 | currentState = Error; |
479 | qWarning( "Unknown encoding, %d", msg ); | 473 | qWarning( "Unknown encoding, %d", msg ); |
480 | emit error( protocolError ); | 474 | emit error( protocolError ); |
481 | return; | 475 | return; |
482 | } | 476 | } |
483 | } | 477 | } |
484 | 478 | ||
485 | // | 479 | // |
486 | // Raw Encoding | 480 | // Raw Encoding |
487 | // | 481 | // |
488 | 482 | ||
489 | void KRFBDecoder::handleRawRect() | 483 | void KRFBDecoder::handleRawRect() |
490 | { | 484 | { |
491 | // We need something a bit cleverer here to handle large | 485 | // We need something a bit cleverer here to handle large |
492 | // rectanges nicely. The chunking should be based on the | 486 | // rectanges nicely. The chunking should be based on the |
493 | // overall size (but has to be in complete lines). | 487 | // overall size (but has to be in complete lines). |
494 | 488 | ||
495 | // qWarning( "Handling a raw rect chunk" ); | 489 | // qWarning( "Handling a raw rect chunk" ); |
496 | 490 | ||
497 | // CARD32 lineCount = w * format->bpp / 8; | 491 | // CARD32 lineCount = w * format->bpp / 8; |
498 | 492 | ||
499 | if ( h > RectChunkSize ) { | 493 | if ( h > RectChunkSize ) { |
500 | // if ( con->sock->size() / lineCount ) { | 494 | // if ( con->sock->size() / lineCount ) { |
501 | // getRawRectChunk( con->sock->size() / lineCount ); | 495 | // getRawRectChunk( con->sock->size() / lineCount ); |
502 | // } | 496 | // } |
503 | // else { | 497 | // else { |
504 | getRawRectChunk( RectChunkSize ); | 498 | getRawRectChunk( RectChunkSize ); |
505 | // } | 499 | // } |
506 | } | 500 | } |
507 | else { | 501 | else { |
508 | getRawRectChunk( h ); | 502 | getRawRectChunk( h ); |
509 | } | 503 | } |
510 | } | 504 | } |
511 | 505 | ||
512 | void KRFBDecoder::getRawRectChunk( int lines ) | 506 | void KRFBDecoder::getRawRectChunk( int lines ) |
513 | { | 507 | { |
514 | this->lines = lines; | 508 | this->lines = lines; |
515 | CARD32 count = lines * w * format->bpp / 8; | 509 | CARD32 count = lines * w * format->bpp / 8; |
516 | 510 | ||
517 | // Wait for server init | 511 | // Wait for server init |
518 | // qWarning( "Waiting for raw rect chunk, %ld", count ); | 512 | // qWarning( "Waiting for raw rect chunk, %ld", count ); |
519 | 513 | ||
520 | currentState = AwaitingRawRectChunk; | 514 | currentState = AwaitingRawRectChunk; |
521 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotRawRectChunk() ) ); | 515 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotRawRectChunk() ) ); |
522 | con->waitForData( count ); | 516 | con->waitForData( count ); |
523 | } | 517 | } |
524 | 518 | ||
525 | void KRFBDecoder::gotRawRectChunk() | 519 | void KRFBDecoder::gotRawRectChunk() |
526 | { | 520 | { |
527 | assert( currentState == AwaitingRawRectChunk ); | 521 | assert( currentState == AwaitingRawRectChunk ); |
528 | 522 | ||
529 | disconnect( con, SIGNAL( gotEnoughData() ), | 523 | disconnect( con, SIGNAL( gotEnoughData() ), |
530 | this, SLOT( gotRawRectChunk() ) ); | 524 | this, SLOT( gotRawRectChunk() ) ); |
531 | 525 | ||
532 | // qWarning( "Got raw rect chunk" ); | 526 | // qWarning( "Got raw rect chunk" ); |
533 | 527 | ||
534 | // | 528 | // |
535 | // Read the rect data and copy it to the buffer. | 529 | // Read the rect data and copy it to the buffer. |
536 | // | 530 | // |
537 | 531 | ||
538 | // TODO: Replace this! | 532 | // TODO: Replace this! |
539 | int count = lines * w * format->bpp / 8; | 533 | int count = lines * w * format->bpp / 8; |
540 | char *hack = new char[ count ]; | 534 | char *hack = new char[ count ]; |
541 | con->read( hack, count ); | 535 | con->read( hack, count ); |
542 | buf->drawRawRectChunk( hack, x, y, w, lines ); | 536 | buf->drawRawRectChunk( hack, x, y, w, lines ); |
543 | delete hack; | 537 | delete hack; |
544 | // /TODO: | 538 | // /TODO: |
545 | 539 | ||
546 | h = h - lines; | 540 | h = h - lines; |
547 | y = y + lines; | 541 | y = y + lines; |
548 | 542 | ||
549 | if ( h > 0 ) { | 543 | if ( h > 0 ) { |
550 | handleRawRect(); | 544 | handleRawRect(); |
551 | } | 545 | } |
552 | else { | 546 | else { |
553 | noRects--; | 547 | noRects--; |
554 | 548 | ||
555 | // qWarning( "There are %d rects left", noRects ); | 549 | // qWarning( "There are %d rects left", noRects ); |
556 | 550 | ||
557 | if ( noRects ) { | 551 | if ( noRects ) { |
558 | currentState = AwaitingRectHeader; | 552 | currentState = AwaitingRectHeader; |
559 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotRectHeader() ) ); | 553 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotRectHeader() ) ); |
560 | con->waitForData( RectHeaderLength ); | 554 | con->waitForData( RectHeaderLength ); |
561 | } | 555 | } |
562 | else { | 556 | else { |
563 | // we are now ready for the next update - no need to wait for the timer | 557 | // we are now ready for the next update - no need to wait for the timer |
564 | currentState = Idle; | 558 | currentState = Idle; |
565 | sendUpdateRequest (1); | 559 | sendUpdateRequest (1); |
566 | } | 560 | } |
567 | } | 561 | } |
568 | } | 562 | } |
569 | 563 | ||
570 | // | 564 | // |
571 | // Copy Rectangle Encoding | 565 | // Copy Rectangle Encoding |
572 | // | 566 | // |
573 | 567 | ||
574 | void KRFBDecoder::handleCopyRect() | 568 | void KRFBDecoder::handleCopyRect() |
575 | { | 569 | { |
576 | currentState = AwaitingCopyRectPos; | 570 | currentState = AwaitingCopyRectPos; |
577 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotCopyRectPos() ) ); | 571 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotCopyRectPos() ) ); |
578 | con->waitForData( CopyRectPosLength ); | 572 | con->waitForData( CopyRectPosLength ); |
579 | } | 573 | } |
580 | 574 | ||
581 | void KRFBDecoder::gotCopyRectPos() | 575 | void KRFBDecoder::gotCopyRectPos() |
582 | { | 576 | { |
583 | disconnect( con, SIGNAL( gotEnoughData() ), | 577 | disconnect( con, SIGNAL( gotEnoughData() ), |
584 | this, SLOT( gotCopyRectPos() ) ); | 578 | this, SLOT( gotCopyRectPos() ) ); |
585 | 579 | ||
586 | CARD16 srcX; | 580 | CARD16 srcX; |
587 | CARD16 srcY; | 581 | CARD16 srcY; |
588 | 582 | ||
589 | con->read( &srcX, 2 ); | 583 | con->read( &srcX, 2 ); |
590 | con->read( &srcY, 2 ); | 584 | con->read( &srcY, 2 ); |
591 | 585 | ||
592 | srcX = Swap16IfLE( srcX ); | 586 | srcX = Swap16IfLE( srcX ); |
593 | srcY = Swap16IfLE( srcY ); | 587 | srcY = Swap16IfLE( srcY ); |
594 | 588 | ||
595 | buf->copyRect( srcX, srcY, x, y, w, h ); | 589 | buf->copyRect( srcX, srcY, x, y, w, h ); |
596 | 590 | ||
597 | noRects--; | 591 | noRects--; |
598 | 592 | ||
599 | // qWarning( "There are %d rects left", noRects ); | 593 | // qWarning( "There are %d rects left", noRects ); |
600 | 594 | ||
601 | if ( noRects ) { | 595 | if ( noRects ) { |
602 | currentState = AwaitingRectHeader; | 596 | currentState = AwaitingRectHeader; |
603 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotRectHeader() ) ); | 597 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotRectHeader() ) ); |
604 | con->waitForData( RectHeaderLength ); | 598 | con->waitForData( RectHeaderLength ); |
605 | } | 599 | } |
606 | else | 600 | else |
607 | currentState = Idle; | 601 | currentState = Idle; |
608 | } | 602 | } |
609 | 603 | ||
610 | void KRFBDecoder::handleRRERect() | 604 | void KRFBDecoder::handleRRERect() |
611 | { | 605 | { |
612 | qWarning( "RRE not implemented" ); | 606 | qWarning( "RRE not implemented" ); |
613 | } | 607 | } |
614 | 608 | ||
615 | void KRFBDecoder::handleCoRRERect() | 609 | void KRFBDecoder::handleCoRRERect() |
616 | { | 610 | { |
617 | qWarning( "CoRRE not implemented" ); | 611 | qWarning( "CoRRE not implemented" ); |
618 | } | 612 | } |
619 | 613 | ||
620 | void KRFBDecoder::handleHexTileRect() | 614 | void KRFBDecoder::handleHexTileRect() |
621 | { | 615 | { |
622 | qWarning( "HexTile not implemented" ); | 616 | qWarning( "HexTile not implemented" ); |
623 | } | 617 | } |
624 | 618 | ||
625 | void KRFBDecoder::sendMouseEvent( QMouseEvent *e ) | 619 | void KRFBDecoder::sendMouseEvent( QMouseEvent *e ) |
626 | { | 620 | { |
627 | // Deal with the buttons | 621 | // Deal with the buttons |
628 | if ( e->type() != QEvent::MouseMove ) { | 622 | if ( e->type() != QEvent::MouseMove ) { |
629 | buttonMask = 0; | 623 | buttonMask = 0; |
630 | if ( e->type() == QEvent::MouseButtonPress ) { | 624 | if ( e->type() == QEvent::MouseButtonPress ) { |
631 | if ( e->button() & LeftButton ) | 625 | if ( e->button() & LeftButton ) |
632 | buttonMask |= 0x01; | 626 | buttonMask |= 0x01; |
633 | if ( e->button() & MidButton ) | 627 | if ( e->button() & MidButton ) |
634 | buttonMask |= 0x04; | 628 | buttonMask |= 0x04; |
635 | if ( e->button() & RightButton ) | 629 | if ( e->button() & RightButton ) |
636 | buttonMask |= 0x02; | 630 | buttonMask |= 0x02; |
637 | } | 631 | } |
638 | else if ( e->type() == QEvent::MouseButtonRelease ) { | 632 | else if ( e->type() == QEvent::MouseButtonRelease ) { |
639 | if ( e->button() & LeftButton ) | 633 | if ( e->button() & LeftButton ) |
640 | buttonMask &= 0x06; | 634 | buttonMask &= 0x06; |
641 | if ( e->button() & MidButton ) | 635 | if ( e->button() & MidButton ) |
642 | buttonMask |= 0x03; | 636 | buttonMask |= 0x03; |
643 | if ( e->button() & RightButton ) | 637 | if ( e->button() & RightButton ) |
644 | buttonMask |= 0x05; | 638 | buttonMask |= 0x05; |
645 | } | 639 | } |
646 | } | 640 | } |
647 | 641 | ||
648 | // HACK: Scaling | 642 | // HACK: Scaling |
649 | CARD16 x = Swap16IfLE( e->x() * con->options()->scaleFactor ); | 643 | CARD16 x = Swap16IfLE( e->x() * con->options()->scaleFactor ); |
650 | CARD16 y = Swap16IfLE( e->y() *con->options()->scaleFactor ); | 644 | CARD16 y = Swap16IfLE( e->y() *con->options()->scaleFactor ); |
651 | 645 | ||
652 | con->write( &PointerEventId, 1 ); | 646 | con->write( &PointerEventId, 1 ); |
653 | con->write( &buttonMask, 1 ); | 647 | con->write( &buttonMask, 1 ); |
654 | con->write( &x, 2 ); | 648 | con->write( &x, 2 ); |
655 | con->write( &y, 2 ); | 649 | con->write( &y, 2 ); |
656 | } | 650 | } |
657 | 651 | ||
658 | 652 | ||
659 | void KRFBDecoder::sendCutEvent( const QString &unicode ) | 653 | void KRFBDecoder::sendCutEvent( const QString &unicode ) |
660 | { | 654 | { |
661 | // | 655 | // |
662 | // Warning: There is a bug in the RFB protocol because there is no way to find | 656 | // Warning: There is a bug in the RFB protocol because there is no way to find |
663 | // out the codepage in use on the remote machine. This could be fixed by requiring | 657 | // out the codepage in use on the remote machine. This could be fixed by requiring |
664 | // the remote server to use utf8 etc. but for now we have to assume they're the | 658 | // the remote server to use utf8 etc. but for now we have to assume they're the |
665 | // same. I've reported this problem to the ORL guys, but they apparantly have no | 659 | // same. I've reported this problem to the ORL guys, but they apparantly have no |
666 | // immediate plans to fix the issue. :-( (rich) | 660 | // immediate plans to fix the issue. :-( (rich) |
667 | // | 661 | // |
668 | 662 | ||
669 | CARD8 padding[3]; | 663 | CARD8 padding[3]; |
670 | QCString text = unicode.local8Bit(); | 664 | QCString text = unicode.local8Bit(); |
671 | CARD32 length = text.length(); | 665 | CARD32 length = text.length(); |
672 | length = Swap32IfLE( length ); | 666 | length = Swap32IfLE( length ); |
673 | 667 | ||
674 | con->write( &ClientCutTextId, 1 ); | 668 | con->write( &ClientCutTextId, 1 ); |
675 | con->write( &padding, 3 ); | 669 | con->write( &padding, 3 ); |
676 | con->write( &length, 4 ); | 670 | con->write( &length, 4 ); |
677 | con->write( text.data(), length ); | 671 | con->write( text.data(), length ); |
678 | } | 672 | } |
679 | 673 | ||
680 | void KRFBDecoder::gotServerCut() | 674 | void KRFBDecoder::gotServerCut() |
681 | { | 675 | { |
682 | qWarning( "Got server cut" ); | 676 | qWarning( "Got server cut" ); |
683 | 677 | ||
684 | currentState = AwaitingServerCutLength; | 678 | currentState = AwaitingServerCutLength; |
685 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotServerCutLength() ) ); | 679 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotServerCutLength() ) ); |
686 | con->waitForData( ServerCutLenLength ); | 680 | con->waitForData( ServerCutLenLength ); |
687 | } | 681 | } |
688 | 682 | ||
689 | void KRFBDecoder::gotServerCutLength() | 683 | void KRFBDecoder::gotServerCutLength() |
690 | { | 684 | { |
691 | assert( currentState = AwaitingServerCutLength ); | 685 | assert( currentState = AwaitingServerCutLength ); |
692 | disconnect( con, SIGNAL( gotEnoughData() ), | 686 | disconnect( con, SIGNAL( gotEnoughData() ), |
693 | this, SLOT( gotServerCutLength() ) ); | 687 | this, SLOT( gotServerCutLength() ) ); |
694 | 688 | ||
695 | CARD8 padding[3]; | 689 | CARD8 padding[3]; |
696 | con->read( padding, 3 ); | 690 | con->read( padding, 3 ); |
697 | 691 | ||
698 | con->read( &serverCutTextLen, 4 ); | 692 | con->read( &serverCutTextLen, 4 ); |
699 | serverCutTextLen = Swap32IfLE( serverCutTextLen ); | 693 | serverCutTextLen = Swap32IfLE( serverCutTextLen ); |
700 | 694 | ||
701 | currentState = AwaitingServerCutText; | 695 | currentState = AwaitingServerCutText; |
702 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotServerCutText() ) ); | 696 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotServerCutText() ) ); |
703 | con->waitForData( serverCutTextLen ); | 697 | con->waitForData( serverCutTextLen ); |
704 | } | 698 | } |
705 | 699 | ||
706 | void KRFBDecoder::gotServerCutText() | 700 | void KRFBDecoder::gotServerCutText() |
707 | { | 701 | { |
708 | assert( currentState = AwaitingServerCutText ); | 702 | assert( currentState = AwaitingServerCutText ); |
709 | 703 | ||
710 | disconnect( con, SIGNAL( gotEnoughData() ), | 704 | disconnect( con, SIGNAL( gotEnoughData() ), |
711 | this, SLOT( gotServerCutText() ) ); | 705 | this, SLOT( gotServerCutText() ) ); |
712 | 706 | ||
713 | 707 | ||
714 | // | 708 | // |
715 | // Warning: There is a bug in the RFB protocol because there is no way to find | 709 | // Warning: There is a bug in the RFB protocol because there is no way to find |
716 | // out the codepage in use on the remote machine. This could be fixed by requiring | 710 | // out the codepage in use on the remote machine. This could be fixed by requiring |
717 | // the remote server to use utf8 etc. but for now we have to assume they're the | 711 | // the remote server to use utf8 etc. but for now we have to assume they're the |
718 | // same. I've reported this problem to the ORL guys, but they apparantly have no | 712 | // same. I've reported this problem to the ORL guys, but they apparantly have no |
719 | // immediate plans to fix the issue. :-( (rich) | 713 | // immediate plans to fix the issue. :-( (rich) |
720 | // | 714 | // |
721 | 715 | ||
722 | char *cutbuf = new char[ serverCutTextLen + 1 ]; | 716 | char *cutbuf = new char[ serverCutTextLen + 1 ]; |
723 | CHECK_PTR( cutbuf ); | 717 | CHECK_PTR( cutbuf ); |
724 | 718 | ||
725 | con->read( cutbuf, serverCutTextLen ); | 719 | con->read( cutbuf, serverCutTextLen ); |
726 | cutbuf[ serverCutTextLen ] = '\0'; | 720 | cutbuf[ serverCutTextLen ] = '\0'; |
727 | 721 | ||
728 | /* For some reason QApplication::clipboard()->setText() segfaults when called | 722 | /* For some reason QApplication::clipboard()->setText() segfaults when called |
729 | * from within keypebble's mass of signals and slots | 723 | * from within keypebble's mass of signals and slots |
730 | qWarning( "Server cut: %s", cutbuf ); | 724 | qWarning( "Server cut: %s", cutbuf ); |
731 | 725 | ||
732 | QString cutText( cutbuf ); // DANGER!! | 726 | QString cutText( cutbuf ); // DANGER!! |
733 | qApp->clipboard()->setText( cutText ); | 727 | qApp->clipboard()->setText( cutText ); |
734 | */ | 728 | */ |
735 | 729 | ||
736 | delete cutbuf; | 730 | delete cutbuf; |
737 | // Now wait for the update (again) | 731 | // Now wait for the update (again) |
738 | if ( oldState == AwaitingUpdate ) { | 732 | if ( oldState == AwaitingUpdate ) { |
739 | currentState = AwaitingUpdate; | 733 | currentState = AwaitingUpdate; |
740 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotUpdateHeader() ) ); | 734 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotUpdateHeader() ) ); |
741 | con->waitForData( UpdateHeaderLength ); | 735 | con->waitForData( UpdateHeaderLength ); |
742 | } | 736 | } |
743 | else if ( oldState == Idle ) { | 737 | else if ( oldState == Idle ) { |
744 | currentState = Idle; | 738 | currentState = Idle; |
745 | } | 739 | } |
746 | else { | 740 | else { |
747 | qWarning( "Async handled in weird state" ); | 741 | qWarning( "Async handled in weird state" ); |
748 | currentState = oldState; | 742 | currentState = oldState; |
749 | }; | 743 | }; |
750 | } | 744 | } |
751 | 745 | ||
752 | void KRFBDecoder::gotBell() | 746 | void KRFBDecoder::gotBell() |
753 | { | 747 | { |
754 | qWarning( "Got server bell" ); | 748 | qWarning( "Got server bell" ); |
755 | buf->soundBell(); | 749 | buf->soundBell(); |
756 | 750 | ||
757 | // Now wait for the update (again) | 751 | // Now wait for the update (again) |
758 | if ( oldState == AwaitingUpdate ) { | 752 | if ( oldState == AwaitingUpdate ) { |
759 | currentState = AwaitingUpdate; | 753 | currentState = AwaitingUpdate; |
760 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotUpdateHeader() ) ); | 754 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotUpdateHeader() ) ); |
761 | con->waitForData( UpdateHeaderLength ); | 755 | con->waitForData( UpdateHeaderLength ); |
762 | } | 756 | } |
763 | else if ( oldState == Idle ) { | 757 | else if ( oldState == Idle ) { |
764 | currentState = Idle; | 758 | currentState = Idle; |
765 | } | 759 | } |
766 | else { | 760 | else { |
767 | qWarning( "Async handled in weird state" ); | 761 | qWarning( "Async handled in weird state" ); |
768 | currentState = oldState; | 762 | currentState = oldState; |
769 | }; | 763 | }; |
770 | } | 764 | } |
771 | 765 | ||
772 | void KRFBDecoder::sendKeyPressEvent( QKeyEvent *event ) | 766 | void KRFBDecoder::sendKeyPressEvent( QKeyEvent *event ) |
773 | { | 767 | { |
774 | int key; | 768 | int key; |
775 | key = toKeySym( event ); | 769 | key = toKeySym( event ); |
776 | if ( key ) { | 770 | if ( key ) { |
777 | key = Swap32IfLE( key ); | 771 | key = Swap32IfLE( key ); |
778 | 772 | ||
779 | CARD8 mask = true; | 773 | CARD8 mask = true; |
780 | 774 | ||
781 | CARD16 padding = 0; | 775 | CARD16 padding = 0; |
diff --git a/noncore/comm/keypebble/krfblogin.cpp b/noncore/comm/keypebble/krfblogin.cpp index 0d2a205..0b4a757 100644 --- a/noncore/comm/keypebble/krfblogin.cpp +++ b/noncore/comm/keypebble/krfblogin.cpp | |||
@@ -1,254 +1,253 @@ | |||
1 | #include <assert.h> | 1 | #include <assert.h> |
2 | 2 | ||
3 | 3 | ||
4 | extern "C" { | 4 | extern "C" { |
5 | #include "vncauth.h" | 5 | #include "vncauth.h" |
6 | } | 6 | } |
7 | 7 | ||
8 | #include "krfblogin.h" | 8 | #include "krfblogin.h" |
9 | #include "krfbconnection.h" | 9 | #include "krfbconnection.h" |
10 | #include <qtimer.h> | 10 | #include <qtimer.h> |
11 | #include <qregexp.h> | ||
12 | 11 | ||
13 | // The length of the various messages (used to decide how many bytes to | 12 | // The length of the various messages (used to decide how many bytes to |
14 | // wait for). | 13 | // wait for). |
15 | const int ServerVersionLength = 12; | 14 | const int ServerVersionLength = 12; |
16 | const int ClientVersionLength = 12; | 15 | const int ClientVersionLength = 12; |
17 | const int AuthSchemeLength = 4; | 16 | const int AuthSchemeLength = 4; |
18 | const int FailureReasonSizeLength = 4; | 17 | const int FailureReasonSizeLength = 4; |
19 | const int ChallengeLength = 16; | 18 | const int ChallengeLength = 16; |
20 | const int AuthResultLength = 4; | 19 | const int AuthResultLength = 4; |
21 | 20 | ||
22 | // Authentication results | 21 | // Authentication results |
23 | enum AuthResult { | 22 | enum AuthResult { |
24 | AuthOk, | 23 | AuthOk, |
25 | AuthFailed, | 24 | AuthFailed, |
26 | AuthTooMany | 25 | AuthTooMany |
27 | }; | 26 | }; |
28 | 27 | ||
29 | typedef unsigned char CARD8; | 28 | typedef unsigned char CARD8; |
30 | typedef unsigned short CARD16; | 29 | typedef unsigned short CARD16; |
31 | typedef unsigned long CARD32; | 30 | typedef unsigned long CARD32; |
32 | 31 | ||
33 | const int endianTest = 1; | 32 | const int endianTest = 1; |
34 | 33 | ||
35 | // Endian stuff | 34 | // Endian stuff |
36 | #define Swap16IfLE(s) \ | 35 | #define Swap16IfLE(s) \ |
37 | (*(char *)&endianTest ? ((((s) & 0xff) << 8) | (((s) >> 8) & 0xff)) : (s)) | 36 | (*(char *)&endianTest ? ((((s) & 0xff) << 8) | (((s) >> 8) & 0xff)) : (s)) |
38 | 37 | ||
39 | #define Swap32IfLE(l) \ | 38 | #define Swap32IfLE(l) \ |
40 | (*(char *)&endianTest ? ((((l) & 0xff000000) >> 24) | \ | 39 | (*(char *)&endianTest ? ((((l) & 0xff000000) >> 24) | \ |
41 | (((l) & 0x00ff0000) >> 8) | \ | 40 | (((l) & 0x00ff0000) >> 8) | \ |
42 | (((l) & 0x0000ff00) << 8) | \ | 41 | (((l) & 0x0000ff00) << 8) | \ |
43 | (((l) & 0x000000ff) << 24)) : (l)) | 42 | (((l) & 0x000000ff) << 24)) : (l)) |
44 | 43 | ||
45 | KRFBLogin::KRFBLogin( KRFBConnection *con ) | 44 | KRFBLogin::KRFBLogin( KRFBConnection *con ) |
46 | : QObject( con, "RFB login manager" ) | 45 | : QObject( con, "RFB login manager" ) |
47 | { | 46 | { |
48 | assert( con ); | 47 | assert( con ); |
49 | this->con = con; | 48 | this->con = con; |
50 | currentState = AwaitingServerVersion; | 49 | currentState = AwaitingServerVersion; |
51 | 50 | ||
52 | connect( this, SIGNAL( error( const QString & ) ), | 51 | connect( this, SIGNAL( error( const QString & ) ), |
53 | con, SIGNAL( error( const QString & ) ) ); | 52 | con, SIGNAL( error( const QString & ) ) ); |
54 | 53 | ||
55 | 54 | ||
56 | qWarning( "Waiting for server version..." ); | 55 | qWarning( "Waiting for server version..." ); |
57 | 56 | ||
58 | static QString statusMsg = tr( "Waiting for server version..." ); | 57 | static QString statusMsg = tr( "Waiting for server version..." ); |
59 | emit status( statusMsg ); | 58 | emit status( statusMsg ); |
60 | 59 | ||
61 | // Kick off the state machine | 60 | // Kick off the state machine |
62 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotServerVersion() ) ); | 61 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotServerVersion() ) ); |
63 | con->waitForData( ServerVersionLength ); | 62 | con->waitForData( ServerVersionLength ); |
64 | } | 63 | } |
65 | 64 | ||
66 | KRFBLogin::~KRFBLogin() | 65 | KRFBLogin::~KRFBLogin() |
67 | { | 66 | { |
68 | 67 | ||
69 | } | 68 | } |
70 | 69 | ||
71 | KRFBLogin::State KRFBLogin::state() const | 70 | KRFBLogin::State KRFBLogin::state() const |
72 | { | 71 | { |
73 | return currentState; | 72 | return currentState; |
74 | } | 73 | } |
75 | 74 | ||
76 | void KRFBLogin::gotServerVersion() | 75 | void KRFBLogin::gotServerVersion() |
77 | { | 76 | { |
78 | qWarning( "Got server version" ); | 77 | qWarning( "Got server version" ); |
79 | 78 | ||
80 | disconnect( con, SIGNAL( gotEnoughData() ), | 79 | disconnect( con, SIGNAL( gotEnoughData() ), |
81 | this, SLOT( gotServerVersion() ) ); | 80 | this, SLOT( gotServerVersion() ) ); |
82 | 81 | ||
83 | // Read the server's version message | 82 | // Read the server's version message |
84 | char serverVersion[ ServerVersionLength + 1 ]; | 83 | char serverVersion[ ServerVersionLength + 1 ]; |
85 | con->read( serverVersion, ServerVersionLength ); | 84 | con->read( serverVersion, ServerVersionLength ); |
86 | serverVersion[ ServerVersionLength ] = '\0'; | 85 | serverVersion[ ServerVersionLength ] = '\0'; |
87 | 86 | ||
88 | QCString rfbString( serverVersion, ServerVersionLength + 1 ); | 87 | QCString rfbString( serverVersion, ServerVersionLength + 1 ); |
89 | versionString = rfbString; | 88 | versionString = rfbString; |
90 | 89 | ||
91 | QRegExp regexp( "RFB [0-9][0-9][0-9]\\.[0-9][0-9][0-9]\n" ); | 90 | QRegExp regexp( "RFB [0-9][0-9][0-9]\\.[0-9][0-9][0-9]\n" ); |
92 | 91 | ||
93 | if ( rfbString.find( regexp ) == -1 ) { | 92 | if ( rfbString.find( regexp ) == -1 ) { |
94 | static QString msg = tr( "Error: Invalid server version, %1" ).arg( rfbString ); | 93 | static QString msg = tr( "Error: Invalid server version, %1" ).arg( rfbString ); |
95 | 94 | ||
96 | qWarning( msg ); | 95 | qWarning( msg ); |
97 | emit error( msg ); | 96 | emit error( msg ); |
98 | currentState = Error; | 97 | currentState = Error; |
99 | return; | 98 | return; |
100 | } | 99 | } |
101 | 100 | ||
102 | // Calculate the actual version number | 101 | // Calculate the actual version number |
103 | serverMajor = (serverVersion[4] - '0') * 100 | 102 | serverMajor = (serverVersion[4] - '0') * 100 |
104 | + (serverVersion[5] - '0') * 10 | 103 | + (serverVersion[5] - '0') * 10 |
105 | + (serverVersion[6] - '0'); | 104 | + (serverVersion[6] - '0'); |
106 | serverMinor = (serverVersion[8] - '0') * 100 | 105 | serverMinor = (serverVersion[8] - '0') * 100 |
107 | + (serverVersion[9] - '0') * 10 | 106 | + (serverVersion[9] - '0') * 10 |
108 | + (serverVersion[10] - '0'); | 107 | + (serverVersion[10] - '0'); |
109 | 108 | ||
110 | qWarning("Server Version: %03d.%03d", serverMajor, serverMinor ); | 109 | qWarning("Server Version: %03d.%03d", serverMajor, serverMinor ); |
111 | 110 | ||
112 | if ( serverMajor != 3 ) { | 111 | if ( serverMajor != 3 ) { |
113 | QString msg = tr( "Error: Unsupported server version, %1" ) | 112 | QString msg = tr( "Error: Unsupported server version, %1" ) |
114 | .arg( rfbString ); | 113 | .arg( rfbString ); |
115 | 114 | ||
116 | qWarning( msg ); | 115 | qWarning( msg ); |
117 | emit error( msg ); | 116 | emit error( msg ); |
118 | currentState = Error; | 117 | currentState = Error; |
119 | return; | 118 | return; |
120 | } | 119 | } |
121 | 120 | ||
122 | if ( serverMinor != 3 ) { | 121 | if ( serverMinor != 3 ) { |
123 | qWarning( "Minor version mismatch: %d", serverMinor ); | 122 | qWarning( "Minor version mismatch: %d", serverMinor ); |
124 | } | 123 | } |
125 | 124 | ||
126 | // Setup for the next state | 125 | // Setup for the next state |
127 | sendClientVersion(); | 126 | sendClientVersion(); |
128 | 127 | ||
129 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotAuthScheme() ) ); | 128 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotAuthScheme() ) ); |
130 | con->waitForData( AuthSchemeLength ); | 129 | con->waitForData( AuthSchemeLength ); |
131 | } | 130 | } |
132 | 131 | ||
133 | void KRFBLogin::gotAuthScheme() | 132 | void KRFBLogin::gotAuthScheme() |
134 | { | 133 | { |
135 | disconnect( con, SIGNAL( gotEnoughData() ), | 134 | disconnect( con, SIGNAL( gotEnoughData() ), |
136 | this, SLOT( gotAuthScheme() ) ); | 135 | this, SLOT( gotAuthScheme() ) ); |
137 | 136 | ||
138 | // Got data | 137 | // Got data |
139 | CARD32 scheme; | 138 | CARD32 scheme; |
140 | con->read( &scheme, AuthSchemeLength ); | 139 | con->read( &scheme, AuthSchemeLength ); |
141 | scheme = Swap32IfLE( scheme ); | 140 | scheme = Swap32IfLE( scheme ); |
142 | 141 | ||
143 | static QString statusMsgOk = tr( "Logged in" ); | 142 | static QString statusMsgOk = tr( "Logged in" ); |
144 | 143 | ||
145 | switch ( scheme ) { | 144 | switch ( scheme ) { |
146 | case 0: | 145 | case 0: |
147 | qWarning( "Failed" ); | 146 | qWarning( "Failed" ); |
148 | // Handle failure | 147 | // Handle failure |
149 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotFailureReasonSize() ) ); | 148 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotFailureReasonSize() ) ); |
150 | con->waitForData( FailureReasonSizeLength ); | 149 | con->waitForData( FailureReasonSizeLength ); |
151 | break; | 150 | break; |
152 | case 1: | 151 | case 1: |
153 | // Handle no auth | 152 | // Handle no auth |
154 | emit status( statusMsgOk ); | 153 | emit status( statusMsgOk ); |
155 | con->gotRFBConnection(); | 154 | con->gotRFBConnection(); |
156 | break; | 155 | break; |
157 | case 2: | 156 | case 2: |
158 | // Handle VNC auth | 157 | // Handle VNC auth |
159 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotChallenge() ) ); | 158 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotChallenge() ) ); |
160 | con->waitForData( ChallengeLength ); | 159 | con->waitForData( ChallengeLength ); |
161 | break; | 160 | break; |
162 | default: | 161 | default: |
163 | qWarning( "Unknown authentication scheme, 0x%08lx", scheme ); | 162 | qWarning( "Unknown authentication scheme, 0x%08lx", scheme ); |
164 | currentState = Error; | 163 | currentState = Error; |
165 | break; | 164 | break; |
166 | }; | 165 | }; |
167 | } | 166 | } |
168 | 167 | ||
169 | void KRFBLogin::gotChallenge() | 168 | void KRFBLogin::gotChallenge() |
170 | { | 169 | { |
171 | disconnect( con, SIGNAL( gotEnoughData() ), | 170 | disconnect( con, SIGNAL( gotEnoughData() ), |
172 | this, SLOT( gotChallenge() ) ); | 171 | this, SLOT( gotChallenge() ) ); |
173 | 172 | ||
174 | QTimer::singleShot( 0, this, SLOT(getPassword()) ); | 173 | QTimer::singleShot( 0, this, SLOT(getPassword()) ); |
175 | } | 174 | } |
176 | 175 | ||
177 | void KRFBLogin::getPassword() | 176 | void KRFBLogin::getPassword() |
178 | { | 177 | { |
179 | // Got data | 178 | // Got data |
180 | CARD8 challenge[ ChallengeLength ]; | 179 | CARD8 challenge[ ChallengeLength ]; |
181 | con->read( challenge, ChallengeLength ); | 180 | con->read( challenge, ChallengeLength ); |
182 | 181 | ||
183 | // Last chance to enter a password | 182 | // Last chance to enter a password |
184 | if ( con->options_->password.isNull() ) { | 183 | if ( con->options_->password.isNull() ) { |
185 | qWarning( "krfblogin needs a password" ); | 184 | qWarning( "krfblogin needs a password" ); |
186 | emit passwordRequired( con ); | 185 | emit passwordRequired( con ); |
187 | } | 186 | } |
188 | 187 | ||
189 | if ( con->options_->password.isNull() ) { | 188 | if ( con->options_->password.isNull() ) { |
190 | QString msg = tr( "Error: This server requires a password, but none " | 189 | QString msg = tr( "Error: This server requires a password, but none " |
191 | "has been specified.\n" ); | 190 | "has been specified.\n" ); |
192 | 191 | ||
193 | emit error( msg ); | 192 | emit error( msg ); |
194 | return; | 193 | return; |
195 | } | 194 | } |
196 | 195 | ||
197 | vncEncryptBytes( (unsigned char *) challenge, QCString(con->options_->password.latin1()).data() ); | 196 | vncEncryptBytes( (unsigned char *) challenge, QCString(con->options_->password.latin1()).data() ); |
198 | con->write( challenge, ChallengeLength ); | 197 | con->write( challenge, ChallengeLength ); |
199 | 198 | ||
200 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotAuthResult() ) ); | 199 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotAuthResult() ) ); |
201 | con->waitForData( AuthResultLength ); | 200 | con->waitForData( AuthResultLength ); |
202 | } | 201 | } |
203 | 202 | ||
204 | void KRFBLogin::gotFailureReasonSize() | 203 | void KRFBLogin::gotFailureReasonSize() |
205 | { | 204 | { |
206 | disconnect( con, SIGNAL( gotEnoughData() ), this, | 205 | disconnect( con, SIGNAL( gotEnoughData() ), this, |
207 | SLOT( gotFailureReasonSize() ) ); | 206 | SLOT( gotFailureReasonSize() ) ); |
208 | } | 207 | } |
209 | 208 | ||
210 | void KRFBLogin::gotAuthResult() | 209 | void KRFBLogin::gotAuthResult() |
211 | { | 210 | { |
212 | // Got data | 211 | // Got data |
213 | disconnect( con, SIGNAL( gotEnoughData() ), this, | 212 | disconnect( con, SIGNAL( gotEnoughData() ), this, |
214 | SLOT( gotAuthResult() ) ); | 213 | SLOT( gotAuthResult() ) ); |
215 | 214 | ||
216 | long result; | 215 | long result; |
217 | con->read( &result, AuthResultLength ); | 216 | con->read( &result, AuthResultLength ); |
218 | result = Swap32IfLE( result ); | 217 | result = Swap32IfLE( result ); |
219 | 218 | ||
220 | qWarning( "Authentication Result is 0x%08lx", result ); | 219 | qWarning( "Authentication Result is 0x%08lx", result ); |
221 | 220 | ||
222 | static QString failed = tr( "Error: The password you specified was incorrect." ); | 221 | static QString failed = tr( "Error: The password you specified was incorrect." ); |
223 | static QString tooMany = tr( "Error: Too many invalid login attempts have been made\n" | 222 | static QString tooMany = tr( "Error: Too many invalid login attempts have been made\n" |
224 | "to this account, please try later." ); | 223 | "to this account, please try later." ); |
225 | 224 | ||
226 | static QString statusMsgOk = tr( "Logged in" ); | 225 | static QString statusMsgOk = tr( "Logged in" ); |
227 | static QString statusMsgFailed = tr( "Login Failed" ); | 226 | static QString statusMsgFailed = tr( "Login Failed" ); |
228 | static QString statusMsgTooMany = tr( "Too many failures" ); | 227 | static QString statusMsgTooMany = tr( "Too many failures" ); |
229 | 228 | ||
230 | switch( result ) { | 229 | switch( result ) { |
231 | case AuthOk: | 230 | case AuthOk: |
232 | emit status( statusMsgOk ); | 231 | emit status( statusMsgOk ); |
233 | con->gotRFBConnection(); | 232 | con->gotRFBConnection(); |
234 | break; | 233 | break; |
235 | case AuthFailed: | 234 | case AuthFailed: |
236 | qWarning( "Dammit" ); | 235 | qWarning( "Dammit" ); |
237 | emit status( statusMsgFailed ); | 236 | emit status( statusMsgFailed ); |
238 | emit error( failed ); | 237 | emit error( failed ); |
239 | break; | 238 | break; |
240 | case AuthTooMany: | 239 | case AuthTooMany: |
241 | emit status( statusMsgTooMany ); | 240 | emit status( statusMsgTooMany ); |
242 | emit error( tooMany ); | 241 | emit error( tooMany ); |
243 | break; | 242 | break; |
244 | default: | 243 | default: |
245 | qWarning( "Invalid authentication result, %lx", result ); | 244 | qWarning( "Invalid authentication result, %lx", result ); |
246 | break; | 245 | break; |
247 | } | 246 | } |
248 | } | 247 | } |
249 | 248 | ||
250 | void KRFBLogin::sendClientVersion() | 249 | void KRFBLogin::sendClientVersion() |
251 | { | 250 | { |
252 | qWarning( "Sending client version" ); | 251 | qWarning( "Sending client version" ); |
253 | con->write( (void*)"RFB 003.003\n", ClientVersionLength ); | 252 | con->write( (void*)"RFB 003.003\n", ClientVersionLength ); |
254 | } | 253 | } |
diff --git a/noncore/comm/keypebble/krfbserver.cpp b/noncore/comm/keypebble/krfbserver.cpp index b47534e..fda81a1 100644 --- a/noncore/comm/keypebble/krfbserver.cpp +++ b/noncore/comm/keypebble/krfbserver.cpp | |||
@@ -1,41 +1,40 @@ | |||
1 | #include <qpe/config.h> | ||
2 | #include <qpe/qpeapplication.h> | 1 | #include <qpe/qpeapplication.h> |
3 | #include "krfbserver.h" | 2 | #include "krfbserver.h" |
4 | 3 | ||
5 | KRFBServer::KRFBServer() | 4 | KRFBServer::KRFBServer() |
6 | { | 5 | { |
7 | QString name; | 6 | QString name; |
8 | QString hostname; | 7 | QString hostname; |
9 | QString password; | 8 | QString password; |
10 | display=0; | 9 | display=0; |
11 | 10 | ||
12 | scaleFactor=1; | 11 | scaleFactor=1; |
13 | 12 | ||
14 | hexTile=0; | 13 | hexTile=0; |
15 | corre=0; | 14 | corre=0; |
16 | rre=0; | 15 | rre=0; |
17 | copyrect=1; | 16 | copyrect=1; |
18 | 17 | ||
19 | colors256=1; | 18 | colors256=1; |
20 | shared=0; | 19 | shared=0; |
21 | readOnly=0; | 20 | readOnly=0; |
22 | deIconify=0; | 21 | deIconify=0; |
23 | 22 | ||
24 | updateRate=0; | 23 | updateRate=0; |
25 | } | 24 | } |
26 | KRFBServer::~KRFBServer() | 25 | KRFBServer::~KRFBServer() |
27 | { | 26 | { |
28 | } | 27 | } |
29 | 28 | ||
30 | int KRFBServer::encodings() | 29 | int KRFBServer::encodings() |
31 | { | 30 | { |
32 | // Initially one because we always support raw encoding | 31 | // Initially one because we always support raw encoding |
33 | int count = 1; | 32 | int count = 1; |
34 | 33 | ||
35 | count += hexTile ? 1 : 0; | 34 | count += hexTile ? 1 : 0; |
36 | count += corre ? 1 : 0; | 35 | count += corre ? 1 : 0; |
37 | count += rre ? 1 : 0; | 36 | count += rre ? 1 : 0; |
38 | count += copyrect ? 1 : 0; | 37 | count += copyrect ? 1 : 0; |
39 | 38 | ||
40 | return count; | 39 | return count; |
41 | } | 40 | } |
diff --git a/noncore/comm/keypebble/kvnc.cpp b/noncore/comm/keypebble/kvnc.cpp index 2fa8d1f..c678edf 100644 --- a/noncore/comm/keypebble/kvnc.cpp +++ b/noncore/comm/keypebble/kvnc.cpp | |||
@@ -1,292 +1,279 @@ | |||
1 | #include <qiconset.h> | ||
2 | #include <qdialog.h> | ||
3 | #include <qpixmap.h> | ||
4 | #include <qdom.h> | ||
5 | #include <qaction.h> | 1 | #include <qaction.h> |
6 | #include <qmenubar.h> | ||
7 | #include <qstatusbar.h> | ||
8 | #include <qpopupmenu.h> | 2 | #include <qpopupmenu.h> |
9 | #include <qpushbutton.h> | 3 | #include <qpushbutton.h> |
10 | #include <qpe/qpetoolbar.h> | ||
11 | #include <qtimer.h> | ||
12 | #include <qmessagebox.h> | 4 | #include <qmessagebox.h> |
13 | #include <qspinbox.h> | ||
14 | #include <qlistbox.h> | 5 | #include <qlistbox.h> |
15 | #include <qlineedit.h> | ||
16 | #include <qpe/qpeapplication.h> | 6 | #include <qpe/qpeapplication.h> |
17 | #include <qpe/global.h> | ||
18 | #include <qpe/qpetoolbar.h> | ||
19 | #include <qpe/resource.h> | 7 | #include <qpe/resource.h> |
20 | 8 | ||
21 | #include <assert.h> | 9 | #include <assert.h> |
22 | 10 | ||
23 | #include "kvnc.h" | 11 | #include "kvnc.h" |
24 | #include "krfbcanvas.h" | 12 | #include "krfbcanvas.h" |
25 | #include "krfbconnection.h" | 13 | #include "krfbconnection.h" |
26 | #include "kvncconndlg.h" | 14 | #include "kvncconndlg.h" |
27 | #include "krfbserver.h" | ||
28 | 15 | ||
29 | static int u_id = 1; | 16 | static int u_id = 1; |
30 | static int get_unique_id() | 17 | static int get_unique_id() |
31 | { | 18 | { |
32 | return u_id++; | 19 | return u_id++; |
33 | } | 20 | } |
34 | 21 | ||
35 | 22 | ||
36 | /* XPM */ | 23 | /* XPM */ |
37 | static char * menu_xpm[] = { | 24 | static char * menu_xpm[] = { |
38 | "12 12 5 1", | 25 | "12 12 5 1", |
39 | " c None", | 26 | " c None", |
40 | ".c #000000", | 27 | ".c #000000", |
41 | "+c #FFFDAD", | 28 | "+c #FFFDAD", |
42 | "@c #FFFF00", | 29 | "@c #FFFF00", |
43 | "#c #E5E100", | 30 | "#c #E5E100", |
44 | " ", | 31 | " ", |
45 | " ", | 32 | " ", |
46 | " ......... ", | 33 | " ......... ", |
47 | " .+++++++. ", | 34 | " .+++++++. ", |
48 | " .+@@@@#. ", | 35 | " .+@@@@#. ", |
49 | " .+@@@#. ", | 36 | " .+@@@#. ", |
50 | " .+@@#. ", | 37 | " .+@@#. ", |
51 | " .+@#. ", | 38 | " .+@#. ", |
52 | " .+#. ", | 39 | " .+#. ", |
53 | " .+. ", | 40 | " .+. ", |
54 | " .. ", | 41 | " .. ", |
55 | " "}; | 42 | " "}; |
56 | 43 | ||
57 | const int StatusTextId = 0; | 44 | const int StatusTextId = 0; |
58 | 45 | ||
59 | KVNC::KVNC( QWidget *parent, const char *name, WFlags f) : QMainWindow( 0, name ,WStyle_ContextHelp) | 46 | KVNC::KVNC( QWidget *parent, const char *name, WFlags f) : QMainWindow( 0, name ,WStyle_ContextHelp) |
60 | { | 47 | { |
61 | setCaption( tr("VNC Viewer") ); | 48 | setCaption( tr("VNC Viewer") ); |
62 | fullscreen = false; | 49 | fullscreen = false; |
63 | 50 | ||
64 | stack = new QWidgetStack( this ); | 51 | stack = new QWidgetStack( this ); |
65 | setCentralWidget( stack ); | 52 | setCentralWidget( stack ); |
66 | 53 | ||
67 | bookmarkSelector=new KVNCBookmarkDlg(); | 54 | bookmarkSelector=new KVNCBookmarkDlg(); |
68 | stack->addWidget(bookmarkSelector,get_unique_id()); | 55 | stack->addWidget(bookmarkSelector,get_unique_id()); |
69 | stack->raiseWidget( bookmarkSelector ); | 56 | stack->raiseWidget( bookmarkSelector ); |
70 | 57 | ||
71 | canvas = new KRFBCanvas( stack, "canvas" ); | 58 | canvas = new KRFBCanvas( stack, "canvas" ); |
72 | stack->addWidget(canvas,get_unique_id()); | 59 | stack->addWidget(canvas,get_unique_id()); |
73 | setCentralWidget( stack ); | 60 | setCentralWidget( stack ); |
74 | 61 | ||
75 | 62 | ||
76 | connect( bookmarkSelector->bookmarkList, SIGNAL(clicked(QListBoxItem *)), | 63 | connect( bookmarkSelector->bookmarkList, SIGNAL(clicked(QListBoxItem *)), |
77 | this, SLOT(openConnection(QListBoxItem *)) ); | 64 | this, SLOT(openConnection(QListBoxItem *)) ); |
78 | connect( canvas->connection(), SIGNAL(statusChanged(const QString &)), | 65 | connect( canvas->connection(), SIGNAL(statusChanged(const QString &)), |
79 | this, SLOT(statusMessage(const QString &)) ); | 66 | this, SLOT(statusMessage(const QString &)) ); |
80 | connect( canvas->connection(), SIGNAL(error(const QString &)), | 67 | connect( canvas->connection(), SIGNAL(error(const QString &)), |
81 | this, SLOT(error(const QString &)) ); | 68 | this, SLOT(error(const QString &)) ); |
82 | connect( canvas->connection(), SIGNAL(connected()), this, SLOT(connected()) ); | 69 | connect( canvas->connection(), SIGNAL(connected()), this, SLOT(connected()) ); |
83 | connect( canvas->connection(), SIGNAL(loggedIn()), this, SLOT(loggedIn()) ); | 70 | connect( canvas->connection(), SIGNAL(loggedIn()), this, SLOT(loggedIn()) ); |
84 | connect( canvas->connection(), SIGNAL(disconnected()), this, SLOT(disconnected()) ); | 71 | connect( canvas->connection(), SIGNAL(disconnected()), this, SLOT(disconnected()) ); |
85 | 72 | ||
86 | setupActions(); | 73 | setupActions(); |
87 | 74 | ||
88 | cornerButton = new QPushButton( this ); | 75 | cornerButton = new QPushButton( this ); |
89 | cornerButton->setPixmap( QPixmap( (const char**)menu_xpm ) ); | 76 | cornerButton->setPixmap( QPixmap( (const char**)menu_xpm ) ); |
90 | connect( cornerButton, SIGNAL(pressed()), this, SLOT(showMenu()) ); | 77 | connect( cornerButton, SIGNAL(pressed()), this, SLOT(showMenu()) ); |
91 | canvas->setCornerWidget( cornerButton ); | 78 | canvas->setCornerWidget( cornerButton ); |
92 | 79 | ||
93 | stack->raiseWidget( bookmarkSelector ); | 80 | stack->raiseWidget( bookmarkSelector ); |
94 | 81 | ||
95 | 82 | ||
96 | bar= new QToolBar( this ); | 83 | bar= new QToolBar( this ); |
97 | setToolBarsMovable( false ); | 84 | setToolBarsMovable( false ); |
98 | setRightJustification(false); | 85 | setRightJustification(false); |
99 | 86 | ||
100 | 87 | ||
101 | QAction *n = new QAction( tr( "New Connection" ), Resource::loadPixmap( "new" ), | 88 | QAction *n = new QAction( tr( "New Connection" ), Resource::loadPixmap( "new" ), |
102 | QString::null, 0, this, 0 ); | 89 | QString::null, 0, this, 0 ); |
103 | connect( n, SIGNAL( activated() ), | 90 | connect( n, SIGNAL( activated() ), |
104 | this, SLOT( newConnection() ) ); | 91 | this, SLOT( newConnection() ) ); |
105 | n->addTo( bar ); | 92 | n->addTo( bar ); |
106 | 93 | ||
107 | QAction *o = new QAction( tr( "Open Bookmark" ), Resource::loadPixmap( "fileopen" ), | 94 | QAction *o = new QAction( tr( "Open Bookmark" ), Resource::loadPixmap( "fileopen" ), |
108 | QString::null, 0, this, 0 ); | 95 | QString::null, 0, this, 0 ); |
109 | connect( o, SIGNAL( activated() ), | 96 | connect( o, SIGNAL( activated() ), |
110 | this, SLOT( openConnection() ) ); | 97 | this, SLOT( openConnection() ) ); |
111 | o->addTo( bar ); | 98 | o->addTo( bar ); |
112 | 99 | ||
113 | QAction *d = new QAction( tr( "Delete Bookmark" ), Resource::loadPixmap( "trash" ), | 100 | QAction *d = new QAction( tr( "Delete Bookmark" ), Resource::loadPixmap( "trash" ), |
114 | QString::null, 0, this, 0 ); | 101 | QString::null, 0, this, 0 ); |
115 | connect( d, SIGNAL( activated() ), | 102 | connect( d, SIGNAL( activated() ), |
116 | this, SLOT( deleteBookmark() ) ); | 103 | this, SLOT( deleteBookmark() ) ); |
117 | d->addTo( bar ); | 104 | d->addTo( bar ); |
118 | } | 105 | } |
119 | 106 | ||
120 | KVNC::~KVNC() | 107 | KVNC::~KVNC() |
121 | { | 108 | { |
122 | 109 | ||
123 | } | 110 | } |
124 | 111 | ||
125 | void KVNC::newConnection() | 112 | void KVNC::newConnection() |
126 | { | 113 | { |
127 | curServer=new KRFBServer; | 114 | curServer=new KRFBServer; |
128 | 115 | ||
129 | KVNCConnDlg dlg( curServer,this); | 116 | KVNCConnDlg dlg( curServer,this); |
130 | if ( QPEApplication::execDialog( &dlg )) { | 117 | if ( QPEApplication::execDialog( &dlg )) { |
131 | if (!curServer->name.isEmpty()) | 118 | if (!curServer->name.isEmpty()) |
132 | bookmarkSelector->addBookmark(curServer); | 119 | bookmarkSelector->addBookmark(curServer); |
133 | canvas->openConnection(*curServer); | 120 | canvas->openConnection(*curServer); |
134 | } else | 121 | } else |
135 | curServer=0; | 122 | curServer=0; |
136 | } | 123 | } |
137 | 124 | ||
138 | void KVNC::openConnection( QString name) | 125 | void KVNC::openConnection( QString name) |
139 | { | 126 | { |
140 | curServer=bookmarkSelector->getServer(name); | 127 | curServer=bookmarkSelector->getServer(name); |
141 | 128 | ||
142 | if (curServer) { | 129 | if (curServer) { |
143 | KVNCConnDlg dlg( curServer,this); | 130 | KVNCConnDlg dlg( curServer,this); |
144 | if ( QPEApplication::execDialog( &dlg ) ) { | 131 | if ( QPEApplication::execDialog( &dlg ) ) { |
145 | canvas->openConnection(*curServer); | 132 | canvas->openConnection(*curServer); |
146 | bookmarkSelector->writeBookmarks(); | 133 | bookmarkSelector->writeBookmarks(); |
147 | } else | 134 | } else |
148 | curServer=0; | 135 | curServer=0; |
149 | } | 136 | } |
150 | } | 137 | } |
151 | 138 | ||
152 | void KVNC::openConnection( void ) | 139 | void KVNC::openConnection( void ) |
153 | { | 140 | { |
154 | openConnection( bookmarkSelector->selectedBookmark()); | 141 | openConnection( bookmarkSelector->selectedBookmark()); |
155 | } | 142 | } |
156 | 143 | ||
157 | void KVNC::openConnection( QListBoxItem * item) | 144 | void KVNC::openConnection( QListBoxItem * item) |
158 | { | 145 | { |
159 | if (item) | 146 | if (item) |
160 | openConnection(item->text()); | 147 | openConnection(item->text()); |
161 | } | 148 | } |
162 | 149 | ||
163 | void KVNC::setupActions() | 150 | void KVNC::setupActions() |
164 | { | 151 | { |
165 | cornerMenu = new QPopupMenu( this ); | 152 | cornerMenu = new QPopupMenu( this ); |
166 | 153 | ||
167 | fullScreenAction = new QAction( tr("Full Screen"), QString::null, 0, 0 ); | 154 | fullScreenAction = new QAction( tr("Full Screen"), QString::null, 0, 0 ); |
168 | connect( fullScreenAction, SIGNAL(activated()), | 155 | connect( fullScreenAction, SIGNAL(activated()), |
169 | this, SLOT( toggleFullScreen() ) ); | 156 | this, SLOT( toggleFullScreen() ) ); |
170 | fullScreenAction->addTo( cornerMenu ); | 157 | fullScreenAction->addTo( cornerMenu ); |
171 | fullScreenAction->setEnabled( false ); | 158 | fullScreenAction->setEnabled( false ); |
172 | 159 | ||
173 | ctlAltDelAction = new QAction( tr("Send Contrl-Alt-Delete"), QString::null, 0, 0 ); | 160 | ctlAltDelAction = new QAction( tr("Send Contrl-Alt-Delete"), QString::null, 0, 0 ); |
174 | connect( ctlAltDelAction, SIGNAL(activated()), | 161 | connect( ctlAltDelAction, SIGNAL(activated()), |
175 | canvas, SLOT( sendCtlAltDel() ) ); | 162 | canvas, SLOT( sendCtlAltDel() ) ); |
176 | ctlAltDelAction->addTo( cornerMenu ); | 163 | ctlAltDelAction->addTo( cornerMenu ); |
177 | ctlAltDelAction->setEnabled( false ); | 164 | ctlAltDelAction->setEnabled( false ); |
178 | 165 | ||
179 | disconnectAction = new QAction( tr("Disconnect"), QString::null, 0, 0 ); | 166 | disconnectAction = new QAction( tr("Disconnect"), QString::null, 0, 0 ); |
180 | connect( disconnectAction, SIGNAL(activated()), | 167 | connect( disconnectAction, SIGNAL(activated()), |
181 | this, SLOT( closeConnection() ) ); | 168 | this, SLOT( closeConnection() ) ); |
182 | disconnectAction->addTo( cornerMenu ); | 169 | disconnectAction->addTo( cornerMenu ); |
183 | disconnectAction->setEnabled( false ); | 170 | disconnectAction->setEnabled( false ); |
184 | 171 | ||
185 | doubleClickAction = new QAction( tr("Next Click is Double Click"), QString::null, 0, 0 ); | 172 | doubleClickAction = new QAction( tr("Next Click is Double Click"), QString::null, 0, 0 ); |
186 | connect( doubleClickAction, SIGNAL(activated()), | 173 | connect( doubleClickAction, SIGNAL(activated()), |
187 | canvas, SLOT( markDoubleClick() ) ); | 174 | canvas, SLOT( markDoubleClick() ) ); |
188 | doubleClickAction->addTo( cornerMenu ); | 175 | doubleClickAction->addTo( cornerMenu ); |
189 | doubleClickAction->setEnabled( false ); | 176 | doubleClickAction->setEnabled( false ); |
190 | 177 | ||
191 | rightClickAction = new QAction( tr("Next Click is Right Click"), QString::null, 0, 0 ); | 178 | rightClickAction = new QAction( tr("Next Click is Right Click"), QString::null, 0, 0 ); |
192 | connect( rightClickAction, SIGNAL(activated()), | 179 | connect( rightClickAction, SIGNAL(activated()), |
193 | canvas, SLOT( markRightClick() ) ); | 180 | canvas, SLOT( markRightClick() ) ); |
194 | rightClickAction->addTo( cornerMenu ); | 181 | rightClickAction->addTo( cornerMenu ); |
195 | rightClickAction->setEnabled( false ); | 182 | rightClickAction->setEnabled( false ); |
196 | } | 183 | } |
197 | 184 | ||
198 | void KVNC::toggleFullScreen() | 185 | void KVNC::toggleFullScreen() |
199 | { | 186 | { |
200 | if ( fullscreen ) { | 187 | if ( fullscreen ) { |
201 | canvas->releaseKeyboard(); | 188 | canvas->releaseKeyboard(); |
202 | canvas->reparent( stack, 0, QPoint(0,0), false ); | 189 | canvas->reparent( stack, 0, QPoint(0,0), false ); |
203 | canvas->setFrameStyle( QFrame::Panel | QFrame::Sunken ); | 190 | canvas->setFrameStyle( QFrame::Panel | QFrame::Sunken ); |
204 | setCentralWidget( stack ); | 191 | setCentralWidget( stack ); |
205 | stack->addWidget(canvas,get_unique_id()); | 192 | stack->addWidget(canvas,get_unique_id()); |
206 | stack->raiseWidget(canvas); | 193 | stack->raiseWidget(canvas); |
207 | canvas->show(); | 194 | canvas->show(); |
208 | stack->show(); | 195 | stack->show(); |
209 | fullScreenAction->setText( tr("Full Screen") ); | 196 | fullScreenAction->setText( tr("Full Screen") ); |
210 | } else { | 197 | } else { |
211 | canvas->setFrameStyle( QFrame::NoFrame ); | 198 | canvas->setFrameStyle( QFrame::NoFrame ); |
212 | stack->removeWidget(canvas); | 199 | stack->removeWidget(canvas); |
213 | canvas->reparent( 0,WStyle_Tool | WStyle_Customize | WStyle_StaysOnTop, | 200 | canvas->reparent( 0,WStyle_Tool | WStyle_Customize | WStyle_StaysOnTop, |
214 | QPoint(0,0),false); | 201 | QPoint(0,0),false); |
215 | canvas->resize(qApp->desktop()->width(), qApp->desktop()->height()); | 202 | canvas->resize(qApp->desktop()->width(), qApp->desktop()->height()); |
216 | canvas->raise(); | 203 | canvas->raise(); |
217 | canvas->setFocus(); | 204 | canvas->setFocus(); |
218 | canvas->grabKeyboard(); | 205 | canvas->grabKeyboard(); |
219 | canvas->show(); | 206 | canvas->show(); |
220 | 207 | ||
221 | fullScreenAction->setText( tr("Stop Full Screen") ); | 208 | fullScreenAction->setText( tr("Stop Full Screen") ); |
222 | } | 209 | } |
223 | 210 | ||
224 | 211 | ||
225 | fullscreen = !fullscreen; | 212 | fullscreen = !fullscreen; |
226 | } | 213 | } |
227 | 214 | ||
228 | void KVNC::closeConnection() | 215 | void KVNC::closeConnection() |
229 | { | 216 | { |
230 | if ( fullscreen ) | 217 | if ( fullscreen ) |
231 | toggleFullScreen(); | 218 | toggleFullScreen(); |
232 | canvas->closeConnection(); | 219 | canvas->closeConnection(); |
233 | } | 220 | } |
234 | 221 | ||
235 | void KVNC::showMenu() | 222 | void KVNC::showMenu() |
236 | { | 223 | { |
237 | QPoint pt = mapToGlobal(cornerButton->pos()); | 224 | QPoint pt = mapToGlobal(cornerButton->pos()); |
238 | QSize s = cornerMenu->sizeHint(); | 225 | QSize s = cornerMenu->sizeHint(); |
239 | pt.ry() -= s.height(); | 226 | pt.ry() -= s.height(); |
240 | pt.rx() -= s.width(); | 227 | pt.rx() -= s.width(); |
241 | cornerMenu->popup( pt ); | 228 | cornerMenu->popup( pt ); |
242 | } | 229 | } |
243 | 230 | ||
244 | void KVNC::connected() | 231 | void KVNC::connected() |
245 | { | 232 | { |
246 | static QString msg = tr( "Connected to remote host" ); | 233 | static QString msg = tr( "Connected to remote host" ); |
247 | statusMessage( msg ); | 234 | statusMessage( msg ); |
248 | ctlAltDelAction->setEnabled(true); | 235 | ctlAltDelAction->setEnabled(true); |
249 | disconnectAction->setEnabled( true ); | 236 | disconnectAction->setEnabled( true ); |
250 | fullScreenAction->setEnabled( true ); | 237 | fullScreenAction->setEnabled( true ); |
251 | doubleClickAction->setEnabled( false ); | 238 | doubleClickAction->setEnabled( false ); |
252 | rightClickAction->setEnabled( true ); | 239 | rightClickAction->setEnabled( true ); |
253 | stack->raiseWidget(canvas); | 240 | stack->raiseWidget(canvas); |
254 | bar->hide(); | 241 | bar->hide(); |
255 | } | 242 | } |
256 | 243 | ||
257 | void KVNC::loggedIn() | 244 | void KVNC::loggedIn() |
258 | { | 245 | { |
259 | static QString msg = tr( "Logged in to remote host" ); | 246 | static QString msg = tr( "Logged in to remote host" ); |
260 | statusMessage( msg ); | 247 | statusMessage( msg ); |
261 | } | 248 | } |
262 | 249 | ||
263 | void KVNC::disconnected() | 250 | void KVNC::disconnected() |
264 | { | 251 | { |
265 | 252 | ||
266 | if ( fullscreen ) | 253 | if ( fullscreen ) |
267 | toggleFullScreen(); | 254 | toggleFullScreen(); |
268 | static QString msg = tr( "Connection closed" ); | 255 | static QString msg = tr( "Connection closed" ); |
269 | statusMessage( msg ); | 256 | statusMessage( msg ); |
270 | ctlAltDelAction->setEnabled(false); | 257 | ctlAltDelAction->setEnabled(false); |
271 | disconnectAction->setEnabled( false ); | 258 | disconnectAction->setEnabled( false ); |
272 | fullScreenAction->setEnabled( false ); | 259 | fullScreenAction->setEnabled( false ); |
273 | doubleClickAction->setEnabled( false ); | 260 | doubleClickAction->setEnabled( false ); |
274 | rightClickAction->setEnabled( false ); | 261 | rightClickAction->setEnabled( false ); |
275 | stack->raiseWidget(bookmarkSelector); | 262 | stack->raiseWidget(bookmarkSelector); |
276 | bar->show(); | 263 | bar->show(); |
277 | } | 264 | } |
278 | 265 | ||
279 | void KVNC::statusMessage( const QString &m ) | 266 | void KVNC::statusMessage( const QString &m ) |
280 | { | 267 | { |
281 | Global::statusMessage( m ); | 268 | Global::statusMessage( m ); |
282 | } | 269 | } |
283 | 270 | ||
284 | void KVNC::error( const QString &msg ) | 271 | void KVNC::error( const QString &msg ) |
285 | { | 272 | { |
286 | statusMessage( msg ); | 273 | statusMessage( msg ); |
287 | QMessageBox::warning( this, tr("VNC Viewer"), msg ); | 274 | QMessageBox::warning( this, tr("VNC Viewer"), msg ); |
288 | } | 275 | } |
289 | void KVNC::deleteBookmark(void) | 276 | void KVNC::deleteBookmark(void) |
290 | { | 277 | { |
291 | bookmarkSelector->deleteBookmark(bookmarkSelector->selectedBookmark()); | 278 | bookmarkSelector->deleteBookmark(bookmarkSelector->selectedBookmark()); |
292 | } | 279 | } |
diff --git a/noncore/comm/keypebble/kvncbookmarkdlg.cpp b/noncore/comm/keypebble/kvncbookmarkdlg.cpp index 8556d49..ef2fa12 100644 --- a/noncore/comm/keypebble/kvncbookmarkdlg.cpp +++ b/noncore/comm/keypebble/kvncbookmarkdlg.cpp | |||
@@ -1,223 +1,209 @@ | |||
1 | #include <qframe.h> | ||
2 | #include <qvbox.h> | ||
3 | #include <qcheckbox.h> | ||
4 | #include <qspinbox.h> | ||
5 | #include <qlabel.h> | ||
6 | #include <qlayout.h> | ||
7 | #include <qwhatsthis.h> | ||
8 | #include <qfile.h> | ||
9 | #include <qdir.h> | 1 | #include <qdir.h> |
10 | #include <qstring.h> | ||
11 | #include <qapplication.h> | ||
12 | #include <qlineedit.h> | ||
13 | #include <qtextstream.h> | 2 | #include <qtextstream.h> |
14 | #include <qpushbutton.h> | ||
15 | #include <qlistbox.h> | 3 | #include <qlistbox.h> |
16 | #include <qpe/config.h> | ||
17 | #include <qpe/global.h> | 4 | #include <qpe/global.h> |
18 | #include "krfbserver.h" | ||
19 | #include "kvncbookmarkdlg.h" | 5 | #include "kvncbookmarkdlg.h" |
20 | 6 | ||
21 | KVNCBookmarkDlg::KVNCBookmarkDlg( QWidget * parent, const char * name, WFlags f ) | 7 | KVNCBookmarkDlg::KVNCBookmarkDlg( QWidget * parent, const char * name, WFlags f ) |
22 | 8 | ||
23 | : KVNCBookmarkDlgBase( parent, name,f) | 9 | : KVNCBookmarkDlgBase( parent, name,f) |
24 | { | 10 | { |
25 | readBookmarks(); | 11 | readBookmarks(); |
26 | refresh(); | 12 | refresh(); |
27 | 13 | ||
28 | } | 14 | } |
29 | 15 | ||
30 | KVNCBookmarkDlg::~KVNCBookmarkDlg() | 16 | KVNCBookmarkDlg::~KVNCBookmarkDlg() |
31 | { | 17 | { |
32 | } | 18 | } |
33 | 19 | ||
34 | void KVNCBookmarkDlg::addBookmark(KRFBServer * server) | 20 | void KVNCBookmarkDlg::addBookmark(KRFBServer * server) |
35 | { | 21 | { |
36 | if (server) { | 22 | if (server) { |
37 | servers.append(server); | 23 | servers.append(server); |
38 | bookmarkList->insertItem(server->name); | 24 | bookmarkList->insertItem(server->name); |
39 | writeBookmarks(); | 25 | writeBookmarks(); |
40 | refresh(); | 26 | refresh(); |
41 | } | 27 | } |
42 | } | 28 | } |
43 | 29 | ||
44 | void KVNCBookmarkDlg::deleteBookmark(QString name) | 30 | void KVNCBookmarkDlg::deleteBookmark(QString name) |
45 | { | 31 | { |
46 | KRFBServer * server=0; | 32 | KRFBServer * server=0; |
47 | for ( server=servers.first(); server != 0; server=servers.next() ) { | 33 | for ( server=servers.first(); server != 0; server=servers.next() ) { |
48 | if (server->name==name) { | 34 | if (server->name==name) { |
49 | servers.remove(servers.at()); | 35 | servers.remove(servers.at()); |
50 | writeBookmarks(); | 36 | writeBookmarks(); |
51 | refresh(); | 37 | refresh(); |
52 | return; | 38 | return; |
53 | } | 39 | } |
54 | } | 40 | } |
55 | } | 41 | } |
56 | KRFBServer *KVNCBookmarkDlg::getServer(QString name) | 42 | KRFBServer *KVNCBookmarkDlg::getServer(QString name) |
57 | { | 43 | { |
58 | KRFBServer * server=0; | 44 | KRFBServer * server=0; |
59 | for ( server=servers.first(); server != 0; server=servers.next() ) { | 45 | for ( server=servers.first(); server != 0; server=servers.next() ) { |
60 | if (server->name==name) | 46 | if (server->name==name) |
61 | 47 | ||
62 | return server; | 48 | return server; |
63 | } | 49 | } |
64 | return 0; | 50 | return 0; |
65 | } | 51 | } |
66 | 52 | ||
67 | 53 | ||
68 | /* | 54 | /* |
69 | Note that the degree of protection offered by the encryption here is | 55 | Note that the degree of protection offered by the encryption here is |
70 | only sufficient to avoid the most casual observation of the configuration | 56 | only sufficient to avoid the most casual observation of the configuration |
71 | files. People with access to the files can write down the contents and | 57 | files. People with access to the files can write down the contents and |
72 | decrypt it using this source code. | 58 | decrypt it using this source code. |
73 | 59 | ||
74 | Conceivably, and at some burden to the user, this encryption could | 60 | Conceivably, and at some burden to the user, this encryption could |
75 | be improved. | 61 | be improved. |
76 | */ | 62 | */ |
77 | QString KVNCBookmarkDlg::encipher(const QString& plain) | 63 | QString KVNCBookmarkDlg::encipher(const QString& plain) |
78 | { | 64 | { |
79 | // mainly, we make it long | 65 | // mainly, we make it long |
80 | QString cipher; | 66 | QString cipher; |
81 | int mix=28730492; | 67 | int mix=28730492; |
82 | for (int i=0; i<(int)plain.length(); i++) { | 68 | for (int i=0; i<(int)plain.length(); i++) { |
83 | int u = plain[i].unicode(); | 69 | int u = plain[i].unicode(); |
84 | int c = u ^ mix; | 70 | int c = u ^ mix; |
85 | QString x = QString::number(c,36); | 71 | QString x = QString::number(c,36); |
86 | cipher.append(QChar('a'+x.length())); | 72 | cipher.append(QChar('a'+x.length())); |
87 | cipher.append(x); | 73 | cipher.append(x); |
88 | mix *= u; | 74 | mix *= u; |
89 | } | 75 | } |
90 | return cipher; | 76 | return cipher; |
91 | } | 77 | } |
92 | 78 | ||
93 | QString KVNCBookmarkDlg::decipher(const QString& cipher) | 79 | QString KVNCBookmarkDlg::decipher(const QString& cipher) |
94 | { | 80 | { |
95 | QString plain; | 81 | QString plain; |
96 | int mix=28730492; | 82 | int mix=28730492; |
97 | for (int i=0; i<(int)cipher.length();) { | 83 | for (int i=0; i<(int)cipher.length();) { |
98 | int l = cipher[i].unicode()-'a'; | 84 | int l = cipher[i].unicode()-'a'; |
99 | QString x = cipher.mid(i+1,l); i+=l+1; | 85 | QString x = cipher.mid(i+1,l); i+=l+1; |
100 | int u = x.toInt(0,36) ^ mix; | 86 | int u = x.toInt(0,36) ^ mix; |
101 | plain.append(QChar(u)); | 87 | plain.append(QChar(u)); |
102 | mix *= u; | 88 | mix *= u; |
103 | } | 89 | } |
104 | return plain; | 90 | return plain; |
105 | } | 91 | } |
106 | 92 | ||
107 | void KVNCBookmarkDlg::readBookmarks(void) | 93 | void KVNCBookmarkDlg::readBookmarks(void) |
108 | { | 94 | { |
109 | QFile f(QDir::homeDirPath() + QString("/Applications/keypebble/bookmarks")); | 95 | QFile f(QDir::homeDirPath() + QString("/Applications/keypebble/bookmarks")); |
110 | 96 | ||
111 | QStringList entry; | 97 | QStringList entry; |
112 | QString key, val; | 98 | QString key, val; |
113 | KRFBServer * server=0; | 99 | KRFBServer * server=0; |
114 | 100 | ||
115 | if ( f.open(IO_ReadOnly) ) { | 101 | if ( f.open(IO_ReadOnly) ) { |
116 | QTextStream t( &f ); | 102 | QTextStream t( &f ); |
117 | QString s; | 103 | QString s; |
118 | int n = 1; | 104 | int n = 1; |
119 | while ( !t.eof() ) { | 105 | while ( !t.eof() ) { |
120 | s = t.readLine(); | 106 | s = t.readLine(); |
121 | 107 | ||
122 | 108 | ||
123 | entry=QStringList::split('=',s); | 109 | entry=QStringList::split('=',s); |
124 | key=entry[0].stripWhiteSpace().lower(); | 110 | key=entry[0].stripWhiteSpace().lower(); |
125 | val=entry[1].stripWhiteSpace(); | 111 | val=entry[1].stripWhiteSpace(); |
126 | 112 | ||
127 | if (key=="server") { | 113 | if (key=="server") { |
128 | 114 | ||
129 | if (server){ | 115 | if (server){ |
130 | servers.append(server); | 116 | servers.append(server); |
131 | server=0; | 117 | server=0; |
132 | } | 118 | } |
133 | server = new KRFBServer(); | 119 | server = new KRFBServer(); |
134 | 120 | ||
135 | if (!server) | 121 | if (!server) |
136 | return; | 122 | return; |
137 | server->name=val; | 123 | server->name=val; |
138 | 124 | ||
139 | } | 125 | } |
140 | else if (key=="hostname") | 126 | else if (key=="hostname") |
141 | server->hostname=val; | 127 | server->hostname=val; |
142 | else if (key=="password") | 128 | else if (key=="password") |
143 | server->password=decipher(val); | 129 | server->password=decipher(val); |
144 | else if (key=="display") | 130 | else if (key=="display") |
145 | server->display=val.toInt(); | 131 | server->display=val.toInt(); |
146 | else if (key=="hextile") | 132 | else if (key=="hextile") |
147 | server->hexTile=val.toInt(); | 133 | server->hexTile=val.toInt(); |
148 | else if (key=="corre") | 134 | else if (key=="corre") |
149 | server->corre=val.toInt(); | 135 | server->corre=val.toInt(); |
150 | else if (key=="rre") | 136 | else if (key=="rre") |
151 | server->rre=val.toInt(); | 137 | server->rre=val.toInt(); |
152 | else if (key=="copyrect") | 138 | else if (key=="copyrect") |
153 | server->copyrect=val.toInt(); | 139 | server->copyrect=val.toInt(); |
154 | else if (key=="colors256") | 140 | else if (key=="colors256") |
155 | server->colors256=val.toInt(); | 141 | server->colors256=val.toInt(); |
156 | else if (key=="shared") | 142 | else if (key=="shared") |
157 | server->shared=val.toInt(); | 143 | server->shared=val.toInt(); |
158 | else if (key=="readonly") | 144 | else if (key=="readonly") |
159 | server->readOnly=val.toInt(); | 145 | server->readOnly=val.toInt(); |
160 | else if (key=="deiconify") | 146 | else if (key=="deiconify") |
161 | server->deIconify=val.toInt(); | 147 | server->deIconify=val.toInt(); |
162 | else if (key=="updaterate") | 148 | else if (key=="updaterate") |
163 | server->updateRate=val.toInt(); | 149 | server->updateRate=val.toInt(); |
164 | else if (key=="scalefactor") | 150 | else if (key=="scalefactor") |
165 | server->scaleFactor=val.toInt(); | 151 | server->scaleFactor=val.toInt(); |
166 | 152 | ||
167 | } | 153 | } |
168 | if (server){ | 154 | if (server){ |
169 | servers.append(server); | 155 | servers.append(server); |
170 | server=0; | 156 | server=0; |
171 | } | 157 | } |
172 | f.close(); | 158 | f.close(); |
173 | } | 159 | } |
174 | } | 160 | } |
175 | 161 | ||
176 | void KVNCBookmarkDlg::writeBookmarks(void) | 162 | void KVNCBookmarkDlg::writeBookmarks(void) |
177 | { | 163 | { |
178 | QString filename=Global::applicationFileName("keypebble","bookmarks"); | 164 | QString filename=Global::applicationFileName("keypebble","bookmarks"); |
179 | 165 | ||
180 | QFile f(filename); | 166 | QFile f(filename); |
181 | 167 | ||
182 | QString key, val; | 168 | QString key, val; |
183 | KRFBServer * server=0; | 169 | KRFBServer * server=0; |
184 | 170 | ||
185 | if ( f.open(IO_ReadWrite) ) { | 171 | if ( f.open(IO_ReadWrite) ) { |
186 | QTextStream t( &f ); | 172 | QTextStream t( &f ); |
187 | QString s; | 173 | QString s; |
188 | int n = 1; | 174 | int n = 1; |
189 | KRFBServer *server; | 175 | KRFBServer *server; |
190 | 176 | ||
191 | for ( server=servers.first(); server != 0; server=servers.next() ) { | 177 | for ( server=servers.first(); server != 0; server=servers.next() ) { |
192 | qDebug(server->name); | 178 | qDebug(server->name); |
193 | t << "server=" << server->name << '\n'; | 179 | t << "server=" << server->name << '\n'; |
194 | t << "\thostname=" << server->hostname << '\n'; | 180 | t << "\thostname=" << server->hostname << '\n'; |
195 | t << "\tpassword=" << encipher(server->password )<< '\n'; | 181 | t << "\tpassword=" << encipher(server->password )<< '\n'; |
196 | t << "\tdisplay=" << server->display << '\n'; | 182 | t << "\tdisplay=" << server->display << '\n'; |
197 | t << "\thextile=" << server->hexTile << '\n'; | 183 | t << "\thextile=" << server->hexTile << '\n'; |
198 | t << "\tcorre=" << server->corre << '\n'; | 184 | t << "\tcorre=" << server->corre << '\n'; |
199 | t << "\trre=" << server->rre << '\n'; | 185 | t << "\trre=" << server->rre << '\n'; |
200 | t << "\tcopyrect=" << server->copyrect << '\n'; | 186 | t << "\tcopyrect=" << server->copyrect << '\n'; |
201 | t << "\tshared=" << server->shared << '\n'; | 187 | t << "\tshared=" << server->shared << '\n'; |
202 | t << "\treadonly=" << server->readOnly << '\n'; | 188 | t << "\treadonly=" << server->readOnly << '\n'; |
203 | t << "\tdeiconify=" << server->deIconify << '\n'; | 189 | t << "\tdeiconify=" << server->deIconify << '\n'; |
204 | t << "\tupdaterate=" << server->updateRate << '\n'; | 190 | t << "\tupdaterate=" << server->updateRate << '\n'; |
205 | t << "\tscalefactor=" << server->scaleFactor << '\n'; | 191 | t << "\tscalefactor=" << server->scaleFactor << '\n'; |
206 | 192 | ||
207 | } | 193 | } |
208 | f.close(); | 194 | f.close(); |
209 | } | 195 | } |
210 | } | 196 | } |
211 | void KVNCBookmarkDlg::refresh(void) | 197 | void KVNCBookmarkDlg::refresh(void) |
212 | { | 198 | { |
213 | bookmarkList->clear(); | 199 | bookmarkList->clear(); |
214 | KRFBServer * server=0; | 200 | KRFBServer * server=0; |
215 | for ( server=servers.first(); server != 0; server=servers.next() ) { | 201 | for ( server=servers.first(); server != 0; server=servers.next() ) { |
216 | bookmarkList->insertItem(server->name); | 202 | bookmarkList->insertItem(server->name); |
217 | } | 203 | } |
218 | } | 204 | } |
219 | 205 | ||
220 | QString KVNCBookmarkDlg::selectedBookmark() | 206 | QString KVNCBookmarkDlg::selectedBookmark() |
221 | { | 207 | { |
222 | return bookmarkList->currentText(); | 208 | return bookmarkList->currentText(); |
223 | } | 209 | } |
diff --git a/noncore/comm/keypebble/kvncconndlg.cpp b/noncore/comm/keypebble/kvncconndlg.cpp index cd55bb0..420c816 100644 --- a/noncore/comm/keypebble/kvncconndlg.cpp +++ b/noncore/comm/keypebble/kvncconndlg.cpp | |||
@@ -1,94 +1,86 @@ | |||
1 | #include <qframe.h> | ||
2 | #include <qvbox.h> | ||
3 | #include <qcheckbox.h> | 1 | #include <qcheckbox.h> |
4 | #include <qcombobox.h> | 2 | #include <qcombobox.h> |
5 | #include <qspinbox.h> | 3 | #include <qspinbox.h> |
6 | #include <qlabel.h> | ||
7 | #include <qlayout.h> | ||
8 | #include <qwhatsthis.h> | ||
9 | #include <qapplication.h> | ||
10 | #include <qlineedit.h> | 4 | #include <qlineedit.h> |
11 | #include <qpushbutton.h> | ||
12 | #include "krfbserver.h" | ||
13 | 5 | ||
14 | #include "kvncconndlg.h" | 6 | #include "kvncconndlg.h" |
15 | 7 | ||
16 | KVNCConnDlg::KVNCConnDlg( KRFBServer *options, | 8 | KVNCConnDlg::KVNCConnDlg( KRFBServer *options, |
17 | QWidget *parent, char *name, bool modal ) | 9 | QWidget *parent, char *name, bool modal ) |
18 | : KVNCConnDlgBase( parent, name, modal, WStyle_ContextHelp ) | 10 | : KVNCConnDlgBase( parent, name, modal, WStyle_ContextHelp ) |
19 | { | 11 | { |
20 | this->options=options; | 12 | this->options=options; |
21 | tmpOptions=*options; | 13 | tmpOptions=*options; |
22 | 14 | ||
23 | serverHostname->setText(options->hostname); | 15 | serverHostname->setText(options->hostname); |
24 | serverDisplay->setValue(options->display); | 16 | serverDisplay->setValue(options->display); |
25 | serverPassword->setText(options->password); | 17 | serverPassword->setText(options->password); |
26 | serverBookmark->setText(options->name); | 18 | serverBookmark->setText(options->name); |
27 | 19 | ||
28 | hex->setChecked( options->hexTile ); | 20 | hex->setChecked( options->hexTile ); |
29 | corre->setChecked( options->corre ); | 21 | corre->setChecked( options->corre ); |
30 | rre->setChecked( options->rre ); | 22 | rre->setChecked( options->rre ); |
31 | copyRect->setChecked( options->copyrect ); | 23 | copyRect->setChecked( options->copyrect ); |
32 | 24 | ||
33 | for (int i=0; i < scaleFactor->count(); ++i) { | 25 | for (int i=0; i < scaleFactor->count(); ++i) { |
34 | if (scaleFactor->text(i).toInt()==tmpOptions.scaleFactor) { | 26 | if (scaleFactor->text(i).toInt()==tmpOptions.scaleFactor) { |
35 | scaleFactor->setCurrentItem(i); | 27 | scaleFactor->setCurrentItem(i); |
36 | } | 28 | } |
37 | } | 29 | } |
38 | 30 | ||
39 | // TODO | 31 | // TODO |
40 | hex->setEnabled( false ); | 32 | hex->setEnabled( false ); |
41 | corre->setEnabled( false ); | 33 | corre->setEnabled( false ); |
42 | rre->setEnabled( false ); | 34 | rre->setEnabled( false ); |
43 | // /TODO | 35 | // /TODO |
44 | 36 | ||
45 | deIconify->setChecked( options->deIconify ); | 37 | deIconify->setChecked( options->deIconify ); |
46 | bit->setChecked( options->colors256 ); | 38 | bit->setChecked( options->colors256 ); |
47 | shared->setChecked( options->shared ); | 39 | shared->setChecked( options->shared ); |
48 | timeBox->setValue( options->updateRate ); | 40 | timeBox->setValue( options->updateRate ); |
49 | 41 | ||
50 | serverPassword->setEchoMode(QLineEdit::Password); | 42 | serverPassword->setEchoMode(QLineEdit::Password); |
51 | 43 | ||
52 | connect(togglePassword, SIGNAL( stateChanged(int) ), this, SLOT( showPassword(int) ) ); | 44 | connect(togglePassword, SIGNAL( stateChanged(int) ), this, SLOT( showPassword(int) ) ); |
53 | 45 | ||
54 | 46 | ||
55 | } | 47 | } |
56 | KVNCConnDlg::~KVNCConnDlg() | 48 | KVNCConnDlg::~KVNCConnDlg() |
57 | { | 49 | { |
58 | } | 50 | } |
59 | 51 | ||
60 | void KVNCConnDlg::accept() | 52 | void KVNCConnDlg::accept() |
61 | { | 53 | { |
62 | save(); | 54 | save(); |
63 | QDialog::accept(); | 55 | QDialog::accept(); |
64 | } | 56 | } |
65 | 57 | ||
66 | void KVNCConnDlg::save() | 58 | void KVNCConnDlg::save() |
67 | { | 59 | { |
68 | tmpOptions.hexTile = hex->isChecked(); | 60 | tmpOptions.hexTile = hex->isChecked(); |
69 | tmpOptions.corre = corre->isChecked(); | 61 | tmpOptions.corre = corre->isChecked(); |
70 | tmpOptions.rre = rre->isChecked(); | 62 | tmpOptions.rre = rre->isChecked(); |
71 | tmpOptions.copyrect = copyRect->isChecked(); | 63 | tmpOptions.copyrect = copyRect->isChecked(); |
72 | tmpOptions.deIconify = deIconify->isChecked(); | 64 | tmpOptions.deIconify = deIconify->isChecked(); |
73 | tmpOptions.colors256 = bit->isChecked(); | 65 | tmpOptions.colors256 = bit->isChecked(); |
74 | tmpOptions.shared = shared->isChecked(); | 66 | tmpOptions.shared = shared->isChecked(); |
75 | tmpOptions.hostname = serverHostname->text(); | 67 | tmpOptions.hostname = serverHostname->text(); |
76 | tmpOptions.password = serverPassword->text(); | 68 | tmpOptions.password = serverPassword->text(); |
77 | tmpOptions.display = serverDisplay->value(); | 69 | tmpOptions.display = serverDisplay->value(); |
78 | tmpOptions.name = serverBookmark->text(); | 70 | tmpOptions.name = serverBookmark->text(); |
79 | tmpOptions.scaleFactor = scaleFactor->currentText().toInt(); | 71 | tmpOptions.scaleFactor = scaleFactor->currentText().toInt(); |
80 | 72 | ||
81 | if (!serverBookmark->text().isEmpty()) { | 73 | if (!serverBookmark->text().isEmpty()) { |
82 | if ( options) { | 74 | if ( options) { |
83 | *options=tmpOptions; | 75 | *options=tmpOptions; |
84 | } | 76 | } |
85 | } | 77 | } |
86 | } | 78 | } |
87 | 79 | ||
88 | void KVNCConnDlg::showPassword(int show) | 80 | void KVNCConnDlg::showPassword(int show) |
89 | { | 81 | { |
90 | if (show) | 82 | if (show) |
91 | serverPassword->setEchoMode(QLineEdit::Normal); | 83 | serverPassword->setEchoMode(QLineEdit::Normal); |
92 | else | 84 | else |
93 | serverPassword->setEchoMode(QLineEdit::Password); | 85 | serverPassword->setEchoMode(QLineEdit::Password); |
94 | } | 86 | } |
diff --git a/noncore/comm/keypebble/main.cpp b/noncore/comm/keypebble/main.cpp index 11f67fc..fc34099 100644 --- a/noncore/comm/keypebble/main.cpp +++ b/noncore/comm/keypebble/main.cpp | |||
@@ -1,10 +1,9 @@ | |||
1 | 1 | ||
2 | 2 | ||
3 | 3 | ||
4 | #include <qpe/qpeapplication.h> | ||
5 | #include "kvnc.h" | 4 | #include "kvnc.h" |
6 | #include <opie/oapplicationfactory.h> | 5 | #include <opie/oapplicationfactory.h> |
7 | 6 | ||
8 | 7 | ||
9 | 8 | ||
10 | OPIE_EXPORT_APP( OApplicationFactory<KVNC> ) | 9 | OPIE_EXPORT_APP( OApplicationFactory<KVNC> ) |
diff --git a/noncore/comm/mobilemsg/mobilemsg.cpp b/noncore/comm/mobilemsg/mobilemsg.cpp index 707872e..9a4db35 100644 --- a/noncore/comm/mobilemsg/mobilemsg.cpp +++ b/noncore/comm/mobilemsg/mobilemsg.cpp | |||
@@ -1,38 +1,33 @@ | |||
1 | #include "mobilemsg.h" | 1 | #include "mobilemsg.h" |
2 | #include <qpushbutton.h> | ||
3 | 2 | ||
4 | #include <qpe/qpeapplication.h> | ||
5 | 3 | ||
6 | #include <qlistbox.h> | ||
7 | #include <qpushbutton.h> | ||
8 | #include <qlayout.h> | ||
9 | 4 | ||
10 | 5 | ||
11 | /* | 6 | /* |
12 | * Constructs a MobileMsg which is a child of 'parent', with the | 7 | * Constructs a MobileMsg which is a child of 'parent', with the |
13 | * name 'name' and widget flags set to 'f' | 8 | * name 'name' and widget flags set to 'f' |
14 | */ | 9 | */ |
15 | MobileMsg::MobileMsg( QWidget* parent, const char* name, WFlags fl ) | 10 | MobileMsg::MobileMsg( QWidget* parent, const char* name, WFlags fl ) |
16 | : MobileMsgBase( parent, name, fl ) | 11 | : MobileMsgBase( parent, name, fl ) |
17 | { | 12 | { |
18 | //connect(add, SIGNAL(clicked()), this, SLOT(goodBye())); | 13 | //connect(add, SIGNAL(clicked()), this, SLOT(goodBye())); |
19 | //connect(remove, SIGNAL(clicked()), this, SLOT(goodBye())); | 14 | //connect(remove, SIGNAL(clicked()), this, SLOT(goodBye())); |
20 | //connect(props, SIGNAL(clicked()), this, SLOT(goodBye())); | 15 | //connect(props, SIGNAL(clicked()), this, SLOT(goodBye())); |
21 | //connect(settings, SIGNAL(selectionChanged()), this, SLOT(goodBye()) ); | 16 | //connect(settings, SIGNAL(selectionChanged()), this, SLOT(goodBye()) ); |
22 | } | 17 | } |
23 | 18 | ||
24 | /* | 19 | /* |
25 | * Destroys the object and frees any allocated resources | 20 | * Destroys the object and frees any allocated resources |
26 | */ | 21 | */ |
27 | MobileMsg::~MobileMsg() | 22 | MobileMsg::~MobileMsg() |
28 | { | 23 | { |
29 | // no need to delete child widgets, Qt does it all for us | 24 | // no need to delete child widgets, Qt does it all for us |
30 | } | 25 | } |
31 | 26 | ||
32 | /* | 27 | /* |
33 | * A simple slot... not very interesting. | 28 | * A simple slot... not very interesting. |
34 | */ | 29 | */ |
35 | void MobileMsg::goodBye() | 30 | void MobileMsg::goodBye() |
36 | { | 31 | { |
37 | close(); | 32 | close(); |
38 | } | 33 | } |
diff --git a/noncore/decorations/liquid/liquid.cpp b/noncore/decorations/liquid/liquid.cpp index ef2ac3c..0bd4b1d 100644 --- a/noncore/decorations/liquid/liquid.cpp +++ b/noncore/decorations/liquid/liquid.cpp | |||
@@ -1,138 +1,136 @@ | |||
1 | #include "liquid.h" | 1 | #include "liquid.h" |
2 | 2 | ||
3 | #include <qapplication.h> | 3 | #include <qapplication.h> |
4 | #include <qpainter.h> | ||
5 | #include <qpalette.h> | ||
6 | #include <qdrawutil.h> | 4 | #include <qdrawutil.h> |
7 | 5 | ||
8 | 6 | ||
9 | LiquidDecoInterface::LiquidDecoInterface ( ) | 7 | LiquidDecoInterface::LiquidDecoInterface ( ) |
10 | { | 8 | { |
11 | } | 9 | } |
12 | 10 | ||
13 | LiquidDecoInterface::~LiquidDecoInterface ( ) | 11 | LiquidDecoInterface::~LiquidDecoInterface ( ) |
14 | { | 12 | { |
15 | } | 13 | } |
16 | 14 | ||
17 | 15 | ||
18 | 16 | ||
19 | QString LiquidDecoInterface::name ( ) const | 17 | QString LiquidDecoInterface::name ( ) const |
20 | { | 18 | { |
21 | return qApp-> translate ( "Decoration", "Liquid" ); | 19 | return qApp-> translate ( "Decoration", "Liquid" ); |
22 | } | 20 | } |
23 | 21 | ||
24 | 22 | ||
25 | QPixmap LiquidDecoInterface::icon ( ) const | 23 | QPixmap LiquidDecoInterface::icon ( ) const |
26 | { | 24 | { |
27 | return QPixmap ( ); | 25 | return QPixmap ( ); |
28 | } | 26 | } |
29 | 27 | ||
30 | void LiquidDecoInterface::drawArea( Area a, QPainter *p, const WindowData *wd ) const | 28 | void LiquidDecoInterface::drawArea( Area a, QPainter *p, const WindowData *wd ) const |
31 | { | 29 | { |
32 | QRect r = wd-> rect; | 30 | QRect r = wd-> rect; |
33 | int th = metric ( TitleHeight, wd ); | 31 | int th = metric ( TitleHeight, wd ); |
34 | 32 | ||
35 | switch ( a ) { | 33 | switch ( a ) { |
36 | case WindowDecorationInterface::Border: { | 34 | case WindowDecorationInterface::Border: { |
37 | const QColorGroup &cg = wd-> palette. active ( ); | 35 | const QColorGroup &cg = wd-> palette. active ( ); |
38 | qDrawWinPanel ( p, r. x ( ) - metric ( LeftBorder, wd ), | 36 | qDrawWinPanel ( p, r. x ( ) - metric ( LeftBorder, wd ), |
39 | r. y ( ) - th - metric ( TopBorder, wd ), | 37 | r. y ( ) - th - metric ( TopBorder, wd ), |
40 | r. width ( ) + metric ( LeftBorder, wd ) + metric ( RightBorder, wd ), | 38 | r. width ( ) + metric ( LeftBorder, wd ) + metric ( RightBorder, wd ), |
41 | r. height ( ) + th + metric ( TopBorder,wd) + metric ( BottomBorder, wd ), | 39 | r. height ( ) + th + metric ( TopBorder,wd) + metric ( BottomBorder, wd ), |
42 | cg, false, &cg. brush ( QColorGroup::Background )); | 40 | cg, false, &cg. brush ( QColorGroup::Background )); |
43 | break; | 41 | break; |
44 | } | 42 | } |
45 | case WindowDecorationInterface::Title: { | 43 | case WindowDecorationInterface::Title: { |
46 | const QColorGroup &cg = wd-> palette. active ( ); | 44 | const QColorGroup &cg = wd-> palette. active ( ); |
47 | 45 | ||
48 | QBrush titleBrush; | 46 | QBrush titleBrush; |
49 | QPen titleLines1, titleLines2; | 47 | QPen titleLines1, titleLines2; |
50 | 48 | ||
51 | titleBrush = cg. brush (( wd-> flags & WindowData::Active ) ? QColorGroup::Highlight : QColorGroup::Background ); | 49 | titleBrush = cg. brush (( wd-> flags & WindowData::Active ) ? QColorGroup::Highlight : QColorGroup::Background ); |
52 | titleLines1 = titleBrush. color ( ). dark ( 105 ); | 50 | titleLines1 = titleBrush. color ( ). dark ( 105 ); |
53 | titleLines2 = titleBrush. color ( ). dark ( 103 ); | 51 | titleLines2 = titleBrush. color ( ). dark ( 103 ); |
54 | 52 | ||
55 | p-> fillRect ( r. x ( ), r. y ( ) - th, r. width ( ), th, titleBrush ); | 53 | p-> fillRect ( r. x ( ), r. y ( ) - th, r. width ( ), th, titleBrush ); |
56 | for ( int i = r.y()-th; i < r.y(); i += 4 ) { | 54 | for ( int i = r.y()-th; i < r.y(); i += 4 ) { |
57 | p-> setPen ( titleLines1 ); | 55 | p-> setPen ( titleLines1 ); |
58 | p-> drawLine ( r. left ( ), i, r. right ( ), i ); | 56 | p-> drawLine ( r. left ( ), i, r. right ( ), i ); |
59 | p-> setPen ( titleLines2 ); | 57 | p-> setPen ( titleLines2 ); |
60 | p-> drawLine ( r. left ( ), i+1, r. right ( ), i+1 ); | 58 | p-> drawLine ( r. left ( ), i+1, r. right ( ), i+1 ); |
61 | } | 59 | } |
62 | break; | 60 | break; |
63 | } | 61 | } |
64 | case WindowDecorationInterface::TitleText: { | 62 | case WindowDecorationInterface::TitleText: { |
65 | QColor textcol = wd-> palette. active ( ). color (( wd-> flags & WindowData::Active ) ? QColorGroup::HighlightedText : QColorGroup::Text ); | 63 | QColor textcol = wd-> palette. active ( ). color (( wd-> flags & WindowData::Active ) ? QColorGroup::HighlightedText : QColorGroup::Text ); |
66 | QColor shadecol = ( qGray ( textcol. rgb ( ) ) > 128 ) ? textcol. dark ( 230 ) : textcol.light( 300 ); | 64 | QColor shadecol = ( qGray ( textcol. rgb ( ) ) > 128 ) ? textcol. dark ( 230 ) : textcol.light( 300 ); |
67 | if ( textcol == shadecol ) { | 65 | if ( textcol == shadecol ) { |
68 | if ( qGray ( shadecol. rgb ( ) ) < 128 ) | 66 | if ( qGray ( shadecol. rgb ( ) ) < 128 ) |
69 | shadecol = QColor ( 225, 225, 225 ); | 67 | shadecol = QColor ( 225, 225, 225 ); |
70 | else | 68 | else |
71 | shadecol = QColor ( 30, 30, 30 ); | 69 | shadecol = QColor ( 30, 30, 30 ); |
72 | } | 70 | } |
73 | QColor fillcol = wd-> palette. active ( ). color (( wd-> flags & WindowData::Active ) ? QColorGroup::Highlight : QColorGroup::Background ); | 71 | QColor fillcol = wd-> palette. active ( ). color (( wd-> flags & WindowData::Active ) ? QColorGroup::Highlight : QColorGroup::Background ); |
74 | QColor bordercol = fillcol. dark ( 110 ); | 72 | QColor bordercol = fillcol. dark ( 110 ); |
75 | fillcol = fillcol. light ( 110 ); | 73 | fillcol = fillcol. light ( 110 ); |
76 | 74 | ||
77 | QRect tr ( r.x ( ) + 3 + metric ( HelpWidth, wd ), r. top ( ) - th, | 75 | QRect tr ( r.x ( ) + 3 + metric ( HelpWidth, wd ), r. top ( ) - th, |
78 | r. width ( ) - metric ( OKWidth, wd ) - metric ( CloseWidth, wd ), th ); | 76 | r. width ( ) - metric ( OKWidth, wd ) - metric ( CloseWidth, wd ), th ); |
79 | 77 | ||
80 | QFont f = p-> font ( ); | 78 | QFont f = p-> font ( ); |
81 | f. setWeight ( QFont::Bold ); | 79 | f. setWeight ( QFont::Bold ); |
82 | p-> setFont ( f ); | 80 | p-> setFont ( f ); |
83 | 81 | ||
84 | QRect br = p-> boundingRect ( tr, QPainter::AlignCenter, wd-> caption ); | 82 | QRect br = p-> boundingRect ( tr, QPainter::AlignCenter, wd-> caption ); |
85 | int trh2 = tr. height ( ) / 2; | 83 | int trh2 = tr. height ( ) / 2; |
86 | 84 | ||
87 | int align = QPainter::AlignCenter; | 85 | int align = QPainter::AlignCenter; |
88 | 86 | ||
89 | if ( br. width ( ) + 2 * trh2 > tr. width ( ) ) { | 87 | if ( br. width ( ) + 2 * trh2 > tr. width ( ) ) { |
90 | br. setLeft ( tr. left ( ) + trh2 ); | 88 | br. setLeft ( tr. left ( ) + trh2 ); |
91 | br. setWidth ( tr. width ( ) - 2 * trh2 ); | 89 | br. setWidth ( tr. width ( ) - 2 * trh2 ); |
92 | 90 | ||
93 | align = QPainter::AlignLeft | QPainter::AlignVCenter; | 91 | align = QPainter::AlignLeft | QPainter::AlignVCenter; |
94 | } | 92 | } |
95 | 93 | ||
96 | p-> setBrush ( fillcol ); | 94 | p-> setBrush ( fillcol ); |
97 | p-> setPen ( bordercol /*Qt::NoPen*/ ); | 95 | p-> setPen ( bordercol /*Qt::NoPen*/ ); |
98 | p->drawChord ( br. left ( ) - trh2, tr. top ( ), 2 * trh2, tr. height ( ), 90*16, 180*16 ); | 96 | p->drawChord ( br. left ( ) - trh2, tr. top ( ), 2 * trh2, tr. height ( ), 90*16, 180*16 ); |
99 | p->drawChord ( br. right ( ) + 1 - trh2, tr. top ( ), 2 * trh2, tr. height ( ), 90*16, -180*16 ); | 97 | p->drawChord ( br. right ( ) + 1 - trh2, tr. top ( ), 2 * trh2, tr. height ( ), 90*16, -180*16 ); |
100 | 98 | ||
101 | p-> fillRect ( br.left() - 1, tr. top ( ), br. width ( ) + 2, tr. height ( ), fillcol); | 99 | p-> fillRect ( br.left() - 1, tr. top ( ), br. width ( ) + 2, tr. height ( ), fillcol); |
102 | 100 | ||
103 | p-> setPen ( shadecol ); | 101 | p-> setPen ( shadecol ); |
104 | p-> drawText ( br, align, wd-> caption ); | 102 | p-> drawText ( br, align, wd-> caption ); |
105 | p-> setPen ( textcol ); | 103 | p-> setPen ( textcol ); |
106 | br. moveBy ( -1, -1 ); | 104 | br. moveBy ( -1, -1 ); |
107 | p-> drawText ( br, align, wd-> caption ); | 105 | p-> drawText ( br, align, wd-> caption ); |
108 | break; | 106 | break; |
109 | } | 107 | } |
110 | default: { | 108 | default: { |
111 | WindowDecorationInterface::drawArea ( a, p, wd ); | 109 | WindowDecorationInterface::drawArea ( a, p, wd ); |
112 | break; | 110 | break; |
113 | } | 111 | } |
114 | } | 112 | } |
115 | } | 113 | } |
116 | 114 | ||
117 | QRESULT LiquidDecoInterface::queryInterface ( const QUuid &uuid, QUnknownInterface **iface ) | 115 | QRESULT LiquidDecoInterface::queryInterface ( const QUuid &uuid, QUnknownInterface **iface ) |
118 | { | 116 | { |
119 | *iface = 0; | 117 | *iface = 0; |
120 | 118 | ||
121 | if ( uuid == IID_QUnknown ) | 119 | if ( uuid == IID_QUnknown ) |
122 | *iface = this; | 120 | *iface = this; |
123 | else if ( uuid == IID_WindowDecoration ) | 121 | else if ( uuid == IID_WindowDecoration ) |
124 | *iface = this; | 122 | *iface = this; |
125 | else | 123 | else |
126 | return QS_FALSE; | 124 | return QS_FALSE; |
127 | 125 | ||
128 | if ( *iface ) | 126 | if ( *iface ) |
129 | (*iface)-> addRef ( ); | 127 | (*iface)-> addRef ( ); |
130 | 128 | ||
131 | return QS_OK; | 129 | return QS_OK; |
132 | } | 130 | } |
133 | 131 | ||
134 | Q_EXPORT_INTERFACE() | 132 | Q_EXPORT_INTERFACE() |
135 | { | 133 | { |
136 | Q_CREATE_INSTANCE( LiquidDecoInterface ) | 134 | Q_CREATE_INSTANCE( LiquidDecoInterface ) |
137 | } | 135 | } |
138 | 136 | ||