From 3f5d9725a23f25ee623123160dd11cea11adb063 Mon Sep 17 00:00:00 2001
From: =?utf8?q?Enar=20V=C3=A4ikene?= <enar@vaikene.net>
Date: Thu, 17 Nov 2011 11:15:21 +0200
Subject: [PATCH] Fixed setting the password length argument that was not
 possible to change once stored into the storage.

---
 src/apps/PswGen/CLI/cli.cpp   | 10 ++++++++--
 src/apps/PswGen/CLI/version.h |  4 ++--
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/src/apps/PswGen/CLI/cli.cpp b/src/apps/PswGen/CLI/cli.cpp
index fbc8450..1b59e8b 100644
--- a/src/apps/PswGen/CLI/cli.cpp
+++ b/src/apps/PswGen/CLI/cli.cpp
@@ -159,7 +159,7 @@ void Module::generatePassword()
 {
     QString masterPassword;
     QString appName;
-    int passwordLength = DefaultPasswordLength;
+    int passwordLength = 0;
 
     // Process command-line arguments
     QStringList args = QCoreApplication::arguments();
@@ -199,10 +199,14 @@ void Module::generatePassword()
     QExplicitlySharedDataPointer<PswGen::Storage::Data> data;
     if (mStorage) {
         data = mStorage->query(appName);
-        if (data)
+        if (data && passwordLength == 0)
             passwordLength = data->length();
     }
 
+    // If the length argument is still not initialized, use the default length value
+    if (!passwordLength)
+        passwordLength = DefaultPasswordLength;
+
     // Generate password
     QString password = mGenerator->generatePassword(appName, masterPassword, passwordLength);
     cout << "Generated password : " << password << endl;
@@ -211,6 +215,8 @@ void Module::generatePassword()
     if (mStorage) {
         if (!data)
             data = new Storage::Data(appName, passwordLength);
+        else
+            data->setLength(passwordLength);
         mStorage->save(appName, data);
     }
 }
diff --git a/src/apps/PswGen/CLI/version.h b/src/apps/PswGen/CLI/version.h
index 2707d5a..348e78a 100644
--- a/src/apps/PswGen/CLI/version.h
+++ b/src/apps/PswGen/CLI/version.h
@@ -25,12 +25,12 @@
 /**
  * Module/library version number in the form major,minor,release,build
  */
-#define VER_FILE_VERSION                0,1,1,1
+#define VER_FILE_VERSION                0,1,1,2
 
 /**
  * Module/library version number in the string format (shall end with \0)
  */
-#define VER_FILE_VERSION_STR            "0.1.1.1\0"
+#define VER_FILE_VERSION_STR            "0.1.1.2\0"
 
 /**
  * Module/library name (shall end with \0)
-- 
2.49.0