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
@@ -110,104 +110,105 @@ static void addAuthors(KAboutData *aboutData)
"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
@@ -493,270 +493,270 @@ void PwM::setVirgin(bool 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::
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
@@ -41,200 +41,202 @@
#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;
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,126 +1,131 @@
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 \
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
@@ -2236,194 +2236,194 @@ bool PwMDoc::execLauncher(unsigned int category, unsigned int entryIndex)
#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
@@ -2925,213 +2925,213 @@ void PwMDoc::ensureLvp()
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;
}
}
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,415 +1,423 @@
/***************************************************************************
* *
* 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(),
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
@@ -77,193 +77,197 @@
#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;
@@ -639,142 +643,142 @@ bool Serializer::writeMeta(QDomElement *e,
//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;
}