summaryrefslogtreecommitdiffabout
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--Makefile613
-rw-r--r--microkde/kdeui/kmainwindow.cpp1
-rw-r--r--microkde/kdeui/kmainwindow.h5
-rw-r--r--pwmanager/pwmanager/getmasterpwwnd_emb.cpp2
-rw-r--r--pwmanager/pwmanager/kcmconfigs/pwmconfigwidget.cpp4
-rw-r--r--pwmanager/pwmanager/libgcryptif.cpp5
-rw-r--r--pwmanager/pwmanager/main.cpp1
-rw-r--r--pwmanager/pwmanager/pwm.cpp10
-rw-r--r--pwmanager/pwmanager/pwmdoc.cpp1
-rw-r--r--pwmanager/pwmanager/pwmdocui.cpp15
-rw-r--r--pwmanager/pwmanager/pwminit.cpp17
11 files changed, 296 insertions, 378 deletions
diff --git a/Makefile b/Makefile
index da5feba..19e1685 100644
--- a/Makefile
+++ b/Makefile
@@ -1,362 +1,253 @@
-export KDEPIMDIR = $(shell pwd)
-
-export KDEPIM_VERSION=$(shell sed -e 's/.*\"\([0-9]*\.[0-9]*\.[0-9]*\).*/\1/' < version)
-
-ifeq ($(PLATFORM) , zaurus)
- BUILD_NO_LDAP_PLUGIN=1
-endif
-
-ifneq ($(PLATFORM) , zaurus)
- BUILD_NO_SHARP_PLUGIN=1
-endif
-
-SUBDIRS_MICROKDE = \
- libical/src/libical \
- libical/src/libicalss \
- qtcompat \
- microkde \
- libkcal \
- libkdepim \
- kabc \
- kabc/formats/binary \
- kabc/plugins/file \
- kabc/plugins/dir \
- korganizer \
- kalarmd \
- kaddressbook
-
-SUBDIRS_QTOPIA_PLUGIN = \
- kabc/plugins/qtopia
-
-SUBDIRS_OPIE_PLUGIN = \
- kabc/plugins/opie
-
-SUBDIRS_SHARP_PLUGIN = \
- kabc/plugins/sharpdtm
-
-SUBDIRS_LDAP_PLUGIN = \
- kabc/plugins/ldap
-
-SUBDIRS_MICROMAIL = \
- kmicromail/libetpan \
- kmicromail/libmailwrapper \
- kmicromail
-
-SUBDIRS_GAMMU = \
- gammu/emb/common \
- gammu/emb/gammu
-
-SUBDIRS_PWMANAGER = \
- pwmanager/libcrypt/mpi \
- pwmanager/libcrypt/error \
- pwmanager/libcrypt/cipher \
- pwmanager/libcrypt/zlib \
- pwmanager/pwmanager
-
-SUBDIRS = \
- $(SUBDIRS_MICROKDE) \
- $(SUBDIRS_QTOPIA_PLUGIN) \
- $(SUBDIRS_OPIE_PLUGIN) \
- $(SUBDIRS_SHARP_PLUGIN) \
- $(SUBDIRS_LDAP_PLUGIN) \
- $(SUBDIRS_MICROMAIL) \
- $(SUBDIRS_GAMMU) \
- $(SUBDIRS_PWMANAGER)
-
-
-all: build_microkde \
- build_qtopia_plugin \
- build_opie_plugin \
- build_sharp_plugin \
- build_ldap_plugin \
- build_micromail \
- build_gammu \
- build_pwmanager
-
-
-build_microkde: variable_test tmake
- for i in $(SUBDIRS_MICROKDE); do pushd $$i; \
- make -f Makefile$(PLATFORM) || exit 1; popd; \
- done
-
-build_qtopia_plugin: build_microkde
- ifdef BUILD_NO_QTOPIA_PLUGIN
- @echo == qtopia plugin not build.
- else
- for i in $(SUBDIRS_QTOPIA_PLUGIN); do pushd $$i; \
- make -f Makefile$(PLATFORM) || exit 1; popd; \
- done
- endif
-
-build_opie_plugin: build_microkde
- ifdef BUILD_NO_OPIE_PLUGIN
- @echo == opie plugin not build.
- else
- for i in $(SUBDIRS_OPIE_PLUGIN); do pushd $$i; \
- make -f Makefile$(PLATFORM) || exit 1; popd; \
- done
- endif
-
-build_sharp_plugin: build_microkde
- ifdef BUILD_NO_SHARP_PLUGIN
- @echo == ldap plugin not build.
- else
- for i in $(SUBDIRS_SHARP_PLUGIN); do pushd $$i; \
- make -f Makefile$(PLATFORM) || exit 1; popd; \
- done
- endif
-
-build_ldap_plugin: build_microkde
- ifdef BUILD_NO_LDAP_PLUGIN
- @echo == ldap plugin not build.
- else
- for i in $(SUBDIRS_LDAP_PLUGIN); do pushd $$i; \
- make -f Makefile$(PLATFORM) || exit 1; popd; \
- done
- endif
-
-
-build_micromail: build_microkde
- ifdef BUILD_NO_MICROMAIL
- @echo == kmicromail not build.
- else
- for i in $(SUBDIRS_MICROMAIL); do pushd $$i; \
- make -f Makefile$(PLATFORM) || exit 1; popd; \
- done
- endif
-
-build_gammu: variable_test tmake
- ifdef BUILD_NO_GAMMU
- @echo == gammu not build.
- else
- for i in $(SUBDIRS_GAMMU); do pushd $$i; \
- make -f Makefile$(PLATFORM) || exit 1; popd; \
- done
- endif
-
-build_pwmanager: build_microkde
- ifdef BUILD_NO_PWMANAGER
- @echo == pwmanager not build.
- else
- for i in $(SUBDIRS_PWMANAGER); do pushd $$i; \
- make -f Makefile$(PLATFORM) || exit 1; popd; \
- done
- endif
-
-
-variable_info:
- @echo --------------------------------------
- @echo KDEPIM buildsystem, variableinfo...
- @echo KDEPIMDIR=$(KDEPIMDIR)
- @echo QTDIR=$(QTDIR)
- @echo QPEDIR=$(QPEDIR)
- @echo OPIEDIR=$(OPIEDIR)
- @echo PLATFORM=$(PLATFORM)
- @echo RELEASE_DEBUG=$(RELEASE_DEBUG)
- @echo BUILD_NO_MICROMAIL=$(BUILD_NO_MICROMAIL)
- @echo BUILD_NO_LDAP_PLUGIN=$(BUILD_NO_LDAP_PLUGIN)
- @echo BUILD_NO_OPIE_PLUGIN=$(BUILD_NO_OPIE_PLUGIN)
- @echo BUILD_NO_QTOPIA_PLUGIN=$(BUILD_NO_QTOPIA_PLUGIN)
- @echo BUILD_NO_SHARP_PLUGIN=$(BUILD_NO_SHARP_PLUGIN)
- ifndef BUILD_NO_SHARP_PLUGIN
- @echo SHARPDTMSDK=$(SHARPDTMSDK)
- endif
- @echo BUILD_NO_GAMMU=$(BUILD_NO_GAMMU)
- @echo BUILD_NO_PWMANAGER=$(BUILD_NO_PWMANAGER)
- @echo --------------------------------------
-
-variable_test: variable_info
- @echo KDEPIM buildsystem, variablecheck...
- ifndef KDEPIMDIR
- @echo KDEPIMDIR is not defined.
- $(error KDEPIMDIR is not defined)
- endif
- ifndef PLATFORM
- @echo PLATFORM is not defined.
- $(error PLATFORM is not defined)
- endif
- ifdef BUILD_NO_LDAP_PLUGIN
- @echo LDAP PLUGIN will not be build, because BUILD_NO_LDAP_PLUGIN is set to $(BUILD_NO_LDAP_PLUGIN)
- endif
- ifdef BUILD_NO_OPIE_PLUGIN
- @echo OPIE PLUGIN will not be build, because BUILD_NO_OPIE_PLUGIN is set to $(BUILD_NO_OPIE_PLUGIN)
- endif
- ifdef BUILD_NO_QTOPIA_PLUGIN
- @echo QTOPIA PLUGIN will not be build, because BUILD_NO__QTOPIA_PLUGIN is set to $(BUILD_NO__QTOPIA_PLUGIN)
- endif
- ifdef BUILD_NO_MICROMAIL
- @echo MICROMAIL will not be build, because BUILD_NO_MICROMAIL is set to $(BUILD_NO_MICROMAIL)
- endif
- ifdef BUILD_NO_SHARP_PLUGIN
- @echo SHARP PLUGIN will not be build, because BUILD_NO_SHARP_PLUGIN is set to $(BUILD_NO_SHARP_PLUGIN)
- else
- ifndef SHARPDTMSDK
- @echo SHARP PLUGIN can not be build, because SHARPDTMSDK is set to $(SHARPDTMSDK)
- $(error SHARPDTMSDK is not defined)
- endif
- endif
- ifdef BUILD_NO_GAMMU
- @echo GAMMU will not be build, because BUILD_NO_GAMMU is set to $(BUILD_NO_GAMMU)
- endif
- ifdef BUILD_NO_PWMANAGER
- @echo PWMANAGER will not be build, because BUILD_NO_PWMANAGER is set to $(BUILD_NO_PWMANAGER)
- endif
- @echo --------------------------------------
-
-
-objects:
- for i in $(SUBDIRS); do mkdir -p $$i/obj/$(PLATFORM); done
- for i in $(SUBDIRS); do mkdir -p $$i/moc/$(PLATFORM); done
- mkdir -p libical/lib/$(PLATFORM)
- mkdir -p pwmanager/libcrypt/$(PLATFORM)
-
-clean:
- rm -rf libical/lib/$(PLATFORM)/*;
- rm -rf pwmanager/libcrypt/$(PLATFORM)/*;
- for i in $(SUBDIRS); do pushd $$i; make clean; rm -f *~;\
- rm -f obj/$(PLATFORM)/*; rm -f moc/$(PLATFORM)/*; rm Makefile$(PLATFORM); popd; \
- done
-
-install:
-
- cd bin/kdepim; make install
- cp -r Pim $(QPEDIR)/apps
- cp db2file/db2file $(QPEDIR)/bin/db2file
- cp korganizer/korganizer.desktop $(QPEDIR)/apps/Pim/korganizer.desktop
- cp kaddressbook/kaddressbook.desktop $(QPEDIR)/apps/Pim/kaddressbook.desktop
- cp kmicromail/kmicromail.desktop $(QPEDIR)/apps/Pim/kopiemail.desktop
- cp pwmanager/pwmanager/pwmanager.desktop $(QPEDIR)/apps/Pim/pwmanager.desktop
-
-dist:
- @echo Dont forget to do "make install" before "make dist"
- rm -f *arm.ipk
- rm -f *~
- cd ..; tar czf kdepimpi-$(KDEPIM_VERSION).tar.gz --exclude=obj --exclude=moc --exclude=CVS --exclude=Makefilezaurus --exclude=Makefileqtopia kdepim
- mkipks kmicrokdelibs.control
- mkipks korganizer.control
- mkipks kaddressbook.control
- ifndef BUILD_NO_MICROMAIL
- mkipks kopiemail.control
- endif
- mkipks korganizer-alarm.control
- ifndef BUILD_NO_GAMMU
- mkipks phoneaccess.control
- endif
- ifndef BUILD_NO_PWMANAGER
- mkipks pwmanager.control
- endif
- mkipks pim_TAB_icon.control
-
-tmake: objects \
- qtcompat/Makefile$(PLATFORM) \
- microkde/Makefile$(PLATFORM) \
- libkcal/Makefile$(PLATFORM) \
- libkdepim/Makefile$(PLATFORM) \
- korganizer/Makefile$(PLATFORM) \
- kalarmd/Makefile$(PLATFORM) \
- libical/src/libical/Makefile$(PLATFORM) \
- libical/src/libicalss/Makefile$(PLATFORM) \
- kabc/Makefile$(PLATFORM) \
- kabc/formats/binary/Makefile$(PLATFORM) \
- kabc/plugins/file/Makefile$(PLATFORM) \
- kabc/plugins/dir/Makefile$(PLATFORM) \
- kabc/plugins/ldap/Makefile$(PLATFORM) \
- kabc/plugins/opie/Makefile$(PLATFORM) \
- kabc/plugins/qtopia/Makefile$(PLATFORM) \
- kabc/plugins/sharpdtm/Makefile$(PLATFORM) \
- kaddressbook/Makefile$(PLATFORM) \
- kmicromail/Makefile$(PLATFORM) \
- kmicromail/libetpan/Makefile$(PLATFORM) \
- kmicromail/libmailwrapper/Makefile$(PLATFORM) \
- gammu/emb/common/Makefile$(PLATFORM) \
- gammu/emb/gammu/Makefile$(PLATFORM) \
- pwmanager/pwmanager/Makefile$(PLATFORM) \
- pwmanager/libcrypt/mpi/Makefile$(PLATFORM) \
- pwmanager/libcrypt/error/Makefile$(PLATFORM) \
- pwmanager/libcrypt/cipher/Makefile$(PLATFORM) \
- pwmanager/libcrypt/zlib/Makefile$(PLATFORM)
-
-qtcompat/Makefile$(PLATFORM): qtcompat/qtcompat.pro
- cd qtcompat; tmake "CONFIG+=$(RELEASE_DEBUG)" "VERSION=$(KDEPIM_VERSION)" qtcompat.pro -o Makefile$(PLATFORM)
-
-microkde/Makefile$(PLATFORM): microkde/microkdeE.pro
- cd microkde; tmake "CONFIG+=$(RELEASE_DEBUG)" "VERSION=$(KDEPIM_VERSION)" microkdeE.pro -o Makefile$(PLATFORM)
-
-libkcal/Makefile$(PLATFORM): libkcal/libkcalE.pro
- cd libkcal; tmake "CONFIG+=$(RELEASE_DEBUG)" "VERSION=$(KDEPIM_VERSION)" libkcalE.pro -o Makefile$(PLATFORM)
-
-
-libkdepim/Makefile$(PLATFORM): libkdepim/libkdepimE.pro
- cd libkdepim; tmake "CONFIG+=$(RELEASE_DEBUG)" "VERSION=$(KDEPIM_VERSION)" libkdepimE.pro -o Makefile$(PLATFORM)
-
-kalarmd/Makefile$(PLATFORM): kalarmd/kalarmdE.pro
- cd kalarmd; tmake "CONFIG+=$(RELEASE_DEBUG)" "VERSION=$(KDEPIM_VERSION)" kalarmdE.pro -o Makefile$(PLATFORM)
-
-korganizer/Makefile$(PLATFORM): korganizer/korganizerE.pro
- cd korganizer; tmake "CONFIG+=$(RELEASE_DEBUG)" "VERSION=$(KDEPIM_VERSION)" korganizerE.pro -o Makefile$(PLATFORM)
-
-libical/src/libical/Makefile$(PLATFORM): libical/src/libical/libicalE.pro
- cd libical/src/libical; tmake "CONFIG+=$(RELEASE_DEBUG)" "VERSION=$(KDEPIM_VERSION)" libicalE.pro -o Makefile$(PLATFORM)
-
-libical/src/libicalss/Makefile$(PLATFORM): libical/src/libicalss/libicalssE.pro
- cd libical/src/libicalss; tmake "CONFIG+=$(RELEASE_DEBUG)" "VERSION=$(KDEPIM_VERSION)" libicalssE.pro -o Makefile$(PLATFORM)
-
-kabc/Makefile$(PLATFORM): kabc/kabcE.pro
- cd kabc; tmake "CONFIG+=$(RELEASE_DEBUG)" "VERSION=$(KDEPIM_VERSION)" kabcE.pro -o Makefile$(PLATFORM)
-
-kabc/formats/binary/Makefile$(PLATFORM): kabc/formats/binary/kabcformat_binaryE.pro
- cd kabc/formats/binary; tmake "CONFIG+=$(RELEASE_DEBUG)" "VERSION=$(KDEPIM_VERSION)" kabcformat_binaryE.pro -o Makefile$(PLATFORM)
-
-kabc/plugins/file/Makefile$(PLATFORM): kabc/plugins/file/fileE.pro
- cd kabc/plugins/file; tmake "CONFIG+=$(RELEASE_DEBUG)" "VERSION=$(KDEPIM_VERSION)" fileE.pro -o Makefile$(PLATFORM)
-
-kabc/plugins/dir/Makefile$(PLATFORM): kabc/plugins/dir/dirE.pro
- cd kabc/plugins/dir; tmake "CONFIG+=$(RELEASE_DEBUG)" "VERSION=$(KDEPIM_VERSION)" dirE.pro -o Makefile$(PLATFORM)
-
-kabc/plugins/ldap/Makefile$(PLATFORM): kabc/plugins/ldap/ldapE.pro
- cd kabc/plugins/ldap; tmake "CONFIG+=$(RELEASE_DEBUG)" "VERSION=$(KDEPIM_VERSION)" ldapE.pro -o Makefile$(PLATFORM)
-
-kabc/plugins/opie/Makefile$(PLATFORM): kabc/plugins/opie/opieE.pro
- cd kabc/plugins/opie; tmake "CONFIG+=$(RELEASE_DEBUG)" "VERSION=$(KDEPIM_VERSION)" opieE.pro -o Makefile$(PLATFORM)
-
-kabc/plugins/qtopia/Makefile$(PLATFORM): kabc/plugins/qtopia/qtopiaE.pro
- cd kabc/plugins/qtopia; tmake "CONFIG+=$(RELEASE_DEBUG)" "VERSION=$(KDEPIM_VERSION)" qtopiaE.pro -o Makefile$(PLATFORM)
-
-kabc/plugins/sharpdtm/Makefile$(PLATFORM): kabc/plugins/sharpdtm/sharpdtmE.pro
- cd kabc/plugins/sharpdtm; tmake "CONFIG+=$(RELEASE_DEBUG)" "VERSION=$(KDEPIM_VERSION)" sharpdtmE.pro -o Makefile$(PLATFORM)
-
-kaddressbook/Makefile$(PLATFORM): kaddressbook/kaddressbookE.pro
- cd kaddressbook; tmake "CONFIG+=$(RELEASE_DEBUG)" "VERSION=$(KDEPIM_VERSION)" kaddressbookE.pro -o Makefile$(PLATFORM)
-
-kmicromail/Makefile$(PLATFORM): kmicromail/kmicromailE.pro
- cd kmicromail; tmake "CONFIG+=$(RELEASE_DEBUG)" "VERSION=$(KDEPIM_VERSION)" kmicromailE.pro -o Makefile$(PLATFORM)
-
-kmicromail/libetpan/Makefile$(PLATFORM): kmicromail/libetpan/libetpanE.pro
- cd kmicromail/libetpan; tmake "CONFIG+=$(RELEASE_DEBUG)" "VERSION=$(KDEPIM_VERSION)" libetpanE.pro -o Makefile$(PLATFORM)
-
-kmicromail/libmailwrapper/Makefile$(PLATFORM): kmicromail/libmailwrapper/libmailwrapperE.pro
- cd kmicromail/libmailwrapper; tmake "CONFIG+=$(RELEASE_DEBUG)" "VERSION=$(KDEPIM_VERSION)" libmailwrapperE.pro -o Makefile$(PLATFORM)
-
-gammu/emb/common/Makefile$(PLATFORM): gammu/emb/common/commonE.pro
- cd gammu/emb/common; tmake "CONFIG+=$(RELEASE_DEBUG)" "VERSION=$(KDEPIM_VERSION)" commonE.pro -o Makefile$(PLATFORM)
-
-gammu/emb/gammu/Makefile$(PLATFORM): gammu/emb/gammu/gammuE.pro
- cd gammu/emb/gammu; tmake "CONFIG+=$(RELEASE_DEBUG)" "VERSION=$(KDEPIM_VERSION)" gammuE.pro -o Makefile$(PLATFORM)
-
-pwmanager/pwmanager/Makefile$(PLATFORM): pwmanager/pwmanager/pwmanagerE.pro
- cd pwmanager/pwmanager; tmake "CONFIG+=$(RELEASE_DEBUG)" "VERSION=$(KDEPIM_VERSION)" pwmanagerE.pro -o Makefile$(PLATFORM)
-
-
-pwmanager/libcrypt/mpi/Makefile$(PLATFORM): pwmanager/libcrypt/mpi/mpi.pro
- cd pwmanager/libcrypt/mpi;tmake "CONFIG+=$(RELEASE_DEBUG)" "VERSION=$(KDEPIM_VERSION)" mpi.pro -o Makefile$(PLATFORM)
-
-pwmanager/libcrypt/error/Makefile$(PLATFORM): pwmanager/libcrypt/error/error.pro
- cd pwmanager/libcrypt/error;tmake "CONFIG+=$(RELEASE_DEBUG)" "VERSION=$(KDEPIM_VERSION)" error.pro -o Makefile$(PLATFORM)
-
-pwmanager/libcrypt/cipher/Makefile$(PLATFORM): pwmanager/libcrypt/cipher/cipher.pro
- cd pwmanager/libcrypt/cipher;tmake "CONFIG+=$(RELEASE_DEBUG)" "VERSION=$(KDEPIM_VERSION)" cipher.pro -o Makefile$(PLATFORM)
-
-pwmanager/libcrypt/zlib/Makefile$(PLATFORM): pwmanager/libcrypt/zlib/zlib.pro
- cd pwmanager/libcrypt/zlib;tmake "CONFIG+=$(RELEASE_DEBUG)" "VERSION=$(KDEPIM_VERSION)" zlib.pro -o Makefile$(PLATFORM)
-
+#############################################################################
+# Makefile for building: kdepim-desktop
+# Generated by qmake (1.07a) (Qt 3.3.1) on: Mon Oct 25 11:25:22 2004
+# Project: kdepim-desktop.pro
+# Template: subdirs
+# Command: $(QMAKE) -o Makefile kdepim-desktop.pro
+#############################################################################
+
+MAKEFILE = Makefile
+QMAKE = qmake
+DEL_FILE = rm -f
+CHK_DIR_EXISTS= test -d
+MKDIR = mkdir -p
+SUBTARGETS = \
+ sub-gammu-emb-common \
+ sub-gammu-emb-gammu \
+ sub-libical \
+ sub-libkcal \
+ sub-microkde \
+ sub-libkdepim \
+ sub-kabc \
+ sub-korganizer \
+ sub-kaddressbook \
+ sub-kabc-plugins-file \
+ sub-kabc-plugins-dir \
+ sub-kabc-plugins-file \
+ sub-kabc-plugins-qtopia \
+ sub-pwmanager-libcrypt-cipher \
+ sub-pwmanager-libcrypt-error \
+ sub-pwmanager-libcrypt-mpi \
+ sub-pwmanager-libcrypt-zlib \
+ sub-pwmanager-pwmanager
+
+first: all
+
+all: Makefile $(SUBTARGETS)
+
+gammu/emb/common/$(MAKEFILE):
+ @$(CHK_DIR_EXISTS) "gammu/emb/common" || $(MKDIR) "gammu/emb/common"
+ cd gammu/emb/common && $(QMAKE) common.pro -o $(MAKEFILE)
+sub-gammu-emb-common: gammu/emb/common/$(MAKEFILE) FORCE
+ cd gammu/emb/common && $(MAKE) -f $(MAKEFILE)
+
+gammu/emb/gammu/$(MAKEFILE):
+ @$(CHK_DIR_EXISTS) "gammu/emb/gammu" || $(MKDIR) "gammu/emb/gammu"
+ cd gammu/emb/gammu && $(QMAKE) gammu.pro -o $(MAKEFILE)
+sub-gammu-emb-gammu: gammu/emb/gammu/$(MAKEFILE) FORCE
+ cd gammu/emb/gammu && $(MAKE) -f $(MAKEFILE)
+
+libical/$(MAKEFILE):
+ @$(CHK_DIR_EXISTS) "libical" || $(MKDIR) "libical"
+ cd libical && $(QMAKE) libical.pro -o $(MAKEFILE)
+sub-libical: libical/$(MAKEFILE) FORCE
+ cd libical && $(MAKE) -f $(MAKEFILE)
+
+libkcal/$(MAKEFILE):
+ @$(CHK_DIR_EXISTS) "libkcal" || $(MKDIR) "libkcal"
+ cd libkcal && $(QMAKE) libkcal.pro -o $(MAKEFILE)
+sub-libkcal: libkcal/$(MAKEFILE) FORCE
+ cd libkcal && $(MAKE) -f $(MAKEFILE)
+
+microkde/$(MAKEFILE):
+ @$(CHK_DIR_EXISTS) "microkde" || $(MKDIR) "microkde"
+ cd microkde && $(QMAKE) microkde.pro -o $(MAKEFILE)
+sub-microkde: microkde/$(MAKEFILE) FORCE
+ cd microkde && $(MAKE) -f $(MAKEFILE)
+
+libkdepim/$(MAKEFILE):
+ @$(CHK_DIR_EXISTS) "libkdepim" || $(MKDIR) "libkdepim"
+ cd libkdepim && $(QMAKE) libkdepim.pro -o $(MAKEFILE)
+sub-libkdepim: libkdepim/$(MAKEFILE) FORCE
+ cd libkdepim && $(MAKE) -f $(MAKEFILE)
+
+kabc/$(MAKEFILE):
+ @$(CHK_DIR_EXISTS) "kabc" || $(MKDIR) "kabc"
+ cd kabc && $(QMAKE) kabc.pro -o $(MAKEFILE)
+sub-kabc: kabc/$(MAKEFILE) FORCE
+ cd kabc && $(MAKE) -f $(MAKEFILE)
+
+korganizer/$(MAKEFILE):
+ @$(CHK_DIR_EXISTS) "korganizer" || $(MKDIR) "korganizer"
+ cd korganizer && $(QMAKE) korganizer.pro -o $(MAKEFILE)
+sub-korganizer: korganizer/$(MAKEFILE) FORCE
+ cd korganizer && $(MAKE) -f $(MAKEFILE)
+
+kaddressbook/$(MAKEFILE):
+ @$(CHK_DIR_EXISTS) "kaddressbook" || $(MKDIR) "kaddressbook"
+ cd kaddressbook && $(QMAKE) kaddressbook.pro -o $(MAKEFILE)
+sub-kaddressbook: kaddressbook/$(MAKEFILE) FORCE
+ cd kaddressbook && $(MAKE) -f $(MAKEFILE)
+
+kabc/plugins/file/$(MAKEFILE):
+ @$(CHK_DIR_EXISTS) "kabc/plugins/file" || $(MKDIR) "kabc/plugins/file"
+ cd kabc/plugins/file && $(QMAKE) file.pro -o $(MAKEFILE)
+sub-kabc-plugins-file: kabc/plugins/file/$(MAKEFILE) FORCE
+ cd kabc/plugins/file && $(MAKE) -f $(MAKEFILE)
+
+kabc/plugins/dir/$(MAKEFILE):
+ @$(CHK_DIR_EXISTS) "kabc/plugins/dir" || $(MKDIR) "kabc/plugins/dir"
+ cd kabc/plugins/dir && $(QMAKE) dir.pro -o $(MAKEFILE)
+sub-kabc-plugins-dir: kabc/plugins/dir/$(MAKEFILE) FORCE
+ cd kabc/plugins/dir && $(MAKE) -f $(MAKEFILE)
+
+kabc/plugins/file/$(MAKEFILE):
+ @$(CHK_DIR_EXISTS) "kabc/plugins/file" || $(MKDIR) "kabc/plugins/file"
+ cd kabc/plugins/file && $(QMAKE) file.pro -o $(MAKEFILE)
+sub-kabc-plugins-file: kabc/plugins/file/$(MAKEFILE) FORCE
+ cd kabc/plugins/file && $(MAKE) -f $(MAKEFILE)
+
+kabc/plugins/qtopia/$(MAKEFILE):
+ @$(CHK_DIR_EXISTS) "kabc/plugins/qtopia" || $(MKDIR) "kabc/plugins/qtopia"
+ cd kabc/plugins/qtopia && $(QMAKE) qtopia.pro -o $(MAKEFILE)
+sub-kabc-plugins-qtopia: kabc/plugins/qtopia/$(MAKEFILE) FORCE
+ cd kabc/plugins/qtopia && $(MAKE) -f $(MAKEFILE)
+
+pwmanager/libcrypt/cipher/$(MAKEFILE):
+ @$(CHK_DIR_EXISTS) "pwmanager/libcrypt/cipher" || $(MKDIR) "pwmanager/libcrypt/cipher"
+ cd pwmanager/libcrypt/cipher && $(QMAKE) cipher.pro -o $(MAKEFILE)
+sub-pwmanager-libcrypt-cipher: pwmanager/libcrypt/cipher/$(MAKEFILE) FORCE
+ cd pwmanager/libcrypt/cipher && $(MAKE) -f $(MAKEFILE)
+
+pwmanager/libcrypt/error/$(MAKEFILE):
+ @$(CHK_DIR_EXISTS) "pwmanager/libcrypt/error" || $(MKDIR) "pwmanager/libcrypt/error"
+ cd pwmanager/libcrypt/error && $(QMAKE) error.pro -o $(MAKEFILE)
+sub-pwmanager-libcrypt-error: pwmanager/libcrypt/error/$(MAKEFILE) FORCE
+ cd pwmanager/libcrypt/error && $(MAKE) -f $(MAKEFILE)
+
+pwmanager/libcrypt/mpi/$(MAKEFILE):
+ @$(CHK_DIR_EXISTS) "pwmanager/libcrypt/mpi" || $(MKDIR) "pwmanager/libcrypt/mpi"
+ cd pwmanager/libcrypt/mpi && $(QMAKE) mpi.pro -o $(MAKEFILE)
+sub-pwmanager-libcrypt-mpi: pwmanager/libcrypt/mpi/$(MAKEFILE) FORCE
+ cd pwmanager/libcrypt/mpi && $(MAKE) -f $(MAKEFILE)
+
+pwmanager/libcrypt/zlib/$(MAKEFILE):
+ @$(CHK_DIR_EXISTS) "pwmanager/libcrypt/zlib" || $(MKDIR) "pwmanager/libcrypt/zlib"
+ cd pwmanager/libcrypt/zlib && $(QMAKE) zlib.pro -o $(MAKEFILE)
+sub-pwmanager-libcrypt-zlib: pwmanager/libcrypt/zlib/$(MAKEFILE) FORCE
+ cd pwmanager/libcrypt/zlib && $(MAKE) -f $(MAKEFILE)
+
+pwmanager/pwmanager/$(MAKEFILE):
+ @$(CHK_DIR_EXISTS) "pwmanager/pwmanager" || $(MKDIR) "pwmanager/pwmanager"
+ cd pwmanager/pwmanager && $(QMAKE) pwmanager.pro -o $(MAKEFILE)
+sub-pwmanager-pwmanager: pwmanager/pwmanager/$(MAKEFILE) FORCE
+ cd pwmanager/pwmanager && $(MAKE) -f $(MAKEFILE)
+
+Makefile: kdepim-desktop.pro /usr/lib/qt3/mkspecs/default/qmake.conf
+ $(QMAKE) -o Makefile kdepim-desktop.pro
+qmake: qmake_all
+ @$(QMAKE) -o Makefile kdepim-desktop.pro
+
+all: $(SUBTARGETS)
+qmake_all: gammu/emb/common/$(MAKEFILE) gammu/emb/gammu/$(MAKEFILE) libical/$(MAKEFILE) libkcal/$(MAKEFILE) microkde/$(MAKEFILE) libkdepim/$(MAKEFILE) kabc/$(MAKEFILE) korganizer/$(MAKEFILE) kaddressbook/$(MAKEFILE) kabc/plugins/file/$(MAKEFILE) kabc/plugins/dir/$(MAKEFILE) kabc/plugins/file/$(MAKEFILE) kabc/plugins/qtopia/$(MAKEFILE) pwmanager/libcrypt/cipher/$(MAKEFILE) pwmanager/libcrypt/error/$(MAKEFILE) pwmanager/libcrypt/mpi/$(MAKEFILE) pwmanager/libcrypt/zlib/$(MAKEFILE) pwmanager/pwmanager/$(MAKEFILE)
+ ( [ -d gammu/emb/common ] && cd gammu/emb/common ; grep "^qmake_all:" $(MAKEFILE) && $(MAKE) -f $(MAKEFILE) qmake_all; ) || true
+ ( [ -d gammu/emb/gammu ] && cd gammu/emb/gammu ; grep "^qmake_all:" $(MAKEFILE) && $(MAKE) -f $(MAKEFILE) qmake_all; ) || true
+ ( [ -d libical ] && cd libical ; grep "^qmake_all:" $(MAKEFILE) && $(MAKE) -f $(MAKEFILE) qmake_all; ) || true
+ ( [ -d libkcal ] && cd libkcal ; grep "^qmake_all:" $(MAKEFILE) && $(MAKE) -f $(MAKEFILE) qmake_all; ) || true
+ ( [ -d microkde ] && cd microkde ; grep "^qmake_all:" $(MAKEFILE) && $(MAKE) -f $(MAKEFILE) qmake_all; ) || true
+ ( [ -d libkdepim ] && cd libkdepim ; grep "^qmake_all:" $(MAKEFILE) && $(MAKE) -f $(MAKEFILE) qmake_all; ) || true
+ ( [ -d kabc ] && cd kabc ; grep "^qmake_all:" $(MAKEFILE) && $(MAKE) -f $(MAKEFILE) qmake_all; ) || true
+ ( [ -d korganizer ] && cd korganizer ; grep "^qmake_all:" $(MAKEFILE) && $(MAKE) -f $(MAKEFILE) qmake_all; ) || true
+ ( [ -d kaddressbook ] && cd kaddressbook ; grep "^qmake_all:" $(MAKEFILE) && $(MAKE) -f $(MAKEFILE) qmake_all; ) || true
+ ( [ -d kabc/plugins/file ] && cd kabc/plugins/file ; grep "^qmake_all:" $(MAKEFILE) && $(MAKE) -f $(MAKEFILE) qmake_all; ) || true
+ ( [ -d kabc/plugins/dir ] && cd kabc/plugins/dir ; grep "^qmake_all:" $(MAKEFILE) && $(MAKE) -f $(MAKEFILE) qmake_all; ) || true
+ ( [ -d kabc/plugins/file ] && cd kabc/plugins/file ; grep "^qmake_all:" $(MAKEFILE) && $(MAKE) -f $(MAKEFILE) qmake_all; ) || true
+ ( [ -d kabc/plugins/qtopia ] && cd kabc/plugins/qtopia ; grep "^qmake_all:" $(MAKEFILE) && $(MAKE) -f $(MAKEFILE) qmake_all; ) || true
+ ( [ -d pwmanager/libcrypt/cipher ] && cd pwmanager/libcrypt/cipher ; grep "^qmake_all:" $(MAKEFILE) && $(MAKE) -f $(MAKEFILE) qmake_all; ) || true
+ ( [ -d pwmanager/libcrypt/error ] && cd pwmanager/libcrypt/error ; grep "^qmake_all:" $(MAKEFILE) && $(MAKE) -f $(MAKEFILE) qmake_all; ) || true
+ ( [ -d pwmanager/libcrypt/mpi ] && cd pwmanager/libcrypt/mpi ; grep "^qmake_all:" $(MAKEFILE) && $(MAKE) -f $(MAKEFILE) qmake_all; ) || true
+ ( [ -d pwmanager/libcrypt/zlib ] && cd pwmanager/libcrypt/zlib ; grep "^qmake_all:" $(MAKEFILE) && $(MAKE) -f $(MAKEFILE) qmake_all; ) || true
+ ( [ -d pwmanager/pwmanager ] && cd pwmanager/pwmanager ; grep "^qmake_all:" $(MAKEFILE) && $(MAKE) -f $(MAKEFILE) qmake_all; ) || true
+clean uicables mocables uiclean mocclean lexclean yaccclean : qmake_all FORCE
+ ( [ -d gammu/emb/common ] && cd gammu/emb/common ; $(MAKE) -f $(MAKEFILE) $@; ) || true
+ ( [ -d gammu/emb/gammu ] && cd gammu/emb/gammu ; $(MAKE) -f $(MAKEFILE) $@; ) || true
+ ( [ -d libical ] && cd libical ; $(MAKE) -f $(MAKEFILE) $@; ) || true
+ ( [ -d libkcal ] && cd libkcal ; $(MAKE) -f $(MAKEFILE) $@; ) || true
+ ( [ -d microkde ] && cd microkde ; $(MAKE) -f $(MAKEFILE) $@; ) || true
+ ( [ -d libkdepim ] && cd libkdepim ; $(MAKE) -f $(MAKEFILE) $@; ) || true
+ ( [ -d kabc ] && cd kabc ; $(MAKE) -f $(MAKEFILE) $@; ) || true
+ ( [ -d korganizer ] && cd korganizer ; $(MAKE) -f $(MAKEFILE) $@; ) || true
+ ( [ -d kaddressbook ] && cd kaddressbook ; $(MAKE) -f $(MAKEFILE) $@; ) || true
+ ( [ -d kabc/plugins/file ] && cd kabc/plugins/file ; $(MAKE) -f $(MAKEFILE) $@; ) || true
+ ( [ -d kabc/plugins/dir ] && cd kabc/plugins/dir ; $(MAKE) -f $(MAKEFILE) $@; ) || true
+ ( [ -d kabc/plugins/file ] && cd kabc/plugins/file ; $(MAKE) -f $(MAKEFILE) $@; ) || true
+ ( [ -d kabc/plugins/qtopia ] && cd kabc/plugins/qtopia ; $(MAKE) -f $(MAKEFILE) $@; ) || true
+ ( [ -d pwmanager/libcrypt/cipher ] && cd pwmanager/libcrypt/cipher ; $(MAKE) -f $(MAKEFILE) $@; ) || true
+ ( [ -d pwmanager/libcrypt/error ] && cd pwmanager/libcrypt/error ; $(MAKE) -f $(MAKEFILE) $@; ) || true
+ ( [ -d pwmanager/libcrypt/mpi ] && cd pwmanager/libcrypt/mpi ; $(MAKE) -f $(MAKEFILE) $@; ) || true
+ ( [ -d pwmanager/libcrypt/zlib ] && cd pwmanager/libcrypt/zlib ; $(MAKE) -f $(MAKEFILE) $@; ) || true
+ ( [ -d pwmanager/pwmanager ] && cd pwmanager/pwmanager ; $(MAKE) -f $(MAKEFILE) $@; ) || true
+uninstall_subdirs: qmake_all FORCE
+ ( [ -d gammu/emb/common ] && cd gammu/emb/common ; $(MAKE) -f $(MAKEFILE) uninstall; ) || true
+ ( [ -d gammu/emb/gammu ] && cd gammu/emb/gammu ; $(MAKE) -f $(MAKEFILE) uninstall; ) || true
+ ( [ -d libical ] && cd libical ; $(MAKE) -f $(MAKEFILE) uninstall; ) || true
+ ( [ -d libkcal ] && cd libkcal ; $(MAKE) -f $(MAKEFILE) uninstall; ) || true
+ ( [ -d microkde ] && cd microkde ; $(MAKE) -f $(MAKEFILE) uninstall; ) || true
+ ( [ -d libkdepim ] && cd libkdepim ; $(MAKE) -f $(MAKEFILE) uninstall; ) || true
+ ( [ -d kabc ] && cd kabc ; $(MAKE) -f $(MAKEFILE) uninstall; ) || true
+ ( [ -d korganizer ] && cd korganizer ; $(MAKE) -f $(MAKEFILE) uninstall; ) || true
+ ( [ -d kaddressbook ] && cd kaddressbook ; $(MAKE) -f $(MAKEFILE) uninstall; ) || true
+ ( [ -d kabc/plugins/file ] && cd kabc/plugins/file ; $(MAKE) -f $(MAKEFILE) uninstall; ) || true
+ ( [ -d kabc/plugins/dir ] && cd kabc/plugins/dir ; $(MAKE) -f $(MAKEFILE) uninstall; ) || true
+ ( [ -d kabc/plugins/file ] && cd kabc/plugins/file ; $(MAKE) -f $(MAKEFILE) uninstall; ) || true
+ ( [ -d kabc/plugins/qtopia ] && cd kabc/plugins/qtopia ; $(MAKE) -f $(MAKEFILE) uninstall; ) || true
+ ( [ -d pwmanager/libcrypt/cipher ] && cd pwmanager/libcrypt/cipher ; $(MAKE) -f $(MAKEFILE) uninstall; ) || true
+ ( [ -d pwmanager/libcrypt/error ] && cd pwmanager/libcrypt/error ; $(MAKE) -f $(MAKEFILE) uninstall; ) || true
+ ( [ -d pwmanager/libcrypt/mpi ] && cd pwmanager/libcrypt/mpi ; $(MAKE) -f $(MAKEFILE) uninstall; ) || true
+ ( [ -d pwmanager/libcrypt/zlib ] && cd pwmanager/libcrypt/zlib ; $(MAKE) -f $(MAKEFILE) uninstall; ) || true
+ ( [ -d pwmanager/pwmanager ] && cd pwmanager/pwmanager ; $(MAKE) -f $(MAKEFILE) uninstall; ) || true
+install_subdirs: qmake_all FORCE
+ ( [ -d gammu/emb/common ] && cd gammu/emb/common ; $(MAKE) -f $(MAKEFILE) install; ) || true
+ ( [ -d gammu/emb/gammu ] && cd gammu/emb/gammu ; $(MAKE) -f $(MAKEFILE) install; ) || true
+ ( [ -d libical ] && cd libical ; $(MAKE) -f $(MAKEFILE) install; ) || true
+ ( [ -d libkcal ] && cd libkcal ; $(MAKE) -f $(MAKEFILE) install; ) || true
+ ( [ -d microkde ] && cd microkde ; $(MAKE) -f $(MAKEFILE) install; ) || true
+ ( [ -d libkdepim ] && cd libkdepim ; $(MAKE) -f $(MAKEFILE) install; ) || true
+ ( [ -d kabc ] && cd kabc ; $(MAKE) -f $(MAKEFILE) install; ) || true
+ ( [ -d korganizer ] && cd korganizer ; $(MAKE) -f $(MAKEFILE) install; ) || true
+ ( [ -d kaddressbook ] && cd kaddressbook ; $(MAKE) -f $(MAKEFILE) install; ) || true
+ ( [ -d kabc/plugins/file ] && cd kabc/plugins/file ; $(MAKE) -f $(MAKEFILE) install; ) || true
+ ( [ -d kabc/plugins/dir ] && cd kabc/plugins/dir ; $(MAKE) -f $(MAKEFILE) install; ) || true
+ ( [ -d kabc/plugins/file ] && cd kabc/plugins/file ; $(MAKE) -f $(MAKEFILE) install; ) || true
+ ( [ -d kabc/plugins/qtopia ] && cd kabc/plugins/qtopia ; $(MAKE) -f $(MAKEFILE) install; ) || true
+ ( [ -d pwmanager/libcrypt/cipher ] && cd pwmanager/libcrypt/cipher ; $(MAKE) -f $(MAKEFILE) install; ) || true
+ ( [ -d pwmanager/libcrypt/error ] && cd pwmanager/libcrypt/error ; $(MAKE) -f $(MAKEFILE) install; ) || true
+ ( [ -d pwmanager/libcrypt/mpi ] && cd pwmanager/libcrypt/mpi ; $(MAKE) -f $(MAKEFILE) install; ) || true
+ ( [ -d pwmanager/libcrypt/zlib ] && cd pwmanager/libcrypt/zlib ; $(MAKE) -f $(MAKEFILE) install; ) || true
+ ( [ -d pwmanager/pwmanager ] && cd pwmanager/pwmanager ; $(MAKE) -f $(MAKEFILE) install; ) || true
+distclean: qmake_all FORCE
+ ( [ -d gammu/emb/common ] && cd gammu/emb/common ; $(MAKE) -f $(MAKEFILE) $@; $(DEL_FILE) $(MAKEFILE); ) || true
+ ( [ -d gammu/emb/gammu ] && cd gammu/emb/gammu ; $(MAKE) -f $(MAKEFILE) $@; $(DEL_FILE) $(MAKEFILE); ) || true
+ ( [ -d libical ] && cd libical ; $(MAKE) -f $(MAKEFILE) $@; $(DEL_FILE) $(MAKEFILE); ) || true
+ ( [ -d libkcal ] && cd libkcal ; $(MAKE) -f $(MAKEFILE) $@; $(DEL_FILE) $(MAKEFILE); ) || true
+ ( [ -d microkde ] && cd microkde ; $(MAKE) -f $(MAKEFILE) $@; $(DEL_FILE) $(MAKEFILE); ) || true
+ ( [ -d libkdepim ] && cd libkdepim ; $(MAKE) -f $(MAKEFILE) $@; $(DEL_FILE) $(MAKEFILE); ) || true
+ ( [ -d kabc ] && cd kabc ; $(MAKE) -f $(MAKEFILE) $@; $(DEL_FILE) $(MAKEFILE); ) || true
+ ( [ -d korganizer ] && cd korganizer ; $(MAKE) -f $(MAKEFILE) $@; $(DEL_FILE) $(MAKEFILE); ) || true
+ ( [ -d kaddressbook ] && cd kaddressbook ; $(MAKE) -f $(MAKEFILE) $@; $(DEL_FILE) $(MAKEFILE); ) || true
+ ( [ -d kabc/plugins/file ] && cd kabc/plugins/file ; $(MAKE) -f $(MAKEFILE) $@; $(DEL_FILE) $(MAKEFILE); ) || true
+ ( [ -d kabc/plugins/dir ] && cd kabc/plugins/dir ; $(MAKE) -f $(MAKEFILE) $@; $(DEL_FILE) $(MAKEFILE); ) || true
+ ( [ -d kabc/plugins/file ] && cd kabc/plugins/file ; $(MAKE) -f $(MAKEFILE) $@; $(DEL_FILE) $(MAKEFILE); ) || true
+ ( [ -d kabc/plugins/qtopia ] && cd kabc/plugins/qtopia ; $(MAKE) -f $(MAKEFILE) $@; $(DEL_FILE) $(MAKEFILE); ) || true
+ ( [ -d pwmanager/libcrypt/cipher ] && cd pwmanager/libcrypt/cipher ; $(MAKE) -f $(MAKEFILE) $@; $(DEL_FILE) $(MAKEFILE); ) || true
+ ( [ -d pwmanager/libcrypt/error ] && cd pwmanager/libcrypt/error ; $(MAKE) -f $(MAKEFILE) $@; $(DEL_FILE) $(MAKEFILE); ) || true
+ ( [ -d pwmanager/libcrypt/mpi ] && cd pwmanager/libcrypt/mpi ; $(MAKE) -f $(MAKEFILE) $@; $(DEL_FILE) $(MAKEFILE); ) || true
+ ( [ -d pwmanager/libcrypt/zlib ] && cd pwmanager/libcrypt/zlib ; $(MAKE) -f $(MAKEFILE) $@; $(DEL_FILE) $(MAKEFILE); ) || true
+ ( [ -d pwmanager/pwmanager ] && cd pwmanager/pwmanager ; $(MAKE) -f $(MAKEFILE) $@; $(DEL_FILE) $(MAKEFILE); ) || true
+
+install: install_subdirs
+
+uninstall: uninstall_subdirs
+
+FORCE:
diff --git a/microkde/kdeui/kmainwindow.cpp b/microkde/kdeui/kmainwindow.cpp
index bd5a2cc..3ae4c87 100644
--- a/microkde/kdeui/kmainwindow.cpp
+++ b/microkde/kdeui/kmainwindow.cpp
@@ -1,994 +1,995 @@
/* This file is part of the KDE libraries
Copyright
(C) 2000 Reginald Stadlbauer (reggie@kde.org)
(C) 1997 Stephan Kulow (coolo@kde.org)
(C) 1997-2000 Sven Radej (radej@kde.org)
(C) 1997-2000 Matthias Ettrich (ettrich@kde.org)
(C) 1999 Chris Schlaeger (cs@kde.org)
(C) 2002 Joseph Wenninger (jowenn@kde.org)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2 as published by the Free Software Foundation.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#include <qobjectlist.h>
#include <qstringlist.h>
#include <qtimer.h>
#include <qmenubar.h>
#include <qstatusbar.h>
#include <qapplication.h>
#include "kdebug.h"
#include "kmainwindow.h"
#include "kglobalsettings.h"
#include "kactioncollection.h"
class KMainWindowPrivate {
public:
//US bool showHelpMenu:1;
bool autoSaveSettings:1;
bool settingsDirty:1;
bool autoSaveWindowSize:1;
bool care_about_geometry:1;
QString autoSaveGroup;
//US KAccel * kaccel;
//US KMainWindowInterface *m_interface;
KDEPrivate::ToolBarHandler *toolBarHandler;
QTimer* settingsTimer;
KToggleAction *showStatusBarAction;
QRect defaultWindowSize;
};
static bool no_query_exit = false;
KMainWindow::KMainWindow( QWidget* parent, const char *name, WFlags f )
: QMainWindow( parent, name ) /*LR, f ) with the default widget flag we cannot have fastload */ /*US, KXMLGUIBuilder( this ), helpMenu2( 0 ), factory_( 0 )*/
{
mQToolBar = 0;
initKMainWindow(name);
}
void KMainWindow::parseGeometry(bool parsewidth)
{
//US the following code is not getting used in the embedded version !! So disable it for now
/*US
assert ( !kapp->geometryArgument().isNull() );
assert ( d->care_about_geometry );
#ifndef Q_WS_QWS
// FIXME: (E) Implement something similar for Qt Embedded (or decide we don't need it)
int x, y;
int w, h;
int m = XParseGeometry( kapp->geometryArgument().latin1(), &x, &y, (unsigned int*)&w, (unsigned int*)&h);
if (parsewidth) {
QSize minSize = minimumSize();
QSize maxSize = maximumSize();
if ( (m & WidthValue) == 0 )
w = width();
if ( (m & HeightValue) == 0 )
h = height();
w = QMIN(w,maxSize.width());
h = QMIN(h,maxSize.height());
w = QMAX(w,minSize.width());
h = QMAX(h,minSize.height());
resize(w, h);
} else {
if ( parsewidth && (m & XValue) == 0 )
x = geometry().x();
if ( parsewidth && (m & YValue) == 0 )
y = geometry().y();
if ( (m & XNegative) )
x = KApplication::desktop()->width() + x - w;
if ( (m & YNegative) )
y = KApplication::desktop()->height() + y - h;
move(x, y);
}
#endif
*/
}
KMainWindow::~KMainWindow()
{
delete d->settingsTimer;
QMenuBar* mb = internalMenuBar();
delete mb;
//US delete d->m_interface;
delete d;
//US memberList->remove( this );
}
void KMainWindow::initKMainWindow(const char *name)
{
setDockMenuEnabled( FALSE );
//US mHelpMenu = 0;
//US kapp->setTopWidget( this );
actionCollection()->setWidget( this );
//US connect(kapp, SIGNAL(shutDown()), this, SLOT(shuttingDown()));
//US if( !memberList )
//US memberList = new QPtrList<KMainWindow>;
/*US
if ( !ksm )
ksm = ksmd.setObject(new KMWSessionManaged());
// set a unique object name. Required by session management.
QCString objname;
QCString s;
int unusedNumber;
if ( !name )
{ // no name given
objname = kapp->instanceName() + "-mainwindow#";
s = objname + '1'; // start adding number immediately
unusedNumber = 1;
}
else if( name[ strlen( name ) - 1 ] == '#' )
{ // trailing # - always add a number
objname = name;
s = objname + '1'; // start adding number immediately
unusedNumber = 1;
}
else
{
objname = name;
s = objname;
unusedNumber = 0; // add numbers only when needed
}
for(;;) {
QWidgetList* list = kapp->topLevelWidgets();
QWidgetListIt it( *list );
bool found = false;
for( QWidget* w = it.current();
w != NULL;
++it, w = it.current())
if( w != this && w->name() == s )
{
found = true;
break;
}
delete list;
if( !found )
break;
s.setNum( ++unusedNumber );
s = objname + s;
}
setName( s );
memberList->append( this );
*/
d = new KMainWindowPrivate;
//US d->showHelpMenu = true;
d->settingsDirty = false;
d->autoSaveSettings = false;
d->autoSaveWindowSize = true; // for compatibility
//US d->kaccel = actionCollection()->kaccel();
d->toolBarHandler = 0;
d->settingsTimer = 0;
d->showStatusBarAction = NULL;
/*US
if ((d->care_about_geometry == beeing_first)) {
beeing_first = false;
if ( kapp->geometryArgument().isNull() ) // if there is no geometry, it doesn't mater
d->care_about_geometry = false;
else
parseGeometry(false);
}
*/
d->care_about_geometry = false;
//US setCaption( kapp->caption() );
// attach dcop interface
//US d->m_interface = new KMainWindowInterface(this);
//US if (!kapp->authorize("movable_toolbars"))
//US setDockWindowsMovable(false);
}
KAction *KMainWindow::toolBarMenuAction()
{
if ( !d->toolBarHandler )
return 0;
return d->toolBarHandler->toolBarMenuAction();
}
bool KMainWindow::canBeRestored( int number )
{
/*US we do not have and want to save sessioninformation. Use info from the default
application config.
*/
//US if ( !kapp->isRestored() )
//US return FALSE;
//US KConfig *config = kapp->sessionConfig();
KConfig *config = KGlobal::config();
if ( !config )
return FALSE;
config->setGroup( QString::fromLatin1("Number") );
int n = config->readNumEntry( QString::fromLatin1("NumberOfWindows") , 1 );
return number >= 1 && number <= n;
}
const QString KMainWindow::classNameOfToplevel( int number )
{
/*US we do not have and want to save sessioninformation. Use info from the default
application config.
*/
//US if ( !kapp->isRestored() )
//US return QString::null;
//US KConfig *config = kapp->sessionConfig();
KConfig *config = KGlobal::config();
if ( !config )
return QString::null;
QString s;
s.setNum( number );
s.prepend( QString::fromLatin1("WindowProperties") );
config->setGroup( s );
if ( !config->hasKey( QString::fromLatin1("ClassName") ) )
return QString::null;
else
return config->readEntry( QString::fromLatin1("ClassName") );
}
bool KMainWindow::restore( int number, bool show )
{
/*US we do not have and want to save sessioninformation. Use info from the default
application config.
*/
if ( !canBeRestored( number ) )
return FALSE;
//US KConfig *config = kapp->sessionConfig();
KConfig *config = KGlobal::config();
if ( readPropertiesInternal( config, number ) ){
if ( show )
KMainWindow::show();
return FALSE;
}
return FALSE;
}
void KMainWindow::setCaption( const QString &caption )
{
//US setPlainCaption( kapp->makeStdCaption(caption) );
setPlainCaption( caption );
}
void KMainWindow::setCaption( const QString &caption, bool modified )
{
//US setPlainCaption( kapp->makeStdCaption(caption, true, modified) );
setPlainCaption( caption + "modified:" );
}
void KMainWindow::setPlainCaption( const QString &caption )
{
QMainWindow::setCaption( caption );
#ifndef Q_WS_QWS
//US the following is disabled for the embedded version
//US NETWinInfo info( qt_xdisplay(), winId(), qt_xrootwin(), 0 );
//US info.setName( caption.utf8().data() );
#endif
}
void KMainWindow::slotStateChanged(const QString &newstate)
{
stateChanged(newstate, KXMLGUIClient::StateNoReverse);
}
/*
* Get rid of this for KDE 4.0
*/
void KMainWindow::slotStateChanged(const QString &newstate,
KXMLGUIClient::ReverseStateChange reverse)
{
stateChanged(newstate, reverse);
}
void KMainWindow::closeEvent ( QCloseEvent *e )
{
+ //qDebug("MainWindow::closeEvent ");
// Save settings if auto-save is enabled, and settings have changed
if (d->settingsDirty && d->autoSaveSettings)
saveAutoSaveSettings();
if (queryClose()) {
e->accept();
int not_withdrawn = 0;
/*US
QPtrListIterator<KMainWindow> it(*KMainWindow::memberList);
for (it.toFirst(); it.current(); ++it){
if ( !it.current()->isHidden() && it.current()->isTopLevel() && it.current() != this )
not_withdrawn++;
}
*/
if ( !no_query_exit && not_withdrawn <= 0 ) { // last window close accepted?
/*US
if ( queryExit() && !kapp->sessionSaving()) { // Yes, Quit app?
// don't call queryExit() twice
disconnect(kapp, SIGNAL(shutDown()), this, SLOT(shuttingDown()));
kapp->deref(); // ...and quit aplication.
} else {
// cancel closing, it's stupid to end up with no windows at all....
e->ignore();
}
*/
//US we have no sessionmanagement. Simply close app.
if ( queryExit() ) { // Yes, Quit app?
qDebug("KMainWindow::closeEvent: Exit application ???");
// don't call queryExit() twice
//US disconnect(kapp, SIGNAL(shutDown()), this, SLOT(shuttingDown()));
}
}
}
}
bool KMainWindow::queryExit()
{
return TRUE;
}
bool KMainWindow::queryClose()
{
return TRUE;
}
void KMainWindow::saveGlobalProperties( KConfig* )
{
}
void KMainWindow::readGlobalProperties( KConfig* )
{
}
void KMainWindow::savePropertiesInternal( KConfig *config, int number )
{
bool oldASWS = d->autoSaveWindowSize;
d->autoSaveWindowSize = true; // make saveMainWindowSettings save the window size
QString s;
s.setNum(number);
s.prepend(QString::fromLatin1("WindowProperties"));
config->setGroup(s);
// store objectName, className, Width and Height for later restoring
// (Only useful for session management)
config->writeEntry(QString::fromLatin1("ObjectName"), name());
config->writeEntry(QString::fromLatin1("ClassName"), className());
saveMainWindowSettings(config); // Menubar, statusbar and Toolbar settings.
s.setNum(number);
config->setGroup(s);
saveProperties(config);
d->autoSaveWindowSize = oldASWS;
}
void KMainWindow::setStandardToolBarMenuEnabled( bool enable )
{
if ( enable )
{
if ( d->toolBarHandler )
return;
d->toolBarHandler = new KDEPrivate::ToolBarHandler( this );
/*US if ( factory() )
factory()->addClient( d->toolBarHandler );
*/
}
else
{
if ( !d->toolBarHandler )
return;
/*US
if ( factory() )
factory()->removeClient( d->toolBarHandler );
*/
delete d->toolBarHandler;
d->toolBarHandler = 0;
}
}
bool KMainWindow::isStandardToolBarMenuEnabled() const
{
return ( d->toolBarHandler != 0 );
}
void KMainWindow::createStandardStatusBarAction(){
if(!d->showStatusBarAction){
d->showStatusBarAction = KStdAction::showStatusbar(this, SLOT(setSettingsDirty()), actionCollection());
connect(d->showStatusBarAction, SIGNAL(toggled(bool)), statusBar(), SLOT(setShown(bool)));
if(internalStatusBar())
d->showStatusBarAction->setChecked(!internalStatusBar()->isHidden());
}
}
QToolBar *KMainWindow::tBar( )
{
if ( ! mQToolBar )
mQToolBar = new QToolBar( this );
return mQToolBar;
}
KToolBar *KMainWindow::toolBar( const char * name )
{
if (!name)
name = "mainToolBar";
KToolBar *tb = (KToolBar*)child( name, "KToolBar" );
if ( tb )
return tb;
bool honor_mode = (name == "mainToolBar");
/*US
if ( builderClient() )
return new KToolBar(this, name, honor_mode); // XMLGUI constructor
else
*/
return new KToolBar(this, Top, false, name, honor_mode ); // non-XMLGUI
}
QPtrListIterator<KToolBar> KMainWindow::toolBarIterator()
{
toolbarList.clear();
QPtrList<QToolBar> lst;
for ( int i = (int)QMainWindow::Unmanaged; i <= (int)Minimized; ++i ) {
lst = toolBars( (ToolBarDock)i );
for ( QToolBar *tb = lst.first(); tb; tb = lst.next() ) {
if ( !tb->inherits( "KToolBar" ) )
continue;
toolbarList.append( (KToolBar*)tb );
}
}
return QPtrListIterator<KToolBar>( toolbarList );
}
void KMainWindow::setAutoSaveSettings( const QString & groupName, bool saveWindowSize )
{
d->autoSaveSettings = true;
d->autoSaveGroup = groupName;
d->autoSaveWindowSize = saveWindowSize;
// Get notified when the user moves a toolbar around
//US connect( this, SIGNAL( dockWindowPositionChanged( QDockWindow * ) ),
//US this, SLOT( setSettingsDirty() ) );
connect( this, SIGNAL( toolBarPositionChanged(QToolBar *) ),
this, SLOT( setSettingsDirty() ) );
// Get default values
//US int scnum = QApplication::desktop()->screenNumber(parentWidget());
//US QRect desk = QApplication::desktop()->screenGeometry(scnum);
QRect desk = KGlobalSettings::desktopGeometry(0);
d->defaultWindowSize = QRect(desk.width(), width(), desk.height(), height());
// Now read the previously saved settings
applyMainWindowSettings( KGlobal::config(), groupName );
}
void KMainWindow::resetAutoSaveSettings()
{
d->autoSaveSettings = false;
if ( d->settingsTimer )
d->settingsTimer->stop();
}
bool KMainWindow::autoSaveSettings() const
{
return d->autoSaveSettings;
}
QString KMainWindow::autoSaveGroup() const
{
return d->autoSaveGroup;
}
void KMainWindow::saveAutoSaveSettings()
{
ASSERT( d->autoSaveSettings );
//kdDebug(200) << "KMainWindow::saveAutoSaveSettings -> saving settings" << endl;
saveMainWindowSettings( KGlobal::config(), d->autoSaveGroup );
KGlobal::config()->sync();
d->settingsDirty = false;
if ( d->settingsTimer )
d->settingsTimer->stop();
}
void KMainWindow::createGUI( const QString &xmlfile, bool _conserveMemory )
{
// disabling the updates prevents unnecessary redraws
setUpdatesEnabled( false );
// just in case we are rebuilding, let's remove our old client
//US guiFactory()->removeClient( this );
// make sure to have an empty GUI
QMenuBar* mb = internalMenuBar();
if ( mb )
mb->clear();
(void)toolBarIterator(); // make sure toolbarList is most-up-to-date
toolbarList.setAutoDelete( true );
toolbarList.clear();
toolbarList.setAutoDelete( false );
/*US
// don't build a help menu unless the user ask for it
if (d->showHelpMenu) {
// we always want a help menu
if (helpMenu2 == 0)
helpMenu2 = new KHelpMenu(this, instance()->aboutData(), true,
actionCollection());
}
// we always want to load in our global standards file
setXMLFile( locate( "config", "ui/ui_standards.rc", instance() ) );
// now, merge in our local xml file. if this is null, then that
// means that we will be only using the global file
if ( !xmlfile.isNull() ) {
setXMLFile( xmlfile, true );
} else {
QString auto_file(instance()->instanceName() + "ui.rc");
setXMLFile( auto_file, true );
}
// make sure we don't have any state saved already
setXMLGUIBuildDocument( QDomDocument() );
// do the actual GUI building
guiFactory()->addClient( this );
// try and get back *some* of our memory
if ( _conserveMemory )
{
// before freeing the memory allocated by the DOM document we also
// free all memory allocated internally in the KXMLGUIFactory for
// the menubar and the toolbars . This however implies that we
// have to take care of deleting those widgets ourselves. For
// destruction this is no problem, but when rebuilding we have
// to take care of that (and we want to rebuild the GUI when
// using stuff like the toolbar editor ).
// In addition we have to take care of not removing containers
// like popupmenus, defined in the XML document.
// this code should probably go into a separate method in KMainWindow.
// there's just one problem: I'm bad in finding names ;-) , so
// I skipped this ;-)
QDomDocument doc = domDocument();
QDomElement e = doc.documentElement().firstChild().toElement();
for (; !e.isNull(); e = e.nextSibling().toElement() ) {
if ( e.tagName().lower() == "toolbar" )
factory_->resetContainer( e.attribute( "name" ) );
else if ( e.tagName().lower() == "menubar" )
factory_->resetContainer( e.tagName(), true );
}
conserveMemory();
}
*/
setUpdatesEnabled( true );
updateGeometry();
}
void KMainWindow::saveMainWindowSettings(KConfig *config, const QString &configGroup)
{
kdDebug(200) << "KMainWindow::saveMainWindowSettings " << configGroup << endl;
//US QStrList entryList;
QStringList entryList;
QString oldGroup;
if (!configGroup.isEmpty())
{
oldGroup = config->group();
config->setGroup(configGroup);
}
// Called by session management - or if we want to save the window size anyway
if ( d->autoSaveWindowSize )
saveWindowSize( config );
QStatusBar* sb = internalStatusBar();
if (sb) {
entryList.clear();
if ( sb->isHidden() )
entryList.append("Disabled");
else
entryList.append("Enabled");
if(sb->isHidden())
//US config->writeEntry(QString::fromLatin1("StatusBar"), entryList, ';');
config->writeEntry(QString::fromLatin1("StatusBar"), entryList);
else
config->deleteEntry(QString::fromLatin1("StatusBar"));
}
QMenuBar* mb = internalMenuBar();
if (mb) {
entryList.clear();
if ( mb->isHidden() )
entryList.append("Disabled");
else
entryList.append("Enabled");
// By default we don't hide.
if(mb->isHidden())
//US config->writeEntry(QString::fromLatin1("MenuBar"), entryList, ';');
config->writeEntry(QString::fromLatin1("MenuBar"), entryList);
else
config->deleteEntry(QString::fromLatin1("MenuBar"));
}
int n = 1; // Toolbar counter. toolbars are counted from 1,
KToolBar *toolbar = 0;
QPtrListIterator<KToolBar> it( toolBarIterator() );
while ( ( toolbar = it.current() ) ) {
++it;
QString group;
if (!configGroup.isEmpty())
{
// Give a number to the toolbar, but prefer a name if there is one,
// because there's no real guarantee on the ordering of toolbars
group = (!::qstrcmp(toolbar->name(), "unnamed") ? QString::number(n) : QString(" ")+toolbar->name());
group.prepend(" Toolbar");
group.prepend(configGroup);
}
toolbar->saveSettings(config, group);
n++;
}
if (!configGroup.isEmpty())
config->setGroup(oldGroup);
}
bool KMainWindow::readPropertiesInternal( KConfig *config, int number )
{
if ( number == 1 )
readGlobalProperties( config );
// in order they are in toolbar list
QString s;
s.setNum(number);
s.prepend(QString::fromLatin1("WindowProperties"));
config->setGroup(s);
// restore the object name (window role)
if ( config->hasKey(QString::fromLatin1("ObjectName" )) )
setName( config->readEntry(QString::fromLatin1("ObjectName")).latin1()); // latin1 is right here
applyMainWindowSettings(config); // Menubar, statusbar and toolbar settings.
s.setNum(number);
config->setGroup(s);
readProperties(config);
return true;
}
void KMainWindow::applyMainWindowSettings(KConfig *config, const QString &configGroup)
{
kdDebug(200) << "KMainWindow::applyMainWindowSettings" << endl;
QString entry;
//US QStrList entryList;
QStringList entryList;
int i = 0; // Number of entries in list
if (!configGroup.isEmpty())
config->setGroup(configGroup);
restoreWindowSize(config);
QStatusBar* sb = internalStatusBar();
if (sb) {
entryList.clear();
//US i = config->readListEntry (QString::fromLatin1("StatusBar"), entryList, ';');
entryList = config->readListEntry (QString::fromLatin1("StatusBar"));
entry = entryList.first();
if (entry == QString::fromLatin1("Disabled"))
sb->hide();
else
sb->show();
if(d->showStatusBarAction)
d->showStatusBarAction->setChecked(!sb->isHidden());
}
QMenuBar* mb = internalMenuBar();
if (mb) {
entryList.clear();
//US i = config->readListEntry (QString::fromLatin1("MenuBar"), entryList, ';');
entryList = config->readListEntry (QString::fromLatin1("MenuBar"));
entry = entryList.first();
if (entry==QString::fromLatin1("Disabled"))
{
mb->hide();
} else
{
mb->show();
}
}
int n = 1; // Toolbar counter. toolbars are counted from 1,
KToolBar *toolbar;
QPtrListIterator<KToolBar> it( toolBarIterator() ); // must use own iterator
for ( ; it.current(); ++it) {
toolbar= it.current();
QString group;
if (!configGroup.isEmpty())
{
// Give a number to the toolbar, but prefer a name if there is one,
// because there's no real guarantee on the ordering of toolbars
group = (!::qstrcmp(toolbar->name(), "unnamed") ? QString::number(n) : QString(" ")+toolbar->name());
group.prepend(" Toolbar");
group.prepend(configGroup);
}
toolbar->applySettings(config, group);
n++;
}
finalizeGUI( true );
}
void KMainWindow::finalizeGUI( bool force )
{
//kdDebug(200) << "KMainWindow::finalizeGUI force=" << force << endl;
// The whole reason for this is that moveToolBar relies on the indexes
// of the other toolbars, so in theory it should be called only once per
// toolbar, but in increasing order of indexes.
// Since we can't do that immediately, we move them, and _then_
// we call positionYourself again for each of them, but this time
// the toolbariterator should give them in the proper order.
// Both the XMLGUI and applySettings call this, hence "force" for the latter.
QPtrListIterator<KToolBar> it( toolBarIterator() );
for ( ; it.current() ; ++ it )
it.current()->positionYourself( force );
d->settingsDirty = false;
}
void KMainWindow::saveWindowSize( KConfig * config ) const
{
/*US
int scnum = QApplication::desktop()->screenNumber(parentWidget());
QRect desk = QApplication::desktop()->screenGeometry(scnum);
*/
QRect desk = KGlobalSettings::desktopGeometry(0);
QRect size( desk.width(), width(), desk.height(), height() );
if(size != d->defaultWindowSize){
config->writeEntry(QString::fromLatin1("Width %1").arg(desk.width()), width() );
config->writeEntry(QString::fromLatin1("Height %1").arg(desk.height()), height() );
}
else{
config->deleteEntry(QString::fromLatin1("Width %1").arg(desk.width()));
config->deleteEntry(QString::fromLatin1("Height %1").arg(desk.height()));
}
}
void KMainWindow::restoreWindowSize( KConfig * config )
{
if (d->care_about_geometry) {
parseGeometry(true);
} else {
// restore the size
/*US int scnum = QApplication::desktop()->screenNumber(parentWidget());
QRect desk = QApplication::desktop()->screenGeometry(scnum);
*/
QRect desk = KGlobalSettings::desktopGeometry(0);
QSize size( config->readNumEntry( QString::fromLatin1("Width %1").arg(desk.width()), 0 ),
config->readNumEntry( QString::fromLatin1("Height %1").arg(desk.height()), 0 ) );
if (size.isEmpty()) {
// try the KDE 2.0 way
size = QSize( config->readNumEntry( QString::fromLatin1("Width"), 0 ),
config->readNumEntry( QString::fromLatin1("Height"), 0 ) );
if (!size.isEmpty()) {
// make sure the other resolutions don't get old settings
config->writeEntry( QString::fromLatin1("Width"), 0 );
config->writeEntry( QString::fromLatin1("Height"), 0 );
}
}
if ( !size.isEmpty() )
resize( size );
}
}
bool KMainWindow::initialGeometrySet() const
{
return d->care_about_geometry;
}
void KMainWindow::ignoreInitialGeometry()
{
d->care_about_geometry = false;
}
void KMainWindow::setSettingsDirty()
{
//kdDebug(200) << "KMainWindow::setSettingsDirty" << endl;
d->settingsDirty = true;
if ( d->autoSaveSettings )
{
// Use a timer to save "immediately" user-wise, but not too immediately
// (to compress calls and save only once, in case of multiple changes)
if ( !d->settingsTimer )
{
d->settingsTimer = new QTimer( this );
connect( d->settingsTimer, SIGNAL( timeout() ), SLOT( saveAutoSaveSettings() ) );
}
d->settingsTimer->start( 500, true );
}
}
bool KMainWindow::settingsDirty() const
{
return d->settingsDirty;
}
QString KMainWindow::settingsGroup() const
{
return d->autoSaveGroup;
}
void KMainWindow::resizeEvent( QResizeEvent * )
{
if ( d->autoSaveWindowSize )
setSettingsDirty();
}
bool KMainWindow::hasMenuBar()
{
return (internalMenuBar());
}
//US KMenuBar *KMainWindow::menuBar()
QMenuBar *KMainWindow::menuBar()
{
//US KMenuBar * mb = internalMenuBar();
QMenuBar * mb = internalMenuBar();
if ( !mb ) {
//US mb = new KMenuBar( this );
mb = new QMenuBar( this );
// trigger a re-layout and trigger a call to the private
// setMenuBar method.
QMainWindow::menuBar();
}
return mb;
}
//US KStatusBar *KMainWindow::statusBar()
QStatusBar *KMainWindow::statusBar()
{
//US KStatusBar * sb = internalStatusBar();
QStatusBar * sb = internalStatusBar();
if ( !sb ) {
//US sb = new KStatusBar( this );
sb = new QStatusBar( this );
// trigger a re-layout and trigger a call to the private
// setStatusBar method.
QMainWindow::statusBar();
}
return sb;
}
void KMainWindow::shuttingDown()
{
// Needed for Qt <= 3.0.3 at least to prevent reentrancy
// when queryExit() shows a dialog. Check before removing!
static bool reentrancy_protection = false;
if (!reentrancy_protection)
{
reentrancy_protection = true;
// call the virtual queryExit
queryExit();
reentrancy_protection = false;
}
}
//US KMenuBar *KMainWindow::internalMenuBar()
QMenuBar *KMainWindow::internalMenuBar()
{
//US QObjectList *l = queryList( "KMenuBar", 0, false, false );
QObjectList *l = queryList( "QMenuBar", 0, false, false );
if ( !l || !l->first() ) {
delete l;
return 0;
}
//US KMenuBar *m = (KMenuBar*)l->first();
QMenuBar *m = (QMenuBar*)l->first();
delete l;
return m;
}
//US KStatusBar *KMainWindow::internalStatusBar()
QStatusBar *KMainWindow::internalStatusBar()
{
//US QObjectList *l = queryList( "KStatusBar", 0, false, false );
QObjectList *l = queryList( "QStatusBar", 0, false, false );
if ( !l || !l->first() ) {
delete l;
return 0;
}
//US KStatusBar *s = (KStatusBar*)l->first();
QStatusBar *s = (QStatusBar*)l->first();
delete l;
return s;
}
void KMainWindow::childEvent( QChildEvent* e)
{
QMainWindow::childEvent( e );
}
void KMainWindow::paintEvent( QPaintEvent * )
{
// do nothing
}
QSize KMainWindow::sizeForCentralWidgetSize(QSize size)
{
KToolBar *tb = (KToolBar*)child( "mainToolBar", "KToolBar" );
if (tb && !tb->isHidden()) {
switch( tb->barPos() )
{
case KToolBar::Top:
case KToolBar::Bottom:
size += QSize(0, tb->sizeHint().height());
break;
case KToolBar::Left:
case KToolBar::Right:
size += QSize(toolBar()->sizeHint().width(), 0);
break;
case KToolBar::Flat:
//US size += QSize(0, 3+kapp->style().pixelMetric( QStyle::PM_DockWindowHandleExtent ));
size += QSize(0, tb->sizeHint().height());
break;
default:
break;
}
}
//US KMenuBar *mb = menuBar();
QMenuBar *mb = menuBar();
if (!mb->isHidden()) {
size += QSize(0,mb->heightForWidth(size.width()));
/*US if (style().styleHint(QStyle::SH_MainWindow_SpaceBelowMenuBar, this))
size += QSize( 0, dockWindowsMovable() ? 1 : 2);
*/
size += QSize( 0, 2);
}
QStatusBar *sb = internalStatusBar();
if( sb && !sb->isHidden() )
size += QSize(0, sb->sizeHint().height());
return size;
}
// why do we support old gcc versions? using KXMLGUIBuilder::finalizeGUI;
void KMainWindow::finalizeGUI( KXMLGUIClient *client )
{ /*US KXMLGUIBuilder::finalizeGUI( client );*/ }
void KMainWindow::virtual_hook( int id, void* data )
{ /*US KXMLGUIBuilder::virtual_hook( id, data );*/
KXMLGUIClient::virtual_hook( id, data ); }
diff --git a/microkde/kdeui/kmainwindow.h b/microkde/kdeui/kmainwindow.h
index e76e732..2aafb9d 100644
--- a/microkde/kdeui/kmainwindow.h
+++ b/microkde/kdeui/kmainwindow.h
@@ -1,776 +1,777 @@
/*
This file is part of the KDE libraries
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2 as published by the Free Software Foundation.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
$Id$
*/
#ifndef KMAINWINDOW_H
#define KMAINWINDOW_H
/*US
#include "kxmlguifactory.h"
#include "kxmlguiclient.h"
#include "kxmlguibuilder.h"
#include <qmetaobject.h>
class KPopupMenu;
class KXMLGUIFactory;
class KConfig;
class KHelpMenu;
class KStatusBar;
class QStatusBar;
class KMenuBar;
class KMWSessionManaged;
class KAccel;
class KToolBarMenuAction;
*/
class QMenuBar;
class QStatusBar;
class KMainWindowPrivate;
class KAction;
#include <ktoolbar.h>
#include <ktoolbarhandler.h>
#include <kxmlguiclient.h>
#include <qmainwindow.h>
#include <qptrlist.h>
class KActionCollection;
class KMainWindow : public QMainWindow, virtual public KXMLGUIClient
{
Q_OBJECT
private:
//US create private defaultconstructor
KMainWindow() {;};
-public:
+
public:
/**
* Construct a main window.
*
* @param parent The widget parent. This is usually 0 but it may also be the window
* group leader. In that case, the KMainWindow becomes sort of a
* secondary window.
*
* @param name The object name. For session management and window management to work
* properly, all main windows in the application should have a
* different name. When passing 0 (the default), KMainWindow will create
* a unique name, but it's recommended to explicitly pass a window name that will
* also describe the type of the window. If there can be several windows of the same
* type, append '#' (hash) to the name, and KMainWindow will append numbers to make
* the names unique. For example, for a mail client which has one main window showing
* the mails and folders, and which can also have one or more windows for composing
* mails, the name for the folders window should be e.g. "mainwindow" and
* for the composer windows "composer#".
*
* @param f Specify the widget flags. The default is
* WType_TopLevel and WDestructiveClose. TopLevel indicates that a
* main window is a toplevel window, regardless of whether it has a
* parent or not. DestructiveClose indicates that a main window is
* automatically destroyed when its window is closed. Pass 0 if
* you do not want this behavior.
*
* KMainWindows must be created on the heap with 'new', like:
* <pre> KMainWindow *kmw = new KMainWindow (...</pre>
**/
- KMainWindow( QWidget* parent = 0, const char *name = 0, WFlags f = WType_TopLevel | WDestructiveClose );
+ //LR remove WDestructiveClose
+ KMainWindow( QWidget* parent = 0, const char *name = 0, WFlags f = WType_TopLevel /*| WDestructiveClose*/ );
/**
* Destructor.
*
* Will also destroy the toolbars, and menubar if
* needed.
*/
virtual ~KMainWindow();
/**
* Retrieve the standard help menu.
*
* It contains entires for the
* help system (activated by F1), an optional "What's This?" entry
* (activated by Shift F1), an application specific dialog box,
* and an "About KDE" dialog box.
*
* Example (adding a standard help menu to your application):
* <pre>
* KPopupMenu *help = helpMenu( <myTextString> );
* menuBar()->insertItem( i18n("&Help"), help );
* </pre>
*
* @param aboutAppText The string that is used in the application
* specific dialog box. If you leave this string empty the
* information in the global @ref KAboutData of the
* application will be used to make a standard dialog box.
*
* @param showWhatsThis Set this to false if you do not want to include
* the "What's This" menu entry.
*
* @return A standard help menu.
*/
//US KPopupMenu* helpMenu( const QString &aboutAppText = QString::null,
//US bool showWhatsThis = TRUE );
/**
* Returns the help menu. Creates a standard help menu if none exists yet.
*
* It contains entries for the
* help system (activated by F1), an optional "What's This?" entry
* (activated by Shift F1), an application specific dialog box,
* and an "About KDE" dialog box. You must create the application
* specific dialog box yourself. When the "About application"
* menu entry is activated, a signal will trigger the
* @ref showAboutApplication slot. See @ref showAboutApplication for more
* information.
*
* Example (adding a help menu to your application):
* <pre>
* menuBar()->insertItem( i18n("&Help"), customHelpMenu() );
* </pre>
*
* @param showWhatsThis Set this to @p false if you do not want to include
* the "What's This" menu entry.
*
* @return A standard help menu.
*/
//US KPopupMenu* customHelpMenu( bool showWhatsThis = TRUE );
/**
* @sect Session Management
*
* Try to restore the toplevel widget as defined by the number (1..X).
*
* If the session did not contain so high a number, the configuration
* is not changed and @p false returned.
*
* That means clients could simply do the following:
* <pre>
* if (kapp->isRestored()){
* int n = 1;
* while (KMainWindow::canBeRestored(n)){
* (new childMW)->restore(n);
* n++;
* }
* } else {
* // create default application as usual
* }
* </pre>
* Note that @ref QWidget::show() is called implicitly in restore.
*
* With this you can easily restore all toplevel windows of your
* application.
*
* If your application uses different kinds of toplevel
* windows, then you can use @ref KMainWindow::classNameOfToplevel(n)
* to determine the exact type before calling the childMW
* constructor in the example from above.
*
* If your client has only one kind of toplevel widgets (which
* should be pretty usual) then you should use the RESTORE-macro
* for backwards compatibility with 3.1 and 3.0 branches:
*
* <pre>
* if (kapp->isRestored())
* RESTORE(childMW)
* else {
* // create default application as usual
* }
* </pre>
*
* The macro expands to the term above but is easier to use and
* less code to write.
*
* For new code or if you have more than one kind of toplevel
* widget (each derived from @ref KMainWindow, of course), you can
* use the templated @ref kRestoreMainWindows global functions:
*
* <pre>
* if (kapp->isRestored())
* kRestoreMainWindows< childMW1, childMW2, childMW3 >();
* else {
* // create default application as usual
* }
* </pre>
*
* Currently, these functions are provided for up to three
* template arguments. If you need more, tell us. To help you in
* deciding whether or not you can use @ref kRestoreMainWindows, a
* define KDE_RESTORE_MAIN_WINDOWS_NUM_TEMPLATE_ARGS is provided.
*
* @see restore()
* @see classNameOfToplevel()
*
**/
static bool canBeRestored( int number );
/**
* Returns the @ref className() of the @p number of the toplevel window which
* should be restored.
*
* This is only useful if your application uses
* different kinds of toplevel windows.
*/
static const QString classNameOfToplevel( int number );
/**
* Restore the session specified by @p number.
*
* Returns @p false if this
* fails, otherwise returns @p true and shows the window.
* You should call @ref canBeRestored() first.
* If @p show is true (default), this widget will be shown automatically.
*/
bool restore( int number, bool show = TRUE );
//US virtual KXMLGUIFactory *guiFactory();
/**
* Create a GUI given a local XML file.
*
* If @p xmlfile is NULL,
* then it will try to construct a local XML filename like
* appnameui.rc where 'appname' is your app's name. If that file
* does not exist, then the XML UI code will only use the global
* (standard) XML file for the layout purposes.
*
* Note that when passing true for the conserveMemory argument subsequent
* calls to guiFactory()->addClient/removeClient may not work as expected.
* Also retrieving references to containers like popup menus or toolbars using
* the container method will not work.
*
* @param xmlfile The local xmlfile (relative or absolute)
* @param _conserveMemory Specify whether createGUI() should call
* @ref KXMLGuiClient::conserveMemory() to free all memory
* allocated by the @ref QDomDocument and by the KXMLGUIFactory.
*/
void createGUI( const QString &xmlfile = QString::null, bool _conserveMemory = TRUE );
/**
* Enables the build of a standard help menu when calling createGUI().
*
* The default behavior is to build one, you must call this function
* to disable it
*/
void setHelpMenuEnabled(bool showHelpMenu = true);
/**
* Return @p true when the help menu is enabled
*/
bool isHelpMenuEnabled();
/**
* Returns true, if there is a menubar
* @since 3.1
*/
bool hasMenuBar();
/**
* Returns a pointer to the menu bar.
*
* If there is no menu bar yet one will be created.
**/
//US KMenuBar *menuBar();
QMenuBar *menuBar();
/**
* Returns a pointer to the status bar.
*
* If there is no
* status bar yet one will be created.
*/
//US KStatusBar *statusBar();
QStatusBar *statusBar();
/**
* List of members of KMainWindow class.
*/
//US static QPtrList<KMainWindow>* memberList;
/**
* Returns a pointer to the toolbar with the specified name.
* This refers to toolbars created dynamically from the XML UI
* framework. If the toolbar does not exist one will be created.
*
* @param name The internal name of the toolbar. If no name is
* specified "mainToolBar" is assumed.
*
* @return A pointer to the toolbar
**/
KToolBar *toolBar( const char *name=0 );
// method for getting rid of KDE-Crap
QToolBar *tBar( );
/**
* @return An iterator over the list of all toolbars for this window.
*/
QPtrListIterator<KToolBar> toolBarIterator();
/**
* @return A KAccel instance bound to this mainwindow. Used automatically
* by KAction to make keybindings work in all cases.
*/
KAccel *accel();
void setFrameBorderWidth( int ) {}
/**
* Call this to enable "auto-save" of toolbar/menubar/statusbar settings
* (and optionally window size).
* If the *bars were moved around/shown/hidden when the window is closed,
* saveMainWindowSettings( KGlobal::config(), groupName ) will be called.
*
* @param groupName a name that identifies this "type of window".
* You can have several types of window in the same application.
*
* @param saveWindowSize set it to true to include the window size
* when saving.
*
* Typically, you will call setAutoSaveSettings() in your
* KMainWindow-inherited class constructor, and it will take care
* of restoring and saving automatically. Make sure you call this
* _after all_ your *bars have been created.
*/
void setAutoSaveSettings( const QString & groupName = QString::fromLatin1("MainWindow"),
bool saveWindowSize = true );
/**
* Disable the auto-save-settings feature.
* You don't normally need to call this, ever.
*/
void resetAutoSaveSettings();
/**
* @return the current autosave setting, i.e. true if setAutoSaveSettings() was called,
* false by default or if resetAutoSaveSettings() was called.
* @since 3.1
*/
bool autoSaveSettings() const;
/**
* @return the group used for setting-autosaving.
* Only meaningful if setAutoSaveSettings() was called.
* This can be useful for forcing a save or an apply, e.g. before and after
* using KEditToolbar.
* @since 3.1
*/
QString autoSaveGroup() const;
/**
* Read settings for statusbar, menubar and toolbar from their respective
* groups in the config file and apply them.
*
* @param config Config file to read the settings from.
* @param groupName Group name to use. If not specified, the last used
* group name is used.
*/
void applyMainWindowSettings(KConfig *config, const QString &groupName = QString::null);
/**
* Save settings for statusbar, menubar and toolbar to their respective
* groups in the config file @p config.
*
* @param config Config file to save the settings to.
* @param groupName Group name to use. If not specified, the last used
* group name is used
*/
void saveMainWindowSettings(KConfig *config, const QString &groupName = QString::null);
/**
* Sets whether KMainWindow should provide a menu that allows showing/hiding
* the available toolbars ( using @ref KToggleToolBarAction ) . In case there
* is only one toolbar configured a simple 'Show <toolbar name here>' menu item
* is shown.
*
* The menu / menu item is implemented using xmlgui. It will be inserted in your
* menu structure in the 'Settings' menu.
*
* If your application uses a non-standard xmlgui resource file then you can
* specify the exact position of the menu / menu item by adding a
* &lt;Merge name="StandardToolBarMenuHandler" /&gt;
* line to the settings menu section of your resource file ( usually appname.rc ).
*
* Note that you should enable this feature before calling createGUI() ( or similar ) .
* You enable/disable it anytime if you pass false to the conserveMemory argument of createGUI.
* @since 3.1
*/
void setStandardToolBarMenuEnabled( bool enable );
/// @since 3.1
bool isStandardToolBarMenuEnabled() const;
/**
* Sets whether KMainWindow should provide a menu that allows showing/hiding
* of the statusbar ( using @ref KToggleStatusBarAction ).
*
* The menu / menu item is implemented using xmlgui. It will be inserted
* in your menu structure in the 'Settings' menu.
*
* Note that you should enable this feature before calling createGUI()
* ( or similar ).
*
* If an application maintains the action on its own (i.e. never calls
* this function) a connection needs to be made to let KMainWindow
* know when that status (hidden/shown) of the statusbar has changed.
* For example:
* connect(action, SIGNAL(activated()),
* kmainwindow, SLOT(setSettingsDirty()));
* Otherwise the status (hidden/show) of the statusbar might not be saved
* by KMainWindow.
* @since 3.2
*/
void createStandardStatusBarAction();
/**
* Returns a pointer to the mainwindows action responsible for the toolbars menu
* @since 3.1
*/
KAction *toolBarMenuAction();
// why do we support old gcc versions? using KXMLGUIBuilder::finalizeGUI;
/// @since 3.1
virtual void finalizeGUI( KXMLGUIClient *client );
/**
* @internal
*/
void finalizeGUI( bool force );
/**
* @return true if a -geometry argument was given on the command line,
* and this is the first window created (the one on which this option applies)
*/
bool initialGeometrySet() const;
/**
* @internal
* Used from Konqueror when reusing the main window.
*/
void ignoreInitialGeometry();
/**
* @return the size the mainwindow should have so that the central
* widget will be of @p size.
*/
QSize sizeForCentralWidgetSize(QSize size);
public slots:
/**
* Makes a KDE compliant caption.
*
* @param caption Your caption. @em Do @em not include the application name
* in this string. It will be added automatically according to the KDE
* standard.
*/
virtual void setCaption( const QString &caption );
/**
* Makes a KDE compliant caption.
*
* @param caption Your caption. @em Do @em not include the application name
* in this string. It will be added automatically according to the KDE
* standard.
* @param modified Specify whether the document is modified. This displays
* an additional sign in the title bar, usually "**".
*/
virtual void setCaption( const QString &caption, bool modified );
/**
* Make a plain caption without any modifications.
*
* @param caption Your caption. This is the string that will be
* displayed in the window title.
*/
virtual void setPlainCaption( const QString &caption );
/**
* Open the help page for the application.
*
* The application name is
* used as a key to determine what to display and the system will attempt
* to open <appName>/index.html.
*
* This method is intended for use by a help button in the toolbar or
* components outside the regular help menu. Use @ref helpMenu() when you
* want to provide access to the help system from the help menu.
*
* Example (adding a help button to the first toolbar):
*
* <pre>
* KIconLoader &loader = *KGlobal::iconLoader();
* QPixmap pixmap = loader.loadIcon( "help" );
* toolBar(0)->insertButton( pixmap, 0, SIGNAL(clicked()),
* this, SLOT(appHelpActivated()), true, i18n("Help") );
* </pre>
*
*/
//US void appHelpActivated( void );
/**
* Apply a state change
*
* Enable and disable actions as defined in the XML rc file
* @since 3.1
*/
virtual void slotStateChanged(const QString &newstate);
/**
* Apply a state change
*
* Enable and disable actions as defined in the XML rc file,
* can "reverse" the state (disable the actions which should be
* enabled, and vice-versa) if specified.
* @since 3.1
*/
void slotStateChanged(const QString &newstate,
KXMLGUIClient::ReverseStateChange); // KDE 4.0: remove this
/**
* Apply a state change
*
* Enable and disable actions as defined in the XML rc file,
* can "reverse" the state (disable the actions which should be
* enabled, and vice-versa) if specified.
*/
// void slotStateChanged(const QString &newstate,
// bool reverse); // KDE 4.0: enable this
/**
* Tell the main window that it should save its settings when being closed.
* This is part of the auto-save-settings feature.
* For everything related to toolbars this happens automatically,
* but you have to call setSettingsDirty() in the slot that toggles
* the visibility of the statusbar.
*/
void setSettingsDirty();
protected:
void paintEvent( QPaintEvent* e );
void childEvent( QChildEvent* e);
void resizeEvent( QResizeEvent* e);
/**
* Reimplemented to call the queryClose() and queryExit() handlers.
*
* We recommend that you reimplement the handlers rather than @ref closeEvent().
* If you do it anyway, ensure to call the base implementation to keep
* @ref queryExit() running.
*/
virtual void closeEvent ( QCloseEvent *);
// KDE4 This seems to be flawed to me. Either the app has only one
// mainwindow, so queryClose() is enough, or if it can have more of them,
// then the windows should take care of themselves, and queryExit()
// would be useful only for the annoying 'really quit' dialog, which
// also doesn't make sense in apps with multiple mainwindows.
// And saving configuration in something called queryExit()? IMHO
// one can e.g. use KApplication::shutDown(), which if nothing else
// has at least better fitting name.
// See also KApplication::sessionSaving().
// This stuff should get changed somehow, so that it at least doesn't
// mess with session management.
/**
Called before the very last window is closed, either by the
user or indirectly by the session manager.
It is not recommended to do any user interaction in this
function other than indicating severe errors. Better ask the
user on @ref queryClose() (see below).
A typical usage of @ref queryExit() is to write configuration data back.
Note that the application may continue to run after @ref queryExit()
(the user may have cancelled a shutdown), so you should not do any cleanups
here. The purpose of @ref queryExit() is purely to prepare the application
(with possible user interaction) so it can safely be closed later (without
user interaction).
If you need to do serious things on exit (like shutting a
dial-up connection down), connect to the signal
@ref KApplication::shutDown().
Default implementation returns @p true. Returning @p false will
cancel the exiting. In the latter case, the last window will
remain visible. If KApplication::sessionSaving() is true, refusing
the exit will also cancel KDE logout.
@see queryClose()
@see KApplication::sessionSaving()
*/
virtual bool queryExit();
/**
Called before the window is closed, either by the user or indirectly by
the session manager.
The purpose of this function is to prepare the window in a way that it is
safe to close it, i.e. without the user losing some data.
Default implementation returns true. Returning @p false will cancel
the closing, and, if KApplication::sessionSaving() is true, it will also
cancel KDE logout.
Reimplement this function to prevent the user from losing data.
Example:
<pre>
switch ( KMessageBox::warningYesNoCancel( this,
i18n("Save changes to document foo?")) ) {
case KMessageBox::Yes :
// save document here. If saving fails, return FALSE;
return TRUE;
case KMessageBox::No :
return TRUE;
default: // cancel
return FALSE;
</pre>
@see queryExit()
@see KApplication::sessionSaving()
*/
virtual bool queryClose();
/**
* Save your instance-specific properties. The function is
* invoked when the session manager requests your application
* to save its state.
*
* You @em must @em not change the group of the @p kconfig object, since
* KMainWindow uses one group for each window. Please
* reimplement these function in childclasses.
*
* Note: No user interaction is allowed
* in this function!
*
*/
virtual void saveProperties( KConfig* ) {}
/**
* Read your instance-specific properties.
*/
virtual void readProperties( KConfig* ) {}
/**
* Save your application-wide properties. The function is
* invoked when the session manager requests your application
* to save its state.
*
* This function is similar to @ref saveProperties() but is only called for
* the very first main window, regardless how many main window are open.
* Override it if you need to save other data about your documents on
* session end. sessionConfig is a config to which that data should be
* saved. Normally, you don't need this function. But if you want to save
* data about your documents that are not in opened windows you might need
* it.
*
* Default implementation does nothing.
*/
virtual void saveGlobalProperties( KConfig* sessionConfig );
/**
* The counterpart of @ref saveGlobalProperties().
*
* Read the application-specific properties in again.
*/
virtual void readGlobalProperties( KConfig* sessionConfig );
void savePropertiesInternal( KConfig*, int );
bool readPropertiesInternal( KConfig*, int );
/**
* For inherited classes
*/
bool settingsDirty() const;
/**
* For inherited classes
*/
QString settingsGroup() const;
/**
* For inherited classes
* Note that the group must be set before calling
*/
void saveWindowSize( KConfig * config ) const;
/**
* For inherited classes
* Note that the group must be set before calling, and that
* a -geometry on the command line has priority.
*/
void restoreWindowSize( KConfig * config );
/// parse the geometry from the geometry command line argument
void parseGeometry(bool parsewidth);
protected slots:
/**
* This slot does nothing.
*
* It must be reimplemented if you want
* to use a custom About Application dialog box. This slot is
* connected to the About Application entry in the menu returned
* by @ref customHelpMenu.
*
* Example:
* <pre>
*
* void MyMainLevel::setupInterface()
* {
* ..
* menuBar()->insertItem( i18n("&Help"), customHelpMenu() );
* ..
* }
*
* void MyMainLevel::showAboutApplication()
* {
* <activate your custom dialog>
* }
* </pre>
*/
//US virtual void showAboutApplication();
private slots:
/**
* Called when the app is shutting down.
*/
void shuttingDown();
void saveAutoSaveSettings();
private:
QToolBar * mQToolBar;
//US KMenuBar *internalMenuBar();
QMenuBar *internalMenuBar();
//US KStatusBar *internalStatusBar();
QStatusBar *internalStatusBar();
KMainWindowPrivate *d;
void initKMainWindow(const char *name);
QPtrList<KToolBar> toolbarList;
protected:
virtual void virtual_hook( int id, void* data );
};
#endif
diff --git a/pwmanager/pwmanager/getmasterpwwnd_emb.cpp b/pwmanager/pwmanager/getmasterpwwnd_emb.cpp
index 8404c3e..678f05f 100644
--- a/pwmanager/pwmanager/getmasterpwwnd_emb.cpp
+++ b/pwmanager/pwmanager/getmasterpwwnd_emb.cpp
@@ -1,208 +1,208 @@
/*
This file is part of PwManager/Platform independent.
Copyright (c) 2004 Ulf Schenk
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
As a special exception, permission is given to link this program
with any edition of Qt, and distribute the resulting executable,
without including the source code for Qt in the source distribution.
$Id$
*/
#include "getmasterpwwnd_emb.h"
#include "klocale.h"
/*
#include <qvariant.h>
#include <qpushbutton.h>
#include <qlabel.h>
#include <qlineedit.h>
#include <qlayout.h>
#include <qtooltip.h>
#include <qwhatsthis.h>
*/
#include <qwidget.h>
#include <qlayout.h>
#include <qlabel.h>
#include <qlineedit.h>
#include <qpushbutton.h>
#include <qapplication.h>
/*
* Constructs a getMasterPwWnd as a child of 'parent', with the
* name 'name'
*/
getMasterPwWnd::getMasterPwWnd( QWidget* parent, const char* name)
: KDialogBase( KDialogBase::Plain, i18n( "Master-password" ),
KDialogBase::Ok | KDialogBase::Cancel,
KDialogBase::Ok, parent, name, true )
{
QWidget *page = plainPage();
QVBoxLayout *pageLayout = new QVBoxLayout( page );
pwLineEdit = new QLineEdit( page, "pwLineEdit" );
pwLineEdit->setEchoMode( QLineEdit::Password );
QLabel* textLabel1 = new QLabel( pwLineEdit, i18n("Please enter the master-password:"), page, "textLabel1" );
textLabel1->setAlignment( int( QLabel::WordBreak | QLabel::AlignCenter ) );
pageLayout->addWidget(textLabel1);
pageLayout->addWidget(pwLineEdit);
QWidget* numberBox = new QWidget( page );
#ifndef DESKTOP_VERSION
if ( QApplication::desktop()->width() > 320 ) {
numberBox->setFixedHeight(250);
numberBox->setFixedWidth(200);
}
else{
numberBox->setFixedHeight(150);
numberBox->setFixedWidth(150);
}
#endif
QGridLayout* numberLayout = new QGridLayout( numberBox, 4, 3 );
numberLayout->setMargin( 0 );
numberLayout->setSpacing( 0 );
QPushButton* p1 = new QPushButton( i18n("1"), numberBox );
numberLayout->addWidget( p1, 0, 0 );
QPushButton* p2 = new QPushButton( i18n("2"), numberBox );
numberLayout->addWidget( p2, 0, 1 );
QPushButton* p3 = new QPushButton( i18n("3"), numberBox );
numberLayout->addWidget( p3, 0, 2 );
QPushButton* p4 = new QPushButton( i18n("4"), numberBox );
numberLayout->addWidget( p4, 1, 0 );
QPushButton* p5 = new QPushButton( i18n("5"), numberBox );
numberLayout->addWidget( p5, 1, 1 );
QPushButton* p6 = new QPushButton( i18n("6"), numberBox );
numberLayout->addWidget( p6, 1, 2 );
QPushButton* p7 = new QPushButton( i18n("7"), numberBox );
numberLayout->addWidget( p7, 2, 0 );
QPushButton* p8 = new QPushButton( i18n("8"), numberBox );
numberLayout->addWidget( p8, 2, 1 );
QPushButton* p9 = new QPushButton( i18n("9"), numberBox );
numberLayout->addWidget( p9, 2, 2 );
QPushButton* clear = new QPushButton( i18n("x"), numberBox );
numberLayout->addWidget( clear, 3, 0 );
QPushButton* p0 = new QPushButton( i18n("0"), numberBox );
numberLayout->addWidget( p0, 3, 1 );
QPushButton* backspace = new QPushButton( i18n("-"), numberBox );
numberLayout->addWidget( backspace, 3, 2 );
pageLayout->addWidget(numberBox);
#ifdef DESKTOP_VERSION
resize( sizeHint() );
#else
resize( 200,sizeHint().height() );
#endif
connect( p0, SIGNAL( clicked() ), this, SLOT( add0() ) );
connect( p1, SIGNAL( clicked() ), this, SLOT( add1() ) );
connect( p2, SIGNAL( clicked() ), this, SLOT( add2() ) );
connect( p3, SIGNAL( clicked() ), this, SLOT( add3() ) );
connect( p4, SIGNAL( clicked() ), this, SLOT( add4() ) );
connect( p5, SIGNAL( clicked() ), this, SLOT( add5() ) );
connect( p6, SIGNAL( clicked() ), this, SLOT( add6() ) );
connect( p7, SIGNAL( clicked() ), this, SLOT( add7() ) );
connect( p8, SIGNAL( clicked() ), this, SLOT( add8() ) );
connect( p9, SIGNAL( clicked() ), this, SLOT( add9() ) );
connect( backspace, SIGNAL( clicked() ), this, SLOT( backspace() ) );
connect( clear, SIGNAL( clicked() ), this, SLOT( clear() ) );
-
+ pwLineEdit->setFocus();
}
/*
* Destroys the object and frees any allocated resources
*/
getMasterPwWnd::~getMasterPwWnd()
{
// no need to delete child widgets, Qt does it all for us
}
void getMasterPwWnd::okButton_slot()
{
qWarning( "getMasterPwWnd::okButton_slot(): Not implemented yet" );
}
void getMasterPwWnd::cancelButton_slot()
{
qWarning( "getMasterPwWnd::cancelButton_slot(): Not implemented yet" );
}
void getMasterPwWnd::add0()
{
addCharacter("0");
}
void getMasterPwWnd::add1()
{
addCharacter("1");
}
void getMasterPwWnd::add2()
{
addCharacter("2");
}
void getMasterPwWnd::add3()
{
addCharacter("3");
}
void getMasterPwWnd::add4()
{
addCharacter("4");
}
void getMasterPwWnd::add5()
{
addCharacter("5");
}
void getMasterPwWnd::add6()
{
addCharacter("6");
}
void getMasterPwWnd::add7()
{
addCharacter("7");
}
void getMasterPwWnd::add8()
{
addCharacter("8");
}
void getMasterPwWnd::add9()
{
addCharacter("9");
}
void getMasterPwWnd::backspace()
{
QString old = pwLineEdit->text();
old.truncate(old.length()-1);
pwLineEdit->setText(old);
}
void getMasterPwWnd::clear()
{
pwLineEdit->setText("");
}
void getMasterPwWnd::addCharacter(const QString& s)
{
QString old = pwLineEdit->text();
pwLineEdit->setText(old + s);
}
diff --git a/pwmanager/pwmanager/kcmconfigs/pwmconfigwidget.cpp b/pwmanager/pwmanager/kcmconfigs/pwmconfigwidget.cpp
index 26b9708..a8696ea 100644
--- a/pwmanager/pwmanager/kcmconfigs/pwmconfigwidget.cpp
+++ b/pwmanager/pwmanager/kcmconfigs/pwmconfigwidget.cpp
@@ -1,351 +1,351 @@
/*
This file is part of KAddressBook.
Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
As a special exception, permission is given to link this program
with any edition of Qt, and distribute the resulting executable,
without including the source code for Qt in the source distribution.
*/
#include <qcheckbox.h>
#include <qframe.h>
#include <qgroupbox.h>
#include <qlayout.h>
#include <qpushbutton.h>
#include <qtabwidget.h>
#include <qcombobox.h>
#include <qlineedit.h>
#include <qspinbox.h>
#include <qlabel.h>
#include <qfile.h>
#include <qvbox.h>
#include <kconfig.h>
#include <kdebug.h>
#include <kdialog.h>
#include <klistview.h>
#include <klocale.h>
#include <kglobal.h>
#include <kmessagebox.h>
#include <kstandarddirs.h>
#include <kio/kfile/kurlrequester.h>
#include "pwmprefs.h"
#include "pwmconfigwidget.h"
#include "pwmexception.h"
PWMConfigWidget::PWMConfigWidget(PWMPrefs *prefs, QWidget *parent, const char *name )
: KPrefsWidget(prefs, parent, name )
{
QVBoxLayout *topLayout = new QVBoxLayout( this, 0,
KDialog::spacingHint() );
QTabWidget *tabWidget = new QTabWidget( this );
topLayout->addWidget( tabWidget );
// windowsStyle page
//////////////////////////////////////////////////////
QWidget *windowStylePage = new QWidget( this );
QGridLayout *windowStyleLayout = new QGridLayout( windowStylePage, 3, 3);
int i = 0;
KPrefsWidRadios * windowStyle = addWidRadios(i18n("Window-style:") ,&(prefs->mMainViewStyle), windowStylePage);
windowStyle->addRadio(i18n("Category on top"));
windowStyle->addRadio(i18n("Category-list left/top"));
windowStyleLayout->addMultiCellWidget( (QWidget*)windowStyle->groupBox(),i,i,0,2);
++i;
QLabel* lab = new QLabel(i18n("<b>Font for Password entries:</b>"), windowStylePage);
windowStyleLayout->addMultiCellWidget( lab,i,i,0,2);
++i;
KPrefsWidFont *selEntrFont =
addWidFont(i18n("Password"),i18n("Font:"),
&(prefs->mEntryFont),windowStylePage);
windowStyleLayout->addWidget(selEntrFont->label(),i,0);
windowStyleLayout->addWidget(selEntrFont->preview(),i,1);
windowStyleLayout->addWidget(selEntrFont->button(),i,2);
++i;
lab = new QLabel(i18n(""), windowStylePage);
windowStyleLayout->addMultiCellWidget( lab,i,i,0,2);
// File page
//////////////////////////////////////////////////////
QWidget *filePage = new QWidget( this );
QGridLayout *fileLayout = new QGridLayout( filePage, 3, 2);
i = 0;
QLabel* kcfg_compression_label = new QLabel(i18n("Compression:"), filePage);
fileLayout->addWidget(kcfg_compression_label,i,0);
kcfg_compression = new QComboBox(filePage, "kcfg_compression");
kcfg_compression->insertItem(i18n("None"));
kcfg_compression->insertItem(i18n("gzip"));
//US not yet supported: kcfg_compression->insertItem(i18n("bzip2"));
fileLayout->addWidget( kcfg_compression,i,1);
++i;
QLabel* kcfg_crypt_label = new QLabel(i18n("Encryption:"), filePage);
fileLayout->addWidget(kcfg_crypt_label,i,0);
kcfg_cryptAlgo = new QComboBox(filePage, "kcfg_cryptAlgo");
kcfg_cryptAlgo->insertItem(i18n("Blowfish (128 bit)"));
#ifdef CONFIG_PWMANAGER_GCRY
kcfg_cryptAlgo->insertItem(i18n("AES-128, Rijndael (128 bit)"));
kcfg_cryptAlgo->insertItem(i18n("AES-192, Rijndael (192 bit)"));
kcfg_cryptAlgo->insertItem(i18n("AES-256, Rijndael (256 bit)"));
kcfg_cryptAlgo->insertItem(i18n("Triple-DES (168 bit)"));
kcfg_cryptAlgo->insertItem(i18n("Twofish (256 bit)"));
kcfg_cryptAlgo->insertItem(i18n("Twofish-128 (128 bit)"));
#endif // CONFIG_PWMANAGER_GCRY
fileLayout->addWidget( kcfg_cryptAlgo,i,1);
++i;
QLabel* kcfg_hash_label = new QLabel(i18n("Hashing:"), filePage);
fileLayout->addWidget(kcfg_hash_label,i,0);
kcfg_hashAlgo = new QComboBox(filePage, "kcfg_hashAlgo");
kcfg_hashAlgo->insertItem(i18n("SHA-160, SHA1 (160 bit)"));
#ifdef CONFIG_PWMANAGER_GCRY
kcfg_hashAlgo->insertItem(i18n("SHA-256 (256 bit)"));
kcfg_hashAlgo->insertItem(i18n("SHA-384 (384 bit)"));
kcfg_hashAlgo->insertItem(i18n("SHA-512 (512 bit)"));
kcfg_hashAlgo->insertItem(i18n("MD5 (128 bit)"));
kcfg_hashAlgo->insertItem(i18n("RIPE-MD-160 (160 bit)"));
kcfg_hashAlgo->insertItem(i18n("Tiger (192 bit)"));
#endif // CONFIG_PWMANAGER_GCRY
fileLayout->addWidget( kcfg_hashAlgo,i,1);
++i;
permissionLineEdit = new QLineEdit(filePage);
QLabel* permissionLineLabel = new QLabel(permissionLineEdit, i18n("Permissions:"), filePage);
fileLayout->addWidget(permissionLineLabel,i,0);
fileLayout->addWidget(permissionLineEdit,i,1);
++i;
KPrefsWidBool *sb = addWidBool(i18n("Make backup before saving"),
&(prefs->mMakeFileBackup),filePage);
fileLayout->addMultiCellWidget(sb->checkBox(), i,i,0,1);
++i;
// Timeout page
//////////////////////////////////////////////////////
QWidget *timeoutPage = new QWidget( this );
QGridLayout *timeoutLayout = new QGridLayout( timeoutPage, 3, 2);
i = 0;
- pwTimeoutSpinBox = new QSpinBox( timeoutPage, "pwTimeoutSpinBox" );
+ pwTimeoutSpinBox = new QSpinBox( 0,600,10,timeoutPage, "pwTimeoutSpinBox" );
QLabel* timeoutLabel = new QLabel(pwTimeoutSpinBox, i18n("Password timeout\n(timeout to hold password in\nmemory,so you don't have to\nre-enter it,if you\nalready have entered it)\n[set to 0 to disable]:"), timeoutPage);
timeoutLayout->addMultiCellWidget(timeoutLabel,i, i, 0 ,0);
timeoutLayout->addWidget(pwTimeoutSpinBox,i,1);
++i;
- lockTimeoutSpinBox = new QSpinBox( timeoutPage, "lockTimeoutSpinBox" );
+ lockTimeoutSpinBox = new QSpinBox( 0,600,10,timeoutPage, "lockTimeoutSpinBox" );
QLabel* lockTimeoutLabel = new QLabel(lockTimeoutSpinBox, i18n("Auto-lock timeout\n(auto lock document after this\namount of seconds)\n[set to 0 to disable]:"), timeoutPage);
timeoutLayout->addMultiCellWidget(lockTimeoutLabel,i, i, 0 ,0);
timeoutLayout->addWidget(lockTimeoutSpinBox,i,1);
++i;
sb = addWidBool(i18n("deep-lock on autolock"),
&(prefs->mAutoDeeplock),timeoutPage);
timeoutLayout->addMultiCellWidget(sb->checkBox(), i,i,0,1);
++i;
// Autostart page
//////////////////////////////////////////////////////
QWidget *autostartPage = new QWidget( this );
QGridLayout *autostartLayout = new QGridLayout( autostartPage, 3, 2);
i = 0;
autostartLineEdit = new KURLRequester(autostartPage, "autoStartLineEdit");
QLabel* autostartLineLabel = new QLabel(autostartLineEdit, "Open this file automatically on startup:",autostartPage);
autostartLayout->addMultiCellWidget(autostartLineLabel,i,i,0,1);
++i;
autostartLayout->addMultiCellWidget(autostartLineEdit,i,i,0,1);
++i;
sb = addWidBool(i18n("open deeplocked"),
&(prefs->mAutostartDeeplocked),autostartPage);
autostartLayout->addMultiCellWidget(sb->checkBox(), i,i,0,1);
++i;
// external app page
//////////////////////////////////////////////////////
QWidget *externalappPage = new QWidget( this );
QGridLayout *externalappLayout = new QGridLayout( externalappPage, 3, 2);
i = 0;
browserLineEdit = new QLineEdit(externalappPage);
QLabel* browserLineLabel = new QLabel(browserLineEdit, i18n("Favourite browser:"), externalappPage);
externalappLayout->addWidget(browserLineLabel,i,0);
externalappLayout->addWidget(browserLineEdit,i,1);
++i;
xtermLineEdit = new QLineEdit(externalappPage);
QLabel* xtermLineLabel = new QLabel(xtermLineEdit, i18n("Favourite x-terminal:"), externalappPage);
externalappLayout->addWidget(xtermLineLabel,i,0);
externalappLayout->addWidget(xtermLineEdit,i,1);
++i;
// miscelaneous page
//////////////////////////////////////////////////////
QWidget *miscPage = new QWidget( this );
QGridLayout *miscLayout = new QGridLayout( miscPage, 3, 2);
i = 0;
/*US ENH: PWM/Pi has no tray and con be minimized
sb = addWidBool(i18n("Show icon in system-tray"),&(prefs->mTray),miscPage);
miscLayout->addMultiCellWidget(sb->checkBox(), i,i,0,1);
++i;
*/
sb = addWidBool(i18n("Open document with passwords unlocked"),&(prefs->mUnlockOnOpen),miscPage);
miscLayout->addMultiCellWidget(sb->checkBox(), i,i,0,1);
++i;
/*US ENH: PWM/Pi has no tray and con be minimized
sb = addWidBool(i18n("auto-minimize to tray on startup"),&(prefs->mAutoMinimizeOnStart),miscPage);
miscLayout->addMultiCellWidget(sb->checkBox(), i,i,0,1);
++i;
KPrefsWidRadios * minimizeRadio = addWidRadios(i18n("auto-lock on minimize:") ,&(prefs->mMinimizeLock), miscPage);
minimizeRadio->addRadio(i18n("don't lock"));
minimizeRadio->addRadio(i18n("normal lock"));
minimizeRadio->addRadio(i18n("deep-lock"));
miscLayout->addMultiCellWidget( (QWidget*)minimizeRadio->groupBox(),i,i,0,2);
++i;
sb = addWidBool(i18n("KWallet emulation"),&(prefs->mKWalletEmu),miscPage);
miscLayout->addMultiCellWidget(sb->checkBox(), i,i,0,1);
++i;
sb = addWidBool(i18n("Close instead Minimize into tray"),&(prefs->mClose),miscPage);
miscLayout->addMultiCellWidget(sb->checkBox(), i,i,0,1);
++i;
*/
tabWidget->addTab( windowStylePage, i18n( "Look && feel" ) );
tabWidget->addTab( filePage, i18n( "File" ) );
tabWidget->addTab( timeoutPage, i18n( "Timeout" ) );
tabWidget->addTab( autostartPage, i18n( "Autostart" ) );
tabWidget->addTab( externalappPage, i18n( "External apps" ) );
tabWidget->addTab( miscPage, i18n( "Miscellaneous" ) );
connect( permissionLineEdit, SIGNAL( textChanged(const QString&) ), this, SLOT( modified() ) );
connect( pwTimeoutSpinBox, SIGNAL( valueChanged(int) ), this, SLOT( modified() ) );
connect( lockTimeoutSpinBox, SIGNAL( valueChanged(int) ), this, SLOT( modified() ) );
connect( autostartLineEdit, SIGNAL( textChanged(const QString&) ), this, SLOT( modified() ) );
connect( browserLineEdit, SIGNAL( textChanged(const QString&) ), this, SLOT( modified() ) );
connect( xtermLineEdit, SIGNAL( textChanged(const QString&) ), this, SLOT( modified() ) );
}
void PWMConfigWidget::usrReadConfig()
{
PWMPrefs* prefs = PWMPrefs::instance();
setFilePermissions(prefs->mFilePermissions);
pwTimeoutSpinBox->setValue(prefs->mPwTimeout);
lockTimeoutSpinBox->setValue(prefs->mLockTimeout);
autostartLineEdit->setURL(prefs->mAutoStart);
browserLineEdit->setText(prefs->mBrowserCommand);
xtermLineEdit->setText(prefs->mXTermCommand);
kcfg_compression->setCurrentItem(prefs->mCompression);
kcfg_cryptAlgo->setCurrentItem(prefs->mCryptAlgo);
kcfg_hashAlgo->setCurrentItem(prefs->mHashAlgo);
}
void PWMConfigWidget::usrWriteConfig()
{
PWMPrefs* prefs = PWMPrefs::instance();
prefs->mFilePermissions = getFilePermissions();
prefs->mPwTimeout = pwTimeoutSpinBox->value();
prefs->mLockTimeout = lockTimeoutSpinBox->value();
prefs->mAutoStart = autostartLineEdit->url();
prefs->mBrowserCommand = browserLineEdit->text();
prefs->mXTermCommand = xtermLineEdit->text();
prefs->mCompression = kcfg_compression->currentItem();
prefs->mCryptAlgo = kcfg_cryptAlgo->currentItem();
prefs->mHashAlgo = kcfg_hashAlgo->currentItem();
}
int PWMConfigWidget::getFilePermissions()
{
char octalDigits[] = "01234567";
bool isOctal;
QString permString(permissionLineEdit->text());
int i, j, length = permString.length();
if (length != 3) {
printWarn("Wrong permission string length! Please enter "
"the string like the following example: 600");
return CONF_DEFAULT_FILEPERMISSIONS;
}
for (i = 0; i < length; ++i) {
isOctal = false;
for (j = 0; j < 8; ++j) {
if (permString.at(i) == octalDigits[j]) {
isOctal = true;
break;
}
}
if (!isOctal) {
printWarn("CONFIG: File-permissions: This is "
"not an octal number ");
return CONF_DEFAULT_FILEPERMISSIONS;
}
}
int ret = strtol(permString.latin1(), 0, 8);
if (ret == 0) {
/* either an error occured, or the user did really type 000 */
printWarn("CONFIG: File-permissions: Hm, either conversion error, "
"or you really typed 000. 8-)");
return CONF_DEFAULT_FILEPERMISSIONS;
}
return ret;
}
void PWMConfigWidget::setFilePermissions(int perm)
{
char tmpBuf[30];
sprintf(tmpBuf, "%o", perm);
permissionLineEdit->setText(tmpBuf);
}
#ifndef PWM_EMBEDDED
#include "pwmconfigwidget.moc"
#endif //PWM_EMBEDDED
diff --git a/pwmanager/pwmanager/libgcryptif.cpp b/pwmanager/pwmanager/libgcryptif.cpp
index eafd318..ff94bf6 100644
--- a/pwmanager/pwmanager/libgcryptif.cpp
+++ b/pwmanager/pwmanager/libgcryptif.cpp
@@ -1,449 +1,454 @@
/***************************************************************************
* *
* copyright (C) 2004 by Michael Buesch *
* email: mbuesch@freenet.de *
* *
* hashPassphrase() is derived from GnuPG and is *
* Copyright (C) 1998, 1999, 2000, 2001, 2003 *
* Free Software Foundation, Inc. *
* *
* 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 "libgcryptif.h"
#ifdef CONFIG_PWMANAGER_GCRY
#include "pwmdoc.h"
#include "randomizer.h"
#include <gcrypt.h>
#ifdef PWM_EMBEDDED
#include <pwmprefs.h>
#endif
PwMerror LibGCryptIf::encrypt(unsigned char **outBuf,
size_t *outBufLen,
unsigned char *inBuf,
size_t inBufLen,
const unsigned char *key,
size_t keylen,
char _algo)
{
PwMerror ret = e_success;
gcry_error_t err;
gcry_cipher_hd_t handle;
size_t blklen;
size_t unpaddedLen = inBufLen;
size_t cipherKeylen;
unsigned char *hashedKey;
unsigned char salt[STRING2KEY_SALTLEN];
int algo = mapCipherId(_algo);
if (!inBufLen || !keylen)
return e_invalidArg;
// test if algo is ready for encryption
err = gcry_cipher_algo_info(algo,
GCRYCTL_TEST_ALGO,
0, 0);
if (err != GPG_ERR_NO_ERROR) {
printDebug(string("LibGCryptIf::doEncrypt(): GCRYCTL_TEST_ALGO failed: ")
+ gcry_strerror(err));
ret = e_cryptNotImpl;
goto out;
}
// get the algo block length
err = gcry_cipher_algo_info(algo,
GCRYCTL_GET_BLKLEN,
0,
&blklen);
if (err != GPG_ERR_NO_ERROR) {
printDebug(string("LibGCryptIf::doEncrypt(): GCRYCTL_GET_BLKLEN failed: ")
+ gcry_strerror(err));
ret = e_cryptNotImpl;
goto out;
}
/* double check if we have enough space.
* We have only 1024 extra bytes for padding and salt.
*/
BUG_ON(blklen > 1024 - STRING2KEY_SALTLEN);
// get the algo key length
err = gcry_cipher_algo_info(algo,
GCRYCTL_GET_KEYLEN,
0,
&cipherKeylen);
if (err != GPG_ERR_NO_ERROR) {
printDebug(string("LibGCryptIf::doEncrypt(): GCRYCTL_GET_KEYLEN failed: ")
+ gcry_strerror(err));
ret = e_cryptNotImpl;
goto out;
}
// now open the algo and get a handle
err = gcry_cipher_open(&handle,
algo,
GCRY_CIPHER_MODE_CBC,
0);
if (err != GPG_ERR_NO_ERROR) {
printDebug(string("LibGCryptIf::doEncrypt(): gcry_cipher_open() failed: ")
+ gcry_strerror(err));
ret = e_cryptNotImpl;
goto out;
}
// hash the "key" to a fixed size hash matching "cipherKeylen"
hashedKey = new unsigned char[cipherKeylen];
hashPassphrase(key, keylen, salt, hashedKey, cipherKeylen, true);
// so now set the hashed key
err = gcry_cipher_setkey(handle, hashedKey, cipherKeylen);
if (err != GPG_ERR_NO_ERROR) {
printDebug(string("LibGCryptIf::doEncrypt(): gcry_cipher_setkey() failed: ")
+ gcry_strerror(err));
ret = e_cryptNotImpl;
delete [] hashedKey;
goto out_close;
}
delete [] hashedKey;
/* allocate a buffer for the encrypted data.
* The size of the buffer is the inBuf length, but blklen
* aligned and plus the length of the salt, that is appended.
*/
*outBufLen = getBufLen(unpaddedLen, blklen) + STRING2KEY_SALTLEN;
*outBuf = new unsigned char[*outBufLen];
padData(inBuf, unpaddedLen, blklen);
// encrypt the padded data
err = gcry_cipher_encrypt(handle,
*outBuf,
*outBufLen - STRING2KEY_SALTLEN,
inBuf,
*outBufLen - STRING2KEY_SALTLEN);
if (err != GPG_ERR_NO_ERROR) {
printDebug(string("LibGCryptIf::doEncrypt(): gcry_cipher_encrypt() failed: ")
+ gcry_strerror(err));
ret = e_cryptNotImpl;
goto out_delete;
}
// append the salt to the encrypted data
memcpy(*outBuf + *outBufLen - STRING2KEY_SALTLEN, salt, STRING2KEY_SALTLEN);
goto out_close;
out_delete:
delete [] *outBuf;
out_close:
gcry_cipher_close(handle);
out:
return ret;
}
PwMerror LibGCryptIf::decrypt(unsigned char **outBuf,
size_t *outBufLen,
const unsigned char *inBuf,
size_t inBufLen,
const unsigned char *key,
size_t keylen,
char _algo)
{
PwMerror ret = e_success;
gcry_error_t err;
gcry_cipher_hd_t handle;
size_t cipherKeylen;
unsigned char *hashedKey;
unsigned char salt[STRING2KEY_SALTLEN];
int algo = mapCipherId(_algo);
if (!inBufLen || !keylen)
return e_invalidArg;
// test if algo is ready for encryption
err = gcry_cipher_algo_info(algo,
GCRYCTL_TEST_ALGO,
0, 0);
if (err != GPG_ERR_NO_ERROR) {
printDebug(string("LibGCryptIf::doDecrypt(): GCRYCTL_TEST_ALGO failed: ")
+ gcry_strerror(err));
ret = e_cryptNotImpl;
goto out;
}
// get algo key length
err = gcry_cipher_algo_info(algo,
GCRYCTL_GET_KEYLEN,
0,
&cipherKeylen);
if (err != GPG_ERR_NO_ERROR) {
printDebug(string("LibGCryptIf::doDecrypt(): GCRYCTL_GET_KEYLEN failed: ")
+ gcry_strerror(err));
ret = e_cryptNotImpl;
goto out;
}
// extract the salt of the encrypted data buffer
memcpy(salt, inBuf + inBufLen - STRING2KEY_SALTLEN, STRING2KEY_SALTLEN);
// open the algo and get a handle
err = gcry_cipher_open(&handle,
algo,
GCRY_CIPHER_MODE_CBC,
0);
if (err != GPG_ERR_NO_ERROR) {
printDebug(string("LibGCryptIf::doDecrypt(): gcry_cipher_open() failed: ")
+ gcry_strerror(err));
ret = e_cryptNotImpl;
goto out;
}
// hash the "key" to a fixed size hash matching "cipherKeylen"
hashedKey = new unsigned char[cipherKeylen];
hashPassphrase(key, keylen, salt, hashedKey, cipherKeylen, false);
// so now set the hashed key
err = gcry_cipher_setkey(handle, hashedKey, cipherKeylen);
if (err != GPG_ERR_NO_ERROR) {
printDebug(string("LibGCryptIf::doDecrypt(): gcry_cipher_setkey() failed: ")
+ gcry_strerror(err));
ret = e_cryptNotImpl;
delete [] hashedKey;
goto out_close;
}
delete [] hashedKey;
*outBufLen = inBufLen - STRING2KEY_SALTLEN;
*outBuf = new unsigned char[*outBufLen];
// decrypt the data
err = gcry_cipher_decrypt(handle,
*outBuf,
*outBufLen,
inBuf,
*outBufLen);
if (err != GPG_ERR_NO_ERROR) {
printDebug(string("LibGCryptIf::doEncrypt(): gcry_cipher_encrypt() failed: ")
+ gcry_strerror(err));
ret = e_cryptNotImpl;
goto out_delete;
}
// remove all random padding
unpadData(*outBuf, outBufLen);
goto out_close;
out_delete:
delete [] *outBuf;
out_close:
gcry_cipher_close(handle);
out:
return ret;
}
PwMerror LibGCryptIf::hash(unsigned char **outBuf,
size_t *outBufLen,
const unsigned char *inBuf,
size_t inBufLen,
char _algo)
{
PwMerror ret = e_success;
unsigned int hashLen;
int algo = mapHashId(_algo);
hashLen = gcry_md_get_algo_dlen(algo);
*outBufLen = hashLen;
*outBuf = new unsigned char[*outBufLen];
gcry_md_hash_buffer(algo,
*outBuf,
inBuf,
inBufLen);
return ret;
}
unsigned int LibGCryptIf::hashLength(char _algo)
{
unsigned int ret;
int algo = mapHashId(_algo);
ret = gcry_md_get_algo_dlen(algo);
return ret;
}
int LibGCryptIf::mapCipherId(char algo)
{
switch (algo) {
case PWM_CRYPT_AES128:
return GCRY_CIPHER_AES;
case PWM_CRYPT_AES192:
return GCRY_CIPHER_AES192;
case PWM_CRYPT_AES256:
return GCRY_CIPHER_AES256;
case PWM_CRYPT_3DES:
return GCRY_CIPHER_3DES;
case PWM_CRYPT_TWOFISH:
return GCRY_CIPHER_TWOFISH;
case PWM_CRYPT_TWOFISH128:
return GCRY_CIPHER_TWOFISH128;
default:
BUG();
}
return GCRY_CIPHER_NONE;
}
int LibGCryptIf::mapHashId(char algo)
{
switch (algo) {
case PWM_HASH_SHA1:
return GCRY_MD_SHA1;
case PWM_HASH_SHA256:
return GCRY_MD_SHA256;
case PWM_HASH_SHA384:
return GCRY_MD_SHA384;
case PWM_HASH_SHA512:
return GCRY_MD_SHA512;
case PWM_HASH_MD5:
return GCRY_MD_MD5;
case PWM_HASH_RMD160:
return GCRY_MD_RMD160;
case PWM_HASH_TIGER:
return GCRY_MD_TIGER;
default:
BUG();
}
return GCRY_MD_NONE;
}
bool LibGCryptIf::hashPassphrase(const unsigned char *pw,
size_t pwlen,
unsigned char *salt,
unsigned char *key,
size_t keylen,
bool create)
{
DEK dek;
STRING2KEY s2k;
bool ret;
dek.keylen = keylen;
s2k.mode = 1;
s2k.hash_algo = mapHashId(conf()->confGlobHashAlgo());
s2k.count = 0;
if (!create)
memcpy(s2k.salt, salt, STRING2KEY_SALTLEN);
ret = doHashPassphrase(&dek,
pw,
pwlen,
&s2k,
create);
if (!ret)
goto out;
memcpy(key, dek.key, dek.keylen);
if (create)
memcpy(salt, s2k.salt, STRING2KEY_SALTLEN);
out:
return ret;
}
bool LibGCryptIf::doHashPassphrase(DEK *dek,
const unsigned char *pw,
size_t pwlen,
STRING2KEY *s2k,
bool create)
{
// This function is derived from GnuPG-1.2.5-rc2
gcry_md_hd_t md;
gcry_error_t err;
bool ret = true;
size_t pass, i;
size_t used = 0;
PWM_ASSERT(s2k->hash_algo);
BUG_ON(!(dek->keylen > 0 && dek->keylen <= array_size(dek->key)));
err = gcry_md_open(&md, s2k->hash_algo, 0);
if (err != GPG_ERR_NO_ERROR) {
ret = false;
goto out;
}
for (pass = 0; used < dek->keylen; pass++) {
if (pass) {
gcry_md_reset(md);
for (i = 0; i < pass; i++) // preset the hash context
gcry_md_putc(md, 0);
}
if (s2k->mode == 1 || s2k->mode == 3) {
size_t len2 = pwlen + 8;
size_t count = len2;
if (create && !pass) {
Randomizer *rnd = Randomizer::obj();
const unsigned int salt_len = 8;
string rndBuf(rnd->genRndBuf(salt_len));
memcpy(s2k->salt, rndBuf.c_str(), salt_len);
if (s2k->mode == 3)
s2k->count = 96; // 65536 iterations
}
if (s2k->mode == 3) {
count = (16ul + (s2k->count & 15)) << ((s2k->count >> 4) + 6);
if (count < len2)
count = len2;
}
// a little bit complicated because we need a ulong for count
while (count > len2) { // maybe iterated+salted
gcry_md_write(md, s2k->salt, 8);
gcry_md_write(md, pw, pwlen);
count -= len2;
}
if (count < 8) {
gcry_md_write(md, s2k->salt, count);
} else {
gcry_md_write(md, s2k->salt, 8);
count -= 8;
gcry_md_write(md, pw, count);
}
} else
gcry_md_write(md, pw, pwlen);
gcry_md_final(md);
i = gcry_md_get_algo_dlen(s2k->hash_algo);
if (i > dek->keylen - used)
i = dek->keylen - used;
memcpy(dek->key+used, gcry_md_read(md, s2k->hash_algo), i);
used += i;
}
gcry_md_close(md);
out:
return ret;
}
void LibGCryptIf::padData(unsigned char *buf,
size_t bufLen,
size_t boundary)
{
size_t numPadBytes = boundary - ((bufLen + 1) % boundary);
buf[bufLen] = static_cast<char>(0x01);
size_t i = 0;
Randomizer *rnd = Randomizer::obj();
char c;
unsigned char *b;
while (i < numPadBytes) {
c = rnd->genRndChar();
if (c == static_cast<char>(0x01))
continue;
b = buf + bufLen + 1 + i;
*b = c;
++i;
}
}
void LibGCryptIf::unpadData(const unsigned char *buf,
size_t *bufLen)
{
size_t pos;
BUG_ON(*bufLen % 8);
pos = *bufLen - 1;
while (buf[pos] != static_cast<char>(0x01)) {
+ qDebug("pos %d %d %d", pos, buf[pos], static_cast<char>(0x01) );
BUG_ON(!pos);
+ //LR BUG we should terminte the loop if p == 0
+ if ( pos == 0 )
+ break;
--pos;
}
*bufLen = pos;
+ qDebug("ente ");
}
#endif // CONFIG_PWMANAGER_GCRY
diff --git a/pwmanager/pwmanager/main.cpp b/pwmanager/pwmanager/main.cpp
index 1ca7ba8..70df15d 100644
--- a/pwmanager/pwmanager/main.cpp
+++ b/pwmanager/pwmanager/main.cpp
@@ -1,219 +1,220 @@
/***************************************************************************
* *
* 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_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
#ifdef WORDS_BIGENDIAN
cout << "Endianess 2: big-endian" << endl;
#else
cout << "Endianess 2: 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
*/
+ QObject::connect( &a, SIGNAL( lastWindowClosed()), &a, SLOT (quit()));
a.exec();
KPimGlobalPrefs::instance()->writeConfig();
}
qDebug("PWMPI: Bye! ");
#endif
}
diff --git a/pwmanager/pwmanager/pwm.cpp b/pwmanager/pwmanager/pwm.cpp
index 1ab2b71..2b8f2fa 100644
--- a/pwmanager/pwmanager/pwm.cpp
+++ b/pwmanager/pwmanager/pwm.cpp
@@ -1,1466 +1,1472 @@
/***************************************************************************
* *
* copyright (C) 2003, 2004 by Michael Buesch *
* email: mbuesch@freenet.de *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License version 2 *
* as published by the Free Software Foundation. *
* *
***************************************************************************/
/***************************************************************************
* copyright (C) 2004 by Ulf Schenk
* This file is originaly based on version 1.0.1 of pwmanager
* and was modified to run on embedded devices that run microkde
*
* $Id$
**************************************************************************/
#include <klocale.h>
#include <klistview.h>
#include <ktoolbar.h>
#include <kfiledialog.h>
#include <kiconloader.h>
#include <kmessagebox.h>
#include <qstatusbar.h>
#ifndef PWM_EMBEDDED
#include <kmenubar.h>
#include <kstatusbar.h>
#include <dcopclient.h>
#include "configwndimpl.h"
#include "configuration.h"
#else
#include <qmenubar.h>
#include <qmessagebox.h>
#include <pwmprefs.h>
#include <kpimglobalprefs.h>
#include <kcmconfigs/kcmpwmconfig.h>
#include <kcmconfigs/kcmkdepimconfig.h>
#include <kcmultidialog.h>
#endif
#ifndef DESKTOP_VERSION
#include <qpe/global.h>
#endif
#include <qpixmap.h>
#include <qcheckbox.h>
#include <qspinbox.h>
#include <qlineedit.h>
#include <qfileinfo.h>
#include <qclipboard.h>
#include <stdio.h>
#include "pwm.h"
#include "pwminit.h"
#include "pwmprint.h"
#include "addentrywndimpl.h"
#include "globalstuff.h"
#include "findwndimpl.h"
#include "csv.h"
#ifdef CONFIG_KWALLETIF
# include "kwalletif.h"
# include "kwalletemu.h"
#endif
#ifdef CONFIG_KEYCARD
# include "pwmkeycard.h"
#endif
#define DEFAULT_SIZE (QSize(700, 400))
// Button IDs for "file" popup menu
enum {
BUTTON_POPUP_FILE_NEW = 0,
BUTTON_POPUP_FILE_OPEN,
BUTTON_POPUP_FILE_CLOSE,
BUTTON_POPUP_FILE_SAVE,
BUTTON_POPUP_FILE_SAVEAS,
BUTTON_POPUP_FILE_EXPORT,
BUTTON_POPUP_FILE_IMPORT,
BUTTON_POPUP_FILE_PRINT,
BUTTON_POPUP_FILE_QUIT
};
// Button IDs for "manage" popup menu
enum {
BUTTON_POPUP_MANAGE_ADD = 0,
BUTTON_POPUP_MANAGE_EDIT,
BUTTON_POPUP_MANAGE_DEL,
BUTTON_POPUP_MANAGE_CHANGEMP
};
// Button IDs for chipcard popup menu
enum {
#ifdef CONFIG_KEYCARD
BUTTON_POPUP_CHIPCARD_GENNEW = 0,
BUTTON_POPUP_CHIPCARD_DEL,
BUTTON_POPUP_CHIPCARD_READID,
BUTTON_POPUP_CHIPCARD_SAVEBACKUP,
BUTTON_POPUP_CHIPCARD_REPLAYBACKUP
#else // CONFIG_KEYCARD
BUTTON_POPUP_CHIPCARD_NO = 0
#endif // CONFIG_KEYCARD
};
// Button IDs for "view" popup menu
enum {
BUTTON_POPUP_VIEW_FIND = 0,
BUTTON_POPUP_VIEW_LOCK,
BUTTON_POPUP_VIEW_DEEPLOCK,
BUTTON_POPUP_VIEW_UNLOCK
};
// Button IDs for "options" popup menu
enum {
BUTTON_POPUP_OPTIONS_CONFIG = 0
};
// Button IDs for "export" popup menu (in "file" popup menu)
enum {
BUTTON_POPUP_EXPORT_TEXT = 0,
BUTTON_POPUP_EXPORT_GPASMAN,
BUTTON_POPUP_EXPORT_CSV
#ifdef CONFIG_KWALLETIF
,BUTTON_POPUP_EXPORT_KWALLET
#endif
};
// Button IDs for "import" popup menu (in "file" popup menu)
enum {
BUTTON_POPUP_IMPORT_TEXT = 0,
BUTTON_POPUP_IMPORT_GPASMAN,
BUTTON_POPUP_IMPORT_CSV
#ifdef CONFIG_KWALLETIF
,BUTTON_POPUP_IMPORT_KWALLET
#endif
};
#ifdef PWM_EMBEDDED
// Button IDs for "help" popup menu
enum {
BUTTON_POPUP_HELP_LICENSE = 0,
BUTTON_POPUP_HELP_FAQ,
BUTTON_POPUP_HELP_ABOUT,
BUTTON_POPUP_HELP_SYNC,
BUTTON_POPUP_HELP_WHATSNEW
};
#endif
// Button IDs for toolbar
enum {
BUTTON_TOOL_NEW = 0,
BUTTON_TOOL_OPEN,
BUTTON_TOOL_SAVE,
BUTTON_TOOL_SAVEAS,
BUTTON_TOOL_PRINT,
BUTTON_TOOL_ADD,
BUTTON_TOOL_EDIT,
BUTTON_TOOL_DEL,
BUTTON_TOOL_FIND,
BUTTON_TOOL_LOCK,
BUTTON_TOOL_DEEPLOCK,
BUTTON_TOOL_UNLOCK
};
PwM::PwM(PwMInit *_init, PwMDoc *doc,
bool virginity,
QWidget *parent, const char *name)
: KMainWindow(parent, "HALLO")
, forceQuit (false)
, forceMinimizeToTray (false)
{
syncManager = 0;
virgin = !virginity;
init = _init;
connect(doc, SIGNAL(docClosed(PwMDoc *)),
this, SLOT(docClosed(PwMDoc *)));
initMenubar();
initToolbar();
initMetrics();
setVirgin(virginity);
setFocusPolicy(QWidget::WheelFocus);
#ifndef PWM_EMBEDDED
statusBar()->show();
#endif
view = makeNewListView(doc);
setCentralWidget(view);
updateCaption();
showStatMsg(i18n("Ready."));
}
PwM::~PwM()
{
- //qDebug("PwM::~PwM()");
+ qDebug("PwM::~PwM() %x", this);
disconnect(curDoc(), SIGNAL(docClosed(PwMDoc *)),
this, SLOT(docClosed(PwMDoc *)));
conf()->confWndMainWndSize(size());
- emit closed(this);
+ //LR closing of windows changed
+ //needed for fastload option on PDA
+ //emit closed(this);
//qDebug("PwM::~PwM() emited closed(this)");
delete view;
delete syncManager;
}
void PwM::initMenubar()
{
KIconLoader* picons;
#ifndef PWM_EMBEDDED
KIconLoader icons;
picons = &icons;
#else
picons = KGlobal::iconLoader();
syncPopup = new KPopupMenu(this);
syncManager = new KSyncManager((QWidget*)this, (KSyncInterface*)this, KSyncManager::PWMPI, PWMPrefs::instance(), syncPopup);
syncManager->setBlockSave(false);
connect ( syncPopup, SIGNAL( activated ( int ) ), syncManager, SLOT (slotSyncMenu( int ) ) );
syncManager->fillSyncMenu();
#endif
filePopup = new KPopupMenu(this);
importPopup = new KPopupMenu(filePopup);
exportPopup = new KPopupMenu(filePopup);
managePopup = new KPopupMenu(this);
#ifdef CONFIG_KEYCARD
chipcardPopup = new KPopupMenu(this);
#endif // CONFIG_KEYCARD
viewPopup = new KPopupMenu(this);
optionsPopup = new KPopupMenu(this);
// "file" popup menu
filePopup->insertItem(QIconSet(picons->loadIcon("filenew", KIcon::Small)),
i18n("&New"), this,
SLOT(new_slot()), 0, BUTTON_POPUP_FILE_NEW);
filePopup->insertItem(QIconSet(picons->loadIcon("fileopen", KIcon::Small)),
i18n("&Open"), this,
SLOT(open_slot()), 0, BUTTON_POPUP_FILE_OPEN);
filePopup->insertItem(QIconSet(picons->loadIcon("fileclose", KIcon::Small)),
i18n("&Close"), this,
SLOT(close_slot()), 0, BUTTON_POPUP_FILE_CLOSE);
filePopup->insertSeparator();
filePopup->insertItem(QIconSet(picons->loadIcon("filesave", KIcon::Small)),
i18n("&Save"), this,
SLOT(save_slot()), 0, BUTTON_POPUP_FILE_SAVE);
filePopup->insertItem(QIconSet(picons->loadIcon("filesaveas", KIcon::Small)),
i18n("Save &as..."),
this, SLOT(saveAs_slot()), 0,
BUTTON_POPUP_FILE_SAVEAS);
filePopup->insertSeparator();
// "file/export" popup menu
exportPopup->insertItem(i18n("&Text-file..."), this,
SLOT(exportToText()), 0, BUTTON_POPUP_EXPORT_TEXT);
exportPopup->insertItem(i18n("&Gpasman / Kpasman ..."), this,
SLOT(exportToGpasman()), 0, BUTTON_POPUP_EXPORT_GPASMAN);
exportPopup->insertItem(i18n("&CSV (Comma Separated Value) ..."), this,
SLOT(exportToCsv()), 0, BUTTON_POPUP_EXPORT_CSV);
#ifdef CONFIG_KWALLETIF
exportPopup->insertItem(i18n("&KWallet..."), this,
SLOT(exportToKWallet()), 0, BUTTON_POPUP_EXPORT_KWALLET);
#endif
filePopup->insertItem(QIconSet(picons->loadIcon("fileexport", KIcon::Small)),
i18n("E&xport"), exportPopup,
BUTTON_POPUP_FILE_EXPORT);
// "file/import" popup menu
importPopup->insertItem(i18n("&Text-file..."), this,
SLOT(importFromText()), 0, BUTTON_POPUP_IMPORT_TEXT);
importPopup->insertItem(i18n("&Gpasman / Kpasman ..."), this,
SLOT(importFromGpasman()), 0, BUTTON_POPUP_IMPORT_GPASMAN);
importPopup->insertItem(i18n("&CSV (Comma Separated Value) ..."), this,
SLOT(importCsv()), 0, BUTTON_POPUP_IMPORT_CSV);
#ifdef CONFIG_KWALLETIF
importPopup->insertItem(i18n("&KWallet..."), this,
SLOT(importKWallet()), 0, BUTTON_POPUP_IMPORT_KWALLET);
#endif
filePopup->insertItem(QIconSet(picons->loadIcon("fileimport", KIcon::Small)),
i18n("I&mport"), importPopup,
BUTTON_POPUP_FILE_IMPORT);
filePopup->insertSeparator();
filePopup->insertItem(QIconSet(picons->loadIcon("fileprint", KIcon::Small)),
i18n("&Print..."), this,
SLOT(print_slot()), 0, BUTTON_POPUP_FILE_PRINT);
filePopup->insertSeparator();
filePopup->insertItem(QIconSet(picons->loadIcon("exit", KIcon::Small)),
i18n("&Quit"), this,
SLOT(quitButton_slot()), 0, BUTTON_POPUP_FILE_QUIT);
menuBar()->insertItem(i18n("&File"), filePopup);
// "manage" popup menu
managePopup->insertItem(QIconSet(picons->loadIcon("pencil", KIcon::Small)),
i18n("&Add password"), this,
SLOT(addPwd_slot()), 0,
BUTTON_POPUP_MANAGE_ADD);
managePopup->insertItem(QIconSet(picons->loadIcon("edit", KIcon::Small)),
i18n("&Edit"), this, SLOT(editPwd_slot()), 0,
BUTTON_POPUP_MANAGE_EDIT);
managePopup->insertItem(QIconSet(picons->loadIcon("editdelete", KIcon::Small)),
i18n("&Delete"), this, SLOT(deletePwd_slot()),
0, BUTTON_POPUP_MANAGE_DEL);
managePopup->insertSeparator();
managePopup->insertItem(QIconSet(picons->loadIcon("rotate", KIcon::Small)),
i18n("Change &Master Password"), this,
SLOT(changeMasterPwd_slot()), 0,
BUTTON_POPUP_MANAGE_CHANGEMP);
menuBar()->insertItem(i18n("&Manage"), managePopup);
// "chipcard" popup menu
#ifdef CONFIG_KEYCARD
chipcardPopup->insertItem(QIconSet(picons->loadIcon("filenew", KIcon::Small)),
i18n("&Generate new key-card"), this,
SLOT(genNewCard_slot()), 0,
BUTTON_POPUP_CHIPCARD_GENNEW);
chipcardPopup->insertItem(QIconSet(picons->loadIcon("editdelete", KIcon::Small)),
i18n("&Erase key-card"), this,
SLOT(eraseCard_slot()), 0,
BUTTON_POPUP_CHIPCARD_DEL);
chipcardPopup->insertItem(QIconSet(picons->loadIcon("", KIcon::Small)),
i18n("Read card-&ID"), this,
SLOT(readCardId_slot()), 0,
BUTTON_POPUP_CHIPCARD_READID);
chipcardPopup->insertSeparator();
chipcardPopup->insertItem(QIconSet(picons->loadIcon("2rightarrow", KIcon::Small)),
i18n("&Make card backup-image"), this,
SLOT(makeCardBackup_slot()), 0,
BUTTON_POPUP_CHIPCARD_SAVEBACKUP);
chipcardPopup->insertItem(QIconSet(picons->loadIcon("2leftarrow", KIcon::Small)),
i18n("&Replay card backup-image"), this,
SLOT(replayCardBackup_slot()), 0,
BUTTON_POPUP_CHIPCARD_REPLAYBACKUP);
menuBar()->insertItem(i18n("&Chipcard manager"), chipcardPopup);
#endif // CONFIG_KEYCARD
// "view" popup menu
viewPopup->insertItem(QIconSet(picons->loadIcon("find", KIcon::Small)),
i18n("&Find"), this,
SLOT(find_slot()), 0, BUTTON_POPUP_VIEW_FIND);
viewPopup->insertSeparator();
viewPopup->insertItem(QIconSet(picons->loadIcon("halfencrypted", KIcon::Small)),
i18n("&Lock all entries"), this,
SLOT(lockWnd_slot()), 0,
BUTTON_POPUP_VIEW_LOCK);
viewPopup->insertItem(QIconSet(picons->loadIcon("encrypted", KIcon::Small)),
i18n("&Deep-lock all entries"), this,
SLOT(deepLockWnd_slot()), 0,
BUTTON_POPUP_VIEW_DEEPLOCK);
viewPopup->insertItem(QIconSet(picons->loadIcon("decrypted", KIcon::Small)),
i18n("&Unlock all entries"), this,
SLOT(unlockWnd_slot()), 0,
BUTTON_POPUP_VIEW_UNLOCK);
menuBar()->insertItem(i18n("&View"), viewPopup);
// "options" popup menu
optionsPopup->insertItem(QIconSet(picons->loadIcon("configure", KIcon::Small)),
i18n("&Configure..."), this,
SLOT(config_slot()),
BUTTON_POPUP_OPTIONS_CONFIG);
menuBar()->insertItem(i18n("&Options"), optionsPopup);
// "help" popup menu
#ifndef PWM_EMBEDDED
helpPopup = helpMenu(QString::null, false);
#else
menuBar()->insertItem(i18n("&Sync"), syncPopup);
helpPopup = new KPopupMenu(this);
helpPopup->insertItem(i18n("&License"), this,
SLOT(showLicense_slot()), 0,
BUTTON_POPUP_HELP_LICENSE);
helpPopup->insertItem(i18n("&Faq"), this,
SLOT(faq_slot()), 0,
BUTTON_POPUP_HELP_FAQ);
helpPopup->insertItem(i18n("&About PwManager"), this,
SLOT(createAboutData_slot()), 0,
BUTTON_POPUP_HELP_ABOUT);
helpPopup->insertItem(i18n("&Sync HowTo"), this,
SLOT(syncHowTo_slot()), 0,
BUTTON_POPUP_HELP_SYNC);
helpPopup->insertItem(i18n("&What's New"), this,
SLOT(whatsnew_slot()), 0,
BUTTON_POPUP_HELP_WHATSNEW);
#endif
menuBar()->insertItem(i18n("&Help"), helpPopup);
}
void PwM::initToolbar()
{
KIconLoader* picons;
#ifndef PWM_EMBEDDED
KIconLoader icons;
picons = &icons;
#else
picons = KGlobal::iconLoader();
#endif
#ifdef PWM_EMBEDDED
if ( QApplication::desktop()->width() > 320 )
#endif
{
toolBar()->insertButton(picons->loadIcon("filenew", KIcon::Toolbar),
BUTTON_TOOL_NEW, SIGNAL(clicked(int)), this,
SLOT(new_slot()), true, i18n("New"));
toolBar()->insertButton(picons->loadIcon("fileopen", KIcon::Toolbar),
BUTTON_TOOL_OPEN, SIGNAL(clicked(int)), this,
SLOT(open_slot()), true, i18n("Open"));
toolBar()->insertSeparator();
}
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_slot1(0, 0);
}
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_slot3(0,0,0);
}
void PwM::editPwd_slot1(const QString *category)
{
editPwd_slot3(category, 0, 0);
}
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\n"
"this entry is already present\nin 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
pwm->curView()->setFont(conf()->confGlobEntryFont());
++i2;
}
}
void PwM::activateMpButton(bool activate)
{
managePopup->setItemEnabled(BUTTON_POPUP_MANAGE_CHANGEMP, activate);
}
void PwM::closeEvent(QCloseEvent *e)
{
+ qDebug("PwM::closeEvent ");
+ emit closed( this );
+ return;
e->accept();
}
void PwM::docClosed(PwMDoc *doc)
{
+ qDebug("PwM::docClosed ");
PARAM_UNUSED(doc);
PWM_ASSERT(doc == curDoc());
close();
}
void PwM::find_slot()
{
PWM_ASSERT(curDoc());
if (curDoc()->isDocEmpty())
return;
if (curDoc()->isDeepLocked())
return;
curDoc()->timer()->getLock(DocTimer::id_autoLockTimer);
FindWndImpl findWnd(view);
findWnd.exec();
curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
}
void PwM::exportToText()
{
PWM_ASSERT(curDoc());
if (curDoc()->isDocEmpty()) {
KMessageBox::information(this,
i18n
("Sorry, there's nothing to export.\n"
"Please first add some passwords."),
i18n("nothing to do"));
return;
}
curDoc()->timer()->getLock(DocTimer::id_autoLockTimer);
QString fn(KFileDialog::getSaveFileName(QString::null,
i18n("*|plain-text file"),
this));
if (fn == "") {
curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
return;
}
PwMerror ret = curDoc()->exportToText(&fn);
if (ret != e_success) {
KMessageBox::error(this,
i18n("Error: Couldn't write to file.\n"
"Please check if you have permission to write\n"
"to the file in that directory."),
i18n("error while writing"));
} else
showStatMsg(i18n("Successfully exported data."));
curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
}
bool PwM::importFromText()
{
if (!isVirgin()) {
if (KMessageBox::questionYesNo(this,
i18n("Do you want to import the data\n"
"into the current document? (If you\n"
"select \"no\", a new document will be\n"
"opened.)"),
i18n("import into this document?"))
== KMessageBox::No) {
// import the data to a new window.
PwM *newInstance = init->createMainWnd();
bool ok = newInstance->importFromText();
if (!ok) {
newInstance->setForceQuit(true);
delete_and_null(newInstance);
}
return ok;
}
}
curDoc()->timer()->getLock(DocTimer::id_autoLockTimer);
PwMerror ret;
QString path(KFileDialog::getOpenFileName(QString::null,
i18n("*|PWM-exported text file"),
this));
if (path == "")
goto cancelImport;
ret = curDoc()->importFromText(&path, 0);
if (ret == e_fileFormat) {
KMessageBox::error(this,
i18n("Could not read file-format.\n"
"This seems to be _not_ a valid file\n"
"exported by PwM."),
i18n("invalid file-format"));
goto cancelImport;
} else if (ret == e_invalidArg) {
BUG();
goto cancelImport;
} else if (ret != e_success) {
KMessageBox::error(this,
i18n("Could not import file!\n"
"Do you have permission to read this file?\n"
"Do you have enough free memory?"),
i18n("import failed"));
goto cancelImport;
}
setVirgin(false);
curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
return true;
cancelImport:
curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
return false;
}
void PwM::exportToGpasman()
{
PWM_ASSERT(curDoc());
if (curDoc()->isDocEmpty()) {
KMessageBox::information(this,
i18n
("Sorry, there's nothing to export.\n"
"Please first add some passwords."),
i18n("nothing to do"));
return;
}
curDoc()->timer()->getLock(DocTimer::id_autoLockTimer);
QString fn(KFileDialog::getSaveFileName(QString::null,
i18n("*|Gpasman or Kpasman file"),
this));
if (fn == "") {
curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
return;
}
PwMerror ret = curDoc()->exportToGpasman(&fn);
if (ret != e_success) {
if (ret == e_noPw) {
curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
return;
}
KMessageBox::error(this,
i18n("Error: Couldn't write to file.\n"
"Please check if you have permission to write "
"to the file in that directory."),
i18n("error while writing"));
} else
showStatMsg(i18n("Successfully exported data."));
curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
}
void PwM::exportToCsv()
{
PWM_ASSERT(curDoc());
if (curDoc()->isDocEmpty()) {
KMessageBox::information(this,
i18n
("Sorry, there is nothing to export;\n"
"please add some passwords first."),
i18n("Nothing to Do"));
return;
}
curDoc()->timer()->getLock(DocTimer::id_autoLockTimer);
QString fn(KFileDialog::getSaveFileName("*.csv", i18n("*|CSV Text File"), this));
if (fn.isEmpty()) {
curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
return;
}
Csv csv(this);
if (!csv.exportData(fn, curDoc())) {
curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
showStatMsg(i18n("CSV file export failed."));
return;
}
showStatMsg(i18n("Successfully exported data."));
curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
}
bool PwM::importCsv()
{
Csv csv(this);
if (!isVirgin()) {
if (KMessageBox::questionYesNo(this,
i18n("Do you want to import the data\n"
"into the current document? (If you\n"
"select \"no\", a new document will be\n"
"opened.)"),
i18n("Import into This Document?"))
== KMessageBox::No) {
// import the data to a new window.
PwM *newInstance = init->createMainWnd();
bool ok = newInstance->importCsv();
if (!ok) {
newInstance->setForceQuit(true);
delete_and_null(newInstance);
}
return ok;
}
}
QString filename = KFileDialog::getOpenFileName("*.csv", i18n("*|CSV Text File"), this);
if (filename.isEmpty())
return false;
curDoc()->timer()->getLock(DocTimer::id_autoLockTimer);
if (!csv.importData(filename, curDoc())) {
curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
showStatMsg(i18n("CSV file import failed."));
return false;
}
curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
KMessageBox::information(this,
i18n("Successfully imported the CSV data\n"
"into the current document."), i18n("Successfully Imported"));
showStatMsg(i18n("Successfully imported"));
setVirgin(false);
return true;
}
void PwM::exportToKWallet()
{
#ifdef CONFIG_KWALLETIF
if (!checkAndAskForKWalletEmu())
return;
PWM_ASSERT(curDoc());
if (curDoc()->isDocEmpty()) {
KMessageBox::information(this,
i18n
("Sorry, there's nothing to export.\n"
"Please first add some passwords."),
i18n("nothing to do"));
init->initKWalletEmu();
return;
}
curDoc()->timer()->getLock(DocTimer::id_autoLockTimer);
KWalletIf walletIf(this);
if (walletIf.kwalletExport(curDoc())) {
KMessageBox::information(this,
i18n("Successfully exported the data of the current "
"document to KWallet."),
i18n("Successfully exported data."));
showStatMsg(i18n("Successfully exported data."));
}
init->initKWalletEmu();
curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
#endif // CONFIG_KWALLETIF
}
bool PwM::importFromGpasman()
{
if (!isVirgin()) {
if (KMessageBox::questionYesNo(this,
i18n("Do you want to import the data\n"
"into the current document? (If you\n"
"select \"no\", a new document will be\n"
"opened.)"),
i18n("import into this document?"))
== KMessageBox::No) {
// import the data to a new window.
PwM *newInstance = init->createMainWnd();
bool ok = newInstance->importFromGpasman();
if (!ok) {
newInstance->setForceQuit(true);
delete_and_null(newInstance);
}
return ok;
}
}
curDoc()->timer()->getLock(DocTimer::id_autoLockTimer);
PwMerror ret;
QString path(KFileDialog::getOpenFileName(QString::null,
i18n("*|Gpasman or Kpasman file"), this));
if (path == "")
goto cancelImport;
ret = curDoc()->importFromGpasman(&path);
if (ret == e_wrongPw) {
if (KMessageBox::questionYesNo(this,
i18n
("This is probably the wrong master-password\n"
"you have typed in.\n"
"There is no real way to determine the\n"
"correctness of the password in the Gpasman\n"
"file-format. But I think this\n"
"password ist wrong.\n"
"Do you want to continue nevertheless?"),
i18n("password error"))
== KMessageBox::No) {
goto cancelImport;
}
} else if (ret != e_success) {
KMessageBox::error(this,
i18n("Could not import file!\n"
"Do you have permission to read this file?"),
i18n("import failed"));
goto cancelImport;
}
setVirgin(false);
curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
return true;
cancelImport:
curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
return false;
}
#ifdef CONFIG_KWALLETIF
bool PwM::checkAndAskForKWalletEmu()
{
if (init->kwalletEmu()) {
/* KWallet emulation is enabled. We can't import/export
* data from/to it, while emulation is active.
*/
if (KMessageBox::questionYesNo(this,
i18n("KWallet emulation is enabled.\n"
"You can't import or export data from/to "
"the original KWallet, while the emulation "
"is active.\n"
"Do you want to tempoarly disable the KWallet emulation?"),
i18n("Tempoarly disable KWallet emulation?"))
== KMessageBox::Yes) {
init->initKWalletEmu(true);
PWM_ASSERT(!init->kwalletEmu());
return true;
}
return false;
}
return true;
}
#endif // CONFIG_KWALLETIF
bool PwM::importKWallet()
{
#ifdef CONFIG_KWALLETIF
if (!checkAndAskForKWalletEmu())
return false;
KWalletIf walletIf(this);
if (!isVirgin()) {
if (KMessageBox::questionYesNo(this,
i18n("Do you want to import the data "
"into the current document? (If you "
"select \"no\", a new document will be "
"opened.)"),
i18n("import into this document?"))
== KMessageBox::No) {
// import the data to a new window.
PwM *newInstance = init->createMainWnd();
bool ok = newInstance->importKWallet();
if (!ok) {
newInstance->setForceQuit(true);
delete_and_null(newInstance);
goto exit_fail;
} else {
goto exit_ok;
}
}
}
curDoc()->timer()->getLock(DocTimer::id_autoLockTimer);
if (!walletIf.kwalletImport(curDoc())) {
curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
showStatMsg(i18n("KWallet import failed"));
goto exit_fail;
}
KMessageBox::information(this,
i18n("Successfully imported the KWallet data "
"into the current document."),
i18n("successfully imported"));
showStatMsg(i18n("successfully imported"));
setVirgin(false);
curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
exit_ok:
init->initKWalletEmu();
return true;
exit_fail:
init->initKWalletEmu();
#endif // CONFIG_KWALLETIF
return false;
}
void PwM::print_slot()
{
curDoc()->timer()->getLock(DocTimer::id_autoLockTimer);
#ifndef PWM_EMBEDDED
PwMPrint p(curDoc(), this);
p.printNow();
#else
qDebug("PwM::print_slot , PRINTING IS NOT IMPLEMENTED");
#endif
curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
}
void PwM::genNewCard_slot()
{
#ifdef CONFIG_KEYCARD
init->keycard()->genNewCard();
#endif
}
void PwM::eraseCard_slot()
{
#ifdef CONFIG_KEYCARD
init->keycard()->eraseCard();
#endif
}
void PwM::readCardId_slot()
{
#ifdef CONFIG_KEYCARD
init->keycard()->displayKey();
#endif
}
void PwM::makeCardBackup_slot()
{
#ifdef CONFIG_KEYCARD
init->keycard()->makeBackupImage();
#endif
}
void PwM::replayCardBackup_slot()
{
#ifdef CONFIG_KEYCARD
init->keycard()->replayBackupImage();
#endif
}
void PwM::execLauncher_slot()
{
PWM_ASSERT(curDoc());
if (curDoc()->isDeepLocked())
return;
unsigned int curEntryIndex;
if (!view->getCurEntryIndex(&curEntryIndex))
return;
bool ret = curDoc()->execLauncher(view->getCurrentCategory(),
curEntryIndex);
if (ret)
showStatMsg(i18n("Executed the \"Launcher\"."));
else
showStatMsg(i18n("ERROR: Couldn't execute the \"Launcher\"!"));
}
void PwM::goToURL_slot()
{
PWM_ASSERT(curDoc());
if (curDoc()->isDeepLocked())
return;
unsigned int curEntryIndex;
if (!view->getCurEntryIndex(&curEntryIndex))
return;
bool ret = curDoc()->goToURL(view->getCurrentCategory(),
curEntryIndex);
if (ret)
showStatMsg(i18n("started browser with current URL."));
else
showStatMsg(i18n("ERROR: Couldn't start browser! Maybe invalid URL?"));
}
void PwM::copyToClipboard(const QString &s)
{
QClipboard *cb = QApplication::clipboard();
#ifndef PWM_EMBEDDED
if (cb->supportsSelection())
cb->setText(s, QClipboard::Selection);
cb->setText(s, QClipboard::Clipboard);
#else
cb->setText(s);
#endif
}
void PwM::showStatMsg(const QString &msg)
{
#ifdef DESKTOP_VERSION
statusBar()->message(msg, STATUSBAR_MSG_TIMEOUT * 1000);
#else
qDebug("Statusbar : %s",msg.latin1());
Global::statusMessage(msg);
#endif
}
void PwM::focusInEvent(QFocusEvent *e)
{
if (e->gotFocus()) {
emit gotFocus(this);
} else if (e->lostFocus()) {
emit lostFocus(this);
}
}
#ifdef PWM_EMBEDDED
void PwM::whatsnew_slot()
{
KApplication::showFile( "KDE-Pim/Pi Version Info", "kdepim/WhatsNew.txt" );
}
void PwM::showLicense_slot()
{
KApplication::showLicence();
}
void PwM::faq_slot()
{
KApplication::showFile( "PWM/Pi FAQ", "kdepim/pwmanager/pwmanagerFAQ.txt" );
}
void PwM::syncHowTo_slot()
{
KApplication::showFile( "KDE-Pim/Pi Synchronization HowTo", "kdepim/SyncHowto.txt" );
}
void PwM::createAboutData_slot()
{
QString version;
#include <../version>
;
QMessageBox::about( this, "About PwManager/Pi",
"PwManager/Platform-independent\n"
"(PWM/Pi) " +version + " - " +
#ifdef DESKTOP_VERSION
"Desktop Edition\n"
#else
"PDA-Edition\n"
"for: Zaurus 5500 / 7x0 / 8x0\n"
#endif
"(c) 2004 Ulf Schenk\n"
"(c) 2004 Lutz Rogowski\n"
"(c) 1997-2004, The KDE PIM Team\n"
"(c) Michael Buesch - main programming\nand current maintainer\nmbuesch@freenet.de\n"
"Matt Scifo - mscifo@o1.com\n"
"Elias Probst - elias.probst@gmx.de\n"
"George Staikos - staikos@kde.org\n"
"Matthew Palmer - mjp16@uow.edu.au\n"
"Olivier Sessink - gpasman@nl.linux.org\n"
"The libgcrypt developers -\nBlowfish and SHA1 algorithms\nftp://ftp.gnupg.org/gcrypt/alpha/libgcrypt/\n"
"Troy Engel - tengel@sonic.net\n"
"Wickey - wickey@gmx.at\n"
"Ian MacGregor - original documentation author.\n"
);
}
//this are the overwritten callbackmethods from the syncinterface
bool PwM::sync(KSyncManager* manager, QString filename, int mode)
{
PWM_ASSERT(curDoc());
bool ret = curDoc()->sync(manager, filename, mode);
qDebug("PwM::sync save now: ret=%i", ret);
if (ret == true) {
//US BUG: what can we call here to update the view of the current doc?
//mViewManager->refreshView();
//US curDoc()->sync sets the dirtyFlag in case the sync was successfull.
save();
}
return ret;
}
#endif
#ifndef PWM_EMBEDDED
#include "pwm.moc"
#endif
diff --git a/pwmanager/pwmanager/pwmdoc.cpp b/pwmanager/pwmanager/pwmdoc.cpp
index 129bf7b..cf8690f 100644
--- a/pwmanager/pwmanager/pwmdoc.cpp
+++ b/pwmanager/pwmanager/pwmdoc.cpp
@@ -2212,1286 +2212,1287 @@ void PwMDoc::getEntryList(unsigned int category, QStringList *list)
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)
{
#ifndef _WIN32_
if (geteuid() == 0) {
rootAlertMsgBox();
return false;
}
#endif
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)
{
#ifndef _WIN32_
if (geteuid() == 0) {
rootAlertMsgBox();
return false;
}
#endif
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).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);
// read username-line
if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1)
goto formatError;
if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.name))
goto formatError;
// read pw-line
if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1)
goto formatError;
if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.pw))
goto formatError;
// read comment-line
if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1)
goto formatError;
if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.comment))
goto formatError;
// read URL-line
if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1)
goto formatError;
if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.url))
goto formatError;
// read launcher-line
if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1)
goto formatError;
if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.launcher))
goto formatError;
currItem.lockStat = true;
currItem.listViewPos = -1;
addEntry(curCat.c_str(), &currItem, true);
++entriesRead;
} while (1);
} while (1);
if (!entriesRead)
goto formatError;
free(ch_tmp);
fclose(f);
flagDirty();
return e_success;
formatError:
free(ch_tmp);
fclose(f);
return e_fileFormat;
#else
PWM_ASSERT(file);
QFile f(file->latin1());
int tmp;
ssize_t ret;
string curCat;
unsigned int entriesRead = 0;
PwMDataItem currItem;
bool res = f.open(IO_ReadOnly);
if (res == false)
return e_openFile;
unsigned int ch_tmp_size = 1024;
char *ch_tmp = (char*)malloc(ch_tmp_size);
if (!ch_tmp) {
f.close();
return e_outOfMem;
}
// - check header
if (f.readLine(ch_tmp, ch_tmp_size) == -1) // skip first line.
goto formatError;
//US read fileversion first, then check if ok.
if (f.readLine(ch_tmp, ch_tmp_size) == -1)
goto formatError;
// check version-string and return version in "ch_tmp".
//US if (fscanf(f, "PwM v%s", ch_tmp) != 1) {
//US // header not recognized as PwM generated header
//US goto formatError;
//US }
//US set filepointer behind version-string-line previously checked
//US if (f.readLine(ch_tmp, ch_tmp_size) == -1)
//US goto formatError;
// skip next line containing the build-date
if (f.readLine(ch_tmp, ch_tmp_size) == -1)
goto formatError;
// read header termination line
if (f.readLine(ch_tmp, ch_tmp_size) == -1)
goto formatError;
if (strcmp(ch_tmp, "==============================\n"))
goto formatError;
// - read entries
do {
// find beginning of next category
do {
tmp = f.getch();
} while (tmp == '\n' && tmp != EOF);
if (tmp == EOF)
break;
// decrement filepos by one
f.at(f.at()-1);
// read cat-name
if (f.readLine(ch_tmp, ch_tmp_size) == -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 = f.getch();
} while (tmp == '\n' && tmp != EOF && tmp != '=');
if (tmp == EOF)
break;
if (tmp == '=') {
f.at(f.at()-1);
break;
}
// decrement filepos by one
f.at(f.at()-1);
// read desc-line
if (f.readLine(ch_tmp, ch_tmp_size) == -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);
// read username-line
if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1)
goto formatError;
if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.name))
goto formatError;
// read pw-line
if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1)
goto formatError;
if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.pw))
goto formatError;
// read comment-line
if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1)
goto formatError;
if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.comment))
goto formatError;
// read URL-line
if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1)
goto formatError;
if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.url))
goto formatError;
// read launcher-line
if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1)
goto formatError;
if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.launcher))
goto formatError;
currItem.lockStat = true;
currItem.listViewPos = -1;
addEntry(curCat.c_str(), &currItem, true);
++entriesRead;
} while (1);
} while (1);
if (!entriesRead)
goto formatError;
free(ch_tmp);
f.close();
flagDirty();
return e_success;
formatError:
free(ch_tmp);
f.close();
return e_fileFormat;
#endif
}
bool PwMDoc::textExtractEntry_PwM(const char *in, ssize_t in_size, string *out)
{
PWM_ASSERT(in && out);
ssize_t i = 0, len = in_size - 1;
while (i < len) {
if (in[i] == ':')
break;
++i;
}
i += 2;
*out = "";
out->append(in + i, in_size - i - 1);
return true;
}
PwMerror PwMDoc::exportToGpasman(const QString *file)
{
PWM_ASSERT(file);
GpasmanFile gp;
int ret;
if (!unlockAll_tempoary())
return e_lock;
QString gpmPassword;
while (1) {
gpmPassword = requestNewMpw(0);
if (gpmPassword == "") {
unlockAll_tempoary(true);
return e_noPw;
}
if (gpmPassword.length() < 4) {
gpmPwLenErrMsgBox();
} else {
break;
}
}
ret = gp.save_init(file->latin1(), gpmPassword.latin1());
if (ret != 1) {
unlockAll_tempoary(true);
return e_accessFile;
}
char *entry[4];
unsigned int numCat = numCategories(), i;
unsigned int numEntr, j;
int descLen, nameLen, pwLen, commentLen;
for (i = 0; i < numCat; ++i) {
numEntr = numEntries(i);
for (j = 0; j < numEntr; ++j) {
descLen = dti.dta[i].d[j].desc.length();
nameLen = dti.dta[i].d[j].name.length();
pwLen = dti.dta[i].d[j].pw.length();
commentLen = dti.dta[i].d[j].comment.length();
entry[0] = new char[descLen + 1];
entry[1] = new char[nameLen + 1];
entry[2] = new char[pwLen + 1];
entry[3] = new char[commentLen + 1];
strcpy(entry[0], descLen == 0 ? " " : dti.dta[i].d[j].desc.c_str());
strcpy(entry[1], nameLen == 0 ? " " : dti.dta[i].d[j].name.c_str());
strcpy(entry[2], pwLen == 0 ? " " : dti.dta[i].d[j].pw.c_str());
strcpy(entry[3], commentLen == 0 ? " " : dti.dta[i].d[j].comment.c_str());
entry[0][descLen == 0 ? descLen + 1 : descLen] = '\0';
entry[1][nameLen == 0 ? nameLen + 1 : nameLen] = '\0';
entry[2][pwLen == 0 ? pwLen + 1 : pwLen] = '\0';
entry[3][commentLen == 0 ? commentLen + 1 : commentLen] = '\0';
ret = gp.save_entry(entry);
if (ret == -1){
delete [] entry[0];
delete [] entry[1];
delete [] entry[2];
delete [] entry[3];
gp.save_finalize();
unlockAll_tempoary(true);
return e_writeFile;
}
delete [] entry[0];
delete [] entry[1];
delete [] entry[2];
delete [] entry[3];
}
}
unlockAll_tempoary(true);
if (gp.save_finalize() == -1)
return e_writeFile;
return e_success;
}
PwMerror PwMDoc::importFromGpasman(const QString *file)
{
PWM_ASSERT(file);
QString pw = requestMpw(false);
if (pw == "")
return e_noPw;
GpasmanFile gp;
int ret, i;
PwMerror ret2;
char *entry[4];
PwMDataItem tmpData;
ret = gp.load_init(file->latin1(), pw.latin1());
if (ret != 1)
return e_accessFile;
do {
ret = gp.load_entry(entry);
if(ret != 1)
break;
tmpData.desc = entry[0];
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.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.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);
syncLocal->addEntry(remotecat->c_str(), inRemote, true, false);
++addedPasswordsLocal;
} else {
// pending checkExternSyncAddressee(addresseeRSyncSharp, inR);
syncRemote->delEntry(catRemote, indexRemote, true);
++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);
++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);
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;
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 ) {
bool equ = ( (*local) == (*remote) );
if ( equ ) {
//qDebug("equal ");
if ( mode < SYNC_PREF_FORCE_LOCAL )
return 0;
}//else //debug only
//qDebug("not equal %s %s ", local->desc.c_str(), remote->desc.c_str());
}
int result;
bool localIsNew;
//qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , local->lastModified().toString().latin1() , remote->lastModified().toString().latin1() );
if ( full && mode < SYNC_PREF_NEWEST )
mode = SYNC_PREF_ASK;
switch( mode ) {
case SYNC_PREF_LOCAL:
if ( lastSync > remoteMod )
return 1;
if ( lastSync > localMod )
return 2;
return 1;
break;
case SYNC_PREF_REMOTE:
if ( lastSync > remoteMod )
return 1;
if ( lastSync > localMod )
return 2;
return 2;
break;
case SYNC_PREF_NEWEST:
if ( localMod > remoteMod )
return 1;
else
return 2;
break;
case SYNC_PREF_ASK:
//qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
if ( lastSync > remoteMod )
return 1;
if ( lastSync > localMod )
return 2;
localIsNew = localMod >= remoteMod;
//qDebug("conflict! ************************************** ");
{
PwMDataItemChooser acd ( *local,*remote, localIsNew , 0/*this*/ );
result = acd.executeD(localIsNew);
return result;
}
break;
case SYNC_PREF_FORCE_LOCAL:
return 1;
break;
case SYNC_PREF_FORCE_REMOTE:
return 2;
break;
default:
// SYNC_PREF_TAKE_BOTH not implemented
break;
}
return 0;
}
//this are the overwritten callbackmethods from the syncinterface
bool PwMDoc::sync(KSyncManager* manager, QString filename, int mode)
{
QString mCurrentSyncDevice = manager->getCurrentSyncDevice();
//1) unlock local file first if necessary (ask for password)
if (this->isDeepLocked()) {
PwMerror ret = this->deepLock(false);
if (ret != e_success)
return false;
}
//2) construct and open a new doc on the stack(automatic cleanup of remote file).
PwMDoc syncTarget(this, "synctarget");
PwMDoc* pSyncTarget = &syncTarget;
PwMerror err = pSyncTarget->openDoc(&filename, 1 /*== open with all entries locked*/);
if (err == e_alreadyOpen) {
PwMDocList::listItem li;
if (getOpenDocList()->find(filename.latin1(), &li))
pSyncTarget = li.doc;
else {
qDebug("PwmDoc::sync: sync failed. Error %i while opening file %s",err, filename.latin1());
return false;
}
}
else if (err != e_success) {
qDebug("PwmDoc::sync: sync failed. Error %i while opening file %s",err, filename.latin1());
return false;
}
qDebug("PWM file loaded %s,sync mode %d",filename.latin1(), mode );
//3) unlock remote file first if necessary (ask for password)
if (pSyncTarget->isDeepLocked()) {
PwMerror ret = pSyncTarget->deepLock(false);
if (ret != e_success)
return false;
}
err = syncronize(manager, this, pSyncTarget, mode );
if (err == e_success) {
if ( manager->mWriteBackFile ) {
qDebug("Saving remote PWManager file");
err = pSyncTarget->saveDoc(conf()->confGlobCompression());
if (err != e_success) {
qDebug("PwmDoc::sync: Sync failed. Error %i while storing file %s",err, filename.latin1());
return false;
}
}
flagDirty();
return true;
}
else {
return false;
}
}
#endif
bool PwMDoc::findSyncData(const QString &syncname, unsigned int *index)
{
vector<PwMSyncItem>::iterator i = dti.syncDta.begin(),
end = dti.syncDta.end();
while (i != end) {
if ((*i).syncName == syncname.latin1()) {
if (index) {
*index = i - dti.syncDta.begin();
}
return true;
}
++i;
}
return false;
};
/** add new syncdataentry */
PwMerror PwMDoc::addSyncDataEntry(PwMSyncItem *d, bool dontFlagDirty)
{
PWM_ASSERT(d);
if (isDeepLocked()) {
PwMerror ret;
ret = deepLock(false);
if (ret != e_success)
return e_lock;
}
unsigned int index;
const QString tmp = d->syncName.c_str();
bool exists = findSyncData(d->syncName.c_str(), &index);
if (exists == true) {
// DOH! We found this entry.
return e_entryExists;
}
dti.syncDta.push_back(*d);
if (!dontFlagDirty)
flagDirty();
return e_success;
}
/** delete syncdata entry */
bool PwMDoc::delSyncDataEntry(unsigned int index, bool dontFlagDirty)
{
if (isDeepLocked())
return false;
if (index > dti.syncDta.size() - 1)
return false;
// delete entry
dti.syncDta.erase(dti.syncDta.begin() + index);
if (!dontFlagDirty)
flagDirty();
return true;
}
PwMDataItem* PwMDoc::findEntryByID(const QString &uid, unsigned int *category, unsigned int *index)
{
vector<PwMCategoryItem>::iterator catcounter = dti.dta.begin(),
catend = dti.dta.end();
vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI;
while (catcounter != catend) {
entrBegin = catcounter->d.begin();
entrEnd = catcounter->d.end();
entrI = entrBegin;
while (entrI != entrEnd) {
if ((*entrI).meta.uniqueid == uid.latin1()) {
if (category)
*category = catcounter - dti.dta.begin();
if (index)
*index = entrI - entrBegin;
return &(*entrI);
}
++entrI;
}
++catcounter;
}
return 0;
}
QStringList PwMDoc::getIDEntryList()
{
QStringList results;
vector<PwMCategoryItem>::iterator catcounter = dti.dta.begin(),
catend = dti.dta.end();
vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI;
while (catcounter != catend) {
entrBegin = catcounter->d.begin();
entrEnd = catcounter->d.end();
entrI = entrBegin;
while (entrI != entrEnd) {
results.append( (*entrI).meta.uniqueid.c_str() );
++entrI;
}
++catcounter;
}
return results;
}
#ifndef PWM_EMBEDDED
#include "pwmdoc.moc"
#endif
diff --git a/pwmanager/pwmanager/pwmdocui.cpp b/pwmanager/pwmanager/pwmdocui.cpp
index 71b4a8d..a9916c2 100644
--- a/pwmanager/pwmanager/pwmdocui.cpp
+++ b/pwmanager/pwmanager/pwmdocui.cpp
@@ -1,467 +1,470 @@
/***************************************************************************
* *
* copyright (C) 2003, 2004 by Michael Buesch *
* email: mbuesch@freenet.de *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License version 2 *
* as published by the Free Software Foundation. *
* *
***************************************************************************/
/***************************************************************************
* copyright (C) 2004 by Ulf Schenk
* This file is originaly based on version 1.0.1 of pwmanager
* and was modified to run on embedded devices that run microkde
*
* $Id$
**************************************************************************/
#include "pwmdocui.h"
#include "setmasterpwwndimpl.h"
#include "getmasterpwwndimpl.h"
#include "pwmexception.h"
#include "getkeycardwnd.h"
#include "pwm.h"
#include "globalstuff.h"
#include "spinforsignal.h"
#include <qlineedit.h>
#include <qtabwidget.h>
#include <kmessagebox.h>
#include <kfiledialog.h>
#ifndef PWM_EMBEDDED
#include <kwin.h>
#else
#include <qdir.h>
#include "pwmprefs.h"
#endif
#ifdef CONFIG_KEYCARD
# include "pwmkeycard.h"
#endif
PwMDocUi::PwMDocUi(QObject *parent, const char *name)
: QObject(parent, name)
{
currentView = 0;
keyCard = 0;
}
PwMDocUi::~PwMDocUi()
{
}
QString PwMDocUi::requestMpw(bool chipcard)
{
QString pw;
if (chipcard) {
#ifdef CONFIG_KEYCARD
PWM_ASSERT(keyCard);
uint32_t id;
string ret;
SpinForSignal *spinner = keyCard->getSpinner();
connect(keyCard, SIGNAL(keyAvailable(uint32_t, const string &)),
spinner, SLOT(u32_str_slot(uint32_t, const string &)));
keyCard->getKey();
spinner->spin(&id, &ret);
disconnect(keyCard, SIGNAL(keyAvailable(uint32_t, const string &)),
spinner, SLOT(u32_str_slot(uint32_t, const string &)));
if (ret == "")
return "";
pw = ret.c_str();
#else // CONFIG_KEYCARD
no_keycard_support_msg_box(currentView);
#endif // CONFIG_KEYCARD
} else {
#ifndef PWM_EMBEDDED
GetMasterPwWndImpl pwWnd;
KWin::setState(pwWnd.winId(), NET::StaysOnTop);
#else
GetMasterPwWndImpl pwWnd;
#endif
if (pwWnd.exec() != 1)
return "";
pw = pwWnd.pwLineEdit->text();
}
return pw;
}
QString PwMDocUi::requestNewMpw(bool *chipcard)
{
QString pw;
SetMasterPwWndImpl pwWnd(currentView);
pwWnd.setPwMKeyCard(keyCard);
if (!chipcard) {
#ifndef PWM_EMBEDDED
pwWnd.mainTab->removePage(pwWnd.mainTab->page(1));
#else
pwWnd.mainTab->removePage(pwWnd.tab_2);
#endif
}
if (pwWnd.exec() != 1)
return "";
pw = pwWnd.getPw(chipcard).c_str();
return pw;
}
QString PwMDocUi::requestMpwChange(const QString *currentPw, bool *chipcard)
{
QString pw(requestMpw(*chipcard));
if (pw == "")
return "";
if (pw != *currentPw) {
wrongMpwMsgBox(*chipcard);
return "";
}
pw = requestNewMpw(chipcard);
if (pw == "")
return "";
return pw;
}
void PwMDocUi::wrongMpwMsgBox(bool chipcard, QString prefix, QString postfix)
{
QString msg;
if (prefix != "") {
msg += prefix;
msg += "\n";
}
if (chipcard) {
msg += i18n("Wrong key-card!\n"
"Please try again with the\n"
"correct key-card.");
} else {
msg += i18n("Wrong master-password!\n"
"Please try again.");
}
if (postfix != "") {
msg += "\n";
msg += postfix;
}
KMessageBox::error(currentView, msg,
(chipcard) ? (i18n("wrong chipcard"))
: (i18n("password error")));
}
void PwMDocUi::noMpwMsgBox(bool chipcard, QString prefix, QString postfix)
{
QString msg;
if (prefix != "") {
msg += prefix;
msg += "\n";
}
if (chipcard) {
msg += i18n("No key-card found!\n"
"Please insert the\n"
"correct key-card.");
} else {
msg += i18n("No master-password given!");
}
if (postfix != "") {
msg += "\n";
msg += postfix;
}
KMessageBox::error(currentView, msg,
(chipcard) ? (i18n("no chipcard"))
: (i18n("password error")));
}
void PwMDocUi::rootAlertMsgBox()
{
KMessageBox::error(currentView,
i18n("This feature is not available,n"
"if you execute PwM with \"root\" \n"
"UID 0 privileges, for security reasons!"),
i18n("not allowed as root!"));
}
void PwMDocUi::cantDeeplock_notSavedMsgBox()
{
KMessageBox::error(currentView,
i18n("Can't deep-lock, because the document\n"
"hasn't been saved, yet. Please save\n"
"to a file and try again."),
i18n("not saved, yet"));
}
void PwMDocUi::gpmPwLenErrMsgBox()
{
KMessageBox::error(currentView,
i18n("GPasman does not support passwords\n"
"shorter than 4 characters! Please try\n"
"again with a longer password."),
- i18n("password too short"));
+ i18n("Password too short"));
}
int PwMDocUi::dirtyAskSave(const QString &docTitle)
{
int ret;
#ifndef PWM_EMBEDDED
ret = KMessageBox::questionYesNoCancel(currentView,
- i18n("The list \"") +
+ i18n("The list\n\"") +
docTitle +
i18n
("\" has been modified.\n"
"Do you want to save it?"),
- i18n("save?"));
+ i18n("Save?"));
if (ret == KMessageBox::Yes) {
return 0;
} else if (ret == KMessageBox::No) {
return 1;
}
#else
+ QString doc = docTitle;
+ if ( doc.length() > 33 )
+ doc = "..." + doc.right(30);
ret = KMessageBox::warningYesNoCancel(currentView,
- i18n("The list \"") +
- docTitle +
+ i18n("The list\n \"") +
+ doc +
i18n
("\"\nhas been modified.\n"
"Do you want to save it?"),
- i18n("save?"));
+ i18n("Save?"));
if (ret == KMessageBox::Yes) {
return 0;
} else if (ret == KMessageBox::No) {
return 1;
}
#endif
// cancel
return -1;
}
bool PwMDocUi::saveDocUi(PwMDoc *doc)
{
PWM_ASSERT(doc);
doc->timer()->getLock(DocTimer::id_autoLockTimer);
if (doc->isDocEmpty()) {
KMessageBox::information(currentView,
i18n
("Sorry, there's nothing to save.\n"
"Please first add some passwords."),
i18n("nothing to do"));
doc->timer()->putLock(DocTimer::id_autoLockTimer);
return true;
}
PwMerror ret = doc->saveDoc(conf()->confGlobCompression());
if (ret == e_filename) {
doc->timer()->putLock(DocTimer::id_autoLockTimer);
return saveAsDocUi(doc);
} else if (ret == e_weakPw) {
KMessageBox::error(currentView,
i18n("Error: This is a weak password.\n"
"Please select another password."),
i18n("weak password"));
doc->timer()->putLock(DocTimer::id_autoLockTimer);
return false;
} else if (ret == e_fileBackup) {
KMessageBox::error(currentView,
i18n("Error: Couldn't make backup-file!"),
i18n("backup failed"));
doc->timer()->putLock(DocTimer::id_autoLockTimer);
return false;
} else if (ret == e_noPw ||
ret == e_wrongPw ||
ret == e_openFile) {
doc->timer()->putLock(DocTimer::id_autoLockTimer);
return false;
} else if (ret != e_success) {
KMessageBox::error(currentView,
i18n("Error: Couldn't write to file.\n"
"Please check if you have permission to\n"
"write to the file in that directory."),
i18n("error while writing"));
doc->timer()->putLock(DocTimer::id_autoLockTimer);
return false;
}
doc->timer()->putLock(DocTimer::id_autoLockTimer);
return true;
}
bool PwMDocUi::saveAsDocUi(PwMDoc *doc)
{
PWM_ASSERT(doc);
doc->timer()->getLock(DocTimer::id_autoLockTimer);
if (doc->isDocEmpty()) {
KMessageBox::information(currentView,
i18n
("Sorry, there's nothing to save.\n"
"Please first add some passwords."),
i18n("nothing to do"));
doc->timer()->putLock(DocTimer::id_autoLockTimer);
return true;
}
#ifndef PWM_EMBEDDED
QString fn(KFileDialog::getSaveFileName(QString::null,
i18n("*.pwm|PwManager Password file"),
currentView));
#else
QString fn = locateLocal( "data", KGlobal::getAppName() + "/*.pwm" );
fn = KFileDialog::getSaveFileName(fn,
i18n("password filename(*.pwm)"),
currentView);
#endif
if (fn == "") {
doc->timer()->putLock(DocTimer::id_autoLockTimer);
return false;
}
if (fn.right(4) != ".pwm")
fn += ".pwm";
PwMerror ret = doc->saveDoc(conf()->confGlobCompression(), &fn);
if (ret == e_noPw ||
ret == e_wrongPw ||
ret == e_openFile) {
doc->timer()->putLock(DocTimer::id_autoLockTimer);
return false;
} else if (ret != e_success) {
KMessageBox::error(currentView,
i18n("Error: Couldn't write to file.\n"
"Please check if you have permission to\n"
"write to the file in that directory."),
i18n("error while writing"));
doc->timer()->putLock(DocTimer::id_autoLockTimer);
return false;
}
doc->timer()->putLock(DocTimer::id_autoLockTimer);
return true;
}
bool PwMDocUi::openDocUi(PwMDoc *doc,
QString filename,
bool openDeepLocked)
{
if (filename.isEmpty())
{
#ifndef PWM_EMBEDDED
filename = KFileDialog::getOpenFileName(QString::null,
i18n("*.pwm|PwManager Password file\n"
"*|All files"), getCurrentView());
#else
filename = locateLocal( "data", KGlobal::getAppName() + "/*.pwm");
filename = KFileDialog::getOpenFileName(filename,
i18n("password filename(*.pwm)"), getCurrentView());
#endif
}
if (filename.isEmpty())
goto cancelOpen;
PwMerror ret;
while (true) {
int lockStat = -1;
if (openDeepLocked) {
lockStat = 2;
} else {
if (conf()->confGlobUnlockOnOpen()) {
lockStat = 0;
} else {
lockStat = 1;
}
}
ret = doc->openDoc(&filename, lockStat);
//qDebug("pwmdocui::OpenDocui %i", ret);
if (ret != e_success) {
if (ret == e_readFile || ret == e_openFile) {
KMessageBox::error(getCurrentView(),
i18n("Could not read file!")
+ "\n"
+ filename,
i18n("File error"));
goto cancelOpen;
}
if (ret == e_alreadyOpen) {
KMessageBox::error(getCurrentView(),
i18n("This file is already open."),
i18n("Already open"));
goto cancelOpen;
}
if (ret == e_fileVer) {
KMessageBox::error(getCurrentView(),
i18n
("File-version is not supported!\n"
"Did you create this file with an\nolder or newer version of PwM?"),
i18n
("Incompatible version"));
goto cancelOpen;
}
if (ret == e_wrongPw) {
continue;
}
if (ret == e_noPw) {
goto cancelOpen;
}
if (ret == e_fileFormat) {
KMessageBox::error(getCurrentView(),
i18n
("Sorry, this file has not been recognized\n"
"as a PwM Password file.\n"
"Probably you have selected the wrong file."),
i18n
("No PwM password-file"));
goto cancelOpen;
}
if (ret == e_fileCorrupt) {
KMessageBox::error(getCurrentView(),
i18n
("File corrupt!\n"
"Maybe the media, you stored this file on,\n"
"had bad sectors?"),
i18n
("Checksum error"));
goto cancelOpen;
}
}
break;
}
return true;
cancelOpen:
return false;
}
QString PwMDocUi::string_defaultCategory()
{
return i18n("Default");
}
QString PwMDocUi::string_locked()
{
return i18n("<LOCKED>");
}
QString PwMDocUi::string_deepLockedShort()
{
return i18n("DEEP-LOCKED");
}
QString PwMDocUi::string_deepLockedLong()
{
return i18n("This file is DEEP-LOCKED!\n"
"That means all data has been encrypted\n"
"and written out to the file. If you want\n"
"to see the entries, please UNLOCK the file.\n"
"While unlocking, you will be prompted for the\n"
"master-password or the key-card.");
}
QString PwMDocUi::string_defaultTitle()
{
return i18n("Untitled");
}
#ifndef PWM_EMBEDDED
#include "pwmdocui.moc"
#endif
diff --git a/pwmanager/pwmanager/pwminit.cpp b/pwmanager/pwmanager/pwminit.cpp
index d775aa9..fbd17a7 100644
--- a/pwmanager/pwmanager/pwminit.cpp
+++ b/pwmanager/pwmanager/pwminit.cpp
@@ -1,641 +1,650 @@
/***************************************************************************
* *
* 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;
#ifdef _WIN32_
static void sig_handler(int signum)
#else
static NOREGPARM void sig_handler(int signum)
#endif
{
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()
{
+ qDebug("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();
bool openDeeplocked = false;
if (conf()->confGlobAutostartDeepLocked() ||
savedCmd.open_deeplocked)
openDeeplocked = true;
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)
{
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) {
-
+ qDebug("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) {
+ qDebug("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
+
+ if ( app->mainWidget() == wnd ) {
+ if ( _mainWndList.count() ) {
+#ifndef DESKTOP_VERSION
+ app->showMainWidget(_mainWndList.first() );
+#endif //DESKTOP_VERSION
+
+ }
+ }
+ delete wnd;
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 {
PwM *newInstance = createMainWnd(QString::null,
false,
true,
0,
savedCmd.minimized);
PwMDoc *newDoc = newInstance->openDoc(curArg,
savedCmd.open_deeplocked);
if (!newDoc) {
newInstance->setForceQuit(true);
delete_and_null(newInstance);
}
}
}
if (savedCmd.minToTray) {
minimizeAllMainWnd(true);
} else if (savedCmd.minimized) {
minimizeAllMainWnd(false);
}
if (!savedCmd.skipSelfTest && initial) {
SelfTest::schedule();
}
args->clear();
#endif
}
void PwMInit::minimizeAllMainWnd(bool toTray)
{
#ifndef PWM_EMBEDDED
if (!_mainWndList.size())
return;
#else
if (!_mainWndList.count())
return;
#endif
const QValueList<PwM *> *ml = mainWndList();
#ifndef PWM_EMBEDDED
QValueList<PwM *>::const_iterator it = ml->begin(),
end = ml->end();
#else
QValueList<PwM *>::ConstIterator it = ml->begin(),
end = ml->end();
#endif
PwM *wnd;
if (toTray && _tray) {
/* minimize to tray.
* close all mainWnd.
*/
while (it != end) {
wnd = *it;
wnd->setForceMinimizeToTray(true);
wnd->close_slot();
++it;
}
} else {
// normal minimize
while (it != end) {
wnd = *it;
wnd->hide();
wnd->showMinimized();
++it;
}
}
}
#ifdef PWM_EMBEDDED
#ifndef DESKTOP_VERSION
PwMApplication::PwMApplication(int & argc, char ** argv)
: QPEApplication( argc, argv )
, init (0)
{
this->setKeepRunning ();
}
PwMApplication::~PwMApplication()
{
delete_ifnot_null(init);
}
#else //DESKTOP_VERSION
PwMApplication::PwMApplication(int & argc, char ** argv)
: QApplication( argc, argv )
, init (0)
{
setStyle( new QPlatinumStyle ());
QString hdir = QDir::homeDirPath();
// there is a bug when creating dirs for WIN 98
// it is difficult to fix, because we have no WIN 98 runnung
// such that we try it to create the dirs at startup here
if ( hdir == "C:\\" )
{
// win 98 or ME
QDir app_dir;
if ( !app_dir.exists("C:\\kdepim") )
app_dir.mkdir ("C:\\kdepim");
if ( !app_dir.exists("C:\\kdepim\\apps") )
app_dir.mkdir ("C:\\kdepim\\apps");
if ( !app_dir.exists("C:\\kdepim\\config") )
app_dir.mkdir ("C:\\kdepim\\config");
if ( !app_dir.exists("C:\\kdepim\\apps\\pwmanager") )
app_dir.mkdir ("C:\\kdepim\\apps\\pwmanager");
}
}
PwMApplication::~PwMApplication()
{
delete_ifnot_null(init);
}
#endif //DESKTOP_VERSION
#endif //PWM_EMBEDDED
#ifndef PWM_EMBEDDED
#include "pwminit.moc"
#endif