gwenhywfar  4.8.0beta
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  GWEN_DIALOG *dlg;
40  GWEN_DLGINPUT *xdlg;
41  GWEN_BUFFER *fbuf;
42  GWEN_GUI *gui;
43  uint32_t gflags=0;
44  int n;
45  int rv;
46  char dlgNameBuf[128];
47 
48  /* get GUI flags */
49  gui=GWEN_Gui_GetGui();
50  if (gui)
51  gflags=GWEN_Gui_GetFlags(gui);
52 
53  /* setup dialog name */
54  n=0;
55  if (flags & GWEN_GUI_INPUT_FLAGS_CONFIRM) n|=1;
56  if (
57  (gflags & GWEN_GUI_FLAGS_PERMPASSWORDS) &&
58  !(flags & GWEN_GUI_INPUT_FLAGS_DIRECT) &&
59  !(flags & GWEN_GUI_INPUT_FLAGS_TAN) &&
60  !(flags & GWEN_GUI_INPUT_FLAGS_DIRECT)
61  )
62  n|=2;
63 
64  snprintf(dlgNameBuf, sizeof(dlgNameBuf)-1, "dlg_gwen_input%d", n);
65  dlgNameBuf[sizeof(dlgNameBuf)-1]=0;
66 
67  dlg=GWEN_Dialog_new(dlgNameBuf);
68  GWEN_NEW_OBJECT(GWEN_DLGINPUT, xdlg);
69 
70  GWEN_INHERIT_SETDATA(GWEN_DIALOG, GWEN_DLGINPUT, dlg, xdlg,
72 
74 
75  /* get path of dialog description file */
76  fbuf=GWEN_Buffer_new(0, 256, 0, 1);
78  "gwenhywfar/dialogs/dlg_input.dlg",
79  fbuf);
80  if (rv<0) {
81  DBG_INFO(GWEN_LOGDOMAIN, "Dialog description file not found (%d).", rv);
82  GWEN_Buffer_free(fbuf);
83  GWEN_Dialog_free(dlg);
84  return NULL;
85  }
86 
87  /* read dialog from dialog description file */
89  if (rv<0) {
90  DBG_INFO(GWEN_LOGDOMAIN, "here (%d).", rv);
91  GWEN_Buffer_free(fbuf);
92  GWEN_Dialog_free(dlg);
93  return NULL;
94  }
95  GWEN_Buffer_free(fbuf);
96 
97  xdlg->flags=flags;
98  if (title)
99  xdlg->title=strdup(title);
100  if (text)
101  xdlg->text=strdup(text);
102  xdlg->minLen=minLen;
103  xdlg->maxLen=maxLen;
104 
105  if (!(flags & GWEN_GUI_INPUT_FLAGS_SHOW)) {
108  }
109 
110  if (maxLen>32) {
111  GWEN_Dialog_SetWidgetColumns(dlg, "input1", 64);
112  GWEN_Dialog_SetWidgetColumns(dlg, "input2", 64);
113  }
114  else {
115  GWEN_Dialog_SetWidgetColumns(dlg, "input1", 32);
116  GWEN_Dialog_SetWidgetColumns(dlg, "input2", 32);
117  }
118 
119  if (!(flags & GWEN_GUI_INPUT_FLAGS_CONFIRM)) {
120  GWEN_Dialog_RemoveWidget(dlg, "input2");
121  GWEN_Dialog_RemoveWidget(dlg, "label2");
122  }
123 
124  if (!(n & 2)) {
125  GWEN_Dialog_RemoveWidget(dlg, "storePasswordCheck");
126  }
127 
128  return dlg;
129 }
130 
131 
132 
133 void GWENHYWFAR_CB GWEN_DlgInput_FreeData(void *bp, void *p) {
134  GWEN_DLGINPUT *xdlg;
135 
136  xdlg=(GWEN_DLGINPUT*) p;
137 
138  if (xdlg->response) {
139  memset(xdlg->response, 0, strlen(xdlg->response));
140  xdlg->response=NULL;
141  }
142  free(xdlg->title);
143  free(xdlg->text);
144 
145  GWEN_FREE_OBJECT(xdlg);
146 }
147 
148 
149 
151  GWEN_DLGINPUT *xdlg;
152  const char *s1;
153 
154  assert(dlg);
155  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, GWEN_DLGINPUT, dlg);
156  assert(xdlg);
157 
159  if (xdlg->flags & GWEN_GUI_INPUT_FLAGS_CONFIRM) {
160  const char *s2;
161 
163 
164  /* check for equality */
165  if (!s1 || !s2 || strcasecmp(s1, s2)!=0)
166  return -1;
167  }
168 
169  if (!s1)
170  return -1;
171 
172  if (xdlg->minLen>=0) {
173  if (strlen(s1)<xdlg->minLen)
174  return -1;
175  }
176 
177  return 0;
178 }
179 
180 
181 
183  GWEN_DLGINPUT *xdlg;
184  GWEN_DB_NODE *dbParams;
185 
186  assert(dlg);
187  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, GWEN_DLGINPUT, dlg);
188  assert(xdlg);
189 
190  dbParams=GWEN_Dialog_GetPreferences(dlg);
191  assert(dbParams);
192 
193 #if 0
194  /* read width */
195  i=GWEN_DB_GetIntValue(dbParams, "dialog_width", 0, -1);
196  if (i>=DIALOG_MINWIDTH)
198 
199  /* read height */
200  i=GWEN_DB_GetIntValue(dbParams, "dialog_height", 0, -1);
201  if (i>=DIALOG_MINHEIGHT)
203 #endif
204 
205  /* special stuff */
206  if (xdlg->title)
207  GWEN_Dialog_SetCharProperty(dlg, "", GWEN_DialogProperty_Title, 0, xdlg->title, 0);
208 
209  if (xdlg->text)
210  GWEN_Dialog_SetCharProperty(dlg, "descrLabel", GWEN_DialogProperty_Title, 0, xdlg->text, 0);
211 
212 
213  GWEN_Dialog_SetIntProperty(dlg, "okButton", GWEN_DialogProperty_Enabled, 0, 0, 0);
214  GWEN_Dialog_SetIntProperty(dlg, "abortButton", GWEN_DialogProperty_Enabled, 0, 1, 0);
215 
216  GWEN_Dialog_SetIntProperty(dlg, "input1", GWEN_DialogProperty_Focus, 0, 1, 0);
217 
218 
219  xdlg->wasInit=1;
220 }
221 
222 
223 
225  GWEN_DLGINPUT *xdlg;
226  GWEN_DB_NODE *dbParams;
227 
228  assert(dlg);
229  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, GWEN_DLGINPUT, dlg);
230  assert(xdlg);
231 
232  dbParams=GWEN_Dialog_GetPreferences(dlg);
233  assert(dbParams);
234 
235  if (xdlg->response) {
236  memset(xdlg->response, 0, strlen(xdlg->response));
237  xdlg->response=NULL;
238  }
239 
240  if (GWEN_DlgInput_CheckInput(dlg)==0) {
241  const char *s;
242 
244  if (s)
245  xdlg->response=strdup(s);
246  xdlg->flagAllowStore=GWEN_Dialog_GetIntProperty(dlg, "storePasswordCheck", GWEN_DialogProperty_Value, 0, 0);
247  }
248 
249 #if 0
250  /* store dialog width */
252  if (i<DIALOG_MINWIDTH)
253  i=DIALOG_MINWIDTH;
254  GWEN_DB_SetIntValue(dbParams,
256  "dialog_width",
257  i);
258 
259  /* store dialog height */
261  if (i<DIALOG_MINHEIGHT)
263  GWEN_DB_SetIntValue(dbParams,
265  "dialog_height",
266  i);
267 #endif
268 }
269 
270 
271 
272 
273 int GWEN_DlgInput_HandleActivated(GWEN_DIALOG *dlg, const char *sender) {
274  GWEN_DLGINPUT *xdlg;
275 
276  assert(dlg);
277  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, GWEN_DLGINPUT, dlg);
278  assert(xdlg);
279 
280  if (strcasecmp(sender, "okButton")==0) {
282  }
283  else if (strcasecmp(sender, "abortButton")==0) {
285  }
286  else if (strcasecmp(sender, "input1")==0 ||
287  strcasecmp(sender, "input2")==0) {
288  if (GWEN_DlgInput_CheckInput(dlg)==0)
291  }
292 
294 }
295 
296 
297 
298 int GWEN_DlgInput_HandleValueChanged(GWEN_DIALOG *dlg, const char *sender) {
299  GWEN_DLGINPUT *xdlg;
300 
301  assert(dlg);
302  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, GWEN_DLGINPUT, dlg);
303  assert(xdlg);
304 
305  if (strcasecmp(sender, "input1")==0 ||
306  strcasecmp(sender, "input2")==0) {
307  if (GWEN_DlgInput_CheckInput(dlg))
308  /* disable okButton */
309  GWEN_Dialog_SetIntProperty(dlg, "okButton", GWEN_DialogProperty_Enabled, 0, 0, 0);
310  else
311  /* enable okButton */
312  GWEN_Dialog_SetIntProperty(dlg, "okButton", GWEN_DialogProperty_Enabled, 0, 1, 0);
314  }
315 
317 }
318 
319 
320 
323  const char *sender) {
324  GWEN_DLGINPUT *xdlg;
325 
326  assert(dlg);
327  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, GWEN_DLGINPUT, dlg);
328  assert(xdlg);
329 
330  switch(t) {
332  GWEN_DlgInput_Init(dlg);
334 
336  GWEN_DlgInput_Fini(dlg);
338 
340  return GWEN_DlgInput_HandleValueChanged(dlg, sender);
341  break;
342 
344  return GWEN_DlgInput_HandleActivated(dlg, sender);
345 
348 
351 
354  }
355 
357 
358 }
359 
360 
361 
362 int GWEN_DlgInput_CopyInput(GWEN_DIALOG *dlg, char *buffer, int size) {
363  GWEN_DLGINPUT *xdlg;
364 
365  assert(dlg);
366  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, GWEN_DLGINPUT, dlg);
367  assert(xdlg);
368 
369  if (xdlg->response) {
370  int l;
371 
372  l=strlen(xdlg->response);
373  if ((l+1)>size) {
374  DBG_ERROR(GWEN_LOGDOMAIN, "Buffer too small");
376  }
377  /* buffer ok, copy */
378  memmove(buffer, xdlg->response, l+1);
379  return 0;
380  }
381  return GWEN_ERROR_NO_DATA;
382 }
383 
384 
385 
387  GWEN_DLGINPUT *xdlg;
388 
389  assert(dlg);
390  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, GWEN_DLGINPUT, dlg);
391  assert(xdlg);
392 
393  return xdlg->flagAllowStore;
394 }
395 
396 
397 
398