gwenhywfar  4.99.8beta
gui/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  GWEN_GUI *gui;
30  int rv;
31  GWEN_DIALOG *dlg;
32 
33  rv=GWEN_Init();
34  if (rv) {
35  DBG_ERROR_ERR(0, rv);
36  return 2;
37  }
38 
40 
41  gtk_set_locale ();
42  gtk_init (&argc, &argv);
43 
44  /* create GUI */
45  gui=Gtk2_Gui_new();
46  GWEN_Gui_SetGui(gui);
47 
48  dlg=Dlg_Test1_new();
49  if (dlg==NULL) {
50  fprintf(stderr, "Could not create dialog.\n");
51  return 2;
52  }
53 
54  rv=GWEN_Gui_ExecDialog(dlg, 0);
55  fprintf(stderr, "Result: %d\n", rv);
56 
57  return 0;
58 }
59 
60 
61 
62 
63 
64 int test2(int argc, char **argv) {
65  int rv;
66  uint32_t id1;
67  uint32_t id2;
68  uint64_t i1;
69  uint64_t i2;
70  GWEN_GUI *gui;
71 
72  gtk_set_locale ();
73  gtk_init (&argc, &argv);
74 
75  gui=Gtk2_Gui_new();
76  GWEN_Gui_SetGui(gui);
77 
81  "Progress-Title",
82  "<html>"
83  "<p><b>This</b> is an example <i>text</i>..</p>"
84  "<p>As you can see <font color=red>colors</font> can "
85  "be used.</p>"
86  "</html>",
87  10,
88  0);
89  for (i1=1; i1<=10; i1++) {
90  char numbuf[128];
91 
92  snprintf(numbuf, sizeof(numbuf)-1, "Step %d\n", (int)i1);
97  "2nd progress",
98  "Starting 2nd progress...",
99  10,
100  id1);
101  for (i2=1; i2<=10; i2++) {
102  sleep(1);
103  fprintf(stderr, "Advancing %d/%d\n", (int)i1, (int)i2);
104  rv=GWEN_Gui_ProgressAdvance(id2, i2);
105  if (rv==GWEN_ERROR_USER_ABORTED) {
106  fprintf(stderr, "Aborted by user (2)\n");
107  break;
108  }
109  }
111 
112  rv=GWEN_Gui_ProgressAdvance(id1, i1);
113  if (rv==GWEN_ERROR_USER_ABORTED) {
114  fprintf(stderr, "Aborted by user (1)\n");
115  break;
116  }
117  }
118 
120 
121  return 0;
122 }
123 
124 
125 
126 int test3(int argc, char **argv) {
127  GWEN_GUI *gui;
128  int rv;
129  GWEN_DIALOG *dlg;
130 
131  rv=GWEN_Init();
132  if (rv) {
133  DBG_ERROR_ERR(0, rv);
134  return 2;
135  }
136 
138 
139  gtk_set_locale ();
140  gtk_init (&argc, &argv);
141 
142  /* create GUI */
143  gui=Gtk2_Gui_new();
144  GWEN_Gui_SetGui(gui);
145 
146  dlg=Dlg_Test2_new();
147  if (dlg==NULL) {
148  fprintf(stderr, "Could not create dialog.\n");
149  return 2;
150  }
151 
152  rv=GWEN_Gui_ExecDialog(dlg, 0);
153  fprintf(stderr, "Result: %d\n", rv);
154 
155  return 0;
156 }
157 
158 
159 
160 
161 
162 int main(int argc, char **argv) {
163  if (argc>1) {
164  if (strcasecmp(argv[1], "1")==0)
165  return test1(argc, argv);
166  else if (strcasecmp(argv[1], "2")==0)
167  return test2(argc, argv);
168  else if (strcasecmp(argv[1], "3")==0)
169  return test3(argc, argv);
170  }
171  return test1(argc, argv);
172 }
173 
174 
int GWEN_Gui_ProgressLog(uint32_t id, GWEN_LOGGER_LEVEL level, const char *text)
Definition: gui.c:940
int GWEN_Gui_ProgressAdvance(uint32_t id, uint32_t progress)
Definition: gui.c:920
void GWEN_Logger_SetLevel(const char *logDomain, GWEN_LOGGER_LEVEL l)
Definition: logger.c:604
#define NULL
Definition: binreloc.c:290
GWEN_GUI * Gtk2_Gui_new()
Definition: gtk2_gui.c:38
#define GWEN_GUI_PROGRESS_DELAY
Definition: gui.h:192
int test1(int argc, char **argv)
#define DBG_ERROR_ERR(dbg_logger, dbg_err)
Definition: debug.h:108
int GWEN_Gui_ExecDialog(GWEN_DIALOG *dlg, uint32_t guiid)
Definition: gui.c:1415
struct GWEN_DIALOG GWEN_DIALOG
Definition: dialog.h:54
int main(int argc, char **argv)
GWEN_DIALOG * Dlg_Test2_new()
Definition: dlg_test2.c:89
uint32_t GWEN_Gui_ProgressStart(uint32_t progressFlags, const char *title, const char *text, uint64_t total, uint32_t guiid)
Definition: gui.c:903
int GWEN_Gui_ProgressEnd(uint32_t id)
Definition: gui.c:971
#define GWEN_GUI_PROGRESS_KEEP_OPEN
Definition: gui.h:198
#define GWEN_GUI_PROGRESS_SHOW_LOG
Definition: gui.h:193
int test2(int argc, char **argv)
struct GWEN_GUI GWEN_GUI
Definition: gui.h:176
int test3(int argc, char **argv)
GWEN_DIALOG * Dlg_Test1_new()
Definition: dlg_test.c:262
#define GWEN_ERROR_USER_ABORTED
Definition: error.h:65
void GWEN_Gui_SetGui(GWEN_GUI *gui)
Definition: gui.c:152
int GWEN_Init(void)
Definition: gwenhywfar.c:92
#define GWEN_GUI_PROGRESS_SHOW_ABORT
Definition: gui.h:194