gwenhywfar  4.6.0beta
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 
23 #ifdef OS_WIN32
24 # include <windows.h>
25 # define sleep(x) Sleep(x)
26 #endif
27 
28 #include <unistd.h>
29 
30 
31 
32 
33 
34 int test1(int argc, char **argv) {
35  GWEN_GUI *gui;
36  int rv;
37  GWEN_DIALOG *dlg;
38 
39  rv=GWEN_Init();
40  if (rv) {
41  DBG_ERROR_ERR(0, rv);
42  return 2;
43  }
44 
46 
47  gtk_set_locale ();
48  gtk_init (&argc, &argv);
49 
50  /* create GUI */
51  gui=Gtk2_Gui_new();
52  GWEN_Gui_SetGui(gui);
53 
54  dlg=Dlg_Test1_new();
55  if (dlg==NULL) {
56  fprintf(stderr, "Could not create dialog.\n");
57  return 2;
58  }
59 
60  rv=GWEN_Gui_ExecDialog(dlg, 0);
61  fprintf(stderr, "Result: %d\n", rv);
62 
63  return 0;
64 }
65 
66 
67 
68 
69 
70 int test2(int argc, char **argv) {
71  int rv;
72  uint32_t id1;
73  uint32_t id2;
74  uint64_t i1;
75  uint64_t i2;
76  GWEN_GUI *gui;
77 
78  gtk_set_locale ();
79  gtk_init (&argc, &argv);
80 
81  gui=Gtk2_Gui_new();
82  GWEN_Gui_SetGui(gui);
83 
87  "Progress-Title",
88  "<html>"
89  "<p><b>This</b> is an example <i>text</i>..</p>"
90  "<p>As you can see <font color=red>colors</font> can "
91  "be used.</p>"
92  "</html>",
93  10,
94  0);
95  for (i1=1; i1<=10; i1++) {
96  char numbuf[128];
97 
98  snprintf(numbuf, sizeof(numbuf)-1, "Step %d\n", (int)i1);
103  "2nd progress",
104  "Starting 2nd progress...",
105  10,
106  id1);
107  for (i2=1; i2<=10; i2++) {
108  sleep(1);
109  fprintf(stderr, "Advancing %d/%d\n", (int)i1, (int)i2);
110  rv=GWEN_Gui_ProgressAdvance(id2, i2);
111  if (rv==GWEN_ERROR_USER_ABORTED) {
112  fprintf(stderr, "Aborted by user (2)\n");
113  break;
114  }
115  }
117 
118  rv=GWEN_Gui_ProgressAdvance(id1, i1);
119  if (rv==GWEN_ERROR_USER_ABORTED) {
120  fprintf(stderr, "Aborted by user (1)\n");
121  break;
122  }
123  }
124 
126 
127  return 0;
128 }
129 
130 
131 
132 int test3(int argc, char **argv) {
133  GWEN_GUI *gui;
134  int rv;
135  GWEN_DIALOG *dlg;
136 
137  rv=GWEN_Init();
138  if (rv) {
139  DBG_ERROR_ERR(0, rv);
140  return 2;
141  }
142 
144 
145  gtk_set_locale ();
146  gtk_init (&argc, &argv);
147 
148  /* create GUI */
149  gui=Gtk2_Gui_new();
150  GWEN_Gui_SetGui(gui);
151 
152  dlg=Dlg_Test2_new();
153  if (dlg==NULL) {
154  fprintf(stderr, "Could not create dialog.\n");
155  return 2;
156  }
157 
158  rv=GWEN_Gui_ExecDialog(dlg, 0);
159  fprintf(stderr, "Result: %d\n", rv);
160 
161  return 0;
162 }
163 
164 
165 
166 
167 
168 int main(int argc, char **argv) {
169  if (argc>1) {
170  if (strcasecmp(argv[1], "1")==0)
171  return test1(argc, argv);
172  else if (strcasecmp(argv[1], "2")==0)
173  return test2(argc, argv);
174  else if (strcasecmp(argv[1], "3")==0)
175  return test3(argc, argv);
176  }
177  return test1(argc, argv);
178 }
179 
180