gwenhywfar  4.99.15beta
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 {
41  GWEN_DIALOG *dlg;
42  GWEN_DLGMSG *xdlg;
43  GWEN_BUFFER *fbuf;
44  int rv;
45  int confirmButton;
46 
47  dlg=GWEN_Dialog_new("dlg_gwen_message");
48  GWEN_NEW_OBJECT(GWEN_DLGMSG, xdlg);
49 
50  GWEN_INHERIT_SETDATA(GWEN_DIALOG, GWEN_DLGMSG, dlg, xdlg,
52 
54 
55  /* get path of dialog description file */
56  fbuf=GWEN_Buffer_new(0, 256, 0, 1);
58  "gwenhywfar/dialogs/dlg_message.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  confirmButton=GWEN_GUI_MSG_FLAGS_CONFIRM_BUTTON(flags);
78 
79 
80  xdlg->flags=flags;
81  if (title)
82  xdlg->title=strdup(title);
83  if (text)
84  xdlg->text=strdup(text);
85 
86  if (b1 && *b1) {
87  GWEN_Dialog_SetWidgetText(dlg, "button1", b1);
88  if (confirmButton==1)
90  }
91  else
92  GWEN_Dialog_RemoveWidget(dlg, "button1");
93 
94 
95  if (b2 && *b2) {
96  GWEN_Dialog_SetWidgetText(dlg, "button2", b2);
97  if (confirmButton==2)
99  }
100  else
101  GWEN_Dialog_RemoveWidget(dlg, "button2");
102 
103  if (b3 && *b3) {
104  GWEN_Dialog_SetWidgetText(dlg, "button3", b3);
105  if (confirmButton==3)
107  }
108  else
109  GWEN_Dialog_RemoveWidget(dlg, "button3");
110 
111  return dlg;
112 }
113 
114 
115 
117 {
118  GWEN_DLGMSG *xdlg;
119 
120  xdlg=(GWEN_DLGMSG *) p;
121 
122  free(xdlg->title);
123  free(xdlg->text);
124 
125  GWEN_FREE_OBJECT(xdlg);
126 }
127 
128 
129 
131 {
132  GWEN_DLGMSG *xdlg;
133 
134  assert(dlg);
135  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, GWEN_DLGMSG, dlg);
136  assert(xdlg);
137 
138  return xdlg->response;
139 }
140 
141 
142 
144 {
145  GWEN_DLGMSG *xdlg;
146  GWEN_DB_NODE *dbParams;
147 
148  assert(dlg);
149  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, GWEN_DLGMSG, dlg);
150  assert(xdlg);
151 
152  dbParams=GWEN_Dialog_GetPreferences(dlg);
153  assert(dbParams);
154 
155 #if 0
156  /* read width */
157  i=GWEN_DB_GetIntValue(dbParams, "dialog_width", 0, -1);
158  if (i>=DIALOG_MINWIDTH)
160 
161  /* read height */
162  i=GWEN_DB_GetIntValue(dbParams, "dialog_height", 0, -1);
163  if (i>=DIALOG_MINHEIGHT)
165 #endif
166 
167  /* special stuff */
168  if (xdlg->title)
169  GWEN_Dialog_SetCharProperty(dlg, "", GWEN_DialogProperty_Title, 0, xdlg->title, 0);
170 
171  if (xdlg->text)
172  GWEN_Dialog_SetCharProperty(dlg, "descrLabel", GWEN_DialogProperty_Title, 0, xdlg->text, 0);
173 
174 
175  xdlg->wasInit=1;
176 }
177 
178 
179 
181 {
182  GWEN_DLGMSG *xdlg;
183  GWEN_DB_NODE *dbParams;
184 
185  assert(dlg);
186  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, GWEN_DLGMSG, dlg);
187  assert(xdlg);
188 
189  dbParams=GWEN_Dialog_GetPreferences(dlg);
190  assert(dbParams);
191 
192 #if 0
193  /* store dialog width */
195  if (i<DIALOG_MINWIDTH)
196  i=DIALOG_MINWIDTH;
197  GWEN_DB_SetIntValue(dbParams,
199  "dialog_width",
200  i);
201 
202  /* store dialog height */
204  if (i<DIALOG_MINHEIGHT)
206  GWEN_DB_SetIntValue(dbParams,
208  "dialog_height",
209  i);
210 #endif
211 }
212 
213 
214 
215 
216 int GWEN_DlgMessage_HandleActivated(GWEN_DIALOG *dlg, const char *sender)
217 {
218  GWEN_DLGMSG *xdlg;
219 
220  assert(dlg);
221  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, GWEN_DLGMSG, dlg);
222  assert(xdlg);
223 
224  if (strcasecmp(sender, "button1")==0) {
225  xdlg->response=1;
227  }
228  else if (strcasecmp(sender, "button2")==0) {
229  xdlg->response=2;
231  }
232  else if (strcasecmp(sender, "button3")==0) {
233  xdlg->response=3;
235  }
236 
238 }
239 
240 
241 
242 
245  const char *sender)
246 {
247  GWEN_DLGMSG *xdlg;
248 
249  assert(dlg);
250  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, GWEN_DLGMSG, dlg);
251  assert(xdlg);
252 
253  switch (t) {
257 
261 
263  return GWEN_DlgMessage_HandleActivated(dlg, sender);
264 
268 
271 
274  }
275 
277 
278 }
279 
280 
281 
282 
void GWEN_DlgMessage_Init(GWEN_DIALOG *dlg)
Definition: dlg_message.c:143
char * GWEN_Buffer_GetStart(const GWEN_BUFFER *bf)
Definition: buffer.c:235
#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
#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
void GWEN_Dialog_AddWidgetFlags(GWEN_DIALOG *dlg, const char *name, uint32_t fl)
Definition: dialog.c:758
GWEN_DIALOG_EVENTTYPE
Definition: dialog.h:90
int GWENHYWFAR_CB GWEN_DlgMessage_SignalHandler(GWEN_DIALOG *dlg, GWEN_DIALOG_EVENTTYPE t, const char *sender)
Definition: dlg_message.c:243
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
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
void GWEN_Dialog_SetWidgetText(GWEN_DIALOG *dlg, const char *name, const char *t)
Definition: dialog.c:834
#define GWEN_WIDGET_FLAGS_DEFAULT_WIDGET
Definition: dialog.h:65
#define GWEN_NEW_OBJECT(typ, varname)
Definition: memory.h:86
#define DIALOG_MINWIDTH
Definition: dlg_progress.c:27
#define GWEN_GUI_MSG_FLAGS_CONFIRM_BUTTON(fl)
Definition: gui.h:305
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
void GWENHYWFAR_CB GWEN_DlgMessage_FreeData(void *bp, void *p)
Definition: dlg_message.c:116
void GWEN_DlgMessage_Fini(GWEN_DIALOG *dlg)
Definition: dlg_message.c:180
int GWEN_DlgMessage_GetResponse(const GWEN_DIALOG *dlg)
Definition: dlg_message.c:130
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
GWEN_DIALOG * GWEN_DlgMessage_new(uint32_t flags, const char *title, const char *text, const char *b1, const char *b2, const char *b3)
Definition: dlg_message.c:34
int GWEN_DlgMessage_HandleActivated(GWEN_DIALOG *dlg, const char *sender)
Definition: dlg_message.c:216
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
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
#define GWEN_INHERIT_SETDATA(bt, t, element, data, fn)
Definition: inherit.h:292
#define GWEN_INHERIT_GETDATA(bt, t, element)
Definition: inherit.h:271
#define DIALOG_MINHEIGHT
Definition: dlg_progress.c:28