gwenhywfar 5.14.1
dlg_input.c
Go to the documentation of this file.
1/***************************************************************************
2 begin : Wed Feb 17 2010
3 copyright : (C) 2010 by Martin Preuss
4 email : martin@libchipcard.de
5
6 ***************************************************************************
7 * Please see toplevel file COPYING for license details *
8 ***************************************************************************/
9
10
11#ifdef HAVE_CONFIG_H
12# include <config.h>
13#endif
14
15#define DISABLE_DEBUGLOG
16
17
18#include "dlg_input_p.h"
19
20#include <gwenhywfar/gwenhywfar.h>
21#include <gwenhywfar/pathmanager.h>
22#include <gwenhywfar/gui.h>
23#include <gwenhywfar/debug.h>
24
25
26
27
28GWEN_INHERIT(GWEN_DIALOG, GWEN_DLGINPUT)
29
30
31
32
33
35 const char *title,
36 const char *text,
37 int minLen,
38 int maxLen)
39{
40 GWEN_DIALOG *dlg;
41 GWEN_DLGINPUT *xdlg;
42 GWEN_BUFFER *fbuf;
43 GWEN_GUI *gui;
44 uint32_t gflags=0;
45 int n;
46 int rv;
47 char dlgNameBuf[128];
48
49 /* get GUI flags */
50 gui=GWEN_Gui_GetGui();
51 if (gui)
52 gflags=GWEN_Gui_GetFlags(gui);
53
54 /* setup dialog name */
55 n=0;
57 n|=1;
58 if (
60 !(flags & GWEN_GUI_INPUT_FLAGS_DIRECT) &&
61 !(flags & GWEN_GUI_INPUT_FLAGS_TAN) &&
63 )
64 n|=2;
65
66 snprintf(dlgNameBuf, sizeof(dlgNameBuf)-1, "dlg_gwen_input%d", n);
67 dlgNameBuf[sizeof(dlgNameBuf)-1]=0;
68
69 dlg=GWEN_Dialog_new(dlgNameBuf);
70 GWEN_NEW_OBJECT(GWEN_DLGINPUT, xdlg);
71
72 GWEN_INHERIT_SETDATA(GWEN_DIALOG, GWEN_DLGINPUT, dlg, xdlg,
74
76
77 /* get path of dialog description file */
78 fbuf=GWEN_Buffer_new(0, 256, 0, 1);
80 "gwenhywfar/dialogs/dlg_input.dlg",
81 fbuf);
82 if (rv<0) {
83 DBG_INFO(GWEN_LOGDOMAIN, "Dialog description file not found (%d).", rv);
84 GWEN_Buffer_free(fbuf);
86 return NULL;
87 }
88
89 /* read dialog from dialog description file */
91 if (rv<0) {
92 DBG_INFO(GWEN_LOGDOMAIN, "here (%d).", rv);
93 GWEN_Buffer_free(fbuf);
95 return NULL;
96 }
97 GWEN_Buffer_free(fbuf);
98
99 xdlg->flags=flags;
100 if (title)
101 xdlg->title=strdup(title);
102 if (text)
103 xdlg->text=strdup(text);
104 xdlg->minLen=minLen;
105 xdlg->maxLen=maxLen;
106
107 if (!(flags & GWEN_GUI_INPUT_FLAGS_SHOW)) {
110 }
111
112 if (maxLen>32) {
113 GWEN_Dialog_SetWidgetColumns(dlg, "input1", 64);
114 GWEN_Dialog_SetWidgetColumns(dlg, "input2", 64);
115 }
116 else {
117 GWEN_Dialog_SetWidgetColumns(dlg, "input1", 32);
118 GWEN_Dialog_SetWidgetColumns(dlg, "input2", 32);
119 }
120
121 if (!(flags & GWEN_GUI_INPUT_FLAGS_CONFIRM)) {
122 GWEN_Dialog_RemoveWidget(dlg, "input2");
123 GWEN_Dialog_RemoveWidget(dlg, "label2");
124 }
125
126 if (!(n & 2)) {
127 GWEN_Dialog_RemoveWidget(dlg, "storePasswordCheck");
128 xdlg->storePasswordCheckEnabled = 1;
129 }
130
131 return dlg;
132}
133
134
135
137{
138 GWEN_DLGINPUT *xdlg;
139
140 xdlg=(GWEN_DLGINPUT *) p;
141
142 if (xdlg->response) {
143 memset(xdlg->response, 0, strlen(xdlg->response));
144 free(xdlg->response);
145 xdlg->response=NULL;
146 }
147 free(xdlg->title);
148 free(xdlg->text);
149
150 GWEN_FREE_OBJECT(xdlg);
151}
152
153
154
156{
157 GWEN_DLGINPUT *xdlg;
158 const char *s1;
159
160 assert(dlg);
161 xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, GWEN_DLGINPUT, dlg);
162 assert(xdlg);
163
165 if (xdlg->flags & GWEN_GUI_INPUT_FLAGS_CONFIRM) {
166 const char *s2;
167
169
170 /* check for equality */
171 if (!s1 || !s2 || strcasecmp(s1, s2)!=0)
172 return -1;
173 }
174
175 if (!s1)
176 return -1;
177
178 if (xdlg->minLen>=0) {
179 if (strlen(s1)<xdlg->minLen)
180 return -1;
181 }
182
183 return 0;
184}
185
186
187
189{
190 GWEN_DLGINPUT *xdlg;
191 GWEN_DB_NODE *dbParams;
192
193 assert(dlg);
194 xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, GWEN_DLGINPUT, dlg);
195 assert(xdlg);
196
197 dbParams=GWEN_Dialog_GetPreferences(dlg);
198 assert(dbParams);
199
200#if 0
201 /* read width */
202 i=GWEN_DB_GetIntValue(dbParams, "dialog_width", 0, -1);
203 if (i>=DIALOG_MINWIDTH)
205
206 /* read height */
207 i=GWEN_DB_GetIntValue(dbParams, "dialog_height", 0, -1);
208 if (i>=DIALOG_MINHEIGHT)
210#endif
211
212 /* special stuff */
213 if (xdlg->title)
214 GWEN_Dialog_SetCharProperty(dlg, "", GWEN_DialogProperty_Title, 0, xdlg->title, 0);
215
216 if (xdlg->text)
217 GWEN_Dialog_SetCharProperty(dlg, "descrLabel", GWEN_DialogProperty_Title, 0, xdlg->text, 0);
218
219
221 GWEN_Dialog_SetIntProperty(dlg, "abortButton", GWEN_DialogProperty_Enabled, 0, 1, 0);
222
224
225 xdlg->storePasswordCheckEnabled = 0;
226 xdlg->wasInit=1;
227}
228
229
230
232{
233 GWEN_DLGINPUT *xdlg;
234 GWEN_DB_NODE *dbParams;
235
236 assert(dlg);
237 xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, GWEN_DLGINPUT, dlg);
238 assert(xdlg);
239
240 dbParams=GWEN_Dialog_GetPreferences(dlg);
241 assert(dbParams);
242
243 if (xdlg->response) {
244 memset(xdlg->response, 0, strlen(xdlg->response));
245 free(xdlg->response);
246 xdlg->response=NULL;
247 }
248
249 if (GWEN_DlgInput_CheckInput(dlg)==0) {
250 const char *s;
251
253 if (s)
254 xdlg->response=strdup(s);
255 if (xdlg->storePasswordCheckEnabled)
256 xdlg->flagAllowStore=GWEN_Dialog_GetIntProperty(dlg, "storePasswordCheck", GWEN_DialogProperty_Value, 0, 0);
257 else
258 xdlg->flagAllowStore=0;
259 }
260
261#if 0
262 /* store dialog width */
264 if (i<DIALOG_MINWIDTH)
266 GWEN_DB_SetIntValue(dbParams,
268 "dialog_width",
269 i);
270
271 /* store dialog height */
273 if (i<DIALOG_MINHEIGHT)
275 GWEN_DB_SetIntValue(dbParams,
277 "dialog_height",
278 i);
279#endif
280}
281
282
283
284
285int GWEN_DlgInput_HandleActivated(GWEN_DIALOG *dlg, const char *sender)
286{
287 GWEN_DLGINPUT *xdlg;
288
289 assert(dlg);
290 xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, GWEN_DLGINPUT, dlg);
291 assert(xdlg);
292
293 if (strcasecmp(sender, "okButton")==0) {
295 }
296 else if (strcasecmp(sender, "abortButton")==0) {
298 }
299 else if (strcasecmp(sender, "input1")==0 ||
300 strcasecmp(sender, "input2")==0) {
301 if (GWEN_DlgInput_CheckInput(dlg)==0)
304 }
305
307}
308
309
310
312{
313 GWEN_DLGINPUT *xdlg;
314
315 assert(dlg);
316 xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, GWEN_DLGINPUT, dlg);
317 assert(xdlg);
318
319 if (strcasecmp(sender, "input1")==0 ||
320 strcasecmp(sender, "input2")==0) {
322 /* disable okButton */
324 else
325 /* enable okButton */
328 }
329
331}
332
333
334
337 const char *sender)
338{
339 GWEN_DLGINPUT *xdlg;
340
341 assert(dlg);
342 xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, GWEN_DLGINPUT, dlg);
343 assert(xdlg);
344
345 switch (t) {
349
353
355 return GWEN_DlgInput_HandleValueChanged(dlg, sender);
356 break;
357
359 return GWEN_DlgInput_HandleActivated(dlg, sender);
360
363
366
371 }
372
374
375}
376
377
378
379int GWEN_DlgInput_CopyInput(GWEN_DIALOG *dlg, char *buffer, int size)
380{
381 GWEN_DLGINPUT *xdlg;
382
383 assert(dlg);
384 xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, GWEN_DLGINPUT, dlg);
385 assert(xdlg);
386
387 if (xdlg->response) {
388 int l;
389
390 l=strlen(xdlg->response);
391 if ((l+1)>size) {
392 DBG_ERROR(GWEN_LOGDOMAIN, "Buffer too small");
394 }
395 /* buffer ok, copy */
396 memmove(buffer, xdlg->response, l+1);
397 return 0;
398 }
399 return GWEN_ERROR_NO_DATA;
400}
401
402
403
405{
406 GWEN_DLGINPUT *xdlg;
407
408 assert(dlg);
409 xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, GWEN_DLGINPUT, dlg);
410 assert(xdlg);
411
412 return xdlg->flagAllowStore;
413}
414
415
416
417
#define NULL
Definition binreloc.c:300
GWEN_BUFFER * GWEN_Buffer_new(char *buffer, uint32_t size, uint32_t used, int take)
Definition buffer.c:42
void GWEN_Buffer_free(GWEN_BUFFER *bf)
Definition buffer.c:89
char * GWEN_Buffer_GetStart(const GWEN_BUFFER *bf)
Definition buffer.c:235
int GWEN_DB_SetIntValue(GWEN_DB_NODE *n, uint32_t flags, const char *path, int val)
Definition db.c:1202
int GWEN_DB_GetIntValue(GWEN_DB_NODE *n, const char *path, int idx, int defVal)
Definition db.c:1163
#define GWEN_DB_FLAGS_OVERWRITE_VARS
Definition db.h:121
struct GWEN_DB_NODE GWEN_DB_NODE
Definition db.h:228
#define DBG_INFO(dbg_logger, format,...)
Definition debug.h:181
#define DBG_ERROR(dbg_logger, format,...)
Definition debug.h:97
int GWEN_Dialog_SetIntProperty(GWEN_DIALOG *dlg, const char *name, GWEN_DIALOG_PROPERTY prop, int index, int value, int doSignal)
Definition dialog.c:703
GWEN_DIALOG_SIGNALHANDLER GWEN_Dialog_SetSignalHandler(GWEN_DIALOG *dlg, GWEN_DIALOG_SIGNALHANDLER fn)
Definition dialog.c:305
void GWEN_Dialog_SetWidgetColumns(GWEN_DIALOG *dlg, const char *name, int i)
Definition dialog.c:900
int GWEN_Dialog_RemoveWidget(GWEN_DIALOG *dlg, const char *name)
Definition dialog.c:821
int GWEN_Dialog_SetCharProperty(GWEN_DIALOG *dlg, const char *name, GWEN_DIALOG_PROPERTY prop, int index, const char *value, int doSignal)
Definition dialog.c:762
void GWEN_Dialog_AddWidgetFlags(GWEN_DIALOG *dlg, const char *name, uint32_t fl)
Definition dialog.c:862
GWEN_DB_NODE * GWEN_Dialog_GetPreferences(const GWEN_DIALOG *dlg)
Definition dialog.c:1002
void GWEN_Dialog_free(GWEN_DIALOG *dlg)
Definition dialog.c:137
GWEN_DIALOG * GWEN_Dialog_new(const char *dialogId)
Definition dialog.c:54
int GWEN_Dialog_GetIntProperty(GWEN_DIALOG *dlg, const char *name, GWEN_DIALOG_PROPERTY prop, int index, int defaultProperty)
Definition dialog.c:733
int GWEN_Dialog_ReadXmlFile(GWEN_DIALOG *dlg, const char *fname)
Definition dialog.c:531
const char * GWEN_Dialog_GetCharProperty(GWEN_DIALOG *dlg, const char *name, GWEN_DIALOG_PROPERTY prop, int index, const char *defaultProperty)
Definition dialog.c:792
#define GWEN_WIDGET_FLAGS_PASSWORD
Definition dialog.h:64
struct GWEN_DIALOG GWEN_DIALOG
Definition dialog.h:54
@ GWEN_DialogProperty_Title
Definition dialog.h:263
@ GWEN_DialogProperty_Height
Definition dialog.h:273
@ GWEN_DialogProperty_Enabled
Definition dialog.h:267
@ GWEN_DialogProperty_Value
Definition dialog.h:264
@ GWEN_DialogProperty_Focus
Definition dialog.h:276
@ GWEN_DialogProperty_Width
Definition dialog.h:272
GWEN_DIALOG_EVENTTYPE
Definition dialog.h:98
@ GWEN_DialogEvent_TypeKeyPressed
Definition dialog.h:106
@ GWEN_DialogEvent_TypeValueChanged
Definition dialog.h:101
@ GWEN_DialogEvent_TypeInit
Definition dialog.h:99
@ GWEN_DialogEvent_TypeFini
Definition dialog.h:100
@ GWEN_DialogEvent_TypeClose
Definition dialog.h:105
@ GWEN_DialogEvent_TypeKeyReleased
Definition dialog.h:107
@ GWEN_DialogEvent_TypeActivated
Definition dialog.h:102
@ GWEN_DialogEvent_TypeEnabled
Definition dialog.h:103
@ GWEN_DialogEvent_TypeDisabled
Definition dialog.h:104
@ GWEN_DialogEvent_TypeLast
Definition dialog.h:109
@ GWEN_DialogEvent_ResultHandled
Definition dialog.h:120
@ GWEN_DialogEvent_ResultAccept
Definition dialog.h:122
@ GWEN_DialogEvent_ResultNotHandled
Definition dialog.h:121
@ GWEN_DialogEvent_ResultReject
Definition dialog.h:123
GWEN_DIALOG * GWEN_DlgInput_new(uint32_t flags, const char *title, const char *text, int minLen, int maxLen)
Definition dlg_input.c:34
int GWENHYWFAR_CB GWEN_DlgInput_SignalHandler(GWEN_DIALOG *dlg, GWEN_DIALOG_EVENTTYPE t, const char *sender)
Definition dlg_input.c:335
int GWEN_DlgInput_HandleValueChanged(GWEN_DIALOG *dlg, const char *sender)
Definition dlg_input.c:311
void GWEN_DlgInput_Fini(GWEN_DIALOG *dlg)
Definition dlg_input.c:231
int GWEN_DlgInput_CheckInput(GWEN_DIALOG *dlg)
Definition dlg_input.c:155
int GWEN_DlgInput_CopyInput(GWEN_DIALOG *dlg, char *buffer, int size)
Definition dlg_input.c:379
int GWEN_DlgInput_HandleActivated(GWEN_DIALOG *dlg, const char *sender)
Definition dlg_input.c:285
void GWEN_DlgInput_Init(GWEN_DIALOG *dlg)
Definition dlg_input.c:188
void GWENHYWFAR_CB GWEN_DlgInput_FreeData(GWEN_UNUSED void *bp, void *p)
Definition dlg_input.c:136
int GWEN_DlgInput_GetFlagAllowStore(GWEN_DIALOG *dlg)
Definition dlg_input.c:404
#define DIALOG_MINWIDTH
#define DIALOG_MINHEIGHT
#define GWEN_ERROR_BUFFER_OVERFLOW
Definition error.h:79
#define GWEN_ERROR_NO_DATA
Definition error.h:94
struct GWEN_BUFFER GWEN_BUFFER
A dynamically resizeable text buffer.
Definition buffer.h:38
GWEN_GUI * GWEN_Gui_GetGui(void)
Definition gui.c:160
uint32_t GWEN_Gui_GetFlags(const GWEN_GUI *gui)
Definition gui.c:195
#define GWEN_GUI_INPUT_FLAGS_SHOW
Definition gui.h:213
#define GWEN_GUI_INPUT_FLAGS_DIRECT
Definition gui.h:226
#define GWEN_GUI_FLAGS_PERMPASSWORDS
Definition gui.h:998
#define GWEN_GUI_INPUT_FLAGS_TAN
Definition gui.h:222
#define GWEN_GUI_INPUT_FLAGS_CONFIRM
Definition gui.h:211
struct GWEN_GUI GWEN_GUI
Definition gui.h:176
#define GWEN_PM_LIBNAME
Definition gwenhywfar.h:42
#define GWEN_PM_SYSDATADIR
Definition gwenhywfar.h:66
#define GWEN_UNUSED
#define GWENHYWFAR_CB
#define GWEN_INHERIT_SETDATA(bt, t, element, data, fn)
Definition inherit.h:300
#define GWEN_INHERIT(bt, t)
Definition inherit.h:264
#define GWEN_INHERIT_GETDATA(bt, t, element)
Definition inherit.h:279
#define GWEN_LOGDOMAIN
Definition logger.h:32
#define GWEN_FREE_OBJECT(varname)
Definition memory.h:61
#define GWEN_NEW_OBJECT(typ, varname)
Definition memory.h:55
int GWEN_PathManager_FindFile(const char *destLib, const char *pathName, const char *fileName, GWEN_BUFFER *fbuf)