gwenhywfar  4.99.8beta
gui/gtk3/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 "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 
29 int test1(int argc, char **argv) {
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  setlocale (LC_ALL, "");
43  gtk_init (&argc, &argv);
44 
45  /* create GUI */
46  gui=Gtk3_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  int rv;
67  uint32_t id1;
68  uint32_t id2;
69  uint64_t i1;
70  uint64_t i2;
71  GWEN_GUI *gui;
72 
73  setlocale(LC_ALL, "");
74  gtk_init (&argc, &argv);
75 
76  gui=Gtk3_Gui_new();
77  GWEN_Gui_SetGui(gui);
78 
82  "Progress-Title",
83  "<html>"
84  "<p><b>This</b> is an example <i>text</i>..</p>"
85  "<p>As you can see <font color=red>colors</font> can "
86  "be used.</p>"
87  "</html>",
88  10,
89  0);
90  for (i1=1; i1<=10; i1++) {
91  char numbuf[128];
92 
93  snprintf(numbuf, sizeof(numbuf)-1, "Step %d\n", (int)i1);
98  "2nd progress",
99  "Starting 2nd progress...",
100  10,
101  id1);
102  for (i2=1; i2<=10; i2++) {
103  sleep(1);
104  fprintf(stderr, "Advancing %d/%d\n", (int)i1, (int)i2);
105  rv=GWEN_Gui_ProgressAdvance(id2, i2);
106  if (rv==GWEN_ERROR_USER_ABORTED) {
107  fprintf(stderr, "Aborted by user (2)\n");
108  break;
109  }
110  }
112 
113  rv=GWEN_Gui_ProgressAdvance(id1, i1);
114  if (rv==GWEN_ERROR_USER_ABORTED) {
115  fprintf(stderr, "Aborted by user (1)\n");
116  break;
117  }
118  }
119 
121 
122  return 0;
123 }
124 
125 
126 
127 int test3(int argc, char **argv) {
128  GWEN_GUI *gui;
129  int rv;
130  GWEN_DIALOG *dlg;
131 
132  rv=GWEN_Init();
133  if (rv) {
134  DBG_ERROR_ERR(0, rv);
135  return 2;
136  }
137 
139 
140  setlocale(LC_ALL, "");
141  gtk_init (&argc, &argv);
142 
143  /* create GUI */
144  gui=Gtk3_Gui_new();
145  GWEN_Gui_SetGui(gui);
146 
147  dlg=Dlg_Test2_new();
148  if (dlg==NULL) {
149  fprintf(stderr, "Could not create dialog.\n");
150  return 2;
151  }
152 
153  rv=GWEN_Gui_ExecDialog(dlg, 0);
154  fprintf(stderr, "Result: %d\n", rv);
155 
156  return 0;
157 }
158 
159 
160 
161 
162 
163 int main(int argc, char **argv) {
164  if (argc>1) {
165  if (strcasecmp(argv[1], "1")==0)
166  return test1(argc, argv);
167  else if (strcasecmp(argv[1], "2")==0)
168  return test2(argc, argv);
169  else if (strcasecmp(argv[1], "3")==0)
170  return test3(argc, argv);
171  }
172  return test1(argc, argv);
173 }
174 
175 
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
int test3(int argc, char **argv)
#define GWEN_GUI_PROGRESS_DELAY
Definition: gui.h:192
#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
int test1(int argc, char **argv)
struct GWEN_DIALOG GWEN_DIALOG
Definition: dialog.h:54
int test2(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
struct GWEN_GUI GWEN_GUI
Definition: gui.h:176
GWEN_DIALOG * Dlg_Test1_new()
Definition: dlg_test.c:262
#define GWEN_ERROR_USER_ABORTED
Definition: error.h:65
int main(int argc, char **argv)
void GWEN_Gui_SetGui(GWEN_GUI *gui)
Definition: gui.c:152
GWEN_GUI * Gtk3_Gui_new()
Definition: gtk3_gui.c:38
int GWEN_Init(void)
Definition: gwenhywfar.c:92
#define GWEN_GUI_PROGRESS_SHOW_ABORT
Definition: gui.h:194