gwenhywfar  5.10.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 
28 GWEN_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;
56  if (flags & GWEN_GUI_INPUT_FLAGS_CONFIRM)
57  n|=1;
58  if (
59  (gflags & GWEN_GUI_FLAGS_PERMPASSWORDS) &&
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);
85  GWEN_Dialog_free(dlg);
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);
94  GWEN_Dialog_free(dlg);
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 
220  GWEN_Dialog_SetIntProperty(dlg, "okButton", GWEN_DialogProperty_Enabled, 0, 0, 0);
221  GWEN_Dialog_SetIntProperty(dlg, "abortButton", GWEN_DialogProperty_Enabled, 0, 1, 0);
222 
223  GWEN_Dialog_SetIntProperty(dlg, "input1", GWEN_DialogProperty_Focus, 0, 1, 0);
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)
265  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 
285 int 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 
311 int GWEN_DlgInput_HandleValueChanged(GWEN_DIALOG *dlg, const char *sender)
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) {
321  if (GWEN_DlgInput_CheckInput(dlg))
322  /* disable okButton */
323  GWEN_Dialog_SetIntProperty(dlg, "okButton", GWEN_DialogProperty_Enabled, 0, 0, 0);
324  else
325  /* enable okButton */
326  GWEN_Dialog_SetIntProperty(dlg, "okButton", GWEN_DialogProperty_Enabled, 0, 1, 0);
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) {
347  GWEN_DlgInput_Init(dlg);
349 
351  GWEN_DlgInput_Fini(dlg);
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 
379 int 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 
void GWEN_Dialog_SetWidgetColumns(GWEN_DIALOG *dlg, const char *name, int i)
Definition: dialog.c:900
char * GWEN_Buffer_GetStart(const GWEN_BUFFER *bf)
Definition: buffer.c:235
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
#define GWEN_DB_FLAGS_OVERWRITE_VARS
Definition: db.h:121
void GWENHYWFAR_CB GWEN_DlgInput_FreeData(GWEN_UNUSED void *bp, void *p)
Definition: dlg_input.c:136
struct GWEN_DB_NODE GWEN_DB_NODE
Definition: db.h:228
#define GWEN_PM_SYSDATADIR
Definition: gwenhywfar.h:66
int GWEN_DlgInput_CopyInput(GWEN_DIALOG *dlg, char *buffer, int size)
Definition: dlg_input.c:379
void GWEN_DlgInput_Init(GWEN_DIALOG *dlg)
Definition: dlg_input.c:188
#define GWEN_GUI_INPUT_FLAGS_CONFIRM
Definition: gui.h:211
#define GWEN_FREE_OBJECT(varname)
Definition: memory.h:61
#define NULL
Definition: binreloc.c:300
int GWEN_Dialog_RemoveWidget(GWEN_DIALOG *dlg, const char *name)
Definition: dialog.c:821
#define GWEN_GUI_FLAGS_PERMPASSWORDS
Definition: gui.h:998
void GWEN_Dialog_AddWidgetFlags(GWEN_DIALOG *dlg, const char *name, uint32_t fl)
Definition: dialog.c:862
GWEN_DIALOG_EVENTTYPE
Definition: dialog.h:98
GWEN_DIALOG_SIGNALHANDLER GWEN_Dialog_SetSignalHandler(GWEN_DIALOG *dlg, GWEN_DIALOG_SIGNALHANDLER fn)
Definition: dialog.c:305
#define GWEN_LOGDOMAIN
Definition: logger.h:35
GWEN_DB_NODE * GWEN_Dialog_GetPreferences(const GWEN_DIALOG *dlg)
Definition: dialog.c:1002
int GWEN_DlgInput_HandleValueChanged(GWEN_DIALOG *dlg, const char *sender)
Definition: dlg_input.c:311
#define GWEN_GUI_INPUT_FLAGS_DIRECT
Definition: gui.h:226
GWEN_BUFFER * GWEN_Buffer_new(char *buffer, uint32_t size, uint32_t used, int take)
Definition: buffer.c:42
struct GWEN_DIALOG GWEN_DIALOG
Definition: dialog.h:54
#define GWEN_ERROR_BUFFER_OVERFLOW
Definition: error.h:79
#define GWEN_NEW_OBJECT(typ, varname)
Definition: memory.h:55
#define DIALOG_MINWIDTH
Definition: dlg_progress.c:27
int GWEN_Dialog_GetIntProperty(GWEN_DIALOG *dlg, const char *name, GWEN_DIALOG_PROPERTY prop, int index, int defaultProperty)
Definition: dialog.c:733
#define GWENHYWFAR_CB
Definition: gwenhywfarapi.h:89
#define GWEN_GUI_INPUT_FLAGS_TAN
Definition: gui.h:222
#define GWEN_WIDGET_FLAGS_PASSWORD
Definition: dialog.h:64
GWEN_GUI * GWEN_Gui_GetGui(void)
Definition: gui.c:160
void GWEN_DlgInput_Fini(GWEN_DIALOG *dlg)
Definition: dlg_input.c:231
void GWEN_Buffer_free(GWEN_BUFFER *bf)
Definition: buffer.c:89
struct GWEN_BUFFER GWEN_BUFFER
A dynamically resizeable text buffer.
Definition: buffer.h:38
int GWEN_DlgInput_GetFlagAllowStore(GWEN_DIALOG *dlg)
Definition: dlg_input.c:404
#define DBG_ERROR(dbg_logger, format, args...)
Definition: debug.h:97
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_GUI_INPUT_FLAGS_SHOW
Definition: gui.h:213
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 * GWEN_Dialog_new(const char *dialogId)
Definition: dialog.c:54
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
#define DBG_INFO(dbg_logger, format, args...)
Definition: debug.h:181
#define GWEN_PM_LIBNAME
Definition: gwenhywfar.h:42
struct GWEN_GUI GWEN_GUI
Definition: gui.h:176
int GWEN_DB_GetIntValue(GWEN_DB_NODE *n, const char *path, int idx, int defVal)
Definition: db.c:1163
void GWEN_Dialog_free(GWEN_DIALOG *dlg)
Definition: dialog.c:137
#define GWEN_INHERIT(bt, t)
Definition: inherit.h:264
int GWEN_Dialog_ReadXmlFile(GWEN_DIALOG *dlg, const char *fname)
Definition: dialog.c:531
int GWEN_DB_SetIntValue(GWEN_DB_NODE *n, uint32_t flags, const char *path, int val)
Definition: db.c:1202
int GWEN_PathManager_FindFile(const char *destLib, const char *pathName, const char *fileName, GWEN_BUFFER *fbuf)
Definition: pathmanager.c:541
#define GWEN_ERROR_NO_DATA
Definition: error.h:94
#define GWEN_INHERIT_SETDATA(bt, t, element, data, fn)
Definition: inherit.h:292
int GWEN_DlgInput_HandleActivated(GWEN_DIALOG *dlg, const char *sender)
Definition: dlg_input.c:285
uint32_t GWEN_Gui_GetFlags(const GWEN_GUI *gui)
Definition: gui.c:195
#define GWEN_UNUSED
#define GWEN_INHERIT_GETDATA(bt, t, element)
Definition: inherit.h:271
int GWEN_DlgInput_CheckInput(GWEN_DIALOG *dlg)
Definition: dlg_input.c:155
#define DIALOG_MINHEIGHT
Definition: dlg_progress.c:28