- support for precompiled headers

- made password dialog more userfriendly (especially key file creation/selection)
- database file as command line argument is recognized again
- fixed bug #1825446 (commandline option -cfg does NOT take relative path)
- fixed mac buid problem (see item #1908868)


git-svn-id: https://svn.code.sf.net/p/keepassx/code/trunk@174 b624d157-de02-0410-bad0-e51aec6abb33
master
tarek_saidi 17 years ago
parent 97bac939dd
commit bdec5c8450
  1. 12
      changelog
  2. 1
      src/Application_X11.cpp
  3. 1
      src/Application_X11.h
  4. 4
      src/Database.cpp
  5. 28
      src/Database.h
  6. 84
      src/Kdb3Database.cpp
  7. 22
      src/Kdb3Database.h
  8. 5
      src/KpxConfig.cpp
  9. 9
      src/KpxConfig.h
  10. 2
      src/crypto/twofish.cpp
  11. 4
      src/crypto/twofish.h
  12. 4
      src/crypto/yarrow.cpp
  13. 5
      src/dialogs/AboutDlg.cpp
  14. 4
      src/dialogs/AboutDlg.h
  15. 5
      src/dialogs/AddBookmarkDlg.cpp
  16. 4
      src/dialogs/AddBookmarkDlg.h
  17. 6
      src/dialogs/AutoTypeDlg.cpp
  18. 1
      src/dialogs/AutoTypeDlg.h
  19. 3
      src/dialogs/CalendarDlg.cpp
  20. 1
      src/dialogs/CalendarDlg.h
  21. 5
      src/dialogs/CollectEntropyDlg.cpp
  22. 6
      src/dialogs/CollectEntropyDlg.h
  23. 8
      src/dialogs/CustomizeDetailViewDlg.cpp
  24. 2
      src/dialogs/CustomizeDetailViewDlg.h
  25. 9
      src/dialogs/DatabaseSettingsDlg.cpp
  26. 3
      src/dialogs/DatabaseSettingsDlg.h
  27. 16
      src/dialogs/EditEntryDlg.cpp
  28. 4
      src/dialogs/EditEntryDlg.h
  29. 2
      src/dialogs/EditGroupDlg.cpp
  30. 3
      src/dialogs/EditGroupDlg.h
  31. 7
      src/dialogs/ExpiredEntriesDlg.cpp
  32. 4
      src/dialogs/ExpiredEntriesDlg.h
  33. 7
      src/dialogs/ManageBookmarksDlg.cpp
  34. 3
      src/dialogs/ManageBookmarksDlg.h
  35. 548
      src/dialogs/PasswordDlg.cpp
  36. 93
      src/dialogs/PasswordDlg.h
  37. 14
      src/dialogs/PasswordGenDlg.cpp
  38. 3
      src/dialogs/PasswordGenDlg.h
  39. 10
      src/dialogs/SearchDlg.cpp
  40. 4
      src/dialogs/SearchDlg.h
  41. 13
      src/dialogs/SelectIconDlg.cpp
  42. 5
      src/dialogs/SelectIconDlg.h
  43. 12
      src/dialogs/SettingsDlg.cpp
  44. 5
      src/dialogs/SettingsDlg.h
  45. 5
      src/dialogs/SimplePasswordDlg.cpp
  46. 6
      src/export/Export.cpp
  47. 4
      src/export/Export.h
  48. 3
      src/export/Export_KeePassX_Xml.cpp
  49. 1
      src/export/Export_KeePassX_Xml.h
  50. 5
      src/export/Export_Txt.cpp
  51. 1
      src/export/Export_Txt.h
  52. 345
      src/forms/PasswordDlg.ui
  53. 6
      src/import/Import.cpp
  54. 5
      src/import/Import.h
  55. 5
      src/import/Import_KWalletXml.cpp
  56. 2
      src/import/Import_KWalletXml.h
  57. 4
      src/import/Import_KeePassX_Xml.cpp
  58. 1
      src/import/Import_KeePassX_Xml.h
  59. 11
      src/import/Import_PwManager.cpp
  60. 4
      src/import/Import_PwManager.h
  61. 3
      src/lib/AutoType.h
  62. 12
      src/lib/AutoType_X11.cpp
  63. 20
      src/lib/EntryView.cpp
  64. 10
      src/lib/EntryView.h
  65. 6
      src/lib/FileDialogs.cpp
  66. 6
      src/lib/FileDialogs.h
  67. 19
      src/lib/GroupView.cpp
  68. 5
      src/lib/GroupView.h
  69. 1
      src/lib/HelperX11.cpp
  70. 5
      src/lib/SecString.cpp
  71. 5
      src/lib/SecString.h
  72. 1
      src/lib/ShortcutWidget.h
  73. 9
      src/lib/UrlLabel.cpp
  74. 2
      src/lib/UrlLabel.h
  75. 5
      src/lib/WaitAnimationWidget.cpp
  76. 7
      src/lib/WaitAnimationWidget.h
  77. 4
      src/lib/bookmarks.cpp
  78. 3
      src/lib/bookmarks.h
  79. 6
      src/lib/random.h
  80. 41
      src/lib/tools.cpp
  81. 6
      src/lib/tools.h
  82. 34
      src/main.cpp
  83. 32
      src/main.h
  84. 4
      src/main_macx.cpp
  85. 56
      src/main_unix.cpp
  86. 2
      src/main_win32.cpp
  87. 111
      src/mainwindow.cpp
  88. 20
      src/mainwindow.h
  89. 122
      src/src.pro

@ -1,3 +1,15 @@
---------------
0.3.1
---------------
- made key/password dialog more user friendly
- program accepts Qt command line switches like "-style" again
---------------
0.3.0a
---------------
- fixed bug which prevented MacOS X bundle from starting (Bug #1906517)
- fixed error message about missing license file when opening about dialog (Bug #1906696)
---------------
0.3.0
---------------

@ -17,6 +17,7 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "Application_X11.h"
#include "lib/AutoType.h"
#include "lib/HelperX11.h"

@ -20,7 +20,6 @@
#ifndef APPLICATION_X11_H
#define APPLICATION_X11_H
#include <QApplication>
class KeepassApplication : public QApplication
{

@ -18,9 +18,7 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "Database.h"
#include "lib/random.h"
#include <QCoreApplication>
KpxUuid::KpxUuid(){
Data.fill(0,16);

@ -21,14 +21,6 @@
#ifndef _DATABASE_H_
#define _DATABASE_H_
#include <QList>
#include <QDateTime>
#include <QFile>
#include <QPixmap>
#include <QByteArray>
#include "lib/SecString.h"
using namespace std;
extern const QDateTime Date_Never;
typedef enum CryptAlgorithm{
@ -246,6 +238,9 @@ This is the common base interface for databases. Every database class must imple
class IDatabase:public QObject{
public:
virtual ~IDatabase(){};
virtual bool setKey(const QString& password,const QString& keyfile)=0;
virtual bool isKeyError()=0;
//! Loads a database.
/*! It is not allowed to call this function if a database is already loaded.
@ -409,23 +404,6 @@ public:
};
//! Interface for password/file based authentication
class IFilePasswordAuth{
public:
virtual void authByPwd(QString& password)=0;
virtual bool authByFile(QString& filename)=0;
virtual bool authByFileAndPwd(QString& password, QString& filename)=0;
/*! Creates a key file.
\param filename Filename of the new key file.
\param length Length of the key file.
\param Hex Wether the key file should be binary or hexadecimal ASCII code. If Hex is true the real file size will be double of length.
\return TRUE if the creation was successfull, otherwise FALSE.
*/
virtual bool createKeyFile(const QString& filename,int length=32, bool Hex=false)=0;
virtual bool isKeyError()=0;
};
class IKdbSettings{
public:
virtual void setCryptAlgorithm(CryptAlgorithm algo)=0;

@ -17,23 +17,9 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "global.h"
#include <iostream>
#include <time.h>
#include <QFile>
#include <QStringList>
#include <QDateTime>
#include <QSysInfo>
#include <QBuffer>
#include <QDir>
#include "crypto/twoclass.h"
#include "crypto/aescpp.h"
#include "crypto/sha256.h"
#include "crypto/yarrow.h"
#include "lib/random.h"
using namespace std;
#include "Kdb3Database.h"
#include "KpxConfig.h"
#define UNEXP_ERROR error=QString("Unexpected error in: %1, Line:%2").arg(__FILE__).arg(__LINE__);
@ -739,29 +725,26 @@ bool Kdb3Database::convHexToBinaryKey(char* HexKey, char* dst){
return true;
}
/*
void Kdb3Database::authByPwd(QString& Password){
if(!Password.size()) {
memcpy(RawMasterKey,QByteArray(32,'\0').data(),32);
return;
}
SHA256::hashBuffer(Password.toUtf8().data(),RawMasterKey,Password.toUtf8().size());
return;
}*/
bool Kdb3Database::setKey(const QString& password,const QString& keyfile){
if(!password.isEmpty() && !keyfile.isEmpty())
return setCompositeKey(password,keyfile);
if(!password.isEmpty())
return setPasswordKey(password);
if(!keyfile.isEmpty())
return setFileKey(keyfile);
assert(false);
}
void Kdb3Database::authByPwd(QString& Password){
if(!Password.size()) {
memcpy(RawMasterKey,QByteArray(32,'\0').data(),32);
return;
}
bool Kdb3Database::setPasswordKey(const QString& Password){
assert(Password.size());
SHA256::hashBuffer(Password.toLatin1().data(),RawMasterKey,Password.toLatin1().size());
QByteArray lat,utf;
utf=Password.toUtf8();
lat=Password.toLatin1();
return;
return true;
}
bool Kdb3Database::authByFile(QString& filename){
bool Kdb3Database::setFileKey(const QString& filename){
QFile file(filename);
if(!file.open(QIODevice::ReadOnly|QIODevice::Unbuffered)){
error=decodeFileError(file.error());
@ -799,14 +782,13 @@ bool Kdb3Database::authByFile(QString& filename){
return true;
}
bool Kdb3Database::authByFileAndPwd(QString& Password, QString& filename){
bool Kdb3Database::setCompositeKey(const QString& Password,const QString& filename){
unsigned char PasswordKey[32];
unsigned char FileKey[32];
if(!authByFile(filename))return false;
if(!setFileKey(filename))return false;
memcpy(FileKey,RawMasterKey,32);
authByPwd(Password);
setPasswordKey(Password);
memcpy(PasswordKey,RawMasterKey,32);
SHA256 sha;
sha.update(PasswordKey,32);
sha.update(FileKey,32);
@ -1637,38 +1619,6 @@ void Kdb3Database::rebuildIndices(QList<StdGroup*>& list){
}
}
bool Kdb3Database::createKeyFile(const QString& filename,int length, bool Hex){
QFile file(filename);
if(!file.open(QIODevice::WriteOnly|QIODevice::Truncate|QIODevice::Unbuffered)){
error=decodeFileError(file.error());
return false;
}
if(Hex)length*=2;
unsigned char* key=new unsigned char[length];
randomize(key,length);
if(Hex){
for(int i=0; i<length; i+=2){
unsigned char dig1,dig2;
dig1=key[i]/16;
key[i]-=(16*dig1);
dig2=key[i];
if(dig1>9)key[i]='A'+dig1-10;
else key[i]='0'+dig1;
if(dig2>9)key[i+1]='A'+dig2-10;
else key[i+1]='0'+dig2;
}
}
if(file.write((char*)key,length)==-1){
delete [] key;
error=decodeFileError(file.error());
file.close();
return false;
}
file.close();
delete [] key;
return true;
}
void Kdb3Database::moveGroup(IGroupHandle* groupHandle,IGroupHandle* NewParent,int Pos){
StdGroup* Parent;

@ -30,25 +30,13 @@
#define PWM_FLAG_TWOFISH 8
#define PWM_STD_KEYENCROUNDS 6000
#include <QColor>
#include <QDateTime>
#include <QDate>
#include <QTime>
#include <QStringList>
#include <QPixmap>
#include <QMap>
#include "main.h"
#include "lib/SecString.h"
#include "Database.h"
void memcpyFromLEnd32(quint32* dst,const char* src);
void memcpyFromLEnd16(quint16* dst,const char* src);
void memcpyToLEnd32(char* src,const quint32* dst);
void memcpyToLEnd16(char* src,const quint16* dst);
//! Implementation of the standard KeePassX database.
class Kdb3Database:public ICustomIcons,public IDatabase, public IFilePasswordAuth, public IKdbSettings{
class Kdb3Database:public ICustomIcons,public IDatabase, public IKdbSettings{
Q_OBJECT
public:
class StdGroup;
@ -169,10 +157,6 @@ public:
virtual void removeIcon(int index);
virtual void replaceIcon(int index,const QPixmap& icon);
virtual int builtinIcons(){return BUILTIN_ICONS;};
virtual void authByPwd(QString& password);
virtual bool authByFile(QString& filename);
virtual bool authByFileAndPwd(QString& password, QString& filename);
virtual bool createKeyFile(const QString& filename,int length=32, bool Hex=false);
virtual QList<IEntryHandle*> search(IGroupHandle* Group,const QString& SearchString, bool CaseSensitve, bool RegExp,bool Recursive,bool* Fields);
virtual QFile* file(){return File;}
virtual bool changeFile(const QString& filename);
@ -180,6 +164,10 @@ public:
virtual CryptAlgorithm cryptAlgorithm(){return Algorithm;}
virtual unsigned int keyTransfRounds(){return KeyTransfRounds;}
virtual void setKeyTransfRounds(unsigned int rounds){KeyTransfRounds=rounds;}
virtual bool setKey(const QString& password, const QString& keyfile);
virtual bool setPasswordKey(const QString& password);
virtual bool setFileKey(const QString& filename);
virtual bool setCompositeKey(const QString& password,const QString& filename);
virtual QList<IEntryHandle*> entries();
virtual QList<IEntryHandle*> entries(IGroupHandle* Group);

@ -21,12 +21,7 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "KpxConfig.h"
#include <QApplication>
#include <QSettings>
#include <QDir>
#include <QLayout>
#include <QWidget>
KpxConfig::KpxConfig(const QString& filePath) : settings(filePath,QSettings::IniFormat){
configFile=filePath;

@ -23,14 +23,7 @@
#ifndef _KPXCONFIG_H_
#define _KPXCONFIG_H_
#include "lib/tools.h"
#include "AutoType.h"
#include <QBitArray>
#include <QByteArray>
#include <QColor>
#include <QList>
#include <QSettings>
#include <QString>
#include "lib/AutoType.h"
#if defined(Q_WS_MAC)
# define DEFAULT_MOUNT_DIR "/Volumes/"

@ -171,7 +171,7 @@
* Standard include files will probably be ok.
*/
#include <QString> /* for memset(), memcpy(), and memcmp() */
//#include <QString> /* for memset(), memcpy(), and memcmp() */
#include <cstdlib>
#include "twofish.h"

@ -1,3 +1,5 @@
#ifndef TWOFISH_H_
#define TWOFISH_H_
/*
* Fast, portable, and easy-to-use Twofish implementation,
* Version 0.3.
@ -177,3 +179,5 @@ extern void Twofish_decrypt(
Twofish_Byte c[16],
Twofish_Byte p[16]
);
#endif

@ -20,10 +20,6 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#if HAVE_CONFIG_H
# include "config.h"
#endif
#include <assert.h>
#include <stdlib.h>
#include <string.h>

@ -17,10 +17,7 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include <QMessageBox>
#include <QPainter>
#include <QFile>
#include "lib/tools.h"
#include "AboutDlg.h"

@ -20,11 +20,7 @@
#ifndef _ABOUTDIALOG_H_
#define _ABOUTDIALOG_H_
#include <QPaintEvent>
#include "ui_AboutDlg.h"
#include "lib/UrlLabel.h"
#include "main.h"
class AboutDialog : public QDialog, public Ui_AboutDlg
{

@ -17,11 +17,6 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include <QFileInfo>
#include <QPainter>
#include "lib/tools.h"
#include "lib/FileDialogs.h"
#include "lib/bookmarks.h"
#include "AddBookmarkDlg.h"

@ -20,12 +20,8 @@
#ifndef _ADDBOOKMARKDLG_H_
#define _ADDBOOKMARKDLG_H_
#include <QDialog>
#include <QPaintEvent>
#include "ui_AddBookmarkDlg.h"
#include "main.h"
class AddBookmarkDlg : public QDialog, private Ui::AddBookmarkDlg
{
Q_OBJECT

@ -17,12 +17,8 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "main.h"
#include "AutoTypeDlg.h"
#include "KpxConfig.h"
#include <QDesktopWidget>
#include <QPainter>
#include <QPaintEvent>
#include "AutoTypeDlg.h"
AutoTypeDlg::AutoTypeDlg(QList<IEntryHandle*> entries, QList<int> numbers){
setupUi(this);

@ -18,7 +18,6 @@
***************************************************************************/
#include "ui_AutoTypeDlg.h"
#include "Database.h"
class AutoTypeDlg : public QWidget, private Ui::AutoTypeDlg
{

@ -18,8 +18,7 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "lib/tools.h"
#include "main.h"
#include "CalendarDlg.h"
CalendarDialog::CalendarDialog(QWidget* parent, const QDate& Start):QDialog(parent){

@ -20,7 +20,6 @@
#ifndef _CALENDAR_DLG_H_
#define _CALENDAR_DLG_H_
#include <QDate>
#include "ui_CalendarDlg.h"
class CalendarDialog:public QDialog, public Ui_CalendarDialog{

@ -18,13 +18,8 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include <QPainter>
#include <QCursor>
#include <QFile>
#include "lib/tools.h"
#include "crypto/yarrow.h"
#include "CollectEntropyDlg.h"

@ -22,12 +22,6 @@
#define _COLLECT_ENTROPY_DLG_H_
#include "ui_CollectEntropyDlg.h"
#include <QDialog>
#include <QPaintEvent>
#include <QShowEvent>
#include "main.h"
class CollectEntropyDlg: public QDialog, public Ui_CollectEntropyDlg{
Q_OBJECT

@ -18,16 +18,8 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include <QTextCursor>
#include <QTextBlockFormat>
#include <QLineEdit>
#include <QPushButton>
#include <QColorDialog>
#include <QPixmap>
#include <QMenu>
#include "main.h"
#include "CustomizeDetailViewDlg.h"
#include "KpxConfig.h"
bool DisableButtonSlots=false;

@ -21,8 +21,6 @@
#define _CUSTOMIZE_DETAIL_VIEW_H_
#include "ui_CustomizeDetailViewDlg.h"
#include <QColor>
#include <QAction>
class CustomizeDetailViewDialog : public QDialog, public Ui_CustomizeDetailViewDialog{
Q_OBJECT

@ -18,14 +18,7 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include <QPainter>
#include <QComboBox>
#include <QLineEdit>
#include <QMessageBox>
#include <QShowEvent>
#include <QFile>
#include "lib/tools.h"
#include "main.h"
#include "DatabaseSettingsDlg.h"

@ -22,9 +22,6 @@
#define DBSETTINGSDLG_H
#include "ui_DatabaseSettingsDlg.h"
#include "main.h"
#include "Database.h"
#include <QPaintEvent>
class CDbSettingsDlg : public QDialog, public Ui_DatabaseSettingsDlg
{

@ -18,29 +18,13 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "main.h"
#include "KpxConfig.h"
#include <QPalette>
#include <QFont>
#include <QProgressBar>
#include <QPixmap>
#include <QColor>
#include <QPainter>
#include <QPen>
#include <QFileDialog>
#include <QMessageBox>
#include <QToolButton>
#include <QShowEvent>
#include <QResizeEvent>
#include <math.h>
#include "SelectIconDlg.h"
#include "PasswordGenDlg.h"
#include "EditEntryDlg.h"
#include "CalendarDlg.h"
CEditEntryDlg::CEditEntryDlg(IDatabase* _db, IEntryHandle* _entry,QWidget* parent, bool modal, bool newEntry)
: QDialog(parent)
{

@ -20,10 +20,8 @@
#ifndef EDITENTRYDLG_H
#define EDITENTRYDLG_H
#include "ui_EditEntryDlg.h"
#include <QPixmap>
#include <QShowEvent>
#include "main.h"
#include "Kdb3Database.h"
class CEditEntryDlg : public QDialog, public Ui_EditEntryDialog

@ -18,9 +18,7 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "main.h"
#include <QShowEvent>
#include "EditGroupDlg.h"
#include "SelectIconDlg.h"

@ -22,9 +22,6 @@
#define EDITGROUPDLG_H
#include "ui_EditGroupDlg.h"
#include <QString>
#include <QShowEvent>
#include "Database.h"
class CEditGroupDialog : public QDialog, public Ui_EditGroupDialog
{

@ -18,12 +18,7 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include <QTreeWidget>
#include <QPainter>
#include <QPaintEvent>
#include <QResizeEvent>
#include "lib/tools.h"
#include "main.h"
#include "ExpiredEntriesDlg.h"
ExpiredEntriesDialog::ExpiredEntriesDialog(QWidget* parent,IDatabase* database,const QList<IEntryHandle*>& ExpiredEntries):QDialog(parent){

@ -21,10 +21,8 @@
#ifndef _EXP_ENTRIES_DLG_
#define _EXP_ENTRIES_DLG_
#include <QList>
#include <QPixmap>
#include "ui_ExpiredEntriesDlg.h"
#include "Database.h"
class ExpiredEntriesDialog:public QDialog, public Ui_ExpiredEntriesDialog{
Q_OBJECT

@ -17,11 +17,8 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include <QListWidget>
#include <QPainter>
#include "lib/tools.h"
#include "ManageBookmarksDlg.h"
#include "lib/bookmarks.h"
#include "dialogs/ManageBookmarksDlg.h"
#include "dialogs/AddBookmarkDlg.h"
ManageBookmarksDlg::ManageBookmarksDlg(QWidget* parent):QDialog(parent)

@ -20,9 +20,6 @@
#ifndef MANAGEBOOKMARKSDLG_H
#define MANAGEBOOKMARKSDLG_H
#include <QDialog>
#include <QCloseEvent>
#include <QPaintEvent>
#include "ui_ManageBookmarksDlg.h"
#include "main.h"

@ -1,5 +1,5 @@
/***************************************************************************
* Copyright (C) 2005-2007 by Tarek Saidi *
* Copyright (C) 2005-2008 by Tarek Saidi *
* tarek.saidi@arcor.de *
* *
* This program is free software; you can redistribute it and/or modify *
@ -17,372 +17,334 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include <QFileDialog>
#include <QDir>
#include <QStringList>
#include <QCheckBox>
#include <QLineEdit>
#include <QComboBox>
#include <QPushButton>
#include <QMessageBox>
#include <QPainter>
#include <QPalette>
#include <QMenu>
#include <QTimer>
#include "dialogs/PasswordDlg.h"
#include "main.h"
#include "KpxConfig.h"
#include "PasswordDlg.h"
#include "lib/FileDialogs.h"
#include "lib/bookmarks.h"
CPasswordDialog::CPasswordDialog(QWidget* parent,QString filename,IDatabase* DB,bool IsAuto,bool ChangeKeyMode)
PasswordDialog::PasswordDialog(QWidget* parent,DlgMode mode,DlgFlags flags,const QString& filename)
: QDialog(parent)
{
setupUi(this);
createBanner(&BannerPixmap,getPixmap("key"),tr("Database Key"),width());
Button_Bookmarks->setIcon(getIcon("bookmark"));
db=DB;
LastFile=filename;
if (ChangeKeyMode)
setWindowTitle(tr("Change Master Key"));
else
setWindowTitle(LastFile);
QString mountDir=config->mountDir();
QDir media(mountDir);
if(media.exists()){
Mode=mode;
Filename=filename;
QString BannerTitle;
if(Mode==Mode_Ask){
BannerTitle=tr("Enter Master Key");
}
else if(Mode==Mode_Set){
BannerTitle=tr("Set Master Key");
}
else if(Mode==Mode_Change){
BannerTitle=tr("Change Master Key");
}
if(filename==QString()){
setWindowTitle(tr("Database Key"));
}
else {
setWindowTitle(filename);
}
// Add list of subdirs in the mounting dir to the combobox.
// For example making /media/cd1 and /media/myflashdrive to two entries cd1 and myflashdrive in the combobox
QDir mountDir(config->mountDir());
if(mountDir.exists()){
QStringList Paths;
Paths=media.entryList(QStringList()<<"*",QDir::Dirs | QDir::NoDotAndDotDot);
Paths=mountDir.entryList(QStringList()<<"*",QDir::Dirs | QDir::NoDotAndDotDot);
for(int i=0;i<Paths.count();i++)
Combo_Dirs->addItem(mountDir+Paths[i]);
Combo_KeyFile->addItem(config->mountDir()+Paths[i]);
}
Combo_Dirs->setEditText(QString());
if(config->rememberLastKey() && config->openLastFile() && !ChangeKeyMode){
Combo_KeyFile->setEditText(QString());
if(config->rememberLastKey() && Mode!=Mode_Change && Mode!=Mode_Set){
switch(config->lastKeyType()){
case PASSWORD:
Check_Password->setChecked(true);
Check_KeyFile->setChecked(false);
Combo_KeyFile->setEditText("");
break;
case KEYFILE:
Check_Password->setChecked(false);
Check_KeyFile->setChecked(true);
Combo_KeyFile->setEditText(QDir::cleanPath(QDir::current().absoluteFilePath(config->lastKeyLocation())));
break;
case BOTH:
Check_Password->setChecked(true);
Check_KeyFile->setChecked(true);
Combo_KeyFile->setEditText(QDir::cleanPath(QDir::current().absoluteFilePath(config->lastKeyLocation())));
break;
}
}
if(Mode!=Mode_Set && Mode!=Mode_Change){
Button_GenKeyFile->hide();
}
if(flags & Flag_Auto){
/*
QPushButton* Button_Quit = buttonBox->addButton(tr("Quit"),QDialogButtonBox::DestructiveRole);
connect(Button_Quit,SIGNAL(clicked()),this,SLOT(OnButtonQuit()));
*/
if(config->rememberLastKey()){
switch(config->lastKeyType()){
case PASSWORD:
Check_Password->setChecked(true);
Check_KeyFile->setChecked(false);
break;
case KEYFILE:
setStateKeyFileOnly();
Combo_Dirs->setEditText(QDir::cleanPath(QDir::current().absoluteFilePath(config->lastKeyLocation())));
Check_Password->setChecked(false);
Check_KeyFile->setChecked(true);
Combo_KeyFile->setEditText(config->lastKeyLocation());
break;
case BOTH:
setStateBoth();
CheckBox_Both->setChecked(true);
Combo_Dirs->setEditText(QDir::cleanPath(QDir::current().absoluteFilePath(config->lastKeyLocation())));
Check_Password->setChecked(true);
Check_KeyFile->setChecked(true);
Combo_KeyFile->setEditText(config->lastKeyLocation());
break;
}
}
// if(LastKeyType==Password){... is not required because it is already the default state.
}
// Bookmarks //
QPalette palette=Button_Bookmarks->palette();
palette.setColor(QPalette::Active,QPalette::Button,config->bannerColor1());
palette.setColor(QPalette::Active,QPalette::Window,config->bannerColor2());
Button_Bookmarks->setPalette(palette);
palette=Label_Bookmark->palette();
palette.setColor(QPalette::Active,QPalette::WindowText,config->bannerTextColor());
Label_Bookmark->setPalette(palette);
QMenu* BookmarkMenu=new QMenu(this);
QAction* action=new QAction(this);
action->setData(QString());
action->setText(tr("Last File"));
action->setIcon(getIcon("document"));
BookmarkMenu->addAction(action);
BookmarkMenu->addSeparator();
for(int i=0;i<KpxBookmarks::count();i++){
// Setting up the bookmark button
if(Mode==Mode_Ask && config->featureBookmarks()){
// Button Color
QPalette palette=Button_Bookmarks->palette();
palette.setColor(QPalette::Active,QPalette::Button,config->bannerColor1());
palette.setColor(QPalette::Active,QPalette::Window,config->bannerColor2());
Button_Bookmarks->setPalette(palette);
palette=Label_Bookmark->palette();
palette.setColor(QPalette::Active,QPalette::WindowText,config->bannerTextColor());
Label_Bookmark->setPalette(palette);
// Create menu and add "last file" menu entry
QMenu* BookmarkMenu=new QMenu(this);
QAction* action=new QAction(this);
action->setData(KpxBookmarks::path(i));
action->setText(KpxBookmarks::title(i));
action->setData(QString());
action->setText(tr("Last File"));
action->setIcon(getIcon("document"));
BookmarkMenu->addAction(action);
BookmarkMenu->addAction(action);
BookmarkMenu->addSeparator();
// Adding all existing bookmarks
for(int i=0;i<KpxBookmarks::count();i++){
QAction* action=new QAction(this);
action->setData(KpxBookmarks::path(i));
action->setText(KpxBookmarks::title(i));
action->setIcon(getIcon("document"));
BookmarkMenu->addAction(action);
}
Button_Bookmarks->setMenu(BookmarkMenu);
connect(BookmarkMenu,SIGNAL(triggered(QAction*)),this,SLOT(OnBookmarkTriggered(QAction*)));
}
Button_Bookmarks->setMenu(BookmarkMenu);
if(!IsAuto || !config->featureBookmarks()){
else {
Button_Bookmarks->hide();
Label_Bookmark->hide();
}
connect(Combo_Dirs, SIGNAL( editTextChanged(const QString&) ),this, SLOT( OnComboTextChanged(const QString&)));
connect(ButtonBox, SIGNAL( rejected() ), this, SLOT( OnCancel() ) );
connect(Edit_Password, SIGNAL( textChanged(const QString&) ), this, SLOT( OnPasswordChanged(const QString&) ) );
connect(CheckBox_Both, SIGNAL( stateChanged(int) ), this, SLOT( OnCheckBox_BothChanged(int) ) );
connect(buttonBox->button(QDialogButtonBox::Cancel), SIGNAL( clicked() ), this, SLOT( OnCancel() ) );
connect(ButtonChangeEchoMode, SIGNAL( clicked() ), this, SLOT( ChangeEchoModeDatabaseKey() ) );
connect(Edit_Password, SIGNAL( returnPressed() ), this, SLOT( OnOK() ) );
connect(Edit_PasswordRep, SIGNAL( returnPressed() ), this, SLOT( OnOK() ) );
connect(BookmarkMenu,SIGNAL(triggered(QAction*)),this,SLOT(OnBookmarkTriggered(QAction*)));
Mode_Set=ChangeKeyMode;
if(!ChangeKeyMode){
Edit_PasswordRep->hide();
Label_PasswordRep->hide();
connect( ButtonBox, SIGNAL( accepted() ), this, SLOT( OnOK() ) );
connect( ButtonBrowse, SIGNAL( clicked() ), this, SLOT( OnButtonBrowse() ) );
}else{
connect( ButtonBox, SIGNAL( accepted() ), this, SLOT( OnOK_Set() ) );
connect( ButtonBrowse, SIGNAL( clicked() ), this, SLOT( OnButtonBrowse_Set() ) );
}
connect(Edit_PwRepeat, SIGNAL( returnPressed() ), this, SLOT( OnOK() ) );
connect(buttonBox->button(QDialogButtonBox::Ok), SIGNAL( clicked() ), this, SLOT( OnOK() ) );
connect(Button_Browse, SIGNAL( clicked() ), this, SLOT( OnButtonBrowse() ) );
connect(Button_GenKeyFile,SIGNAL(clicked()),this,SLOT(OnGenKeyFile()));
connect(Check_Password,SIGNAL(stateChanged(int)),this,SLOT(OnCheckBoxesChanged(int)));
connect(Check_KeyFile,SIGNAL(stateChanged(int)),this,SLOT(OnCheckBoxesChanged(int)));
connect(Button_Back,SIGNAL(clicked()),this,SLOT(OnButtonBack()));
if(!config->showPasswordsPasswordDlg())ChangeEchoModeDatabaseKey();
adjustSize();
setMaximumSize(size());
setMinimumSize(size());
createBanner(&BannerPixmap,getPixmap("key"),BannerTitle,width());
Button_Bookmarks->setIcon(getIcon("bookmark"));
OnCheckBoxesChanged(0);
}
void CPasswordDialog::setStatePasswordOnly(){
Combo_Dirs->setEnabled(false);
ButtonBrowse->setEnabled(false);
Label_KeyFile->setEnabled(false);
Label_Password->setEnabled(true);
Label_PasswordRep->setEnabled(true);
Edit_Password->setEnabled(true);
Edit_PasswordRep->setEnabled(true);
ButtonChangeEchoMode->setEnabled(true);
KeyType=PASSWORD;
}
void CPasswordDialog::setStateKeyFileOnly(){
Combo_Dirs->setEnabled(true);
ButtonBrowse->setEnabled(true);
Label_KeyFile->setEnabled(true);
Label_Password->setEnabled(false);
Label_PasswordRep->setEnabled(false);
Edit_Password->setEnabled(false);
Edit_PasswordRep->setEnabled(false);
ButtonChangeEchoMode->setEnabled(false);
KeyType=KEYFILE;
}
void CPasswordDialog::setStateBoth(){
Combo_Dirs->setEnabled(true);
ButtonBrowse->setEnabled(true);
Label_KeyFile->setEnabled(true);
Label_Password->setEnabled(true);
Label_PasswordRep->setEnabled(true);
Edit_Password->setEnabled(true);
Edit_PasswordRep->setEnabled(true);
ButtonChangeEchoMode->setEnabled(true);
KeyType=BOTH;
}
void CPasswordDialog::OnButtonBrowse()
void PasswordDialog::OnButtonBrowse()
{
QString filename=KpxFileDialogs::openExistingFile(this,"PasswordDlg",tr("Select a Key File"),
QStringList() << tr("Key Files (*.key)") << tr("All Files (*)"));
if(filename!=QString()){
Combo_Dirs->setEditText(filename);
}
return;
QStringList() << tr("All Files (*)")
<< tr("Key Files (*.key)"));
if(filename!=QString())
Combo_KeyFile->setEditText(filename);
}
void CPasswordDialog::OnButtonBrowse_Set()
void PasswordDialog::OnCancel()
{
QString filename=KpxFileDialogs::saveFile(this,"PasswordDlg",tr("Select a Key File"),
QStringList() << tr("Key Files (*.key)") << tr("All Files (*)"),
false);
if(filename!=QString()){
Combo_Dirs->setEditText(filename);
}
return;
done(Exit_Cancel);
}
void CPasswordDialog::OnCancel()
{
done(0);
}
void CPasswordDialog::OnOK(){
password=Edit_Password->text();
keyfile=Combo_Dirs->currentText();
if(password.isEmpty() && keyfile.isEmpty()){
QMessageBox::warning(this,tr("Error"),tr("Please enter a Password or select a key file."),tr("OK"),"","",0,0);
void PasswordDialog::OnOK(){
if(stackedWidget->currentIndex()==1){
if(Password==Edit_PwRepeat->text()){
done(Exit_Ok);
}
Edit_PwRepeat->clear();
Edit_PwRepeat->setFocus(Qt::OtherFocusReason);
Label_Unequal->show();
QTimer::singleShot(2000,Label_Unequal,SLOT(hide()));
return;
}
if(KeyType==BOTH){
if(password.isEmpty()){
QMessageBox::warning(this,tr("Error"),tr("Please enter a Password."),tr("OK"),"","",0,0);
return;}
if(keyfile.isEmpty()){
QMessageBox::warning(this,tr("Error"),tr("Please choose a key file."),tr("OK"),"","",0,0);
return;}
Password=Edit_Password->text();
KeyFile=Combo_KeyFile->currentText();
if(!Check_Password->isChecked() && !Check_KeyFile->isChecked()){
showErrMsg(tr("Please enter a Password or select a key file."),this);
return;
}
if(Check_Password->isChecked() && Password.isEmpty()){
showErrMsg(tr("Please enter a Password."));
return;
}
if(Check_KeyFile->isChecked() && KeyFile.isEmpty()){
showErrMsg(tr("Please provide a key file."));
return;
}
if(KeyType==BOTH || KeyType==KEYFILE){
QFileInfo fileinfo(keyfile);
if(Check_KeyFile->isChecked()){
/* Check wether key path exists and is readable */
QFileInfo fileinfo(KeyFile);
if(!fileinfo.exists()){
QMessageBox::warning(this,tr("Error"),tr("The selected key file or directory does not exist."),tr("OK"),"","",0,0);
showErrMsg(tr("%1:\nNo such file or directory.").arg(KeyFile),this);
return;
}
if(!fileinfo.isReadable()){
QMessageBox::warning(this,tr("Error"),tr("The selected key file or directory is not readable.\nPlease check your permissions."),tr("OK"),"","",0,0);
showErrMsg(tr("The selected key file or directory is not readable."),this);
return;
}
/* If the given path is a directory, we need to find the key file in it */
if(fileinfo.isDir()){
if(keyfile.right(1)!="/")keyfile+="/";
QFile file(keyfile+"pwsafe.key");
if(!file.exists()){
QDir dir(keyfile);
if(KeyFile.right(1)!="/")KeyFile+="/";
// First, we try to find $path/pwsafe.key
QFile file(KeyFile+"pwsafe.key");
if(file.exists())
KeyFile+="pwsafe.key";
else{
// If pwsafe.key does not exist, we try to see if there is exactly one file in the
// given directory which has the extension *.key.
QDir dir(KeyFile);
QStringList files;
files=dir.entryList(QStringList()<<"*.key",QDir::Files);
// No Key Files
if(!files.size()){
QMessageBox::warning(this,tr("Error"),tr("The given directory does not contain any key files."),tr("OK"),"","",0,0);
return;}
if(files.size()>1){
QMessageBox::warning(this,tr("Error"),tr("The given directory contains more then one key file.\nPlease specify the key file directly."),tr("OK"),"","",0,0);
return;}
QFile file(keyfile+files[0]);
Q_ASSERT(file.exists());
if(!QFileInfo(file).isReadable()){
QMessageBox::warning(this,tr("Error"),tr("The key file found in the given directory is not readable.\nPlease check your permissions."),tr("OK"),"","",0,0);
return;}
keyfile+=files[0];
showErrMsg(tr("The given directory does not contain any key files."),this);
return;
}
else{ /* pwsafe.key exists */
if(!QFileInfo(file).isReadable()){
QMessageBox::warning(this,tr("Error"),tr("The key file found in the given directory is not readable.\nPlease check your permissions."),tr("OK"),"","",0,0);
return;}
keyfile+="pwsafe.key";
// More than one key file
if(files.size()>1){
showErrMsg(tr("The given directory contains more then one key files.\n"
"Please specify the key file directly."),this);
return;
}
}
else{ /* not a directory */
QFile file(keyfile);
if(!file.exists()){
QMessageBox::warning(this,tr("Error"),tr("Key file could not be found."),tr("OK"),"","",0,0);
return;}
if(!QFileInfo(file).isReadable()){
QMessageBox::warning(this,tr("Error"),tr("Key file is not readable.\nPlease check your permissions."),tr("OK"),"","",0,0);
return;}
}
}
if(doAuth())done(1);
}
void CPasswordDialog::OnOK_Set(){
password=Edit_Password->text();
if(password!=Edit_PasswordRep->text()){
QMessageBox::warning(this,tr("Warning"),tr("Password an password repetition are not equal.\nPlease check your input."),tr("OK"),"","",0,0);
return;
}
keyfile=Combo_Dirs->currentText();
if(password.isEmpty() && keyfile.isEmpty()){
QMessageBox::warning(this,tr("Error"),tr("Please enter a password or select a key file."),tr("OK"),"","",0,0);
return;
}