gwenhywfar  4.99.8beta
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  GWEN_XMLNODE *n;
41  GWEN_XMLNODE *nn;
42  GWEN_DB_NODE *dbData;
43  int res;
44 
45  GWEN_Logger_Open(0, "dlgtest", "dlgtest.log",
46  GWEN_LoggerTypeFile,
47  GWEN_LoggerFacilityUser);
48  GWEN_Logger_SetLevel(0, GWEN_LoggerLevelWarning);
49 
50  if (argc<3) {
51  fprintf(stderr, "Usage: %s FILENAME DIALOGNAME.\n", argv[0]);
52  return 1;
53  }
55  if (GWEN_XML_ReadFile(n, argv[1], GWEN_XML_FLAGS_DEFAULT)) {
56  fprintf(stderr, "Error reading XML file.\n");
57  return 2;
58  }
59 
60  nn=GWEN_XMLNode_FindFirstTag(n, "widget", "name", argv[2]);
61  if (!nn) {
62  DBG_ERROR(0, "Dialog \"%s\" not found", argv[2]);
63  return 2;
64  }
65 
66  dbData=GWEN_DB_Group_new("dialogData");
67  if (GWEN_UI_Begin()) {
68  DBG_ERROR(0, "Could not init UI");
69  return 2;
70  }
71 
72  res=GWEN_UILoader_ExecDialog(0, nn, dbData);
73 
74  if (GWEN_UI_End()) {
75  DBG_ERROR(0, "Could not deinit UI");
76  return 2;
77  }
78 
79  if (res==1) {
80  fprintf(stdout, "Dialog data:\n");
81  GWEN_DB_Dump(dbData, stdout, 2);
82  }
83 
84  fprintf(stdout, "Result of dialog was: ");
85  switch(res) {
86  case 1: fprintf(stdout, "Accepted.\n"); break;
87  case 2: fprintf(stdout, "Aborted.\n"); break;
88  case -1: fprintf(stdout, "Error.\n"); break;
89  default: fprintf(stdout, "Unknown.\n"); break;
90  }
91 
92  return 0;
93 }
94 
95 
96 
97 
98 
99 
void GWEN_DB_Dump(GWEN_DB_NODE *n, int insert)
Definition: db.c:1297
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:604
GWENHYWFAR_API int GWEN_XML_ReadFile(GWEN_XMLNODE *n, const char *filepath, uint32_t flags)
Definition: xmlrw.c:973
GWEN_XMLNODE * GWEN_XMLNode_new(GWEN_XMLNODE_TYPE t, const char *data)
Definition: xml.c:137
GWEN_XMLNODE * GWEN_XMLNode_FindFirstTag(const GWEN_XMLNODE *n, const char *tname, const char *pname, const char *pvalue)
Definition: xml.c:695
int GWEN_Logger_Open(const char *logDomain, const char *ident, const char *file, GWEN_LOGGER_LOGTYPE logtype, GWEN_LOGGER_FACILITY facility)
Definition: logger.c:212
#define DBG_ERROR(dbg_logger, format, args...)
Definition: debug.h:97
GWEN_DB_NODE * GWEN_DB_Group_new(const char *name)
Definition: db.c:131
int main(int argc, char **argv)
Definition: dlgtest/main.c:39
struct GWEN__XMLNODE GWEN_XMLNODE
Definition: xml.h:148