gwenhywfar  4.99.15beta
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 
135 void GWENHYWFAR_CB GWEN_DlgInput_FreeData(void *bp, void *p)
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  xdlg->response=NULL;
144  }
145  free(xdlg->title);
146  free(xdlg->text);
147 
148  GWEN_FREE_OBJECT(xdlg);
149 }
150 
151 
152 
154 {
155  GWEN_DLGINPUT *xdlg;
156  const char *s1;
157 
158  assert(dlg);
159  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, GWEN_DLGINPUT, dlg);
160  assert(xdlg);
161 
163  if (xdlg->flags & GWEN_GUI_INPUT_FLAGS_CONFIRM) {
164  const char *s2;
165 
167 
168  /* check for equality */
169  if (!s1 || !s2 || strcasecmp(s1, s2)!=0)
170  return -1;
171  }
172 
173  if (!s1)
174  return -1;
175 
176  if (xdlg->minLen>=0) {
177  if (strlen(s1)<xdlg->minLen)
178  return -1;
179  }
180 
181  return 0;
182 }
183 
184 
185 
187 {
188  GWEN_DLGINPUT *xdlg;
189  GWEN_DB_NODE *dbParams;
190 
191  assert(dlg);
192  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, GWEN_DLGINPUT, dlg);
193  assert(xdlg);
194 
195  dbParams=GWEN_Dialog_GetPreferences(dlg);
196  assert(dbParams);
197 
198 #if 0
199  /* read width */
200  i=GWEN_DB_GetIntValue(dbParams, "dialog_width", 0, -1);
201  if (i>=DIALOG_MINWIDTH)
203 
204  /* read height */
205  i=GWEN_DB_GetIntValue(dbParams, "dialog_height", 0, -1);
206  if (i>=DIALOG_MINHEIGHT)
208 #endif
209 
210  /* special stuff */
211  if (xdlg->title)
212  GWEN_Dialog_SetCharProperty(dlg, "", GWEN_DialogProperty_Title, 0, xdlg->title, 0);
213 
214  if (xdlg->text)
215  GWEN_Dialog_SetCharProperty(dlg, "descrLabel", GWEN_DialogProperty_Title, 0, xdlg->text, 0);
216 
217 
218  GWEN_Dialog_SetIntProperty(dlg, "okButton", GWEN_DialogProperty_Enabled, 0, 0, 0);
219  GWEN_Dialog_SetIntProperty(dlg, "abortButton", GWEN_DialogProperty_Enabled, 0, 1, 0);
220 
221  GWEN_Dialog_SetIntProperty(dlg, "input1", GWEN_DialogProperty_Focus, 0, 1, 0);
222 
223 
224  xdlg->wasInit=1;
225 }
226 
227 
228 
230 {
231  GWEN_DLGINPUT *xdlg;
232  GWEN_DB_NODE *dbParams;
233 
234  assert(dlg);
235  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, GWEN_DLGINPUT, dlg);
236  assert(xdlg);
237 
238  dbParams=GWEN_Dialog_GetPreferences(dlg);
239  assert(dbParams);
240 
241  if (xdlg->response) {
242  memset(xdlg->response, 0, strlen(xdlg->response));
243  xdlg->response=NULL;
244  }
245 
246  if (GWEN_DlgInput_CheckInput(dlg)==0) {
247  const char *s;
248 
250  if (s)
251  xdlg->response=strdup(s);
252  xdlg->flagAllowStore=GWEN_Dialog_GetIntProperty(dlg, "storePasswordCheck", GWEN_DialogProperty_Value, 0, 0);
253  }
254 
255 #if 0
256  /* store dialog width */
258  if (i<DIALOG_MINWIDTH)
259  i=DIALOG_MINWIDTH;
260  GWEN_DB_SetIntValue(dbParams,
262  "dialog_width",
263  i);
264 
265  /* store dialog height */
267  if (i<DIALOG_MINHEIGHT)
269  GWEN_DB_SetIntValue(dbParams,
271  "dialog_height",
272  i);
273 #endif
274 }
275 
276 
277 
278 
279 int GWEN_DlgInput_HandleActivated(GWEN_DIALOG *dlg, const char *sender)
280 {
281  GWEN_DLGINPUT *xdlg;
282 
283  assert(dlg);
284  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, GWEN_DLGINPUT, dlg);
285  assert(xdlg);
286 
287  if (strcasecmp(sender, "okButton")==0) {
289  }
290  else if (strcasecmp(sender, "abortButton")==0) {
292  }
293  else if (strcasecmp(sender, "input1")==0 ||
294  strcasecmp(sender, "input2")==0) {
295  if (GWEN_DlgInput_CheckInput(dlg)==0)
298  }
299 
301 }
302 
303 
304 
305 int GWEN_DlgInput_HandleValueChanged(GWEN_DIALOG *dlg, const char *sender)
306 {
307  GWEN_DLGINPUT *xdlg;
308 
309  assert(dlg);
310  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, GWEN_DLGINPUT, dlg);
311  assert(xdlg);
312 
313  if (strcasecmp(sender, "input1")==0 ||
314  strcasecmp(sender, "input2")==0) {
315  if (GWEN_DlgInput_CheckInput(dlg))
316  /* disable okButton */
317  GWEN_Dialog_SetIntProperty(dlg, "okButton", GWEN_DialogProperty_Enabled, 0, 0, 0);
318  else
319  /* enable okButton */
320  GWEN_Dialog_SetIntProperty(dlg, "okButton", GWEN_DialogProperty_Enabled, 0, 1, 0);
322  }
323 
325 }
326 
327 
328 
331  const char *sender)
332 {
333  GWEN_DLGINPUT *xdlg;
334 
335  assert(dlg);
336  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, GWEN_DLGINPUT, dlg);
337  assert(xdlg);
338 
339  switch (t) {
341  GWEN_DlgInput_Init(dlg);
343 
345  GWEN_DlgInput_Fini(dlg);
347 
349  return GWEN_DlgInput_HandleValueChanged(dlg, sender);
350  break;
351 
353  return GWEN_DlgInput_HandleActivated(dlg, sender);
354 
357 
360 
363  }
364 
366 
367 }
368 
369 
370 
371 int GWEN_DlgInput_CopyInput(GWEN_DIALOG *dlg, char *buffer, int size)
372 {
373  GWEN_DLGINPUT *xdlg;
374 
375  assert(dlg);
376  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, GWEN_DLGINPUT, dlg);
377  assert(xdlg);
378 
379  if (xdlg->response) {
380  int l;
381 
382  l=strlen(xdlg->response);
383  if ((l+1)>size) {
384  DBG_ERROR(GWEN_LOGDOMAIN, "Buffer too small");
386  }
387  /* buffer ok, copy */
388  memmove(buffer, xdlg->response, l+1);
389  return 0;
390  }
391  return GWEN_ERROR_NO_DATA;
392 }
393 
394 
395 
397 {
398  GWEN_DLGINPUT *xdlg;
399 
400  assert(dlg);
401  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, GWEN_DLGINPUT, dlg);
402  assert(xdlg);
403 
404  return xdlg->flagAllowStore;
405 }
406 
407 
408 
409 
void GWEN_Dialog_SetWidgetColumns(GWEN_DIALOG *dlg, const char *name, int i)
Definition: dialog.c:796
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:329
#define GWEN_DB_FLAGS_OVERWRITE_VARS
Definition: db.h:121
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:371
void GWEN_DlgInput_Init(GWEN_DIALOG *dlg)
Definition: dlg_input.c:186
#define GWEN_GUI_INPUT_FLAGS_CONFIRM
Definition: gui.h:211
#define GWEN_FREE_OBJECT(varname)
Definition: memory.h:92
#define NULL
Definition: binreloc.c:297
int GWEN_Dialog_RemoveWidget(GWEN_DIALOG *dlg, const char *name)
Definition: dialog.c:717
#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:758
GWEN_DIALOG_EVENTTYPE
Definition: dialog.h:90
GWEN_DIALOG_SIGNALHANDLER GWEN_Dialog_SetSignalHandler(GWEN_DIALOG *dlg, GWEN_DIALOG_SIGNALHANDLER fn)
Definition: dialog.c:257
#define GWEN_LOGDOMAIN
Definition: logger.h:35
GWEN_DB_NODE * GWEN_Dialog_GetPreferences(const GWEN_DIALOG *dlg)
Definition: dialog.c:898
int GWEN_DlgInput_HandleValueChanged(GWEN_DIALOG *dlg, const char *sender)
Definition: dlg_input.c:305
#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:38
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:86
#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:629
#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:229
void GWEN_Buffer_free(GWEN_BUFFER *bf)
Definition: buffer.c:85
struct GWEN_BUFFER GWEN_BUFFER
A dynamically resizeable text buffer.
Definition: buffer.h:41
int GWEN_DlgInput_GetFlagAllowStore(GWEN_DIALOG *dlg)
Definition: dlg_input.c:396
#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:688
#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:599
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:658
#define DBG_INFO(dbg_logger, format, args...)
Definition: debug.h:177
#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:1150
void GWEN_Dialog_free(GWEN_DIALOG *dlg)
Definition: dialog.c:89
#define GWEN_INHERIT(bt, t)
Definition: inherit.h:264
int GWEN_Dialog_ReadXmlFile(GWEN_DIALOG *dlg, const char *fname)
Definition: dialog.c:427
int GWEN_DB_SetIntValue(GWEN_DB_NODE *n, uint32_t flags, const char *path, int val)
Definition: db.c:1189
int GWEN_PathManager_FindFile(const char *destLib, const char *pathName, const char *fileName, GWEN_BUFFER *fbuf)
Definition: pathmanager.c:541
void GWENHYWFAR_CB GWEN_DlgInput_FreeData(void *bp, void *p)
Definition: dlg_input.c:135
#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:279
uint32_t GWEN_Gui_GetFlags(const GWEN_GUI *gui)
Definition: gui.c:686
#define GWEN_INHERIT_GETDATA(bt, t, element)
Definition: inherit.h:271
int GWEN_DlgInput_CheckInput(GWEN_DIALOG *dlg)
Definition: dlg_input.c:153
#define DIALOG_MINHEIGHT
Definition: dlg_progress.c:28