summaryrefslogtreecommitdiffabout
authorulf69 <ulf69>2004-09-15 22:39:25 (UTC)
committer ulf69 <ulf69>2004-09-15 22:39:25 (UTC)
commit610cf2a6c7aaf9855b54cd0453f347edf9c1a855 (patch) (side-by-side diff)
tree5ef182e00afa3fbc6cb9a2d6f59654c599c6118a
parent7fae8b87a05c3572bf0c9218d300d99fdc02adc4 (diff)
downloadkdepimpi-610cf2a6c7aaf9855b54cd0453f347edf9c1a855.zip
kdepimpi-610cf2a6c7aaf9855b54cd0453f347edf9c1a855.tar.gz
kdepimpi-610cf2a6c7aaf9855b54cd0453f347edf9c1a855.tar.bz2
enhanced code
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--pwmanager/pwmanager/pwm.cpp167
-rw-r--r--pwmanager/pwmanager/pwm.h6
-rw-r--r--pwmanager/pwmanager/pwmdocui.cpp17
3 files changed, 152 insertions, 38 deletions
diff --git a/pwmanager/pwmanager/pwm.cpp b/pwmanager/pwmanager/pwm.cpp
index 0e57650..e5579f8 100644
--- a/pwmanager/pwmanager/pwm.cpp
+++ b/pwmanager/pwmanager/pwm.cpp
@@ -1,422 +1,461 @@
/***************************************************************************
* *
* 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 <klocale.h>
#include <klistview.h>
#include <ktoolbar.h>
#include <kfiledialog.h>
#include <kiconloader.h>
#include <kmessagebox.h>
#ifndef PWM_EMBEDDED
#include <kmenubar.h>
#include <kstatusbar.h>
#include <dcopclient.h>
#else
#include <qmenubar.h>
+#include <qmessagebox.h>
#endif
#include <qpixmap.h>
#include <qcheckbox.h>
#include <qspinbox.h>
#include <qlineedit.h>
#include <qfileinfo.h>
#include <qclipboard.h>
#include <stdio.h>
#include "pwm.h"
#include "pwminit.h"
#include "configwndimpl.h"
#include "pwmprint.h"
#include "addentrywndimpl.h"
#include "globalstuff.h"
#include "findwndimpl.h"
#include "configuration.h"
#ifdef CONFIG_KWALLETIF
# include "kwalletif.h"
# include "kwalletemu.h"
#endif
#ifdef CONFIG_KEYCARD
# include "pwmkeycard.h"
#endif
#define DEFAULT_SIZE (QSize(700, 400))
// Button IDs for "file" popup menu
enum {
BUTTON_POPUP_FILE_NEW = 0,
BUTTON_POPUP_FILE_OPEN,
BUTTON_POPUP_FILE_CLOSE,
BUTTON_POPUP_FILE_SAVE,
BUTTON_POPUP_FILE_SAVEAS,
BUTTON_POPUP_FILE_EXPORT,
BUTTON_POPUP_FILE_IMPORT,
BUTTON_POPUP_FILE_PRINT,
BUTTON_POPUP_FILE_QUIT
};
// Button IDs for "manage" popup menu
enum {
BUTTON_POPUP_MANAGE_ADD = 0,
BUTTON_POPUP_MANAGE_EDIT,
BUTTON_POPUP_MANAGE_DEL,
BUTTON_POPUP_MANAGE_CHANGEMP
};
// Button IDs for chipcard popup menu
enum {
#ifdef CONFIG_KEYCARD
BUTTON_POPUP_CHIPCARD_GENNEW = 0,
BUTTON_POPUP_CHIPCARD_DEL,
BUTTON_POPUP_CHIPCARD_READID,
BUTTON_POPUP_CHIPCARD_SAVEBACKUP,
BUTTON_POPUP_CHIPCARD_REPLAYBACKUP
#else // CONFIG_KEYCARD
BUTTON_POPUP_CHIPCARD_NO = 0
#endif // CONFIG_KEYCARD
};
// Button IDs for "view" popup menu
enum {
BUTTON_POPUP_VIEW_FIND = 0,
BUTTON_POPUP_VIEW_LOCK,
BUTTON_POPUP_VIEW_DEEPLOCK,
BUTTON_POPUP_VIEW_UNLOCK
};
// Button IDs for "options" popup menu
enum {
BUTTON_POPUP_OPTIONS_CONFIG = 0
};
// Button IDs for "export" popup menu (in "file" popup menu)
enum {
BUTTON_POPUP_EXPORT_TEXT = 0,
BUTTON_POPUP_EXPORT_GPASMAN
#ifdef CONFIG_KWALLETIF
,BUTTON_POPUP_EXPORT_KWALLET
#endif
};
// Button IDs for "import" popup menu (in "file" popup menu)
enum {
BUTTON_POPUP_IMPORT_TEXT = 0,
BUTTON_POPUP_IMPORT_GPASMAN
#ifdef CONFIG_KWALLETIF
,BUTTON_POPUP_IMPORT_KWALLET
#endif
};
+
+#ifdef PWM_EMBEDDED
+// Button IDs for "help" popup menu
+enum {
+ BUTTON_POPUP_HELP_LICENSE = 0,
+ BUTTON_POPUP_HELP_FAQ,
+ BUTTON_POPUP_HELP_ABOUT
+};
+#endif
+
// Button IDs for toolbar
enum {
BUTTON_TOOL_NEW = 0,
BUTTON_TOOL_OPEN,
BUTTON_TOOL_SAVE,
BUTTON_TOOL_SAVEAS,
BUTTON_TOOL_PRINT,
BUTTON_TOOL_ADD,
BUTTON_TOOL_EDIT,
BUTTON_TOOL_DEL,
BUTTON_TOOL_FIND,
BUTTON_TOOL_LOCK,
BUTTON_TOOL_DEEPLOCK,
BUTTON_TOOL_UNLOCK
};
PwM::PwM(PwMInit *_init, PwMDoc *doc,
bool virginity,
QWidget *parent, const char *name)
: KMainWindow(parent, name)
, forceQuit (false)
, forceMinimizeToTray (false)
{
init = _init;
connect(doc, SIGNAL(docClosed(PwMDoc *)),
this, SLOT(docClosed(PwMDoc *)));
initMenubar();
initToolbar();
initMetrics();
setVirgin(virginity);
setFocusPolicy(QWidget::WheelFocus);
#ifndef PWM_EMBEDDED
statusBar()->show();
#endif
view = makeNewListView(doc);
setCentralWidget(view);
updateCaption();
showStatMsg(i18n("Ready."));
}
PwM::~PwM()
{
disconnect(curDoc(), SIGNAL(docClosed(PwMDoc *)),
this, SLOT(docClosed(PwMDoc *)));
conf()->confWndMainWndSize(size());
emit closed(this);
delete view;
}
void PwM::initMenubar()
{
+ KIconLoader* picons;
+#ifndef PWM_EMBEDDED
KIconLoader icons;
-
+ picons = &icons;
+#else
+ picons = KGlobal::iconLoader();
+#endif
filePopup = new KPopupMenu(this);
importPopup = new KPopupMenu(filePopup);
exportPopup = new KPopupMenu(filePopup);
managePopup = new KPopupMenu(this);
#ifdef CONFIG_KEYCARD
chipcardPopup = new KPopupMenu(this);
#endif // CONFIG_KEYCARD
viewPopup = new KPopupMenu(this);
optionsPopup = new KPopupMenu(this);
// "file" popup menu
- filePopup->insertItem(QIconSet(icons.loadIcon("filenew", KIcon::Small)),
+ filePopup->insertItem(QIconSet(picons->loadIcon("filenew", KIcon::Small)),
i18n("&New"), this,
SLOT(new_slot()), 0, BUTTON_POPUP_FILE_NEW);
- filePopup->insertItem(QIconSet(icons.loadIcon("fileopen", KIcon::Small)),
+ filePopup->insertItem(QIconSet(picons->loadIcon("fileopen", KIcon::Small)),
i18n("&Open"), this,
SLOT(open_slot()), 0, BUTTON_POPUP_FILE_OPEN);
- filePopup->insertItem(QIconSet(icons.loadIcon("fileclose", KIcon::Small)),
+ filePopup->insertItem(QIconSet(picons->loadIcon("fileclose", KIcon::Small)),
i18n("&Close"), this,
SLOT(close_slot()), 0, BUTTON_POPUP_FILE_CLOSE);
filePopup->insertSeparator();
- filePopup->insertItem(QIconSet(icons.loadIcon("filesave", KIcon::Small)),
+ filePopup->insertItem(QIconSet(picons->loadIcon("filesave", KIcon::Small)),
i18n("&Save"), this,
SLOT(save_slot()), 0, BUTTON_POPUP_FILE_SAVE);
- filePopup->insertItem(QIconSet(icons.loadIcon("filesaveas", KIcon::Small)),
+ filePopup->insertItem(QIconSet(picons->loadIcon("filesaveas", KIcon::Small)),
i18n("Save &as..."),
this, SLOT(saveAs_slot()), 0,
BUTTON_POPUP_FILE_SAVEAS);
filePopup->insertSeparator();
// "file/export" popup menu
exportPopup->insertItem(i18n("&Text-file..."), this,
SLOT(exportToText()), 0, BUTTON_POPUP_EXPORT_TEXT);
exportPopup->insertItem(i18n("&Gpasman / Kpasman ..."), this,
SLOT(exportToGpasman()), 0, BUTTON_POPUP_EXPORT_GPASMAN);
#ifdef CONFIG_KWALLETIF
exportPopup->insertItem(i18n("&KWallet..."), this,
SLOT(exportToKWallet()), 0, BUTTON_POPUP_EXPORT_KWALLET);
#endif
- filePopup->insertItem(QIconSet(icons.loadIcon("fileexport", KIcon::Small)),
+ filePopup->insertItem(QIconSet(picons->loadIcon("fileexport", KIcon::Small)),
i18n("E&xport"), exportPopup,
BUTTON_POPUP_FILE_EXPORT);
// "file/import" popup menu
importPopup->insertItem(i18n("&Text-file..."), this,
SLOT(importFromText()), 0, BUTTON_POPUP_IMPORT_TEXT);
importPopup->insertItem(i18n("&Gpasman / Kpasman ..."), this,
SLOT(importFromGpasman()), 0, BUTTON_POPUP_IMPORT_GPASMAN);
#ifdef CONFIG_KWALLETIF
importPopup->insertItem(i18n("&KWallet..."), this,
SLOT(importKWallet()), 0, BUTTON_POPUP_IMPORT_KWALLET);
#endif
- filePopup->insertItem(QIconSet(icons.loadIcon("fileimport", KIcon::Small)),
+ filePopup->insertItem(QIconSet(picons->loadIcon("fileimport", KIcon::Small)),
i18n("I&mport"), importPopup,
BUTTON_POPUP_FILE_IMPORT);
filePopup->insertSeparator();
- filePopup->insertItem(QIconSet(icons.loadIcon("fileprint", KIcon::Small)),
+ filePopup->insertItem(QIconSet(picons->loadIcon("fileprint", KIcon::Small)),
i18n("&Print..."), this,
SLOT(print_slot()), 0, BUTTON_POPUP_FILE_PRINT);
filePopup->insertSeparator();
- filePopup->insertItem(QIconSet(icons.loadIcon("exit", KIcon::Small)),
+ filePopup->insertItem(QIconSet(picons->loadIcon("exit", KIcon::Small)),
i18n("&Quit"), this,
SLOT(quitButton_slot()), 0, BUTTON_POPUP_FILE_QUIT);
menuBar()->insertItem(i18n("&File"), filePopup);
// "manage" popup menu
- managePopup->insertItem(QIconSet(icons.loadIcon("pencil", KIcon::Small)),
+ managePopup->insertItem(QIconSet(picons->loadIcon("pencil", KIcon::Small)),
i18n("&Add password"), this,
SLOT(addPwd_slot()), 0,
BUTTON_POPUP_MANAGE_ADD);
- managePopup->insertItem(QIconSet(icons.loadIcon("edit", KIcon::Small)),
+ managePopup->insertItem(QIconSet(picons->loadIcon("edit", KIcon::Small)),
i18n("&Edit"), this, SLOT(editPwd_slot()), 0,
BUTTON_POPUP_MANAGE_EDIT);
- managePopup->insertItem(QIconSet(icons.loadIcon("editdelete", KIcon::Small)),
+ managePopup->insertItem(QIconSet(picons->loadIcon("editdelete", KIcon::Small)),
i18n("&Delete"), this, SLOT(deletePwd_slot()),
0, BUTTON_POPUP_MANAGE_DEL);
managePopup->insertSeparator();
- managePopup->insertItem(QIconSet(icons.loadIcon("rotate", KIcon::Small)),
+ managePopup->insertItem(QIconSet(picons->loadIcon("rotate", KIcon::Small)),
i18n("Change &Master Password"), this,
SLOT(changeMasterPwd_slot()), 0,
BUTTON_POPUP_MANAGE_CHANGEMP);
menuBar()->insertItem(i18n("&Manage"), managePopup);
// "chipcard" popup menu
#ifdef CONFIG_KEYCARD
- chipcardPopup->insertItem(QIconSet(icons.loadIcon("filenew", KIcon::Small)),
+ chipcardPopup->insertItem(QIconSet(picons->loadIcon("filenew", KIcon::Small)),
i18n("&Generate new key-card"), this,
SLOT(genNewCard_slot()), 0,
BUTTON_POPUP_CHIPCARD_GENNEW);
- chipcardPopup->insertItem(QIconSet(icons.loadIcon("editdelete", KIcon::Small)),
+ chipcardPopup->insertItem(QIconSet(picons->loadIcon("editdelete", KIcon::Small)),
i18n("&Erase key-card"), this,
SLOT(eraseCard_slot()), 0,
BUTTON_POPUP_CHIPCARD_DEL);
- chipcardPopup->insertItem(QIconSet(icons.loadIcon("", KIcon::Small)),
+ chipcardPopup->insertItem(QIconSet(picons->loadIcon("", KIcon::Small)),
i18n("Read card-&ID"), this,
SLOT(readCardId_slot()), 0,
BUTTON_POPUP_CHIPCARD_READID);
chipcardPopup->insertSeparator();
- chipcardPopup->insertItem(QIconSet(icons.loadIcon("2rightarrow", KIcon::Small)),
+ chipcardPopup->insertItem(QIconSet(picons->loadIcon("2rightarrow", KIcon::Small)),
i18n("&Make card backup-image"), this,
SLOT(makeCardBackup_slot()), 0,
BUTTON_POPUP_CHIPCARD_SAVEBACKUP);
- chipcardPopup->insertItem(QIconSet(icons.loadIcon("2leftarrow", KIcon::Small)),
+ chipcardPopup->insertItem(QIconSet(picons->loadIcon("2leftarrow", KIcon::Small)),
i18n("&Replay card backup-image"), this,
SLOT(replayCardBackup_slot()), 0,
BUTTON_POPUP_CHIPCARD_REPLAYBACKUP);
menuBar()->insertItem(i18n("&Chipcard manager"), chipcardPopup);
#endif // CONFIG_KEYCARD
// "view" popup menu
- viewPopup->insertItem(QIconSet(icons.loadIcon("find", KIcon::Small)),
+ viewPopup->insertItem(QIconSet(picons->loadIcon("find", KIcon::Small)),
i18n("&Find"), this,
SLOT(find_slot()), 0, BUTTON_POPUP_VIEW_FIND);
viewPopup->insertSeparator();
- viewPopup->insertItem(QIconSet(icons.loadIcon("halfencrypted", KIcon::Small)),
+ viewPopup->insertItem(QIconSet(picons->loadIcon("halfencrypted", KIcon::Small)),
i18n("&Lock all entries"), this,
SLOT(lockWnd_slot()), 0,
BUTTON_POPUP_VIEW_LOCK);
- viewPopup->insertItem(QIconSet(icons.loadIcon("encrypted", KIcon::Small)),
+ viewPopup->insertItem(QIconSet(picons->loadIcon("encrypted", KIcon::Small)),
i18n("&Deep-lock all entries"), this,
SLOT(deepLockWnd_slot()), 0,
BUTTON_POPUP_VIEW_DEEPLOCK);
- viewPopup->insertItem(QIconSet(icons.loadIcon("decrypted", KIcon::Small)),
+ viewPopup->insertItem(QIconSet(picons->loadIcon("decrypted", KIcon::Small)),
i18n("&Unlock all entries"), this,
SLOT(unlockWnd_slot()), 0,
BUTTON_POPUP_VIEW_UNLOCK);
menuBar()->insertItem(i18n("&View"), viewPopup);
// "options" popup menu
- optionsPopup->insertItem(QIconSet(icons.loadIcon("configure", KIcon::Small)),
+ optionsPopup->insertItem(QIconSet(picons->loadIcon("configure", KIcon::Small)),
i18n("&Configure..."), this,
SLOT(config_slot()),
BUTTON_POPUP_OPTIONS_CONFIG);
menuBar()->insertItem(i18n("&Options"), optionsPopup);
// "help" popup menu
#ifndef PWM_EMBEDDED
helpPopup = helpMenu(QString::null, false);
- menuBar()->insertItem(i18n("&Help"), helpPopup);
+#else
+ helpPopup = new KPopupMenu(this);
+
+
+ helpPopup->insertItem(i18n("&License"), this,
+ SLOT(showLicense_slot()), 0,
+ BUTTON_POPUP_HELP_LICENSE);
+
+ helpPopup->insertItem(i18n("&Faq"), this,
+ SLOT(faq_slot()), 0,
+ BUTTON_POPUP_HELP_FAQ);
+
+ helpPopup->insertItem(i18n("&About PwManager"), this,
+ SLOT(createAboutData_slot()), 0,
+ BUTTON_POPUP_HELP_ABOUT);
+
#endif
+ menuBar()->insertItem(i18n("&Help"), helpPopup);
+
}
void PwM::initToolbar()
{
+ KIconLoader* picons;
+#ifndef PWM_EMBEDDED
KIconLoader icons;
+ picons = &icons;
+#else
+ picons = KGlobal::iconLoader();
+#endif
- toolBar()->insertButton(icons.loadIcon("filenew", KIcon::Toolbar),
+ toolBar()->insertButton(picons->loadIcon("filenew", KIcon::Toolbar),
BUTTON_TOOL_NEW, SIGNAL(clicked(int)), this,
SLOT(new_slot()), true, i18n("New"));
- toolBar()->insertButton(icons.loadIcon("fileopen", KIcon::Toolbar),
+ toolBar()->insertButton(picons->loadIcon("fileopen", KIcon::Toolbar),
BUTTON_TOOL_OPEN, SIGNAL(clicked(int)), this,
SLOT(open_slot()), true, i18n("Open"));
toolBar()->insertSeparator();
- toolBar()->insertButton(icons.loadIcon("filesave", KIcon::Toolbar),
+ toolBar()->insertButton(picons->loadIcon("filesave", KIcon::Toolbar),
BUTTON_TOOL_SAVE, SIGNAL(clicked(int)), this,
SLOT(save_slot()), true, i18n("Save"));
- toolBar()->insertButton(icons.loadIcon("filesaveas", KIcon::Toolbar),
+ toolBar()->insertButton(picons->loadIcon("filesaveas", KIcon::Toolbar),
BUTTON_TOOL_SAVEAS, SIGNAL(clicked(int)), this,
SLOT(saveAs_slot()), true, i18n("Save as"));
- toolBar()->insertButton(icons.loadIcon("fileprint", KIcon::Toolbar),
+ toolBar()->insertButton(picons->loadIcon("fileprint", KIcon::Toolbar),
BUTTON_TOOL_PRINT, SIGNAL(clicked(int)), this,
SLOT(print_slot()), true, i18n("Print..."));
toolBar()->insertSeparator();
- toolBar()->insertButton(icons.loadIcon("pencil", KIcon::Toolbar),
+ toolBar()->insertButton(picons->loadIcon("pencil", KIcon::Toolbar),
BUTTON_TOOL_ADD, SIGNAL(clicked(int)), this,
SLOT(addPwd_slot()), true,
i18n("Add password"));
- toolBar()->insertButton(icons.loadIcon("edit", KIcon::Toolbar),
+ toolBar()->insertButton(picons->loadIcon("edit", KIcon::Toolbar),
BUTTON_TOOL_EDIT, SIGNAL(clicked(int)), this,
SLOT(editPwd_slot()), true,
i18n("Edit password"));
- toolBar()->insertButton(icons.loadIcon("editdelete", KIcon::Toolbar),
+ toolBar()->insertButton(picons->loadIcon("editdelete", KIcon::Toolbar),
BUTTON_TOOL_DEL, SIGNAL(clicked(int)), this,
SLOT(deletePwd_slot()), true,
i18n("Delete password"));
toolBar()->insertSeparator();
- toolBar()->insertButton(icons.loadIcon("find", KIcon::Toolbar),
+ toolBar()->insertButton(picons->loadIcon("find", KIcon::Toolbar),
BUTTON_TOOL_FIND, SIGNAL(clicked(int)), this,
SLOT(find_slot()), true, i18n("Find entry"));
toolBar()->insertSeparator();
- toolBar()->insertButton(icons.loadIcon("halfencrypted", KIcon::Toolbar),
+ toolBar()->insertButton(picons->loadIcon("halfencrypted", KIcon::Toolbar),
BUTTON_TOOL_LOCK, SIGNAL(clicked(int)), this,
SLOT(lockWnd_slot()), true,
i18n("Lock all entries"));
- toolBar()->insertButton(icons.loadIcon("encrypted", KIcon::Toolbar),
+ toolBar()->insertButton(picons->loadIcon("encrypted", KIcon::Toolbar),
BUTTON_TOOL_DEEPLOCK, SIGNAL(clicked(int)), this,
SLOT(deepLockWnd_slot()), true,
i18n("Deep-Lock all entries"));
- toolBar()->insertButton(icons.loadIcon("decrypted", KIcon::Toolbar),
+ toolBar()->insertButton(picons->loadIcon("decrypted", KIcon::Toolbar),
BUTTON_TOOL_UNLOCK, SIGNAL(clicked(int)), this,
SLOT(unlockWnd_slot()), true,
i18n("Unlock all entries"));
}
void PwM::initMetrics()
{
QSize s = conf()->confWndMainWndSize();
if (s.isValid())
resize(s);
else
resize(DEFAULT_SIZE);
}
void PwM::updateCaption()
{
setPlainCaption(curDoc()->getTitle() + " - " PROG_NAME " " PACKAGE_VER);
}
void PwM::hideEvent(QHideEvent *)
{
if (isMinimized()) {
if (init->tray()) {
forceMinimizeToTray = true;
close();
}
int mmlock = conf()->confGlobMinimizeLock();
switch (mmlock) {
case 0: // don't lock anything
break;
case 1: { // normal lock
curDoc()->lockAll(true);
break;
} case 2: { // deep-lock
curDoc()->deepLock();
break;
} default:
WARN();
}
}
}
void PwM::setVirgin(bool v)
{
if (virgin == v)
return;
virgin = v;
filePopup->setItemEnabled(BUTTON_POPUP_FILE_SAVE, !v);
filePopup->setItemEnabled(BUTTON_POPUP_FILE_SAVEAS, !v);
filePopup->setItemEnabled(BUTTON_POPUP_FILE_EXPORT, !v);
filePopup->setItemEnabled(BUTTON_POPUP_FILE_PRINT, !v);
managePopup->setItemEnabled(BUTTON_POPUP_MANAGE_EDIT, !v);
managePopup->setItemEnabled(BUTTON_POPUP_MANAGE_DEL, !v);
managePopup->setItemEnabled(BUTTON_POPUP_MANAGE_CHANGEMP, !v);
viewPopup->setItemEnabled(BUTTON_POPUP_VIEW_LOCK, !v);
viewPopup->setItemEnabled(BUTTON_POPUP_VIEW_DEEPLOCK, !v);
viewPopup->setItemEnabled(BUTTON_POPUP_VIEW_UNLOCK, !v);
viewPopup->setItemEnabled(BUTTON_POPUP_VIEW_FIND, !v);
toolBar()->setItemEnabled(BUTTON_TOOL_SAVE, !v);
toolBar()->setItemEnabled(BUTTON_TOOL_SAVEAS, !v);
toolBar()->setItemEnabled(BUTTON_TOOL_PRINT, !v);
toolBar()->setItemEnabled(BUTTON_TOOL_EDIT, !v);
toolBar()->setItemEnabled(BUTTON_TOOL_DEL, !v);
toolBar()->setItemEnabled(BUTTON_TOOL_LOCK, !v);
@@ -475,129 +514,130 @@ void PwM::close_slot()
close();
}
void PwM::quitButton_slot()
{
init->shutdownApp(0);
}
void PwM::save_slot()
{
save();
}
bool PwM::save()
{
if (!curDoc()->saveDocUi(curDoc()))
return false;
showStatMsg(i18n("Successfully saved data."));
updateCaption();
return true;
}
void PwM::saveAs_slot()
{
saveAs();
}
bool PwM::saveAs()
{
if (!curDoc()->saveAsDocUi(curDoc()))
return false;
showStatMsg(i18n("Successfully saved data."));
updateCaption();
return true;
}
//US ENH : changed code to run with older MOC
void PwM::addPwd_slot()
{
addPwd_slot(0, 0);
}
void PwM::addPwd_slot(QString *pw, PwMDoc *_doc)
{
PwMDoc *doc;
if (_doc) {
doc = _doc;
} else {
doc = curDoc();
}
PWM_ASSERT(doc);
doc->timer()->getLock(DocTimer::id_autoLockTimer);
AddEntryWndImpl w;
vector<string> catList;
doc->getCategoryList(&catList);
unsigned i, size = catList.size();
for (i = 0; i < size; ++i) {
w.addCategory(catList[i].c_str());
}
w.setCurrCategory(view->getCurrentCategory());
if (pw)
w.pwLineEdit->setText(*pw);
tryAgain:
- if (w.exec() == 1) {
+ if (w.exec() == 1)
+ {
PwMDataItem d;
d.desc = w.getDescription().latin1();
d.name = w.getUsername().latin1();
d.pw = w.getPassword().latin1();
d.comment = w.getComment().latin1();
d.url = w.getUrl().latin1();
d.launcher = w.getLauncher().latin1();
PwMerror ret = doc->addEntry(w.getCategory(), &d);
if (ret == e_entryExists) {
KMessageBox::error(this,
i18n
("An entry with this \"Description\", "
"does already exist.\n"
"Please select another description."),
i18n("entry already exists."));
goto tryAgain;
} else if (ret == e_maxAllowedEntr) {
KMessageBox::error(this, i18n("The maximum possible number of entries "
"has been reached. You can't add more entries."),
i18n("maximum number of entries"));
doc->timer()->putLock(DocTimer::id_autoLockTimer);
return;
}
}
setVirgin(false);
doc->timer()->putLock(DocTimer::id_autoLockTimer);
}
//US ENH : changed code to run with older MOC
void PwM::editPwd_slot()
{
editPwd_slot(0,0,0);
}
void PwM::editPwd_slot(const QString *category)
{
editPwd_slot(category, 0, 0);
}
void PwM::editPwd_slot(const QString *category, const int *index,
PwMDoc *_doc)
{
PwMDoc *doc;
if (_doc) {
doc = _doc;
} else {
doc = curDoc();
}
PWM_ASSERT(doc);
if (doc->isDocEmpty())
return;
if (doc->isDeepLocked())
return;
doc->timer()->getLock(DocTimer::id_autoLockTimer);
unsigned int curEntryIndex;
if (index) {
curEntryIndex = *index;
} else {
if (!(view->getCurEntryIndex(&curEntryIndex))) {
printDebug("couldn't get index. Maybe we have a binary entry here.");
doc->timer()->putLock(DocTimer::id_autoLockTimer);
return;
}
}
@@ -1126,67 +1166,118 @@ void PwM::execLauncher_slot()
{
PWM_ASSERT(curDoc());
if (curDoc()->isDeepLocked())
return;
unsigned int curEntryIndex;
if (!view->getCurEntryIndex(&curEntryIndex))
return;
bool ret = curDoc()->execLauncher(view->getCurrentCategory(),
curEntryIndex);
if (ret)
showStatMsg(i18n("Executed the \"Launcher\"."));
else
showStatMsg(i18n("ERROR: Couldn't execute the \"Launcher\"!"));
}
void PwM::goToURL_slot()
{
PWM_ASSERT(curDoc());
if (curDoc()->isDeepLocked())
return;
unsigned int curEntryIndex;
if (!view->getCurEntryIndex(&curEntryIndex))
return;
bool ret = curDoc()->goToURL(view->getCurrentCategory(),
curEntryIndex);
if (ret)
showStatMsg(i18n("started browser with current URL."));
else
showStatMsg(i18n("ERROR: Couldn't start browser! Maybe invalid URL?"));
}
void PwM::copyToClipboard(const QString &s)
{
QClipboard *cb = QApplication::clipboard();
#ifndef PWM_EMBEDDED
if (cb->supportsSelection())
cb->setText(s, QClipboard::Selection);
cb->setText(s, QClipboard::Clipboard);
#else
cb->setText(s);
#endif
}
void PwM::showStatMsg(const QString &msg)
{
#ifndef PWM_EMBEDDED
KStatusBar *statBar = statusBar();
statBar->message(msg, STATUSBAR_MSG_TIMEOUT * 1000);
#else
qDebug("Statusbar : %s",msg.latin1());
#endif
}
void PwM::focusInEvent(QFocusEvent *e)
{
if (e->gotFocus()) {
emit gotFocus(this);
} else if (e->lostFocus()) {
emit lostFocus(this);
}
}
+
+#ifdef PWM_EMBEDDED
+
+void PwM::showLicense_slot()
+{
+ KApplication::showLicence();
+}
+
+void PwM::faq_slot()
+{
+ KApplication::showFile( "PWM/Pi FAQ", "kdepim/pwmanager/pwmanagerFAQ.txt" );
+}
+
+void PwM::createAboutData_slot()
+{
+ QString version;
+#include <../version>
+ QMessageBox::about( this, "About PwManager/Pi",
+ "PwManager/Platform-independent\n"
+ "(PWM/Pi) " +version + " - " +
+#ifdef DESKTOP_VERSION
+ "Desktop Edition\n"
+#else
+ "PDA-Edition\n"
+ "for: Zaurus 5500 / 7x0 / 8x0\n"
+#endif
+
+ "(c) 2004 Ulf Schenk\n"
+ "(c) 2004 Lutz Rogowski\n"
+ "(c) 1997-2003, The KDE PIM Team\n"
+
+ "Michael Buesch - main programming and current maintainer\nmbuesch@freenet.de\n"
+ "Matt Scifo - original implementaion of \n"
+ "\"categories\" and the password-tree \n"
+ "in the system-tray. Original implementations of \n"
+ "numerous view-improvements.\n"
+ "mscifo@o1.com\n"
+ "Elias Probst - Gentoo ebuild maintainer.\nelias.probst@gmx.de\n"
+ "George Staikos - KWallet\nstaikos@kde.org\n"
+ "Matthew Palmer - rc2 code\nmjp16@uow.edu.au\n"
+ "Olivier Sessink - gpasman\ngpasman@nl.linux.org\n"
+ "The libgcrypt developers - Blowfish and SHA1 algorithms\nftp://ftp.gnupg.org/gcrypt/alpha/libgcrypt/\n"
+ "Troy Engel - kpasman\n tengel@sonic.net\n"
+ "Wickey - graphics-design in older versions\nwickey@gmx.at\n"
+ "Ian MacGregor - original documentation author.\n"
+ );
+}
+
+#endif
+
+
#ifndef PWM_EMBEDDED
#include "pwm.moc"
#endif
diff --git a/pwmanager/pwmanager/pwm.h b/pwmanager/pwmanager/pwm.h
index 3a79e67..36a8b5b 100644
--- a/pwmanager/pwmanager/pwm.h
+++ b/pwmanager/pwmanager/pwm.h
@@ -105,128 +105,134 @@ public slots:
void open_slot(QString fn);
/** file/close triggered */
void close_slot();
/** file/quit triggered */
void quitButton_slot();
/** file/save triggered */
void save_slot();
/** file/saveAs triggered */
void saveAs_slot();
/** file/export/text triggered */
void exportToText();
/** file/export/gpasman triggered */
void exportToGpasman();
/** file/export/kwallet triggered */
void exportToKWallet();
/** file/import/text triggered */
bool importFromText();
/** file/import/gpasman triggered */
bool importFromGpasman();
/** file/import/kwallet triggered */
bool importKWallet();
/** file/print triggered */
void print_slot();
/** manage/add triggered */
//US ENH : changed code to run with older MOC
void addPwd_slot();
void addPwd_slot(QString *pw, PwMDoc *_doc);
/** manage/edit triggered */
//US ENH : changed code to run with older MOC
void editPwd_slot();
void editPwd_slot(const QString *category);
void editPwd_slot(const QString *category = 0, const int *index = 0,
PwMDoc *_doc = 0);
/** manage/delete triggered */
void deletePwd_slot();
/** execute the "Launcher" entry */
void execLauncher_slot();
/** open browser with URL entry */
void goToURL_slot();
/** manage/changeMasterPwd triggered */
void changeMasterPwd_slot();
/** lock current document */
void lockWnd_slot();
/** deeplock current document */
void deepLockWnd_slot();
/** window/unlock triggered */
void unlockWnd_slot();
/** find item */
void find_slot();
/** configure clicked */
void config_slot();
/** (de)activate the "change master pw" button in the menu-bar */
void activateMpButton(bool activate = true);
/** generate a new chipcard */
void genNewCard_slot();
/** completely erase the current card */
void eraseCard_slot();
/** returns the ID number of the current card */
void readCardId_slot();
/** make backup image of the current card */
void makeCardBackup_slot();
/** write backup image to current card */
void replayCardBackup_slot();
+#ifdef PWM_EMBEDDED
+ void showLicense_slot();
+ void faq_slot();
+ void createAboutData_slot();
+#endif
+
protected:
/** is this window virgin? */
bool isVirgin()
{ return virgin; }
/** add/remove virginity */
void setVirgin(bool v);
/** initialize the menubar */
void initMenubar();
/** initialize the toolbar */
void initToolbar();
/** initialize the window-metrics */
void initMetrics();
/** close-event */
void closeEvent(QCloseEvent *e);
/** creates a new PwM-ListView and returns it */
PwMView * makeNewListView(PwMDoc *doc);
/** Window hide-event */
void hideEvent(QHideEvent *);
/** is this window minimized? */
bool isMinimized()
{
#ifndef PWM_EMBEDDED
#if KDE_VERSION >= KDE_MAKE_VERSION(3, 2, 0)
return KWin::windowInfo(winId()).isMinimized();
#else // KDE_VERSION
return KWin::info(winId()).isIconified();
#endif // KDE_VERSION
#else
return false;
#endif
}
/** window got the focus */
void focusInEvent(QFocusEvent *e);
/** update the caption string */
void updateCaption();
#ifdef CONFIG_KWALLETIF
/** check if kwalletemu is enabled and ask the user what to do */
bool checkAndAskForKWalletEmu();
#endif // CONFIG_KWALLETIF
protected slots:
/** doc got closed */
void docClosed(PwMDoc *doc);
signals:
/** window got closed (by user or someone else) */
void closed(PwM *wnd);
/** window got the focus (was brought to foreground) */
void gotFocus(PwM *wnd);
/** window lost the focus */
void lostFocus(PwM *wnd);
protected:
/** pointer to the view active in this KMainWindow */
PwMView *view;
/** pointer to the init class */
PwMInit *init;
/** has this window already lost its virginity?
* Means is there an open working document
*/
bool virgin;
/** "file" popup-menu */
KPopupMenu *filePopup;
diff --git a/pwmanager/pwmanager/pwmdocui.cpp b/pwmanager/pwmanager/pwmdocui.cpp
index 66a1b59..b308b40 100644
--- a/pwmanager/pwmanager/pwmdocui.cpp
+++ b/pwmanager/pwmanager/pwmdocui.cpp
@@ -1,101 +1,102 @@
/***************************************************************************
* *
* 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
+#include <qdir.h>
#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
@@ -234,160 +235,176 @@ int PwMDocUi::dirtyAskSave(const QString &docTitle)
}
#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;
}
+#ifndef PWM_EMBEDDED
QString fn(KFileDialog::getSaveFileName(QString::null,
i18n("*.pwm|PwManager Password file"),
currentView));
+#else
+ QString fn = locateLocal( "data", KGlobal::getAppName() + "/*.pwm" );
+ fn = KFileDialog::getSaveFileName(fn,
+ i18n("password filename(*.pwm)"),
+ currentView);
+
+#endif
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())
+ {
+#ifndef PWM_EMBEDDED
filename = KFileDialog::getOpenFileName(QString::null,
i18n("*.pwm|PwManager Password file\n"
"*|All files"), getCurrentView());
+#else
+ filename = locateLocal( "data", KGlobal::getAppName() + "/*.pwm");
+ filename = KFileDialog::getOpenFileName(filename,
+ i18n("password filename(*.pwm)"), getCurrentView());
+#endif
+ }
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;