[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [KSecretService] bc65bca: Rename result() in user interface jobs to
From: Michael Leupold <lemma () confuego ! org>
Date: 2010-11-09 19:14:28
Message-ID: 20101109191428.04507A60E2 () git ! kde ! org
[Download RAW message or body]
commit bc65bca6ebe3ae101b043aede4afebff34844e70
branch master
Author: Michael Leupold <lemma@confuego.org>
Date: Sun Aug 29 13:10:39 2010 +0000
Rename result() in user interface jobs to cancelled() and reverse the meaning.
Add a ui job for asking the user for a new password.
svn path=/trunk/playground/base/ksecretservice/; revision=1169508
diff --git a/ui/abstractuijobs.cpp b/ui/abstractuijobs.cpp
index b8304b0..6a5277d 100644
--- a/ui/abstractuijobs.cpp
+++ b/ui/abstractuijobs.cpp
@@ -40,7 +40,8 @@ void AbstractUiJob::exec()
AbstractAskPasswordJob::AbstractAskPasswordJob(AbstractUiManager *manager,
const QString &collection,
bool secondTry)
- : AbstractUiJob(manager), m_collection(collection), m_secondTry(secondTry)
+ : AbstractUiJob(manager), m_collection(collection), m_secondTry(secondTry),
+ m_cancelled(false)
{
}
@@ -58,9 +59,9 @@ bool AbstractAskPasswordJob::isSecondTry() const
return m_secondTry;
}
-bool AbstractAskPasswordJob::result() const
+bool AbstractAskPasswordJob::cancelled() const
{
- return m_result;
+ return m_cancelled;
}
const QCA::SecureArray &AbstractAskPasswordJob::password() const
@@ -68,9 +69,9 @@ const QCA::SecureArray &AbstractAskPasswordJob::password() const
return m_password;
}
-void AbstractAskPasswordJob::setResult(bool result)
+void AbstractAskPasswordJob::setCancelled(bool cancelled)
{
- m_result = result;
+ m_cancelled = cancelled;
}
void AbstractAskPasswordJob::setPassword(const QCA::SecureArray &password)
@@ -78,4 +79,39 @@ void AbstractAskPasswordJob::setPassword(const QCA::SecureArray &password)
m_password = password;
}
+AbstractNewPasswordJob::AbstractNewPasswordJob(AbstractUiManager* manager,
+ const QString& collection)
+ : AbstractUiJob(manager), m_collection(collection), m_cancelled(false)
+{
+}
+
+AbstractNewPasswordJob::~AbstractNewPasswordJob()
+{
+}
+
+const QString &AbstractNewPasswordJob::collection() const
+{
+ return m_collection;
+}
+
+bool AbstractNewPasswordJob::cancelled() const
+{
+ return m_cancelled;
+}
+
+const QCA::SecureArray &AbstractNewPasswordJob::password() const
+{
+ return m_password;
+}
+
+void AbstractNewPasswordJob::setCancelled(bool cancelled)
+{
+ m_cancelled = cancelled;
+}
+
+void AbstractNewPasswordJob::setPassword(const QCA::SecureArray &password)
+{
+ m_password = password;
+}
+
#include "abstractuijobs.moc"
diff --git a/ui/abstractuijobs.h b/ui/abstractuijobs.h
index c9ad9aa..23ce0e4 100644
--- a/ui/abstractuijobs.h
+++ b/ui/abstractuijobs.h
@@ -96,11 +96,11 @@ public:
bool isSecondTry() const;
/**
- * Get the result of the operation.
+ * Check if the dialog was cancelled by the user.
*
- * @return true if the user entered a password, false if not
+ * @return true if the user cancelled instead of entering a password, false if not
*/
- bool result() const;
+ bool cancelled() const;
/**
* Get the password the user entered.
@@ -112,12 +112,11 @@ public:
protected:
/**
- * Set the result of the operation.
+ * Set if the user cancels entering a password.
*
- * @remarks this is used by derived classes
- * @param result result of the operation
+ * @param cancelled true if the user cancelled the dialog, false if not
*/
- void setResult(bool result);
+ void setCancelled(bool cancelled);
/**
* Set the password entered by the user.
@@ -128,10 +127,70 @@ protected:
void setPassword(const QCA::SecureArray &password);
private:
- QString m_collection; // name of the collection to be unlocked
+ QString m_collection; // name of the collection to be unlocked
bool m_secondTry; // true if this is not the first try
- bool m_result; // the result of the operation
- QCA::SecureArray m_password; // the password entered by the user
+ bool m_cancelled; // the result of the operation
+ QCA::SecureArray m_password; // the password entered by the user
+};
+
+/**
+ * Job that asks a user for a new password for a collection.
+ */
+class AbstractNewPasswordJob : public AbstractUiJob
+{
+ Q_OBJECT
+
+public:
+ /**
+ * Constructor.
+ *
+ * @param manager ui job manager and parent object
+ * @param collection label of the collection the password is for
+ */
+ AbstractNewPasswordJob(AbstractUiManager *manager, const QString &collection);
+
+ /**
+ * Destructor.
+ */
+ virtual ~AbstractNewPasswordJob();
+
+ /**
+ * Get the label of the collection the password is for.
+ */
+ const QString &collection() const;
+
+ /**
+ * Check if the dialog was cancelled by the user.
+ *
+ * @return true if the user cancelled instead of entering a password, false else
+ */
+ bool cancelled() const;
+
+ /**
+ * Get the password the user entered.
+ *
+ * @return the password entered by the user or an empty array if the user
+ * didn't enter a password
+ */
+ const QCA::SecureArray &password() const;
+
+protected:
+ /**
+ * Set if the user cancels entering a password.
+ *
+ * @param cancelled true if the user cancelled the dialog, false if not
+ */
+ void setCancelled(bool cancelled);
+
+ /**
+ * Set the password entered by the user.
+ */
+ void setPassword(const QCA::SecureArray &password);
+
+private:
+ QString m_collection; // name of the collection the password is for
+ bool m_cancelled; // true if the operation was cancelled
+ QCA::SecureArray m_password; // the new password entered by the user
};
#endif
diff --git a/ui/abstractuimanager.h b/ui/abstractuimanager.h
index 24e0d06..947d67d 100644
--- a/ui/abstractuimanager.h
+++ b/ui/abstractuimanager.h
@@ -48,6 +48,14 @@ public:
*/
virtual AbstractAskPasswordJob *createAskPasswordJob(const QString &collection,
bool secondTry) = 0;
+
+ /**
+ * Create a job for asking a user for a new password for a collection.
+ *
+ * @param collection label of the collection to change the password for
+ * @return a job which can be enqueued to ask the user for a new password
+ */
+ virtual AbstractNewPasswordJob *createNewPasswordJob(const QString &collection) = 0;
};
#endif
diff --git a/ui/dialoguifactory.cpp b/ui/dialoguifactory.cpp
index ae12429..cfbfdab 100644
--- a/ui/dialoguifactory.cpp
+++ b/ui/dialoguifactory.cpp
@@ -22,15 +22,10 @@
#include <QtCore/QTimer>
#include <kpassworddialog.h>
-
-AbstractAskPasswordJob* DialogUiFactory::createAskPasswordJob(const QString& collection,
- bool secondTry)
-{
- return new DialogAskPasswordJob(this, collection, secondTry);
-}
+#include <knewpassworddialog.h>
DialogAskPasswordJob::DialogAskPasswordJob(AbstractUiManager *manager,
- const QString& collection,
+ const QString &collection,
bool secondTry)
: AbstractAskPasswordJob(manager, collection, secondTry), m_dialog(0)
{
@@ -57,11 +52,54 @@ void DialogAskPasswordJob::dialogFinished(int result)
Q_ASSERT(m_dialog);
if (result == QDialog::Accepted) {
setPassword(QCA::SecureArray(m_dialog->password().toUtf8()));
- setResult(true);
} else {
- setResult(false);
+ setCancelled(true);
}
emitResult();
}
+DialogNewPasswordJob::DialogNewPasswordJob(AbstractUiManager *manager,
+ const QString &collection)
+ : AbstractNewPasswordJob(manager, collection), m_dialog(0)
+{
+}
+
+DialogNewPasswordJob::~DialogNewPasswordJob()
+{
+}
+
+void DialogNewPasswordJob::start()
+{
+ Q_ASSERT(!m_dialog);
+ // TODO: provide parent widget!
+ m_dialog = new KNewPasswordDialog;
+ m_dialog->setAttribute(Qt::WA_DeleteOnClose, true);
+ // TODO: needs proper string
+ m_dialog->setPrompt("Collection " + collection() + " wants new password.");
+ connect(m_dialog, SIGNAL(finished(int)), this, SLOT(dialogFinished(int)));
+ m_dialog->show();
+}
+
+void DialogNewPasswordJob::dialogFinished(int result)
+{
+ Q_ASSERT(m_dialog);
+ if (result == QDialog::Accepted) {
+ setPassword(QCA::SecureArray(m_dialog->password().toUtf8()));
+ } else {
+ setCancelled(true);
+ }
+ emitResult();
+}
+
+AbstractAskPasswordJob *DialogUiFactory::createAskPasswordJob(const QString &collection,
+ bool secondTry)
+{
+ return new DialogAskPasswordJob(this, collection, secondTry);
+}
+
+AbstractNewPasswordJob *DialogUiFactory::createNewPasswordJob(const QString &collection)
+{
+ return new DialogNewPasswordJob(this, collection);
+}
+
#include "dialoguifactory.moc"
diff --git a/ui/dialoguifactory.h b/ui/dialoguifactory.h
index f3c4dc0..2e56e93 100644
--- a/ui/dialoguifactory.h
+++ b/ui/dialoguifactory.h
@@ -25,6 +25,7 @@
#include "abstractuimanager.h"
class KPasswordDialog;
+class KNewPasswordDialog;
class DialogAskPasswordJob : public AbstractAskPasswordJob
{
@@ -34,10 +35,10 @@ public:
/**
* Constructor.
*/
- DialogAskPasswordJob(AbstractUiManager *manager, const QString& collection, bool secondTry);
+ DialogAskPasswordJob(AbstractUiManager *manager, const QString &collection, bool secondTry);
/**
- * Destructor.
+ * Destructor.Inheritance graph
*/
~DialogAskPasswordJob();
@@ -56,6 +57,36 @@ private:
KPasswordDialog *m_dialog;
};
+class DialogNewPasswordJob : public AbstractNewPasswordJob
+{
+ Q_OBJECT
+
+public:
+ /**
+ * Constructor.
+ */
+ DialogNewPasswordJob(AbstractUiManager *manager, const QString &collection);
+
+ /**
+ * Destructor.
+ */
+ ~DialogNewPasswordJob();
+
+ /**
+ * Contains the actual workload of showing the dialog.
+ */
+ virtual void start();
+
+private Q_SLOTS:
+ /**
+ * Called when the dialog shown is either accepted or rejected.
+ */
+ void dialogFinished(int result);
+
+private:
+ KNewPasswordDialog *m_dialog;
+};
+
/**
* Implement AbstractUiFactory to provide a user interface using dialogs.
*/
@@ -70,8 +101,13 @@ public:
/**
* Create a job to ask for a user's password to unlock a collection.
*/
- virtual AbstractAskPasswordJob* createAskPasswordJob(const QString& collection,
+ virtual AbstractAskPasswordJob* createAskPasswordJob(const QString &collection,
bool secondTry);
+
+ /**
+ * Create a job to ask a user for a new password for a collection.
+ */
+ virtual AbstractNewPasswordJob *createNewPasswordJob(const QString &collection);
};
#endif
diff --git a/ui/tests/dialoguifactorytest.cpp b/ui/tests/dialoguifactorytest.cpp
index 73f1a02..7db42b7 100644
--- a/ui/tests/dialoguifactorytest.cpp
+++ b/ui/tests/dialoguifactorytest.cpp
@@ -44,6 +44,18 @@ void DialogUiFactoryTest::testAskPassword()
loop.exec();
}
+void DialogUiFactoryTest::testNewPassword()
+{
+ DialogUiFactory fact;
+
+ // ask for a new password (asynchronously)
+ AbstractNewPasswordJob *asyncJob1 = fact.createNewPasswordJob("TESTCOLLECTION");
+ QEventLoop loop;
+ connect(asyncJob1, SIGNAL(result(QueuedJob*)), &loop, SLOT(quit()));
+ asyncJob1->enqueue();
+ loop.exec();
+}
+
void DialogUiFactoryTest::cleanupTestCase()
{
}
diff --git a/ui/tests/dialoguifactorytest.h b/ui/tests/dialoguifactorytest.h
index d862ea7..bd3e225 100644
--- a/ui/tests/dialoguifactorytest.h
+++ b/ui/tests/dialoguifactorytest.h
@@ -31,6 +31,7 @@ private Q_SLOTS:
void initTestCase();
void testAskPassword();
+ void testNewPassword();
void cleanupTestCase();
};
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic