summaryrefslogtreecommitdiffabout
path: root/pwmanager
Side-by-side diff
Diffstat (limited to 'pwmanager') (more/less context) (show whitespace changes)
-rw-r--r--pwmanager/pwmanager/main.cpp1
-rw-r--r--pwmanager/pwmanager/pwm.cpp12
-rw-r--r--pwmanager/pwmanager/pwm.h8
-rw-r--r--pwmanager/pwmanager/pwmanager.pro33
-rw-r--r--pwmanager/pwmanager/pwmdoc.cpp8
-rw-r--r--pwmanager/pwmanager/pwminit.cpp16
-rw-r--r--pwmanager/pwmanager/serializer.cpp6
7 files changed, 52 insertions, 32 deletions
diff --git a/pwmanager/pwmanager/main.cpp b/pwmanager/pwmanager/main.cpp
index 3f2d055..9d1d863 100644
--- a/pwmanager/pwmanager/main.cpp
+++ b/pwmanager/pwmanager/main.cpp
@@ -14,200 +14,201 @@
* This file is originaly based on version 1.0.1 of pwmanager
* and was modified to run on embedded devices that run microkde
*
* $Id$
**************************************************************************/
#ifndef PWM_EMBEDDED
#include <kcmdlineargs.h>
#include <kaboutdata.h>
#else
#include <qdir.h>
#include <kpimglobalprefs.h>
#endif
#include <klocale.h>
#include <kstandarddirs.h>
#include "pwmexception.h"
#include "pwminit.h"
#define LICENSE_FILE (::locate("data", "pwmanager/pwmanager_license_text"))
int PwMApplication::newInstance()
{
static bool initial = true;
if (initial) {
initial = false;
init = new PwMInit(this);
init->initializeApp();
} else {
BUG_ON(!init);
printInfo("passing parameters to old instance.");
init->handleCmdLineArgs(false);
}
return EXIT_SUCCESS;
}
static const char *description = I18N_NOOP("PwManager\n"
"The convenient way of managing passwords");
#ifndef PWM_EMBEDDED
static KCmdLineOptions options[] =
{
{ "minimized", I18N_NOOP("Windows minimized"), 0 },
{ "mintray", I18N_NOOP("Windows minimized to tray"), 0 },
{ "open-deeplocked", I18N_NOOP("Open all \"files\" deeplocked"), 0 },
{ "skip-self-test", I18N_NOOP("Don't run a self-test on startup"), 0 },
{ "+[files...]", I18N_NOOP("Files to open on startup"), 0 },
{ 0, 0, 0 }
};
#endif
#ifdef PWM_DEBUG
static void printDebugConfigureInfo()
{
cout << "================================" << endl;
cout << PROG_NAME " version " PACKAGE_VER << endl;
#ifdef CONFIG_KEYCARD
cout << "CONFIG_KEYCARD: enabled" << endl;
#else
cout << "CONFIG_KEYCARD: disabled" << endl;
#endif
#ifdef CONFIG_KWALLETIF
cout << "CONFIG_KWALLETIF: enabled" << endl;
#else
cout << "CONFIG_KWALLETIF: disabled" << endl;
#endif
#ifdef BIG_ENDIAN_HOST
cout << "Endianess: big-endian" << endl;
#else
cout << "Endianess: little-endian" << endl;
#endif
cout << "sizeof(long): " << sizeof(long) << endl;
cout << "================================" << endl;
}
#else // PWM_DEBUG
static inline void printDebugConfigureInfo() { /* nothing */ }
#endif // PWM_DEBUG
#ifndef PWM_EMBEDDED
static void addAuthors(KAboutData *aboutData)
{
aboutData->addAuthor("Michael Buesch",
I18N_NOOP(
"main programming and current maintainer"),
"mbuesch@freenet.de");
aboutData->addAuthor("Matt Scifo",
I18N_NOOP(
"original implementaion of \n"
"\"categories\" and the password-tree \n"
"in the system-tray. Original implementations of \n"
"numerous view-improvements."),
"mscifo@o1.com");
aboutData->addCredit("Elias Probst",
I18N_NOOP(
"Gentoo ebuild maintainer."),
"elias.probst@gmx.de");
aboutData->addCredit("George Staikos",
I18N_NOOP("KWallet"),
"staikos@kde.org");
aboutData->addCredit("Matthew Palmer",
I18N_NOOP("rc2 code"),
"mjp16@uow.edu.au");
aboutData->addCredit("Olivier Sessink",
I18N_NOOP("gpasman"),
"gpasman@nl.linux.org");
aboutData->addCredit("The libgcrypt developers",
I18N_NOOP("Blowfish and SHA1 algorithms"),
0, "ftp://ftp.gnupg.org/gcrypt/alpha/libgcrypt/");
aboutData->addCredit("Troy Engel",
I18N_NOOP("kpasman"),
"tengel@sonic.net");
aboutData->addCredit("Wickey",
I18N_NOOP("graphics-design in older versions."),
"wickey@gmx.at");
aboutData->addCredit("Ian MacGregor",
I18N_NOOP(
"original documentation author."));
}
#endif
int main(int argc, char *argv[])
{
printDebugConfigureInfo();
#ifndef PWM_EMBEDDED
KAboutData aboutData(PACKAGE_NAME, PROG_NAME,
PACKAGE_VER, description, KAboutData::License_File,
"(c) 2003, 2004 Michael Buesch and the PwManager Team", 0,
"http://passwordmanager.sourceforge.net/",
"mbuesch@freenet.de");
addAuthors(&aboutData);
KCmdLineArgs::init(argc, argv, &aboutData);
KCmdLineArgs::addCmdLineOptions(options);
KUniqueApplication::addCmdLineOptions();
if (!KUniqueApplication::start()) {
printInfo("already running.");
return EXIT_SUCCESS;
}
PwMApplication a;
aboutData.setLicenseTextFile(LICENSE_FILE);
return a.exec();
#else
bool exitHelp = false;
if ( argc > 1 ) {
QString command = argv[1];
if ( command == "-help" ){
printf("PWM/PI command line commands:\n");
printf(" no command: Start PWM/PI in usual way\n");
printf(" -help: This output\n");
printf(" PWM/PI is exiting now. Bye!\n");
exitHelp = true;
}
}
if ( ! exitHelp ) {
PwMApplication a(argc, argv);
KGlobal::setAppName( "pwmanager" );
#ifndef DESKTOP_VERSION
//qDebug("width %d ",QApplication::desktop()->width() );
if ( QApplication::desktop()->width() > 320 )
KGlobal::iconLoader()->setIconPath(QString(getenv("QPEDIR"))+"/pics/kdepim/pwmanager/icons22/");
else
KGlobal::iconLoader()->setIconPath(QString(getenv("QPEDIR"))+"/pics/kdepim/pwmanager/icons16/");
#else
QString fileName ;
fileName = qApp->applicationDirPath () + "/kdepim/pwmanager/icons22/";
KGlobal::iconLoader()->setIconPath(QDir::convertSeparators(fileName));
QApplication::addLibraryPath ( qApp->applicationDirPath () );
#endif
KStandardDirs::setAppDir( QDir::convertSeparators(locateLocal("data", "pwmanager")));
KPimGlobalPrefs::instance()->setGlobalConfig();
a.newInstance();
//US KAddressBookMain m ;
//US QObject::connect(&a, SIGNAL (appMessage ( const QCString &, const QByteArray & )), ExternalAppHandler::instance(), SLOT (appMessage ( const QCString &, const QByteArray & )));
/*US
#ifndef DESKTOP_VERSION
a.showMainWidget( &m );
#else
a.setMainWidget( &m );
m.resize (640, 480 );
m.show();
#endif
*/
+ qDebug("exec ");
a.exec();
}
qDebug("PWMPI: Bye! ");
#endif
}
diff --git a/pwmanager/pwmanager/pwm.cpp b/pwmanager/pwmanager/pwm.cpp
index 26a44b1..c511661 100644
--- a/pwmanager/pwmanager/pwm.cpp
+++ b/pwmanager/pwmanager/pwm.cpp
@@ -397,462 +397,462 @@ void PwM::initToolbar()
}
toolBar()->insertButton(picons->loadIcon("filesave", KIcon::Toolbar),
BUTTON_TOOL_SAVE, SIGNAL(clicked(int)), this,
SLOT(save_slot()), true, i18n("Save"));
toolBar()->insertButton(picons->loadIcon("filesaveas", KIcon::Toolbar),
BUTTON_TOOL_SAVEAS, SIGNAL(clicked(int)), this,
SLOT(saveAs_slot()), true, i18n("Save as"));
toolBar()->insertButton(picons->loadIcon("fileprint", KIcon::Toolbar),
BUTTON_TOOL_PRINT, SIGNAL(clicked(int)), this,
SLOT(print_slot()), true, i18n("Print..."));
toolBar()->insertSeparator();
toolBar()->insertButton(picons->loadIcon("pencil", KIcon::Toolbar),
BUTTON_TOOL_ADD, SIGNAL(clicked(int)), this,
SLOT(addPwd_slot()), true,
i18n("Add password"));
toolBar()->insertButton(picons->loadIcon("edit", KIcon::Toolbar),
BUTTON_TOOL_EDIT, SIGNAL(clicked(int)), this,
SLOT(editPwd_slot()), true,
i18n("Edit password"));
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(picons->loadIcon("find", KIcon::Toolbar),
BUTTON_TOOL_FIND, SIGNAL(clicked(int)), this,
SLOT(find_slot()), true, i18n("Find entry"));
toolBar()->insertSeparator();
toolBar()->insertButton(picons->loadIcon("halfencrypted", KIcon::Toolbar),
BUTTON_TOOL_LOCK, SIGNAL(clicked(int)), this,
SLOT(lockWnd_slot()), true,
i18n("Lock all entries"));
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(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);
toolBar()->setItemEnabled(BUTTON_TOOL_DEEPLOCK, !v);
toolBar()->setItemEnabled(BUTTON_TOOL_UNLOCK, !v);
toolBar()->setItemEnabled(BUTTON_TOOL_FIND, !v);
}
void PwM::new_slot()
{
init->createMainWnd();
}
//US ENH
void PwM::open_slot()
{
open_slot("");
}
void PwM::open_slot(QString fn)
{
openDoc(fn);
}
PwMDoc * PwM::openDoc(QString filename, bool openDeepLocked)
{
if (!isVirgin()) {
// open the document in a new window.
PwM *newInstance = init->createMainWnd();
PwMDoc *newDoc = newInstance->openDoc(filename, openDeepLocked);
if (!newDoc) {
newInstance->setForceQuit(true);
delete_and_null(newInstance);
}
return newDoc;
}
if (!curDoc()->openDocUi(curDoc(), filename, openDeepLocked))
return 0;
showStatMsg(i18n("Successfully opened file."));
updateCaption();
setVirgin(false);
return curDoc();
}
PwMView * PwM::makeNewListView(PwMDoc *doc)
{
PwMView *ret = new PwMView(this, this, doc);
ret->setFont(conf()->confGlobEntryFont());
ret->show();
return ret;
}
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);
+ addPwd_slot1(0, 0);
}
-void PwM::addPwd_slot(QString *pw, PwMDoc *_doc)
+void PwM::addPwd_slot1(QString *pw, PwMDoc *_doc)
{
PwMDoc *doc;
if (_doc) {
doc = _doc;
} else {
doc = curDoc();
}
PWM_ASSERT(doc);
doc->timer()->getLock(DocTimer::id_autoLockTimer);
#ifndef PWM_EMBEDDED
AddEntryWndImpl w;
#else
AddEntryWndImpl w(this, "addentrywndimpl");
#endif
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)
{
PwMDataItem d;
//US BUG: to initialize all values of curEntr with meaningfulldata,
// we call clear on it. Reason: Metadata will be uninitialized otherwise.
// another option would be to create a constructor for PwMDataItem
d.clear(true);
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\",\n"
"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\nentries"
"has been reached.\nYou 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);
+ editPwd_slot3(0,0,0);
}
-void PwM::editPwd_slot(const QString *category)
+void PwM::editPwd_slot1(const QString *category)
{
- editPwd_slot(category, 0, 0);
+ editPwd_slot3(category, 0, 0);
}
-void PwM::editPwd_slot(const QString *category, const int *index,
+void PwM::editPwd_slot3(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;
}
}
QString curCategory;
if (category) {
curCategory = *category;
} else {
curCategory = view->getCurrentCategory();
}
PwMDataItem currItem;
if (!doc->getEntry(curCategory, curEntryIndex, &currItem, true)) {
doc->timer()->putLock(DocTimer::id_autoLockTimer);
return;
}
BUG_ON(currItem.binary);
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(curCategory);
w.setDescription(currItem.desc.c_str());
w.setUsername(currItem.name.c_str());
w.setPassword(currItem.pw.c_str());
w.setUrl(currItem.url.c_str());
w.setLauncher(currItem.launcher.c_str());
w.setComment(currItem.comment.c_str());
if (w.exec() == 1) {
currItem.desc = w.getDescription().latin1();
currItem.name = w.getUsername().latin1();
currItem.pw = w.getPassword().latin1();
currItem.comment = w.getComment().latin1();
currItem.url = w.getUrl().latin1();
currItem.launcher = w.getLauncher().latin1();
if (!doc->editEntry(curCategory, w.getCategory(),
curEntryIndex, &currItem)) {
KMessageBox::error(this,
i18n("Couldn't edit the entry.\n"
"Maybe you changed the category and "
"this entry is already present in the new "
"category?"),
i18n("couldn't edit entry."));
doc->timer()->putLock(DocTimer::id_autoLockTimer);
return;
}
}
doc->timer()->putLock(DocTimer::id_autoLockTimer);
}
void PwM::deletePwd_slot()
{
PWM_ASSERT(curDoc());
if (curDoc()->isDocEmpty())
return;
if (curDoc()->isDeepLocked())
return;
curDoc()->timer()->getLock(DocTimer::id_autoLockTimer);
unsigned int curEntryIndex = 0;
if (!(view->getCurEntryIndex(&curEntryIndex))) {
printDebug("couldn't get index");
curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
return;
}
PwMDataItem currItem;
QString curCategory = view->getCurrentCategory();
if (!curDoc()->getEntry(curCategory, curEntryIndex, &currItem)) {
printDebug("couldn't get entry");
curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
return;
}
if (KMessageBox::
questionYesNo(this,
i18n
("Do you really want to delete\nthe selected entry") +
" \n\"" + QString(currItem.desc.c_str())
+ "\" ?", i18n("delete?"))
== KMessageBox::Yes) {
curDoc()->delEntry(curCategory, curEntryIndex);
}
curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
}
void PwM::changeMasterPwd_slot()
{
PWM_ASSERT(curDoc());
curDoc()->changeCurrentPw();
}
void PwM::lockWnd_slot()
{
PWM_ASSERT(curDoc());
curDoc()->lockAll(true);
}
void PwM::deepLockWnd_slot()
{
PWM_ASSERT(curDoc());
curDoc()->deepLock();
}
void PwM::unlockWnd_slot()
{
PWM_ASSERT(curDoc());
curDoc()->lockAll(false);
}
void PwM::config_slot()
{
int oldStyle = conf()->confWndMainViewStyle();
#ifdef PWM_EMBEDDED
KCMultiDialog* ConfigureDialog = new KCMultiDialog( "PIM", this ,"pwmconfigdialog", true );
KCMPwmConfig* pwmcfg = new KCMPwmConfig( ConfigureDialog->getNewVBoxPage(i18n( "PwManager")) , "KCMPwmConfig" );
ConfigureDialog->addModule(pwmcfg );
KCMKdePimConfig* kdelibcfg = new KCMKdePimConfig( ConfigureDialog->getNewVBoxPage(i18n( "Global")) , "KCMKdeLibConfig" );
ConfigureDialog->addModule(kdelibcfg );
#ifndef DESKTOP_VERSION
ConfigureDialog->showMaximized();
#endif
if ( ConfigureDialog->exec() )
KMessageBox::information( this, i18n("Some changes are only\neffective after a restart!\n") );
delete ConfigureDialog;
#else //PWM_EMBEDDED
// display the configuration window (modal mode)
if (!conf()->showConfWnd(this))
return;
#endif
int newStyle = conf()->confWndMainViewStyle();
// reinitialize tray
init->initTray();
// reinitialize KWallet emulation
init->initKWalletEmu();
PwMDocList *_dl = PwMDoc::getOpenDocList();
const vector<PwMDocList::listItem> *dl = _dl->getList();
vector<PwMDocList::listItem>::const_iterator i = dl->begin(),
end = dl->end();
PwMDoc *doc;
while (i != end) {
doc = (*i).doc;
// unlock-without-mpw timeout
doc->timer()->start(DocTimer::id_mpwTimer);
// auto-lock timeout
doc->timer()->start(DocTimer::id_autoLockTimer);
++i;
}
const QValueList<PwM *> *ml = init->mainWndList();
#ifndef PWM_EMBEDDED
QValueList<PwM *>::const_iterator i2 = ml->begin(),
end2 = ml->end();
#else
QValueList<PwM *>::ConstIterator i2 = ml->begin(),
end2 = ml->end();
#endif
PwM *pwm;
while (i2 != end2) {
pwm = *i2;
// reinitialize the window style.
if (oldStyle != newStyle)
pwm->curView()->initStyle(newStyle);
// set the new font
diff --git a/pwmanager/pwmanager/pwm.h b/pwmanager/pwmanager/pwm.h
index fe1f7a1..116bc66 100644
--- a/pwmanager/pwmanager/pwm.h
+++ b/pwmanager/pwmanager/pwm.h
@@ -1,292 +1,294 @@
/***************************************************************************
* *
* 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$
**************************************************************************/
#ifndef __PWM_H
#define __PWM_H
#include <kpopupmenu.h>
#include <klistview.h>
#include <kmainwindow.h>
#ifndef PWM_EMBEDDED
#include <kwin.h>
#include <kapp.h>
#include <kdeversion.h>
#else
#include <ksyncmanager.h>
#endif
#include <kaction.h>
#include <qglobal.h>
#include "pwmview.h"
#include "pwmexception.h"
/** timeout for displaying a message on the status-bar (in seconds) */
#define STATUSBAR_MSG_TIMEOUT 5
class PwMInit;
class KSyncManager;
/** PwM is the base class of the project */
#ifndef PWM_EMBEDDED
//MOC_SKIP_BEGIN
class PwM : public KMainWindow
//MOC_SKIP_END
#else
class PwM : public KMainWindow, public KSyncInterface
#endif
{
Q_OBJECT
public:
friend class PwMView;
/** construtor */
PwM(PwMInit *_init, PwMDoc *doc,
bool virginity = true,
QWidget* parent = 0, const char *name = 0);
/** destructor */
~PwM();
/** copy some text to the global clipboard */
static void copyToClipboard(const QString &s);
/** returns pointer to the view */
PwMView * curView()
{ return view; }
/** returns pointer to the currently using document. */
PwMDoc * curDoc()
{ return curView()->document(); }
/** open a new doc with the given filename */
PwMDoc * openDoc(QString filename, bool openDeepLocked = false);
/** show a message on the global status bar.
* The message times out after some seconds.
*/
void showStatMsg(const QString &msg);
/** ask the user where to save the doc (if it has not been saved, yet)
* and write the data to disk.
*/
bool save();
/** ask the user where to save the doc
* and write the data to disk.
*/
bool saveAs();
/** force quit. Quit this window, always! Don't minimize it */
bool isForceQuit()
{ return forceQuit; }
/** set forceQuit */
void setForceQuit(bool force)
{ forceQuit = force; }
/** force minimize this window */
bool isForceMinimizeToTray()
{ return forceMinimizeToTray; }
/** set forceMinimizeToTray */
void setForceMinimizeToTray(bool force)
{ forceMinimizeToTray = force; }
public slots:
/** file/new triggered */
void new_slot();
/** file/open triggered */
//US ENH
void open_slot();
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);
+ void addPwd_slot1(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,
+ void editPwd_slot1(const QString *category);
+ void editPwd_slot3(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 whatsnew_slot();
void showLicense_slot();
void faq_slot();
void createAboutData_slot();
void syncHowTo_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;
/** "manage" popup-menu */
KPopupMenu *managePopup;
#ifdef CONFIG_KEYCARD
/** "chipcard" popup-menu */
KPopupMenu *chipcardPopup;
#endif // CONFIG_KEYCARD
/** "view" popup-menu */
KPopupMenu *viewPopup;
/** "options" popup-menu */
KPopupMenu *optionsPopup;
/** "help" popup-menu */
KPopupMenu *helpPopup;
/** "export" popup-menu */
KPopupMenu *exportPopup;
/** "import" popup-menu */
KPopupMenu *importPopup;
/** force quit this window? */
bool forceQuit;
/** force minimize this window to the tray */
bool forceMinimizeToTray;
private:
#ifdef PWM_EMBEDDED
//this are the overwritten callbackmethods from the syncinterface
virtual bool sync(KSyncManager* manager, QString filename, int mode);
// LR *******************************
// sync stuff!
QPopupMenu *syncPopup;
KSyncManager* syncManager;
#endif
};
#endif
diff --git a/pwmanager/pwmanager/pwmanager.pro b/pwmanager/pwmanager/pwmanager.pro
index 34f7403..7f39c76 100644
--- a/pwmanager/pwmanager/pwmanager.pro
+++ b/pwmanager/pwmanager/pwmanager.pro
@@ -1,168 +1,173 @@
TEMPLATE = app
CONFIG += qt warn_on
-
-
+DESTDIR= ../../bin
TARGET = pwmpi
-OBJECTS_DIR = obj/$(PLATFORM)
-MOC_DIR = moc/$(PLATFORM)
-DESTDIR=$(QPEDIR)/bin
+include( ../../variables.pri )
-INCLUDEPATH += . ../../ ../../qtcompat ../../qtcompat/xml ../../libkdepim ../../microkde ../../microkde/kdecore ../../microkde/kdeui ../../microkde/kutils $(QPEDIR)/include
+INCLUDEPATH += . ../../ ../../libkdepim ../../microkde ../../microkde/kdecore ../../microkde/kdeui ../../microkde/kutils
DEFINES += PWM_EMBEDDED CONFIG_PWMANAGER_GCRY DESKTOP_VERSION
#enable this setting if you want debugoutput for pwmanager
#DEFINES += CONFIG_DEBUG
-LIBS += -L../libcrypt/$(PLATFORM)
+LIBS += -L../libcrypt/
+LIBS += -L../../bin/
LIBS += -lmicrokde
-LIBS += -lmicroqtcompat
LIBS += -lmicrokdepim
-LIBS += -L$(QPEDIR)/lib
-LIBS += -lqpe
LIBS += -lzlib
-#LIBS += -lbz2
-#LIBS += -lkpmicrogcrypt
-LIBS += -ljpeg
-LIBS += $(QTOPIALIB)
LIBS += -lkpmicrocipher
LIBS += -lkpmicroerror
LIBS += -lkpmicrompi
LIBS += -lstdc++
+unix:{
+OBJECTS_DIR = obj/unix
+MOC_DIR = moc/unix
+
+}
+win32:{
+
+DEFINES += _WIN32_
+OBJECTS_DIR = obj/win
+MOC_DIR = moc/win
+QMAKE_LINK += /NODEFAULTLIB:LIBC
+
+}
+
#INTERFACES = \
#addentrywnd.ui \
#configwnd.ui \
#findwnd.ui \
#getmasterpwwnd.ui \
#pwgenwnd.ui \
#setmasterpwwnd.ui \
#subtbledit.ui
#INTERFACES = \
#subtbledit.ui \
#HEADERS = \
#configuration_31compat.h \
#configuration.h \
#configwnd.h \
#configwndimpl.h \
#selftest.h
#subtbledit.h \
#subtbleditimpl.h \
#compressbzip2.h \
HEADERS = \
addentrywnd_emb.h \
addentrywndimpl.h \
base64.h \
binentrygen.h \
blowfish.h \
commentbox.h \
compiler.h \
compressgzip.h \
findwnd_emb.h \
findwndimpl.h \
genpasswd.h \
getkeycardwnd.h \
getmasterpwwnd_emb.h \
getmasterpwwndimpl.h \
globalstuff.h \
gpasmanfile.h \
htmlgen.h \
htmlparse.h \
ipc.h \
libgcryptif.h \
listobjselectwnd.h \
listviewpwm.h \
printtext.h \
pwgenwnd_emb.h \
pwgenwndimpl.h \
pwmdoc.h \
pwmdocui.h \
pwmexception.h \
pwm.h \
pwminit.h \
pwmprefs.h \
pwmprint.h \
pwmtray.h \
pwmview.h \
pwmviewstyle_0.h \
pwmviewstyle_1.h \
pwmviewstyle.h \
randomizer.h \
rc2.h \
rencatwnd.h \
serializer.h \
setmasterpwwnd_emb.h \
setmasterpwwndimpl.h \
sha1.h \
waitwnd.h \
kcmconfigs/kcmpwmconfig.h \
kcmconfigs/pwmconfigwidget.h
#sources that need not be build
#SOURCES = \
#advcommeditimpl.cpp \
#configuration.cpp \
#configwnd.cpp \
#configwndimpl.cpp \
#configuration_31compat.cpp \
#htmlparse.cpp \
#printtext.cpp \
#selftest.cpp \
#pwmprint.cpp \
#spinforsignal.cpp
#subtbledit.cpp \
#subtbleditimpl.cpp \
#compressbzip2.cpp
SOURCES = \
addentrywnd_emb.cpp \
addentrywndimpl.cpp \
base64.cpp \
binentrygen.cpp \
blowfish.cpp \
commentbox.cpp \
compressgzip.cpp \
findwnd_emb.cpp \
findwndimpl.cpp \
genpasswd.cpp \
getkeycardwnd.cpp \
getmasterpwwnd_emb.cpp \
getmasterpwwndimpl.cpp \
globalstuff.cpp \
gpasmanfile.cpp \
htmlgen.cpp \
ipc.cpp \
libgcryptif.cpp \
listobjselectwnd.cpp \
listviewpwm.cpp \
main.cpp \
pwgenwnd_emb.cpp \
pwgenwndimpl.cpp \
pwm.cpp \
pwmdoc.cpp \
pwmdocui.cpp \
pwmexception.cpp \
pwminit.cpp \
pwmprefs.cpp \
pwmtray.cpp \
pwmview.cpp \
pwmviewstyle_0.cpp \
pwmviewstyle_1.cpp \
pwmviewstyle.cpp \
randomizer.cpp \
rc2.cpp \
rencatwnd.cpp \
serializer.cpp \
setmasterpwwnd_emb.cpp \
setmasterpwwndimpl.cpp \
sha1.cpp \
waitwnd.cpp \
kcmconfigs/kcmpwmconfig.cpp \
kcmconfigs/pwmconfigwidget.cpp
diff --git a/pwmanager/pwmanager/pwmdoc.cpp b/pwmanager/pwmanager/pwmdoc.cpp
index e29e3d1..8869f3a 100644
--- a/pwmanager/pwmanager/pwmdoc.cpp
+++ b/pwmanager/pwmanager/pwmdoc.cpp
@@ -2140,386 +2140,386 @@ void PwMDoc::getCategoryList(QStringList *list)
end = dti.dta.end();
while (i != end) {
#ifndef PWM_EMBEDDED
list->push_back(i->name.c_str());
#else
list->append(i->name.c_str());
#endif
++i;
}
}
void PwMDoc::getEntryList(const QString &category, QStringList *list)
{
PWM_ASSERT(list);
unsigned int cat = 0;
if (!findCategory(category, &cat)) {
list->clear();
return;
}
getEntryList(cat, list);
}
void PwMDoc::getEntryList(const QString &category, vector<string> *list)
{
PWM_ASSERT(list);
unsigned int cat = 0;
if (!findCategory(category, &cat)) {
list->clear();
return;
}
getEntryList(cat, list);
}
void PwMDoc::getEntryList(unsigned int category, vector<string> *list)
{
PWM_ASSERT(list);
list->clear();
vector<PwMDataItem>::iterator begin = dti.dta[category].d.begin(),
end = dti.dta[category].d.end(),
i = begin;
while (i != end) {
list->push_back(i->desc);
++i;
}
}
void PwMDoc::getEntryList(unsigned int category, QStringList *list)
{
PWM_ASSERT(list);
list->clear();
vector<PwMDataItem>::iterator begin = dti.dta[category].d.begin(),
end = dti.dta[category].d.end(),
i = begin;
while (i != end) {
#ifndef PWM_EMBEDDED
list->push_back(i->desc.c_str());
#else
list->append(i->desc.c_str());
#endif
++i;
}
}
bool PwMDoc::execLauncher(const QString &category, unsigned int entryIndex)
{
unsigned int cat = 0;
if (!findCategory(category, &cat))
return false;
return execLauncher(cat, entryIndex);
}
bool PwMDoc::execLauncher(unsigned int category, unsigned int entryIndex)
{
if (geteuid() == 0) {
rootAlertMsgBox();
return false;
}
QString command(dti.dta[category].d[entryIndex].launcher.c_str());
bool wasLocked = isLocked(category, entryIndex);
if (command.find("$p") != -1) {
/* the user requested the password to be included
* into the command. We have to ask for the password,
* if it's locked. We do that by unlocking the entry
*/
if (!lockAt(category, entryIndex, false))
return false;
}
#ifndef PWM_EMBEDDED
command.replace("$d", dti.dta[category].d[entryIndex].desc.c_str());
command.replace("$n", dti.dta[category].d[entryIndex].name.c_str());
command.replace("$p", dti.dta[category].d[entryIndex].pw.c_str());
command.replace("$u", dti.dta[category].d[entryIndex].url.c_str());
command.replace("$c", dti.dta[category].d[entryIndex].comment.c_str());
#else
command.replace(QRegExp("$d"), dti.dta[category].d[entryIndex].desc.c_str());
command.replace(QRegExp("$n"), dti.dta[category].d[entryIndex].name.c_str());
command.replace(QRegExp("$p"), dti.dta[category].d[entryIndex].pw.c_str());
command.replace(QRegExp("$u"), dti.dta[category].d[entryIndex].url.c_str());
command.replace(QRegExp("$c"), dti.dta[category].d[entryIndex].comment.c_str());
#endif
command.append(" &");
QString customXterm(conf()->confGlobXtermCommand());
if (!customXterm.isEmpty())
command = customXterm + " " + command;
system(command.latin1());
lockAt(category, entryIndex, wasLocked);
return true;
}
bool PwMDoc::goToURL(const QString &category, unsigned int entryIndex)
{
unsigned int cat = 0;
if (!findCategory(category, &cat))
return false;
return goToURL(cat, entryIndex);
}
bool PwMDoc::goToURL(unsigned int category, unsigned int entryIndex)
{
if (geteuid() == 0) {
rootAlertMsgBox();
return false;
}
QString url(dti.dta[category].d[entryIndex].url.c_str());
if (url.isEmpty())
return false;
QString customBrowser(conf()->confGlobBrowserCommand());
if (!customBrowser.isEmpty()) {
browserProc.clearArguments();
browserProc << customBrowser << url;
if (browserProc.start(KProcess::DontCare))
return true;
}
browserProc.clearArguments();
browserProc << "konqueror" << url;
if (browserProc.start(KProcess::DontCare))
return true;
browserProc.clearArguments();
browserProc << "mozilla" << url;
if (browserProc.start(KProcess::DontCare))
return true;
browserProc.clearArguments();
browserProc << "opera" << url;
if (browserProc.start(KProcess::DontCare))
return true;
return false;
}
PwMerror PwMDoc::exportToText(const QString *file)
{
PWM_ASSERT(file);
if (QFile::exists(*file)) {
if (!QFile::remove(*file))
return e_accessFile;
}
QFile f(*file);
if (!f.open(IO_ReadWrite))
return e_openFile;
if (!unlockAll_tempoary()) {
f.close();
return e_lock;
}
// write header
string header = i18n("Password table generated by\nPwM v").latin1();
header += PACKAGE_VER;
header += i18n("\non ").latin1();
QDate currDate = QDate::currentDate();
QTime currTime = QTime::currentTime();
#ifndef PWM_EMBEDDED
header += currDate.toString("ddd MMMM d ").latin1();
header += currTime.toString("hh:mm:ss ").latin1();
#else
QString dfs = KGlobal::locale()->dateFormatShort();
bool ampm = KGlobal::locale()->use12Clock();
KGlobal::locale()->setDateFormatShort("%A %B %d");
KGlobal::locale()->setHore24Format(true);
- header += KGlobal::locale()->formatDate(currDate, true, KLocale::Userdefined);
- header += KGlobal::locale()->formatTime(currTime, true);
+ header += KGlobal::locale()->formatDate(currDate, true, KLocale::Userdefined).latin1();
+ header += KGlobal::locale()->formatTime(currTime, true).latin1();
KGlobal::locale()->setDateFormatShort(dfs);
KGlobal::locale()->setHore24Format(!ampm);
#endif
header += tostr(currDate.year());
header += "\n==============================\n\n";
#ifndef PWM_EMBEDDED
if (f.writeBlock(header.c_str(), header.length()) != (Q_LONG)header.length()) {
unlockAll_tempoary(true);
f.close();
return e_writeFile;
}
#else
if (f.writeBlock(header.c_str(), header.length()) != (long)header.length()) {
unlockAll_tempoary(true);
f.close();
return e_writeFile;
}
#endif
unsigned int i, numCat = numCategories();
unsigned int j, numEnt;
string exp;
for (i = 0; i < numCat; ++i) {
numEnt = numEntries(i);
exp = "\n== Category: ";
exp += dti.dta[i].name;
exp += " ==\n";
#ifndef PWM_EMBEDDED
if (f.writeBlock(exp.c_str(), exp.length()) != (Q_LONG)exp.length()) {
unlockAll_tempoary(true);
f.close();
return e_writeFile;
}
#else
if (f.writeBlock(exp.c_str(), exp.length()) != (long)exp.length()) {
unlockAll_tempoary(true);
f.close();
return e_writeFile;
}
#endif
for (j = 0; j < numEnt; ++j) {
exp = "\n-- ";
exp += dti.dta[i].d[j].desc;
exp += " --\n";
exp += i18n("Username: ").latin1();
exp += dti.dta[i].d[j].name;
exp += "\n";
exp += i18n("Password: ").latin1();
exp += dti.dta[i].d[j].pw;
exp += "\n";
exp += i18n("Comment: ").latin1();
exp += dti.dta[i].d[j].comment;
exp += "\n";
exp += i18n("URL: ").latin1();
exp += dti.dta[i].d[j].url;
exp += "\n";
exp += i18n("Launcher: ").latin1();
exp += dti.dta[i].d[j].launcher;
exp += "\n";
#ifndef PWM_EMBEDDED
if (f.writeBlock(exp.c_str(), exp.length()) != (Q_LONG)exp.length()) {
unlockAll_tempoary(true);
f.close();
return e_writeFile;
}
#else
if (f.writeBlock(exp.c_str(), exp.length()) != (long)exp.length()) {
unlockAll_tempoary(true);
f.close();
return e_writeFile;
}
#endif
}
}
unlockAll_tempoary(true);
f.close();
return e_success;
}
PwMerror PwMDoc::importFromText(const QString *file, int format)
{
PWM_ASSERT(file);
if (format == 0)
return importText_PwM(file);
else if (format == -1) {
// probe for all formats
if (importText_PwM(file) == e_success)
return e_success;
dti.clear();
emitDataChanged(this);
// add next format here...
return e_fileFormat;
}
return e_invalidArg;
}
PwMerror PwMDoc::importText_PwM(const QString *file)
{
#ifndef PWM_EMBEDDED
PWM_ASSERT(file);
FILE *f;
int tmp;
ssize_t ret;
string curCat;
unsigned int entriesRead = 0;
PwMDataItem currItem;
f = fopen(file->latin1(), "r");
if (!f)
return e_openFile;
size_t ch_tmp_size = 1024;
char *ch_tmp = (char*)malloc(ch_tmp_size);
if (!ch_tmp) {
fclose(f);
return e_outOfMem;
}
// - check header
if (getline(&ch_tmp, &ch_tmp_size, f) == -1) // skip first line.
goto formatError;
// check version-string and return version in "ch_tmp".
if (fscanf(f, "PwM v%s", ch_tmp) != 1) {
// header not recognized as PwM generated header
goto formatError;
}
// set filepointer behind version-string-line previously checked
if (getline(&ch_tmp, &ch_tmp_size, f) == -1)
goto formatError;
// skip next line containing the build-date
if (getline(&ch_tmp, &ch_tmp_size, f) == -1)
goto formatError;
// read header termination line
if (getline(&ch_tmp, &ch_tmp_size, f) == -1)
goto formatError;
if (strcmp(ch_tmp, "==============================\n"))
goto formatError;
// - read entries
do {
// find beginning of next category
do {
tmp = fgetc(f);
} while (tmp == '\n' && tmp != EOF);
if (tmp == EOF)
break;
// decrement filepos by one
fseek(f, -1, SEEK_CUR);
// read cat-name
if (getline(&ch_tmp, &ch_tmp_size, f) == -1)
goto formatError;
// check cat-name format
if (memcmp(ch_tmp, "== Category: ", 13) != 0)
goto formatError;
if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " ==", 3) != 0)
goto formatError;
// copy cat-name
curCat.assign(ch_tmp + 13, strlen(ch_tmp) - 1 - 16);
do {
// find beginning of next entry
do {
tmp = fgetc(f);
} while (tmp == '\n' && tmp != EOF && tmp != '=');
if (tmp == EOF)
break;
if (tmp == '=') {
fseek(f, -1, SEEK_CUR);
break;
}
// decrement filepos by one
fseek(f, -1, SEEK_CUR);
// read desc-line
if (getline(&ch_tmp, &ch_tmp_size, f) == -1)
goto formatError;
// check desc-line format
if (memcmp(ch_tmp, "-- ", 3) != 0)
goto formatError;
if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " --", 3) != 0)
goto formatError;
// add desc-line
currItem.desc.assign(ch_tmp + 3, strlen(ch_tmp) - 1 - 6);
@@ -2829,405 +2829,405 @@ PwMerror PwMDoc::importFromGpasman(const QString *file)
tmpData.name = entry[1];
tmpData.pw = entry[2];
tmpData.comment = entry[3];
tmpData.lockStat = true;
tmpData.listViewPos = -1;
ret2 = addEntry(DEFAULT_CATEGORY, &tmpData, true);
for (i = 0; i < 4; ++i)
free(entry[i]);
if (ret2 == e_maxAllowedEntr) {
gp.load_finalize();
return e_maxAllowedEntr;
}
} while (1);
gp.load_finalize();
if (isDocEmpty())
return e_wrongPw; // we assume this.
flagDirty();
return e_success;
}
//US: we use the stl sort algorythm to sort all elements in the order
//of its listViewPos (in the order 1,2,3,5,...,x,-1, -1, -1
struct PwMDataItemListViewPosSort
{
bool operator()(PwMDataItem* rpStart, PwMDataItem* rpEnd)
{
//qDebug("pwMDoc::PwMDataItemListViewPosSort()");
if ((rpEnd)->listViewPos < 0)
return false;
else
return (rpStart)->listViewPos < (rpEnd)->listViewPos;
}
};
void PwMDoc::ensureLvp()
{
if (isDocEmpty())
return;
//US ENH BUG: when using syncronizing, this way of sorting
//is not sufficient, because there might be empty spaces
// at the beginning. But the old algorythm only can add elements
//to the end.The result are crashes because of list overflows
//we need something to fill all gaps.
vector<PwMDataItem*> sorted;
vector< PwMDataItem*>::iterator sortedBegin,
sortedEnd,
sortedI;
vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(),
catEnd = dti.dta.end(),
catI = catBegin;
vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI;
int lvpTop, tmpLvp;
//qDebug("collect:");
while (catI != catEnd) {
lvpTop = -1;
sorted.clear();
entrBegin = catI->d.begin();
entrEnd = catI->d.end();
entrI = entrBegin;
//US: we use the stl sort algorythm to sort all elements in the order
//of its listViewPos (in the order 1,2,2,3,5,...,x,-1, -1, -1
while (entrI != entrEnd) {
//qDebug("found: %s, pos=%i", (*entrI).desc.c_str(), (*entrI).listViewPos);
sorted.push_back((PwMDataItem*)&(*entrI));
++entrI;
}
sortedBegin = sorted.begin();
sortedEnd = sorted.end();
sort(sortedBegin, sortedEnd, PwMDataItemListViewPosSort());
// qDebug("resort:");
//now we have all sorted in a collection
//Now start with the sorted and reset listviewpos.
sortedBegin = sorted.begin();
sortedEnd = sorted.end();
sortedI = sortedBegin;
while (sortedI != sortedEnd) {
// qDebug("reset defined: %s, from pos=%i to pos=%i", (*sortedI)->desc.c_str(), (*sortedI)->listViewPos, lvpTop+1);
(*sortedI)->listViewPos = ++lvpTop;
++sortedI;
}
/*/debug
entrBegin = catI->d.begin();
entrEnd = catI->d.end();
entrI = entrBegin;
while (entrI != entrEnd) {
qDebug("check: %s, pos=%i", (*entrI).desc.c_str(), (*entrI).listViewPos);
++entrI;
}
*/
++catI;
}
}
QString PwMDoc::getTitle()
{
/* NOTE: We have to ensure, that the returned title
* is unique and not reused somewhere else while
* this document is valid (open).
*/
QString title(getFilename());
//US ENH: The whole filename on PDAs is too long. So use only the last characters
if (QApplication::desktop()->width() < 640)
{
if (title.length() > 30)
title = "..." + title.right(30);
}
if (title.isEmpty()) {
if (unnamedNum == 0) {
unnamedNum = PwMDocList::getNewUnnamedNumber();
PWM_ASSERT(unnamedNum != 0);
}
title = DEFAULT_TITLE;
title += " ";
title += tostr(unnamedNum).c_str();
}
return title;
}
bool PwMDoc::tryDelete()
{
if (deleted)
return true;
int ret;
if (isDirty()) {
ret = dirtyAskSave(getTitle());
if (ret == 0) { // save to disk
if (!saveDocUi(this))
goto out_ignore;
} else if (ret == 1) { // don't save and delete
goto out_accept;
} else { // cancel operation
goto out_ignore;
}
}
out_accept:
deleted = true;
delete this;
return true;
out_ignore:
return false;
}
#ifdef PWM_EMBEDDED
//US ENH: this is the magic function that syncronizes the this doc with the remote doc
//US it could have been defined as static, but I did not want to.
PwMerror PwMDoc::syncronize(KSyncManager* manager, PwMDoc* syncLocal , PwMDoc* syncRemote, int mode )
{
int addedPasswordsLocal = 0;
int addedPasswordsRemote = 0;
int deletedPasswordsRemote = 0;
int deletedPasswordsLocal = 0;
int changedLocal = 0;
int changedRemote = 0;
PwMSyncItem* syncItemLocal;
PwMSyncItem* syncItemRemote;
QString mCurrentSyncName = manager->getCurrentSyncName();
QString mCurrentSyncDevice = manager->getCurrentSyncDevice();
bool fullDateRange = false;
int take;
// local->resetTempSyncStat();
QDateTime mLastSync = QDateTime::currentDateTime();
QDateTime modifiedSync = mLastSync;
unsigned int index;
//Step 1. Find syncinfo in Local file and create if not existent.
bool found = syncLocal->findSyncData(mCurrentSyncDevice, &index);
if (found == false)
{
PwMSyncItem newSyncItemLocal;
- newSyncItemLocal.syncName = mCurrentSyncDevice;
+ newSyncItemLocal.syncName = mCurrentSyncDevice.latin1();
newSyncItemLocal.lastSyncDate = mLastSync;
syncLocal->addSyncDataEntry(&newSyncItemLocal, true);
found = syncLocal->findSyncData(mCurrentSyncDevice, &index);
if (found == false) {
qDebug("PwMDoc::syncronize : newly created local sync data could not be found");
return e_syncError;
}
}
syncItemLocal = syncLocal->getSyncDataEntry(index);
qDebug("Last Sync Local %s ", syncItemLocal->lastSyncDate.toString().latin1());
//Step 2. Find syncinfo in remote file and create if not existent.
found = syncRemote->findSyncData(mCurrentSyncName, &index);
if (found == false)
{
qDebug("FULLDATE 1");
fullDateRange = true;
PwMSyncItem newSyncItemRemote;
- newSyncItemRemote.syncName = mCurrentSyncName;
+ newSyncItemRemote.syncName = mCurrentSyncName.latin1();
newSyncItemRemote.lastSyncDate = mLastSync;
syncRemote->addSyncDataEntry(&newSyncItemRemote, true);
found = syncRemote->findSyncData(mCurrentSyncName, &index);
if (found == false) {
qDebug("PwMDoc::syncronize : newly created remote sync data could not be found");
return e_syncError;
}
}
syncItemRemote = syncRemote->getSyncDataEntry(index);
qDebug("Last Sync Remote %s ", syncItemRemote->lastSyncDate.toString().latin1());
//and remove the found entry here. We will reenter it later again.
//US syncRemote->delSyncDataEntry(index, true);
if ( syncItemLocal->lastSyncDate == mLastSync ) {
qDebug("FULLDATE 2");
fullDateRange = true;
}
if ( ! fullDateRange ) {
if ( syncItemLocal->lastSyncDate != syncItemRemote->lastSyncDate ) {
fullDateRange = true;
qDebug("FULLDATE 3 %s %s", syncItemLocal->lastSyncDate.toString().latin1() , syncItemRemote->lastSyncDate.toString().latin1() );
}
}
// fullDateRange = true; // debug only!
if ( fullDateRange )
mLastSync = QDateTime::currentDateTime().addDays( -100*365);
else
mLastSync = syncItemLocal->lastSyncDate;
qDebug("*************************** ");
qDebug("mLastSync %s ",mLastSync.toString().latin1() );
QStringList er = syncRemote->getIDEntryList();
PwMDataItem* inRemote ;//= er.first();
PwMDataItem* inLocal;
unsigned int catLocal, indexLocal;
unsigned int catRemote, indexRemote;
QString uid;
manager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count());
int modulo = (er.count()/10)+1;
unsigned int incCounter = 0;
while ( incCounter < er.count()) {
if (manager->isProgressBarCanceled())
return e_syncError;
if ( incCounter % modulo == 0 )
manager->showProgressBar(incCounter);
uid = er[ incCounter ];
qDebug("sync uid %s from remote file", uid.latin1());
qApp->processEvents();
inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal );
inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote );
PWM_ASSERT(inRemote);
if ( inLocal != 0 ) { // maybe conflict - same uid in both files
if ( (take = takePwMDataItem( inLocal, inRemote, mLastSync, mode, fullDateRange) ) ) {
qDebug("take %d %s ", take, inLocal->desc.c_str());
if ( take == 3 )
return e_syncError;
if ( take == 1 ) {// take local
int oldlistpos = inRemote->listViewPos;
(*inRemote) = (*inLocal);
inRemote->listViewPos = oldlistpos;
++changedRemote;
} else { // take == 2 take remote
int oldlistpos = inLocal->listViewPos;
(*inLocal) = (*inRemote);
inLocal->listViewPos = oldlistpos;
++changedLocal;
}
}
} else { // no conflict
if ( inRemote->meta.update > mLastSync || mode == 5 ) {
inRemote->meta.update = modifiedSync;
//first check if we have a matching category in the local file
const string* remotecat = syncRemote->getCategory(catRemote);
//US syncRemote->insertAddressee( inRemote, false );
//US syncLocal->insertAddressee( inRemote, false );
syncLocal->addEntry(remotecat->c_str(), inRemote, true, false);
++addedPasswordsLocal;
} else {
// pending checkExternSyncAddressee(addresseeRSyncSharp, inR);
syncRemote->delEntry(catRemote, indexRemote, true);
//USsyncRemote->removeAddressee( inRemote );
++deletedPasswordsRemote;
}
}
++incCounter;
}
er.clear();
QStringList el = syncLocal->getIDEntryList();
modulo = (el.count()/10)+1;
manager->showProgressBar(0, i18n("Add / remove addressees"), el.count());
incCounter = 0;
while ( incCounter < el.count()) {
qApp->processEvents();
if (manager->isProgressBarCanceled())
return e_syncError;
if ( incCounter % modulo == 0 )
manager->showProgressBar(incCounter);
uid = el[ incCounter ];
qDebug("sync uid %s from local file", uid.latin1());
inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal );
inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote );
PWM_ASSERT(inLocal);
if ( inRemote == 0 ) {
if ( inLocal->meta.update < mLastSync && mode != 4 ) {
// pending checkExternSyncAddressee(addresseeLSyncSharp, inL);
syncLocal->delEntry(catLocal, indexLocal, true);
//USsyncLocal->removeAddressee( inLocal );
++deletedPasswordsLocal;
} else {
if ( ! manager->mWriteBackExistingOnly ) {
++addedPasswordsRemote;
inLocal->meta.update = modifiedSync;
//first check if we have a matching category in the remote file
const string* localcat = syncLocal->getCategory(catLocal);
//USsyncLocal->insertAddressee( inLocal, false );
PwMDataItem newEntry;
newEntry = *inLocal;
inRemote = &newEntry;
//USsyncRemote->insertAddressee( inRemote, false );
syncRemote->addEntry(localcat->c_str(), inRemote, true, false);
}
}
}
++incCounter;
}
el.clear();
manager->hideProgressBar();
// Now write the info back into the sync data space of the files
mLastSync = QDateTime::currentDateTime().addSecs( 1 );
// get rid of micro seconds
QTime t = mLastSync.time();
mLastSync.setTime( QTime (t.hour (), t.minute (), t.second () ) );
syncItemLocal->lastSyncDate = mLastSync;
syncItemRemote->lastSyncDate = mLastSync;
QString mes;
mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n"),addedPasswordsLocal, addedPasswordsRemote, changedLocal, changedRemote, deletedPasswordsLocal, deletedPasswordsRemote );
if ( manager->mShowSyncSummary ) {
KMessageBox::information(0, mes, i18n("PWM/Pi Synchronization") );
}
qDebug( mes );
return e_success;
}
int PwMDoc::takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime lastSync, int mode , bool full )
{
// 0 equal
// 1 take local
// 2 take remote
// 3 cancel
QDateTime localMod = local->meta.update;
QDateTime remoteMod = remote->meta.update;
//US QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice();
if ( localMod == remoteMod )
return 0;
qDebug(" %d %d conflict on %s %s ", mode, full, local->desc.c_str(), remote->desc.c_str() );
//qDebug("%s %d %s %d", local->lastModified().toString().latin1() , localMod, remote->lastModified().toString().latin1(), remoteMod);
//qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() );
//full = true; //debug only
if ( full ) {
diff --git a/pwmanager/pwmanager/pwminit.cpp b/pwmanager/pwmanager/pwminit.cpp
index 8946443..ea9e330 100644
--- a/pwmanager/pwmanager/pwminit.cpp
+++ b/pwmanager/pwmanager/pwminit.cpp
@@ -1,511 +1,519 @@
/***************************************************************************
* *
* copyright (C) 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 "pwminit.h"
#include "randomizer.h"
+#include <qdir.h>
#ifndef PWM_EMBEDDED
#include "selftest.h"
#include "configuration.h"
#else
#include "pwmprefs.h"
#endif
#include "pwm.h"
#include "pwmexception.h"
#include "pwmtray.h"
#include "pwmdoc.h"
#ifdef CONFIG_KWALLETIF
# include "kwalletemu.h"
#endif // CONFIG_KWALLETIF
#ifdef CONFIG_KEYCARD
# include "pwmkeycard.h"
#endif // CONFIG_KEYCARD
#include <qmessagebox.h>
#include <kmessagebox.h>
#ifndef PWM_EMBEDDED
#include <kcmdlineargs.h>
#include <kwin.h>
#include <dcopclient.h>
#endif
#include <kapplication.h>
#include <kiconloader.h>
#include <signal.h>
static PwMInit *sig_init_pointer;
static NOREGPARM void sig_handler(int signum)
{
switch (signum) {
case SIGINT:
case SIGTERM:
sig_init_pointer->shutdownApp(20 + signum);
break;
default:
printDebug(string("unhandled signal ")
+ tostr(signum));
}
}
PwMInit::PwMInit(PwMApplication *_app)
: runStatus (unknown)
, _curWidget (0)
, _dcopClient (0)
, _kwalletEmu (0)
, _keycard (0)
, _tray (0)
{
sig_init_pointer = this;
app = _app;
}
PwMInit::~PwMInit()
{
#ifndef PWM_EMBEDDED
SelfTest::cancel();
// close all open mainwnds
QValueList<PwM *>::iterator i = _mainWndList.begin(),
end = _mainWndList.end();
#else
// close all open mainwnds
QValueList<PwM *>::Iterator i = _mainWndList.begin(),
end = _mainWndList.end();
#endif
while (i != end) {
disconnect(*i, SIGNAL(closed(PwM *)),
this, SLOT(mainWndClosed(PwM *)));
delete *i;
++i;
}
_mainWndList.clear();
// close all remaining open documents
PwMDocList *_dl = PwMDoc::getOpenDocList();
vector<PwMDocList::listItem> dl = *(_dl->getList());
vector<PwMDocList::listItem>::iterator i2 = dl.begin(),
end2 = dl.end();
while (i2 != end2) {
delete (*i2).doc;
++i2;
}
#ifdef CONFIG_KWALLETIF
delete_ifnot_null(_kwalletEmu);
#endif // CONFIG_KWALLETIF
#ifdef CONFIG_KEYCARD
delete_ifnot_null(_keycard);
#endif // CONFIG_KEYCARD
delete_ifnot_null(_tray);
Randomizer::cleanup();
#ifndef PWM_EMBEDDED
Configuration::cleanup();
#endif
}
void PwMInit::initializeApp()
{
+ qDebug("PwMInit::initializeApp() ");
PWM_ASSERT(runStatus == unknown);
runStatus = init;
initPosixSignalHandler();
Randomizer::init();
#ifndef PWM_EMBEDDED
Configuration::init();
#endif
initDCOP();
initKWalletEmu();
initKeycard();
initTray();
handleCmdLineArgs();
-
+ qDebug("handle ");
bool openDeeplocked = false;
if (conf()->confGlobAutostartDeepLocked() ||
savedCmd.open_deeplocked)
openDeeplocked = true;
- if (conf()->confWndAutoMinimizeOnStart() ||
- savedCmd.minToTray) {
+ if ( false ){
+ // LR is not working
+ //if (conf()->confWndAutoMinimizeOnStart() ||
+ // savedCmd.minToTray) {
PwMDoc *newDoc = createDoc();
+ qDebug(" createDoc()");
if (!newDoc->openDocUi(newDoc,
conf()->confGlobAutoStart(),
openDeeplocked)) {
delete newDoc;
+ }
//US ENH for embedded devices: in the case of failure, open a document the default way
createMainWnd(conf()->confGlobAutoStart(),
openDeeplocked,
true,
0,
savedCmd.minimized);
- }
+ // }
} else {
createMainWnd(conf()->confGlobAutoStart(),
openDeeplocked,
true,
0,
savedCmd.minimized);
}
runStatus = running;
}
void PwMInit::shutdownApp(int exitStatus)
{
printDebug(string("PwMInit::shutdownApp(")
+ tostr(exitStatus) + ") called.");
PWM_ASSERT((runStatus == running) || (runStatus == init));
runStatus = shutdown;
QApplication::exit(exitStatus);
/* The destructor of PwMInit is called when control
* leaves main()
*/
}
void PwMInit::initPosixSignalHandler()
{
signal(SIGINT, sig_handler);
signal(SIGTERM, sig_handler);
}
void PwMInit::initDCOP()
{
#ifndef PWM_EMBEDDED
_dcopClient = app->dcopClient();
_dcopClient->setNotifications(true);
#endif
}
void PwMInit::initKWalletEmu(bool forceDisable, bool forceReload)
{
#ifdef CONFIG_KWALLETIF
if (!conf()->confGlobKwalletEmu() ||
forceDisable) {
delete_ifnot_null(_kwalletEmu);
return;
}
try {
if (_kwalletEmu && forceReload)
delete_and_null(_kwalletEmu);
if (!_kwalletEmu)
_kwalletEmu = new KWalletEmu(this);
} catch (PwMException e) {
string errMsg("initializing KWallet emulation failed. ID: ");
errMsg += tostr(static_cast<int>(e.getId()));
errMsg += " err-message: ";
errMsg += e.getMessage();
printWarn(errMsg);
return;
}
#else // CONFIG_KWALLETIF
PARAM_UNUSED(forceDisable);
PARAM_UNUSED(forceReload);
#endif // CONFIG_KWALLETIF
}
void PwMInit::initKeycard()
{
#ifdef CONFIG_KEYCARD
PWM_ASSERT(!_keycard);
_keycard = new PwMKeyCard(this);
#endif // CONFIG_KEYCARD
}
void PwMInit::initTray()
{
#ifdef PWM_EMBEDDED
//US ENH : embedded version does not support a tray
return;
#endif
if (!conf()->confGlobTray()) {
if (!_tray)
return;
_tray->hide();
delete_and_null(_tray);
return;
}
if (_tray)
return;
_tray = new PwMTray(this);
connect(_tray, SIGNAL(quitSelected()),
this, SLOT(removeTrayAndQuit()));
connect(_tray, SIGNAL(closed(PwMTray *)),
this, SLOT(trayIconClosed(PwMTray *)));
KIconLoader icons;
#ifndef PWM_EMBEDDED
_tray->setPixmap(icons.loadIcon(PACKAGE_NAME, KIcon::Small));
#endif
_tray->show();
// connect the signals of all open documents.
const vector<PwMDocList::listItem> *dl = PwMDoc::getOpenDocList()->getList();
vector<PwMDocList::listItem>::const_iterator i = dl->begin(),
end = dl->end();
while (i != end) {
_tray->connectDocToTray((*i).doc);
++i;
}
}
void PwMInit::removeTrayAndQuit()
{
PWM_ASSERT(_tray);
// _tray is deleted in ~PwMInit
shutdownApp(0);
}
PwM * PwMInit::createMainWnd(const QString &loadFile,
bool loadFileDeepLocked,
bool virginity,
PwMDoc *doc,
bool minimized)
{
+ qDebug("PwMInit::createMainWnd ");
PwM *newWnd;
if (!doc)
doc = createDoc();
newWnd = new PwM(this, doc, virginity);
#ifndef PWM_EMBEDDED
_mainWndList.push_back(newWnd);
#else
_mainWndList.append(newWnd);
#endif
connect(newWnd, SIGNAL(closed(PwM *)),
this, SLOT(mainWndClosed(PwM *)));
connect(newWnd, SIGNAL(gotFocus(PwM *)),
this, SLOT(setCurWidget(PwM *)));
connect(newWnd, SIGNAL(lostFocus(PwM *)),
this, SLOT(resetCurWidget()));
//US ENH
#ifndef PWM_EMBEDDED
if (minimized)
newWnd->showMinimized();
else
newWnd->show();
#else //PWM_EMBEDDED
#ifndef DESKTOP_VERSION
app->showMainWidget( newWnd );
#else //DESKTOP_VERSION
app->setMainWidget( newWnd );
newWnd->resize (640, 480 );
newWnd->show();
+ qDebug("show ");
#endif //DESKTOP_VERSION
#endif //PWM_EMBEDDED
if (loadFile != QString::null &&
loadFile != "") {
newWnd->openDoc(loadFile, loadFileDeepLocked);
}
return newWnd;
}
PwMDoc * PwMInit::createDoc()
{
PwMDoc *doc = new PwMDoc(this);
#ifdef CONFIG_KEYCARD
doc->setPwMKeyCard(keycard());
#endif
#ifdef CONFIG_KWALLETIF
if (kwalletEmu())
kwalletEmu()->connectDocSignals(doc);
#endif
if (_tray)
_tray->connectDocToTray(doc);
return doc;
}
void PwMInit::mainWndClosed(PwM *wnd)
{
bool doMinimizeToTray = false;
bool doDeleteDoc = false;
#ifndef PWM_EMBEDDED
dcopClient()->suspend();
dcopClient()->setAcceptCalls(false);
#endif
again:
if (wnd->isForceMinimizeToTray()) {
if (unlikely(!_tray)) {
/* This should not happen! If we set forceMinimizeToTray ,
* we must be sure that _tray exists.
*/
BUG();
wnd->setForceMinimizeToTray(false);
goto again;
}
doMinimizeToTray = true;
} else {
// Ask to minimize to tray. If not, delete doc.
if (_tray &&
runStatus != shutdown &&
!wnd->isForceQuit() &&
!wnd->curDoc()->isDeleted()) {
if (conf()->confWndClose())
doDeleteDoc = true;
else
doMinimizeToTray = true;
} else {
doDeleteDoc = true;
}
}
if (doMinimizeToTray) {
PWM_ASSERT(_tray);
int mmlock = conf()->confGlobMinimizeLock();
switch (mmlock) {
case 0: // don't lock anything
break;
case 1: // normal lock
wnd->curDoc()->lockAll(true);
break;
case 2: // deep-lock
wnd->curDoc()->deepLock();
break;
default:
WARN();
}
} else if (doDeleteDoc) {
if (!wnd->curDoc()->tryDelete()) {
/* We failed deleting the doc,
* so open a new window with it, again.
*/
createMainWnd(QString::null, false,
false, wnd->curDoc());
}
}
#ifndef PWM_EMBEDDED
// find the closed window in the "mainWndList" and delete it.
QValueList<PwM *>::iterator i = _mainWndList.begin(),
end = _mainWndList.end();
#else
// find the closed window in the "mainWndList" and delete it.
QValueList<PwM *>::Iterator i = _mainWndList.begin(),
end = _mainWndList.end();
#endif
while (i != end) {
if (*i == wnd) {
#ifndef PWM_EMBEDDED
_mainWndList.erase(i);
#else
_mainWndList.remove(i);
#endif
goto out_success;
}
++i;
}
BUG();
out_success:
#ifndef PWM_EMBEDDED
if (!_mainWndList.size())
#else
if (!_mainWndList.count())
#endif
{
/* If there's no main window and no tray icon
* left, we have no user interface, so we can
* shut down the application.
*/
if (!_tray) {
#ifndef PWM_EMBEDDED
dcopClient()->setAcceptCalls(true);
dcopClient()->resume();
#endif
shutdownApp(0);
return;
}
/* There is no widget left, so set
* _curWidget to 0
*/
resetCurWidget();
}
#ifndef PWM_EMBEDDED
dcopClient()->setAcceptCalls(true);
dcopClient()->resume();
#endif
}
void PwMInit::trayIconClosed(PwMTray *tray)
{
if (runStatus != running)
return;
PARAM_UNUSED(tray);
PWM_ASSERT(tray == _tray);
/* If there's no main wnd left we have to
* shutdown the app (same as in mainWndClosed())
*/
#ifndef PWM_EMBEDDED
if (!_mainWndList.size())
shutdownApp(0);
#else
if (!_mainWndList.count())
shutdownApp(0);
#endif
}
void PwMInit::handleCmdLineArgs(bool initial)
{
#ifndef PWM_EMBEDDED
KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
PWM_ASSERT(args);
int i, numArgs = args->count();
const char *curArg;
// read all cmdline options
savedCmd.open_deeplocked = args->isSet("open-deeplocked");
savedCmd.minimized = args->isSet("minimized");
savedCmd.minToTray = args->isSet("mintray");
savedCmd.skipSelfTest = args->isSet("skip-self-test");
if (savedCmd.minimized &&
savedCmd.minToTray) {
printInfo(i18n("Commandline option \"--minimized\" and "
"\"--mintray\" selected. These are incompatible. "
"\"--mintray\" will be selected.").latin1());
}
/* Iterate through all non-option arguments.
* Every non-option arg is a filename to open.
*/
for (i = 0; i < numArgs; ++i) {
curArg = args->arg(i);
PWM_ASSERT(curArg);
if (savedCmd.minToTray) {
PwMDoc *newDoc = createDoc();
if (!newDoc->openDocUi(newDoc,
curArg,
savedCmd.open_deeplocked)) {
delete newDoc;
}
} else {
diff --git a/pwmanager/pwmanager/serializer.cpp b/pwmanager/pwmanager/serializer.cpp
index 2d6498e..ed0f754 100644
--- a/pwmanager/pwmanager/serializer.cpp
+++ b/pwmanager/pwmanager/serializer.cpp
@@ -1,365 +1,369 @@
/***************************************************************************
* *
* copyright (C) 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.1 of pwmanager
* and was modified to run on embedded devices that run microkde
*
* $Id$
**************************************************************************/
#include "serializer.h"
#include "pwmexception.h"
#ifdef PWM_EMBEDDED
#include <kglobal.h>
#include <klocale.h>
#endif
/* enable/disable serializer debugging (0/1) */
#define SERIALIZER_DEBUG 0
/* use the old xml tags for writing (0/1) */
#define USE_OLD_TAGS 0
/* write a CDATA section (0/1) */
#define WRITE_CDATA_SEC 0
#define META_CREATE_DATE "c"
#define META_VALID_DATE "v"
#define META_EXPIRE_DATE "e"
#define META_UPDATE_DATE "u"
#define META_UPDATE_INT "i"
//US ENH : uniqueid
#define META_UNIQUEID "n"
#define SYNC_ROOT "s"
#define SYNC_TARGET_PREFIX "t"
#define SYNC_TARGET_NAME "n"
/* This is compatibility stuff.
* The names of the entries have changed and here are the
* new and old ones
*/
#define ROOT_MAGIC_OLD "PwM-xml-dat"
#define VER_STR_OLD "ver"
#define COMPAT_VER_OLD "0x02"
#define CAT_ROOT_OLD "categories"
#define CAT_PREFIX_OLD "cat_"
#define CAT_NAME_OLD "name"
#define ENTRY_PREFIX_OLD "entry_"
#define ENTRY_DESC_OLD "desc"
#define ENTRY_NAME_OLD "name"
#define ENTRY_PW_OLD "pw"
#define ENTRY_COMMENT_OLD "comment"
#define ENTRY_URL_OLD "url"
#define ENTRY_LAUNCHER_OLD "launcher"
#define ENTRY_LVP_OLD "listViewPos"
#define ENTRY_BIN_OLD "b"
#define ENTRY_META_OLD "m"
#define ROOT_MAGIC_NEW "P"
#define VER_STR_NEW "v"
#define COMPAT_VER_NEW "2"
#define CAT_ROOT_NEW "c"
#define CAT_PREFIX_NEW "c"
#define CAT_NAME_NEW "n"
#define ENTRY_PREFIX_NEW "e"
#define ENTRY_DESC_NEW "d"
#define ENTRY_NAME_NEW "n"
#define ENTRY_PW_NEW "p"
#define ENTRY_COMMENT_NEW "c"
#define ENTRY_URL_NEW "u"
#define ENTRY_LAUNCHER_NEW "l"
#define ENTRY_LVP_NEW "v"
#define ENTRY_BIN_NEW ENTRY_BIN_OLD
#define ENTRY_META_NEW ENTRY_META_OLD
#if USE_OLD_TAGS != 0
# define ROOT_MAGIC_WR ROOT_MAGIC_OLD
# define VER_STR_WR VER_STR_OLD
# define COMPAT_VER_WR COMPAT_VER_OLD
# define CAT_ROOT_WR CAT_ROOT_OLD
# define CAT_PREFIX_WR CAT_PREFIX_OLD
# define CAT_NAME_WR CAT_NAME_OLD
# define ENTRY_PREFIX_WR ENTRY_PREFIX_OLD
# define ENTRY_DESC_WR ENTRY_DESC_OLD
# define ENTRY_NAME_WR ENTRY_NAME_OLD
# define ENTRY_PW_WR ENTRY_PW_OLD
# define ENTRY_COMMENT_WR ENTRY_COMMENT_OLD
# define ENTRY_URL_WR ENTRY_URL_OLD
# define ENTRY_LAUNCHER_WR ENTRY_LAUNCHER_OLD
# define ENTRY_LVP_WR ENTRY_LVP_OLD
# define ENTRY_BIN_WR ENTRY_BIN_OLD
# define ENTRY_META_WR ENTRY_META_OLD
#else
# define ROOT_MAGIC_WR ROOT_MAGIC_NEW
# define VER_STR_WR VER_STR_NEW
# define COMPAT_VER_WR COMPAT_VER_NEW
# define CAT_ROOT_WR CAT_ROOT_NEW
# define CAT_PREFIX_WR CAT_PREFIX_NEW
# define CAT_NAME_WR CAT_NAME_NEW
# define ENTRY_PREFIX_WR ENTRY_PREFIX_NEW
# define ENTRY_DESC_WR ENTRY_DESC_NEW
# define ENTRY_NAME_WR ENTRY_NAME_NEW
# define ENTRY_PW_WR ENTRY_PW_NEW
# define ENTRY_COMMENT_WR ENTRY_COMMENT_NEW
# define ENTRY_URL_WR ENTRY_URL_NEW
# define ENTRY_LAUNCHER_WR ENTRY_LAUNCHER_NEW
# define ENTRY_LVP_WR ENTRY_LVP_NEW
# define ENTRY_BIN_WR ENTRY_BIN_NEW
# define ENTRY_META_WR ENTRY_META_NEW
#endif
Serializer::Serializer()
{
defaultLockStat = true;
//US BUG: I needed to specify a document name. Otherwise impl will not be created for serializing
#ifndef PWM_EMBEDDED
domDoc = new QDomDocument;
#else
domDoc = new QDomDocument("mydoc");
#endif
}
Serializer::Serializer(const QCString &buffer)
{
defaultLockStat = true;
//US BUG: I needed to specify a document name. Otherwise impl will not be created for serializing
#ifndef PWM_EMBEDDED
domDoc = new QDomDocument;
#else
domDoc = new QDomDocument("mydoc");
#endif
if (!parseXml(buffer)) {
delete domDoc;
#ifndef PWM_EMBEDDED
throw PwMException(PwMException::EX_PARSE);
#else
qDebug("Serializer::Serializer : Parse Exception ");
#endif
}
}
Serializer::~Serializer()
{
delete_ifnot_null(domDoc);
}
void Serializer::clear()
{
delete_ifnot_null(domDoc);
domDoc = new QDomDocument;
}
bool Serializer::parseXml(const QCString &buffer)
{
PWM_ASSERT(domDoc);
#ifndef PWM_EMBEDDED
if (!domDoc->setContent(buffer, true))
return false;
#else
+#ifdef DESKTOP_VERSION
+ if (!domDoc->setContent(buffer, true))
+#else
if (!domDoc->setContent(buffer))
+#endif
return false;
#endif
if (!checkValid())
return false;
return true;
}
QCString Serializer::getXml()
{
PWM_ASSERT(domDoc);
#ifndef PWM_EMBEDDED
#if defined(PWM_DEBUG) && SERIALIZER_DEBUG != 0
QCString tmp(domDoc->toCString(8));
printDebug("<BEGIN Serializer::getXml() dump>\n");
cout << tmp << endl;
printDebug("<END Serializer::getXml() dump>");
#endif // DEBUG
QCString ret(domDoc->toCString(0));
ret.replace('\n', "");
return ret;
#else
#if defined(PWM_DEBUG) && SERIALIZER_DEBUG != 0
QCString tmp(" " + domDoc->toCString());
printDebug("<BEGIN Serializer::getXml() dump>\n");
qDebug(tmp);
cout << tmp << endl;
printDebug("<END Serializer::getXml() dump>");
#endif // DEBUG
QCString ret(domDoc->toCString());
ret.replace(QRegExp("\n"), "");
return ret;
#endif
}
bool Serializer::serialize(PwMItem &dta)
{
PWM_ASSERT(domDoc);
QDomElement root(genNewRoot());
QDomElement catNode(domDoc->createElement(CAT_ROOT_WR));
QDomElement syncNode(domDoc->createElement(SYNC_ROOT));
if (!addSyncData(&syncNode, dta.syncDta))
return false;
root.appendChild(syncNode);
if (!addCategories(&catNode, dta.dta))
return false;
root.appendChild(catNode);
return true;
}
bool Serializer::deSerialize(PwMItem *dta)
{
PWM_ASSERT(domDoc);
PWM_ASSERT(dta);
QDomElement root(domDoc->documentElement());
QDomNode n;
dta->clear();
for (n = root.firstChild(); !n.isNull(); n = n.nextSibling()) {
// find <categories> ... </categories>
// <c> ... </c>
if (n.nodeName() == CAT_ROOT_NEW ||
n.nodeName() == CAT_ROOT_OLD) {
if (!readCategories(n, &(dta->dta))) {
return false;
}
continue;
}
else if (n.nodeName() == SYNC_ROOT) {
if (!readSyncData(n, &(dta->syncDta))) {
return false;
}
continue;
}
/* NOTE: We can stop processing here, as we
* don't have more nodes in root, yet.
*/
return false;
}
return true;
}
bool Serializer::readCategories(const QDomNode &n,
vector<PwMCategoryItem> *dta)
{
QDomNodeList nl(n.childNodes());
QDomNode cur;
QString name;
unsigned int numCat = nl.count(), i;
PwMCategoryItem curCat;
vector<PwMDataItem> curEntr;
if (!numCat) {
printDebug("Serializer::readCategories(): empty");
return false;
}
for (i = 0; i < numCat; ++i) {
cur = nl.item(i);
if (cur.nodeName().left(1) == CAT_PREFIX_NEW ||
cur.nodeName().left(4) == CAT_PREFIX_OLD) {
name = cur.toElement().attribute(CAT_NAME_NEW);
if (name == QString::null)
name = cur.toElement().attribute(CAT_NAME_OLD);
PWM_ASSERT(name != QString::null);
PWM_ASSERT(name != "");
curCat.clear();
curCat.name = name.latin1();
if (!readEntries(cur, &curEntr)) {
dta->clear();
return false;
}
curCat.d = curEntr;
dta->push_back(curCat);
} else {
printDebug("Serializer::readCategories(): uh? not a category?");
}
}
return true;
}
bool Serializer::readEntries(const QDomNode &n,
vector<PwMDataItem> *dta)
{
QDomNodeList nl(n.childNodes());
QDomNode cur;
unsigned int numEntr = nl.count(), i;
PwMDataItem curEntr;
//US BUG: to initialize all values of curEntr with meaningfulldata,
// we call clear on it. Reason: Information in the file we will read might be incomplete.
// e.g. the metadata is missing.
curEntr.clear(true);
dta->clear();
for (i = 0; i < numEntr; ++i) {
cur = nl.item(i);
if (cur.nodeName().left(1) == ENTRY_PREFIX_NEW ||
cur.nodeName().left(6) == ENTRY_PREFIX_OLD) {
if (!extractEntry(cur, &curEntr)) {
return false;
}
dta->push_back(curEntr);
} else {
printDebug("Serializer::readEntries(): hm? not an entry?");
}
}
return true;
}
bool Serializer::extractEntry(const QDomNode &n,
PwMDataItem *dta)
{
QDomNodeList nl(n.childNodes());
QDomNode cur, cdata;
unsigned int cnt = nl.count(), i;
QString name, text;
if (!cnt) {
printDebug("Serializer::extractEntry(): empty");
return false;
}
dta->clear();
for (i = 0; i < cnt; ++i) {
cur = nl.item(i);
name = cur.nodeName();
cdata = cur.firstChild();
if (unlikely(cdata.isCDATASection())) {
text = cdata.toCDATASection().data();
} else if (likely(cur.isElement())) {
text = cur.toElement().text();
} else {
printDebug("Serializer::extractEntry(): neither CDATA nor element.");
return false;
}
if (text == " ")
text = ""; // for backward compatibility.
if (name == ENTRY_DESC_NEW ||
name == ENTRY_DESC_OLD) {
dta->desc = unescapeEntryData(text).latin1();
} else if (name == ENTRY_NAME_NEW ||
name == ENTRY_NAME_OLD) {
dta->name = unescapeEntryData(text).latin1();
} else if (name == ENTRY_PW_NEW ||
name == ENTRY_PW_OLD) {
dta->pw = unescapeEntryData(text).latin1();
} else if (name == ENTRY_COMMENT_NEW ||
name == ENTRY_COMMENT_OLD) {
@@ -543,238 +547,238 @@ bool Serializer::writeEntry(QDomElement *e,
dta.name = " ";
if (!dta.pw.size())
dta.pw = " ";
if (!dta.comment.size())
dta.comment = " ";
if (!dta.url.size())
dta.url = " ";
if (!dta.launcher.size())
dta.launcher = " ";
// end -- This is for compatibility with the old serializer
tag = domDoc->createElement(ENTRY_DESC_WR);
curText = new_text(escapeEntryData(dta.desc.c_str()));
tag.appendChild(curText);
e->appendChild(tag);
tag = domDoc->createElement(ENTRY_NAME_WR);
curText = new_text(escapeEntryData(dta.name.c_str()));
tag.appendChild(curText);
e->appendChild(tag);
tag = domDoc->createElement(ENTRY_PW_WR);
curText = new_text(escapeEntryData(dta.pw.c_str()));
tag.appendChild(curText);
e->appendChild(tag);
tag = domDoc->createElement(ENTRY_COMMENT_WR);
curText = new_text(escapeEntryData(dta.comment.c_str()));
tag.appendChild(curText);
e->appendChild(tag);
tag = domDoc->createElement(ENTRY_URL_WR);
curText = new_text(escapeEntryData(dta.url.c_str()));
tag.appendChild(curText);
e->appendChild(tag);
tag = domDoc->createElement(ENTRY_LAUNCHER_WR);
curText = new_text(escapeEntryData(dta.launcher.c_str()));
tag.appendChild(curText);
e->appendChild(tag);
tag = domDoc->createElement(ENTRY_LVP_WR);
plainText = domDoc->createTextNode(tostr(dta.listViewPos).c_str());
tag.appendChild(plainText);
e->appendChild(tag);
tag = domDoc->createElement(ENTRY_BIN_WR);
if (dta.binary)
plainText = domDoc->createTextNode("1");
else
plainText = domDoc->createTextNode("0");
tag.appendChild(plainText);
e->appendChild(tag);
tag = domDoc->createElement(ENTRY_META_WR);
if (!writeMeta(&tag, dta.meta))
return false;
e->appendChild(tag);
#undef new_text
return true;
}
bool Serializer::writeMeta(QDomElement *e,
const PwMMetaData &dta)
{
QDomText text;
QDomElement tag;
//US BUG!!!: The transformation of an empty date into an ISO date is different on different systems/compilers.
//So do not transform an empty value at all.
if (dta.create.isValid())
{
tag = domDoc->createElement(META_CREATE_DATE);
#ifndef PWM_EMBEDDED
text = domDoc->createTextNode(dta.create.toString(Qt::ISODate));
#else
text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.create, KLocale::ISODate));
#endif
tag.appendChild(text);
e->appendChild(tag);
}
//US BUG!!!: The transformation of an empty date into an ISO date is different on different systems/compilers.
//So do not transform an empty value at all.
if (dta.valid.isValid())
{
tag = domDoc->createElement(META_VALID_DATE);
#ifndef PWM_EMBEDDED
text = domDoc->createTextNode(dta.valid.toString(Qt::ISODate));
#else
text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.valid, KLocale::ISODate));
#endif
tag.appendChild(text);
e->appendChild(tag);
}
//US BUG!!!: The transformation of an empty date into an ISO date is different on different systems/compilers.
//So do not transform an empty value at all.
if (dta.expire.isValid())
{
tag = domDoc->createElement(META_EXPIRE_DATE);
#ifndef PWM_EMBEDDED
text = domDoc->createTextNode(dta.expire.toString(Qt::ISODate));
#else
text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.expire, KLocale::ISODate));
#endif
tag.appendChild(text);
e->appendChild(tag);
}
//US BUG!!!: The transformation of an empty date into an ISO date is different on different systems/compilers.
//So do not transform an empty value at all.
if (dta.update.isValid())
{
tag = domDoc->createElement(META_UPDATE_DATE);
#ifndef PWM_EMBEDDED
text = domDoc->createTextNode(dta.update.toString(Qt::ISODate));
#else
text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.update, KLocale::ISODate));
#endif
tag.appendChild(text);
e->appendChild(tag);
}
tag = domDoc->createElement(META_UPDATE_INT);
text = domDoc->createTextNode(tostr(dta.updateInt).c_str());
tag.appendChild(text);
e->appendChild(tag);
tag = domDoc->createElement(META_UNIQUEID);
text = domDoc->createTextNode(escapeEntryData(dta.uniqueid.c_str()));
tag.appendChild(text);
e->appendChild(tag);
#undef new_text
return true;
}
QString Serializer::escapeEntryData(QString dta)
{
#ifndef PWM_EMBEDDED
dta.replace('\n', "$>--endl--<$");
dta.replace("]]>", "||>");
#else
dta.replace(QRegExp("\n"), "$>--endl--<$");
dta.replace(QRegExp("]]>"), "||>");
#endif
return dta;
}
QString Serializer::unescapeEntryData(QString dta)
{
#ifndef PWM_EMBEDDED
dta.replace("$>--endl--<$", "\n");
dta.replace("||>", "]]>");
#else
dta.replace(QRegExp("\\$>--endl--<\\$"), "\n");
dta.replace(QRegExp("||>"), "]]>");
#endif
return dta;
}
//US ENH: the following methods are getting used to write/read sync entries
/** read the syncentries in the node "n" */
bool Serializer::readSyncData(const QDomNode &n, vector<PwMSyncItem> *dta)
{
QDomNodeList nl(n.childNodes());
QDomNode cur;
QString devicename, val;
unsigned int numSync = nl.count(), i;
PwMSyncItem curSync;
bool ok = true;
if (!numSync) {
//no sync entries is a possible result
printDebug("Serializer::readSyncData(): empty");
return true;
}
for (i = 0; i < numSync; ++i) {
cur = nl.item(i);
if (cur.nodeName().left(1) == SYNC_TARGET_PREFIX) {
devicename = cur.toElement().attribute(SYNC_TARGET_NAME);
val = cur.toElement().text();
if ((val == "") || (devicename == QString::null)) {
printDebug("Serializer::readSyncData(): empty synctarget name or syncdate");
continue;
}
- curSync.syncName = devicename;
+ curSync.syncName = devicename.latin1();
#ifndef PWM_EMBEDDED
curSync.lastSyncDate = QDateTime::fromString(val, Qt::ISODate);
#else
curSync.lastSyncDate = KGlobal::locale()->readDateTime(val, KLocale::ISODate, &ok);
if (ok == false)
qDebug("Serializer::readSyncData(): could not parse syncdate:%s",val.latin1());
#endif
dta->push_back(curSync);
}
}
return true;
}
bool Serializer::addSyncData(QDomElement *e,
const vector<PwMSyncItem> &dta)
{
unsigned int numSync = dta.size(), i;
QString curId, curDeviceName;
QDomElement curSync;
QDomText text;
for (i = 0; i < numSync; ++i) {
curId = SYNC_TARGET_PREFIX;
curId += tostr(i).c_str();
curDeviceName = dta[i].syncName.c_str();
curSync = domDoc->createElement(curId);
curSync.setAttribute(SYNC_TARGET_NAME, curDeviceName);
#ifndef PWM_EMBEDDED
text = domDoc->createTextNode(dta[i].lastSyncDate.toString(Qt::ISODate));
#else
text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta[i].lastSyncDate, KLocale::ISODate));
#endif
curSync.appendChild(text);
e->appendChild(curSync);
}
return true;
}