Kennwortmanager KeePassX Weiterentwicklung der Version 1
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
keepassx1/src/dialogs/PasswordDlg.cpp

207 lines
6.2 KiB

/***************************************************************************
* Copyright (C) 2005 by Tarek Saidi *
* tarek@linux *
* *
* 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. *
***************************************************************************/
#include "mainwindow.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>
CPasswordDialog::CPasswordDialog(QWidget* parent, const char* name, bool modal, Qt::WFlags fl)
: PasswordDlg(parent,name, modal,fl)
{
parentwnd=((CMainWindow*)parentWidget());
parentwnd->CreateBanner(Banner,parentwnd->Icon_Key32x32,trUtf8("Datenbank öffnen"));
Label_select=new LinkLabel((QWidget*)groupframe,"Select",trUtf8("Datei manuell wählen..."),410,100);
connect(Label_select,SIGNAL(clicked()),this,SLOT(OnSelectClicked()));
///@PlatformSpecific
QDir media("/media");
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(trUtf8("< keiner >"));
}
for(int i=0;i<Paths.count();i++){
Combo_Dirs->insertItem(0,Paths[i]);
IsFile.append(false);
}
if(!parentwnd->config->ShowPasswords)ChangeEchoMode();
}
CPasswordDialog::~CPasswordDialog()
{
delete Label_select;
}
void CPasswordDialog::OnComboSelectionChanged(int i)
{
if(i==0){
keyfile="";
Edit_Password->setEnabled(true);
return;
}
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;
}
QMessageBox::warning(this,"Datei nicht gefunden",QString::fromUtf8("Im gewählten Verzeichnis konnte keine Schlüsseldatei gefunden werden.\nStellen Sie sicher, dass der Schlüssel-Datenträger ordnungsgemäß eingehängt (mounted) ist.\nSollte die Schlüsseldatei nicht den Dateinamen 'pwsafe.key' haben, nutzen Sie bitte die manuelle Dateiauswahl."),"OK","","",0,0);
Edit_Password->setEnabled(true);
Combo_Dirs->setCurrentItem(0);
return;
}
void CPasswordDialog::OnButtonBrowse()
{
///@PlatformSpecific
QString dir=Q3FileDialog::getExistingDirectory(QDir::homeDirPath(),NULL,QString::fromUtf8("Verzeichnis wählen"));
if(dir=="")return;
QFile file(dir+"/pwsafe.key");
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="";
}
Paths.append(dir);
IsFile.append(false);
return;}
QMessageBox::warning(this,"Datei nicht gefunden",QString::fromUtf8("Im gewählten Verzeichnis konnte keine Schlüsseldatei gefunden werden.\nStellen Sie sicher, dass der Schlüssel-Datenträger ordnungsgemäß eingehängt (mounted) ist.\nSollte die Schlüsseldatei nicht den Dateinamen 'pwsafe.key' haben, nutzen Sie bitte die manuelle Dateiauswahl."),"OK","","",0,0);
}
void CPasswordDialog::OnSelectClicked()
{
if(Button_Browse->isEnabled()){
keyfile=Q3FileDialog::getOpenFileName(QDir::homeDirPath(),"",this,QString::fromUtf8("Schlüsseldatei öffnen"));
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);
}
}
void CPasswordDialog::OnCancel()
{
canceled=true;
close();
}
void CPasswordDialog::OnOK()
{
canceled=false;
if(CheckBox_Both->isChecked()){
if(password==""){QMessageBox::warning(this,trUtf8("Fehler"),trUtf8("Bitte geben Sie ein Passwort ein.")
,trUtf8("OK"),"","",0,0);
return;}
if(keyfile==""){QMessageBox::warning(this,trUtf8("Fehler"),trUtf8("Bitte wählen Sie eine Schlüsseldatei.")
,trUtf8("OK"),"","",0,0);
return;}
}
else
{
if(password=="" && keyfile==""){QMessageBox::warning(this,trUtf8("Fehler"),trUtf8("Geben Sie bitte ein Passwort ein oder wählen Sie eine Schlüsseldatei.")
,trUtf8("OK"),"","",0,0);
return;}
}
close();
}
void CPasswordDialog::OnPasswordChanged(const QString &txt)
{
password=Edit_Password->text();
if(txt!="" && !(CheckBox_Both->isChecked())){
Combo_Dirs->setDisabled(true);
Button_Browse->setDisabled(true);}
else{
Combo_Dirs->setEnabled(true);
Button_Browse->setEnabled(true);}
}
void CPasswordDialog::OnCheckBox_BothChanged(int state)
{
if(state==QCheckBox::On){
Combo_Dirs->setEnabled(true);
Button_Browse->setEnabled(true);
Edit_Password->setEnabled(true);}
else{
Edit_Password->setText("");
}
}
void CPasswordDialog::ChangeEchoMode()
{
if(Edit_Password->echoMode()==QLineEdit::Normal){
Edit_Password->setEchoMode(QLineEdit::Password);
}
else
{
Edit_Password->setEchoMode(QLineEdit::Normal);
}
}
/*$SPECIALIZATION$*/
//#include "passworddialog.moc"