gwenhywfar  5.10.1
gtk2/libtest.c
Go to the documentation of this file.
1 /***************************************************************************
2  begin : Sun May 16 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 #include "config.h" /* for OS_WIN32 */
12 
13 #include "gtk2_gui.h"
14 #include "../testdialogs/dlg_test.h"
15 #include "../testdialogs/dlg_test2.h"
16 
17 #include <gwenhywfar/gwenhywfar.h>
18 #include <gwenhywfar/gui.h>
19 #include <gwenhywfar/dialog.h>
20 #include <gwenhywfar/debug.h>
21 
22 #include <unistd.h>
23 
24 
25 
26 
27 
28 int test1(int argc, char **argv)
29 {
30  GWEN_GUI *gui;
31  int rv;
32  GWEN_DIALOG *dlg;
33 
34  rv=GWEN_Init();
35  if (rv) {
36  DBG_ERROR_ERR(0, rv);
37  return 2;
38  }
39 
41 
42  gtk_set_locale();
43  gtk_init(&argc, &argv);
44 
45  /* create GUI */
46  gui=Gtk2_Gui_new();
47  GWEN_Gui_SetGui(gui);
48 
49  dlg=Dlg_Test1_new();
50  if (dlg==NULL) {
51  fprintf(stderr, "Could not create dialog.\n");
52  return 2;
53  }
54 
55  rv=GWEN_Gui_ExecDialog(dlg, 0);
56  fprintf(stderr, "Result: %d\n", rv);
57 
58  return 0;
59 }
60 
61 
62 
63 
64 
65 int test2(int argc, char **argv)
66 {
67  int rv;
68  uint32_t id1;
69  uint32_t id2;
70  uint64_t i1;
71  uint64_t i2;
72  GWEN_GUI *gui;
73 
74  gtk_set_locale();
75  gtk_init(&argc, &argv);
76 
77  gui=Gtk2_Gui_new();
78  GWEN_Gui_SetGui(gui);
79 
83  "Progress-Title",
84  "<html>"
85  "<p><b>This</b> is an example <i>text</i>..</p>"
86  "<p>As you can see <font color=red>colors</font> can "
87  "be used.</p>"
88  "</html>",
89  10,
90  0);
91  for (i1=1; i1<=10; i1++) {
92  char numbuf[128];
93 
94  snprintf(numbuf, sizeof(numbuf)-1, "Step %d\n", (int)i1);
99  "2nd progress",
100  "Starting 2nd progress...",
101  10,
102  id1);
103  for (i2=1; i2<=10; i2++) {
104  sleep(1);
105  fprintf(stderr, "Advancing %d/%d\n", (int)i1, (int)i2);
106  rv=GWEN_Gui_ProgressAdvance(id2, i2);
107  if (rv==GWEN_ERROR_USER_ABORTED) {
108  fprintf(stderr, "Aborted by user (2)\n");
109  break;
110  }
111  }
113 
114  rv=GWEN_Gui_ProgressAdvance(id1, i1);
115  if (rv==GWEN_ERROR_USER_ABORTED) {
116  fprintf(stderr, "Aborted by user (1)\n");
117  break;
118  }
119  }
120 
122 
123  return 0;
124 }
125 
126 
127 
128 int test3(int argc, char **argv)
129 {
130  GWEN_GUI *gui;
131  int rv;
132  GWEN_DIALOG *dlg;
133 
134  rv=GWEN_Init();
135  if (rv) {
136  DBG_ERROR_ERR(0, rv);
137  return 2;
138  }
139 
141 
142  gtk_set_locale();
143  gtk_init(&argc, &argv);
144 
145  /* create GUI */
146  gui=Gtk2_Gui_new();
147  GWEN_Gui_SetGui(gui);
148 
149  dlg=Dlg_Test2_new();
150  if (dlg==NULL) {
151  fprintf(stderr, "Could not create dialog.\n");
152  return 2;
153  }
154 
155  rv=GWEN_Gui_ExecDialog(dlg, 0);
156  fprintf(stderr, "Result: %d\n", rv);
157 
158  return 0;
159 }
160 
161 
162 
163 
164 
165 int main(int argc, char **argv)
166 {
167  if (argc>1) {
168  if (strcasecmp(argv[1], "1")==0)
169  return test1(argc, argv);
170  else if (strcasecmp(argv[1], "2")==0)
171  return test2(argc, argv);
172  else if (strcasecmp(argv[1], "3")==0)
173  return test3(argc, argv);
174  }
175  return test1(argc, argv);
176 }
177 
178 
GWENHYWFAR_API int GWEN_Gui_ProgressLog(uint32_t id, GWEN_LOGGER_LEVEL level, const char *text)
Definition: gui_virtual.c:444
int main(int argc, char **argv)
Definition: gtk2/libtest.c:165
GWENHYWFAR_API int GWEN_Gui_ProgressAdvance(uint32_t id, uint32_t progress)
Definition: gui_virtual.c:420
void GWEN_Logger_SetLevel(const char *logDomain, GWEN_LOGGER_LEVEL l)
Definition: logger.c:627
#define NULL
Definition: binreloc.c:300
GWEN_GUI * Gtk2_Gui_new()
Definition: gtk2_gui.c:38
#define GWEN_GUI_PROGRESS_DELAY
Definition: gui.h:192
int test2(int argc, char **argv)
Definition: gtk2/libtest.c:65
#define DBG_ERROR_ERR(dbg_logger, dbg_err)
Definition: debug.h:113
GWENHYWFAR_API int GWEN_Gui_ExecDialog(GWEN_DIALOG *dlg, uint32_t guiid)
Definition: gui_virtual.c:559
struct GWEN_DIALOG GWEN_DIALOG
Definition: dialog.h:54
int test1(int argc, char **argv)
Definition: gtk2/libtest.c:28
int test3(int argc, char **argv)
Definition: gtk2/libtest.c:128
GWEN_DIALOG * Dlg_Test2_new()
Definition: dlg_test2.c:94
GWENHYWFAR_API uint32_t GWEN_Gui_ProgressStart(uint32_t progressFlags, const char *title, const char *text, uint64_t total, uint32_t guiid)
Definition: gui_virtual.c:404
GWENHYWFAR_API int GWEN_Gui_ProgressEnd(uint32_t id)
Definition: gui_virtual.c:480
#define GWEN_GUI_PROGRESS_KEEP_OPEN
Definition: gui.h:198
#define GWEN_GUI_PROGRESS_SHOW_LOG
Definition: gui.h:193
struct GWEN_GUI GWEN_GUI
Definition: gui.h:176
GWEN_DIALOG * Dlg_Test1_new()
Definition: dlg_test.c:269
#define GWEN_ERROR_USER_ABORTED
Definition: error.h:65
void GWEN_Gui_SetGui(GWEN_GUI *gui)
Definition: gui.c:170
int GWEN_Init(void)
Definition: gwenhywfar.c:92
#define GWEN_GUI_PROGRESS_SHOW_ABORT
Definition: gui.h:194