gwenhywfar  4.99.8beta
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 
void GWEN_DlgMessage_Init(GWEN_DIALOG *dlg)
Definition: dlg_message.c:140
char * GWEN_Buffer_GetStart(const GWEN_BUFFER *bf)
Definition: buffer.c:223
#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:290
int GWEN_Dialog_RemoveWidget(GWEN_DIALOG *dlg, const char *name)
Definition: dialog.c:685
void GWEN_Dialog_AddWidgetFlags(GWEN_DIALOG *dlg, const char *name, uint32_t fl)
Definition: dialog.c:723
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:237
GWEN_DIALOG_SIGNALHANDLER GWEN_Dialog_SetSignalHandler(GWEN_DIALOG *dlg, GWEN_DIALOG_SIGNALHANDLER fn)
Definition: dialog.c:243
#define GWEN_LOGDOMAIN
Definition: logger.h:35
GWEN_DB_NODE * GWEN_Dialog_GetPreferences(const GWEN_DIALOG *dlg)
Definition: dialog.c:853
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:793
#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:600
#define GWENHYWFAR_CB
Definition: gwenhywfarapi.h:89
void GWENHYWFAR_CB GWEN_DlgMessage_FreeData(void *bp, void *p)
Definition: dlg_message.c:115
void GWEN_DlgMessage_Fini(GWEN_DIALOG *dlg)
Definition: dlg_message.c:176
int GWEN_DlgMessage_GetResponse(const GWEN_DIALOG *dlg)
Definition: dlg_message.c:128
void GWEN_Buffer_free(GWEN_BUFFER *bf)
Definition: buffer.c:83
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:211
int GWEN_Dialog_SetIntProperty(GWEN_DIALOG *dlg, const char *name, GWEN_DIALOG_PROPERTY prop, int index, int value, int doSignal)
Definition: dialog.c:571
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:628
#define DBG_INFO(dbg_logger, format, args...)
Definition: debug.h:164
#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:1048
void GWEN_Dialog_free(GWEN_DIALOG *dlg)
Definition: dialog.c:88
#define GWEN_INHERIT(bt, t)
Definition: inherit.h:264
int GWEN_Dialog_ReadXmlFile(GWEN_DIALOG *dlg, const char *fname)
Definition: dialog.c:407
int GWEN_DB_SetIntValue(GWEN_DB_NODE *n, uint32_t flags, const char *path, int val)
Definition: db.c:1086
int GWEN_PathManager_FindFile(const char *destLib, const char *pathName, const char *fileName, GWEN_BUFFER *fbuf)
Definition: pathmanager.c:529
#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