gwenhywfar  4.8.0beta
dlg_message.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_message_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_DLGMSG)
29 
30 
31 
32 
33 
35  const char *title,
36  const char *text,
37  const char *b1,
38  const char *b2,
39  const char *b3) {
40  GWEN_DIALOG *dlg;
41  GWEN_DLGMSG *xdlg;
42  GWEN_BUFFER *fbuf;
43  int rv;
44  int confirmButton;
45 
46  dlg=GWEN_Dialog_new("dlg_gwen_message");
47  GWEN_NEW_OBJECT(GWEN_DLGMSG, xdlg);
48 
49  GWEN_INHERIT_SETDATA(GWEN_DIALOG, GWEN_DLGMSG, dlg, xdlg,
51 
53 
54  /* get path of dialog description file */
55  fbuf=GWEN_Buffer_new(0, 256, 0, 1);
57  "gwenhywfar/dialogs/dlg_message.dlg",
58  fbuf);
59  if (rv<0) {
60  DBG_INFO(GWEN_LOGDOMAIN, "Dialog description file not found (%d).", rv);
61  GWEN_Buffer_free(fbuf);
62  GWEN_Dialog_free(dlg);
63  return NULL;
64  }
65 
66  /* read dialog from dialog description file */
68  if (rv<0) {
69  DBG_INFO(GWEN_LOGDOMAIN, "here (%d).", rv);
70  GWEN_Buffer_free(fbuf);
71  GWEN_Dialog_free(dlg);
72  return NULL;
73  }
74  GWEN_Buffer_free(fbuf);
75 
76  confirmButton=GWEN_GUI_MSG_FLAGS_CONFIRM_BUTTON(flags);
77 
78 
79  xdlg->flags=flags;
80  if (title)
81  xdlg->title=strdup(title);
82  if (text)
83  xdlg->text=strdup(text);
84 
85  if (b1 && *b1) {
86  GWEN_Dialog_SetWidgetText(dlg, "button1", b1);
87  if (confirmButton==1)
89  }
90  else
91  GWEN_Dialog_RemoveWidget(dlg, "button1");
92 
93 
94  if (b2 && *b2) {
95  GWEN_Dialog_SetWidgetText(dlg, "button2", b2);
96  if (confirmButton==2)
98  }
99  else
100  GWEN_Dialog_RemoveWidget(dlg, "button2");
101 
102  if (b3 && *b3) {
103  GWEN_Dialog_SetWidgetText(dlg, "button3", b3);
104  if (confirmButton==3)
106  }
107  else
108  GWEN_Dialog_RemoveWidget(dlg, "button3");
109 
110  return dlg;
111 }
112 
113 
114 
115 void GWENHYWFAR_CB GWEN_DlgMessage_FreeData(void *bp, void *p) {
116  GWEN_DLGMSG *xdlg;
117 
118  xdlg=(GWEN_DLGMSG*) p;
119 
120  free(xdlg->title);
121  free(xdlg->text);
122 
123  GWEN_FREE_OBJECT(xdlg);
124 }
125 
126 
127 
129  GWEN_DLGMSG *xdlg;
130 
131  assert(dlg);
132  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, GWEN_DLGMSG, dlg);
133  assert(xdlg);
134 
135  return xdlg->response;
136 }
137 
138 
139 
141  GWEN_DLGMSG *xdlg;
142  GWEN_DB_NODE *dbParams;
143 
144  assert(dlg);
145  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, GWEN_DLGMSG, dlg);
146  assert(xdlg);
147 
148  dbParams=GWEN_Dialog_GetPreferences(dlg);
149  assert(dbParams);
150 
151 #if 0
152  /* read width */
153  i=GWEN_DB_GetIntValue(dbParams, "dialog_width", 0, -1);
154  if (i>=DIALOG_MINWIDTH)
156 
157  /* read height */
158  i=GWEN_DB_GetIntValue(dbParams, "dialog_height", 0, -1);
159  if (i>=DIALOG_MINHEIGHT)
161 #endif
162 
163  /* special stuff */
164  if (xdlg->title)
165  GWEN_Dialog_SetCharProperty(dlg, "", GWEN_DialogProperty_Title, 0, xdlg->title, 0);
166 
167  if (xdlg->text)
168  GWEN_Dialog_SetCharProperty(dlg, "descrLabel", GWEN_DialogProperty_Title, 0, xdlg->text, 0);
169 
170 
171  xdlg->wasInit=1;
172 }
173 
174 
175 
177  GWEN_DLGMSG *xdlg;
178  GWEN_DB_NODE *dbParams;
179 
180  assert(dlg);
181  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, GWEN_DLGMSG, dlg);
182  assert(xdlg);
183 
184  dbParams=GWEN_Dialog_GetPreferences(dlg);
185  assert(dbParams);
186 
187 #if 0
188  /* store dialog width */
190  if (i<DIALOG_MINWIDTH)
191  i=DIALOG_MINWIDTH;
192  GWEN_DB_SetIntValue(dbParams,
194  "dialog_width",
195  i);
196 
197  /* store dialog height */
199  if (i<DIALOG_MINHEIGHT)
201  GWEN_DB_SetIntValue(dbParams,
203  "dialog_height",
204  i);
205 #endif
206 }
207 
208 
209 
210 
211 int GWEN_DlgMessage_HandleActivated(GWEN_DIALOG *dlg, const char *sender) {
212  GWEN_DLGMSG *xdlg;
213 
214  assert(dlg);
215  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, GWEN_DLGMSG, dlg);
216  assert(xdlg);
217 
218  if (strcasecmp(sender, "button1")==0) {
219  xdlg->response=1;
221  }
222  else if (strcasecmp(sender, "button2")==0) {
223  xdlg->response=2;
225  }
226  else if (strcasecmp(sender, "button3")==0) {
227  xdlg->response=3;
229  }
230 
232 }
233 
234 
235 
236 
239  const char *sender) {
240  GWEN_DLGMSG *xdlg;
241 
242  assert(dlg);
243  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, GWEN_DLGMSG, dlg);
244  assert(xdlg);
245 
246  switch(t) {
250 
254 
256  return GWEN_DlgMessage_HandleActivated(dlg, sender);
257 
261 
264 
267  }
268 
270 
271 }
272 
273 
274 
275