author | ulf69 <ulf69> | 2004-10-19 18:19:48 (UTC) |
---|---|---|
committer | ulf69 <ulf69> | 2004-10-19 18:19:48 (UTC) |
commit | 3b4dc5931f729bd1385ec83f8c9b82a1eb42ef36 (patch) (side-by-side diff) | |
tree | 0c39138398640a7996ea4eea4c0f8196dbdc2bef /pwmanager | |
parent | 695c64501950e0503ed558fbe8d8c06993776eaa (diff) | |
download | kdepimpi-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
-rw-r--r-- | pwmanager/pwmanager/pwmdoc.cpp | 63 | ||||
-rw-r--r-- | pwmanager/pwmanager/pwmdoc.h | 2 | ||||
-rw-r--r-- | pwmanager/pwmanager/pwmdocui.cpp | 12 |
3 files changed, 66 insertions, 11 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 @@ -12,5 +12,5 @@ /*************************************************************************** * copyright (C) 2004 by Ulf Schenk - * This file is originaly based on version 2.0 of pwmanager + * This file is originaly based on version 1.1 of pwmanager * and was modified to run on embedded devices that run microkde * @@ -331,7 +331,22 @@ PwMerror PwMDoc::saveDoc(char compress, const QString *file) { PwMerror ret, e; + string serialized; + QFile f; + QString tmpFileMoved(QString::null); + bool wasDeepLocked; + QString savedFilename(filename); + if (!file) { if (filename == "") return e_filename; + if (isDeepLocked()) { + /* We don't need to save any data. + * It's already all on disk, because + * we are deeplocked. + */ + unsetDocStatFlag(DOC_STAT_DISK_DIRTY); + ret = e_success; + goto out; + } } else { if (*file == "" && filename == "") @@ -341,8 +356,29 @@ PwMerror PwMDoc::saveDoc(char compress, const QString *file) } - bool wasDeepLocked = isDeepLocked(); + wasDeepLocked = isDeepLocked(); if (wasDeepLocked) { - if (deepLock(false) != e_success) - return e_noPw; + /* We are deeplocked. That means all data is already + * on disk. BUT we need to do saving procedure, + * because *file != savedFilename. + * Additionally we need to tempoarly restore + * the old "filename", because deepLock() references it. + */ + QString newFilename(filename); + filename = savedFilename; + getDataChangedLock(); + e = deepLock(false); + putDataChangedLock(); + filename = newFilename; + switch (e) { + case e_success: + break; + case e_wrongPw: + case e_noPw: + emitDataChanged(this); + return e; + default: + emitDataChanged(this); + return e_openFile; + } } @@ -390,5 +426,4 @@ PwMerror PwMDoc::saveDoc(char compress, const QString *file) return e_fileBackup; } - QString tmpFileMoved(QString::null); if (QFile::exists(filename)) { /* Move the existing file to some tmp file. @@ -409,6 +444,5 @@ PwMerror PwMDoc::saveDoc(char compress, const QString *file) } } - QFile f(filename); - string serialized; + f.setName(filename); if (!f.open(IO_ReadWrite)) { ret = e_openFile; @@ -477,6 +511,14 @@ PwMerror PwMDoc::saveDoc(char compress, const QString *file) } openDocList.edit(this, getTitle().latin1()); - if (wasDeepLocked) - deepLock(true); + if (wasDeepLocked) { + /* Do _not_ save the data with the deepLock() + * call, because this will recurse + * into saveDoc() + */ + deepLock(true, false); + /* We don't check return value here, because + * it won't fail. See NOTE in deepLock() + */ + } if (tmpFileMoved != QString::null) { // now remove the moved file. @@ -1770,4 +1812,7 @@ PwMerror PwMDoc::deepLock(bool lock, bool saveToFile) { PwMerror ret; + /* NOTE: saveDoc() depends on this function to return + * e_success if saveToFile == false + */ if (lock) { 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 @@ -12,5 +12,5 @@ /*************************************************************************** * copyright (C) 2004 by Ulf Schenk - * This file is originaly based on version 2.0 of pwmanager + * This file is originaly based on version 1.1 of pwmanager * and was modified to run on embedded devices that run microkde * 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 @@ -274,4 +274,9 @@ bool PwMDocUi::saveDocUi(PwMDoc *doc) doc->timer()->putLock(DocTimer::id_autoLockTimer); return false; + } else if (ret == e_noPw || + ret == e_wrongPw || + ret == e_openFile) { + doc->timer()->putLock(DocTimer::id_autoLockTimer); + return false; } else if (ret != e_success) { KMessageBox::error(currentView, @@ -319,5 +324,10 @@ bool PwMDocUi::saveAsDocUi(PwMDoc *doc) PwMerror ret = doc->saveDoc(conf()->confGlobCompression(), &fn); - if (ret != e_success) { + if (ret == e_noPw || + ret == e_wrongPw || + ret == e_openFile) { + doc->timer()->putLock(DocTimer::id_autoLockTimer); + return false; + } else if (ret != e_success) { KMessageBox::error(currentView, i18n("Error: Couldn't write to file.\n" |