summaryrefslogtreecommitdiff
authorerik <erik>2007-01-26 20:22:50 (UTC)
committer erik <erik>2007-01-26 20:22:50 (UTC)
commit53d630c9c4813142ee13e6843c30476a5db26e78 (patch) (unidiff)
tree50a77a94cfeaccbb3d993bced8b7d0f498f74c7c
parent152a8fe978851aea8dac6ae5cb11f73540746b83 (diff)
downloadopie-53d630c9c4813142ee13e6843c30476a5db26e78.zip
opie-53d630c9c4813142ee13e6843c30476a5db26e78.tar.gz
opie-53d630c9c4813142ee13e6843c30476a5db26e78.tar.bz2
Each file in this commit exhibit an example of what prevent calls
'reverse inull'. All that means is that a pointer gets dereferenced. Then a pointer gets checked for validity before being dereferenced again. This almost always points to shenanigans. For example, the konsole.cpp file has this konsoleInit() call which passes in a const char** shell variable. Since it is a double pointer the programmer who wrote the code made the mistake of mixing the checking of the pointer and the pointer that points to the pointer. This commit attempts to correct that. Of course there are other instances of the same thing. But they all boil down to a small mistake which might have produced strange side effects.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/apps/embeddedkonsole/konsole.cpp10
-rw-r--r--core/apps/textedit/textedit.cpp100
-rw-r--r--noncore/applets/notesapplet/notes.cpp2
-rw-r--r--noncore/apps/advancedfm/advancedfm.cpp2
4 files changed, 49 insertions, 65 deletions
diff --git a/core/apps/embeddedkonsole/konsole.cpp b/core/apps/embeddedkonsole/konsole.cpp
index f4ca0bf..5c40569 100644
--- a/core/apps/embeddedkonsole/konsole.cpp
+++ b/core/apps/embeddedkonsole/konsole.cpp
@@ -1,1924 +1,1930 @@
1 1
2/* ---------------------------------------------------------------------- */ 2/* ---------------------------------------------------------------------- */
3/* */ 3/* */
4/* [main.C] Konsole */ 4/* [main.C] Konsole */
5/* */ 5/* */
6/* ---------------------------------------------------------------------- */ 6/* ---------------------------------------------------------------------- */
7/* */ 7/* */
8/* Copyright (c) 1997,1998 by Lars Doelle <lars.doelle@on-line.de> */ 8/* Copyright (c) 1997,1998 by Lars Doelle <lars.doelle@on-line.de> */
9/* */ 9/* */
10/* This file is part of Konsole, an X terminal. */ 10/* This file is part of Konsole, an X terminal. */
11/* */ 11/* */
12/* The material contained in here more or less directly orginates from */ 12/* The material contained in here more or less directly orginates from */
13/* kvt, which is copyright (c) 1996 by Matthias Ettrich <ettrich@kde.org> */ 13/* kvt, which is copyright (c) 1996 by Matthias Ettrich <ettrich@kde.org> */
14/* */ 14/* */
15/* ---------------------------------------------------------------------- */ 15/* ---------------------------------------------------------------------- */
16/* */ 16/* */
17/* Ported Konsole to Qt/Embedded */ 17/* Ported Konsole to Qt/Embedded */
18/* */ 18/* */
19/* Copyright (C) 2000 by John Ryland <jryland@trolltech.com> */ 19/* Copyright (C) 2000 by John Ryland <jryland@trolltech.com> */
20/* */ 20/* */
21/* -------------------------------------------------------------------------- */ 21/* -------------------------------------------------------------------------- */
22// enhancements added by L.J. Potter <ljp@llornkcor.com> 22// enhancements added by L.J. Potter <ljp@llornkcor.com>
23// enhancements added by Phillip Kuhn 23// enhancements added by Phillip Kuhn
24 24
25#include <stdlib.h> 25#include <stdlib.h>
26#include <sys/types.h> 26#include <sys/types.h>
27#include <pwd.h> 27#include <pwd.h>
28#include <unistd.h> 28#include <unistd.h>
29 29
30#ifdef QT_QWS_OPIE 30#ifdef QT_QWS_OPIE
31#include <opie2/ocolorpopupmenu.h> 31#include <opie2/ocolorpopupmenu.h>
32#include <opie2/odebug.h> 32#include <opie2/odebug.h>
33#include <opie2/oresource.h> 33#include <opie2/oresource.h>
34 34
35using namespace Opie; 35using namespace Opie;
36#endif 36#endif
37 37
38#include <qmenubar.h> 38#include <qmenubar.h>
39#include <qtabbar.h> 39#include <qtabbar.h>
40#include <qpe/config.h> 40#include <qpe/config.h>
41#include <qfontdatabase.h> 41#include <qfontdatabase.h>
42#include <qfile.h> 42#include <qfile.h>
43#include <qspinbox.h> 43#include <qspinbox.h>
44#include <qlayout.h> 44#include <qlayout.h>
45 45
46#include <sys/wait.h> 46#include <sys/wait.h>
47#include <stdio.h> 47#include <stdio.h>
48#include <stdlib.h> 48#include <stdlib.h>
49#include <assert.h> 49#include <assert.h>
50 50
51#include "konsole.h" 51#include "konsole.h"
52#include "commandeditdialog.h" 52#include "commandeditdialog.h"
53 53
54class EKNumTabBar : public QTabBar 54class EKNumTabBar : public QTabBar
55{ 55{
56public: 56public:
57 EKNumTabBar(QWidget *parent = 0, const char *name = 0) : 57 EKNumTabBar(QWidget *parent = 0, const char *name = 0) :
58 QTabBar(parent, name) 58 QTabBar(parent, name)
59 {} 59 {}
60 60
61 // QList<QTab> *getTabList() { return(tabList()); } 61 // QList<QTab> *getTabList() { return(tabList()); }
62 62
63 void numberTabs() 63 void numberTabs()
64 { 64 {
65 // Yes, it really is this messy. QTabWidget needs functions 65 // Yes, it really is this messy. QTabWidget needs functions
66 // that provide acces to tabs in a sequential way. 66 // that provide acces to tabs in a sequential way.
67 int m=INT_MIN; 67 int m=INT_MIN;
68 for (int i=0; i<count(); i++) 68 for (int i=0; i<count(); i++)
69 { 69 {
70 QTab* left=0; 70 QTab* left=0;
71 QListIterator<QTab> it(*tabList()); 71 QListIterator<QTab> it(*tabList());
72 int x=INT_MAX; 72 int x=INT_MAX;
73 for( QTab* t; (t=it.current()); ++it ) 73 for( QTab* t; (t=it.current()); ++it )
74 { 74 {
75 int tx = t->rect().x(); 75 int tx = t->rect().x();
76 if ( tx<x && tx>m ) 76 if ( tx<x && tx>m )
77 { 77 {
78 x = tx; 78 x = tx;
79 left = t; 79 left = t;
80 } 80 }
81 } 81 }
82 if ( left ) 82 if ( left )
83 { 83 {
84 left->setText(QString::number(i+1)); 84 left->setText(QString::number(i+1));
85 m = left->rect().x(); 85 m = left->rect().x();
86 } 86 }
87 } 87 }
88 } 88 }
89 89
90 virtual QSize sizeHint() const 90 virtual QSize sizeHint() const
91 { 91 {
92 if (isHidden()) 92 if (isHidden())
93 { 93 {
94 return(QSize(0,0)); 94 return(QSize(0,0));
95 } 95 }
96 else 96 else
97 { 97 {
98 QSize size = QTabBar::sizeHint(); 98 QSize size = QTabBar::sizeHint();
99 int shrink = 5; 99 int shrink = 5;
100 if (qApp->desktop()->width() > 600 || qApp->desktop()->height() > 600) 100 if (qApp->desktop()->width() > 600 || qApp->desktop()->height() > 600)
101 { 101 {
102 shrink = 10; 102 shrink = 10;
103 } 103 }
104 size.setHeight(size.height() - shrink); 104 size.setHeight(size.height() - shrink);
105 return(size); 105 return(size);
106 } 106 }
107 } 107 }
108 108
109}; 109};
110 110
111class EKNumTabWidget : public QTabWidget 111class EKNumTabWidget : public QTabWidget
112{ 112{
113public: 113public:
114 EKNumTabWidget(QWidget* parent) : QTabWidget(parent) 114 EKNumTabWidget(QWidget* parent) : QTabWidget(parent)
115 { 115 {
116 setTabBar(new EKNumTabBar(parent,"EKTabBar")); 116 setTabBar(new EKNumTabBar(parent,"EKTabBar"));
117 setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) ); 117 setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
118 } 118 }
119 119
120 EKNumTabBar *getTabBar() const 120 EKNumTabBar *getTabBar() const
121 { 121 {
122 return ((EKNumTabBar*)tabBar()); 122 return ((EKNumTabBar*)tabBar());
123 } 123 }
124 124
125 125
126 void addTab(QWidget* w) 126 void addTab(QWidget* w)
127 { 127 {
128 QTab* t = new QTab(QString::number(tabBar()->count()+1)); 128 QTab* t = new QTab(QString::number(tabBar()->count()+1));
129 QTabWidget::addTab(w,t); 129 QTabWidget::addTab(w,t);
130 } 130 }
131 131
132 void removeTab(QWidget* w) 132 void removeTab(QWidget* w)
133 { 133 {
134 removePage(w); 134 removePage(w);
135 ((EKNumTabBar*)tabBar())->numberTabs(); 135 ((EKNumTabBar*)tabBar())->numberTabs();
136 } 136 }
137}; 137};
138 138
139// This could be configurable or dynamicly generated from the bash history 139// This could be configurable or dynamicly generated from the bash history
140// file of the user 140// file of the user
141static const char *commonCmds[] = 141static const char *commonCmds[] =
142 { 142 {
143 "ls ", // I left this here, cause it looks better than the first alpha 143 "ls ", // I left this here, cause it looks better than the first alpha
144 "cardctl eject", 144 "cardctl eject",
145 "cat ", 145 "cat ",
146 "cd ", 146 "cd ",
147 "chmod ", 147 "chmod ",
148 "clear", 148 "clear",
149 "cp ", 149 "cp ",
150 "dc ", 150 "dc ",
151 "df ", 151 "df ",
152 "dmesg", 152 "dmesg",
153 "echo ", 153 "echo ",
154 "env", 154 "env",
155 "find ", 155 "find ",
156 "free", 156 "free",
157 "grep ", 157 "grep ",
158 "ifconfig ", 158 "ifconfig ",
159 "ipkg ", 159 "ipkg ",
160 "mkdir ", 160 "mkdir ",
161 "mv ", 161 "mv ",
162 "nc localhost 7776", 162 "nc localhost 7776",
163 "nc localhost 7777", 163 "nc localhost 7777",
164 "netstat ", 164 "netstat ",
165 "nslookup ", 165 "nslookup ",
166 "ping ", 166 "ping ",
167 "ps aux", 167 "ps aux",
168 "pwd ", 168 "pwd ",
169// "qcop QPE/System 'linkChanged(QString)' ''", 169// "qcop QPE/System 'linkChanged(QString)' ''",
170// "qcop QPE/System 'restart()'", 170// "qcop QPE/System 'restart()'",
171// "qcop QPE/System 'quit()'", 171// "qcop QPE/System 'quit()'",
172 "rm ", 172 "rm ",
173 "rmdir ", 173 "rmdir ",
174 "route ", 174 "route ",
175 "set ", 175 "set ",
176 "traceroute", 176 "traceroute",
177 177
178 /* 178 /*
179 "gzip", 179 "gzip",
180 "gunzip", 180 "gunzip",
181 "chgrp", 181 "chgrp",
182 "chown", 182 "chown",
183 "date", 183 "date",
184 "dd", 184 "dd",
185 "df", 185 "df",
186 "dmesg", 186 "dmesg",
187 "fuser", 187 "fuser",
188 "hostname", 188 "hostname",
189 "kill", 189 "kill",
190 "killall", 190 "killall",
191 "ln", 191 "ln",
192 "ping", 192 "ping",
193 "mount", 193 "mount",
194 "more", 194 "more",
195 "sort", 195 "sort",
196 "touch", 196 "touch",
197 "umount", 197 "umount",
198 "mknod", 198 "mknod",
199 "netstat", 199 "netstat",
200 */ 200 */
201 201
202 "exit", 202 "exit",
203 NULL 203 NULL
204 }; 204 };
205 205
206 206
207static void konsoleInit(const char** shell) { 207static void konsoleInit(const char** shell) {
208 if(setuid(getuid()) !=0) odebug << "setuid failed" << oendl; 208 if(setuid(getuid()) !=0) odebug << "setuid failed" << oendl;
209 if(setgid(getgid()) != 0) odebug << "setgid failed" << oendl; // drop privileges 209 if(setgid(getgid()) != 0) odebug << "setgid failed" << oendl; // drop privileges
210 210
211 211
212// QPEApplication::grabKeyboard(); // for CTRL and ALT 212// QPEApplication::grabKeyboard(); // for CTRL and ALT
213 213
214 odebug << "keyboard grabbed" << oendl; 214 odebug << "keyboard grabbed" << oendl;
215#ifdef FAKE_CTRL_AND_ALT 215#ifdef FAKE_CTRL_AND_ALT
216 odebug << "Fake Ctrl and Alt defined" << oendl; 216 odebug << "Fake Ctrl and Alt defined" << oendl;
217 QPEApplication::grabKeyboard(); // for CTRL and ALT 217 QPEApplication::grabKeyboard(); // for CTRL and ALT
218#endif 218#endif
219 219
220 if (!shell) {
221 owarn << "No double pointer 'shell'" << oendl;
222 return;
223 }
224
220 *shell = getenv("SHELL"); 225 *shell = getenv("SHELL");
221 owarn << "SHell initially is " << *shell << "" << oendl; 226 if (*shell)
227 owarn << "Current shell: " << *shell << "" << oendl;
222 228
223 if (shell == NULL || *shell == '\0') { 229 if (*shell == NULL || **shell == '\0') {
224 struct passwd *ent = 0; 230 struct passwd *ent = 0;
225 uid_t me = getuid(); 231 uid_t me = getuid();
226 *shell = "/bin/sh"; 232 *shell = "/bin/sh";
227 233
228 while ( (ent = getpwent()) != 0 ) { 234 while ( (ent = getpwent()) != 0 ) {
229 if (ent->pw_uid == me) { 235 if (ent->pw_uid == me) {
230 if (ent->pw_shell != "") 236 if (ent->pw_shell != "")
231 *shell = ent->pw_shell; 237 *shell = ent->pw_shell;
232 break; 238 break;
233 } 239 }
234 } 240 }
235 endpwent(); 241 endpwent();
236 } 242 }
237 243
238 if( putenv((char*)"COLORTERM=") !=0) 244 if( putenv((char*)"COLORTERM=") !=0)
239 odebug << "putenv failed" << oendl; // to trigger mc's color detection 245 odebug << "putenv failed" << oendl; // to trigger mc's color detection
240} 246}
241 247
242 248
243Konsole::Konsole(QWidget* parent, const char* name, WFlags fl) : 249Konsole::Konsole(QWidget* parent, const char* name, WFlags fl) :
244 QMainWindow(parent, name, fl) 250 QMainWindow(parent, name, fl)
245{ 251{
246 QStrList tmp; const char* shell; 252 QStrList tmp; const char* shell;
247 253
248 konsoleInit( &shell); 254 konsoleInit( &shell);
249 init(shell,tmp); 255 init(shell,tmp);
250} 256}
251 257
252Konsole::Konsole(const char* name, const char* _pgm, QStrList & _args, int) 258Konsole::Konsole(const char* name, const char* _pgm, QStrList & _args, int)
253 : QMainWindow(0, name) 259 : QMainWindow(0, name)
254{ 260{
255 init(_pgm,_args); 261 init(_pgm,_args);
256} 262}
257 263
258struct HistoryItem 264struct HistoryItem
259{ 265{
260 HistoryItem(int c, const QString &l) 266 HistoryItem(int c, const QString &l)
261 { 267 {
262 count = c; 268 count = c;
263 line = l; 269 line = l;
264 } 270 }
265 int count; 271 int count;
266 QString line; 272 QString line;
267}; 273};
268 274
269class HistoryList : public QList<HistoryItem> 275class HistoryList : public QList<HistoryItem>
270{ 276{
271 virtual int compareItems( QCollection::Item item1, QCollection::Item item2) 277 virtual int compareItems( QCollection::Item item1, QCollection::Item item2)
272 { 278 {
273 int c1 = ((HistoryItem*)item1)->count; 279 int c1 = ((HistoryItem*)item1)->count;
274 int c2 = ((HistoryItem*)item2)->count; 280 int c2 = ((HistoryItem*)item2)->count;
275 if (c1 > c2) 281 if (c1 > c2)
276 return(1); 282 return(1);
277 if (c1 < c2) 283 if (c1 < c2)
278 return(-1); 284 return(-1);
279 return(0); 285 return(0);
280 } 286 }
281}; 287};
282 288
283void Konsole::initCommandList() 289void Konsole::initCommandList()
284{ 290{
285 // odebug << "Konsole::initCommandList" << oendl; 291 // odebug << "Konsole::initCommandList" << oendl;
286 Config cfg( "Konsole" ); 292 Config cfg( "Konsole" );
287 cfg.setGroup("Commands"); 293 cfg.setGroup("Commands");
288 // commonCombo->setInsertionPolicy(QComboBox::AtCurrent); 294 // commonCombo->setInsertionPolicy(QComboBox::AtCurrent);
289 commonCombo->clear(); 295 commonCombo->clear();
290 296
291 if (cfg.readEntry("ShellHistory","TRUE") == "FALSE") { 297 if (cfg.readEntry("ShellHistory","TRUE") == "FALSE") {
292 QString histfilename = QString(getenv("HOME")) + "/.bash_history"; 298 QString histfilename = QString(getenv("HOME")) + "/.bash_history";
293 histfilename = cfg.readEntry("ShellHistoryPath",histfilename); 299 histfilename = cfg.readEntry("ShellHistoryPath",histfilename);
294 QFile histfile(histfilename); 300 QFile histfile(histfilename);
295 // note: compiler barfed on: 301 // note: compiler barfed on:
296 // QFile histfile(QString(getenv("HOME")) + "/.bash_history"); 302 // QFile histfile(QString(getenv("HOME")) + "/.bash_history");
297 if (histfile.open( IO_ReadOnly )) { 303 if (histfile.open( IO_ReadOnly )) {
298 QString line; 304 QString line;
299 uint i; 305 uint i;
300 HistoryList items; 306 HistoryList items;
301 307
302 int lineno = 0; 308 int lineno = 0;
303 while(!histfile.atEnd()) { 309 while(!histfile.atEnd()) {
304 if (histfile.readLine(line, 200) < 0) { 310 if (histfile.readLine(line, 200) < 0) {
305 break; 311 break;
306 } 312 }
307 line = line.left(line.length()-1); 313 line = line.left(line.length()-1);
308 lineno++; 314 lineno++;
309 315
310 for(i=0; i<items.count(); i++) { 316 for(i=0; i<items.count(); i++) {
311 if (line == items.at(i)->line) { 317 if (line == items.at(i)->line) {
312 // weight recent commands & repeated commands more 318 // weight recent commands & repeated commands more
313 // by adding up the index of each command 319 // by adding up the index of each command
314 items.at(i)->count += lineno; 320 items.at(i)->count += lineno;
315 break; 321 break;
316 } 322 }
317 } 323 }
318 if (i >= items.count()) { 324 if (i >= items.count()) {
319 items.append(new HistoryItem(lineno, line)); 325 items.append(new HistoryItem(lineno, line));
320 } 326 }
321 } 327 }
322 items.sort(); 328 items.sort();
323 int n = items.count(); 329 int n = items.count();
324 if (n > 40) { 330 if (n > 40) {
325 n = 40; 331 n = 40;
326 } 332 }
327 for(int i=0; i<n; i++) { 333 for(int i=0; i<n; i++) {
328 // should insert start of command, but keep whole thing 334 // should insert start of command, but keep whole thing
329 if (items.at(items.count()-i-1)->line.length() < 30) { 335 if (items.at(items.count()-i-1)->line.length() < 30) {
330 commonCombo->insertItem(items.at(items.count()-i-1)->line); 336 commonCombo->insertItem(items.at(items.count()-i-1)->line);
331 } 337 }
332 } 338 }
333 histfile.close(); 339 histfile.close();
334 } 340 }
335 } 341 }
336 if (cfg.readEntry("Commands Set","FALSE") == "FALSE") { 342 if (cfg.readEntry("Commands Set","FALSE") == "FALSE") {
337 for (int i = 0; commonCmds[i] != NULL; i++) { 343 for (int i = 0; commonCmds[i] != NULL; i++) {
338 commonCombo->insertItem(commonCmds[i]); 344 commonCombo->insertItem(commonCmds[i]);
339 } 345 }
340 } else { 346 } else {
341 for (int i = 0; i < 100; i++) { 347 for (int i = 0; i < 100; i++) {
342 if (!(cfg.readEntry( QString::number(i),"")).isEmpty()) 348 if (!(cfg.readEntry( QString::number(i),"")).isEmpty())
343 commonCombo->insertItem(cfg.readEntry( QString::number(i),"")); 349 commonCombo->insertItem(cfg.readEntry( QString::number(i),""));
344 } 350 }
345 } 351 }
346 352
347 353
348} 354}
349 355
350static void sig_handler(int x) 356static void sig_handler(int x)
351{ 357{
352 printf("got signal %d\n",x); 358 printf("got signal %d\n",x);
353} 359}
354 360
355void Konsole::init(const char* _pgm, QStrList & _args) 361void Konsole::init(const char* _pgm, QStrList & _args)
356{ 362{
357 363
358#if 0 364#if 0
359 for(int i=1; i<=31; i++) 365 for(int i=1; i<=31; i++)
360 { 366 {
361 if (i != SIGPIPE && i != SIGPROF && i != SIGSEGV 367 if (i != SIGPIPE && i != SIGPROF && i != SIGSEGV
362 && i != SIGINT && i != SIGILL && i != SIGTERM 368 && i != SIGINT && i != SIGILL && i != SIGTERM
363 && i != SIGBUS) 369 && i != SIGBUS)
364 signal(i,sig_handler); 370 signal(i,sig_handler);
365 } 371 }
366#endif 372#endif
367 signal(SIGSTOP, sig_handler); 373 signal(SIGSTOP, sig_handler);
368 signal(SIGCONT, sig_handler); 374 signal(SIGCONT, sig_handler);
369 signal(SIGTSTP, sig_handler); 375 signal(SIGTSTP, sig_handler);
370 376
371 b_scroll = TRUE; // histon; 377 b_scroll = TRUE; // histon;
372 n_keytab = 0; 378 n_keytab = 0;
373 n_render = 0; 379 n_render = 0;
374 startUp=0; 380 startUp=0;
375 fromMenu = FALSE; 381 fromMenu = FALSE;
376 fullscreen = false; 382 fullscreen = false;
377 383
378 setCaption( tr( "Konsole" ) ); 384 setCaption( tr( "Konsole" ) );
379 setIcon( Opie::Core::OResource::loadPixmap( "konsole/Terminal", Opie::Core::OResource::SmallIcon ) ); 385 setIcon( Opie::Core::OResource::loadPixmap( "konsole/Terminal", Opie::Core::OResource::SmallIcon ) );
380 386
381 Config cfg( "Konsole" ); 387 Config cfg( "Konsole" );
382 cfg.setGroup("Font"); 388 cfg.setGroup("Font");
383 QString tmp; 389 QString tmp;
384 390
385 // initialize the list of allowed fonts /////////////////////////////////// 391 // initialize the list of allowed fonts ///////////////////////////////////
386 392
387 QString cfgFontName = cfg.readEntry("FontName","Lcfont"); 393 QString cfgFontName = cfg.readEntry("FontName","Lcfont");
388 int cfgFontSize = cfg.readNumEntry("FontSize",18); 394 int cfgFontSize = cfg.readNumEntry("FontSize",18);
389 395
390 cfont = -1; 396 cfont = -1;
391 397
392 // this code causes repeated access to all the font files 398 // this code causes repeated access to all the font files
393 // which does slow down startup 399 // which does slow down startup
394 QFontDatabase fontDB; 400 QFontDatabase fontDB;
395 QStringList familyNames; 401 QStringList familyNames;
396 familyNames = fontDB.families( FALSE ); 402 familyNames = fontDB.families( FALSE );
397 QString s; 403 QString s;
398 int fontIndex = 0; 404 int fontIndex = 0;
399 int familyNum = 0; 405 int familyNum = 0;
400 fontList = new QPopupMenu( this ); 406 fontList = new QPopupMenu( this );
401 407
402 for(uint j = 0; j < (uint)familyNames.count(); j++) 408 for(uint j = 0; j < (uint)familyNames.count(); j++)
403 { 409 {
404 s = familyNames[j]; 410 s = familyNames[j];
405 if ( s.contains('-') ) 411 if ( s.contains('-') )
406 { 412 {
407 int i = s.find('-'); 413 int i = s.find('-');
408 s = s.right( s.length() - i - 1 ) + " [" + s.left( i ) + "]"; 414 s = s.right( s.length() - i - 1 ) + " [" + s.left( i ) + "]";
409 } 415 }
410 s[0] = s[0].upper(); 416 s[0] = s[0].upper();
411 417
412 QValueList<int> sizes = fontDB.pointSizes( familyNames[j] ); 418 QValueList<int> sizes = fontDB.pointSizes( familyNames[j] );
413 419
414 printf("family[%d] = %s with %d sizes\n", j, familyNames[j].latin1(), 420 printf("family[%d] = %s with %d sizes\n", j, familyNames[j].latin1(),
415 sizes.count()); 421 sizes.count());
416 422
417 if (sizes.count() > 0) 423 if (sizes.count() > 0)
418 { 424 {
419 QPopupMenu *sizeMenu; 425 QPopupMenu *sizeMenu;
420 QFont f; 426 QFont f;
421 int last_width = -1; 427 int last_width = -1;
422 sizeMenu = NULL; 428 sizeMenu = NULL;
423 429
424 for(uint i = 0; i < (uint)sizes.count() + 4; i++) 430 for(uint i = 0; i < (uint)sizes.count() + 4; i++)
425 { 431 {
426 // printf("family %s size %d ", familyNames[j].latin1(), sizes[i]); 432 // printf("family %s size %d ", familyNames[j].latin1(), sizes[i]);
427 // need to divide by 10 on the Z, but not otherwise 433 // need to divide by 10 on the Z, but not otherwise
428 int size; 434 int size;
429 435
430 if (i >= (uint)sizes.count()) 436 if (i >= (uint)sizes.count())
431 { 437 {
432 // try for expandable fonts 438 // try for expandable fonts
433 size = sizes[sizes.count()-1] + 2 * (i - sizes.count() + 1); 439 size = sizes[sizes.count()-1] + 2 * (i - sizes.count() + 1);
434 } 440 }
435 else 441 else
436 { 442 {
437 printf("sizes[%d] = %d\n", i, sizes[i]); 443 printf("sizes[%d] = %d\n", i, sizes[i]);
438 size = sizes[i]; 444 size = sizes[i];
439 } 445 }
440 446
441 f = QFont(familyNames[j], size); 447 f = QFont(familyNames[j], size);
442 f.setFixedPitch(true); 448 f.setFixedPitch(true);
443 QFontMetrics fm(f); 449 QFontMetrics fm(f);
444 // don't trust f.fixedPitch() or f.exactMatch(), they lie!! 450 // don't trust f.fixedPitch() or f.exactMatch(), they lie!!
445 if (fm.width("l") == fm.width("m") 451 if (fm.width("l") == fm.width("m")
446 && (i < (uint)sizes.count() 452 && (i < (uint)sizes.count()
447 || fm.width("m") > last_width)) 453 || fm.width("m") > last_width))
448 { 454 {
449 if (i < (uint)sizes.count()) 455 if (i < (uint)sizes.count())
450 { 456 {
451 last_width = fm.width("m"); 457 last_width = fm.width("m");
452 } 458 }
453 if (sizeMenu == NULL) 459 if (sizeMenu == NULL)
454 { 460 {
455 sizeMenu = new QPopupMenu(); 461 sizeMenu = new QPopupMenu();
456 } 462 }
457 int id = sizeMenu->insertItem(QString("%1").arg(size), fontIndex); 463 int id = sizeMenu->insertItem(QString("%1").arg(size), fontIndex);
458 sizeMenu->setItemParameter(id, fontIndex); 464 sizeMenu->setItemParameter(id, fontIndex);
459 sizeMenu->connectItem(id, this, SLOT(setFont(int))); 465 sizeMenu->connectItem(id, this, SLOT(setFont(int)));
460 QString name = s + " " + QString::number(size); 466 QString name = s + " " + QString::number(size);
461 fonts.append(new VTFont(name, f, familyNames[j], familyNum, size)); 467 fonts.append(new VTFont(name, f, familyNames[j], familyNum, size));
462 if (familyNames[j] == cfgFontName && size == cfgFontSize) 468 if (familyNames[j] == cfgFontName && size == cfgFontSize)
463 { 469 {
464 cfont = fontIndex; 470 cfont = fontIndex;
465 } 471 }
466 printf("FOUND: %s family %s size %d\n", name.latin1(), familyNames[j].latin1(), size); 472 printf("FOUND: %s family %s size %d\n", name.latin1(), familyNames[j].latin1(), size);
467 fontIndex++; 473 fontIndex++;
468 } 474 }
469 } 475 }
470 if (sizeMenu) 476 if (sizeMenu)
471 { 477 {
472 fontList->insertItem(s, sizeMenu, familyNum + 1000); 478 fontList->insertItem(s, sizeMenu, familyNum + 1000);
473 479
474 familyNum++; 480 familyNum++;
475 } 481 }
476 } 482 }
477 483
478 } 484 }
479 485
480 if (cfont < 0 || cfont >= (int)fonts.count()) 486 if (cfont < 0 || cfont >= (int)fonts.count())
481 { 487 {
482 cfont = 0; 488 cfont = 0;
483 } 489 }
484 490
485 // create terminal emulation framework //////////////////////////////////// 491 // create terminal emulation framework ////////////////////////////////////
486 nsessions = 0; 492 nsessions = 0;
487 493
488 tab = new EKNumTabWidget(this); 494 tab = new EKNumTabWidget(this);
489 // tab->setMargin(tab->margin()-5); 495 // tab->setMargin(tab->margin()-5);
490 connect(tab, SIGNAL(currentChanged(QWidget*)), this, SLOT(switchSession(QWidget*))); 496 connect(tab, SIGNAL(currentChanged(QWidget*)), this, SLOT(switchSession(QWidget*)));
491 497
492 // create terminal toolbar //////////////////////////////////////////////// 498 // create terminal toolbar ////////////////////////////////////////////////
493 setToolBarsMovable( FALSE ); 499 setToolBarsMovable( FALSE );
494 menuToolBar = new QToolBar( this ); 500 menuToolBar = new QToolBar( this );
495 menuToolBar->setHorizontalStretchable( TRUE ); 501 menuToolBar->setHorizontalStretchable( TRUE );
496 502
497 QMenuBar *menuBar = new QMenuBar( menuToolBar ); 503 QMenuBar *menuBar = new QMenuBar( menuToolBar );
498 504
499 setFont(cfont); 505 setFont(cfont);
500 506
501 configMenu = new QPopupMenu( this); 507 configMenu = new QPopupMenu( this);
502 colorMenu = new QPopupMenu( this); 508 colorMenu = new QPopupMenu( this);
503 scrollMenu = new QPopupMenu( this); 509 scrollMenu = new QPopupMenu( this);
504 editCommandListMenu = new QPopupMenu( this); 510 editCommandListMenu = new QPopupMenu( this);
505 511
506 configMenu->insertItem(tr("Command List"), editCommandListMenu); 512 configMenu->insertItem(tr("Command List"), editCommandListMenu);
507 513
508 bool listHidden; 514 bool listHidden;
509 cfg.setGroup("Menubar"); 515 cfg.setGroup("Menubar");
510 if( cfg.readEntry("Hidden","FALSE") == "TRUE") 516 if( cfg.readEntry("Hidden","FALSE") == "TRUE")
511 { 517 {
512 ec_cmdlist = editCommandListMenu->insertItem( tr( "Show command list" )); 518 ec_cmdlist = editCommandListMenu->insertItem( tr( "Show command list" ));
513 listHidden=TRUE; 519 listHidden=TRUE;
514 } 520 }
515 else 521 else
516 { 522 {
517 ec_cmdlist = editCommandListMenu->insertItem( tr( "Hide command list" )); 523 ec_cmdlist = editCommandListMenu->insertItem( tr( "Hide command list" ));
518 listHidden=FALSE; 524 listHidden=FALSE;
519 } 525 }
520 526
521 cfg.setGroup("Tabs"); 527 cfg.setGroup("Tabs");
522 528
523 tabMenu = new QPopupMenu(this); 529 tabMenu = new QPopupMenu(this);
524 tm_bottom = tabMenu->insertItem(tr("Bottom" )); 530 tm_bottom = tabMenu->insertItem(tr("Bottom" ));
525 tm_top = tabMenu->insertItem(tr("Top")); 531 tm_top = tabMenu->insertItem(tr("Top"));
526 tm_hidden = tabMenu->insertItem(tr("Hidden")); 532 tm_hidden = tabMenu->insertItem(tr("Hidden"));
527 533
528 configMenu->insertItem(tr("Tabs"), tabMenu); 534 configMenu->insertItem(tr("Tabs"), tabMenu);
529 535
530 tmp=cfg.readEntry("Position","Top"); 536 tmp=cfg.readEntry("Position","Top");
531 if(tmp=="Top") 537 if(tmp=="Top")
532 { 538 {
533 tab->setTabPosition(QTabWidget::Top); 539 tab->setTabPosition(QTabWidget::Top);
534 tab->getTabBar()->show(); 540 tab->getTabBar()->show();
535 tabPos = tm_top; 541 tabPos = tm_top;
536 } 542 }
537 else if (tmp=="Bottom") 543 else if (tmp=="Bottom")
538 { 544 {
539 tab->setTabPosition(QTabWidget::Bottom); 545 tab->setTabPosition(QTabWidget::Bottom);
540 tab->getTabBar()->show(); 546 tab->getTabBar()->show();
541 tabPos = tm_bottom; 547 tabPos = tm_bottom;
542 } 548 }
543 else 549 else
544 { 550 {
545 tab->getTabBar()->hide(); 551 tab->getTabBar()->hide();
546 tab->setMargin(tab->margin()); 552 tab->setMargin(tab->margin());
547 tabPos = tm_hidden; 553 tabPos = tm_hidden;
548 } 554 }
549 555
550 cm_bw = colorMenu->insertItem(tr( "Black on White")); 556 cm_bw = colorMenu->insertItem(tr( "Black on White"));
551 cm_wb = colorMenu->insertItem(tr( "White on Black")); 557 cm_wb = colorMenu->insertItem(tr( "White on Black"));
552 cm_gb = colorMenu->insertItem(tr( "Green on Black")); 558 cm_gb = colorMenu->insertItem(tr( "Green on Black"));
553 // cm_bt = colorMenu->insertItem(tr( "Black on Transparent")); 559 // cm_bt = colorMenu->insertItem(tr( "Black on Transparent"));
554 cm_br = colorMenu->insertItem(tr( "Black on Pink")); 560 cm_br = colorMenu->insertItem(tr( "Black on Pink"));
555 cm_rb = colorMenu->insertItem(tr( "Pink on Black")); 561 cm_rb = colorMenu->insertItem(tr( "Pink on Black"));
556 cm_gy = colorMenu->insertItem(tr( "Green on Yellow")); 562 cm_gy = colorMenu->insertItem(tr( "Green on Yellow"));
557 cm_bm = colorMenu->insertItem(tr( "Blue on Magenta")); 563 cm_bm = colorMenu->insertItem(tr( "Blue on Magenta"));
558 cm_mb = colorMenu->insertItem(tr( "Magenta on Blue")); 564 cm_mb = colorMenu->insertItem(tr( "Magenta on Blue"));
559 cm_cw = colorMenu->insertItem(tr( "Cyan on White")); 565 cm_cw = colorMenu->insertItem(tr( "Cyan on White"));
560 cm_wc = colorMenu->insertItem(tr( "White on Cyan")); 566 cm_wc = colorMenu->insertItem(tr( "White on Cyan"));
561 cm_bb = colorMenu->insertItem(tr( "Blue on Black")); 567 cm_bb = colorMenu->insertItem(tr( "Blue on Black"));
562 cm_ab = colorMenu->insertItem(tr( "Amber on Black")); 568 cm_ab = colorMenu->insertItem(tr( "Amber on Black"));
563 cm_default = colorMenu->insertItem(tr("default")); 569 cm_default = colorMenu->insertItem(tr("default"));
564 570
565#ifdef QT_QWS_OPIE 571#ifdef QT_QWS_OPIE
566 572
567 colorMenu->insertItem(tr( "Custom")); 573 colorMenu->insertItem(tr( "Custom"));
568#endif 574#endif
569 575
570 configMenu->insertItem(tr( "Colors") ,colorMenu); 576 configMenu->insertItem(tr( "Colors") ,colorMenu);
571 577
572 sessionList = new QPopupMenu(this); 578 sessionList = new QPopupMenu(this);
573 sessionList-> insertItem ( Opie::Core::OResource::loadPixmap( "konsole/Terminal", Opie::Core::OResource::SmallIcon ), 579 sessionList-> insertItem ( Opie::Core::OResource::loadPixmap( "konsole/Terminal", Opie::Core::OResource::SmallIcon ),
574 tr( "new session" ), this, SLOT(newSession()) ); 580 tr( "new session" ), this, SLOT(newSession()) );
575 581
576 // connect( fontList, SIGNAL( activated(int) ), this, SLOT( fontChanged(int) )); 582 // connect( fontList, SIGNAL( activated(int) ), this, SLOT( fontChanged(int) ));
577 connect( configMenu, SIGNAL( activated(int) ), this, SLOT( configMenuSelected(int) )); 583 connect( configMenu, SIGNAL( activated(int) ), this, SLOT( configMenuSelected(int) ));
578 connect( colorMenu, SIGNAL( activated(int) ), this, SLOT( colorMenuIsSelected(int) )); 584 connect( colorMenu, SIGNAL( activated(int) ), this, SLOT( colorMenuIsSelected(int) ));
579 connect( tabMenu, SIGNAL( activated(int) ), this, SLOT( tabMenuSelected(int) )); 585 connect( tabMenu, SIGNAL( activated(int) ), this, SLOT( tabMenuSelected(int) ));
580 connect( scrollMenu, SIGNAL(activated(int)),this,SLOT(scrollMenuSelected(int))); 586 connect( scrollMenu, SIGNAL(activated(int)),this,SLOT(scrollMenuSelected(int)));
581 connect( editCommandListMenu,SIGNAL(activated(int)),this,SLOT(editCommandListMenuSelected(int))); 587 connect( editCommandListMenu,SIGNAL(activated(int)),this,SLOT(editCommandListMenuSelected(int)));
582 connect( sessionList, SIGNAL(activated(int)), this, SLOT( sessionListSelected(int) ) ); 588 connect( sessionList, SIGNAL(activated(int)), this, SLOT( sessionListSelected(int) ) );
583 589
584 menuBar->insertItem( tr("View"), configMenu ); 590 menuBar->insertItem( tr("View"), configMenu );
585 menuBar->insertItem( tr("Fonts"), fontList ); 591 menuBar->insertItem( tr("Fonts"), fontList );
586 menuBar->insertItem( tr("Sessions"), sessionList ); 592 menuBar->insertItem( tr("Sessions"), sessionList );
587 593
588 toolBar = new QToolBar( this ); 594 toolBar = new QToolBar( this );
589 595
590 QAction *a; 596 QAction *a;
591 597
592 // Button Commands 598 // Button Commands
593 a = new QAction( tr("New"), Opie::Core::OResource::loadPixmap( "konsole/konsole", Opie::Core::OResource::SmallIcon ), 599 a = new QAction( tr("New"), Opie::Core::OResource::loadPixmap( "konsole/konsole", Opie::Core::OResource::SmallIcon ),
594 QString::null, 0, this, 0 ); 600 QString::null, 0, this, 0 );
595 connect( a, SIGNAL( activated() ), this, SLOT( newSession() ) ); 601 connect( a, SIGNAL( activated() ), this, SLOT( newSession() ) );
596 a->addTo( toolBar ); 602 a->addTo( toolBar );
597 603
598 a = new QAction( tr("Full Screen"), Opie::Core::OResource::loadPixmap( "fullscreen", Opie::Core::OResource::SmallIcon ), 604 a = new QAction( tr("Full Screen"), Opie::Core::OResource::loadPixmap( "fullscreen", Opie::Core::OResource::SmallIcon ),
599 QString::null, 0, this, 0 ); 605 QString::null, 0, this, 0 );
600 connect( a, SIGNAL( activated() ), this, SLOT( toggleFullScreen() ) ); 606 connect( a, SIGNAL( activated() ), this, SLOT( toggleFullScreen() ) );
601 a->addTo( toolBar ); 607 a->addTo( toolBar );
602 608
603 a = new QAction( tr("Zoom"), Opie::Core::OResource::loadPixmap( "zoom", Opie::Core::OResource::SmallIcon ), 609 a = new QAction( tr("Zoom"), Opie::Core::OResource::loadPixmap( "zoom", Opie::Core::OResource::SmallIcon ),
604 QString::null, 0, this, 0 ); 610 QString::null, 0, this, 0 );
605 connect( a, SIGNAL( activated() ), this, SLOT( cycleZoom() ) ); 611 connect( a, SIGNAL( activated() ), this, SLOT( cycleZoom() ) );
606 a->addTo( toolBar ); 612 a->addTo( toolBar );
607 613
608 614
609 a = new QAction( tr("Enter"), Opie::Core::OResource::loadPixmap( "konsole/enter", Opie::Core::OResource::SmallIcon ), 615 a = new QAction( tr("Enter"), Opie::Core::OResource::loadPixmap( "konsole/enter", Opie::Core::OResource::SmallIcon ),
610 QString::null, 0, this, 0 ); 616 QString::null, 0, this, 0 );
611 connect( a, SIGNAL( activated() ), this, SLOT( hitEnter() ) ); a->addTo( toolBar ); 617 connect( a, SIGNAL( activated() ), this, SLOT( hitEnter() ) ); a->addTo( toolBar );
612 a = new QAction( tr("Space"), Opie::Core::OResource::loadPixmap( "konsole/space", Opie::Core::OResource::SmallIcon ), 618 a = new QAction( tr("Space"), Opie::Core::OResource::loadPixmap( "konsole/space", Opie::Core::OResource::SmallIcon ),
613 QString::null, 0, this, 0 ); 619 QString::null, 0, this, 0 );
614 connect( a, SIGNAL( activated() ), this, SLOT( hitSpace() ) ); a->addTo( toolBar ); 620 connect( a, SIGNAL( activated() ), this, SLOT( hitSpace() ) ); a->addTo( toolBar );
615 a = new QAction( tr("Tab"), Opie::Core::OResource::loadPixmap( "konsole/tab", Opie::Core::OResource::SmallIcon ), 621 a = new QAction( tr("Tab"), Opie::Core::OResource::loadPixmap( "konsole/tab", Opie::Core::OResource::SmallIcon ),
616 QString::null, 0, this, 0 ); 622 QString::null, 0, this, 0 );
617 connect( a, SIGNAL( activated() ), this, SLOT( hitTab() ) ); a->addTo( toolBar ); 623 connect( a, SIGNAL( activated() ), this, SLOT( hitTab() ) ); a->addTo( toolBar );
618 a = new QAction( tr("Up"), Opie::Core::OResource::loadPixmap( "konsole/up", Opie::Core::OResource::SmallIcon ), 624 a = new QAction( tr("Up"), Opie::Core::OResource::loadPixmap( "konsole/up", Opie::Core::OResource::SmallIcon ),
619 QString::null, 0, this, 0 ); 625 QString::null, 0, this, 0 );
620 connect( a, SIGNAL( activated() ), this, SLOT( hitUp() ) ); a->addTo( toolBar ); 626 connect( a, SIGNAL( activated() ), this, SLOT( hitUp() ) ); a->addTo( toolBar );
621 a = new QAction( tr("Down"), Opie::Core::OResource::loadPixmap( "konsole/down", Opie::Core::OResource::SmallIcon ), 627 a = new QAction( tr("Down"), Opie::Core::OResource::loadPixmap( "konsole/down", Opie::Core::OResource::SmallIcon ),
622 QString::null, 0, this, 0 ); 628 QString::null, 0, this, 0 );
623 connect( a, SIGNAL( activated() ), this, SLOT( hitDown() ) ); a->addTo( toolBar ); 629 connect( a, SIGNAL( activated() ), this, SLOT( hitDown() ) ); a->addTo( toolBar );
624 630
625 a = new QAction( tr("Paste"), Opie::Core::OResource::loadPixmap( "paste", Opie::Core::OResource::SmallIcon ), QString::null, 0, this, 0 ); 631 a = new QAction( tr("Paste"), Opie::Core::OResource::loadPixmap( "paste", Opie::Core::OResource::SmallIcon ), QString::null, 0, this, 0 );
626 connect( a, SIGNAL( activated() ), this, SLOT( hitPaste() ) ); 632 connect( a, SIGNAL( activated() ), this, SLOT( hitPaste() ) );
627 633
628 a = new QAction( tr("Close"), Opie::Core::OResource::loadPixmap( "close", Opie::Core::OResource::SmallIcon ),QString::null, 0, this, 0 ); 634 a = new QAction( tr("Close"), Opie::Core::OResource::loadPixmap( "close", Opie::Core::OResource::SmallIcon ),QString::null, 0, this, 0 );
629 connect( a, SIGNAL( activated() ), this, SLOT( closeSession() ) ); 635 connect( a, SIGNAL( activated() ), this, SLOT( closeSession() ) );
630 636
631 a->addTo( toolBar ); 637 a->addTo( toolBar );
632 638
633 secondToolBar = new QToolBar( this ); 639 secondToolBar = new QToolBar( this );
634 secondToolBar->setHorizontalStretchable( TRUE ); 640 secondToolBar->setHorizontalStretchable( TRUE );
635 641
636 commonCombo = new QComboBox( secondToolBar ); 642 commonCombo = new QComboBox( secondToolBar );
637 // commonCombo->setMaximumWidth(236); 643 // commonCombo->setMaximumWidth(236);
638 644
639 ec_quick = editCommandListMenu->insertItem( tr( "Quick Edit" ) ); 645 ec_quick = editCommandListMenu->insertItem( tr( "Quick Edit" ) );
640 if( listHidden) 646 if( listHidden)
641 { 647 {
642 secondToolBar->hide(); 648 secondToolBar->hide();
643 editCommandListMenu->setItemEnabled(ec_quick ,FALSE); 649 editCommandListMenu->setItemEnabled(ec_quick ,FALSE);
644 } 650 }
645 ec_edit = editCommandListMenu->insertItem(tr( "Edit..." ) ); 651 ec_edit = editCommandListMenu->insertItem(tr( "Edit..." ) );
646 652
647 cfg.setGroup("Commands"); 653 cfg.setGroup("Commands");
648 commonCombo->setInsertionPolicy(QComboBox::AtCurrent); 654 commonCombo->setInsertionPolicy(QComboBox::AtCurrent);
649 655
650 initCommandList(); 656 initCommandList();
651 // for (int i = 0; commonCmds[i] != NULL; i++) { 657 // for (int i = 0; commonCmds[i] != NULL; i++) {
652 // commonCombo->insertItem( commonCmds[i], i ); 658 // commonCombo->insertItem( commonCmds[i], i );
653 // tmp = cfg.readEntry( QString::number(i),""); 659 // tmp = cfg.readEntry( QString::number(i),"");
654 // if(tmp != "") 660 // if(tmp != "")
655 // commonCombo->changeItem( tmp,i ); 661 // commonCombo->changeItem( tmp,i );
656 // } 662 // }
657 663
658 connect( commonCombo, SIGNAL( activated(int) ), this, SLOT( enterCommand(int) )); 664 connect( commonCombo, SIGNAL( activated(int) ), this, SLOT( enterCommand(int) ));
659 665
660 sm_none = scrollMenu->insertItem(tr( "None" )); 666 sm_none = scrollMenu->insertItem(tr( "None" ));
661 sm_left = scrollMenu->insertItem(tr( "Left" )); 667 sm_left = scrollMenu->insertItem(tr( "Left" ));
662 sm_right = scrollMenu->insertItem(tr( "Right" )); 668 sm_right = scrollMenu->insertItem(tr( "Right" ));
663 // scrollMenu->insertSeparator(4); 669 // scrollMenu->insertSeparator(4);
664 // scrollMenu->insertItem(tr( "Horizontal" )); 670 // scrollMenu->insertItem(tr( "Horizontal" ));
665 671
666 configMenu->insertItem(tr( "ScrollBar" ),scrollMenu); 672 configMenu->insertItem(tr( "ScrollBar" ),scrollMenu);
667 673
668 configMenu->insertItem(tr( "History..." ), this, SLOT(historyDialog())); 674 configMenu->insertItem(tr( "History..." ), this, SLOT(historyDialog()));
669 675
670 cm_wrap = configMenu->insertItem(tr( "Wrap" )); 676 cm_wrap = configMenu->insertItem(tr( "Wrap" ));
671 cfg.setGroup("ScrollBar"); 677 cfg.setGroup("ScrollBar");
672 configMenu->setItemChecked(cm_wrap, cfg.readBoolEntry("HorzScroll",0)); 678 configMenu->setItemChecked(cm_wrap, cfg.readBoolEntry("HorzScroll",0));
673 679
674 cm_beep = configMenu->insertItem(tr( "Use Beep" )); 680 cm_beep = configMenu->insertItem(tr( "Use Beep" ));
675 cfg.setGroup("Menubar"); 681 cfg.setGroup("Menubar");
676 configMenu->setItemChecked(cm_beep, cfg.readBoolEntry("useBeep",0)); 682 configMenu->setItemChecked(cm_beep, cfg.readBoolEntry("useBeep",0));
677 683
678 fullscreen_msg = new QLabel(this); 684 fullscreen_msg = new QLabel(this);
679 fullscreen_msg-> setAlignment ( AlignCenter | SingleLine ); 685 fullscreen_msg-> setAlignment ( AlignCenter | SingleLine );
680 fullscreen_msg-> hide(); 686 fullscreen_msg-> hide();
681 fullscreen_msg-> setSizePolicy ( QSizePolicy ( QSizePolicy::Expanding, QSizePolicy::Expanding )); 687 fullscreen_msg-> setSizePolicy ( QSizePolicy ( QSizePolicy::Expanding, QSizePolicy::Expanding ));
682 fullscreen_msg-> setAutoResize(true); 688 fullscreen_msg-> setAutoResize(true);
683 fullscreen_msg-> setFrameStyle(QFrame::PopupPanel | QFrame::Raised); 689 fullscreen_msg-> setFrameStyle(QFrame::PopupPanel | QFrame::Raised);
684 fullscreen_msg-> setText(tr("To exit fullscreen, tap here.")); 690 fullscreen_msg-> setText(tr("To exit fullscreen, tap here."));
685 691
686 fullscreen_timer = new QTimer(this); 692 fullscreen_timer = new QTimer(this);
687 connect(fullscreen_timer, SIGNAL(timeout()), 693 connect(fullscreen_timer, SIGNAL(timeout()),
688 this, SLOT(fullscreenTimeout())); 694 this, SLOT(fullscreenTimeout()));
689 show_fullscreen_msg = true; 695 show_fullscreen_msg = true;
690 696
691 //scrollMenuSelected(-29); 697 //scrollMenuSelected(-29);
692 // cfg.setGroup("ScrollBar"); 698 // cfg.setGroup("ScrollBar");
693 // if(cfg.readBoolEntry("HorzScroll",0)) { 699 // if(cfg.readBoolEntry("HorzScroll",0)) {
694 // if(cfg.readNumEntry("Position",2) == 0) 700 // if(cfg.readNumEntry("Position",2) == 0)
695 // te->setScrollbarLocation(1); 701 // te->setScrollbarLocation(1);
696 // else 702 // else
697 // te->setScrollbarLocation(0); 703 // te->setScrollbarLocation(0);
698 // te->setScrollbarLocation( cfg.readNumEntry("Position",2)); 704 // te->setScrollbarLocation( cfg.readNumEntry("Position",2));
699 // te->setWrapAt(120); 705 // te->setWrapAt(120);
700 // } 706 // }
701 // create applications ///////////////////////////////////////////////////// 707 // create applications /////////////////////////////////////////////////////
702 setCentralWidget(tab); 708 setCentralWidget(tab);
703 709
704 // load keymaps //////////////////////////////////////////////////////////// 710 // load keymaps ////////////////////////////////////////////////////////////
705 KeyTrans::loadAll(); 711 KeyTrans::loadAll();
706 for (int i = 0; i < KeyTrans::count(); i++) 712 for (int i = 0; i < KeyTrans::count(); i++)
707 { 713 {
708 KeyTrans* s = KeyTrans::find(i); 714 KeyTrans* s = KeyTrans::find(i);
709 assert( s ); 715 assert( s );
710 } 716 }
711 717
712 se_pgm = _pgm; 718 se_pgm = _pgm;
713 se_args = _args; 719 se_args = _args;
714 720
715 cfg.setGroup("CommandLine"); 721 cfg.setGroup("CommandLine");
716 722
717 if (cfg.hasKey("shell_args")) 723 if (cfg.hasKey("shell_args"))
718 { 724 {
719 QStringList se_args_list = cfg.readListEntry("shell_args",'|'); 725 QStringList se_args_list = cfg.readListEntry("shell_args",'|');
720 for(uint i = 0; i < se_args_list.count(); i++) 726 for(uint i = 0; i < se_args_list.count(); i++)
721 { 727 {
722 se_args.prepend(se_args_list[se_args_list.count() - i - 1].latin1()); 728 se_args.prepend(se_args_list[se_args_list.count() - i - 1].latin1());
723 } 729 }
724 } 730 }
725 else 731 else
726 { 732 {
727 se_args.prepend("--login"); 733 se_args.prepend("--login");
728 } 734 }
729 735
730 se_pgm = cfg.readEntry("shell_bin", QString(se_pgm)); 736 se_pgm = cfg.readEntry("shell_bin", QString(se_pgm));
731 737
732 // this is the "documentation" for those who know to look 738 // this is the "documentation" for those who know to look
733 if (! cfg.hasKey("shell_args")) 739 if (! cfg.hasKey("shell_args"))
734 { 740 {
735 cfg.writeEntry("shell_args",QStringList::fromStrList(se_args),'|'); 741 cfg.writeEntry("shell_args",QStringList::fromStrList(se_args),'|');
736 } 742 }
737 if (! cfg.hasKey("shell_bin")) 743 if (! cfg.hasKey("shell_bin"))
738 { 744 {
739 cfg.writeEntry("shell_bin",QString(se_pgm)); 745 cfg.writeEntry("shell_bin",QString(se_pgm));
740 } 746 }
741 747
742 parseCommandLine(); 748 parseCommandLine();
743 749
744 // read and apply default values /////////////////////////////////////////// 750 // read and apply default values ///////////////////////////////////////////
745 resize(321, 321); // Dummy. 751 resize(321, 321); // Dummy.
746 QSize currentSize = size(); 752 QSize currentSize = size();
747 if (currentSize != size()) 753 if (currentSize != size())
748 defaultSize = size(); 754 defaultSize = size();
749 755
750 756
751 /* allows us to catch cancel/escape */ 757 /* allows us to catch cancel/escape */
752 reparent ( 0, WStyle_Customize | WStyle_NoBorder, 758 reparent ( 0, WStyle_Customize | WStyle_NoBorder,
753 QPoint ( 0, 0 )); 759 QPoint ( 0, 0 ));
754} 760}
755 761
756void Konsole::show() 762void Konsole::show()
757{ 763{
758 if ( !nsessions ) 764 if ( !nsessions )
759 { 765 {
760 newSession(); 766 newSession();
761 } 767 }
762 QMainWindow::show(); 768 QMainWindow::show();
763 769
764} 770}
765 771
766void Konsole::initSession(const char*, QStrList &) 772void Konsole::initSession(const char*, QStrList &)
767{ 773{
768 QMainWindow::show(); 774 QMainWindow::show();
769} 775}
770 776
771Konsole::~Konsole() 777Konsole::~Konsole()
772{ 778{
773 while (nsessions > 0) 779 while (nsessions > 0)
774 { 780 {
775 doneSession(getTe(), 0); 781 doneSession(getTe(), 0);
776 } 782 }
777} 783}
778 784
779void 785void
780Konsole::historyDialog() 786Konsole::historyDialog()
781{ 787{
782 QDialog *d = new QDialog ( this, "histdlg", true ); 788 QDialog *d = new QDialog ( this, "histdlg", true );
783 // d-> setCaption ( tr( "History" )); 789 // d-> setCaption ( tr( "History" ));
784 790
785 QBoxLayout *lay = new QVBoxLayout ( d, 4, 4 ); 791 QBoxLayout *lay = new QVBoxLayout ( d, 4, 4 );
786 792
787 QLabel *l = new QLabel ( tr( "History Lines:" ), d ); 793 QLabel *l = new QLabel ( tr( "History Lines:" ), d );
788 lay-> addWidget ( l ); 794 lay-> addWidget ( l );
789 795
790 Config cfg( "Konsole" ); 796 Config cfg( "Konsole" );
791 cfg.setGroup("History"); 797 cfg.setGroup("History");
792 int hist = cfg.readNumEntry("history_lines",300); 798 int hist = cfg.readNumEntry("history_lines",300);
793 int avg_line = cfg.readNumEntry("avg_line_length",60); 799 int avg_line = cfg.readNumEntry("avg_line_length",60);
794 800
795 QSpinBox *spin = new QSpinBox ( 1, 100000, 20, d ); 801 QSpinBox *spin = new QSpinBox ( 1, 100000, 20, d );
796 spin-> setValue ( hist ); 802 spin-> setValue ( hist );
797 spin-> setWrapping ( true ); 803 spin-> setWrapping ( true );
798 spin-> setButtonSymbols ( QSpinBox::PlusMinus ); 804 spin-> setButtonSymbols ( QSpinBox::PlusMinus );
799 lay-> addWidget ( spin ); 805 lay-> addWidget ( spin );
800 806
801 if ( d-> exec ( ) == QDialog::Accepted ) 807 if ( d-> exec ( ) == QDialog::Accepted )
802 { 808 {
803 cfg.writeEntry("history_lines", spin->value()); 809 cfg.writeEntry("history_lines", spin->value());
804 cfg.writeEntry("avg_line_length", avg_line); 810 cfg.writeEntry("avg_line_length", avg_line);
805 if (getTe() != NULL) 811 if (getTe() != NULL)
806 { 812 {
807 getTe()->currentSession->setHistory(true); 813 getTe()->currentSession->setHistory(true);
808 } 814 }
809 } 815 }
810 816
811 delete d; 817 delete d;
812} 818}
813 819
814 820
815void Konsole::cycleZoom() 821void Konsole::cycleZoom()
816{ 822{
817 TEWidget* te = getTe(); 823 TEWidget* te = getTe();
818 QFont font = te->getVTFont(); 824 QFont font = te->getVTFont();
819 int size = font.pointSize(); 825 int size = font.pointSize();
820 changeFontSize(1); 826 changeFontSize(1);
821 font = te->getVTFont(); 827 font = te->getVTFont();
822 if (font.pointSize() <= size) 828 if (font.pointSize() <= size)
823 { 829 {
824 do 830 do
825 { 831 {
826 font = te->getVTFont(); 832 font = te->getVTFont();
827 size = font.pointSize(); 833 size = font.pointSize();
828 changeFontSize(-1); 834 changeFontSize(-1);
829 font = te->getVTFont(); 835 font = te->getVTFont();
830 } 836 }
831 while (font.pointSize() < size); 837 while (font.pointSize() < size);
832 } 838 }
833} 839}
834 840
835void Konsole::changeFontSize(int delta) 841void Konsole::changeFontSize(int delta)
836{ 842{
837 // printf("delta font size %d\n", delta); 843 // printf("delta font size %d\n", delta);
838 TEWidget* te = getTe(); 844 TEWidget* te = getTe();
839 QFont font = te->getVTFont(); 845 QFont font = te->getVTFont();
840 int size = font.pointSize(); 846 int size = font.pointSize();
841 int closest = delta > 0? 10000 : -10000; 847 int closest = delta > 0? 10000 : -10000;
842 int closest_font = -1; 848 int closest_font = -1;
843 for(uint i = 0; i < fonts.count(); i++) 849 for(uint i = 0; i < fonts.count(); i++)
844 { 850 {
845 if (fonts.at(i)->getFont() == font) 851 if (fonts.at(i)->getFont() == font)
846 { 852 {
847 if (delta > 0) 853 if (delta > 0)
848 { 854 {
849 if (i+1 < fonts.count() 855 if (i+1 < fonts.count()
850 && fonts.at(i+1)->getFamilyNum() == fonts.at(i)->getFamilyNum()) 856 && fonts.at(i+1)->getFamilyNum() == fonts.at(i)->getFamilyNum())
851 { 857 {
852 setFont(i+1); 858 setFont(i+1);
853 printf("font %d\n", i+1); 859 printf("font %d\n", i+1);
854 return; 860 return;
855 } 861 }
856 } 862 }
857 else if (delta < 0) 863 else if (delta < 0)
858 { 864 {
859 if (i > 0 865 if (i > 0
860 && fonts.at(i-1)->getFamilyNum() == fonts.at(i)->getFamilyNum()) 866 && fonts.at(i-1)->getFamilyNum() == fonts.at(i)->getFamilyNum())
861 { 867 {
862 setFont(i-1); 868 setFont(i-1);
863 printf("font %d\n", i-1); 869 printf("font %d\n", i-1);
864 return; 870 return;
865 } 871 }
866 } 872 }
867 } 873 }
868 int fsize = fonts.at(i)->getSize(); 874 int fsize = fonts.at(i)->getSize();
869 printf("%d size=%d fsize=%d closest=%d\n", i, size, fsize, closest); 875 printf("%d size=%d fsize=%d closest=%d\n", i, size, fsize, closest);
870 if ((delta > 0 && fsize > size && fsize < closest) 876 if ((delta > 0 && fsize > size && fsize < closest)
871 || (delta < 0 && fsize < size && fsize > closest)) 877 || (delta < 0 && fsize < size && fsize > closest))
872 { 878 {
873 closest = fsize; 879 closest = fsize;
874 closest_font = i; 880 closest_font = i;
875 } 881 }
876 } 882 }
877 if (closest_font >= 0) 883 if (closest_font >= 0)
878 { 884 {
879 printf("font closest %d (%d)\n", closest_font, closest); 885 printf("font closest %d (%d)\n", closest_font, closest);
880 setFont(closest_font); 886 setFont(closest_font);
881 } 887 }
882} 888}
883 889
884int Konsole::findFont(const QString& name, int size, bool exactMatch) 890int Konsole::findFont(const QString& name, int size, bool exactMatch)
885{ 891{
886 for(uint i = 0; i < fonts.count(); i++) 892 for(uint i = 0; i < fonts.count(); i++)
887 { 893 {
888 if (fonts.at(i)->getName() == name 894 if (fonts.at(i)->getName() == name
889 && fonts.at(i)->getSize() == size) 895 && fonts.at(i)->getSize() == size)
890 { 896 {
891 return(i); 897 return(i);
892 } 898 }
893 } 899 }
894 if (exactMatch) 900 if (exactMatch)
895 { 901 {
896 return(-1); 902 return(-1);
897 } 903 }
898 for(uint i = 0; i < fonts.count(); i++) 904 for(uint i = 0; i < fonts.count(); i++)
899 { 905 {
900 if (fonts.at(i)->getSize() == size) 906 if (fonts.at(i)->getSize() == size)
901 { 907 {
902 return(i); 908 return(i);
903 } 909 }
904 } 910 }
905 return(-1); 911 return(-1);
906} 912}
907 913
908void Konsole::setFont(int f) 914void Konsole::setFont(int f)
909{ 915{
910 VTFont* font = fonts.at(f); 916 VTFont* font = fonts.at(f);
911 if (font) 917 if (font)
912 { 918 {
913 TEWidget* te = getTe(); 919 TEWidget* te = getTe();
914 if (te != 0) 920 if (te != 0)
915 { 921 {
916 te->setVTFont(font->getFont()); 922 te->setVTFont(font->getFont());
917 } 923 }
918 cfont = f; 924 cfont = f;
919 925
920 int familyNum = font->getFamilyNum(); 926 int familyNum = font->getFamilyNum();
921 int size = font->getSize(); 927 int size = font->getSize();
922 printf("familyNum = %d size = %d count=%d\n", familyNum, size, 928 printf("familyNum = %d size = %d count=%d\n", familyNum, size,
923 fontList->count()); 929 fontList->count());
924 for(int i = 0; i < (int)fontList->count(); i++) 930 for(int i = 0; i < (int)fontList->count(); i++)
925 { 931 {
926 fontList->setItemChecked(i + 1000, i == familyNum); 932 fontList->setItemChecked(i + 1000, i == familyNum);
927 } 933 }
928 for(int i = 0; i < (int)fonts.count(); i++) 934 for(int i = 0; i < (int)fonts.count(); i++)
929 { 935 {
930 fontList->setItemChecked(i, fonts.at(i)->getFamilyNum() == familyNum 936 fontList->setItemChecked(i, fonts.at(i)->getFamilyNum() == familyNum
931 && fonts.at(i)->getSize() == size); 937 && fonts.at(i)->getSize() == size);
932 } 938 }
933 Config cfg( "Konsole" ); 939 Config cfg( "Konsole" );
934 cfg.setGroup("Font"); 940 cfg.setGroup("Font");
935 QString ss = "Session"+ QString::number(tab->currentPageIndex()+1); 941 QString ss = "Session"+ QString::number(tab->currentPageIndex()+1);
936 if (tab->currentPageIndex() == 0) 942 if (tab->currentPageIndex() == 0)
937 { 943 {
938 cfg.writeEntry("FontName", fonts.at(cfont)->getFamily()); 944 cfg.writeEntry("FontName", fonts.at(cfont)->getFamily());
939 cfg.writeEntry("FontSize", fonts.at(cfont)->getSize()); 945 cfg.writeEntry("FontSize", fonts.at(cfont)->getSize());
940 } 946 }
941 cfg.writeEntry("FontName"+ss, fonts.at(cfont)->getFamily()); 947 cfg.writeEntry("FontName"+ss, fonts.at(cfont)->getFamily());
942 cfg.writeEntry("FontSize"+ss, fonts.at(cfont)->getSize()); 948 cfg.writeEntry("FontSize"+ss, fonts.at(cfont)->getSize());
943 } 949 }
944} 950}
945 951
946#if 0 952#if 0
947void Konsole::fontChanged(int f) 953void Konsole::fontChanged(int f)
948{ 954{
949 VTFont* font = fonts.at(f); 955 VTFont* font = fonts.at(f);
950 if (font != 0) 956 if (font != 0)
951 { 957 {
952 for(uint i = 0; i < fonts.count(); i++) 958 for(uint i = 0; i < fonts.count(); i++)
953 { 959 {
954 fontList->setItemChecked(i, (i == (uint) f) ? TRUE : FALSE); 960 fontList->setItemChecked(i, (i == (uint) f) ? TRUE : FALSE);
955 } 961 }
956 962
957 cfont = f; 963 cfont = f;
958 964
959 TEWidget* te = getTe(); 965 TEWidget* te = getTe();
960 if (te != 0) 966 if (te != 0)
961 { 967 {
962 te->setVTFont(font->getFont()); 968 te->setVTFont(font->getFont());
963 } 969 }
964 } 970 }
965} 971}
966#endif 972#endif
967 973
968 974
969void Konsole::enterCommand(int c) 975void Konsole::enterCommand(int c)
970{ 976{
971 TEWidget* te = getTe(); 977 TEWidget* te = getTe();
972 if (te != 0) 978 if (te != 0)
973 { 979 {
974 if(!commonCombo->editable()) 980 if(!commonCombo->editable())
975 { 981 {
976 QString text = commonCombo->text(c); //commonCmds[c]; 982 QString text = commonCombo->text(c); //commonCmds[c];
977 te->emitText(text); 983 te->emitText(text);
978 } 984 }
979 else 985 else
980 { 986 {
981 changeCommand( commonCombo->text(c), c); 987 changeCommand( commonCombo->text(c), c);
982 } 988 }
983 } 989 }
984} 990}
985 991
986void Konsole::hitEnter() 992void Konsole::hitEnter()
987{ 993{
988 TEWidget* te = getTe(); 994 TEWidget* te = getTe();
989 if (te != 0) 995 if (te != 0)
990 { 996 {
991 te->emitText(QString("\r")); 997 te->emitText(QString("\r"));
992 } 998 }
993} 999}
994 1000
995void Konsole::hitSpace() 1001void Konsole::hitSpace()
996{ 1002{
997 TEWidget* te = getTe(); 1003 TEWidget* te = getTe();
998 if (te != 0) 1004 if (te != 0)
999 { 1005 {
1000 te->emitText(QString(" ")); 1006 te->emitText(QString(" "));
1001 } 1007 }
1002} 1008}
1003 1009
1004void Konsole::hitTab() 1010void Konsole::hitTab()
1005{ 1011{
1006 TEWidget* te = getTe(); 1012 TEWidget* te = getTe();
1007 if (te != 0) 1013 if (te != 0)
1008 { 1014 {
1009 te->emitText(QString("\t")); 1015 te->emitText(QString("\t"));
1010 } 1016 }
1011} 1017}
1012 1018
1013void Konsole::hitPaste() 1019void Konsole::hitPaste()
1014{ 1020{
1015 TEWidget* te = getTe(); 1021 TEWidget* te = getTe();
1016 if (te != 0) 1022 if (te != 0)
1017 { 1023 {
1018 te->pasteClipboard(); 1024 te->pasteClipboard();
1019 } 1025 }
1020} 1026}
1021 1027
1022void Konsole::hitUp() 1028void Konsole::hitUp()
1023{ 1029{
1024 TEWidget* te = getTe(); 1030 TEWidget* te = getTe();
1025 if (te != 0) 1031 if (te != 0)
1026 { 1032 {
1027 QKeyEvent ke( QKeyEvent::KeyPress, Qt::Key_Up, 0, 0); 1033 QKeyEvent ke( QKeyEvent::KeyPress, Qt::Key_Up, 0, 0);
1028 QApplication::sendEvent( te, &ke ); 1034 QApplication::sendEvent( te, &ke );
1029 } 1035 }
1030} 1036}
1031 1037
1032void Konsole::hitDown() 1038void Konsole::hitDown()
1033{ 1039{
1034 TEWidget* te = getTe(); 1040 TEWidget* te = getTe();
1035 if (te != 0) 1041 if (te != 0)
1036 { 1042 {
1037 QKeyEvent ke( QKeyEvent::KeyPress, Qt::Key_Down, 0, 0); 1043 QKeyEvent ke( QKeyEvent::KeyPress, Qt::Key_Down, 0, 0);
1038 QApplication::sendEvent( te, &ke ); 1044 QApplication::sendEvent( te, &ke );
1039 } 1045 }
1040} 1046}
1041 1047
1042/** 1048/**
1043 This function calculates the size of the external widget 1049 This function calculates the size of the external widget
1044 needed for the internal widget to be 1050 needed for the internal widget to be
1045 */ 1051 */
1046QSize Konsole::calcSize(int columns, int lines) 1052QSize Konsole::calcSize(int columns, int lines)
1047{ 1053{
1048 TEWidget* te = getTe(); 1054 TEWidget* te = getTe();
1049 if (te != 0) 1055 if (te != 0)
1050 { 1056 {
1051 QSize size = te->calcSize(columns, lines); 1057 QSize size = te->calcSize(columns, lines);
1052 return size; 1058 return size;
1053 } 1059 }
1054 else 1060 else
1055 { 1061 {
1056 QSize size; 1062 QSize size;
1057 return size; 1063 return size;
1058 } 1064 }
1059} 1065}
1060 1066
1061/** 1067/**
1062 sets application window to a size based on columns X lines of the te 1068 sets application window to a size based on columns X lines of the te
1063 guest widget. Call with (0,0) for setting default size. 1069 guest widget. Call with (0,0) for setting default size.
1064*/ 1070*/
1065 1071
1066void Konsole::setColLin(int columns, int lines) 1072void Konsole::setColLin(int columns, int lines)
1067{ 1073{
1068 odebug << "konsole::setColLin:: Columns " << columns << "" << oendl; 1074 odebug << "konsole::setColLin:: Columns " << columns << "" << oendl;
1069 1075
1070 if ((columns==0) || (lines==0)) 1076 if ((columns==0) || (lines==0))
1071 { 1077 {
1072 if (defaultSize.isEmpty()) // not in config file : set default value 1078 if (defaultSize.isEmpty()) // not in config file : set default value
1073 { 1079 {
1074 defaultSize = calcSize(80,24); 1080 defaultSize = calcSize(80,24);
1075 // notifySize(24,80); // set menu items (strange arg order !) 1081 // notifySize(24,80); // set menu items (strange arg order !)
1076 } 1082 }
1077 resize(defaultSize); 1083 resize(defaultSize);
1078 } 1084 }
1079 else 1085 else
1080 { 1086 {
1081 resize(calcSize(columns, lines)); 1087 resize(calcSize(columns, lines));
1082 // notifySize(lines,columns); // set menu items (strange arg order !) 1088 // notifySize(lines,columns); // set menu items (strange arg order !)
1083 } 1089 }
1084} 1090}
1085 1091
1086/* 1092/*
1087void Konsole::setFont(int fontno) 1093void Konsole::setFont(int fontno)
1088{ 1094{
1089 QFont f; 1095 QFont f;
1090 if (fontno == 0) 1096 if (fontno == 0)
1091 f = defaultFont = QFont( "Helvetica", 12 ); 1097 f = defaultFont = QFont( "Helvetica", 12 );
1092 else 1098 else
1093 if (fonts[fontno][0] == '-') 1099 if (fonts[fontno][0] == '-')
1094 f.setRawName( fonts[fontno] ); 1100 f.setRawName( fonts[fontno] );
1095 else 1101 else
1096 { 1102 {
1097 f.setFamily(fonts[fontno]); 1103 f.setFamily(fonts[fontno]);
1098 f.setRawMode( TRUE ); 1104 f.setRawMode( TRUE );
1099 } 1105 }
1100 if ( !f.exactMatch() && fontno != 0) 1106 if ( !f.exactMatch() && fontno != 0)
1101 { 1107 {
1102 QString msg = i18n("Font `%1' not found.\nCheck README.linux.console for help.").arg(fonts[fontno]); 1108 QString msg = i18n("Font `%1' not found.\nCheck README.linux.console for help.").arg(fonts[fontno]);
1103 QMessageBox(this, msg); 1109 QMessageBox(this, msg);
1104 return; 1110 return;
1105 } 1111 }
1106 if (se) se->setFontNo(fontno); 1112 if (se) se->setFontNo(fontno);
1107 te->setVTFont(f); 1113 te->setVTFont(f);
1108 n_font = fontno; 1114 n_font = fontno;
1109} 1115}
1110*/ 1116*/
1111 1117
1112// --| color selection |------------------------------------------------------- 1118// --| color selection |-------------------------------------------------------
1113 1119
1114void Konsole::changeColumns(int /*columns*/) 1120void Konsole::changeColumns(int /*columns*/)
1115{ //FIXME this seems to cause silliness when reset command is executed 1121{ //FIXME this seems to cause silliness when reset command is executed
1116 // odebug << "change columns" << oendl; 1122 // odebug << "change columns" << oendl;
1117 // TEWidget* te = getTe(); 1123 // TEWidget* te = getTe();
1118 // if (te != 0) { 1124 // if (te != 0) {
1119 // setColLin(columns,te->Lines()); 1125 // setColLin(columns,te->Lines());
1120 // te->update(); 1126 // te->update();
1121 // } 1127 // }
1122} 1128}
1123 1129
1124//FIXME: If a child dies during session swap, 1130//FIXME: If a child dies during session swap,
1125// this routine might be called before 1131// this routine might be called before
1126// session swap is completed. 1132// session swap is completed.
1127 1133
1128void Konsole::doneSession(TEWidget* te, int ) 1134void Konsole::doneSession(TEWidget* te, int )
1129{ 1135{
1130 // TEWidget *te = NULL; 1136 // TEWidget *te = NULL;
1131 // if (sess->currentSession == tab->currentPage()) { 1137 // if (sess->currentSession == tab->currentPage()) {
1132 // printf("done current session\n"); 1138 // printf("done current session\n");
1133 // te = getTe(); 1139 // te = getTe();
1134 // } else { 1140 // } else {
1135 // int currentPage = tab->currentPageIndex(); 1141 // int currentPage = tab->currentPageIndex();
1136 // printf("done not current session\n"); 1142 // printf("done not current session\n");
1137 // for(int i = 0; i < nsessions; i++) { 1143 // for(int i = 0; i < nsessions; i++) {
1138 // tab->setCurrentPage(i); 1144 // tab->setCurrentPage(i);
1139 // printf("find session %d tab page %x session %x\n", 1145 // printf("find session %d tab page %x session %x\n",
1140 // i, tab->currentPage(), sess->currentSession); 1146 // i, tab->currentPage(), sess->currentSession);
1141 // if (tab->currentPage() == sess->currentSession) { 1147 // if (tab->currentPage() == sess->currentSession) {
1142 // printf("found session %d\n", i); 1148 // printf("found session %d\n", i);
1143 // te = tab->currentPage(); 1149 // te = tab->currentPage();
1144 // break; 1150 // break;
1145 // } 1151 // }
1146 // } 1152 // }
1147 // tab->setCurrentPage(currentPage); 1153 // tab->setCurrentPage(currentPage);
1148 // } 1154 // }
1149 if (te != 0) 1155 if (te != 0)
1150 { 1156 {
1151 te->currentSession->setConnect(FALSE); 1157 te->currentSession->setConnect(FALSE);
1152 tab->removeTab(te); 1158 tab->removeTab(te);
1153 delete te->currentSession; 1159 delete te->currentSession;
1154 delete te; 1160 delete te;
1155 sessionList->removeItem(nsessions); 1161 sessionList->removeItem(nsessions);
1156 nsessions--; 1162 nsessions--;
1157 } 1163 }
1158 if (nsessions == 0) 1164 if (nsessions == 0)
1159 { 1165 {
1160 close(); 1166 close();
1161 } 1167 }
1162} 1168}
1163 1169
1164void Konsole::changeTitle(TEWidget* te, const QString& newTitle ) 1170void Konsole::changeTitle(TEWidget* te, const QString& newTitle )
1165{ 1171{
1166 if (te == getTe()) 1172 if (te == getTe())
1167 { 1173 {
1168 setCaption( newTitle + " - " + tr( "Konsole " ) ); 1174 setCaption( newTitle + " - " + tr( "Konsole " ) );
1169 } 1175 }
1170} 1176}
1171 1177
1172 1178
1173void Konsole::newSession() 1179void Konsole::newSession()
1174{ 1180{
1175 if(nsessions < 15) 1181 if(nsessions < 15)
1176 { // seems to be something weird about 16 tabs on the Zaurus.... memory? 1182 { // seems to be something weird about 16 tabs on the Zaurus.... memory?
1177 TEWidget* te = new TEWidget(tab); 1183 TEWidget* te = new TEWidget(tab);
1178 Config cfg( "Konsole" ); 1184 Config cfg( "Konsole" );
1179 cfg.setGroup("Menubar"); 1185 cfg.setGroup("Menubar");
1180 1186
1181 // FIXME use more defaults from config file 1187 // FIXME use more defaults from config file
1182 te->useBeep=cfg.readBoolEntry("useBeep",0); 1188 te->useBeep=cfg.readBoolEntry("useBeep",0);
1183 1189
1184 // te->setBackgroundMode(PaletteBase); //we want transparent!! 1190 // te->setBackgroundMode(PaletteBase); //we want transparent!!
1185 1191
1186 cfg.setGroup("Font"); 1192 cfg.setGroup("Font");
1187 QString sn = "Session" + QString::number(nsessions+1); 1193 QString sn = "Session" + QString::number(nsessions+1);
1188 printf("read font session %s\n", sn.latin1()); 1194 printf("read font session %s\n", sn.latin1());
1189 QString fontName = cfg.readEntry("FontName"+sn, 1195 QString fontName = cfg.readEntry("FontName"+sn,
1190 cfg.readEntry("FontName", 1196 cfg.readEntry("FontName",
1191 fonts.at(cfont)->getFamily())); 1197 fonts.at(cfont)->getFamily()));
1192 int fontSize = cfg.readNumEntry("FontSize"+sn, 1198 int fontSize = cfg.readNumEntry("FontSize"+sn,
1193 cfg.readNumEntry("FontSize", 1199 cfg.readNumEntry("FontSize",
1194 fonts.at(cfont)->getSize())); 1200 fonts.at(cfont)->getSize()));
1195 cfont = findFont(fontName, fontSize, false); 1201 cfont = findFont(fontName, fontSize, false);
1196 printf("lookup font %s size %d got %d\n", fontName.latin1(), fontSize, cfont); 1202 printf("lookup font %s size %d got %d\n", fontName.latin1(), fontSize, cfont);
1197 if (cfont < 0) 1203 if (cfont < 0)
1198 cfont = 0; 1204 cfont = 0;
1199 te->setVTFont(fonts.at(cfont)->getFont()); 1205 te->setVTFont(fonts.at(cfont)->getFont());
1200 1206
1201 tab->addTab(te); 1207 tab->addTab(te);
1202 TESession* se = new TESession(this, te, se_pgm, se_args, "xterm"); 1208 TESession* se = new TESession(this, te, se_pgm, se_args, "xterm");
1203 te->currentSession = se; 1209 te->currentSession = se;
1204 connect( se, SIGNAL(done(TEWidget*,int)), this, SLOT(doneSession(TEWidget*,int)) ); 1210 connect( se, SIGNAL(done(TEWidget*,int)), this, SLOT(doneSession(TEWidget*,int)) );
1205 connect( se, SIGNAL(changeTitle(TEWidget*,const QString&)), this, 1211 connect( se, SIGNAL(changeTitle(TEWidget*,const QString&)), this,
1206 SLOT(changeTitle(TEWidget*,const QString&)) ); 1212 SLOT(changeTitle(TEWidget*,const QString&)) );
1207 connect(te, SIGNAL(changeFontSize(int)), this, SLOT(changeFontSize(int))); 1213 connect(te, SIGNAL(changeFontSize(int)), this, SLOT(changeFontSize(int)));
1208 connect(te, SIGNAL(changeSession(int)), this, SLOT(changeSession(int))); 1214 connect(te, SIGNAL(changeSession(int)), this, SLOT(changeSession(int)));
1209 connect(te, SIGNAL(newSession()), this, SLOT(newSession())); 1215 connect(te, SIGNAL(newSession()), this, SLOT(newSession()));
1210 connect(te, SIGNAL(toggleFullScreen()), this, SLOT(toggleFullScreen())); 1216 connect(te, SIGNAL(toggleFullScreen()), this, SLOT(toggleFullScreen()));
1211 connect(te, SIGNAL(setFullScreen(bool)), this, SLOT(setFullScreen(bool))); 1217 connect(te, SIGNAL(setFullScreen(bool)), this, SLOT(setFullScreen(bool)));
1212 se->run(); 1218 se->run();
1213 se->setConnect(TRUE); 1219 se->setConnect(TRUE);
1214 se->setHistory(b_scroll); 1220 se->setHistory(b_scroll);
1215 nsessions++; 1221 nsessions++;
1216 sessionList->insertItem(QString::number(nsessions), nsessions); 1222 sessionList->insertItem(QString::number(nsessions), nsessions);
1217 sessionListSelected(nsessions); 1223 sessionListSelected(nsessions);
1218 doWrap(); 1224 doWrap();
1219 setColor(nsessions-1); 1225 setColor(nsessions-1);
1220 } 1226 }
1221} 1227}
1222 1228
1223TEWidget* Konsole::getTe() 1229TEWidget* Konsole::getTe()
1224{ 1230{
1225 if (nsessions) 1231 if (nsessions)
1226 { 1232 {
1227 return (TEWidget *) tab->currentPage(); 1233 return (TEWidget *) tab->currentPage();
1228 } 1234 }
1229 else 1235 else
1230 { 1236 {
1231 return 0; 1237 return 0;
1232 } 1238 }
1233} 1239}
1234 1240
1235void Konsole::sessionListSelected(int id) 1241void Konsole::sessionListSelected(int id)
1236{ 1242{
1237 if (id < 0) 1243 if (id < 0)
1238 { 1244 {
1239 return; 1245 return;
1240 } 1246 }
1241 QString selected = sessionList->text(id); 1247 QString selected = sessionList->text(id);
1242 EKNumTabBar *tabBar = tab->getTabBar(); 1248 EKNumTabBar *tabBar = tab->getTabBar();
1243 1249
1244 int n = 0; 1250 int n = 0;
1245 for(int i = 0; n < tabBar->count(); i++) 1251 for(int i = 0; n < tabBar->count(); i++)
1246 { 1252 {
1247 if (tabBar->tab(i)) 1253 if (tabBar->tab(i))
1248 { 1254 {
1249 // printf("selected = %s tab %d = %s\n", selected.latin1(), 1255 // printf("selected = %s tab %d = %s\n", selected.latin1(),
1250 // i, tabBar->tab(i)->text().latin1()); 1256 // i, tabBar->tab(i)->text().latin1());
1251 if (tabBar->tab(i)->text() == selected) 1257 if (tabBar->tab(i)->text() == selected)
1252 { 1258 {
1253 tab->setCurrentPage(i); 1259 tab->setCurrentPage(i);
1254 break; 1260 break;
1255 } 1261 }
1256 n++; 1262 n++;
1257 } 1263 }
1258 } 1264 }
1259} 1265}
1260 1266
1261 1267
1262void Konsole::changeSession(int delta) 1268void Konsole::changeSession(int delta)
1263{ 1269{
1264 printf("delta session %d\n", delta); 1270 printf("delta session %d\n", delta);
1265 QTabBar *tabBar = tab->getTabBar(); 1271 QTabBar *tabBar = tab->getTabBar();
1266 int i = tabBar->tab(tabBar->currentTab())->text().toInt() - 1; 1272 int i = tabBar->tab(tabBar->currentTab())->text().toInt() - 1;
1267 i += delta; 1273 i += delta;
1268 if (i < 0) 1274 if (i < 0)
1269 i += tabBar->count(); 1275 i += tabBar->count();
1270 if (i >= tabBar->count()) 1276 if (i >= tabBar->count())
1271 i -= tabBar->count(); 1277 i -= tabBar->count();
1272 1278
1273 QString selected = QString::number(i+1); 1279 QString selected = QString::number(i+1);
1274 int n = 0; 1280 int n = 0;
1275 for(int i = 0; n < tabBar->count(); i++) 1281 for(int i = 0; n < tabBar->count(); i++)
1276 { 1282 {
1277 if (tabBar->tab(i)) 1283 if (tabBar->tab(i))
1278 { 1284 {
1279 printf("selected = %s tab %d = %s\n", selected.latin1(), 1285 printf("selected = %s tab %d = %s\n", selected.latin1(),
1280 i, tabBar->tab(i)->text().latin1()); 1286 i, tabBar->tab(i)->text().latin1());
1281 if (tabBar->tab(i)->text() == selected) 1287 if (tabBar->tab(i)->text() == selected)
1282 { 1288 {
1283 tab->setCurrentPage(i); 1289 tab->setCurrentPage(i);
1284 break; 1290 break;
1285 } 1291 }
1286 n++; 1292 n++;
1287 } 1293 }
1288 } 1294 }
1289} 1295}
1290 1296
1291void Konsole::switchSession(QWidget* w) 1297void Konsole::switchSession(QWidget* w)
1292{ 1298{
1293 TEWidget* te = (TEWidget *) w; 1299 TEWidget* te = (TEWidget *) w;
1294 QFont teFnt = te->getVTFont(); 1300 QFont teFnt = te->getVTFont();
1295 int familyNum = -1; 1301 int familyNum = -1;
1296 1302
1297 for(uint i = 0; i < fonts.count(); i++) 1303 for(uint i = 0; i < fonts.count(); i++)
1298 { 1304 {
1299 VTFont *fnt = fonts.at(i); 1305 VTFont *fnt = fonts.at(i);
1300 bool cf = fnt->getFont() == teFnt; 1306 bool cf = fnt->getFont() == teFnt;
1301 fontList->setItemChecked(i, cf); 1307 fontList->setItemChecked(i, cf);
1302 if (cf) 1308 if (cf)
1303 { 1309 {
1304 cfont = i; 1310 cfont = i;
1305 familyNum = fnt->getFamilyNum(); 1311 familyNum = fnt->getFamilyNum();
1306 } 1312 }
1307 } 1313 }
1308 for(int i = 0; i < (int)fontList->count(); i++) 1314 for(int i = 0; i < (int)fontList->count(); i++)
1309 { 1315 {
1310 fontList->setItemChecked(i + 1000, i == familyNum); 1316 fontList->setItemChecked(i + 1000, i == familyNum);
1311 } 1317 }
1312 if (! te->currentSession->Title().isEmpty() ) 1318 if (! te->currentSession->Title().isEmpty() )
1313 { 1319 {
1314 setCaption( te->currentSession->Title() + " - " + tr( "Konsole" ) ); 1320 setCaption( te->currentSession->Title() + " - " + tr( "Konsole" ) );
1315 } 1321 }
1316 else 1322 else
1317 { 1323 {
1318 setCaption( tr( "Konsole" ) ); 1324 setCaption( tr( "Konsole" ) );
1319 } 1325 }
1320 // colorMenuSelected(te->color_menu_item); 1326 // colorMenuSelected(te->color_menu_item);
1321} 1327}
1322 1328
1323 1329
1324void Konsole::toggleFullScreen() 1330void Konsole::toggleFullScreen()
1325{ 1331{
1326 setFullScreen(! fullscreen); 1332 setFullScreen(! fullscreen);
1327} 1333}
1328 1334
1329void Konsole::setFullScreen ( bool b ) 1335void Konsole::setFullScreen ( bool b )
1330{ 1336{
1331 static QSize normalsize; 1337 static QSize normalsize;
1332 static bool listHidden; 1338 static bool listHidden;
1333 1339
1334 if (b == fullscreen) 1340 if (b == fullscreen)
1335 { 1341 {
1336 return; 1342 return;
1337 } 1343 }
1338 1344
1339 fullscreen = b; 1345 fullscreen = b;
1340 1346
1341 if ( b ) 1347 if ( b )
1342 { 1348 {
1343 if ( !normalsize. isValid ( )) 1349 if ( !normalsize. isValid ( ))
1344 { 1350 {
1345 normalsize = size ( ); 1351 normalsize = size ( );
1346 } 1352 }
1347 1353
1348 setFixedSize ( qApp-> desktop ( )-> size ( )); 1354 setFixedSize ( qApp-> desktop ( )-> size ( ));
1349 showNormal ( ); 1355 showNormal ( );
1350 reparent ( 0, WStyle_Customize | WStyle_NoBorder, 1356 reparent ( 0, WStyle_Customize | WStyle_NoBorder,
1351 QPoint ( 0, 0 )); 1357 QPoint ( 0, 0 ));
1352 showFullScreen ( ); 1358 showFullScreen ( );
1353 1359
1354 menuToolBar->hide(); 1360 menuToolBar->hide();
1355 toolBar->hide(); 1361 toolBar->hide();
1356 listHidden = secondToolBar->isHidden(); 1362 listHidden = secondToolBar->isHidden();
1357 secondToolBar->hide(); 1363 secondToolBar->hide();
1358 // commonCombo->hide(); 1364 // commonCombo->hide();
1359 tab->getTabBar()->hide(); 1365 tab->getTabBar()->hide();
1360 tab->setMargin(tab->margin()); 1366 tab->setMargin(tab->margin());
1361 1367
1362 if (show_fullscreen_msg) 1368 if (show_fullscreen_msg)
1363 { 1369 {
1364 fullscreen_msg-> move(tab->x() + tab->width()/2 - fullscreen_msg->width()/2, 1370 fullscreen_msg-> move(tab->x() + tab->width()/2 - fullscreen_msg->width()/2,
1365 qApp->desktop()->height()/16 - fullscreen_msg->height()/2); 1371 qApp->desktop()->height()/16 - fullscreen_msg->height()/2);
1366 fullscreen_msg->show(); 1372 fullscreen_msg->show();
1367 fullscreen_timer->start(3000, true); 1373 fullscreen_timer->start(3000, true);
1368 show_fullscreen_msg = false; 1374 show_fullscreen_msg = false;
1369 } 1375 }
1370 } 1376 }
1371 else 1377 else
1372 { 1378 {
1373 showNormal ( ); 1379 showNormal ( );
1374 reparent ( 0, WStyle_Customize, QPoint ( 0, 0 )); 1380 reparent ( 0, WStyle_Customize, QPoint ( 0, 0 ));
1375 resize ( normalsize ); 1381 resize ( normalsize );
1376 showMaximized ( ); 1382 showMaximized ( );
1377 normalsize = QSize ( ); 1383 normalsize = QSize ( );
1378 1384
1379 menuToolBar->show(); 1385 menuToolBar->show();
1380 toolBar->show(); 1386 toolBar->show();
1381 if(! listHidden) 1387 if(! listHidden)
1382 { 1388 {
1383 secondToolBar->show(); 1389 secondToolBar->show();
1384 } 1390 }
1385 // commonCombo->show(); 1391 // commonCombo->show();
1386 menuToolBar->show(); 1392 menuToolBar->show();
1387 if (tabPos != tm_hidden) 1393 if (tabPos != tm_hidden)
1388 { 1394 {
1389 tab->getTabBar()->show(); 1395 tab->getTabBar()->show();
1390 } 1396 }
1391 } 1397 }
1392 tab->setMargin(tab->margin()); // cause setup to run 1398 tab->setMargin(tab->margin()); // cause setup to run
1393} 1399}
1394 1400
1395 1401
1396void Konsole::fullscreenTimeout() 1402void Konsole::fullscreenTimeout()
1397{ 1403{
1398 fullscreen_msg->hide(); 1404 fullscreen_msg->hide();
1399} 1405}
1400 1406
1401void Konsole::colorMenuIsSelected(int iD) 1407void Konsole::colorMenuIsSelected(int iD)
1402{ 1408{
1403 fromMenu = TRUE; 1409 fromMenu = TRUE;
1404 colorMenuSelected(iD); 1410 colorMenuSelected(iD);
1405} 1411}
1406 1412
1407/// ------------------------------- some new stuff by L.J. Potter 1413/// ------------------------------- some new stuff by L.J. Potter
1408 1414
1409 1415
1410void Konsole::colorMenuSelected(int iD) 1416void Konsole::colorMenuSelected(int iD)
1411{ 1417{
1412 // this is NOT pretty, elegant or anything else besides functional 1418 // this is NOT pretty, elegant or anything else besides functional
1413 // QString temp; 1419 // QString temp;
1414 // odebug << temp.sprintf("colormenu " << iD) << "" << oendl; 1420 // odebug << temp.sprintf("colormenu " << iD) << "" << oendl;
1415 1421
1416 TEWidget* te = getTe(); 1422 TEWidget* te = getTe();
1417 Config cfg( "Konsole" ); 1423 Config cfg( "Konsole" );
1418 cfg.setGroup("Colors"); 1424 cfg.setGroup("Colors");
1419 1425
1420 ColorEntry m_table[TABLE_COLORS]; 1426 ColorEntry m_table[TABLE_COLORS];
1421 const ColorEntry * defaultCt=te->getdefaultColorTable(); 1427 const ColorEntry * defaultCt=te->getdefaultColorTable();
1422 1428
1423 int i; 1429 int i;
1424 1430
1425 // te->color_menu_item = iD; 1431 // te->color_menu_item = iD;
1426 1432
1427 colorMenu->setItemChecked(cm_ab,FALSE); 1433 colorMenu->setItemChecked(cm_ab,FALSE);
1428 colorMenu->setItemChecked(cm_bb,FALSE); 1434 colorMenu->setItemChecked(cm_bb,FALSE);
1429 colorMenu->setItemChecked(cm_wc,FALSE); 1435 colorMenu->setItemChecked(cm_wc,FALSE);
1430 colorMenu->setItemChecked(cm_cw,FALSE); 1436 colorMenu->setItemChecked(cm_cw,FALSE);
1431 colorMenu->setItemChecked(cm_mb,FALSE); 1437 colorMenu->setItemChecked(cm_mb,FALSE);
1432 colorMenu->setItemChecked(cm_bm,FALSE); 1438 colorMenu->setItemChecked(cm_bm,FALSE);
1433 colorMenu->setItemChecked(cm_gy,FALSE); 1439 colorMenu->setItemChecked(cm_gy,FALSE);
1434 colorMenu->setItemChecked(cm_rb,FALSE); 1440 colorMenu->setItemChecked(cm_rb,FALSE);
1435 colorMenu->setItemChecked(cm_br,FALSE); 1441 colorMenu->setItemChecked(cm_br,FALSE);
1436 colorMenu->setItemChecked(cm_wb,FALSE); 1442 colorMenu->setItemChecked(cm_wb,FALSE);
1437 colorMenu->setItemChecked(cm_bw,FALSE); 1443 colorMenu->setItemChecked(cm_bw,FALSE);
1438 colorMenu->setItemChecked(cm_gb,FALSE); 1444 colorMenu->setItemChecked(cm_gb,FALSE);
1439 1445
1440 if(iD==cm_default) 1446 if(iD==cm_default)
1441 { // default default 1447 { // default default
1442 printf("default colors\n"); 1448 printf("default colors\n");
1443 for (i = 0; i < TABLE_COLORS; i++) 1449 for (i = 0; i < TABLE_COLORS; i++)
1444 { 1450 {
1445 m_table[i].color = defaultCt[i].color; 1451 m_table[i].color = defaultCt[i].color;
1446 if(i==1 || i == 11) 1452 if(i==1 || i == 11)
1447 m_table[i].transparent=1; 1453 m_table[i].transparent=1;
1448 colorMenu->setItemChecked(cm_default,TRUE); 1454 colorMenu->setItemChecked(cm_default,TRUE);
1449 } 1455 }
1450 te->setColorTable(m_table); 1456 te->setColorTable(m_table);
1451 } 1457 }
1452 if(iD==cm_gb) 1458 if(iD==cm_gb)
1453 { // green black 1459 { // green black
1454 foreground.setRgb(100,255,100); // (0x18,255,0x18); 1460 foreground.setRgb(100,255,100); // (0x18,255,0x18);
1455 background.setRgb(0x00,0x00,0x00); 1461 background.setRgb(0x00,0x00,0x00);
1456 colorMenu->setItemChecked(cm_gb,TRUE); 1462 colorMenu->setItemChecked(cm_gb,TRUE);
1457 } 1463 }
1458 if(iD==cm_bw) 1464 if(iD==cm_bw)
1459 { // black white 1465 { // black white
1460 foreground.setRgb(0x00,0x00,0x00); 1466 foreground.setRgb(0x00,0x00,0x00);
1461 background.setRgb(0xFF,0xFF,0xFF); 1467 background.setRgb(0xFF,0xFF,0xFF);
1462 colorMenu->setItemChecked(cm_bw,TRUE); 1468 colorMenu->setItemChecked(cm_bw,TRUE);
1463 } 1469 }
1464 if(iD==cm_wb) 1470 if(iD==cm_wb)
1465 { // white black 1471 { // white black
1466 foreground.setRgb(0xFF,0xFF,0xFF); 1472 foreground.setRgb(0xFF,0xFF,0xFF);
1467 background.setRgb(0x00,0x00,0x00); 1473 background.setRgb(0x00,0x00,0x00);
1468 colorMenu->setItemChecked(cm_wb,TRUE); 1474 colorMenu->setItemChecked(cm_wb,TRUE);
1469 } 1475 }
1470 if(iD==cm_br) 1476 if(iD==cm_br)
1471 {// Black, Red 1477 {// Black, Red
1472 foreground.setRgb(0x00,0x00,0x00); 1478 foreground.setRgb(0x00,0x00,0x00);
1473 background.setRgb(255,85,85); //(0xB2,0x18,0x18); 1479 background.setRgb(255,85,85); //(0xB2,0x18,0x18);
1474 colorMenu->setItemChecked(cm_br,TRUE); 1480 colorMenu->setItemChecked(cm_br,TRUE);
1475 } 1481 }
1476 if(iD==cm_rb) 1482 if(iD==cm_rb)
1477 {// Red, Black 1483 {// Red, Black
1478 foreground.setRgb(255,85,85); 1484 foreground.setRgb(255,85,85);
1479 background.setRgb(0x00,0x00,0x00); 1485 background.setRgb(0x00,0x00,0x00);
1480 colorMenu->setItemChecked(cm_rb,TRUE); 1486 colorMenu->setItemChecked(cm_rb,TRUE);
1481 } 1487 }
1482 if(iD==cm_gy) 1488 if(iD==cm_gy)
1483 {// Green, Yellow - is ugly 1489 {// Green, Yellow - is ugly
1484 // foreground.setRgb(0x18,0xB2,0x18); 1490 // foreground.setRgb(0x18,0xB2,0x18);
1485 foreground.setRgb(15,115,0); 1491 foreground.setRgb(15,115,0);
1486 // background.setRgb(0xB2,0x68,0x18); 1492 // background.setRgb(0xB2,0x68,0x18);
1487 background.setRgb(255,255,0); 1493 background.setRgb(255,255,0);
1488 colorMenu->setItemChecked(cm_gy,TRUE); 1494 colorMenu->setItemChecked(cm_gy,TRUE);
1489 } 1495 }
1490 if(iD==cm_bm) 1496 if(iD==cm_bm)
1491 {// Blue, Magenta 1497 {// Blue, Magenta
1492 foreground.setRgb(3,24,132); 1498 foreground.setRgb(3,24,132);
1493 background.setRgb(225,2,255); 1499 background.setRgb(225,2,255);
1494 colorMenu->setItemChecked(cm_bm,TRUE); 1500 colorMenu->setItemChecked(cm_bm,TRUE);
1495 } 1501 }
1496 if(iD==cm_mb) 1502 if(iD==cm_mb)
1497 {// Magenta, Blue 1503 {// Magenta, Blue
1498 foreground.setRgb(225,2,255); 1504 foreground.setRgb(225,2,255);
1499 background.setRgb(3,24,132); 1505 background.setRgb(3,24,132);
1500 colorMenu->setItemChecked(cm_mb,TRUE); 1506 colorMenu->setItemChecked(cm_mb,TRUE);
1501 } 1507 }
1502 if(iD==cm_cw) 1508 if(iD==cm_cw)
1503 {// Cyan, White 1509 {// Cyan, White
1504 foreground.setRgb(8,91,129); 1510 foreground.setRgb(8,91,129);
1505 background.setRgb(0xFF,0xFF,0xFF); 1511 background.setRgb(0xFF,0xFF,0xFF);
1506 colorMenu->setItemChecked(cm_cw,TRUE); 1512 colorMenu->setItemChecked(cm_cw,TRUE);
1507 } 1513 }
1508 if(iD==cm_wc) 1514 if(iD==cm_wc)
1509 {// White, Cyan 1515 {// White, Cyan
1510 background.setRgb(8,91,129); 1516 background.setRgb(8,91,129);
1511 foreground.setRgb(0xFF,0xFF,0xFF); 1517 foreground.setRgb(0xFF,0xFF,0xFF);
1512 colorMenu->setItemChecked(cm_wc,TRUE); 1518 colorMenu->setItemChecked(cm_wc,TRUE);
1513 } 1519 }
1514 if(iD==cm_bb) 1520 if(iD==cm_bb)
1515 {// Black, Blue 1521 {// Black, Blue
1516 background.setRgb(0x00,0x00,0x00); 1522 background.setRgb(0x00,0x00,0x00);
1517 foreground.setRgb(127,147,225); 1523 foreground.setRgb(127,147,225);
1518 colorMenu->setItemChecked(cm_bb,TRUE); 1524 colorMenu->setItemChecked(cm_bb,TRUE);
1519 } 1525 }
1520 if(iD==cm_ab) 1526 if(iD==cm_ab)
1521 {// Black, Gold 1527 {// Black, Gold
1522 background.setRgb(0x00,0x00,0x00); 1528 background.setRgb(0x00,0x00,0x00);
1523 foreground.setRgb(255,215,105); 1529 foreground.setRgb(255,215,105);
1524 colorMenu->setItemChecked(cm_ab,TRUE); 1530 colorMenu->setItemChecked(cm_ab,TRUE);
1525 } 1531 }
1526#ifdef QT_QWS_OPIE 1532#ifdef QT_QWS_OPIE
1527 if(iD==-19) 1533 if(iD==-19)
1528 { 1534 {
1529 // Custom 1535 // Custom
1530 odebug << "do custom" << oendl; 1536 odebug << "do custom" << oendl;
1531 if(fromMenu) 1537 if(fromMenu)
1532 { 1538 {
1533 Opie::OColorPopupMenu* penColorPopupMenu = new Opie::OColorPopupMenu(Qt::black, this, "foreground color"); 1539 Opie::OColorPopupMenu* penColorPopupMenu = new Opie::OColorPopupMenu(Qt::black, this, "foreground color");
1534 connect(penColorPopupMenu, SIGNAL(colorSelected(const QColor&)), this, 1540 connect(penColorPopupMenu, SIGNAL(colorSelected(const QColor&)), this,
1535 SLOT(changeForegroundColor(const QColor&))); 1541 SLOT(changeForegroundColor(const QColor&)));
1536 penColorPopupMenu->exec(); 1542 penColorPopupMenu->exec();
1537 } 1543 }
1538 if(!fromMenu) 1544 if(!fromMenu)
1539 { 1545 {
1540 foreground.setNamedColor(cfg.readEntry("foreground","")); 1546 foreground.setNamedColor(cfg.readEntry("foreground",""));
1541 background.setNamedColor(cfg.readEntry("background","")); 1547 background.setNamedColor(cfg.readEntry("background",""));
1542 } 1548 }
1543 fromMenu=FALSE; 1549 fromMenu=FALSE;
1544 colorMenu->setItemChecked(-19,TRUE); 1550 colorMenu->setItemChecked(-19,TRUE);
1545 } 1551 }
1546#endif 1552#endif
1547 1553
1548 lastSelectedMenu = iD; 1554 lastSelectedMenu = iD;
1549 1555
1550 setColors(foreground, background); 1556 setColors(foreground, background);
1551 1557
1552 QTabBar *tabBar = tab->getTabBar(); 1558 QTabBar *tabBar = tab->getTabBar();
1553 QString ss = QString("Session%1").arg(tabBar->currentTab()); 1559 QString ss = QString("Session%1").arg(tabBar->currentTab());
1554 // printf("current tab = %d\n", tabBar->currentTab()); 1560 // printf("current tab = %d\n", tabBar->currentTab());
1555 1561
1556 if (tabBar->currentTab() == 0) 1562 if (tabBar->currentTab() == 0)
1557 { 1563 {
1558 cfg.writeEntry("foregroundRed",QString::number(foreground.red())); 1564 cfg.writeEntry("foregroundRed",QString::number(foreground.red()));
1559 cfg.writeEntry("foregroundGreen",QString::number(foreground.green())); 1565 cfg.writeEntry("foregroundGreen",QString::number(foreground.green()));
1560 cfg.writeEntry("foregroundBlue",QString::number(foreground.blue())); 1566 cfg.writeEntry("foregroundBlue",QString::number(foreground.blue()));
1561 cfg.writeEntry("backgroundRed",QString::number(background.red())); 1567 cfg.writeEntry("backgroundRed",QString::number(background.red()));
1562 cfg.writeEntry("backgroundGreen",QString::number(background.green())); 1568 cfg.writeEntry("backgroundGreen",QString::number(background.green()));
1563 cfg.writeEntry("backgroundBlue",QString::number(background.blue())); 1569 cfg.writeEntry("backgroundBlue",QString::number(background.blue()));
1564 } 1570 }
1565 cfg.writeEntry("foregroundRed"+ss,QString::number(foreground.red())); 1571 cfg.writeEntry("foregroundRed"+ss,QString::number(foreground.red()));
1566 cfg.writeEntry("foregroundGreen"+ss,QString::number(foreground.green())); 1572 cfg.writeEntry("foregroundGreen"+ss,QString::number(foreground.green()));
1567 cfg.writeEntry("foregroundBlue"+ss,QString::number(foreground.blue())); 1573 cfg.writeEntry("foregroundBlue"+ss,QString::number(foreground.blue()));
1568 cfg.writeEntry("backgroundRed"+ss,QString::number(background.red())); 1574 cfg.writeEntry("backgroundRed"+ss,QString::number(background.red()));
1569 cfg.writeEntry("backgroundGreen"+ss,QString::number(background.green())); 1575 cfg.writeEntry("backgroundGreen"+ss,QString::number(background.green()));
1570 cfg.writeEntry("backgroundBlue"+ss,QString::number(background.blue())); 1576 cfg.writeEntry("backgroundBlue"+ss,QString::number(background.blue()));
1571 1577
1572 update(); 1578 update();
1573} 1579}
1574 1580
1575void Konsole::setColors(QColor foreground, QColor background) 1581void Konsole::setColors(QColor foreground, QColor background)
1576{ 1582{
1577 int i; 1583 int i;
1578 ColorEntry m_table[TABLE_COLORS]; 1584 ColorEntry m_table[TABLE_COLORS];
1579 TEWidget* te = getTe(); 1585 TEWidget* te = getTe();
1580 const ColorEntry * defaultCt=te->getdefaultColorTable(); 1586 const ColorEntry * defaultCt=te->getdefaultColorTable();
1581 1587
1582 for (i = 0; i < TABLE_COLORS; i++) 1588 for (i = 0; i < TABLE_COLORS; i++)
1583 { 1589 {
1584 if(i==0 || i == 10) 1590 if(i==0 || i == 10)
1585 { 1591 {
1586 m_table[i].color = foreground; 1592 m_table[i].color = foreground;
1587 } 1593 }
1588 else if(i==1 || i == 11) 1594 else if(i==1 || i == 11)
1589 { 1595 {
1590 m_table[i].color = background; 1596 m_table[i].color = background;
1591 m_table[i].transparent=0; 1597 m_table[i].transparent=0;
1592 } 1598 }
1593 else 1599 else
1594 m_table[i].color = defaultCt[i].color; 1600 m_table[i].color = defaultCt[i].color;
1595 } 1601 }
1596 te->setColorTable(m_table); 1602 te->setColorTable(m_table);
1597} 1603}
1598 1604
1599void Konsole::tabMenuSelected(int id) 1605void Konsole::tabMenuSelected(int id)
1600{ 1606{
1601 Config cfg( "Konsole" ); 1607 Config cfg( "Konsole" );
1602 cfg.setGroup("Tabs"); 1608 cfg.setGroup("Tabs");
1603 tabMenu->setItemChecked(tabPos, false); 1609 tabMenu->setItemChecked(tabPos, false);
1604 if (id == tm_bottom) 1610 if (id == tm_bottom)
1605 { 1611 {
1606 printf("set bottom tab\n"); 1612 printf("set bottom tab\n");
1607 tab->getTabBar()->show(); 1613 tab->getTabBar()->show();
1608 tab->setTabPosition(QTabWidget::Bottom); 1614 tab->setTabPosition(QTabWidget::Bottom);
1609 tab->getTabBar()->show(); 1615 tab->getTabBar()->show();
1610 cfg.writeEntry("Position","Bottom"); 1616 cfg.writeEntry("Position","Bottom");
1611 } 1617 }
1612 else if (id == tm_top) 1618 else if (id == tm_top)
1613 { 1619 {
1614 printf("set top tab\n"); 1620 printf("set top tab\n");
1615 tab->getTabBar()->show(); 1621 tab->getTabBar()->show();
1616 tab->setTabPosition(QTabWidget::Bottom); 1622 tab->setTabPosition(QTabWidget::Bottom);
1617 tab->setTabPosition(QTabWidget::Top); 1623 tab->setTabPosition(QTabWidget::Top);
1618 tab->getTabBar()->show(); 1624 tab->getTabBar()->show();
1619 cfg.writeEntry("Position","Top"); 1625 cfg.writeEntry("Position","Top");
1620 } 1626 }
1621 else if (id == tm_hidden) 1627 else if (id == tm_hidden)
1622 { 1628 {
1623 tab->getTabBar()->hide(); 1629 tab->getTabBar()->hide();
1624 tab->setMargin(tab->margin()); 1630 tab->setMargin(tab->margin());
1625 cfg.writeEntry("Position","Hidden"); 1631 cfg.writeEntry("Position","Hidden");
1626 } 1632 }
1627 tabMenu->setItemChecked(id, true); 1633 tabMenu->setItemChecked(id, true);
1628 tabPos = id; 1634 tabPos = id;
1629} 1635}
1630 1636
1631 1637
1632void Konsole::configMenuSelected(int iD) 1638void Konsole::configMenuSelected(int iD)
1633{ 1639{
1634 // QString temp; 1640 // QString temp;
1635 // odebug << temp.sprintf("configmenu " << iD) << "" << oendl; 1641 // odebug << temp.sprintf("configmenu " << iD) << "" << oendl;
1636 1642
1637 TEWidget* te = getTe(); 1643 TEWidget* te = getTe();
1638 Config cfg( "Konsole" ); 1644 Config cfg( "Konsole" );
1639 cfg.setGroup("Menubar"); 1645 cfg.setGroup("Menubar");
1640 if(iD == cm_wrap) 1646 if(iD == cm_wrap)
1641 { 1647 {
1642 cfg.setGroup("ScrollBar"); 1648 cfg.setGroup("ScrollBar");
1643 bool b=cfg.readBoolEntry("HorzScroll",0); 1649 bool b=cfg.readBoolEntry("HorzScroll",0);
1644 b=!b; 1650 b=!b;
1645 cfg.writeEntry("HorzScroll", b ); 1651 cfg.writeEntry("HorzScroll", b );
1646 cfg.write(); 1652 cfg.write();
1647 doWrap(); 1653 doWrap();
1648 if(cfg.readNumEntry("Position",2) == 0) 1654 if(cfg.readNumEntry("Position",2) == 0)
1649 { 1655 {
1650 te->setScrollbarLocation(1); 1656 te->setScrollbarLocation(1);
1651 } 1657 }
1652 else 1658 else
1653 { 1659 {
1654 te->setScrollbarLocation(0); 1660 te->setScrollbarLocation(0);
1655 } 1661 }
1656 te->setScrollbarLocation( cfg.readNumEntry("Position",2)); 1662 te->setScrollbarLocation( cfg.readNumEntry("Position",2));
1657 } 1663 }
1658 if(iD == cm_beep) 1664 if(iD == cm_beep)
1659 { 1665 {
1660 cfg.setGroup("Menubar"); 1666 cfg.setGroup("Menubar");
1661 bool b=cfg.readBoolEntry("useBeep",0); 1667 bool b=cfg.readBoolEntry("useBeep",0);
1662 b=!b; 1668 b=!b;
1663 cfg.writeEntry("useBeep", b ); 1669 cfg.writeEntry("useBeep", b );
1664 cfg.write(); 1670 cfg.write();
1665 configMenu->setItemChecked(cm_beep,b); 1671 configMenu->setItemChecked(cm_beep,b);
1666 te->useBeep=b; 1672 te->useBeep=b;
1667 } 1673 }
1668} 1674}
1669 1675
1670void Konsole::changeCommand(const QString &text, int c) 1676void Konsole::changeCommand(const QString &text, int c)
1671{ 1677{
1672 Config cfg( "Konsole" ); 1678 Config cfg( "Konsole" );
1673 cfg.setGroup("Commands"); 1679 cfg.setGroup("Commands");
1674 if(commonCmds[c] != text) 1680 if(commonCmds[c] != text)
1675 { 1681 {
1676 cfg.writeEntry(QString::number(c),text); 1682 cfg.writeEntry(QString::number(c),text);
1677 commonCombo->clearEdit(); 1683 commonCombo->clearEdit();
1678 commonCombo->setCurrentItem(c); 1684 commonCombo->setCurrentItem(c);
1679 } 1685 }
1680} 1686}
1681 1687
1682void Konsole::setColor(int sess) 1688void Konsole::setColor(int sess)
1683{ 1689{
1684 Config cfg( "Konsole" ); 1690 Config cfg( "Konsole" );
1685 cfg.setGroup("Colors"); 1691 cfg.setGroup("Colors");
1686 QColor foreground, background; 1692 QColor foreground, background;
1687 QString ss = QString("Session") + QString::number(sess); 1693 QString ss = QString("Session") + QString::number(sess);
1688 foreground.setRgb(cfg.readNumEntry("foregroundRed"+ss, 1694 foreground.setRgb(cfg.readNumEntry("foregroundRed"+ss,
1689 cfg.readNumEntry("foregroundRed",0xff)), 1695 cfg.readNumEntry("foregroundRed",0xff)),
1690 cfg.readNumEntry("foregroundGreen"+ss, 1696 cfg.readNumEntry("foregroundGreen"+ss,
1691 cfg.readNumEntry("foregroundGreen",0xff)), 1697 cfg.readNumEntry("foregroundGreen",0xff)),
1692 cfg.readNumEntry("foregroundBlue"+ss, 1698 cfg.readNumEntry("foregroundBlue"+ss,
1693 cfg.readNumEntry("foregroundBlue",0xff))); 1699 cfg.readNumEntry("foregroundBlue",0xff)));
1694 background.setRgb(cfg.readNumEntry("backgroundRed"+ss, 1700 background.setRgb(cfg.readNumEntry("backgroundRed"+ss,
1695 cfg.readNumEntry("backgroundRed",0)), 1701 cfg.readNumEntry("backgroundRed",0)),
1696 cfg.readNumEntry("backgroundGreen"+ss, 1702 cfg.readNumEntry("backgroundGreen"+ss,
1697 cfg.readNumEntry("backgroundGreen",0)), 1703 cfg.readNumEntry("backgroundGreen",0)),
1698 cfg.readNumEntry("backgroundBlue"+ss, 1704 cfg.readNumEntry("backgroundBlue"+ss,
1699 cfg.readNumEntry("backgroundBlue",0))); 1705 cfg.readNumEntry("backgroundBlue",0)));
1700 setColors(foreground, background); 1706 setColors(foreground, background);
1701} 1707}
1702 1708
1703void Konsole::scrollMenuSelected(int index) 1709void Konsole::scrollMenuSelected(int index)
1704{ 1710{
1705 // odebug << "scrollbar menu " << index << "" << oendl; 1711 // odebug << "scrollbar menu " << index << "" << oendl;
1706 1712
1707 TEWidget* te = getTe(); 1713 TEWidget* te = getTe();
1708 Config cfg( "Konsole" ); 1714 Config cfg( "Konsole" );
1709 cfg.setGroup("ScrollBar"); 1715 cfg.setGroup("ScrollBar");
1710 1716
1711 if(index == sm_none) 1717 if(index == sm_none)
1712 { 1718 {
1713 te->setScrollbarLocation(0); 1719 te->setScrollbarLocation(0);
1714 cfg.writeEntry("Position",0); 1720 cfg.writeEntry("Position",0);
1715 } 1721 }
1716 else if(index == sm_left) 1722 else if(index == sm_left)
1717 { 1723 {
1718 te->setScrollbarLocation(1); 1724 te->setScrollbarLocation(1);
1719 cfg.writeEntry("Position",1); 1725 cfg.writeEntry("Position",1);
1720 } 1726 }
1721 else if(index == sm_right) 1727 else if(index == sm_right)
1722 { 1728 {
1723 te->setScrollbarLocation(2); 1729 te->setScrollbarLocation(2);
1724 cfg.writeEntry("Position",2); 1730 cfg.writeEntry("Position",2);
1725 } 1731 }
1726 scrollMenu->setItemChecked(sm_none, index == sm_none); 1732 scrollMenu->setItemChecked(sm_none, index == sm_none);
1727 scrollMenu->setItemChecked(sm_left, index == sm_left); 1733 scrollMenu->setItemChecked(sm_left, index == sm_left);
1728 scrollMenu->setItemChecked(sm_right, index == sm_right); 1734 scrollMenu->setItemChecked(sm_right, index == sm_right);
1729} 1735}
1730 1736
1731// case -29: { 1737// case -29: {
1732// bool b=cfg.readBoolEntry("HorzScroll",0); 1738// bool b=cfg.readBoolEntry("HorzScroll",0);
1733// cfg.writeEntry("HorzScroll", !b ); 1739// cfg.writeEntry("HorzScroll", !b );
1734// cfg.write(); 1740// cfg.write();
1735// if(cfg.readNumEntry("Position",2) == 0) { 1741// if(cfg.readNumEntry("Position",2) == 0) {
1736// te->setScrollbarLocation(1); 1742// te->setScrollbarLocation(1);
1737// te->setWrapAt(0); 1743// te->setWrapAt(0);
1738// } else { 1744// } else {
1739// te->setScrollbarLocation(0); 1745// te->setScrollbarLocation(0);
1740// te->setWrapAt(120); 1746// te->setWrapAt(120);
1741// } 1747// }
1742// te->setScrollbarLocation( cfg.readNumEntry("Position",2)); 1748// te->setScrollbarLocation( cfg.readNumEntry("Position",2));
1743// } 1749// }
1744// break; 1750// break;
1745 1751
1746void Konsole::editCommandListMenuSelected(int iD) 1752void Konsole::editCommandListMenuSelected(int iD)
1747{ 1753{
1748 // QString temp; 1754 // QString temp;
1749 // odebug << temp.sprintf("edit command list " << iD) << "" << oendl; 1755 // odebug << temp.sprintf("edit command list " << iD) << "" << oendl;
1750 1756
1751 // FIXME: more cleanup needed here 1757 // FIXME: more cleanup needed here
1752 1758
1753 1759
1754 TEWidget* te = getTe(); 1760 TEWidget* te = getTe();
1755 Config cfg( "Konsole" ); 1761 Config cfg( "Konsole" );
1756 cfg.setGroup("Menubar"); 1762 cfg.setGroup("Menubar");
1757 if( iD == ec_cmdlist) 1763 if( iD == ec_cmdlist)
1758 { 1764 {
1759 if(!secondToolBar->isHidden()) 1765 if(!secondToolBar->isHidden())
1760 { 1766 {
1761 secondToolBar->hide(); 1767 secondToolBar->hide();
1762 configMenu->changeItem( iD,tr( "Show Command List" )); 1768 configMenu->changeItem( iD,tr( "Show Command List" ));
1763 cfg.writeEntry("Hidden","TRUE"); 1769 cfg.writeEntry("Hidden","TRUE");
1764 configMenu->setItemEnabled(ec_edit ,FALSE); 1770 configMenu->setItemEnabled(ec_edit ,FALSE);
1765 configMenu->setItemEnabled(ec_quick ,FALSE); 1771 configMenu->setItemEnabled(ec_quick ,FALSE);
1766 } 1772 }
1767 else 1773 else
1768 { 1774 {
1769 secondToolBar->show(); 1775 secondToolBar->show();
1770 configMenu->changeItem( iD,tr( "Hide Command List" )); 1776 configMenu->changeItem( iD,tr( "Hide Command List" ));
1771 cfg.writeEntry("Hidden","FALSE"); 1777 cfg.writeEntry("Hidden","FALSE");
1772 configMenu->setItemEnabled(ec_edit ,TRUE); 1778 configMenu->setItemEnabled(ec_edit ,TRUE);
1773 configMenu->setItemEnabled(ec_quick ,TRUE); 1779 configMenu->setItemEnabled(ec_quick ,TRUE);
1774 1780
1775 if(cfg.readEntry("EditEnabled","FALSE")=="TRUE") 1781 if(cfg.readEntry("EditEnabled","FALSE")=="TRUE")
1776 { 1782 {
1777 configMenu->setItemChecked(ec_edit,TRUE); 1783 configMenu->setItemChecked(ec_edit,TRUE);
1778 commonCombo->setEditable( TRUE ); 1784 commonCombo->setEditable( TRUE );
1779 } 1785 }
1780 else 1786 else
1781 { 1787 {
1782 configMenu->setItemChecked(ec_edit,FALSE); 1788 configMenu->setItemChecked(ec_edit,FALSE);
1783 commonCombo->setEditable( FALSE ); 1789 commonCombo->setEditable( FALSE );
1784 } 1790 }
1785 } 1791 }
1786 } 1792 }
1787 if( iD == ec_quick) 1793 if( iD == ec_quick)
1788 { 1794 {
1789 cfg.setGroup("Commands"); 1795 cfg.setGroup("Commands");
1790 // odebug << "enableCommandEdit" << oendl; 1796 // odebug << "enableCommandEdit" << oendl;
1791 if( !configMenu->isItemChecked(iD) ) 1797 if( !configMenu->isItemChecked(iD) )
1792 { 1798 {
1793 commonCombo->setEditable( TRUE ); 1799 commonCombo->setEditable( TRUE );
1794 configMenu->setItemChecked(iD,TRUE); 1800 configMenu->setItemChecked(iD,TRUE);
1795 commonCombo->setCurrentItem(0); 1801 commonCombo->setCurrentItem(0);
1796 cfg.writeEntry("EditEnabled","TRUE"); 1802 cfg.writeEntry("EditEnabled","TRUE");
1797 } 1803 }
1798 else 1804 else
1799 { 1805 {
1800 commonCombo->setEditable( FALSE ); 1806 commonCombo->setEditable( FALSE );
1801 configMenu->setItemChecked(iD,FALSE); 1807 configMenu->setItemChecked(iD,FALSE);
1802 cfg.writeEntry("EditEnabled","FALSE"); 1808 cfg.writeEntry("EditEnabled","FALSE");
1803 commonCombo->setFocusPolicy(QWidget::NoFocus); 1809 commonCombo->setFocusPolicy(QWidget::NoFocus);
1804 te->setFocus(); 1810 te->setFocus();
1805 } 1811 }
1806 } 1812 }
1807 if(iD == ec_edit) 1813 if(iD == ec_edit)
1808 { 1814 {
1809 // "edit commands" 1815 // "edit commands"
1810 CommandEditDialog *m = new CommandEditDialog(this); 1816 CommandEditDialog *m = new CommandEditDialog(this);
1811 connect(m,SIGNAL(commandsEdited()),this,SLOT(initCommandList())); 1817 connect(m,SIGNAL(commandsEdited()),this,SLOT(initCommandList()));
1812 m->showMaximized(); 1818 m->showMaximized();
1813 } 1819 }
1814 1820
1815} 1821}
1816 1822
1817// $QPEDIR/bin/qcop QPE/Application/embeddedkonsole 'setDocument(QString)' 'ssh -V' 1823// $QPEDIR/bin/qcop QPE/Application/embeddedkonsole 'setDocument(QString)' 'ssh -V'
1818void Konsole::setDocument( const QString &cmd) 1824void Konsole::setDocument( const QString &cmd)
1819{ 1825{
1820 newSession(); 1826 newSession();
1821 TEWidget* te = getTe(); 1827 TEWidget* te = getTe();
1822 if(cmd.find("-e", 0, TRUE) != -1) 1828 if(cmd.find("-e", 0, TRUE) != -1)
1823 { 1829 {
1824 QString cmd2; 1830 QString cmd2;
1825 cmd2=cmd.right(cmd.length()-3)+" &"; 1831 cmd2=cmd.right(cmd.length()-3)+" &";
1826 system(cmd2.latin1()); 1832 system(cmd2.latin1());
1827 if(startUp <= 1 && nsessions < 2) 1833 if(startUp <= 1 && nsessions < 2)
1828 { 1834 {
1829 doneSession(getTe(), 0); 1835 doneSession(getTe(), 0);
1830 exit(0); 1836 exit(0);
1831 } 1837 }
1832 else 1838 else
1833 doneSession(getTe(), 0); 1839 doneSession(getTe(), 0);
1834 } 1840 }
1835 else 1841 else
1836 { 1842 {
1837 if (te != 0) 1843 if (te != 0)
1838 { 1844 {
1839 te->emitText(cmd+"\r"); 1845 te->emitText(cmd+"\r");
1840 } 1846 }
1841 } 1847 }
1842 startUp++; 1848 startUp++;
1843} 1849}
1844 1850
1845 1851
1846// what is the point of this when you can just 1852// what is the point of this when you can just
1847// run commands by using the shell directly?? 1853// run commands by using the shell directly??
1848void Konsole::parseCommandLine() 1854void Konsole::parseCommandLine()
1849{ 1855{
1850 QString cmd; 1856 QString cmd;
1851 // newSession(); 1857 // newSession();
1852 for (int i=1;i< qApp->argc();i++) 1858 for (int i=1;i< qApp->argc();i++)
1853 { 1859 {
1854 if( QString(qApp->argv()[i]) == "-e") 1860 if( QString(qApp->argv()[i]) == "-e")
1855 { 1861 {
1856 i++; 1862 i++;
1857 for ( int j=i;j< qApp->argc();j++) 1863 for ( int j=i;j< qApp->argc();j++)
1858 { 1864 {
1859 cmd+=QString(qApp->argv()[j])+" "; 1865 cmd+=QString(qApp->argv()[j])+" ";
1860 } 1866 }
1861 cmd.stripWhiteSpace(); 1867 cmd.stripWhiteSpace();
1862 system(cmd.latin1()); 1868 system(cmd.latin1());
1863 exit(0);//close(); 1869 exit(0);//close();
1864 } // end -e switch 1870 } // end -e switch
1865 } 1871 }
1866 startUp++; 1872 startUp++;
1867} 1873}
1868 1874
1869void Konsole::changeForegroundColor(const QColor &color) 1875void Konsole::changeForegroundColor(const QColor &color)
1870{ 1876{
1871 Config cfg( "Konsole" ); 1877 Config cfg( "Konsole" );
1872 cfg.setGroup("Colors"); 1878 cfg.setGroup("Colors");
1873 int r, g, b; 1879 int r, g, b;
1874 color.rgb(&r,&g,&b); 1880 color.rgb(&r,&g,&b);
1875 foreground.setRgb(r,g,b); 1881 foreground.setRgb(r,g,b);
1876 1882
1877 cfg.writeEntry("foreground",color.name()); 1883 cfg.writeEntry("foreground",color.name());
1878 odebug << "foreground "+color.name() << oendl; 1884 odebug << "foreground "+color.name() << oendl;
1879 cfg.write(); 1885 cfg.write();
1880 1886
1881 odebug << "do other dialog" << oendl; 1887 odebug << "do other dialog" << oendl;
1882#ifdef QT_QWS_OPIE 1888#ifdef QT_QWS_OPIE
1883 1889
1884 Opie::OColorPopupMenu* penColorPopupMenu2 = new Opie::OColorPopupMenu(Qt::black, this,"background color"); 1890 Opie::OColorPopupMenu* penColorPopupMenu2 = new Opie::OColorPopupMenu(Qt::black, this,"background color");
1885 connect(penColorPopupMenu2, SIGNAL(colorSelected(const QColor&)), this, 1891 connect(penColorPopupMenu2, SIGNAL(colorSelected(const QColor&)), this,
1886 SLOT(changeBackgroundColor(const QColor&))); 1892 SLOT(changeBackgroundColor(const QColor&)));
1887 penColorPopupMenu2->exec(); 1893 penColorPopupMenu2->exec();
1888#endif 1894#endif
1889} 1895}
1890 1896
1891void Konsole::changeBackgroundColor(const QColor &color) 1897void Konsole::changeBackgroundColor(const QColor &color)
1892{ 1898{
1893 1899
1894 odebug << "Change background" << oendl; 1900 odebug << "Change background" << oendl;
1895 Config cfg( "Konsole" ); 1901 Config cfg( "Konsole" );
1896 cfg.setGroup("Colors"); 1902 cfg.setGroup("Colors");
1897 int r, g, b; 1903 int r, g, b;
1898 color.rgb(&r,&g,&b); 1904 color.rgb(&r,&g,&b);
1899 background.setRgb(r,g,b); 1905 background.setRgb(r,g,b);
1900 cfg.writeEntry("background",color.name()); 1906 cfg.writeEntry("background",color.name());
1901 odebug << "background "+color.name() << oendl; 1907 odebug << "background "+color.name() << oendl;
1902 cfg.write(); 1908 cfg.write();
1903} 1909}
1904 1910
1905void Konsole::doWrap() 1911void Konsole::doWrap()
1906{ 1912{
1907 Config cfg( "Konsole" ); 1913 Config cfg( "Konsole" );
1908 cfg.setGroup("ScrollBar"); 1914 cfg.setGroup("ScrollBar");
1909 TEWidget* te = getTe(); 1915 TEWidget* te = getTe();
1910 if( !cfg.readBoolEntry("HorzScroll",0)) 1916 if( !cfg.readBoolEntry("HorzScroll",0))
1911 { 1917 {
1912 te->setWrapAt(0); 1918 te->setWrapAt(0);
1913 configMenu->setItemChecked( cm_wrap,TRUE); 1919 configMenu->setItemChecked( cm_wrap,TRUE);
1914 } 1920 }
1915 else 1921 else
1916 { 1922 {
1917 // te->setWrapAt(90); 1923 // te->setWrapAt(90);
1918 te->setWrapAt(120); 1924 te->setWrapAt(120);
1919 configMenu->setItemChecked( cm_wrap,FALSE); 1925 configMenu->setItemChecked( cm_wrap,FALSE);
1920 } 1926 }
1921} 1927}
1922void Konsole::closeSession() { 1928void Konsole::closeSession() {
1923 doneSession(getTe(), 0); 1929 doneSession(getTe(), 0);
1924} 1930}
diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp
index 61beac5..4bbc62b 100644
--- a/core/apps/textedit/textedit.cpp
+++ b/core/apps/textedit/textedit.cpp
@@ -1,1213 +1,1191 @@
1/********************************************************************** 1/**********************************************************************
2// textedit.cpp 2// textedit.cpp
3** Copyright (C) 2000 Trolltech AS. All rights reserved. 3** Copyright (C) 2000 Trolltech AS. All rights reserved.
4** 4**
5** This file is part of Opie Environment. 5** This file is part of Opie Environment.
6** 6**
7** This file may be distributed and/or modified under the terms of the 7** This file may be distributed and/or modified under the terms of the
8** GNU General Public License version 2 as published by the Free Software 8** GNU General Public License version 2 as published by the Free Software
9** Foundation and appearing in the file LICENSE.GPL included in the 9** Foundation and appearing in the file LICENSE.GPL included in the
10** packaging of this file. 10** packaging of this file.
11** 11**
12**********************************************************************/ 12**********************************************************************/
13// changes added by L. J. Potter Sun 02-17-2002 21:31:31 13// changes added by L. J. Potter Sun 02-17-2002 21:31:31
14 14
15#include "textedit.h" 15#include "textedit.h"
16#include "filePermissions.h" 16#include "filePermissions.h"
17 17
18/* OPIE */ 18/* OPIE */
19#include <opie2/odebug.h> 19#include <opie2/odebug.h>
20#include <opie2/ofileselector.h> 20#include <opie2/ofileselector.h>
21#include <opie2/ofiledialog.h> 21#include <opie2/ofiledialog.h>
22#include <opie2/ofontselector.h> 22#include <opie2/ofontselector.h>
23#include <opie2/oresource.h> 23#include <opie2/oresource.h>
24 24
25#include <qpe/config.h> 25#include <qpe/config.h>
26#include <qpe/qpeapplication.h> 26#include <qpe/qpeapplication.h>
27 27
28 28
29/* QT */ 29/* QT */
30#include <qmenubar.h> 30#include <qmenubar.h>
31#include <qtoolbar.h> 31#include <qtoolbar.h>
32#include <qtextstream.h> 32#include <qtextstream.h>
33#include <qclipboard.h> 33#include <qclipboard.h>
34#include <qaction.h> 34#include <qaction.h>
35#include <qlineedit.h> 35#include <qlineedit.h>
36#include <qmessagebox.h> 36#include <qmessagebox.h>
37#include <qlayout.h> 37#include <qlayout.h>
38#include <qtimer.h> 38#include <qtimer.h>
39#include <qdir.h> 39#include <qdir.h>
40 40
41/* STD */ 41/* STD */
42#include <unistd.h> 42#include <unistd.h>
43#include <sys/stat.h> 43#include <sys/stat.h>
44#include <stdlib.h> //getenv 44#include <stdlib.h> //getenv
45 45
46using namespace Opie::Core; 46using namespace Opie::Core;
47using namespace Opie::Ui; 47using namespace Opie::Ui;
48 48
49#if QT_VERSION < 0x030000 49#if QT_VERSION < 0x030000
50class QpeEditor : public QMultiLineEdit 50class QpeEditor : public QMultiLineEdit
51{ 51{
52 52
53public: 53public:
54 QpeEditor( QWidget *parent, const char * name = 0 ) 54 QpeEditor( QWidget *parent, const char * name = 0 )
55 : QMultiLineEdit( parent, name ) { 55 : QMultiLineEdit( parent, name ) {
56 clearTableFlags(); 56 clearTableFlags();
57 setTableFlags( Tbl_vScrollBar | Tbl_autoHScrollBar ); 57 setTableFlags( Tbl_vScrollBar | Tbl_autoHScrollBar );
58} 58}
59 59
60 void find( const QString &txt, bool caseSensitive, 60 void find( const QString &txt, bool caseSensitive,
61 bool backwards ); 61 bool backwards );
62protected: 62protected:
63 bool markIt; 63 bool markIt;
64 int line1, line2, col1, col2; 64 int line1, line2, col1, col2;
65 void mousePressEvent( QMouseEvent * ); 65 void mousePressEvent( QMouseEvent * );
66 void mouseReleaseEvent( QMouseEvent * ); 66 void mouseReleaseEvent( QMouseEvent * );
67 67
68//public slots: 68//public slots:
69 /* 69 /*
70signals: 70signals:
71 void notFound(); 71 void notFound();
72 void searchWrapped(); 72 void searchWrapped();
73 */ 73 */
74 74
75private: 75private:
76 76
77}; 77};
78 78
79void QpeEditor::mousePressEvent( QMouseEvent *e ) { 79void QpeEditor::mousePressEvent( QMouseEvent *e ) {
80 switch(e->button()) { 80 switch(e->button()) {
81 case RightButton: 81 case RightButton:
82 { //rediculous workaround for qt popup menu 82 { //rediculous workaround for qt popup menu
83 //and the hold right click mechanism 83 //and the hold right click mechanism
84 this->setSelection( line1, col1, line2, col2); 84 this->setSelection( line1, col1, line2, col2);
85 QMultiLineEdit::mousePressEvent( e ); 85 QMultiLineEdit::mousePressEvent( e );
86 markIt = false; 86 markIt = false;
87 } 87 }
88 break; 88 break;
89 default: 89 default:
90 { 90 {
91 if(!markIt) { 91 if(!markIt) {
92 int line, col; 92 int line, col;
93 this->getCursorPosition(&line, &col); 93 this->getCursorPosition(&line, &col);
94 line1=line2=line; 94 line1=line2=line;
95 col1=col2=col; 95 col1=col2=col;
96 } 96 }
97 QMultiLineEdit::mousePressEvent( e ); 97 QMultiLineEdit::mousePressEvent( e );
98 } 98 }
99 break; 99 break;
100 }; 100 };
101} 101}
102 102
103void QpeEditor::mouseReleaseEvent( QMouseEvent * ) { 103void QpeEditor::mouseReleaseEvent( QMouseEvent * ) {
104 if(this->hasMarkedText()) { 104 if(this->hasMarkedText()) {
105 markIt = true; 105 markIt = true;
106 this->getMarkedRegion( &line1, &col1, &line2, & col2 ); 106 this->getMarkedRegion( &line1, &col1, &line2, & col2 );
107 } else { 107 } else {
108 markIt = false; 108 markIt = false;
109 } 109 }
110} 110}
111 111
112void QpeEditor::find ( const QString &txt, bool caseSensitive, 112void QpeEditor::find ( const QString &txt, bool caseSensitive,
113 bool backwards ) 113 bool backwards )
114{ 114{
115 static bool wrap = false; 115 static bool wrap = false;
116 int line, col; 116 int line, col;
117 if ( wrap ) { 117 if ( wrap ) {
118 if ( !backwards ) 118 if ( !backwards )
119 line = col = 0; 119 line = col = 0;
120 wrap = false; 120 wrap = false;
121 // emit searchWrapped(); 121 // emit searchWrapped();
122 } else { 122 } else {
123 getCursorPosition( &line, &col ); 123 getCursorPosition( &line, &col );
124 } 124 }
125 //ignore backwards for now.... 125 //ignore backwards for now....
126 if ( !backwards ) { 126 if ( !backwards ) {
127 for ( ; ; ) { 127 for ( ; ; ) {
128 if ( line >= numLines() ) { 128 if ( line >= numLines() ) {
129 wrap = true; 129 wrap = true;
130 //emit notFound(); 130 //emit notFound();
131 break; 131 break;
132 } 132 }
133 int findCol = getString( line )->find( txt, col, caseSensitive ); 133 int findCol = getString( line )->find( txt, col, caseSensitive );
134 if ( findCol >= 0 ) { 134 if ( findCol >= 0 ) {
135 setCursorPosition( line, findCol, false ); 135 setCursorPosition( line, findCol, false );
136 col = findCol + txt.length(); 136 col = findCol + txt.length();
137 setCursorPosition( line, col, true ); 137 setCursorPosition( line, col, true );
138 138
139 //found = true; 139 //found = true;
140 break; 140 break;
141 } 141 }
142 line++; 142 line++;
143 col = 0; 143 col = 0;
144 } 144 }
145 } 145 }
146} 146}
147 147
148 148
149#else 149#else
150 150
151#error "Must make a QpeEditor that inherits QTextEdit" 151#error "Must make a QpeEditor that inherits QTextEdit"
152 152
153#endif 153#endif
154 154
155 155
156static const int nfontsizes = 6; 156static const int nfontsizes = 6;
157static const int fontsize[nfontsizes] = {8,10,12,14,18,24}; 157static const int fontsize[nfontsizes] = {8,10,12,14,18,24};
158 158
159TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) 159TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f )
160 : QMainWindow( parent, name, f ), bFromDocView( false ) 160 : QMainWindow( parent, name, f ), bFromDocView( false )
161{ 161{
162 doc = 0; 162 doc = 0;
163 edited=false; 163 edited=false;
164 fromSetDocument=false; 164 fromSetDocument=false;
165 165
166 setToolBarsMovable( false ); 166 setToolBarsMovable( false );
167 connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) ); 167 connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) );
168 168
169 channel = new QCopChannel( "QPE/Application/textedit", this ); 169 channel = new QCopChannel( "QPE/Application/textedit", this );
170 connect( channel, SIGNAL(received(const QCString&,const QByteArray&)), 170 connect( channel, SIGNAL(received(const QCString&,const QByteArray&)),
171 this, SLOT(receive(const QCString&,const QByteArray&)) ); 171 this, SLOT(receive(const QCString&,const QByteArray&)) );
172 172
173 setIcon( Opie::Core::OResource::loadPixmap( "textedit/TextEditor", Opie::Core::OResource::SmallIcon ) ); 173 setIcon( Opie::Core::OResource::loadPixmap( "textedit/TextEditor", Opie::Core::OResource::SmallIcon ) );
174 174
175 QToolBar *bar = new QToolBar( this ); 175 QToolBar *bar = new QToolBar( this );
176 bar->setHorizontalStretchable( true ); 176 bar->setHorizontalStretchable( true );
177 menu = bar; 177 menu = bar;
178 178
179 QMenuBar *mb = new QMenuBar( bar ); 179 QMenuBar *mb = new QMenuBar( bar );
180 QPopupMenu *file = new QPopupMenu( this ); 180 QPopupMenu *file = new QPopupMenu( this );
181 QPopupMenu *edit = new QPopupMenu( this ); 181 QPopupMenu *edit = new QPopupMenu( this );
182 QPopupMenu *advancedMenu = new QPopupMenu(this); 182 QPopupMenu *advancedMenu = new QPopupMenu(this);
183 183
184 font = new QPopupMenu( this ); 184 font = new QPopupMenu( this );
185 185
186 bar = new QToolBar( this ); 186 bar = new QToolBar( this );
187 editBar = bar; 187 editBar = bar;
188 188
189 QAction *a = new QAction( tr( "New" ), Opie::Core::OResource::loadPixmap( "new", Opie::Core::OResource::SmallIcon ), 189 QAction *a = new QAction( tr( "New" ), Opie::Core::OResource::loadPixmap( "new", Opie::Core::OResource::SmallIcon ),
190 QString::null, 0, this, 0 ); 190 QString::null, 0, this, 0 );
191 connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) ); 191 connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) );
192// a->addTo( bar ); 192// a->addTo( bar );
193 a->addTo( file ); 193 a->addTo( file );
194 194
195 a = new QAction( tr( "Open" ), Opie::Core::OResource::loadPixmap( "fileopen", Opie::Core::OResource::SmallIcon ), 195 a = new QAction( tr( "Open" ), Opie::Core::OResource::loadPixmap( "fileopen", Opie::Core::OResource::SmallIcon ),
196 QString::null, 0, this, 0 ); 196 QString::null, 0, this, 0 );
197 connect( a, SIGNAL( activated() ), this, SLOT( fileOpen() ) ); 197 connect( a, SIGNAL( activated() ), this, SLOT( fileOpen() ) );
198 a->addTo( bar ); 198 a->addTo( bar );
199 a->addTo( file ); 199 a->addTo( file );
200 200
201 a = new QAction( tr( "Save" ), Opie::Core::OResource::loadPixmap( "save", Opie::Core::OResource::SmallIcon ), 201 a = new QAction( tr( "Save" ), Opie::Core::OResource::loadPixmap( "save", Opie::Core::OResource::SmallIcon ),
202 QString::null, 0, this, 0 ); 202 QString::null, 0, this, 0 );
203 connect( a, SIGNAL( activated() ), this, SLOT( save() ) ); 203 connect( a, SIGNAL( activated() ), this, SLOT( save() ) );
204 file->insertSeparator(); 204 file->insertSeparator();
205 a->addTo( bar ); 205 a->addTo( bar );
206 a->addTo( file ); 206 a->addTo( file );
207 207
208 a = new QAction( tr( "Save As" ), Opie::Core::OResource::loadPixmap( "save", Opie::Core::OResource::SmallIcon ), 208 a = new QAction( tr( "Save As" ), Opie::Core::OResource::loadPixmap( "save", Opie::Core::OResource::SmallIcon ),
209 QString::null, 0, this, 0 ); 209 QString::null, 0, this, 0 );
210 connect( a, SIGNAL( activated() ), this, SLOT( saveAs() ) ); 210 connect( a, SIGNAL( activated() ), this, SLOT( saveAs() ) );
211 a->addTo( file ); 211 a->addTo( file );
212 212
213 a = new QAction( tr( "Cut" ), Opie::Core::OResource::loadPixmap( "cut", Opie::Core::OResource::SmallIcon ), 213 a = new QAction( tr( "Cut" ), Opie::Core::OResource::loadPixmap( "cut", Opie::Core::OResource::SmallIcon ),
214 QString::null, 0, this, 0 ); 214 QString::null, 0, this, 0 );
215 connect( a, SIGNAL( activated() ), this, SLOT( editCut() ) ); 215 connect( a, SIGNAL( activated() ), this, SLOT( editCut() ) );
216 a->addTo( editBar ); 216 a->addTo( editBar );
217 a->addTo( edit ); 217 a->addTo( edit );
218 218
219 a = new QAction( tr( "Copy" ), Opie::Core::OResource::loadPixmap( "copy", Opie::Core::OResource::SmallIcon ), 219 a = new QAction( tr( "Copy" ), Opie::Core::OResource::loadPixmap( "copy", Opie::Core::OResource::SmallIcon ),
220 QString::null, 0, this, 0 ); 220 QString::null, 0, this, 0 );
221 connect( a, SIGNAL( activated() ), this, SLOT( editCopy() ) ); 221 connect( a, SIGNAL( activated() ), this, SLOT( editCopy() ) );
222 a->addTo( editBar ); 222 a->addTo( editBar );
223 a->addTo( edit ); 223 a->addTo( edit );
224 224
225 a = new QAction( tr( "Paste" ), Opie::Core::OResource::loadPixmap( "paste", Opie::Core::OResource::SmallIcon ), 225 a = new QAction( tr( "Paste" ), Opie::Core::OResource::loadPixmap( "paste", Opie::Core::OResource::SmallIcon ),
226 QString::null, 0, this, 0 ); 226 QString::null, 0, this, 0 );
227 connect( a, SIGNAL( activated() ), this, SLOT( editPaste() ) ); 227 connect( a, SIGNAL( activated() ), this, SLOT( editPaste() ) );
228 a->addTo( editBar ); 228 a->addTo( editBar );
229 a->addTo( edit ); 229 a->addTo( edit );
230 230
231 231
232#ifndef QT_NO_CLIPBOARD 232#ifndef QT_NO_CLIPBOARD
233 a = new QAction( tr( "Insert Time and Date" ), Opie::Core::OResource::loadPixmap( "paste", Opie::Core::OResource::SmallIcon ), 233 a = new QAction( tr( "Insert Time and Date" ), Opie::Core::OResource::loadPixmap( "paste", Opie::Core::OResource::SmallIcon ),
234 QString::null, 0, this, 0 ); 234 QString::null, 0, this, 0 );
235 connect( a, SIGNAL( activated() ), this, SLOT( editPasteTimeDate() ) ); 235 connect( a, SIGNAL( activated() ), this, SLOT( editPasteTimeDate() ) );
236 a->addTo( edit ); 236 a->addTo( edit );
237#endif 237#endif
238 238
239 a = new QAction( tr( "Goto Line..." ), Opie::Core::OResource::loadPixmap( "find", Opie::Core::OResource::SmallIcon ), 239 a = new QAction( tr( "Goto Line..." ), Opie::Core::OResource::loadPixmap( "find", Opie::Core::OResource::SmallIcon ),
240 QString::null, 0, this, 0 ); 240 QString::null, 0, this, 0 );
241 connect( a, SIGNAL( activated() ), this, SLOT( gotoLine() ) ); 241 connect( a, SIGNAL( activated() ), this, SLOT( gotoLine() ) );
242 edit->insertSeparator(); 242 edit->insertSeparator();
243 a->addTo( edit ); 243 a->addTo( edit );
244 244
245 a = new QAction( tr( "Find..." ), Opie::Core::OResource::loadPixmap( "find", Opie::Core::OResource::SmallIcon ), 245 a = new QAction( tr( "Find..." ), Opie::Core::OResource::loadPixmap( "find", Opie::Core::OResource::SmallIcon ),
246 QString::null, 0, this, 0 ); 246 QString::null, 0, this, 0 );
247 connect( a, SIGNAL( activated() ), this, SLOT( editFind() ) ); 247 connect( a, SIGNAL( activated() ), this, SLOT( editFind() ) );
248 a->addTo( bar ); 248 a->addTo( bar );
249 a->addTo( edit ); 249 a->addTo( edit );
250 250
251 zin = new QAction( tr("Zoom in"), QString::null, 0, this, 0 ); 251 zin = new QAction( tr("Zoom in"), QString::null, 0, this, 0 );
252 connect( zin, SIGNAL( activated() ), this, SLOT( zoomIn() ) ); 252 connect( zin, SIGNAL( activated() ), this, SLOT( zoomIn() ) );
253 zin->addTo( font ); 253 zin->addTo( font );
254 254
255 zout = new QAction( tr("Zoom out"), QString::null, 0, this, 0 ); 255 zout = new QAction( tr("Zoom out"), QString::null, 0, this, 0 );
256 connect( zout, SIGNAL( activated() ), this, SLOT( zoomOut() ) ); 256 connect( zout, SIGNAL( activated() ), this, SLOT( zoomOut() ) );
257 zout->addTo( font ); 257 zout->addTo( font );
258 258
259 font->insertSeparator(); 259 font->insertSeparator();
260 260
261 font->insertItem(tr("Font"), this, SLOT(changeFont()) ); 261 font->insertItem(tr("Font"), this, SLOT(changeFont()) );
262 262
263 font->insertSeparator(); 263 font->insertSeparator();
264 font->insertItem(tr("Advanced Features"), advancedMenu); 264 font->insertItem(tr("Advanced Features"), advancedMenu);
265 265
266 QAction *wa = new QAction( tr("Wrap lines"), 266 QAction *wa = new QAction( tr("Wrap lines"),
267 QString::null, 0, this, 0 ); 267 QString::null, 0, this, 0 );
268 connect( wa, SIGNAL( toggled(bool) ), 268 connect( wa, SIGNAL( toggled(bool) ),
269 this, SLOT( setWordWrap(bool) ) ); 269 this, SLOT( setWordWrap(bool) ) );
270 wa->setToggleAction(true); 270 wa->setToggleAction(true);
271 wa->addTo( advancedMenu); 271 wa->addTo( advancedMenu);
272 272
273 nStart = new QAction( tr("Start with new file"), 273 nStart = new QAction( tr("Start with new file"),
274 QString::null, 0, this, 0 ); 274 QString::null, 0, this, 0 );
275 connect( nStart, SIGNAL( toggled(bool) ), 275 connect( nStart, SIGNAL( toggled(bool) ),
276 this, SLOT( changeStartConfig(bool) ) ); 276 this, SLOT( changeStartConfig(bool) ) );
277 nStart->setToggleAction(true); 277 nStart->setToggleAction(true);
278 nStart->addTo( advancedMenu ); 278 nStart->addTo( advancedMenu );
279 nStart->setEnabled(false); 279 nStart->setEnabled(false);
280 280
281 nAdvanced = new QAction( tr("Prompt on Exit"), 281 nAdvanced = new QAction( tr("Prompt on Exit"),
282 QString::null, 0, this, 0 ); 282 QString::null, 0, this, 0 );
283 connect( nAdvanced, SIGNAL( toggled(bool) ), 283 connect( nAdvanced, SIGNAL( toggled(bool) ),
284 this, SLOT( doPrompt(bool) ) ); 284 this, SLOT( doPrompt(bool) ) );
285 nAdvanced->setToggleAction(true); 285 nAdvanced->setToggleAction(true);
286 nAdvanced->addTo( advancedMenu ); 286 nAdvanced->addTo( advancedMenu );
287 287
288 desktopAction = new QAction( tr("Always open linked file"), 288 desktopAction = new QAction( tr("Always open linked file"),
289 QString::null, 0, this, 0 ); 289 QString::null, 0, this, 0 );
290 connect( desktopAction, SIGNAL( toggled(bool) ), 290 connect( desktopAction, SIGNAL( toggled(bool) ),
291 this, SLOT( doDesktop(bool) ) ); 291 this, SLOT( doDesktop(bool) ) );
292 desktopAction->setToggleAction(true); 292 desktopAction->setToggleAction(true);
293 desktopAction->addTo( advancedMenu); 293 desktopAction->addTo( advancedMenu);
294 294
295 filePermAction = new QAction( tr("File Permissions"), 295 filePermAction = new QAction( tr("File Permissions"),
296 QString::null, 0, this, 0 ); 296 QString::null, 0, this, 0 );
297 connect( filePermAction, SIGNAL( toggled(bool) ), 297 connect( filePermAction, SIGNAL( toggled(bool) ),
298 this, SLOT( doFilePerms(bool) ) ); 298 this, SLOT( doFilePerms(bool) ) );
299 filePermAction->setToggleAction(true); 299 filePermAction->setToggleAction(true);
300 filePermAction->addTo( advancedMenu); 300 filePermAction->addTo( advancedMenu);
301 301
302 searchBarAction = new QAction( tr("Search Bar Open"), 302 searchBarAction = new QAction( tr("Search Bar Open"),
303 QString::null, 0, this, 0 ); 303 QString::null, 0, this, 0 );
304 connect( searchBarAction, SIGNAL( toggled(bool) ), 304 connect( searchBarAction, SIGNAL( toggled(bool) ),
305 this, SLOT( setSearchBar(bool) ) ); 305 this, SLOT( setSearchBar(bool) ) );
306 searchBarAction->setToggleAction(true); 306 searchBarAction->setToggleAction(true);
307 searchBarAction->addTo( advancedMenu); 307 searchBarAction->addTo( advancedMenu);
308 308
309 nAutoSave = new QAction( tr("Auto Save 5 min."), 309 nAutoSave = new QAction( tr("Auto Save 5 min."),
310 QString::null, 0, this, 0 ); 310 QString::null, 0, this, 0 );
311 connect( nAutoSave, SIGNAL( toggled(bool) ), 311 connect( nAutoSave, SIGNAL( toggled(bool) ),
312 this, SLOT( doTimer(bool) ) ); 312 this, SLOT( doTimer(bool) ) );
313 nAutoSave->setToggleAction(true); 313 nAutoSave->setToggleAction(true);
314 nAutoSave->addTo( advancedMenu); 314 nAutoSave->addTo( advancedMenu);
315 315
316 316
317 //font->insertSeparator(); 317 //font->insertSeparator();
318 318
319 //font->insertItem(tr("About"), this, SLOT( doAbout()) ); 319 //font->insertItem(tr("About"), this, SLOT( doAbout()) );
320 320
321 mb->insertItem( tr( "File" ), file ); 321 mb->insertItem( tr( "File" ), file );
322 mb->insertItem( tr( "Edit" ), edit ); 322 mb->insertItem( tr( "Edit" ), edit );
323 mb->insertItem( tr( "View" ), font ); 323 mb->insertItem( tr( "View" ), font );
324 324
325 searchBar = new QToolBar(this); 325 searchBar = new QToolBar(this);
326 addToolBar( searchBar, "Search", QMainWindow::Top, true ); 326 addToolBar( searchBar, "Search", QMainWindow::Top, true );
327 327
328 searchBar->setHorizontalStretchable( true ); 328 searchBar->setHorizontalStretchable( true );
329 329
330 searchEdit = new QLineEdit( searchBar, "searchEdit" ); 330 searchEdit = new QLineEdit( searchBar, "searchEdit" );
331 searchBar->setStretchableWidget( searchEdit ); 331 searchBar->setStretchableWidget( searchEdit );
332 connect( searchEdit, SIGNAL( textChanged(const QString&) ), 332 connect( searchEdit, SIGNAL( textChanged(const QString&) ),
333 this, SLOT( search() ) ); 333 this, SLOT( search() ) );
334 334
335 a = new QAction( tr( "Find Next" ), Opie::Core::OResource::loadPixmap( "next", Opie::Core::OResource::SmallIcon ), 335 a = new QAction( tr( "Find Next" ), Opie::Core::OResource::loadPixmap( "next", Opie::Core::OResource::SmallIcon ),
336 QString::null, 0, this, 0 ); 336 QString::null, 0, this, 0 );
337 connect( a, SIGNAL( activated() ), this, SLOT( findNext() ) ); 337 connect( a, SIGNAL( activated() ), this, SLOT( findNext() ) );
338 a->addTo( searchBar ); 338 a->addTo( searchBar );
339 a->addTo( edit ); 339 a->addTo( edit );
340 340
341 a = new QAction( tr( "Close Find" ), Opie::Core::OResource::loadPixmap( "close", Opie::Core::OResource::SmallIcon ), 341 a = new QAction( tr( "Close Find" ), Opie::Core::OResource::loadPixmap( "close", Opie::Core::OResource::SmallIcon ),
342 QString::null, 0, this, 0 ); 342 QString::null, 0, this, 0 );
343 connect( a, SIGNAL( activated() ), this, SLOT( findClose() ) ); 343 connect( a, SIGNAL( activated() ), this, SLOT( findClose() ) );
344 a->addTo( searchBar ); 344 a->addTo( searchBar );
345 345
346 edit->insertSeparator(); 346 edit->insertSeparator();
347 a = new QAction( tr( "Delete" ), Opie::Core::OResource::loadPixmap( "close", Opie::Core::OResource::SmallIcon ), 347 a = new QAction( tr( "Delete" ), Opie::Core::OResource::loadPixmap( "close", Opie::Core::OResource::SmallIcon ),
348 QString::null, 0, this, 0 ); 348 QString::null, 0, this, 0 );
349 connect( a, SIGNAL( activated() ), this, SLOT( editDelete() ) ); 349 connect( a, SIGNAL( activated() ), this, SLOT( editDelete() ) );
350 a->addTo( edit ); 350 a->addTo( edit );
351 351
352 searchBar->hide(); 352 searchBar->hide();
353 353
354 editor = new QpeEditor( this ); 354 editor = new QpeEditor( this );
355 setCentralWidget( editor ); 355 setCentralWidget( editor );
356 editor->setFrameStyle( QFrame::Panel | QFrame::Sunken ); 356 editor->setFrameStyle( QFrame::Panel | QFrame::Sunken );
357 connect( editor, SIGNAL( textChanged() ), 357 connect( editor, SIGNAL( textChanged() ),
358 this, SLOT( editorChanged() ) ); 358 this, SLOT( editorChanged() ) );
359 359
360 QPEApplication::setStylusOperation( editor, QPEApplication::RightOnHold); 360 QPEApplication::setStylusOperation( editor, QPEApplication::RightOnHold);
361 361
362 Config cfg("TextEdit"); 362 Config cfg("TextEdit");
363 cfg. setGroup ( "Font" ); 363 cfg. setGroup ( "Font" );
364 364
365 QFont defaultFont = editor-> font ( ); 365 QFont defaultFont = editor-> font ( );
366 366
367 QString family = cfg. readEntry ( "Family", defaultFont. family ( )); 367 QString family = cfg. readEntry ( "Family", defaultFont. family ( ));
368 int size = cfg. readNumEntry ( "Size", defaultFont. pointSize ( )); 368 int size = cfg. readNumEntry ( "Size", defaultFont. pointSize ( ));
369 int weight = cfg. readNumEntry ( "Weight", defaultFont. weight ( )); 369 int weight = cfg. readNumEntry ( "Weight", defaultFont. weight ( ));
370 bool italic = cfg. readBoolEntry ( "Italic", defaultFont. italic ( )); 370 bool italic = cfg. readBoolEntry ( "Italic", defaultFont. italic ( ));
371 371
372 defaultFont = QFont ( family, size, weight, italic ); 372 defaultFont = QFont ( family, size, weight, italic );
373 editor-> setFont ( defaultFont ); 373 editor-> setFont ( defaultFont );
374// updateCaption(); 374// updateCaption();
375 375
376 cfg.setGroup ( "View" ); 376 cfg.setGroup ( "View" );
377 377
378 promptExit = cfg.readBoolEntry ( "PromptExit", false ); 378 promptExit = cfg.readBoolEntry ( "PromptExit", false );
379 openDesktop = cfg.readBoolEntry ( "OpenDesktop", true ); 379 openDesktop = cfg.readBoolEntry ( "OpenDesktop", true );
380 filePerms = cfg.readBoolEntry ( "FilePermissions", false ); 380 filePerms = cfg.readBoolEntry ( "FilePermissions", false );
381 useSearchBar = cfg.readBoolEntry ( "SearchBar", false ); 381 useSearchBar = cfg.readBoolEntry ( "SearchBar", false );
382 startWithNew = cfg.readBoolEntry ( "startNew", true); 382 startWithNew = cfg.readBoolEntry ( "startNew", true);
383 featureAutoSave = cfg.readBoolEntry( "autosave", false); 383 featureAutoSave = cfg.readBoolEntry( "autosave", false);
384 384
385 if(useSearchBar) searchBarAction->setOn(true); 385 if(useSearchBar) searchBarAction->setOn(true);
386 if(promptExit) nAdvanced->setOn( true ); 386 if(promptExit) nAdvanced->setOn( true );
387 if(openDesktop) desktopAction->setOn( true ); 387 if(openDesktop) desktopAction->setOn( true );
388 if(filePerms) filePermAction->setOn( true ); 388 if(filePerms) filePermAction->setOn( true );
389 if(startWithNew) nStart->setOn( true ); 389 if(startWithNew) nStart->setOn( true );
390 if(featureAutoSave) nAutoSave->setOn(true); 390 if(featureAutoSave) nAutoSave->setOn(true);
391 391
392// { 392// {
393// doTimer(true); 393// doTimer(true);
394// } 394// }
395 395
396 bool wrap = cfg. readBoolEntry ( "Wrap", true ); 396 bool wrap = cfg. readBoolEntry ( "Wrap", true );
397 wa-> setOn ( wrap ); 397 wa-> setOn ( wrap );
398 setWordWrap ( wrap ); 398 setWordWrap ( wrap );
399 399
400///////////////// 400/////////////////
401 if( qApp->argc() > 1) { 401 if( qApp->argc() > 1) {
402 currentFileName=qApp->argv()[1]; 402 currentFileName=qApp->argv()[1];
403 403
404 QFileInfo fi(currentFileName); 404 QFileInfo fi(currentFileName);
405 405
406 if(fi.baseName().left(1) == "") { 406 if(fi.baseName().left(1) == "") {
407 openDotFile(currentFileName); 407 openDotFile(currentFileName);
408 } else { 408 } else {
409 openFile(currentFileName); 409 openFile(currentFileName);
410 } 410 }
411 } else { 411 } else {
412 edited1=false; 412 edited1=false;
413 openDotFile(""); 413 openDotFile("");
414 } 414 }
415 415
416 viewSelection = cfg.readNumEntry( "FileView", 0 ); 416 viewSelection = cfg.readNumEntry( "FileView", 0 );
417} 417}
418 418
419TextEdit::~TextEdit() { 419TextEdit::~TextEdit() {
420 if( edited1 && !promptExit) { 420 if( edited1 && !promptExit) {
421 switch( savePrompt() ) { 421 switch( savePrompt() ) {
422 case 1: { 422 case 1: {
423 saveAs(); 423 saveAs();
424 } 424 }
425 break; 425 break;
426 }; 426 };
427 } 427 }
428 428
429 delete editor; 429 delete editor;
430} 430}
431 431
432void TextEdit::closeEvent(QCloseEvent *) { 432void TextEdit::closeEvent(QCloseEvent *) {
433 if( promptExit) { 433 if( promptExit) {
434 switch( savePrompt() ) { 434 switch( savePrompt() ) {
435 case 1: { 435 case 1: {
436 saveAs(); 436 saveAs();
437 qApp->quit(); 437 qApp->quit();
438 } 438 }
439 break; 439 break;
440 440
441 case 2: { 441 case 2: {
442 qApp->quit(); 442 qApp->quit();
443 } 443 }
444 break; 444 break;
445 445
446 case -1: 446 case -1:
447 break; 447 break;
448 }; 448 };
449 } 449 }
450 else 450 else
451 qApp->quit(); 451 qApp->quit();
452} 452}
453 453
454void TextEdit::cleanUp() { 454void TextEdit::cleanUp() {
455 455
456 Config cfg ( "TextEdit" ); 456 Config cfg ( "TextEdit" );
457 cfg. setGroup ( "Font" ); 457 cfg. setGroup ( "Font" );
458 QFont f = editor->font(); 458 QFont f = editor->font();
459 cfg.writeEntry ( "Family", f. family ( )); 459 cfg.writeEntry ( "Family", f. family ( ));
460 cfg.writeEntry ( "Size", f. pointSize ( )); 460 cfg.writeEntry ( "Size", f. pointSize ( ));
461 cfg.writeEntry ( "Weight", f. weight ( )); 461 cfg.writeEntry ( "Weight", f. weight ( ));
462 cfg.writeEntry ( "Italic", f. italic ( )); 462 cfg.writeEntry ( "Italic", f. italic ( ));
463 463
464 cfg.setGroup ( "View" ); 464 cfg.setGroup ( "View" );
465 cfg.writeEntry ( "Wrap", editor->wordWrap() == QMultiLineEdit::WidgetWidth ); 465 cfg.writeEntry ( "Wrap", editor->wordWrap() == QMultiLineEdit::WidgetWidth );
466 cfg.writeEntry ( "FileView", viewSelection ); 466 cfg.writeEntry ( "FileView", viewSelection );
467 467
468 cfg.writeEntry ( "PromptExit", promptExit ); 468 cfg.writeEntry ( "PromptExit", promptExit );
469 cfg.writeEntry ( "OpenDesktop", openDesktop ); 469 cfg.writeEntry ( "OpenDesktop", openDesktop );
470 cfg.writeEntry ( "FilePermissions", filePerms ); 470 cfg.writeEntry ( "FilePermissions", filePerms );
471 cfg.writeEntry ( "SearchBar", useSearchBar ); 471 cfg.writeEntry ( "SearchBar", useSearchBar );
472 cfg.writeEntry ( "startNew", startWithNew ); 472 cfg.writeEntry ( "startNew", startWithNew );
473 473
474} 474}
475 475
476 476
477void TextEdit::accept() { 477void TextEdit::accept() {
478 if( edited1) 478 if( edited1)
479 saveAs(); 479 saveAs();
480 qApp->quit(); 480 qApp->quit();
481} 481}
482 482
483void TextEdit::zoomIn() { 483void TextEdit::zoomIn() {
484 setFontSize(editor->font().pointSize()+1,false); 484 setFontSize(editor->font().pointSize()+1,false);
485} 485}
486 486
487void TextEdit::zoomOut() { 487void TextEdit::zoomOut() {
488 setFontSize(editor->font().pointSize()-1,true); 488 setFontSize(editor->font().pointSize()-1,true);
489} 489}
490 490
491 491
492void TextEdit::setFontSize(int sz, bool round_down_not_up) { 492void TextEdit::setFontSize(int sz, bool round_down_not_up) {
493 int s=10; 493 int s=10;
494 for (int i=0; i<nfontsizes; i++) { 494 for (int i=0; i<nfontsizes; i++) {
495 if ( fontsize[i] == sz ) { 495 if ( fontsize[i] == sz ) {
496 s = sz; 496 s = sz;
497 break; 497 break;
498 } else if ( round_down_not_up ) { 498 } else if ( round_down_not_up ) {
499 if ( fontsize[i] < sz ) 499 if ( fontsize[i] < sz )
500 s = fontsize[i]; 500 s = fontsize[i];
501 } else { 501 } else {
502 if ( fontsize[i] > sz ) { 502 if ( fontsize[i] > sz ) {
503 s = fontsize[i]; 503 s = fontsize[i];
504 break; 504 break;
505 } 505 }
506 } 506 }
507 } 507 }
508 508
509 QFont f = editor->font(); 509 QFont f = editor->font();
510 f.setPointSize(s); 510 f.setPointSize(s);
511 editor->setFont(f); 511 editor->setFont(f);
512 512
513 zin->setEnabled(s != fontsize[nfontsizes-1]); 513 zin->setEnabled(s != fontsize[nfontsizes-1]);
514 zout->setEnabled(s != fontsize[0]); 514 zout->setEnabled(s != fontsize[0]);
515} 515}
516 516
517void TextEdit::setBold(bool y) { 517void TextEdit::setBold(bool y) {
518 QFont f = editor->font(); 518 QFont f = editor->font();
519 f.setBold(y); 519 f.setBold(y);
520 editor->setFont(f); 520 editor->setFont(f);
521} 521}
522 522
523void TextEdit::setItalic(bool y) { 523void TextEdit::setItalic(bool y) {
524 QFont f = editor->font(); 524 QFont f = editor->font();
525 f.setItalic(y); 525 f.setItalic(y);
526 editor->setFont(f); 526 editor->setFont(f);
527} 527}
528 528
529void TextEdit::setWordWrap(bool y) { 529void TextEdit::setWordWrap(bool y) {
530 bool state = editor->edited(); 530 bool state = editor->edited();
531 QString captionStr = caption(); 531 QString captionStr = caption();
532 bool b1 = edited1; 532 bool b1 = edited1;
533 bool b2 = edited; 533 bool b2 = edited;
534 534
535 editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap ); 535 editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap );
536 editor->setEdited( state ); 536 editor->setEdited( state );
537 edited1=b1; 537 edited1=b1;
538 edited=b2; 538 edited=b2;
539 setCaption(captionStr); 539 setCaption(captionStr);
540} 540}
541 541
542void TextEdit::setSearchBar(bool b) { 542void TextEdit::setSearchBar(bool b) {
543 useSearchBar=b; 543 useSearchBar=b;
544 Config cfg("TextEdit"); 544 Config cfg("TextEdit");
545 cfg.setGroup("View"); 545 cfg.setGroup("View");
546 cfg.writeEntry ( "SearchBar", b ); 546 cfg.writeEntry ( "SearchBar", b );
547 searchBarAction->setOn(b); 547 searchBarAction->setOn(b);
548 if(b) 548 if(b)
549 searchBar->show(); 549 searchBar->show();
550 else 550 else
551 searchBar->hide(); 551 searchBar->hide();
552 editor->setFocus(); 552 editor->setFocus();
553} 553}
554 554
555void TextEdit::fileNew() { 555void TextEdit::fileNew() {
556// if( !bFromDocView ) { 556// if( !bFromDocView ) {
557// saveAs(); 557// saveAs();
558// } 558// }
559 newFile(DocLnk()); 559 newFile(DocLnk());
560} 560}
561 561
562void TextEdit::fileOpen() { 562void TextEdit::fileOpen() {
563 Config cfg("TextEdit"); 563 Config cfg("TextEdit");
564 cfg. setGroup ( "View" ); 564 cfg. setGroup ( "View" );
565 QMap<QString, QStringList> map; 565 QMap<QString, QStringList> map;
566 map.insert(tr("All"), QStringList() ); 566 map.insert(tr("All"), QStringList() );
567 QStringList text; 567 QStringList text;
568 text << "text/*"; 568 text << "text/*";
569 map.insert(tr("Text"), text ); 569 map.insert(tr("Text"), text );
570 text << "*"; 570 text << "*";
571 map.insert(tr("All"), text ); 571 map.insert(tr("All"), text );
572 QString str = OFileDialog::getOpenFileName( 2, 572 QString str = OFileDialog::getOpenFileName( 2,
573 QString::null , 573 QString::null ,
574 QString::null, map); 574 QString::null, map);
575 if( !str.isEmpty() && QFile(str).exists() && !QFileInfo(str).isDir() ) 575 if( !str.isEmpty() && QFile(str).exists() && !QFileInfo(str).isDir() )
576 { 576 {
577 openFile( str ); 577 openFile( str );
578 } 578 }
579 else 579 else
580 updateCaption(); 580 updateCaption();
581} 581}
582 582
583void TextEdit::doSearchBar() { 583void TextEdit::doSearchBar() {
584 if(!useSearchBar) 584 if(!useSearchBar)
585 searchBar->hide(); 585 searchBar->hide();
586 else 586 else
587 searchBar->show(); 587 searchBar->show();
588} 588}
589 589
590#if 0 590#if 0
591void TextEdit::slotFind() { 591void TextEdit::slotFind() {
592 FindDialog frmFind( tr("Text Editor"), this ); 592 FindDialog frmFind( tr("Text Editor"), this );
593 connect( &frmFind, SIGNAL(signalFindClicked(const QString&,bool,bool,int)), 593 connect( &frmFind, SIGNAL(signalFindClicked(const QString&,bool,bool,int)),
594 editor, SLOT(slotDoFind(const QString&,bool,bool))); 594 editor, SLOT(slotDoFind(const QString&,bool,bool)));
595 595
596 //case sensitive, backwards, [category] 596 //case sensitive, backwards, [category]
597 597
598 connect( editor, SIGNAL(notFound()), 598 connect( editor, SIGNAL(notFound()),
599 &frmFind, SLOT(slotNotFound()) ); 599 &frmFind, SLOT(slotNotFound()) );
600 connect( editor, SIGNAL(searchWrapped()), 600 connect( editor, SIGNAL(searchWrapped()),
601 &frmFind, SLOT(slotWrapAround()) ); 601 &frmFind, SLOT(slotWrapAround()) );
602 602
603 frmFind.exec(); 603 frmFind.exec();
604 604
605 605
606} 606}
607#endif 607#endif
608 608
609void TextEdit::fileRevert() { 609void TextEdit::fileRevert() {
610 clear(); 610 clear();
611 fileOpen(); 611 fileOpen();
612} 612}
613 613
614void TextEdit::editCut() { 614void TextEdit::editCut() {
615#ifndef QT_NO_CLIPBOARD 615#ifndef QT_NO_CLIPBOARD
616 editor->cut(); 616 editor->cut();
617#endif 617#endif
618} 618}
619 619
620void TextEdit::editCopy() { 620void TextEdit::editCopy() {
621#ifndef QT_NO_CLIPBOARD 621#ifndef QT_NO_CLIPBOARD
622 editor->copy(); 622 editor->copy();
623#endif 623#endif
624} 624}
625 625
626void TextEdit::editPaste() { 626void TextEdit::editPaste() {
627#ifndef QT_NO_CLIPBOARD 627#ifndef QT_NO_CLIPBOARD
628 editor->paste(); 628 editor->paste();
629#endif 629#endif
630} 630}
631 631
632void TextEdit::editFind() { 632void TextEdit::editFind() {
633 searchBar->show(); 633 searchBar->show();
634 searchEdit->setFocus(); 634 searchEdit->setFocus();
635} 635}
636 636
637void TextEdit::findNext() { 637void TextEdit::findNext() {
638 editor->find( searchEdit->text(), false, false ); 638 editor->find( searchEdit->text(), false, false );
639 639
640} 640}
641 641
642void TextEdit::findClose() { 642void TextEdit::findClose() {
643 searchBar->hide(); 643 searchBar->hide();
644} 644}
645 645
646void TextEdit::search() { 646void TextEdit::search() {
647 editor->find( searchEdit->text(), false, false ); 647 editor->find( searchEdit->text(), false, false );
648} 648}
649 649
650void TextEdit::newFile( const DocLnk &f ) { 650void TextEdit::newFile( const DocLnk &f ) {
651 DocLnk nf = f; 651 DocLnk nf = f;
652 nf.setType("text/plain"); 652 nf.setType("text/plain");
653 clear(); 653 clear();
654 setWState (WState_Reserved1 ); 654 setWState (WState_Reserved1 );
655 editor->setFocus(); 655 editor->setFocus();
656 doc = new DocLnk(nf); 656 doc = new DocLnk(nf);
657 currentFileName = "Unnamed"; 657 currentFileName = "Unnamed";
658 odebug << "newFile "+currentFileName << oendl; 658 odebug << "newFile "+currentFileName << oendl;
659 updateCaption( currentFileName); 659 updateCaption( currentFileName);
660// editor->setEdited( false); 660// editor->setEdited( false);
661} 661}
662 662
663void TextEdit::openDotFile( const QString &f ) { 663void TextEdit::openDotFile( const QString &f ) {
664 if(!currentFileName.isEmpty()) { 664 if(!currentFileName.isEmpty()) {
665 currentFileName=f; 665 currentFileName=f;
666 666
667 odebug << "openFile dotfile " + currentFileName << oendl; 667 odebug << "openFile dotfile " + currentFileName << oendl;
668 QString txt; 668 QString txt;
669 QFile file(f); 669 QFile file(f);
670 if (!file.open(IO_ReadWrite)) 670 if (!file.open(IO_ReadWrite))
671 owarn << "Failed to open file " << file.name() << oendl; 671 owarn << "Failed to open file " << file.name() << oendl;
672 else { 672 else {
673 QTextStream t(&file); 673 QTextStream t(&file);
674 while ( !t.atEnd()) { 674 while ( !t.atEnd()) {
675 txt+=t.readLine()+"\n"; 675 txt+=t.readLine()+"\n";
676 } 676 }
677 editor->setText(txt); 677 editor->setText(txt);
678 editor->setEdited( false); 678 editor->setEdited( false);
679 edited1=false; 679 edited1=false;
680 edited=false; 680 edited=false;
681 } 681 }
682 } 682 }
683 updateCaption( currentFileName); 683 updateCaption( currentFileName);
684} 684}
685 685
686void TextEdit::openFile( const QString &f ) { 686void TextEdit::openFile( const QString &f ) {
687 odebug << "filename is "+ f << oendl; 687 odebug << "filename is "+ f << oendl;
688 QString filer; 688 QString filer;
689 QFileInfo fi( f); 689 QFileInfo fi( f);
690// bFromDocView = true; 690// bFromDocView = true;
691 if(f.find(".desktop",0,true) != -1 && !openDesktop ) 691 if(f.find(".desktop",0,true) != -1 && !openDesktop )
692 { 692 {
693 switch ( QMessageBox::warning(this,tr("Text Editor"),tr("Text Editor has detected<BR>you selected a <B>.desktop</B>file.<BR>Open<B>.desktop</B> file or <B>linked</B> file?"),tr(".desktop File"),tr("Linked Document"),0,1,1) ) 693 switch ( QMessageBox::warning(this,tr("Text Editor"),tr("Text Editor has detected<BR>you selected a <B>.desktop</B>file.<BR>Open<B>.desktop</B> file or <B>linked</B> file?"),tr(".desktop File"),tr("Linked Document"),0,1,1) )
694 { 694 {
695 case 0: //desktop 695 case 0: //desktop
696 filer = f; 696 filer = f;
697 break; 697 break;
698 case 1: //linked 698 case 1: //linked
699 DocLnk sf(f); 699 DocLnk sf(f);
700 filer = sf.file(); 700 filer = sf.file();
701 break; 701 break;
702 }; 702 };
703 } 703 }
704 else if(fi.baseName().left(1) == "") 704 else if(fi.baseName().left(1) == "")
705 { 705 {
706 odebug << "opening dotfile" << oendl; 706 odebug << "opening dotfile" << oendl;
707 currentFileName=f; 707 currentFileName=f;
708 openDotFile(currentFileName); 708 openDotFile(currentFileName);
709 return; 709 return;
710 } 710 }
711 /* 711 /*
712 * The problem is a file where Config(f).isValid() and it does not 712 * The problem is a file where Config(f).isValid() and it does not
713 * end with .desktop will be treated as desktop file 713 * end with .desktop will be treated as desktop file
714 */ 714 */
715 else if (f.find(".desktop",0,true) != -1 ) 715 else if (f.find(".desktop",0,true) != -1 )
716 { 716 {
717 DocLnk sf(f); 717 DocLnk sf(f);
718 filer = sf.file(); 718 filer = sf.file();
719 if(filer.right(1) == "/") 719 if(filer.right(1) == "/")
720 filer = f; 720 filer = f;
721 721
722 } 722 }
723 else 723 else
724 filer = f; 724 filer = f;
725 725
726 DocLnk nf; 726 DocLnk nf;
727 nf.setType("text/plain"); 727 nf.setType("text/plain");
728 nf.setFile(filer); 728 nf.setFile(filer);
729 currentFileName=filer; 729 currentFileName=filer;
730 730
731 nf.setName(fi.baseName()); 731 nf.setName(fi.baseName());
732 openFile(nf); 732 openFile(nf);
733 733
734 odebug << "openFile string "+currentFileName << oendl; 734 odebug << "openFile string "+currentFileName << oendl;
735 735
736 showEditTools(); 736 showEditTools();
737 // Show filename in caption 737 // Show filename in caption
738 QString name = filer; 738 QString name = filer;
739 int sep = name.findRev( '/' ); 739 int sep = name.findRev( '/' );
740 if ( sep > 0 ) 740 if ( sep > 0 )
741 name = name.mid( sep+1 ); 741 name = name.mid( sep+1 );
742 updateCaption( name ); 742 updateCaption( name );
743} 743}
744 744
745void TextEdit::openFile( const DocLnk &f ) { 745void TextEdit::openFile( const DocLnk &f ) {
746// clear(); 746// clear();
747// bFromDocView = true; 747// bFromDocView = true;
748 FileManager fm; 748 FileManager fm;
749 QString txt; 749 QString txt;
750 currentFileName=f.file(); 750 currentFileName=f.file();
751 odebug << "openFile doclnk " + currentFileName << oendl; 751 odebug << "openFile doclnk " + currentFileName << oendl;
752 if ( !fm.loadFile( f, txt ) ) { 752 if ( !fm.loadFile( f, txt ) ) {
753 // ####### could be a new file 753 // ####### could be a new file
754 odebug << "Cannot open file" << oendl; 754 odebug << "Cannot open file" << oendl;
755 } 755 }
756// fileNew(); 756// fileNew();
757 if ( doc ) 757 if ( doc )
758 delete doc; 758 delete doc;
759 doc = new DocLnk(f); 759 doc = new DocLnk(f);
760 editor->setText(txt); 760 editor->setText(txt);
761 editor->setEdited( false); 761 editor->setEdited( false);
762 edited1=false; 762 edited1=false;
763 edited=false; 763 edited=false;
764 764
765 doc->setName(currentFileName); 765 doc->setName(currentFileName);
766 updateCaption(); 766 updateCaption();
767 setTimer(); 767 setTimer();
768} 768}
769 769
770void TextEdit::showEditTools() { 770void TextEdit::showEditTools() {
771 menu->show(); 771 menu->show();
772 editBar->show(); 772 editBar->show();
773 if(!useSearchBar) 773 if(!useSearchBar)
774 searchBar->hide(); 774 searchBar->hide();
775 else 775 else
776 searchBar->show(); 776 searchBar->show();
777 setWState (WState_Reserved1 ); 777 setWState (WState_Reserved1 );
778} 778}
779 779
780/*! 780/*!
781 unprompted save */ 781 unprompted save */
782bool TextEdit::save() { 782bool TextEdit::save() {
783 QString name, file; 783 QString name, file;
784 odebug << "saveAsFile " + currentFileName << oendl; 784 odebug << "saveAsFile " + currentFileName << oendl;
785 if(currentFileName.isEmpty()) { 785 if(currentFileName.isEmpty()) {
786 saveAs(); 786 saveAs();
787 return false; 787 return false;
788 } 788 }
789 name = currentFileName; 789 name = currentFileName;
790 if(doc) { 790 if(doc) {
791 file = doc->file(); 791 file = doc->file();
792 odebug << "saver file "+file << oendl; 792 odebug << "saver file "+file << oendl;
793 name = doc->name(); 793 name = doc->name();
794 odebug << "File named "+name << oendl; 794 odebug << "File named "+name << oendl;
795 } else { 795 } else {
796 file = currentFileName; 796 file = currentFileName;
797 name = QFileInfo(currentFileName).baseName(); 797 name = QFileInfo(currentFileName).baseName();
798 } 798 }
799 799
800 QString rt = editor->text(); 800 QString rt = editor->text();
801 if( !rt.isEmpty() ) { 801 if( !rt.isEmpty() ) {
802 if(name.isEmpty()) { 802 if(name.isEmpty()) {
803 saveAs(); 803 saveAs();
804 } else { 804 } else {
805 currentFileName = name; 805 currentFileName = name;
806 odebug << "saveFile "+currentFileName << oendl; 806 odebug << "saveFile "+currentFileName << oendl;
807 807
808 struct stat buf; 808 struct stat buf;
809 mode_t mode; 809 mode_t mode;
810 stat(file.latin1(), &buf); 810 stat(file.latin1(), &buf);
811 mode = buf.st_mode; 811 mode = buf.st_mode;
812 812
813 if(!fileIs) { 813 if(!fileIs) {
814 doc->setName( name); 814 doc->setName( name);
815 FileManager fm; 815 FileManager fm;
816 if ( !fm.saveFile( *doc, rt ) ) { 816 if ( !fm.saveFile( *doc, rt ) ) {
817 QMessageBox::message(tr("Text Edit"),tr("Save Failed")); 817 QMessageBox::message(tr("Text Edit"),tr("Save Failed"));
818 return false; 818 return false;
819 } 819 }
820 } else { 820 } else {
821 odebug << "regular save file" << oendl; 821 odebug << "regular save file" << oendl;
822 QFile f(file); 822 QFile f(file);
823 if( f.open(IO_WriteOnly)) { 823 if( f.open(IO_WriteOnly)) {
824 QCString crt = rt.utf8(); 824 QCString crt = rt.utf8();
825 f.writeBlock(crt,crt.length()); 825 f.writeBlock(crt,crt.length());
826 } else { 826 } else {
827 QMessageBox::message(tr("Text Edit"),tr("Write Failed")); 827 QMessageBox::message(tr("Text Edit"),tr("Write Failed"));
828 return false; 828 return false;
829 } 829 }
830 830
831 } 831 }
832 editor->setEdited( false); 832 editor->setEdited( false);
833 edited1=false; 833 edited1=false;
834 edited=false; 834 edited=false;
835 if(caption().left(1)=="*") 835 if(caption().left(1)=="*")
836 setCaption(caption().right(caption().length()-1)); 836 setCaption(caption().right(caption().length()-1));
837 837
838 838
839 chmod( file.latin1(), mode); 839 chmod( file.latin1(), mode);
840 } 840 }
841 return true; 841 return true;
842 } 842 }
843 return false; 843 return false;
844} 844}
845 845
846/*! 846/*!
847 prompted save */ 847 prompted save */
848bool TextEdit::saveAs() { 848bool TextEdit::saveAs() {
849 849
850 if(caption() == tr("Text Editor")) 850 if(caption() == tr("Text Editor"))
851 return false; 851 return false;
852 odebug << "saveAsFile " + currentFileName << oendl; 852 odebug << "saveAsFile " + currentFileName << oendl;
853 // case of nothing to save...
854// if ( !doc && !currentFileName.isEmpty()) {
855// //|| !bFromDocView)
856// odebug << "no doc" << oendl;
857// return true;
858// }
859// if ( !editor->edited() ) {
860// delete doc;
861// doc = 0;
862// return true;
863// }
864 853
865 QString rt = editor->text(); 854 QString rt = editor->text();
866 odebug << currentFileName << oendl; 855 odebug << currentFileName << oendl;
867 856
868 if( currentFileName.isEmpty() 857 if( currentFileName.isEmpty()
869 || currentFileName == tr("Unnamed") 858 || currentFileName == tr("Unnamed")
870 || currentFileName == tr("Text Editor")) { 859 || currentFileName == tr("Text Editor"))
860 {
871 odebug << "do silly TT filename thing" << oendl; 861 odebug << "do silly TT filename thing" << oendl;
872// if ( doc && doc->name().isEmpty() ) {
873 QString pt = rt.simplifyWhiteSpace(); 862 QString pt = rt.simplifyWhiteSpace();
874 int i = pt.find( ' ' ); 863 int i = pt.find( ' ' );
875 QString docname = pt; 864 QString docname = pt;
876 if ( i > 0 ) 865 if ( i > 0 ) docname = pt.left( i );
877 docname = pt.left( i ); 866
878 // remove "." at the beginning
879 while( docname.startsWith( "." ) ) 867 while( docname.startsWith( "." ) )
880 docname = docname.mid( 1 ); 868 docname = docname.mid( 1 );
881 docname.replace( QRegExp("/"), "_" ); 869 docname.replace( QRegExp("/"), "_" );
882 // cut the length. filenames longer than that 870 // Cut the length. Filenames longer than 40 are not helpful
883 //don't make sense and something goes wrong when they get too long. 871 // and something goes wrong when they get too long.
884 if ( docname.length() > 40 ) 872 if ( docname.length() > 40 ) docname = docname.left(40);
885 docname = docname.left(40); 873
886 if ( docname.isEmpty() ) 874 if ( docname.isEmpty() ) docname = tr("Unnamed");
887 docname = tr("Unnamed"); 875
888 if(doc) doc->setName(docname); 876 if(doc) doc->setName(docname);
877
889 currentFileName=docname; 878 currentFileName=docname;
890// }
891// else
892// odebug << "hmmmmmm" << oendl;
893 } 879 }
894 880
895 881
896 QMap<QString, QStringList> map; 882 QMap<QString, QStringList> map;
897 map.insert(tr("All"), QStringList() ); 883 map.insert(tr("All"), QStringList() );
898 QStringList text; 884 QStringList text;
899 text << "text/*"; 885 text << "text/*";
900 map.insert(tr("Text"), text ); 886 map.insert(tr("Text"), text );
901 text << "*"; 887 text << "*";
902 map.insert(tr("All"), text ); 888 map.insert(tr("All"), text );
903 889
904 QFileInfo cuFi( currentFileName); 890 QFileInfo cuFi( currentFileName);
905 QString filee = cuFi.fileName(); 891 QString filee = cuFi.fileName();
906 QString dire = cuFi.dirPath(); 892 QString dire = cuFi.dirPath();
907 if(dire==".") 893 if(dire==".")
908 dire = QPEApplication::documentDir(); 894 dire = QPEApplication::documentDir();
895
909 QString str; 896 QString str;
910 if( !featureAutoSave) { 897 if( !featureAutoSave) {
911 str = OFileDialog::getSaveFileName( 2, 898 str = OFileDialog::getSaveFileName( 2, dire, filee, map);
912 dire, 899 } else
913 filee, map);
914 } else
915 str = currentFileName; 900 str = currentFileName;
916 901
917 if(!str.isEmpty()) { 902 if(!str.isEmpty()) {
918 QString fileNm=str; 903 QString fileNm=str;
919 904
920 odebug << "saving filename "+fileNm << oendl; 905 odebug << "saving filename "+fileNm << oendl;
921 QFileInfo fi(fileNm); 906 QFileInfo fi(fileNm);
922 currentFileName=fi.fileName(); 907 currentFileName=fi.fileName();
923 if(doc) 908 if(doc)
924// QString file = doc->file();
925// doc->removeFiles();
926 delete doc; 909 delete doc;
927 DocLnk nf; 910
928 nf.setType("text/plain"); 911 DocLnk nf;
929 nf.setFile( fileNm); 912 nf.setType("text/plain");
930 doc = new DocLnk(nf); 913 nf.setFile( fileNm);
931// editor->setText(rt); 914 doc = new DocLnk(nf);
932 odebug << "Saving file as "+currentFileName << oendl; 915 odebug << "Saving file as "+currentFileName << oendl;
933 doc->setName( fi.baseName() /*currentFileName*/); 916 doc->setName( fi.baseName() );
934 updateCaption( currentFileName); 917 updateCaption( currentFileName);
935 918
936 FileManager fm; 919 FileManager fm;
937 if ( !fm.saveFile( *doc, rt ) ) { 920 if ( !fm.saveFile( *doc, rt ) ) {
938 QMessageBox::message(tr("Text Edit"),tr("Save Failed")); 921 QMessageBox::message(tr("Text Edit"),tr("Save Failed"));
939 return false; 922 return false;
940 } 923 }
941 924
942 if( filePerms ) { 925 if( filePerms ) {
943 filePermissions *filePerm; 926 filePermissions *filePerm;
944 filePerm = new filePermissions(this, 927 filePerm = new filePermissions(this, tr("Permissions"),true, 0,
945 tr("Permissions"),true, 928 (const QString &)fileNm);
946 0,(const QString &)fileNm); 929 QPEApplication::execDialog( filePerm );
947 QPEApplication::execDialog( filePerm ); 930
948 931 delete filePerm;
949 if( filePerm) 932 }
950 delete filePerm;
951 }
952// }
953 editor->setEdited( false); 933 editor->setEdited( false);
954 edited1 = false; 934 edited1 = false;
955 edited = false; 935 edited = false;
956 if(caption().left(1)=="*") 936 if(caption().left(1)=="*")
957 setCaption(caption().right(caption().length()-1)); 937 setCaption(caption().right(caption().length()-1));
958 938
959 return true; 939 return true;
960 } 940 }
961 odebug << "returning false" << oendl; 941 odebug << "returning false" << oendl;
962 currentFileName = ""; 942 currentFileName = "";
963 return false; 943 return false;
964} //end saveAs 944} //end saveAs
965 945
966void TextEdit::clear() { 946void TextEdit::clear() {
967 delete doc; 947 delete doc;
968 doc = 0; 948 doc = 0;
969 editor->clear(); 949 editor->clear();
970} 950}
971 951
972void TextEdit::updateCaption( const QString &name ) { 952void TextEdit::updateCaption( const QString &name ) {
973 953
974 if ( name.isEmpty() ) 954 if ( name.isEmpty() )
975 setCaption( tr("Text Editor") ); 955 setCaption( tr("Text Editor") );
976 else { 956 else {
977 QString s = name; 957 QString s = name;
978 if ( s.isNull() ) 958 if ( s.isNull() )
979 s = doc->name(); 959 s = doc->name();
980 if ( s.isEmpty() ) { 960 if ( s.isEmpty() ) {
981 s = tr( "Unnamed" ); 961 s = tr( "Unnamed" );
982 currentFileName=s; 962 currentFileName=s;
983 } 963 }
984// if(s.left(1) == "/") 964// if(s.left(1) == "/")
985// s = s.right(s.length()-1); 965// s = s.right(s.length()-1);
986 setCaption( tr("%1 - Text Editor").arg( s ) ); 966 setCaption( tr("%1 - Text Editor").arg( s ) );
987 } 967 }
988} 968}
989 969
990void TextEdit::setDocument(const QString& fileref) { 970void TextEdit::setDocument(const QString& fileref) {
991 if(fileref != "Unnamed") { 971 if(fileref != "Unnamed") {
992 currentFileName=fileref; 972 currentFileName=fileref;
993 odebug << "setDocument" << oendl; 973 odebug << "setDocument" << oendl;
994 QFileInfo fi(currentFileName); 974 QFileInfo fi(currentFileName);
995 odebug << "basename:"+fi.baseName()+": current filenmame "+currentFileName << oendl; 975 odebug << "basename:"+fi.baseName()+": current filenmame "+currentFileName << oendl;
996 if( (fi.baseName().left(1)).isEmpty() ) { 976 if( (fi.baseName().left(1)).isEmpty() ) {
997 openDotFile(currentFileName); 977 openDotFile(currentFileName);
998 978
999 } else { 979 } else {
1000 odebug << "setDoc open" << oendl; 980 odebug << "setDoc open" << oendl;
1001 bFromDocView = true; 981 bFromDocView = true;
1002 openFile(fileref); 982 openFile(fileref);
1003 editor->setEdited(true); 983 editor->setEdited(true);
1004 edited1=false; 984 edited1=false;
1005 edited=true; 985 edited=true;
1006 // fromSetDocument=false; 986 // fromSetDocument=false;
1007 // doSearchBar(); 987 // doSearchBar();
1008 } 988 }
1009 } 989 }
1010 updateCaption( currentFileName); 990 updateCaption( currentFileName);
1011} 991}
1012 992
1013void TextEdit::changeFont() { 993void TextEdit::changeFont() {
1014 QDialog *d = new QDialog ( this, "FontDialog", true ); 994 QDialog *d = new QDialog ( this, "FontDialog", true );
1015 d-> setCaption ( tr( "Choose font" )); 995 d-> setCaption ( tr( "Choose font" ));
1016 QBoxLayout *lay = new QVBoxLayout ( d ); 996 QBoxLayout *lay = new QVBoxLayout ( d );
1017 OFontSelector *ofs = new OFontSelector ( true, d ); 997 OFontSelector *ofs = new OFontSelector ( true, d );
1018 lay-> addWidget ( ofs ); 998 lay-> addWidget ( ofs );
1019 ofs-> setSelectedFont ( editor-> font ( )); 999 ofs-> setSelectedFont ( editor-> font ( ));
1020 1000
1021 if ( QPEApplication::execDialog( d ) == QDialog::Accepted ) 1001 if ( QPEApplication::execDialog( d ) == QDialog::Accepted )
1022 editor-> setFont ( ofs-> selectedFont ( )); 1002 editor-> setFont ( ofs-> selectedFont ( ));
1023 delete d; 1003 delete d;
1024 1004
1025} 1005}
1026 1006
1027void TextEdit::editDelete() { 1007void TextEdit::editDelete() {
1028 switch ( QMessageBox::warning(this,tr("Text Editor"), 1008 switch ( QMessageBox::warning(this,tr("Text Editor"),
1029 tr("Do you really want<BR>to <B>delete</B> " 1009 tr("Do you really want<BR>to <B>delete</B> "
1030 "the current file\nfrom the disk?<BR>This is " 1010 "the current file\nfrom the disk?<BR>This is "
1031 "<B>irreversable!</B>"), 1011 "<B>irreversable!</B>"),
1032 tr("Yes"),tr("No"),0,0,1) ) { 1012 tr("Yes"),tr("No"),0,0,1) ) {
1033 case 0: 1013 case 0:
1034 if(doc) { 1014 if(doc) {
1035 doc->removeFiles(); 1015 doc->removeFiles();
1036 clear(); 1016 clear();
1037 setCaption( tr("Text Editor") ); 1017 setCaption( tr("Text Editor") );
1038 } 1018 }
1039 break; 1019 break;
1040 case 1: 1020 case 1:
1041 // exit 1021 // exit
1042 break; 1022 break;
1043 }; 1023 };
1044} 1024}
1045 1025
1046void TextEdit::changeStartConfig( bool b ) { 1026void TextEdit::changeStartConfig( bool b ) {
1047 startWithNew=b; 1027 startWithNew=b;
1048 Config cfg("TextEdit"); 1028 Config cfg("TextEdit");
1049 cfg.setGroup("View"); 1029 cfg.setGroup("View");
1050 cfg.writeEntry("startNew",b); 1030 cfg.writeEntry("startNew",b);
1051 update(); 1031 update();
1052} 1032}
1053 1033
1054void TextEdit::editorChanged() { 1034void TextEdit::editorChanged() {
1055// odebug << "editor changed" << oendl; 1035// odebug << "editor changed" << oendl;
1056 if( /*editor->edited() &&*/ /*edited && */!edited1) { 1036 if( /*editor->edited() &&*/ /*edited && */!edited1) {
1057 setCaption( "*"+caption()); 1037 setCaption( "*"+caption());
1058 edited1=true; 1038 edited1=true;
1059 } 1039 }
1060 edited=true; 1040 edited=true;
1061} 1041}
1062 1042
1063void TextEdit::receive(const QCString&msg, const QByteArray &) { 1043void TextEdit::receive(const QCString&msg, const QByteArray &) {
1064 odebug << "QCop "+msg << oendl; 1044 odebug << "QCop "+msg << oendl;
1065 if ( msg == "setDocument(QString)" ) { 1045 if ( msg == "setDocument(QString)" ) {
1066 odebug << "bugger all" << oendl; 1046 odebug << "bugger all" << oendl;
1067 1047
1068 } 1048 }
1069 1049
1070} 1050}
1071 1051
1072void TextEdit::doAbout() { 1052void TextEdit::doAbout() {
1073 QMessageBox::about(0,tr("Text Edit"),tr("Text Edit is copyright<BR>" 1053 QMessageBox::about(0,tr("Text Edit"),tr("Text Edit is copyright<BR>"
1074 "2000 Trolltech AS, and<BR>" 1054 "2000 Trolltech AS, and<BR>"
1075 "2002 by <B>L. J. Potter <BR>llornkcor@handhelds.org</B><BR>" 1055 "2002 by <B>L. J. Potter <BR>llornkcor@handhelds.org</B><BR>"
1076 "and is licensed under the GPL")); 1056 "and is licensed under the GPL"));
1077} 1057}
1078 1058
1079void TextEdit::doPrompt(bool b) { 1059void TextEdit::doPrompt(bool b) {
1080 promptExit=b; 1060 promptExit=b;
1081 Config cfg("TextEdit"); 1061 Config cfg("TextEdit");
1082 cfg.setGroup ( "View" ); 1062 cfg.setGroup ( "View" );
1083 cfg.writeEntry ( "PromptExit", b); 1063 cfg.writeEntry ( "PromptExit", b);
1084} 1064}
1085 1065
1086void TextEdit::doDesktop(bool b) { 1066void TextEdit::doDesktop(bool b) {
1087 openDesktop=b; 1067 openDesktop=b;
1088 Config cfg("TextEdit"); 1068 Config cfg("TextEdit");
1089 cfg.setGroup ( "View" ); 1069 cfg.setGroup ( "View" );
1090 cfg.writeEntry ( "OpenDesktop", b); 1070 cfg.writeEntry ( "OpenDesktop", b);
1091} 1071}
1092 1072
1093void TextEdit::doFilePerms(bool b) { 1073void TextEdit::doFilePerms(bool b) {
1094 filePerms=b; 1074 filePerms=b;
1095 Config cfg("TextEdit"); 1075 Config cfg("TextEdit");
1096 cfg.setGroup ( "View" ); 1076 cfg.setGroup ( "View" );
1097 cfg.writeEntry ( "FilePermissions", b); 1077 cfg.writeEntry ( "FilePermissions", b);
1098} 1078}
1099 1079
1100void TextEdit::editPasteTimeDate() { 1080void TextEdit::editPasteTimeDate() {
1101#ifndef QT_NO_CLIPBOARD 1081#ifndef QT_NO_CLIPBOARD
1102 QClipboard *cb = QApplication::clipboard(); 1082 QClipboard *cb = QApplication::clipboard();
1103 QDateTime dt = QDateTime::currentDateTime(); 1083 QDateTime dt = QDateTime::currentDateTime();
1104 cb->setText( dt.toString()); 1084 cb->setText( dt.toString());
1105 editor->paste(); 1085 editor->paste();
1106#endif 1086#endif
1107} 1087}
1108 1088
1109int TextEdit::savePrompt() 1089int TextEdit::savePrompt()
1110{ 1090{
1111 switch( QMessageBox::information( 0, (tr("Textedit")), 1091 switch( QMessageBox::information( 0, (tr("Textedit")),
1112 (tr("Textedit detected\n" 1092 (tr("Textedit detected\n"
1113 "you have unsaved changes\n" 1093 "you have unsaved changes\n"
1114 "Go ahead and save?\n")), 1094 "Go ahead and save?\n")),
1115 (tr("Save")), (tr("Don't Save")), (tr("&Cancel")), 2, 2 ) ) 1095 (tr("Save")), (tr("Don't Save")), (tr("&Cancel")), 2, 2 ) )
1116 { 1096 {
1117 case 0: 1097 case 0:
1118 { 1098 {
1119 return 1; 1099 return 1;
1120 } 1100 }
1121 break; 1101 break;
1122 1102
1123 case 1: 1103 case 1:
1124 { 1104 {
1125 return 2; 1105 return 2;
1126 } 1106 }
1127 break; 1107 break;
1128 1108
1129 case 2: 1109 case 2:
1130 { 1110 {
1131 return -1; 1111 return -1;
1132 } 1112 }
1133 break; 1113 break;
1134 }; 1114 };
1135 1115
1136 return 0; 1116 return 0;
1137} 1117}
1138 1118
1139void TextEdit::timerCrank() 1119void TextEdit::timerCrank()
1140{ 1120{
1141 if(featureAutoSave && edited1) 1121 if(featureAutoSave && edited1)
1142 { 1122 {
1143 if(currentFileName.isEmpty()) 1123 if(currentFileName.isEmpty())
1144 { 1124 {
1145 currentFileName = QDir::homeDirPath()+"/textedit.tmp"; 1125 currentFileName = QDir::homeDirPath()+"/textedit.tmp";
1146 saveAs(); 1126 saveAs();
1147 } 1127 }
1148 else 1128 else
1149 { 1129 {
1150// odebug << "autosave" << oendl; 1130// odebug << "autosave" << oendl;
1151 save(); 1131 save();
1152 } 1132 }
1153 setTimer(); 1133 setTimer();
1154 } 1134 }
1155} 1135}
1156 1136
1157void TextEdit::doTimer(bool b) 1137void TextEdit::doTimer(bool b)
1158{ 1138{
1159 Config cfg("TextEdit"); 1139 Config cfg("TextEdit");
1160 cfg.setGroup ( "View" ); 1140 cfg.setGroup ( "View" );
1161 cfg.writeEntry ( "autosave", b); 1141 cfg.writeEntry ( "autosave", b);
1162 featureAutoSave = b; 1142 featureAutoSave = b;
1163 nAutoSave->setOn(b); 1143 nAutoSave->setOn(b);
1164 if(b) 1144 if(b)
1165 { 1145 {
1166// odebug << "doTimer true" << oendl; 1146// odebug << "doTimer true" << oendl;
1167 setTimer(); 1147 setTimer();
1168 } 1148 }
1169// else 1149// else
1170// odebug << "doTimer false" << oendl; 1150// odebug << "doTimer false" << oendl;
1171} 1151}
1172 1152
1173void TextEdit::setTimer() 1153void TextEdit::setTimer()
1174{ 1154{
1175if(featureAutoSave) 1155if(featureAutoSave)
1176 { 1156 {
1177// odebug << "setting autosave" << oendl; 1157// odebug << "setting autosave" << oendl;
1178 QTimer *timer = new QTimer(this ); 1158 QTimer *timer = new QTimer(this );
1179 connect( timer, SIGNAL(timeout()), this, SLOT(timerCrank()) ); 1159 connect( timer, SIGNAL(timeout()), this, SLOT(timerCrank()) );
1180 timer->start( 300000, true); //5 minutes 1160 timer->start( 300000, true); //5 minutes
1181 } 1161 }
1182} 1162}
1183 1163
1184void TextEdit::gotoLine() { 1164void TextEdit::gotoLine() {
1185 if( editor->length() < 1) 1165 if( editor->length() < 1)
1186 return; 1166 return;
1187 QWidget *d = QApplication::desktop(); 1167 QWidget *d = QApplication::desktop();
1188 gotoEdit = new QLineEdit( 0, "Goto line"); 1168 gotoEdit = new QLineEdit( 0, "Goto line");
1189 1169
1190 gotoEdit->move( (d->width()/2) - ( gotoEdit->width()/2) , (d->height()/2) - (gotoEdit->height()/2)); 1170 gotoEdit->move( (d->width()/2) - ( gotoEdit->width()/2) , (d->height()/2) - (gotoEdit->height()/2));
1191 gotoEdit->setFrame(true); 1171 gotoEdit->setFrame(true);
1192 gotoEdit->show(); 1172 gotoEdit->show();
1193 connect (gotoEdit,SIGNAL(returnPressed()), this, SLOT(doGoto())); 1173 connect (gotoEdit,SIGNAL(returnPressed()), this, SLOT(doGoto()));
1194} 1174}
1195 1175
1196void TextEdit::doGoto() { 1176void TextEdit::doGoto() {
1197 QString number = gotoEdit->text(); 1177 QString number = gotoEdit->text();
1198 gotoEdit->hide(); 1178 gotoEdit->hide();
1199 1179
1200 if(gotoEdit) { 1180 delete gotoEdit;
1201 delete gotoEdit; 1181 gotoEdit = 0;
1202 gotoEdit = 0;
1203 }
1204 1182
1205 bool ok; 1183 bool ok;
1206 int lineNumber = number.toInt(&ok, 10); 1184 int lineNumber = number.toInt(&ok, 10);
1207 if( editor->numLines() < lineNumber) 1185 if( editor->numLines() < lineNumber)
1208 QMessageBox::message(tr("Text Edit"),tr("Not enough lines")); 1186 QMessageBox::message(tr("Text Edit"),tr("Not enough lines"));
1209 else 1187 else
1210 { 1188 {
1211 editor->setCursorPosition(lineNumber, 0, false); 1189 editor->setCursorPosition(lineNumber, 0, false);
1212 } 1190 }
1213} 1191}
diff --git a/noncore/applets/notesapplet/notes.cpp b/noncore/applets/notesapplet/notes.cpp
index 13f297e..61a47d7 100644
--- a/noncore/applets/notesapplet/notes.cpp
+++ b/noncore/applets/notesapplet/notes.cpp
@@ -1,486 +1,486 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2002 L.J. Potter <llornkcor@handhelds.org> 2** Copyright (C) 2002 L.J. Potter <llornkcor@handhelds.org>
3 3
4** All rights reserved. 4** All rights reserved.
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**********************************************************************/ 14**********************************************************************/
15 15
16#include "notes.h" 16#include "notes.h"
17 17
18/* OPIE */ 18/* OPIE */
19#include <opie2/odebug.h> 19#include <opie2/odebug.h>
20#include <opie2/otaskbarapplet.h> 20#include <opie2/otaskbarapplet.h>
21#include <opie2/oresource.h> 21#include <opie2/oresource.h>
22#include <qpe/filemanager.h> 22#include <qpe/filemanager.h>
23#include <qpe/qpeapplication.h> 23#include <qpe/qpeapplication.h>
24#include <qpe/timestring.h> 24#include <qpe/timestring.h>
25#include <qpe/applnk.h> 25#include <qpe/applnk.h>
26#include <qpe/ir.h> 26#include <qpe/ir.h>
27#include <qpe/config.h> 27#include <qpe/config.h>
28using namespace Opie::Core; 28using namespace Opie::Core;
29using namespace Opie::Ui; 29using namespace Opie::Ui;
30 30
31/* QT */ 31/* QT */
32#include <qmultilineedit.h> 32#include <qmultilineedit.h>
33#include <qlistbox.h> 33#include <qlistbox.h>
34#include <qpopupmenu.h> 34#include <qpopupmenu.h>
35#include <qmessagebox.h> 35#include <qmessagebox.h>
36#include <qapplication.h> 36#include <qapplication.h>
37#include <qdir.h> 37#include <qdir.h>
38#include <qfile.h> 38#include <qfile.h>
39#include <qpoint.h> 39#include <qpoint.h>
40#include <qpushbutton.h> 40#include <qpushbutton.h>
41#include <qpainter.h> 41#include <qpainter.h>
42#include <qlayout.h> 42#include <qlayout.h>
43#include <qframe.h> 43#include <qframe.h>
44#include <qpixmap.h> 44#include <qpixmap.h>
45#include <qstring.h> 45#include <qstring.h>
46#include <qstringlist.h> 46#include <qstringlist.h>
47#include <qtimer.h> 47#include <qtimer.h>
48 48
49/* STD */ 49/* STD */
50#include <stdlib.h> 50#include <stdlib.h>
51 51
52NotesControl::NotesControl( QWidget *, const char * ) 52NotesControl::NotesControl( QWidget *, const char * )
53 : QVBox( 0, "NotesControl",/* WDestructiveClose | */WStyle_StaysOnTop ) 53 : QVBox( 0, "NotesControl",/* WDestructiveClose | */WStyle_StaysOnTop )
54// : QFrame( parent, name, WDestructiveClose | WStyle_StaysOnTop | WType_Popup ) 54// : QFrame( parent, name, WDestructiveClose | WStyle_StaysOnTop | WType_Popup )
55{ 55{
56 QDir d( QDir::homeDirPath()+"/notes"); 56 QDir d( QDir::homeDirPath()+"/notes");
57 if( !d.exists()) { 57 if( !d.exists()) {
58 odebug << "make dir" << oendl; 58 odebug << "make dir" << oendl;
59 if(!d.mkdir( QDir::homeDirPath()+"/notes", true)) 59 if(!d.mkdir( QDir::homeDirPath()+"/notes", true))
60 odebug << "<<<<<<<<<<<<<<<<<<<<<<<<<<<make dir failed" << oendl; 60 odebug << "<<<<<<<<<<<<<<<<<<<<<<<<<<<make dir failed" << oendl;
61 } 61 }
62 Config cfg("Notes"); 62 Config cfg("Notes");
63 cfg.setGroup("Options"); 63 cfg.setGroup("Options");
64 showMax = cfg.readBoolEntry("ShowMax", false); 64 showMax = cfg.readBoolEntry("ShowMax", false);
65 65
66 setFrameStyle( QFrame::PopupPanel | QFrame::Raised ); 66 setFrameStyle( QFrame::PopupPanel | QFrame::Raised );
67 loaded=false; 67 loaded=false;
68 edited=false; 68 edited=false;
69 doPopulate=true; 69 doPopulate=true;
70 isNew=false; 70 isNew=false;
71 QVBox *vbox = new QVBox( this, "Vlayout" ); 71 QVBox *vbox = new QVBox( this, "Vlayout" );
72 QHBox *hbox = new QHBox( this, "HLayout" ); 72 QHBox *hbox = new QHBox( this, "HLayout" );
73 73
74 view = new QMultiLineEdit(vbox, "OpieNotesView"); 74 view = new QMultiLineEdit(vbox, "OpieNotesView");
75 75
76 box = new QListBox(vbox, "OpieNotesBox"); 76 box = new QListBox(vbox, "OpieNotesBox");
77 77
78 QPEApplication::setStylusOperation( box->viewport(),QPEApplication::RightOnHold); 78 QPEApplication::setStylusOperation( box->viewport(),QPEApplication::RightOnHold);
79 79
80 box->setFixedHeight(50); 80 box->setFixedHeight(50);
81 81
82 vbox->setMargin( 6 ); 82 vbox->setMargin( 6 );
83 vbox->setSpacing( 3 ); 83 vbox->setSpacing( 3 );
84 84
85 85
86 86
87 setFocusPolicy(QWidget::StrongFocus); 87 setFocusPolicy(QWidget::StrongFocus);
88 88
89 newButton= new QPushButton( hbox, "newButton" ); 89 newButton= new QPushButton( hbox, "newButton" );
90 newButton->setText(tr("New")); 90 newButton->setText(tr("New"));
91 91
92 92
93 saveButton= new QPushButton( hbox, "saveButton" ); 93 saveButton= new QPushButton( hbox, "saveButton" );
94 saveButton->setText(tr("Save")); 94 saveButton->setText(tr("Save"));
95 95
96 96
97 deleteButton= new QPushButton( hbox, "deleteButton" ); 97 deleteButton= new QPushButton( hbox, "deleteButton" );
98 deleteButton->setText(tr("Delete")); 98 deleteButton->setText(tr("Delete"));
99 99
100 100
101 101
102 connect( box, SIGNAL( mouseButtonPressed(int,QListBoxItem*,const QPoint&)), 102 connect( box, SIGNAL( mouseButtonPressed(int,QListBoxItem*,const QPoint&)),
103 this,SLOT( boxPressed(int,QListBoxItem*,const QPoint&)) ); 103 this,SLOT( boxPressed(int,QListBoxItem*,const QPoint&)) );
104 104
105 connect(box, SIGNAL(highlighted(const QString&)), this, SLOT(slotBoxSelected(const QString&))); 105 connect(box, SIGNAL(highlighted(const QString&)), this, SLOT(slotBoxSelected(const QString&)));
106 106
107 connect( &menuTimer, SIGNAL( timeout() ), SLOT( showMenu() ) ); 107 connect( &menuTimer, SIGNAL( timeout() ), SLOT( showMenu() ) );
108 108
109 connect(view,SIGNAL( textChanged() ), this, SLOT(slotViewEdited() ) ); 109 connect(view,SIGNAL( textChanged() ), this, SLOT(slotViewEdited() ) );
110 110
111 connect(newButton, SIGNAL(clicked()), this, SLOT(slotNewButton())); 111 connect(newButton, SIGNAL(clicked()), this, SLOT(slotNewButton()));
112 connect(saveButton, SIGNAL(clicked()), this, SLOT(slotSaveButton())); 112 connect(saveButton, SIGNAL(clicked()), this, SLOT(slotSaveButton()));
113 connect(deleteButton, SIGNAL(clicked()), this, SLOT(slotDeleteButtonClicked())); 113 connect(deleteButton, SIGNAL(clicked()), this, SLOT(slotDeleteButtonClicked()));
114 114
115 populateBox(); 115 populateBox();
116 load(); 116 load();
117 setCaption("Notes"); 117 setCaption("Notes");
118 // parent->setFocus(); 118 // parent->setFocus();
119} 119}
120 120
121void NotesControl::slotSaveButton() { 121void NotesControl::slotSaveButton() {
122 slotNewButton(); 122 slotNewButton();
123 populateBox(); 123 populateBox();
124} 124}
125 125
126void NotesControl::slotDeleteButtonClicked() { 126void NotesControl::slotDeleteButtonClicked() {
127 switch ( QMessageBox::warning(this,tr("Delete?") 127 switch ( QMessageBox::warning(this,tr("Delete?")
128 ,tr("Do you really want to<BR><B> delete</B> this note ?") 128 ,tr("Do you really want to<BR><B> delete</B> this note ?")
129 ,tr("Yes"),tr("No"),0,1,1) ) { 129 ,tr("Yes"),tr("No"),0,1,1) ) {
130 case 0: 130 case 0:
131 slotDeleteButton(); 131 slotDeleteButton();
132 break; 132 break;
133 }; 133 };
134} 134}
135 135
136void NotesControl::slotDeleteButton() { 136void NotesControl::slotDeleteButton() {
137 137
138 QString selectedText = box->currentText(); 138 QString selectedText = box->currentText();
139 odebug << "deleting "+selectedText << oendl; 139 odebug << "deleting "+selectedText << oendl;
140 140
141 if( !selectedText.isEmpty()) { 141 if( !selectedText.isEmpty()) {
142 142
143 Config cfg("Notes"); 143 Config cfg("Notes");
144 cfg.setGroup("Docs"); 144 cfg.setGroup("Docs");
145 int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); 145 int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 );
146 QString entryName, entryName2;; 146 QString entryName, entryName2;;
147 for ( int i = 0; i < noOfFiles; i++ ) { 147 for ( int i = 0; i < noOfFiles; i++ ) {
148 entryName.sprintf( "File%i", i + 1 ); 148 entryName.sprintf( "File%i", i + 1 );
149 if(selectedText == cfg.readEntry( entryName )) { 149 if(selectedText == cfg.readEntry( entryName )) {
150 odebug << "removing " << selectedText.latin1() << ", " << i << "" << oendl; 150 odebug << "removing " << selectedText.latin1() << ", " << i << "" << oendl;
151 for ( int j = i; j < noOfFiles; j++ ) { 151 for ( int j = i; j < noOfFiles; j++ ) {
152 entryName.sprintf( "File%i", i + 1 ); 152 entryName.sprintf( "File%i", i + 1 );
153 entryName2.sprintf( "File%i", i + 2 ); 153 entryName2.sprintf( "File%i", i + 2 );
154 QString temp = cfg.readEntry(entryName2); 154 QString temp = cfg.readEntry(entryName2);
155 odebug << "move "+temp << oendl; 155 odebug << "move "+temp << oendl;
156 cfg.writeEntry(entryName, temp); 156 cfg.writeEntry(entryName, temp);
157 i++; 157 i++;
158 } 158 }
159 cfg.writeEntry("NumberOfFiles", noOfFiles-1 ); 159 cfg.writeEntry("NumberOfFiles", noOfFiles-1 );
160 entryName.sprintf( "File%i", noOfFiles ); 160 entryName.sprintf( "File%i", noOfFiles );
161 cfg.removeEntry(entryName); 161 cfg.removeEntry(entryName);
162 cfg.write(); 162 cfg.write();
163 DocLnk nf(selectedText); 163 DocLnk nf(selectedText);
164 nf.removeFiles(); 164 nf.removeFiles();
165 QString fi=QPEApplication::documentDir()+"/text/plain/"+selectedText+".desktop"; 165 QString fi=QPEApplication::documentDir()+"/text/plain/"+selectedText+".desktop";
166 odebug << fi << oendl; 166 odebug << fi << oendl;
167 167
168 QFile f( fi); 168 QFile f( fi);
169 if( !f.remove()) odebug << ".desktop file not removed" << oendl; 169 if( !f.remove()) odebug << ".desktop file not removed" << oendl;
170 170
171 } 171 }
172 } 172 }
173 view->clear(); 173 view->clear();
174 174
175 populateBox(); 175 populateBox();
176 } 176 }
177} 177}
178 178
179void NotesControl::slotNewButton() { 179void NotesControl::slotNewButton() {
180 if(edited) save(); 180 if(edited) save();
181 view->clear(); 181 view->clear();
182 view->setFocus(); 182 view->setFocus();
183 edited=false; 183 edited=false;
184 isNew=false; 184 isNew=false;
185} 185}
186 186
187void NotesControl::slotBeamButton() { 187void NotesControl::slotBeamButton() {
188 Ir ir; 188 Ir ir;
189 if(!ir.supported()){ 189 if(!ir.supported()){
190 } else { 190 } else {
191 this->hide(); 191 this->hide();
192 QString selectedText = box->currentText(); 192 QString selectedText = box->currentText();
193 if( !selectedText.isEmpty()) { 193 if( !selectedText.isEmpty()) {
194 QString file = QDir::homeDirPath()+"/"+selectedText; 194 QString file = QDir::homeDirPath()+"/"+selectedText;
195 QFile f(file); 195 QFile f(file);
196 Ir *irFile = new Ir(this, "IR"); 196 Ir *irFile = new Ir(this, "IR");
197 connect( irFile, SIGNAL(done(Ir*)), this, SLOT( slotBeamFinished(Ir*))); 197 connect( irFile, SIGNAL(done(Ir*)), this, SLOT( slotBeamFinished(Ir*)));
198 irFile->send( file, "Note", "text/plain" ); 198 irFile->send( file, "Note", "text/plain" );
199 } 199 }
200 } 200 }
201} 201}
202 202
203void NotesControl::slotBeamFinished(Ir *) { 203void NotesControl::slotBeamFinished(Ir *) {
204 this->show(); 204 this->show();
205} 205}
206 206
207void NotesControl::boxPressed(int mouse, QListBoxItem *, const QPoint&) { 207void NotesControl::boxPressed(int mouse, QListBoxItem *, const QPoint&) {
208 switch (mouse) { 208 switch (mouse) {
209 case 1:{ 209 case 1:{
210 } 210 }
211 break; 211 break;
212 case 2: 212 case 2:
213 menuTimer.start( 500, TRUE ); 213 menuTimer.start( 500, TRUE );
214 break; 214 break;
215 }; 215 };
216} 216}
217 217
218void NotesControl::slotBoxSelected(const QString &itemString) { 218void NotesControl::slotBoxSelected(const QString &itemString) {
219 if(edited) { 219 if(edited) {
220 save(); 220 save();
221 } 221 }
222 loaded=false; 222 loaded=false;
223 edited=false; 223 edited=false;
224 load(itemString); 224 load(itemString);
225} 225}
226 226
227 227
228void NotesControl::showMenu() { 228void NotesControl::showMenu() {
229 QPopupMenu *m = new QPopupMenu(0); 229 QPopupMenu *m = new QPopupMenu(0);
230 m->insertItem( tr( "Beam Out" ), this, SLOT( slotBeamButton() )); 230 m->insertItem( tr( "Beam Out" ), this, SLOT( slotBeamButton() ));
231 m->insertItem( tr( "Search For..." ), this, SLOT( slotSearch() )); 231 m->insertItem( tr( "Search For..." ), this, SLOT( slotSearch() ));
232 m->insertItem( tr( "Toggle Maximized" ), this, SLOT( slotShowMax() )); 232 m->insertItem( tr( "Toggle Maximized" ), this, SLOT( slotShowMax() ));
233 m->insertSeparator(); 233 m->insertSeparator();
234 m->insertItem( tr( "Delete" ), this, SLOT( slotDeleteButton() )); 234 m->insertItem( tr( "Delete" ), this, SLOT( slotDeleteButton() ));
235 m->setFocus(); 235 m->setFocus();
236 m->exec( QCursor::pos() ); 236 m->exec( QCursor::pos() );
237 237
238 if(m) delete m; 238 delete m;
239} 239}
240 240
241void NotesControl::focusOutEvent ( QFocusEvent * e) { 241void NotesControl::focusOutEvent ( QFocusEvent * e) {
242 if( e->reason() == QFocusEvent::Popup) 242 if( e->reason() == QFocusEvent::Popup)
243 save(); 243 save();
244 else { 244 else {
245 if(!loaded) { 245 if(!loaded) {
246 populateBox(); 246 populateBox();
247 load(); 247 load();
248 } 248 }
249 } 249 }
250 QWidget::focusOutEvent(e); 250 QWidget::focusOutEvent(e);
251} 251}
252 252
253void NotesControl::save() { 253void NotesControl::save() {
254 Config cfg("Notes"); 254 Config cfg("Notes");
255 cfg.setGroup("Docs"); 255 cfg.setGroup("Docs");
256 if( edited) { 256 if( edited) {
257// odebug << "is edited" << oendl; 257// odebug << "is edited" << oendl;
258 QString rt = view->text(); 258 QString rt = view->text();
259 if( rt.length()>1) { 259 if( rt.length()>1) {
260 QString pt = rt.simplifyWhiteSpace(); 260 QString pt = rt.simplifyWhiteSpace();
261 int i = pt.find( ' ', pt.find( ' ' )+2 ); 261 int i = pt.find( ' ', pt.find( ' ' )+2 );
262 QString docname = pt; 262 QString docname = pt;
263 if ( i > 0 ) 263 if ( i > 0 )
264 docname = pt.left(i); 264 docname = pt.left(i);
265 // remove "." at the beginning 265 // remove "." at the beginning
266 while( docname.startsWith( "." ) ) 266 while( docname.startsWith( "." ) )
267 docname = docname.mid( 1 ); 267 docname = docname.mid( 1 );
268 docname.replace( QRegExp("/"), "_" ); 268 docname.replace( QRegExp("/"), "_" );
269 // cut the length. filenames longer than that don't make sense 269 // cut the length. filenames longer than that don't make sense
270 // and something goes wrong when they get too long. 270 // and something goes wrong when they get too long.
271 if ( docname.length() > 40 ) 271 if ( docname.length() > 40 )
272 docname = docname.left(40); 272 docname = docname.left(40);
273 if ( docname.isEmpty() ) 273 if ( docname.isEmpty() )
274 docname = "Empty Text"; 274 docname = "Empty Text";
275// odebug << docname << oendl; 275// odebug << docname << oendl;
276 276
277 if( oldDocName != docname) { 277 if( oldDocName != docname) {
278 int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); 278 int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 );
279 QString entryName; 279 QString entryName;
280 entryName.sprintf( "File%i", noOfFiles + 1 ); 280 entryName.sprintf( "File%i", noOfFiles + 1 );
281 cfg.writeEntry( entryName,docname ); 281 cfg.writeEntry( entryName,docname );
282 cfg.writeEntry("NumberOfFiles", noOfFiles+1 ); 282 cfg.writeEntry("NumberOfFiles", noOfFiles+1 );
283 cfg.write(); 283 cfg.write();
284 } 284 }
285// else 285// else
286// odebug << "oldname equals docname" << oendl; 286// odebug << "oldname equals docname" << oendl;
287 287
288 doc = new DocLnk(docname); 288 doc = new DocLnk(docname);
289 if(QFile(doc->linkFile()).exists()) 289 if(QFile(doc->linkFile()).exists())
290 odebug << "puppie" << oendl; 290 odebug << "puppie" << oendl;
291 doc->setType("text/plain"); 291 doc->setType("text/plain");
292 doc->setName(docname); 292 doc->setName(docname);
293 QString temp = docname.replace( QRegExp(" "), "_" ); 293 QString temp = docname.replace( QRegExp(" "), "_" );
294 doc->setFile( QDir::homeDirPath()+"/notes/"+temp); 294 doc->setFile( QDir::homeDirPath()+"/notes/"+temp);
295 FileManager fm; 295 FileManager fm;
296 if ( !fm.saveFile( *doc, rt ) ) { 296 if ( !fm.saveFile( *doc, rt ) ) {
297 } 297 }
298 298
299 oldDocName=docname; 299 oldDocName=docname;
300 edited=false; 300 edited=false;
301// odebug << "save" << oendl; 301// odebug << "save" << oendl;
302 if (doPopulate) 302 if (doPopulate)
303 populateBox(); 303 populateBox();
304 } 304 }
305 cfg.writeEntry( "LastDoc",oldDocName ); 305 cfg.writeEntry( "LastDoc",oldDocName );
306 cfg.write(); 306 cfg.write();
307 307
308 } 308 }
309} 309}
310 310
311void NotesControl::populateBox() { 311void NotesControl::populateBox() {
312 box->clear(); 312 box->clear();
313// odebug << "populate" << oendl; 313// odebug << "populate" << oendl;
314 Config cfg("Notes"); 314 Config cfg("Notes");
315 cfg.setGroup("Docs"); 315 cfg.setGroup("Docs");
316 int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); 316 int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 );
317 QStringList list; 317 QStringList list;
318 QString entryName; 318 QString entryName;
319 for ( int i = 0; i < noOfFiles; i++ ) { 319 for ( int i = 0; i < noOfFiles; i++ ) {
320 entryName.sprintf( "File%i", i + 1 ); 320 entryName.sprintf( "File%i", i + 1 );
321 list.append(cfg.readEntry( entryName )); 321 list.append(cfg.readEntry( entryName ));
322 } 322 }
323 list.sort(); 323 list.sort();
324 box->insertStringList(list,-1); 324 box->insertStringList(list,-1);
325 doPopulate=false; 325 doPopulate=false;
326 update(); 326 update();
327} 327}
328 328
329void NotesControl::load() { 329void NotesControl::load() {
330 330
331 if(!loaded) { 331 if(!loaded) {
332 Config cfg("Notes"); 332 Config cfg("Notes");
333 cfg.setGroup("Docs"); 333 cfg.setGroup("Docs");
334 QString lastDoc=cfg.readEntry( "LastDoc","notes"); 334 QString lastDoc=cfg.readEntry( "LastDoc","notes");
335 DocLnk nf; 335 DocLnk nf;
336 nf.setType("text/plain"); 336 nf.setType("text/plain");
337 nf.setFile(lastDoc); 337 nf.setFile(lastDoc);
338 338
339 loadDoc(nf); 339 loadDoc(nf);
340 loaded=true; 340 loaded=true;
341 oldDocName=lastDoc; 341 oldDocName=lastDoc;
342 cfg.writeEntry( "LastDoc",oldDocName ); 342 cfg.writeEntry( "LastDoc",oldDocName );
343 cfg.write(); 343 cfg.write();
344 } 344 }
345} 345}
346 346
347void NotesControl::load(const QString & file) { 347void NotesControl::load(const QString & file) {
348 odebug << "loading "+file << oendl; 348 odebug << "loading "+file << oendl;
349 QString name = file; 349 QString name = file;
350 QString temp; 350 QString temp;
351 if( !QFile( QDir::homeDirPath()+"/"+file).exists() ) 351 if( !QFile( QDir::homeDirPath()+"/"+file).exists() )
352 temp = QDir::homeDirPath()+"/notes/"+ name.replace( QRegExp(" "), "_" ); 352 temp = QDir::homeDirPath()+"/notes/"+ name.replace( QRegExp(" "), "_" );
353 else 353 else
354 temp = name; 354 temp = name;
355 if(!loaded) { 355 if(!loaded) {
356 DocLnk nf; 356 DocLnk nf;
357 nf.setType("text/plain"); 357 nf.setType("text/plain");
358 nf.setFile( temp); 358 nf.setFile( temp);
359 if(!temp.isEmpty()) 359 if(!temp.isEmpty())
360 loadDoc(nf); 360 loadDoc(nf);
361 loaded=true; 361 loaded=true;
362 } 362 }
363// view->setFocus(); 363// view->setFocus();
364 oldDocName=file; 364 oldDocName=file;
365 Config cfg("Notes"); 365 Config cfg("Notes");
366 cfg.setGroup("Docs"); 366 cfg.setGroup("Docs");
367 cfg.writeEntry( "LastDoc",oldDocName ); 367 cfg.writeEntry( "LastDoc",oldDocName );
368 cfg.write(); 368 cfg.write();
369} 369}
370 370
371void NotesControl::loadDoc( const DocLnk &f) { 371void NotesControl::loadDoc( const DocLnk &f) {
372 FileManager fm; 372 FileManager fm;
373 QString txt; 373 QString txt;
374 if ( !fm.loadFile( f, txt ) ) { 374 if ( !fm.loadFile( f, txt ) ) {
375 odebug << "could not load file "+f.file() << oendl; 375 odebug << "could not load file "+f.file() << oendl;
376 return; 376 return;
377 } 377 }
378 view->setText(txt); 378 view->setText(txt);
379} 379}
380 380
381void NotesControl::slotViewEdited() { 381void NotesControl::slotViewEdited() {
382 if(loaded) { 382 if(loaded) {
383 edited=true; 383 edited=true;
384 } 384 }
385} 385}
386 386
387 387
388void NotesControl::slotShowMax() { 388void NotesControl::slotShowMax() {
389 Config cfg("Notes"); 389 Config cfg("Notes");
390 cfg.setGroup("Options"); 390 cfg.setGroup("Options");
391 showMax=!showMax; 391 showMax=!showMax;
392 cfg.writeEntry("ShowMax", showMax); 392 cfg.writeEntry("ShowMax", showMax);
393 cfg.write(); 393 cfg.write();
394 hide(); 394 hide();
395} 395}
396 396
397void NotesControl::slotSearch() { 397void NotesControl::slotSearch() {
398 int boxCount = box->count(); 398 int boxCount = box->count();
399 for(int i=0;i< boxCount;i++) { 399 for(int i=0;i< boxCount;i++) {
400 400
401 } 401 }
402} 402}
403 403
404// void NotesControl::keyReleaseEvent( QKeyEvent *e) { 404// void NotesControl::keyReleaseEvent( QKeyEvent *e) {
405 405
406// switch ( e->state() ) { 406// switch ( e->state() ) {
407// case ControlButton: 407// case ControlButton:
408// if(e->key() == Key_C) { //copy 408// if(e->key() == Key_C) { //copy
409// odebug << "copy" << oendl; 409// odebug << "copy" << oendl;
410// QClipboard *cb = QApplication::clipboard(); 410// QClipboard *cb = QApplication::clipboard();
411// QString text; 411// QString text;
412 412
413// // Copy text from the clipboard (paste) 413// // Copy text from the clipboard (paste)
414// text = cb->text(); 414// text = cb->text();
415// } 415// }
416// if(e->key() == Key_X) { //cut 416// if(e->key() == Key_X) { //cut
417// } 417// }
418// if(e->key() == Key_V) { //paste 418// if(e->key() == Key_V) { //paste
419// QClipboard *cb = QApplication::clipboard(); 419// QClipboard *cb = QApplication::clipboard();
420// QString text; 420// QString text;
421// //view 421// //view
422// cb->setText(); 422// cb->setText();
423// } 423// }
424// break; 424// break;
425// }; 425// };
426// QWidget::keyReleaseEvent(e); 426// QWidget::keyReleaseEvent(e);
427// } 427// }
428 428
429//=========================================================================== 429//===========================================================================
430 430
431NotesApplet::NotesApplet( QWidget *parent, const char *name ) 431NotesApplet::NotesApplet( QWidget *parent, const char *name )
432 : QWidget( parent, name ) { 432 : QWidget( parent, name ) {
433 setFixedHeight( AppLnk::smallIconSize() ); 433 setFixedHeight( AppLnk::smallIconSize() );
434 setFixedWidth( AppLnk::smallIconSize() ); 434 setFixedWidth( AppLnk::smallIconSize() );
435 notesPixmap = Opie::Core::OResource::loadImage( "edit", Opie::Core::OResource::SmallIcon ); 435 notesPixmap = Opie::Core::OResource::loadImage( "edit", Opie::Core::OResource::SmallIcon );
436 vc = new NotesControl; 436 vc = new NotesControl;
437} 437}
438 438
439NotesApplet::~NotesApplet() { 439NotesApplet::~NotesApplet() {
440 delete vc; 440 delete vc;
441} 441}
442 442
443int NotesApplet::position() 443int NotesApplet::position()
444{ 444{
445 return 6; 445 return 6;
446} 446}
447 447
448void NotesApplet::mousePressEvent( QMouseEvent *) { 448void NotesApplet::mousePressEvent( QMouseEvent *) {
449 if( !vc->isHidden()) { 449 if( !vc->isHidden()) {
450 vc->doPopulate=false; 450 vc->doPopulate=false;
451 vc->save(); 451 vc->save();
452 vc->close(); 452 vc->close();
453 } else { 453 } else {
454// vc = new NotesControl; 454// vc = new NotesControl;
455// QPoint curPos = mapToGlobal( rect().topLeft() ); 455// QPoint curPos = mapToGlobal( rect().topLeft() );
456 if(vc->showMax) { 456 if(vc->showMax) {
457 odebug << "show max" << oendl; 457 odebug << "show max" << oendl;
458 vc->showMaximized(); 458 vc->showMaximized();
459 } else { 459 } else {
460 odebug << "no show max" << oendl; 460 odebug << "no show max" << oendl;
461 QWidget *wid = QPEApplication::desktop(); 461 QWidget *wid = QPEApplication::desktop();
462 QRect rect = QApplication::desktop()->geometry(); 462 QRect rect = QApplication::desktop()->geometry();
463 vc->setGeometry( ( wid->width() / 2) - ( vc->width() / 2 ) , 28 , wid->width() -10 , 180); 463 vc->setGeometry( ( wid->width() / 2) - ( vc->width() / 2 ) , 28 , wid->width() -10 , 180);
464 vc->move ( (rect.center()/2) - (vc->rect().center()/2)); 464 vc->move ( (rect.center()/2) - (vc->rect().center()/2));
465// vc->move( (( wid->width() / 2) - ( vc->width() / 2 ))-4, 28); 465// vc->move( (( wid->width() / 2) - ( vc->width() / 2 ))-4, 28);
466 } 466 }
467 vc->show(); 467 vc->show();
468 vc->doPopulate=true; 468 vc->doPopulate=true;
469 vc->populateBox(); 469 vc->populateBox();
470 vc->doPopulate=false; 470 vc->doPopulate=false;
471 vc->loaded=false; 471 vc->loaded=false;
472 472
473 vc->load(); 473 vc->load();
474// this->setFocus(); 474// this->setFocus();
475 vc->view->setFocus(); 475 vc->view->setFocus();
476 } 476 }
477} 477}
478 478
479void NotesApplet::paintEvent( QPaintEvent* ) { 479void NotesApplet::paintEvent( QPaintEvent* ) {
480 QPainter p(this); 480 QPainter p(this);
481 p.drawPixmap( 0, 2, notesPixmap ); 481 p.drawPixmap( 0, 2, notesPixmap );
482} 482}
483 483
484 484
485EXPORT_OPIE_APPLET_v1( NotesApplet ) 485EXPORT_OPIE_APPLET_v1( NotesApplet )
486 486
diff --git a/noncore/apps/advancedfm/advancedfm.cpp b/noncore/apps/advancedfm/advancedfm.cpp
index 828f5a1..cf19ba8 100644
--- a/noncore/apps/advancedfm/advancedfm.cpp
+++ b/noncore/apps/advancedfm/advancedfm.cpp
@@ -1,739 +1,739 @@
1/*************************************************************************** 1/***************************************************************************
2 AdvancedFm.cpp 2 AdvancedFm.cpp
3 ------------------- 3 -------------------
4 ** Created: Sat Mar 9 23:33:09 2002 4 ** Created: Sat Mar 9 23:33:09 2002
5 copyright : (C) 2002 by ljp 5 copyright : (C) 2002 by ljp
6 email : ljp@llornkcor.com 6 email : ljp@llornkcor.com
7 * This program is free software; you can redistribute it and/or modify * 7 * This program is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by * 8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or * 9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. * 10 * (at your option) any later version. *
11 ***************************************************************************/ 11 ***************************************************************************/
12#define DEVELOPERS_VERSION 12#define DEVELOPERS_VERSION
13#include "advancedfm.h" 13#include "advancedfm.h"
14 14
15#include <opie2/odebug.h> 15#include <opie2/odebug.h>
16#include <opie2/oresource.h> 16#include <opie2/oresource.h>
17#include <opie2/ostorageinfo.h> 17#include <opie2/ostorageinfo.h>
18 18
19#include <qpe/qpeapplication.h> 19#include <qpe/qpeapplication.h>
20#include <qpe/config.h> 20#include <qpe/config.h>
21#include <qpe/mimetype.h> 21#include <qpe/mimetype.h>
22#include <qpe/applnk.h> 22#include <qpe/applnk.h>
23#include <qpe/menubutton.h> 23#include <qpe/menubutton.h>
24 24
25#include <qcombobox.h> 25#include <qcombobox.h>
26#include <qpopupmenu.h> 26#include <qpopupmenu.h>
27#include <qlistview.h> 27#include <qlistview.h>
28#include <qmessagebox.h> 28#include <qmessagebox.h>
29#include <qlineedit.h> 29#include <qlineedit.h>
30 30
31 31
32#include <sys/stat.h> 32#include <sys/stat.h>
33#include <time.h> 33#include <time.h>
34#include <dirent.h> 34#include <dirent.h>
35#include <fcntl.h> 35#include <fcntl.h>
36#include <sys/vfs.h> 36#include <sys/vfs.h>
37#include <mntent.h> 37#include <mntent.h>
38 38
39using namespace Opie::Ui; 39using namespace Opie::Ui;
40 40
41AdvancedFm::AdvancedFm(QWidget *,const char*, WFlags ) 41AdvancedFm::AdvancedFm(QWidget *,const char*, WFlags )
42 : QMainWindow( ) { 42 : QMainWindow( ) {
43 init(); 43 init();
44 renameBox = 0; 44 renameBox = 0;
45 whichTab = 1; 45 whichTab = 1;
46 unknownXpm = Opie::Core::OResource::loadImage("UnknownDocument", Opie::Core::OResource::SmallIcon); 46 unknownXpm = Opie::Core::OResource::loadImage("UnknownDocument", Opie::Core::OResource::SmallIcon);
47 47
48 initConnections(); 48 initConnections();
49 rePopulate(); 49 rePopulate();
50 channel = new QCopChannel( "QPE/Application/advancedfm", this ); 50 channel = new QCopChannel( "QPE/Application/advancedfm", this );
51 connect(channel,SIGNAL(received(const QCString&,const QByteArray&)),this,SLOT(qcopReceive(const QCString&,const QByteArray&))); 51 connect(channel,SIGNAL(received(const QCString&,const QByteArray&)),this,SLOT(qcopReceive(const QCString&,const QByteArray&)));
52 switchToLocalTab(); 52 switchToLocalTab();
53} 53}
54 54
55AdvancedFm::~AdvancedFm() { 55AdvancedFm::~AdvancedFm() {
56} 56}
57 57
58 58
59void AdvancedFm::cleanUp() { 59void AdvancedFm::cleanUp() {
60 QString sfile=QDir::homeDirPath(); 60 QString sfile=QDir::homeDirPath();
61 if(sfile.right(1) != "/") 61 if(sfile.right(1) != "/")
62 sfile+="/._temp"; 62 sfile+="/._temp";
63 else 63 else
64 sfile+="._temp"; 64 sfile+="._temp";
65 QFile file( sfile); 65 QFile file( sfile);
66 if(file.exists()) 66 if(file.exists())
67 file.remove(); 67 file.remove();
68} 68}
69 69
70void AdvancedFm::tabChanged(QWidget *wd) { 70void AdvancedFm::tabChanged(QWidget *wd) {
71 if(wd == tab) { 71 if(wd == tab) {
72 whichTab = 1; 72 whichTab = 1;
73 viewMenu->setItemChecked(viewMenu->idAt(0), true); 73 viewMenu->setItemChecked(viewMenu->idAt(0), true);
74 viewMenu->setItemChecked(viewMenu->idAt(1), false); 74 viewMenu->setItemChecked(viewMenu->idAt(1), false);
75 // qDebug("tabchanged: LOCAL VIEW SHOWN"); 75 // qDebug("tabchanged: LOCAL VIEW SHOWN");
76 } 76 }
77 77
78 else if(wd == tab_2) { 78 else if(wd == tab_2) {
79 whichTab = 2; 79 whichTab = 2;
80 viewMenu->setItemChecked(viewMenu->idAt(0), false); 80 viewMenu->setItemChecked(viewMenu->idAt(0), false);
81 viewMenu->setItemChecked(viewMenu->idAt(1), true); 81 viewMenu->setItemChecked(viewMenu->idAt(1), true);
82 // qDebug("tabchanged: REMOTE VIEW SHOWN"); 82 // qDebug("tabchanged: REMOTE VIEW SHOWN");
83 } 83 }
84 qApp->processEvents(); 84 qApp->processEvents();
85 QString path = CurrentDir()->canonicalPath(); 85 QString path = CurrentDir()->canonicalPath();
86 86
87 chdir( path.latin1()); 87 chdir( path.latin1());
88 currentPathCombo->lineEdit()->setText(path); 88 currentPathCombo->lineEdit()->setText(path);
89} 89}
90 90
91 91
92void AdvancedFm::populateView() { 92void AdvancedFm::populateView() {
93 93
94 QPixmap pm; 94 QPixmap pm;
95 QListView *thisView = CurrentView(); 95 QListView *thisView = CurrentView();
96 QDir *thisDir = CurrentDir(); 96 QDir *thisDir = CurrentDir();
97 QString path = thisDir->canonicalPath(); 97 QString path = thisDir->canonicalPath();
98 98
99 thisView->clear(); 99 thisView->clear();
100 thisDir->setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); 100 thisDir->setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst);
101 thisDir->setMatchAllDirs(TRUE); 101 thisDir->setMatchAllDirs(TRUE);
102 thisDir->setNameFilter(filterStr); 102 thisDir->setNameFilter(filterStr);
103 QString fileL, fileS, fileDate; 103 QString fileL, fileS, fileDate;
104 104
105 QString fs = getFileSystemType((const QString &) path); 105 QString fs = getFileSystemType((const QString &) path);
106 setCaption(tr("AdvancedFm :: ")+fs+" :: " 106 setCaption(tr("AdvancedFm :: ")+fs+" :: "
107 +checkDiskSpace((const QString &) path)+ tr(" kB free") ); 107 +checkDiskSpace((const QString &) path)+ tr(" kB free") );
108 bool isDir = FALSE; 108 bool isDir = FALSE;
109 109
110 const QFileInfoList *list = thisDir->entryInfoList( /*QDir::All*/ /*, QDir::SortByMask*/); 110 const QFileInfoList *list = thisDir->entryInfoList( /*QDir::All*/ /*, QDir::SortByMask*/);
111 QFileInfoListIterator it(*list); 111 QFileInfoListIterator it(*list);
112 QFileInfo *fi; 112 QFileInfo *fi;
113 while ( (fi=it.current()) ) { 113 while ( (fi=it.current()) ) {
114 if (fi->isSymLink() ) { 114 if (fi->isSymLink() ) {
115 QString symLink = fi->readLink(); 115 QString symLink = fi->readLink();
116 QFileInfo sym( symLink); 116 QFileInfo sym( symLink);
117 fileS.sprintf( "%10i", sym.size() ); 117 fileS.sprintf( "%10i", sym.size() );
118 fileL = fi->fileName() +" -> " + sym.filePath().data(); 118 fileL = fi->fileName() +" -> " + sym.filePath().data();
119 fileDate = sym.lastModified().toString(); 119 fileDate = sym.lastModified().toString();
120 } else { 120 } else {
121 fileS.sprintf( "%10i", fi->size() ); 121 fileS.sprintf( "%10i", fi->size() );
122 fileL = fi->fileName(); 122 fileL = fi->fileName();
123 fileDate= fi->lastModified().toString(); 123 fileDate= fi->lastModified().toString();
124 if( QDir(QDir::cleanDirPath( path +"/"+fileL)).exists() ) { 124 if( QDir(QDir::cleanDirPath( path +"/"+fileL)).exists() ) {
125// if(fileL == "..") 125// if(fileL == "..")
126 fileL += "/"; 126 fileL += "/";
127 isDir=TRUE; 127 isDir=TRUE;
128 } 128 }
129 } 129 }
130 QFileInfo fileInfo( path + "/" + fileL); 130 QFileInfo fileInfo( path + "/" + fileL);
131 131
132 if(fileL !="./" && fi->exists()) { 132 if(fileL !="./" && fi->exists()) {
133 item = new QListViewItem( thisView, fileL, fileS , fileDate); 133 item = new QListViewItem( thisView, fileL, fileS , fileDate);
134 134
135 if(isDir || fileL.find("/",0,TRUE) != -1) { 135 if(isDir || fileL.find("/",0,TRUE) != -1) {
136 136
137 if( !QDir( fi->filePath() ).isReadable()) //is directory 137 if( !QDir( fi->filePath() ).isReadable()) //is directory
138 pm = Opie::Core::OResource::loadPixmap( "lockedfolder", Opie::Core::OResource::SmallIcon ); 138 pm = Opie::Core::OResource::loadPixmap( "lockedfolder", Opie::Core::OResource::SmallIcon );
139 else 139 else
140 pm = Opie::Core::OResource::loadPixmap( "folder", Opie::Core::OResource::SmallIcon ); 140 pm = Opie::Core::OResource::loadPixmap( "folder", Opie::Core::OResource::SmallIcon );
141 } 141 }
142 else if ( fs == "vfat" && fileInfo.filePath().contains("/bin") ) { 142 else if ( fs == "vfat" && fileInfo.filePath().contains("/bin") ) {
143 pm = Opie::Core::OResource::loadPixmap( "exec", Opie::Core::OResource::SmallIcon ); 143 pm = Opie::Core::OResource::loadPixmap( "exec", Opie::Core::OResource::SmallIcon );
144 } 144 }
145 else if( (fileInfo.permission( QFileInfo::ExeUser) 145 else if( (fileInfo.permission( QFileInfo::ExeUser)
146 | fileInfo.permission( QFileInfo::ExeGroup) 146 | fileInfo.permission( QFileInfo::ExeGroup)
147 | fileInfo.permission( QFileInfo::ExeOther)) && fs != "vfat" ) { 147 | fileInfo.permission( QFileInfo::ExeOther)) && fs != "vfat" ) {
148 pm = Opie::Core::OResource::loadPixmap( "exec", Opie::Core::OResource::SmallIcon ); 148 pm = Opie::Core::OResource::loadPixmap( "exec", Opie::Core::OResource::SmallIcon );
149 } 149 }
150 else if( !fi->isReadable() ) { 150 else if( !fi->isReadable() ) {
151 pm = Opie::Core::OResource::loadPixmap( "locked", Opie::Core::OResource::SmallIcon ); 151 pm = Opie::Core::OResource::loadPixmap( "locked", Opie::Core::OResource::SmallIcon );
152 } 152 }
153 else { //everything else goes by mimetype 153 else { //everything else goes by mimetype
154 MimeType mt(fi->filePath()); 154 MimeType mt(fi->filePath());
155 pm=mt.pixmap(); //sets the correct pixmap for mimetype 155 pm=mt.pixmap(); //sets the correct pixmap for mimetype
156 if(pm.isNull()) { 156 if(pm.isNull()) {
157 pm = unknownXpm; 157 pm = unknownXpm;
158 } 158 }
159 } 159 }
160 if( fi->isSymLink() || fileL.find("->",0,TRUE) != -1) { 160 if( fi->isSymLink() || fileL.find("->",0,TRUE) != -1) {
161 // odebug << " overlay link image" << oendl; 161 // odebug << " overlay link image" << oendl;
162 pm = Opie::Core::OResource::loadPixmap( "advancedfm/symlink", Opie::Core::OResource::SmallIcon ); 162 pm = Opie::Core::OResource::loadPixmap( "advancedfm/symlink", Opie::Core::OResource::SmallIcon );
163 } 163 }
164 item->setPixmap( 0, pm ); 164 item->setPixmap( 0, pm );
165 165
166 } 166 }
167 isDir=FALSE; 167 isDir=FALSE;
168 ++it; 168 ++it;
169 } 169 }
170 170
171 if( path.find("dev",0,TRUE) != -1) { 171 if( path.find("dev",0,TRUE) != -1) {
172 struct stat buf; 172 struct stat buf;
173 dev_t devT; 173 dev_t devT;
174 DIR *dir; 174 DIR *dir;
175 struct dirent *mydirent; 175 struct dirent *mydirent;
176 176
177 if((dir = opendir( path.latin1())) != NULL) 177 if((dir = opendir( path.latin1())) != NULL)
178 while ((mydirent = readdir(dir)) != NULL) { 178 while ((mydirent = readdir(dir)) != NULL) {
179 lstat( mydirent->d_name, &buf); 179 lstat( mydirent->d_name, &buf);
180// odebug << mydirent->d_name << oendl; 180// odebug << mydirent->d_name << oendl;
181 fileL.sprintf("%s", mydirent->d_name); 181 fileL.sprintf("%s", mydirent->d_name);
182 devT = buf.st_dev; 182 devT = buf.st_dev;
183 fileS.sprintf("%d, %d", (int) ( devT >>8) &0xFF, (int)devT &0xFF); 183 fileS.sprintf("%d, %d", (int) ( devT >>8) &0xFF, (int)devT &0xFF);
184 fileDate.sprintf("%s", ctime( &buf.st_mtime)); 184 fileDate.sprintf("%s", ctime( &buf.st_mtime));
185 if( fileL.find(".") == -1 ) { 185 if( fileL.find(".") == -1 ) {
186 item= new QListViewItem( thisView, fileL, fileS, fileDate); 186 item= new QListViewItem( thisView, fileL, fileS, fileDate);
187 pm = unknownXpm; 187 pm = unknownXpm;
188 item->setPixmap( 0,pm); 188 item->setPixmap( 0,pm);
189 } 189 }
190 } 190 }
191 191
192 closedir(dir); 192 closedir(dir);
193 } 193 }
194 194
195 thisView->setSorting( 3,FALSE); 195 thisView->setSorting( 3,FALSE);
196 fillCombo( (const QString &) path ); 196 fillCombo( (const QString &) path );
197} 197}
198 198
199void AdvancedFm::rePopulate() { 199void AdvancedFm::rePopulate() {
200 // qDebug("repopulate views"); 200 // qDebug("repopulate views");
201 populateView(); 201 populateView();
202 setOtherTabCurrent(); 202 setOtherTabCurrent();
203 populateView(); 203 populateView();
204} 204}
205 205
206void AdvancedFm::ListClicked(QListViewItem *selectedItem) { 206void AdvancedFm::ListClicked(QListViewItem *selectedItem) {
207 if(selectedItem) { 207 if(selectedItem) {
208 QString strItem=selectedItem->text(0); 208 QString strItem=selectedItem->text(0);
209// owarn << strItem << oendl; 209// owarn << strItem << oendl;
210 QString strSize=selectedItem->text(1); 210 QString strSize=selectedItem->text(1);
211 strSize=strSize.stripWhiteSpace(); 211 strSize=strSize.stripWhiteSpace();
212 bool isDirectory = false; 212 bool isDirectory = false;
213 QString strItem2; 213 QString strItem2;
214 214
215 if(strItem.find("@",0,TRUE) !=-1 || strItem.find("->",0,TRUE) !=-1 ) {//if symlink 215 if(strItem.find("@",0,TRUE) !=-1 || strItem.find("->",0,TRUE) !=-1 ) {//if symlink
216 strItem2 = dealWithSymName((const QString&)strItem); 216 strItem2 = dealWithSymName((const QString&)strItem);
217 if(QDir(strItem2).exists() ) 217 if(QDir(strItem2).exists() )
218 strItem = strItem2; 218 strItem = strItem2;
219 } 219 }
220 220
221 if( strItem.find(". .",0,TRUE) && strItem.find("/",0,TRUE)!=-1 ) { 221 if( strItem.find(". .",0,TRUE) && strItem.find("/",0,TRUE)!=-1 ) {
222 222
223 if(QDir(strItem).exists()) 223 if(QDir(strItem).exists())
224 isDirectory = true; 224 isDirectory = true;
225 } 225 }
226 226
227 if( isDirectory ) { 227 if( isDirectory ) {
228 CurrentDir()->cd( strItem, TRUE); 228 CurrentDir()->cd( strItem, TRUE);
229 populateView(); 229 populateView();
230 CurrentView()->ensureItemVisible( CurrentView()->firstChild()); 230 CurrentView()->ensureItemVisible( CurrentView()->firstChild());
231 } 231 }
232 chdir( strItem.latin1()); 232 chdir( strItem.latin1());
233 } 233 }
234} 234}
235 235
236void AdvancedFm::ListPressed( int mouse, QListViewItem *item, const QPoint& , int ) { 236void AdvancedFm::ListPressed( int mouse, QListViewItem *item, const QPoint& , int ) {
237 Q_UNUSED(item); 237 Q_UNUSED(item);
238 switch (mouse) { 238 switch (mouse) {
239 case 1: 239 case 1:
240 { 240 {
241 if(renameBox != 0 ) { 241 if(renameBox != 0 ) {
242 cancelRename(); 242 cancelRename();
243 } 243 }
244 } 244 }
245 break; 245 break;
246// case 2: 246// case 2:
247// menuTimer.start( 50, TRUE ); 247// menuTimer.start( 50, TRUE );
248// break; 248// break;
249 }; 249 };
250} 250}
251 251
252 252
253void AdvancedFm::refreshCurrentTab() { 253void AdvancedFm::refreshCurrentTab() {
254 populateView(); 254 populateView();
255 // if ( TabWidget->currentWidget() == tab) { 255 // if ( TabWidget->currentWidget() == tab) {
256} 256}
257 257
258void AdvancedFm::switchToLocalTab() { 258void AdvancedFm::switchToLocalTab() {
259 TabWidget->setCurrentWidget(tab); 259 TabWidget->setCurrentWidget(tab);
260 Local_View->setFocus(); 260 Local_View->setFocus();
261 // whichTab = 1; 261 // whichTab = 1;
262} 262}
263 263
264void AdvancedFm::switchToRemoteTab() { 264void AdvancedFm::switchToRemoteTab() {
265 TabWidget->setCurrentWidget(tab_2); 265 TabWidget->setCurrentWidget(tab_2);
266 Remote_View->setFocus(); 266 Remote_View->setFocus();
267 // whichTab = 2; 267 // whichTab = 2;
268} 268}
269 269
270void AdvancedFm::currentPathComboChanged() { 270void AdvancedFm::currentPathComboChanged() {
271 QString pDir = currentPathCombo->lineEdit()->text(); 271 QString pDir = currentPathCombo->lineEdit()->text();
272 if(QDir(pDir).exists()) { 272 if(QDir(pDir).exists()) {
273 CurrentDir()->setPath(pDir ); 273 CurrentDir()->setPath(pDir );
274 populateView(); 274 populateView();
275 } else { 275 } else {
276 QMessageBox::message(tr("Note"),tr("<p>%1 does not exist</p>").arg(pDir)); 276 QMessageBox::message(tr("Note"),tr("<p>%1 does not exist</p>").arg(pDir));
277 } 277 }
278} 278}
279 279
280void AdvancedFm::fillCombo(const QString &currentPath) { 280void AdvancedFm::fillCombo(const QString &currentPath) {
281 281
282 if ( TabWidget->currentWidget() == tab) { 282 if ( TabWidget->currentWidget() == tab) {
283// if ( whichTab == 1) { 283// if ( whichTab == 1) {
284 currentPathCombo->lineEdit()->setText( currentPath); 284 currentPathCombo->lineEdit()->setText( currentPath);
285 if( localDirPathStringList.grep( currentPath,TRUE).isEmpty() ) { 285 if( localDirPathStringList.grep( currentPath,TRUE).isEmpty() ) {
286 currentPathCombo->clear(); 286 currentPathCombo->clear();
287 localDirPathStringList.prepend( currentPath ); 287 localDirPathStringList.prepend( currentPath );
288 currentPathCombo->insertStringList( localDirPathStringList,-1); 288 currentPathCombo->insertStringList( localDirPathStringList,-1);
289 } 289 }
290 } else { 290 } else {
291 currentPathCombo->lineEdit()->setText( currentPath); 291 currentPathCombo->lineEdit()->setText( currentPath);
292 if( remoteDirPathStringList.grep( currentPath,TRUE).isEmpty() ) { 292 if( remoteDirPathStringList.grep( currentPath,TRUE).isEmpty() ) {
293 currentPathCombo->clear(); 293 currentPathCombo->clear();
294 remoteDirPathStringList.prepend( currentPath ); 294 remoteDirPathStringList.prepend( currentPath );
295 currentPathCombo->insertStringList( remoteDirPathStringList,-1); 295 currentPathCombo->insertStringList( remoteDirPathStringList,-1);
296 } 296 }
297 } 297 }
298} 298}
299 299
300QStringList AdvancedFm::getPath() { 300QStringList AdvancedFm::getPath() {
301 QStringList strList; 301 QStringList strList;
302 QListView *thisView=CurrentView(); 302 QListView *thisView=CurrentView();
303 QList<QListViewItem> * getSelectedItems( QListView * thisView ); 303 QList<QListViewItem> * getSelectedItems( QListView * thisView );
304 QListViewItemIterator it( thisView ); 304 QListViewItemIterator it( thisView );
305 for ( ; it.current(); ++it ) { 305 for ( ; it.current(); ++it ) {
306 if ( it.current()->isSelected() ) { 306 if ( it.current()->isSelected() ) {
307 strList << it.current()->text(0); 307 strList << it.current()->text(0);
308// odebug << it.current()->text(0) << oendl; 308// odebug << it.current()->text(0) << oendl;
309 } 309 }
310 } 310 }
311 return strList; 311 return strList;
312} 312}
313 313
314void AdvancedFm::changeTo(const QString &dir) { 314void AdvancedFm::changeTo(const QString &dir) {
315 chdir( dir.latin1()); 315 chdir( dir.latin1());
316 CurrentDir()->cd(dir, TRUE); 316 CurrentDir()->cd(dir, TRUE);
317 populateView(); 317 populateView();
318 update(); 318 update();
319} 319}
320 320
321void AdvancedFm::homeButtonPushed() { 321void AdvancedFm::homeButtonPushed() {
322 changeTo(QDir::homeDirPath()); 322 changeTo(QDir::homeDirPath());
323} 323}
324 324
325void AdvancedFm::docButtonPushed() { 325void AdvancedFm::docButtonPushed() {
326 changeTo(QPEApplication::documentDir()); 326 changeTo(QPEApplication::documentDir());
327} 327}
328 328
329void AdvancedFm::SDButtonPushed() { 329void AdvancedFm::SDButtonPushed() {
330 Opie::Core::OStorageInfo info; 330 Opie::Core::OStorageInfo info;
331 if(StorageInfo::hasSd() ) { 331 if(StorageInfo::hasSd() ) {
332 changeTo(info.sdPath()); 332 changeTo(info.sdPath());
333 } 333 }
334 else if(StorageInfo::hasMmc()) { 334 else if(StorageInfo::hasMmc()) {
335 changeTo(info.mmcPath()); 335 changeTo(info.mmcPath());
336 } 336 }
337} 337}
338 338
339void AdvancedFm::CFButtonPushed() { 339void AdvancedFm::CFButtonPushed() {
340 Opie::Core::OStorageInfo info; 340 Opie::Core::OStorageInfo info;
341 changeTo(info.cfPath()); 341 changeTo(info.cfPath());
342} 342}
343 343
344void AdvancedFm::QPEButtonPushed() { 344void AdvancedFm::QPEButtonPushed() {
345 changeTo(QPEApplication::qpeDir()); 345 changeTo(QPEApplication::qpeDir());
346} 346}
347 347
348void AdvancedFm::doAbout() { 348void AdvancedFm::doAbout() {
349 QMessageBox::message("AdvancedFm",tr("<P>Advanced FileManager is copyright 2002-2003 by L.J.Potter<llornkcor@handhelds.org> and is licensed by the GPL</P>")); 349 QMessageBox::message("AdvancedFm",tr("<P>Advanced FileManager is copyright 2002-2003 by L.J.Potter<llornkcor@handhelds.org> and is licensed by the GPL</P>"));
350} 350}
351 351
352void AdvancedFm::keyPressEvent( QKeyEvent *e) { 352void AdvancedFm::keyPressEvent( QKeyEvent *e) {
353 Q_UNUSED(e); 353 Q_UNUSED(e);
354} 354}
355 355
356void AdvancedFm::keyReleaseEvent( QKeyEvent *e) { 356void AdvancedFm::keyReleaseEvent( QKeyEvent *e) {
357// if( CurrentView()->hasFocus() ) 357// if( CurrentView()->hasFocus() )
358// e->ignore(); 358// e->ignore();
359 359
360 if( currentPathCombo->lineEdit()->hasFocus()) { 360 if( currentPathCombo->lineEdit()->hasFocus()) {
361 // qDebug("shout!"); 361 // qDebug("shout!");
362 } 362 }
363 363
364 else if( e->key() == Key_Left ) 364 else if( e->key() == Key_Left )
365 upDir(); 365 upDir();
366 else if( e->key() == Key_Return || e->key() == Key_Enter) 366 else if( e->key() == Key_Return || e->key() == Key_Enter)
367 navigateToSelected(); 367 navigateToSelected();
368 else if( e->key() == Key_Tab) 368 else if( e->key() == Key_Tab)
369 setOtherTabCurrent(); 369 setOtherTabCurrent();
370 else if( e->key() == Key_Delete ) 370 else if( e->key() == Key_Delete )
371 del(); 371 del();
372 else 372 else
373 e->accept(); 373 e->accept();
374 374
375} 375}
376 376
377 377
378void AdvancedFm::parsetab(const QString &fileName) { 378void AdvancedFm::parsetab(const QString &fileName) {
379 379
380 fileSystemTypeList.clear(); 380 fileSystemTypeList.clear();
381 fsList.clear(); 381 fsList.clear();
382 struct mntent *me; 382 struct mntent *me;
383 FILE *mntfp = setmntent( fileName.latin1(), "r" ); 383 FILE *mntfp = setmntent( fileName.latin1(), "r" );
384 if ( mntfp ) { 384 if ( mntfp ) {
385 while ( (me = getmntent( mntfp )) != 0 ) { 385 while ( (me = getmntent( mntfp )) != 0 ) {
386 QString deviceName = me->mnt_fsname; 386 QString deviceName = me->mnt_fsname;
387 QString filesystemType = me->mnt_type; 387 QString filesystemType = me->mnt_type;
388 QString mountDir = me->mnt_dir; 388 QString mountDir = me->mnt_dir;
389 if(deviceName != "none") { 389 if(deviceName != "none") {
390 if( fsList.contains(filesystemType) == 0 390 if( fsList.contains(filesystemType) == 0
391 & filesystemType.find("proc",0,TRUE) == -1 391 & filesystemType.find("proc",0,TRUE) == -1
392 & filesystemType.find("cramfs",0,TRUE) == -1 392 & filesystemType.find("cramfs",0,TRUE) == -1
393 & filesystemType.find("auto",0,TRUE) == -1) 393 & filesystemType.find("auto",0,TRUE) == -1)
394 fsList << filesystemType; 394 fsList << filesystemType;
395 fileSystemTypeList << mountDir+"::"+filesystemType; 395 fileSystemTypeList << mountDir+"::"+filesystemType;
396 } 396 }
397 } 397 }
398 } 398 }
399 endmntent( mntfp ); 399 endmntent( mntfp );
400} 400}
401 401
402QString AdvancedFm::getFileSystemType(const QString &currentText) { 402QString AdvancedFm::getFileSystemType(const QString &currentText) {
403 parsetab("/etc/mtab"); //why did TT forget filesystem type? 403 parsetab("/etc/mtab"); //why did TT forget filesystem type?
404 QString current = currentText;//.right( currentText.length()-1); 404 QString current = currentText;//.right( currentText.length()-1);
405 QString baseFs; 405 QString baseFs;
406 for ( QStringList::Iterator it = fileSystemTypeList.begin(); it != fileSystemTypeList.end(); ++it ) { 406 for ( QStringList::Iterator it = fileSystemTypeList.begin(); it != fileSystemTypeList.end(); ++it ) {
407 QString temp = (*it); 407 QString temp = (*it);
408 QString path = temp.left(temp.find("::",0,TRUE) ); 408 QString path = temp.left(temp.find("::",0,TRUE) );
409 path = path.right( path.length()-1); 409 path = path.right( path.length()-1);
410 if(path.isEmpty()) baseFs = temp.right( temp.length() - temp.find("::",0,TRUE) - 2); 410 if(path.isEmpty()) baseFs = temp.right( temp.length() - temp.find("::",0,TRUE) - 2);
411 if( current.find( path,0,TRUE) != -1 && !path.isEmpty()) { 411 if( current.find( path,0,TRUE) != -1 && !path.isEmpty()) {
412 return temp.right( temp.length() - temp.find("::",0,TRUE) - 2); 412 return temp.right( temp.length() - temp.find("::",0,TRUE) - 2);
413 } 413 }
414 } 414 }
415 return baseFs; 415 return baseFs;
416} 416}
417 417
418QString AdvancedFm::getDiskSpace( const QString &path) { 418QString AdvancedFm::getDiskSpace( const QString &path) {
419 struct statfs fss; 419 struct statfs fss;
420 if ( !statfs( path.latin1(), &fss ) ) { 420 if ( !statfs( path.latin1(), &fss ) ) {
421 int blkSize = fss.f_bsize; 421 int blkSize = fss.f_bsize;
422 // int totalBlks = fs.f_blocks; 422 // int totalBlks = fs.f_blocks;
423 int availBlks = fss.f_bavail; 423 int availBlks = fss.f_bavail;
424 424
425 long mult = blkSize / 1024; 425 long mult = blkSize / 1024;
426 long div = 1024 / blkSize; 426 long div = 1024 / blkSize;
427 if ( !mult ) mult = 1; 427 if ( !mult ) mult = 1;
428 if ( !div ) div = 1; 428 if ( !div ) div = 1;
429 429
430 return QString::number(availBlks * mult / div); 430 return QString::number(availBlks * mult / div);
431 } 431 }
432 return ""; 432 return "";
433} 433}
434 434
435 435
436void AdvancedFm::showFileMenu() { 436void AdvancedFm::showFileMenu() {
437 QString curApp; 437 QString curApp;
438 curApp = CurrentView()->currentItem()->text(0); 438 curApp = CurrentView()->currentItem()->text(0);
439 439
440 MimeType mt(curApp); 440 MimeType mt(curApp);
441 const AppLnk* app = mt.application(); 441 const AppLnk* app = mt.application();
442 QFile fi(curApp); 442 QFile fi(curApp);
443 QPopupMenu *m = new QPopupMenu(0); 443 QPopupMenu *m = new QPopupMenu(0);
444 QPopupMenu *n = new QPopupMenu(0); 444 QPopupMenu *n = new QPopupMenu(0);
445 // QPopupMenu *o = new QPopupMenu(0); 445 // QPopupMenu *o = new QPopupMenu(0);
446 m->insertItem(tr("Show Hidden Files"),this,SLOT(showHidden())); 446 m->insertItem(tr("Show Hidden Files"),this,SLOT(showHidden()));
447 447
448 if ( QFileInfo(fi).isDir()) { 448 if ( QFileInfo(fi).isDir()) {
449 m->insertSeparator(); 449 m->insertSeparator();
450 m->insertItem(tr("Change Directory"),this,SLOT(doDirChange())); 450 m->insertItem(tr("Change Directory"),this,SLOT(doDirChange()));
451 } else { 451 } else {
452 452
453 if (app) 453 if (app)
454 m->insertItem(app->pixmap(),tr("Open in " + app->name()),this,SLOT(runThis())); 454 m->insertItem(app->pixmap(),tr("Open in " + app->name()),this,SLOT(runThis()));
455 else if(QFileInfo(fi).isExecutable() ) //damn opie doesnt like this 455 else if(QFileInfo(fi).isExecutable() ) //damn opie doesnt like this
456 m->insertItem(tr("Execute"),this,SLOT(runThis())); 456 m->insertItem(tr("Execute"),this,SLOT(runThis()));
457 m->insertItem( Opie::Core::OResource::loadPixmap( "txt", Opie::Core::OResource::SmallIcon ), 457 m->insertItem( Opie::Core::OResource::loadPixmap( "txt", Opie::Core::OResource::SmallIcon ),
458 tr("Open as text"),this,SLOT(runText())); 458 tr("Open as text"),this,SLOT(runText()));
459 } 459 }
460 460
461 m->insertItem(tr("Actions"),n); 461 m->insertItem(tr("Actions"),n);
462 n->insertItem(tr("Make Directory"),this,SLOT(makeDir())); 462 n->insertItem(tr("Make Directory"),this,SLOT(makeDir()));
463 463
464 n->insertItem(tr("Make Symlink"),this,SLOT(mkSym())); 464 n->insertItem(tr("Make Symlink"),this,SLOT(mkSym()));
465 465
466 n->insertSeparator(); 466 n->insertSeparator();
467 n->insertItem(tr("Rename"),this,SLOT(renameIt())); 467 n->insertItem(tr("Rename"),this,SLOT(renameIt()));
468 468
469 n->insertItem(tr("Copy"),this,SLOT(copyTimer())); 469 n->insertItem(tr("Copy"),this,SLOT(copyTimer()));
470 n->insertItem(tr("Copy As"),this,SLOT(copyAsTimer())); 470 n->insertItem(tr("Copy As"),this,SLOT(copyAsTimer()));
471 n->insertItem(tr("Copy Same Dir"),this,SLOT(copySameDirTimer())); 471 n->insertItem(tr("Copy Same Dir"),this,SLOT(copySameDirTimer()));
472 n->insertItem(tr("Move"),this,SLOT(moveTimer())); 472 n->insertItem(tr("Move"),this,SLOT(moveTimer()));
473 473
474 n->insertSeparator(); 474 n->insertSeparator();
475 n->insertItem(tr("Delete"),this,SLOT(doDelete())); 475 n->insertItem(tr("Delete"),this,SLOT(doDelete()));
476 m->insertItem(tr("Add To Documents"),this,SLOT(addToDocs())); 476 m->insertItem(tr("Add To Documents"),this,SLOT(addToDocs()));
477 477
478 m->insertItem(tr("Run Command"),this,SLOT(runCommand())); 478 m->insertItem(tr("Run Command"),this,SLOT(runCommand()));
479 m->insertItem(tr("File Info"),this,SLOT(fileStatus())); 479 m->insertItem(tr("File Info"),this,SLOT(fileStatus()));
480 480
481 m->insertSeparator(); 481 m->insertSeparator();
482 m->insertItem(tr("Set Permissions"),this,SLOT(filePerms())); 482 m->insertItem(tr("Set Permissions"),this,SLOT(filePerms()));
483 483
484#if defined(QT_QWS_OPIE) 484#if defined(QT_QWS_OPIE)
485 m->insertItem(tr("Properties"),this,SLOT(doProperties())); 485 m->insertItem(tr("Properties"),this,SLOT(doProperties()));
486#endif 486#endif
487 m->setCheckable(TRUE); 487 m->setCheckable(TRUE);
488 if (!b) 488 if (!b)
489 m->setItemChecked(m->idAt(0),TRUE); 489 m->setItemChecked(m->idAt(0),TRUE);
490 else 490 else
491 m->setItemChecked(m->idAt(0),FALSE); 491 m->setItemChecked(m->idAt(0),FALSE);
492 492
493 if(Ir::supported()) 493 if(Ir::supported())
494 m->insertItem(tr("Beam File"),this,SLOT(doBeam())); 494 m->insertItem(tr("Beam File"),this,SLOT(doBeam()));
495 m->setFocus(); 495 m->setFocus();
496 496
497 m->exec(QPoint(QCursor::pos().x(),QCursor::pos().y())); 497 m->exec(QPoint(QCursor::pos().x(),QCursor::pos().y()));
498 498
499 if(m) delete m; 499 delete m;
500} 500}
501 501
502 502
503QString AdvancedFm::checkDiskSpace(const QString &path) { 503QString AdvancedFm::checkDiskSpace(const QString &path) {
504 struct statfs fss; 504 struct statfs fss;
505 if ( !statfs( path.latin1(), &fss ) ) { 505 if ( !statfs( path.latin1(), &fss ) ) {
506 int blkSize = fss.f_bsize; 506 int blkSize = fss.f_bsize;
507// int totalBlks = fs.f_blocks; 507// int totalBlks = fs.f_blocks;
508 int availBlks = fss.f_bavail; 508 int availBlks = fss.f_bavail;
509 509
510 long mult = blkSize / 1024; 510 long mult = blkSize / 1024;
511 long div = 1024 / blkSize; 511 long div = 1024 / blkSize;
512 if ( !mult ) mult = 1; 512 if ( !mult ) mult = 1;
513 if ( !div ) div = 1; 513 if ( !div ) div = 1;
514 514
515 515
516 return QString::number(availBlks * mult / div); 516 return QString::number(availBlks * mult / div);
517 } 517 }
518 return ""; 518 return "";
519} 519}
520 520
521void AdvancedFm::addToDocs() { 521void AdvancedFm::addToDocs() {
522 QStringList strListPaths = getPath(); 522 QStringList strListPaths = getPath();
523 QDir *thisDir = CurrentDir(); 523 QDir *thisDir = CurrentDir();
524 524
525 if( strListPaths.count() > 0) { 525 if( strListPaths.count() > 0) {
526 QString curFile; 526 QString curFile;
527 for ( QStringList::Iterator it = strListPaths.begin(); it != strListPaths.end(); ++it ) { 527 for ( QStringList::Iterator it = strListPaths.begin(); it != strListPaths.end(); ++it ) {
528 curFile = thisDir->canonicalPath()+"/"+(*it); 528 curFile = thisDir->canonicalPath()+"/"+(*it);
529// odebug << curFile << oendl; 529// odebug << curFile << oendl;
530 QFileInfo fi(curFile); 530 QFileInfo fi(curFile);
531 DocLnk f; 531 DocLnk f;
532// curFile.replace(QRegExp("\\..*"),""); 532// curFile.replace(QRegExp("\\..*"),"");
533 f.setName(fi.baseName() ); 533 f.setName(fi.baseName() );
534 f.setFile( curFile); 534 f.setFile( curFile);
535 f.writeLink(); 535 f.writeLink();
536 } 536 }
537 } 537 }
538} 538}
539 539
540 540
541void AdvancedFm::customDirsToMenu() { 541void AdvancedFm::customDirsToMenu() {
542 542
543 Config cfg("AdvancedFm"); 543 Config cfg("AdvancedFm");
544 cfg.setGroup("Menu"); 544 cfg.setGroup("Menu");
545 545
546 QStringList list = cfg.readListEntry( "CustomDir", ','); 546 QStringList list = cfg.readListEntry( "CustomDir", ',');
547 menuButton->insertItems(list ); 547 menuButton->insertItems(list );
548 548
549// for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) 549// for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it )
550// { 550// {
551// customDirMenu->insertItem(*it ); 551// customDirMenu->insertItem(*it );
552// } 552// }
553} 553}
554 554
555void AdvancedFm::dirMenuSelected(int item) { 555void AdvancedFm::dirMenuSelected(int item) {
556 switch(item) 556 switch(item)
557 { 557 {
558 558
559 case -21: 559 case -21:
560 case 0: 560 case 0:
561 addCustomDir(); 561 addCustomDir();
562 break; 562 break;
563 case -22: 563 case -22:
564 case 1: 564 case 1:
565 removeCustomDir(); 565 removeCustomDir();
566 break; 566 break;
567 default: 567 default:
568 { 568 {
569// gotoCustomDir( menuButton->text(item)); 569// gotoCustomDir( menuButton->text(item));
570// gotoCustomDir( customDirMenu->text(item)); 570// gotoCustomDir( customDirMenu->text(item));
571 } 571 }
572 break; 572 break;
573 573
574 }; 574 };
575} 575}
576 576
577void AdvancedFm::addCustomDir() { 577void AdvancedFm::addCustomDir() {
578 Config cfg("AdvancedFm"); 578 Config cfg("AdvancedFm");
579 cfg.setGroup("Menu"); 579 cfg.setGroup("Menu");
580 QString dir; 580 QString dir;
581 QStringList list = cfg.readListEntry( (const QString &)"CustomDir", (const QChar)','); 581 QStringList list = cfg.readListEntry( (const QString &)"CustomDir", (const QChar)',');
582 582
583 dir = CurrentDir()->canonicalPath(); 583 dir = CurrentDir()->canonicalPath();
584 584
585 bool addIt=true; 585 bool addIt=true;
586 for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { 586 for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) {
587 if( dir == (*it)) { 587 if( dir == (*it)) {
588 addIt=false; 588 addIt=false;
589 } 589 }
590 } 590 }
591 if(addIt) { 591 if(addIt) {
592 menuButton->insertItem(dir); 592 menuButton->insertItem(dir);
593// customDirMenu->insertItem(dir); 593// customDirMenu->insertItem(dir);
594 list << dir; 594 list << dir;
595 } 595 }
596 596
597 cfg.writeEntry("CustomDir", list, ','); 597 cfg.writeEntry("CustomDir", list, ',');
598 cfg.write(); 598 cfg.write();
599} 599}
600 600
601void AdvancedFm::removeCustomDir() { 601void AdvancedFm::removeCustomDir() {
602// odebug << "remove custom dir" << oendl; 602// odebug << "remove custom dir" << oendl;
603 Config cfg("AdvancedFm"); 603 Config cfg("AdvancedFm");
604 cfg.setGroup("Menu"); 604 cfg.setGroup("Menu");
605 QString dir; 605 QString dir;
606 QStringList list = cfg.readListEntry( (const QString &)"CustomDir", (const QChar)','); 606 QStringList list = cfg.readListEntry( (const QString &)"CustomDir", (const QChar)',');
607 QStringList list2; 607 QStringList list2;
608 dir = CurrentDir()->canonicalPath(); 608 dir = CurrentDir()->canonicalPath();
609 int ramble=2; 609 int ramble=2;
610// int ramble=-24; 610// int ramble=-24;
611//first remove list 611//first remove list
612 if(list.grep(dir,true).isEmpty()) { 612 if(list.grep(dir,true).isEmpty()) {
613 QMessageBox::message(tr( "AdvancedFm" ), 613 QMessageBox::message(tr( "AdvancedFm" ),
614 tr("<p>Cannot remove current directory from bookmarks. It is not bookmarked!</p>")); 614 tr("<p>Cannot remove current directory from bookmarks. It is not bookmarked!</p>"));
615 } else { 615 } else {
616 for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { 616 for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) {
617 if((*it) != dir) { 617 if((*it) != dir) {
618//current item is not our current dir, so add it to temp list 618//current item is not our current dir, so add it to temp list
619 list2 <<(*it); 619 list2 <<(*it);
620 } else { 620 } else {
621// customDirMenu->removeItem( ramble); 621// customDirMenu->removeItem( ramble);
622 menuButton->remove( ramble); 622 menuButton->remove( ramble);
623 623
624 } 624 }
625 ramble++; 625 ramble++;
626// ramble--; 626// ramble--;
627 } 627 }
628 628
629 cfg.writeEntry("CustomDir", list2, ','); 629 cfg.writeEntry("CustomDir", list2, ',');
630 cfg.write(); 630 cfg.write();
631 } 631 }
632// customDirsToMenu(); 632// customDirsToMenu();
633 633
634} 634}
635 635
636void AdvancedFm::gotoCustomDir(const QString &dir) { 636void AdvancedFm::gotoCustomDir(const QString &dir) {
637// odebug << "gotoCustomDir(const QString &dir) " +dir << oendl; 637// odebug << "gotoCustomDir(const QString &dir) " +dir << oendl;
638// QString curDir = dir; 638// QString curDir = dir;
639// QDir *thisDir = CurrentDir(); 639// QDir *thisDir = CurrentDir();
640// if( curDir.isEmpty()) { 640// if( curDir.isEmpty()) {
641// } 641// }
642 if( dir == s_addBookmark) { 642 if( dir == s_addBookmark) {
643 addCustomDir(); 643 addCustomDir();
644 } 644 }
645 if( dir == s_removeBookmark) { 645 if( dir == s_removeBookmark) {
646 removeCustomDir( ); 646 removeCustomDir( );
647 } else { 647 } else {
648 changeTo( dir); 648 changeTo( dir);
649// if(QDir( curDir).exists() ) 649// if(QDir( curDir).exists() )
650// { 650// {
651// thisDir->setPath( curDir ); 651// thisDir->setPath( curDir );
652// chdir( curDir.latin1() ); 652// chdir( curDir.latin1() );
653// thisDir->cd( curDir, TRUE); 653// thisDir->cd( curDir, TRUE);
654// populateView(); 654// populateView();
655// } 655// }
656 } 656 }
657} 657}
658 658
659QDir *AdvancedFm::CurrentDir() { 659QDir *AdvancedFm::CurrentDir() {
660 if ( whichTab == 1) { 660 if ( whichTab == 1) {
661 // qDebug("CurrentTab is Local"); 661 // qDebug("CurrentTab is Local");
662 return &currentDir; 662 return &currentDir;
663 } else { 663 } else {
664 // qDebug("CurrentTab is Remote"); 664 // qDebug("CurrentTab is Remote");
665 return &currentRemoteDir; 665 return &currentRemoteDir;
666 } 666 }
667} 667}
668 668
669QDir *AdvancedFm::OtherDir() { 669QDir *AdvancedFm::OtherDir() {
670 // if ( TabWidget->currentWidget() == tab) { 670 // if ( TabWidget->currentWidget() == tab) {
671 if ( whichTab == 1) { 671 if ( whichTab == 1) {
672 return &currentRemoteDir; 672 return &currentRemoteDir;
673 } else { 673 } else {
674 return &currentDir; 674 return &currentDir;
675 } 675 }
676} 676}
677 677
678QListView * AdvancedFm::CurrentView() { 678QListView * AdvancedFm::CurrentView() {
679 // if ( TabWidget->currentWidget() == tab) { 679 // if ( TabWidget->currentWidget() == tab) {
680 if ( whichTab == 1) { 680 if ( whichTab == 1) {
681 // qDebug("CurrentView: local"); 681 // qDebug("CurrentView: local");
682 return Local_View; 682 return Local_View;
683 } else { 683 } else {
684// owarn << "CurrentView Tab 2" << oendl; 684// owarn << "CurrentView Tab 2" << oendl;
685 // qDebug("CurrentView: remote"); 685 // qDebug("CurrentView: remote");
686 return Remote_View; 686 return Remote_View;
687 } 687 }
688} 688}
689 689
690QListView * AdvancedFm::OtherView() { 690QListView * AdvancedFm::OtherView() {
691 if ( whichTab == 1) 691 if ( whichTab == 1)
692 return Remote_View; 692 return Remote_View;
693 else 693 else
694 return Local_View; 694 return Local_View;
695} 695}
696 696
697void AdvancedFm::setOtherTabCurrent() { 697void AdvancedFm::setOtherTabCurrent() {
698 // qDebug("setOtherTabCurrent() %d",whichTab); 698 // qDebug("setOtherTabCurrent() %d",whichTab);
699 if ( whichTab == 1) { 699 if ( whichTab == 1) {
700 TabWidget->setCurrentWidget(1); 700 TabWidget->setCurrentWidget(1);
701 } else { 701 } else {
702 TabWidget->setCurrentWidget(0); 702 TabWidget->setCurrentWidget(0);
703 } 703 }
704// OtherView()->setFocus(); 704// OtherView()->setFocus();
705 OtherView()->setSelected( CurrentView()->firstChild(), true); 705 OtherView()->setSelected( CurrentView()->firstChild(), true);
706} 706}
707 707
708void AdvancedFm::qcopReceive(const QCString &msg, const QByteArray &data) { 708void AdvancedFm::qcopReceive(const QCString &msg, const QByteArray &data) {
709// odebug << "qcop message "+msg << oendl; 709// odebug << "qcop message "+msg << oendl;
710 QDataStream stream ( data, IO_ReadOnly ); 710 QDataStream stream ( data, IO_ReadOnly );
711 if ( msg == "openDirectory(QString)" ) { 711 if ( msg == "openDirectory(QString)" ) {
712// odebug << "received" << oendl; 712// odebug << "received" << oendl;
713 QString file; 713 QString file;
714 stream >> file; 714 stream >> file;
715 changeTo( (const QString &) file); 715 changeTo( (const QString &) file);
716 } 716 }
717} 717}
718 718
719void AdvancedFm::setDocument(const QString &file) { 719void AdvancedFm::setDocument(const QString &file) {
720 changeTo( file); 720 changeTo( file);
721} 721}
722 722
723 723
724void AdvancedFm::slotSwitchMenu(int item) { 724void AdvancedFm::slotSwitchMenu(int item) {
725 if(item == -23) { 725 if(item == -23) {
726 switchToLocalTab(); 726 switchToLocalTab();
727 tabChanged( tab); 727 tabChanged( tab);
728 } 728 }
729 729
730 if(item == -24) { 730 if(item == -24) {
731 switchToRemoteTab(); 731 switchToRemoteTab();
732 tabChanged( tab_2); 732 tabChanged( tab_2);
733 } 733 }
734} 734}
735 735
736void AdvancedFm::navigateToSelected() { 736void AdvancedFm::navigateToSelected() {
737 if( !CurrentView()->currentItem()) return; 737 if( !CurrentView()->currentItem()) return;
738 doDirChange(); 738 doDirChange();
739} 739}