gwenhywfar
4.3.1
|
00001 /*************************************************************************** 00002 begin : Sun May 16 2010 00003 copyright : (C) 2010 by Martin Preuss 00004 email : martin@libchipcard.de 00005 00006 *************************************************************************** 00007 * Please see toplevel file COPYING for license details * 00008 ***************************************************************************/ 00009 00010 00011 #include "config.h" /* for OS_WIN32 */ 00012 00013 #include "gtk2_gui.h" 00014 #include "../testdialogs/dlg_test.h" 00015 #include "../testdialogs/dlg_test2.h" 00016 00017 #include <gwenhywfar/gwenhywfar.h> 00018 #include <gwenhywfar/gui.h> 00019 #include <gwenhywfar/dialog.h> 00020 #include <gwenhywfar/debug.h> 00021 00022 00023 #ifdef OS_WIN32 00024 # include <windows.h> 00025 # define sleep(x) Sleep(x) 00026 #endif 00027 00028 #include <unistd.h> 00029 00030 00031 00032 00033 00034 int test1(int argc, char **argv) { 00035 GWEN_GUI *gui; 00036 int rv; 00037 GWEN_DIALOG *dlg; 00038 00039 rv=GWEN_Init(); 00040 if (rv) { 00041 DBG_ERROR_ERR(0, rv); 00042 return 2; 00043 } 00044 00045 GWEN_Logger_SetLevel(0, GWEN_LoggerLevel_Info); 00046 00047 gtk_set_locale (); 00048 gtk_init (&argc, &argv); 00049 00050 /* create GUI */ 00051 gui=Gtk2_Gui_new(); 00052 GWEN_Gui_SetGui(gui); 00053 00054 dlg=Dlg_Test1_new(); 00055 if (dlg==NULL) { 00056 fprintf(stderr, "Could not create dialog.\n"); 00057 return 2; 00058 } 00059 00060 rv=GWEN_Gui_ExecDialog(dlg, 0); 00061 fprintf(stderr, "Result: %d\n", rv); 00062 00063 return 0; 00064 } 00065 00066 00067 00068 00069 00070 int test2(int argc, char **argv) { 00071 int rv; 00072 uint32_t id1; 00073 uint32_t id2; 00074 uint64_t i1; 00075 uint64_t i2; 00076 GWEN_GUI *gui; 00077 00078 gtk_set_locale (); 00079 gtk_init (&argc, &argv); 00080 00081 gui=Gtk2_Gui_new(); 00082 GWEN_Gui_SetGui(gui); 00083 00084 id1=GWEN_Gui_ProgressStart(GWEN_GUI_PROGRESS_SHOW_LOG | 00085 GWEN_GUI_PROGRESS_SHOW_ABORT | 00086 GWEN_GUI_PROGRESS_KEEP_OPEN, 00087 "Progress-Title", 00088 "<html>" 00089 "<p><b>This</b> is an example <i>text</i>..</p>" 00090 "<p>As you can see <font color=red>colors</font> can " 00091 "be used.</p>" 00092 "</html>", 00093 10, 00094 0); 00095 for (i1=1; i1<=10; i1++) { 00096 char numbuf[128]; 00097 00098 snprintf(numbuf, sizeof(numbuf)-1, "Step %d\n", (int)i1); 00099 GWEN_Gui_ProgressLog(id1, GWEN_LoggerLevel_Notice, numbuf); 00100 id2=GWEN_Gui_ProgressStart(GWEN_GUI_PROGRESS_SHOW_LOG | 00101 GWEN_GUI_PROGRESS_DELAY | 00102 GWEN_GUI_PROGRESS_SHOW_ABORT, 00103 "2nd progress", 00104 "Starting 2nd progress...", 00105 10, 00106 id1); 00107 for (i2=1; i2<=10; i2++) { 00108 sleep(1); 00109 fprintf(stderr, "Advancing %d/%d\n", (int)i1, (int)i2); 00110 rv=GWEN_Gui_ProgressAdvance(id2, i2); 00111 if (rv==GWEN_ERROR_USER_ABORTED) { 00112 fprintf(stderr, "Aborted by user (2)\n"); 00113 break; 00114 } 00115 } 00116 GWEN_Gui_ProgressEnd(id2); 00117 00118 rv=GWEN_Gui_ProgressAdvance(id1, i1); 00119 if (rv==GWEN_ERROR_USER_ABORTED) { 00120 fprintf(stderr, "Aborted by user (1)\n"); 00121 break; 00122 } 00123 } 00124 00125 GWEN_Gui_ProgressEnd(id1); 00126 00127 return 0; 00128 } 00129 00130 00131 00132 int test3(int argc, char **argv) { 00133 GWEN_GUI *gui; 00134 int rv; 00135 GWEN_DIALOG *dlg; 00136 00137 rv=GWEN_Init(); 00138 if (rv) { 00139 DBG_ERROR_ERR(0, rv); 00140 return 2; 00141 } 00142 00143 GWEN_Logger_SetLevel(0, GWEN_LoggerLevel_Info); 00144 00145 gtk_set_locale (); 00146 gtk_init (&argc, &argv); 00147 00148 /* create GUI */ 00149 gui=Gtk2_Gui_new(); 00150 GWEN_Gui_SetGui(gui); 00151 00152 dlg=Dlg_Test2_new(); 00153 if (dlg==NULL) { 00154 fprintf(stderr, "Could not create dialog.\n"); 00155 return 2; 00156 } 00157 00158 rv=GWEN_Gui_ExecDialog(dlg, 0); 00159 fprintf(stderr, "Result: %d\n", rv); 00160 00161 return 0; 00162 } 00163 00164 00165 00166 00167 00168 int main(int argc, char **argv) { 00169 if (argc>1) { 00170 if (strcasecmp(argv[1], "1")==0) 00171 return test1(argc, argv); 00172 else if (strcasecmp(argv[1], "2")==0) 00173 return test2(argc, argv); 00174 else if (strcasecmp(argv[1], "3")==0) 00175 return test3(argc, argv); 00176 } 00177 return test1(argc, argv); 00178 } 00179 00180