summaryrefslogtreecommitdiffabout
authorulf69 <ulf69>2004-10-19 18:19:48 (UTC)
committer ulf69 <ulf69>2004-10-19 18:19:48 (UTC)
commit3b4dc5931f729bd1385ec83f8c9b82a1eb42ef36 (patch) (unidiff)
tree0c39138398640a7996ea4eea4c0f8196dbdc2bef
parent695c64501950e0503ed558fbe8d8c06993776eaa (diff)
downloadkdepimpi-3b4dc5931f729bd1385ec83f8c9b82a1eb42ef36.zip
kdepimpi-3b4dc5931f729bd1385ec83f8c9b82a1eb42ef36.tar.gz
kdepimpi-3b4dc5931f729bd1385ec83f8c9b82a1eb42ef36.tar.bz2
merging of two bugfixes provided by Michael:
1) files were getting stored always twice 2) "Save As..." returned a No permission dialogbox when executed right after starting the application
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--pwmanager/pwmanager/pwmdoc.cpp65
-rw-r--r--pwmanager/pwmanager/pwmdoc.h2
-rw-r--r--pwmanager/pwmanager/pwmdocui.cpp12
3 files changed, 67 insertions, 12 deletions
diff --git a/pwmanager/pwmanager/pwmdoc.cpp b/pwmanager/pwmanager/pwmdoc.cpp
index e9906a4..f4a1636 100644
--- a/pwmanager/pwmanager/pwmdoc.cpp
+++ b/pwmanager/pwmanager/pwmdoc.cpp
@@ -8,13 +8,13 @@
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 2.0 of pwmanager 14 * This file is originaly based on version 1.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 "pwmdoc.h" 20#include "pwmdoc.h"
@@ -327,26 +327,62 @@ PwMDoc::~PwMDoc()
327 delete _timer; 327 delete _timer;
328} 328}
329 329
330PwMerror PwMDoc::saveDoc(char compress, const QString *file) 330PwMerror PwMDoc::saveDoc(char compress, const QString *file)
331{ 331{
332 PwMerror ret, e; 332 PwMerror ret, e;
333 string serialized;
334 QFile f;
335 QString tmpFileMoved(QString::null);
336 bool wasDeepLocked;
337 QString savedFilename(filename);
338
333 if (!file) { 339 if (!file) {
334 if (filename == "") 340 if (filename == "")
335 return e_filename; 341 return e_filename;
336 } else { 342 if (isDeepLocked()) {
343 /* We don't need to save any data.
344 * It's already all on disk, because
345 * we are deeplocked.
346 */
347 unsetDocStatFlag(DOC_STAT_DISK_DIRTY);
348 ret = e_success;
349 goto out;
350 }
351 } else {
337 if (*file == "" && filename == "") 352 if (*file == "" && filename == "")
338 return e_filename; 353 return e_filename;
339 if (*file != "") 354 if (*file != "")
340 filename = *file; 355 filename = *file;
341 } 356 }
342 357
343 bool wasDeepLocked = isDeepLocked(); 358 wasDeepLocked = isDeepLocked();
344 if (wasDeepLocked) { 359 if (wasDeepLocked) {
345 if (deepLock(false) != e_success) 360 /* We are deeplocked. That means all data is already
346 return e_noPw; 361 * on disk. BUT we need to do saving procedure,
362 * because *file != savedFilename.
363 * Additionally we need to tempoarly restore
364 * the old "filename", because deepLock() references it.
365 */
366 QString newFilename(filename);
367 filename = savedFilename;
368 getDataChangedLock();
369 e = deepLock(false);
370 putDataChangedLock();
371 filename = newFilename;
372 switch (e) {
373 case e_success:
374 break;
375 case e_wrongPw:
376 case e_noPw:
377 emitDataChanged(this);
378 return e;
379 default:
380 emitDataChanged(this);
381 return e_openFile;
382 }
347 } 383 }
348 384
349 if (!isPwAvailable()) { 385 if (!isPwAvailable()) {
350 /* password is not available. This means, the 386 /* password is not available. This means, the
351 * document wasn't saved, yet. 387 * document wasn't saved, yet.
352 */ 388 */
@@ -386,13 +422,12 @@ PwMerror PwMDoc::saveDoc(char compress, const QString *file)
386 char hashAlgo = static_cast<char>(_hashAlgo); 422 char hashAlgo = static_cast<char>(_hashAlgo);
387 423
388 if (conf()->confGlobMakeFileBackup()) { 424 if (conf()->confGlobMakeFileBackup()) {
389 if (!backupFile(filename)) 425 if (!backupFile(filename))
390 return e_fileBackup; 426 return e_fileBackup;
391 } 427 }
392 QString tmpFileMoved(QString::null);
393 if (QFile::exists(filename)) { 428 if (QFile::exists(filename)) {
394 /* Move the existing file to some tmp file. 429 /* Move the existing file to some tmp file.
395 * When saving file succeeds, delete tmp file. Otherwise 430 * When saving file succeeds, delete tmp file. Otherwise
396 * move tmp file back. See below. 431 * move tmp file back. See below.
397 */ 432 */
398 Randomizer *rnd = Randomizer::obj(); 433 Randomizer *rnd = Randomizer::obj();
@@ -405,14 +440,13 @@ PwMerror PwMDoc::saveDoc(char compress, const QString *file)
405 if (!QFile::remove(filename)) { 440 if (!QFile::remove(filename)) {
406 printWarn(string("removing orig file ") 441 printWarn(string("removing orig file ")
407 + filename.latin1() 442 + filename.latin1()
408 + " failed!"); 443 + " failed!");
409 } 444 }
410 } 445 }
411 QFile f(filename); 446 f.setName(filename);
412 string serialized;
413 if (!f.open(IO_ReadWrite)) { 447 if (!f.open(IO_ReadWrite)) {
414 ret = e_openFile; 448 ret = e_openFile;
415 goto out_moveback; 449 goto out_moveback;
416 } 450 }
417 e = writeFileHeader(hashAlgo, hashAlgo, 451 e = writeFileHeader(hashAlgo, hashAlgo,
418 cryptAlgo, compress, 452 cryptAlgo, compress,
@@ -473,14 +507,22 @@ PwMerror PwMDoc::saveDoc(char compress, const QString *file)
473 f.close(); 507 f.close();
474 if (chmod(filename.latin1(), 508 if (chmod(filename.latin1(),
475 conf()->confGlobFilePermissions())) { 509 conf()->confGlobFilePermissions())) {
476 printWarn(string("chmod failed: ") + strerror(errno)); 510 printWarn(string("chmod failed: ") + strerror(errno));
477 } 511 }
478 openDocList.edit(this, getTitle().latin1()); 512 openDocList.edit(this, getTitle().latin1());
479 if (wasDeepLocked) 513 if (wasDeepLocked) {
480 deepLock(true); 514 /* Do _not_ save the data with the deepLock()
515 * call, because this will recurse
516 * into saveDoc()
517 */
518 deepLock(true, false);
519 /* We don't check return value here, because
520 * it won't fail. See NOTE in deepLock()
521 */
522 }
481 if (tmpFileMoved != QString::null) { 523 if (tmpFileMoved != QString::null) {
482 // now remove the moved file. 524 // now remove the moved file.
483 if (!QFile::remove(tmpFileMoved)) { 525 if (!QFile::remove(tmpFileMoved)) {
484 printWarn(string("removing file ") 526 printWarn(string("removing file ")
485 + tmpFileMoved.latin1() 527 + tmpFileMoved.latin1()
486 + " failed!"); 528 + " failed!");
@@ -1766,12 +1808,15 @@ bool PwMDoc::unlockAll_tempoary(bool revert)
1766 return true; 1808 return true;
1767} 1809}
1768 1810
1769PwMerror PwMDoc::deepLock(bool lock, bool saveToFile) 1811PwMerror PwMDoc::deepLock(bool lock, bool saveToFile)
1770{ 1812{
1771 PwMerror ret; 1813 PwMerror ret;
1814 /* NOTE: saveDoc() depends on this function to return
1815 * e_success if saveToFile == false
1816 */
1772 1817
1773 if (lock) { 1818 if (lock) {
1774 if (isDeepLocked()) 1819 if (isDeepLocked())
1775 return e_lock; 1820 return e_lock;
1776 if (saveToFile) { 1821 if (saveToFile) {
1777 if (isDocEmpty()) 1822 if (isDocEmpty())
diff --git a/pwmanager/pwmanager/pwmdoc.h b/pwmanager/pwmanager/pwmdoc.h
index 535fb92..a6e5f58 100644
--- a/pwmanager/pwmanager/pwmdoc.h
+++ b/pwmanager/pwmanager/pwmdoc.h
@@ -8,13 +8,13 @@
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 2.0 of pwmanager 14 * This file is originaly based on version 1.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#ifndef __PWMDOC_H 20#ifndef __PWMDOC_H
diff --git a/pwmanager/pwmanager/pwmdocui.cpp b/pwmanager/pwmanager/pwmdocui.cpp
index 7b8e0ee..6ddb6f5 100644
--- a/pwmanager/pwmanager/pwmdocui.cpp
+++ b/pwmanager/pwmanager/pwmdocui.cpp
@@ -270,12 +270,17 @@ bool PwMDocUi::saveDocUi(PwMDoc *doc)
270 } else if (ret == e_fileBackup) { 270 } else if (ret == e_fileBackup) {
271 KMessageBox::error(currentView, 271 KMessageBox::error(currentView,
272 i18n("Error: Couldn't make backup-file!"), 272 i18n("Error: Couldn't make backup-file!"),
273 i18n("backup failed")); 273 i18n("backup failed"));
274 doc->timer()->putLock(DocTimer::id_autoLockTimer); 274 doc->timer()->putLock(DocTimer::id_autoLockTimer);
275 return false; 275 return false;
276 } else if (ret == e_noPw ||
277 ret == e_wrongPw ||
278 ret == e_openFile) {
279 doc->timer()->putLock(DocTimer::id_autoLockTimer);
280 return false;
276 } else if (ret != e_success) { 281 } else if (ret != e_success) {
277 KMessageBox::error(currentView, 282 KMessageBox::error(currentView,
278 i18n("Error: Couldn't write to file.\n" 283 i18n("Error: Couldn't write to file.\n"
279 "Please check if you have permission to\n" 284 "Please check if you have permission to\n"
280 "write to the file in that directory."), 285 "write to the file in that directory."),
281 i18n("error while writing")); 286 i18n("error while writing"));
@@ -315,13 +320,18 @@ bool PwMDocUi::saveAsDocUi(PwMDoc *doc)
315 return false; 320 return false;
316 } 321 }
317 if (fn.right(4) != ".pwm") 322 if (fn.right(4) != ".pwm")
318 fn += ".pwm"; 323 fn += ".pwm";
319 324
320 PwMerror ret = doc->saveDoc(conf()->confGlobCompression(), &fn); 325 PwMerror ret = doc->saveDoc(conf()->confGlobCompression(), &fn);
321 if (ret != e_success) { 326 if (ret == e_noPw ||
327 ret == e_wrongPw ||
328 ret == e_openFile) {
329 doc->timer()->putLock(DocTimer::id_autoLockTimer);
330 return false;
331 } else if (ret != e_success) {
322 KMessageBox::error(currentView, 332 KMessageBox::error(currentView,
323 i18n("Error: Couldn't write to file.\n" 333 i18n("Error: Couldn't write to file.\n"
324 "Please check if you have permission to\n" 334 "Please check if you have permission to\n"
325 "write to the file in that directory."), 335 "write to the file in that directory."),
326 i18n("error while writing")); 336 i18n("error while writing"));
327 doc->timer()->putLock(DocTimer::id_autoLockTimer); 337 doc->timer()->putLock(DocTimer::id_autoLockTimer);