gwenhywfar  5.4.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  }
129 
130  return dlg;
131 }
132 
133 
134 
136 {
137  GWEN_DLGINPUT *xdlg;
138 
139  xdlg=(GWEN_DLGINPUT *) p;
140 
141  if (xdlg->response) {
142  memset(xdlg->response, 0, strlen(xdlg->response));
143  free(xdlg->response);
144  xdlg->response=NULL;
145  }
146  free(xdlg->title);
147  free(xdlg->text);
148 
149  GWEN_FREE_OBJECT(xdlg);
150 }
151 
152 
153 
155 {
156  GWEN_DLGINPUT *xdlg;
157  const char *s1;
158 
159  assert(dlg);
160  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, GWEN_DLGINPUT, dlg);
161  assert(xdlg);
162 
164  if (xdlg->flags & GWEN_GUI_INPUT_FLAGS_CONFIRM) {
165  const char *s2;
166 
168 
169  /* check for equality */
170  if (!s1 || !s2 || strcasecmp(s1, s2)!=0)
171  return -1;
172  }
173 
174  if (!s1)
175  return -1;
176 
177  if (xdlg->minLen>=0) {
178  if (strlen(s1)<xdlg->minLen)
179  return -1;
180  }
181 
182  return 0;
183 }
184 
185 
186 
188 {
189  GWEN_DLGINPUT *xdlg;
190  GWEN_DB_NODE *dbParams;
191 
192  assert(dlg);
193  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, GWEN_DLGINPUT, dlg);
194  assert(xdlg);
195 
196  dbParams=GWEN_Dialog_GetPreferences(dlg);
197  assert(dbParams);
198 
199 #if 0
200  /* read width */
201  i=GWEN_DB_GetIntValue(dbParams, "dialog_width", 0, -1);
202  if (i>=DIALOG_MINWIDTH)
204 
205  /* read height */
206  i=GWEN_DB_GetIntValue(dbParams, "dialog_height", 0, -1);
207  if (i>=DIALOG_MINHEIGHT)
209 #endif
210 
211  /* special stuff */
212  if (xdlg->title)
213  GWEN_Dialog_SetCharProperty(dlg, "", GWEN_DialogProperty_Title, 0, xdlg->title, 0);
214 
215  if (xdlg->text)
216  GWEN_Dialog_SetCharProperty(dlg, "descrLabel", GWEN_DialogProperty_Title, 0, xdlg->text, 0);
217 
218 
219  GWEN_Dialog_SetIntProperty(dlg, "okButton", GWEN_DialogProperty_Enabled, 0, 0, 0);
220  GWEN_Dialog_SetIntProperty(dlg, "abortButton", GWEN_DialogProperty_Enabled, 0, 1, 0);
221 
222  GWEN_Dialog_SetIntProperty(dlg, "input1", GWEN_DialogProperty_Focus, 0, 1, 0);
223 
224 
225  xdlg->wasInit=1;
226 }
227 
228 
229 
231 {
232  GWEN_DLGINPUT *xdlg;
233  GWEN_DB_NODE *dbParams;
234 
235  assert(dlg);
236  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, GWEN_DLGINPUT, dlg);
237  assert(xdlg);
238 
239  dbParams=GWEN_Dialog_GetPreferences(dlg);
240  assert(dbParams);
241 
242  if (xdlg->response) {
243  memset(xdlg->response, 0, strlen(xdlg->response));
244  free(xdlg->response);
245  xdlg->response=NULL;
246  }
247 
248  if (GWEN_DlgInput_CheckInput(dlg)==0) {
249  const char *s;
250 
252  if (s)
253  xdlg->response=strdup(s);
254  xdlg->flagAllowStore=GWEN_Dialog_GetIntProperty(dlg, "storePasswordCheck", GWEN_DialogProperty_Value, 0, 0);
255  }
256 
257 #if 0
258  /* store dialog width */
260  if (i<DIALOG_MINWIDTH)
261  i=DIALOG_MINWIDTH;
262  GWEN_DB_SetIntValue(dbParams,
264  "dialog_width",
265  i);
266 
267  /* store dialog height */
269  if (i<DIALOG_MINHEIGHT)
271  GWEN_DB_SetIntValue(dbParams,
273  "dialog_height",
274  i);
275 #endif
276 }
277 
278 
279 
280 
281 int GWEN_DlgInput_HandleActivated(GWEN_DIALOG *dlg, const char *sender)
282 {
283  GWEN_DLGINPUT *xdlg;
284 
285  assert(dlg);
286  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, GWEN_DLGINPUT, dlg);
287  assert(xdlg);
288 
289  if (strcasecmp(sender, "okButton")==0) {
291  }
292  else if (strcasecmp(sender, "abortButton")==0) {
294  }
295  else if (strcasecmp(sender, "input1")==0 ||
296  strcasecmp(sender, "input2")==0) {
297  if (GWEN_DlgInput_CheckInput(dlg)==0)
300  }
301 
303 }
304 
305 
306 
307 int GWEN_DlgInput_HandleValueChanged(GWEN_DIALOG *dlg, const char *sender)
308 {
309  GWEN_DLGINPUT *xdlg;
310 
311  assert(dlg);
312  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, GWEN_DLGINPUT, dlg);
313  assert(xdlg);
314 
315  if (strcasecmp(sender, "input1")==0 ||
316  strcasecmp(sender, "input2")==0) {
317  if (GWEN_DlgInput_CheckInput(dlg))
318  /* disable okButton */
319  GWEN_Dialog_SetIntProperty(dlg, "okButton", GWEN_DialogProperty_Enabled, 0, 0, 0);
320  else
321  /* enable okButton */
322  GWEN_Dialog_SetIntProperty(dlg, "okButton", GWEN_DialogProperty_Enabled, 0, 1, 0);
324  }
325 
327 }
328 
329 
330 
333  const char *sender)
334 {
335  GWEN_DLGINPUT *xdlg;
336 
337  assert(dlg);
338  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, GWEN_DLGINPUT, dlg);
339  assert(xdlg);
340 
341  switch (t) {
343  GWEN_DlgInput_Init(dlg);
345 
347  GWEN_DlgInput_Fini(dlg);
349 
351  return GWEN_DlgInput_HandleValueChanged(dlg, sender);
352  break;
353 
355  return GWEN_DlgInput_HandleActivated(dlg, sender);
356 
359 
362 
365  }
366 
368 
369 }
370 
371 
372 
373 int GWEN_DlgInput_CopyInput(GWEN_DIALOG *dlg, char *buffer, int size)
374 {
375  GWEN_DLGINPUT *xdlg;
376 
377  assert(dlg);
378  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, GWEN_DLGINPUT, dlg);
379  assert(xdlg);
380 
381  if (xdlg->response) {
382  int l;
383 
384  l=strlen(xdlg->response);
385  if ((l+1)>size) {
386  DBG_ERROR(GWEN_LOGDOMAIN, "Buffer too small");
388  }
389  /* buffer ok, copy */
390  memmove(buffer, xdlg->response, l+1);
391  return 0;
392  }
393  return GWEN_ERROR_NO_DATA;
394 }
395 
396 
397 
399 {
400  GWEN_DLGINPUT *xdlg;
401 
402  assert(dlg);
403  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, GWEN_DLGINPUT, dlg);
404  assert(xdlg);
405 
406  return xdlg->flagAllowStore;
407 }
408 
409 
410 
411 
void GWEN_Dialog_SetWidgetColumns(GWEN_DIALOG *dlg, const char *name, int i)
Definition: dialog.c:843
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:331
#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:135
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:373
void GWEN_DlgInput_Init(GWEN_DIALOG *dlg)
Definition: dlg_input.c:187
#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:764
#define GWEN_GUI_FLAGS_PERMPASSWORDS
Definition: gui.h:992
void GWEN_Dialog_AddWidgetFlags(GWEN_DIALOG *dlg, const char *name, uint32_t fl)
Definition: dialog.c:805
GWEN_DIALOG_EVENTTYPE
Definition: dialog.h:90
GWEN_DIALOG_SIGNALHANDLER GWEN_Dialog_SetSignalHandler(GWEN_DIALOG *dlg, GWEN_DIALOG_SIGNALHANDLER fn)
Definition: dialog.c:304
#define GWEN_LOGDOMAIN
Definition: logger.h:35
GWEN_DB_NODE * GWEN_Dialog_GetPreferences(const GWEN_DIALOG *dlg)
Definition: dialog.c:945
int GWEN_DlgInput_HandleValueChanged(GWEN_DIALOG *dlg, const char *sender)
Definition: dlg_input.c:307
#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:676
#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:167
void GWEN_DlgInput_Fini(GWEN_DIALOG *dlg)
Definition: dlg_input.c:230
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:398
#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:735
#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:646
GWEN_DIALOG * GWEN_Dialog_new(const char *dialogId)
Definition: dialog.c:53
int GWEN_Dialog_SetCharProperty(GWEN_DIALOG *dlg, const char *name, GWEN_DIALOG_PROPERTY prop, int index, const char *value, int doSignal)
Definition: dialog.c:705
#define DBG_INFO(dbg_logger, format, args...)
Definition: debug.h:178
#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:1161
void GWEN_Dialog_free(GWEN_DIALOG *dlg)
Definition: dialog.c:136
#define GWEN_INHERIT(bt, t)
Definition: inherit.h:264
int GWEN_Dialog_ReadXmlFile(GWEN_DIALOG *dlg, const char *fname)
Definition: dialog.c:474
int GWEN_DB_SetIntValue(GWEN_DB_NODE *n, uint32_t flags, const char *path, int val)
Definition: db.c:1200
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:281
uint32_t GWEN_Gui_GetFlags(const GWEN_GUI *gui)
Definition: gui.c:700
#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:154
#define DIALOG_MINHEIGHT
Definition: dlg_progress.c:28