gwenhywfar  5.3.0
dlgtest/main.c
Go to the documentation of this file.
1 /***************************************************************************
2  $RCSfile$
3  -------------------
4  cvs : $Id$
5  begin : Fri Jun 02 2004
6  copyright : (C) 2004 by Martin Preuss
7  email : martin@libchipcard.de
8 
9  ***************************************************************************
10  * Please see toplevel file COPYING for license details *
11  ***************************************************************************/
12 
13 
14 
15 #ifdef HAVE_CONFIG_H
16 # include <config.h>
17 #endif
18 
19 /* Internationalization */
20 #ifdef ENABLE_NLS
21 # include <libintl.h>
22 # include <locale.h>
23 # define I18N(m) dgettext("gwenhywfar", m)
24 # define I18S(m) m
25 #else
26 # define I18N(m) m
27 # define I18S(m) m
28 #endif
29 
30 
31 #include <stdio.h>
32 
33 #include <gwenhywfar/ui/loader.h>
34 #include <gwenhywfar/logger.h>
35 #include <gwenhywfar/debug.h>
36 
37 
38 
39 int main(int argc, char **argv)
40 {
41  GWEN_XMLNODE *n;
42  GWEN_XMLNODE *nn;
43  GWEN_DB_NODE *dbData;
44  int res;
45 
46  GWEN_Logger_Open(0, "dlgtest", "dlgtest.log",
47  GWEN_LoggerTypeFile,
48  GWEN_LoggerFacilityUser);
49  GWEN_Logger_SetLevel(0, GWEN_LoggerLevelWarning);
50 
51  if (argc<3) {
52  fprintf(stderr, "Usage: %s FILENAME DIALOGNAME.\n", argv[0]);
53  return 1;
54  }
56  if (GWEN_XML_ReadFile(n, argv[1], GWEN_XML_FLAGS_DEFAULT)) {
57  fprintf(stderr, "Error reading XML file.\n");
58  return 2;
59  }
60 
61  nn=GWEN_XMLNode_FindFirstTag(n, "widget", "name", argv[2]);
62  if (!nn) {
63  DBG_ERROR(0, "Dialog \"%s\" not found", argv[2]);
64  return 2;
65  }
66 
67  dbData=GWEN_DB_Group_new("dialogData");
68  if (GWEN_UI_Begin()) {
69  DBG_ERROR(0, "Could not init UI");
70  return 2;
71  }
72 
73  res=GWEN_UILoader_ExecDialog(0, nn, dbData);
74 
75  if (GWEN_UI_End()) {
76  DBG_ERROR(0, "Could not deinit UI");
77  return 2;
78  }
79 
80  if (res==1) {
81  fprintf(stdout, "Dialog data:\n");
82  GWEN_DB_Dump(dbData, stdout, 2);
83  }
84 
85  fprintf(stdout, "Result of dialog was: ");
86  switch (res) {
87  case 1:
88  fprintf(stdout, "Accepted.\n");
89  break;
90  case 2:
91  fprintf(stdout, "Aborted.\n");
92  break;
93  case -1:
94  fprintf(stdout, "Error.\n");
95  break;
96  default:
97  fprintf(stdout, "Unknown.\n");
98  break;
99  }
100 
101  return 0;
102 }
103 
104 
105 
106 
107 
108 
void GWEN_DB_Dump(GWEN_DB_NODE *n, int insert)
Definition: db.c:1418
struct GWEN_DB_NODE GWEN_DB_NODE
Definition: db.h:228
#define GWEN_XML_FLAGS_DEFAULT
Definition: xml.h:110
void GWEN_Logger_SetLevel(const char *logDomain, GWEN_LOGGER_LEVEL l)
Definition: logger.c:627
GWENHYWFAR_API int GWEN_XML_ReadFile(GWEN_XMLNODE *n, const char *filepath, uint32_t flags)
Definition: xmlrw.c:1297
GWEN_XMLNODE * GWEN_XMLNode_new(GWEN_XMLNODE_TYPE t, const char *data)
Definition: xml.c:144
GWEN_XMLNODE * GWEN_XMLNode_FindFirstTag(const GWEN_XMLNODE *n, const char *tname, const char *pname, const char *pvalue)
Definition: xml.c:736
int GWEN_Logger_Open(const char *logDomain, const char *ident, const char *file, GWEN_LOGGER_LOGTYPE logtype, GWEN_LOGGER_FACILITY facility)
Definition: logger.c:225
#define DBG_ERROR(dbg_logger, format, args...)
Definition: debug.h:97
GWEN_DB_NODE * GWEN_DB_Group_new(const char *name)
Definition: db.c:171
int main(int argc, char **argv)
Definition: dlgtest/main.c:39
struct GWEN__XMLNODE GWEN_XMLNODE
Definition: xml.h:149