summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--pwmanager/pwmanager/pwminit.cpp2
1 files changed, 0 insertions, 2 deletions
diff --git a/pwmanager/pwmanager/pwminit.cpp b/pwmanager/pwmanager/pwminit.cpp
index b0a78c2..2f1aa4e 100644
--- a/pwmanager/pwmanager/pwminit.cpp
+++ b/pwmanager/pwmanager/pwminit.cpp
@@ -1,569 +1,567 @@
1/*************************************************************************** 1/***************************************************************************
2 * * 2 * *
3 * copyright (C) 2004 by Michael Buesch * 3 * copyright (C) 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de * 4 * email: mbuesch@freenet.de *
5 * * 5 * *
6 * This program is free software; you can redistribute it and/or modify * 6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 * 7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. * 8 * as published by the Free Software Foundation. *
9 * * 9 * *
10 ***************************************************************************/ 10 ***************************************************************************/
11 11
12/*************************************************************************** 12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk 13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.0.1 of pwmanager 14 * This file is originaly based on version 1.0.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde 15 * and was modified to run on embedded devices that run microkde
16 * 16 *
17 * $Id$ 17 * $Id$
18 **************************************************************************/ 18 **************************************************************************/
19 19
20#include "pwminit.h" 20#include "pwminit.h"
21#include "configuration.h" 21#include "configuration.h"
22#include "randomizer.h" 22#include "randomizer.h"
23 23
24#ifndef PWM_EMBEDDED 24#ifndef PWM_EMBEDDED
25#include "selftest.h" 25#include "selftest.h"
26#endif 26#endif
27 27
28#include "pwm.h" 28#include "pwm.h"
29#include "pwmexception.h" 29#include "pwmexception.h"
30#include "pwmtray.h" 30#include "pwmtray.h"
31#include "pwmdoc.h" 31#include "pwmdoc.h"
32 32
33#ifdef CONFIG_KWALLETIF 33#ifdef CONFIG_KWALLETIF
34# include "kwalletemu.h" 34# include "kwalletemu.h"
35#endif // CONFIG_KWALLETIF 35#endif // CONFIG_KWALLETIF
36#ifdef CONFIG_KEYCARD 36#ifdef CONFIG_KEYCARD
37# include "pwmkeycard.h" 37# include "pwmkeycard.h"
38#endif // CONFIG_KEYCARD 38#endif // CONFIG_KEYCARD
39 39
40#include <qmessagebox.h> 40#include <qmessagebox.h>
41 41
42#include <kmessagebox.h> 42#include <kmessagebox.h>
43#ifndef PWM_EMBEDDED 43#ifndef PWM_EMBEDDED
44#include <kcmdlineargs.h> 44#include <kcmdlineargs.h>
45#include <kwin.h> 45#include <kwin.h>
46#include <dcopclient.h> 46#include <dcopclient.h>
47#endif 47#endif
48 48
49#include <kapplication.h> 49#include <kapplication.h>
50#include <kiconloader.h> 50#include <kiconloader.h>
51 51
52#include <signal.h> 52#include <signal.h>
53 53
54static PwMInit *sig_init_pointer; 54static PwMInit *sig_init_pointer;
55static NOREGPARM void sig_handler(int signum) 55static NOREGPARM void sig_handler(int signum)
56{ 56{
57 switch (signum) { 57 switch (signum) {
58 case SIGINT: 58 case SIGINT:
59 case SIGTERM: 59 case SIGTERM:
60 sig_init_pointer->shutdownApp(20 + signum); 60 sig_init_pointer->shutdownApp(20 + signum);
61 break; 61 break;
62 default: 62 default:
63 printDebug(string("unhandled signal ") 63 printDebug(string("unhandled signal ")
64 + tostr(signum)); 64 + tostr(signum));
65 } 65 }
66} 66}
67 67
68 68
69 69
70 70
71PwMInit::PwMInit(PwMApplication *_app) 71PwMInit::PwMInit(PwMApplication *_app)
72 : runStatus (unknown) 72 : runStatus (unknown)
73 , _curWidget (0) 73 , _curWidget (0)
74 , _dcopClient (0) 74 , _dcopClient (0)
75 , _kwalletEmu (0) 75 , _kwalletEmu (0)
76 , _keycard (0) 76 , _keycard (0)
77 , _tray (0) 77 , _tray (0)
78{ 78{
79 sig_init_pointer = this; 79 sig_init_pointer = this;
80 app = _app; 80 app = _app;
81} 81}
82 82
83PwMInit::~PwMInit() 83PwMInit::~PwMInit()
84{ 84{
85#ifndef PWM_EMBEDDED 85#ifndef PWM_EMBEDDED
86 SelfTest::cancel(); 86 SelfTest::cancel();
87 // close all open mainwnds 87 // close all open mainwnds
88 QValueList<PwM *>::iterator i = _mainWndList.begin(), 88 QValueList<PwM *>::iterator i = _mainWndList.begin(),
89 end = _mainWndList.end(); 89 end = _mainWndList.end();
90 90
91#else 91#else
92 // close all open mainwnds 92 // close all open mainwnds
93 QValueList<PwM *>::Iterator i = _mainWndList.begin(), 93 QValueList<PwM *>::Iterator i = _mainWndList.begin(),
94 end = _mainWndList.end(); 94 end = _mainWndList.end();
95#endif 95#endif
96 while (i != end) { 96 while (i != end) {
97 disconnect(*i, SIGNAL(closed(PwM *)), 97 disconnect(*i, SIGNAL(closed(PwM *)),
98 this, SLOT(mainWndClosed(PwM *))); 98 this, SLOT(mainWndClosed(PwM *)));
99 delete *i; 99 delete *i;
100 ++i; 100 ++i;
101 } 101 }
102 _mainWndList.clear(); 102 _mainWndList.clear();
103 // close all remaining open documents 103 // close all remaining open documents
104 PwMDocList *_dl = PwMDoc::getOpenDocList(); 104 PwMDocList *_dl = PwMDoc::getOpenDocList();
105 vector<PwMDocList::listItem> dl = *(_dl->getList()); 105 vector<PwMDocList::listItem> dl = *(_dl->getList());
106 vector<PwMDocList::listItem>::iterator i2 = dl.begin(), 106 vector<PwMDocList::listItem>::iterator i2 = dl.begin(),
107 end2 = dl.end(); 107 end2 = dl.end();
108 while (i2 != end2) { 108 while (i2 != end2) {
109 delete (*i2).doc; 109 delete (*i2).doc;
110 ++i2; 110 ++i2;
111 } 111 }
112 112
113#ifdef CONFIG_KWALLETIF 113#ifdef CONFIG_KWALLETIF
114 delete_ifnot_null(_kwalletEmu); 114 delete_ifnot_null(_kwalletEmu);
115#endif // CONFIG_KWALLETIF 115#endif // CONFIG_KWALLETIF
116#ifdef CONFIG_KEYCARD 116#ifdef CONFIG_KEYCARD
117 delete_ifnot_null(_keycard); 117 delete_ifnot_null(_keycard);
118#endif // CONFIG_KEYCARD 118#endif // CONFIG_KEYCARD
119 delete_ifnot_null(_tray); 119 delete_ifnot_null(_tray);
120 120
121 Randomizer::cleanup(); 121 Randomizer::cleanup();
122 Configuration::cleanup(); 122 Configuration::cleanup();
123} 123}
124 124
125void PwMInit::initializeApp() 125void PwMInit::initializeApp()
126{ 126{
127 PWM_ASSERT(runStatus == unknown); 127 PWM_ASSERT(runStatus == unknown);
128 runStatus = init; 128 runStatus = init;
129 initPosixSignalHandler(); 129 initPosixSignalHandler();
130 Randomizer::init(); 130 Randomizer::init();
131 Configuration::init(); 131 Configuration::init();
132 initDCOP(); 132 initDCOP();
133 initKWalletEmu(); 133 initKWalletEmu();
134 initKeycard(); 134 initKeycard();
135 initTray(); 135 initTray();
136 handleCmdLineArgs(); 136 handleCmdLineArgs();
137 137
138 bool openDeeplocked = false; 138 bool openDeeplocked = false;
139 if (conf()->confGlobAutostartDeepLocked() || 139 if (conf()->confGlobAutostartDeepLocked() ||
140 savedCmd.open_deeplocked) 140 savedCmd.open_deeplocked)
141 openDeeplocked = true; 141 openDeeplocked = true;
142 if (conf()->confWndAutoMinimizeOnStart() || 142 if (conf()->confWndAutoMinimizeOnStart() ||
143 savedCmd.minToTray) { 143 savedCmd.minToTray) {
144 PwMDoc *newDoc = createDoc(); 144 PwMDoc *newDoc = createDoc();
145 if (!newDoc->openDocUi(newDoc, 145 if (!newDoc->openDocUi(newDoc,
146 conf()->confGlobAutoStart(), 146 conf()->confGlobAutoStart(),
147 openDeeplocked)) { 147 openDeeplocked)) {
148 delete newDoc; 148 delete newDoc;
149 } 149 }
150 } else { 150 } else {
151 createMainWnd(conf()->confGlobAutoStart(), 151 createMainWnd(conf()->confGlobAutoStart(),
152 openDeeplocked, 152 openDeeplocked,
153 true, 153 true,
154 0, 154 0,
155 savedCmd.minimized); 155 savedCmd.minimized);
156 } 156 }
157 157
158 runStatus = running; 158 runStatus = running;
159} 159}
160 160
161void PwMInit::shutdownApp(int exitStatus) 161void PwMInit::shutdownApp(int exitStatus)
162{ 162{
163 printDebug(string("PwMInit::shutdownApp(") 163 printDebug(string("PwMInit::shutdownApp(")
164 + tostr(exitStatus) + ") called."); 164 + tostr(exitStatus) + ") called.");
165 PWM_ASSERT((runStatus == running) || (runStatus == init)); 165 PWM_ASSERT((runStatus == running) || (runStatus == init));
166 runStatus = shutdown; 166 runStatus = shutdown;
167 QApplication::exit(exitStatus); 167 QApplication::exit(exitStatus);
168 /* The destructor of PwMInit is called when control 168 /* The destructor of PwMInit is called when control
169 * leaves main() 169 * leaves main()
170 */ 170 */
171} 171}
172 172
173void PwMInit::initPosixSignalHandler() 173void PwMInit::initPosixSignalHandler()
174{ 174{
175 signal(SIGINT, sig_handler); 175 signal(SIGINT, sig_handler);
176 signal(SIGTERM, sig_handler); 176 signal(SIGTERM, sig_handler);
177} 177}
178 178
179void PwMInit::initDCOP() 179void PwMInit::initDCOP()
180{ 180{
181#ifndef PWM_EMBEDDED 181#ifndef PWM_EMBEDDED
182 _dcopClient = app->dcopClient(); 182 _dcopClient = app->dcopClient();
183 _dcopClient->setNotifications(true); 183 _dcopClient->setNotifications(true);
184#else
185 qDebug("PwMInit::initDCOP() has to be implemented");
186#endif 184#endif
187 185
188} 186}
189 187
190void PwMInit::initKWalletEmu(bool forceDisable, bool forceReload) 188void PwMInit::initKWalletEmu(bool forceDisable, bool forceReload)
191{ 189{
192#ifdef CONFIG_KWALLETIF 190#ifdef CONFIG_KWALLETIF
193 if (!conf()->confGlobKwalletEmu() || 191 if (!conf()->confGlobKwalletEmu() ||
194 forceDisable) { 192 forceDisable) {
195 delete_ifnot_null(_kwalletEmu); 193 delete_ifnot_null(_kwalletEmu);
196 return; 194 return;
197 } 195 }
198 try { 196 try {
199 if (_kwalletEmu && forceReload) 197 if (_kwalletEmu && forceReload)
200 delete_and_null(_kwalletEmu); 198 delete_and_null(_kwalletEmu);
201 if (!_kwalletEmu) 199 if (!_kwalletEmu)
202 _kwalletEmu = new KWalletEmu(this); 200 _kwalletEmu = new KWalletEmu(this);
203 } catch (PwMException e) { 201 } catch (PwMException e) {
204 string errMsg("initializing KWallet emulation failed. ID: "); 202 string errMsg("initializing KWallet emulation failed. ID: ");
205 errMsg += tostr(static_cast<int>(e.getId())); 203 errMsg += tostr(static_cast<int>(e.getId()));
206 errMsg += " err-message: "; 204 errMsg += " err-message: ";
207 errMsg += e.getMessage(); 205 errMsg += e.getMessage();
208 printWarn(errMsg); 206 printWarn(errMsg);
209 return; 207 return;
210 } 208 }
211#else // CONFIG_KWALLETIF 209#else // CONFIG_KWALLETIF
212 PARAM_UNUSED(forceDisable); 210 PARAM_UNUSED(forceDisable);
213 PARAM_UNUSED(forceReload); 211 PARAM_UNUSED(forceReload);
214#endif // CONFIG_KWALLETIF 212#endif // CONFIG_KWALLETIF
215} 213}
216 214
217void PwMInit::initKeycard() 215void PwMInit::initKeycard()
218{ 216{
219#ifdef CONFIG_KEYCARD 217#ifdef CONFIG_KEYCARD
220 PWM_ASSERT(!_keycard); 218 PWM_ASSERT(!_keycard);
221 _keycard = new PwMKeyCard(this); 219 _keycard = new PwMKeyCard(this);
222#endif // CONFIG_KEYCARD 220#endif // CONFIG_KEYCARD
223} 221}
224 222
225void PwMInit::initTray() 223void PwMInit::initTray()
226{ 224{
227#ifdef PWM_EMBEDDED 225#ifdef PWM_EMBEDDED
228 //US ENH : embedded version does not support a tray 226 //US ENH : embedded version does not support a tray
229 return; 227 return;
230#endif 228#endif
231 229
232 if (!conf()->confGlobTray()) { 230 if (!conf()->confGlobTray()) {
233 if (!_tray) 231 if (!_tray)
234 return; 232 return;
235 _tray->hide(); 233 _tray->hide();
236 delete_and_null(_tray); 234 delete_and_null(_tray);
237 return; 235 return;
238 } 236 }
239 if (_tray) 237 if (_tray)
240 return; 238 return;
241 _tray = new PwMTray(this); 239 _tray = new PwMTray(this);
242 connect(_tray, SIGNAL(quitSelected()), 240 connect(_tray, SIGNAL(quitSelected()),
243 this, SLOT(removeTrayAndQuit())); 241 this, SLOT(removeTrayAndQuit()));
244 connect(_tray, SIGNAL(closed(PwMTray *)), 242 connect(_tray, SIGNAL(closed(PwMTray *)),
245 this, SLOT(trayIconClosed(PwMTray *))); 243 this, SLOT(trayIconClosed(PwMTray *)));
246 KIconLoader icons; 244 KIconLoader icons;
247#ifndef PWM_EMBEDDED 245#ifndef PWM_EMBEDDED
248 _tray->setPixmap(icons.loadIcon(PACKAGE_NAME, KIcon::Small)); 246 _tray->setPixmap(icons.loadIcon(PACKAGE_NAME, KIcon::Small));
249#endif 247#endif
250 _tray->show(); 248 _tray->show();
251 // connect the signals of all open documents. 249 // connect the signals of all open documents.
252 const vector<PwMDocList::listItem> *dl = PwMDoc::getOpenDocList()->getList(); 250 const vector<PwMDocList::listItem> *dl = PwMDoc::getOpenDocList()->getList();
253 vector<PwMDocList::listItem>::const_iterator i = dl->begin(), 251 vector<PwMDocList::listItem>::const_iterator i = dl->begin(),
254 end = dl->end(); 252 end = dl->end();
255 while (i != end) { 253 while (i != end) {
256 _tray->connectDocToTray((*i).doc); 254 _tray->connectDocToTray((*i).doc);
257 ++i; 255 ++i;
258 } 256 }
259} 257}
260 258
261void PwMInit::removeTrayAndQuit() 259void PwMInit::removeTrayAndQuit()
262{ 260{
263 PWM_ASSERT(_tray); 261 PWM_ASSERT(_tray);
264 // _tray is deleted in ~PwMInit 262 // _tray is deleted in ~PwMInit
265 shutdownApp(0); 263 shutdownApp(0);
266} 264}
267 265
268PwM * PwMInit::createMainWnd(const QString &loadFile, 266PwM * PwMInit::createMainWnd(const QString &loadFile,
269 bool loadFileDeepLocked, 267 bool loadFileDeepLocked,
270 bool virginity, 268 bool virginity,
271 PwMDoc *doc, 269 PwMDoc *doc,
272 bool minimized) 270 bool minimized)
273{ 271{
274 PwM *newWnd; 272 PwM *newWnd;
275 if (!doc) 273 if (!doc)
276 doc = createDoc(); 274 doc = createDoc();
277 newWnd = new PwM(this, doc, virginity); 275 newWnd = new PwM(this, doc, virginity);
278#ifndef PWM_EMBEDDED 276#ifndef PWM_EMBEDDED
279 _mainWndList.push_back(newWnd); 277 _mainWndList.push_back(newWnd);
280#else 278#else
281 _mainWndList.append(newWnd); 279 _mainWndList.append(newWnd);
282#endif 280#endif
283 connect(newWnd, SIGNAL(closed(PwM *)), 281 connect(newWnd, SIGNAL(closed(PwM *)),
284 this, SLOT(mainWndClosed(PwM *))); 282 this, SLOT(mainWndClosed(PwM *)));
285 connect(newWnd, SIGNAL(gotFocus(PwM *)), 283 connect(newWnd, SIGNAL(gotFocus(PwM *)),
286 this, SLOT(setCurWidget(PwM *))); 284 this, SLOT(setCurWidget(PwM *)));
287 connect(newWnd, SIGNAL(lostFocus(PwM *)), 285 connect(newWnd, SIGNAL(lostFocus(PwM *)),
288 this, SLOT(resetCurWidget())); 286 this, SLOT(resetCurWidget()));
289 287
290 //US ENH 288 //US ENH
291#ifndef PWM_EMBEDDED 289#ifndef PWM_EMBEDDED
292 if (minimized) 290 if (minimized)
293 newWnd->showMinimized(); 291 newWnd->showMinimized();
294 else 292 else
295 newWnd->show(); 293 newWnd->show();
296 294
297#else //PWM_EMBEDDED 295#else //PWM_EMBEDDED
298 296
299#ifndef DESKTOP_VERSION 297#ifndef DESKTOP_VERSION
300 app->showMainWidget( newWnd ); 298 app->showMainWidget( newWnd );
301#else //DESKTOP_VERSION 299#else //DESKTOP_VERSION
302 app->setMainWidget( newWnd ); 300 app->setMainWidget( newWnd );
303 newWnd->resize (640, 480 ); 301 newWnd->resize (640, 480 );
304 newWnd->show(); 302 newWnd->show();
305#endif //DESKTOP_VERSION 303#endif //DESKTOP_VERSION
306 304
307#endif //PWM_EMBEDDED 305#endif //PWM_EMBEDDED
308 306
309 if (loadFile != QString::null && 307 if (loadFile != QString::null &&
310 loadFile != "") { 308 loadFile != "") {
311 newWnd->openDoc(loadFile, loadFileDeepLocked); 309 newWnd->openDoc(loadFile, loadFileDeepLocked);
312 } 310 }
313 return newWnd; 311 return newWnd;
314} 312}
315 313
316PwMDoc * PwMInit::createDoc() 314PwMDoc * PwMInit::createDoc()
317{ 315{
318 PwMDoc *doc = new PwMDoc(this); 316 PwMDoc *doc = new PwMDoc(this);
319#ifdef CONFIG_KEYCARD 317#ifdef CONFIG_KEYCARD
320 doc->setPwMKeyCard(keycard()); 318 doc->setPwMKeyCard(keycard());
321#endif 319#endif
322#ifdef CONFIG_KWALLETIF 320#ifdef CONFIG_KWALLETIF
323 if (kwalletEmu()) 321 if (kwalletEmu())
324 kwalletEmu()->connectDocSignals(doc); 322 kwalletEmu()->connectDocSignals(doc);
325#endif 323#endif
326 324
327 if (_tray) 325 if (_tray)
328 _tray->connectDocToTray(doc); 326 _tray->connectDocToTray(doc);
329 327
330 return doc; 328 return doc;
331 329
332} 330}
333 331
334void PwMInit::mainWndClosed(PwM *wnd) 332void PwMInit::mainWndClosed(PwM *wnd)
335{ 333{
336 bool doMinimizeToTray = false; 334 bool doMinimizeToTray = false;
337 bool doDeleteDoc = false; 335 bool doDeleteDoc = false;
338#ifndef PWM_EMBEDDED 336#ifndef PWM_EMBEDDED
339 dcopClient()->suspend(); 337 dcopClient()->suspend();
340 dcopClient()->setAcceptCalls(false); 338 dcopClient()->setAcceptCalls(false);
341#endif 339#endif
342again: 340again:
343 341
344 if (wnd->isForceMinimizeToTray()) { 342 if (wnd->isForceMinimizeToTray()) {
345 if (unlikely(!_tray)) { 343 if (unlikely(!_tray)) {
346 /* This should not happen! If we set forceMinimizeToTray , 344 /* This should not happen! If we set forceMinimizeToTray ,
347 * we must be sure that _tray exists. 345 * we must be sure that _tray exists.
348 */ 346 */
349 BUG(); 347 BUG();
350 wnd->setForceMinimizeToTray(false); 348 wnd->setForceMinimizeToTray(false);
351 goto again; 349 goto again;
352 } 350 }
353 doMinimizeToTray = true; 351 doMinimizeToTray = true;
354 } else { 352 } else {
355 // Ask to minimize to tray. If not, delete doc. 353 // Ask to minimize to tray. If not, delete doc.
356 if (_tray && 354 if (_tray &&
357 runStatus != shutdown && 355 runStatus != shutdown &&
358 !wnd->isForceQuit() && 356 !wnd->isForceQuit() &&
359 !wnd->curDoc()->isDeleted()) { 357 !wnd->curDoc()->isDeleted()) {
360 if (conf()->confWndClose()) 358 if (conf()->confWndClose())
361 doDeleteDoc = true; 359 doDeleteDoc = true;
362 else 360 else
363 doMinimizeToTray = true; 361 doMinimizeToTray = true;
364 } else { 362 } else {
365 doDeleteDoc = true; 363 doDeleteDoc = true;
366 } 364 }
367 } 365 }
368 366
369 if (doMinimizeToTray) { 367 if (doMinimizeToTray) {
370 368
371 PWM_ASSERT(_tray); 369 PWM_ASSERT(_tray);
372 int mmlock = conf()->confGlobMinimizeLock(); 370 int mmlock = conf()->confGlobMinimizeLock();
373 switch (mmlock) { 371 switch (mmlock) {
374 case 0: // don't lock anything 372 case 0: // don't lock anything
375 break; 373 break;
376 case 1: // normal lock 374 case 1: // normal lock
377 wnd->curDoc()->lockAll(true); 375 wnd->curDoc()->lockAll(true);
378 break; 376 break;
379 case 2: // deep-lock 377 case 2: // deep-lock
380 wnd->curDoc()->deepLock(); 378 wnd->curDoc()->deepLock();
381 break; 379 break;
382 default: 380 default:
383 WARN(); 381 WARN();
384 } 382 }
385 } else if (doDeleteDoc) { 383 } else if (doDeleteDoc) {
386 if (!wnd->curDoc()->tryDelete()) { 384 if (!wnd->curDoc()->tryDelete()) {
387 /* We failed deleting the doc, 385 /* We failed deleting the doc,
388 * so open a new window with it, again. 386 * so open a new window with it, again.
389 */ 387 */
390 createMainWnd(QString::null, false, 388 createMainWnd(QString::null, false,
391 false, wnd->curDoc()); 389 false, wnd->curDoc());
392 } 390 }
393 } 391 }
394#ifndef PWM_EMBEDDED 392#ifndef PWM_EMBEDDED
395 // find the closed window in the "mainWndList" and delete it. 393 // find the closed window in the "mainWndList" and delete it.
396 QValueList<PwM *>::iterator i = _mainWndList.begin(), 394 QValueList<PwM *>::iterator i = _mainWndList.begin(),
397 end = _mainWndList.end(); 395 end = _mainWndList.end();
398#else 396#else
399 // find the closed window in the "mainWndList" and delete it. 397 // find the closed window in the "mainWndList" and delete it.
400 QValueList<PwM *>::Iterator i = _mainWndList.begin(), 398 QValueList<PwM *>::Iterator i = _mainWndList.begin(),
401 end = _mainWndList.end(); 399 end = _mainWndList.end();
402#endif 400#endif
403 while (i != end) { 401 while (i != end) {
404 if (*i == wnd) { 402 if (*i == wnd) {
405#ifndef PWM_EMBEDDED 403#ifndef PWM_EMBEDDED
406 _mainWndList.erase(i); 404 _mainWndList.erase(i);
407#else 405#else
408 _mainWndList.remove(i); 406 _mainWndList.remove(i);
409#endif 407#endif
410 goto out_success; 408 goto out_success;
411 } 409 }
412 ++i; 410 ++i;
413 } 411 }
414 BUG(); 412 BUG();
415out_success: 413out_success:
416#ifndef PWM_EMBEDDED 414#ifndef PWM_EMBEDDED
417 if (!_mainWndList.size()) 415 if (!_mainWndList.size())
418#else 416#else
419 if (!_mainWndList.count()) 417 if (!_mainWndList.count())
420#endif 418#endif
421 419
422 { 420 {
423 /* If there's no main window and no tray icon 421 /* If there's no main window and no tray icon
424 * left, we have no user interface, so we can 422 * left, we have no user interface, so we can
425 * shut down the application. 423 * shut down the application.
426 */ 424 */
427 if (!_tray) { 425 if (!_tray) {
428#ifndef PWM_EMBEDDED 426#ifndef PWM_EMBEDDED
429 dcopClient()->setAcceptCalls(true); 427 dcopClient()->setAcceptCalls(true);
430 dcopClient()->resume(); 428 dcopClient()->resume();
431#endif 429#endif
432 shutdownApp(0); 430 shutdownApp(0);
433 return; 431 return;
434 } 432 }
435 /* There is no widget left, so set 433 /* There is no widget left, so set
436 * _curWidget to 0 434 * _curWidget to 0
437 */ 435 */
438 resetCurWidget(); 436 resetCurWidget();
439 } 437 }
440#ifndef PWM_EMBEDDED 438#ifndef PWM_EMBEDDED
441 dcopClient()->setAcceptCalls(true); 439 dcopClient()->setAcceptCalls(true);
442 dcopClient()->resume(); 440 dcopClient()->resume();
443#endif 441#endif
444} 442}
445 443
446void PwMInit::trayIconClosed(PwMTray *tray) 444void PwMInit::trayIconClosed(PwMTray *tray)
447{ 445{
448 if (runStatus != running) 446 if (runStatus != running)
449 return; 447 return;
450 PARAM_UNUSED(tray); 448 PARAM_UNUSED(tray);
451 PWM_ASSERT(tray == _tray); 449 PWM_ASSERT(tray == _tray);
452 /* If there's no main wnd left we have to 450 /* If there's no main wnd left we have to
453 * shutdown the app (same as in mainWndClosed()) 451 * shutdown the app (same as in mainWndClosed())
454 */ 452 */
455#ifndef PWM_EMBEDDED 453#ifndef PWM_EMBEDDED
456 if (!_mainWndList.size()) 454 if (!_mainWndList.size())
457 shutdownApp(0); 455 shutdownApp(0);
458#else 456#else
459 if (!_mainWndList.count()) 457 if (!_mainWndList.count())
460 shutdownApp(0); 458 shutdownApp(0);
461#endif 459#endif
462} 460}
463 461
464void PwMInit::handleCmdLineArgs(bool initial) 462void PwMInit::handleCmdLineArgs(bool initial)
465{ 463{
466#ifndef PWM_EMBEDDED 464#ifndef PWM_EMBEDDED
467 KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); 465 KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
468 PWM_ASSERT(args); 466 PWM_ASSERT(args);
469 int i, numArgs = args->count(); 467 int i, numArgs = args->count();
470 const char *curArg; 468 const char *curArg;
471 469
472 // read all cmdline options 470 // read all cmdline options
473 savedCmd.open_deeplocked = args->isSet("open-deeplocked"); 471 savedCmd.open_deeplocked = args->isSet("open-deeplocked");
474 savedCmd.minimized = args->isSet("minimized"); 472 savedCmd.minimized = args->isSet("minimized");
475 savedCmd.minToTray = args->isSet("mintray"); 473 savedCmd.minToTray = args->isSet("mintray");
476 savedCmd.skipSelfTest = args->isSet("skip-self-test"); 474 savedCmd.skipSelfTest = args->isSet("skip-self-test");
477 if (savedCmd.minimized && 475 if (savedCmd.minimized &&
478 savedCmd.minToTray) { 476 savedCmd.minToTray) {
479 printInfo(i18n("Commandline option \"--minimized\" and " 477 printInfo(i18n("Commandline option \"--minimized\" and "
480 "\"--mintray\" selected. These are incompatible. " 478 "\"--mintray\" selected. These are incompatible. "
481 "\"--mintray\" will be selected.").latin1()); 479 "\"--mintray\" will be selected.").latin1());
482 } 480 }
483 /* Iterate through all non-option arguments. 481 /* Iterate through all non-option arguments.
484 * Every non-option arg is a filename to open. 482 * Every non-option arg is a filename to open.
485 */ 483 */
486 for (i = 0; i < numArgs; ++i) { 484 for (i = 0; i < numArgs; ++i) {
487 curArg = args->arg(i); 485 curArg = args->arg(i);
488 PWM_ASSERT(curArg); 486 PWM_ASSERT(curArg);
489 if (savedCmd.minToTray) { 487 if (savedCmd.minToTray) {
490 PwMDoc *newDoc = createDoc(); 488 PwMDoc *newDoc = createDoc();
491 if (!newDoc->openDocUi(newDoc, 489 if (!newDoc->openDocUi(newDoc,
492 curArg, 490 curArg,
493 savedCmd.open_deeplocked)) { 491 savedCmd.open_deeplocked)) {
494 delete newDoc; 492 delete newDoc;
495 } 493 }
496 } else { 494 } else {
497 PwM *newInstance = createMainWnd(QString::null, 495 PwM *newInstance = createMainWnd(QString::null,
498 false, 496 false,
499 true, 497 true,
500 0, 498 0,
501 savedCmd.minimized); 499 savedCmd.minimized);
502 PwMDoc *newDoc = newInstance->openDoc(curArg, 500 PwMDoc *newDoc = newInstance->openDoc(curArg,
503 savedCmd.open_deeplocked); 501 savedCmd.open_deeplocked);
504 if (!newDoc) { 502 if (!newDoc) {
505 newInstance->setForceQuit(true); 503 newInstance->setForceQuit(true);
506 delete_and_null(newInstance); 504 delete_and_null(newInstance);
507 } 505 }
508 } 506 }
509 } 507 }
510 508
511 if (savedCmd.minToTray) { 509 if (savedCmd.minToTray) {
512 minimizeAllMainWnd(true); 510 minimizeAllMainWnd(true);
513 } else if (savedCmd.minimized) { 511 } else if (savedCmd.minimized) {
514 minimizeAllMainWnd(false); 512 minimizeAllMainWnd(false);
515 } 513 }
516 if (!savedCmd.skipSelfTest && initial) { 514 if (!savedCmd.skipSelfTest && initial) {
517 SelfTest::schedule(); 515 SelfTest::schedule();
518 } 516 }
519 args->clear(); 517 args->clear();
520#endif 518#endif
521} 519}
522 520
523void PwMInit::minimizeAllMainWnd(bool toTray) 521void PwMInit::minimizeAllMainWnd(bool toTray)
524{ 522{
525#ifndef PWM_EMBEDDED 523#ifndef PWM_EMBEDDED
526 if (!_mainWndList.size()) 524 if (!_mainWndList.size())
527 return; 525 return;
528#else 526#else
529 if (!_mainWndList.count()) 527 if (!_mainWndList.count())
530 return; 528 return;
531#endif 529#endif
532 const QValueList<PwM *> *ml = mainWndList(); 530 const QValueList<PwM *> *ml = mainWndList();
533#ifndef PWM_EMBEDDED 531#ifndef PWM_EMBEDDED
534 QValueList<PwM *>::const_iterator it = ml->begin(), 532 QValueList<PwM *>::const_iterator it = ml->begin(),
535 end = ml->end(); 533 end = ml->end();
536#else 534#else
537 QValueList<PwM *>::ConstIterator it = ml->begin(), 535 QValueList<PwM *>::ConstIterator it = ml->begin(),
538 end = ml->end(); 536 end = ml->end();
539#endif 537#endif
540 PwM *wnd; 538 PwM *wnd;
541 if (toTray && _tray) { 539 if (toTray && _tray) {
542 /* minimize to tray. 540 /* minimize to tray.
543 * close all mainWnd. 541 * close all mainWnd.
544 */ 542 */
545 while (it != end) { 543 while (it != end) {
546 wnd = *it; 544 wnd = *it;
547 wnd->setForceMinimizeToTray(true); 545 wnd->setForceMinimizeToTray(true);
548 wnd->close_slot(); 546 wnd->close_slot();
549 ++it; 547 ++it;
550 } 548 }
551 } else { 549 } else {
552 // normal minimize 550 // normal minimize
553 while (it != end) { 551 while (it != end) {
554 wnd = *it; 552 wnd = *it;
555 wnd->hide(); 553 wnd->hide();
556 wnd->showMinimized(); 554 wnd->showMinimized();
557 ++it; 555 ++it;
558 } 556 }
559 } 557 }
560} 558}
561 559
562#ifdef PWM_EMBEDDED 560#ifdef PWM_EMBEDDED
563 561
564#ifndef DESKTOP_VERSION 562#ifndef DESKTOP_VERSION
565 563
566PwMApplication::PwMApplication(int & argc, char ** argv) 564PwMApplication::PwMApplication(int & argc, char ** argv)
567 : QPEApplication( argc, argv ) 565 : QPEApplication( argc, argv )
568 , init (0) 566 , init (0)
569{ 567{