summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/tinykate/libkate/document/katedocument.cpp2
-rw-r--r--noncore/apps/tinykate/libkate/kateconfig.cpp2
-rw-r--r--noncore/apps/tinykate/libkate/view/kateview.cpp9
-rw-r--r--noncore/apps/tinykate/libkate/view/kateviewdialog.cpp4
-rw-r--r--noncore/apps/tinykate/tinykate.cpp5
-rw-r--r--noncore/apps/zsafe/category.cpp1
-rw-r--r--noncore/apps/zsafe/main.cpp1
-rwxr-xr-xnoncore/apps/zsafe/qsettings.cpp1
-rw-r--r--noncore/apps/zsafe/scqtfiledlg.cpp5
-rw-r--r--noncore/apps/zsafe/scqtfileedit.cpp4
-rw-r--r--noncore/apps/zsafe/zlistview.cpp2
-rw-r--r--noncore/apps/zsafe/zsafe.cpp1
-rw-r--r--noncore/comm/keypebble/krfbbuffer.cpp3
-rw-r--r--noncore/comm/keypebble/krfbcanvas.cpp9
-rw-r--r--noncore/comm/keypebble/krfbconnection.cpp1
-rw-r--r--noncore/comm/keypebble/krfbdecoder.cpp6
-rw-r--r--noncore/comm/keypebble/krfblogin.cpp1
-rw-r--r--noncore/comm/keypebble/krfbserver.cpp1
-rw-r--r--noncore/comm/keypebble/kvnc.cpp13
-rw-r--r--noncore/comm/keypebble/kvncbookmarkdlg.cpp14
-rw-r--r--noncore/comm/keypebble/kvncconndlg.cpp8
-rw-r--r--noncore/comm/keypebble/main.cpp1
-rw-r--r--noncore/comm/mobilemsg/mobilemsg.cpp5
-rw-r--r--noncore/decorations/liquid/liquid.cpp2
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,3176 +1,3174 @@
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
83KateAction::KateAction(Action a, PointStruc &cursor, int len, const QString &text) 81KateAction::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
87KateActionGroup::KateActionGroup(PointStruc &aStart, int type) 85KateActionGroup::KateActionGroup(PointStruc &aStart, int type)
88 : start(aStart), action(0L), undoType(type) { 86 : start(aStart), action(0L), undoType(type) {
89} 87}
90 88
91KateActionGroup::~KateActionGroup() { 89KateActionGroup::~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
102void KateActionGroup::insertAction(KateAction *a) { 100void KateActionGroup::insertAction(KateAction *a) {
103 a->next = action; 101 a->next = action;
104 action = a; 102 action = a;
105} 103}
106 104
107const char * KateActionGroup::typeName(int type) 105const 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
128const int KateDocument::maxAttribs = 32; 126const int KateDocument::maxAttribs = 32;
129 127
130QStringList KateDocument::searchForList = QStringList(); 128QStringList KateDocument::searchForList = QStringList();
131QStringList KateDocument::replaceWithList = QStringList(); 129QStringList KateDocument::replaceWithList = QStringList();
132 130
133uint KateDocument::uniqueID = 0; 131uint KateDocument::uniqueID = 0;
134 132
135QPtrDict<KateDocument::KateDocPrivate>* KateDocument::d_ptr = 0; 133QPtrDict<KateDocument::KateDocPrivate>* KateDocument::d_ptr = 0;
136 134
137 135
138KateDocument::KateDocument(bool bSingleViewMode, bool bBrowserView, 136KateDocument::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
214void KateDocument::setDontChangeHlOnSave() 212void KateDocument::setDontChangeHlOnSave()
215{ 213{
216 d(this)->hlSetByUser = true; 214 d(this)->hlSetByUser = true;
217} 215}
218 216
219void KateDocument::setFont (QFont font) 217void 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
246long KateDocument::needPreHighlight(long till) 244long 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
264void KateDocument::doPreHighlight() 262void 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
280KateDocument::~KateDocument() 278KateDocument::~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
294void KateDocument::openURL(const QString &filename) 292void 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
330bool KateDocument::saveFile() 328bool 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
372KTextEditor::View *KateDocument::createView( QWidget *parent, const char *name ) 370KTextEditor::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
377QString KateDocument::textLine( int line ) const 375QString 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
386void KateDocument::replaceLine(const QString& s,int line) 384void 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
392void KateDocument::insertLine( const QString &str, int l ) { 390void KateDocument::insertLine( const QString &str, int l ) {
393 insert_Line(str,l,true); 391 insert_Line(str,l,true);
394} 392}
395 393
396void KateDocument::insert_Line(const QString& s,int line, bool update) 394void 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
410void KateDocument::insertAt( const QString &s, int line, int col, bool ) 408void 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
421void KateDocument::removeLine( int line ) { 419void KateDocument::removeLine( int line ) {
422 remove_Line(line,true); 420 remove_Line(line,true);
423} 421}
424 422
425void KateDocument::remove_Line(int line,bool update) 423void 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
438int KateDocument::length() const 436int KateDocument::length() const
439{ 437{
440 return text().length(); 438 return text().length();
441} 439}
442 440
443void KateDocument::setSelection( int , int , int , int ) 441void KateDocument::setSelection( int , int , int , int )
444{ 442{
445} 443}
446 444
447bool KateDocument::hasSelection() const 445bool KateDocument::hasSelection() const
448{ 446{
449 return (selectEnd >= selectStart); 447 return (selectEnd >= selectStart);
450} 448}
451 449
452QString KateDocument::selection() const 450QString 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
511int KateDocument::numLines() const 509int KateDocument::numLines() const
512{ 510{
513 return buffer->count(); 511 return buffer->count();
514} 512}
515 513
516 514
517TextLine::Ptr KateDocument::getTextLine(int line) const 515TextLine::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
523int KateDocument::textLength(int line) { 521int 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
529void KateDocument::setTabWidth(int chars) { 527void 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
548void KateDocument::setReadOnly(bool m) { 546void 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
560bool KateDocument::isReadOnly() const { 558bool KateDocument::isReadOnly() const {
561 return readOnly; 559 return readOnly;
562} 560}
563 561
564void KateDocument::setNewDoc( bool m ) 562void 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
578bool KateDocument::isNewDoc() const { 576bool KateDocument::isNewDoc() const {
579 return newDoc; 577 return newDoc;
580} 578}
581 579
582void KateDocument::setModified(bool m) { 580void 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
594bool KateDocument::isModified() const { 592bool KateDocument::isModified() const {
595 return modified; 593 return modified;
596} 594}
597 595
598void KateDocument::readConfig() 596void 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
620void KateDocument::writeConfig() 618void 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
636void KateDocument::readSessionConfig(KateConfig *config) 634void 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
650void KateDocument::writeSessionConfig(KateConfig *config) 648void 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
668void KateDocument::setHighlight(int n) { 666void 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
687void KateDocument::makeAttribs() { 685void 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
694void KateDocument::updateFontData() { 692void 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
714void KateDocument::hlChanged() { //slot 712void KateDocument::hlChanged() { //slot
715 makeAttribs(); 713 makeAttribs();
716 updateViews(); 714 updateViews();
717} 715}
718 716
719 717
720void KateDocument::addView(KTextEditor::View *view) { 718void 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
726void KateDocument::removeView(KTextEditor::View *view) { 724void 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
733void KateDocument::slotViewDestroyed() 731void KateDocument::slotViewDestroyed()
734{ 732{
735 views.removeRef( static_cast<const KateView *>( sender() ) ); 733 views.removeRef( static_cast<const KateView *>( sender() ) );
736} 734}
737 735
738bool KateDocument::ownedView(KateView *view) { 736bool 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
743bool KateDocument::isLastView(int numViews) { 741bool KateDocument::isLastView(int numViews) {
744 return ((int) views.count() == numViews); 742 return ((int) views.count() == numViews);
745} 743}
746 744
747int KateDocument::textWidth(const TextLine::Ptr &textLine, int cursorX) { 745int 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
772int KateDocument::textWidth(PointStruc &cursor) { 770int 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
782int KateDocument::textWidth(bool wrapCursor, PointStruc &cursor, int xPos) { 780int 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
822int KateDocument::textPos(const TextLine::Ptr &textLine, int xPos) { 820int 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)
837 x += myFontMetricsBI.width(ch); 835 x += myFontMetricsBI.width(ch);
838 else if (a->bold) 836 else if (a->bold)
839 x += myFontMetricsBold.width(ch); 837 x += myFontMetricsBold.width(ch);
840 else if (a->italic) 838 else if (a->italic)
841 x += myFontMetricsItalic.width(ch); 839 x += myFontMetricsItalic.width(ch);
842 else 840 else
843 x += myFontMetrics.width(ch); 841 x += myFontMetrics.width(ch);
844 842
845 z++; 843 z++;
846 } 844 }
847 if (xPos - oldX < x - xPos && z > 0) { 845 if (xPos - oldX < x - xPos && z > 0) {
848 z--; 846 z--;
849 // newXPos = oldX; 847 // newXPos = oldX;
850 }// else newXPos = x; 848 }// else newXPos = x;
851 return z; 849 return z;
852} 850}
853 851
854int KateDocument::textWidth() { 852int KateDocument::textWidth() {
855 return int(maxLength + 8); 853 return int(maxLength + 8);
856} 854}
857 855
858int KateDocument::textHeight() { 856int KateDocument::textHeight() {
859 return numLines()*fontHeight; 857 return numLines()*fontHeight;
860} 858}
861 859
862void KateDocument::insert(VConfig &c, const QString &s) { 860void KateDocument::insert(VConfig &c, const QString &s) {
863 int pos; 861 int pos;
864 QChar ch; 862 QChar ch;
865 QString buf; 863 QString buf;
866 864
867 if (s.isEmpty()) return; 865 if (s.isEmpty()) return;
868 866
869 recordStart(c, KateActionGroup::ugPaste); 867 recordStart(c, KateActionGroup::ugPaste);
870 868
871 pos = 0; 869 pos = 0;
872 if (!(c.flags & KateView::cfVerticalSelect)) { 870 if (!(c.flags & KateView::cfVerticalSelect)) {
873 do { 871 do {
874 ch = s[pos]; 872 ch = s[pos];
875 if (ch.isPrint() || ch == '\t') { 873 if (ch.isPrint() || ch == '\t') {
876 buf += ch; // append char to buffer 874 buf += ch; // append char to buffer
877 } else if (ch == '\n') { 875 } else if (ch == '\n') {
878 recordAction(KateAction::newLine, c.cursor); // wrap contents behind cursor to new line 876 recordAction(KateAction::newLine, c.cursor); // wrap contents behind cursor to new line
879 recordInsert(c, buf); // append to old line 877 recordInsert(c, buf); // append to old line
880// c.cursor.x += buf.length(); 878// c.cursor.x += buf.length();
881 buf.truncate(0); // clear buffer 879 buf.truncate(0); // clear buffer
882 c.cursor.y++; 880 c.cursor.y++;
883 c.cursor.x = 0; 881 c.cursor.x = 0;
884 } 882 }
885 pos++; 883 pos++;
886 } while (pos < (int) s.length()); 884 } while (pos < (int) s.length());
887 } else { 885 } else {
888 int xPos; 886 int xPos;
889 887
890 xPos = textWidth(c.cursor); 888 xPos = textWidth(c.cursor);
891 do { 889 do {
892 ch = s[pos]; 890 ch = s[pos];
893 if (ch.isPrint() || ch == '\t') { 891 if (ch.isPrint() || ch == '\t') {
894 buf += ch; 892 buf += ch;
895 } else if (ch == '\n') { 893 } else if (ch == '\n') {
896 recordInsert(c, buf); 894 recordInsert(c, buf);
897 c.cursor.x += buf.length(); 895 c.cursor.x += buf.length();
898 buf.truncate(0); 896 buf.truncate(0);
899 c.cursor.y++; 897 c.cursor.y++;
900 if (c.cursor.y >= numLines()) 898 if (c.cursor.y >= numLines())
901 recordAction(KateAction::insLine, c.cursor); 899 recordAction(KateAction::insLine, c.cursor);
902 c.cursor.x = textPos(getTextLine(c.cursor.y), xPos); 900 c.cursor.x = textPos(getTextLine(c.cursor.y), xPos);
903 } 901 }
904 pos++; 902 pos++;
905 } while (pos < (int) s.length()); 903 } while (pos < (int) s.length());
906 } 904 }
907 recordInsert(c, buf); 905 recordInsert(c, buf);
908 c.cursor.x += buf.length(); 906 c.cursor.x += buf.length();
909 recordEnd(c); 907 recordEnd(c);
910} 908}
911 909
912void KateDocument::insertFile(VConfig &c, QIODevice &dev) 910void KateDocument::insertFile(VConfig &c, QIODevice &dev)
913{ 911{
914 recordStart(c, KateActionGroup::ugPaste); 912 recordStart(c, KateActionGroup::ugPaste);
915 913
916 QString buf; 914 QString buf;
917 QChar ch, last; 915 QChar ch, last;
918 916
919 QTextStream stream( &dev ); 917 QTextStream stream( &dev );
920 918
921 while ( !stream.atEnd() ) { 919 while ( !stream.atEnd() ) {
922 stream >> ch; 920 stream >> ch;
923 921
924 if (ch.isPrint() || ch == '\t') { 922 if (ch.isPrint() || ch == '\t') {
925 buf += ch; 923 buf += ch;
926 } else if (ch == '\n' || ch == '\r') { 924 } else if (ch == '\n' || ch == '\r') {
927 if (last != '\r' || ch != '\n') { 925 if (last != '\r' || ch != '\n') {
928 recordAction(KateAction::newLine, c.cursor); 926 recordAction(KateAction::newLine, c.cursor);
929 recordInsert(c, buf); 927 recordInsert(c, buf);
930 buf.truncate(0); 928 buf.truncate(0);
931 c.cursor.y++; 929 c.cursor.y++;
932 c.cursor.x = 0; 930 c.cursor.x = 0;
933 } 931 }
934 last = ch; 932 last = ch;
935 } 933 }
936 } 934 }
937 935
938 recordInsert(c, buf); 936 recordInsert(c, buf);
939 recordEnd(c); 937 recordEnd(c);
940} 938}
941 939
942int KateDocument::currentColumn(PointStruc &cursor) { 940int KateDocument::currentColumn(PointStruc &cursor) {
943 return getTextLine(cursor.y)->cursorX(cursor.x,tabChars); 941 return getTextLine(cursor.y)->cursorX(cursor.x,tabChars);
944} 942}
945 943
946bool KateDocument::insertChars(VConfig &c, const QString &chars) { 944bool KateDocument::insertChars(VConfig &c, const QString &chars) {
947 int z, pos, l; 945 int z, pos, l;
948 bool onlySpaces; 946 bool onlySpaces;
949 QChar ch; 947 QChar ch;
950 QString buf; 948 QString buf;
951 949
952 TextLine::Ptr textLine = getTextLine(c.cursor.y); 950 TextLine::Ptr textLine = getTextLine(c.cursor.y);
953 951
954 pos = 0; 952 pos = 0;
955 onlySpaces = true; 953 onlySpaces = true;
956 for (z = 0; z < (int) chars.length(); z++) { 954 for (z = 0; z < (int) chars.length(); z++) {
957 ch = chars[z]; 955 ch = chars[z];
958 if (ch == '\t' && c.flags & KateView::cfReplaceTabs) { 956 if (ch == '\t' && c.flags & KateView::cfReplaceTabs) {
959 l = tabChars - (textLine->cursorX(c.cursor.x, tabChars) % tabChars); 957 l = tabChars - (textLine->cursorX(c.cursor.x, tabChars) % tabChars);
960 while (l > 0) { 958 while (l > 0) {
961 buf.insert(pos, ' '); 959 buf.insert(pos, ' ');
962 pos++; 960 pos++;
963 l--; 961 l--;
964 } 962 }
965 } else if (ch.isPrint() || ch == '\t') { 963 } else if (ch.isPrint() || ch == '\t') {
966 buf.insert(pos, ch); 964 buf.insert(pos, ch);
967 pos++; 965 pos++;
968 if (ch != ' ') onlySpaces = false; 966 if (ch != ' ') onlySpaces = false;
969 if (c.flags & KateView::cfAutoBrackets) { 967 if (c.flags & KateView::cfAutoBrackets) {
970 if (ch == '(') buf.insert(pos, ')'); 968 if (ch == '(') buf.insert(pos, ')');
971 if (ch == '[') buf.insert(pos, ']'); 969 if (ch == '[') buf.insert(pos, ']');
972 if (ch == '{') buf.insert(pos, '}'); 970 if (ch == '{') buf.insert(pos, '}');
973 } 971 }
974 } 972 }
975 } 973 }
976 //pos = cursor increment 974 //pos = cursor increment
977 975
978 //return false if nothing has to be inserted 976 //return false if nothing has to be inserted
979 if (buf.isEmpty()) return false; 977 if (buf.isEmpty()) return false;
980 978
981 //auto deletion of the marked text occurs not very often and can therefore 979 //auto deletion of the marked text occurs not very often and can therefore
982 // be recorded separately 980 // be recorded separately
983 if (c.flags &KateView:: cfDelOnInput) delMarkedText(c); 981 if (c.flags &KateView:: cfDelOnInput) delMarkedText(c);
984 982
985 recordStart(c, KateActionGroup::ugInsChar); 983 recordStart(c, KateActionGroup::ugInsChar);
986 recordReplace(c/*.cursor*/, (c.flags & KateView::cfOvr) ? buf.length() : 0, buf); 984 recordReplace(c/*.cursor*/, (c.flags & KateView::cfOvr) ? buf.length() : 0, buf);
987 c.cursor.x += pos; 985 c.cursor.x += pos;
988 986
989 if (myWordWrap && myWordWrapAt > 0) { 987 if (myWordWrap && myWordWrapAt > 0) {
990 int line; 988 int line;
991 const QChar *s; 989 const QChar *s;
992// int pos; 990// int pos;
993 PointStruc actionCursor; 991 PointStruc actionCursor;
994 992
995 line = c.cursor.y; 993 line = c.cursor.y;
996 do { 994 do {
997 textLine = getTextLine(line); 995 textLine = getTextLine(line);
998 s = textLine->getText(); 996 s = textLine->getText();
999 l = textLine->length(); 997 l = textLine->length();
1000 for (z = myWordWrapAt; z < l; z++) if (!s[z].isSpace()) break; //search for text to wrap 998 for (z = myWordWrapAt; z < l; z++) if (!s[z].isSpace()) break; //search for text to wrap
1001 if (z >= l) break; // nothing more to wrap 999 if (z >= l) break; // nothing more to wrap
1002 pos = myWordWrapAt; 1000 pos = myWordWrapAt;
1003 for (; z >= 0; z--) { //find wrap position 1001 for (; z >= 0; z--) { //find wrap position
1004 if (s[z].isSpace()) { 1002 if (s[z].isSpace()) {
1005 pos = z + 1; 1003 pos = z + 1;
1006 break; 1004 break;
1007 } 1005 }
1008 } 1006 }
1009 //pos = wrap position 1007 //pos = wrap position
1010 1008
1011 if (line == c.cursor.y && pos <= c.cursor.x) { 1009 if (line == c.cursor.y && pos <= c.cursor.x) {
1012 //wrap cursor 1010 //wrap cursor
1013 c.cursor.y++; 1011 c.cursor.y++;
1014 c.cursor.x -= pos; 1012 c.cursor.x -= pos;
1015 } 1013 }
1016 1014
1017 if (line == lastLine() || (getTextLine(line+1)->length() == 0) ) { 1015 if (line == lastLine() || (getTextLine(line+1)->length() == 0) ) {
1018 //at end of doc: create new line 1016 //at end of doc: create new line
1019 actionCursor.x = pos; 1017 actionCursor.x = pos;
1020 actionCursor.y = line; 1018 actionCursor.y = line;
1021 recordAction(KateAction::newLine,actionCursor); 1019 recordAction(KateAction::newLine,actionCursor);
1022 } else { 1020 } else {
1023 //wrap 1021 //wrap
1024 actionCursor.y = line + 1; 1022 actionCursor.y = line + 1;
1025 if (!s[l - 1].isSpace()) { //add space in next line if necessary 1023 if (!s[l - 1].isSpace()) { //add space in next line if necessary
1026 actionCursor.x = 0; 1024 actionCursor.x = 0;
1027 recordInsert(actionCursor, " "); 1025 recordInsert(actionCursor, " ");
1028 } 1026 }
1029 actionCursor.x = textLine->length() - pos; 1027 actionCursor.x = textLine->length() - pos;
1030 recordAction(KateAction::wordWrap, actionCursor); 1028 recordAction(KateAction::wordWrap, actionCursor);
1031 } 1029 }
1032 line++; 1030 line++;
1033 } while (true); 1031 } while (true);
1034 } 1032 }
1035 recordEnd(c); 1033 recordEnd(c);
1036 return true; 1034 return true;
1037} 1035}
1038 1036
1039QString tabString(int pos, int tabChars) { 1037QString tabString(int pos, int tabChars) {
1040 QString s; 1038 QString s;
1041 while (pos >= tabChars) { 1039 while (pos >= tabChars) {
1042 s += '\t'; 1040 s += '\t';
1043 pos -= tabChars; 1041 pos -= tabChars;
1044 } 1042 }
1045 while (pos > 0) { 1043 while (pos > 0) {
1046 s += ' '; 1044 s += ' ';
1047 pos--; 1045 pos--;
1048 } 1046 }
1049 return s; 1047 return s;
1050} 1048}
1051 1049
1052void KateDocument::newLine(VConfig &c) { 1050void KateDocument::newLine(VConfig &c) {
1053 1051
1054 //auto deletion of marked text is done by the view to have a more 1052 //auto deletion of marked text is done by the view to have a more
1055 // "low level" KateDocument::newLine method 1053 // "low level" KateDocument::newLine method
1056 recordStart(c, KateActionGroup::ugInsLine); 1054 recordStart(c, KateActionGroup::ugInsLine);
1057 1055
1058 if (!(c.flags & KateView::cfAutoIndent)) { 1056 if (!(c.flags & KateView::cfAutoIndent)) {
1059 recordAction(KateAction::newLine,c.cursor); 1057 recordAction(KateAction::newLine,c.cursor);
1060 c.cursor.y++; 1058 c.cursor.y++;
1061 c.cursor.x = 0; 1059 c.cursor.x = 0;
1062 } else { 1060 } else {
1063 TextLine::Ptr textLine = getTextLine(c.cursor.y); 1061 TextLine::Ptr textLine = getTextLine(c.cursor.y);
1064 int pos = textLine->firstChar(); 1062 int pos = textLine->firstChar();
1065 if (c.cursor.x < pos) c.cursor.x = pos; // place cursor on first char if before 1063 if (c.cursor.x < pos) c.cursor.x = pos; // place cursor on first char if before
1066 1064
1067 int y = c.cursor.y; 1065 int y = c.cursor.y;
1068 while ((y > 0) && (pos < 0)) { // search a not empty text line 1066 while ((y > 0) && (pos < 0)) { // search a not empty text line
1069 textLine = getTextLine(--y); 1067 textLine = getTextLine(--y);
1070 pos = textLine->firstChar(); 1068 pos = textLine->firstChar();
1071 } 1069 }
1072 recordAction(KateAction::newLine, c.cursor); 1070 recordAction(KateAction::newLine, c.cursor);
1073 c.cursor.y++; 1071 c.cursor.y++;
1074 c.cursor.x = 0; 1072 c.cursor.x = 0;
1075 if (pos > 0) { 1073 if (pos > 0) {
1076 pos = textLine->cursorX(pos, tabChars); 1074 pos = textLine->cursorX(pos, tabChars);
1077// if (getTextLine(c.cursor.y)->length() > 0) { 1075// if (getTextLine(c.cursor.y)->length() > 0) {
1078 QString s = tabString(pos, (c.flags & KateView::cfSpaceIndent) ? 0xffffff : tabChars); 1076 QString s = tabString(pos, (c.flags & KateView::cfSpaceIndent) ? 0xffffff : tabChars);
1079 recordInsert(c.cursor, s); 1077 recordInsert(c.cursor, s);
1080 pos = s.length(); 1078 pos = s.length();
1081// } 1079// }
1082// recordInsert(c.cursor, QString(textLine->getText(), pos)); 1080// recordInsert(c.cursor, QString(textLine->getText(), pos));
1083 c.cursor.x = pos; 1081 c.cursor.x = pos;
1084 } 1082 }
1085 } 1083 }
1086 1084
1087 recordEnd(c); 1085 recordEnd(c);
1088} 1086}
1089 1087
1090void KateDocument::killLine(VConfig &c) { 1088void KateDocument::killLine(VConfig &c) {
1091 1089
1092 recordStart(c, KateActionGroup::ugDelLine); 1090 recordStart(c, KateActionGroup::ugDelLine);
1093 c.cursor.x = 0; 1091 c.cursor.x = 0;
1094 recordDelete(c.cursor, 0xffffff); 1092 recordDelete(c.cursor, 0xffffff);
1095 if (c.cursor.y < lastLine()) { 1093 if (c.cursor.y < lastLine()) {
1096 recordAction(KateAction::killLine, c.cursor); 1094 recordAction(KateAction::killLine, c.cursor);
1097 } 1095 }
1098 recordEnd(c); 1096 recordEnd(c);
1099} 1097}
1100 1098
1101void KateDocument::backspace(VConfig &c) { 1099void KateDocument::backspace(VConfig &c) {
1102 1100
1103 if (c.cursor.x <= 0 && c.cursor.y <= 0) return; 1101 if (c.cursor.x <= 0 && c.cursor.y <= 0) return;
1104 1102
1105 if (c.cursor.x > 0) { 1103 if (c.cursor.x > 0) {
1106 recordStart(c, KateActionGroup::ugDelChar); 1104 recordStart(c, KateActionGroup::ugDelChar);
1107 if (!(c.flags & KateView::cfBackspaceIndents)) { 1105 if (!(c.flags & KateView::cfBackspaceIndents)) {
1108 // ordinary backspace 1106 // ordinary backspace
1109 c.cursor.x--; 1107 c.cursor.x--;
1110 recordDelete(c.cursor, 1); 1108 recordDelete(c.cursor, 1);
1111 } else { 1109 } else {
1112 // backspace indents: erase to next indent position 1110 // backspace indents: erase to next indent position
1113 int l = 1; // del one char 1111 int l = 1; // del one char
1114 1112
1115 TextLine::Ptr textLine = getTextLine(c.cursor.y); 1113 TextLine::Ptr textLine = getTextLine(c.cursor.y);
1116 int pos = textLine->firstChar(); 1114 int pos = textLine->firstChar();
1117 if (pos < 0 || pos >= c.cursor.x) { 1115 if (pos < 0 || pos >= c.cursor.x) {
1118 // only spaces on left side of cursor 1116 // only spaces on left side of cursor
1119 // search a line with less spaces 1117 // search a line with less spaces
1120 int y = c.cursor.y; 1118 int y = c.cursor.y;
1121 while (y > 0) { 1119 while (y > 0) {
1122 textLine = getTextLine(--y); 1120 textLine = getTextLine(--y);
1123 pos = textLine->firstChar(); 1121 pos = textLine->firstChar();
1124 if (pos >= 0 && pos < c.cursor.x) { 1122 if (pos >= 0 && pos < c.cursor.x) {
1125 l = c.cursor.x - pos; // del more chars 1123 l = c.cursor.x - pos; // del more chars
1126 break; 1124 break;
1127 } 1125 }
1128 } 1126 }
1129 } 1127 }
1130 // break effectively jumps here 1128 // break effectively jumps here
1131 c.cursor.x -= l; 1129 c.cursor.x -= l;
1132 recordDelete(c.cursor, l); 1130 recordDelete(c.cursor, l);
1133 } 1131 }
1134 } else { 1132 } else {
1135 // c.cursor.x == 0: wrap to previous line 1133 // c.cursor.x == 0: wrap to previous line
1136 recordStart(c, KateActionGroup::ugDelLine); 1134 recordStart(c, KateActionGroup::ugDelLine);
1137 c.cursor.y--; 1135 c.cursor.y--;
1138 c.cursor.x = getTextLine(c.cursor.y)->length(); 1136 c.cursor.x = getTextLine(c.cursor.y)->length();
1139 recordAction(KateAction::delLine,c.cursor); 1137 recordAction(KateAction::delLine,c.cursor);
1140 } 1138 }
1141 recordEnd(c); 1139 recordEnd(c);
1142} 1140}
1143 1141
1144 1142
1145void KateDocument::del(VConfig &c) { 1143void KateDocument::del(VConfig &c) {
1146 TextLine::Ptr textLine = getTextLine(c.cursor.y); 1144 TextLine::Ptr textLine = getTextLine(c.cursor.y);
1147 int len = (c.flags & KateView::cfRemoveSpaces) ? textLine->lastChar() : textLine->length(); 1145 int len = (c.flags & KateView::cfRemoveSpaces) ? textLine->lastChar() : textLine->length();
1148 if (c.cursor.x < len/*getTextLine(c.cursor.y)->length()*/) { 1146 if (c.cursor.x < len/*getTextLine(c.cursor.y)->length()*/) {
1149 // delete one character 1147 // delete one character
1150 recordStart(c, KateActionGroup::ugDelChar); 1148 recordStart(c, KateActionGroup::ugDelChar);
1151 recordDelete(c.cursor, 1); 1149 recordDelete(c.cursor, 1);
1152 recordEnd(c); 1150 recordEnd(c);
1153 } else { 1151 } else {
1154 if (c.cursor.y < lastLine()) { 1152 if (c.cursor.y < lastLine()) {
1155 // wrap next line to this line 1153 // wrap next line to this line
1156 textLine->truncate(c.cursor.x); // truncate spaces 1154 textLine->truncate(c.cursor.x); // truncate spaces
1157 recordStart(c, KateActionGroup::ugDelLine); 1155 recordStart(c, KateActionGroup::ugDelLine);
1158 recordAction(KateAction::delLine,c.cursor); 1156 recordAction(KateAction::delLine,c.cursor);
1159 recordEnd(c); 1157 recordEnd(c);
1160 } 1158 }
1161 } 1159 }
1162} 1160}
1163 1161
1164void KateDocument::clear() { 1162void KateDocument::clear() {
1165 PointStruc cursor; 1163 PointStruc cursor;
1166 KateView *view; 1164 KateView *view;
1167 1165
1168 setPseudoModal(0L); 1166 setPseudoModal(0L);
1169 cursor.x = cursor.y = 0; 1167 cursor.x = cursor.y = 0;
1170 for (view = views.first(); view != 0L; view = views.next() ) { 1168 for (view = views.first(); view != 0L; view = views.next() ) {
1171 view->updateCursor(cursor); 1169 view->updateCursor(cursor);
1172 view->tagAll(); 1170 view->tagAll();
1173 } 1171 }
1174 1172
1175 eolMode = KateDocument::eolUnix; 1173 eolMode = KateDocument::eolUnix;
1176 1174
1177 buffer->clear(); 1175 buffer->clear();
1178 longestLine = buffer->line(0); 1176 longestLine = buffer->line(0);
1179 1177
1180 maxLength = 0; 1178 maxLength = 0;
1181 1179
1182 select.x = -1; 1180 select.x = -1;
1183 1181
1184 selectStart = 0xffffff; 1182 selectStart = 0xffffff;
1185 selectEnd = 0; 1183 selectEnd = 0;
1186 oldMarkState = false; 1184 oldMarkState = false;
1187 1185
1188 setModified(false); 1186 setModified(false);
1189 1187
1190 undoList.clear(); 1188 undoList.clear();
1191 currentUndo = 0; 1189 currentUndo = 0;
1192 newUndo(); 1190 newUndo();
1193} 1191}
1194 1192
1195void KateDocument::cut(VConfig &c) { 1193void KateDocument::cut(VConfig &c) {
1196 1194
1197 if (selectEnd < selectStart) return; 1195 if (selectEnd < selectStart) return;
1198 1196
1199 copy(c.flags); 1197 copy(c.flags);
1200 delMarkedText(c); 1198 delMarkedText(c);
1201} 1199}
1202 1200
1203void KateDocument::copy(int flags) { 1201void KateDocument::copy(int flags) {
1204 1202
1205 if (selectEnd < selectStart) return; 1203 if (selectEnd < selectStart) return;
1206 1204
1207 QString s = markedText(flags); 1205 QString s = markedText(flags);
1208 if (!s.isEmpty()) { 1206 if (!s.isEmpty()) {
1209//#if defined(_WS_X11_) 1207//#if defined(_WS_X11_)
1210 if (m_singleSelection) 1208 if (m_singleSelection)
1211 disconnect(QApplication::clipboard(), SIGNAL(dataChanged()), this, 0); 1209 disconnect(QApplication::clipboard(), SIGNAL(dataChanged()), this, 0);
1212//#endif 1210//#endif
1213 QApplication::clipboard()->setText(s); 1211 QApplication::clipboard()->setText(s);
1214//#if defined(_WS_X11_) 1212//#if defined(_WS_X11_)
1215 if (m_singleSelection) { 1213 if (m_singleSelection) {
1216 connect(QApplication::clipboard(), SIGNAL(dataChanged()), 1214 connect(QApplication::clipboard(), SIGNAL(dataChanged()),
1217 this, SLOT(clipboardChanged())); 1215 this, SLOT(clipboardChanged()));
1218 } 1216 }
1219//#endif 1217//#endif
1220 } 1218 }
1221} 1219}
1222 1220
1223void KateDocument::paste(VConfig &c) { 1221void KateDocument::paste(VConfig &c) {
1224 QString s = QApplication::clipboard()->text(); 1222 QString s = QApplication::clipboard()->text();
1225 if (!s.isEmpty()) { 1223 if (!s.isEmpty()) {
1226 insert(c, s); 1224 insert(c, s);
1227 } 1225 }
1228} 1226}
1229 1227
1230void KateDocument::toggleRect(int start, int end, int x1, int x2) { 1228void KateDocument::toggleRect(int start, int end, int x1, int x2) {
1231 int z, line; 1229 int z, line;
1232 bool t; 1230 bool t;
1233 1231
1234 if (x1 > x2) { 1232 if (x1 > x2) {
1235 z = x1; 1233 z = x1;
1236 x1 = x2; 1234 x1 = x2;
1237 x2 = z; 1235 x2 = z;
1238 } 1236 }
1239 if (start > end) { 1237 if (start > end) {
1240 z = start; 1238 z = start;
1241 start = end; 1239 start = end;
1242 end = z; 1240 end = z;
1243 } 1241 }
1244 1242
1245 t = false; 1243 t = false;
1246 for (line = start; line < end; line++) { 1244 for (line = start; line < end; line++) {
1247 int x, oldX, s, e, newX1, newX2; 1245 int x, oldX, s, e, newX1, newX2;
1248 QChar ch; 1246 QChar ch;
1249 Attribute *a; 1247 Attribute *a;
1250 1248
1251 TextLine::Ptr textLine = getTextLine(line); 1249 TextLine::Ptr textLine = getTextLine(line);
1252 1250
1253 //--- speed optimization 1251 //--- speed optimization
1254 //s = textPos(textLine, x1, newX1); 1252 //s = textPos(textLine, x1, newX1);
1255 x = oldX = z = 0; 1253 x = oldX = z = 0;
1256 while (x < x1) { // && z < len) { 1254 while (x < x1) { // && z < len) {
1257 oldX = x; 1255 oldX = x;
1258 ch = textLine->getChar(z); 1256 ch = textLine->getChar(z);
1259 a = &m_attribs[textLine->getAttr(z)]; 1257 a = &m_attribs[textLine->getAttr(z)];
1260 1258
1261 if (ch == '\t') 1259 if (ch == '\t')
1262 x += m_tabWidth - (x % m_tabWidth); 1260 x += m_tabWidth - (x % m_tabWidth);
1263 else if (a->bold && a->italic) 1261 else if (a->bold && a->italic)
1264 x += myFontMetricsBI.width(ch); 1262 x += myFontMetricsBI.width(ch);
1265 else if (a->bold) 1263 else if (a->bold)
1266 x += myFontMetricsBold.width(ch); 1264 x += myFontMetricsBold.width(ch);
1267 else if (a->italic) 1265 else if (a->italic)
1268 x += myFontMetricsItalic.width(ch); 1266 x += myFontMetricsItalic.width(ch);
1269 else 1267 else
1270 x += myFontMetrics.width(ch); 1268 x += myFontMetrics.width(ch);
1271 1269
1272 z++; 1270 z++;
1273 } 1271 }
1274 s = z; 1272 s = z;
1275 if (x1 - oldX < x - x1 && z > 0) { 1273 if (x1 - oldX < x - x1 && z > 0) {
1276 s--; 1274 s--;
1277 newX1 = oldX; 1275 newX1 = oldX;
1278 } else newX1 = x; 1276 } else newX1 = x;
1279 //e = textPos(textLine, x2, newX2); 1277 //e = textPos(textLine, x2, newX2);
1280 while (x < x2) { // && z < len) { 1278 while (x < x2) { // && z < len) {
1281 oldX = x; 1279 oldX = x;
1282 ch = textLine->getChar(z); 1280 ch = textLine->getChar(z);
1283 a = &m_attribs[textLine->getAttr(z)]; 1281 a = &m_attribs[textLine->getAttr(z)];
1284 1282
1285 if (ch == '\t') 1283 if (ch == '\t')
1286 x += m_tabWidth - (x % m_tabWidth); 1284 x += m_tabWidth - (x % m_tabWidth);
1287 else if (a->bold && a->italic) 1285 else if (a->bold && a->italic)
1288 x += myFontMetricsBI.width(ch); 1286 x += myFontMetricsBI.width(ch);
1289 else if (a->bold) 1287 else if (a->bold)
1290 x += myFontMetricsBold.width(ch); 1288 x += myFontMetricsBold.width(ch);
1291 else if (a->italic) 1289 else if (a->italic)
1292 x += myFontMetricsItalic.width(ch); 1290 x += myFontMetricsItalic.width(ch);
1293 else 1291 else
1294 x += myFontMetrics.width(ch); 1292 x += myFontMetrics.width(ch);
1295 1293
1296 z++; 1294 z++;
1297 } 1295 }
1298 e = z; 1296 e = z;
1299 if (x2 - oldX < x - x2 && z > 0) { 1297 if (x2 - oldX < x - x2 && z > 0) {
1300 e--; 1298 e--;
1301 newX2 = oldX; 1299 newX2 = oldX;
1302 } else newX2 = x; 1300 } else newX2 = x;
1303 //--- 1301 //---
1304 1302
1305 if (e > s) { 1303 if (e > s) {
1306 textLine->toggleSelect(s, e); 1304 textLine->toggleSelect(s, e);
1307 tagLineRange(line, newX1, newX2); 1305 tagLineRange(line, newX1, newX2);
1308 t = true; 1306 t = true;
1309 } 1307 }
1310 } 1308 }
1311 if (t) { 1309 if (t) {
1312 end--; 1310 end--;
1313// tagLines(start, end); 1311// tagLines(start, end);
1314 1312
1315 if (start < selectStart) selectStart = start; 1313 if (start < selectStart) selectStart = start;
1316 if (end > selectEnd) selectEnd = end; 1314 if (end > selectEnd) selectEnd = end;
1317 emit selectionChanged(); 1315 emit selectionChanged();
1318 } 1316 }
1319} 1317}
1320 1318
1321void KateDocument::selectTo(VConfig &c, PointStruc &cursor, int cXPos) { 1319void KateDocument::selectTo(VConfig &c, PointStruc &cursor, int cXPos) {
1322 //c.cursor = old cursor position 1320 //c.cursor = old cursor position
1323 //cursor = new cursor position 1321 //cursor = new cursor position
1324 1322
1325 if (c.cursor.x != select.x || c.cursor.y != select.y) { 1323 if (c.cursor.x != select.x || c.cursor.y != select.y) {
1326 //new selection 1324 //new selection
1327 1325
1328 if (!(c.flags & KateView::cfKeepSelection)) deselectAll(); 1326 if (!(c.flags & KateView::cfKeepSelection)) deselectAll();
1329// else recordReset(); 1327// else recordReset();
1330 1328
1331 anchor = c.cursor; 1329 anchor = c.cursor;
1332 aXPos = c.cXPos; 1330 aXPos = c.cXPos;
1333 } 1331 }
1334 1332
1335 if (!(c.flags & KateView::cfVerticalSelect)) { 1333 if (!(c.flags & KateView::cfVerticalSelect)) {
1336 //horizontal selections 1334 //horizontal selections
1337 int x, y, sXPos; 1335 int x, y, sXPos;
1338 int ex, ey, eXPos; 1336 int ex, ey, eXPos;
1339 bool sel; 1337 bool sel;
1340 1338
1341 if (cursor.y > c.cursor.y || (cursor.y == c.cursor.y && cursor.x > c.cursor.x)) { 1339 if (cursor.y > c.cursor.y || (cursor.y == c.cursor.y && cursor.x > c.cursor.x)) {
1342 x = c.cursor.x; 1340 x = c.cursor.x;
1343 y = c.cursor.y; 1341 y = c.cursor.y;
1344 sXPos = c.cXPos; 1342 sXPos = c.cXPos;
1345 ex = cursor.x; 1343 ex = cursor.x;
1346 ey = cursor.y; 1344 ey = cursor.y;
1347 eXPos = cXPos; 1345 eXPos = cXPos;
1348 sel = true; 1346 sel = true;
1349 } else { 1347 } else {
1350 x = cursor.x; 1348 x = cursor.x;
1351 y = cursor.y; 1349 y = cursor.y;
1352 sXPos = cXPos; 1350 sXPos = cXPos;
1353 ex = c.cursor.x; 1351 ex = c.cursor.x;
1354 ey = c.cursor.y; 1352 ey = c.cursor.y;
1355 eXPos = c.cXPos; 1353 eXPos = c.cXPos;
1356 sel = false; 1354 sel = false;
1357 } 1355 }
1358 1356
1359// tagLines(y, ye); 1357// tagLines(y, ye);
1360 if (y < ey) { 1358 if (y < ey) {
1361 //tagLineRange(y, sXPos, 0xffffff); 1359 //tagLineRange(y, sXPos, 0xffffff);
1362 tagLines(y, ey -1); 1360 tagLines(y, ey -1);
1363 tagLineRange(ey, 0, eXPos); 1361 tagLineRange(ey, 0, eXPos);
1364 } else tagLineRange(y, sXPos, eXPos); 1362 } else tagLineRange(y, sXPos, eXPos);
1365 1363
1366 if (y < selectStart) selectStart = y; 1364 if (y < selectStart) selectStart = y;
1367 if (ey > selectEnd) selectEnd = ey; 1365 if (ey > selectEnd) selectEnd = ey;
1368 1366
1369 TextLine::Ptr textLine = getTextLine(y); 1367 TextLine::Ptr textLine = getTextLine(y);
1370 1368
1371 if (c.flags & KateView::cfXorSelect) { 1369 if (c.flags & KateView::cfXorSelect) {
1372 //xor selection with old selection 1370 //xor selection with old selection
1373 while (y < ey) { 1371 while (y < ey) {
1374 textLine->toggleSelectEol(x); 1372 textLine->toggleSelectEol(x);
1375 x = 0; 1373 x = 0;
1376 y++; 1374 y++;
1377 textLine = getTextLine(y); 1375 textLine = getTextLine(y);
1378 } 1376 }
1379 textLine->toggleSelect(x, ex); 1377 textLine->toggleSelect(x, ex);
1380 } else { 1378 } else {
1381 //set selection over old selection 1379 //set selection over old selection
1382 1380
1383 if (anchor.y > y || (anchor.y == y && anchor.x > x)) { 1381 if (anchor.y > y || (anchor.y == y && anchor.x > x)) {
1384 if (anchor.y < ey || (anchor.y == ey && anchor.x < ex)) { 1382 if (anchor.y < ey || (anchor.y == ey && anchor.x < ex)) {
1385 sel = !sel; 1383 sel = !sel;
1386 while (y < anchor.y) { 1384 while (y < anchor.y) {
1387 textLine->selectEol(sel, x); 1385 textLine->selectEol(sel, x);
1388 x = 0; 1386 x = 0;
1389 y++; 1387 y++;
1390 textLine = getTextLine(y); 1388 textLine = getTextLine(y);
1391 } 1389 }
1392 textLine->select(sel, x, anchor.x); 1390 textLine->select(sel, x, anchor.x);
1393 x = anchor.x; 1391 x = anchor.x;
1394 } 1392 }
1395 sel = !sel; 1393 sel = !sel;
1396 } 1394 }
1397 while (y < ey) { 1395 while (y < ey) {
1398 textLine->selectEol(sel, x); 1396 textLine->selectEol(sel, x);
1399 x = 0; 1397 x = 0;
1400 y++; 1398 y++;
1401 textLine = getTextLine(y); 1399 textLine = getTextLine(y);
1402 } 1400 }
1403 textLine->select(sel, x, ex); 1401 textLine->select(sel, x, ex);
1404 } 1402 }
1405 } else { 1403 } else {
1406 //vertical (block) selections 1404 //vertical (block) selections
1407// int ax, sx, ex; 1405// int ax, sx, ex;
1408 1406
1409// ax = textWidth(anchor); 1407// ax = textWidth(anchor);
1410// sx = textWidth(start); 1408// sx = textWidth(start);
1411// ex = textWidth(end); 1409// ex = textWidth(end);
1412 1410
1413 toggleRect(c.cursor.y + 1, cursor.y + 1, aXPos, c.cXPos); 1411 toggleRect(c.cursor.y + 1, cursor.y + 1, aXPos, c.cXPos);
1414 toggleRect(anchor.y, cursor.y + 1, c.cXPos, cXPos); 1412 toggleRect(anchor.y, cursor.y + 1, c.cXPos, cXPos);
1415 } 1413 }
1416 select = cursor; 1414 select = cursor;
1417 optimizeSelection(); 1415 optimizeSelection();
1418 emit selectionChanged(); 1416 emit selectionChanged();
1419} 1417}
1420 1418
1421 1419
1422void KateDocument::selectAll() { 1420void KateDocument::selectAll() {
1423 int z; 1421 int z;
1424 TextLine::Ptr textLine; 1422 TextLine::Ptr textLine;
1425 1423
1426 select.x = -1; 1424 select.x = -1;
1427 1425
1428// if (selectStart != 0 || selectEnd != lastLine()) recordReset(); 1426// if (selectStart != 0 || selectEnd != lastLine()) recordReset();
1429 1427
1430 selectStart = 0; 1428 selectStart = 0;
1431 selectEnd = lastLine(); 1429 selectEnd = lastLine();
1432 1430
1433 tagLines(selectStart,selectEnd); 1431 tagLines(selectStart,selectEnd);
1434 1432
1435 for (z = selectStart; z < selectEnd; z++) { 1433 for (z = selectStart; z < selectEnd; z++) {
1436 textLine = getTextLine(z); 1434 textLine = getTextLine(z);
1437 textLine->selectEol(true,0); 1435 textLine->selectEol(true,0);
1438 } 1436 }
1439 textLine = getTextLine(z); 1437 textLine = getTextLine(z);
1440 textLine->select(true,0,textLine->length()); 1438 textLine->select(true,0,textLine->length());
1441 emit selectionChanged(); 1439 emit selectionChanged();
1442} 1440}
1443 1441
1444void KateDocument::deselectAll() { 1442void KateDocument::deselectAll() {
1445 select.x = -1; 1443 select.x = -1;
1446 if (selectEnd < selectStart) return; 1444 if (selectEnd < selectStart) return;
1447 1445
1448// recordReset(); 1446// recordReset();
1449 1447
1450 tagLines(selectStart,selectEnd); 1448 tagLines(selectStart,selectEnd);
1451 1449
1452 for (int z = selectStart; z <= selectEnd; z++) { 1450 for (int z = selectStart; z <= selectEnd; z++) {
1453 TextLine::Ptr textLine = getTextLine(z); 1451 TextLine::Ptr textLine = getTextLine(z);
1454 textLine->selectEol(false,0); 1452 textLine->selectEol(false,0);
1455 } 1453 }
1456 selectStart = 0xffffff; 1454 selectStart = 0xffffff;
1457 selectEnd = 0; 1455 selectEnd = 0;
1458 emit selectionChanged(); 1456 emit selectionChanged();
1459} 1457}
1460 1458
1461void KateDocument::invertSelection() { 1459void KateDocument::invertSelection() {
1462 TextLine::Ptr textLine; 1460 TextLine::Ptr textLine;
1463 1461
1464 select.x = -1; 1462 select.x = -1;
1465 1463
1466// if (selectStart != 0 || selectEnd != lastLine()) recordReset(); 1464// if (selectStart != 0 || selectEnd != lastLine()) recordReset();
1467 1465
1468 selectStart = 0; 1466 selectStart = 0;
1469 selectEnd = lastLine(); 1467 selectEnd = lastLine();
1470 1468
1471 tagLines(selectStart,selectEnd); 1469 tagLines(selectStart,selectEnd);
1472 1470
1473 for (int z = selectStart; z < selectEnd; z++) { 1471 for (int z = selectStart; z < selectEnd; z++) {
1474 textLine = getTextLine(z); 1472 textLine = getTextLine(z);
1475 textLine->toggleSelectEol(0); 1473 textLine->toggleSelectEol(0);
1476 } 1474 }
1477 textLine = getTextLine(selectEnd); 1475 textLine = getTextLine(selectEnd);
1478 textLine->toggleSelect(0,textLine->length()); 1476 textLine->toggleSelect(0,textLine->length());
1479 optimizeSelection(); 1477 optimizeSelection();
1480 emit selectionChanged(); 1478 emit selectionChanged();
1481} 1479}
1482 1480
1483void KateDocument::selectWord(PointStruc &cursor, int flags) { 1481void KateDocument::selectWord(PointStruc &cursor, int flags) {
1484 int start, end, len; 1482 int start, end, len;
1485 1483
1486 TextLine::Ptr textLine = getTextLine(cursor.y); 1484 TextLine::Ptr textLine = getTextLine(cursor.y);
1487 len = textLine->length(); 1485 len = textLine->length();
1488 start = end = cursor.x; 1486 start = end = cursor.x;
1489 while (start > 0 && m_highlight->isInWord(textLine->getChar(start - 1))) start--; 1487 while (start > 0 && m_highlight->isInWord(textLine->getChar(start - 1))) start--;
1490 while (end < len && m_highlight->isInWord(textLine->getChar(end))) end++; 1488 while (end < len && m_highlight->isInWord(textLine->getChar(end))) end++;
1491 if (end <= start) return; 1489 if (end <= start) return;
1492 if (!(flags & KateView::cfKeepSelection)) deselectAll(); 1490 if (!(flags & KateView::cfKeepSelection)) deselectAll();
1493// else recordReset(); 1491// else recordReset();
1494 1492
1495 textLine->select(true, start, end); 1493 textLine->select(true, start, end);
1496 1494
1497 anchor.x = start; 1495 anchor.x = start;
1498 select.x = end; 1496 select.x = end;
1499 anchor.y = select.y = cursor.y; 1497 anchor.y = select.y = cursor.y;
1500 tagLines(cursor.y, cursor.y); 1498 tagLines(cursor.y, cursor.y);
1501 if (cursor.y < selectStart) selectStart = cursor.y; 1499 if (cursor.y < selectStart) selectStart = cursor.y;
1502 if (cursor.y > selectEnd) selectEnd = cursor.y; 1500 if (cursor.y > selectEnd) selectEnd = cursor.y;
1503 emit selectionChanged(); 1501 emit selectionChanged();
1504} 1502}
1505 1503
1506void KateDocument::selectLength(PointStruc &cursor, int length, int flags) { 1504void KateDocument::selectLength(PointStruc &cursor, int length, int flags) {
1507 int start, end; 1505 int start, end;
1508 1506
1509 TextLine::Ptr textLine = getTextLine(cursor.y); 1507 TextLine::Ptr textLine = getTextLine(cursor.y);
1510 start = cursor.x; 1508 start = cursor.x;
1511 end = start + length; 1509 end = start + length;
1512 if (end <= start) return; 1510 if (end <= start) return;
1513 if (!(flags & KateView::cfKeepSelection)) deselectAll(); 1511 if (!(flags & KateView::cfKeepSelection)) deselectAll();
1514 1512
1515 textLine->select(true, start, end); 1513 textLine->select(true, start, end);
1516 1514
1517 anchor.x = start; 1515 anchor.x = start;
1518 select.x = end; 1516 select.x = end;
1519 anchor.y = select.y = cursor.y; 1517 anchor.y = select.y = cursor.y;
1520 tagLines(cursor.y, cursor.y); 1518 tagLines(cursor.y, cursor.y);
1521 if (cursor.y < selectStart) selectStart = cursor.y; 1519 if (cursor.y < selectStart) selectStart = cursor.y;
1522 if (cursor.y > selectEnd) selectEnd = cursor.y; 1520 if (cursor.y > selectEnd) selectEnd = cursor.y;
1523 emit selectionChanged(); 1521 emit selectionChanged();
1524} 1522}
1525 1523
1526void KateDocument::doIndent(VConfig &c, int change) { 1524void KateDocument::doIndent(VConfig &c, int change) {
1527 1525
1528 c.cursor.x = 0; 1526 c.cursor.x = 0;
1529 1527
1530 recordStart(c, (change < 0) ? KateActionGroup::ugUnindent 1528 recordStart(c, (change < 0) ? KateActionGroup::ugUnindent
1531 : KateActionGroup::ugIndent); 1529 : KateActionGroup::ugIndent);
1532 1530
1533 if (selectEnd < selectStart) { 1531 if (selectEnd < selectStart) {
1534 // single line 1532 // single line
1535 optimizeLeadingSpace(c.cursor.y, c.flags, change); 1533 optimizeLeadingSpace(c.cursor.y, c.flags, change);
1536 } else { 1534 } else {
1537 // entire selection 1535 // entire selection
1538 TextLine::Ptr textLine; 1536 TextLine::Ptr textLine;
1539 int line, z; 1537 int line, z;
1540 QChar ch; 1538 QChar ch;
1541 1539
1542 if (c.flags & KateView::cfKeepIndentProfile && change < 0) { 1540 if (c.flags & KateView::cfKeepIndentProfile && change < 0) {
1543 // unindent so that the existing indent profile doesn´t get screwed 1541 // unindent so that the existing indent profile doesn´t get screwed
1544 // if any line we may unindent is already full left, don't do anything 1542 // if any line we may unindent is already full left, don't do anything
1545 for (line = selectStart; line <= selectEnd; line++) { 1543 for (line = selectStart; line <= selectEnd; line++) {
1546 textLine = getTextLine(line); 1544 textLine = getTextLine(line);
1547 if (textLine->isSelected() || textLine->numSelected()) { 1545 if (textLine->isSelected() || textLine->numSelected()) {
1548 for (z = 0; z < tabChars; z++) { 1546 for (z = 0; z < tabChars; z++) {
1549 ch = textLine->getChar(z); 1547 ch = textLine->getChar(z);
1550 if (ch == '\t') break; 1548 if (ch == '\t') break;
1551 if (ch != ' ') { 1549 if (ch != ' ') {
1552 change = 0; 1550 change = 0;
1553 goto jumpOut; 1551 goto jumpOut;
1554 } 1552 }
1555 } 1553 }
1556 } 1554 }
1557 } 1555 }
1558 jumpOut:; 1556 jumpOut:;
1559 } 1557 }
1560 1558
1561 for (line = selectStart; line <= selectEnd; line++) { 1559 for (line = selectStart; line <= selectEnd; line++) {
1562 textLine = getTextLine(line); 1560 textLine = getTextLine(line);
1563 if (textLine->isSelected() || textLine->numSelected()) { 1561 if (textLine->isSelected() || textLine->numSelected()) {
1564 optimizeLeadingSpace(line, c.flags, change); 1562 optimizeLeadingSpace(line, c.flags, change);
1565 } 1563 }
1566 } 1564 }
1567 } 1565 }
1568 // recordEnd now removes empty undo records 1566 // recordEnd now removes empty undo records
1569 recordEnd(c.view, c.cursor, c.flags | KateView::cfPersistent); 1567 recordEnd(c.view, c.cursor, c.flags | KateView::cfPersistent);
1570} 1568}
1571 1569
1572/* 1570/*
1573 Optimize the leading whitespace for a single line. 1571 Optimize the leading whitespace for a single line.
1574 If change is > 0, it adds indentation units (tabChars) 1572 If change is > 0, it adds indentation units (tabChars)
1575 if change is == 0, it only optimizes 1573 if change is == 0, it only optimizes
1576 If change is < 0, it removes indentation units 1574 If change is < 0, it removes indentation units
1577 This will be used to indent, unindent, and optimal-fill a line. 1575 This will be used to indent, unindent, and optimal-fill a line.
1578 If excess space is removed depends on the flag cfKeepExtraSpaces 1576 If excess space is removed depends on the flag cfKeepExtraSpaces
1579 which has to be set by the user 1577 which has to be set by the user
1580*/ 1578*/
1581void KateDocument::optimizeLeadingSpace(int line, int flags, int change) { 1579void KateDocument::optimizeLeadingSpace(int line, int flags, int change) {
1582 int len; 1580 int len;
1583 int chars, space, okLen; 1581 int chars, space, okLen;
1584 QChar ch; 1582 QChar ch;
1585 int extra; 1583 int extra;
1586 QString s; 1584 QString s;
1587 PointStruc cursor; 1585 PointStruc cursor;
1588 1586
1589 TextLine::Ptr textLine = getTextLine(line); 1587 TextLine::Ptr textLine = getTextLine(line);
1590 len = textLine->length(); 1588 len = textLine->length();
1591 space = 0; // length of space at the beginning of the textline 1589 space = 0; // length of space at the beginning of the textline
1592 okLen = 0; // length of space which does not have to be replaced 1590 okLen = 0; // length of space which does not have to be replaced
1593 for (chars = 0; chars < len; chars++) { 1591 for (chars = 0; chars < len; chars++) {
1594 ch = textLine->getChar(chars); 1592 ch = textLine->getChar(chars);
1595 if (ch == ' ') { 1593 if (ch == ' ') {
1596 space++; 1594 space++;
1597 if (flags & KateView::cfSpaceIndent && okLen == chars) okLen++; 1595 if (flags & KateView::cfSpaceIndent && okLen == chars) okLen++;
1598 } else if (ch == '\t') { 1596 } else if (ch == '\t') {
1599 space += tabChars - space % tabChars; 1597 space += tabChars - space % tabChars;
1600 if (!(flags & KateView::cfSpaceIndent) && okLen == chars) okLen++; 1598 if (!(flags & KateView::cfSpaceIndent) && okLen == chars) okLen++;
1601 } else break; 1599 } else break;
1602 } 1600 }
1603 1601
1604 space += change*tabChars; // modify space width 1602 space += change*tabChars; // modify space width
1605 // if line contains only spaces it will be cleared 1603 // if line contains only spaces it will be cleared
1606 if (space < 0 || chars == len) space = 0; 1604 if (space < 0 || chars == len) space = 0;
1607 1605
1608 extra = space % tabChars; // extra spaces which don´t fit the indentation pattern 1606 extra = space % tabChars; // extra spaces which don´t fit the indentation pattern
1609 if (flags & KateView::cfKeepExtraSpaces) chars -= extra; 1607 if (flags & KateView::cfKeepExtraSpaces) chars -= extra;
1610 1608
1611 if (flags & KateView::cfSpaceIndent) { 1609 if (flags & KateView::cfSpaceIndent) {
1612 space -= extra; 1610 space -= extra;
1613 ch = ' '; 1611 ch = ' ';
1614 } else { 1612 } else {
1615 space /= tabChars; 1613 space /= tabChars;
1616 ch = '\t'; 1614 ch = '\t';
1617 } 1615 }
1618 1616
1619 // don´t replace chars which are already ok 1617 // don´t replace chars which are already ok
1620 cursor.x = QMIN(okLen, QMIN(chars, space)); 1618 cursor.x = QMIN(okLen, QMIN(chars, space));
1621 chars -= cursor.x; 1619 chars -= cursor.x;
1622 space -= cursor.x; 1620 space -= cursor.x;
1623 if (chars == 0 && space == 0) return; //nothing to do 1621 if (chars == 0 && space == 0) return; //nothing to do
1624 1622
1625 s.fill(ch, space); 1623 s.fill(ch, space);
1626 1624
1627//printf("chars %d insert %d cursor.x %d\n", chars, insert, cursor.x); 1625//printf("chars %d insert %d cursor.x %d\n", chars, insert, cursor.x);
1628 cursor.y = line; 1626 cursor.y = line;
1629 recordReplace(cursor, chars, s); 1627 recordReplace(cursor, chars, s);
1630} 1628}
1631 1629
1632void KateDocument::doComment(VConfig &c, int change) 1630void KateDocument::doComment(VConfig &c, int change)
1633{ 1631{
1634 c.flags |=KateView:: cfPersistent; 1632 c.flags |=KateView:: cfPersistent;
1635 1633
1636 recordStart(c, (change < 0) ? KateActionGroup::ugUncomment 1634 recordStart(c, (change < 0) ? KateActionGroup::ugUncomment
1637 : KateActionGroup::ugComment); 1635 : KateActionGroup::ugComment);
1638 1636
1639 QString startComment = m_highlight->getCommentStart(); 1637 QString startComment = m_highlight->getCommentStart();
1640 QString startLineComment = m_highlight->getCommentSingleLineStart(); 1638 QString startLineComment = m_highlight->getCommentSingleLineStart();
1641 QString endComment = m_highlight->getCommentEnd(); 1639 QString endComment = m_highlight->getCommentEnd();
1642 1640
1643 int startCommentLen = startComment.length(); 1641 int startCommentLen = startComment.length();
1644 int startLineCommentLen = startLineComment.length(); 1642 int startLineCommentLen = startLineComment.length();
1645 int endCommentLen = endComment.length(); 1643 int endCommentLen = endComment.length();
1646 1644
1647 if (change > 0) 1645 if (change > 0)
1648 { 1646 {
1649 if ( !hasMarkedText() ) 1647 if ( !hasMarkedText() )
1650 { 1648 {
1651 if (startLineComment != "") 1649 if (startLineComment != "")
1652 { 1650 {
1653 // Add a start comment mark 1651 // Add a start comment mark
1654 c.cursor.x = 0; 1652 c.cursor.x = 0;
1655 recordReplace(c.cursor, 0, startLineComment); 1653 recordReplace(c.cursor, 0, startLineComment);
1656 } 1654 }
1657 else if ((startComment != "") && (endComment != "")) 1655 else if ((startComment != "") && (endComment != ""))
1658 { 1656 {
1659 // Add a start comment mark 1657 // Add a start comment mark
1660 c.cursor.x = 0; 1658 c.cursor.x = 0;
1661 recordReplace(c.cursor, 0, startComment); 1659 recordReplace(c.cursor, 0, startComment);
1662 1660
1663 // Add an end comment mark 1661 // Add an end comment mark
1664 TextLine* textline = getTextLine(c.cursor.y); 1662 TextLine* textline = getTextLine(c.cursor.y);
1665 c.cursor.x = textline->length(); 1663 c.cursor.x = textline->length();
1666 recordReplace(c.cursor, 0, endComment); 1664 recordReplace(c.cursor, 0, endComment);
1667 c.cursor.x = 0; 1665 c.cursor.x = 0;
1668 } 1666 }
1669 } 1667 }
1670 else if ((startComment != "") && (endComment != "")) 1668 else if ((startComment != "") && (endComment != ""))
1671 { 1669 {
1672 QString marked (c.view->markedText ()); 1670 QString marked (c.view->markedText ());
1673 int preDeleteLine = -1, preDeleteCol = -1; 1671 int preDeleteLine = -1, preDeleteCol = -1;
1674 c.view->getCursorPosition (&preDeleteLine, &preDeleteCol); 1672 c.view->getCursorPosition (&preDeleteLine, &preDeleteCol);
1675 1673
1676 if (marked.length() > 0) 1674 if (marked.length() > 0)
1677 c.view->keyDelete (); 1675 c.view->keyDelete ();
1678 1676
1679 int line = -1, col = -1; 1677 int line = -1, col = -1;
1680 c.view->getCursorPosition (&line, &col); 1678 c.view->getCursorPosition (&line, &col);
1681 1679
1682 c.view->insertText (startComment + marked + endComment); 1680 c.view->insertText (startComment + marked + endComment);
1683 } 1681 }
1684 } 1682 }
1685 else 1683 else
1686 { 1684 {
1687 if ( !hasMarkedText() ) 1685 if ( !hasMarkedText() )
1688 { 1686 {
1689 TextLine* textline = getTextLine(c.cursor.y); 1687 TextLine* textline = getTextLine(c.cursor.y);
1690 1688
1691 if(textline->startingWith(startLineComment)) 1689 if(textline->startingWith(startLineComment))
1692 { 1690 {
1693 // Remove start comment mark 1691 // Remove start comment mark
1694 c.cursor.x = 0; 1692 c.cursor.x = 0;
1695 recordReplace(c.cursor, startLineCommentLen, ""); 1693 recordReplace(c.cursor, startLineCommentLen, "");
1696 } 1694 }
1697 else if (textline->startingWith(startComment) && textline->endingWith(endComment)) 1695 else if (textline->startingWith(startComment) && textline->endingWith(endComment))
1698 { 1696 {
1699 // Remove start comment mark 1697 // Remove start comment mark
1700 c.cursor.x = 0; 1698 c.cursor.x = 0;
1701 recordReplace(c.cursor, startCommentLen, ""); 1699 recordReplace(c.cursor, startCommentLen, "");
1702 1700
1703 // Remove end comment mark 1701 // Remove end comment mark
1704 if(endComment != "") 1702 if(endComment != "")
1705 { 1703 {
1706 c.cursor.x = textline->length() - endCommentLen; 1704 c.cursor.x = textline->length() - endCommentLen;
1707 recordReplace(c.cursor, endCommentLen, ""); 1705 recordReplace(c.cursor, endCommentLen, "");
1708 c.cursor.x = 0; 1706 c.cursor.x = 0;
1709 } 1707 }
1710 } 1708 }
1711 } 1709 }
1712 else 1710 else
1713 { 1711 {
1714 QString marked (c.view->markedText ()); 1712 QString marked (c.view->markedText ());
1715 int preDeleteLine = -1, preDeleteCol = -1; 1713 int preDeleteLine = -1, preDeleteCol = -1;
1716 c.view->getCursorPosition (&preDeleteLine, &preDeleteCol); 1714 c.view->getCursorPosition (&preDeleteLine, &preDeleteCol);
1717 1715
1718 int start = marked.find (startComment); 1716 int start = marked.find (startComment);
1719 int end = marked.findRev (endComment); 1717 int end = marked.findRev (endComment);
1720 1718
1721 if ((start > -1) && (end > -1)) 1719 if ((start > -1) && (end > -1))
1722 { 1720 {
1723 marked.remove (start, startCommentLen); 1721 marked.remove (start, startCommentLen);
1724 marked.remove (end-startCommentLen, endCommentLen); 1722 marked.remove (end-startCommentLen, endCommentLen);
1725 1723
1726 c.view->keyDelete (); 1724 c.view->keyDelete ();
1727 1725
1728 int line = -1, col = -1; 1726 int line = -1, col = -1;
1729 c.view->getCursorPosition (&line, &col); 1727 c.view->getCursorPosition (&line, &col);
1730 c.view->insertText (marked); 1728 c.view->insertText (marked);
1731 } 1729 }
1732 } 1730 }
1733 } 1731 }
1734 1732
1735 recordEnd(c.view, c.cursor, c.flags | KateView::cfPersistent); 1733 recordEnd(c.view, c.cursor, c.flags | KateView::cfPersistent);
1736} 1734}
1737 1735
1738 1736
1739QString KateDocument::text() const 1737QString KateDocument::text() const
1740{ 1738{
1741 QString s; 1739 QString s;
1742 1740
1743 for (int i=0; i < buffer->count(); i++) 1741 for (int i=0; i < buffer->count(); i++)
1744 { 1742 {
1745 TextLine::Ptr textLine = buffer->line(i); 1743 TextLine::Ptr textLine = buffer->line(i);
1746 s.insert(s.length(), textLine->getText(), textLine->length()); 1744 s.insert(s.length(), textLine->getText(), textLine->length());
1747 if ( (i < (buffer->count()-1)) ) 1745 if ( (i < (buffer->count()-1)) )
1748 s.append('\n'); 1746 s.append('\n');
1749 } 1747 }
1750 1748
1751 return s; 1749 return s;
1752} 1750}
1753 1751
1754QString KateDocument::getWord(PointStruc &cursor) { 1752QString KateDocument::getWord(PointStruc &cursor) {
1755 int start, end, len; 1753 int start, end, len;
1756 1754
1757 TextLine::Ptr textLine = getTextLine(cursor.y); 1755 TextLine::Ptr textLine = getTextLine(cursor.y);
1758 len = textLine->length(); 1756 len = textLine->length();
1759 start = end = cursor.x; 1757 start = end = cursor.x;
1760 while (start > 0 && m_highlight->isInWord(textLine->getChar(start - 1))) start--; 1758 while (start > 0 && m_highlight->isInWord(textLine->getChar(start - 1))) start--;
1761 while (end < len && m_highlight->isInWord(textLine->getChar(end))) end++; 1759 while (end < len && m_highlight->isInWord(textLine->getChar(end))) end++;
1762 len = end - start; 1760 len = end - start;
1763 return QString(&textLine->getText()[start], len); 1761 return QString(&textLine->getText()[start], len);
1764} 1762}
1765 1763
1766void KateDocument::setText(const QString &s) { 1764void KateDocument::setText(const QString &s) {
1767 int pos; 1765 int pos;
1768 QChar ch; 1766 QChar ch;
1769 1767
1770 clear(); 1768 clear();
1771 1769
1772 int line=1; 1770 int line=1;
1773 1771
1774 TextLine::Ptr textLine = buffer->line(0); 1772 TextLine::Ptr textLine = buffer->line(0);
1775 for (pos = 0; pos <= (int) s.length(); pos++) { 1773 for (pos = 0; pos <= (int) s.length(); pos++) {
1776 ch = s[pos]; 1774 ch = s[pos];
1777 if (ch.isPrint() || ch == '\t') { 1775 if (ch.isPrint() || ch == '\t') {
1778 textLine->append(&ch, 1); 1776 textLine->append(&ch, 1);
1779 } else if (ch == '\n') 1777 } else if (ch == '\n')
1780 { 1778 {
1781 textLine = new TextLine(); 1779 textLine = new TextLine();
1782 buffer->insertLine (line, textLine); 1780 buffer->insertLine (line, textLine);
1783 line++; 1781 line++;
1784 } 1782 }
1785 } 1783 }
1786 updateLines(); 1784 updateLines();
1787} 1785}
1788 1786
1789 1787
1790QString KateDocument::markedText(int flags) { 1788QString KateDocument::markedText(int flags) {
1791 TextLine::Ptr textLine; 1789 TextLine::Ptr textLine;
1792 int len, z, start, end, i; 1790 int len, z, start, end, i;
1793 1791
1794 len = 1; 1792 len = 1;
1795 if (!(flags & KateView::cfVerticalSelect)) { 1793 if (!(flags & KateView::cfVerticalSelect)) {
1796 for (z = selectStart; z <= selectEnd; z++) { 1794 for (z = selectStart; z <= selectEnd; z++) {
1797 textLine = getTextLine(z); 1795 textLine = getTextLine(z);
1798 len += textLine->numSelected(); 1796 len += textLine->numSelected();
1799 if (textLine->isSelected()) len++; 1797 if (textLine->isSelected()) len++;
1800 } 1798 }
1801 QString s; 1799 QString s;
1802 len = 0; 1800 len = 0;
1803 for (z = selectStart; z <= selectEnd; z++) { 1801 for (z = selectStart; z <= selectEnd; z++) {
1804 textLine = getTextLine(z); 1802 textLine = getTextLine(z);
1805 end = 0; 1803 end = 0;
1806 do { 1804 do {
1807 start = textLine->findUnselected(end); 1805 start = textLine->findUnselected(end);
1808 end = textLine->findSelected(start); 1806 end = textLine->findSelected(start);
1809 for (i = start; i < end; i++) { 1807 for (i = start; i < end; i++) {
1810 s[len] = textLine->getChar(i); 1808 s[len] = textLine->getChar(i);
1811 len++; 1809 len++;
1812 } 1810 }
1813 } while (start < end); 1811 } while (start < end);
1814 if (textLine->isSelected()) { 1812 if (textLine->isSelected()) {
1815 s[len] = '\n'; 1813 s[len] = '\n';
1816 len++; 1814 len++;
1817 } 1815 }
1818 } 1816 }
1819// s[len] = '\0'; 1817// s[len] = '\0';
1820 return s; 1818 return s;
1821 } else { 1819 } else {
1822 for (z = selectStart; z <= selectEnd; z++) { 1820 for (z = selectStart; z <= selectEnd; z++) {
1823 textLine = getTextLine(z); 1821 textLine = getTextLine(z);
1824 len += textLine->numSelected() + 1; 1822 len += textLine->numSelected() + 1;
1825 } 1823 }
1826 QString s; 1824 QString s;
1827 len = 0; 1825 len = 0;
1828 for (z = selectStart; z <= selectEnd; z++) { 1826 for (z = selectStart; z <= selectEnd; z++) {
1829 textLine = getTextLine(z); 1827 textLine = getTextLine(z);
1830 end = 0; 1828 end = 0;
1831 do { 1829 do {
1832 start = textLine->findUnselected(end); 1830 start = textLine->findUnselected(end);
1833 end = textLine->findSelected(start); 1831 end = textLine->findSelected(start);
1834 for (i = start; i < end; i++) { 1832 for (i = start; i < end; i++) {
1835 s[len] = textLine->getChar(i); 1833 s[len] = textLine->getChar(i);
1836 len++; 1834 len++;
1837 } 1835 }
1838 } while (start < end); 1836 } while (start < end);
1839 s[len] = '\n'; 1837 s[len] = '\n';
1840 len++; 1838 len++;
1841 } 1839 }
1842// s[len] = '\0'; // the final \0 is not counted in length() 1840// s[len] = '\0'; // the final \0 is not counted in length()
1843 return s; 1841 return s;
1844 } 1842 }
1845} 1843}
1846 1844
1847void KateDocument::delMarkedText(VConfig &c/*, bool undo*/) { 1845void KateDocument::delMarkedText(VConfig &c/*, bool undo*/) {
1848 int end = 0; 1846 int end = 0;
1849 1847
1850 if (selectEnd < selectStart) return; 1848 if (selectEnd < selectStart) return;
1851 1849
1852 // the caller may have already started an undo record for the current action 1850 // the caller may have already started an undo record for the current action
1853// if (undo) 1851// if (undo)
1854 1852
1855 //auto deletion of the marked text occurs not very often and can therefore 1853 //auto deletion of the marked text occurs not very often and can therefore
1856 // be recorded separately 1854 // be recorded separately
1857 recordStart(c, KateActionGroup::ugDelBlock); 1855 recordStart(c, KateActionGroup::ugDelBlock);
1858 1856
1859 for (c.cursor.y = selectEnd; c.cursor.y >= selectStart; c.cursor.y--) { 1857 for (c.cursor.y = selectEnd; c.cursor.y >= selectStart; c.cursor.y--) {
1860 TextLine::Ptr textLine = getTextLine(c.cursor.y); 1858 TextLine::Ptr textLine = getTextLine(c.cursor.y);
1861 1859
1862 c.cursor.x = textLine->length(); 1860 c.cursor.x = textLine->length();
1863 do { 1861 do {
1864 end = textLine->findRevUnselected(c.cursor.x); 1862 end = textLine->findRevUnselected(c.cursor.x);
1865 if (end == 0) break; 1863 if (end == 0) break;
1866 c.cursor.x = textLine->findRevSelected(end); 1864 c.cursor.x = textLine->findRevSelected(end);
1867 recordDelete(c.cursor, end - c.cursor.x); 1865 recordDelete(c.cursor, end - c.cursor.x);
1868 } while (true); 1866 } while (true);
1869 end = c.cursor.x; 1867 end = c.cursor.x;
1870 c.cursor.x = textLine->length(); 1868 c.cursor.x = textLine->length();
1871 if (textLine->isSelected()) recordAction(KateAction::delLine,c.cursor); 1869 if (textLine->isSelected()) recordAction(KateAction::delLine,c.cursor);
1872 } 1870 }
1873 c.cursor.y++; 1871 c.cursor.y++;
1874 /*if (end < c.cursor.x)*/ c.cursor.x = end; 1872 /*if (end < c.cursor.x)*/ c.cursor.x = end;
1875 1873
1876 selectEnd = -1; 1874 selectEnd = -1;
1877 select.x = -1; 1875 select.x = -1;
1878 1876
1879 /*if (undo)*/ recordEnd(c); 1877 /*if (undo)*/ recordEnd(c);
1880} 1878}
1881 1879
1882void KateDocument::tagLineRange(int line, int x1, int x2) { 1880void KateDocument::tagLineRange(int line, int x1, int x2) {
1883 int z; 1881 int z;
1884 1882
1885 for (z = 0; z < (int) views.count(); z++) { 1883 for (z = 0; z < (int) views.count(); z++) {
1886 views.at(z)->tagLines(line, line, x1, x2); 1884 views.at(z)->tagLines(line, line, x1, x2);
1887 } 1885 }
1888} 1886}
1889 1887
1890void KateDocument::tagLines(int start, int end) { 1888void KateDocument::tagLines(int start, int end) {
1891 int z; 1889 int z;
1892 1890
1893 for (z = 0; z < (int) views.count(); z++) { 1891 for (z = 0; z < (int) views.count(); z++) {
1894 views.at(z)->tagLines(start, end, 0, 0xffffff); 1892 views.at(z)->tagLines(start, end, 0, 0xffffff);
1895 } 1893 }
1896} 1894}
1897 1895
1898void KateDocument::tagAll() { 1896void KateDocument::tagAll() {
1899 int z; 1897 int z;
1900 1898
1901 for (z = 0; z < (int) views.count(); z++) { 1899 for (z = 0; z < (int) views.count(); z++) {
1902 views.at(z)->tagAll(); 1900 views.at(z)->tagAll();
1903 } 1901 }
1904} 1902}
1905 1903
1906void KateDocument::updateLines(int startLine, int endLine, int flags, int cursorY) { 1904void KateDocument::updateLines(int startLine, int endLine, int flags, int cursorY) {
1907 TextLine::Ptr textLine; 1905 TextLine::Ptr textLine;
1908 int line, last_line; 1906 int line, last_line;
1909 int ctxNum, endCtx; 1907 int ctxNum, endCtx;
1910// kdDebug(13020)<<"******************KateDocument::updateLines Checkpoint 1"<<endl; 1908// kdDebug(13020)<<"******************KateDocument::updateLines Checkpoint 1"<<endl;
1911 if (buffer->line(startLine)==0) {kdDebug(13020)<<"********************No buffer for line " << startLine << " found**************"<<endl; return;}; 1909 if (buffer->line(startLine)==0) {kdDebug(13020)<<"********************No buffer for line " << startLine << " found**************"<<endl; return;};
1912// kdDebug(13020)<<"KateDocument::updateLines Checkpoint 2"<<endl; 1910// kdDebug(13020)<<"KateDocument::updateLines Checkpoint 2"<<endl;
1913 last_line = lastLine(); 1911 last_line = lastLine();
1914// if (endLine >= last_line) endLine = last_line; 1912// if (endLine >= last_line) endLine = last_line;
1915 1913
1916 line = startLine; 1914 line = startLine;
1917 ctxNum = 0; 1915 ctxNum = 0;
1918 if (line > 0) ctxNum = getTextLine(line - 1)->getContext(); 1916 if (line > 0) ctxNum = getTextLine(line - 1)->getContext();
1919 do { 1917 do {
1920// kdDebug(13020)<<QString("**************Working on line: %1").arg(line)<<endl; 1918// kdDebug(13020)<<QString("**************Working on line: %1").arg(line)<<endl;
1921 textLine = getTextLine(line); 1919 textLine = getTextLine(line);
1922 if (textLine==0) kdDebug(13020)<<"****updateLines()>> error textLine==0"<<endl; 1920 if (textLine==0) kdDebug(13020)<<"****updateLines()>> error textLine==0"<<endl;
1923 if (line <= endLine && line != cursorY) { 1921 if (line <= endLine && line != cursorY) {
1924 if (flags & KateView::cfRemoveSpaces) textLine->removeSpaces(); 1922 if (flags & KateView::cfRemoveSpaces) textLine->removeSpaces();
1925 updateMaxLength(textLine); 1923 updateMaxLength(textLine);
1926 } 1924 }
1927 endCtx = textLine->getContext(); 1925 endCtx = textLine->getContext();
1928// qDebug("DOHIGHLIGHT"); 1926// qDebug("DOHIGHLIGHT");
1929 1927
1930 ctxNum = m_highlight->doHighlight(ctxNum,textLine); 1928 ctxNum = m_highlight->doHighlight(ctxNum,textLine);
1931 textLine->setContext(ctxNum); 1929 textLine->setContext(ctxNum);
1932 line++; 1930 line++;
1933 } while ((buffer->line(line)!=0) && (line <= endLine || endCtx != ctxNum)); 1931 } while ((buffer->line(line)!=0) && (line <= endLine || endCtx != ctxNum));
1934// kdDebug(13020)<<"updateLines :: while loop left"<<endl; 1932// kdDebug(13020)<<"updateLines :: while loop left"<<endl;
1935 tagLines(startLine, line - 1); 1933 tagLines(startLine, line - 1);
1936} 1934}
1937 1935
1938 1936
1939void KateDocument::updateMaxLength(TextLine::Ptr &textLine) { 1937void KateDocument::updateMaxLength(TextLine::Ptr &textLine) {
1940 int len; 1938 int len;
1941 1939
1942 len = textWidth(textLine,textLine->length()); 1940 len = textWidth(textLine,textLine->length());
1943 1941
1944 if (len > maxLength) { 1942 if (len > maxLength) {
1945 longestLine = textLine; 1943 longestLine = textLine;
1946 maxLength = len; 1944 maxLength = len;
1947 newDocGeometry = true; 1945 newDocGeometry = true;
1948 } else { 1946 } else {
1949 if (!longestLine || (textLine == longestLine && len <= maxLength*3/4)) { 1947 if (!longestLine || (textLine == longestLine && len <= maxLength*3/4)) {
1950 maxLength = -1; 1948 maxLength = -1;
1951 for (int i = 0; i < numLines();i++) { 1949 for (int i = 0; i < numLines();i++) {
1952 textLine = getTextLine(i); 1950 textLine = getTextLine(i);
1953 len = textWidth(textLine,textLine->length()); 1951 len = textWidth(textLine,textLine->length());
1954 if (len > maxLength) { 1952 if (len > maxLength) {
1955 maxLength = len; 1953 maxLength = len;
1956 longestLine = textLine; 1954 longestLine = textLine;
1957 } 1955 }
1958 } 1956 }
1959 newDocGeometry = true; 1957 newDocGeometry = true;
1960 } 1958 }
1961 } 1959 }
1962} 1960}
1963 1961
1964void KateDocument::slotBufferChanged() { 1962void KateDocument::slotBufferChanged() {
1965 newDocGeometry = true; 1963 newDocGeometry = true;
1966 //updateLines();//JW 1964 //updateLines();//JW
1967 updateViews(); 1965 updateViews();
1968} 1966}
1969 1967
1970void KateDocument::slotBufferHighlight(long start,long stop) { 1968void KateDocument::slotBufferHighlight(long start,long stop) {
1971 kdDebug(13020)<<"KateDocument::slotBufferHighlight"<<QString("%1-%2").arg(start).arg(stop)<<endl; 1969 kdDebug(13020)<<"KateDocument::slotBufferHighlight"<<QString("%1-%2").arg(start).arg(stop)<<endl;
1972 updateLines(start,stop); 1970 updateLines(start,stop);
1973// buffer->startLoadTimer(); 1971// buffer->startLoadTimer();
1974} 1972}
1975 1973
1976void KateDocument::updateViews(KateView *exclude) { 1974void KateDocument::updateViews(KateView *exclude) {
1977 KateView *view; 1975 KateView *view;
1978 int flags; 1976 int flags;
1979 bool markState = hasMarkedText(); 1977 bool markState = hasMarkedText();
1980 1978
1981 flags = (newDocGeometry) ? KateView::ufDocGeometry : 0; 1979 flags = (newDocGeometry) ? KateView::ufDocGeometry : 0;
1982 for (view = views.first(); view != 0L; view = views.next() ) { 1980 for (view = views.first(); view != 0L; view = views.next() ) {
1983 if (view != exclude) view->updateView(flags); 1981 if (view != exclude) view->updateView(flags);
1984 1982
1985 // notify every view about the changed mark state.... 1983 // notify every view about the changed mark state....
1986 if (oldMarkState != markState) emit view->newMarkStatus(); 1984 if (oldMarkState != markState) emit view->newMarkStatus();
1987 } 1985 }
1988 oldMarkState = markState; 1986 oldMarkState = markState;
1989 newDocGeometry = false; 1987 newDocGeometry = false;
1990} 1988}
1991 1989
1992QColor &KateDocument::cursorCol(int x, int y) { 1990QColor &KateDocument::cursorCol(int x, int y) {
1993 int attr; 1991 int attr;
1994 Attribute *a; 1992 Attribute *a;
1995 1993
1996 TextLine::Ptr textLine = getTextLine(y); 1994 TextLine::Ptr textLine = getTextLine(y);
1997 attr = textLine->getRawAttr(x); 1995 attr = textLine->getRawAttr(x);
1998 a = &m_attribs[attr & taAttrMask]; 1996 a = &m_attribs[attr & taAttrMask];
1999 if (attr & taSelected) return a->selCol; else return a->col; 1997 if (attr & taSelected) return a->selCol; else return a->col;
2000} 1998}
2001 1999
2002void KateDocument::paintTextLine(QPainter &paint, int line, int xStart, int xEnd, bool showTabs) 2000void KateDocument::paintTextLine(QPainter &paint, int line, int xStart, int xEnd, bool showTabs)
2003{ 2001{
2004 paintTextLine (paint, line, 0, xStart, xEnd, showTabs); 2002 paintTextLine (paint, line, 0, xStart, xEnd, showTabs);
2005} 2003}
2006 2004
2007void KateDocument::paintTextLine(QPainter &paint, int line, int y, int xStart, int xEnd, bool showTabs) 2005void KateDocument::paintTextLine(QPainter &paint, int line, int y, int xStart, int xEnd, bool showTabs)
2008{ 2006{
2009 TextLine::Ptr textLine; 2007 TextLine::Ptr textLine;
2010 int len; 2008 int len;
2011 const QChar *s; 2009 const QChar *s;
2012 int z, x; 2010 int z, x;
2013 QChar ch; 2011 QChar ch;
2014 Attribute *a = 0L; 2012 Attribute *a = 0L;
2015 int attr, nextAttr; 2013 int attr, nextAttr;
2016 int xs; 2014 int xs;
2017 int xc, zc; 2015 int xc, zc;
2018 2016
2019 if (line > lastLine()) { 2017 if (line > lastLine()) {
2020 paint.fillRect(0, y, xEnd - xStart,fontHeight, colors[0]); 2018 paint.fillRect(0, y, xEnd - xStart,fontHeight, colors[0]);
2021 return; 2019 return;
2022 } 2020 }
2023 2021
2024 textLine = getTextLine(line); 2022 textLine = getTextLine(line);
2025 len = textLine->length(); 2023 len = textLine->length();
2026 s = textLine->getText(); 2024 s = textLine->getText();
2027 2025
2028 // skip to first visible character 2026 // skip to first visible character
2029 x = 0; 2027 x = 0;
2030 z = 0; 2028 z = 0;
2031 do { 2029 do {
2032 xc = x; 2030 xc = x;
2033 zc = z; 2031 zc = z;
2034 if (z == len) break; 2032 if (z == len) break;
2035 ch = s[z];//textLine->getChar(z); 2033 ch = s[z];//textLine->getChar(z);
2036 if (ch == '\t') { 2034 if (ch == '\t') {
2037 x += m_tabWidth - (x % m_tabWidth); 2035 x += m_tabWidth - (x % m_tabWidth);
2038 } else { 2036 } else {
2039 a = &m_attribs[textLine->getAttr(z)]; 2037 a = &m_attribs[textLine->getAttr(z)];
2040 2038
2041 if (a->bold && a->italic) 2039 if (a->bold && a->italic)
2042 x += myFontMetricsBI.width(ch); 2040 x += myFontMetricsBI.width(ch);
2043 else if (a->bold) 2041 else if (a->bold)
2044 x += myFontMetricsBold.width(ch); 2042 x += myFontMetricsBold.width(ch);
2045 else if (a->italic) 2043 else if (a->italic)
2046 x += myFontMetricsItalic.width(ch); 2044 x += myFontMetricsItalic.width(ch);
2047 else 2045 else
2048 x += myFontMetrics.width(ch); 2046 x += myFontMetrics.width(ch);
2049 } 2047 }
2050 z++; 2048 z++;
2051 } while (x <= xStart); 2049 } while (x <= xStart);
2052 2050
2053 // draw background 2051 // draw background
2054 xs = xStart; 2052 xs = xStart;
2055 attr = textLine->getRawAttr(zc); 2053 attr = textLine->getRawAttr(zc);
2056 while (x < xEnd) 2054 while (x < xEnd)
2057 { 2055 {
2058 nextAttr = textLine->getRawAttr(z); 2056 nextAttr = textLine->getRawAttr(z);
2059 if ((nextAttr ^ attr) & taSelected) 2057 if ((nextAttr ^ attr) & taSelected)
2060 { 2058 {
2061 if (attr & taSelected) 2059 if (attr & taSelected)
2062 paint.fillRect(xs - xStart, y, x - xs, fontHeight, colors[1]); 2060 paint.fillRect(xs - xStart, y, x - xs, fontHeight, colors[1]);
2063 else 2061 else
2064 paint.fillRect(xs - xStart, y, x - xs, fontHeight, colors[0]); 2062 paint.fillRect(xs - xStart, y, x - xs, fontHeight, colors[0]);
2065 2063
2066 xs = x; 2064 xs = x;
2067 attr = nextAttr; 2065 attr = nextAttr;
2068 } 2066 }
2069 2067
2070 if (z == len) break; 2068 if (z == len) break;
2071 2069
2072 ch = s[z];//textLine->getChar(z); 2070 ch = s[z];//textLine->getChar(z);
2073 2071
2074 if (ch == '\t') 2072 if (ch == '\t')
2075 x += m_tabWidth - (x % m_tabWidth); 2073 x += m_tabWidth - (x % m_tabWidth);
2076 else 2074 else
2077 { 2075 {
2078 a = &m_attribs[textLine->getAttr(z)]; 2076 a = &m_attribs[textLine->getAttr(z)];
2079 2077
2080 if (a->bold && a->italic) 2078 if (a->bold && a->italic)
2081 x += myFontMetricsBI.width(ch); 2079 x += myFontMetricsBI.width(ch);
2082 else if (a->bold) 2080 else if (a->bold)
2083 x += myFontMetricsBold.width(ch); 2081 x += myFontMetricsBold.width(ch);
2084 else if (a->italic) 2082 else if (a->italic)
2085 x += myFontMetricsItalic.width(ch); 2083 x += myFontMetricsItalic.width(ch);
2086 else 2084 else
2087 x += myFontMetrics.width(ch); 2085 x += myFontMetrics.width(ch);
2088 } 2086 }
2089 z++; 2087 z++;
2090 } 2088 }
2091 2089
2092 if (attr & taSelected) 2090 if (attr & taSelected)
2093 paint.fillRect(xs - xStart, y, xEnd - xs, fontHeight, colors[1]); 2091 paint.fillRect(xs - xStart, y, xEnd - xs, fontHeight, colors[1]);
2094 else 2092 else
2095 paint.fillRect(xs - xStart, y, xEnd - xs, fontHeight, colors[0]); 2093 paint.fillRect(xs - xStart, y, xEnd - xs, fontHeight, colors[0]);
2096 2094
2097 len = z; //reduce length to visible length 2095 len = z; //reduce length to visible length
2098 2096
2099 // draw text 2097 // draw text
2100 x = xc; 2098 x = xc;
2101 z = zc; 2099 z = zc;
2102 y += fontAscent;// -1; 2100 y += fontAscent;// -1;
2103 attr = -1; 2101 attr = -1;
2104 while (z < len) { 2102 while (z < len) {
2105 ch = s[z];//textLine->getChar(z); 2103 ch = s[z];//textLine->getChar(z);
2106 if (ch == '\t') { 2104 if (ch == '\t') {
2107 if (z > zc) { 2105 if (z > zc) {
2108 //this should cause no copy at all 2106 //this should cause no copy at all
2109 QConstString str((QChar *) &s[zc], z - zc /*+1*/); 2107 QConstString str((QChar *) &s[zc], z - zc /*+1*/);
2110 QString s = str.string(); 2108 QString s = str.string();
2111 paint.drawText(x - xStart, y, s); 2109 paint.drawText(x - xStart, y, s);
2112 2110
2113 if (a->bold && a->italic) 2111 if (a->bold && a->italic)
2114 x += myFontMetricsBI.width(s); 2112 x += myFontMetricsBI.width(s);
2115 else if (a->bold) 2113 else if (a->bold)
2116 x += myFontMetricsBold.width(s); 2114 x += myFontMetricsBold.width(s);
2117 else if (a->italic) 2115 else if (a->italic)
2118 x += myFontMetricsItalic.width(s); 2116 x += myFontMetricsItalic.width(s);
2119 else 2117 else
2120 x += myFontMetrics.width(s); 2118 x += myFontMetrics.width(s);
2121 } 2119 }
2122 zc = z +1; 2120 zc = z +1;
2123 2121
2124 if (showTabs) { 2122 if (showTabs) {
2125 nextAttr = textLine->getRawAttr(z); 2123 nextAttr = textLine->getRawAttr(z);
2126 if (nextAttr != attr) { 2124 if (nextAttr != attr) {
2127 attr = nextAttr; 2125 attr = nextAttr;
2128 a = &m_attribs[attr & taAttrMask]; 2126 a = &m_attribs[attr & taAttrMask];
2129 2127
2130 if (attr & taSelected) paint.setPen(a->selCol); 2128 if (attr & taSelected) paint.setPen(a->selCol);
2131 else paint.setPen(a->col); 2129 else paint.setPen(a->col);
2132 2130
2133 if (a->bold && a->italic) 2131 if (a->bold && a->italic)
2134 paint.setFont(myFontBI); 2132 paint.setFont(myFontBI);
2135 else if (a->bold) 2133 else if (a->bold)
2136 paint.setFont(myFontBold); 2134 paint.setFont(myFontBold);
2137 else if (a->italic) 2135 else if (a->italic)
2138 paint.setFont(myFontItalic); 2136 paint.setFont(myFontItalic);
2139 else 2137 else
2140 paint.setFont(myFont); 2138 paint.setFont(myFont);
2141 } 2139 }
2142 2140
2143// paint.drawLine(x - xStart, y -2, x - xStart, y); 2141// paint.drawLine(x - xStart, y -2, x - xStart, y);
2144// paint.drawLine(x - xStart, y, x - xStart + 2, y); 2142// paint.drawLine(x - xStart, y, x - xStart + 2, y);
2145 paint.drawPoint(x - xStart, y); 2143 paint.drawPoint(x - xStart, y);
2146 paint.drawPoint(x - xStart +1, y); 2144 paint.drawPoint(x - xStart +1, y);
2147 paint.drawPoint(x - xStart, y -1); 2145 paint.drawPoint(x - xStart, y -1);
2148 } 2146 }
2149 x += m_tabWidth - (x % m_tabWidth); 2147 x += m_tabWidth - (x % m_tabWidth);
2150 } else { 2148 } else {
2151 nextAttr = textLine->getRawAttr(z); 2149 nextAttr = textLine->getRawAttr(z);
2152 if (nextAttr != attr) { 2150 if (nextAttr != attr) {
2153 if (z > zc) { 2151 if (z > zc) {
2154 QConstString str((QChar *) &s[zc], z - zc /*+1*/); 2152 QConstString str((QChar *) &s[zc], z - zc /*+1*/);
2155 QString s = str.string(); 2153 QString s = str.string();
2156 paint.drawText(x - xStart, y, s); 2154 paint.drawText(x - xStart, y, s);
2157 2155
2158 if (a->bold && a->italic) 2156 if (a->bold && a->italic)
2159 x += myFontMetricsBI.width(s); 2157 x += myFontMetricsBI.width(s);
2160 else if (a->bold) 2158 else if (a->bold)
2161 x += myFontMetricsBold.width(s); 2159 x += myFontMetricsBold.width(s);
2162 else if (a->italic) 2160 else if (a->italic)
2163 x += myFontMetricsItalic.width(s); 2161 x += myFontMetricsItalic.width(s);
2164 else 2162 else
2165 x += myFontMetrics.width(s); 2163 x += myFontMetrics.width(s);
2166 zc = z; 2164 zc = z;
2167 } 2165 }
2168 attr = nextAttr; 2166 attr = nextAttr;
2169 a = &m_attribs[attr & taAttrMask]; 2167 a = &m_attribs[attr & taAttrMask];
2170 2168
2171 if (attr & taSelected) paint.setPen(a->selCol); 2169 if (attr & taSelected) paint.setPen(a->selCol);
2172 else paint.setPen(a->col); 2170 else paint.setPen(a->col);
2173 2171
2174 if (a->bold && a->italic) 2172 if (a->bold && a->italic)
2175 paint.setFont(myFontBI); 2173 paint.setFont(myFontBI);
2176 else if (a->bold) 2174 else if (a->bold)
2177 paint.setFont(myFontBold); 2175 paint.setFont(myFontBold);
2178 else if (a->italic) 2176 else if (a->italic)
2179 paint.setFont(myFontItalic); 2177 paint.setFont(myFontItalic);
2180 else 2178 else
2181 paint.setFont(myFont); 2179 paint.setFont(myFont);
2182 } 2180 }
2183 } 2181 }
2184 z++; 2182 z++;
2185 } 2183 }
2186 if (z > zc) { 2184 if (z > zc) {
2187 QConstString str((QChar *) &s[zc], z - zc /*+1*/); 2185 QConstString str((QChar *) &s[zc], z - zc /*+1*/);
2188 paint.drawText(x - xStart, y, str.string()); 2186 paint.drawText(x - xStart, y, str.string());
2189 } 2187 }
2190} 2188}
2191 2189
2192// Applies the search context, and returns whether a match was found. If one is, 2190// Applies the search context, and returns whether a match was found. If one is,
2193// the length of the string matched is also returned. 2191// the length of the string matched is also returned.
2194bool KateDocument::doSearch(SConfig &sc, const QString &searchFor) { 2192bool KateDocument::doSearch(SConfig &sc, const QString &searchFor) {
2195 int line, col; 2193 int line, col;
2196 int searchEnd; 2194 int searchEnd;
2197 int bufLen, tlen; 2195 int bufLen, tlen;
2198 QChar *t; 2196 QChar *t;
2199 TextLine::Ptr textLine; 2197 TextLine::Ptr textLine;
2200 int pos, newPos; 2198 int pos, newPos;
2201 2199
2202 if (searchFor.isEmpty()) return false; 2200 if (searchFor.isEmpty()) return false;
2203 2201
2204 bufLen = 0; 2202 bufLen = 0;
2205 t = 0L; 2203 t = 0L;
2206 2204
2207 line = sc.cursor.y; 2205 line = sc.cursor.y;
2208 col = sc.cursor.x; 2206 col = sc.cursor.x;
2209 if (!(sc.flags & KateView::sfBackward)) { 2207 if (!(sc.flags & KateView::sfBackward)) {
2210 //forward search 2208 //forward search
2211 if (sc.flags & KateView::sfSelected) { 2209 if (sc.flags & KateView::sfSelected) {
2212 if (line < selectStart) { 2210 if (line < selectStart) {
2213 line = selectStart; 2211 line = selectStart;
2214 col = 0; 2212 col = 0;
2215 } 2213 }
2216 searchEnd = selectEnd; 2214 searchEnd = selectEnd;
2217 } else searchEnd = lastLine(); 2215 } else searchEnd = lastLine();
2218 2216
2219 while (line <= searchEnd) { 2217 while (line <= searchEnd) {
2220 textLine = getTextLine(line); 2218 textLine = getTextLine(line);
2221 tlen = textLine->length(); 2219 tlen = textLine->length();
2222 if (tlen > bufLen) { 2220 if (tlen > bufLen) {
2223 delete t; 2221 delete t;
2224 bufLen = (tlen + 255) & (~255); 2222 bufLen = (tlen + 255) & (~255);
2225 t = new QChar[bufLen]; 2223 t = new QChar[bufLen];
2226 } 2224 }
2227 memcpy(t, textLine->getText(), tlen*sizeof(QChar)); 2225 memcpy(t, textLine->getText(), tlen*sizeof(QChar));
2228 if (sc.flags & KateView::sfSelected) { 2226 if (sc.flags & KateView::sfSelected) {
2229 pos = 0; 2227 pos = 0;
2230 do { 2228 do {
2231 pos = textLine->findSelected(pos); 2229 pos = textLine->findSelected(pos);
2232 newPos = textLine->findUnselected(pos); 2230 newPos = textLine->findUnselected(pos);
2233 memset(&t[pos], 0, (newPos - pos)*sizeof(QChar)); 2231 memset(&t[pos], 0, (newPos - pos)*sizeof(QChar));
2234 pos = newPos; 2232 pos = newPos;
2235 } while (pos < tlen); 2233 } while (pos < tlen);
2236 } 2234 }
2237 2235
2238 QString text(t, tlen); 2236 QString text(t, tlen);
2239 if (sc.flags & KateView::sfWholeWords) { 2237 if (sc.flags & KateView::sfWholeWords) {
2240 // Until the end of the line... 2238 // Until the end of the line...
2241 while (col < tlen) { 2239 while (col < tlen) {
2242 // ...find the next match. 2240 // ...find the next match.
2243 col = sc.search(text, col); 2241 col = sc.search(text, col);
2244 if (col != -1) { 2242 if (col != -1) {
2245 // Is the match delimited correctly? 2243 // Is the match delimited correctly?
2246 if (((col == 0) || (!m_highlight->isInWord(t[col]))) && 2244 if (((col == 0) || (!m_highlight->isInWord(t[col]))) &&
2247 ((col + sc.matchedLength == tlen) || (!m_highlight->isInWord(t[col + sc.matchedLength])))) { 2245 ((col + sc.matchedLength == tlen) || (!m_highlight->isInWord(t[col + sc.matchedLength])))) {
2248 goto found; 2246 goto found;
2249 } 2247 }
2250 else { 2248 else {
2251 // Start again from the next character. 2249 // Start again from the next character.
2252 col++; 2250 col++;
2253 } 2251 }
2254 } 2252 }
2255 else { 2253 else {
2256 // No match. 2254 // No match.
2257 break; 2255 break;
2258 } 2256 }
2259 } 2257 }
2260 } 2258 }
2261 else { 2259 else {
2262 // Non-whole-word search. 2260 // Non-whole-word search.
2263 col = sc.search(text, col); 2261 col = sc.search(text, col);
2264 if (col != -1) 2262 if (col != -1)
2265 goto found; 2263 goto found;
2266 } 2264 }
2267 col = 0; 2265 col = 0;
2268 line++; 2266 line++;
2269 } 2267 }
2270 } else { 2268 } else {
2271 // backward search 2269 // backward search
2272 if (sc.flags & KateView::sfSelected) { 2270 if (sc.flags & KateView::sfSelected) {
2273 if (line > selectEnd) { 2271 if (line > selectEnd) {
2274 line = selectEnd; 2272 line = selectEnd;
2275 col = -1; 2273 col = -1;
2276 } 2274 }
2277 searchEnd = selectStart; 2275 searchEnd = selectStart;
2278 } else searchEnd = 0; 2276 } else searchEnd = 0;
2279 2277
2280 while (line >= searchEnd) { 2278 while (line >= searchEnd) {
2281 textLine = getTextLine(line); 2279 textLine = getTextLine(line);
2282 tlen = textLine->length(); 2280 tlen = textLine->length();
2283 if (tlen > bufLen) { 2281 if (tlen > bufLen) {
2284 delete t; 2282 delete t;
2285 bufLen = (tlen + 255) & (~255); 2283 bufLen = (tlen + 255) & (~255);
2286 t = new QChar[bufLen]; 2284 t = new QChar[bufLen];
2287 } 2285 }
2288 memcpy(t, textLine->getText(), tlen*sizeof(QChar)); 2286 memcpy(t, textLine->getText(), tlen*sizeof(QChar));
2289 if (sc.flags & KateView::sfSelected) { 2287 if (sc.flags & KateView::sfSelected) {
2290 pos = 0; 2288 pos = 0;
2291 do { 2289 do {
2292 pos = textLine->findSelected(pos); 2290 pos = textLine->findSelected(pos);
2293 newPos = textLine->findUnselected(pos); 2291 newPos = textLine->findUnselected(pos);
2294 memset(&t[pos], 0, (newPos - pos)*sizeof(QChar)); 2292 memset(&t[pos], 0, (newPos - pos)*sizeof(QChar));
2295 pos = newPos; 2293 pos = newPos;
2296 } while (pos < tlen); 2294 } while (pos < tlen);
2297 } 2295 }
2298 2296
2299 if (col < 0 || col > tlen) col = tlen; 2297 if (col < 0 || col > tlen) col = tlen;
2300 2298
2301 QString text(t, tlen); 2299 QString text(t, tlen);
2302 if (sc.flags & KateView::sfWholeWords) { 2300 if (sc.flags & KateView::sfWholeWords) {
2303 // Until the beginning of the line... 2301 // Until the beginning of the line...
2304 while (col >= 0) { 2302 while (col >= 0) {
2305 // ...find the next match. 2303 // ...find the next match.
2306 col = sc.search(text, col); 2304 col = sc.search(text, col);
2307 if (col != -1) { 2305 if (col != -1) {
2308 // Is the match delimited correctly? 2306 // Is the match delimited correctly?
2309 if (((col == 0) || (!m_highlight->isInWord(t[col]))) && 2307 if (((col == 0) || (!m_highlight->isInWord(t[col]))) &&
2310 ((col + sc.matchedLength == tlen) || (!m_highlight->isInWord(t[col + sc.matchedLength])))) { 2308 ((col + sc.matchedLength == tlen) || (!m_highlight->isInWord(t[col + sc.matchedLength])))) {
2311 goto found; 2309 goto found;
2312 } 2310 }
2313 else { 2311 else {
2314 // Start again from the previous character. 2312 // Start again from the previous character.
2315 col--; 2313 col--;
2316 } 2314 }
2317 } 2315 }
2318 else { 2316 else {
2319 // No match. 2317 // No match.
2320 break; 2318 break;
2321 } 2319 }
2322 } 2320 }
2323 } 2321 }
2324 else { 2322 else {
2325 // Non-whole-word search. 2323 // Non-whole-word search.
2326 col = sc.search(text, col); 2324 col = sc.search(text, col);
2327 if (col != -1) 2325 if (col != -1)
2328 goto found; 2326 goto found;
2329 } 2327 }
2330 col = -1; 2328 col = -1;
2331 line--; 2329 line--;
2332 } 2330 }
2333 } 2331 }
2334 sc.flags |= KateView::sfWrapped; 2332 sc.flags |= KateView::sfWrapped;
2335 return false; 2333 return false;
2336found: 2334found:
2337 if (sc.flags & KateView::sfWrapped) { 2335 if (sc.flags & KateView::sfWrapped) {
2338 if ((line > sc.startCursor.y || (line == sc.startCursor.y && col >= sc.startCursor.x)) 2336 if ((line > sc.startCursor.y || (line == sc.startCursor.y && col >= sc.startCursor.x))
2339 ^ ((sc.flags & KateView::sfBackward) != 0)) return false; 2337 ^ ((sc.flags & KateView::sfBackward) != 0)) return false;
2340 } 2338 }
2341 sc.cursor.x = col; 2339 sc.cursor.x = col;
2342 sc.cursor.y = line; 2340 sc.cursor.y = line;
2343 return true; 2341 return true;
2344} 2342}
2345 2343
2346void KateDocument::tagLine(int line) { 2344void KateDocument::tagLine(int line) {
2347 2345
2348 if (tagStart > line) tagStart = line; 2346 if (tagStart > line) tagStart = line;
2349 if (tagEnd < line) tagEnd = line; 2347 if (tagEnd < line) tagEnd = line;
2350} 2348}
2351 2349
2352void KateDocument::insLine(int line) { 2350void KateDocument::insLine(int line) {
2353 KateView *view; 2351 KateView *view;
2354 2352
2355 if (selectStart >= line) selectStart++; 2353 if (selectStart >= line) selectStart++;
2356 if (selectEnd >= line) selectEnd++; 2354 if (selectEnd >= line) selectEnd++;
2357 if (tagStart >= line) tagStart++; 2355 if (tagStart >= line) tagStart++;
2358 if (tagEnd >= line) tagEnd++; 2356 if (tagEnd >= line) tagEnd++;
2359 2357
2360 newDocGeometry = true; 2358 newDocGeometry = true;
2361 for (view = views.first(); view != 0L; view = views.next() ) { 2359 for (view = views.first(); view != 0L; view = views.next() ) {
2362 view->insLine(line); 2360 view->insLine(line);
2363 } 2361 }
2364} 2362}
2365 2363
2366void KateDocument::delLine(int line) { 2364void KateDocument::delLine(int line) {
2367 KateView *view; 2365 KateView *view;
2368 2366
2369 if (selectStart >= line && selectStart > 0) selectStart--; 2367 if (selectStart >= line && selectStart > 0) selectStart--;
2370 if (selectEnd >= line) selectEnd--; 2368 if (selectEnd >= line) selectEnd--;
2371 if (tagStart >= line && tagStart > 0) tagStart--; 2369 if (tagStart >= line && tagStart > 0) tagStart--;
2372 if (tagEnd >= line) tagEnd--; 2370 if (tagEnd >= line) tagEnd--;
2373 2371
2374 newDocGeometry = true; 2372 newDocGeometry = true;
2375 for (view = views.first(); view != 0L; view = views.next() ) { 2373 for (view = views.first(); view != 0L; view = views.next() ) {
2376 view->delLine(line); 2374 view->delLine(line);
2377 } 2375 }
2378} 2376}
2379 2377
2380void KateDocument::optimizeSelection() { 2378void KateDocument::optimizeSelection() {
2381 TextLine::Ptr textLine; 2379 TextLine::Ptr textLine;
2382 2380
2383 while (selectStart <= selectEnd) { 2381 while (selectStart <= selectEnd) {
2384 textLine = getTextLine(selectStart); 2382 textLine = getTextLine(selectStart);
2385 if (textLine->isSelected() || textLine->numSelected() > 0) break; 2383 if (textLine->isSelected() || textLine->numSelected() > 0) break;
2386 selectStart++; 2384 selectStart++;
2387 } 2385 }
2388 while (selectEnd >= selectStart) { 2386 while (selectEnd >= selectStart) {
2389 textLine = getTextLine(selectEnd); 2387 textLine = getTextLine(selectEnd);
2390 if (textLine->isSelected() || textLine->numSelected() > 0) break; 2388 if (textLine->isSelected() || textLine->numSelected() > 0) break;
2391 selectEnd--; 2389 selectEnd--;
2392 } 2390 }
2393 if (selectStart > selectEnd) { 2391 if (selectStart > selectEnd) {
2394 selectStart = 0xffffff; 2392 selectStart = 0xffffff;
2395 selectEnd = 0; 2393 selectEnd = 0;
2396 } 2394 }
2397} 2395}
2398 2396
2399void KateDocument::doAction(KateAction *a) { 2397void KateDocument::doAction(KateAction *a) {
2400 2398
2401 switch (a->action) { 2399 switch (a->action) {
2402 case KateAction::replace: 2400 case KateAction::replace:
2403 doReplace(a); 2401 doReplace(a);
2404 break; 2402 break;
2405 case KateAction::wordWrap: 2403 case KateAction::wordWrap:
2406 doWordWrap(a); 2404 doWordWrap(a);
2407 break; 2405 break;
2408 case KateAction::wordUnWrap: 2406 case KateAction::wordUnWrap:
2409 doWordUnWrap(a); 2407 doWordUnWrap(a);
2410 break; 2408 break;
2411 case KateAction::newLine: 2409 case KateAction::newLine:
2412 doNewLine(a); 2410 doNewLine(a);
2413 break; 2411 break;
2414 case KateAction::delLine: 2412 case KateAction::delLine:
2415 doDelLine(a); 2413 doDelLine(a);
2416 break; 2414 break;
2417 case KateAction::insLine: 2415 case KateAction::insLine:
2418 doInsLine(a); 2416 doInsLine(a);
2419 break; 2417 break;
2420 case KateAction::killLine: 2418 case KateAction::killLine:
2421 doKillLine(a); 2419 doKillLine(a);
2422 break; 2420 break;
2423/* case KateAction::doubleLine: 2421/* case KateAction::doubleLine:
2424 break; 2422 break;
2425 case KateAction::removeLine: 2423 case KateAction::removeLine:
2426 break;*/ 2424 break;*/
2427 } 2425 }
2428} 2426}
2429 2427
2430void KateDocument::doReplace(KateAction *a) { 2428void KateDocument::doReplace(KateAction *a) {
2431 TextLine::Ptr textLine; 2429 TextLine::Ptr textLine;
2432 int l; 2430 int l;
2433 2431
2434 //exchange current text with stored text in KateAction *a 2432 //exchange current text with stored text in KateAction *a
2435 2433
2436 textLine = getTextLine(a->cursor.y); 2434 textLine = getTextLine(a->cursor.y);
2437 l = textLine->length() - a->cursor.x; 2435 l = textLine->length() - a->cursor.x;
2438 if (l > a->len) l = a->len; 2436 if (l > a->len) l = a->len;
2439 2437
2440 QString oldText(&textLine->getText()[a->cursor.x], (l < 0) ? 0 : l); 2438 QString oldText(&textLine->getText()[a->cursor.x], (l < 0) ? 0 : l);
2441 textLine->replace(a->cursor.x, a->len, a->text.unicode(), a->text.length()); 2439 textLine->replace(a->cursor.x, a->len, a->text.unicode(), a->text.length());
2442 2440
2443 a->len = a->text.length(); 2441 a->len = a->text.length();
2444 a->text = oldText; 2442 a->text = oldText;
2445 2443
2446 buffer->changeLine(a->cursor.y); 2444 buffer->changeLine(a->cursor.y);
2447 2445
2448 tagLine(a->cursor.y); 2446 tagLine(a->cursor.y);
2449} 2447}
2450 2448
2451void KateDocument::doWordWrap(KateAction *a) { 2449void KateDocument::doWordWrap(KateAction *a) {
2452 TextLine::Ptr textLine; 2450 TextLine::Ptr textLine;
2453 2451
2454 textLine = getTextLine(a->cursor.y - 1); 2452 textLine = getTextLine(a->cursor.y - 1);
2455 a->len = textLine->length() - a->cursor.x; 2453 a->len = textLine->length() - a->cursor.x;
2456 textLine->wrap(getTextLine(a->cursor.y),a->len); 2454 textLine->wrap(getTextLine(a->cursor.y),a->len);
2457 2455
2458 buffer->changeLine(a->cursor.y - 1); 2456 buffer->changeLine(a->cursor.y - 1);
2459 buffer->changeLine(a->cursor.y); 2457 buffer->changeLine(a->cursor.y);
2460 2458
2461 tagLine(a->cursor.y - 1); 2459 tagLine(a->cursor.y - 1);
2462 tagLine(a->cursor.y); 2460 tagLine(a->cursor.y);
2463 if (selectEnd == a->cursor.y - 1) selectEnd++; 2461 if (selectEnd == a->cursor.y - 1) selectEnd++;
2464 2462
2465 a->action = KateAction::wordUnWrap; 2463 a->action = KateAction::wordUnWrap;
2466} 2464}
2467 2465
2468void KateDocument::doWordUnWrap(KateAction *a) { 2466void KateDocument::doWordUnWrap(KateAction *a) {
2469 TextLine::Ptr textLine; 2467 TextLine::Ptr textLine;
2470 2468
2471 textLine = getTextLine(a->cursor.y - 1); 2469 textLine = getTextLine(a->cursor.y - 1);
2472// textLine->setLength(a->len); 2470// textLine->setLength(a->len);
2473 textLine->unWrap(a->len, getTextLine(a->cursor.y),a->cursor.x); 2471 textLine->unWrap(a->len, getTextLine(a->cursor.y),a->cursor.x);
2474 2472
2475 buffer->changeLine(a->cursor.y - 1); 2473 buffer->changeLine(a->cursor.y - 1);
2476 buffer->changeLine(a->cursor.y); 2474 buffer->changeLine(a->cursor.y);
2477 2475
2478 tagLine(a->cursor.y - 1); 2476 tagLine(a->cursor.y - 1);
2479 tagLine(a->cursor.y); 2477 tagLine(a->cursor.y);
2480 2478
2481 a->action = KateAction::wordWrap; 2479 a->action = KateAction::wordWrap;
2482} 2480}
2483 2481
2484void KateDocument::doNewLine(KateAction *a) { 2482void KateDocument::doNewLine(KateAction *a) {
2485 TextLine::Ptr textLine, newLine; 2483 TextLine::Ptr textLine, newLine;
2486 2484
2487 textLine = getTextLine(a->cursor.y); 2485 textLine = getTextLine(a->cursor.y);
2488 newLine = new TextLine(textLine->getRawAttr(), textLine->getContext()); 2486 newLine = new TextLine(textLine->getRawAttr(), textLine->getContext());
2489 textLine->wrap(newLine,a->cursor.x); 2487 textLine->wrap(newLine,a->cursor.x);
2490 2488
2491 buffer->insertLine(a->cursor.y + 1, newLine); 2489 buffer->insertLine(a->cursor.y + 1, newLine);
2492 buffer->changeLine(a->cursor.y); 2490 buffer->changeLine(a->cursor.y);
2493 2491
2494 insLine(a->cursor.y + 1); 2492 insLine(a->cursor.y + 1);
2495 tagLine(a->cursor.y); 2493 tagLine(a->cursor.y);
2496 tagLine(a->cursor.y + 1); 2494 tagLine(a->cursor.y + 1);
2497 if (selectEnd == a->cursor.y) selectEnd++;//addSelection(a->cursor.y + 1); 2495 if (selectEnd == a->cursor.y) selectEnd++;//addSelection(a->cursor.y + 1);
2498 2496
2499 a->action = KateAction::delLine; 2497 a->action = KateAction::delLine;
2500} 2498}
2501 2499
2502void KateDocument::doDelLine(KateAction *a) { 2500void KateDocument::doDelLine(KateAction *a) {
2503 TextLine::Ptr textLine, nextLine; 2501 TextLine::Ptr textLine, nextLine;
2504 2502
2505 textLine = getTextLine(a->cursor.y); 2503 textLine = getTextLine(a->cursor.y);
2506 nextLine = getTextLine(a->cursor.y+1); 2504 nextLine = getTextLine(a->cursor.y+1);
2507// textLine->setLength(a->cursor.x); 2505// textLine->setLength(a->cursor.x);
2508 textLine->unWrap(a->cursor.x, nextLine,nextLine->length()); 2506 textLine->unWrap(a->cursor.x, nextLine,nextLine->length());
2509 textLine->setContext(nextLine->getContext()); 2507 textLine->setContext(nextLine->getContext());
2510 if (longestLine == nextLine) longestLine = 0L; 2508 if (longestLine == nextLine) longestLine = 0L;
2511 2509
2512 buffer->changeLine(a->cursor.y); 2510 buffer->changeLine(a->cursor.y);
2513 buffer->removeLine(a->cursor.y+1); 2511 buffer->removeLine(a->cursor.y+1);
2514 2512
2515 tagLine(a->cursor.y); 2513 tagLine(a->cursor.y);
2516 delLine(a->cursor.y + 1); 2514 delLine(a->cursor.y + 1);
2517 2515
2518 a->action = KateAction::newLine; 2516 a->action = KateAction::newLine;
2519} 2517}
2520 2518
2521void KateDocument::doInsLine(KateAction *a) { 2519void KateDocument::doInsLine(KateAction *a) {
2522 2520
2523 buffer->insertLine(a->cursor.y, new TextLine()); 2521 buffer->insertLine(a->cursor.y, new TextLine());
2524 2522
2525 insLine(a->cursor.y); 2523 insLine(a->cursor.y);
2526 2524
2527 a->action = KateAction::killLine; 2525 a->action = KateAction::killLine;
2528} 2526}
2529 2527
2530void KateDocument::doKillLine(KateAction *a) { 2528void KateDocument::doKillLine(KateAction *a) {
2531 TextLine::Ptr textLine = getTextLine(a->cursor.y); 2529 TextLine::Ptr textLine = getTextLine(a->cursor.y);
2532 if (longestLine == textLine) longestLine = 0L; 2530 if (longestLine == textLine) longestLine = 0L;
2533 2531
2534 buffer->removeLine(a->cursor.y); 2532 buffer->removeLine(a->cursor.y);
2535 2533
2536 delLine(a->cursor.y); 2534 delLine(a->cursor.y);
2537 tagLine(a->cursor.y); 2535 tagLine(a->cursor.y);
2538 2536
2539 a->action = KateAction::insLine; 2537 a->action = KateAction::insLine;
2540} 2538}
2541 2539
2542void KateDocument::newUndo() { 2540void KateDocument::newUndo() {
2543 KTextEditor::View *view; 2541 KTextEditor::View *view;
2544 int state; 2542 int state;
2545 2543
2546 state = 0; 2544 state = 0;
2547 if (currentUndo > 0) state |= 1; 2545 if (currentUndo > 0) state |= 1;
2548 if (currentUndo < (int) undoList.count()) state |= 2; 2546 if (currentUndo < (int) undoList.count()) state |= 2;
2549 undoState = state; 2547 undoState = state;
2550 for (view = m_views.first(); view != 0L; view = m_views.next() ) { 2548 for (view = m_views.first(); view != 0L; view = m_views.next() ) {
2551 emit static_cast<KateView *>( view )->newUndo(); 2549 emit static_cast<KateView *>( view )->newUndo();
2552 } 2550 }
2553} 2551}
2554 2552
2555void KateDocument::recordStart(VConfig &c, int newUndoType) { 2553void KateDocument::recordStart(VConfig &c, int newUndoType) {
2556 recordStart(c.view, c.cursor, c.flags, newUndoType); 2554 recordStart(c.view, c.cursor, c.flags, newUndoType);
2557} 2555}
2558 2556
2559void KateDocument::recordStart(KateView *, PointStruc &cursor, int flags, 2557void KateDocument::recordStart(KateView *, PointStruc &cursor, int flags,
2560 int newUndoType, bool keepModal, bool mergeUndo) { 2558 int newUndoType, bool keepModal, bool mergeUndo) {
2561 2559
2562 KateActionGroup *g; 2560 KateActionGroup *g;
2563 2561
2564// if (newUndoType == KateActionGroup::ugNone) { 2562// if (newUndoType == KateActionGroup::ugNone) {
2565 // only a bug would cause this 2563 // only a bug would cause this
2566//why should someone do this? we can't prevent all programming errors :) (jochen whilhelmy) 2564//why should someone do this? we can't prevent all programming errors :) (jochen whilhelmy)
2567// debug("KateDocument::recordStart() called with no undo group type!"); 2565// debug("KateDocument::recordStart() called with no undo group type!");
2568// return; 2566// return;
2569// } 2567// }
2570 2568
2571 if (!keepModal) setPseudoModal(0L); 2569 if (!keepModal) setPseudoModal(0L);
2572 2570
2573 //i optimized the group undo stuff a bit (jochen wilhelmy) 2571 //i optimized the group undo stuff a bit (jochen wilhelmy)
2574 // recordReset() is not needed any more 2572 // recordReset() is not needed any more
2575 g = undoList.getLast(); 2573 g = undoList.getLast();
2576 if (g != 0L && ((undoCount < 1024 && flags & KateView::cfGroupUndo 2574 if (g != 0L && ((undoCount < 1024 && flags & KateView::cfGroupUndo
2577 && g->end.x == cursor.x && g->end.y == cursor.y) || mergeUndo)) { 2575 && g->end.x == cursor.x && g->end.y == cursor.y) || mergeUndo)) {
2578 2576
2579 //undo grouping : same actions are put into one undo step 2577 //undo grouping : same actions are put into one undo step
2580 //precondition : new action starts where old stops or mergeUndo flag 2578 //precondition : new action starts where old stops or mergeUndo flag
2581 if (g->undoType == newUndoType 2579 if (g->undoType == newUndoType
2582 || (g->undoType == KateActionGroup::ugInsChar 2580 || (g->undoType == KateActionGroup::ugInsChar
2583 && newUndoType == KateActionGroup::ugInsLine) 2581 && newUndoType == KateActionGroup::ugInsLine)
2584 || (g->undoType == KateActionGroup::ugDelChar 2582 || (g->undoType == KateActionGroup::ugDelChar
2585 && newUndoType == KateActionGroup::ugDelLine)) { 2583 && newUndoType == KateActionGroup::ugDelLine)) {
2586 2584
2587 undoCount++; 2585 undoCount++;
2588 if (g->undoType != newUndoType) undoCount = 0xffffff; 2586 if (g->undoType != newUndoType) undoCount = 0xffffff;
2589 return; 2587 return;
2590 } 2588 }
2591 } 2589 }
2592 undoCount = 0; 2590 undoCount = 0;
2593/* 2591/*
2594 if (undoView != view) { 2592 if (undoView != view) {
2595 // always kill the current undo group if the editing view changes 2593 // always kill the current undo group if the editing view changes
2596 recordReset(); 2594 recordReset();
2597 undoType = newUndoType; 2595 undoType = newUndoType;
2598 } else if (newUndoType == undoType) { 2596 } else if (newUndoType == undoType) {
2599printf("bla!!!\n"); 2597printf("bla!!!\n");
2600 // same as current type, keep using it 2598 // same as current type, keep using it
2601 return; 2599 return;
2602 } else if ( (undoType == KateActionGroup::ugInsChar && newUndoType == KateActionGroup::ugInsLine) || 2600 } else if ( (undoType == KateActionGroup::ugInsChar && newUndoType == KateActionGroup::ugInsLine) ||
2603 (undoType == KateActionGroup::ugDelChar && newUndoType == KateActionGroup::ugDelLine) ) { 2601 (undoType == KateActionGroup::ugDelChar && newUndoType == KateActionGroup::ugDelLine) ) {
2604 // some type combinations can run together... 2602 // some type combinations can run together...
2605 undoType += 1000; 2603 undoType += 1000;
2606 return; 2604 return;
2607 } else { 2605 } else {
2608 recordReset(); 2606 recordReset();
2609 undoType = newUndoType; 2607 undoType = newUndoType;
2610 } 2608 }
2611 2609
2612 undoView = view; 2610 undoView = view;
2613*/ 2611*/
2614 while ((int) undoList.count() > currentUndo) undoList.removeLast(); 2612 while ((int) undoList.count() > currentUndo) undoList.removeLast();
2615 while ((int) undoList.count() > undoSteps) { 2613 while ((int) undoList.count() > undoSteps) {
2616 undoList.removeFirst(); 2614 undoList.removeFirst();
2617 currentUndo--; 2615 currentUndo--;
2618 } 2616 }
2619 2617
2620 g = new KateActionGroup(cursor, newUndoType); 2618 g = new KateActionGroup(cursor, newUndoType);
2621 undoList.append(g); 2619 undoList.append(g);
2622// currentUndo++; 2620// currentUndo++;
2623 2621
2624 tagEnd = 0; 2622 tagEnd = 0;
2625 tagStart = 0xffffff; 2623 tagStart = 0xffffff;
2626} 2624}
2627 2625
2628void KateDocument::recordAction(KateAction::Action action, PointStruc &cursor) { 2626void KateDocument::recordAction(KateAction::Action action, PointStruc &cursor) {
2629 KateAction *a; 2627 KateAction *a;
2630 2628
2631 a = new KateAction(action, cursor); 2629 a = new KateAction(action, cursor);
2632 doAction(a); 2630 doAction(a);
2633 undoList.getLast()->insertAction(a); 2631 undoList.getLast()->insertAction(a);
2634} 2632}
2635 2633
2636void KateDocument::recordInsert(VConfig &c, const QString &text) { 2634void KateDocument::recordInsert(VConfig &c, const QString &text) {
2637 recordReplace(c, 0, text); 2635 recordReplace(c, 0, text);
2638} 2636}
2639 2637
2640void KateDocument::recordReplace(VConfig &c, int len, const QString &text) { 2638void KateDocument::recordReplace(VConfig &c, int len, const QString &text) {
2641 if (c.cursor.x > 0 && !(c.flags & KateView::cfSpaceIndent)) { 2639 if (c.cursor.x > 0 && !(c.flags & KateView::cfSpaceIndent)) {
2642 TextLine::Ptr textLine = getTextLine(c.cursor.y); 2640 TextLine::Ptr textLine = getTextLine(c.cursor.y);
2643 if (textLine->length() == 0) { 2641 if (textLine->length() == 0) {
2644 QString s = tabString(c.cursor.x, tabChars); 2642 QString s = tabString(c.cursor.x, tabChars);
2645 int len = s.length(); 2643 int len = s.length();
2646 s += text; 2644 s += text;
2647 c.cursor.x = 0; 2645 c.cursor.x = 0;
2648 recordReplace(c.cursor, len, s); 2646 recordReplace(c.cursor, len, s);
2649 c.cursor.x = len; 2647 c.cursor.x = len;
2650 return; 2648 return;
2651 } 2649 }
2652 } 2650 }
2653 recordReplace(c.cursor, len, text); 2651 recordReplace(c.cursor, len, text);
2654} 2652}
2655 2653
2656void KateDocument::recordInsert(PointStruc &cursor, const QString &text) { 2654void KateDocument::recordInsert(PointStruc &cursor, const QString &text) {
2657 recordReplace(cursor, 0, text); 2655 recordReplace(cursor, 0, text);
2658} 2656}
2659 2657
2660void KateDocument::recordDelete(PointStruc &cursor, int len) { 2658void KateDocument::recordDelete(PointStruc &cursor, int len) {
2661 recordReplace(cursor, len, QString::null); 2659 recordReplace(cursor, len, QString::null);
2662} 2660}
2663 2661
2664void KateDocument::recordReplace(PointStruc &cursor, int len, const QString &text) { 2662void KateDocument::recordReplace(PointStruc &cursor, int len, const QString &text) {
2665 KateAction *a; 2663 KateAction *a;
2666 TextLine::Ptr textLine; 2664 TextLine::Ptr textLine;
2667 int l; 2665 int l;
2668 2666
2669 if (len == 0 && text.isEmpty()) return; 2667 if (len == 0 && text.isEmpty()) return;
2670 2668
2671 //try to append to last replace action 2669 //try to append to last replace action
2672 a = undoList.getLast()->action; 2670 a = undoList.getLast()->action;
2673 if (a == 0L || a->action != KateAction::replace 2671 if (a == 0L || a->action != KateAction::replace
2674 || a->cursor.x + a->len != cursor.x || a->cursor.y != cursor.y) { 2672 || a->cursor.x + a->len != cursor.x || a->cursor.y != cursor.y) {
2675 2673
2676//if (a != 0L) printf("new %d %d\n", a->cursor.x + a->len, cursor.x); 2674//if (a != 0L) printf("new %d %d\n", a->cursor.x + a->len, cursor.x);
2677 a = new KateAction(KateAction::replace, cursor); 2675 a = new KateAction(KateAction::replace, cursor);
2678 undoList.getLast()->insertAction(a); 2676 undoList.getLast()->insertAction(a);
2679 } 2677 }
2680 2678
2681 //replace 2679 //replace
2682 textLine = getTextLine(cursor.y); 2680 textLine = getTextLine(cursor.y);
2683 l = textLine->length() - cursor.x; 2681 l = textLine->length() - cursor.x;
2684 if (l > len) l = len; 2682 if (l > len) l = len;
2685 a->text.insert(a->text.length(), &textLine->getText()[cursor.x], (l < 0) ? 0 : l); 2683 a->text.insert(a->text.length(), &textLine->getText()[cursor.x], (l < 0) ? 0 : l);
2686 textLine->replace(cursor.x, len, text.unicode(), text.length()); 2684 textLine->replace(cursor.x, len, text.unicode(), text.length());
2687 a->len += text.length(); 2685 a->len += text.length();
2688 2686
2689 buffer->changeLine(a->cursor.y); 2687 buffer->changeLine(a->cursor.y);
2690 updateMaxLength(textLine); 2688 updateMaxLength(textLine);
2691 tagLine(a->cursor.y); 2689 tagLine(a->cursor.y);
2692} 2690}
2693 2691
2694void KateDocument::recordEnd(VConfig &c) { 2692void KateDocument::recordEnd(VConfig &c) {
2695 recordEnd(c.view, c.cursor, c.flags); 2693 recordEnd(c.view, c.cursor, c.flags);
2696} 2694}
2697 2695
2698void KateDocument::recordEnd(KateView *view, PointStruc &cursor, int flags) { 2696void KateDocument::recordEnd(KateView *view, PointStruc &cursor, int flags) {
2699 KateActionGroup *g; 2697 KateActionGroup *g;
2700 2698
2701 // clear selection if option "persistent selections" is off 2699 // clear selection if option "persistent selections" is off
2702// if (!(flags & cfPersistent)) deselectAll(); 2700// if (!(flags & cfPersistent)) deselectAll();
2703 2701
2704 g = undoList.getLast(); 2702 g = undoList.getLast();
2705 if (g->action == 0L) { 2703 if (g->action == 0L) {
2706 // no action has been done: remove empty undo record 2704 // no action has been done: remove empty undo record
2707 undoList.removeLast(); 2705 undoList.removeLast();
2708 return; 2706 return;
2709 } 2707 }
2710 // store end cursor position for redo 2708 // store end cursor position for redo
2711 g->end = cursor; 2709 g->end = cursor;
2712 currentUndo = undoList.count(); 2710 currentUndo = undoList.count();
2713 2711
2714 if (tagStart <= tagEnd) { 2712 if (tagStart <= tagEnd) {
2715 optimizeSelection(); 2713 optimizeSelection();
2716 updateLines(tagStart, tagEnd, flags, cursor.y); 2714 updateLines(tagStart, tagEnd, flags, cursor.y);
2717 setModified(true); 2715 setModified(true);
2718 } 2716 }
2719 2717
2720 view->updateCursor(cursor, flags); 2718 view->updateCursor(cursor, flags);
2721 2719
2722// newUndo(); 2720// newUndo();
2723/* 2721/*
2724 undoCount++; 2722 undoCount++;
2725 // we limit the number of individual undo operations for sanity - is 1K reasonable? 2723 // we limit the number of individual undo operations for sanity - is 1K reasonable?
2726 // this is also where we handle non-group undo preference 2724 // this is also where we handle non-group undo preference
2727 // if the undo type is singlular, we always finish it now 2725 // if the undo type is singlular, we always finish it now
2728 if ( undoType == KateActionGroup::ugPaste || 2726 if ( undoType == KateActionGroup::ugPaste ||
2729 undoType == KateActionGroup::ugDelBlock || 2727 undoType == KateActionGroup::ugDelBlock ||
2730 undoType > 1000 || 2728 undoType > 1000 ||
2731 undoCount > 1024 || !(flags & cfGroupUndo) ) { 2729 undoCount > 1024 || !(flags & cfGroupUndo) ) {
2732printf("recordend %d %d\n", undoType, undoCount); 2730printf("recordend %d %d\n", undoType, undoCount);
2733 recordReset(); 2731 recordReset();
2734 } 2732 }
2735*/ 2733*/
2736 2734
2737 // this should keep the flood of signals down a little... 2735 // this should keep the flood of signals down a little...
2738 if (undoCount == 0) newUndo(); 2736 if (undoCount == 0) newUndo();
2739 emit textChanged(); 2737 emit textChanged();
2740} 2738}
2741/* 2739/*
2742void KateDocument::recordReset() 2740void KateDocument::recordReset()
2743{ 2741{
2744 if (pseudoModal) 2742 if (pseudoModal)
2745 return; 2743 return;
2746 2744
2747 // forces the next call of recordStart() to begin a new undo group 2745 // forces the next call of recordStart() to begin a new undo group
2748 // not used in normal editing, but used by markFound(), etc. 2746 // not used in normal editing, but used by markFound(), etc.
2749 undoType = KateActionGroup::ugNone; 2747 undoType = KateActionGroup::ugNone;
2750 undoCount = 0; 2748 undoCount = 0;
2751 undoView = NULL; 2749 undoView = NULL;
2752 undoReported = false; 2750 undoReported = false;
2753printf("recordreset\n"); 2751printf("recordreset\n");
2754} 2752}
2755*/ 2753*/
2756 2754
2757/* 2755/*
2758void KateDocument::recordDel(PointStruc &cursor, TextLine::Ptr &textLine, int l) { 2756void KateDocument::recordDel(PointStruc &cursor, TextLine::Ptr &textLine, int l) {
2759 int len; 2757 int len;
2760 2758
2761 len = textLine->length() - cursor.x; 2759 len = textLine->length() - cursor.x;
2762 if (len > l) len = l; 2760 if (len > l) len = l;
2763 if (len > 0) { 2761 if (len > 0) {
2764 insertUndo(new KateAction(KateAction::replace,cursor,&textLine->getText()[cursor.x],len)); 2762 insertUndo(new KateAction(KateAction::replace,cursor,&textLine->getText()[cursor.x],len));
2765 } 2763 }
2766} 2764}
2767*/ 2765*/
2768 2766
2769 2767
2770void KateDocument::doActionGroup(KateActionGroup *g, int flags, bool undo) { 2768void KateDocument::doActionGroup(KateActionGroup *g, int flags, bool undo) {
2771 KateAction *a, *next; 2769 KateAction *a, *next;
2772 2770
2773 setPseudoModal(0L); 2771 setPseudoModal(0L);
2774 if (!(flags & KateView::cfPersistent)) deselectAll(); 2772 if (!(flags & KateView::cfPersistent)) deselectAll();
2775 tagEnd = 0; 2773 tagEnd = 0;
2776 tagStart = 0xffffff; 2774 tagStart = 0xffffff;
2777 2775
2778 a = g->action; 2776 a = g->action;
2779 g->action = 0L; 2777 g->action = 0L;
2780 while (a) { 2778 while (a) {
2781 doAction(a); 2779 doAction(a);
2782 next = a->next; 2780 next = a->next;
2783 g->insertAction(a); 2781 g->insertAction(a);
2784 a = next; 2782 a = next;
2785 } 2783 }
2786 optimizeSelection(); 2784 optimizeSelection();
2787 if (tagStart <= tagEnd) updateLines(tagStart, tagEnd, flags); 2785 if (tagStart <= tagEnd) updateLines(tagStart, tagEnd, flags);
2788 2786
2789 // the undo/redo functions set undo to true, all others should leave it 2787 // the undo/redo functions set undo to true, all others should leave it
2790 // alone (default) 2788 // alone (default)
2791 if (!undo) { 2789 if (!undo) {
2792 setModified(true); 2790 setModified(true);
2793 newUndo(); 2791 newUndo();
2794 } 2792 }
2795} 2793}
2796 2794
2797int KateDocument::nextUndoType() 2795int KateDocument::nextUndoType()
2798{ 2796{
2799 KateActionGroup *g; 2797 KateActionGroup *g;
2800 2798
2801 if (currentUndo <= 0) return KateActionGroup::ugNone; 2799 if (currentUndo <= 0) return KateActionGroup::ugNone;
2802 g = undoList.at(currentUndo - 1); 2800 g = undoList.at(currentUndo - 1);
2803 return g->undoType; 2801 return g->undoType;
2804} 2802}
2805 2803
2806int KateDocument::nextRedoType() 2804int KateDocument::nextRedoType()
2807{ 2805{
2808 KateActionGroup *g; 2806 KateActionGroup *g;
2809 2807
2810 if (currentUndo >= (int) undoList.count()) return KateActionGroup::ugNone; 2808 if (currentUndo >= (int) undoList.count()) return KateActionGroup::ugNone;
2811 g = undoList.at(currentUndo); 2809 g = undoList.at(currentUndo);
2812// if (!g) return KateActionGroup::ugNone; 2810// if (!g) return KateActionGroup::ugNone;
2813 return g->undoType; 2811 return g->undoType;
2814} 2812}
2815 2813
2816void KateDocument::undoTypeList(QValueList<int> &lst) 2814void KateDocument::undoTypeList(QValueList<int> &lst)
2817{ 2815{
2818 lst.clear(); 2816 lst.clear();
2819 for (int i = currentUndo-1; i>=0 ;i--) 2817 for (int i = currentUndo-1; i>=0 ;i--)
2820 lst.append(undoList.at(i)->undoType); 2818 lst.append(undoList.at(i)->undoType);
2821} 2819}
2822 2820
2823void KateDocument::redoTypeList(QValueList<int> &lst) 2821void KateDocument::redoTypeList(QValueList<int> &lst)
2824{ 2822{
2825 lst.clear(); 2823 lst.clear();
2826 for (int i = currentUndo+1; i<(int)undoList.count(); i++) 2824 for (int i = currentUndo+1; i<(int)undoList.count(); i++)
2827 lst.append(undoList.at(i)->undoType); 2825 lst.append(undoList.at(i)->undoType);
2828} 2826}
2829 2827
2830void KateDocument::undo(VConfig &c, int count) { 2828void KateDocument::undo(VConfig &c, int count) {
2831 KateActionGroup *g = 0L; 2829 KateActionGroup *g = 0L;
2832 int num; 2830 int num;
2833 bool needUpdate = false; // don't update the cursor until completely done 2831 bool needUpdate = false; // don't update the cursor until completely done
2834 2832
2835 if (count <= 0) return; 2833 if (count <= 0) return;
2836 2834
2837 for (num = 0 ; num < count ; num++) { 2835 for (num = 0 ; num < count ; num++) {
2838 if (currentUndo <= 0) break; 2836 if (currentUndo <= 0) break;
2839 currentUndo--; 2837 currentUndo--;
2840 g = undoList.at(currentUndo); 2838 g = undoList.at(currentUndo);
2841 doActionGroup(g, c.flags, true); // do not setModified() or newUndo() 2839 doActionGroup(g, c.flags, true); // do not setModified() or newUndo()
2842 needUpdate = true; 2840 needUpdate = true;
2843 2841
2844// if (num == 0) recordReset(); 2842// if (num == 0) recordReset();
2845 } 2843 }
2846 2844
2847 if (needUpdate) { 2845 if (needUpdate) {
2848 // since we told doActionGroup() not to do this stuff, we need to do it now 2846 // since we told doActionGroup() not to do this stuff, we need to do it now
2849 c.view->updateCursor(g->start); 2847 c.view->updateCursor(g->start);
2850 setModified(true); 2848 setModified(true);
2851 newUndo(); 2849 newUndo();
2852 } 2850 }
2853} 2851}
2854 2852
2855void KateDocument::redo(VConfig &c, int count) { 2853void KateDocument::redo(VConfig &c, int count) {
2856 KateActionGroup *g = 0L; 2854 KateActionGroup *g = 0L;
2857 int num; 2855 int num;
2858 bool needUpdate = false; // don't update the cursor until completely done 2856 bool needUpdate = false; // don't update the cursor until completely done
2859 2857
2860 if (count <= 0) return; 2858 if (count <= 0) return;
2861 2859
2862 for (num = 0 ; num < count ; num++) { 2860 for (num = 0 ; num < count ; num++) {
2863 if (currentUndo+1 > (int)undoList.count()) break; 2861 if (currentUndo+1 > (int)undoList.count()) break;
2864 g = undoList.at(currentUndo); 2862 g = undoList.at(currentUndo);
2865 currentUndo++; 2863 currentUndo++;
2866 doActionGroup(g, c.flags, true); // do not setModified() or newUndo() 2864 doActionGroup(g, c.flags, true); // do not setModified() or newUndo()
2867 needUpdate = true; 2865 needUpdate = true;
2868 2866
2869// if (num == 0) recordReset(); 2867// if (num == 0) recordReset();
2870 } 2868 }
2871 2869
2872 if (needUpdate) { 2870 if (needUpdate) {
2873 // since we told doActionGroup() not to do this stuff, we need to do it now 2871 // since we told doActionGroup() not to do this stuff, we need to do it now
2874 c.view->updateCursor(g->end); 2872 c.view->updateCursor(g->end);
2875 setModified(true); 2873 setModified(true);
2876 newUndo(); 2874 newUndo();
2877 } 2875 }
2878} 2876}
2879 2877
2880void KateDocument::clearRedo() { 2878void KateDocument::clearRedo() {
2881 // disable redos 2879 // disable redos
2882 // this was added as an assist to the spell checker 2880 // this was added as an assist to the spell checker
2883 bool deleted = false; 2881 bool deleted = false;
2884 2882
2885 while ((int) undoList.count() > currentUndo) { 2883 while ((int) undoList.count() > currentUndo) {
2886 deleted = true; 2884 deleted = true;
2887 undoList.removeLast(); 2885 undoList.removeLast();
2888 } 2886 }
2889 2887
2890 if (deleted) newUndo(); 2888 if (deleted) newUndo();
2891} 2889}
2892 2890
2893void KateDocument::setUndoSteps(int steps) { 2891void KateDocument::setUndoSteps(int steps) {
2894 if (steps < 5) steps = 5; 2892 if (steps < 5) steps = 5;
2895 undoSteps = steps; 2893 undoSteps = steps;
2896} 2894}
2897 2895
2898void KateDocument::setPseudoModal(QWidget *w) { 2896void KateDocument::setPseudoModal(QWidget *w) {
2899// QWidget *old = pseudoModal; 2897// QWidget *old = pseudoModal;
2900 2898
2901 // (glenebob) 2899 // (glenebob)
2902 // this is a temporary hack to make the spell checker work a little 2900 // this is a temporary hack to make the spell checker work a little
2903 // better - as kspell progresses, this sort of thing should become 2901 // better - as kspell progresses, this sort of thing should become
2904 // obsolete or worked around more cleanly 2902 // obsolete or worked around more cleanly
2905 // this is relied upon *only* by the spell-check code 2903 // this is relied upon *only* by the spell-check code
2906 if (pseudoModal && pseudoModal != (QWidget*)1L) 2904 if (pseudoModal && pseudoModal != (QWidget*)1L)
2907 delete pseudoModal; 2905 delete pseudoModal;
2908 2906
2909// pseudoModal = 0L; 2907// pseudoModal = 0L;
2910// if (old || w) recordReset(); 2908// if (old || w) recordReset();
2911 2909
2912 pseudoModal = w; 2910 pseudoModal = w;
2913} 2911}
2914 2912
2915 2913
2916void KateDocument::newBracketMark(PointStruc &cursor, BracketMark &bm) 2914void KateDocument::newBracketMark(PointStruc &cursor, BracketMark &bm)
2917{ 2915{
2918 TextLine::Ptr textLine; 2916 TextLine::Ptr textLine;
2919 int x, line, count, attr; 2917 int x, line, count, attr;
2920 QChar bracket, opposite, ch; 2918 QChar bracket, opposite, ch;
2921 Attribute *a; 2919 Attribute *a;
2922 2920
2923 bm.eXPos = -1; //mark bracked mark as invalid 2921 bm.eXPos = -1; //mark bracked mark as invalid
2924 x = cursor.x -1; // -1 to look at left side of cursor 2922 x = cursor.x -1; // -1 to look at left side of cursor
2925 if (x < 0) return; 2923 if (x < 0) return;
2926 line = cursor.y; //current line 2924 line = cursor.y; //current line
2927 count = 0; //bracket counter for nested brackets 2925 count = 0; //bracket counter for nested brackets
2928 2926
2929 textLine = getTextLine(line); 2927 textLine = getTextLine(line);
2930 if (!textLine) return; 2928 if (!textLine) return;
2931 2929
2932 bracket = textLine->getChar(x); 2930 bracket = textLine->getChar(x);
2933 attr = textLine->getAttr(x); 2931 attr = textLine->getAttr(x);
2934 2932
2935 if (bracket == '(' || bracket == '[' || bracket == '{') 2933 if (bracket == '(' || bracket == '[' || bracket == '{')
2936 { 2934 {
2937 //get opposite bracket 2935 //get opposite bracket
2938 opposite = ')'; 2936 opposite = ')';
2939 if (bracket == '[') opposite = ']'; 2937 if (bracket == '[') opposite = ']';
2940 if (bracket == '{') opposite = '}'; 2938 if (bracket == '{') opposite = '}';
2941 //get attribute of bracket (opposite bracket must have the same attribute) 2939 //get attribute of bracket (opposite bracket must have the same attribute)
2942 x++; 2940 x++;
2943 while (line - cursor.y < 40) { 2941 while (line - cursor.y < 40) {
2944 //go to next line on end of line 2942 //go to next line on end of line
2945 while (x >= (int) textLine->length()) { 2943 while (x >= (int) textLine->length()) {
2946 line++; 2944 line++;
2947 if (line > lastLine()) return; 2945 if (line > lastLine()) return;
2948 textLine = getTextLine(line); 2946 textLine = getTextLine(line);
2949 x = 0; 2947 x = 0;
2950 } 2948 }
2951 if (textLine->getAttr(x) == attr) { 2949 if (textLine->getAttr(x) == attr) {
2952 //try to find opposite bracked 2950 //try to find opposite bracked
2953 ch = textLine->getChar(x); 2951 ch = textLine->getChar(x);
2954 if (ch == bracket) count++; //same bracket : increase counter 2952 if (ch == bracket) count++; //same bracket : increase counter
2955 if (ch == opposite) { 2953 if (ch == opposite) {
2956 count--; 2954 count--;
2957 if (count < 0) goto found; 2955 if (count < 0) goto found;
2958 } 2956 }
2959 } 2957 }
2960 x++; 2958 x++;
2961 } 2959 }
2962 } 2960 }
2963 else if (bracket == ')' || bracket == ']' || bracket == '}') 2961 else if (bracket == ')' || bracket == ']' || bracket == '}')
2964 { 2962 {
2965 opposite = '('; 2963 opposite = '(';
2966 if (bracket == ']') opposite = '['; 2964 if (bracket == ']') opposite = '[';
2967 if (bracket == '}') opposite = '{'; 2965 if (bracket == '}') opposite = '{';
2968 x--; 2966 x--;
2969 while (cursor.y - line < 20) { 2967 while (cursor.y - line < 20) {
2970 2968
2971 while (x < 0) { 2969 while (x < 0) {
2972 line--; 2970 line--;
2973 if (line < 0) return; 2971 if (line < 0) return;
2974 textLine = getTextLine(line); 2972 textLine = getTextLine(line);
2975 x = textLine->length() -1; 2973 x = textLine->length() -1;
2976 } 2974 }
2977 if (textLine->getAttr(x) == attr) { 2975 if (textLine->getAttr(x) == attr) {
2978 ch = textLine->getChar(x); 2976 ch = textLine->getChar(x);
2979 if (ch == bracket) count++; 2977 if (ch == bracket) count++;
2980 if (ch == opposite) { 2978 if (ch == opposite) {
2981 count--; 2979 count--;
2982 if (count < 0) goto found; 2980 if (count < 0) goto found;
2983 } 2981 }
2984 } 2982 }
2985 x--; 2983 x--;
2986 } 2984 }
2987 } 2985 }
2988 return; 2986 return;
2989 2987
2990found: 2988found:
2991 //cursor position of opposite bracket 2989 //cursor position of opposite bracket
2992 bm.cursor.x = x; 2990 bm.cursor.x = x;
2993 bm.cursor.y = line; 2991 bm.cursor.y = line;
2994 //x position (start and end) of related bracket 2992 //x position (start and end) of related bracket
2995 bm.sXPos = textWidth(textLine, x); 2993 bm.sXPos = textWidth(textLine, x);
2996 a = &m_attribs[attr]; 2994 a = &m_attribs[attr];
2997 2995
2998 if (a->bold && a->italic) 2996 if (a->bold && a->italic)
2999 bm.eXPos = bm.sXPos + myFontMetricsBI.width(bracket); 2997 bm.eXPos = bm.sXPos + myFontMetricsBI.width(bracket);
3000 else if (a->bold) 2998 else if (a->bold)
3001 bm.eXPos = bm.sXPos + myFontMetricsBold.width(bracket); 2999 bm.eXPos = bm.sXPos + myFontMetricsBold.width(bracket);
3002 else if (a->italic) 3000 else if (a->italic)
3003 bm.eXPos = bm.sXPos + myFontMetricsItalic.width(bracket); 3001 bm.eXPos = bm.sXPos + myFontMetricsItalic.width(bracket);
3004 else 3002 else
3005 bm.eXPos = bm.sXPos + myFontMetrics.width(bracket); 3003 bm.eXPos = bm.sXPos + myFontMetrics.width(bracket);
3006} 3004}
3007 3005
3008void KateDocument::clipboardChanged() { //slot 3006void KateDocument::clipboardChanged() { //slot
3009//#if defined(_WS_X11_) 3007//#if defined(_WS_X11_)
3010 if (m_singleSelection) { 3008 if (m_singleSelection) {
3011 disconnect(QApplication::clipboard(), SIGNAL(dataChanged()), 3009 disconnect(QApplication::clipboard(), SIGNAL(dataChanged()),
3012 this, SLOT(clipboardChanged())); 3010 this, SLOT(clipboardChanged()));
3013 deselectAll(); 3011 deselectAll();
3014 updateViews(); 3012 updateViews();
3015 } 3013 }
3016//#endif 3014//#endif
3017} 3015}
3018 3016
3019#if 0 3017#if 0
3020void KateDocument::guiActivateEvent( KParts::GUIActivateEvent *ev ) 3018void KateDocument::guiActivateEvent( KParts::GUIActivateEvent *ev )
3021{ 3019{
3022 KParts::ReadWritePart::guiActivateEvent( ev ); 3020 KParts::ReadWritePart::guiActivateEvent( ev );
3023 if ( ev->activated() ) 3021 if ( ev->activated() )
3024 emit selectionChanged(); 3022 emit selectionChanged();
3025} 3023}
3026#endif 3024#endif
3027 3025
3028void KateDocument::setDocName (QString docName) 3026void KateDocument::setDocName (QString docName)
3029{ 3027{
3030 myDocName = docName; 3028 myDocName = docName;
3031 emit nameChanged (this); 3029 emit nameChanged (this);
3032} 3030}
3033 3031
3034void KateDocument::setDocFile (QString docFile) 3032void KateDocument::setDocFile (QString docFile)
3035{ 3033{
3036 m_file = docFile; 3034 m_file = docFile;
3037 emit fileNameChanged (); 3035 emit fileNameChanged ();
3038} 3036}
3039 3037
3040void KateDocument::setMTime() 3038void KateDocument::setMTime()
3041{ 3039{
3042 if (fileInfo && !fileInfo->fileName().isEmpty()) { 3040 if (fileInfo && !fileInfo->fileName().isEmpty()) {
3043 fileInfo->refresh(); 3041 fileInfo->refresh();
3044 mTime = fileInfo->lastModified(); 3042 mTime = fileInfo->lastModified();
3045 } 3043 }
3046} 3044}
3047 3045
3048void KateDocument::isModOnHD(bool forceReload) 3046void KateDocument::isModOnHD(bool forceReload)
3049{ 3047{
3050 if (fileInfo && !fileInfo->fileName().isEmpty()) { 3048 if (fileInfo && !fileInfo->fileName().isEmpty()) {
3051 fileInfo->refresh(); 3049 fileInfo->refresh();
3052 if (fileInfo->lastModified() > mTime) { 3050 if (fileInfo->lastModified() > mTime) {
3053 if ( forceReload || 3051 if ( forceReload ||
3054 (KMessageBox::warningContinueCancel(0, 3052 (KMessageBox::warningContinueCancel(0,
3055 (i18n("The file %1 has changed on disk.\nDo you want to reload it?\n\nIf you cancel you will lose these changes next time you save this file")).arg(m_url), 3053 (i18n("The file %1 has changed on disk.\nDo you want to reload it?\n\nIf you cancel you will lose these changes next time you save this file")).arg(m_url),
3056 i18n("File has changed on Disk"), 3054 i18n("File has changed on Disk"),
3057 i18n("Yes") ) == KMessageBox::Continue) 3055 i18n("Yes") ) == KMessageBox::Continue)
3058 ) 3056 )
3059 reloadFile(); 3057 reloadFile();
3060 else 3058 else
3061 setMTime(); 3059 setMTime();
3062 } 3060 }
3063 } 3061 }
3064} 3062}
3065 3063
3066void KateDocument::reloadFile() 3064void KateDocument::reloadFile()
3067{ 3065{
3068#warning fixme 3066#warning fixme
3069#if 0 3067#if 0
3070 if (fileInfo && !fileInfo->fileName().isEmpty()) { 3068 if (fileInfo && !fileInfo->fileName().isEmpty()) {
3071 KateDocument::openFile(); 3069 KateDocument::openFile();
3072 setMTime(); 3070 setMTime();
3073 } 3071 }
3074#endif 3072#endif
3075} 3073}
3076 3074
3077void KateDocument::slotModChanged() 3075void KateDocument::slotModChanged()
3078{ 3076{
3079 emit modStateChanged (this); 3077 emit modStateChanged (this);
3080} 3078}
3081 3079
3082QList<Kate::Mark> KateDocument::marks () 3080QList<Kate::Mark> KateDocument::marks ()
3083{ 3081{
3084 QList<Kate::Mark> list; 3082 QList<Kate::Mark> list;
3085 TextLine::Ptr line; 3083 TextLine::Ptr line;
3086 3084
3087 for (int i=0; i < numLines(); i++) 3085 for (int i=0; i < numLines(); i++)
3088 { 3086 {
3089 line = getTextLine(i); 3087 line = getTextLine(i);
3090 if (line->mark() != 0) 3088 if (line->mark() != 0)
3091 { 3089 {
3092 Kate::Mark *mark=new Kate::Mark; 3090 Kate::Mark *mark=new Kate::Mark;
3093 mark->line = i; 3091 mark->line = i;
3094 mark->type = line->mark(); 3092 mark->type = line->mark();
3095 list.append (mark); 3093 list.append (mark);
3096 } 3094 }
3097 } 3095 }
3098 3096
3099 return list; 3097 return list;
3100} 3098}
3101 3099
3102void KateDocument::flush () 3100void KateDocument::flush ()
3103{ 3101{
3104 if (isReadOnly()) 3102 if (isReadOnly())
3105 return; 3103 return;
3106 3104
3107 m_url = QString::null; 3105 m_url = QString::null;
3108 fileInfo->setFile (QString()); 3106 fileInfo->setFile (QString());
3109 setMTime(); 3107 setMTime();
3110 3108
3111 clear(); 3109 clear();
3112 updateViews(); 3110 updateViews();
3113 3111
3114 emit fileNameChanged (); 3112 emit fileNameChanged ();
3115} 3113}
3116 3114
3117void KateDocument::open (const QString &name) 3115void KateDocument::open (const QString &name)
3118{ 3116{
3119 openURL (name); 3117 openURL (name);
3120} 3118}
3121 3119
3122void KateDocument::wrapText (uint col) 3120void KateDocument::wrapText (uint col)
3123{ 3121{
3124 int line = 0; 3122 int line = 0;
3125 int z = 0; 3123 int z = 0;
3126 3124
3127 while(true) 3125 while(true)
3128 { 3126 {
3129 TextLine::Ptr l = getTextLine(line); 3127 TextLine::Ptr l = getTextLine(line);
3130 3128
3131 if (l->length() > col) 3129 if (l->length() > col)
3132 { 3130 {
3133 TextLine::Ptr tl = new TextLine(); 3131 TextLine::Ptr tl = new TextLine();
3134 buffer->insertLine(line+1,tl); 3132 buffer->insertLine(line+1,tl);
3135 const QChar *text = l->getText(); 3133 const QChar *text = l->getText();
3136 3134
3137 for (z=col; z>0; z--) 3135 for (z=col; z>0; z--)
3138 { 3136 {
3139 if (z < 1) break; 3137 if (z < 1) break;
3140 if (text[z].isSpace()) break; 3138 if (text[z].isSpace()) break;
3141 } 3139 }
3142 3140
3143 if (z < 1) z=col; 3141 if (z < 1) z=col;
3144 3142
3145 l->wrap (tl, z); 3143 l->wrap (tl, z);
3146 } 3144 }
3147 3145
3148 line++; 3146 line++;
3149 if (line >= numLines()) break; 3147 if (line >= numLines()) break;
3150 }; 3148 };
3151 3149
3152 newDocGeometry=true; 3150 newDocGeometry=true;
3153 updateLines(); 3151 updateLines();
3154 updateViews(); 3152 updateViews();
3155} 3153}
3156 3154
3157void KateDocument::setWordWrap (bool on) 3155void KateDocument::setWordWrap (bool on)
3158{ 3156{
3159 if (on != myWordWrap && on) 3157 if (on != myWordWrap && on)
3160 wrapText (myWordWrapAt); 3158 wrapText (myWordWrapAt);
3161 3159
3162 myWordWrap = on; 3160 myWordWrap = on;
3163} 3161}
3164 3162
3165void KateDocument::setWordWrapAt (uint col) 3163void KateDocument::setWordWrapAt (uint col)
3166{ 3164{
3167 if (myWordWrapAt != col && myWordWrap) 3165 if (myWordWrapAt != col && myWordWrap)
3168 wrapText (myWordWrapAt); 3166 wrapText (myWordWrapAt);
3169 3167
3170 myWordWrapAt = col; 3168 myWordWrapAt = col;
3171} 3169}
3172 3170
3173void KateDocument::applyWordWrap () 3171void KateDocument::applyWordWrap ()
3174{ 3172{
3175 wrapText (myWordWrapAt); 3173 wrapText (myWordWrapAt);
3176} 3174}
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*/
44QString KateConfig::configFilename(const QString& name, Domain d) 42QString 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*/
95KateConfig::KateConfig( const QString &name, Domain domain ) 93KateConfig::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
108KateConfig::KateConfig ( const QString &name, bool what ) 106KateConfig::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*/
121KateConfig::~KateConfig() 119KateConfig::~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*/
131bool KateConfig::hasKey( const QString &key ) const 129bool 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*/
148void KateConfig::setGroup( const QString &gname ) 146void 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*/
164void KateConfig::writeEntry( const QString &key, const char* value ) 162void 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*/
174void KateConfig::writeEntry( const QString &key, const QString &value ) 172void 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*/
195static QString encipher(const QString& plain) 193static 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
211static QString decipher(const QString& cipher) 209static 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*/
234void KateConfig::writeEntryCrypt( const QString &key, const QString &value ) 232void 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*/
252void KateConfig::writeEntry( const QString &key, int num ) 250void 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
259void KateConfig::writeEntry( const QString &key, unsigned int num ) 257void 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*/
273void KateConfig::writeEntry( const QString &key, bool b ) 271void 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*/
287void KateConfig::writeEntry( const QString &key, const QStringList &lst, const QChar &sep ) 285void 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
296void KateConfig::writeEntry( const QString &key, const QColor &val ) 294void 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
306void KateConfig::writeEntry( const QString &key, const QFont &val ) 304void 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
323void KateConfig::removeEntry( const QString &key ) 321void 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*/
355QString KateConfig::readEntry( const QString &key, const QString &deflt ) 353QString 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*/
378QString KateConfig::readEntryCrypt( const QString &key, const QString &deflt ) 376QString 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*/
399QString KateConfig::readEntryDirect( const QString &key, const QString &deflt ) 397QString 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*/
421int KateConfig::readNumEntry( const QString &key, int deflt ) 419int 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*/
439bool KateConfig::readBoolEntry( const QString &key, bool deflt ) 437bool 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*/
457QStringList KateConfig::readListEntry( const QString &key, const QChar &sep ) 455QStringList 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
466QColor KateConfig::readColorEntry( const QString &key, const QColor &def ) const 464QColor 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
475QFont KateConfig::readFontEntry( const QString &key, const QFont &def ) const 473QFont 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
484QValueList<int> KateConfig::readIntListEntry( const QString &key ) const 482QValueList<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*/
502void KateConfig::clearGroup() 500void 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*/
517void KateConfig::write( const QString &fn ) 515void 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*/
565bool KateConfig::isValid() const 563bool 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*/
573void KateConfig::read() 571void 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*/
610bool KateConfig::parse( const QString &l ) 608bool 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,2923 +1,2916 @@
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
89KateViewInternal::KateViewInternal(KateView *view, KateDocument *doc) : QWidget(view) 82KateViewInternal::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
141KateViewInternal::~KateViewInternal() 134KateViewInternal::~KateViewInternal()
142{ 135{
143 delete [] lineRanges; 136 delete [] lineRanges;
144 delete drawBuffer; 137 delete drawBuffer;
145} 138}
146 139
147 140
148void KateViewInternal::slotPreHighlightUpdate(long line) 141void 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
161void KateViewInternal::doCursorCommand(VConfig &c, int cmdNum) { 154void 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
215void KateViewInternal::doEditCommand(VConfig &c, int cmdNum) { 208void 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
283void KateViewInternal::cursorLeft(VConfig &c) { 276void 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
294void KateViewInternal::cursorRight(VConfig &c) { 287void 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
308void KateViewInternal::wordLeft(VConfig &c) { 301void 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
332void KateViewInternal::wordRight(VConfig &c) { 325void 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
358void KateViewInternal::home(VConfig &c) { 351void 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
373void KateViewInternal::end(VConfig &c) { 366void 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
380void KateViewInternal::cursorUp(VConfig &c) { 373void 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
388void KateViewInternal::cursorDown(VConfig &c) { 381void 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
403void KateViewInternal::scrollUp(VConfig &c) { 396void 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
416void KateViewInternal::scrollDown(VConfig &c) { 409void 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
428void KateViewInternal::topOfView(VConfig &c) { 421void 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
436void KateViewInternal::bottomOfView(VConfig &c) { 429void 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
446void KateViewInternal::pageUp(VConfig &c) { 439void 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
461void KateViewInternal::pageDown(VConfig &c) { 454void 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
478void KateViewInternal::top(VConfig &c) { 471void 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
488void KateViewInternal::bottom(VConfig &c) { 481void 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
498void KateViewInternal::top_home(VConfig &c) 491void 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
507void KateViewInternal::bottom_end(VConfig &c) { 500void 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
516void KateViewInternal::changeXPos(int p) { 509void 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
524void KateViewInternal::changeYPos(int p) { 517void 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
541void KateViewInternal::getVConfig(VConfig &c) { 534void 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
549void KateViewInternal::changeState(VConfig &c) { 542void 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
600void KateViewInternal::insLine(int line) { 593void 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
614void KateViewInternal::delLine(int line) { 607void 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
628void KateViewInternal::updateCursor() { 621void KateViewInternal::updateCursor() {
629 cOldXPos = cXPos = myDoc->textWidth(cursor); 622 cOldXPos = cXPos = myDoc->textWidth(cursor);
630} 623}
631 624
632 625
633void KateViewInternal::updateCursor(PointStruc &newCursor) { 626void KateViewInternal::updateCursor(PointStruc &newCursor) {
634 updateCursor(newCursor, myView->config()); 627 updateCursor(newCursor, myView->config());
635} 628}
636 629
637void KateViewInternal::updateCursor(PointStruc &newCursor, int flags) { 630void 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
657void KateViewInternal::clearDirtyCache(int height) { 650void 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
680void KateViewInternal::tagLines(int start, int end, int x1, int x2) { 673void 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
703void KateViewInternal::tagAll() { 696void KateViewInternal::tagAll() {
704 updateState = 3; 697 updateState = 3;
705} 698}
706 699
707void KateViewInternal::setPos(int x, int y) { 700void KateViewInternal::setPos(int x, int y) {
708 newXPos = x; 701 newXPos = x;
709 newYPos = y; 702 newYPos = y;
710} 703}
711 704
712void KateViewInternal::center() { 705void 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
718void KateViewInternal::updateView(int flags) { 711void 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
853 if (b) { 846 if (b) {
854 clearDirtyCache(h); 847 clearDirtyCache(h);
855 update(); 848 update();
856 } else { 849 } else {
857 if (dy) 850 if (dy)
858 leftBorder->scroll(0, dy); 851 leftBorder->scroll(0, dy);
859 if (updateState > 0) paintTextLines(oldXPos, oldYPos); 852 if (updateState > 0) paintTextLines(oldXPos, oldYPos);
860 clearDirtyCache(h); 853 clearDirtyCache(h);
861 854
862 if (dx || dy) { 855 if (dx || dy) {
863 scroll(dx,dy); 856 scroll(dx,dy);
864// kapp->syncX(); 857// kapp->syncX();
865// scroll2(dx - dx/2,dy - dy/2); 858// scroll2(dx - dx/2,dy - dy/2);
866// } else { 859// } else {
867 } 860 }
868 if (cursorOn) paintCursor(); 861 if (cursorOn) paintCursor();
869 if (bm.eXPos > bm.sXPos) paintBracketMark(); 862 if (bm.eXPos > bm.sXPos) paintBracketMark();
870 } 863 }
871 } 864 }
872 exposeCursor = false; 865 exposeCursor = false;
873// updateState = 0; 866// updateState = 0;
874} 867}
875 868
876 869
877void KateViewInternal::paintTextLines(int xPos, int yPos) { 870void KateViewInternal::paintTextLines(int xPos, int yPos) {
878// int xStart, xEnd; 871// int xStart, xEnd;
879 int line;//, z; 872 int line;//, z;
880 int h; 873 int h;
881 LineRange *r; 874 LineRange *r;
882 875
883 if (!drawBuffer) return; 876 if (!drawBuffer) return;
884 if (drawBuffer->isNull()) return; 877 if (drawBuffer->isNull()) return;
885 878
886 QPainter paint; 879 QPainter paint;
887 paint.begin(drawBuffer); 880 paint.begin(drawBuffer);
888 881
889 h = myDoc->fontHeight; 882 h = myDoc->fontHeight;
890 r = lineRanges; 883 r = lineRanges;
891 for (line = startLine; line <= endLine; line++) { 884 for (line = startLine; line <= endLine; line++) {
892 if (r->start < r->end) { 885 if (r->start < r->end) {
893//debug("painttextline %d %d %d", line, r->start, r->end); 886//debug("painttextline %d %d %d", line, r->start, r->end);
894 myDoc->paintTextLine(paint, line, r->start, r->end, myView->configFlags & KateView::cfShowTabs); 887 myDoc->paintTextLine(paint, line, r->start, r->end, myView->configFlags & KateView::cfShowTabs);
895 bitBlt(this, r->start - (xPos-2), line*h - yPos, drawBuffer, 0, 0, 888 bitBlt(this, r->start - (xPos-2), line*h - yPos, drawBuffer, 0, 0,
896 r->end - r->start, h); 889 r->end - r->start, h);
897 leftBorder->paintLine(line); 890 leftBorder->paintLine(line);
898 } 891 }
899 r++; 892 r++;
900 } 893 }
901 894
902 paint.end(); 895 paint.end();
903} 896}
904 897
905void KateViewInternal::paintCursor() { 898void KateViewInternal::paintCursor() {
906 int h, y, x; 899 int h, y, x;
907 static int cx = 0, cy = 0, ch = 0; 900 static int cx = 0, cy = 0, ch = 0;
908 901
909 h = myDoc->fontHeight; 902 h = myDoc->fontHeight;
910 y = h*cursor.y - yPos; 903 y = h*cursor.y - yPos;
911 x = cXPos - (xPos-2); 904 x = cXPos - (xPos-2);
912 905
913 if(myDoc->myFont != font()) setFont(myDoc->myFont); 906 if(myDoc->myFont != font()) setFont(myDoc->myFont);
914 if(cx != x || cy != y || ch != h){ 907 if(cx != x || cy != y || ch != h){
915 cx = x; 908 cx = x;
916 cy = y; 909 cy = y;
917 ch = h; 910 ch = h;
918 setMicroFocusHint(cx, cy, 0, ch - 2); 911 setMicroFocusHint(cx, cy, 0, ch - 2);
919 } 912 }
920 913
921 QPainter paint; 914 QPainter paint;
922 if (cursorOn) { 915 if (cursorOn) {
923 paint.begin(this); 916 paint.begin(this);
924 paint.setClipping(false); 917 paint.setClipping(false);
925 paint.setPen(myDoc->cursorCol(cursor.x,cursor.y)); 918 paint.setPen(myDoc->cursorCol(cursor.x,cursor.y));
926 919
927 h += y - 1; 920 h += y - 1;
928 paint.drawLine(x, y, x, h); 921 paint.drawLine(x, y, x, h);
929 922
930 paint.end(); 923 paint.end();
931 } else { if (drawBuffer && !drawBuffer->isNull()) { 924 } else { if (drawBuffer && !drawBuffer->isNull()) {
932 paint.begin(drawBuffer); 925 paint.begin(drawBuffer);
933 myDoc->paintTextLine(paint, cursor.y, cXPos - 2, cXPos + 3, myView->configFlags & KateView::cfShowTabs); 926 myDoc->paintTextLine(paint, cursor.y, cXPos - 2, cXPos + 3, myView->configFlags & KateView::cfShowTabs);
934 bitBlt(this,x - 2,y, drawBuffer, 0, 0, 5, h); 927 bitBlt(this,x - 2,y, drawBuffer, 0, 0, 5, h);
935 paint.end(); } 928 paint.end(); }
936 } 929 }
937 930
938} 931}
939 932
940void KateViewInternal::paintBracketMark() { 933void KateViewInternal::paintBracketMark() {
941 int y; 934 int y;
942 935
943 y = myDoc->fontHeight*(bm.cursor.y +1) - yPos -1; 936 y = myDoc->fontHeight*(bm.cursor.y +1) - yPos -1;
944 937
945 QPainter paint; 938 QPainter paint;
946 paint.begin(this); 939 paint.begin(this);
947 paint.setPen(myDoc->cursorCol(bm.cursor.x, bm.cursor.y)); 940 paint.setPen(myDoc->cursorCol(bm.cursor.x, bm.cursor.y));
948 941
949 paint.drawLine(bm.sXPos - (xPos-2), y, bm.eXPos - (xPos-2) -1, y); 942 paint.drawLine(bm.sXPos - (xPos-2), y, bm.eXPos - (xPos-2) -1, y);
950 paint.end(); 943 paint.end();
951} 944}
952 945
953void KateViewInternal::placeCursor(int x, int y, int flags) { 946void KateViewInternal::placeCursor(int x, int y, int flags) {
954 VConfig c; 947 VConfig c;
955 948
956 getVConfig(c); 949 getVConfig(c);
957 c.flags |= flags; 950 c.flags |= flags;
958 cursor.y = (yPos + y)/myDoc->fontHeight; 951 cursor.y = (yPos + y)/myDoc->fontHeight;
959 cXPos = cOldXPos = myDoc->textWidth(c.flags & KateView::cfWrapCursor, cursor,xPos-2 + x); 952 cXPos = cOldXPos = myDoc->textWidth(c.flags & KateView::cfWrapCursor, cursor,xPos-2 + x);
960 changeState(c); 953 changeState(c);
961} 954}
962 955
963// given physical coordinates, report whether the text there is selected 956// given physical coordinates, report whether the text there is selected
964bool KateViewInternal::isTargetSelected(int x, int y) { 957bool KateViewInternal::isTargetSelected(int x, int y) {
965 958
966 y = (yPos + y) / myDoc->fontHeight; 959 y = (yPos + y) / myDoc->fontHeight;
967 960
968 TextLine::Ptr line = myDoc->getTextLine(y); 961 TextLine::Ptr line = myDoc->getTextLine(y);
969 if (!line) 962 if (!line)
970 return false; 963 return false;
971 964
972 x = myDoc->textPos(line, x); 965 x = myDoc->textPos(line, x);
973 966
974 return line->isSelected(x); 967 return line->isSelected(x);
975} 968}
976 969
977void KateViewInternal::focusInEvent(QFocusEvent *) { 970void KateViewInternal::focusInEvent(QFocusEvent *) {
978// debug("got focus %d",cursorTimer); 971// debug("got focus %d",cursorTimer);
979 972
980 if (!cursorTimer) { 973 if (!cursorTimer) {
981 cursorTimer = startTimer(KApplication::cursorFlashTime() / 2); 974 cursorTimer = startTimer(KApplication::cursorFlashTime() / 2);
982 cursorOn = true; 975 cursorOn = true;
983 paintCursor(); 976 paintCursor();
984 } 977 }
985} 978}
986 979
987void KateViewInternal::focusOutEvent(QFocusEvent *) { 980void KateViewInternal::focusOutEvent(QFocusEvent *) {
988// debug("lost focus %d", cursorTimer); 981// debug("lost focus %d", cursorTimer);
989 982
990 if (cursorTimer) { 983 if (cursorTimer) {
991 killTimer(cursorTimer); 984 killTimer(cursorTimer);
992 cursorTimer = 0; 985 cursorTimer = 0;
993 } 986 }
994 987
995 if (cursorOn) { 988 if (cursorOn) {
996 cursorOn = false; 989 cursorOn = false;
997 paintCursor(); 990 paintCursor();
998 } 991 }
999} 992}
1000 993
1001void KateViewInternal::keyPressEvent(QKeyEvent *e) { 994void KateViewInternal::keyPressEvent(QKeyEvent *e) {
1002 VConfig c; 995 VConfig c;
1003// int ascii; 996// int ascii;
1004 997
1005/* if (e->state() & AltButton) { 998/* if (e->state() & AltButton) {
1006 e->ignore(); 999 e->ignore();
1007 return; 1000 return;
1008 }*/ 1001 }*/
1009// debug("ascii %i, key %i, state %i",e->ascii(), e->key(), e->state()); 1002// debug("ascii %i, key %i, state %i",e->ascii(), e->key(), e->state());
1010 1003
1011 getVConfig(c); 1004 getVConfig(c);
1012// ascii = e->ascii(); 1005// ascii = e->ascii();
1013 1006
1014 if (!myView->isReadOnly()) { 1007 if (!myView->isReadOnly()) {
1015 if (c.flags & KateView::cfTabIndents && myDoc->hasMarkedText()) { 1008 if (c.flags & KateView::cfTabIndents && myDoc->hasMarkedText()) {
1016 if (e->key() == Qt::Key_Tab) { 1009 if (e->key() == Qt::Key_Tab) {
1017 myDoc->indent(c); 1010 myDoc->indent(c);
1018 myDoc->updateViews(); 1011 myDoc->updateViews();
1019 return; 1012 return;
1020 } 1013 }
1021 if (e->key() == Qt::Key_Backtab) { 1014 if (e->key() == Qt::Key_Backtab) {
1022 myDoc->unIndent(c); 1015 myDoc->unIndent(c);
1023 myDoc->updateViews(); 1016 myDoc->updateViews();
1024 return; 1017 return;
1025 } 1018 }
1026 } 1019 }
1027 if ( !(e->state() & ControlButton ) && myDoc->insertChars(c, e->text())) { 1020 if ( !(e->state() & ControlButton ) && myDoc->insertChars(c, e->text())) {
1028 myDoc->updateViews(); 1021 myDoc->updateViews();
1029 e->accept(); 1022 e->accept();
1030 return; 1023 return;
1031 } 1024 }
1032 } 1025 }
1033 e->ignore(); 1026 e->ignore();
1034} 1027}
1035 1028
1036void KateViewInternal::mousePressEvent(QMouseEvent *e) { 1029void KateViewInternal::mousePressEvent(QMouseEvent *e) {
1037 1030
1038 if (e->button() == LeftButton) { 1031 if (e->button() == LeftButton) {
1039 1032
1040 int flags; 1033 int flags;
1041 1034
1042 flags = 0; 1035 flags = 0;
1043 if (e->state() & ShiftButton) { 1036 if (e->state() & ShiftButton) {
1044 flags |= KateView::cfMark; 1037 flags |= KateView::cfMark;
1045 if (e->state() & ControlButton) flags |= KateView::cfMark | KateView::cfKeepSelection; 1038 if (e->state() & ControlButton) flags |= KateView::cfMark | KateView::cfKeepSelection;
1046 } 1039 }
1047 placeCursor(e->x(), e->y(), flags); 1040 placeCursor(e->x(), e->y(), flags);
1048 scrollX = 0; 1041 scrollX = 0;
1049 scrollY = 0; 1042 scrollY = 0;
1050 if (!scrollTimer) scrollTimer = startTimer(50); 1043 if (!scrollTimer) scrollTimer = startTimer(50);
1051 myDoc->updateViews(); 1044 myDoc->updateViews();
1052 } 1045 }
1053 if (e->button() == MidButton) { 1046 if (e->button() == MidButton) {
1054 placeCursor(e->x(), e->y()); 1047 placeCursor(e->x(), e->y());
1055 if (! myView->isReadOnly()) 1048 if (! myView->isReadOnly())
1056 myView->paste(); 1049 myView->paste();
1057 } 1050 }
1058 if (myView->rmbMenu && e->button() == RightButton) { 1051 if (myView->rmbMenu && e->button() == RightButton) {
1059 myView->rmbMenu->popup(mapToGlobal(e->pos())); 1052 myView->rmbMenu->popup(mapToGlobal(e->pos()));
1060 } 1053 }
1061 myView->mousePressEvent(e); // this doesn't do anything, does it? 1054 myView->mousePressEvent(e); // this doesn't do anything, does it?
1062 // it does :-), we need this for KDevelop, so please don't uncomment it again -Sandy 1055 // it does :-), we need this for KDevelop, so please don't uncomment it again -Sandy
1063} 1056}
1064 1057
1065void KateViewInternal::mouseDoubleClickEvent(QMouseEvent *e) { 1058void KateViewInternal::mouseDoubleClickEvent(QMouseEvent *e) {
1066 1059
1067 if (e->button() == LeftButton) { 1060 if (e->button() == LeftButton) {
1068 VConfig c; 1061 VConfig c;
1069 getVConfig(c); 1062 getVConfig(c);
1070 myDoc->selectWord(c.cursor, c.flags); 1063 myDoc->selectWord(c.cursor, c.flags);
1071 myDoc->updateViews(); 1064 myDoc->updateViews();
1072 } 1065 }
1073} 1066}
1074 1067
1075void KateViewInternal::mouseReleaseEvent(QMouseEvent *e) { 1068void KateViewInternal::mouseReleaseEvent(QMouseEvent *e) {
1076 1069
1077 if (e->button() == LeftButton) { 1070 if (e->button() == LeftButton) {
1078 if (myView->config() & KateView::cfMouseAutoCopy) myView->copy(); 1071 if (myView->config() & KateView::cfMouseAutoCopy) myView->copy();
1079 killTimer(scrollTimer); 1072 killTimer(scrollTimer);
1080 scrollTimer = 0; 1073 scrollTimer = 0;
1081 } 1074 }
1082} 1075}
1083 1076
1084void KateViewInternal::mouseMoveEvent(QMouseEvent *e) { 1077void KateViewInternal::mouseMoveEvent(QMouseEvent *e) {
1085 1078
1086 if (e->state() & LeftButton) { 1079 if (e->state() & LeftButton) {
1087 int flags; 1080 int flags;
1088 int d; 1081 int d;
1089 int x = e->x(), 1082 int x = e->x(),
1090 y = e->y(); 1083 y = e->y();
1091 1084
1092 mouseX = e->x(); 1085 mouseX = e->x();
1093 mouseY = e->y(); 1086 mouseY = e->y();
1094 scrollX = 0; 1087 scrollX = 0;
1095 scrollY = 0; 1088 scrollY = 0;
1096 d = myDoc->fontHeight; 1089 d = myDoc->fontHeight;
1097 if (mouseX < 0) { 1090 if (mouseX < 0) {
1098 mouseX = 0; 1091 mouseX = 0;
1099 scrollX = -d; 1092 scrollX = -d;
1100 } 1093 }
1101 if (mouseX > width()) { 1094 if (mouseX > width()) {
1102 mouseX = width(); 1095 mouseX = width();
1103 scrollX = d; 1096 scrollX = d;
1104 } 1097 }
1105 if (mouseY < 0) { 1098 if (mouseY < 0) {
1106 mouseY = 0; 1099 mouseY = 0;
1107 scrollY = -d; 1100 scrollY = -d;
1108 } 1101 }
1109 if (mouseY > height()) { 1102 if (mouseY > height()) {
1110 mouseY = height(); 1103 mouseY = height();
1111 scrollY = d; 1104 scrollY = d;
1112 } 1105 }
1113//debug("modifiers %d", ((KGuiCmdApp *) kapp)->getModifiers()); 1106//debug("modifiers %d", ((KGuiCmdApp *) kapp)->getModifiers());
1114 flags = KateView::cfMark; 1107 flags = KateView::cfMark;
1115 if (e->state() & ControlButton) flags |= KateView::cfKeepSelection; 1108 if (e->state() & ControlButton) flags |= KateView::cfKeepSelection;
1116 placeCursor(mouseX, mouseY, flags); 1109 placeCursor(mouseX, mouseY, flags);
1117 myDoc->updateViews(/*ufNoScroll*/); 1110 myDoc->updateViews(/*ufNoScroll*/);
1118 } 1111 }
1119} 1112}
1120 1113
1121 1114
1122 1115
1123void KateViewInternal::wheelEvent( QWheelEvent *e ) 1116void KateViewInternal::wheelEvent( QWheelEvent *e )
1124{ 1117{
1125 if( yScroll->isVisible() == true ) 1118 if( yScroll->isVisible() == true )
1126 { 1119 {
1127 QApplication::sendEvent( yScroll, e ); 1120 QApplication::sendEvent( yScroll, e );
1128 } 1121 }
1129} 1122}
1130 1123
1131 1124
1132 1125
1133void KateViewInternal::paintEvent(QPaintEvent *e) { 1126void KateViewInternal::paintEvent(QPaintEvent *e) {
1134 int xStart, xEnd; 1127 int xStart, xEnd;
1135 int h; 1128 int h;
1136 int line, y, yEnd; 1129 int line, y, yEnd;
1137 1130
1138 QRect updateR = e->rect(); 1131 QRect updateR = e->rect();
1139 1132
1140 if (!drawBuffer) return; 1133 if (!drawBuffer) return;
1141 if (drawBuffer->isNull()) return; 1134 if (drawBuffer->isNull()) return;
1142 1135
1143 QPainter paint; 1136 QPainter paint;
1144 paint.begin(drawBuffer); 1137 paint.begin(drawBuffer);
1145 1138
1146 xStart = xPos-2 + updateR.x(); 1139 xStart = xPos-2 + updateR.x();
1147 xEnd = xStart + updateR.width(); 1140 xEnd = xStart + updateR.width();
1148 1141
1149 h = myDoc->fontHeight; 1142 h = myDoc->fontHeight;
1150 line = (yPos + updateR.y()) / h; 1143 line = (yPos + updateR.y()) / h;
1151 y = line*h - yPos; 1144 y = line*h - yPos;
1152 yEnd = updateR.y() + updateR.height(); 1145 yEnd = updateR.y() + updateR.height();
1153 waitForPreHighlight=myDoc->needPreHighlight(waitForPreHighlight=line+((long)(yEnd-y)/h)+5); 1146 waitForPreHighlight=myDoc->needPreHighlight(waitForPreHighlight=line+((long)(yEnd-y)/h)+5);
1154 1147
1155 while (y < yEnd) 1148 while (y < yEnd)
1156 { 1149 {
1157 TextLine *textLine; 1150 TextLine *textLine;
1158 int ctxNum = 0; 1151 int ctxNum = 0;
1159 myDoc->paintTextLine(paint, line, xStart, xEnd, myView->configFlags & KateView::cfShowTabs); 1152 myDoc->paintTextLine(paint, line, xStart, xEnd, myView->configFlags & KateView::cfShowTabs);
1160 bitBlt(this, updateR.x(), y, drawBuffer, 0, 0, updateR.width(), h); 1153 bitBlt(this, updateR.x(), y, drawBuffer, 0, 0, updateR.width(), h);
1161 leftBorder->paintLine(line); 1154 leftBorder->paintLine(line);
1162 line++; 1155 line++;
1163 y += h; 1156 y += h;
1164 } 1157 }
1165 paint.end(); 1158 paint.end();
1166 1159
1167 if (cursorOn) paintCursor(); 1160 if (cursorOn) paintCursor();
1168 if (bm.eXPos > bm.sXPos) paintBracketMark(); 1161 if (bm.eXPos > bm.sXPos) paintBracketMark();
1169} 1162}
1170 1163
1171void KateViewInternal::resizeEvent(QResizeEvent *) 1164void KateViewInternal::resizeEvent(QResizeEvent *)
1172{ 1165{
1173 drawBuffer->resize (width(), myDoc->fontHeight); 1166 drawBuffer->resize (width(), myDoc->fontHeight);
1174 leftBorder->resize(iconBorderWidth, height()); 1167 leftBorder->resize(iconBorderWidth, height());
1175} 1168}
1176 1169
1177void KateViewInternal::timerEvent(QTimerEvent *e) { 1170void KateViewInternal::timerEvent(QTimerEvent *e) {
1178 if (e->timerId() == cursorTimer) { 1171 if (e->timerId() == cursorTimer) {
1179 cursorOn = !cursorOn; 1172 cursorOn = !cursorOn;
1180 paintCursor(); 1173 paintCursor();
1181 } 1174 }
1182 if (e->timerId() == scrollTimer && (scrollX | scrollY)) { 1175 if (e->timerId() == scrollTimer && (scrollX | scrollY)) {
1183 xScroll->setValue(xPos + scrollX); 1176 xScroll->setValue(xPos + scrollX);
1184 yScroll->setValue(yPos + scrollY); 1177 yScroll->setValue(yPos + scrollY);
1185 1178
1186 placeCursor(mouseX, mouseY, KateView::cfMark); 1179 placeCursor(mouseX, mouseY, KateView::cfMark);
1187 myDoc->updateViews(/*ufNoScroll*/); 1180 myDoc->updateViews(/*ufNoScroll*/);
1188 } 1181 }
1189} 1182}
1190 1183
1191uint KateView::uniqueID = 0; 1184uint KateView::uniqueID = 0;
1192 1185
1193KateView::KateView(KateDocument *doc, QWidget *parent, const char * name) : Kate::View (doc, parent, name) 1186KateView::KateView(KateDocument *doc, QWidget *parent, const char * name) : Kate::View (doc, parent, name)
1194{ 1187{
1195 1188
1196 myViewID = uniqueID; 1189 myViewID = uniqueID;
1197 uniqueID++; 1190 uniqueID++;
1198 1191
1199 active = false; 1192 active = false;
1200 myIconBorder = false; 1193 myIconBorder = false;
1201 1194
1202 myDoc = doc; 1195 myDoc = doc;
1203 myViewInternal = new KateViewInternal (this,doc); 1196 myViewInternal = new KateViewInternal (this,doc);
1204 myViewInternal->move(2, 2); 1197 myViewInternal->move(2, 2);
1205 myViewInternal->leftBorder = new KateIconBorder(this, myViewInternal); 1198 myViewInternal->leftBorder = new KateIconBorder(this, myViewInternal);
1206 myViewInternal->leftBorder->setGeometry(2, 2, myViewInternal->iconBorderWidth, myViewInternal->iconBorderHeight); 1199 myViewInternal->leftBorder->setGeometry(2, 2, myViewInternal->iconBorderWidth, myViewInternal->iconBorderHeight);
1207 myViewInternal->leftBorder->hide(); 1200 myViewInternal->leftBorder->hide();
1208 1201
1209 doc->addView( this ); 1202 doc->addView( this );
1210 1203
1211 1204
1212 // some defaults 1205 // some defaults
1213 configFlags = KateView::cfAutoIndent | KateView::cfBackspaceIndents 1206 configFlags = KateView::cfAutoIndent | KateView::cfBackspaceIndents
1214 | KateView::cfTabIndents | KateView::cfKeepIndentProfile 1207 | KateView::cfTabIndents | KateView::cfKeepIndentProfile
1215 | KateView::cfRemoveSpaces 1208 | KateView::cfRemoveSpaces
1216 | KateView::cfDelOnInput | KateView::cfMouseAutoCopy | KateView::cfWrapCursor 1209 | KateView::cfDelOnInput | KateView::cfMouseAutoCopy | KateView::cfWrapCursor
1217 | KateView::cfGroupUndo | KateView::cfShowTabs | KateView::cfSmartHome; 1210 | KateView::cfGroupUndo | KateView::cfShowTabs | KateView::cfSmartHome;
1218 1211
1219 searchFlags = 0; 1212 searchFlags = 0;
1220 replacePrompt = 0L; 1213 replacePrompt = 0L;
1221 rmbMenu = 0L; 1214 rmbMenu = 0L;
1222 1215
1223 1216
1224 setFocusProxy( myViewInternal ); 1217 setFocusProxy( myViewInternal );
1225 myViewInternal->setFocus(); 1218 myViewInternal->setFocus();
1226 resize(parent->width() -4, parent->height() -4); 1219 resize(parent->width() -4, parent->height() -4);
1227 1220
1228 1221
1229 myViewInternal->installEventFilter( this ); 1222 myViewInternal->installEventFilter( this );
1230 1223
1231 //setupActions(); 1224 //setupActions();
1232 1225
1233 connect( this, SIGNAL( newStatus() ), this, SLOT( slotUpdate() ) ); 1226 connect( this, SIGNAL( newStatus() ), this, SLOT( slotUpdate() ) );
1234 connect( this, SIGNAL( newUndo() ), this, SLOT( slotNewUndo() ) ); 1227 connect( this, SIGNAL( newUndo() ), this, SLOT( slotNewUndo() ) );
1235 connect( doc, SIGNAL( fileNameChanged() ), this, SLOT( slotFileStatusChanged() ) ); 1228 connect( doc, SIGNAL( fileNameChanged() ), this, SLOT( slotFileStatusChanged() ) );
1236 connect( doc, SIGNAL( highlightChanged() ), this, SLOT( slotHighlightChanged() ) ); 1229 connect( doc, SIGNAL( highlightChanged() ), this, SLOT( slotHighlightChanged() ) );
1237 1230
1238 readConfig(); 1231 readConfig();
1239// setHighlight->setCurrentItem(getHl()); 1232// setHighlight->setCurrentItem(getHl());
1240 slotUpdate(); 1233 slotUpdate();
1241} 1234}
1242 1235
1243KateView::~KateView() 1236KateView::~KateView()
1244{ 1237{
1245 writeConfig(); 1238 writeConfig();
1246 1239
1247 if (myDoc && !myDoc->m_bSingleViewMode) 1240 if (myDoc && !myDoc->m_bSingleViewMode)
1248 myDoc->removeView( this ); 1241 myDoc->removeView( this );
1249 1242
1250 delete myViewInternal; 1243 delete myViewInternal;
1251} 1244}
1252 1245
1253#if 0 1246#if 0
1254void KateView::setupActions() 1247void KateView::setupActions()
1255{ 1248{
1256#if 0 1249#if 0
1257 KStdAction::close( this, SLOT(flush()), actionCollection(), "file_close" ); 1250 KStdAction::close( this, SLOT(flush()), actionCollection(), "file_close" );
1258 1251
1259 KStdAction::save(this, SLOT(save()), actionCollection()); 1252 KStdAction::save(this, SLOT(save()), actionCollection());
1260 1253
1261 // setup edit menu 1254 // setup edit menu
1262 editUndo = KStdAction::undo(this, SLOT(undo()), actionCollection()); 1255 editUndo = KStdAction::undo(this, SLOT(undo()), actionCollection());
1263 editRedo = KStdAction::redo(this, SLOT(redo()), actionCollection()); 1256 editRedo = KStdAction::redo(this, SLOT(redo()), actionCollection());
1264 editUndoHist = new KAction(i18n("Undo/Redo &History..."), 0, this, SLOT(undoHistory()), 1257 editUndoHist = new KAction(i18n("Undo/Redo &History..."), 0, this, SLOT(undoHistory()),
1265 actionCollection(), "edit_undoHistory"); 1258 actionCollection(), "edit_undoHistory");
1266 KStdAction::cut(this, SLOT(cut()), actionCollection()); 1259 KStdAction::cut(this, SLOT(cut()), actionCollection());
1267 KStdAction::copy(this, SLOT(copy()), actionCollection()); 1260 KStdAction::copy(this, SLOT(copy()), actionCollection());
1268 KStdAction::paste(this, SLOT(paste()), actionCollection()); 1261 KStdAction::paste(this, SLOT(paste()), actionCollection());
1269 1262
1270 if ( myDoc->hasBrowserExtension() ) 1263 if ( myDoc->hasBrowserExtension() )
1271 { 1264 {
1272 KStdAction::saveAs(this, SLOT(saveAs()), myDoc->actionCollection()); 1265 KStdAction::saveAs(this, SLOT(saveAs()), myDoc->actionCollection());
1273 KStdAction::find(this, SLOT(find()), myDoc->actionCollection(), "find"); 1266 KStdAction::find(this, SLOT(find()), myDoc->actionCollection(), "find");
1274 KStdAction::findNext(this, SLOT(findAgain()), myDoc->actionCollection(), "find_again"); 1267 KStdAction::findNext(this, SLOT(findAgain()), myDoc->actionCollection(), "find_again");
1275 KStdAction::findPrev(this, SLOT(findPrev()), myDoc->actionCollection(), "find_prev"); 1268 KStdAction::findPrev(this, SLOT(findPrev()), myDoc->actionCollection(), "find_prev");
1276 KStdAction::gotoLine(this, SLOT(gotoLine()), myDoc->actionCollection(), "goto_line" ); 1269 KStdAction::gotoLine(this, SLOT(gotoLine()), myDoc->actionCollection(), "goto_line" );
1277 new KAction(i18n("&Configure Editor..."), 0, this, SLOT(configDialog()),myDoc->actionCollection(), "set_confdlg"); 1270 new KAction(i18n("&Configure Editor..."), 0, this, SLOT(configDialog()),myDoc->actionCollection(), "set_confdlg");
1278 setHighlight = new KSelectAction(i18n("&Highlight Mode"), 0, myDoc->actionCollection(), "set_highlight"); 1271 setHighlight = new KSelectAction(i18n("&Highlight Mode"), 0, myDoc->actionCollection(), "set_highlight");
1279 KStdAction::selectAll(this, SLOT(selectAll()), myDoc->actionCollection(), "select_all"); 1272 KStdAction::selectAll(this, SLOT(selectAll()), myDoc->actionCollection(), "select_all");
1280 new KAction(i18n("&Deselect All"), 0, this, SLOT(deselectAll()), 1273 new KAction(i18n("&Deselect All"), 0, this, SLOT(deselectAll()),
1281 myDoc->actionCollection(), "unselect_all"); 1274 myDoc->actionCollection(), "unselect_all");
1282 new KAction(i18n("Invert &Selection"), 0, this, SLOT(invertSelection()), 1275 new KAction(i18n("Invert &Selection"), 0, this, SLOT(invertSelection()),
1283 myDoc->actionCollection(), "invert_select"); 1276 myDoc->actionCollection(), "invert_select");
1284 1277
1285 new KAction(i18n("Increase Font Sizes"), "viewmag+", 0, this, SLOT(slotIncFontSizes()), 1278 new KAction(i18n("Increase Font Sizes"), "viewmag+", 0, this, SLOT(slotIncFontSizes()),
1286 myDoc->actionCollection(), "incFontSizes"); 1279 myDoc->actionCollection(), "incFontSizes");
1287 new KAction(i18n("Decrease Font Sizes"), "viewmag-", 0, this, SLOT(slotDecFontSizes()), 1280 new KAction(i18n("Decrease Font Sizes"), "viewmag-", 0, this, SLOT(slotDecFontSizes()),
1288 myDoc->actionCollection(), "decFontSizes"); 1281 myDoc->actionCollection(), "decFontSizes");
1289 } 1282 }
1290 else 1283 else
1291 { 1284 {
1292 KStdAction::saveAs(this, SLOT(saveAs()), actionCollection()); 1285 KStdAction::saveAs(this, SLOT(saveAs()), actionCollection());
1293 KStdAction::find(this, SLOT(find()), actionCollection()); 1286 KStdAction::find(this, SLOT(find()), actionCollection());
1294 KStdAction::findNext(this, SLOT(findAgain()), actionCollection()); 1287 KStdAction::findNext(this, SLOT(findAgain()), actionCollection());
1295 KStdAction::findPrev(this, SLOT(findPrev()), actionCollection(), "edit_find_prev"); 1288 KStdAction::findPrev(this, SLOT(findPrev()), actionCollection(), "edit_find_prev");
1296 KStdAction::gotoLine(this, SLOT(gotoLine()), actionCollection()); 1289 KStdAction::gotoLine(this, SLOT(gotoLine()), actionCollection());
1297 new KAction(i18n("&Configure Editor..."), 0, this, SLOT(configDialog()),actionCollection(), "set_confdlg"); 1290 new KAction(i18n("&Configure Editor..."), 0, this, SLOT(configDialog()),actionCollection(), "set_confdlg");
1298 setHighlight = new KSelectAction(i18n("&Highlight Mode"), 0, actionCollection(), "set_highlight"); 1291 setHighlight = new KSelectAction(i18n("&Highlight Mode"), 0, actionCollection(), "set_highlight");
1299 KStdAction::selectAll(this, SLOT(selectAll()), actionCollection()); 1292 KStdAction::selectAll(this, SLOT(selectAll()), actionCollection());
1300 new KAction(i18n("&Deselect All"), 0, this, SLOT(deselectAll()), 1293 new KAction(i18n("&Deselect All"), 0, this, SLOT(deselectAll()),
1301 actionCollection(), "edit_deselectAll"); 1294 actionCollection(), "edit_deselectAll");
1302 new KAction(i18n("Invert &Selection"), 0, this, SLOT(invertSelection()), 1295 new KAction(i18n("Invert &Selection"), 0, this, SLOT(invertSelection()),
1303 actionCollection(), "edit_invertSelection"); 1296 actionCollection(), "edit_invertSelection");
1304 1297
1305 new KAction(i18n("Increase Font Sizes"), "viewmag+", 0, this, SLOT(slotIncFontSizes()), 1298 new KAction(i18n("Increase Font Sizes"), "viewmag+", 0, this, SLOT(slotIncFontSizes()),
1306 actionCollection(), "incFontSizes"); 1299 actionCollection(), "incFontSizes");
1307 new KAction(i18n("Decrease Font Sizes"), "viewmag-", 0, this, SLOT(slotDecFontSizes()), 1300 new KAction(i18n("Decrease Font Sizes"), "viewmag-", 0, this, SLOT(slotDecFontSizes()),
1308 actionCollection(), "decFontSizes"); 1301 actionCollection(), "decFontSizes");
1309 } 1302 }
1310 1303
1311 new KAction(i18n("Apply Word Wrap"), 0, myDoc, SLOT(applyWordWrap()), actionCollection(), "edit_apply_wordwrap"); 1304 new KAction(i18n("Apply Word Wrap"), 0, myDoc, SLOT(applyWordWrap()), actionCollection(), "edit_apply_wordwrap");
1312 1305
1313 KStdAction::replace(this, SLOT(replace()), actionCollection()); 1306 KStdAction::replace(this, SLOT(replace()), actionCollection());
1314 1307
1315 new KAction(i18n("Editing Co&mmand"), Qt::CTRL+Qt::Key_M, this, SLOT(slotEditCommand()), 1308 new KAction(i18n("Editing Co&mmand"), Qt::CTRL+Qt::Key_M, this, SLOT(slotEditCommand()),
1316 actionCollection(), "edit_cmd"); 1309 actionCollection(), "edit_cmd");
1317 1310
1318 // setup bookmark menu 1311 // setup bookmark menu
1319 bookmarkToggle = new KAction(i18n("Toggle &Bookmark"), Qt::CTRL+Qt::Key_B, this, SLOT(toggleBookmark()), actionCollection(), "edit_bookmarkToggle"); 1312 bookmarkToggle = new KAction(i18n("Toggle &Bookmark"), Qt::CTRL+Qt::Key_B, this, SLOT(toggleBookmark()), actionCollection(), "edit_bookmarkToggle");
1320 bookmarkClear = new KAction(i18n("Clear Bookmarks"), 0, this, SLOT(clearBookmarks()), actionCollection(), "edit_bookmarksClear"); 1313 bookmarkClear = new KAction(i18n("Clear Bookmarks"), 0, this, SLOT(clearBookmarks()), actionCollection(), "edit_bookmarksClear");
1321 1314
1322 // connect settings menu aboutToshow 1315 // connect settings menu aboutToshow
1323 bookmarkMenu = new KActionMenu(i18n("&Bookmarks"), actionCollection(), "bookmarks"); 1316 bookmarkMenu = new KActionMenu(i18n("&Bookmarks"), actionCollection(), "bookmarks");
1324 connect(bookmarkMenu->popupMenu(), SIGNAL(aboutToShow()), this, SLOT(bookmarkMenuAboutToShow())); 1317 connect(bookmarkMenu->popupMenu(), SIGNAL(aboutToShow()), this, SLOT(bookmarkMenuAboutToShow()));
1325 1318
1326 new KToggleAction(i18n("Show &IconBorder"), Key_F6, this, SLOT(toggleIconBorder()), actionCollection(), "view_border"); 1319 new KToggleAction(i18n("Show &IconBorder"), Key_F6, this, SLOT(toggleIconBorder()), actionCollection(), "view_border");
1327 1320
1328 // setup Tools menu 1321 // setup Tools menu
1329 KStdAction::spelling(this, SLOT(spellcheck()), actionCollection()); 1322 KStdAction::spelling(this, SLOT(spellcheck()), actionCollection());
1330 new KAction(i18n("&Indent"), "indent", Qt::CTRL+Qt::Key_I, this, SLOT(indent()), 1323 new KAction(i18n("&Indent"), "indent", Qt::CTRL+Qt::Key_I, this, SLOT(indent()),
1331 actionCollection(), "tools_indent"); 1324 actionCollection(), "tools_indent");
1332 new KAction(i18n("&Unindent"), "unindent", Qt::CTRL+Qt::Key_U, this, SLOT(unIndent()), 1325 new KAction(i18n("&Unindent"), "unindent", Qt::CTRL+Qt::Key_U, this, SLOT(unIndent()),
1333 actionCollection(), "tools_unindent"); 1326 actionCollection(), "tools_unindent");
1334 new KAction(i18n("&Clean Indentation"), 0, this, SLOT(cleanIndent()), 1327 new KAction(i18n("&Clean Indentation"), 0, this, SLOT(cleanIndent()),
1335 actionCollection(), "tools_cleanIndent"); 1328 actionCollection(), "tools_cleanIndent");
1336 new KAction(i18n("C&omment"), CTRL+Qt::Key_NumberSign, this, SLOT(comment()), 1329 new KAction(i18n("C&omment"), CTRL+Qt::Key_NumberSign, this, SLOT(comment()),
1337 actionCollection(), "tools_comment"); 1330 actionCollection(), "tools_comment");
1338 new KAction(i18n("Unco&mment"), CTRL+SHIFT+Qt::Key_NumberSign, this, SLOT(uncomment()), 1331 new KAction(i18n("Unco&mment"), CTRL+SHIFT+Qt::Key_NumberSign, this, SLOT(uncomment()),
1339 actionCollection(), "tools_uncomment"); 1332 actionCollection(), "tools_uncomment");
1340 1333
1341 setVerticalSelection = new KToggleAction(i18n("&Vertical Selection"), Key_F4, this, SLOT(toggleVertical()), 1334 setVerticalSelection = new KToggleAction(i18n("&Vertical Selection"), Key_F4, this, SLOT(toggleVertical()),
1342 actionCollection(), "set_verticalSelect"); 1335 actionCollection(), "set_verticalSelect");
1343 1336
1344 connect(setHighlight, SIGNAL(activated(int)), this, SLOT(setHl(int))); 1337 connect(setHighlight, SIGNAL(activated(int)), this, SLOT(setHl(int)));
1345 QStringList list; 1338 QStringList list;
1346 for (int z = 0; z < HlManager::self()->highlights(); z++) 1339 for (int z = 0; z < HlManager::self()->highlights(); z++)
1347 list.append(HlManager::self()->hlName(z)); 1340 list.append(HlManager::self()->hlName(z));
1348 setHighlight->setItems(list); 1341 setHighlight->setItems(list);
1349 1342
1350 setEndOfLine = new KSelectAction(i18n("&End Of Line"), 0, actionCollection(), "set_eol"); 1343 setEndOfLine = new KSelectAction(i18n("&End Of Line"), 0, actionCollection(), "set_eol");
1351 connect(setEndOfLine, SIGNAL(activated(int)), this, SLOT(setEol(int))); 1344 connect(setEndOfLine, SIGNAL(activated(int)), this, SLOT(setEol(int)));
1352 list.clear(); 1345 list.clear();
1353 list.append("&Unix"); 1346 list.append("&Unix");
1354 list.append("&Windows/Dos"); 1347 list.append("&Windows/Dos");
1355 list.append("&Macintosh"); 1348 list.append("&Macintosh");
1356 setEndOfLine->setItems(list); 1349 setEndOfLine->setItems(list);
1357#endif 1350#endif
1358} 1351}
1359#endif 1352#endif
1360 1353
1361void KateView::slotUpdate() 1354void KateView::slotUpdate()
1362{ 1355{
1363 int cfg = config(); 1356 int cfg = config();
1364 1357
1365#warning fixme setVerticalSelection->setChecked(cfg & KateView::cfVerticalSelect); 1358#warning fixme setVerticalSelection->setChecked(cfg & KateView::cfVerticalSelect);
1366 1359
1367 slotNewUndo(); 1360 slotNewUndo();
1368} 1361}
1369void KateView::slotFileStatusChanged() 1362void KateView::slotFileStatusChanged()
1370{ 1363{
1371 int eol = getEol(); 1364 int eol = getEol();
1372 eol = eol>=1 ? eol : 0; 1365 eol = eol>=1 ? eol : 0;
1373 1366
1374#warning fixme setEndOfLine->setCurrentItem(eol); 1367#warning fixme setEndOfLine->setCurrentItem(eol);
1375} 1368}
1376void KateView::slotNewUndo() 1369void KateView::slotNewUndo()
1377{ 1370{
1378#if 0 1371#if 0
1379 int state = undoState(); 1372 int state = undoState();
1380 1373
1381 editUndoHist->setEnabled(state & 1 || state & 2); 1374 editUndoHist->setEnabled(state & 1 || state & 2);
1382 1375
1383 QString t = i18n("Und&o"); // it would be nicer to fetch the original string 1376 QString t = i18n("Und&o"); // it would be nicer to fetch the original string
1384 if (state & 1) { 1377 if (state & 1) {
1385 editUndo->setEnabled(true); 1378 editUndo->setEnabled(true);
1386 t += ' '; 1379 t += ' ';
1387 t += i18n(undoTypeName(nextUndoType())); 1380 t += i18n(undoTypeName(nextUndoType()));
1388 } else { 1381 } else {
1389 editUndo->setEnabled(false); 1382 editUndo->setEnabled(false);
1390 } 1383 }
1391 editUndo->setText(t); 1384 editUndo->setText(t);
1392 1385
1393 t = i18n("Re&do"); // it would be nicer to fetch the original string 1386 t = i18n("Re&do"); // it would be nicer to fetch the original string
1394 if (state & 2) { 1387 if (state & 2) {
1395 editRedo->setEnabled(true); 1388 editRedo->setEnabled(true);
1396 t += ' '; 1389 t += ' ';
1397 t += i18n(undoTypeName(nextRedoType())); 1390 t += i18n(undoTypeName(nextRedoType()));
1398 } else { 1391 } else {
1399 editRedo->setEnabled(false); 1392 editRedo->setEnabled(false);
1400 } 1393 }
1401 editRedo->setText(t); 1394 editRedo->setText(t);
1402#endif 1395#endif
1403} 1396}
1404 1397
1405void KateView::slotHighlightChanged() 1398void KateView::slotHighlightChanged()
1406{ 1399{
1407// setHighlight->setCurrentItem(getHl()); 1400// setHighlight->setCurrentItem(getHl());
1408} 1401}
1409 1402
1410 1403
1411void KateView::keyPressEvent( QKeyEvent *ev ) 1404void KateView::keyPressEvent( QKeyEvent *ev )
1412{ 1405{
1413 switch ( ev->key() ) 1406 switch ( ev->key() )
1414 { 1407 {
1415 case Key_Left: 1408 case Key_Left:
1416 if ( ev->state() & ShiftButton ) 1409 if ( ev->state() & ShiftButton )
1417 { 1410 {
1418 if ( ev->state() & ControlButton ) 1411 if ( ev->state() & ControlButton )
1419 shiftWordLeft(); 1412 shiftWordLeft();
1420 else 1413 else
1421 shiftCursorLeft(); 1414 shiftCursorLeft();
1422 } 1415 }
1423 else if ( ev->state() & ControlButton ) 1416 else if ( ev->state() & ControlButton )
1424 wordLeft(); 1417 wordLeft();
1425 else 1418 else
1426 cursorLeft(); 1419 cursorLeft();
1427 break; 1420 break;
1428 case Key_Right: 1421 case Key_Right:
1429 if ( ev->state() & ShiftButton ) 1422 if ( ev->state() & ShiftButton )
1430 { 1423 {
1431 if ( ev->state() & ControlButton ) 1424 if ( ev->state() & ControlButton )
1432 shiftWordRight(); 1425 shiftWordRight();
1433 else 1426 else
1434 shiftCursorRight(); 1427 shiftCursorRight();
1435 } 1428 }
1436 else if ( ev->state() & ControlButton ) 1429 else if ( ev->state() & ControlButton )
1437 wordRight(); 1430 wordRight();
1438 else 1431 else
1439 cursorRight(); 1432 cursorRight();
1440 break; 1433 break;
1441 case Key_Home: 1434 case Key_Home:
1442 if ( ev->state() & ShiftButton ) 1435 if ( ev->state() & ShiftButton )
1443 { 1436 {
1444 if ( ev->state() & ControlButton ) 1437 if ( ev->state() & ControlButton )
1445 shiftTop(); 1438 shiftTop();
1446 else 1439 else
1447 shiftHome(); 1440 shiftHome();
1448 } 1441 }
1449 else if ( ev->state() & ControlButton ) 1442 else if ( ev->state() & ControlButton )
1450 top(); 1443 top();
1451 else 1444 else
1452 home(); 1445 home();
1453 break; 1446 break;
1454 case Key_End: 1447 case Key_End:
1455 if ( ev->state() & ShiftButton ) 1448 if ( ev->state() & ShiftButton )
1456 { 1449 {
1457 if ( ev->state() & ControlButton ) 1450 if ( ev->state() & ControlButton )
1458 shiftBottom(); 1451 shiftBottom();
1459 else 1452 else
1460 shiftEnd(); 1453 shiftEnd();
1461 } 1454 }
1462 else if ( ev->state() & ControlButton ) 1455 else if ( ev->state() & ControlButton )
1463 bottom(); 1456 bottom();
1464 else 1457 else
1465 end(); 1458 end();
1466 break; 1459 break;
1467 case Key_Up: 1460 case Key_Up:
1468 if ( ev->state() & ShiftButton ) 1461 if ( ev->state() & ShiftButton )
1469 shiftUp(); 1462 shiftUp();
1470 else if ( ev->state() & ControlButton ) 1463 else if ( ev->state() & ControlButton )
1471 scrollUp(); 1464 scrollUp();
1472 else 1465 else
1473 up(); 1466 up();
1474 break; 1467 break;
1475 case Key_Down: 1468 case Key_Down:
1476 if ( ev->state() & ShiftButton ) 1469 if ( ev->state() & ShiftButton )
1477 shiftDown(); 1470 shiftDown();
1478 else if ( ev->state() & ControlButton ) 1471 else if ( ev->state() & ControlButton )
1479 scrollDown(); 1472 scrollDown();
1480 else 1473 else
1481 down(); 1474 down();
1482 break; 1475 break;
1483 case Key_PageUp: 1476 case Key_PageUp:
1484 if ( ev->state() & ShiftButton ) 1477 if ( ev->state() & ShiftButton )
1485 shiftPageUp(); 1478 shiftPageUp();
1486 else if ( ev->state() & ControlButton ) 1479 else if ( ev->state() & ControlButton )
1487 topOfView(); 1480 topOfView();
1488 else 1481 else
1489 pageUp(); 1482 pageUp();
1490 break; 1483 break;
1491 case Key_PageDown: 1484 case Key_PageDown:
1492 if ( ev->state() & ShiftButton ) 1485 if ( ev->state() & ShiftButton )
1493 shiftPageDown(); 1486 shiftPageDown();
1494 else if ( ev->state() & ControlButton ) 1487 else if ( ev->state() & ControlButton )
1495 bottomOfView(); 1488 bottomOfView();
1496 else 1489 else
1497 pageDown(); 1490 pageDown();
1498 break; 1491 break;
1499 case Key_Return: 1492 case Key_Return:
1500 case Key_Enter: 1493 case Key_Enter:
1501 keyReturn(); 1494 keyReturn();
1502 break; 1495 break;
1503 case Key_Delete: 1496 case Key_Delete:
1504 if ( ev->state() & ControlButton ) 1497 if ( ev->state() & ControlButton )
1505 { 1498 {
1506 VConfig c; 1499 VConfig c;
1507 shiftWordRight(); 1500 shiftWordRight();
1508 myViewInternal->getVConfig(c); 1501 myViewInternal->getVConfig(c);
1509 myDoc->delMarkedText(c); 1502 myDoc->delMarkedText(c);
1510 myViewInternal->update(); 1503 myViewInternal->update();
1511 } 1504 }
1512 else keyDelete(); 1505 else keyDelete();
1513 break; 1506 break;
1514 case Key_Backspace: 1507 case Key_Backspace:
1515 if ( ev->state() & ControlButton ) 1508 if ( ev->state() & ControlButton )
1516 { 1509 {
1517 VConfig c; 1510 VConfig c;
1518 shiftWordLeft(); 1511 shiftWordLeft();
1519 myViewInternal->getVConfig(c); 1512 myViewInternal->getVConfig(c);
1520 myDoc->delMarkedText(c); 1513 myDoc->delMarkedText(c);
1521 myViewInternal->update(); 1514 myViewInternal->update();
1522 } 1515 }
1523 else backspace(); 1516 else backspace();
1524 break; 1517 break;
1525 case Key_Insert: 1518 case Key_Insert:
1526 toggleInsert(); 1519 toggleInsert();
1527 break; 1520 break;
1528 case Key_K: 1521 case Key_K:
1529 if ( ev->state() & ControlButton ) 1522 if ( ev->state() & ControlButton )
1530 { 1523 {
1531 killLine(); 1524 killLine();
1532 break; 1525 break;
1533 } 1526 }
1534 default: 1527 default:
1535 KTextEditor::View::keyPressEvent( ev ); 1528 KTextEditor::View::keyPressEvent( ev );
1536 return; 1529 return;
1537 break; 1530 break;
1538 } 1531 }
1539 ev->accept(); 1532 ev->accept();
1540} 1533}
1541 1534
1542 1535
1543void KateView::setCursorPosition( int line, int col, bool /*mark*/ ) 1536void KateView::setCursorPosition( int line, int col, bool /*mark*/ )
1544{ 1537{
1545 setCursorPositionInternal( line, col ); 1538 setCursorPositionInternal( line, col );
1546} 1539}
1547 1540
1548void KateView::getCursorPosition( int *line, int *col ) 1541void KateView::getCursorPosition( int *line, int *col )
1549{ 1542{
1550 if ( line ) 1543 if ( line )
1551 *line = currentLine(); 1544 *line = currentLine();
1552 1545
1553 if ( col ) 1546 if ( col )
1554 *col = currentColumn(); 1547 *col = currentColumn();
1555} 1548}
1556 1549
1557 1550
1558int KateView::currentLine() { 1551int KateView::currentLine() {
1559 return myViewInternal->cursor.y; 1552 return myViewInternal->cursor.y;
1560} 1553}
1561 1554
1562int KateView::currentColumn() { 1555int KateView::currentColumn() {
1563 return myDoc->currentColumn(myViewInternal->cursor); 1556 return myDoc->currentColumn(myViewInternal->cursor);
1564} 1557}
1565 1558
1566int KateView::currentCharNum() { 1559int KateView::currentCharNum() {
1567 return myViewInternal->cursor.x; 1560 return myViewInternal->cursor.x;
1568} 1561}
1569 1562
1570void KateView::setCursorPositionInternal(int line, int col) { 1563void KateView::setCursorPositionInternal(int line, int col) {
1571 PointStruc cursor; 1564 PointStruc cursor;
1572 1565
1573 cursor.x = col; 1566 cursor.x = col;
1574 cursor.y = line; 1567 cursor.y = line;
1575 myViewInternal->updateCursor(cursor); 1568 myViewInternal->updateCursor(cursor);
1576 myViewInternal->center(); 1569 myViewInternal->center();
1577// myViewInternal->updateView(ufPos, 0, line*myDoc->fontHeight - height()/2); 1570// myViewInternal->updateView(ufPos, 0, line*myDoc->fontHeight - height()/2);
1578// myDoc->updateViews(myViewInternal); //uptade all other views except this one 1571// myDoc->updateViews(myViewInternal); //uptade all other views except this one
1579 myDoc->updateViews(); 1572 myDoc->updateViews();
1580} 1573}
1581 1574
1582int KateView::config() { 1575int KateView::config() {
1583 int flags; 1576 int flags;
1584 1577
1585 flags = configFlags; 1578 flags = configFlags;
1586 if (myDoc->singleSelection()) flags |= KateView::cfSingleSelection; 1579 if (myDoc->singleSelection()) flags |= KateView::cfSingleSelection;
1587 return flags; 1580 return flags;
1588} 1581}
1589 1582
1590void KateView::setConfig(int flags) { 1583void KateView::setConfig(int flags) {
1591 bool updateView; 1584 bool updateView;
1592 1585
1593 // cfSingleSelection is a doc-property 1586 // cfSingleSelection is a doc-property
1594 myDoc->setSingleSelection(flags & KateView::cfSingleSelection); 1587 myDoc->setSingleSelection(flags & KateView::cfSingleSelection);
1595 flags &= ~KateView::cfSingleSelection; 1588 flags &= ~KateView::cfSingleSelection;
1596 1589
1597 if (flags != configFlags) { 1590 if (flags != configFlags) {
1598 // update the view if visibility of tabs has changed 1591 // update the view if visibility of tabs has changed
1599 updateView = (flags ^ configFlags) & KateView::cfShowTabs; 1592 updateView = (flags ^ configFlags) & KateView::cfShowTabs;
1600 configFlags = flags; 1593 configFlags = flags;
1601 emit newStatus(); 1594 emit newStatus();
1602 if (updateView) myViewInternal->update(); 1595 if (updateView) myViewInternal->update();
1603 } 1596 }
1604} 1597}
1605 1598
1606int KateView::tabWidth() { 1599int KateView::tabWidth() {
1607 return myDoc->tabChars; 1600 return myDoc->tabChars;
1608} 1601}
1609 1602
1610void KateView::setTabWidth(int w) { 1603void KateView::setTabWidth(int w) {
1611 myDoc->setTabWidth(w); 1604 myDoc->setTabWidth(w);
1612 myDoc->updateViews(); 1605 myDoc->updateViews();
1613} 1606}
1614 1607
1615void KateView::setEncoding (QString e) { 1608void KateView::setEncoding (QString e) {
1616 myDoc->setEncoding (e); 1609 myDoc->setEncoding (e);
1617 myDoc->updateViews(); 1610 myDoc->updateViews();
1618} 1611}
1619 1612
1620int KateView::undoSteps() { 1613int KateView::undoSteps() {
1621 return myDoc->undoSteps; 1614 return myDoc->undoSteps;
1622} 1615}
1623 1616
1624void KateView::setUndoSteps(int s) { 1617void KateView::setUndoSteps(int s) {
1625 myDoc->setUndoSteps(s); 1618 myDoc->setUndoSteps(s);
1626} 1619}
1627 1620
1628bool KateView::isReadOnly() { 1621bool KateView::isReadOnly() {
1629 return myDoc->readOnly; 1622 return myDoc->readOnly;
1630} 1623}
1631 1624
1632bool KateView::isModified() { 1625bool KateView::isModified() {
1633 return myDoc->modified; 1626 return myDoc->modified;
1634} 1627}
1635 1628
1636void KateView::setReadOnly(bool m) { 1629void KateView::setReadOnly(bool m) {
1637 myDoc->setReadOnly(m); 1630 myDoc->setReadOnly(m);
1638} 1631}
1639 1632
1640void KateView::setModified(bool m) { 1633void KateView::setModified(bool m) {
1641 myDoc->setModified(m); 1634 myDoc->setModified(m);
1642} 1635}
1643 1636
1644bool KateView::isLastView() { 1637bool KateView::isLastView() {
1645 return myDoc->isLastView(1); 1638 return myDoc->isLastView(1);
1646} 1639}
1647 1640
1648KateDocument *KateView::doc() { 1641KateDocument *KateView::doc() {
1649 return myDoc; 1642 return myDoc;
1650} 1643}
1651 1644
1652int KateView::undoState() { 1645int KateView::undoState() {
1653 if (isReadOnly()) 1646 if (isReadOnly())
1654 return 0; 1647 return 0;
1655 else 1648 else
1656 return myDoc->undoState; 1649 return myDoc->undoState;
1657} 1650}
1658 1651
1659int KateView::nextUndoType() { 1652int KateView::nextUndoType() {
1660 return myDoc->nextUndoType(); 1653 return myDoc->nextUndoType();
1661} 1654}
1662 1655
1663int KateView::nextRedoType() { 1656int KateView::nextRedoType() {
1664 return myDoc->nextRedoType(); 1657 return myDoc->nextRedoType();
1665} 1658}
1666 1659
1667void KateView::undoTypeList(QValueList<int> &lst) 1660void KateView::undoTypeList(QValueList<int> &lst)
1668{ 1661{
1669 myDoc->undoTypeList(lst); 1662 myDoc->undoTypeList(lst);
1670} 1663}
1671 1664
1672void KateView::redoTypeList(QValueList<int> &lst) 1665void KateView::redoTypeList(QValueList<int> &lst)
1673{ 1666{
1674 myDoc->redoTypeList(lst); 1667 myDoc->redoTypeList(lst);
1675} 1668}
1676 1669
1677const char * KateView::undoTypeName(int type) { 1670const char * KateView::undoTypeName(int type) {
1678 return KateActionGroup::typeName(type); 1671 return KateActionGroup::typeName(type);
1679} 1672}
1680 1673
1681QColor* KateView::getColors() 1674QColor* KateView::getColors()
1682{ 1675{
1683 return myDoc->colors; 1676 return myDoc->colors;
1684} 1677}
1685 1678
1686void KateView::applyColors() 1679void KateView::applyColors()
1687{ 1680{
1688 myDoc->tagAll(); 1681 myDoc->tagAll();
1689 myDoc->updateViews(); 1682 myDoc->updateViews();
1690} 1683}
1691 1684
1692bool KateView::isOverwriteMode() const 1685bool KateView::isOverwriteMode() const
1693{ 1686{
1694 return ( configFlags & KateView::cfOvr ); 1687 return ( configFlags & KateView::cfOvr );
1695} 1688}
1696 1689
1697void KateView::setOverwriteMode( bool b ) 1690void KateView::setOverwriteMode( bool b )
1698{ 1691{
1699 if ( isOverwriteMode() && !b ) 1692 if ( isOverwriteMode() && !b )
1700 setConfig( configFlags ^ KateView::cfOvr ); 1693 setConfig( configFlags ^ KateView::cfOvr );
1701 else 1694 else
1702 setConfig( configFlags | KateView::cfOvr ); 1695 setConfig( configFlags | KateView::cfOvr );
1703} 1696}
1704 1697
1705void KateView::toggleInsert() { 1698void KateView::toggleInsert() {
1706 setConfig(configFlags ^ KateView::cfOvr); 1699 setConfig(configFlags ^ KateView::cfOvr);
1707} 1700}
1708 1701
1709void KateView::toggleVertical() 1702void KateView::toggleVertical()
1710{ 1703{
1711 setConfig(configFlags ^ KateView::cfVerticalSelect); 1704 setConfig(configFlags ^ KateView::cfVerticalSelect);
1712} 1705}
1713 1706
1714 1707
1715int KateView::numLines() { 1708int KateView::numLines() {
1716 return myDoc->numLines(); 1709 return myDoc->numLines();
1717} 1710}
1718 1711
1719QString KateView::text() { 1712QString KateView::text() {
1720 return myDoc->text(); 1713 return myDoc->text();
1721} 1714}
1722 1715
1723QString KateView::currentTextLine() { 1716QString KateView::currentTextLine() {
1724 TextLine::Ptr textLine = myDoc->getTextLine(myViewInternal->cursor.y); 1717 TextLine::Ptr textLine = myDoc->getTextLine(myViewInternal->cursor.y);
1725 return QString(textLine->getText(), textLine->length()); 1718 return QString(textLine->getText(), textLine->length());
1726} 1719}
1727 1720
1728QString KateView::textLine(int num) { 1721QString KateView::textLine(int num) {
1729 TextLine::Ptr textLine = myDoc->getTextLine(num); 1722 TextLine::Ptr textLine = myDoc->getTextLine(num);
1730 return QString(textLine->getText(), textLine->length()); 1723 return QString(textLine->getText(), textLine->length());
1731} 1724}
1732 1725
1733QString KateView::currentWord() { 1726QString KateView::currentWord() {
1734 return myDoc->getWord(myViewInternal->cursor); 1727 return myDoc->getWord(myViewInternal->cursor);
1735} 1728}
1736 1729
1737QString KateView::word(int x, int y) { 1730QString KateView::word(int x, int y) {
1738 PointStruc cursor; 1731 PointStruc cursor;
1739 cursor.y = (myViewInternal->yPos + y)/myDoc->fontHeight; 1732 cursor.y = (myViewInternal->yPos + y)/myDoc->fontHeight;
1740 if (cursor.y < 0 || cursor.y > myDoc->lastLine()) return QString(); 1733 if (cursor.y < 0 || cursor.y > myDoc->lastLine()) return QString();
1741 cursor.x = myDoc->textPos(myDoc->getTextLine(cursor.y), myViewInternal->xPos-2 + x); 1734 cursor.x = myDoc->textPos(myDoc->getTextLine(cursor.y), myViewInternal->xPos-2 + x);
1742 return myDoc->getWord(cursor); 1735 return myDoc->getWord(cursor);
1743} 1736}
1744 1737
1745void KateView::setText(const QString &s) { 1738void KateView::setText(const QString &s) {
1746 myDoc->setText(s); 1739 myDoc->setText(s);
1747 myDoc->updateViews(); 1740 myDoc->updateViews();
1748} 1741}
1749 1742
1750void KateView::insertText(const QString &s, bool /*mark*/) { 1743void KateView::insertText(const QString &s, bool /*mark*/) {
1751 VConfig c; 1744 VConfig c;
1752 myViewInternal->getVConfig(c); 1745 myViewInternal->getVConfig(c);
1753 myDoc->insert(c, s); 1746 myDoc->insert(c, s);
1754 myDoc->updateViews(); 1747 myDoc->updateViews();
1755} 1748}
1756 1749
1757bool KateView::hasMarkedText() { 1750bool KateView::hasMarkedText() {
1758 return myDoc->hasMarkedText(); 1751 return myDoc->hasMarkedText();
1759} 1752}
1760 1753
1761QString KateView::markedText() { 1754QString KateView::markedText() {
1762 return myDoc->markedText(configFlags); 1755 return myDoc->markedText(configFlags);
1763} 1756}
1764 1757
1765bool KateView::canDiscard() { 1758bool KateView::canDiscard() {
1766 int query; 1759 int query;
1767 1760
1768 if (isModified()) { 1761 if (isModified()) {
1769 query = KMessageBox::warningYesNoCancel(this, 1762 query = KMessageBox::warningYesNoCancel(this,
1770 i18n("The current Document has been modified.\nWould you like to save it?")); 1763 i18n("The current Document has been modified.\nWould you like to save it?"));
1771 switch (query) { 1764 switch (query) {
1772 case KMessageBox::Yes: //yes 1765 case KMessageBox::Yes: //yes
1773 if (save() == CANCEL) return false; 1766 if (save() == CANCEL) return false;
1774 if (isModified()) { 1767 if (isModified()) {
1775 query = KMessageBox::warningContinueCancel(this, 1768 query = KMessageBox::warningContinueCancel(this,
1776 i18n("Could not save the document.\nDiscard it and continue?"), 1769 i18n("Could not save the document.\nDiscard it and continue?"),
1777 QString::null, i18n("&Discard")); 1770 QString::null, i18n("&Discard"));
1778 if (query == KMessageBox::Cancel) return false; 1771 if (query == KMessageBox::Cancel) return false;
1779 } 1772 }
1780 break; 1773 break;
1781 case KMessageBox::Cancel: //cancel 1774 case KMessageBox::Cancel: //cancel
1782 return false; 1775 return false;
1783 } 1776 }
1784 } 1777 }
1785 return true; 1778 return true;
1786} 1779}
1787 1780
1788void KateView::flush() 1781void KateView::flush()
1789{ 1782{
1790 if (canDiscard()) myDoc->flush(); 1783 if (canDiscard()) myDoc->flush();
1791} 1784}
1792 1785
1793KateView::fileResult KateView::save() { 1786KateView::fileResult KateView::save() {
1794 int query = KMessageBox::Yes; 1787 int query = KMessageBox::Yes;
1795 if (isModified()) { 1788 if (isModified()) {
1796 return saveAs(); 1789 return saveAs();
1797 } 1790 }
1798 return OK; 1791 return OK;
1799} 1792}
1800 1793
1801KateView::fileResult KateView::saveAs() { 1794KateView::fileResult KateView::saveAs() {
1802 return OK; 1795 return OK;
1803} 1796}
1804 1797
1805void KateView::doCursorCommand(int cmdNum) { 1798void KateView::doCursorCommand(int cmdNum) {
1806 VConfig c; 1799 VConfig c;
1807 myViewInternal->getVConfig(c); 1800 myViewInternal->getVConfig(c);
1808 if (cmdNum & selectFlag) c.flags |= KateView::cfMark; 1801 if (cmdNum & selectFlag) c.flags |= KateView::cfMark;
1809 if (cmdNum & multiSelectFlag) c.flags |= KateView::cfMark | KateView::cfKeepSelection; 1802 if (cmdNum & multiSelectFlag) c.flags |= KateView::cfMark | KateView::cfKeepSelection;
1810 cmdNum &= ~(selectFlag | multiSelectFlag); 1803 cmdNum &= ~(selectFlag | multiSelectFlag);
1811 myViewInternal->doCursorCommand(c, cmdNum); 1804 myViewInternal->doCursorCommand(c, cmdNum);
1812 myDoc->updateViews(); 1805 myDoc->updateViews();
1813} 1806}
1814 1807
1815void KateView::doEditCommand(int cmdNum) { 1808void KateView::doEditCommand(int cmdNum) {
1816 VConfig c; 1809 VConfig c;
1817 myViewInternal->getVConfig(c); 1810 myViewInternal->getVConfig(c);
1818 myViewInternal->doEditCommand(c, cmdNum); 1811 myViewInternal->doEditCommand(c, cmdNum);
1819 myDoc->updateViews(); 1812 myDoc->updateViews();
1820} 1813}
1821 1814
1822void KateView::undoMultiple(int count) { 1815void KateView::undoMultiple(int count) {
1823 if (isReadOnly()) 1816 if (isReadOnly())
1824 return; 1817 return;
1825 1818
1826 VConfig c; 1819 VConfig c;
1827 myViewInternal->getVConfig(c); 1820 myViewInternal->getVConfig(c);
1828 myDoc->undo(c, count); 1821 myDoc->undo(c, count);
1829 myDoc->updateViews(); 1822 myDoc->updateViews();
1830} 1823}
1831 1824
1832void KateView::redoMultiple(int count) { 1825void KateView::redoMultiple(int count) {
1833 if (isReadOnly()) 1826 if (isReadOnly())
1834 return; 1827 return;
1835 1828
1836 VConfig c; 1829 VConfig c;
1837 myViewInternal->getVConfig(c); 1830 myViewInternal->getVConfig(c);
1838 myDoc->redo(c, count); 1831 myDoc->redo(c, count);
1839 myDoc->updateViews(); 1832 myDoc->updateViews();
1840} 1833}
1841 1834
1842void KateView::undoHistory() 1835void KateView::undoHistory()
1843{ 1836{
1844 UndoHistory *undoH; 1837 UndoHistory *undoH;
1845 1838
1846 undoH = new UndoHistory(this, this, "UndoHistory", true); 1839 undoH = new UndoHistory(this, this, "UndoHistory", true);
1847 1840
1848 undoH->setCaption(i18n("Undo/Redo History")); 1841 undoH->setCaption(i18n("Undo/Redo History"));
1849 1842
1850 connect(this,SIGNAL(newUndo()),undoH,SLOT(newUndo())); 1843 connect(this,SIGNAL(newUndo()),undoH,SLOT(newUndo()));
1851 connect(undoH,SIGNAL(undo(int)),this,SLOT(undoMultiple(int))); 1844 connect(undoH,SIGNAL(undo(int)),this,SLOT(undoMultiple(int)));
1852 connect(undoH,SIGNAL(redo(int)),this,SLOT(redoMultiple(int))); 1845 connect(undoH,SIGNAL(redo(int)),this,SLOT(redoMultiple(int)));
1853 1846
1854 undoH->exec(); 1847 undoH->exec();
1855 1848
1856 delete undoH; 1849 delete undoH;
1857} 1850}
1858 1851
1859static void kwview_addToStrList(QStringList &list, const QString &str) { 1852static void kwview_addToStrList(QStringList &list, const QString &str) {
1860 if (list.count() > 0) { 1853 if (list.count() > 0) {
1861 if (list.first() == str) return; 1854 if (list.first() == str) return;
1862 QStringList::Iterator it; 1855 QStringList::Iterator it;
1863 it = list.find(str); 1856 it = list.find(str);
1864 if (*it != 0L) list.remove(it); 1857 if (*it != 0L) list.remove(it);
1865 if (list.count() >= 16) list.remove(list.fromLast()); 1858 if (list.count() >= 16) list.remove(list.fromLast());
1866 } 1859 }
1867 list.prepend(str); 1860 list.prepend(str);
1868} 1861}
1869 1862
1870void KateView::find() { 1863void KateView::find() {
1871 SearchDialog *searchDialog; 1864 SearchDialog *searchDialog;
1872 1865
1873 if (!myDoc->hasMarkedText()) searchFlags &= ~KateView::sfSelected; 1866 if (!myDoc->hasMarkedText()) searchFlags &= ~KateView::sfSelected;
1874 1867
1875 searchDialog = new SearchDialog(this, myDoc->searchForList, myDoc->replaceWithList, 1868 searchDialog = new SearchDialog(this, myDoc->searchForList, myDoc->replaceWithList,
1876 searchFlags & ~KateView::sfReplace); 1869 searchFlags & ~KateView::sfReplace);
1877 1870
1878 // If the user has marked some text we use that otherwise 1871 // If the user has marked some text we use that otherwise
1879 // use the word under the cursor. 1872 // use the word under the cursor.
1880 QString str; 1873 QString str;
1881 if (myDoc->hasMarkedText()) 1874 if (myDoc->hasMarkedText())
1882 str = markedText(); 1875 str = markedText();
1883 1876
1884 if (str.isEmpty()) 1877 if (str.isEmpty())
1885 str = currentWord(); 1878 str = currentWord();
1886 1879
1887 if (!str.isEmpty()) 1880 if (!str.isEmpty())
1888 { 1881 {
1889 str.replace(QRegExp("^\n"), ""); 1882 str.replace(QRegExp("^\n"), "");
1890 int pos=str.find("\n"); 1883 int pos=str.find("\n");
1891 if (pos>-1) 1884 if (pos>-1)
1892 str=str.left(pos); 1885 str=str.left(pos);
1893 searchDialog->setSearchText( str ); 1886 searchDialog->setSearchText( str );
1894 } 1887 }
1895 1888
1896 myViewInternal->focusOutEvent(0L);// QT bug ? 1889 myViewInternal->focusOutEvent(0L);// QT bug ?
1897 if (searchDialog->exec() == QDialog::Accepted) { 1890 if (searchDialog->exec() == QDialog::Accepted) {
1898 kwview_addToStrList(myDoc->searchForList, searchDialog->getSearchFor()); 1891 kwview_addToStrList(myDoc->searchForList, searchDialog->getSearchFor());
1899 searchFlags = searchDialog->getFlags() | (searchFlags & KateView::sfPrompt); 1892 searchFlags = searchDialog->getFlags() | (searchFlags & KateView::sfPrompt);
1900 initSearch(s, searchFlags); 1893 initSearch(s, searchFlags);
1901 findAgain(s); 1894 findAgain(s);
1902 } 1895 }
1903 delete searchDialog; 1896 delete searchDialog;
1904} 1897}
1905 1898
1906void KateView::replace() { 1899void KateView::replace() {
1907 SearchDialog *searchDialog; 1900 SearchDialog *searchDialog;
1908 1901
1909 if (isReadOnly()) return; 1902 if (isReadOnly()) return;
1910 1903
1911 if (!myDoc->hasMarkedText()) searchFlags &= ~KateView::sfSelected; 1904 if (!myDoc->hasMarkedText()) searchFlags &= ~KateView::sfSelected;
1912 searchDialog = new SearchDialog(this, myDoc->searchForList, myDoc->replaceWithList, 1905 searchDialog = new SearchDialog(this, myDoc->searchForList, myDoc->replaceWithList,
1913 searchFlags | KateView::sfReplace); 1906 searchFlags | KateView::sfReplace);
1914 1907
1915 // If the user has marked some text we use that otherwise 1908 // If the user has marked some text we use that otherwise
1916 // use the word under the cursor. 1909 // use the word under the cursor.
1917 QString str; 1910 QString str;
1918 if (myDoc->hasMarkedText()) 1911 if (myDoc->hasMarkedText())
1919 str = markedText(); 1912 str = markedText();
1920 1913
1921 if (str.isEmpty()) 1914 if (str.isEmpty())
1922 str = currentWord(); 1915 str = currentWord();
1923 1916
1924 if (!str.isEmpty()) 1917 if (!str.isEmpty())
1925 { 1918 {
1926 str.replace(QRegExp("^\n"), ""); 1919 str.replace(QRegExp("^\n"), "");
1927 int pos=str.find("\n"); 1920 int pos=str.find("\n");
1928 if (pos>-1) 1921 if (pos>-1)
1929 str=str.left(pos); 1922 str=str.left(pos);
1930 searchDialog->setSearchText( str ); 1923 searchDialog->setSearchText( str );
1931 } 1924 }
1932 1925
1933 myViewInternal->focusOutEvent(0L);// QT bug ? 1926 myViewInternal->focusOutEvent(0L);// QT bug ?
1934 if (searchDialog->exec() == QDialog::Accepted) { 1927 if (searchDialog->exec() == QDialog::Accepted) {
1935// myDoc->recordReset(); 1928// myDoc->recordReset();
1936 kwview_addToStrList(myDoc->searchForList, searchDialog->getSearchFor()); 1929 kwview_addToStrList(myDoc->searchForList, searchDialog->getSearchFor());
1937 kwview_addToStrList(myDoc->replaceWithList, searchDialog->getReplaceWith()); 1930 kwview_addToStrList(myDoc->replaceWithList, searchDialog->getReplaceWith());
1938 searchFlags = searchDialog->getFlags(); 1931 searchFlags = searchDialog->getFlags();
1939 initSearch(s, searchFlags); 1932 initSearch(s, searchFlags);
1940 replaceAgain(); 1933 replaceAgain();
1941 } 1934 }
1942 delete searchDialog; 1935 delete searchDialog;
1943} 1936}
1944 1937
1945void KateView::gotoLine() { 1938void KateView::gotoLine() {
1946 GotoLineDialog *dlg; 1939 GotoLineDialog *dlg;
1947 PointStruc cursor; 1940 PointStruc cursor;
1948 1941
1949 dlg = new GotoLineDialog(this, myViewInternal->cursor.y + 1, myDoc->numLines()); 1942 dlg = new GotoLineDialog(this, myViewInternal->cursor.y + 1, myDoc->numLines());
1950// dlg = new GotoLineDialog(myViewInternal->cursor.y + 1, this); 1943// dlg = new GotoLineDialog(myViewInternal->cursor.y + 1, this);
1951 1944
1952 if (dlg->exec() == QDialog::Accepted) { 1945 if (dlg->exec() == QDialog::Accepted) {
1953// myDoc->recordReset(); 1946// myDoc->recordReset();
1954 cursor.x = 0; 1947 cursor.x = 0;
1955 cursor.y = dlg->getLine() - 1; 1948 cursor.y = dlg->getLine() - 1;
1956 myDoc->needPreHighlight(cursor.y); 1949 myDoc->needPreHighlight(cursor.y);
1957 myViewInternal->updateCursor(cursor); 1950 myViewInternal->updateCursor(cursor);
1958 myViewInternal->center(); 1951 myViewInternal->center();
1959 myViewInternal->updateView(KateView::ufUpdateOnScroll); 1952 myViewInternal->updateView(KateView::ufUpdateOnScroll);
1960 myDoc->updateViews(this); //uptade all other views except this one 1953 myDoc->updateViews(this); //uptade all other views except this one
1961 } 1954 }
1962 delete dlg; 1955 delete dlg;
1963} 1956}
1964 1957
1965 1958
1966void KateView::initSearch(SConfig &s, int flags) { 1959void KateView::initSearch(SConfig &s, int flags) {
1967 1960
1968 s.flags = flags; 1961 s.flags = flags;
1969 s.setPattern(myDoc->searchForList.first()); 1962 s.setPattern(myDoc->searchForList.first());
1970 1963
1971 if (!(s.flags & KateView::sfFromBeginning)) { 1964 if (!(s.flags & KateView::sfFromBeginning)) {
1972 // If we are continuing a backward search, make sure we do not get stuck 1965 // If we are continuing a backward search, make sure we do not get stuck
1973 // at an existing match. 1966 // at an existing match.
1974 s.cursor = myViewInternal->cursor; 1967 s.cursor = myViewInternal->cursor;
1975 TextLine::Ptr textLine = myDoc->getTextLine(s.cursor.y); 1968 TextLine::Ptr textLine = myDoc->getTextLine(s.cursor.y);
1976 QString const txt(textLine->getText(),textLine->length()); 1969 QString const txt(textLine->getText(),textLine->length());
1977 const QString searchFor= myDoc->searchForList.first(); 1970 const QString searchFor= myDoc->searchForList.first();
1978 int pos = s.cursor.x-searchFor.length()-1; 1971 int pos = s.cursor.x-searchFor.length()-1;
1979 if ( pos < 0 ) pos = 0; 1972 if ( pos < 0 ) pos = 0;
1980 pos= txt.find(searchFor, pos, s.flags & KateView::sfCaseSensitive); 1973 pos= txt.find(searchFor, pos, s.flags & KateView::sfCaseSensitive);
1981 if ( s.flags & KateView::sfBackward ) 1974 if ( s.flags & KateView::sfBackward )
1982 { 1975 {
1983 if ( pos <= s.cursor.x ) s.cursor.x= pos-1; 1976 if ( pos <= s.cursor.x ) s.cursor.x= pos-1;
1984 } 1977 }
1985 else 1978 else
1986 if ( pos == s.cursor.x ) s.cursor.x++; 1979 if ( pos == s.cursor.x ) s.cursor.x++;
1987 } else { 1980 } else {
1988 if (!(s.flags & KateView::sfBackward)) { 1981 if (!(s.flags & KateView::sfBackward)) {
1989 s.cursor.x = 0; 1982 s.cursor.x = 0;
1990 s.cursor.y = 0; 1983 s.cursor.y = 0;
1991 } else { 1984 } else {
1992 s.cursor.x = -1; 1985 s.cursor.x = -1;
1993 s.cursor.y = myDoc->lastLine(); 1986 s.cursor.y = myDoc->lastLine();
1994 } 1987 }
1995 s.flags |= KateView::sfFinished; 1988 s.flags |= KateView::sfFinished;
1996 } 1989 }
1997 if (!(s.flags & KateView::sfBackward)) { 1990 if (!(s.flags & KateView::sfBackward)) {
1998 if (!(s.cursor.x || s.cursor.y)) 1991 if (!(s.cursor.x || s.cursor.y))
1999 s.flags |= KateView::sfFinished; 1992 s.flags |= KateView::sfFinished;
2000 } 1993 }
2001 s.startCursor = s.cursor; 1994 s.startCursor = s.cursor;
2002} 1995}
2003 1996
2004void KateView::continueSearch(SConfig &s) { 1997void KateView::continueSearch(SConfig &s) {
2005 1998
2006 if (!(s.flags & KateView::sfBackward)) { 1999 if (!(s.flags & KateView::sfBackward)) {
2007 s.cursor.x = 0; 2000 s.cursor.x = 0;
2008 s.cursor.y = 0; 2001 s.cursor.y = 0;
2009 } else { 2002 } else {
2010 s.cursor.x = -1; 2003 s.cursor.x = -1;
2011 s.cursor.y = myDoc->lastLine(); 2004 s.cursor.y = myDoc->lastLine();
2012 } 2005 }
2013 s.flags |= KateView::sfFinished; 2006 s.flags |= KateView::sfFinished;
2014 s.flags &= ~KateView::sfAgain; 2007 s.flags &= ~KateView::sfAgain;
2015} 2008}
2016 2009
2017void KateView::findAgain(SConfig &s) { 2010void KateView::findAgain(SConfig &s) {
2018 int query; 2011 int query;
2019 PointStruc cursor; 2012 PointStruc cursor;
2020 QString str; 2013 QString str;
2021 2014
2022 QString searchFor = myDoc->searchForList.first(); 2015 QString searchFor = myDoc->searchForList.first();
2023 2016
2024 if( searchFor.isEmpty() ) { 2017 if( searchFor.isEmpty() ) {
2025 find(); 2018 find();
2026 return; 2019 return;
2027 } 2020 }
2028 2021
2029 do { 2022 do {
2030 query = KMessageBox::Cancel; 2023 query = KMessageBox::Cancel;
2031 if (myDoc->doSearch(s,searchFor)) { 2024 if (myDoc->doSearch(s,searchFor)) {
2032 cursor = s.cursor; 2025 cursor = s.cursor;
2033 if (!(s.flags & KateView::sfBackward)) 2026 if (!(s.flags & KateView::sfBackward))
2034 s.cursor.x += s.matchedLength; 2027 s.cursor.x += s.matchedLength;
2035 myViewInternal->updateCursor(s.cursor); //does deselectAll() 2028 myViewInternal->updateCursor(s.cursor); //does deselectAll()
2036 exposeFound(cursor,s.matchedLength,(s.flags & KateView::sfAgain) ? 0 : KateView::ufUpdateOnScroll,false); 2029 exposeFound(cursor,s.matchedLength,(s.flags & KateView::sfAgain) ? 0 : KateView::ufUpdateOnScroll,false);
2037 } else { 2030 } else {
2038 if (!(s.flags & KateView::sfFinished)) { 2031 if (!(s.flags & KateView::sfFinished)) {
2039 // ask for continue 2032 // ask for continue
2040 if (!(s.flags & KateView::sfBackward)) { 2033 if (!(s.flags & KateView::sfBackward)) {
2041 // forward search 2034 // forward search
2042 str = i18n("End of document reached.\n" 2035 str = i18n("End of document reached.\n"
2043 "Continue from the beginning?"); 2036 "Continue from the beginning?");
2044 query = KMessageBox::warningContinueCancel(this, 2037 query = KMessageBox::warningContinueCancel(this,
2045 str, i18n("Find"), i18n("Continue")); 2038 str, i18n("Find"), i18n("Continue"));
2046 } else { 2039 } else {
2047 // backward search 2040 // backward search
2048 str = i18n("Beginning of document reached.\n" 2041 str = i18n("Beginning of document reached.\n"
2049 "Continue from the end?"); 2042 "Continue from the end?");
2050 query = KMessageBox::warningContinueCancel(this, 2043 query = KMessageBox::warningContinueCancel(this,
2051 str, i18n("Find"), i18n("Continue")); 2044 str, i18n("Find"), i18n("Continue"));
2052 } 2045 }
2053 continueSearch(s); 2046 continueSearch(s);
2054 } else { 2047 } else {
2055 // wrapped 2048 // wrapped
2056 KMessageBox::sorry(this, 2049 KMessageBox::sorry(this,
2057 i18n("Search string '%1' not found!").arg(searchFor), 2050 i18n("Search string '%1' not found!").arg(searchFor),
2058 i18n("Find")); 2051 i18n("Find"));
2059 } 2052 }
2060 } 2053 }
2061 } while (query == KMessageBox::Continue); 2054 } while (query == KMessageBox::Continue);
2062} 2055}
2063 2056
2064void KateView::replaceAgain() { 2057void KateView::replaceAgain() {
2065 if (isReadOnly()) 2058 if (isReadOnly())
2066 return; 2059 return;
2067 2060
2068 replaces = 0; 2061 replaces = 0;
2069 if (s.flags & KateView::sfPrompt) { 2062 if (s.flags & KateView::sfPrompt) {
2070 doReplaceAction(-1); 2063 doReplaceAction(-1);
2071 } else { 2064 } else {
2072 doReplaceAction(KateView::srAll); 2065 doReplaceAction(KateView::srAll);
2073 } 2066 }
2074} 2067}
2075 2068
2076void KateView::doReplaceAction(int result, bool found) { 2069void KateView::doReplaceAction(int result, bool found) {
2077 int rlen; 2070 int rlen;
2078 PointStruc cursor; 2071 PointStruc cursor;
2079 bool started; 2072 bool started;
2080 2073
2081 QString searchFor = myDoc->searchForList.first(); 2074 QString searchFor = myDoc->searchForList.first();
2082 QString replaceWith = myDoc->replaceWithList.first(); 2075 QString replaceWith = myDoc->replaceWithList.first();
2083 rlen = replaceWith.length(); 2076 rlen = replaceWith.length();
2084 2077
2085 switch (result) { 2078 switch (result) {
2086 case KateView::srYes: //yes 2079 case KateView::srYes: //yes
2087 myDoc->recordStart(this, s.cursor, configFlags, 2080 myDoc->recordStart(this, s.cursor, configFlags,
2088 KateActionGroup::ugReplace, true); 2081 KateActionGroup::ugReplace, true);
2089 myDoc->recordReplace(s.cursor, s.matchedLength, replaceWith); 2082 myDoc->recordReplace(s.cursor, s.matchedLength, replaceWith);
2090 replaces++; 2083 replaces++;
2091 if (s.cursor.y == s.startCursor.y && s.cursor.x < s.startCursor.x) 2084 if (s.cursor.y == s.startCursor.y && s.cursor.x < s.startCursor.x)
2092 s.startCursor.x += rlen - s.matchedLength; 2085 s.startCursor.x += rlen - s.matchedLength;
2093 if (!(s.flags & KateView::sfBackward)) s.cursor.x += rlen; 2086 if (!(s.flags & KateView::sfBackward)) s.cursor.x += rlen;
2094 myDoc->recordEnd(this, s.cursor, configFlags | KateView::cfPersistent); 2087 myDoc->recordEnd(this, s.cursor, configFlags | KateView::cfPersistent);
2095 break; 2088 break;
2096 case KateView::srNo: //no 2089 case KateView::srNo: //no
2097 if (!(s.flags & KateView::sfBackward)) s.cursor.x += s.matchedLength; 2090 if (!(s.flags & KateView::sfBackward)) s.cursor.x += s.matchedLength;
2098 break; 2091 break;
2099 case KateView::srAll: //replace all 2092 case KateView::srAll: //replace all
2100 deleteReplacePrompt(); 2093 deleteReplacePrompt();
2101 do { 2094 do {
2102 started = false; 2095 started = false;
2103 while (found || myDoc->doSearch(s,searchFor)) { 2096 while (found || myDoc->doSearch(s,searchFor)) {
2104 if (!started) { 2097 if (!started) {
2105 found = false; 2098 found = false;
2106 myDoc->recordStart(this, s.cursor, configFlags, 2099 myDoc->recordStart(this, s.cursor, configFlags,
2107 KateActionGroup::ugReplace); 2100 KateActionGroup::ugReplace);
2108 started = true; 2101 started = true;
2109 } 2102 }
2110 myDoc->recordReplace(s.cursor, s.matchedLength, replaceWith); 2103 myDoc->recordReplace(s.cursor, s.matchedLength, replaceWith);
2111 replaces++; 2104 replaces++;
2112 if (s.cursor.y == s.startCursor.y && s.cursor.x < s.startCursor.x) 2105 if (s.cursor.y == s.startCursor.y && s.cursor.x < s.startCursor.x)
2113 s.startCursor.x += rlen - s.matchedLength; 2106 s.startCursor.x += rlen - s.matchedLength;
2114 if (!(s.flags & KateView::sfBackward)) s.cursor.x += rlen; 2107 if (!(s.flags & KateView::sfBackward)) s.cursor.x += rlen;
2115 } 2108 }
2116 if (started) myDoc->recordEnd(this, s.cursor, 2109 if (started) myDoc->recordEnd(this, s.cursor,
2117 configFlags | KateView::cfPersistent); 2110 configFlags | KateView::cfPersistent);
2118 } while (!askReplaceEnd()); 2111 } while (!askReplaceEnd());
2119 return; 2112 return;
2120 case KateView::srCancel: //cancel 2113 case KateView::srCancel: //cancel
2121 deleteReplacePrompt(); 2114 deleteReplacePrompt();
2122 return; 2115 return;
2123 default: 2116 default:
2124 replacePrompt = 0L; 2117 replacePrompt = 0L;
2125 } 2118 }
2126 2119
2127 do { 2120 do {
2128 if (myDoc->doSearch(s,searchFor)) { 2121 if (myDoc->doSearch(s,searchFor)) {
2129 //text found: highlight it, show replace prompt if needed and exit 2122 //text found: highlight it, show replace prompt if needed and exit
2130 cursor = s.cursor; 2123 cursor = s.cursor;
2131 if (!(s.flags & KateView::sfBackward)) cursor.x += s.matchedLength; 2124 if (!(s.flags & KateView::sfBackward)) cursor.x += s.matchedLength;
2132 myViewInternal->updateCursor(cursor); //does deselectAll() 2125 myViewInternal->updateCursor(cursor); //does deselectAll()
2133 exposeFound(s.cursor,s.matchedLength,(s.flags & KateView::sfAgain) ? 0 : KateView::ufUpdateOnScroll,true); 2126 exposeFound(s.cursor,s.matchedLength,(s.flags & KateView::sfAgain) ? 0 : KateView::ufUpdateOnScroll,true);
2134 if (replacePrompt == 0L) { 2127 if (replacePrompt == 0L) {
2135 replacePrompt = new ReplacePrompt(this); 2128 replacePrompt = new ReplacePrompt(this);
2136 myDoc->setPseudoModal(replacePrompt);//disable(); 2129 myDoc->setPseudoModal(replacePrompt);//disable();
2137 connect(replacePrompt,SIGNAL(clicked()),this,SLOT(replaceSlot())); 2130 connect(replacePrompt,SIGNAL(clicked()),this,SLOT(replaceSlot()));
2138 replacePrompt->show(); //this is not modal 2131 replacePrompt->show(); //this is not modal
2139 } 2132 }
2140 return; //exit if text found 2133 return; //exit if text found
2141 } 2134 }
2142 //nothing found: repeat until user cancels "repeat from beginning" dialog 2135 //nothing found: repeat until user cancels "repeat from beginning" dialog
2143 } while (!askReplaceEnd()); 2136 } while (!askReplaceEnd());
2144 deleteReplacePrompt(); 2137 deleteReplacePrompt();
2145} 2138}
2146 2139
2147void KateView::exposeFound(PointStruc &cursor, int slen, int flags, bool replace) { 2140void KateView::exposeFound(PointStruc &cursor, int slen, int flags, bool replace) {
2148 int x1, x2, y1, y2, xPos, yPos; 2141 int x1, x2, y1, y2, xPos, yPos;
2149 2142
2150 VConfig c; 2143 VConfig c;
2151 myViewInternal->getVConfig(c); 2144 myViewInternal->getVConfig(c);
2152 myDoc->selectLength(cursor,slen,c.flags); 2145 myDoc->selectLength(cursor,slen,c.flags);
2153 2146
2154 TextLine::Ptr textLine = myDoc->getTextLine(cursor.y); 2147 TextLine::Ptr textLine = myDoc->getTextLine(cursor.y);
2155 x1 = myDoc->textWidth(textLine,cursor.x) -10; 2148 x1 = myDoc->textWidth(textLine,cursor.x) -10;
2156 x2 = myDoc->textWidth(textLine,cursor.x + slen) +20; 2149 x2 = myDoc->textWidth(textLine,cursor.x + slen) +20;
2157 y1 = myDoc->fontHeight*cursor.y -10; 2150 y1 = myDoc->fontHeight*cursor.y -10;
2158 y2 = y1 + myDoc->fontHeight +30; 2151 y2 = y1 + myDoc->fontHeight +30;
2159 2152
2160 xPos = myViewInternal->xPos; 2153 xPos = myViewInternal->xPos;
2161 yPos = myViewInternal->yPos; 2154 yPos = myViewInternal->yPos;
2162 2155
2163 if (x1 < 0) x1 = 0; 2156 if (x1 < 0) x1 = 0;
2164 if (replace) y2 += 90; 2157 if (replace) y2 += 90;
2165 2158
2166 if (x1 < xPos || x2 > xPos + myViewInternal->width()) { 2159 if (x1 < xPos || x2 > xPos + myViewInternal->width()) {
2167 xPos = x2 - myViewInternal->width(); 2160 xPos = x2 - myViewInternal->width();
2168 } 2161 }
2169 if (y1 < yPos || y2 > yPos + myViewInternal->height()) { 2162 if (y1 < yPos || y2 > yPos + myViewInternal->height()) {
2170 xPos = x2 - myViewInternal->width(); 2163 xPos = x2 - myViewInternal->width();
2171 yPos = myDoc->fontHeight*cursor.y - height()/3; 2164 yPos = myDoc->fontHeight*cursor.y - height()/3;
2172 } 2165 }
2173 myViewInternal->setPos(xPos, yPos); 2166 myViewInternal->setPos(xPos, yPos);
2174 myViewInternal->updateView(flags);// | ufPos,xPos,yPos); 2167 myViewInternal->updateView(flags);// | ufPos,xPos,yPos);
2175 myDoc->updateViews(this); 2168 myDoc->updateViews(this);
2176} 2169}
2177 2170
2178void KateView::deleteReplacePrompt() { 2171void KateView::deleteReplacePrompt() {
2179 myDoc->setPseudoModal(0L); 2172 myDoc->setPseudoModal(0L);
2180} 2173}
2181 2174
2182bool KateView::askReplaceEnd() { 2175bool KateView::askReplaceEnd() {
2183 QString str; 2176 QString str;
2184 int query; 2177 int query;
2185 2178
2186 myDoc->updateViews(); 2179 myDoc->updateViews();
2187 if (s.flags & KateView::sfFinished) { 2180 if (s.flags & KateView::sfFinished) {
2188 // replace finished 2181 // replace finished
2189 str = i18n("%1 replacement(s) made").arg(replaces); 2182 str = i18n("%1 replacement(s) made").arg(replaces);
2190 KMessageBox::information(this, str, i18n("Replace")); 2183 KMessageBox::information(this, str, i18n("Replace"));
2191 return true; 2184 return true;
2192 } 2185 }
2193 2186
2194 // ask for continue 2187 // ask for continue
2195 if (!(s.flags & KateView::sfBackward)) { 2188 if (!(s.flags & KateView::sfBackward)) {
2196 // forward search 2189 // forward search
2197 str = i18n("%1 replacement(s) made.\n" 2190 str = i18n("%1 replacement(s) made.\n"
2198 "End of document reached.\n" 2191 "End of document reached.\n"
2199 "Continue from the beginning?").arg(replaces); 2192 "Continue from the beginning?").arg(replaces);
2200 query = KMessageBox::questionYesNo(this, str, i18n("Replace"), 2193 query = KMessageBox::questionYesNo(this, str, i18n("Replace"),
2201 i18n("Continue"), i18n("Stop")); 2194 i18n("Continue"), i18n("Stop"));
2202 } else { 2195 } else {
2203 // backward search 2196 // backward search
2204 str = i18n("%1 replacement(s) made.\n" 2197 str = i18n("%1 replacement(s) made.\n"
2205 "Beginning of document reached.\n" 2198 "Beginning of document reached.\n"
2206 "Continue from the end?").arg(replaces); 2199 "Continue from the end?").arg(replaces);
2207 query = KMessageBox::questionYesNo(this, str, i18n("Replace"), 2200 query = KMessageBox::questionYesNo(this, str, i18n("Replace"),
2208 i18n("Continue"), i18n("Stop")); 2201 i18n("Continue"), i18n("Stop"));
2209 } 2202 }
2210 replaces = 0; 2203 replaces = 0;
2211 continueSearch(s); 2204 continueSearch(s);
2212 return (query == KMessageBox::No); 2205 return (query == KMessageBox::No);
2213} 2206}
2214 2207
2215void KateView::replaceSlot() { 2208void KateView::replaceSlot() {
2216 doReplaceAction(replacePrompt->result(),true); 2209 doReplaceAction(replacePrompt->result(),true);
2217} 2210}
2218 2211
2219void KateView::installPopup(QPopupMenu *rmb_Menu) 2212void KateView::installPopup(QPopupMenu *rmb_Menu)
2220{ 2213{
2221 rmbMenu = rmb_Menu; 2214 rmbMenu = rmb_Menu;
2222} 2215}
2223 2216
2224void KateView::readConfig() 2217void KateView::readConfig()
2225{ 2218{
2226 KateConfig *config = KGlobal::config(); 2219 KateConfig *config = KGlobal::config();
2227 config->setGroup("Kate View"); 2220 config->setGroup("Kate View");
2228 2221
2229 searchFlags = config->readNumEntry("SearchFlags", KateView::sfPrompt); 2222 searchFlags = config->readNumEntry("SearchFlags", KateView::sfPrompt);
2230 configFlags = config->readNumEntry("ConfigFlags", configFlags) & ~KateView::cfMark; 2223 configFlags = config->readNumEntry("ConfigFlags", configFlags) & ~KateView::cfMark;
2231 2224
2232// config->sync(); 2225// config->sync();
2233} 2226}
2234 2227
2235void KateView::writeConfig() 2228void KateView::writeConfig()
2236{ 2229{
2237 KateConfig *config = KGlobal::config(); 2230 KateConfig *config = KGlobal::config();
2238 config->setGroup("Kate View"); 2231 config->setGroup("Kate View");
2239 2232
2240 config->writeEntry("SearchFlags",searchFlags); 2233 config->writeEntry("SearchFlags",searchFlags);
2241 config->writeEntry("ConfigFlags",configFlags); 2234 config->writeEntry("ConfigFlags",configFlags);
2242 2235
2243// config->sync(); 2236// config->sync();
2244} 2237}
2245 2238
2246void KateView::readSessionConfig(KateConfig *config) 2239void KateView::readSessionConfig(KateConfig *config)
2247{ 2240{
2248 PointStruc cursor; 2241 PointStruc cursor;
2249 2242
2250 myViewInternal->xPos = config->readNumEntry("XPos"); 2243 myViewInternal->xPos = config->readNumEntry("XPos");
2251 myViewInternal->yPos = config->readNumEntry("YPos"); 2244 myViewInternal->yPos = config->readNumEntry("YPos");
2252 cursor.x = config->readNumEntry("CursorX"); 2245 cursor.x = config->readNumEntry("CursorX");
2253 cursor.y = config->readNumEntry("CursorY"); 2246 cursor.y = config->readNumEntry("CursorY");
2254 myViewInternal->updateCursor(cursor); 2247 myViewInternal->updateCursor(cursor);
2255 myIconBorder = config->readBoolEntry("IconBorder on"); 2248 myIconBorder = config->readBoolEntry("IconBorder on");
2256 setIconBorder(myIconBorder); 2249 setIconBorder(myIconBorder);
2257} 2250}
2258 2251
2259void KateView::writeSessionConfig(KateConfig *config) 2252void KateView::writeSessionConfig(KateConfig *config)
2260{ 2253{
2261 config->writeEntry("XPos",myViewInternal->xPos); 2254 config->writeEntry("XPos",myViewInternal->xPos);
2262 config->writeEntry("YPos",myViewInternal->yPos); 2255 config->writeEntry("YPos",myViewInternal->yPos);
2263 config->writeEntry("CursorX",myViewInternal->cursor.x); 2256 config->writeEntry("CursorX",myViewInternal->cursor.x);
2264 config->writeEntry("CursorY",myViewInternal->cursor.y); 2257 config->writeEntry("CursorY",myViewInternal->cursor.y);
2265 config->writeEntry("IconBorder on", myIconBorder); 2258 config->writeEntry("IconBorder on", myIconBorder);
2266} 2259}
2267 2260
2268void KateView::configDialog() 2261void KateView::configDialog()
2269{ 2262{
2270 2263
2271#warning fixme 2264#warning fixme
2272 2265
2273#if 1 2266#if 1
2274 KDialogBase *kd = new KDialogBase(KDialogBase::IconList, 2267 KDialogBase *kd = new KDialogBase(KDialogBase::IconList,
2275 i18n("Configure Editor"), 2268 i18n("Configure Editor"),
2276 KDialogBase::Ok | KDialogBase::Cancel | 2269 KDialogBase::Ok | KDialogBase::Cancel |
2277 KDialogBase::Help , 2270 KDialogBase::Help ,
2278 KDialogBase::Ok, this, "tabdialog"); 2271 KDialogBase::Ok, this, "tabdialog");
2279 2272
2280 // color options 2273 // color options
2281 QFrame *page=kd->addPage(i18n("Colors")); 2274 QFrame *page=kd->addPage(i18n("Colors"));
2282 (new QVBoxLayout(page))->setAutoAdd(true); 2275 (new QVBoxLayout(page))->setAutoAdd(true);
2283 ColorConfig *colorConfig = new ColorConfig(page); 2276 ColorConfig *colorConfig = new ColorConfig(page);
2284 QColor* colors = getColors(); 2277 QColor* colors = getColors();
2285 colorConfig->setColors(colors); 2278 colorConfig->setColors(colors);
2286 2279
2287 page = kd->addPage(i18n("Fonts")); 2280 page = kd->addPage(i18n("Fonts"));
2288 (new QVBoxLayout(page))->setAutoAdd(true); 2281 (new QVBoxLayout(page))->setAutoAdd(true);
2289 2282
2290 FontConfig *fontConfig = new FontConfig(page); 2283 FontConfig *fontConfig = new FontConfig(page);
2291 fontConfig->setFont (myDoc->getFont()); 2284 fontConfig->setFont (myDoc->getFont());
2292 2285
2293 // indent options 2286 // indent options
2294 page=kd->addPage(i18n("Indent")); 2287 page=kd->addPage(i18n("Indent"));
2295 (new QVBoxLayout(page))->setAutoAdd(true); 2288 (new QVBoxLayout(page))->setAutoAdd(true);
2296 2289
2297 IndentConfigTab *indentConfig = new IndentConfigTab(page, this); 2290 IndentConfigTab *indentConfig = new IndentConfigTab(page, this);
2298 2291
2299 // select options 2292 // select options
2300 page=kd->addPage(i18n("Select")); 2293 page=kd->addPage(i18n("Select"));
2301 (new QVBoxLayout(page))->setAutoAdd(true); 2294 (new QVBoxLayout(page))->setAutoAdd(true);
2302 2295
2303 SelectConfigTab *selectConfig = new SelectConfigTab(page, this); 2296 SelectConfigTab *selectConfig = new SelectConfigTab(page, this);
2304 2297
2305 // edit options 2298 // edit options
2306 page=kd->addPage(i18n("Edit")); 2299 page=kd->addPage(i18n("Edit"));
2307 (new QVBoxLayout(page))->setAutoAdd(true); 2300 (new QVBoxLayout(page))->setAutoAdd(true);
2308 2301
2309 EditConfigTab *editConfig = new EditConfigTab(page, this); 2302 EditConfigTab *editConfig = new EditConfigTab(page, this);
2310 2303
2311 2304
2312 2305
2313 HighlightDialogPage *hlPage; 2306 HighlightDialogPage *hlPage;
2314 HlManager *hlManager; 2307 HlManager *hlManager;
2315 HlDataList hlDataList; 2308 HlDataList hlDataList;
2316 ItemStyleList defaultStyleList; 2309 ItemStyleList defaultStyleList;
2317 2310
2318 hlManager = HlManager::self(); 2311 hlManager = HlManager::self();
2319 2312
2320 defaultStyleList.setAutoDelete(true); 2313 defaultStyleList.setAutoDelete(true);
2321 hlManager->getDefaults(defaultStyleList); 2314 hlManager->getDefaults(defaultStyleList);
2322 2315
2323 hlDataList.setAutoDelete(true); 2316 hlDataList.setAutoDelete(true);
2324 //this gets the data from the KateConfig object 2317 //this gets the data from the KateConfig object
2325 hlManager->getHlDataList(hlDataList); 2318 hlManager->getHlDataList(hlDataList);
2326 2319
2327 page=kd->addPage(i18n("Highlighting")); 2320 page=kd->addPage(i18n("Highlighting"));
2328 (new QVBoxLayout(page))->setAutoAdd(true); 2321 (new QVBoxLayout(page))->setAutoAdd(true);
2329 2322
2330 hlPage = new HighlightDialogPage(hlManager, &defaultStyleList, &hlDataList, 0, page); 2323 hlPage = new HighlightDialogPage(hlManager, &defaultStyleList, &hlDataList, 0, page);
2331 if ( QPEApplication::execDialog( kd )) { 2324 if ( QPEApplication::execDialog( kd )) {
2332 // color options 2325 // color options
2333 colorConfig->getColors(colors); 2326 colorConfig->getColors(colors);
2334 myDoc->setFont (fontConfig->getFont()); 2327 myDoc->setFont (fontConfig->getFont());
2335 2328
2336 applyColors(); 2329 applyColors();
2337 // indent options 2330 // indent options
2338 indentConfig->getData(this); 2331 indentConfig->getData(this);
2339 // select options 2332 // select options
2340 selectConfig->getData(this); 2333 selectConfig->getData(this);
2341 // edit options 2334 // edit options
2342 editConfig->getData(this); 2335 editConfig->getData(this);
2343 // spell checker 2336 // spell checker
2344 hlManager->setHlDataList(hlDataList); 2337 hlManager->setHlDataList(hlDataList);
2345 hlManager->setDefaults(defaultStyleList); 2338 hlManager->setDefaults(defaultStyleList);
2346 hlPage->saveData(); 2339 hlPage->saveData();
2347 } 2340 }
2348 2341
2349// delete kd; 2342// delete kd;
2350 2343
2351#endif 2344#endif
2352} 2345}
2353 2346
2354int KateView::getHl() { 2347int KateView::getHl() {
2355 return myDoc->highlightNum(); 2348 return myDoc->highlightNum();
2356} 2349}
2357 2350
2358void KateView::setDontChangeHlOnSave() 2351void KateView::setDontChangeHlOnSave()
2359{ 2352{
2360 myDoc->setDontChangeHlOnSave(); 2353 myDoc->setDontChangeHlOnSave();
2361} 2354}
2362 2355
2363void KateView::setHl(int n) { 2356void KateView::setHl(int n) {
2364 myDoc->setHighlight(n); 2357 myDoc->setHighlight(n);
2365 myDoc->setDontChangeHlOnSave(); 2358 myDoc->setDontChangeHlOnSave();
2366 myDoc->updateViews(); 2359 myDoc->updateViews();
2367} 2360}
2368 2361
2369int KateView::getEol() { 2362int KateView::getEol() {
2370 return myDoc->eolMode; 2363 return myDoc->eolMode;
2371} 2364}
2372 2365
2373void KateView::setEol(int eol) { 2366void KateView::setEol(int eol) {
2374 if (isReadOnly()) 2367 if (isReadOnly())
2375 return; 2368 return;
2376 2369
2377 myDoc->eolMode = eol; 2370 myDoc->eolMode = eol;
2378 myDoc->setModified(true); 2371 myDoc->setModified(true);
2379} 2372}
2380 2373
2381 2374
2382 2375
2383void KateView::paintEvent(QPaintEvent *e) { 2376void KateView::paintEvent(QPaintEvent *e) {
2384 int x, y; 2377 int x, y;
2385 2378
2386 QRect updateR = e->rect(); // update rectangle 2379 QRect updateR = e->rect(); // update rectangle
2387// debug("Update rect = ( %i, %i, %i, %i )", 2380// debug("Update rect = ( %i, %i, %i, %i )",
2388// updateR.x(),updateR.y(), updateR.width(), updateR.height() ); 2381// updateR.x(),updateR.y(), updateR.width(), updateR.height() );
2389 2382
2390 int ux1 = updateR.x(); 2383 int ux1 = updateR.x();
2391 int uy1 = updateR.y(); 2384 int uy1 = updateR.y();
2392 int ux2 = ux1 + updateR.width(); 2385 int ux2 = ux1 + updateR.width();
2393 int uy2 = uy1 + updateR.height(); 2386 int uy2 = uy1 + updateR.height();
2394 2387
2395 QPainter paint; 2388 QPainter paint;
2396 paint.begin(this); 2389 paint.begin(this);
2397 2390
2398 QColorGroup g = colorGroup(); 2391 QColorGroup g = colorGroup();
2399 x = width(); 2392 x = width();
2400 y = height(); 2393 y = height();
2401 2394
2402 paint.setPen(g.dark()); 2395 paint.setPen(g.dark());
2403 if (uy1 <= 0) paint.drawLine(0,0,x-2,0); 2396 if (uy1 <= 0) paint.drawLine(0,0,x-2,0);
2404 if (ux1 <= 0) paint.drawLine(0,1,0,y-2); 2397 if (ux1 <= 0) paint.drawLine(0,1,0,y-2);
2405 2398
2406 paint.setPen(black); 2399 paint.setPen(black);
2407 if (uy1 <= 1) paint.drawLine(1,1,x-3,1); 2400 if (uy1 <= 1) paint.drawLine(1,1,x-3,1);
2408 if (ux1 <= 1) paint.drawLine(1,2,1,y-3); 2401 if (ux1 <= 1) paint.drawLine(1,2,1,y-3);
2409 2402
2410 paint.setPen(g.midlight()); 2403 paint.setPen(g.midlight());
2411 if (uy2 >= y-1) paint.drawLine(1,y-2,x-3,y-2); 2404 if (uy2 >= y-1) paint.drawLine(1,y-2,x-3,y-2);
2412 if (ux2 >= x-1) paint.drawLine(x-2,1,x-2,y-2); 2405 if (ux2 >= x-1) paint.drawLine(x-2,1,x-2,y-2);
2413 2406
2414 paint.setPen(g.light()); 2407 paint.setPen(g.light());
2415 if (uy2 >= y) paint.drawLine(0,y-1,x-2,y-1); 2408 if (uy2 >= y) paint.drawLine(0,y-1,x-2,y-1);
2416 if (ux2 >= x) paint.drawLine(x-1,0,x-1,y-1); 2409 if (ux2 >= x) paint.drawLine(x-1,0,x-1,y-1);
2417 2410
2418 x -= 2 + 16; 2411 x -= 2 + 16;
2419 y -= 2 + 16; 2412 y -= 2 + 16;
2420 if (ux2 > x && uy2 > y) { 2413 if (ux2 > x && uy2 > y) {
2421 paint.fillRect(x,y,16,16,g.background()); 2414 paint.fillRect(x,y,16,16,g.background());
2422 } 2415 }
2423 paint.end(); 2416 paint.end();
2424} 2417}
2425 2418
2426void KateView::resizeEvent(QResizeEvent *) { 2419void KateView::resizeEvent(QResizeEvent *) {
2427 2420
2428// debug("Resize %d, %d",e->size().width(),e->size().height()); 2421// debug("Resize %d, %d",e->size().width(),e->size().height());
2429 2422
2430//myViewInternal->resize(width() -20, height() -20); 2423//myViewInternal->resize(width() -20, height() -20);
2431 myViewInternal->tagAll(); 2424 myViewInternal->tagAll();
2432 myViewInternal->updateView(0/*ufNoScroll*/); 2425 myViewInternal->updateView(0/*ufNoScroll*/);
2433} 2426}
2434 2427
2435 2428
2436// Applies a new pattern to the search context. 2429// Applies a new pattern to the search context.
2437void SConfig::setPattern(QString &newPattern) { 2430void SConfig::setPattern(QString &newPattern) {
2438 bool regExp = (flags & KateView::sfRegularExpression); 2431 bool regExp = (flags & KateView::sfRegularExpression);
2439 2432
2440 m_pattern = newPattern; 2433 m_pattern = newPattern;
2441 if (regExp) { 2434 if (regExp) {
2442 m_regExp.setCaseSensitive(flags & KateView::sfCaseSensitive); 2435 m_regExp.setCaseSensitive(flags & KateView::sfCaseSensitive);
2443 m_regExp.setPattern(m_pattern); 2436 m_regExp.setPattern(m_pattern);
2444 } 2437 }
2445} 2438}
2446 2439
2447// Applies the search context to the given string, and returns whether a match was found. If one is, 2440// Applies the search context to the given string, and returns whether a match was found. If one is,
2448// the length of the string matched is also returned. 2441// the length of the string matched is also returned.
2449int SConfig::search(QString &text, int index) { 2442int SConfig::search(QString &text, int index) {
2450 bool regExp = (flags & KateView::sfRegularExpression); 2443 bool regExp = (flags & KateView::sfRegularExpression);
2451 bool caseSensitive = (flags & KateView::sfCaseSensitive); 2444 bool caseSensitive = (flags & KateView::sfCaseSensitive);
2452 2445
2453 if (flags & KateView::sfBackward) { 2446 if (flags & KateView::sfBackward) {
2454 if (regExp) { 2447 if (regExp) {
2455 index = text.findRev(m_regExp, index); 2448 index = text.findRev(m_regExp, index);
2456 } 2449 }
2457 else { 2450 else {
2458 index = text.findRev(m_pattern, index, caseSensitive); 2451 index = text.findRev(m_pattern, index, caseSensitive);
2459 } 2452 }
2460 } 2453 }
2461 else { 2454 else {
2462 if (regExp) { 2455 if (regExp) {
2463 index = text.find(m_regExp, index); 2456 index = text.find(m_regExp, index);
2464 } 2457 }
2465 else { 2458 else {
2466 index = text.find(m_pattern, index, caseSensitive); 2459 index = text.find(m_pattern, index, caseSensitive);
2467 } 2460 }
2468 } 2461 }
2469 2462
2470 // Work out the matched length. 2463 // Work out the matched length.
2471 if (index != -1) 2464 if (index != -1)
2472 { 2465 {
2473 if (regExp) { 2466 if (regExp) {
2474 m_regExp.match(text, index, &matchedLength, false); 2467 m_regExp.match(text, index, &matchedLength, false);
2475 } 2468 }
2476 else { 2469 else {
2477 matchedLength = m_pattern.length(); 2470 matchedLength = m_pattern.length();
2478 } 2471 }
2479 } 2472 }
2480 return index; 2473 return index;
2481} 2474}
2482 2475
2483void KateView::setActive (bool b) 2476void KateView::setActive (bool b)
2484{ 2477{
2485 active = b; 2478 active = b;
2486} 2479}
2487 2480
2488bool KateView::isActive () 2481bool KateView::isActive ()
2489{ 2482{
2490 return active; 2483 return active;
2491} 2484}
2492 2485
2493void KateView::setFocus () 2486void KateView::setFocus ()
2494{ 2487{
2495 QWidget::setFocus (); 2488 QWidget::setFocus ();
2496 2489
2497 emit gotFocus (this); 2490 emit gotFocus (this);
2498} 2491}
2499 2492
2500bool KateView::eventFilter (QObject *object, QEvent *event) 2493bool KateView::eventFilter (QObject *object, QEvent *event)
2501{ 2494{
2502 2495
2503 if ( (event->type() == QEvent::FocusIn) ) 2496 if ( (event->type() == QEvent::FocusIn) )
2504 emit gotFocus (this); 2497 emit gotFocus (this);
2505 2498
2506 if ( (event->type() == QEvent::KeyPress) ) 2499 if ( (event->type() == QEvent::KeyPress) )
2507 { 2500 {
2508 QKeyEvent * ke=(QKeyEvent *)event; 2501 QKeyEvent * ke=(QKeyEvent *)event;
2509 2502
2510 if ((ke->key()==Qt::Key_Tab) || (ke->key()==Qt::Key_BackTab)) 2503 if ((ke->key()==Qt::Key_Tab) || (ke->key()==Qt::Key_BackTab))
2511 { 2504 {
2512 myViewInternal->keyPressEvent(ke); 2505 myViewInternal->keyPressEvent(ke);
2513 return true; 2506 return true;
2514 } 2507 }
2515 } 2508 }
2516 return QWidget::eventFilter (object, event); 2509 return QWidget::eventFilter (object, event);
2517} 2510}
2518 2511
2519void KateView::findAgain (bool back) 2512void KateView::findAgain (bool back)
2520{ 2513{
2521 bool b= (searchFlags & sfBackward) > 0; 2514 bool b= (searchFlags & sfBackward) > 0;
2522 initSearch(s, (searchFlags & ((b==back)?~sfBackward:~0) & ~sfFromBeginning) // clear flag for forward searching 2515 initSearch(s, (searchFlags & ((b==back)?~sfBackward:~0) & ~sfFromBeginning) // clear flag for forward searching
2523 | sfPrompt | sfAgain | ((b!=back)?sfBackward:0) ); 2516 | sfPrompt | sfAgain | ((b!=back)?sfBackward:0) );
2524 if (s.flags & sfReplace) 2517 if (s.flags & sfReplace)
2525 replaceAgain(); 2518 replaceAgain();
2526 else 2519 else
2527 KateView::findAgain(s); 2520 KateView::findAgain(s);
2528} 2521}
2529 2522
2530void KateView::slotEditCommand () 2523void KateView::slotEditCommand ()
2531{ 2524{
2532#warning fixme 2525#warning fixme
2533/* 2526/*
2534 bool ok; 2527 bool ok;
2535 QString cmd = KLineEditDlg::getText("Editing Command", "", &ok, this); 2528 QString cmd = KLineEditDlg::getText("Editing Command", "", &ok, this);
2536 2529
2537 if (ok) 2530 if (ok)
2538 myDoc->cmd()->execCmd (cmd, this);*/ 2531 myDoc->cmd()->execCmd (cmd, this);*/
2539} 2532}
2540 2533
2541void KateView::setIconBorder (bool enable) 2534void KateView::setIconBorder (bool enable)
2542{ 2535{
2543 myIconBorder = enable; 2536 myIconBorder = enable;
2544 2537
2545 if (myIconBorder) 2538 if (myIconBorder)
2546 { 2539 {
2547 myViewInternal->move(myViewInternal->iconBorderWidth+2, 2); 2540 myViewInternal->move(myViewInternal->iconBorderWidth+2, 2);
2548 myViewInternal->leftBorder->show(); 2541 myViewInternal->leftBorder->show();
2549 } 2542 }
2550 else 2543 else
2551 { 2544 {
2552 myViewInternal->leftBorder->hide(); 2545 myViewInternal->leftBorder->hide();
2553 myViewInternal->move(2, 2); 2546 myViewInternal->move(2, 2);
2554 } 2547 }
2555} 2548}
2556 2549
2557void KateView::toggleIconBorder () 2550void KateView::toggleIconBorder ()
2558{ 2551{
2559 setIconBorder (!myIconBorder); 2552 setIconBorder (!myIconBorder);
2560} 2553}
2561 2554
2562void KateView::gotoMark (Kate::Mark *mark) 2555void KateView::gotoMark (Kate::Mark *mark)
2563{ 2556{
2564 PointStruc cursor; 2557 PointStruc cursor;
2565 2558
2566 cursor.x = 0; 2559 cursor.x = 0;
2567 cursor.y = mark->line; 2560 cursor.y = mark->line;
2568 myDoc->needPreHighlight(cursor.y); 2561 myDoc->needPreHighlight(cursor.y);
2569 myViewInternal->updateCursor(cursor); 2562 myViewInternal->updateCursor(cursor);
2570 myViewInternal->center(); 2563 myViewInternal->center();
2571 myViewInternal->updateView(KateView::ufUpdateOnScroll); 2564 myViewInternal->updateView(KateView::ufUpdateOnScroll);
2572 myDoc->updateViews(this); 2565 myDoc->updateViews(this);
2573} 2566}
2574 2567
2575void KateView::toggleBookmark () 2568void KateView::toggleBookmark ()
2576{ 2569{
2577 TextLine::Ptr line = myDoc->getTextLine (currentLine()); 2570 TextLine::Ptr line = myDoc->getTextLine (currentLine());
2578 2571
2579 if (line->mark()&KateDocument::Bookmark) 2572 if (line->mark()&KateDocument::Bookmark)
2580 line->delMark(KateDocument::Bookmark); 2573 line->delMark(KateDocument::Bookmark);
2581 else 2574 else
2582 line->addMark(KateDocument::Bookmark); 2575 line->addMark(KateDocument::Bookmark);
2583 2576
2584 myDoc->tagLines (currentLine(), currentLine()); 2577 myDoc->tagLines (currentLine(), currentLine());
2585 myDoc->updateViews(); 2578 myDoc->updateViews();
2586} 2579}
2587 2580
2588void KateView::clearBookmarks() 2581void KateView::clearBookmarks()
2589{ 2582{
2590 QList<Kate::Mark> list = myDoc->marks(); 2583 QList<Kate::Mark> list = myDoc->marks();
2591 for (int i=0; (uint) i < list.count(); i++) 2584 for (int i=0; (uint) i < list.count(); i++)
2592 { 2585 {
2593 if (list.at(i)->type&KateDocument::Bookmark) 2586 if (list.at(i)->type&KateDocument::Bookmark)
2594 { 2587 {
2595 myDoc->getTextLine(list.at(i)->line)->delMark(KateDocument::Bookmark); 2588 myDoc->getTextLine(list.at(i)->line)->delMark(KateDocument::Bookmark);
2596 myDoc->tagLines(list.at(i)->line, list.at(i)->line); 2589 myDoc->tagLines(list.at(i)->line, list.at(i)->line);
2597 } 2590 }
2598 } 2591 }
2599 2592
2600 myDoc->updateViews(); 2593 myDoc->updateViews();
2601} 2594}
2602 2595
2603void KateView::bookmarkMenuAboutToShow() 2596void KateView::bookmarkMenuAboutToShow()
2604{ 2597{
2605#warning fixme 2598#warning fixme
2606#if 0 2599#if 0
2607 bookmarkMenu->popupMenu()->clear (); 2600 bookmarkMenu->popupMenu()->clear ();
2608 bookmarkToggle->plug (bookmarkMenu->popupMenu()); 2601 bookmarkToggle->plug (bookmarkMenu->popupMenu());
2609 bookmarkClear->plug (bookmarkMenu->popupMenu()); 2602 bookmarkClear->plug (bookmarkMenu->popupMenu());
2610 bookmarkMenu->popupMenu()->insertSeparator (); 2603 bookmarkMenu->popupMenu()->insertSeparator ();
2611 2604
2612 list = myDoc->marks(); 2605 list = myDoc->marks();
2613 for (int i=0; (uint) i < list.count(); i++) 2606 for (int i=0; (uint) i < list.count(); i++)
2614 { 2607 {
2615 if (list.at(i)->type&KateDocument::Bookmark) 2608 if (list.at(i)->type&KateDocument::Bookmark)
2616 { 2609 {
2617 QString bText = textLine(list.at(i)->line); 2610 QString bText = textLine(list.at(i)->line);
2618 bText.truncate(32); 2611 bText.truncate(32);
2619 bText.append ("..."); 2612 bText.append ("...");
2620 bookmarkMenu->popupMenu()->insertItem ( QString("%1 - \"%2\"").arg(list.at(i)->line).arg(bText), this, SLOT (gotoBookmark(int)), 0, i ); 2613 bookmarkMenu->popupMenu()->insertItem ( QString("%1 - \"%2\"").arg(list.at(i)->line).arg(bText), this, SLOT (gotoBookmark(int)), 0, i );
2621 } 2614 }
2622 } 2615 }
2623#endif 2616#endif
2624} 2617}
2625 2618
2626void KateView::gotoBookmark (int n) 2619void KateView::gotoBookmark (int n)
2627{ 2620{
2628 gotoMark (list.at(n)); 2621 gotoMark (list.at(n));
2629} 2622}
2630 2623
2631int KateView::getHlCount () 2624int KateView::getHlCount ()
2632{ 2625{
2633 return HlManager::self()->highlights(); 2626 return HlManager::self()->highlights();
2634} 2627}
2635 2628
2636QString KateView::getHlName (int z) 2629QString KateView::getHlName (int z)
2637{ 2630{
2638 return HlManager::self()->hlName(z); 2631 return HlManager::self()->hlName(z);
2639} 2632}
2640 2633
2641QString KateView::getHlSection (int z) 2634QString KateView::getHlSection (int z)
2642{ 2635{
2643 return HlManager::self()->hlSection (z); 2636 return HlManager::self()->hlSection (z);
2644} 2637}
2645 2638
2646void KateView::slotIncFontSizes () 2639void KateView::slotIncFontSizes ()
2647{ 2640{
2648 QFont font = myDoc->getFont(); 2641 QFont font = myDoc->getFont();
2649 font.setPointSize (font.pointSize()+2); 2642 font.setPointSize (font.pointSize()+2);
2650 myDoc->setFont (font); 2643 myDoc->setFont (font);
2651} 2644}
2652 2645
2653void KateView::slotDecFontSizes () 2646void KateView::slotDecFontSizes ()
2654{ 2647{
2655 QFont font = myDoc->getFont(); 2648 QFont font = myDoc->getFont();
2656 font.setPointSize (font.pointSize()-2); 2649 font.setPointSize (font.pointSize()-2);
2657 myDoc->setFont (font); 2650 myDoc->setFont (font);
2658} 2651}
2659 2652
2660const char*bookmark_xpm[]={ 2653const char*bookmark_xpm[]={
2661"12 16 4 1", 2654"12 16 4 1",
2662"b c #808080", 2655"b c #808080",
2663"a c #000080", 2656"a c #000080",
2664"# c #0000ff", 2657"# c #0000ff",
2665". c None", 2658". c None",
2666"............", 2659"............",
2667"............", 2660"............",
2668"........###.", 2661"........###.",
2669".......#...a", 2662".......#...a",
2670"......#.##.a", 2663"......#.##.a",
2671".....#.#..aa", 2664".....#.#..aa",
2672"....#.#...a.", 2665"....#.#...a.",
2673"...#.#.a.a..", 2666"...#.#.a.a..",
2674"..#.#.a.a...", 2667"..#.#.a.a...",
2675".#.#.a.a....", 2668".#.#.a.a....",
2676"#.#.a.a.....", 2669"#.#.a.a.....",
2677"#.#a.a...bbb", 2670"#.#a.a...bbb",
2678"#...a..bbb..", 2671"#...a..bbb..",
2679".aaa.bbb....", 2672".aaa.bbb....",
2680"............", 2673"............",
2681"............"}; 2674"............"};
2682 2675
2683const char* breakpoint_xpm[]={ 2676const char* breakpoint_xpm[]={
2684"11 16 6 1", 2677"11 16 6 1",
2685"c c #c6c6c6", 2678"c c #c6c6c6",
2686". c None", 2679". c None",
2687"# c #000000", 2680"# c #000000",
2688"d c #840000", 2681"d c #840000",
2689"a c #ffffff", 2682"a c #ffffff",
2690"b c #ff0000", 2683"b c #ff0000",
2691"...........", 2684"...........",
2692"...........", 2685"...........",
2693"...#####...", 2686"...#####...",
2694"..#aaaaa#..", 2687"..#aaaaa#..",
2695".#abbbbbb#.", 2688".#abbbbbb#.",
2696"#abbbbbbbb#", 2689"#abbbbbbbb#",
2697"#abcacacbd#", 2690"#abcacacbd#",
2698"#abbbbbbbb#", 2691"#abbbbbbbb#",
2699"#abcacacbd#", 2692"#abcacacbd#",
2700"#abbbbbbbb#", 2693"#abbbbbbbb#",
2701".#bbbbbbb#.", 2694".#bbbbbbb#.",
2702"..#bdbdb#..", 2695"..#bdbdb#..",
2703"...#####...", 2696"...#####...",
2704"...........", 2697"...........",
2705"...........", 2698"...........",
2706"..........."}; 2699"..........."};
2707 2700
2708const char*breakpoint_bl_xpm[]={ 2701const char*breakpoint_bl_xpm[]={
2709"11 16 7 1", 2702"11 16 7 1",
2710"a c #c0c0ff", 2703"a c #c0c0ff",
2711"# c #000000", 2704"# c #000000",
2712"c c #0000c0", 2705"c c #0000c0",
2713"e c #0000ff", 2706"e c #0000ff",
2714"b c #dcdcdc", 2707"b c #dcdcdc",
2715"d c #ffffff", 2708"d c #ffffff",
2716". c None", 2709". c None",
2717"...........", 2710"...........",
2718"...........", 2711"...........",
2719"...#####...", 2712"...#####...",
2720"..#ababa#..", 2713"..#ababa#..",
2721".#bcccccc#.", 2714".#bcccccc#.",
2722"#acccccccc#", 2715"#acccccccc#",
2723"#bcadadace#", 2716"#bcadadace#",
2724"#acccccccc#", 2717"#acccccccc#",
2725"#bcadadace#", 2718"#bcadadace#",
2726"#acccccccc#", 2719"#acccccccc#",
2727".#ccccccc#.", 2720".#ccccccc#.",
2728"..#cecec#..", 2721"..#cecec#..",
2729"...#####...", 2722"...#####...",
2730"...........", 2723"...........",
2731"...........", 2724"...........",
2732"..........."}; 2725"..........."};
2733 2726
2734const char*breakpoint_gr_xpm[]={ 2727const char*breakpoint_gr_xpm[]={
2735"11 16 6 1", 2728"11 16 6 1",
2736"c c #c6c6c6", 2729"c c #c6c6c6",
2737"d c #2c2c2c", 2730"d c #2c2c2c",
2738"# c #000000", 2731"# c #000000",
2739". c None", 2732". c None",
2740"a c #ffffff", 2733"a c #ffffff",
2741"b c #555555", 2734"b c #555555",
2742"...........", 2735"...........",
2743"...........", 2736"...........",
2744"...#####...", 2737"...#####...",
2745"..#aaaaa#..", 2738"..#aaaaa#..",
2746".#abbbbbb#.", 2739".#abbbbbb#.",
2747"#abbbbbbbb#", 2740"#abbbbbbbb#",
2748"#abcacacbd#", 2741"#abcacacbd#",
2749"#abbbbbbbb#", 2742"#abbbbbbbb#",
2750"#abcacacbd#", 2743"#abcacacbd#",
2751"#abbbbbbbb#", 2744"#abbbbbbbb#",
2752".#bbbbbbb#.", 2745".#bbbbbbb#.",
2753"..#bdbdb#..", 2746"..#bdbdb#..",
2754"...#####...", 2747"...#####...",
2755"...........", 2748"...........",
2756"...........", 2749"...........",
2757"..........."}; 2750"..........."};
2758 2751
2759const char*ddd_xpm[]={ 2752const char*ddd_xpm[]={
2760"11 16 4 1", 2753"11 16 4 1",
2761"a c #00ff00", 2754"a c #00ff00",
2762"b c #000000", 2755"b c #000000",
2763". c None", 2756". c None",
2764"# c #00c000", 2757"# c #00c000",
2765"...........", 2758"...........",
2766"...........", 2759"...........",
2767"...........", 2760"...........",
2768"#a.........", 2761"#a.........",
2769"#aaa.......", 2762"#aaa.......",
2770"#aaaaa.....", 2763"#aaaaa.....",
2771"#aaaaaaa...", 2764"#aaaaaaa...",
2772"#aaaaaaaaa.", 2765"#aaaaaaaaa.",
2773"#aaaaaaa#b.", 2766"#aaaaaaa#b.",
2774"#aaaaa#b...", 2767"#aaaaa#b...",
2775"#aaa#b.....", 2768"#aaa#b.....",
2776"#a#b.......", 2769"#a#b.......",
2777"#b.........", 2770"#b.........",
2778"...........", 2771"...........",
2779"...........", 2772"...........",
2780"..........."}; 2773"..........."};
2781 2774
2782 2775
2783 2776
2784KateIconBorder::KateIconBorder(KateView *view, KateViewInternal *internalView) 2777KateIconBorder::KateIconBorder(KateView *view, KateViewInternal *internalView)
2785 : QWidget(view), myView(view), myInternalView(internalView) 2778 : QWidget(view), myView(view), myInternalView(internalView)
2786{ 2779{
2787 lmbSetsBreakpoints = true; 2780 lmbSetsBreakpoints = true;
2788} 2781}
2789 2782
2790KateIconBorder::~KateIconBorder() 2783KateIconBorder::~KateIconBorder()
2791{ 2784{
2792} 2785}
2793 2786
2794void KateIconBorder::paintLine(int i) 2787void KateIconBorder::paintLine(int i)
2795{ 2788{
2796 if (!myView->myIconBorder) return; 2789 if (!myView->myIconBorder) return;
2797 2790
2798 QPainter p(this); 2791 QPainter p(this);
2799 2792
2800 int fontHeight = myView->doc()->fontHeight; 2793 int fontHeight = myView->doc()->fontHeight;
2801 int y = i*fontHeight - myInternalView->yPos; 2794 int y = i*fontHeight - myInternalView->yPos;
2802 p.fillRect(0, y, myInternalView->iconBorderWidth-2, fontHeight, colorGroup().background()); 2795 p.fillRect(0, y, myInternalView->iconBorderWidth-2, fontHeight, colorGroup().background());
2803 p.setPen(white); 2796 p.setPen(white);
2804 p.drawLine(myInternalView->iconBorderWidth-2, y, myInternalView->iconBorderWidth-2, y + fontHeight); 2797 p.drawLine(myInternalView->iconBorderWidth-2, y, myInternalView->iconBorderWidth-2, y + fontHeight);
2805 p.setPen(QColor(colorGroup().background()).dark()); 2798 p.setPen(QColor(colorGroup().background()).dark());
2806 p.drawLine(myInternalView->iconBorderWidth-1, y, myInternalView->iconBorderWidth-1, y + fontHeight); 2799 p.drawLine(myInternalView->iconBorderWidth-1, y, myInternalView->iconBorderWidth-1, y + fontHeight);
2807 2800
2808 TextLine *line = myView->doc()->getTextLine(i); 2801 TextLine *line = myView->doc()->getTextLine(i);
2809 if (!line) 2802 if (!line)
2810 return; 2803 return;
2811 2804
2812 if (line->mark()&KateDocument::Bookmark) 2805 if (line->mark()&KateDocument::Bookmark)
2813 p.drawPixmap(2, y, QPixmap(bookmark_xpm)); /* 2806 p.drawPixmap(2, y, QPixmap(bookmark_xpm)); /*
2814 if (line && (line->breakpointId() != -1)) { 2807 if (line && (line->breakpointId() != -1)) {
2815 if (!line->breakpointEnabled()) 2808 if (!line->breakpointEnabled())
2816 p.drawPixmap(2, y, QPixmap(breakpoint_gr_xpm)); 2809 p.drawPixmap(2, y, QPixmap(breakpoint_gr_xpm));
2817 else if (line->breakpointPending()) 2810 else if (line->breakpointPending())
2818 p.drawPixmap(2, y, QPixmap(breakpoint_bl_xpm)); 2811 p.drawPixmap(2, y, QPixmap(breakpoint_bl_xpm));
2819 else 2812 else
2820 p.drawPixmap(2, y, QPixmap(breakpoint_xpm)); 2813 p.drawPixmap(2, y, QPixmap(breakpoint_xpm));
2821 } 2814 }
2822 if (line->isExecutionPoint()) 2815 if (line->isExecutionPoint())
2823 p.drawPixmap(2, y, QPixmap(ddd_xpm)); */ 2816 p.drawPixmap(2, y, QPixmap(ddd_xpm)); */
2824} 2817}
2825 2818
2826 2819
2827void KateIconBorder::paintEvent(QPaintEvent* e) 2820void KateIconBorder::paintEvent(QPaintEvent* e)
2828{ 2821{
2829 if (!myView->myIconBorder) return; 2822 if (!myView->myIconBorder) return;
2830 2823
2831 int lineStart = 0; 2824 int lineStart = 0;
2832 int lineEnd = 0; 2825 int lineEnd = 0;
2833 2826
2834 QRect updateR = e->rect(); 2827 QRect updateR = e->rect();
2835 2828
2836 KateDocument *doc = myView->doc(); 2829 KateDocument *doc = myView->doc();
2837 int h = doc->fontHeight; 2830 int h = doc->fontHeight;
2838 int yPos = myInternalView->yPos; 2831 int yPos = myInternalView->yPos;
2839 if (h) { 2832 if (h) {
2840 lineStart = (yPos + updateR.y()) / h; 2833 lineStart = (yPos + updateR.y()) / h;
2841 lineEnd = QMAX((yPos + updateR.y() + updateR.height()) / h, (int)doc->numLines()); 2834 lineEnd = QMAX((yPos + updateR.y() + updateR.height()) / h, (int)doc->numLines());
2842 } 2835 }
2843 2836
2844 for(int i = lineStart; i <= lineEnd; ++i) 2837 for(int i = lineStart; i <= lineEnd; ++i)
2845 paintLine(i); 2838 paintLine(i);
2846} 2839}
2847 2840
2848 2841
2849void KateIconBorder::mousePressEvent(QMouseEvent* e) 2842void KateIconBorder::mousePressEvent(QMouseEvent* e)
2850{ 2843{
2851 myInternalView->placeCursor( 0, e->y(), 0 ); 2844 myInternalView->placeCursor( 0, e->y(), 0 );
2852 2845
2853 KateDocument *doc = myView->doc(); 2846 KateDocument *doc = myView->doc();
2854 int cursorOnLine = (e->y() + myInternalView->yPos) / doc->fontHeight; 2847 int cursorOnLine = (e->y() + myInternalView->yPos) / doc->fontHeight;
2855 TextLine *line = doc->getTextLine(cursorOnLine); 2848 TextLine *line = doc->getTextLine(cursorOnLine);
2856 2849
2857 switch (e->button()) { 2850 switch (e->button()) {
2858 case LeftButton: 2851 case LeftButton:
2859 if (!line) 2852 if (!line)
2860 break; 2853 break;
2861 else 2854 else
2862 { 2855 {
2863 if (line->mark()&KateDocument::Bookmark) 2856 if (line->mark()&KateDocument::Bookmark)
2864 line->delMark (KateDocument::Bookmark); 2857 line->delMark (KateDocument::Bookmark);
2865 else 2858 else
2866 line->addMark (KateDocument::Bookmark); 2859 line->addMark (KateDocument::Bookmark);
2867 2860
2868 doc->tagLines(cursorOnLine, cursorOnLine); 2861 doc->tagLines(cursorOnLine, cursorOnLine);
2869 doc->updateViews(); 2862 doc->updateViews();
2870 } 2863 }
2871 break; 2864 break;
2872 /* case RightButton: 2865 /* case RightButton:
2873 { 2866 {
2874 if (!line) 2867 if (!line)
2875 break; 2868 break;
2876 KPopupMenu popup; 2869 KPopupMenu popup;
2877 popup.setCheckable(true); 2870 popup.setCheckable(true);
2878 popup.insertTitle(i18n("Breakpoints/Bookmarks")); 2871 popup.insertTitle(i18n("Breakpoints/Bookmarks"));
2879 int idToggleBookmark = popup.insertItem(i18n("Toggle bookmark")); 2872 int idToggleBookmark = popup.insertItem(i18n("Toggle bookmark"));
2880 popup.insertSeparator(); 2873 popup.insertSeparator();
2881 int idToggleBreakpoint = popup.insertItem(i18n("Toggle breakpoint")); 2874 int idToggleBreakpoint = popup.insertItem(i18n("Toggle breakpoint"));
2882 int idEditBreakpoint = popup.insertItem(i18n("Edit breakpoint")); 2875 int idEditBreakpoint = popup.insertItem(i18n("Edit breakpoint"));
2883 int idEnableBreakpoint = popup.insertItem(i18n("Disable breakpoint")); 2876 int idEnableBreakpoint = popup.insertItem(i18n("Disable breakpoint"));
2884 popup.insertSeparator(); 2877 popup.insertSeparator();
2885 popup.insertSeparator(); 2878 popup.insertSeparator();
2886 int idLmbSetsBreakpoints = popup.insertItem(i18n("LMB sets breakpoints")); 2879 int idLmbSetsBreakpoints = popup.insertItem(i18n("LMB sets breakpoints"));
2887 int idLmbSetsBookmarks = popup.insertItem(i18n("LMB sets bookmarks")); 2880 int idLmbSetsBookmarks = popup.insertItem(i18n("LMB sets bookmarks"));
2888 2881
2889 popup.setItemChecked(idLmbSetsBreakpoints, lmbSetsBreakpoints); 2882 popup.setItemChecked(idLmbSetsBreakpoints, lmbSetsBreakpoints);
2890 popup.setItemChecked(idLmbSetsBookmarks, !lmbSetsBreakpoints); 2883 popup.setItemChecked(idLmbSetsBookmarks, !lmbSetsBreakpoints);
2891 2884
2892 if (line->breakpointId() == -1) { 2885 if (line->breakpointId() == -1) {
2893 popup.setItemEnabled(idEditBreakpoint, false); 2886 popup.setItemEnabled(idEditBreakpoint, false);
2894 popup.setItemEnabled(idEnableBreakpoint, false); 2887 popup.setItemEnabled(idEnableBreakpoint, false);
2895 popup.changeItem(idEnableBreakpoint, i18n("Enable breakpoint")); 2888 popup.changeItem(idEnableBreakpoint, i18n("Enable breakpoint"));
2896 } 2889 }
2897 int res = popup.exec(mapToGlobal(e->pos())); 2890 int res = popup.exec(mapToGlobal(e->pos()));
2898 if (res == idToggleBookmark) { 2891 if (res == idToggleBookmark) {
2899 line->toggleBookmark(); 2892 line->toggleBookmark();
2900 doc->tagLines(cursorOnLine, cursorOnLine); 2893 doc->tagLines(cursorOnLine, cursorOnLine);
2901 doc->updateViews(); 2894 doc->updateViews();
2902 } else if (res == idToggleBreakpoint) 2895 } else if (res == idToggleBreakpoint)
2903 emit myView->toggledBreakpoint(cursorOnLine); 2896 emit myView->toggledBreakpoint(cursorOnLine);
2904 else if (res == idEditBreakpoint) 2897 else if (res == idEditBreakpoint)
2905 emit myView->editedBreakpoint(cursorOnLine); 2898 emit myView->editedBreakpoint(cursorOnLine);
2906 else if (res == idEnableBreakpoint) 2899 else if (res == idEnableBreakpoint)
2907 emit myView->toggledBreakpointEnabled(cursorOnLine+1); 2900 emit myView->toggledBreakpointEnabled(cursorOnLine+1);
2908 else if (res == idLmbSetsBreakpoints || res == idLmbSetsBookmarks) 2901 else if (res == idLmbSetsBreakpoints || res == idLmbSetsBookmarks)
2909 lmbSetsBreakpoints = !lmbSetsBreakpoints; 2902 lmbSetsBreakpoints = !lmbSetsBreakpoints;
2910 break; 2903 break;
2911 } 2904 }
2912 case MidButton: 2905 case MidButton:
2913 line->toggleBookmark(); 2906 line->toggleBookmark();
2914 doc->tagLines(cursorOnLine, cursorOnLine); 2907 doc->tagLines(cursorOnLine, cursorOnLine);
2915 doc->updateViews(); 2908 doc->updateViews();
2916 break; */ 2909 break; */
2917 default: 2910 default:
2918 break; 2911 break;
2919 } 2912 }
2920} 2913}
2921 2914
2922 2915
2923 2916
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
52SearchDialog::SearchDialog( QWidget *parent, QStringList &searchFor, QStringList &replaceWith, int flags ) 50SearchDialog::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
124QString SearchDialog::getSearchFor() 122QString SearchDialog::getSearchFor()
125{ 123{
126 return m_search->currentText(); 124 return m_search->currentText();
127} 125}
128 126
129QString SearchDialog::getReplaceWith() 127QString SearchDialog::getReplaceWith()
130{ 128{
131 return m_replace->currentText(); 129 return m_replace->currentText();
132} 130}
133 131
134int SearchDialog::getFlags() 132int 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
155void SearchDialog::slotOk() 153void 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
175void SearchDialog::setSearchText( const QString &searchstr ) 173void 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
183ReplacePrompt::ReplacePrompt( QWidget *parent ) 181ReplacePrompt::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
196void ReplacePrompt::slotUser1( void ) { // All 194void ReplacePrompt::slotUser1( void ) { // All
197 done(KateView::srAll); 195 done(KateView::srAll);
198} 196}
199 197
200void ReplacePrompt::slotUser2( void ) { // No 198void ReplacePrompt::slotUser2( void ) { // No
201 done(KateView::srNo); 199 done(KateView::srNo);
202} 200}
203 201
204void ReplacePrompt::slotUser3( void ) { // Yes 202void ReplacePrompt::slotUser3( void ) { // Yes
205 accept(); 203 accept();
206} 204}
207 205
208void ReplacePrompt::done(int r) { 206void ReplacePrompt::done(int r) {
209 setResult(r); 207 setResult(r);
210 emit clicked(); 208 emit clicked();
211} 209}
212 210
213void ReplacePrompt::closeEvent(QCloseEvent *) { 211void ReplacePrompt::closeEvent(QCloseEvent *) {
214 reject(); 212 reject();
215} 213}
216 214
217GotoLineDialog::GotoLineDialog(QWidget *parent, int line, int max) 215GotoLineDialog::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
237int GotoLineDialog::getLine() { 235int GotoLineDialog::getLine() {
238 return e1->value(); 236 return e1->value();
239} 237}
240 238
241const int IndentConfigTab::flags[] = {KateView::cfAutoIndent, KateView::cfSpaceIndent, 239const 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
244IndentConfigTab::IndentConfigTab(QWidget *parent, KateView *view) 242IndentConfigTab::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
287void IndentConfigTab::getData(KateView *view) { 285void 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
298const int SelectConfigTab::flags[] = {KateView::cfPersistent, KateView::cfDelOnInput, 296const 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
301SelectConfigTab::SelectConfigTab(QWidget *parent, KateView *view) 299SelectConfigTab::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
342void SelectConfigTab::getData(KateView *view) { 340void 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
353const int EditConfigTab::flags[] = {KateView::cfWordWrap, KateView::cfReplaceTabs, KateView::cfRemoveSpaces, 351const 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
357EditConfigTab::EditConfigTab(QWidget *parent, KateView *view) 355EditConfigTab::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
464void EditConfigTab::getData(KateView *view) 462void 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
482ColorConfig::ColorConfig( QWidget *parent, char *name ) 480ColorConfig::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 &quot;<b>Configure Highlighting</b>&quot; dialog.")); 503 QWhatsThis::add(m_selected, i18n("Sets the background color of the selection. To set the text color for selected text, use the &quot;<b>Configure Highlighting</b>&quot; dialog."));
506} 504}
507 505
508 506
509ColorConfig::~ColorConfig() 507ColorConfig::~ColorConfig()
510{ 508{
511} 509}
512 510
513void ColorConfig::setColors(QColor *colors) 511void 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
519void ColorConfig::getColors(QColor *colors) 517void 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
525FontConfig::FontConfig( QWidget *parent, char *name ) 523FontConfig::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
554FontConfig::~FontConfig() 552FontConfig::~FontConfig()
555{ 553{
556} 554}
557 555
558void FontConfig::setFont ( const QFont &font ) 556void FontConfig::setFont ( const QFont &font )
559{ 557{
560//#if 0 558//#if 0
561m_fontselect->setFont (font); 559m_fontselect->setFont (font);
562 myFont = font; 560 myFont = font;
563//#endif 561//#endif
564} 562}
565 563
566void FontConfig::slotFontSelected( const QFont &font ) 564void 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
35TinyKate::TinyKate( QWidget *parent, const char *name, WFlags f) : 30TinyKate::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
157TinyKate::~TinyKate( ) 152TinyKate::~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
172void TinyKate::slotOpen( ) 167void 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
181void TinyKate::open(const QString & filename) 176void 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
195void TinyKate::setDocument(const QString& fileref) 190void TinyKate::setDocument(const QString& fileref)
196{ 191{
197 open( fileref ); 192 open( fileref );
198} 193}
199 194
200void TinyKate::slotCurrentChanged( QWidget * view) 195void 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
229void TinyKate::slotNew( ) 224void 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
239void TinyKate::slotClose( ) 234void 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
250void TinyKate::slotSave() { 245void 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
265void TinyKate::slotSaveAs() { 260void 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
8Category::Category() 7Category::Category()
9{ 8{
10} 9}
11 10
12Category::~Category() 11Category::~Category()
13{ 12{
14} 13}
15 14
16QString Category::getIconName() 15QString Category::getIconName()
17{ 16{
18 return iconName; 17 return iconName;
19} 18}
20 19
21QString Category::getCategoryName() 20QString Category::getCategoryName()
22{ 21{
23 return categoryName; 22 return categoryName;
24} 23}
25 24
26QListViewItem * Category::getListItem() 25QListViewItem * Category::getListItem()
27{ 26{
28 return listItem; 27 return listItem;
29} 28}
30 29
31QPixmap Category::getIcon() 30QPixmap Category::getIcon()
32{ 31{
33 return icon; 32 return icon;
34} 33}
35 34
36void Category::setIconName(QString name) 35void Category::setIconName(QString name)
37{ 36{
38 iconName = name; 37 iconName = name;
39} 38}
40 39
41void Category::setCategoryName(QString name) 40void Category::setCategoryName(QString name)
42{ 41{
43 categoryName = name; 42 categoryName = name;
44} 43}
45 44
46void Category::setListItem(QListViewItem *item) 45void Category::setListItem(QListViewItem *item)
47{ 46{
48 listItem = item; 47 listItem = item;
49} 48}
50 49
51void Category::setIcon(QPixmap item) 50void Category::setIcon(QPixmap item)
52{ 51{
53 icon = item; 52 icon = item;
54} 53}
55 54
56void Category::initListItem() 55void 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
20ZSafe *zs; 19ZSafe *zs;
21#ifdef DESKTOP 20#ifdef DESKTOP
22QApplication *appl; 21QApplication *appl;
23#else 22#else
24QPEApplication *appl; 23QPEApplication *appl;
25#endif 24#endif
26 25
27int DeskW; 26int DeskW;
28int DeskH; 27int DeskH;
29 28
30void suspend (int signum) 29void 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
35void resume (int signum) 34void 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
41int main( int argc, char ** argv ) 40int 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
12QSettings::QSettings(const QString &_fn) 11QSettings::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
38QSettings::~QSettings() 37QSettings::~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
61void QSettings::insertSearchPath (System sys, const QString &str) 60void QSettings::insertSearchPath (System sys, const QString &str)
62{ 61{
63 fn = str; 62 fn = str;
64} 63}
65 64
66QString QSettings::readEntry (const QString &key, const QString &def) 65QString 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
77int QSettings::readNumEntry (const QString &key, int def) 76int 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
84bool QSettings::readBoolEntry (const QString &key, bool def) 83bool 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
94bool QSettings::writeEntry (const QString &key, int val) 93bool 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
103bool QSettings::writeEntry (const QString &key, bool val) 102bool 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
114bool QSettings::writeEntry (const QString &key, const QString &val) 113bool 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
121bool QSettings::writeEntry (const QString &key, const char *val) 120bool 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
128bool QSettings::removeEntry (const QString &key) 127bool 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
134QStringList QSettings::entryList (const QString &key) const 133QStringList 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
24static const char* const image0_data[] = { 19static 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
46static const char* const image1_data[] = { 41static 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
69static const char* const image2_data[] = { 64static 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 */
99ScQtFileDlg::ScQtFileDlg( QWidget* parent, const char* name, bool modal, WFlags fl ) 94ScQtFileDlg::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 */
217ScQtFileDlg::~ScQtFileDlg() 212ScQtFileDlg::~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
222void ScQtFileDlg::slotCancel() 217void ScQtFileDlg::slotCancel()
223{ 218{
224 qWarning( "ScQtFileDlg::slotCancel(): Not implemented yet!" ); 219 qWarning( "ScQtFileDlg::slotCancel(): Not implemented yet!" );
225} 220}
226 221
227void ScQtFileDlg::slotDirComboBoxChanged( int ) 222void 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
232void ScQtFileDlg::slotDoubleClicked(QListViewItem *) 227void 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
237void ScQtFileDlg::slotFileTextChanged( const QString & ) 232void 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
242void ScQtFileDlg::slotMkDir() 237void ScQtFileDlg::slotMkDir()
243{ 238{
244 qWarning( "ScQtFileDlg::slotMkDir(): Not implemented yet!" ); 239 qWarning( "ScQtFileDlg::slotMkDir(): Not implemented yet!" );
245} 240}
246 241
247void ScQtFileDlg::slotOK() 242void ScQtFileDlg::slotOK()
248{ 243{
249 qWarning( "ScQtFileDlg::slotOK(): Not implemented yet!" ); 244 qWarning( "ScQtFileDlg::slotOK(): Not implemented yet!" );
250} 245}
251 246
252void ScQtFileDlg::slotSelectionChanged(QListViewItem *) 247void 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
257void ScQtFileDlg::slotTypeComboBoxChanged( int ) 252void 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 */
36static const char* const file_xpm[]={ 32static 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 */
61static const char * const link_file_xpm[]={ 57static 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 */
91static const char * const closed_xpm[]={ 87static 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 */
117static const char* const cdtoparent_xpm[]={ 113static 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
136ScQtFileEditDlg::ScQtFileEditDlg( QWidget *parent, const char *name, 132ScQtFileEditDlg::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
187ScQtFileEditDlg::~ScQtFileEditDlg() 183ScQtFileEditDlg::~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
216void ScQtFileEditDlg::readIt( ) 212void ScQtFileEditDlg::readIt( )
217{ 213{
218 qfil = readDir( bpath, bfilter ); 214 qfil = readDir( bpath, bfilter );
219 slotShowDir( ); 215 slotShowDir( );
220} 216}
221 217
222void ScQtFileEditDlg::setAutoExtension( bool ex ) 218void ScQtFileEditDlg::setAutoExtension( bool ex )
223{ 219{
224 exflag = ex; 220 exflag = ex;
225} 221}
226 222
227 223
228int ScQtFileEditDlg::checkComboEntryExists( QComboBox *com, const QString &str ) 224int 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
248void ScQtFileEditDlg::initDirCombo( const QString &str ) 244void 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
257void ScQtFileEditDlg::initTypeCombo( const QString &str ) 253void 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
266void ScQtFileEditDlg::insDirCombo( const QString &str ) 262void 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
284void ScQtFileEditDlg::insTypeCombo( const QString &str ) 280void 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
303const QFileInfoList *ScQtFileEditDlg::readDir( const QString &path, const QString &filter ) 299const 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
348QString ScQtFileEditDlg::getResult( ) 344QString 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
364QString ScQtFileEditDlg::getFileName( ) 360QString 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
385void ScQtFileEditDlg::slotShowDir() 381void 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
444void ScQtFileEditDlg::slotDirComboBoxChanged( int item ) 440void 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
454void ScQtFileEditDlg::slotTypeComboBoxChanged( int item ) 450void 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
464void ScQtFileEditDlg::slotFileTextChanged( const QString &txt ) 460void ScQtFileEditDlg::slotFileTextChanged( const QString &txt )
465{ 461{
466 filename = txt; 462 filename = txt;
467} 463}
468 464
469void ScQtFileEditDlg::slotSelectionChanged( QListViewItem *item ) 465void 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
509void ScQtFileEditDlg::slotMkDir( ) 505void 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
524void ScQtFileEditDlg::slotDoubleClicked( QListViewItem *item ) 520void 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
556void ScQtFileEditDlg::autoExtension( ) 552void 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
578void ScQtFileEditDlg::setMode( int mode ) 574void ScQtFileEditDlg::setMode( int mode )
579{ 575{
580 fmode = mode; 576 fmode = mode;
581} 577}
582 578
583void ScQtFileEditDlg::setNFilter( bool ff ) 579void ScQtFileEditDlg::setNFilter( bool ff )
584{ 580{
585 fnfilter = ff; 581 fnfilter = ff;
586} 582}
587 583
588void ScQtFileEditDlg::setFSorting( bool ff ) 584void ScQtFileEditDlg::setFSorting( bool ff )
589{ 585{
590 fsorting = ff; 586 fsorting = ff;
591} 587}
592 588
593void ScQtFileEditDlg::allowMkDir( bool mkdir ) 589void 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
600void ScQtFileEditDlg::slotOK( ) 596void 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
611void ScQtFileEditDlg::slotCancel( ) 607void 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***************************************************************************/
625ScQtFileEdit::ScQtFileEdit( QWidget *parent, const char *name ) 621ScQtFileEdit::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
633ScQtFileEdit::~ScQtFileEdit() 629ScQtFileEdit::~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
641QString ScQtFileEdit::getOpenFileName( QWidget *parent, const char *name, 637QString 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
671QString ScQtFileEdit::getSaveAsFileName( QWidget *parent, const char *name, 667QString 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
701QString ScQtFileEdit::getDirName( QWidget *parent, const char *name, 697QString 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
729QString ScQtFileEdit::mkDir( QWidget *parent, const char *name, 725QString 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
11ZListView::ZListView (ZSafe *zsafe, const char *id) : QListView(zsafe, id) 9ZListView::ZListView (ZSafe *zsafe, const char *id) : QListView(zsafe, id)
12{ 10{
13 zs = zsafe; 11 zs = zsafe;
14} 12}
15 13
16ZListView::~ZListView() 14ZListView::~ZListView()
17{ 15{
18} 16}
19 17
20void ZListView::keyPressEvent ( QKeyEvent *e ) 18void 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,3734 +1,3733 @@
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
33using Opie::OFileDialog; 33using Opie::OFileDialog;
34using Opie::OFileSelector; 34using 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
100extern int DeskW, DeskH; 99extern int DeskW, DeskH;
101#ifdef DESKTOP 100#ifdef DESKTOP
102extern QApplication *appl; 101extern QApplication *appl;
103#else 102#else
104extern QPEApplication *appl; 103extern 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
114const QString APP_KEY="/.zsafe/"; 113const QString APP_KEY="/.zsafe/";
115#else 114#else
116const QString APP_KEY=""; 115const QString APP_KEY="";
117#endif 116#endif
118#else 117#else
119const QString APP_KEY=""; 118const 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
140static const char* const bank_cards_data[] = { 139static 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
174static const char* const passwords_data[] = { 173static 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
213static const char* const software_data[] = { 212static 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
237static const char* const general_data[] = { 236static 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 */
392ZSafe::ZSafe( QWidget* parent, const char* name, bool modal, WFlags fl ) 391ZSafe::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
703const QColor *ZSafe::evenRowColor = &Qt::white; 702const QColor *ZSafe::evenRowColor = &Qt::white;
704// const QColor *ZSafe::oddRowColor = &Qt::lightGray; 703// const QColor *ZSafe::oddRowColor = &Qt::lightGray;
705const QColor *ZSafe::oddRowColor = new QColor(216,240,255); 704const 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 */
710ZSafe::~ZSafe() 709ZSafe::~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
717void ZSafe::slotLoadDocu() 716void ZSafe::slotLoadDocu()
718{ 717{
719 openDocument (filename); 718 openDocument (filename);
720} 719}
721 720
722void ZSafe::deletePwd() 721void 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
750void ZSafe::editPwd() 749void 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
814void ZSafe::newPwd() 813void 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")));
839retype: 838retype:
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)
851 { 850 {
852 QMessageBox::critical( 0, tr("ZSafe"), 851 QMessageBox::critical( 0, tr("ZSafe"),
853 tr("Entry name must be different\nfrom the category name.") ); 852 tr("Entry name must be different\nfrom the category name.") );
854 goto retype; // it's not a good programming style :-) 853 goto retype; // it's not a good programming style :-)
855 } 854 }
856 855
857 modified = true; 856 modified = true;
858 // add the new item 857 // add the new item
859 QListViewItem *i = new ShadedListItem (0, selectedItem); 858 QListViewItem *i = new ShadedListItem (0, selectedItem);
860 i->setOpen (TRUE); 859 i->setOpen (TRUE);
861 860
862 i->setText (0, tr (name)); 861 i->setText (0, tr (name));
863 QString user = dialog->UsernameField->text(); 862 QString user = dialog->UsernameField->text();
864 i->setText (1, tr (user)); 863 i->setText (1, tr (user));
865 QString pwd = dialog->PasswordField->text(); 864 QString pwd = dialog->PasswordField->text();
866 i->setText (2, tr (pwd)); 865 i->setText (2, tr (pwd));
867 QString comment = dialog->CommentField->text(); 866 QString comment = dialog->CommentField->text();
868 comment.replace (QRegExp("\n"), "<br>"); 867 comment.replace (QRegExp("\n"), "<br>");
869 i->setText (3, tr (comment)); 868 i->setText (3, tr (comment));
870 QString f5 = dialog->Field5->text(); 869 QString f5 = dialog->Field5->text();
871 i->setText (4, tr (f5)); 870 i->setText (4, tr (f5));
872 QString f6 = dialog->Field6->text(); 871 QString f6 = dialog->Field6->text();
873 i->setText (5, tr (f6)); 872 i->setText (5, tr (f6));
874 } 873 }
875 874
876 delete dialog; 875 delete dialog;
877 } 876 }
878} 877}
879 878
880void ZSafe::findPwd() 879void ZSafe::findPwd()
881{ 880{
882 881
883 // open the 'Search' dialog 882 // open the 'Search' dialog
884 SearchDialog *dialog = new SearchDialog(this, tr("Search"), TRUE); 883 SearchDialog *dialog = new SearchDialog(this, tr("Search"), TRUE);
885#ifdef WIN32 884#ifdef WIN32
886 dialog->setCaption ("Qt " + tr("Search")); 885 dialog->setCaption ("Qt " + tr("Search"));
887#endif 886#endif
888 887
889#ifdef DESKTOP 888#ifdef DESKTOP
890#endif 889#endif
891 if (lastSearchedName) 890 if (lastSearchedName)
892 dialog->NameField->setText(lastSearchedName); 891 dialog->NameField->setText(lastSearchedName);
893 else 892 else
894 dialog->NameField->setText(""); 893 dialog->NameField->setText("");
895 if (lastSearchedUsername) 894 if (lastSearchedUsername)
896 dialog->UsernameField->setText(lastSearchedUsername); 895 dialog->UsernameField->setText(lastSearchedUsername);
897 else 896 else
898 dialog->UsernameField->setText(""); 897 dialog->UsernameField->setText("");
899 if (lastSearchedComment) 898 if (lastSearchedComment)
900 dialog->CommentField->setText(lastSearchedComment); 899 dialog->CommentField->setText(lastSearchedComment);
901 else 900 else
902 dialog->CommentField->setText(""); 901 dialog->CommentField->setText("");
903 DialogCode result = (DialogCode) dialog->exec(); 902 DialogCode result = (DialogCode) dialog->exec();
904#ifdef DESKTOP 903#ifdef DESKTOP
905 result = Accepted; 904 result = Accepted;
906#endif 905#endif
907 906
908 QString name; 907 QString name;
909 QString username; 908 QString username;
910 QString comment; 909 QString comment;
911 if (result == Accepted) 910 if (result == Accepted)
912 { 911 {
913 name = dialog->NameField->text(); 912 name = dialog->NameField->text();
914 username = dialog->UsernameField->text(); 913 username = dialog->UsernameField->text();
915 comment = dialog->CommentField->text(); 914 comment = dialog->CommentField->text();
916 qWarning (name); 915 qWarning (name);
917 } 916 }
918 else 917 else
919 { 918 {
920 delete dialog; 919 delete dialog;
921 return; 920 return;
922 } 921 }
923 922
924 if (!name.isEmpty() && name != lastSearchedName || 923 if (!name.isEmpty() && name != lastSearchedName ||
925 lastSearchedName.isEmpty() && !name.isEmpty()) 924 lastSearchedName.isEmpty() && !name.isEmpty())
926 { 925 {
927 // set search at the beginning if a new name is given 926 // set search at the beginning if a new name is given
928 lastSearchedCategory = NULL; 927 lastSearchedCategory = NULL;
929 lastSearchedItem = NULL; 928 lastSearchedItem = NULL;
930 } 929 }
931 lastSearchedName = name; 930 lastSearchedName = name;
932 if (!username.isEmpty() && username != lastSearchedUsername || 931 if (!username.isEmpty() && username != lastSearchedUsername ||
933 lastSearchedUsername.isEmpty() && !username.isEmpty()) 932 lastSearchedUsername.isEmpty() && !username.isEmpty())
934 { 933 {
935 // set search at the beginning if a new name is given 934 // set search at the beginning if a new name is given
936 lastSearchedCategory = NULL; 935 lastSearchedCategory = NULL;
937 lastSearchedItem = NULL; 936 lastSearchedItem = NULL;
938 } 937 }
939 lastSearchedUsername = username; 938 lastSearchedUsername = username;
940 if (!comment.isEmpty() && comment != lastSearchedComment || 939 if (!comment.isEmpty() && comment != lastSearchedComment ||
941 lastSearchedComment.isEmpty() && !comment.isEmpty()) 940 lastSearchedComment.isEmpty() && !comment.isEmpty())
942 { 941 {
943 // set search at the beginning if a new name is given 942 // set search at the beginning if a new name is given
944 lastSearchedCategory = NULL; 943 lastSearchedCategory = NULL;
945 lastSearchedItem = NULL; 944 lastSearchedItem = NULL;
946 } 945 }
947 lastSearchedComment = comment; 946 lastSearchedComment = comment;
948 947
949 ListView->clearSelection(); 948 ListView->clearSelection();
950 949
951 bool found=FALSE; 950 bool found=FALSE;
952 // step through all categories 951 // step through all categories
953 QListViewItem *i; 952 QListViewItem *i;
954 if (lastSearchedCategory) 953 if (lastSearchedCategory)
955 i = lastSearchedCategory; 954 i = lastSearchedCategory;
956 else 955 else
957 i = ListView->firstChild(); 956 i = ListView->firstChild();
958 for (; 957 for (;
959 i != NULL; 958 i != NULL;
960 i = i->nextSibling()) 959 i = i->nextSibling())
961 { 960 {
962 qWarning (i->text(0)); 961 qWarning (i->text(0));
963 i->setSelected(FALSE); 962 i->setSelected(FALSE);
964 963
965 // step through all subitems 964 // step through all subitems
966 QListViewItem *si; 965 QListViewItem *si;
967 if (lastSearchedItem) 966 if (lastSearchedItem)
968 si = lastSearchedItem; 967 si = lastSearchedItem;
969 else 968 else
970 si = i->firstChild(); 969 si = i->firstChild();
971 // for (si = i->firstChild(); 970 // for (si = i->firstChild();
972 for (; 971 for (;
973 si != NULL; 972 si != NULL;
974 si = si->nextSibling()) 973 si = si->nextSibling())
975 { 974 {
976 qWarning (si->text(0)); 975 qWarning (si->text(0));
977 if (si->isSelected()) 976 if (si->isSelected())
978 si->setSelected(FALSE); 977 si->setSelected(FALSE);
979 // ListView->repaintItem(si); 978 // ListView->repaintItem(si);
980 979
981 bool n=TRUE; 980 bool n=TRUE;
982 bool u=TRUE; 981 bool u=TRUE;
983 bool c=TRUE; 982 bool c=TRUE;
984 if (!name.isEmpty()) 983 if (!name.isEmpty())
985 n = (si->text(0)).contains (name, FALSE); 984 n = (si->text(0)).contains (name, FALSE);
986 if (!username.isEmpty()) 985 if (!username.isEmpty())
987 u = (si->text(1)).contains (username, FALSE); 986 u = (si->text(1)).contains (username, FALSE);
988 if (!comment.isEmpty()) 987 if (!comment.isEmpty())
989 c = (si->text(3)).contains (comment, FALSE); 988 c = (si->text(3)).contains (comment, FALSE);
990 989
991 if ((n && u && c ) && !found) 990 if ((n && u && c ) && !found)
992 { 991 {
993 qWarning ("Found"); 992 qWarning ("Found");
994 selectedItem = si; 993 selectedItem = si;
995 si->setSelected(TRUE); 994 si->setSelected(TRUE);
996 ListView->setCurrentItem(si); 995 ListView->setCurrentItem(si);
997 ListView->ensureItemVisible(si); 996 ListView->ensureItemVisible(si);
998 ListView->triggerUpdate(); 997 ListView->triggerUpdate();
999 998
1000 lastSearchedCategory = i; 999 lastSearchedCategory = i;
1001 // set to the next item 1000 // set to the next item
1002 lastSearchedItem = si->nextSibling(); 1001 lastSearchedItem = si->nextSibling();
1003 if (!lastSearchedItem) 1002 if (!lastSearchedItem)
1004 { 1003 {
1005 // no next item within category -> set next category 1004 // no next item within category -> set next category
1006 lastSearchedCategory = i->nextSibling(); 1005 lastSearchedCategory = i->nextSibling();
1007 if (!lastSearchedCategory) 1006 if (!lastSearchedCategory)
1008 lastSearchedItem = NULL; // END 1007 lastSearchedItem = NULL; // END
1009 } 1008 }
1010 1009
1011 found = TRUE; 1010 found = TRUE;
1012 delete dialog; 1011 delete dialog;
1013 update(); 1012 update();
1014 return; 1013 return;
1015 } 1014 }
1016 } 1015 }
1017 lastSearchedCategory = i->nextSibling(); 1016 lastSearchedCategory = i->nextSibling();
1018 lastSearchedItem = NULL; 1017 lastSearchedItem = NULL;
1019 } 1018 }
1020 lastSearchedCategory = NULL; 1019 lastSearchedCategory = NULL;
1021 lastSearchedItem = NULL; 1020 lastSearchedItem = NULL;
1022 delete dialog; 1021 delete dialog;
1023 update(); 1022 update();
1024 QMessageBox::information( this, tr("ZSafe"), 1023 QMessageBox::information( this, tr("ZSafe"),
1025 tr("Entry not found"), tr("&OK"), 0); 1024 tr("Entry not found"), tr("&OK"), 0);
1026 1025
1027} 1026}
1028 1027
1029QString ZSafe::getFieldLabel (QListViewItem *_item, QString field, QString def) 1028QString ZSafe::getFieldLabel (QListViewItem *_item, QString field, QString def)
1030{ 1029{
1031 QString category; 1030 QString category;
1032 if (_item) 1031 if (_item)
1033 { 1032 {
1034 if (isCategory(_item)) 1033 if (isCategory(_item))
1035 { 1034 {
1036 category = _item->text(0); 1035 category = _item->text(0);
1037 } 1036 }
1038 else 1037 else
1039 { 1038 {
1040 QListViewItem *cat = _item->parent(); 1039 QListViewItem *cat = _item->parent();
1041 category = cat->text(0); 1040 category = cat->text(0);
1042 } 1041 }
1043 } 1042 }
1044 else 1043 else
1045 { 1044 {
1046 return def; 1045 return def;
1047 } 1046 }
1048 1047
1049 QString app_key = APP_KEY; 1048 QString app_key = APP_KEY;
1050#ifndef DESKTOP 1049#ifndef DESKTOP
1051#ifndef WIN32 1050#ifndef WIN32
1052 conf->setGroup ("fieldDefs"); 1051 conf->setGroup ("fieldDefs");
1053#endif 1052#endif
1054#else 1053#else
1055#ifndef WIN32 1054#ifndef WIN32
1056 app_key += "/fieldDefs/"; 1055 app_key += "/fieldDefs/";
1057#endif 1056#endif
1058#endif 1057#endif
1059// #ifndef WIN32 1058// #ifndef WIN32
1060 QString label = conf->readEntry(app_key+category+"-field"+field,def); 1059 QString label = conf->readEntry(app_key+category+"-field"+field,def);
1061// #else 1060// #else
1062// QString label(def); 1061// QString label(def);
1063// #endif 1062// #endif
1064 1063
1065#ifndef DESKTOP 1064#ifndef DESKTOP
1066 conf->setGroup ("zsafe"); 1065 conf->setGroup ("zsafe");
1067#endif 1066#endif
1068 return label; 1067 return label;
1069} 1068}
1070 1069
1071QString ZSafe::getFieldLabel (QString category, QString field, QString def) 1070QString ZSafe::getFieldLabel (QString category, QString field, QString def)
1072{ 1071{
1073 QString app_key = APP_KEY; 1072 QString app_key = APP_KEY;
1074#ifndef DESKTOP 1073#ifndef DESKTOP
1075 conf->setGroup ("fieldDefs"); 1074 conf->setGroup ("fieldDefs");
1076#else 1075#else
1077#ifndef WIN32 1076#ifndef WIN32
1078 app_key += "/fieldDefs/"; 1077 app_key += "/fieldDefs/";
1079#endif 1078#endif
1080#endif 1079#endif
1081// #ifndef WIN32 1080// #ifndef WIN32
1082 QString label = conf->readEntry(app_key+category+"-field"+field, 1081 QString label = conf->readEntry(app_key+category+"-field"+field,
1083 def); 1082 def);
1084// #else 1083// #else
1085 // QString label(def); 1084 // QString label(def);
1086// #endif 1085// #endif
1087#ifndef DESKTOP 1086#ifndef DESKTOP
1088 conf->setGroup ("zsafe"); 1087 conf->setGroup ("zsafe");
1089#endif 1088#endif
1090 return label; 1089 return label;
1091} 1090}
1092 1091
1093void ZSafe::showInfo( QListViewItem *_item) 1092void ZSafe::showInfo( QListViewItem *_item)
1094{ 1093{
1095 if (!_item) 1094 if (!_item)
1096 return; 1095 return;
1097 if (selectedItem != NULL) 1096 if (selectedItem != NULL)
1098 selectedItem->setSelected(FALSE); 1097 selectedItem->setSelected(FALSE);
1099 1098
1100 selectedItem = _item; 1099 selectedItem = _item;
1101 selectedItem->setSelected(TRUE); 1100 selectedItem->setSelected(TRUE);
1102 1101
1103 if (!isCategory(_item)) 1102 if (!isCategory(_item))
1104 { 1103 {
1105/* 1104/*
1106 QString label=selectedItem->text(0); 1105 QString label=selectedItem->text(0);
1107 label+="\n"; 1106 label+="\n";
1108 label+=selectedItem->text(1); 1107 label+=selectedItem->text(1);
1109 label+="\n"; 1108 label+="\n";
1110 label+=selectedItem->text(2); 1109 label+=selectedItem->text(2);
1111 label+="\n"; 1110 label+="\n";
1112 label+=selectedItem->text(3); 1111 label+=selectedItem->text(3);
1113*/ 1112*/
1114 1113
1115 QString text; 1114 QString text;
1116 QString entry; 1115 QString entry;
1117 1116
1118 text = "<html><body><div align=""center""><u><b>"; 1117 text = "<html><body><div align=""center""><u><b>";
1119 text += selectedItem->text(0); 1118 text += selectedItem->text(0);
1120 text += "</b></u><br></div><br>"; 1119 text += "</b></u><br></div><br>";
1121 1120
1122 entry = selectedItem->text(1); 1121 entry = selectedItem->text(1);
1123 if (!entry.isEmpty() && entry.compare(" ")) 1122 if (!entry.isEmpty() && entry.compare(" "))
1124 { 1123 {
1125 text += "<u><b>"; 1124 text += "<u><b>";
1126 text += getFieldLabel (selectedItem, "2", tr("Username")); 1125 text += getFieldLabel (selectedItem, "2", tr("Username"));
1127 text += ":<br></b></u><blockquote>"; 1126 text += ":<br></b></u><blockquote>";
1128 text += entry; 1127 text += entry;
1129 text += "</blockquote>"; 1128 text += "</blockquote>";
1130 // text += "<br>"; 1129 // text += "<br>";
1131 } 1130 }
1132 1131
1133 entry = selectedItem->text(2); 1132 entry = selectedItem->text(2);
1134 if (!entry.isEmpty() && entry.compare(" ")) 1133 if (!entry.isEmpty() && entry.compare(" "))
1135 { 1134 {
1136 text += "<u><b>"; 1135 text += "<u><b>";
1137 text += getFieldLabel (selectedItem, "3", tr("Password")); 1136 text += getFieldLabel (selectedItem, "3", tr("Password"));
1138 text += ":<br> </b></u><blockquote>"; 1137 text += ":<br> </b></u><blockquote>";
1139 text += entry; 1138 text += entry;
1140 text += "</blockquote>"; 1139 text += "</blockquote>";
1141 // text += "<br>"; 1140 // text += "<br>";
1142 } 1141 }
1143 1142
1144 entry = selectedItem->text(4); 1143 entry = selectedItem->text(4);
1145 if (!entry.isEmpty() && entry.compare(" ")) 1144 if (!entry.isEmpty() && entry.compare(" "))
1146 { 1145 {
1147 text += "<u><b>"; 1146 text += "<u><b>";
1148 text += getFieldLabel (selectedItem, "5", tr("Field 4")); 1147 text += getFieldLabel (selectedItem, "5", tr("Field 4"));
1149 text += ":<br> </b></u><blockquote>"; 1148 text += ":<br> </b></u><blockquote>";
1150 text += entry; 1149 text += entry;
1151 text += "</blockquote>"; 1150 text += "</blockquote>";
1152 // text += "<br>"; 1151 // text += "<br>";
1153 } 1152 }
1154 1153
1155 entry = selectedItem->text(5); 1154 entry = selectedItem->text(5);
1156 if (!entry.isEmpty() && entry.compare(" ")) 1155 if (!entry.isEmpty() && entry.compare(" "))
1157 { 1156 {
1158 text += "<u><b>"; 1157 text += "<u><b>";
1159 text += getFieldLabel (selectedItem, "6", tr("Field 5")); 1158 text += getFieldLabel (selectedItem, "6", tr("Field 5"));
1160 text += ":<br> </b></u><blockquote>"; 1159 text += ":<br> </b></u><blockquote>";
1161 text += entry; 1160 text += entry;
1162 text += "</blockquote>"; 1161 text += "</blockquote>";
1163 // text += "<br>"; 1162 // text += "<br>";
1164 } 1163 }
1165 1164
1166 entry = selectedItem->text(3); 1165 entry = selectedItem->text(3);
1167 if (!entry.isEmpty() && entry.compare(" ")) 1166 if (!entry.isEmpty() && entry.compare(" "))
1168 { 1167 {
1169 text += "<u><b>"; 1168 text += "<u><b>";
1170 text += getFieldLabel (selectedItem, "4", tr("Comment")); 1169 text += getFieldLabel (selectedItem, "4", tr("Comment"));
1171 text += ":<br> </b></u>"; 1170 text += ":<br> </b></u>";
1172 QString comment = selectedItem->text(3); 1171 QString comment = selectedItem->text(3);
1173 comment.replace (QRegExp("\n"), "<br>"); 1172 comment.replace (QRegExp("\n"), "<br>");
1174 text += comment; 1173 text += comment;
1175 // text += "<br>"; 1174 // text += "<br>";
1176 } 1175 }
1177 1176
1178 text += "</body></html>"; 1177 text += "</body></html>";
1179 1178
1180 infoForm->InfoText->setText(text); 1179 infoForm->InfoText->setText(text);
1181 infoForm->hide(); 1180 infoForm->hide();
1182 QPEApplication::showDialog( infoForm ); 1181 QPEApplication::showDialog( infoForm );
1183 } 1182 }
1184} 1183}
1185 1184
1186void ZSafe::listViewSelected( QListViewItem *_item) 1185void ZSafe::listViewSelected( QListViewItem *_item)
1187{ 1186{
1188 if (!_item) 1187 if (!_item)
1189 return; 1188 return;
1190 if (selectedItem != NULL) 1189 if (selectedItem != NULL)
1191 selectedItem->setSelected(FALSE); 1190 selectedItem->setSelected(FALSE);
1192 1191
1193 selectedItem = _item; 1192 selectedItem = _item;
1194 1193
1195#ifndef DESKTOP 1194#ifndef DESKTOP
1196 // set the column text dependent on the selected item 1195 // set the column text dependent on the selected item
1197 ListView->setColumnText(0, getFieldLabel (selectedItem, "1", tr("Name"))); 1196 ListView->setColumnText(0, getFieldLabel (selectedItem, "1", tr("Name")));
1198 ListView->setColumnText(1, getFieldLabel (selectedItem, "2", tr("Field 2"))); 1197 ListView->setColumnText(1, getFieldLabel (selectedItem, "2", tr("Field 2")));
1199 ListView->setColumnText(2, getFieldLabel (selectedItem, "3", tr("Field 3"))); 1198 ListView->setColumnText(2, getFieldLabel (selectedItem, "3", tr("Field 3")));
1200 ListView->setColumnText(3, getFieldLabel (selectedItem, "4", tr("Comment"))); 1199 ListView->setColumnText(3, getFieldLabel (selectedItem, "4", tr("Comment")));
1201 ListView->setColumnText(4, getFieldLabel (selectedItem, "5", tr("Field 4"))); 1200 ListView->setColumnText(4, getFieldLabel (selectedItem, "5", tr("Field 4")));
1202 ListView->setColumnText(5, getFieldLabel (selectedItem, "6", tr("Field 5"))); 1201 ListView->setColumnText(5, getFieldLabel (selectedItem, "6", tr("Field 5")));
1203#endif 1202#endif
1204#ifdef WIN32 1203#ifdef WIN32
1205 // set the column text dependent on the selected item 1204 // set the column text dependent on the selected item
1206 ListView->setColumnText(0, getFieldLabel (selectedItem, "1", tr("Name"))); 1205 ListView->setColumnText(0, getFieldLabel (selectedItem, "1", tr("Name")));
1207 ListView->setColumnText(1, getFieldLabel (selectedItem, "2", tr("Field 2"))); 1206 ListView->setColumnText(1, getFieldLabel (selectedItem, "2", tr("Field 2")));
1208 ListView->setColumnText(2, getFieldLabel (selectedItem, "3", tr("Field 3"))); 1207 ListView->setColumnText(2, getFieldLabel (selectedItem, "3", tr("Field 3")));
1209 ListView->setColumnText(3, getFieldLabel (selectedItem, "4", tr("Comment"))); 1208 ListView->setColumnText(3, getFieldLabel (selectedItem, "4", tr("Comment")));
1210 ListView->setColumnText(4, getFieldLabel (selectedItem, "5", tr("Field 4"))); 1209 ListView->setColumnText(4, getFieldLabel (selectedItem, "5", tr("Field 4")));
1211 ListView->setColumnText(5, getFieldLabel (selectedItem, "6", tr("Field 5"))); 1210 ListView->setColumnText(5, getFieldLabel (selectedItem, "6", tr("Field 5")));
1212#endif 1211#endif
1213 1212
1214} 1213}
1215 1214
1216bool ZSafe::isCategory(QListViewItem *_item) 1215bool ZSafe::isCategory(QListViewItem *_item)
1217{ 1216{
1218 if (_item == NULL) 1217 if (_item == NULL)
1219 return FALSE; 1218 return FALSE;
1220 1219
1221 QString categoryName = _item->text (0); 1220 QString categoryName = _item->text (0);
1222 if (categories.find (categoryName)) 1221 if (categories.find (categoryName))
1223 return TRUE; 1222 return TRUE;
1224 else 1223 else
1225 return FALSE; 1224 return FALSE;
1226} 1225}
1227 1226
1228void ZSafe::removeAsciiFile() 1227void ZSafe::removeAsciiFile()
1229{ 1228{
1230 // QString fn = filename + ".txt"; 1229 // QString fn = filename + ".txt";
1231 // open the file dialog 1230 // open the file dialog
1232#ifndef DESKTOP 1231#ifndef DESKTOP
1233#ifndef NO_OPIE 1232#ifndef NO_OPIE
1234 QMap<QString, QStringList> mimeTypes; 1233 QMap<QString, QStringList> mimeTypes;
1235 mimeTypes.insert(tr("All"), QStringList() ); 1234 mimeTypes.insert(tr("All"), QStringList() );
1236 mimeTypes.insert(tr("Text"), "text/*" ); 1235 mimeTypes.insert(tr("Text"), "text/*" );
1237 QString fn = OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL, 1236 QString fn = OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL,
1238 QDir::homeDirPath() + "/Documents/application/zsafe", 1237 QDir::homeDirPath() + "/Documents/application/zsafe",
1239 QString::null, 1238 QString::null,
1240 mimeTypes, 1239 mimeTypes,
1241 this, 1240 this,
1242 tr ("Remove text file")); 1241 tr ("Remove text file"));
1243#else 1242#else
1244 QString fn = ScQtFileEdit::getOpenFileName(this, 1243 QString fn = ScQtFileEdit::getOpenFileName(this,
1245 tr ("Remove text file"), 1244 tr ("Remove text file"),
1246 QDir::homeDirPath() + "/Documents/application/zsafe", 1245 QDir::homeDirPath() + "/Documents/application/zsafe",
1247 "*.txt"); 1246 "*.txt");
1248#endif 1247#endif
1249#else 1248#else
1250 QString fn = QFileDialog::getOpenFileName( 1249 QString fn = QFileDialog::getOpenFileName(
1251 QDir::homeDirPath() + "/Documents/application/zsafe", 1250 QDir::homeDirPath() + "/Documents/application/zsafe",
1252 "ZSafe (*.txt)", 1251 "ZSafe (*.txt)",
1253 this, 1252 this,
1254 "ZSafe File Dialog" 1253 "ZSafe File Dialog"
1255 "Choose a text file" ); 1254 "Choose a text file" );
1256#endif 1255#endif
1257 1256
1258 if (fn && fn.length() > 0 ) 1257 if (fn && fn.length() > 0 )
1259 { 1258 {
1260 QFile f( fn ); 1259 QFile f( fn );
1261 if ( !f.remove() ) 1260 if ( !f.remove() )
1262 { 1261 {
1263 qWarning( QString("Could not remove file %1").arg(fn), 1262 qWarning( QString("Could not remove file %1").arg(fn),
1264 2000 ); 1263 2000 );
1265 QMessageBox::critical( 0, tr("ZSafe"), 1264 QMessageBox::critical( 0, tr("ZSafe"),
1266 tr("Could not remove text file.") ); 1265 tr("Could not remove text file.") );
1267 return; 1266 return;
1268 } 1267 }
1269 } 1268 }
1270} 1269}
1271 1270
1272void ZSafe::writeAllEntries() 1271void ZSafe::writeAllEntries()
1273{ 1272{
1274 if (filename.isEmpty()) 1273 if (filename.isEmpty())
1275 { 1274 {
1276 QMessageBox::critical( 0, tr("ZSafe"), 1275 QMessageBox::critical( 0, tr("ZSafe"),
1277 tr("No document defined.\nYou have to create a new document")); 1276 tr("No document defined.\nYou have to create a new document"));
1278 return; 1277 return;
1279 } 1278 }
1280 1279
1281 // open the file dialog 1280 // open the file dialog
1282#ifndef DESKTOP 1281#ifndef DESKTOP
1283#ifndef NO_OPIE 1282#ifndef NO_OPIE
1284 QMap<QString, QStringList> mimeTypes; 1283 QMap<QString, QStringList> mimeTypes;
1285 mimeTypes.insert(tr("All"), QStringList() ); 1284 mimeTypes.insert(tr("All"), QStringList() );
1286 mimeTypes.insert(tr("Text"), "text/*" ); 1285 mimeTypes.insert(tr("Text"), "text/*" );
1287 QString fn = OFileDialog::getSaveFileName( OFileSelector::EXTENDED_ALL, 1286 QString fn = OFileDialog::getSaveFileName( OFileSelector::EXTENDED_ALL,
1288 QDir::homeDirPath() + "/Documents/application/zsafe", 1287 QDir::homeDirPath() + "/Documents/application/zsafe",
1289 QString::null, 1288 QString::null,
1290 mimeTypes, 1289 mimeTypes,
1291 this, 1290 this,
1292 tr ("Export text file")); 1291 tr ("Export text file"));
1293#else 1292#else
1294 QString fn = ScQtFileEdit::getSaveAsFileName(this, 1293 QString fn = ScQtFileEdit::getSaveAsFileName(this,
1295 tr ("Export text file"), 1294 tr ("Export text file"),
1296 QDir::homeDirPath() + "/Documents/application/zsafe", 1295 QDir::homeDirPath() + "/Documents/application/zsafe",
1297 "*.txt"); 1296 "*.txt");
1298#endif 1297#endif
1299#else 1298#else
1300 QString fn = QFileDialog::getSaveFileName( 1299 QString fn = QFileDialog::getSaveFileName(
1301 QDir::homeDirPath() + "/Documents/application/zsafe", 1300 QDir::homeDirPath() + "/Documents/application/zsafe",
1302 "ZSafe (*.txt)", 1301 "ZSafe (*.txt)",
1303 this, 1302 this,
1304 "ZSafe File Dialog" 1303 "ZSafe File Dialog"
1305 "Choose a text file" ); 1304 "Choose a text file" );
1306#endif 1305#endif
1307 1306
1308 // open the new document 1307 // open the new document
1309 if (fn && fn.length() > 0 ) 1308 if (fn && fn.length() > 0 )
1310 { 1309 {
1311 QFile f( fn ); 1310 QFile f( fn );
1312 if ( !f.open( IO_WriteOnly ) ) { 1311 if ( !f.open( IO_WriteOnly ) ) {
1313 qWarning( QString("Could not write to file %1").arg(fn), 1312 qWarning( QString("Could not write to file %1").arg(fn),
1314 2000 ); 1313 2000 );
1315 QMessageBox::critical( 0, "ZSafe", 1314 QMessageBox::critical( 0, "ZSafe",
1316 QString("Could not export to text file.") ); 1315 QString("Could not export to text file.") );
1317 return; 1316 return;
1318 } 1317 }
1319 QTextStream t( &f ); 1318 QTextStream t( &f );
1320 1319
1321 QListViewItem *i; 1320 QListViewItem *i;
1322 // step through all categories 1321 // step through all categories
1323 for (i = ListView->firstChild(); 1322 for (i = ListView->firstChild();
1324 i != NULL; 1323 i != NULL;
1325 i = i->nextSibling()) 1324 i = i->nextSibling())
1326 { 1325 {
1327 // step through all subitems 1326 // step through all subitems
1328 QListViewItem *si; 1327 QListViewItem *si;
1329 for (si = i->firstChild(); 1328 for (si = i->firstChild();
1330 si != NULL; 1329 si != NULL;
1331 si = si->nextSibling()) 1330 si = si->nextSibling())
1332 { 1331 {
1333 QString oneEntry; 1332 QString oneEntry;
1334 oneEntry += "\""; 1333 oneEntry += "\"";
1335 oneEntry += i->text(0); 1334 oneEntry += i->text(0);
1336 oneEntry += "\";"; 1335 oneEntry += "\";";
1337 oneEntry += "\""; 1336 oneEntry += "\"";
1338 oneEntry += si->text(0); 1337 oneEntry += si->text(0);
1339 oneEntry += "\";"; 1338 oneEntry += "\";";
1340 oneEntry += "\""; 1339 oneEntry += "\"";
1341 oneEntry += si->text(1); 1340 oneEntry += si->text(1);
1342 oneEntry += "\";"; 1341 oneEntry += "\";";
1343 oneEntry += "\""; 1342 oneEntry += "\"";
1344 oneEntry += si->text(2); 1343 oneEntry += si->text(2);
1345 oneEntry += "\";"; 1344 oneEntry += "\";";
1346 oneEntry += "\""; 1345 oneEntry += "\"";
1347 QString comment = si->text(3); 1346 QString comment = si->text(3);
1348 comment.replace (QRegExp("\n"), "<br>"); 1347 comment.replace (QRegExp("\n"), "<br>");
1349 oneEntry += comment; 1348 oneEntry += comment;
1350 oneEntry += "\";"; 1349 oneEntry += "\";";
1351 oneEntry += "\""; 1350 oneEntry += "\"";
1352 oneEntry += si->text(4); 1351 oneEntry += si->text(4);
1353 oneEntry += "\";"; 1352 oneEntry += "\";";
1354 oneEntry += "\""; 1353 oneEntry += "\"";
1355 oneEntry += si->text(5); 1354 oneEntry += si->text(5);
1356 oneEntry += "\""; 1355 oneEntry += "\"";
1357 // qWarning (oneEntry); 1356 // qWarning (oneEntry);
1358 t << oneEntry << endl; 1357 t << oneEntry << endl;
1359 1358
1360 // qWarning (si->text(0)); 1359 // qWarning (si->text(0));
1361 } 1360 }
1362 } 1361 }
1363 f.close(); 1362 f.close();
1364 } 1363 }
1365} 1364}
1366 1365
1367void ZSafe::readAllEntries() 1366void ZSafe::readAllEntries()
1368{ 1367{
1369 if (filename.isEmpty()) 1368 if (filename.isEmpty())
1370 { 1369 {
1371 QMessageBox::critical( 0, tr("ZSafe"), 1370 QMessageBox::critical( 0, tr("ZSafe"),
1372 tr("No document defined.\nYou have to create a new document")); 1371 tr("No document defined.\nYou have to create a new document"));
1373 return; 1372 return;
1374 } 1373 }
1375 1374
1376 // open the file dialog 1375 // open the file dialog
1377#ifndef DESKTOP 1376#ifndef DESKTOP
1378#ifndef NO_OPIE 1377#ifndef NO_OPIE
1379 QMap<QString, QStringList> mimeTypes; 1378 QMap<QString, QStringList> mimeTypes;
1380 mimeTypes.insert(tr("All"), QStringList() ); 1379 mimeTypes.insert(tr("All"), QStringList() );
1381 mimeTypes.insert(tr("Text"), "text/*" ); 1380 mimeTypes.insert(tr("Text"), "text/*" );
1382 QString fn = OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL, 1381 QString fn = OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL,
1383 QDir::homeDirPath() + "/Documents/application/zsafe", 1382 QDir::homeDirPath() + "/Documents/application/zsafe",
1384 QString::null, 1383 QString::null,
1385 mimeTypes, 1384 mimeTypes,
1386 this, 1385 this,
1387 tr ("Import text file")); 1386 tr ("Import text file"));
1388#else 1387#else
1389 QString fn = ScQtFileEdit::getOpenFileName(this, 1388 QString fn = ScQtFileEdit::getOpenFileName(this,
1390 tr ("Import text file"), 1389 tr ("Import text file"),
1391 QDir::homeDirPath() + "/Documents/application/zsafe", 1390 QDir::homeDirPath() + "/Documents/application/zsafe",
1392 "*.txt"); 1391 "*.txt");
1393#endif 1392#endif
1394#else 1393#else
1395 QString fn = QFileDialog::getOpenFileName( 1394 QString fn = QFileDialog::getOpenFileName(
1396 QDir::homeDirPath() + "/Documents/application/zsafe", 1395 QDir::homeDirPath() + "/Documents/application/zsafe",
1397 "ZSafe (*.txt)", 1396 "ZSafe (*.txt)",
1398 this, 1397 this,
1399 "ZSafe File Dialog" 1398 "ZSafe File Dialog"
1400 "Choose a text file" ); 1399 "Choose a text file" );
1401#endif 1400#endif
1402 1401
1403 if (fn && fn.length() > 0 ) 1402 if (fn && fn.length() > 0 )
1404 { 1403 {
1405 QFile f( fn ); 1404 QFile f( fn );
1406 if ( !f.open( IO_ReadOnly ) ) 1405 if ( !f.open( IO_ReadOnly ) )
1407 { 1406 {
1408 qWarning( QString("Could not read file %1").arg(fn), 1407 qWarning( QString("Could not read file %1").arg(fn),
1409 2000 ); 1408 2000 );
1410 QMessageBox::critical( 0, "ZSafe", 1409 QMessageBox::critical( 0, "ZSafe",
1411 QString("Could not import text file.") ); 1410 QString("Could not import text file.") );
1412 return; 1411 return;
1413 } 1412 }
1414 1413
1415 modified = true; 1414 modified = true;
1416 1415
1417 // clear the password list 1416 // clear the password list
1418 selectedItem = NULL; 1417 selectedItem = NULL;
1419 QListViewItem *i; 1418 QListViewItem *i;
1420 // step through all categories 1419 // step through all categories
1421 for (i = ListView->firstChild(); 1420 for (i = ListView->firstChild();
1422 i != NULL; 1421 i != NULL;
1423 i = i->nextSibling()) 1422 i = i->nextSibling())
1424 { 1423 {
1425 // step through all subitems 1424 // step through all subitems
1426 QListViewItem *si; 1425 QListViewItem *si;
1427 for (si = i->firstChild(); 1426 for (si = i->firstChild();
1428 si != NULL; ) 1427 si != NULL; )
1429 // si = si->nextSibling()) 1428 // si = si->nextSibling())
1430 { 1429 {
1431 QListViewItem *_si = si; 1430 QListViewItem *_si = si;
1432 si = si->nextSibling(); 1431 si = si->nextSibling();
1433 i->takeItem(_si); // remove from view list 1432 i->takeItem(_si); // remove from view list
1434 if (_si) delete _si; 1433 if (_si) delete _si;
1435 } 1434 }
1436 } 1435 }
1437 1436
1438 qWarning ("ReadAllEntries(): "); 1437 qWarning ("ReadAllEntries(): ");
1439 1438
1440 QTextStream t(&f); 1439 QTextStream t(&f);
1441 while ( !t.eof() ) 1440 while ( !t.eof() )
1442 { 1441 {
1443 QString s = t.readLine(); 1442 QString s = t.readLine();
1444 s.replace (QRegExp("\";\""), "\"|\""); 1443 s.replace (QRegExp("\";\""), "\"|\"");
1445 // char buffer[1024]; 1444 // char buffer[1024];
1446#ifndef WIN32 1445#ifndef WIN32
1447 char buffer[s.length()+1]; 1446 char buffer[s.length()+1];
1448#else 1447#else
1449 char buffer[4048]; 1448 char buffer[4048];
1450#endif 1449#endif
1451 1450
1452 1451
1453 /* modify QString -> QCString::utf8 */ 1452 /* modify QString -> QCString::utf8 */
1454 1453
1455 strcpy (buffer, s.utf8()); 1454 strcpy (buffer, s.utf8());
1456 1455
1457 QString name; 1456 QString name;
1458 QString user; 1457 QString user;
1459 QString password; 1458 QString password;
1460 QString comment; 1459 QString comment;
1461 QString field5=""; 1460 QString field5="";
1462 QString field6=""; 1461 QString field6="";
1463 1462
1464 // separete the entries 1463 // separete the entries
1465 char *i = strtok (buffer, "|"); 1464 char *i = strtok (buffer, "|");
1466 QString category(QString::fromUtf8(&i[1])); 1465 QString category(QString::fromUtf8(&i[1]));
1467 category.truncate(category.length() -1); 1466 category.truncate(category.length() -1);
1468 1467
1469 int idx=0; 1468 int idx=0;
1470 while ((i = strtok (NULL, "|")) != NULL) 1469 while ((i = strtok (NULL, "|")) != NULL)
1471 { 1470 {
1472 switch (idx) 1471 switch (idx)
1473 { 1472 {
1474 case 0: 1473 case 0:
1475 name = QString::fromUtf8(&i[1]); 1474 name = QString::fromUtf8(&i[1]);
1476 name.truncate(name.length() -1); 1475 name.truncate(name.length() -1);
1477 // name 1476 // name
1478 break; 1477 break;
1479 case 1: 1478 case 1:
1480 // user 1479 // user
1481 user = QString::fromUtf8(&i[1]); 1480 user = QString::fromUtf8(&i[1]);
1482 user.truncate(user.length() -1); 1481 user.truncate(user.length() -1);
1483 break; 1482 break;
1484 case 2: 1483 case 2:
1485 // password 1484 // password
1486 password = QString::fromUtf8(&i[1]); 1485 password = QString::fromUtf8(&i[1]);
1487 password.truncate(password.length() -1); 1486 password.truncate(password.length() -1);
1488 break; 1487 break;
1489 case 3: 1488 case 3:
1490 // comment 1489 // comment
1491 comment = QString::fromUtf8(&i[1]); 1490 comment = QString::fromUtf8(&i[1]);
1492 comment.truncate(comment.length() -1); 1491 comment.truncate(comment.length() -1);
1493 break; 1492 break;
1494 case 4: 1493 case 4:
1495 // field5 1494 // field5
1496 field5 = QString::fromUtf8(&i[1]); 1495 field5 = QString::fromUtf8(&i[1]);
1497 field5.truncate(field5.length() -1); 1496 field5.truncate(field5.length() -1);
1498 break; 1497 break;
1499 case 5: 1498 case 5:
1500 // field6 1499 // field6
1501 field6 = QString::fromUtf8(&i[1]); 1500 field6 = QString::fromUtf8(&i[1]);
1502 field6.truncate(field6.length() -1); 1501 field6.truncate(field6.length() -1);
1503 break; 1502 break;
1504 } 1503 }
1505 idx++; 1504 idx++;
1506 } 1505 }
1507 1506
1508 Category *cat= categories.find (category); 1507 Category *cat= categories.find (category);
1509 if (cat) 1508 if (cat)
1510 { 1509 {
1511 // use the existend item 1510 // use the existend item
1512 QListViewItem *catItem = cat->getListItem(); 1511 QListViewItem *catItem = cat->getListItem();
1513 if (catItem) 1512 if (catItem)
1514 { 1513 {
1515 QListViewItem * item = new ShadedListItem( 0, catItem ); 1514 QListViewItem * item = new ShadedListItem( 0, catItem );
1516 item->setText( 0, tr( name ) ); 1515 item->setText( 0, tr( name ) );
1517 item->setText( 1, tr( user ) ); 1516 item->setText( 1, tr( user ) );
1518 item->setText( 2, tr( password ) ); 1517 item->setText( 2, tr( password ) );
1519 item->setText( 3, tr( comment ) ); 1518 item->setText( 3, tr( comment ) );
1520 item->setText( 4, tr( field5 ) ); 1519 item->setText( 4, tr( field5 ) );
1521 item->setText( 5, tr( field6 ) ); 1520 item->setText( 5, tr( field6 ) );
1522 catItem->setOpen( TRUE ); 1521 catItem->setOpen( TRUE );
1523 } 1522 }
1524 } 1523 }
1525 else 1524 else
1526 { 1525 {
1527 QListViewItem *catI = new ShadedListItem( 1, ListView ); 1526 QListViewItem *catI = new ShadedListItem( 1, ListView );
1528 // create and insert a new item 1527 // create and insert a new item
1529 QListViewItem * item = new ShadedListItem( 0, catI ); 1528 QListViewItem * item = new ShadedListItem( 0, catI );
1530 item->setText( 0, tr( name ) ); 1529 item->setText( 0, tr( name ) );
1531 item->setText( 1, tr( user ) ); 1530 item->setText( 1, tr( user ) );
1532 item->setText( 2, tr( password ) ); 1531 item->setText( 2, tr( password ) );
1533 item->setText( 3, tr( comment ) ); 1532 item->setText( 3, tr( comment ) );
1534 item->setText( 4, tr( field5 ) ); 1533 item->setText( 4, tr( field5 ) );
1535 item->setText( 5, tr( field6 ) ); 1534 item->setText( 5, tr( field6 ) );
1536 1535
1537 catI->setOpen( TRUE ); 1536 catI->setOpen( TRUE );
1538 1537
1539 Category *c1 = new Category(); 1538 Category *c1 = new Category();
1540 c1->setCategoryName(category); 1539 c1->setCategoryName(category);
1541 1540
1542 QString icon; 1541 QString icon;
1543 QString fullIconPath; 1542 QString fullIconPath;
1544 QPixmap *pix; 1543 QPixmap *pix;
1545// #ifndef WIN32 1544// #ifndef WIN32
1546 icon = conf->readEntry(APP_KEY+category); 1545 icon = conf->readEntry(APP_KEY+category);
1547// #endif 1546// #endif
1548 bool isIconAv = false; 1547 bool isIconAv = false;
1549 if (!icon.isEmpty() && !icon.isNull()) 1548 if (!icon.isEmpty() && !icon.isNull())
1550 { 1549 {
1551 // build the full path 1550 // build the full path
1552 fullIconPath = iconPath + icon; 1551 fullIconPath = iconPath + icon;
1553 pix = new QPixmap (fullIconPath); 1552 pix = new QPixmap (fullIconPath);
1554 if (pix) 1553 if (pix)
1555 { 1554 {
1556 QImage img = pix->convertToImage(); 1555 QImage img = pix->convertToImage();
1557 pix->convertFromImage(img.smoothScale(14,14)); 1556 pix->convertFromImage(img.smoothScale(14,14));
1558 c1->setIconName (icon); 1557 c1->setIconName (icon);
1559 c1->setIcon (*pix); 1558 c1->setIcon (*pix);
1560 isIconAv = true; 1559 isIconAv = true;
1561 } 1560 }
1562 } 1561 }
1563 if (!isIconAv) 1562 if (!isIconAv)
1564 { 1563 {
1565 c1->setIcon (*getPredefinedIcon(category)); 1564 c1->setIcon (*getPredefinedIcon(category));
1566 } 1565 }
1567 c1->setListItem (catI); 1566 c1->setListItem (catI);
1568 c1->initListItem(); 1567 c1->initListItem();
1569 categories.insert (c1->getCategoryName(), c1); 1568 categories.insert (c1->getCategoryName(), c1);
1570 } 1569 }
1571 1570
1572 } 1571 }
1573 f.close(); 1572 f.close();
1574 1573
1575 } 1574 }
1576 else 1575 else
1577 { 1576 {
1578 } 1577 }
1579 1578
1580} 1579}
1581 1580
1582#ifdef UNUSED 1581#ifdef UNUSED
1583void ZSafe::writeAllEntries() 1582void ZSafe::writeAllEntries()
1584{ 1583{
1585 // open the file for writing 1584 // open the file for writing
1586 QString fn = filename + ".txt"; 1585 QString fn = filename + ".txt";
1587 QFile f( fn ); 1586 QFile f( fn );
1588 if ( !f.open( IO_WriteOnly ) ) { 1587 if ( !f.open( IO_WriteOnly ) ) {
1589 qWarning( QString("Could not write to file %1").arg(fn), 1588 qWarning( QString("Could not write to file %1").arg(fn),
1590 2000 ); 1589 2000 );
1591 QMessageBox::critical( 0, tr("ZSafe"), 1590 QMessageBox::critical( 0, tr("ZSafe"),
1592 tr("Could not export to text file.") ); 1591 tr("Could not export to text file.") );
1593 return; 1592 return;
1594 } 1593 }
1595 QTextStream t( &f ); 1594 QTextStream t( &f );
1596 1595
1597 QListViewItem *i; 1596 QListViewItem *i;
1598 // step through all categories 1597 // step through all categories
1599 for (i = ListView->firstChild(); 1598 for (i = ListView->firstChild();
1600 i != NULL; 1599 i != NULL;
1601 i = i->nextSibling()) 1600 i = i->nextSibling())
1602 { 1601 {
1603 // step through all subitems 1602 // step through all subitems
1604 QListViewItem *si; 1603 QListViewItem *si;
1605 for (si = i->firstChild(); 1604 for (si = i->firstChild();
1606 si != NULL; 1605 si != NULL;
1607 si = si->nextSibling()) 1606 si = si->nextSibling())
1608 { 1607 {
1609 QString oneEntry; 1608 QString oneEntry;
1610 oneEntry += "\""; 1609 oneEntry += "\"";
1611 oneEntry += i->text(0); 1610 oneEntry += i->text(0);
1612 oneEntry += "\";"; 1611 oneEntry += "\";";
1613 oneEntry += "\""; 1612 oneEntry += "\"";
1614 oneEntry += si->text(0); 1613 oneEntry += si->text(0);
1615 oneEntry += "\";"; 1614 oneEntry += "\";";
1616 oneEntry += "\""; 1615 oneEntry += "\"";
1617 oneEntry += si->text(1); 1616 oneEntry += si->text(1);
1618 oneEntry += "\";"; 1617 oneEntry += "\";";
1619 oneEntry += "\""; 1618 oneEntry += "\"";
1620 oneEntry += si->text(2); 1619 oneEntry += si->text(2);
1621 oneEntry += "\";"; 1620 oneEntry += "\";";
1622 oneEntry += "\""; 1621 oneEntry += "\"";
1623 // oneEntry += si->text(3); 1622 // oneEntry += si->text(3);
1624 QString comment = si->text(3); 1623 QString comment = si->text(3);
1625 comment.replace (QRegExp("\n"), "<br>"); 1624 comment.replace (QRegExp("\n"), "<br>");
1626 oneEntry += comment; 1625 oneEntry += comment;
1627 oneEntry += "\""; 1626 oneEntry += "\"";
1628 // qWarning (oneEntry); 1627 // qWarning (oneEntry);
1629 t << oneEntry << endl; 1628 t << oneEntry << endl;
1630 1629
1631 // qWarning (si->text(0)); 1630 // qWarning (si->text(0));
1632 } 1631 }
1633 } 1632 }
1634 f.close(); 1633 f.close();
1635} 1634}
1636 1635
1637void ZSafe::readAllEntries() 1636void ZSafe::readAllEntries()
1638{ 1637{
1639 QString fn = filename + ".txt"; 1638 QString fn = filename + ".txt";
1640 QFile f( fn ); 1639 QFile f( fn );
1641 if ( !f.open( IO_ReadOnly ) ) 1640 if ( !f.open( IO_ReadOnly ) )
1642 { 1641 {
1643 qWarning( QString("Could not read file %1").arg(fn), 1642 qWarning( QString("Could not read file %1").arg(fn),
1644 2000 ); 1643 2000 );
1645 QMessageBox::critical( 0, tr("ZSafe"), 1644 QMessageBox::critical( 0, tr("ZSafe"),
1646 tr("Could not import text file.") ); 1645 tr("Could not import text file.") );
1647 return; 1646 return;
1648 } 1647 }
1649 1648
1650 modified = true; 1649 modified = true;
1651 1650
1652 // clear the password list 1651 // clear the password list
1653 selectedItem = NULL; 1652 selectedItem = NULL;
1654 QListViewItem *i; 1653 QListViewItem *i;
1655 // step through all categories 1654 // step through all categories
1656 for (i = ListView->firstChild(); 1655 for (i = ListView->firstChild();
1657 i != NULL; 1656 i != NULL;
1658 i = i->nextSibling()) 1657 i = i->nextSibling())
1659 { 1658 {
1660 // step through all subitems 1659 // step through all subitems
1661 QListViewItem *si; 1660 QListViewItem *si;
1662 for (si = i->firstChild(); 1661 for (si = i->firstChild();
1663 si != NULL; ) 1662 si != NULL; )
1664 // si = si->nextSibling()) 1663 // si = si->nextSibling())
1665 { 1664 {
1666 QListViewItem *_si = si; 1665 QListViewItem *_si = si;
1667 si = si->nextSibling(); 1666 si = si->nextSibling();
1668 i->takeItem(_si); // remove from view list 1667 i->takeItem(_si); // remove from view list
1669 if (_si) delete _si; 1668 if (_si) delete _si;
1670 } 1669 }
1671 } 1670 }
1672 1671
1673 qWarning ("ReadAllEntries(): "); 1672 qWarning ("ReadAllEntries(): ");
1674 1673
1675 QTextStream t(&f); 1674 QTextStream t(&f);
1676 while ( !t.eof() ) 1675 while ( !t.eof() )
1677 { 1676 {
1678 QString s = t.readLine(); 1677 QString s = t.readLine();
1679 s.replace (QRegExp("\";\""), "\"|\""); 1678 s.replace (QRegExp("\";\""), "\"|\"");
1680 // char buffer[1024]; 1679 // char buffer[1024];
1681 int len=s.length()+1; 1680 int len=s.length()+1;
1682#ifdef WIN32 1681#ifdef WIN32
1683 char buffer[512]; 1682 char buffer[512];
1684#else 1683#else
1685 char buffer[len]; 1684 char buffer[len];
1686#endif 1685#endif
1687 strcpy (buffer, s); 1686 strcpy (buffer, s);
1688 1687
1689 QString name; 1688 QString name;
1690 QString user; 1689 QString user;
1691 QString password; 1690 QString password;
1692 QString comment; 1691 QString comment;
1693 1692
1694 // separete the entries 1693 // separete the entries
1695 char *i = strtok (buffer, "|"); 1694 char *i = strtok (buffer, "|");
1696 QString category(&i[1]); 1695 QString category(&i[1]);
1697 category.truncate(category.length() -1); 1696 category.truncate(category.length() -1);
1698 1697
1699 int idx=0; 1698 int idx=0;
1700 while (i = strtok (NULL, "|")) 1699 while (i = strtok (NULL, "|"))
1701 { 1700 {
1702 switch (idx) 1701 switch (idx)
1703 { 1702 {
1704 case 0: 1703 case 0:
1705 name = &i[1]; 1704 name = &i[1];
1706 name.truncate(name.length() -1); 1705 name.truncate(name.length() -1);
1707 // name 1706 // name
1708 break; 1707 break;
1709 case 1: 1708 case 1:
1710 // user 1709 // user
1711 user = &i[1]; 1710 user = &i[1];
1712 user.truncate(user.length() -1); 1711 user.truncate(user.length() -1);
1713 break; 1712 break;
1714 case 2: 1713 case 2:
1715 // password 1714 // password
1716 password = &i[1]; 1715 password = &i[1];
1717 password.truncate(password.length() -1); 1716 password.truncate(password.length() -1);
1718 break; 1717 break;
1719 case 3: 1718 case 3:
1720 // comment 1719 // comment
1721 comment = &i[1]; 1720 comment = &i[1];
1722 comment.truncate(comment.length() -1); 1721 comment.truncate(comment.length() -1);
1723 break; 1722 break;
1724 } 1723 }
1725 idx++; 1724 idx++;
1726 } 1725 }
1727 1726
1728 Category *cat= categories.find (category); 1727 Category *cat= categories.find (category);
1729 if (cat) 1728 if (cat)
1730 { 1729 {
1731 // use the existend item 1730 // use the existend item
1732 QListViewItem *catItem = cat->getListItem(); 1731 QListViewItem *catItem = cat->getListItem();
1733 if (catItem) 1732 if (catItem)
1734 { 1733 {
1735 QListViewItem * item = new ShadedListItem( 0, catItem ); 1734 QListViewItem * item = new ShadedListItem( 0, catItem );
1736 item->setText( 0, tr( name ) ); 1735 item->setText( 0, tr( name ) );
1737 item->setText( 1, tr( user ) ); 1736 item->setText( 1, tr( user ) );
1738 item->setText( 2, tr( password ) ); 1737 item->setText( 2, tr( password ) );
1739 item->setText( 3, tr( comment ) ); 1738 item->setText( 3, tr( comment ) );
1740 1739
1741 catItem->setOpen( TRUE ); 1740 catItem->setOpen( TRUE );
1742 } 1741 }
1743 } 1742 }
1744 else 1743 else
1745 { 1744 {
1746 QListViewItem *catI = new ShadedListItem( 1, ListView ); 1745 QListViewItem *catI = new ShadedListItem( 1, ListView );
1747 // create and insert a new item 1746 // create and insert a new item
1748 QListViewItem * item = new ShadedListItem( 0, catI ); 1747 QListViewItem * item = new ShadedListItem( 0, catI );
1749 item->setText( 0, tr( name ) ); 1748 item->setText( 0, tr( name ) );
1750 item->setText( 1, tr( user ) ); 1749 item->setText( 1, tr( user ) );
1751 item->setText( 2, tr( password ) ); 1750 item->setText( 2, tr( password ) );
1752 item->setText( 3, tr( comment ) ); 1751 item->setText( 3, tr( comment ) );
1753 1752
1754 catI->setOpen( TRUE ); 1753 catI->setOpen( TRUE );
1755 1754
1756 Category *c1 = new Category(); 1755 Category *c1 = new Category();
1757 c1->setCategoryName(category); 1756 c1->setCategoryName(category);
1758 1757
1759 QString icon; 1758 QString icon;
1760 QString fullIconPath; 1759 QString fullIconPath;
1761 QPixmap *pix; 1760 QPixmap *pix;
1762// #ifndef WIN32 1761// #ifndef WIN32
1763 icon = conf->readEntry(APP_KEY+category); 1762 icon = conf->readEntry(APP_KEY+category);
1764// #endif 1763// #endif
1765 bool isIconAv = false; 1764 bool isIconAv = false;
1766 if (!icon.isEmpty() && !icon.isNull()) 1765 if (!icon.isEmpty() && !icon.isNull())
1767 { 1766 {
1768 // build the full path 1767 // build the full path
1769 fullIconPath = iconPath + icon; 1768 fullIconPath = iconPath + icon;
1770 pix = new QPixmap (fullIconPath); 1769 pix = new QPixmap (fullIconPath);
1771 if (pix) 1770 if (pix)
1772 { 1771 {
1773 QImage img = pix->convertToImage(); 1772 QImage img = pix->convertToImage();
1774 pix->convertFromImage(img.smoothScale(14,14)); 1773 pix->convertFromImage(img.smoothScale(14,14));
1775 c1->setIconName (icon); 1774 c1->setIconName (icon);
1776 c1->setIcon (*pix); 1775 c1->setIcon (*pix);
1777 isIconAv = true; 1776 isIconAv = true;
1778 } 1777 }
1779 } 1778 }
1780 if (!isIconAv) 1779 if (!isIconAv)
1781 { 1780 {
1782 c1->setIcon (*getPredefinedIcon(category)); 1781 c1->setIcon (*getPredefinedIcon(category));
1783 } 1782 }
1784 c1->setListItem (catI); 1783 c1->setListItem (catI);
1785 c1->initListItem(); 1784 c1->initListItem();
1786 categories.insert (c1->getCategoryName(), c1); 1785 categories.insert (c1->getCategoryName(), c1);
1787 } 1786 }
1788 1787
1789 } 1788 }
1790 f.close(); 1789 f.close();
1791 1790
1792} 1791}
1793#endif // UNUSED 1792#endif // UNUSED
1794 1793
1795void ZSafe::resume(int) 1794void ZSafe::resume(int)
1796{ 1795{
1797 qWarning ("Resume"); 1796 qWarning ("Resume");
1798 // hide the main window 1797 // hide the main window
1799 1798
1800 infoForm->hide(); 1799 infoForm->hide();
1801 // open zsafe again 1800 // open zsafe again
1802 m_password = ""; 1801 m_password = "";
1803 selectedItem = NULL; 1802 selectedItem = NULL;
1804 1803
1805 // clear the password list 1804 // clear the password list
1806 QListViewItem *i; 1805 QListViewItem *i;
1807 // step through all categories 1806 // step through all categories
1808 for (i = ListView->firstChild(); 1807 for (i = ListView->firstChild();
1809 i != NULL; 1808 i != NULL;
1810 i = i->nextSibling()) 1809 i = i->nextSibling())
1811 { 1810 {
1812 // step through all subitems 1811 // step through all subitems
1813 QListViewItem *si; 1812 QListViewItem *si;
1814 for (si = i->firstChild(); 1813 for (si = i->firstChild();
1815 si != NULL; ) 1814 si != NULL; )
1816 { 1815 {
1817 QListViewItem *_si = si; 1816 QListViewItem *_si = si;
1818 si = si->nextSibling(); 1817 si = si->nextSibling();
1819 i->takeItem(_si); // remove from view list 1818 i->takeItem(_si); // remove from view list
1820 if (_si) delete _si; 1819 if (_si) delete _si;
1821 } 1820 }
1822 } 1821 }
1823 1822
1824 // ask for password and read again 1823 // ask for password and read again
1825 openDocument(filename); 1824 openDocument(filename);
1826} 1825}
1827 1826
1828//--------------------------------------------- 1827//---------------------------------------------
1829 1828
1830 1829
1831bool ZSafe::openDocument(const char* _filename, const char* ) 1830bool ZSafe::openDocument(const char* _filename, const char* )
1832{ 1831{
1833 int retval; 1832 int retval;
1834 char* entry[FIELD_SIZE]; 1833 char* entry[FIELD_SIZE];
1835// #ifndef WIN32 1834// #ifndef WIN32
1836 int validationFlag = conf->readNumEntry(APP_KEY+"valzsafe", 1); 1835 int validationFlag = conf->readNumEntry(APP_KEY+"valzsafe", 1);
1837// #else 1836// #else
1838 // int validationFlag = 1; 1837 // int validationFlag = 1;
1839// #endif 1838// #endif
1840 1839
1841 int pwdOk = 0; 1840 int pwdOk = 0;
1842 int numberOfTries = 3; 1841 int numberOfTries = 3;
1843 for (int i=0; i < numberOfTries; i++) 1842 for (int i=0; i < numberOfTries; i++)
1844 { 1843 {
1845 QFile f(_filename); 1844 QFile f(_filename);
1846 if (f.exists()) 1845 if (f.exists())
1847 { 1846 {
1848 // ask with a dialog for the password 1847 // ask with a dialog for the password
1849 if (m_password.isEmpty()) 1848 if (m_password.isEmpty())
1850 getDocPassword(tr("Enter Password")); 1849 getDocPassword(tr("Enter Password"));
1851 if (m_password.isEmpty() && validationFlag == 0) 1850 if (m_password.isEmpty() && validationFlag == 0)
1852 { 1851 {
1853 qWarning ("Wrong password"); 1852 qWarning ("Wrong password");
1854 QMessageBox::critical( 0, tr("ZSafe"), 1853 QMessageBox::critical( 0, tr("ZSafe"),
1855 tr("Wrong password.\n\nZSafe will now exit.") ); 1854 tr("Wrong password.\n\nZSafe will now exit.") );
1856 exitZs (1); 1855 exitZs (1);
1857 } 1856 }
1858 1857
1859 retval = loadInit(_filename, m_password); 1858 retval = loadInit(_filename, m_password);
1860 if (retval != PWERR_GOOD) 1859 if (retval != PWERR_GOOD)
1861 { 1860 {
1862 qWarning ("Error loading Document"); 1861 qWarning ("Error loading Document");
1863 return false; 1862 return false;
1864 } 1863 }
1865 } 1864 }
1866 else 1865 else
1867 { 1866 {
1868#ifdef WIN32 1867#ifdef WIN32
1869 this->setCaption("Qt ZSafe"); 1868 this->setCaption("Qt ZSafe");
1870#else 1869#else
1871 this->setCaption("ZSafe"); 1870 this->setCaption("ZSafe");
1872#endif 1871#endif
1873 filename = ""; 1872 filename = "";
1874 return false; 1873 return false;
1875 } 1874 }
1876 1875
1877 1876
1878 // load the validation entry 1877 // load the validation entry
1879 if (validationFlag == 0) 1878 if (validationFlag == 0)
1880 { 1879 {
1881 pwdOk = 1; 1880 pwdOk = 1;
1882 break; 1881 break;
1883 } 1882 }
1884 1883
1885 retval = loadEntry(entry); 1884 retval = loadEntry(entry);
1886 if (retval == 1 && 1885 if (retval == 1 &&
1887 !strcmp (entry[0], "ZSAFECATEGORY") && 1886 !strcmp (entry[0], "ZSAFECATEGORY") &&
1888 !strcmp (entry[1], "name") && 1887 !strcmp (entry[1], "name") &&
1889 !strcmp (entry[2], "username") && 1888 !strcmp (entry[2], "username") &&
1890 !strcmp (entry[3], "password") && 1889 !strcmp (entry[3], "password") &&
1891 !strcmp (entry[4], "comment") ) 1890 !strcmp (entry[4], "comment") )
1892 { 1891 {
1893 for (int count = 0; count < FIELD_SIZE; count++) free(entry[count]); 1892 for (int count = 0; count < FIELD_SIZE; count++) free(entry[count]);
1894 pwdOk = 1; 1893 pwdOk = 1;
1895 break; 1894 break;
1896 } 1895 }
1897 else 1896 else
1898 // for (int count = 0; count < FIELD_SIZE; count++) free(entry[count]); 1897 // for (int count = 0; count < FIELD_SIZE; count++) free(entry[count]);
1899 fclose (fd); 1898 fclose (fd);
1900 m_password = ""; 1899 m_password = "";
1901 1900
1902 if (i < numberOfTries - 1) 1901 if (i < numberOfTries - 1)
1903 { 1902 {
1904 switch( QMessageBox::warning( this, tr("ZSafe"), 1903 switch( QMessageBox::warning( this, tr("ZSafe"),
1905 tr("Wrong password.\nEnter again?"), 1904 tr("Wrong password.\nEnter again?"),
1906 tr("&Yes"), tr("&No."), 1905 tr("&Yes"), tr("&No."),
1907 0 1906 0
1908 ) ) 1907 ) )
1909 { 1908 {
1910 case 1: // No 1909 case 1: // No
1911 exitZs (1); 1910 exitZs (1);
1912 break; 1911 break;
1913 case 0: // Yes 1912 case 0: // Yes
1914 continue; 1913 continue;
1915 } 1914 }
1916 } 1915 }
1917 } 1916 }
1918 if (pwdOk == 0) 1917 if (pwdOk == 0)
1919 { 1918 {
1920 // unset the document entry 1919 // unset the document entry
1921 conf->writeEntry(APP_KEY+"document", "INVALIDPWD"); 1920 conf->writeEntry(APP_KEY+"document", "INVALIDPWD");
1922 if (conf) 1921 if (conf)
1923 delete conf; 1922 delete conf;
1924 1923
1925 exitZs (1); 1924 exitZs (1);
1926 } 1925 }
1927 1926
1928 1927
1929 retval = loadEntry(entry); 1928 retval = loadEntry(entry);
1930 1929
1931 int numberOfEntries=0; 1930 int numberOfEntries=0;
1932 while (retval == 1) { 1931 while (retval == 1) {
1933 1932
1934 QString category( QString::fromUtf8(entry[0]) ); 1933 QString category( QString::fromUtf8(entry[0]) );
1935 QString name( QString::fromUtf8(entry[1]) ); 1934 QString name( QString::fromUtf8(entry[1]) );
1936 QString user( QString::fromUtf8(entry[2]) ); 1935 QString user( QString::fromUtf8(entry[2]) );
1937 QString password( QString::fromUtf8(entry[3]) ); 1936 QString password( QString::fromUtf8(entry[3]) );
1938 QString comment( QString::fromUtf8(entry[4]) ); 1937 QString comment( QString::fromUtf8(entry[4]) );
1939 QString field5( QString::fromUtf8(entry[5]) ); 1938 QString field5( QString::fromUtf8(entry[5]) );
1940 QString field6( QString::fromUtf8(entry[6]) ); 1939 QString field6( QString::fromUtf8(entry[6]) );
1941 // add the subitems to the categories 1940 // add the subitems to the categories
1942 1941
1943 Category *cat= categories.find (category); 1942 Category *cat= categories.find (category);
1944 if (cat) 1943 if (cat)
1945 { 1944 {
1946 // use the existend item 1945 // use the existend item
1947 QListViewItem *catItem = cat->getListItem(); 1946 QListViewItem *catItem = cat->getListItem();
1948 if (catItem) 1947 if (catItem)
1949 { 1948 {
1950 QListViewItem * item = new ShadedListItem( 0, catItem ); 1949 QListViewItem * item = new ShadedListItem( 0, catItem );
1951 item->setText( 0, tr( name ) ); 1950 item->setText( 0, tr( name ) );
1952 item->setText( 1, tr( user ) ); 1951 item->setText( 1, tr( user ) );
1953 item->setText( 2, tr( password ) ); 1952 item->setText( 2, tr( password ) );
1954 item->setText( 3, tr( comment ) ); 1953 item->setText( 3, tr( comment ) );
1955 item->setText( 4, tr( field5 ) ); 1954 item->setText( 4, tr( field5 ) );
1956 item->setText( 5, tr( field6 ) ); 1955 item->setText( 5, tr( field6 ) );
1957 1956
1958 if (expandTree) 1957 if (expandTree)
1959 catItem->setOpen( TRUE ); 1958 catItem->setOpen( TRUE );
1960 numberOfEntries++; 1959 numberOfEntries++;
1961 } 1960 }
1962 } 1961 }
1963 else 1962 else
1964 { 1963 {
1965 QListViewItem *catI = new ShadedListItem( 1, ListView ); 1964 QListViewItem *catI = new ShadedListItem( 1, ListView );
1966 // create and insert a new item 1965 // create and insert a new item
1967 QListViewItem * item = new ShadedListItem( 0, catI ); 1966 QListViewItem * item = new ShadedListItem( 0, catI );
1968 1967
1969 item->setText( 0, tr( name ) ); 1968 item->setText( 0, tr( name ) );
1970 item->setText( 1, tr( user ) ); 1969 item->setText( 1, tr( user ) );
1971 item->setText( 2, tr( password ) ); 1970 item->setText( 2, tr( password ) );
1972 item->setText( 3, tr( comment ) ); 1971 item->setText( 3, tr( comment ) );
1973 item->setText( 4, tr( field5 ) ); 1972 item->setText( 4, tr( field5 ) );
1974 item->setText( 5, tr( field6 ) ); 1973 item->setText( 5, tr( field6 ) );
1975 1974
1976 if (expandTree) 1975 if (expandTree)
1977 catI->setOpen( TRUE ); 1976 catI->setOpen( TRUE );
1978 1977
1979 Category *c1 = new Category(); 1978 Category *c1 = new Category();
1980 c1->setCategoryName(category); 1979 c1->setCategoryName(category);
1981 1980
1982 QString icon; 1981 QString icon;
1983 QString fullIconPath; 1982 QString fullIconPath;
1984 QPixmap *pix; 1983 QPixmap *pix;
1985// #ifndef WIN32 1984// #ifndef WIN32
1986 icon = conf->readEntry(APP_KEY+category); 1985 icon = conf->readEntry(APP_KEY+category);
1987// #endif 1986// #endif
1988 bool isIconAv = false; 1987 bool isIconAv = false;
1989 if (!icon.isEmpty() && !icon.isNull()) 1988 if (!icon.isEmpty() && !icon.isNull())
1990 { 1989 {
1991 // build the full path 1990 // build the full path
1992 fullIconPath = iconPath + icon; 1991 fullIconPath = iconPath + icon;
1993 pix = new QPixmap (fullIconPath); 1992 pix = new QPixmap (fullIconPath);
1994 if (pix) 1993 if (pix)
1995 { 1994 {
1996 QImage img = pix->convertToImage(); 1995 QImage img = pix->convertToImage();
1997 pix->convertFromImage(img.smoothScale(14,14)); 1996 pix->convertFromImage(img.smoothScale(14,14));
1998 c1->setIconName (icon); 1997 c1->setIconName (icon);
1999 c1->setIcon (*pix); 1998 c1->setIcon (*pix);
2000 isIconAv = true; 1999 isIconAv = true;
2001 } 2000 }
2002 } 2001 }
2003 if (!isIconAv) 2002 if (!isIconAv)
2004 { 2003 {
2005 c1->setIcon (*getPredefinedIcon(category)); 2004 c1->setIcon (*getPredefinedIcon(category));
2006 } 2005 }
2007 2006
2008 c1->setListItem (catI); 2007 c1->setListItem (catI);
2009 c1->initListItem(); 2008 c1->initListItem();
2010 categories.insert (c1->getCategoryName(), c1); 2009 categories.insert (c1->getCategoryName(), c1);
2011 numberOfEntries++; 2010 numberOfEntries++;
2012 } 2011 }
2013 2012
2014 for (int count = 0; count < FIELD_SIZE; count++) { 2013 for (int count = 0; count < FIELD_SIZE; count++) {
2015 free(entry[count]); 2014 free(entry[count]);
2016 } 2015 }
2017 retval = loadEntry(entry); 2016 retval = loadEntry(entry);
2018 if (retval == 2) { 2017 if (retval == 2) {
2019 // m_parent->slotStatusHelpMsg("Last entry loaded"); 2018 // m_parent->slotStatusHelpMsg("Last entry loaded");
2020 } 2019 }
2021 } // end while 2020 } // end while
2022 2021
2023 if (numberOfEntries == 0) 2022 if (numberOfEntries == 0)
2024 { 2023 {
2025 2024
2026 switch( QMessageBox::warning( this, tr("ZSafe"), 2025 switch( QMessageBox::warning( this, tr("ZSafe"),
2027 tr("Empty document or\nwrong password.\nContinue?"), 2026 tr("Empty document or\nwrong password.\nContinue?"),
2028 tr("&No"), tr("&Yes."), 2027 tr("&No"), tr("&Yes."),
2029 0 2028 0
2030 ) ) { 2029 ) ) {
2031 case 0: // No 2030 case 0: // No
2032 retval = loadFinalize(); 2031 retval = loadFinalize();
2033 exitZs (1); 2032 exitZs (1);
2034 break; 2033 break;
2035 case 1: // Yes 2034 case 1: // Yes
2036 break; 2035 break;
2037 } 2036 }
2038 } 2037 }
2039 2038
2040 retval = loadFinalize(); 2039 retval = loadFinalize();
2041 2040
2042 return true; 2041 return true;
2043} 2042}
2044 2043
2045int ZSafe::loadInit(const char* _filename, const char *password) 2044int ZSafe::loadInit(const char* _filename, const char *password)
2046{ 2045{
2047 unsigned int j = 0; 2046 unsigned int j = 0;
2048 unsigned int keylength=0; 2047 unsigned int keylength=0;
2049 int count=0, count2=0, count3=0; 2048 int count=0, count2=0, count3=0;
2050 unsigned char charbuf[8]; 2049 unsigned char charbuf[8];
2051 unsigned short ciphertext[4]; 2050 unsigned short ciphertext[4];
2052 char key[128]; 2051 char key[128];
2053 Krc2* krc2 = new Krc2(); 2052 Krc2* krc2 = new Krc2();
2054 2053
2055 fd = fopen (_filename, "rb"); 2054 fd = fopen (_filename, "rb");
2056 2055
2057 QFileInfo f (_filename); 2056 QFileInfo f (_filename);
2058 load_buffer_length = f.size(); 2057 load_buffer_length = f.size();
2059 load_buffer_length = ((load_buffer_length / 1024)+1) * 1024 * 2; 2058 load_buffer_length = ((load_buffer_length / 1024)+1) * 1024 * 2;
2060 2059
2061 if (fd == NULL) 2060 if (fd == NULL)
2062 return PWERR_OPEN; 2061 return PWERR_OPEN;
2063 2062
2064 buffer = (char *)malloc(load_buffer_length); 2063 buffer = (char *)malloc(load_buffer_length);
2065 for (j = 0; password[j] != '\0'; j++) { 2064 for (j = 0; password[j] != '\0'; j++) {
2066 key[j] = password[j]; 2065 key[j] = password[j];
2067 } 2066 }
2068 keylength = j; 2067 keylength = j;
2069 krc2->rc2_expandkey (key, keylength, 128); 2068 krc2->rc2_expandkey (key, keylength, 128);
2070 2069
2071#ifndef WIN32 2070#ifndef WIN32
2072 size = read(fileno (fd), (unsigned char *) (charbuf + count), 8); 2071 size = read(fileno (fd), (unsigned char *) (charbuf + count), 8);
2073#else 2072#else
2074 printf ("LoadInit() read1"); 2073 printf ("LoadInit() read1");
2075 size = fread ((unsigned char *) (charbuf + count), sizeof(unsigned char), 8, fd); 2074 size = fread ((unsigned char *) (charbuf + count), sizeof(unsigned char), 8, fd);
2076#endif 2075#endif
2077 2076
2078 if (size < 8) 2077 if (size < 8)
2079 return PWERR_DATA; 2078 return PWERR_DATA;
2080 2079
2081 for (count = 0; count < 4; count++) { 2080 for (count = 0; count < 4; count++) {
2082 count2 = count << 1; 2081 count2 = count << 1;
2083 iv[count] = charbuf[count2] << 8; 2082 iv[count] = charbuf[count2] << 8;
2084 iv[count] += charbuf[count2 + 1]; 2083 iv[count] += charbuf[count2 + 1];
2085 } 2084 }
2086 2085
2087 size = 0; 2086 size = 0;
2088 bufferIndex = 0; 2087 bufferIndex = 0;
2089#ifndef WIN32 2088#ifndef WIN32
2090 while ((count = read (fileno (fd), (unsigned char *) charbuf, 8)) > 0) { 2089 while ((count = read (fileno (fd), (unsigned char *) charbuf, 8)) > 0) {
2091 while (count < 8) { 2090 while (count < 8) {
2092 count2 = read (fileno (fd), (unsigned char *) (charbuf + count), 8); 2091 count2 = read (fileno (fd), (unsigned char *) (charbuf + count), 8);
2093#else 2092#else
2094 printf ("LoadInit() read2"); 2093 printf ("LoadInit() read2");
2095 while ((count = fread ((unsigned char *) (charbuf), sizeof(unsigned char), 8, fd)) > 0) { 2094 while ((count = fread ((unsigned char *) (charbuf), sizeof(unsigned char), 8, fd)) > 0) {
2096 while (count < 8) { 2095 while (count < 8) {
2097 count2 = fread ((unsigned char *) (charbuf + count), sizeof(unsigned char), 8, fd); 2096 count2 = fread ((unsigned char *) (charbuf + count), sizeof(unsigned char), 8, fd);
2098#endif 2097#endif
2099 if (count2 == 0) { 2098 if (count2 == 0) {
2100 return PWERR_DATA; 2099 return PWERR_DATA;
2101 } 2100 }
2102 count += count2; 2101 count += count2;
2103 } /* while (count < 8) */ 2102 } /* while (count < 8) */
2104 2103
2105 size += 8; 2104 size += 8;
2106 for (count2 = 0; count2 < 8; count2 += 2) { 2105 for (count2 = 0; count2 < 8; count2 += 2) {
2107 count3 = count2 >> 1; 2106 count3 = count2 >> 1;
2108 ciphertext[count3] = charbuf[count2] << 8; 2107 ciphertext[count3] = charbuf[count2] << 8;
2109 ciphertext[count3] += charbuf[count2 + 1]; 2108 ciphertext[count3] += charbuf[count2 + 1];
2110 2109
2111 plaintext[count3] = ciphertext[count3] ^ iv[count3]; 2110 plaintext[count3] = ciphertext[count3] ^ iv[count3];
2112 iv[count3] = plaintext[count3]; 2111 iv[count3] = plaintext[count3];
2113 } /* for (count2) */ 2112 } /* for (count2) */
2114 2113
2115 krc2->rc2_decrypt (plaintext); 2114 krc2->rc2_decrypt (plaintext);
2116 memcpy ((unsigned char *) (buffer + bufferIndex), plaintext, 8); 2115 memcpy ((unsigned char *) (buffer + bufferIndex), plaintext, 8);
2117 bufferIndex += 8; 2116 bufferIndex += 8;
2118 buffer[bufferIndex + 1] = '\0'; 2117 buffer[bufferIndex + 1] = '\0';
2119 } /* while ((count = read (fileno (fd), (unsigned char *) charbuf, 8)) > 0) */ 2118 } /* while ((count = read (fileno (fd), (unsigned char *) charbuf, 8)) > 0) */
2120 size -= buffer[size - 1]; 2119 size -= buffer[size - 1];
2121 lastcount = 0; 2120 lastcount = 0;
2122 2121
2123 /* This will point to the starting index */ 2122 /* This will point to the starting index */
2124 bufferIndex = 0; 2123 bufferIndex = 0;
2125 return PWERR_GOOD; 2124 return PWERR_GOOD;
2126} 2125}
2127 2126
2128int ZSafe::loadEntry(char *entry[FIELD_SIZE]) 2127int ZSafe::loadEntry(char *entry[FIELD_SIZE])
2129{ 2128{
2130 /* Strip off PKCS 5 padding 2129 /* Strip off PKCS 5 padding
2131 * Should check to make sure it's good here 2130 * Should check to make sure it's good here
2132 */ 2131 */
2133 int count, count1=0; 2132 int count, count1=0;
2134 2133
2135 for (count = lastcount; count < size; count++) { 2134 for (count = lastcount; count < size; count++) {
2136 if ((unsigned char) (buffer[count]) == 255) { 2135 if ((unsigned char) (buffer[count]) == 255) {
2137 if (buffer[bufferIndex] == '\0') { 2136 if (buffer[bufferIndex] == '\0') {
2138 bufferIndex++; 2137 bufferIndex++;
2139 } 2138 }
2140 entry[count1] = (char *) malloc (count - bufferIndex + 1); 2139 entry[count1] = (char *) malloc (count - bufferIndex + 1);
2141 memcpy (entry[count1], (unsigned char *) (buffer + bufferIndex), count - bufferIndex); 2140 memcpy (entry[count1], (unsigned char *) (buffer + bufferIndex), count - bufferIndex);
2142 entry[count1][count - bufferIndex] = '\0'; 2141 entry[count1][count - bufferIndex] = '\0';
2143 count++; 2142 count++;
2144 bufferIndex = count; 2143 bufferIndex = count;
2145 count1++; 2144 count1++;
2146 if (count1 == FIELD_SIZE) { 2145 if (count1 == FIELD_SIZE) {
2147 lastcount = count; 2146 lastcount = count;
2148 return 1; 2147 return 1;
2149 } 2148 }
2150 } /* if ((unsigned char) (buffer[count]) == 255) */ 2149 } /* if ((unsigned char) (buffer[count]) == 255) */
2151 } /* for (count = 0; count < size; count++) */ 2150 } /* for (count = 0; count < size; count++) */
2152 2151
2153 return 2; 2152 return 2;
2154} 2153}
2155 2154
2156int ZSafe::loadFinalize(void) 2155int ZSafe::loadFinalize(void)
2157{ 2156{
2158 fclose (fd); 2157 fclose (fd);
2159 if (buffer) free(buffer); 2158 if (buffer) free(buffer);
2160 return PWERR_GOOD; 2159 return PWERR_GOOD;
2161} 2160}
2162 2161
2163bool ZSafe::saveDocument(const char* _filename, 2162bool ZSafe::saveDocument(const char* _filename,
2164 bool withPwd, 2163 bool withPwd,
2165 const char* ) 2164 const char* )
2166{ 2165{
2167 if (filename.isEmpty()) 2166 if (filename.isEmpty())
2168 { 2167 {
2169 QMessageBox::critical( 0, tr("ZSafe"), 2168 QMessageBox::critical( 0, tr("ZSafe"),
2170 tr("No document defined.\nYou have to create a new document")); 2169 tr("No document defined.\nYou have to create a new document"));
2171 return false; 2170 return false;
2172 } 2171 }
2173 2172
2174 // if (m_password.isEmpty()) 2173 // if (m_password.isEmpty())
2175 // withPwd = true; // the document must be saved with a valid password 2174 // withPwd = true; // the document must be saved with a valid password
2176 if (withPwd) 2175 if (withPwd)
2177 { 2176 {
2178 bool pwdOk = FALSE; 2177 bool pwdOk = FALSE;
2179 while (!pwdOk) 2178 while (!pwdOk)
2180 { 2179 {
2181 getDocPassword(tr("Enter Password")); 2180 getDocPassword(tr("Enter Password"));
2182 if (m_password.isEmpty()) 2181 if (m_password.isEmpty())
2183 { 2182 {
2184 2183
2185 QMessageBox::critical( 0, tr("ZSafe"), 2184 QMessageBox::critical( 0, tr("ZSafe"),
2186 tr("Password is empty.\nPlease enter again.")); 2185 tr("Password is empty.\nPlease enter again."));
2187 continue; 2186 continue;
2188 } 2187 }
2189 2188
2190 QString firstPasswd = m_password; 2189 QString firstPasswd = m_password;
2191 2190
2192 getDocPassword(tr("Reenter Password")); 2191 getDocPassword(tr("Reenter Password"));
2193 if (m_password.isEmpty()) 2192 if (m_password.isEmpty())
2194 { 2193 {
2195 QMessageBox::critical( 0, tr("ZSafe"), 2194 QMessageBox::critical( 0, tr("ZSafe"),
2196 tr("Password is empty.\nPlease enter again.")); 2195 tr("Password is empty.\nPlease enter again."));
2197 continue; 2196 continue;
2198 } 2197 }
2199 if (firstPasswd != m_password) 2198 if (firstPasswd != m_password)
2200 { 2199 {
2201 2200
2202 QMessageBox::critical( 0, tr("ZSafe"), 2201 QMessageBox::critical( 0, tr("ZSafe"),
2203 tr("Passwords must be identical.\nPlease enter again.")); 2202 tr("Passwords must be identical.\nPlease enter again."));
2204 continue; 2203 continue;
2205 } 2204 }
2206 pwdOk = TRUE; 2205 pwdOk = TRUE;
2207 modified = false; 2206 modified = false;
2208 } 2207 }
2209 } 2208 }
2210 else if (modified) 2209 else if (modified)
2211 { 2210 {
2212 QString fns(_filename); 2211 QString fns(_filename);
2213 fns = fns.right (fns.length() - fns.findRev ('/') - 1); 2212 fns = fns.right (fns.length() - fns.findRev ('/') - 1);
2214 switch( QMessageBox::information( this, tr("ZSafe"), 2213 switch( QMessageBox::information( this, tr("ZSafe"),
2215 tr("Do you want to save ") + fns + tr("\nbefore continuing?"), 2214 tr("Do you want to save ") + fns + tr("\nbefore continuing?"),
2216 tr("&Save"), 2215 tr("&Save"),
2217 tr("&Don't Save"), 2216 tr("&Don't Save"),
2218 0 // Enter == button 0 2217 0 // Enter == button 0
2219 ) ) 2218 ) )
2220 { // Escape == button 2 2219 { // Escape == button 2
2221 case 0: // Save clicked, Alt-S or Enter pressed. 2220 case 0: // Save clicked, Alt-S or Enter pressed.
2222 modified = false; 2221 modified = false;
2223 break; 2222 break;
2224 case 1: // Don't Save clicked or Alt-D pressed 2223 case 1: // Don't Save clicked or Alt-D pressed
2225 modified = false; 2224 modified = false;
2226 return true; 2225 return true;
2227 } 2226 }
2228 } 2227 }
2229 modified = false; 2228 modified = false;
2230 2229
2231 if (m_password.isEmpty()) 2230 if (m_password.isEmpty())
2232 return false; 2231 return false;
2233 2232
2234 int retval = saveInit(_filename, m_password); 2233 int retval = saveInit(_filename, m_password);
2235 // int retval = saveInit(_filename, "test"); 2234 // int retval = saveInit(_filename, "test");
2236 if (retval != PWERR_GOOD) { 2235 if (retval != PWERR_GOOD) {
2237 return false; 2236 return false;
2238 } 2237 }
2239 2238
2240 char* entry[FIELD_SIZE]; 2239 char* entry[FIELD_SIZE];
2241 2240
2242 // save the validation entry 2241 // save the validation entry
2243 { 2242 {
2244 int i=0; 2243 int i=0;
2245 entry[i] = (char*)malloc(strlen("ZSAFECATEGORY")+1); 2244 entry[i] = (char*)malloc(strlen("ZSAFECATEGORY")+1);
2246 strcpy(entry[i++], "ZSAFECATEGORY"); 2245 strcpy(entry[i++], "ZSAFECATEGORY");
2247 entry[i] = (char*)malloc(strlen("name")+1); 2246 entry[i] = (char*)malloc(strlen("name")+1);
2248 strcpy(entry[i++], "name"); 2247 strcpy(entry[i++], "name");
2249 entry[i] = (char*)malloc(strlen("username")+1); 2248 entry[i] = (char*)malloc(strlen("username")+1);
2250 strcpy(entry[i++], "username"); 2249 strcpy(entry[i++], "username");
2251 entry[i] = (char*)malloc(strlen("password")+1); 2250 entry[i] = (char*)malloc(strlen("password")+1);
2252 strcpy(entry[i++], "password"); 2251 strcpy(entry[i++], "password");
2253 entry[i] = (char*)malloc(strlen("comment")+1); 2252 entry[i] = (char*)malloc(strlen("comment")+1);
2254 strcpy(entry[i++], "comment"); 2253 strcpy(entry[i++], "comment");
2255 2254
2256 entry[i] = (char*)malloc(strlen("field5")+1); 2255 entry[i] = (char*)malloc(strlen("field5")+1);
2257 strcpy(entry[i++], "field5"); 2256 strcpy(entry[i++], "field5");
2258 entry[i] = (char*)malloc(strlen("field6")+1); 2257 entry[i] = (char*)malloc(strlen("field6")+1);
2259 strcpy(entry[i++], "field6"); 2258 strcpy(entry[i++], "field6");
2260 2259
2261 retval = saveEntry(entry); 2260 retval = saveEntry(entry);
2262 for (int z=0; z<i; z++) free(entry[z]); 2261 for (int z=0; z<i; z++) free(entry[z]);
2263 if (retval == PWERR_DATA) { 2262 if (retval == PWERR_DATA) {
2264 qWarning("1: Error writing file, contents not saved"); 2263 qWarning("1: Error writing file, contents not saved");
2265 saveFinalize(); 2264 saveFinalize();
2266 return false; 2265 return false;
2267 } 2266 }
2268// #ifndef WIN32 2267// #ifndef WIN32
2269 conf->writeEntry(APP_KEY+"valzsafe", 1); 2268 conf->writeEntry(APP_KEY+"valzsafe", 1);
2270// #endif 2269// #endif
2271 saveConf(); 2270 saveConf();
2272 } 2271 }
2273 2272
2274 QListViewItem *i; 2273 QListViewItem *i;
2275 // step through all categories 2274 // step through all categories
2276 for (i = ListView->firstChild(); 2275 for (i = ListView->firstChild();
2277 i != NULL; 2276 i != NULL;
2278 i = i->nextSibling()) 2277 i = i->nextSibling())
2279 { 2278 {
2280 // step through all subitems 2279 // step through all subitems
2281 QListViewItem *si; 2280 QListViewItem *si;
2282 for (si = i->firstChild(); 2281 for (si = i->firstChild();
2283 si != NULL; 2282 si != NULL;
2284 si = si->nextSibling()) 2283 si = si->nextSibling())
2285 { 2284 {
2286 int j=0; 2285 int j=0;
2287 entry[j] = (char*)malloc(strlen(i->text(0).utf8())+1); 2286 entry[j] = (char*)malloc(strlen(i->text(0).utf8())+1);
2288 strcpy(entry[j++], i->text(0).utf8()); 2287 strcpy(entry[j++], i->text(0).utf8());
2289 entry[j] = (char*)malloc(strlen(si->text(0).utf8())+1); 2288 entry[j] = (char*)malloc(strlen(si->text(0).utf8())+1);
2290 strcpy(entry[j++], si->text(0).utf8()); 2289 strcpy(entry[j++], si->text(0).utf8());
2291 entry[j] = (char*)malloc(strlen(si->text(1).utf8())+1); 2290 entry[j] = (char*)malloc(strlen(si->text(1).utf8())+1);
2292 strcpy(entry[j++], si->text(1).utf8()); 2291 strcpy(entry[j++], si->text(1).utf8());
2293 entry[j] = (char*)malloc(strlen(si->text(2).utf8())+1); 2292 entry[j] = (char*)malloc(strlen(si->text(2).utf8())+1);
2294 strcpy(entry[j++], si->text(2).utf8()); 2293 strcpy(entry[j++], si->text(2).utf8());
2295 entry[j] = (char*)malloc(strlen(si->text(3).utf8())+1); 2294 entry[j] = (char*)malloc(strlen(si->text(3).utf8())+1);
2296 strcpy(entry[j++], si->text(3).utf8()); 2295 strcpy(entry[j++], si->text(3).utf8());
2297 entry[j] = (char*)malloc(strlen(si->text(4).utf8())+1); 2296 entry[j] = (char*)malloc(strlen(si->text(4).utf8())+1);
2298 strcpy(entry[j++], si->text(4).utf8()); 2297 strcpy(entry[j++], si->text(4).utf8());
2299 entry[j] = (char*)malloc(strlen(si->text(5).utf8())+1); 2298 entry[j] = (char*)malloc(strlen(si->text(5).utf8())+1);
2300 strcpy(entry[j++], si->text(5).utf8()); 2299 strcpy(entry[j++], si->text(5).utf8());
2301 2300
2302 retval = saveEntry(entry); 2301 retval = saveEntry(entry);
2303 for (int z=0; z<j; z++) 2302 for (int z=0; z<j; z++)
2304 { 2303 {
2305 free(entry[z]); 2304 free(entry[z]);
2306 } 2305 }
2307 if (retval == PWERR_DATA) { 2306 if (retval == PWERR_DATA) {
2308 qWarning("1: Error writing file, contents not saved"); 2307 qWarning("1: Error writing file, contents not saved");
2309 saveFinalize(); 2308 saveFinalize();
2310 return false; 2309 return false;
2311 } 2310 }
2312 2311
2313 } 2312 }
2314 } 2313 }
2315 2314
2316 if (saveFinalize() == PWERR_DATA) { 2315 if (saveFinalize() == PWERR_DATA) {
2317 qWarning("2: Error writing file, contents not saved"); 2316 qWarning("2: Error writing file, contents not saved");
2318 return false; 2317 return false;
2319 } else { 2318 } else {
2320#ifndef DESKTOP 2319#ifndef DESKTOP
2321 Global::statusMessage (tr("Password file saved.")); 2320 Global::statusMessage (tr("Password file saved."));
2322#endif 2321#endif
2323 modified = false; 2322 modified = false;
2324 return true; 2323 return true;
2325 } 2324 }
2326} 2325}
2327 2326
2328PasswordForm *newPwdDialog; 2327PasswordForm *newPwdDialog;
2329bool newPwdDialogResult = false; 2328bool newPwdDialogResult = false;
2330void ZSafe::setPasswordDialogDone() 2329void ZSafe::setPasswordDialogDone()
2331{ 2330{
2332 newPwdDialogResult = true; 2331 newPwdDialogResult = true;
2333 newPwdDialog->close(); 2332 newPwdDialog->close();
2334} 2333}
2335 2334
2336void ZSafe::getDocPassword(QString title) 2335void ZSafe::getDocPassword(QString title)
2337{ 2336{
2338qWarning ("getDocPassword"); 2337qWarning ("getDocPassword");
2339 // open the 'Password' dialog 2338 // open the 'Password' dialog
2340 PasswordForm *dialog = new PasswordForm(this, title, TRUE); 2339 PasswordForm *dialog = new PasswordForm(this, title, TRUE);
2341 newPwdDialog = dialog; 2340 newPwdDialog = dialog;
2342 newPwdDialogResult = false; 2341 newPwdDialogResult = false;
2343 2342
2344 connect( dialog->PasswordField, SIGNAL( returnPressed() ), 2343 connect( dialog->PasswordField, SIGNAL( returnPressed() ),
2345 this, SLOT( setPasswordDialogDone() ) ); 2344 this, SLOT( setPasswordDialogDone() ) );
2346 2345
2347 // CS: !!! 2346 // CS: !!!
2348 // int pos = filename.findRev ('/'); 2347 // int pos = filename.findRev ('/');
2349 QString ti = filename.right (filename.length() - filename.findRev ('/') - 1); 2348 QString ti = filename.right (filename.length() - filename.findRev ('/') - 1);
2350#ifdef WIN32 2349#ifdef WIN32
2351 dialog->setCaption("Qt " + ti); 2350 dialog->setCaption("Qt " + ti);
2352#else 2351#else
2353 dialog->setCaption(ti); 2352 dialog->setCaption(ti);
2354#endif 2353#endif
2355 // dialog->setCaption(title); 2354 // dialog->setCaption(title);
2356 2355
2357 dialog->PasswordField->setFocus(); 2356 dialog->PasswordField->setFocus();
2358 DialogCode result = (DialogCode) dialog->exec(); 2357 DialogCode result = (DialogCode) dialog->exec();
2359#ifdef DESKTOP 2358#ifdef DESKTOP
2360 result = Accepted; 2359 result = Accepted;
2361#endif 2360#endif
2362 2361
2363 QString password; 2362 QString password;
2364 if (result == Accepted || newPwdDialogResult) 2363 if (result == Accepted || newPwdDialogResult)
2365 { 2364 {
2366 m_password = dialog->PasswordField->text(); 2365 m_password = dialog->PasswordField->text();
2367 } 2366 }
2368 else 2367 else
2369 { 2368 {
2370 exitZs (1); 2369 exitZs (1);
2371 } 2370 }
2372} 2371}
2373 2372
2374int ZSafe::saveInit(const char *_filename, const char *password) 2373int ZSafe::saveInit(const char *_filename, const char *password)
2375{ 2374{
2376 char key[128]; 2375 char key[128];
2377 unsigned int j = 0; 2376 unsigned int j = 0;
2378 unsigned int keylength; 2377 unsigned int keylength;
2379 // int val; 2378 // int val;
2380 int count2; 2379 int count2;
2381 Krc2* krc2 = new Krc2(); 2380 Krc2* krc2 = new Krc2();
2382 2381
2383 /* first we should check the permissions of the filename */ 2382 /* first we should check the permissions of the filename */
2384/* 2383/*
2385 if (QFile::exists(_filename)) { 2384 if (QFile::exists(_filename)) {
2386 val = checkFile(_filename); 2385 val = checkFile(_filename);
2387 if (val != PWERR_GOOD) 2386 if (val != PWERR_GOOD)
2388 return val; 2387 return val;
2389 } else 2388 } else
2390 { 2389 {
2391 val = creat (_filename, (S_IRUSR | S_IWUSR)); 2390 val = creat (_filename, (S_IRUSR | S_IWUSR));
2392 if (val == -1) 2391 if (val == -1)
2393 return PWERR_OPEN; 2392 return PWERR_OPEN;
2394 else 2393 else
2395 close(val); 2394 close(val);
2396 } 2395 }
2397*/ 2396*/
2398 QFileInfo f (_filename); 2397 QFileInfo f (_filename);
2399 save_buffer_length = f.size(); 2398 save_buffer_length = f.size();
2400 save_buffer_length = ((save_buffer_length / 1024)+1) * 1024; 2399 save_buffer_length = ((save_buffer_length / 1024)+1) * 1024;
2401 2400
2402 fd = fopen (_filename, "wb"); 2401 fd = fopen (_filename, "wb");
2403 if (fd == NULL) 2402 if (fd == NULL)
2404 return PWERR_OPEN; 2403 return PWERR_OPEN;
2405 2404
2406 buffer = (char*)malloc(save_buffer_length); 2405 buffer = (char*)malloc(save_buffer_length);
2407 2406
2408 /* make the key ready */ 2407 /* make the key ready */
2409 for (j = 0; password[j] != '\0'; j++) { 2408 for (j = 0; password[j] != '\0'; j++) {
2410 key[j] = password[j]; 2409 key[j] = password[j];
2411 } 2410 }
2412 keylength = j; 2411 keylength = j;
2413 krc2->rc2_expandkey (key, keylength, 128); 2412 krc2->rc2_expandkey (key, keylength, 128);
2414 2413
2415 /* First, we make the IV */ 2414 /* First, we make the IV */
2416 for (count2 = 0; count2 < 4; count2++) { 2415 for (count2 = 0; count2 < 4; count2++) {
2417 iv[count2] = rand (); 2416 iv[count2] = rand ();
2418 putc ((unsigned char) (iv[count2] >> 8), fd); 2417 putc ((unsigned char) (iv[count2] >> 8), fd);
2419 putc ((unsigned char) (iv[count2] & 0xff), fd); 2418 putc ((unsigned char) (iv[count2] & 0xff), fd);
2420 } 2419 }
2421 2420
2422 bufferIndex = 0; 2421 bufferIndex = 0;
2423 return PWERR_GOOD; 2422 return PWERR_GOOD;
2424} 2423}
2425 2424
2426 2425
2427int ZSafe::saveEntry(char *entry[FIELD_SIZE]) 2426int ZSafe::saveEntry(char *entry[FIELD_SIZE])
2428{ 2427{
2429 char *text1; 2428 char *text1;
2430 int count2, count3; 2429 int count2, count3;
2431 unsigned short ciphertext[4]; 2430 unsigned short ciphertext[4];
2432 Krc2* krc2 = new Krc2(); 2431 Krc2* krc2 = new Krc2();
2433 2432
2434 buffer = (char*)memset(buffer, '\0', save_buffer_length); 2433 buffer = (char*)memset(buffer, '\0', save_buffer_length);
2435 2434
2436 for (count2 = 0; count2 < FIELD_SIZE; count2++) { 2435 for (count2 = 0; count2 < FIELD_SIZE; count2++) {
2437 text1 = entry[count2]; 2436 text1 = entry[count2];
2438 if (strlen (text1) == 0) { 2437 if (strlen (text1) == 0) {
2439 strncat(buffer, " ", strlen(" ")); 2438 strncat(buffer, " ", strlen(" "));
2440 } else { 2439 } else {
2441 strncat(buffer, text1, strlen(text1)); 2440 strncat(buffer, text1, strlen(text1));
2442 } 2441 }
2443 /* Use 255 as the marker. \n is too tough to test for */ 2442 /* Use 255 as the marker. \n is too tough to test for */
2444 buffer[strlen (buffer)] = 255; 2443 buffer[strlen (buffer)] = 255;
2445 } /*for (count2 = 0; count2 < 5; count2++)*/ 2444 } /*for (count2 = 0; count2 < 5; count2++)*/
2446 count2 = 0; 2445 count2 = 0;
2447 /* I'm using CBC mode and encrypting the data straight from top down. 2446 /* I'm using CBC mode and encrypting the data straight from top down.
2448 * At the bottom, encrypted, I will append an MD5 hash of the file, eventually. 2447 * At the bottom, encrypted, I will append an MD5 hash of the file, eventually.
2449 * PKCS 5 padding (explained at the code section 2448 * PKCS 5 padding (explained at the code section
2450 */ 2449 */
2451 while (count2 < (int)strlen (buffer)) { 2450 while (count2 < (int)strlen (buffer)) {
2452#ifndef WORDS_BIGENDIAN 2451#ifndef WORDS_BIGENDIAN
2453 plaintext[bufferIndex] = buffer[count2 + 1] << 8; 2452 plaintext[bufferIndex] = buffer[count2 + 1] << 8;
2454 plaintext[bufferIndex] += buffer[count2] & 0xff; 2453 plaintext[bufferIndex] += buffer[count2] & 0xff;
2455#endif 2454#endif
2456#ifdef WORDS_BIGENDIAN 2455#ifdef WORDS_BIGENDIAN
2457 plaintext[bufferIndex] = buffer[count2] << 8; 2456 plaintext[bufferIndex] = buffer[count2] << 8;
2458 plaintext[bufferIndex] += buffer[count2 + 1] & 0xff; 2457 plaintext[bufferIndex] += buffer[count2 + 1] & 0xff;
2459#endif 2458#endif
2460 bufferIndex++; 2459 bufferIndex++;
2461 if (bufferIndex == 4) { 2460 if (bufferIndex == 4) {
2462 krc2->rc2_encrypt (plaintext); 2461 krc2->rc2_encrypt (plaintext);
2463 2462
2464 for (count3 = 0; count3 < 4; count3++) { 2463 for (count3 = 0; count3 < 4; count3++) {
2465 ciphertext[count3] = iv[count3] ^ plaintext[count3]; 2464 ciphertext[count3] = iv[count3] ^ plaintext[count3];
2466 2465
2467 /* Now store the ciphertext as the iv */ 2466 /* Now store the ciphertext as the iv */
2468 iv[count3] = plaintext[count3]; 2467 iv[count3] = plaintext[count3];
2469 2468
2470 /* reset the buffer index */ 2469 /* reset the buffer index */
2471 bufferIndex = 0; 2470 bufferIndex = 0;
2472 if (putc ((unsigned char) (ciphertext[count3] >> 8), fd) == EOF) return PWERR_DATA; 2471 if (putc ((unsigned char) (ciphertext[count3] >> 8), fd) == EOF) return PWERR_DATA;
2473 if (putc ((unsigned char) (ciphertext[count3] & 0xff), fd) == EOF) return PWERR_DATA; 2472 if (putc ((unsigned char) (ciphertext[count3] & 0xff), fd) == EOF) return PWERR_DATA;
2474 } /*for (count3 = 0; count3 < 5; count3++)*/ 2473 } /*for (count3 = 0; count3 < 5; count3++)*/
2475 } /*if (bufferIndex == 5)*/ 2474 } /*if (bufferIndex == 5)*/
2476 /* increment a short, not a byte */ 2475 /* increment a short, not a byte */
2477 count2 += 2; 2476 count2 += 2;
2478 } /*while (count2 < strlen (buffer))*/ 2477 } /*while (count2 < strlen (buffer))*/
2479 int ret = PWERR_GOOD; 2478 int ret = PWERR_GOOD;
2480 return ret; 2479 return ret;
2481} 2480}
2482 2481
2483int ZSafe::saveFinalize(void) 2482int ZSafe::saveFinalize(void)
2484{ 2483{
2485 int count1, retval = PWERR_GOOD; 2484 int count1, retval = PWERR_GOOD;
2486 unsigned short ciphertext[4]; 2485 unsigned short ciphertext[4];
2487 Krc2* krc2 = new Krc2(); 2486 Krc2* krc2 = new Krc2();
2488 2487
2489 /* Tack on the PKCS 5 padding 2488 /* Tack on the PKCS 5 padding
2490 * How it works is we fill up the last n bytes with the value n 2489 * How it works is we fill up the last n bytes with the value n
2491 * 2490 *
2492 * So, if we have, say, 13 bytes, 8 of which are used, we have 5 left 2491 * So, if we have, say, 13 bytes, 8 of which are used, we have 5 left
2493 * over, leaving us 3 short, so we fill it in with 3's. 2492 * over, leaving us 3 short, so we fill it in with 3's.
2494 * 2493 *
2495 * If we come out even, we fill it with 8 8s 2494 * If we come out even, we fill it with 8 8s
2496 * 2495 *
2497 * um, except that in this instance we are using 4 shorts instead of 8 bytes. 2496 * um, except that in this instance we are using 4 shorts instead of 8 bytes.
2498 * so, half everything 2497 * so, half everything
2499 */ 2498 */
2500 for (count1 = bufferIndex; count1 < 4; count1++) { 2499 for (count1 = bufferIndex; count1 < 4; count1++) {
2501 plaintext[count1] = (4 - bufferIndex); 2500 plaintext[count1] = (4 - bufferIndex);
2502 } 2501 }
2503 krc2->rc2_encrypt (plaintext); 2502 krc2->rc2_encrypt (plaintext);
2504 for (count1 = 0; count1 < 4; count1++) { 2503 for (count1 = 0; count1 < 4; count1++) {
2505 ciphertext[count1] = iv[count1] ^ plaintext[count1]; 2504 ciphertext[count1] = iv[count1] ^ plaintext[count1];
2506 if (putc ((unsigned char) (ciphertext[count1] >> 8), fd) == EOF) retval = PWERR_DATA; 2505 if (putc ((unsigned char) (ciphertext[count1] >> 8), fd) == EOF) retval = PWERR_DATA;
2507 if (putc ((unsigned char) (ciphertext[count1] & 0xff), fd) == EOF) retval = PWERR_DATA; 2506 if (putc ((unsigned char) (ciphertext[count1] & 0xff), fd) == EOF) retval = PWERR_DATA;
2508 } 2507 }
2509 2508
2510 fclose (fd); 2509 fclose (fd);
2511 free(buffer); 2510 free(buffer);
2512 return retval; 2511 return retval;
2513} 2512}
2514 2513
2515void ZSafe::quitMe () 2514void ZSafe::quitMe ()
2516{ 2515{
2517 qWarning ("QUIT..."); 2516 qWarning ("QUIT...");
2518 2517
2519 if (modified) 2518 if (modified)
2520 { 2519 {
2521 switch( QMessageBox::information( this, tr("ZSafe"), 2520 switch( QMessageBox::information( this, tr("ZSafe"),
2522 tr("Do you want to save\nbefore exiting?"), 2521 tr("Do you want to save\nbefore exiting?"),
2523 tr("&Save"), 2522 tr("&Save"),
2524 tr("S&ave with\nnew\npassword"), 2523 tr("S&ave with\nnew\npassword"),
2525 tr("&Don't Save"), 2524 tr("&Don't Save"),
2526 0 // Enter == button 0 2525 0 // Enter == button 0
2527 ) ) 2526 ) )
2528 { // Escape == button 2 2527 { // Escape == button 2
2529 case 0: // Save clicked, Alt-S or Enter pressed. 2528 case 0: // Save clicked, Alt-S or Enter pressed.
2530 // save 2529 // save
2531 modified = false; 2530 modified = false;
2532 saveDocument(filename, FALSE); 2531 saveDocument(filename, FALSE);
2533 exitZs (1); 2532 exitZs (1);
2534 break; 2533 break;
2535 case 1: // 2534 case 1: //
2536 // Save with new password 2535 // Save with new password
2537 modified = false; 2536 modified = false;
2538 saveDocument(filename, TRUE); 2537 saveDocument(filename, TRUE);
2539 exitZs (1); 2538 exitZs (1);
2540 break; 2539 break;
2541 case 2: // Don't Save clicked or Alt-D pressed 2540 case 2: // Don't Save clicked or Alt-D pressed
2542 // don't save but exitZs 2541 // don't save but exitZs
2543 exitZs (1); 2542 exitZs (1);
2544 break; 2543 break;
2545 } 2544 }
2546 } 2545 }
2547 exitZs (1); 2546 exitZs (1);
2548 2547
2549} 2548}
2550 2549
2551void ZSafe::categoryFieldActivated( const QString& category) 2550void ZSafe::categoryFieldActivated( const QString& category)
2552{ 2551{
2553 if (categoryDialog) 2552 if (categoryDialog)
2554 setCategoryDialogFields(categoryDialog, category); 2553 setCategoryDialogFields(categoryDialog, category);
2555} 2554}
2556 2555
2557void ZSafe::addCategory() 2556void ZSafe::addCategory()
2558{ 2557{
2559 if (filename.isEmpty()) 2558 if (filename.isEmpty())
2560 { 2559 {
2561 QMessageBox::critical( 0, tr("ZSafe"), 2560 QMessageBox::critical( 0, tr("ZSafe"),
2562 tr("No document defined.\nYou have to create a new document")); 2561 tr("No document defined.\nYou have to create a new document"));
2563 return; 2562 return;
2564 } 2563 }
2565 else 2564 else
2566 { 2565 {
2567 // open the 'Category' dialog 2566 // open the 'Category' dialog
2568 bool initIcons = false; 2567 bool initIcons = false;
2569 // open the 'Category' dialog 2568 // open the 'Category' dialog
2570 CategoryDialog *dialog; 2569 CategoryDialog *dialog;
2571 if (categoryDialog) 2570 if (categoryDialog)
2572 { 2571 {
2573 dialog = categoryDialog; 2572 dialog = categoryDialog;
2574 } 2573 }
2575 else 2574 else
2576 { 2575 {
2577 categoryDialog = new CategoryDialog(this, tr("Category"), TRUE); 2576 categoryDialog = new CategoryDialog(this, tr("Category"), TRUE);
2578#ifdef WIN32 2577#ifdef WIN32
2579 categoryDialog->setCaption ("Qt " + tr("Category")); 2578 categoryDialog->setCaption ("Qt " + tr("Category"));
2580#endif 2579#endif
2581 dialog = categoryDialog; 2580 dialog = categoryDialog;
2582 connect( dialog->CategoryField, 2581 connect( dialog->CategoryField,
2583 SIGNAL( activated ( const QString &)), 2582 SIGNAL( activated ( const QString &)),
2584 this, SLOT( categoryFieldActivated( const QString & ) ) ); 2583 this, SLOT( categoryFieldActivated( const QString & ) ) );
2585 initIcons = true; 2584 initIcons = true;
2586 } 2585 }
2587 2586
2588#ifdef DESKTOP 2587#ifdef DESKTOP
2589#ifndef WIN32 2588#ifndef WIN32
2590 QStringList list = conf->entryList( APP_KEY+"/fieldDefs" ); 2589 QStringList list = conf->entryList( APP_KEY+"/fieldDefs" );
2591#else 2590#else
2592 // read all categories from the config file and store 2591 // read all categories from the config file and store
2593 // into a list 2592 // into a list
2594 QFile f (cfgFile); 2593 QFile f (cfgFile);
2595 QStringList list; 2594 QStringList list;
2596 if ( f.open(IO_ReadOnly) ) { // file opened successfully 2595 if ( f.open(IO_ReadOnly) ) { // file opened successfully
2597 QTextStream t( &f ); // use a text stream 2596 QTextStream t( &f ); // use a text stream
2598 QString s; 2597 QString s;
2599 int n = 1; 2598 int n = 1;
2600 while ( !t.eof() ) { // until end of file... 2599 while ( !t.eof() ) { // until end of file...
2601 s = t.readLine(); // line of text excluding '\n' 2600 s = t.readLine(); // line of text excluding '\n'
2602 list.append(s); 2601 list.append(s);
2603 } 2602 }
2604 f.close(); 2603 f.close();
2605 } 2604 }
2606#endif 2605#endif
2607#else 2606#else
2608 // read all categories from the config file and store 2607 // read all categories from the config file and store
2609 // into a list 2608 // into a list
2610 QFile f (cfgFile); 2609 QFile f (cfgFile);
2611 QStringList list; 2610 QStringList list;
2612 if ( f.open(IO_ReadOnly) ) { // file opened successfully 2611 if ( f.open(IO_ReadOnly) ) { // file opened successfully
2613 QTextStream t( &f ); // use a text stream 2612 QTextStream t( &f ); // use a text stream
2614 QString s; 2613 QString s;
2615 while ( !t.eof() ) { // until end of file... 2614 while ( !t.eof() ) { // until end of file...
2616 s = t.readLine(); // line of text excluding '\n' 2615 s = t.readLine(); // line of text excluding '\n'
2617 list.append(s); 2616 list.append(s);
2618 } 2617 }
2619 f.close(); 2618 f.close();
2620 } 2619 }
2621#endif 2620#endif
2622 QStringList::Iterator it = list.begin(); 2621 QStringList::Iterator it = list.begin();
2623 QString categ; 2622 QString categ;
2624 QString firstCategory; 2623 QString firstCategory;
2625 dialog->CategoryField->clear(); // remove all items 2624 dialog->CategoryField->clear(); // remove all items
2626 while( it != list.end() ) 2625 while( it != list.end() )
2627 { 2626 {
2628 QString *cat = new QString (*it); 2627 QString *cat = new QString (*it);
2629 if (cat->contains("-field1", FALSE)) 2628 if (cat->contains("-field1", FALSE))
2630 { 2629 {
2631#ifdef DESKTOP 2630#ifdef DESKTOP
2632#ifndef WIN32 2631#ifndef WIN32
2633 categ = cat->section ("-field1", 0, 0); 2632 categ = cat->section ("-field1", 0, 0);
2634#else 2633#else
2635 int pos = cat->find ("-field1"); 2634 int pos = cat->find ("-field1");
2636 categ = cat->left (pos); 2635 categ = cat->left (pos);
2637#endif 2636#endif
2638#else 2637#else
2639 int pos = cat->find ("-field1"); 2638 int pos = cat->find ("-field1");
2640 cat->truncate(pos); 2639 cat->truncate(pos);
2641 categ = *cat; 2640 categ = *cat;
2642#endif 2641#endif
2643 if (!categ.isEmpty()) 2642 if (!categ.isEmpty())
2644 { 2643 {
2645 dialog->CategoryField->insertItem (categ, -1); 2644 dialog->CategoryField->insertItem (categ, -1);
2646 if (firstCategory.isEmpty()) 2645 if (firstCategory.isEmpty())
2647 firstCategory = categ; 2646 firstCategory = categ;
2648 } 2647 }
2649 } 2648 }
2650 ++it; 2649 ++it;
2651 } 2650 }
2652 2651
2653 2652
2654 if (firstCategory.isEmpty()) 2653 if (firstCategory.isEmpty())
2655 setCategoryDialogFields(dialog); 2654 setCategoryDialogFields(dialog);
2656 else 2655 else
2657 setCategoryDialogFields(dialog, firstCategory); 2656 setCategoryDialogFields(dialog, firstCategory);
2658 2657
2659 // CategoryDialog *dialog = new CategoryDialog(this, "Category", TRUE); 2658 // CategoryDialog *dialog = new CategoryDialog(this, "Category", TRUE);
2660 2659
2661 if (initIcons) 2660 if (initIcons)
2662 { 2661 {
2663 Wait waitDialog(this, tr("Wait dialog")); 2662 Wait waitDialog(this, tr("Wait dialog"));
2664 waitDialog.waitLabel->setText(tr("Gathering icons...")); 2663 waitDialog.waitLabel->setText(tr("Gathering icons..."));
2665 waitDialog.show(); 2664 waitDialog.show();
2666 qApp->processEvents(); 2665 qApp->processEvents();
2667 2666
2668#ifdef DESKTOP 2667#ifdef DESKTOP
2669 QDir d(iconPath); 2668 QDir d(iconPath);
2670#else 2669#else
2671 QDir d(QPEApplication::qpeDir() + "/pics/"); 2670 QDir d(QPEApplication::qpeDir() + "/pics/");
2672#endif 2671#endif
2673 d.setFilter( QDir::Files); 2672 d.setFilter( QDir::Files);
2674 2673
2675 const QFileInfoList *list = d.entryInfoList(); 2674 const QFileInfoList *list = d.entryInfoList();
2676 QFileInfoListIterator it( *list ); // create list iterator 2675 QFileInfoListIterator it( *list ); // create list iterator
2677 QFileInfo *fi; // pointer for traversing 2676 QFileInfo *fi; // pointer for traversing
2678 2677
2679 dialog->IconField->insertItem("predefined"); 2678 dialog->IconField->insertItem("predefined");
2680 while ( (fi=it.current()) ) { // for each file... 2679 while ( (fi=it.current()) ) { // for each file...
2681 QString fileName = fi->fileName(); 2680 QString fileName = fi->fileName();
2682 if(fileName.right(4) == ".png"){ 2681 if(fileName.right(4) == ".png"){
2683 fileName = fileName.mid(0,fileName.length()-4); 2682 fileName = fileName.mid(0,fileName.length()-4);
2684#ifdef DESKTOP 2683#ifdef DESKTOP
2685 QPixmap imageOfFile; 2684 QPixmap imageOfFile;
2686 imageOfFile.load(iconPath + fi->fileName()); 2685 imageOfFile.load(iconPath + fi->fileName());
2687#else 2686#else
2688 QPixmap imageOfFile(Resource::loadPixmap(fileName)); 2687 QPixmap imageOfFile(Resource::loadPixmap(fileName));
2689#endif 2688#endif
2690 QImage foo = imageOfFile.convertToImage(); 2689 QImage foo = imageOfFile.convertToImage();
2691 foo = foo.smoothScale(16,16); 2690 foo = foo.smoothScale(16,16);
2692 imageOfFile.convertFromImage(foo); 2691 imageOfFile.convertFromImage(foo);
2693 dialog->IconField->insertItem(imageOfFile,fileName); 2692 dialog->IconField->insertItem(imageOfFile,fileName);
2694 } 2693 }
2695 ++it; 2694 ++it;
2696 } 2695 }
2697 waitDialog.hide(); 2696 waitDialog.hide();
2698 } 2697 }
2699 2698
2700#ifndef WIN32 2699#ifndef WIN32
2701 dialog->show(); 2700 dialog->show();
2702#endif 2701#endif
2703#ifndef DESKTOP 2702#ifndef DESKTOP
2704 // dialog->move (20, 100); 2703 // dialog->move (20, 100);
2705#endif 2704#endif
2706 DialogCode result = (DialogCode) dialog->exec(); 2705 DialogCode result = (DialogCode) dialog->exec();
2707#ifdef DESKTOP 2706#ifdef DESKTOP
2708 result = Accepted; 2707 result = Accepted;
2709#endif 2708#endif
2710 2709
2711 QString category; 2710 QString category;
2712 QString icon; 2711 QString icon;
2713 QString fullIconPath; 2712 QString fullIconPath;
2714 QPixmap *pix; 2713 QPixmap *pix;
2715 if (result == Accepted) 2714 if (result == Accepted)
2716 { 2715 {
2717 modified = true; 2716 modified = true;
2718 category = dialog->CategoryField->currentText(); 2717 category = dialog->CategoryField->currentText();
2719 icon = dialog->IconField->currentText()+".png"; 2718 icon = dialog->IconField->currentText()+".png";
2720 2719
2721 qWarning (category); 2720 qWarning (category);
2722 2721
2723 QListViewItem *li = new ShadedListItem( 1, ListView ); 2722 QListViewItem *li = new ShadedListItem( 1, ListView );
2724 Category *c1 = new Category(); 2723 Category *c1 = new Category();
2725 c1->setCategoryName(category); 2724 c1->setCategoryName(category);
2726 2725
2727 // if (!icon.isEmpty() && !icon.isNull()) 2726 // if (!icon.isEmpty() && !icon.isNull())
2728 if (icon != "predefined.png") 2727 if (icon != "predefined.png")
2729 { 2728 {
2730 // build the full path 2729 // build the full path
2731 fullIconPath = iconPath + icon; 2730 fullIconPath = iconPath + icon;
2732 pix = new QPixmap (fullIconPath); 2731 pix = new QPixmap (fullIconPath);
2733 // pix->resize(14, 14); 2732 // pix->resize(14, 14);
2734 if (pix) 2733 if (pix)
2735 { 2734 {
2736 // save the full pixmap name into the config file 2735 // save the full pixmap name into the config file
2737// #ifndef WIN32 2736// #ifndef WIN32
2738 conf->writeEntry(APP_KEY+category, icon); 2737 conf->writeEntry(APP_KEY+category, icon);
2739// #endif 2738// #endif
2740 saveConf(); 2739 saveConf();
2741 QImage img = pix->convertToImage(); 2740 QImage img = pix->convertToImage();
2742 pix->convertFromImage(img.smoothScale(14,14)); 2741 pix->convertFromImage(img.smoothScale(14,14));
2743 c1->setIcon (*pix); 2742 c1->setIcon (*pix);
2744 c1->setIconName(icon); 2743 c1->setIconName(icon);
2745 } 2744 }
2746 else 2745 else
2747 { 2746 {
2748 QPixmap folder( ( const char** ) general_data ); 2747 QPixmap folder( ( const char** ) general_data );
2749 c1->setIcon (folder); 2748 c1->setIcon (folder);
2750 } 2749 }
2751 } 2750 }
2752 else 2751 else
2753 { 2752 {
2754 c1->setIcon (*getPredefinedIcon(category)); 2753 c1->setIcon (*getPredefinedIcon(category));
2755 } 2754 }
2756 2755
2757 c1->setListItem (li); 2756 c1->setListItem (li);
2758 c1->initListItem(); 2757 c1->initListItem();
2759 categories.insert (c1->getCategoryName(), c1); 2758 categories.insert (c1->getCategoryName(), c1);
2760 2759
2761 saveCategoryDialogFields(dialog); 2760 saveCategoryDialogFields(dialog);
2762 } 2761 }
2763 else 2762 else
2764 { 2763 {
2765 // delete dialog; 2764 // delete dialog;
2766 dialog->hide(); 2765 dialog->hide();
2767 return; 2766 return;
2768 } 2767 }
2769 2768
2770 } 2769 }
2771 2770
2772} 2771}
2773 2772
2774void ZSafe::delCategory() 2773void ZSafe::delCategory()
2775{ 2774{
2776 if (!selectedItem) 2775 if (!selectedItem)
2777 return; 2776 return;
2778 if (isCategory(selectedItem)) 2777 if (isCategory(selectedItem))
2779 { 2778 {
2780 switch( QMessageBox::information( this, tr("ZSafe"), 2779 switch( QMessageBox::information( this, tr("ZSafe"),
2781 tr("Do you want to delete?"), 2780 tr("Do you want to delete?"),
2782 tr("&Delete"), tr("D&on't Delete"), 2781 tr("&Delete"), tr("D&on't Delete"),
2783 0 // Enter == button 0 2782 0 // Enter == button 0
2784 ) ) { // Escape == button 2 2783 ) ) { // Escape == button 2
2785 case 0: // Delete clicked, Alt-S or Enter pressed. 2784 case 0: // Delete clicked, Alt-S or Enter pressed.
2786 // Delete from the category list 2785 // Delete from the category list
2787 modified = true; 2786 modified = true;
2788 categories.remove (selectedItem->text(0)); 2787 categories.remove (selectedItem->text(0));
2789// #ifndef WIN32 2788// #ifndef WIN32
2790 conf->removeEntry (selectedItem->text(0)); 2789 conf->removeEntry (selectedItem->text(0));
2791// #endif 2790// #endif
2792 saveConf(); 2791 saveConf();
2793 2792
2794 // Delete the selected item and all subitems 2793 // Delete the selected item and all subitems
2795 // step through all subitems 2794 // step through all subitems
2796 QListViewItem *si; 2795 QListViewItem *si;
2797 for (si = selectedItem->firstChild(); 2796 for (si = selectedItem->firstChild();
2798 si != NULL; ) 2797 si != NULL; )
2799 { 2798 {
2800 QListViewItem *_si = si; 2799 QListViewItem *_si = si;
2801 si = si->nextSibling(); 2800 si = si->nextSibling();
2802 selectedItem->takeItem(_si); // remove from view list 2801 selectedItem->takeItem(_si); // remove from view list
2803 if (_si) delete _si; 2802 if (_si) delete _si;
2804 } 2803 }
2805 ListView->takeItem(selectedItem); 2804 ListView->takeItem(selectedItem);
2806 delete selectedItem; 2805 delete selectedItem;
2807 2806
2808 selectedItem = NULL; 2807 selectedItem = NULL;
2809 break; 2808 break;
2810 case 1: // Don't delete 2809 case 1: // Don't delete
2811 break; 2810 break;
2812 } 2811 }
2813 2812
2814 } 2813 }
2815} 2814}
2816 2815
2817void ZSafe::setCategoryDialogFields(CategoryDialog *dialog) 2816void ZSafe::setCategoryDialogFields(CategoryDialog *dialog)
2818{ 2817{
2819 if (!dialog) 2818 if (!dialog)
2820 return; 2819 return;
2821 2820
2822 QString icon; 2821 QString icon;
2823 if (selectedItem) 2822 if (selectedItem)
2824 { 2823 {
2825 dialog->Field1->setText(getFieldLabel (selectedItem, "1", tr("Name"))); 2824 dialog->Field1->setText(getFieldLabel (selectedItem, "1", tr("Name")));
2826 dialog->Field2->setText(getFieldLabel (selectedItem, "2", tr("Username"))); 2825 dialog->Field2->setText(getFieldLabel (selectedItem, "2", tr("Username")));
2827 dialog->Field3->setText(getFieldLabel (selectedItem, "3", tr("Password"))); 2826 dialog->Field3->setText(getFieldLabel (selectedItem, "3", tr("Password")));
2828 dialog->Field4->setText(getFieldLabel (selectedItem, "4", tr("Comment"))); 2827 dialog->Field4->setText(getFieldLabel (selectedItem, "4", tr("Comment")));
2829 dialog->Field5->setText(getFieldLabel (selectedItem, "5", tr("Field 4"))); 2828 dialog->Field5->setText(getFieldLabel (selectedItem, "5", tr("Field 4")));
2830 dialog->Field6->setText(getFieldLabel (selectedItem, "6", tr("Field 5"))); 2829 dialog->Field6->setText(getFieldLabel (selectedItem, "6", tr("Field 5")));
2831 2830
2832 Category *cat= categories.find (selectedItem->text(0)); 2831 Category *cat= categories.find (selectedItem->text(0));
2833 if (cat) 2832 if (cat)
2834 { 2833 {
2835 icon = cat->getIconName(); 2834 icon = cat->getIconName();
2836 } 2835 }
2837 else 2836 else
2838 icon = conf->readEntry(APP_KEY+selectedItem->text(0)); 2837 icon = conf->readEntry(APP_KEY+selectedItem->text(0));
2839 } 2838 }
2840 else 2839 else
2841 { 2840 {
2842 dialog->Field1->setText(tr("Name")); 2841 dialog->Field1->setText(tr("Name"));
2843 dialog->Field2->setText(tr("Username")); 2842 dialog->Field2->setText(tr("Username"));
2844 dialog->Field3->setText(tr("Password")); 2843 dialog->Field3->setText(tr("Password"));
2845 dialog->Field4->setText(tr("Comment")); 2844 dialog->Field4->setText(tr("Comment"));
2846 dialog->Field5->setText(tr("Field 4")); 2845 dialog->Field5->setText(tr("Field 4"));
2847 dialog->Field6->setText(tr("Field 5")); 2846 dialog->Field6->setText(tr("Field 5"));
2848 } 2847 }
2849 2848
2850#ifdef DESKTOP 2849#ifdef DESKTOP
2851 QDir d(iconPath); 2850 QDir d(iconPath);
2852#else 2851#else
2853 QDir d(QPEApplication::qpeDir() + "/pics/"); 2852 QDir d(QPEApplication::qpeDir() + "/pics/");
2854#endif 2853#endif
2855 d.setFilter( QDir::Files); 2854 d.setFilter( QDir::Files);
2856 2855
2857 const QFileInfoList *list = d.entryInfoList(); 2856 const QFileInfoList *list = d.entryInfoList();
2858 int i=0; 2857 int i=0;
2859 QFileInfoListIterator it( *list ); // create list iterator 2858 QFileInfoListIterator it( *list ); // create list iterator
2860 QFileInfo *fi; // pointer for traversing 2859 QFileInfo *fi; // pointer for traversing
2861 if (icon.isEmpty() || icon.isNull()) 2860 if (icon.isEmpty() || icon.isNull())
2862 { 2861 {
2863 dialog->IconField->setCurrentItem(0); 2862 dialog->IconField->setCurrentItem(0);
2864 } 2863 }
2865 else 2864 else
2866 { 2865 {
2867 while ( (fi=it.current()) ) 2866 while ( (fi=it.current()) )
2868 { // for each file... 2867 { // for each file...
2869 QString fileName = fi->fileName(); 2868 QString fileName = fi->fileName();
2870 if(fileName.right(4) == ".png") 2869 if(fileName.right(4) == ".png")
2871 { 2870 {
2872 fileName = fileName.mid(0,fileName.length()-4); 2871 fileName = fileName.mid(0,fileName.length()-4);
2873 2872
2874 if(fileName+".png"==icon) 2873 if(fileName+".png"==icon)
2875 { 2874 {
2876 dialog->IconField->setCurrentItem(i+1); 2875 dialog->IconField->setCurrentItem(i+1);
2877 break; 2876 break;
2878 } 2877 }
2879 ++i; 2878 ++i;
2880 } 2879 }
2881 ++it; 2880 ++it;
2882 } 2881 }
2883 } 2882 }
2884} 2883}
2885 2884
2886void ZSafe::setCategoryDialogFields(CategoryDialog *dialog, QString category) 2885void ZSafe::setCategoryDialogFields(CategoryDialog *dialog, QString category)
2887{ 2886{
2888 if (!dialog) 2887 if (!dialog)
2889 return; 2888 return;
2890 2889
2891 dialog->Field1->setText(getFieldLabel (category, "1", tr("Name"))); 2890 dialog->Field1->setText(getFieldLabel (category, "1", tr("Name")));
2892 dialog->Field2->setText(getFieldLabel (category, "2", tr("Username"))); 2891 dialog->Field2->setText(getFieldLabel (category, "2", tr("Username")));
2893 dialog->Field3->setText(getFieldLabel (category, "3", tr("Password"))); 2892 dialog->Field3->setText(getFieldLabel (category, "3", tr("Password")));
2894 dialog->Field4->setText(getFieldLabel (category, "4", tr("Comment"))); 2893 dialog->Field4->setText(getFieldLabel (category, "4", tr("Comment")));
2895 dialog->Field5->setText(getFieldLabel (category, "5", tr("Field 4"))); 2894 dialog->Field5->setText(getFieldLabel (category, "5", tr("Field 4")));
2896 dialog->Field6->setText(getFieldLabel (category, "6", tr("Field 5"))); 2895 dialog->Field6->setText(getFieldLabel (category, "6", tr("Field 5")));
2897 2896
2898 QString icon; 2897 QString icon;
2899 Category *cat= categories.find (category); 2898 Category *cat= categories.find (category);
2900 if (cat) 2899 if (cat)
2901 { 2900 {
2902 icon = cat->getIconName(); 2901 icon = cat->getIconName();
2903 } 2902 }
2904 else 2903 else
2905 icon = conf->readEntry(APP_KEY+category); 2904 icon = conf->readEntry(APP_KEY+category);
2906 2905
2907#ifdef DESKTOP 2906#ifdef DESKTOP
2908 QDir d(iconPath); 2907 QDir d(iconPath);
2909#else 2908#else
2910 QDir d(QPEApplication::qpeDir() + "/pics/"); 2909 QDir d(QPEApplication::qpeDir() + "/pics/");
2911#endif 2910#endif
2912 d.setFilter( QDir::Files); 2911 d.setFilter( QDir::Files);
2913 2912
2914 const QFileInfoList *list = d.entryInfoList(); 2913 const QFileInfoList *list = d.entryInfoList();
2915 int i=0; 2914 int i=0;
2916 QFileInfoListIterator it( *list ); // create list iterator 2915 QFileInfoListIterator it( *list ); // create list iterator
2917 QFileInfo *fi; // pointer for traversing 2916 QFileInfo *fi; // pointer for traversing
2918 if (icon.isEmpty() || icon.isNull()) 2917 if (icon.isEmpty() || icon.isNull())
2919 { 2918 {
2920 dialog->IconField->setCurrentItem(0); 2919 dialog->IconField->setCurrentItem(0);
2921 } 2920 }
2922 else 2921 else
2923 { 2922 {
2924 while ( (fi=it.current()) ) 2923 while ( (fi=it.current()) )
2925 { // for each file... 2924 { // for each file...
2926 QString fileName = fi->fileName(); 2925 QString fileName = fi->fileName();
2927 if(fileName.right(4) == ".png") 2926 if(fileName.right(4) == ".png")
2928 { 2927 {
2929 fileName = fileName.mid(0,fileName.length()-4); 2928 fileName = fileName.mid(0,fileName.length()-4);
2930 2929
2931 if(fileName+".png"==icon) 2930 if(fileName+".png"==icon)
2932 { 2931 {
2933 dialog->IconField->setCurrentItem(i+1); 2932 dialog->IconField->setCurrentItem(i+1);
2934 break; 2933 break;
2935 } 2934 }
2936 ++i; 2935 ++i;
2937 } 2936 }
2938 ++it; 2937 ++it;
2939 } 2938 }
2940 } 2939 }
2941} 2940}
2942 2941
2943void ZSafe::saveCategoryDialogFields(CategoryDialog *dialog) 2942void ZSafe::saveCategoryDialogFields(CategoryDialog *dialog)
2944{ 2943{
2945 QString app_key = APP_KEY; 2944 QString app_key = APP_KEY;
2946#ifndef DESKTOP 2945#ifndef DESKTOP
2947 conf->setGroup ("fieldDefs"); 2946 conf->setGroup ("fieldDefs");
2948#else 2947#else
2949#ifndef WIN32 2948#ifndef WIN32
2950 app_key += "/fieldDefs/"; 2949 app_key += "/fieldDefs/";
2951#endif 2950#endif
2952#endif 2951#endif
2953 QString category = dialog->CategoryField->currentText(); 2952 QString category = dialog->CategoryField->currentText();
2954// #ifndef WIN32 2953// #ifndef WIN32
2955 conf->writeEntry(app_key+category+"-field1", dialog->Field1->text()); 2954 conf->writeEntry(app_key+category+"-field1", dialog->Field1->text());
2956 conf->writeEntry(app_key+category+"-field2", dialog->Field2->text()); 2955 conf->writeEntry(app_key+category+"-field2", dialog->Field2->text());
2957 conf->writeEntry(app_key+category+"-field3", dialog->Field3->text()); 2956 conf->writeEntry(app_key+category+"-field3", dialog->Field3->text());
2958 conf->writeEntry(app_key+category+"-field4", dialog->Field4->text()); 2957 conf->writeEntry(app_key+category+"-field4", dialog->Field4->text());
2959 conf->writeEntry(app_key+category+"-field5", dialog->Field5->text()); 2958 conf->writeEntry(app_key+category+"-field5", dialog->Field5->text());
2960 conf->writeEntry(app_key+category+"-field6", dialog->Field6->text()); 2959 conf->writeEntry(app_key+category+"-field6", dialog->Field6->text());
2961// #endif 2960// #endif
2962 saveConf(); 2961 saveConf();
2963#ifndef DESKTOP 2962#ifndef DESKTOP
2964 conf->setGroup ("zsafe"); 2963 conf->setGroup ("zsafe");
2965#endif 2964#endif
2966} 2965}
2967 2966
2968void ZSafe::editCategory() 2967void ZSafe::editCategory()
2969{ 2968{
2970 if (!selectedItem) 2969 if (!selectedItem)
2971 return; 2970 return;
2972 if (isCategory(selectedItem)) 2971 if (isCategory(selectedItem))
2973 { 2972 {
2974 QString category = selectedItem->text(0); 2973 QString category = selectedItem->text(0);
2975 bool initIcons = false; 2974 bool initIcons = false;
2976 // open the 'Category' dialog 2975 // open the 'Category' dialog
2977 CategoryDialog *dialog; 2976 CategoryDialog *dialog;
2978 if (categoryDialog) 2977 if (categoryDialog)
2979 { 2978 {
2980 dialog = categoryDialog; 2979 dialog = categoryDialog;
2981 } 2980 }
2982 else 2981 else
2983 { 2982 {
2984 categoryDialog = new CategoryDialog(this, tr("Category"), TRUE); 2983 categoryDialog = new CategoryDialog(this, tr("Category"), TRUE);
2985#ifdef WIN32 2984#ifdef WIN32
2986 categoryDialog->setCaption ("Qt " + tr("Category")); 2985 categoryDialog->setCaption ("Qt " + tr("Category"));
2987#endif 2986#endif
2988 dialog = categoryDialog; 2987 dialog = categoryDialog;
2989 connect( dialog->CategoryField, 2988 connect( dialog->CategoryField,
2990 SIGNAL( activated ( const QString &)), 2989 SIGNAL( activated ( const QString &)),
2991 this, SLOT( categoryFieldActivated( const QString & ) ) ); 2990 this, SLOT( categoryFieldActivated( const QString & ) ) );
2992 initIcons = true; 2991 initIcons = true;
2993 } 2992 }
2994 setCategoryDialogFields(dialog); 2993 setCategoryDialogFields(dialog);
2995 2994
2996#ifdef DESKTOP 2995#ifdef DESKTOP
2997#ifndef WIN32 2996#ifndef WIN32
2998 QStringList list = conf->entryList( APP_KEY+"/fieldDefs" ); 2997 QStringList list = conf->entryList( APP_KEY+"/fieldDefs" );
2999#else 2998#else
3000 // read all categories from the config file and store 2999 // read all categories from the config file and store
3001 // into a list 3000 // into a list
3002 QFile f (cfgFile); 3001 QFile f (cfgFile);
3003 QStringList list; 3002 QStringList list;
3004 if ( f.open(IO_ReadOnly) ) { // file opened successfully 3003 if ( f.open(IO_ReadOnly) ) { // file opened successfully
3005 QTextStream t( &f ); // use a text stream 3004 QTextStream t( &f ); // use a text stream
3006 QString s; 3005 QString s;
3007 int n = 1; 3006 int n = 1;
3008 while ( !t.eof() ) { // until end of file... 3007 while ( !t.eof() ) { // until end of file...
3009 s = t.readLine(); // line of text excluding '\n' 3008 s = t.readLine(); // line of text excluding '\n'
3010 list.append(s); 3009 list.append(s);
3011 } 3010 }
3012 f.close(); 3011 f.close();
3013 } 3012 }
3014#endif 3013#endif
3015#else 3014#else
3016 // read all categories from the config file and store 3015 // read all categories from the config file and store
3017 // into a list 3016 // into a list
3018 QFile f (cfgFile); 3017 QFile f (cfgFile);
3019 QStringList list; 3018 QStringList list;
3020 if ( f.open(IO_ReadOnly) ) { // file opened successfully 3019 if ( f.open(IO_ReadOnly) ) { // file opened successfully
3021 QTextStream t( &f ); // use a text stream 3020 QTextStream t( &f ); // use a text stream
3022 QString s; 3021 QString s;
3023 while ( !t.eof() ) { // until end of file... 3022 while ( !t.eof() ) { // until end of file...
3024 s = t.readLine(); // line of text excluding '\n' 3023 s = t.readLine(); // line of text excluding '\n'
3025 list.append(s); 3024 list.append(s);
3026 } 3025 }
3027 f.close(); 3026 f.close();
3028 } 3027 }
3029#endif 3028#endif
3030 QStringList::Iterator it = list.begin(); 3029 QStringList::Iterator it = list.begin();
3031 QString categ; 3030 QString categ;
3032 dialog->CategoryField->clear(); // remove all items 3031 dialog->CategoryField->clear(); // remove all items
3033 int i=0; 3032 int i=0;
3034 bool foundCategory = false; 3033 bool foundCategory = false;
3035 while( it != list.end() ) 3034 while( it != list.end() )
3036 { 3035 {
3037 QString *cat = new QString (*it); 3036 QString *cat = new QString (*it);
3038 if (cat->contains("-field1", FALSE)) 3037 if (cat->contains("-field1", FALSE))
3039 { 3038 {
3040#ifdef DESKTOP 3039#ifdef DESKTOP
3041#ifndef WIN32 3040#ifndef WIN32
3042 categ = cat->section ("-field1", 0, 0); 3041 categ = cat->section ("-field1", 0, 0);
3043#else 3042#else
3044 int pos = cat->find ("-field1"); 3043 int pos = cat->find ("-field1");
3045 categ = cat->left (pos); 3044 categ = cat->left (pos);
3046#endif 3045#endif
3047#else 3046#else
3048 int pos = cat->find ("-field1"); 3047 int pos = cat->find ("-field1");
3049 cat->truncate(pos); 3048 cat->truncate(pos);
3050 categ = *cat; 3049 categ = *cat;
3051#endif 3050#endif
3052 if (!categ.isEmpty()) 3051 if (!categ.isEmpty())
3053 { 3052 {
3054 dialog->CategoryField->insertItem (categ, i); 3053 dialog->CategoryField->insertItem (categ, i);
3055 if (category.compare(categ) == 0) 3054 if (category.compare(categ) == 0)
3056 { 3055 {
3057 dialog->CategoryField->setCurrentItem(i); 3056 dialog->CategoryField->setCurrentItem(i);
3058 foundCategory = true; 3057 foundCategory = true;
3059 } 3058 }
3060 i++; 3059 i++;
3061 } 3060 }
3062 } 3061 }
3063 ++it; 3062 ++it;
3064 } 3063 }
3065 if (!foundCategory) 3064 if (!foundCategory)
3066 { 3065 {
3067 dialog->CategoryField->insertItem (category, i); 3066 dialog->CategoryField->insertItem (category, i);
3068 dialog->CategoryField->setCurrentItem(i); 3067 dialog->CategoryField->setCurrentItem(i);
3069 } 3068 }
3070 3069
3071 QString icon; 3070 QString icon;
3072 Category *cat= categories.find (selectedItem->text(0)); 3071 Category *cat= categories.find (selectedItem->text(0));
3073 if (cat) 3072 if (cat)
3074 { 3073 {
3075 icon = cat->getIconName(); 3074 icon = cat->getIconName();
3076 } 3075 }
3077 3076
3078 if (initIcons) 3077 if (initIcons)
3079 { 3078 {
3080 3079
3081 Wait waitDialog(this, tr("Wait dialog")); 3080 Wait waitDialog(this, tr("Wait dialog"));
3082 waitDialog.waitLabel->setText(tr("Gathering icons...")); 3081 waitDialog.waitLabel->setText(tr("Gathering icons..."));
3083 waitDialog.show(); 3082 waitDialog.show();
3084 qApp->processEvents(); 3083 qApp->processEvents();
3085 3084
3086#ifdef DESKTOP 3085#ifdef DESKTOP
3087 QDir d(iconPath); 3086 QDir d(iconPath);
3088#else 3087#else
3089 QDir d(QPEApplication::qpeDir() + "/pics/"); 3088 QDir d(QPEApplication::qpeDir() + "/pics/");
3090#endif 3089#endif
3091 d.setFilter( QDir::Files); 3090 d.setFilter( QDir::Files);
3092 3091
3093 const QFileInfoList *list = d.entryInfoList(); 3092 const QFileInfoList *list = d.entryInfoList();
3094 int i=0; 3093 int i=0;
3095 QFileInfoListIterator it( *list ); // create list iterator 3094 QFileInfoListIterator it( *list ); // create list iterator
3096 QFileInfo *fi; // pointer for traversing 3095 QFileInfo *fi; // pointer for traversing
3097 if (icon.isEmpty() || icon.isNull()) 3096 if (icon.isEmpty() || icon.isNull())
3098 { 3097 {
3099 dialog->IconField->setCurrentItem(0); 3098 dialog->IconField->setCurrentItem(0);
3100 } 3099 }
3101 3100
3102 dialog->IconField->insertItem("predefined"); 3101 dialog->IconField->insertItem("predefined");
3103 while ( (fi=it.current()) ) { // for each file... 3102 while ( (fi=it.current()) ) { // for each file...
3104 QString fileName = fi->fileName(); 3103 QString fileName = fi->fileName();
3105 if(fileName.right(4) == ".png") 3104 if(fileName.right(4) == ".png")
3106 { 3105 {
3107 fileName = fileName.mid(0,fileName.length()-4); 3106 fileName = fileName.mid(0,fileName.length()-4);
3108#ifdef DESKTOP 3107#ifdef DESKTOP
3109 QPixmap imageOfFile; 3108 QPixmap imageOfFile;
3110 imageOfFile.load(iconPath + fi->fileName()); 3109 imageOfFile.load(iconPath + fi->fileName());
3111#else 3110#else
3112 QPixmap imageOfFile(Resource::loadPixmap(fileName)); 3111 QPixmap imageOfFile(Resource::loadPixmap(fileName));
3113#endif 3112#endif
3114 QImage foo = imageOfFile.convertToImage(); 3113 QImage foo = imageOfFile.convertToImage();
3115 foo = foo.smoothScale(16,16); 3114 foo = foo.smoothScale(16,16);
3116 imageOfFile.convertFromImage(foo); 3115 imageOfFile.convertFromImage(foo);
3117 dialog->IconField->insertItem(imageOfFile,fileName); 3116 dialog->IconField->insertItem(imageOfFile,fileName);
3118 if(fileName+".png"==icon) 3117 if(fileName+".png"==icon)
3119 dialog->IconField->setCurrentItem(i+1); 3118 dialog->IconField->setCurrentItem(i+1);
3120 ++i; 3119 ++i;
3121 } 3120 }
3122 ++it; 3121 ++it;
3123 } 3122 }
3124 waitDialog.hide(); 3123 waitDialog.hide();
3125 } 3124 }
3126 else 3125 else
3127 { 3126 {
3128#ifdef DESKTOP 3127#ifdef DESKTOP
3129 // QDir d(QDir::homeDirPath() + "/pics/"); 3128 // QDir d(QDir::homeDirPath() + "/pics/");
3130 QDir d(iconPath); 3129 QDir d(iconPath);
3131#else 3130#else
3132 QDir d(QPEApplication::qpeDir() + "/pics/"); 3131 QDir d(QPEApplication::qpeDir() + "/pics/");
3133#endif 3132#endif
3134 d.setFilter( QDir::Files); 3133 d.setFilter( QDir::Files);
3135 3134
3136 const QFileInfoList *list = d.entryInfoList(); 3135 const QFileInfoList *list = d.entryInfoList();
3137 int i=0; 3136 int i=0;
3138 QFileInfoListIterator it( *list ); // create list iterator 3137 QFileInfoListIterator it( *list ); // create list iterator
3139 QFileInfo *fi; // pointer for traversing 3138 QFileInfo *fi; // pointer for traversing
3140 if (icon.isEmpty() || icon.isNull()) 3139 if (icon.isEmpty() || icon.isNull())
3141 { 3140 {
3142 dialog->IconField->setCurrentItem(0); 3141 dialog->IconField->setCurrentItem(0);
3143 } 3142 }
3144 else 3143 else
3145 { 3144 {
3146 3145
3147 while ( (fi=it.current()) ) 3146 while ( (fi=it.current()) )
3148 { // for each file... 3147 { // for each file...
3149 QString fileName = fi->fileName(); 3148 QString fileName = fi->fileName();
3150 if(fileName.right(4) == ".png") 3149 if(fileName.right(4) == ".png")
3151 { 3150 {
3152 fileName = fileName.mid(0,fileName.length()-4); 3151 fileName = fileName.mid(0,fileName.length()-4);
3153 3152
3154 3153
3155 if(fileName+".png"==icon) 3154 if(fileName+".png"==icon)
3156 { 3155 {
3157 dialog->IconField->setCurrentItem(i+1); 3156 dialog->IconField->setCurrentItem(i+1);
3158 break; 3157 break;
3159 } 3158 }
3160 ++i; 3159 ++i;
3161 } 3160 }
3162 ++it; 3161 ++it;
3163 } 3162 }
3164 } 3163 }
3165 } 3164 }
3166 3165
3167 // dialog->show(); 3166 // dialog->show();
3168#ifndef DESKTOP 3167#ifndef DESKTOP
3169 // dialog->move (20, 100); 3168 // dialog->move (20, 100);
3170#endif 3169#endif
3171 DialogCode result = (DialogCode) dialog->exec(); 3170 DialogCode result = (DialogCode) dialog->exec();
3172#ifdef DESKTOP 3171#ifdef DESKTOP
3173 result = Accepted; 3172 result = Accepted;
3174#endif 3173#endif
3175 3174
3176 QString fullIconPath; 3175 QString fullIconPath;
3177 QPixmap *pix; 3176 QPixmap *pix;
3178 if (result == Accepted) 3177 if (result == Accepted)
3179 { 3178 {
3180 modified = true; 3179 modified = true;
3181 if (category != dialog->CategoryField->currentText()) 3180 if (category != dialog->CategoryField->currentText())
3182 { 3181 {
3183 categories.remove (category); 3182 categories.remove (category);
3184// #ifndef WIN32 3183// #ifndef WIN32
3185 conf->removeEntry(category); 3184 conf->removeEntry(category);
3186// #endif 3185// #endif
3187 saveConf(); 3186 saveConf();
3188 } 3187 }
3189 3188
3190 category = dialog->CategoryField->currentText(); 3189 category = dialog->CategoryField->currentText();
3191 icon = dialog->IconField->currentText()+".png"; 3190 icon = dialog->IconField->currentText()+".png";
3192 3191
3193 if (cat) 3192 if (cat)
3194 { 3193 {
3195 qWarning("Category found"); 3194 qWarning("Category found");
3196 3195
3197 // if (!icon.isEmpty() && !icon.isNull()) 3196 // if (!icon.isEmpty() && !icon.isNull())
3198 if (icon != "predefined.png") 3197 if (icon != "predefined.png")
3199 { 3198 {
3200 // build the full path 3199 // build the full path
3201 fullIconPath = iconPath + icon; 3200 fullIconPath = iconPath + icon;
3202 pix = new QPixmap (fullIconPath); 3201 pix = new QPixmap (fullIconPath);
3203 if (pix) 3202 if (pix)
3204 { 3203 {
3205 // save the full pixmap name into the config file 3204 // save the full pixmap name into the config file
3206// #ifndef WIN32 3205// #ifndef WIN32
3207 conf->writeEntry(APP_KEY+category, icon); 3206 conf->writeEntry(APP_KEY+category, icon);
3208// #endif 3207// #endif
3209 saveConf(); 3208 saveConf();
3210 QImage img = pix->convertToImage(); 3209 QImage img = pix->convertToImage();
3211 pix->convertFromImage(img.smoothScale(14,14)); 3210 pix->convertFromImage(img.smoothScale(14,14));
3212 cat->setIconName (icon); 3211 cat->setIconName (icon);
3213 cat->setIcon (*pix); 3212 cat->setIcon (*pix);
3214 } 3213 }
3215 } 3214 }
3216 else 3215 else
3217 { 3216 {
3218// #ifndef WIN32 3217// #ifndef WIN32
3219 conf->removeEntry (category); 3218 conf->removeEntry (category);
3220// #endif 3219// #endif
3221 saveConf(); 3220 saveConf();
3222 cat->setIcon (*getPredefinedIcon(category)); 3221 cat->setIcon (*getPredefinedIcon(category));
3223 } 3222 }
3224 3223
3225 // change the category name of the selected category 3224 // change the category name of the selected category
3226 QListViewItem *catItem = cat->getListItem(); 3225 QListViewItem *catItem = cat->getListItem();
3227 if (catItem) 3226 if (catItem)
3228 { 3227 {
3229 qWarning (category); 3228 qWarning (category);
3230 catItem->setText( 0, tr( category ) ); 3229 catItem->setText( 0, tr( category ) );
3231 cat->setCategoryName (tr(category)); 3230 cat->setCategoryName (tr(category));
3232 3231
3233 cat->initListItem(); 3232 cat->initListItem();
3234 categories.insert (category, cat); 3233 categories.insert (category, cat);
3235 } 3234 }
3236 } 3235 }
3237 saveCategoryDialogFields(dialog); 3236 saveCategoryDialogFields(dialog);
3238 } 3237 }
3239 else 3238 else
3240 { 3239 {
3241 // delete dialog; 3240 // delete dialog;
3242 dialog->hide(); 3241 dialog->hide();
3243 return; 3242 return;
3244 } 3243 }
3245 3244
3246 } 3245 }
3247} 3246}
3248 3247
3249void ZSafe::cutItem() 3248void ZSafe::cutItem()
3250{ 3249{
3251 if (!selectedItem) 3250 if (!selectedItem)
3252 return; 3251 return;
3253 if (!isCategory(selectedItem)) 3252 if (!isCategory(selectedItem))
3254 { 3253 {
3255 IsCut = true; 3254 IsCut = true;
3256 copiedItem = selectedItem; 3255 copiedItem = selectedItem;
3257 } 3256 }
3258} 3257}
3259 3258
3260void ZSafe::copyItem() 3259void ZSafe::copyItem()
3261{ 3260{
3262 if (!selectedItem) 3261 if (!selectedItem)
3263 return; 3262 return;
3264 if (!isCategory(selectedItem)) 3263 if (!isCategory(selectedItem))
3265 { 3264 {
3266 IsCopy = true; 3265 IsCopy = true;
3267 copiedItem = selectedItem; 3266 copiedItem = selectedItem;
3268 } 3267 }
3269} 3268}
3270 3269
3271// paste item into category 3270// paste item into category
3272void ZSafe::pasteItem() 3271void ZSafe::pasteItem()
3273{ 3272{
3274 if (!selectedItem) 3273 if (!selectedItem)
3275 return; 3274 return;
3276 if (isCategory(selectedItem)) 3275 if (isCategory(selectedItem))
3277 { 3276 {
3278 modified = true; 3277 modified = true;
3279 if (IsCut) 3278 if (IsCut)
3280 { 3279 {
3281 if (copiedItem) 3280 if (copiedItem)
3282 { 3281 {
3283 // add the new item 3282 // add the new item
3284 QListViewItem *i = new ShadedListItem (0, selectedItem); 3283 QListViewItem *i = new ShadedListItem (0, selectedItem);
3285 // i->setOpen (TRUE); 3284 // i->setOpen (TRUE);
3286 i->setText (0, copiedItem->text(0)); 3285 i->setText (0, copiedItem->text(0));
3287 i->setText (1, copiedItem->text(1)); 3286 i->setText (1, copiedItem->text(1));
3288 i->setText (2, copiedItem->text(2)); 3287 i->setText (2, copiedItem->text(2));
3289 i->setText (3, copiedItem->text(3)); 3288 i->setText (3, copiedItem->text(3));
3290 i->setText (4, copiedItem->text(4)); 3289 i->setText (4, copiedItem->text(4));
3291 i->setText (5, copiedItem->text(5)); 3290 i->setText (5, copiedItem->text(5));
3292 selectedItem->setOpen( TRUE ); 3291 selectedItem->setOpen( TRUE );
3293 3292
3294 // remove the cutted item 3293 // remove the cutted item
3295 copiedItem->parent()->takeItem(copiedItem); 3294 copiedItem->parent()->takeItem(copiedItem);
3296 selectedItem = NULL; 3295 selectedItem = NULL;
3297 } 3296 }
3298 } 3297 }
3299 else if (IsCopy) 3298 else if (IsCopy)
3300 { 3299 {
3301 if (copiedItem) 3300 if (copiedItem)
3302 { 3301 {
3303 // add the new item 3302 // add the new item
3304 QListViewItem *i = new ShadedListItem (0, selectedItem); 3303 QListViewItem *i = new ShadedListItem (0, selectedItem);
3305 // i->setOpen (TRUE); 3304 // i->setOpen (TRUE);
3306 i->setText (0, copiedItem->text(0)); 3305 i->setText (0, copiedItem->text(0));
3307 i->setText (1, copiedItem->text(1)); 3306 i->setText (1, copiedItem->text(1));
3308 i->setText (2, copiedItem->text(2)); 3307 i->setText (2, copiedItem->text(2));
3309 i->setText (3, copiedItem->text(3)); 3308 i->setText (3, copiedItem->text(3));
3310 i->setText (4, copiedItem->text(4)); 3309 i->setText (4, copiedItem->text(4));
3311 i->setText (5, copiedItem->text(5)); 3310 i->setText (5, copiedItem->text(5));
3312 selectedItem->setOpen( TRUE ); 3311 selectedItem->setOpen( TRUE );
3313 } 3312 }
3314 } 3313 }
3315 } 3314 }
3316 IsCut = false; 3315 IsCut = false;
3317 IsCopy = false; 3316 IsCopy = false;
3318} 3317}
3319 3318
3320void ZSafe::newDocument() 3319void ZSafe::newDocument()
3321{ 3320{
3322 3321
3323 // open the file dialog 3322 // open the file dialog
3324#ifndef DESKTOP 3323#ifndef DESKTOP
3325#ifndef NO_OPIE 3324#ifndef NO_OPIE
3326 QMap<QString, QStringList> mimeTypes; 3325 QMap<QString, QStringList> mimeTypes;
3327 mimeTypes.insert(tr("All"), QStringList() ); 3326 mimeTypes.insert(tr("All"), QStringList() );
3328 mimeTypes.insert(tr("ZSafe"), "zsafe/*" ); 3327 mimeTypes.insert(tr("ZSafe"), "zsafe/*" );
3329 QString newFile = OFileDialog::getSaveFileName( OFileSelector::EXTENDED_ALL, 3328 QString newFile = OFileDialog::getSaveFileName( OFileSelector::EXTENDED_ALL,
3330 QDir::homeDirPath() + "/Documents/application/zsafe", 3329 QDir::homeDirPath() + "/Documents/application/zsafe",
3331 QString::null, 3330 QString::null,
3332 mimeTypes, 3331 mimeTypes,
3333 this, 3332 this,
3334 tr ("Create new ZSafe document")); 3333 tr ("Create new ZSafe document"));
3335#else 3334#else
3336 QString newFile = ScQtFileEdit::getSaveAsFileName(this, 3335 QString newFile = ScQtFileEdit::getSaveAsFileName(this,
3337 tr ("Create new ZSafe document"), 3336 tr ("Create new ZSafe document"),
3338 QDir::homeDirPath() + "/Documents/application/zsafe", 3337 QDir::homeDirPath() + "/Documents/application/zsafe",
3339 "*.zsf"); 3338 "*.zsf");
3340#endif 3339#endif
3341#else 3340#else
3342 QString newFile = QFileDialog::getSaveFileName( 3341 QString newFile = QFileDialog::getSaveFileName(
3343 QDir::homeDirPath() + "/Documents/application/zsafe", 3342 QDir::homeDirPath() + "/Documents/application/zsafe",
3344 "ZSafe (*.zsf)", 3343 "ZSafe (*.zsf)",
3345 this, 3344 this,
3346 "ZSafe File Dialog" 3345 "ZSafe File Dialog"
3347 "Choose a ZSafe file" ); 3346 "Choose a ZSafe file" );
3348#endif 3347#endif
3349 3348
3350 // open the new document 3349 // open the new document
3351 if (newFile && newFile.length() > 0 ) 3350 if (newFile && newFile.length() > 0 )
3352 { 3351 {
3353 // save the previous opened document 3352 // save the previous opened document
3354 if (!filename.isEmpty()) 3353 if (!filename.isEmpty())
3355 saveDocument(filename, FALSE); 3354 saveDocument(filename, FALSE);
3356 3355
3357 modified = true; 3356 modified = true;
3358 3357
3359 // clear the password list 3358 // clear the password list
3360 QListViewItem *i; 3359 QListViewItem *i;
3361 QListViewItem *c = NULL; 3360 QListViewItem *c = NULL;
3362 // step through all categories 3361 // step through all categories
3363 for (i = ListView->firstChild(); 3362 for (i = ListView->firstChild();
3364 i != NULL; 3363 i != NULL;
3365 i = i->nextSibling()) 3364 i = i->nextSibling())
3366 { 3365 {
3367 if (c) delete c; // delete the previous category 3366 if (c) delete c; // delete the previous category
3368 3367
3369 c = i; 3368 c = i;
3370 // step through all subitems 3369 // step through all subitems
3371 QListViewItem *si; 3370 QListViewItem *si;
3372 for (si = i->firstChild(); 3371 for (si = i->firstChild();
3373 si != NULL; ) 3372 si != NULL; )
3374 { 3373 {
3375 QListViewItem *_si = si; 3374 QListViewItem *_si = si;
3376 si = si->nextSibling(); 3375 si = si->nextSibling();
3377 i->takeItem(_si); // remove from view list 3376 i->takeItem(_si); // remove from view list
3378 if (_si) delete _si; 3377 if (_si) delete _si;
3379 } 3378 }
3380 } 3379 }
3381 if (c) delete c; // delete the previous category 3380 if (c) delete c; // delete the previous category
3382 categories.clear(); 3381 categories.clear();
3383 3382
3384 // m_password = ""; 3383 // m_password = "";
3385 selectedItem = NULL; 3384 selectedItem = NULL;
3386 3385
3387 filename = newFile; 3386 filename = newFile;
3388 3387
3389 // save the current filename to the config file 3388 // save the current filename to the config file
3390 conf->writeEntry(APP_KEY+"document", filename); 3389 conf->writeEntry(APP_KEY+"document", filename);
3391 saveConf(); 3390 saveConf();
3392 QString ti = filename.right (filename.length() - filename.findRev ('/') - 1); 3391 QString ti = filename.right (filename.length() - filename.findRev ('/') - 1);
3393#ifdef WIN32 3392#ifdef WIN32
3394 this->setCaption("Qt ZSafe: " + ti); 3393 this->setCaption("Qt ZSafe: " + ti);
3395#else 3394#else
3396 this->setCaption("ZSafe: " + ti); 3395 this->setCaption("ZSafe: " + ti);
3397#endif 3396#endif
3398 3397
3399 // openDocument(filename); 3398 // openDocument(filename);
3400 3399
3401 QMessageBox::information( this, tr("ZSafe"), 3400 QMessageBox::information( this, tr("ZSafe"),
3402 tr("Now you have to enter\na password twice for your\nnewly created document."), tr("&OK"), 0); 3401 tr("Now you have to enter\na password twice for your\nnewly created document."), tr("&OK"), 0);
3403 3402
3404 saveDocumentWithPwd(); 3403 saveDocumentWithPwd();
3405 } 3404 }
3406} 3405}
3407 3406
3408void ZSafe::loadDocument() 3407void ZSafe::loadDocument()
3409{ 3408{
3410 3409
3411 // open the file dialog 3410 // open the file dialog
3412#ifndef DESKTOP 3411#ifndef DESKTOP
3413#ifndef NO_OPIE 3412#ifndef NO_OPIE
3414 QMap<QString, QStringList> mimeTypes; 3413 QMap<QString, QStringList> mimeTypes;
3415 mimeTypes.insert(tr("All"), QStringList() ); 3414 mimeTypes.insert(tr("All"), QStringList() );
3416 mimeTypes.insert(tr("ZSafe"), "zsafe/*" ); 3415 mimeTypes.insert(tr("ZSafe"), "zsafe/*" );
3417 QString newFile = OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL, 3416 QString newFile = OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL,
3418 QDir::homeDirPath() + "/Documents/application/zsafe", 3417 QDir::homeDirPath() + "/Documents/application/zsafe",
3419 QString::null, 3418 QString::null,
3420 mimeTypes, 3419 mimeTypes,
3421 this, 3420 this,
3422 tr ("Open ZSafe document")); 3421 tr ("Open ZSafe document"));
3423#else 3422#else
3424 QString newFile = ScQtFileEdit::getOpenFileName(this, 3423 QString newFile = ScQtFileEdit::getOpenFileName(this,
3425 tr ("Open ZSafe document"), 3424 tr ("Open ZSafe document"),
3426 QDir::homeDirPath() + "/Documents/application/zsafe", 3425 QDir::homeDirPath() + "/Documents/application/zsafe",
3427 "*.zsf"); 3426 "*.zsf");
3428#endif 3427#endif
3429#else 3428#else
3430 QString newFile = QFileDialog::getOpenFileName( 3429 QString newFile = QFileDialog::getOpenFileName(
3431 QDir::homeDirPath() + "/Documents/application/zsafe", 3430 QDir::homeDirPath() + "/Documents/application/zsafe",
3432 "ZSafe (*.zsf)", 3431 "ZSafe (*.zsf)",
3433 this, 3432 this,
3434 "ZSafe File Dialog" 3433 "ZSafe File Dialog"
3435 "Choose a ZSafe file" ); 3434 "Choose a ZSafe file" );
3436#endif 3435#endif
3437 3436
3438 // open the new document 3437 // open the new document
3439 if (newFile && newFile.length() > 0 ) 3438 if (newFile && newFile.length() > 0 )
3440 { 3439 {
3441 // save the previous opened document 3440 // save the previous opened document
3442 if (!filename.isEmpty()) 3441 if (!filename.isEmpty())
3443 saveDocument(filename, FALSE); 3442 saveDocument(filename, FALSE);
3444 3443
3445 // clear the password list 3444 // clear the password list
3446 QListViewItem *i; 3445 QListViewItem *i;
3447 QListViewItem *c = NULL; 3446 QListViewItem *c = NULL;
3448 // step through all categories 3447 // step through all categories
3449 for (i = ListView->firstChild(); 3448 for (i = ListView->firstChild();
3450 i != NULL; 3449 i != NULL;
3451 i = i->nextSibling()) 3450 i = i->nextSibling())
3452 { 3451 {
3453 if (c) delete c; // delete the previous category 3452 if (c) delete c; // delete the previous category
3454 3453
3455 c = i; 3454 c = i;
3456 // step through all subitems 3455 // step through all subitems
3457 QListViewItem *si; 3456 QListViewItem *si;
3458 for (si = i->firstChild(); 3457 for (si = i->firstChild();
3459 si != NULL; ) 3458 si != NULL; )
3460 { 3459 {
3461 QListViewItem *_si = si; 3460 QListViewItem *_si = si;
3462 si = si->nextSibling(); 3461 si = si->nextSibling();
3463 i->takeItem(_si); // remove from view list 3462 i->takeItem(_si); // remove from view list
3464 if (_si) delete _si; 3463 if (_si) delete _si;
3465 } 3464 }
3466 } 3465 }
3467 if (c) delete c; // delete the previous category 3466 if (c) delete c; // delete the previous category
3468 categories.clear(); 3467 categories.clear();
3469 m_password = ""; 3468 m_password = "";
3470 selectedItem = NULL; 3469 selectedItem = NULL;
3471 filename = newFile; 3470 filename = newFile;
3472 3471
3473 // save the current filename to the config file 3472 // save the current filename to the config file
3474 conf->writeEntry(APP_KEY+"document", filename); 3473 conf->writeEntry(APP_KEY+"document", filename);
3475 saveConf(); 3474 saveConf();
3476 QString ti = filename.right (filename.length() - filename.findRev ('/') - 1); 3475 QString ti = filename.right (filename.length() - filename.findRev ('/') - 1);
3477#ifdef WIN32 3476#ifdef WIN32
3478 this->setCaption("Qt ZSafe: " + ti); 3477 this->setCaption("Qt ZSafe: " + ti);
3479#else 3478#else
3480 this->setCaption("ZSafe: " + ti); 3479 this->setCaption("ZSafe: " + ti);
3481#endif 3480#endif
3482 3481
3483 openDocument(filename); 3482 openDocument(filename);
3484 } 3483 }
3485} 3484}
3486 3485
3487void ZSafe::saveDocumentAs() 3486void ZSafe::saveDocumentAs()
3488{ 3487{
3489 3488
3490#ifndef DESKTOP 3489#ifndef DESKTOP
3491#ifndef NO_OPIE 3490#ifndef NO_OPIE
3492 QMap<QString, QStringList> mimeTypes; 3491 QMap<QString, QStringList> mimeTypes;
3493 mimeTypes.insert(tr("All"), QStringList() ); 3492 mimeTypes.insert(tr("All"), QStringList() );
3494 mimeTypes.insert(tr("ZSafe"), "zsafe/*" ); 3493 mimeTypes.insert(tr("ZSafe"), "zsafe/*" );
3495 QString newFile = OFileDialog::getSaveFileName( OFileSelector::EXTENDED_ALL, 3494 QString newFile = OFileDialog::getSaveFileName( OFileSelector::EXTENDED_ALL,
3496 QDir::homeDirPath() + "/Documents/application/zsafe", 3495 QDir::homeDirPath() + "/Documents/application/zsafe",
3497 QString::null, 3496 QString::null,
3498 mimeTypes, 3497 mimeTypes,
3499 this, 3498 this,
3500 tr ("Save ZSafe document as..")); 3499 tr ("Save ZSafe document as.."));
3501#else 3500#else
3502 QString newFile = ScQtFileEdit::getSaveAsFileName(this, 3501 QString newFile = ScQtFileEdit::getSaveAsFileName(this,
3503 tr ("Save ZSafe document as.."), 3502 tr ("Save ZSafe document as.."),
3504 QDir::homeDirPath() + "/Documents/application/zsafe", 3503 QDir::homeDirPath() + "/Documents/application/zsafe",
3505 "*.zsf"); 3504 "*.zsf");
3506#endif 3505#endif
3507#else 3506#else
3508 // open the file dialog 3507 // open the file dialog
3509 QString newFile = QFileDialog::getSaveFileName( 3508 QString newFile = QFileDialog::getSaveFileName(
3510 QDir::homeDirPath() + "/Documents/application/zsafe", 3509 QDir::homeDirPath() + "/Documents/application/zsafe",
3511 "ZSafe (*.zsf)", 3510 "ZSafe (*.zsf)",
3512 this, 3511 this,
3513 "ZSafe File Dialog" 3512 "ZSafe File Dialog"
3514 "Choose a ZSafe file" ); 3513 "Choose a ZSafe file" );
3515#endif 3514#endif
3516 3515
3517 // open the new document 3516 // open the new document
3518 if (newFile && newFile.length() > 0 ) 3517 if (newFile && newFile.length() > 0 )
3519 { 3518 {
3520 // save the previous opened document 3519 // save the previous opened document
3521 if (!filename.isEmpty()) 3520 if (!filename.isEmpty())
3522 saveDocument(filename, FALSE); 3521 saveDocument(filename, FALSE);
3523 3522
3524 selectedItem = NULL; 3523 selectedItem = NULL;
3525 filename = newFile; 3524 filename = newFile;
3526 3525
3527 // save the current filename to the config file 3526 // save the current filename to the config file
3528 conf->writeEntry(APP_KEY+"document", filename); 3527 conf->writeEntry(APP_KEY+"document", filename);
3529 saveConf(); 3528 saveConf();
3530 QString ti = filename.right (filename.length() - filename.findRev ('/') - 1); 3529 QString ti = filename.right (filename.length() - filename.findRev ('/') - 1);
3531#ifdef WIN32 3530#ifdef WIN32
3532 this->setCaption("Qt ZSafe: " + ti); 3531 this->setCaption("Qt ZSafe: " + ti);
3533#else 3532#else
3534 this->setCaption("ZSafe: " + ti); 3533 this->setCaption("ZSafe: " + ti);
3535#endif 3534#endif
3536 3535
3537 QMessageBox::information( this, tr("ZSafe"), 3536 QMessageBox::information( this, tr("ZSafe"),
3538 tr("Now you have to enter\na password twice for your\nnewly created document."), tr("&OK"), 0); 3537 tr("Now you have to enter\na password twice for your\nnewly created document."), tr("&OK"), 0);
3539 3538
3540 saveDocumentWithPwd(); 3539 saveDocumentWithPwd();
3541 } 3540 }
3542} 3541}
3543 3542
3544void ZSafe::saveDocumentWithoutPwd() 3543void ZSafe::saveDocumentWithoutPwd()
3545{ 3544{
3546 saveDocument(filename, FALSE); 3545 saveDocument(filename, FALSE);
3547} 3546}
3548 3547
3549void ZSafe::saveDocumentWithPwd() 3548void ZSafe::saveDocumentWithPwd()
3550{ 3549{
3551 saveDocument(filename, TRUE); 3550 saveDocument(filename, TRUE);
3552} 3551}
3553 3552
3554void ZSafe::about() 3553void ZSafe::about()
3555{ 3554{
3556 QString info; 3555 QString info;
3557#ifdef JPATCH_HDE 3556#ifdef JPATCH_HDE
3558 info = "<html><body><div align=""center"">"; 3557 info = "<html><body><div align=""center"">";
3559 info += "<b>"; 3558 info += "<b>";
3560 info += tr("Zaurus Password Manager<br>"); 3559 info += tr("Zaurus Password Manager<br>");
3561 info += tr("ZSafe version 2.1.2-jv01b<br>"); 3560 info += tr("ZSafe version 2.1.2-jv01b<br>");
3562 info += "</b>"; 3561 info += "</b>";
3563 info += tr("by Carsten Schneider<br>"); 3562 info += tr("by Carsten Schneider<br>");
3564 info += "zcarsten@gmx.net<br>"; 3563 info += "zcarsten@gmx.net<br>";
3565 info += "http://z-soft.z-portal.info/zsafe"; 3564 info += "http://z-soft.z-portal.info/zsafe";
3566 info += "<br>"; 3565 info += "<br>";
3567 info += tr("Translations by Robert Ernst<br>"); 3566 info += tr("Translations by Robert Ernst<br>");
3568 info += "robert.ernst@linux-solutions.at<br>"; 3567 info += "robert.ernst@linux-solutions.at<br>";
3569 3568
3570 info += "<br><br>"; 3569 info += "<br><br>";
3571 info += QString::fromUtf8("æ~W¥æ~\\¬èª~^/VGA Zaurus対å¿~\\ã~C~Qã~C~Cã~C~Aä½~\\æ ~H~P<br>"); 3570 info += QString::fromUtf8("æ~W¥æ~\\¬èª~^/VGA Zaurus対å¿~\\ã~C~Qã~C~Cã~C~Aä½~\\æ ~H~P<br>");
3572 info += "HADECO R&D<br>"; 3571 info += "HADECO R&D<br>";
3573 info += "r&d@hadeco.co.jp<br>"; 3572 info += "r&d@hadeco.co.jp<br>";
3574 info += "http://www.hadeco.co.jp/r&d/<br>"; 3573 info += "http://www.hadeco.co.jp/r&d/<br>";
3575 info += "<br></div>"; 3574 info += "<br></div>";
3576 info += "</body></html>"; 3575 info += "</body></html>";
3577#else 3576#else
3578 info = "<html><body><div align=""center"">"; 3577 info = "<html><body><div align=""center"">";
3579 info += "<b>"; 3578 info += "<b>";
3580 info += tr("Zaurus Password Manager<br>"); 3579 info += tr("Zaurus Password Manager<br>");
3581 info += tr("ZSafe version 2.1.2<br>"); 3580 info += tr("ZSafe version 2.1.2<br>");
3582 info += "</b>"; 3581 info += "</b>";
3583 info += tr("by Carsten Schneider<br>"); 3582 info += tr("by Carsten Schneider<br>");
3584 info += "zcarsten@gmx.net<br>"; 3583 info += "zcarsten@gmx.net<br>";
3585 info += "http://z-soft.z-portal.info/zsafe"; 3584 info += "http://z-soft.z-portal.info/zsafe";
3586 info += "<br>"; 3585 info += "<br>";
3587 info += tr("Translations by Robert Ernst<br>"); 3586 info += tr("Translations by Robert Ernst<br>");
3588 info += "robert.ernst@linux-solutions.at<br>"; 3587 info += "robert.ernst@linux-solutions.at<br>";
3589 info += "<br></div>"; 3588 info += "<br></div>";
3590 info += "</body></html>"; 3589 info += "</body></html>";
3591#endif 3590#endif
3592 3591
3593 // QMessageBox::information( this, tr("ZSafe"), info, tr("&OK"), 0); 3592 // QMessageBox::information( this, tr("ZSafe"), info, tr("&OK"), 0);
3594 3593
3595 QMessageBox mb( this, tr("ZSafe")); 3594 QMessageBox mb( this, tr("ZSafe"));
3596 mb.setText (info); 3595 mb.setText (info);
3597 mb.setButtonText (QMessageBox::Ok, tr ("&OK")); 3596 mb.setButtonText (QMessageBox::Ok, tr ("&OK"));
3598 QPixmap zsafe_img((const char**) zsafe_xpm); 3597 QPixmap zsafe_img((const char**) zsafe_xpm);
3599 mb.setIconPixmap (zsafe_img); 3598 mb.setIconPixmap (zsafe_img);
3600 mb.exec(); 3599 mb.exec();
3601} 3600}
3602 3601
3603void ZSafe::setExpandFlag() 3602void ZSafe::setExpandFlag()
3604{ 3603{
3605 expandTree = !expandTree; 3604 expandTree = !expandTree;
3606 file->setItemChecked('o', expandTree); 3605 file->setItemChecked('o', expandTree);
3607#ifndef DESKTOP 3606#ifndef DESKTOP
3608 conf->setGroup ("zsafePrefs"); 3607 conf->setGroup ("zsafePrefs");
3609#endif 3608#endif
3610// #ifndef WIN32 3609// #ifndef WIN32
3611 conf->writeEntry (APP_KEY+"expandTree", expandTree); 3610 conf->writeEntry (APP_KEY+"expandTree", expandTree);
3612// #endif 3611// #endif
3613 saveConf(); 3612 saveConf();
3614 3613
3615} 3614}
3616 3615
3617void ZSafe::paintEvent( QPaintEvent * ) 3616void ZSafe::paintEvent( QPaintEvent * )
3618{ 3617{
3619 if (raiseFlag) 3618 if (raiseFlag)
3620 { 3619 {
3621 raiseFlag = false; 3620 raiseFlag = false;
3622 raiseTimer.start (1, true); 3621 raiseTimer.start (1, true);
3623 if (infoForm->isVisible()) 3622 if (infoForm->isVisible())
3624 infoForm->raise(); 3623 infoForm->raise();
3625 } 3624 }
3626} 3625}
3627 3626
3628void ZSafe::resizeEvent ( QResizeEvent * ) 3627void ZSafe::resizeEvent ( QResizeEvent * )
3629{ 3628{
3630 // qWarning ("resizeEvent"); 3629 // qWarning ("resizeEvent");
3631#ifndef DESKTOP 3630#ifndef DESKTOP
3632 DeskW = appl->desktop()->width(); 3631 DeskW = appl->desktop()->width();
3633 DeskH = appl->desktop()->height(); 3632 DeskH = appl->desktop()->height();
3634#else 3633#else
3635 DeskW = this->width(); 3634 DeskW = this->width();
3636 DeskH = this->height(); 3635 DeskH = this->height();
3637#endif 3636#endif
3638 3637
3639 if (New) 3638 if (New)
3640 New->setGeometry ( QRect( DeskW-84, 2, 20, 20 ) ); 3639 New->setGeometry ( QRect( DeskW-84, 2, 20, 20 ) );
3641 if (Edit) 3640 if (Edit)
3642 Edit->setGeometry ( QRect( DeskW-64, 2, 20, 20 ) ); 3641 Edit->setGeometry ( QRect( DeskW-64, 2, 20, 20 ) );
3643 if (Delete) 3642 if (Delete)
3644 Delete->setGeometry( QRect( DeskW-44, 2, 20, 20 ) ); 3643 Delete->setGeometry( QRect( DeskW-44, 2, 20, 20 ) );
3645 if (Find) 3644 if (Find)
3646 Find->setGeometry ( QRect( DeskW-24, 2, 20, 20 ) ); 3645 Find->setGeometry ( QRect( DeskW-24, 2, 20, 20 ) );
3647} 3646}
3648 3647
3649void ZSafe::slotRaiseTimer() 3648void ZSafe::slotRaiseTimer()
3650{ 3649{
3651 if (infoForm->isVisible()) 3650 if (infoForm->isVisible())
3652 infoForm->raise(); 3651 infoForm->raise();
3653 raiseFlag = true; 3652 raiseFlag = true;
3654} 3653}
3655 3654
3656QPixmap * ZSafe::getPredefinedIcon(QString category) 3655QPixmap * ZSafe::getPredefinedIcon(QString category)
3657{ 3656{
3658 QPixmap *pm; 3657 QPixmap *pm;
3659 if (category == "Bank cards") 3658 if (category == "Bank cards")
3660 pm = new QPixmap((const char**)bank_cards_data); 3659 pm = new QPixmap((const char**)bank_cards_data);
3661 else if (category == "Passwords") 3660 else if (category == "Passwords")
3662 pm = new QPixmap((const char**)passwords_data); 3661 pm = new QPixmap((const char**)passwords_data);
3663 else if (category == "Software") 3662 else if (category == "Software")
3664 pm = new QPixmap((const char**)software_data); 3663 pm = new QPixmap((const char**)software_data);
3665 else if (category == "General") 3664 else if (category == "General")
3666 pm = new QPixmap((const char**)general_data); 3665 pm = new QPixmap((const char**)general_data);
3667 else 3666 else
3668 pm = new QPixmap((const char**)general_data); 3667 pm = new QPixmap((const char**)general_data);
3669 return pm; 3668 return pm;
3670} 3669}
3671 3670
3672void ZSafe::setDocument(const QString& fileref) 3671void ZSafe::setDocument(const QString& fileref)
3673{ 3672{
3674#ifndef DESKTOP 3673#ifndef DESKTOP
3675 // stop the timer to prevent loading of the default document 3674 // stop the timer to prevent loading of the default document
3676 docuTimer.stop(); 3675 docuTimer.stop();
3677 3676
3678 DocLnk link(fileref); 3677 DocLnk link(fileref);
3679 if ( link.isValid() ) 3678 if ( link.isValid() )
3680 { 3679 {
3681 // if (filename != link.file()) 3680 // if (filename != link.file())
3682 // saveDocument(filename, FALSE); 3681 // saveDocument(filename, FALSE);
3683 filename = link.file(); 3682 filename = link.file();
3684 } 3683 }
3685 else 3684 else
3686 { 3685 {
3687 // if (filename != fileref) 3686 // if (filename != fileref)
3688 // saveDocument(filename, FALSE); 3687 // saveDocument(filename, FALSE);
3689 filename = fileref; 3688 filename = fileref;
3690 } 3689 }
3691 // save the current filename to the config file 3690 // save the current filename to the config file
3692 conf->writeEntry(APP_KEY+"document", filename); 3691 conf->writeEntry(APP_KEY+"document", filename);
3693 saveConf(); 3692 saveConf();
3694 QString ti = filename.right (filename.length() - filename.findRev ('/') - 1); 3693 QString ti = filename.right (filename.length() - filename.findRev ('/') - 1);
3695#ifdef WIN32 3694#ifdef WIN32
3696 this->setCaption("Qt ZSafe: " + ti); 3695 this->setCaption("Qt ZSafe: " + ti);
3697#else 3696#else
3698 this->setCaption("ZSafe: " + ti); 3697 this->setCaption("ZSafe: " + ti);
3699#endif 3698#endif
3700 3699
3701 // clear the password list 3700 // clear the password list
3702 QListViewItem *i; 3701 QListViewItem *i;
3703 QListViewItem *c = NULL; 3702 QListViewItem *c = NULL;
3704 // step through all categories 3703 // step through all categories
3705 for (i = ListView->firstChild(); 3704 for (i = ListView->firstChild();
3706 i != NULL; 3705 i != NULL;
3707 i = i->nextSibling()) 3706 i = i->nextSibling())
3708 { 3707 {
3709 if (c) delete c; // delete the previous category 3708 if (c) delete c; // delete the previous category
3710 3709
3711 c = i; 3710 c = i;
3712 // step through all subitems 3711 // step through all subitems
3713 QListViewItem *si; 3712 QListViewItem *si;
3714 for (si = i->firstChild(); 3713 for (si = i->firstChild();
3715 si != NULL; ) 3714 si != NULL; )
3716 { 3715 {
3717 QListViewItem *_si = si; 3716 QListViewItem *_si = si;
3718 si = si->nextSibling(); 3717 si = si->nextSibling();
3719 i->takeItem(_si); // remove from view list 3718 i->takeItem(_si); // remove from view list
3720 if (_si) delete _si; 3719 if (_si) delete _si;
3721 } 3720 }
3722 } 3721 }
3723 if (c) delete c; // delete the previous category 3722 if (c) delete c; // delete the previous category
3724 categories.clear(); 3723 categories.clear();
3725 3724
3726 m_password = ""; 3725 m_password = "";
3727 selectedItem = NULL; 3726 selectedItem = NULL;
3728 3727
3729 openDocument(filename); 3728 openDocument(filename);
3730#endif 3729#endif
3731} 3730}
3732 3731
3733 3732
3734 3733
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
17const int endianTest = 1; 14const 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
29KRFBBuffer::KRFBBuffer( KRFBDecoder *decoder, 26KRFBBuffer::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
38KRFBBuffer::~KRFBBuffer() 35KRFBBuffer::~KRFBBuffer()
39{ 36{
40 delete pix; 37 delete pix;
41} 38}
42 39
43void KRFBBuffer::resize( int w, int h ) 40void 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
55void KRFBBuffer::soundBell() 52void KRFBBuffer::soundBell()
56{ 53{
57 emit bell(); 54 emit bell();
58} 55}
59 56
60void KRFBBuffer::mouseEvent( QMouseEvent *e ) 57void KRFBBuffer::mouseEvent( QMouseEvent *e )
61{ 58{
62 decoder->sendMouseEvent( e ); 59 decoder->sendMouseEvent( e );
63} 60}
64 61
65void KRFBBuffer::keyPressEvent( QKeyEvent *e ) 62void 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
72void KRFBBuffer::keyReleaseEvent( QKeyEvent *e ) 69void KRFBBuffer::keyReleaseEvent( QKeyEvent *e )
73{ 70{
74 decoder->sendKeyReleaseEvent( e ); 71 decoder->sendKeyReleaseEvent( e );
75} 72}
76 73
77void KRFBBuffer::copyRect( int srcX, int srcY, 74void 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
86void KRFBBuffer::drawRawRectChunk( void *data, 83void 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
18KRFBCanvas::KRFBCanvas( QWidget *parent, const char *name ) 9KRFBCanvas::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
36KRFBCanvas::~KRFBCanvas() 27KRFBCanvas::~KRFBCanvas()
37{ 28{
38} 29}
39 30
40 31
41void KRFBCanvas::openConnection(KRFBServer server) 32void 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
51void KRFBCanvas::openURL( const QUrl &url ) 42void 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
64void KRFBCanvas::closeConnection() 55void 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
76void KRFBCanvas::bell() 67void 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
84void KRFBCanvas::loggedIn() 75void 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
107void KRFBCanvas::viewportPaintEvent( QPaintEvent *e ) 98void 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
124void KRFBCanvas::viewportUpdate( int x, int y, int w, int h ) 115void 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
129void KRFBCanvas::contentsMousePressEvent( QMouseEvent *e ) 120void 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
148void KRFBCanvas::contentsMouseReleaseEvent( QMouseEvent *e ) 139void 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
158void KRFBCanvas::contentsMouseMoveEvent( QMouseEvent *e ) 149void 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
164void KRFBCanvas::keyPressEvent( QKeyEvent *e ) 155void 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
170void KRFBCanvas::keyReleaseEvent( QKeyEvent *e ) 161void 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
176void KRFBCanvas::refresh() 167void KRFBCanvas::refresh()
177{ 168{
178 if ( loggedIn_ ) 169 if ( loggedIn_ )
179 connection_->refresh(); 170 connection_->refresh();
180} 171}
181 172
182void KRFBCanvas::clipboardChanged() 173void 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}
188void KRFBCanvas::sendCtlAltDel( void) 179void 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
201void KRFBCanvas::markDoubleClick( void) 192void KRFBCanvas::markDoubleClick( void)
202{ 193{
203 nextRightClick=1; 194 nextRightClick=1;
204} 195}
205 196
206void KRFBCanvas::markRightClick( void) 197void 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
12KRFBConnection::KRFBConnection( QObject *parent ) 11KRFBConnection::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
25KRFBConnection::~KRFBConnection() 24KRFBConnection::~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
33void KRFBConnection::connectTo( KRFBServer server) 32void 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
53void KRFBConnection::disconnect() 52void 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
70void KRFBConnection::disconnectDone() 69void 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
82void KRFBConnection::gotSocketConnection() 81void 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
95void KRFBConnection::gotRFBConnection() 94void 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
121void KRFBConnection::gotSocketError( int err ) 120void 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
158void KRFBConnection::gotMoreData() 157void 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
169void KRFBConnection::waitForData( unsigned int sz ) 168void 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
186int KRFBConnection::read( void *buf, int sz ) 185int 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
191int KRFBConnection::write( void *buf, int sz ) 190int 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
196KRFBConnection::State KRFBConnection::state() const 195KRFBConnection::State KRFBConnection::state() const
197{ 196{
198 return currentState_; 197 return currentState_;
199} 198}
200 199
201void KRFBConnection::setPortBase( int base ) 200void KRFBConnection::setPortBase( int base )
202{ 201{
203 portBase_ = base; 202 portBase_ = base;
204} 203}
205 204
206int KRFBConnection::portBase() const 205int KRFBConnection::portBase() const
207{ 206{
208 return portBase_; 207 return portBase_;
209} 208}
210 209
211void KRFBConnection::updateTimer() 210void KRFBConnection::updateTimer()
212{ 211{
213 decoder_->sendUpdateRequest( true ); 212 decoder_->sendUpdateRequest( true );
214} 213}
215 214
216void KRFBConnection::refresh() 215void KRFBConnection::refresh()
217{ 216{
218 decoder_->sendUpdateRequest( false ); 217 decoder_->sendUpdateRequest( false );
219} 218}
220 219
221void KRFBConnection::sendCutText( const QString &text ) 220void KRFBConnection::sendCutText( const QString &text )
222{ 221{
223 decoder_->sendCutEvent( text ); 222 decoder_->sendCutEvent( text );
224} 223}
225 224
226const QUrl &KRFBConnection::url() 225const 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,847 +1,841 @@
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
21const int endianTest = 1; 15const 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//
36const int ServerInitLength = 24; 30const int ServerInitLength = 24;
37const int UpdateHeaderLength = 4; 31const int UpdateHeaderLength = 4;
38const int RectHeaderLength = 12; 32const int RectHeaderLength = 12;
39const int RectChunkSize = 4; 33const int RectChunkSize = 4;
40const int CopyRectPosLength = 4; 34const int CopyRectPosLength = 4;
41const int ServerCutLenLength = 7; 35const int ServerCutLenLength = 7;
42 36
43// 37//
44// Client -> Server Message Identifiers 38// Client -> Server Message Identifiers
45// 39//
46static CARD8 SetPixelFormatId = 0; 40static CARD8 SetPixelFormatId = 0;
47//static CARD8 FixColourMapEntriesId = 1; // Not used 41//static CARD8 FixColourMapEntriesId = 1; // Not used
48static CARD8 SetEncodingsId = 2; 42static CARD8 SetEncodingsId = 2;
49static CARD8 UpdateRequestId = 3; 43static CARD8 UpdateRequestId = 3;
50static CARD8 KeyEventId = 4; 44static CARD8 KeyEventId = 4;
51static CARD8 PointerEventId = 5; 45static CARD8 PointerEventId = 5;
52static CARD8 ClientCutTextId = 6; 46static CARD8 ClientCutTextId = 6;
53 47
54// 48//
55// Server -> Client Message Identifiers 49// Server -> Client Message Identifiers
56// 50//
57static CARD8 UpdateId = 0; 51static CARD8 UpdateId = 0;
58static CARD8 BellId = 2; 52static CARD8 BellId = 2;
59static CARD8 ServerCutId = 3; 53static CARD8 ServerCutId = 3;
60 54
61// 55//
62// Encoding identifiers 56// Encoding identifiers
63// 57//
64static CARD32 RawEncoding = Swap32IfLE( 0 ); 58static CARD32 RawEncoding = Swap32IfLE( 0 );
65static CARD32 CopyRectEncoding = Swap32IfLE(1 ); 59static CARD32 CopyRectEncoding = Swap32IfLE(1 );
66static CARD32 RreEncoding = Swap32IfLE( 2 ); 60static CARD32 RreEncoding = Swap32IfLE( 2 );
67static CARD32 CorreEncoding = Swap32IfLE( 4 ); 61static CARD32 CorreEncoding = Swap32IfLE( 4 );
68static CARD32 HexTileEncoding = Swap32IfLE( 5 ); 62static CARD32 HexTileEncoding = Swap32IfLE( 5 );
69 63
70static struct { 64static 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
112KRFBDecoder::KRFBDecoder( KRFBConnection *con ) 106KRFBDecoder::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
126KRFBDecoder::~KRFBDecoder() 120KRFBDecoder::~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
134void KRFBDecoder::start() 128void KRFBDecoder::start()
135{ 129{
136 sendClientInit(); 130 sendClientInit();
137} 131}
138 132
139void KRFBDecoder::sendClientInit() 133void 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
154void KRFBDecoder::gotServerInit() 148void 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
211void KRFBDecoder::gotDesktopName() 205void 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
246void KRFBDecoder::decidePixelFormat() 240void 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
310void KRFBDecoder::sendPixelFormat() 304void 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
331void KRFBDecoder::sendAllowedEncodings() 325void 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
353void KRFBDecoder::sendUpdateRequest( bool incremental ) 347void 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
376void KRFBDecoder::gotUpdateHeader() 370void 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
423void KRFBDecoder::gotRectHeader() 417void 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
489void KRFBDecoder::handleRawRect() 483void 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
512void KRFBDecoder::getRawRectChunk( int lines ) 506void 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
525void KRFBDecoder::gotRawRectChunk() 519void 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
574void KRFBDecoder::handleCopyRect() 568void 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
581void KRFBDecoder::gotCopyRectPos() 575void 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
610void KRFBDecoder::handleRRERect() 604void KRFBDecoder::handleRRERect()
611{ 605{
612 qWarning( "RRE not implemented" ); 606 qWarning( "RRE not implemented" );
613} 607}
614 608
615void KRFBDecoder::handleCoRRERect() 609void KRFBDecoder::handleCoRRERect()
616{ 610{
617 qWarning( "CoRRE not implemented" ); 611 qWarning( "CoRRE not implemented" );
618} 612}
619 613
620void KRFBDecoder::handleHexTileRect() 614void KRFBDecoder::handleHexTileRect()
621{ 615{
622 qWarning( "HexTile not implemented" ); 616 qWarning( "HexTile not implemented" );
623} 617}
624 618
625void KRFBDecoder::sendMouseEvent( QMouseEvent *e ) 619void 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
659void KRFBDecoder::sendCutEvent( const QString &unicode ) 653void 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
680void KRFBDecoder::gotServerCut() 674void 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
689void KRFBDecoder::gotServerCutLength() 683void 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
706void KRFBDecoder::gotServerCutText() 700void 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
752void KRFBDecoder::gotBell() 746void 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
772void KRFBDecoder::sendKeyPressEvent( QKeyEvent *event ) 766void 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;
782 con->write( &KeyEventId, 1 ); 776 con->write( &KeyEventId, 1 );
783 con->write( &mask, 1 ); 777 con->write( &mask, 1 );
784 con->write( &padding, 2 ); 778 con->write( &padding, 2 );
785 con->write( &key, 4 ); 779 con->write( &key, 4 );
786 } 780 }
787} 781}
788 782
789void KRFBDecoder::sendKeyReleaseEvent( QKeyEvent *event ) 783void KRFBDecoder::sendKeyReleaseEvent( QKeyEvent *event )
790{ 784{
791 int key; 785 int key;
792 key = toKeySym( event ); 786 key = toKeySym( event );
793 if ( key ) { 787 if ( key ) {
794 key = Swap32IfLE( key ); 788 key = Swap32IfLE( key );
795 789
796 CARD8 mask = false; 790 CARD8 mask = false;
797 791
798 CARD16 padding = 0; 792 CARD16 padding = 0;
799 con->write( &KeyEventId, 1 ); 793 con->write( &KeyEventId, 1 );
800 con->write( &mask, 1 ); 794 con->write( &mask, 1 );
801 con->write( &padding, 2 ); 795 con->write( &padding, 2 );
802 con->write( &key, 4 ); 796 con->write( &key, 4 );
803 } 797 }
804} 798}
805 799
806 800
807int KRFBDecoder::toKeySym( QKeyEvent *k ) 801int KRFBDecoder::toKeySym( QKeyEvent *k )
808{ 802{
809 int ke = 0; 803 int ke = 0;
810 804
811 ke = k->ascii(); 805 ke = k->ascii();
812 // Markus: Crappy hack. I dont know why lower case letters are 806 // Markus: Crappy hack. I dont know why lower case letters are
813 // not defined in qkeydefs.h. The key() for e.g. 'l' == 'L'. 807 // not defined in qkeydefs.h. The key() for e.g. 'l' == 'L'.
814 // This sucks. :-( 808 // This sucks. :-(
815 809
816 if ( (ke == 'a') || (ke == 'b') || (ke == 'c') || (ke == 'd') 810 if ( (ke == 'a') || (ke == 'b') || (ke == 'c') || (ke == 'd')
817 || (ke == 'e') || (ke == 'f') || (ke == 'g') || (ke == 'h') 811 || (ke == 'e') || (ke == 'f') || (ke == 'g') || (ke == 'h')
818 || (ke == 'i') || (ke == 'j') || (ke == 'k') || (ke == 'l') 812 || (ke == 'i') || (ke == 'j') || (ke == 'k') || (ke == 'l')
819 || (ke == 'm') || (ke == 'n') || (ke == 'o') || (ke == 'p') 813 || (ke == 'm') || (ke == 'n') || (ke == 'o') || (ke == 'p')
820 || (ke == 'q') || (ke == 'r') || (ke == 's') || (ke == 't') 814 || (ke == 'q') || (ke == 'r') || (ke == 's') || (ke == 't')
821 || (ke == 'u') || (ke == 'v') ||( ke == 'w') || (ke == 'x') 815 || (ke == 'u') || (ke == 'v') ||( ke == 'w') || (ke == 'x')
822 || (ke == 'y') || (ke == 'z') ) { 816 || (ke == 'y') || (ke == 'z') ) {
823 ke = k->key(); 817 ke = k->key();
824 ke = ke + 0x20; 818 ke = ke + 0x20;
825 return ke; 819 return ke;
826 } 820 }
827 821
828 // qkeydefs = xkeydefs! :-) 822 // qkeydefs = xkeydefs! :-)
829 if ( ( k->key() >= 0x0a0 ) && k->key() <= 0x0ff ) 823 if ( ( k->key() >= 0x0a0 ) && k->key() <= 0x0ff )
830 return k->key(); 824 return k->key();
831 825
832 if ( ( k->key() >= 0x20 ) && ( k->key() <= 0x7e ) ) 826 if ( ( k->key() >= 0x20 ) && ( k->key() <= 0x7e ) )
833 return k->key(); 827 return k->key();
834 828
835 // qkeydefs != xkeydefs! :-( 829 // qkeydefs != xkeydefs! :-(
836 // This is gonna suck :-( 830 // This is gonna suck :-(
837 831
838 int i = 0; 832 int i = 0;
839 while ( keyMap[i].keycode ) { 833 while ( keyMap[i].keycode ) {
840 if ( k->key() == keyMap[i].keycode ) 834 if ( k->key() == keyMap[i].keycode )
841 return keyMap[i].keysym; 835 return keyMap[i].keysym;
842 i++; 836 i++;
843 } 837 }
844 838
845 return 0; 839 return 0;
846} 840}
847 841
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
4extern "C" { 4extern "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).
15const int ServerVersionLength = 12; 14const int ServerVersionLength = 12;
16const int ClientVersionLength = 12; 15const int ClientVersionLength = 12;
17const int AuthSchemeLength = 4; 16const int AuthSchemeLength = 4;
18const int FailureReasonSizeLength = 4; 17const int FailureReasonSizeLength = 4;
19const int ChallengeLength = 16; 18const int ChallengeLength = 16;
20const int AuthResultLength = 4; 19const int AuthResultLength = 4;
21 20
22// Authentication results 21// Authentication results
23enum AuthResult { 22enum AuthResult {
24 AuthOk, 23 AuthOk,
25 AuthFailed, 24 AuthFailed,
26 AuthTooMany 25 AuthTooMany
27}; 26};
28 27
29typedef unsigned char CARD8; 28typedef unsigned char CARD8;
30typedef unsigned short CARD16; 29typedef unsigned short CARD16;
31typedef unsigned long CARD32; 30typedef unsigned long CARD32;
32 31
33const int endianTest = 1; 32const 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
45KRFBLogin::KRFBLogin( KRFBConnection *con ) 44KRFBLogin::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
66KRFBLogin::~KRFBLogin() 65KRFBLogin::~KRFBLogin()
67{ 66{
68 67
69} 68}
70 69
71KRFBLogin::State KRFBLogin::state() const 70KRFBLogin::State KRFBLogin::state() const
72{ 71{
73 return currentState; 72 return currentState;
74} 73}
75 74
76void KRFBLogin::gotServerVersion() 75void 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
133void KRFBLogin::gotAuthScheme() 132void 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
169void KRFBLogin::gotChallenge() 168void 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
177void KRFBLogin::getPassword() 176void 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
204void KRFBLogin::gotFailureReasonSize() 203void 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
210void KRFBLogin::gotAuthResult() 209void 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
250void KRFBLogin::sendClientVersion() 249void 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
5KRFBServer::KRFBServer() 4KRFBServer::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}
26KRFBServer::~KRFBServer() 25KRFBServer::~KRFBServer()
27{ 26{
28} 27}
29 28
30int KRFBServer::encodings() 29int 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
29static int u_id = 1; 16static int u_id = 1;
30static int get_unique_id() 17static int get_unique_id()
31{ 18{
32 return u_id++; 19 return u_id++;
33} 20}
34 21
35 22
36/* XPM */ 23/* XPM */
37static char * menu_xpm[] = { 24static 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
57const int StatusTextId = 0; 44const int StatusTextId = 0;
58 45
59KVNC::KVNC( QWidget *parent, const char *name, WFlags f) : QMainWindow( 0, name ,WStyle_ContextHelp) 46KVNC::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
120KVNC::~KVNC() 107KVNC::~KVNC()
121{ 108{
122 109
123} 110}
124 111
125void KVNC::newConnection() 112void 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
138void KVNC::openConnection( QString name) 125void 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
152void KVNC::openConnection( void ) 139void KVNC::openConnection( void )
153{ 140{
154 openConnection( bookmarkSelector->selectedBookmark()); 141 openConnection( bookmarkSelector->selectedBookmark());
155} 142}
156 143
157void KVNC::openConnection( QListBoxItem * item) 144void KVNC::openConnection( QListBoxItem * item)
158{ 145{
159 if (item) 146 if (item)
160 openConnection(item->text()); 147 openConnection(item->text());
161} 148}
162 149
163void KVNC::setupActions() 150void 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
198void KVNC::toggleFullScreen() 185void 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
228void KVNC::closeConnection() 215void KVNC::closeConnection()
229{ 216{
230 if ( fullscreen ) 217 if ( fullscreen )
231 toggleFullScreen(); 218 toggleFullScreen();
232 canvas->closeConnection(); 219 canvas->closeConnection();
233} 220}
234 221
235void KVNC::showMenu() 222void 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
244void KVNC::connected() 231void 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
257void KVNC::loggedIn() 244void 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
263void KVNC::disconnected() 250void 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
279void KVNC::statusMessage( const QString &m ) 266void KVNC::statusMessage( const QString &m )
280{ 267{
281 Global::statusMessage( m ); 268 Global::statusMessage( m );
282} 269}
283 270
284void KVNC::error( const QString &msg ) 271void 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}
289void KVNC::deleteBookmark(void) 276void 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
21KVNCBookmarkDlg::KVNCBookmarkDlg( QWidget * parent, const char * name, WFlags f ) 7KVNCBookmarkDlg::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
30KVNCBookmarkDlg::~KVNCBookmarkDlg() 16KVNCBookmarkDlg::~KVNCBookmarkDlg()
31{ 17{
32} 18}
33 19
34void KVNCBookmarkDlg::addBookmark(KRFBServer * server) 20void 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
44void KVNCBookmarkDlg::deleteBookmark(QString name) 30void 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}
56KRFBServer *KVNCBookmarkDlg::getServer(QString name) 42KRFBServer *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*/
77QString KVNCBookmarkDlg::encipher(const QString& plain) 63QString 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
93QString KVNCBookmarkDlg::decipher(const QString& cipher) 79QString 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
107void KVNCBookmarkDlg::readBookmarks(void) 93void 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
176void KVNCBookmarkDlg::writeBookmarks(void) 162void 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}
211void KVNCBookmarkDlg::refresh(void) 197void 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
220QString KVNCBookmarkDlg::selectedBookmark() 206QString 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
16KVNCConnDlg::KVNCConnDlg( KRFBServer *options, 8KVNCConnDlg::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}
56KVNCConnDlg::~KVNCConnDlg() 48KVNCConnDlg::~KVNCConnDlg()
57{ 49{
58} 50}
59 51
60void KVNCConnDlg::accept() 52void KVNCConnDlg::accept()
61{ 53{
62 save(); 54 save();
63 QDialog::accept(); 55 QDialog::accept();
64} 56}
65 57
66void KVNCConnDlg::save() 58void 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
88void KVNCConnDlg::showPassword(int show) 80void 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
10OPIE_EXPORT_APP( OApplicationFactory<KVNC> ) 9OPIE_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 */
15MobileMsg::MobileMsg( QWidget* parent, const char* name, WFlags fl ) 10MobileMsg::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 */
27MobileMsg::~MobileMsg() 22MobileMsg::~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 */
35void MobileMsg::goodBye() 30void 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
9LiquidDecoInterface::LiquidDecoInterface ( ) 7LiquidDecoInterface::LiquidDecoInterface ( )
10{ 8{
11} 9}
12 10
13LiquidDecoInterface::~LiquidDecoInterface ( ) 11LiquidDecoInterface::~LiquidDecoInterface ( )
14{ 12{
15} 13}
16 14
17 15
18 16
19QString LiquidDecoInterface::name ( ) const 17QString LiquidDecoInterface::name ( ) const
20{ 18{
21 return qApp-> translate ( "Decoration", "Liquid" ); 19 return qApp-> translate ( "Decoration", "Liquid" );
22} 20}
23 21
24 22
25QPixmap LiquidDecoInterface::icon ( ) const 23QPixmap LiquidDecoInterface::icon ( ) const
26{ 24{
27 return QPixmap ( ); 25 return QPixmap ( );
28} 26}
29 27
30void LiquidDecoInterface::drawArea( Area a, QPainter *p, const WindowData *wd ) const 28void 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
117QRESULT LiquidDecoInterface::queryInterface ( const QUuid &uuid, QUnknownInterface **iface ) 115QRESULT 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
134Q_EXPORT_INTERFACE() 132Q_EXPORT_INTERFACE()
135{ 133{
136 Q_CREATE_INSTANCE( LiquidDecoInterface ) 134 Q_CREATE_INSTANCE( LiquidDecoInterface )
137} 135}
138 136