work on CPasswordDlg (incomplete)

git-svn-id: https://svn.code.sf.net/p/keepassx/code/trunk@54 b624d157-de02-0410-bad0-e51aec6abb33
This commit is contained in:
tariq
2006-03-15 07:06:23 +00:00
parent 853747bce1
commit e0a2197b53
14 changed files with 438 additions and 1844 deletions

View File

@@ -18,6 +18,7 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "main.h"
#include "PwmConfig.h"
#include "PwManager.h"
#include "../lib/random.h"
#include "ChangeKeyDlg.h"
@@ -93,7 +94,7 @@ Q_UINT8 pw_key[32]={0};
if(keyfile!=""){
QFile file(keyfile);
if(file.exists()){
int r=QMessageBox::warning(this,tr("Overwrite?"),tr("A file with this name already exists.\nDo you want to replace it?"),"Yes","No",NULL,1,1);
int r=QMessageBox::warning(this,tr("Overwrite?"),tr("A key file with this name already exists.\nDo you want to replace it?"),"Yes","No",NULL,1,1);
if(r==1)return;}
getRandomBytes(file_key,1,32,true);
if(file.open(QIODevice::WriteOnly | QIODevice::Truncate)==false){

View File

@@ -18,7 +18,7 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "main.h"
#include "PwmConfig.h"
#include <qpushbutton.h>
#include <qpalette.h>
#include <qfont.h>

View File

@@ -19,30 +19,24 @@
***************************************************************************/
#include "main.h"
#include "PwmConfig.h"
#include "PasswordDlg.h"
#include <qdir.h>
#include <qstringlist.h>
#include <qcheckbox.h>
#include <q3valuelist.h>
#include <qlineedit.h>
#include <qcombobox.h>
#include <qpushbutton.h>
#include <q3filedialog.h>
#include <qmessagebox.h>
#include <QFileDialog>
#include <QDir>
#include <QStringList>
#include <QCheckBox>
#include <QLineEdit>
#include <QComboBox>
#include <QPushButton>
#include <QMessageBox>
CPasswordDialog::CPasswordDialog(QWidget* parent, const char* name, bool modal, bool ShowExitButton, Qt::WFlags fl)
CPasswordDialog::CPasswordDialog(QWidget* parent, const char* name, bool modal, bool ShowExitButton,bool ChangeKeyMode, Qt::WFlags fl)
: QDialog(parent,name, modal,fl)
{
setupUi(this);
ButtonExit->setVisible(ShowExitButton);
createBanner(Banner,Icon_Key32x32,tr("Open Database"));
Label_select=new LinkLabel((QWidget*)groupframe,"Select",tr("Select File Manually..."),410,100);
connect( Combo_Dirs, SIGNAL( activated(int) ), this, SLOT( OnComboSelectionChanged(int) ) );
connect( ButtonBrowse, SIGNAL( clicked() ), this, SLOT( OnButtonBrowse() ) );
connect( ButtonOK, SIGNAL( clicked() ), this, SLOT( OnOK() ) );
createBanner(Banner,Icon_Key32x32,tr("Database Key"));
connect( Combo_Dirs, SIGNAL( editTextChanged(const QString&) ),this, SLOT( OnComboTextChanged(const QString&)));
connect( ButtonCancel, SIGNAL( clicked() ), 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) ) );
@@ -50,99 +44,85 @@ connect( ButtonChangeEchoMode, SIGNAL( clicked() ), this, SLOT( ChangeEchoMode()
connect( Edit_Password, SIGNAL( returnPressed() ), this, SLOT( OnOK() ) );
connect( ButtonExit, SIGNAL( clicked()),this,SLOT(OnButtonExit()));
QDir media("/media");
ButtonExit->setVisible(ShowExitButton);
Mode_Set=ChangeKeyMode;
if(!ChangeKeyMode){
Edit_PasswordRep->hide();
Label_PasswordRep->hide();
connect( ButtonOK, SIGNAL( clicked() ), this, SLOT( OnOK() ) );
connect( ButtonBrowse, SIGNAL( clicked() ), this, SLOT( OnButtonBrowse() ) );
}else{
connect( ButtonOK, SIGNAL( clicked() ), this, SLOT( OnOK_Set() ) );
connect( ButtonBrowse, SIGNAL( clicked() ), this, SLOT( OnButtonBrowse_Set() ) );
}
QDir media(config.MountDir);
if(media.exists()){
Paths=media.entryList("*",QDir::Dirs);
Paths.erase(Paths.begin()); // delete "."
Paths.erase(Paths.begin()); // delete ".."
for(int i=0;i<Paths.count();i++){
Paths[i]="/media/"+Paths[i];
}
Paths.prepend(tr("< none >"));
}
for(int i=0;i<Paths.count();i++){
Combo_Dirs->insertItem(0,Paths[i]);
IsFile.append(false);
QStringList Paths;
Paths=media.entryList("*",QDir::Dirs);
Paths.erase(Paths.begin()); // delete "."
Paths.erase(Paths.begin()); // delete ".."
for(int i=0;i<Paths.count();i++)
Combo_Dirs->addItem(config.MountDir+Paths[i]);
}
Combo_Dirs->setEditText(QString());
if(!config.ShowPasswords)ChangeEchoMode();
}
CPasswordDialog::~CPasswordDialog()
{
delete Label_select;
}
void CPasswordDialog::OnComboSelectionChanged(int i)
{
if(i==0){
keyfile="";
void CPasswordDialog::setStatePasswordOnly(){
Combo_Dirs->setEnabled(false);
ButtonBrowse->setEnabled(false);
Label_KeyFile->setEnabled(false);
Label_Password->setEnabled(true);
Edit_Password->setEnabled(true);
return;
ButtonChangeEchoMode->setEnabled(true);
KeyType=PASSWORD;
}
QFile file;
if(IsFile[i]==true)file.setName(Paths[i]);
else file.setName(Paths[i]+"/pwsafe.key");
if(file.exists()){
keyfile=file.name();
if(!CheckBox_Both->isChecked()){
Edit_Password->setText("");
Edit_Password->setDisabled(true);}
return;
void CPasswordDialog::setStateKeyFileOnly(){
Combo_Dirs->setEnabled(true);
ButtonBrowse->setEnabled(true);
Label_KeyFile->setEnabled(true);
Label_Password->setEnabled(false);
Edit_Password->setEnabled(false);
ButtonChangeEchoMode->setEnabled(false);
KeyType=KEYFILE;
}
QMessageBox::warning(this,tr("No key file found"),tr(
"No key file could be found in the chosen directory.\n\
Make sure that the volume is mounted correctly.\n\
Please use the manual file selection for key files with a filename other than 'pwsafe.key'.")
,tr("OK"),"","",0,0);
void CPasswordDialog::setStateBoth(){
Combo_Dirs->setEnabled(true);
ButtonBrowse->setEnabled(true);
Label_KeyFile->setEnabled(true);
Label_Password->setEnabled(true);
Edit_Password->setEnabled(true);
Combo_Dirs->setCurrentItem(0);
return;
ButtonChangeEchoMode->setEnabled(true);
KeyType=BOTH;
}
void CPasswordDialog::OnButtonBrowse()
{
QString dir=Q3FileDialog::getExistingDirectory(QDir::homeDirPath(),NULL,tr("Browse..."));
if(dir=="")return;
QFile file(dir+"/pwsafe.key");
QString filename=QFileDialog::getOpenFileName(this,tr("Select a Key File"),QDir::homeDirPath(),tr("*.key"));
if(filename=="")return;
QFile file(filename);
if(file.exists()){
keyfile=dir+"/pwsafe.key";
Combo_Dirs->insertItem(dir);
Combo_Dirs->setCurrentItem(Combo_Dirs->count()-1);
if(!CheckBox_Both->isChecked()){
Edit_Password->setDisabled(true);
Edit_Password->setText("");
password="";
Combo_Dirs->setEditText(filename);
return;
}
Paths.append(dir);
IsFile.append(false);
return;}
QMessageBox::warning(this,tr("No key file found"),tr(
"No key file could be found in the chosen directory.\n\
Make sure that the volume is mounted correctly.\n\
Please use the manual file selection for key files with a filename other than 'pwsafe.key'.")
,tr("OK"),"","",0,0);
QMessageBox::warning(this,tr("Error"),tr("Unexpected Error: File does not exist."),tr("OK"),"","",0,0);
}
void CPasswordDialog::OnSelectClicked()
void CPasswordDialog::OnButtonBrowse_Set()
{
if(ButtonBrowse->isEnabled()){
keyfile=Q3FileDialog::getOpenFileName(QDir::homeDirPath(),"",this,tr("Open Key File"));
if(keyfile=="")return;
Combo_Dirs->insertItem(keyfile);
Combo_Dirs->setCurrentItem(Combo_Dirs->count()-1);
if(!CheckBox_Both->isChecked()){
Edit_Password->setDisabled(true);
Edit_Password->setText("");
password="";
}
Paths.append(keyfile);
IsFile.append(true);
}
QString filename=QFileDialog::getSaveFileName(this,tr("Select a Key File"),QDir::homeDirPath(),tr("*.key"));
if(filename=="")return;
Combo_Dirs->setEditText(filename);
}
void CPasswordDialog::OnCancel()
@@ -150,64 +130,119 @@ void CPasswordDialog::OnCancel()
done(0);
}
void CPasswordDialog::OnOK()
{
void CPasswordDialog::OnOK(){
password=Edit_Password->text();
keyfile=Combo_Dirs->currentText();
if(CheckBox_Both->isChecked()){
if(password==""){QMessageBox::warning(this,tr("Error"),tr("Please enter a Password.")
,tr("OK"),"","",0,0);
return;}
if(keyfile==""){QMessageBox::warning(this,tr("Error"),tr("Please choose a key file.")
,tr("OK"),"","",0,0);
return;}
if(password=="" && keyfile==""){
QMessageBox::warning(this,tr("Error"),tr("Please enter a Password or select a key file."),tr("OK"),"","",0,0);
return;}
if(KeyType==BOTH){
if(password==""){
QMessageBox::warning(this,tr("Error"),tr("Please enter a Password."),tr("OK"),"","",0,0);
return;}
if(keyfile==""){
QMessageBox::warning(this,tr("Error"),tr("Please choose a key file."),tr("OK"),"","",0,0);
return;}
}
else
{
if(password=="" && keyfile==""){QMessageBox::warning(this,tr("Error")
,tr("Please enter a Password or select a key file.")
,tr("OK"),"","",0,0);
return;}
if(KeyType==BOTH || KeyType==KEYFILE){
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);
return;
}
if(!fileinfo.isReadable()){
QMessageBox::warning(this,tr("Error"),tr("The selected key file or directory is not readable\n.Please check your permissions."),tr("OK"),"","",0,0);
return;
}
if(fileinfo.isDir()){
if(keyfile.right(1)!="/")keyfile+="/";
QFile file(keyfile+"pwsafe.key");
if(!file.exists()){
QDir dir(keyfile);
QStringList files;
files=dir.entryList("*.key",QDir::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];
}else{
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";
}
}else{
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;}
}
}
done(1);
}
void CPasswordDialog::OnPasswordChanged(const QString &txt)
{
password=Edit_Password->text();
if(txt!="" && !(CheckBox_Both->isChecked())){
Combo_Dirs->setDisabled(true);
ButtonBrowse->setDisabled(true);}
else{
Combo_Dirs->setEnabled(true);
ButtonBrowse->setEnabled(true);}
void CPasswordDialog::OnOK_Set(){
}
void CPasswordDialog::OnCheckBox_BothChanged(int state)
{
if(state==QCheckBox::On){
Combo_Dirs->setEnabled(true);
ButtonBrowse->setEnabled(true);
Edit_Password->setEnabled(true);}
else{
Edit_Password->setText("");
}
}
void CPasswordDialog::ChangeEchoMode()
{
if(Edit_Password->echoMode()==QLineEdit::Normal){
Edit_Password->setEchoMode(QLineEdit::Password);
}
void CPasswordDialog::OnPasswordChanged(const QString &txt){
if(CheckBox_Both->isChecked() || txt==QString())
setStateBoth();
else
{
Edit_Password->setEchoMode(QLineEdit::Normal);
setStatePasswordOnly();
}
void CPasswordDialog::OnComboTextChanged(const QString& txt){
if(CheckBox_Both->isChecked() || txt==QString())
setStateBoth();
else
setStateKeyFileOnly();
}
void CPasswordDialog::OnCheckBox_BothChanged(int state){
if(state==Qt::Checked)
setStateBoth();
if(state==Qt::Unchecked){
if(Edit_Password->text()!=QString() && Combo_Dirs->currentText()!=QString()){
Combo_Dirs->setEditText(QString());
setStatePasswordOnly();
}
else{
if(Edit_Password->text()==QString())
setStateKeyFileOnly();
else
setStatePasswordOnly();
}
}
}
void CPasswordDialog::ChangeEchoMode(){
if(Edit_Password->echoMode()==QLineEdit::Normal)
Edit_Password->setEchoMode(QLineEdit::Password);
else
Edit_Password->setEchoMode(QLineEdit::Normal);
}
void CPasswordDialog::OnButtonExit(){
done(2);

View File

@@ -22,43 +22,36 @@
#define PASSWORDDIALOG_H
#include "lib/UrlLabel.h"
#include "ui_PasswordDlg.h"
//Added by qt3to4:
#include <Q3ValueList>
class CPasswordDialog : public QDialog, public Ui_PasswordDlg
{
Q_OBJECT
private:
int NumComboEntries;
QStringList Paths;
Q3ValueList<bool> IsFile;
LinkLabel* Label_select;
bool Mode_Set; //true = Set, false = Get
void setStatePasswordOnly();
void setStateKeyFileOnly();
void setStateBoth();
public:
QString keyfile;
QString password;
tKeyType KeyType;
public:
CPasswordDialog(QWidget* parent = 0, const char* name = 0, bool modal = false,
bool ShowExitButton = false, Qt::WFlags fl = 0 );
~CPasswordDialog();
CPasswordDialog(QWidget* parent = 0, const char* name = 0, bool modal = false,
bool ShowExitButton = false, bool KeyMode_Set=false, Qt::WFlags fl = 0 );
public slots:
virtual void OnOK();
virtual void OnCancel();
virtual void OnSelectClicked();
virtual void OnButtonBrowse();
virtual void OnButtonExit();
virtual void OnComboSelectionChanged(int);
virtual void OnPasswordChanged(const QString &txt);
virtual void OnCheckBox_BothChanged(int state);
virtual void ChangeEchoMode();
void OnOK();
void OnOK_Set();
void OnCancel();
void OnButtonBrowse();
void OnButtonBrowse_Set();
void OnButtonExit();
void OnPasswordChanged(const QString &txt);
void OnCheckBox_BothChanged(int state);
void ChangeEchoMode();
void OnComboTextChanged(const QString&);
};
#endif

View File

@@ -19,6 +19,7 @@
***************************************************************************/
#include "main.h"
#include "PwmConfig.h"
#include "PwManager.h"
#include "SearchDlg.h"
#include <qlineedit.h>

View File

@@ -18,6 +18,7 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "main.h"
#include "PwmConfig.h"
#include <qpixmap.h>
#include <qcheckbox.h>
#include <qspinbox.h>
@@ -62,6 +63,7 @@ CheckBox_ShowPasswords->setChecked(config.ShowPasswords);
Edit_BrowserCmd->setText(config.OpenUrlCommand);
CheckBox_ExpandGroupTree->setChecked(config.ExpandGroupTree);
CheckBox_AlternatingRowColors->setChecked(config.AlternatingRowColors);
Edit_MountDir->setText(config.MountDir);
}
@@ -80,6 +82,9 @@ config.ShowPasswords=CheckBox_ShowPasswords->isChecked();
config.OpenUrlCommand=Edit_BrowserCmd->text();
config.ExpandGroupTree=CheckBox_ExpandGroupTree->isChecked();
config.AlternatingRowColors=CheckBox_AlternatingRowColors->isChecked();
config.MountDir=Edit_MountDir->text();
if(config.MountDir!="" && config.MountDir.right(1)!="/")
config.MountDir+="/";
close();
}