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