Initial commit
[keepassx] / src / dialogs / DatabaseSettingsDlg.cpp
1 /***************************************************************************
2  *   Copyright (C) 2005 by Tarek Saidi                                     *
3  *   tarek@linux                                                           *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; version 2 of the License.               *
8
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19  ***************************************************************************/
20  
21
22 #include "DatabaseSettingsDlg.h"
23 #include "Kdb3Database.h"
24
25
26 CDbSettingsDlg::CDbSettingsDlg(QWidget* parent,IDatabase* db, Qt::WFlags fl)
27 : QDialog(parent,fl)
28 {
29         setupUi(this);
30         database=dynamic_cast<IKdbSettings*>(db);
31         adjustSize();
32         setMaximumSize(size());
33         setMinimumSize(size());
34         createBanner(&BannerPixmap,getPixmap("appsettings"),tr("Settings"),width());
35         ComboAlgo->insertItem(0,tr("AES(Rijndael):  256 Bit   (default)"));
36         ComboAlgo->insertItem(1,tr("Twofish:  256 Bit"));
37         ComboAlgo->setCurrentIndex(database->cryptAlgorithm()); //Achtung: AlgoID muss gleich dem ComboBox Index sein!
38         EditRounds->setText(QString::number( database->keyTransfRounds() ));
39         ButtonBench->setIcon(getIcon("alarmclock"));
40         connect( ButtonBox, SIGNAL( accepted() ), this, SLOT( OnOK() ) );
41         connect( ButtonBox, SIGNAL( rejected() ), this, SLOT( OnCancel() ) );
42         connect( ButtonBench, SIGNAL( clicked() ), this, SLOT( OnBenchmark() ) );
43 }
44
45 CDbSettingsDlg::~CDbSettingsDlg(){
46 }
47
48 void CDbSettingsDlg::paintEvent(QPaintEvent *event){
49         QDialog::paintEvent(event);
50         QPainter painter(this);
51         painter.setClipRegion(event->region());
52         painter.drawPixmap(QPoint(0,0),BannerPixmap);
53 }
54
55 void CDbSettingsDlg::OnCancel()
56 {
57         done(0);
58 }
59
60
61 void CDbSettingsDlg::OnOK()
62 {
63         if(EditRounds->text()==""){
64                 QMessageBox::warning(NULL,tr("Warning"),tr("Please determine the number of encryption rounds."),tr("OK"));
65                 return;
66         }
67         bool valid;
68         int rounds=EditRounds->text().toUInt(&valid,10);
69         if(valid==false){
70                 QMessageBox::warning(NULL,tr("Error"),tr("'%1' is not valid integer value.").arg(EditRounds->text()),tr("OK"));
71                 return;
72         }
73         if(rounds==0){
74                 QMessageBox::warning(NULL,tr("Error"),tr("The number of encryption rounds have to be greater than 0."),tr("OK"));
75                 return;
76         }
77         database->setKeyTransfRounds(rounds);
78         database->setCryptAlgorithm((CryptAlgorithm)ComboAlgo->currentIndex());
79         done(1);
80 }
81
82 void CDbSettingsDlg::OnBenchmark(){
83         EditRounds->setText(QString::number( KeyTransformBenchmark::benchmark(1000) ));
84 }