summaryrefslogtreecommitdiffabout
path: root/pwmanager/pwmanager/pwmdocui.cpp
authorulf69 <ulf69>2004-09-15 17:53:22 (UTC)
committer ulf69 <ulf69>2004-09-15 17:53:22 (UTC)
commitd3925ba5bd25224bc4a60d3d6a107c464994a1ea (patch) (side-by-side diff)
tree60f69da1d2b79ee3081e7ef5c09a46470ca6eda0 /pwmanager/pwmanager/pwmdocui.cpp
parentce83a3479d23b9e8a59c745ccd0a0b14f64ef4e8 (diff)
downloadkdepimpi-d3925ba5bd25224bc4a60d3d6a107c464994a1ea.zip
kdepimpi-d3925ba5bd25224bc4a60d3d6a107c464994a1ea.tar.gz
kdepimpi-d3925ba5bd25224bc4a60d3d6a107c464994a1ea.tar.bz2
initial revision
Diffstat (limited to 'pwmanager/pwmanager/pwmdocui.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--pwmanager/pwmanager/pwmdocui.cpp436
1 files changed, 436 insertions, 0 deletions
diff --git a/pwmanager/pwmanager/pwmdocui.cpp b/pwmanager/pwmanager/pwmdocui.cpp
new file mode 100644
index 0000000..66a1b59
--- a/dev/null
+++ b/pwmanager/pwmanager/pwmdocui.cpp
@@ -0,0 +1,436 @@
+/***************************************************************************
+ * *
+ * copyright (C) 2003, 2004 by Michael Buesch *
+ * email: mbuesch@freenet.de *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License version 2 *
+ * as published by the Free Software Foundation. *
+ * *
+ ***************************************************************************/
+
+/***************************************************************************
+ * copyright (C) 2004 by Ulf Schenk
+ * This file is originaly based on version 1.0.1 of pwmanager
+ * and was modified to run on embedded devices that run microkde
+ *
+ * $Id$
+ **************************************************************************/
+
+#include "pwmdocui.h"
+#include "setmasterpwwndimpl.h"
+#include "getmasterpwwndimpl.h"
+#include "pwmexception.h"
+#include "getkeycardwnd.h"
+#include "pwm.h"
+#include "globalstuff.h"
+#include "spinforsignal.h"
+
+#include <qlineedit.h>
+#include <qtabwidget.h>
+
+#include <kmessagebox.h>
+#include <kfiledialog.h>
+
+#ifndef PWM_EMBEDDED
+#include <kwin.h>
+#else
+#endif
+
+
+#ifdef CONFIG_KEYCARD
+# include "pwmkeycard.h"
+#endif
+
+
+PwMDocUi::PwMDocUi(QObject *parent, const char *name)
+ : QObject(parent, name)
+{
+ currentView = 0;
+ keyCard = 0;
+}
+
+PwMDocUi::~PwMDocUi()
+{
+}
+
+QString PwMDocUi::requestMpw(bool chipcard)
+{
+ QString pw;
+
+ if (chipcard) {
+#ifdef CONFIG_KEYCARD
+ PWM_ASSERT(keyCard);
+ uint32_t id;
+ string ret;
+ SpinForSignal *spinner = keyCard->getSpinner();
+ connect(keyCard, SIGNAL(keyAvailable(uint32_t, const string &)),
+ spinner, SLOT(u32_str_slot(uint32_t, const string &)));
+ keyCard->getKey();
+ spinner->spin(&id, &ret);
+ disconnect(keyCard, SIGNAL(keyAvailable(uint32_t, const string &)),
+ spinner, SLOT(u32_str_slot(uint32_t, const string &)));
+ if (ret == "")
+ return "";
+ pw = ret.c_str();
+#else // CONFIG_KEYCARD
+ no_keycard_support_msg_box(currentView);
+#endif // CONFIG_KEYCARD
+ } else {
+ GetMasterPwWndImpl pwWnd;
+#ifndef PWM_EMBEDDED
+ KWin::setState(pwWnd.winId(), NET::StaysOnTop);
+#endif
+ if (pwWnd.exec() != 1)
+ return "";
+ pw = pwWnd.pwLineEdit->text();
+ }
+
+ return pw;
+}
+
+QString PwMDocUi::requestNewMpw(bool *chipcard)
+{
+ QString pw;
+ SetMasterPwWndImpl pwWnd(currentView);
+ pwWnd.setPwMKeyCard(keyCard);
+#ifndef PWM_EMBEDDED
+ if (!chipcard) {
+ pwWnd.mainTab->removePage(pwWnd.mainTab->page(1));
+ }
+#else
+ qDebug("PwMDocUi::requestNewMpw must be implemented");
+#endif
+
+ if (pwWnd.exec() != 1)
+ return "";
+ pw = pwWnd.getPw(chipcard).c_str();
+
+ return pw;
+}
+
+QString PwMDocUi::requestMpwChange(const QString *currentPw, bool *chipcard)
+{
+ QString pw(requestMpw(*chipcard));
+ if (pw == "")
+ return "";
+ if (pw != *currentPw) {
+ wrongMpwMsgBox(*chipcard);
+ return "";
+ }
+
+ pw = requestNewMpw(chipcard);
+ if (pw == "")
+ return "";
+ return pw;
+}
+
+void PwMDocUi::wrongMpwMsgBox(bool chipcard, QString prefix, QString postfix)
+{
+ QString msg;
+ if (prefix != "") {
+ msg += prefix;
+ msg += "\n";
+ }
+
+ if (chipcard) {
+ msg += i18n("Wrong key-card!\n"
+ "Please try again with the "
+ "correct key-card.");
+ } else {
+ msg += i18n("Wrong master-password!\n"
+ "Please try again.");
+ }
+
+ if (postfix != "") {
+ msg += "\n";
+ msg += postfix;
+ }
+ KMessageBox::error(currentView, msg,
+ (chipcard) ? (i18n("wrong chipcard"))
+ : (i18n("password error")));
+}
+
+void PwMDocUi::noMpwMsgBox(bool chipcard, QString prefix, QString postfix)
+{
+ QString msg;
+ if (prefix != "") {
+ msg += prefix;
+ msg += "\n";
+ }
+
+ if (chipcard) {
+ msg += i18n("No key-card found!\n"
+ "Please insert the "
+ "correct key-card.");
+ } else {
+ msg += i18n("No master-password given!");
+ }
+
+ if (postfix != "") {
+ msg += "\n";
+ msg += postfix;
+ }
+ KMessageBox::error(currentView, msg,
+ (chipcard) ? (i18n("no chipcard"))
+ : (i18n("password error")));
+}
+
+void PwMDocUi::rootAlertMsgBox()
+{
+ KMessageBox::error(currentView,
+ i18n("This feature is not available, "
+ "if you execute PwM with \"root\" "
+ "UID 0 privileges, for security reasons!"),
+ i18n("not allowed as root!"));
+}
+
+void PwMDocUi::cantDeeplock_notSavedMsgBox()
+{
+ KMessageBox::error(currentView,
+ i18n("Can't deep-lock, because the document "
+ "hasn't been saved, yet. Please save "
+ "to a file and try again."),
+ i18n("not saved, yet"));
+}
+
+void PwMDocUi::gpmPwLenErrMsgBox()
+{
+ KMessageBox::error(currentView,
+ i18n("GPasman does not support passwords "
+ "shorter than 4 characters! Please try "
+ "again with a longer password."),
+ i18n("password too short"));
+}
+
+int PwMDocUi::dirtyAskSave(const QString &docTitle)
+{
+ int ret;
+#ifndef PWM_EMBEDDED
+ ret = KMessageBox::questionYesNoCancel(currentView,
+ i18n("The list \"") +
+ docTitle +
+ i18n
+ ("\" has been modified.\n"
+ "Do you want to save it?"),
+ i18n("save?"));
+ if (ret == KMessageBox::Yes) {
+ return 0;
+ } else if (ret == KMessageBox::No) {
+ return 1;
+ }
+#else
+ ret = KMessageBox::warningYesNoCancel(currentView,
+ i18n("The list \"") +
+ docTitle +
+ i18n
+ ("\" has been modified.\n"
+ "Do you want to save it?"),
+ i18n("save?"));
+ if (ret == KMessageBox::Yes) {
+ return 0;
+ } else if (ret == KMessageBox::No) {
+ return 1;
+ }
+
+#endif
+
+ // cancel
+ return -1;
+}
+
+bool PwMDocUi::saveDocUi(PwMDoc *doc)
+{
+ PWM_ASSERT(doc);
+ doc->timer()->getLock(DocTimer::id_autoLockTimer);
+ if (doc->isDocEmpty()) {
+ KMessageBox::information(currentView,
+ i18n
+ ("Sorry, there's nothing to save.\n"
+ "Please first add some passwords."),
+ i18n("nothing to do"));
+ doc->timer()->putLock(DocTimer::id_autoLockTimer);
+ return true;
+ }
+ PwMerror ret = doc->saveDoc(conf()->confGlobCompression());
+ if (ret == e_filename) {
+ doc->timer()->putLock(DocTimer::id_autoLockTimer);
+ return saveAsDocUi(doc);
+ } else if (ret == e_weakPw) {
+ KMessageBox::error(currentView,
+ i18n("Error: This is a weak password.\n"
+ "Please select another password."),
+ i18n("weak password"));
+ doc->timer()->putLock(DocTimer::id_autoLockTimer);
+ return false;
+ } else if (ret == e_fileBackup) {
+ KMessageBox::error(currentView,
+ i18n("Error: Couldn't make backup-file!"),
+ i18n("backup failed"));
+ doc->timer()->putLock(DocTimer::id_autoLockTimer);
+ return false;
+ } else if (ret != e_success) {
+ KMessageBox::error(currentView,
+ i18n("Error: Couldn't write to file.\n"
+ "Please check if you have permission to "
+ "write to the file in that directory."),
+ i18n("error while writing"));
+ doc->timer()->putLock(DocTimer::id_autoLockTimer);
+ return false;
+ }
+ doc->timer()->putLock(DocTimer::id_autoLockTimer);
+ return true;
+}
+
+bool PwMDocUi::saveAsDocUi(PwMDoc *doc)
+{
+ PWM_ASSERT(doc);
+ doc->timer()->getLock(DocTimer::id_autoLockTimer);
+ if (doc->isDocEmpty()) {
+ KMessageBox::information(currentView,
+ i18n
+ ("Sorry, there's nothing to save.\n"
+ "Please first add some passwords."),
+ i18n("nothing to do"));
+ doc->timer()->putLock(DocTimer::id_autoLockTimer);
+ return true;
+ }
+ QString fn(KFileDialog::getSaveFileName(QString::null,
+ i18n("*.pwm|PwManager Password file"),
+ currentView));
+ if (fn == "") {
+ doc->timer()->putLock(DocTimer::id_autoLockTimer);
+ return false;
+ }
+ if (fn.right(4) != ".pwm")
+ fn += ".pwm";
+
+ PwMerror ret = doc->saveDoc(conf()->confGlobCompression(), &fn);
+ if (ret != e_success) {
+ KMessageBox::error(currentView,
+ i18n("Error: Couldn't write to file.\n"
+ "Please check if you have permission to "
+ "write to the file in that directory."),
+ i18n("error while writing"));
+ doc->timer()->putLock(DocTimer::id_autoLockTimer);
+ return false;
+ }
+ doc->timer()->putLock(DocTimer::id_autoLockTimer);
+ return true;
+}
+
+bool PwMDocUi::openDocUi(PwMDoc *doc,
+ QString filename,
+ bool openDeepLocked)
+{
+ if (filename.isEmpty())
+ filename = KFileDialog::getOpenFileName(QString::null,
+ i18n("*.pwm|PwManager Password file\n"
+ "*|All files"), getCurrentView());
+ if (filename.isEmpty())
+ goto cancelOpen;
+ PwMerror ret;
+ while (true) {
+ int lockStat = -1;
+ if (openDeepLocked) {
+ lockStat = 2;
+ } else {
+ if (conf()->confGlobUnlockOnOpen()) {
+ lockStat = 0;
+ } else {
+ lockStat = 1;
+ }
+ }
+ ret = doc->openDoc(&filename, lockStat);
+ if (ret != e_success) {
+ if (ret == e_readFile || ret == e_openFile) {
+ KMessageBox::error(getCurrentView(),
+ i18n("Could not read file!")
+ + "\n"
+ + filename,
+ i18n("file error"));
+ goto cancelOpen;
+ }
+ if (ret == e_alreadyOpen) {
+ KMessageBox::error(getCurrentView(),
+ i18n("This file is already open."),
+ i18n("already open"));
+ goto cancelOpen;
+ }
+ if (ret == e_fileVer) {
+ KMessageBox::error(getCurrentView(),
+ i18n
+ ("File-version is not supported!\n"
+ "Did you create this file with an older or newer version of PwM?"),
+ i18n
+ ("incompatible version"));
+ goto cancelOpen;
+ }
+ if (ret == e_wrongPw) {
+ continue;
+ }
+ if (ret == e_noPw) {
+ goto cancelOpen;
+ }
+ if (ret == e_fileFormat) {
+ KMessageBox::error(getCurrentView(),
+ i18n
+ ("Sorry, this file has not been recognized "
+ "as a PwM Password file.\n"
+ "Probably you have selected the wrong file."),
+ i18n
+ ("no PwM password-file"));
+ goto cancelOpen;
+ }
+ if (ret == e_fileCorrupt) {
+ KMessageBox::error(getCurrentView(),
+ i18n
+ ("File corrupt!\n"
+ "Maybe the media, you stored this file on, "
+ "had bad sectors?"),
+ i18n
+ ("checksum error"));
+ goto cancelOpen;
+ }
+ }
+ break;
+ }
+ return true;
+
+ cancelOpen:
+ return false;
+}
+
+QString PwMDocUi::string_defaultCategory()
+{
+ return i18n("Default");
+}
+
+QString PwMDocUi::string_locked()
+{
+ return i18n("<LOCKED>");
+}
+
+QString PwMDocUi::string_deepLockedShort()
+{
+ return i18n("DEEP-LOCKED");
+}
+
+QString PwMDocUi::string_deepLockedLong()
+{
+ return i18n("This file is DEEP-LOCKED!\n"
+ "That means all data has been encrypted "
+ "and written out to the file. If you want "
+ "to see the entries, please UNLOCK the file. "
+ "While unlocking, you will be prompted for the "
+ "master-password or the key-card.");
+}
+
+QString PwMDocUi::string_defaultTitle()
+{
+ return i18n("Untitled");
+}
+
+#ifndef PWM_EMBEDDED
+#include "pwmdocui.moc"
+#endif