File: pinwindow.h

package info (click to toggle)
pinentry 1.1.0-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 3,052 kB
  • sloc: ansic: 7,309; sh: 6,517; cpp: 4,169; makefile: 273; python: 40
file content (109 lines) | stat: -rw-r--r-- 2,917 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*
    pinwindow.h - PinWindow is a simple fltk dialog for entring password
    with timeout. if needed description (long text), error message, qualitybar
    and etc should used PassWindow.

    Copyright (C) 2016 Anatoly madRat L. Berenblit

    Written by Anatoly madRat L. Berenblit <madrat-@users.noreply.github.com>.

    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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
    SPDX-License-Identifier: GPL-2.0+
*/

#ifndef __PINWINDOW_H__
#define __PINWINDOW_H__

#include "config.h"

class Fl_Window;
class Fl_Box;
class Fl_Input;
class Fl_Button;
class Fl_Widget;

#include <assert.h>
#include <string>

class PinWindow
{
protected:
	static const char *TITLE;
	static const char *BUTTON_OK;
	static const char *BUTTON_CANCEL;
	static const char *PROMPT;

protected:
	PinWindow(const PinWindow&);
	PinWindow& operator=(const PinWindow&);

	Fl_Window	*window_;
	Fl_Box		*icon_;

	Fl_Box		*message_;
	Fl_Input	*input_;

	Fl_Button	*ok_, *cancel_;

	std::string cancel_name_;
	char *passwd_;			// SECURE_MEMORY
	unsigned int timeout_; 	// click cancel if timeout

public:
	virtual ~PinWindow();

	static PinWindow* create();

	inline const char*   passwd() const { return passwd_; }

	virtual void timeout(unsigned int time);						// 0 - infinity, seconds
	virtual void title(const char *title);
	virtual void ok(const char* ok);
	virtual void cancel(const char* cancel);
	virtual void prompt(const char *message);

	virtual void showModal();
	virtual void showModal(const int argc, char* argv[]);

protected:
	PinWindow();

	void wipe();		// clear UI memory
	void release();		// clear secure memory
	void update_cancel_label();

	virtual int init(const int cx, const int cy);

	//callbacks
	static void cancel_cb(Fl_Widget *button, void *val);
	static void ok_cb(Fl_Widget *button, void *val);
	static void timeout_cb(void*);

	// ISSUE: Fl_Window component in tinycore works only as Fl_Window::label(...); not Fl_Widget
	template <class TWidget> void set_label(TWidget* widget, const char *label, const char *def)
	{
		assert(NULL != widget); // widget must be created

		if (NULL != widget)
		{
			if (NULL != label && 0 != *label)
				widget->copy_label(label);
			else
				widget->label(def);
		}
	};
};

#endif //#ifndef __PINWINDOW_H__