summaryrefslogtreecommitdiff
authorchicken <chicken>2004-03-01 20:00:34 (UTC)
committer chicken <chicken>2004-03-01 20:00:34 (UTC)
commit6bab4a28785c4ab5b0f0707c8c8db953e399cac8 (patch) (unidiff)
tree126dd6c09cc82b3d41ea70410803daac5cde5b60
parent4ffae5ecb25f6d640c69f53f02755b6ec58d4c98 (diff)
downloadopie-6bab4a28785c4ab5b0f0707c8c8db953e399cac8.zip
opie-6bab4a28785c4ab5b0f0707c8c8db953e399cac8.tar.gz
opie-6bab4a28785c4ab5b0f0707c8c8db953e399cac8.tar.bz2
fix includes
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,1604 +1,1602 @@
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
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,1620 +1,1613 @@
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() {
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,1618 +1,1617 @@
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 += "\";";
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