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