gwenhywfar  4.3.3
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  int rv;
43 
44  if (flags & GWEN_GUI_INPUT_FLAGS_CONFIRM)
45  dlg=GWEN_Dialog_new("dlg_gwen_input1");
46  else
47  dlg=GWEN_Dialog_new("dlg_gwen_input2");
48  GWEN_NEW_OBJECT(GWEN_DLGINPUT, xdlg);
49 
50  GWEN_INHERIT_SETDATA(GWEN_DIALOG, GWEN_DLGINPUT, dlg, xdlg,
52 
54 
55  /* get path of dialog description file */
56  fbuf=GWEN_Buffer_new(0, 256, 0, 1);
58  "gwenhywfar/dialogs/dlg_input.dlg",
59  fbuf);
60  if (rv<0) {
61  DBG_INFO(GWEN_LOGDOMAIN, "Dialog description file not found (%d).", rv);
62  GWEN_Buffer_free(fbuf);
63  GWEN_Dialog_free(dlg);
64  return NULL;
65  }
66 
67  /* read dialog from dialog description file */
69  if (rv<0) {
70  DBG_INFO(GWEN_LOGDOMAIN, "here (%d).", rv);
71  GWEN_Buffer_free(fbuf);
72  GWEN_Dialog_free(dlg);
73  return NULL;
74  }
75  GWEN_Buffer_free(fbuf);
76 
77  xdlg->flags=flags;
78  if (title)
79  xdlg->title=strdup(title);
80  if (text)
81  xdlg->text=strdup(text);
82  xdlg->minLen=minLen;
83  xdlg->maxLen=maxLen;
84 
85  if (!(flags & GWEN_GUI_INPUT_FLAGS_SHOW)) {
88  }
89 
90  if (maxLen>32) {
91  GWEN_Dialog_SetWidgetColumns(dlg, "input1", 64);
92  GWEN_Dialog_SetWidgetColumns(dlg, "input2", 64);
93  }
94  else {
95  GWEN_Dialog_SetWidgetColumns(dlg, "input1", 32);
96  GWEN_Dialog_SetWidgetColumns(dlg, "input2", 32);
97  }
98 
99  if (!(flags & GWEN_GUI_INPUT_FLAGS_CONFIRM)) {
100  GWEN_Dialog_RemoveWidget(dlg, "input2");
101  GWEN_Dialog_RemoveWidget(dlg, "label2");
102  }
103 
104  return dlg;
105 }
106 
107 
108 
109 void GWENHYWFAR_CB GWEN_DlgInput_FreeData(void *bp, void *p) {
110  GWEN_DLGINPUT *xdlg;
111 
112  xdlg=(GWEN_DLGINPUT*) p;
113 
114  if (xdlg->response) {
115  memset(xdlg->response, 0, strlen(xdlg->response));
116  xdlg->response=NULL;
117  }
118  free(xdlg->title);
119  free(xdlg->text);
120 
121  GWEN_FREE_OBJECT(xdlg);
122 }
123 
124 
125 
127  GWEN_DLGINPUT *xdlg;
128  const char *s1;
129 
130  assert(dlg);
131  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, GWEN_DLGINPUT, dlg);
132  assert(xdlg);
133 
135  if (xdlg->flags & GWEN_GUI_INPUT_FLAGS_CONFIRM) {
136  const char *s2;
137 
139 
140  /* check for equality */
141  if (!s1 || !s2 || strcasecmp(s1, s2)!=0)
142  return -1;
143  }
144 
145  if (!s1)
146  return -1;
147 
148  if (xdlg->minLen>=0) {
149  if (strlen(s1)<xdlg->minLen)
150  return -1;
151  }
152 
153  return 0;
154 }
155 
156 
157 
159  GWEN_DLGINPUT *xdlg;
160  GWEN_DB_NODE *dbParams;
161 
162  assert(dlg);
163  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, GWEN_DLGINPUT, dlg);
164  assert(xdlg);
165 
166  dbParams=GWEN_Dialog_GetPreferences(dlg);
167  assert(dbParams);
168 
169 #if 0
170  /* read width */
171  i=GWEN_DB_GetIntValue(dbParams, "dialog_width", 0, -1);
172  if (i>=DIALOG_MINWIDTH)
174 
175  /* read height */
176  i=GWEN_DB_GetIntValue(dbParams, "dialog_height", 0, -1);
177  if (i>=DIALOG_MINHEIGHT)
179 #endif
180 
181  /* special stuff */
182  if (xdlg->title)
183  GWEN_Dialog_SetCharProperty(dlg, "", GWEN_DialogProperty_Title, 0, xdlg->title, 0);
184 
185  if (xdlg->text)
186  GWEN_Dialog_SetCharProperty(dlg, "descrLabel", GWEN_DialogProperty_Title, 0, xdlg->text, 0);
187 
188 
189  GWEN_Dialog_SetIntProperty(dlg, "okButton", GWEN_DialogProperty_Enabled, 0, 0, 0);
190  GWEN_Dialog_SetIntProperty(dlg, "abortButton", GWEN_DialogProperty_Enabled, 0, 1, 0);
191 
192  GWEN_Dialog_SetIntProperty(dlg, "input1", GWEN_DialogProperty_Focus, 0, 1, 0);
193 
194 
195  xdlg->wasInit=1;
196 }
197 
198 
199 
201  GWEN_DLGINPUT *xdlg;
202  GWEN_DB_NODE *dbParams;
203 
204  assert(dlg);
205  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, GWEN_DLGINPUT, dlg);
206  assert(xdlg);
207 
208  dbParams=GWEN_Dialog_GetPreferences(dlg);
209  assert(dbParams);
210 
211  if (xdlg->response) {
212  memset(xdlg->response, 0, strlen(xdlg->response));
213  xdlg->response=NULL;
214  }
215 
216  if (GWEN_DlgInput_CheckInput(dlg)==0) {
217  const char *s;
219  if (s)
220  xdlg->response=strdup(s);
221  }
222 
223 #if 0
224  /* store dialog width */
226  if (i<DIALOG_MINWIDTH)
227  i=DIALOG_MINWIDTH;
228  GWEN_DB_SetIntValue(dbParams,
230  "dialog_width",
231  i);
232 
233  /* store dialog height */
235  if (i<DIALOG_MINHEIGHT)
237  GWEN_DB_SetIntValue(dbParams,
239  "dialog_height",
240  i);
241 #endif
242 }
243 
244 
245 
246 
247 int GWEN_DlgInput_HandleActivated(GWEN_DIALOG *dlg, const char *sender) {
248  GWEN_DLGINPUT *xdlg;
249 
250  assert(dlg);
251  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, GWEN_DLGINPUT, dlg);
252  assert(xdlg);
253 
254  if (strcasecmp(sender, "okButton")==0) {
256  }
257  else if (strcasecmp(sender, "abortButton")==0) {
259  }
260  else if (strcasecmp(sender, "input1")==0 ||
261  strcasecmp(sender, "input2")==0) {
262  if (GWEN_DlgInput_CheckInput(dlg)==0)
265  }
266 
268 }
269 
270 
271 
272 int GWEN_DlgInput_HandleValueChanged(GWEN_DIALOG *dlg, const char *sender) {
273  GWEN_DLGINPUT *xdlg;
274 
275  assert(dlg);
276  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, GWEN_DLGINPUT, dlg);
277  assert(xdlg);
278 
279  if (strcasecmp(sender, "input1")==0 ||
280  strcasecmp(sender, "input2")==0) {
281  if (GWEN_DlgInput_CheckInput(dlg))
282  /* disable okButton */
283  GWEN_Dialog_SetIntProperty(dlg, "okButton", GWEN_DialogProperty_Enabled, 0, 0, 0);
284  else
285  /* enable okButton */
286  GWEN_Dialog_SetIntProperty(dlg, "okButton", GWEN_DialogProperty_Enabled, 0, 1, 0);
288  }
289 
291 }
292 
293 
294 
297  const char *sender) {
298  GWEN_DLGINPUT *xdlg;
299 
300  assert(dlg);
301  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, GWEN_DLGINPUT, dlg);
302  assert(xdlg);
303 
304  switch(t) {
306  GWEN_DlgInput_Init(dlg);
308 
310  GWEN_DlgInput_Fini(dlg);
312 
314  return GWEN_DlgInput_HandleValueChanged(dlg, sender);
315  break;
316 
318  return GWEN_DlgInput_HandleActivated(dlg, sender);
319 
322 
325 
328  }
329 
331 
332 }
333 
334 
335 
336 int GWEN_DlgInput_CopyInput(GWEN_DIALOG *dlg, char *buffer, int size) {
337  GWEN_DLGINPUT *xdlg;
338 
339  assert(dlg);
340  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, GWEN_DLGINPUT, dlg);
341  assert(xdlg);
342 
343  if (xdlg->response) {
344  int l;
345 
346  l=strlen(xdlg->response);
347  if ((l+1)>size) {
348  DBG_ERROR(GWEN_LOGDOMAIN, "Buffer too small");
350  }
351  /* buffer ok, copy */
352  memmove(buffer, xdlg->response, l+1);
353  return 0;
354  }
355  return GWEN_ERROR_NO_DATA;
356 }
357 
358 
359 
360