gwenhywfar  4.3.3
qt4/libtest.cpp
Go to the documentation of this file.
00001 
00002 #undef BUILDING_QT4_GUI
00003 
00004 #include "qt4_gui.hpp"
00005 #include "../testdialogs/dlg_test.h"
00006 
00007 #include <gwenhywfar/gwenhywfar.h>
00008 #include <gwenhywfar/gui.h>
00009 #include <gwenhywfar/dialog.h>
00010 #include <gwenhywfar/debug.h>
00011 
00012 #include <qapplication.h>
00013 
00014 #include <unistd.h>
00015 
00016 
00017 
00018 int test1(int argc, char **argv) {
00019   QApplication a(argc, argv);
00020   QT4_Gui *gui;
00021   int rv;
00022   GWEN_DIALOG *dlg;
00023 
00024   rv=GWEN_Init();
00025   if (rv) {
00026     DBG_ERROR_ERR(0, rv);
00027     return 2;
00028   }
00029 
00030   GWEN_Logger_SetLevel(0, GWEN_LoggerLevel_Info);
00031 
00032   /* create GUI */
00033   gui=new QT4_Gui();
00034   GWEN_Gui_SetGui(gui->getCInterface());
00035 
00036   dlg=Dlg_Test1_new();
00037   if (dlg==NULL) {
00038     fprintf(stderr, "Could not create dialog.\n");
00039     return 2;
00040   }
00041 
00042   rv=GWEN_Gui_ExecDialog(dlg, 0);
00043   fprintf(stderr, "Result: %d\n", rv);
00044 
00045   return 0;
00046 }
00047 
00048 
00049 
00050 int test2(int argc, char **argv) {
00051   QApplication a(argc, argv);
00052   QT4_Gui *gui;
00053   QString lf;
00054   int rv;
00055   uint32_t pid;
00056 
00057   rv=GWEN_Init();
00058   if (rv) {
00059     DBG_ERROR_ERR(0, rv);
00060     return 2;
00061   }
00062 
00063   GWEN_Logger_SetLevel(0, GWEN_LoggerLevel_Info);
00064 
00065   /* create GUI */
00066   gui=new QT4_Gui();
00067   GWEN_Gui_SetGui(gui->getCInterface());
00068 
00069 
00070 #if 0
00071   pid=GWEN_Gui_ProgressStart(GWEN_GUI_PROGRESS_SHOW_PROGRESS | GWEN_GUI_PROGRESS_KEEP_OPEN,
00072                              "Progress-Title",
00073                              "This is an example progress with 2 steps"
00074                              "<html>This is an <strong>example</strong> progress with 2 steps</html>",
00075                              2,
00076                              0);
00077 #else
00078   pid=GWEN_Gui_ProgressStart(GWEN_GUI_PROGRESS_SHOW_PROGRESS | GWEN_GUI_PROGRESS_KEEP_OPEN,
00079                              "Progress-Title",
00080                              "This is an <b>example</b> progress with 2 steps",
00081                              2,
00082                              0);
00083 #endif
00084 
00085   GWEN_Gui_ProgressAdvance(pid, 1);
00086   rv=GWEN_Gui_MessageBox(GWEN_GUI_MSG_FLAGS_TYPE_INFO,
00087                          "MessageBox-Title",
00088                          "This message box should appear in the context of the open progress dialog",
00089                          "Button1",
00090                          "Button2",
00091                          "Button3",
00092                          pid);
00093   GWEN_Gui_ProgressAdvance(pid, 2);
00094   GWEN_Gui_ProgressEnd(pid);
00095 
00096   return 0;
00097 }
00098 
00099 
00100 
00101 int test3(int argc, char **argv) {
00102   int rv;
00103   uint32_t id1;
00104   uint32_t id2;
00105   uint64_t i1;
00106   uint64_t i2;
00107   QApplication a(argc, argv);
00108   QT4_Gui *gui;
00109 
00110   gui=new QT4_Gui();
00111   GWEN_Gui_SetGui(gui->getCInterface());
00112 
00113   id1=GWEN_Gui_ProgressStart(GWEN_GUI_PROGRESS_SHOW_LOG |
00114                              GWEN_GUI_PROGRESS_SHOW_ABORT |
00115                              GWEN_GUI_PROGRESS_KEEP_OPEN,
00116                              "Progress-Title",
00117                              "<html>"
00118                              "<p><b>This</b> is an example <i>text</i>..</p>"
00119                              "<p>As you can see <font color=red>colors</font> can "
00120                              "be used.</p>"
00121                              "</html>",
00122                              10,
00123                              0);
00124   for (i1=1; i1<=10; i1++) {
00125     char numbuf[128];
00126 
00127     snprintf(numbuf, sizeof(numbuf)-1, "Step %d\n", (int)i1);
00128     GWEN_Gui_ProgressLog(id1, GWEN_LoggerLevel_Notice, numbuf);
00129     id2=GWEN_Gui_ProgressStart(GWEN_GUI_PROGRESS_SHOW_LOG |
00130                                GWEN_GUI_PROGRESS_DELAY |
00131                                GWEN_GUI_PROGRESS_SHOW_ABORT,
00132                                "2nd progress",
00133                                "Starting 2nd progress...",
00134                                10,
00135                                id1);
00136     for (i2=1; i2<=10; i2++) {
00137       sleep(1);
00138       fprintf(stderr, "Advancing %d/%d\n", (int)i1, (int)i2);
00139       rv=GWEN_Gui_ProgressAdvance(id2, i2);
00140       if (rv==GWEN_ERROR_USER_ABORTED) {
00141         fprintf(stderr, "Aborted by user (2)\n");
00142         break;
00143       }
00144     }
00145     GWEN_Gui_ProgressEnd(id2);
00146 
00147     rv=GWEN_Gui_ProgressAdvance(id1, i1);
00148     if (rv==GWEN_ERROR_USER_ABORTED) {
00149       fprintf(stderr, "Aborted by user (1)\n");
00150       break;
00151     }
00152   }
00153 
00154   GWEN_Gui_ProgressEnd(id1);
00155 
00156   return 0;
00157 }
00158 
00159 
00160 
00161 int main(int argc, char **argv) {
00162   return test1(argc, argv);
00163   //return test2(argc, argv);
00164   //return test3(argc, argv);
00165 }
00166