Initial commit
[keepassx] / src / dialogs / PasswordDlg.h
1 /***************************************************************************
2  *   Copyright (C) 2005-2007 by Tarek Saidi                                *
3  *   tarek.saidi@arcor.de                                                  *
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  *   This program is distributed in the hope that it will be useful,       *
10  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
11  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
12  *   GNU General Public License for more details.                          *
13  *                                                                         *
14  *   You should have received a copy of the GNU General Public License     *
15  *   along with this program; if not, write to the                         *
16  *   Free Software Foundation, Inc.,                                       *
17  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
18  ***************************************************************************/
19
20 #ifndef PASSWORDDIALOG_H
21 #define PASSWORDDIALOG_H
22
23 #include <QPaintEvent>
24 #include "ui_PasswordDlg.h"
25
26
27 class PasswordDialog : public QDialog, private Ui_PasswordDlg {
28         Q_OBJECT
29         public:
30                 enum DlgMode {
31                         Mode_Ask,     // Normal password entry when opening a database
32                         Mode_Set,     // Setting password for the first time after creating a new database
33                         Mode_Change   // Changing the password of a database
34                 };
35                 
36                 enum DlgFlags {
37                         Flag_None = 0x00, 
38                         Flag_Auto = 0x01  // Dialog was automatically opened on start-up        
39                 };
40                 
41                 enum DlgExit {
42                         Exit_Ok=QDialog::Accepted,
43                         Exit_Cancel=QDialog::Rejected,
44                         Exit_Quit=3
45                 };
46                 
47                 typedef bool (KeyFileGenProc)(const QString& filename,QString* error);
48                         
49                 PasswordDialog(QWidget* parent,DlgMode mode,DlgFlags flags,const QString& filename=QString());
50                 
51                 // result functions
52                 QString selectedBookmark();
53                 QString keyFile();
54                 QString password();
55         
56         private slots:
57                 void OnOK();
58                 void OnCancel();
59                 void OnButtonBrowse();
60                 void OnButtonQuit();
61                 void OnGenKeyFile();
62                 void OnButtonBack();
63                 void ChangeEchoModeDatabaseKey();
64                 void OnBookmarkTriggered(QAction* action);
65                 void OnCheckBoxesChanged();
66                 void done(int r);
67
68         private:
69                 DlgMode Mode;
70                 QPixmap BannerPixmap;
71                 QString BookmarkFilename;
72                 QString Filename;
73                 QString Password;
74                 QString KeyFile;
75                 void setStatePasswordOnly();
76                 void setStateKeyFileOnly();
77                 void setStateBoth();
78                 virtual void paintEvent(QPaintEvent*);
79 };
80
81 #endif
82