1 /* pinentrydialog.h - A (not yet) secure Qt 4 dialog for PIN entry.
2  * Copyright (C) 2002, 2008 Klarälvdalens Datakonsult AB (KDAB)
3  * Copyright 2007 Ingo Klöcker
4  * Copyright 2016 Intevation GmbH
5  *
6  * Written by Steffen Hansen <steffen@klaralvdalens-datakonsult.se>.
7  * Modified by Andre Heinecke <aheinecke@intevation.de>
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License as
11  * published by the Free Software Foundation; either version 2 of the
12  * License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, see <https://www.gnu.org/licenses/>.
21  * SPDX-License-Identifier: GPL-2.0+
22  */
23 
24 #ifndef __PINENTRYDIALOG_H__
25 #define __PINENTRYDIALOG_H__
26 
27 #include <QDialog>
28 #include <QStyle>
29 #include <QTimer>
30 
31 #include "pinentry.h"
32 
33 class QLabel;
34 class QPushButton;
35 class QLineEdit;
36 class PinLineEdit;
37 class QString;
38 class QProgressBar;
39 class QCheckBox;
40 class QAction;
41 
42 QPixmap icon(QStyle::StandardPixmap which = QStyle::SP_CustomBase);
43 
44 void raiseWindow(QWidget *w);
45 
46 class PinEntryDialog : public QDialog
47 {
48     Q_OBJECT
49 
50     Q_PROPERTY(QString description READ description WRITE setDescription)
51     Q_PROPERTY(QString error READ error WRITE setError)
52     Q_PROPERTY(QString pin READ pin WRITE setPin)
53     Q_PROPERTY(QString prompt READ prompt WRITE setPrompt)
54 public:
55     explicit PinEntryDialog(QWidget *parent = 0, const char *name = 0,
56                             int timeout = 0, bool modal = false,
57                             bool enable_quality_bar = false,
58                             const QString &repeatString = QString(),
59                             const QString &visibiltyTT = QString(),
60                             const QString &hideTT = QString());
61 
62     void setDescription(const QString &);
63     QString description() const;
64 
65     void setError(const QString &);
66     QString error() const;
67 
68     void setPin(const QString &);
69     QString pin() const;
70 
71     QString repeatedPin() const;
72     void setRepeatErrorText(const QString &);
73 
74     void setPrompt(const QString &);
75     QString prompt() const;
76 
77     void setOkText(const QString &);
78     void setCancelText(const QString &);
79 
80     void setQualityBar(const QString &);
81     void setQualityBarTT(const QString &);
82 
83     void setGenpinLabel(const QString &);
84     void setGenpinTT(const QString &);
85 
86     void setPinentryInfo(pinentry_t);
87 
88     bool timedOut() const;
89 
90 protected slots:
91     void updateQuality(const QString &);
92     void slotTimeout();
93     void textChanged(const QString &);
94     void focusChanged(QWidget *old, QWidget *now);
95     void toggleVisibility();
96     void onBackspace();
97     void generatePin();
98 
99 protected:
100     /* reimp */ void showEvent(QShowEvent *event);
101 
102 private:
103     QLabel    *_icon;
104     QLabel    *_desc;
105     QLabel    *_error;
106     QLabel    *_prompt;
107     QLabel    *_quality_bar_label;
108     QProgressBar *_quality_bar;
109     PinLineEdit *_edit;
110     QLineEdit   *mRepeat;
111     QPushButton *_ok;
112     QPushButton *_cancel;
113     bool       _grabbed;
114     bool       _have_quality_bar;
115     bool       _timed_out;
116     bool       _disable_echo_allowed;
117     pinentry_t _pinentry_info;
118     QTimer    *_timer;
119     QString    mRepeatError,
120                mVisibilityTT,
121                mGenerateTT,
122                mHideTT;
123     QAction   *mVisiActionEdit,
124               *mGenerateActionEdit;
125     QCheckBox *mVisiCB;
126 };
127 
128 #endif // __PINENTRYDIALOG_H__
129