gwenhywfar
4.3.1
|
00001 /*************************************************************************** 00002 begin : Mon Mar 01 2004 00003 copyright : (C) 2004-2010 by Martin Preuss 00004 email : martin@libchipcard.de 00005 00006 *************************************************************************** 00007 * Please see toplevel file COPYING for license details * 00008 ***************************************************************************/ 00009 00010 00011 #ifdef HAVE_CONFIG_H 00012 # include <config.h> 00013 #endif 00014 00015 #include "qt4_gui.hpp" 00016 #include "qt4_gui_dialog.hpp" 00017 00018 #include <gwenhywfar/debug.h> 00019 00020 #include <QMessageBox> 00021 #include <QApplication> 00022 #include <QFileDialog> 00023 00024 #include <assert.h> 00025 00026 00027 00028 00029 QT4_Gui::QT4_Gui() 00030 :CppGui() 00031 ,_parentWidget(NULL) 00032 { 00033 00034 GWEN_Gui_AddFlags(_gui, GWEN_GUI_FLAGS_DIALOGSUPPORTED); 00035 GWEN_Gui_UseDialogs(_gui); 00036 GWEN_Gui_SetName(_gui, "qt4-gui"); 00037 } 00038 00039 00040 00041 QT4_Gui::~QT4_Gui() { 00042 } 00043 00044 00045 00046 void QT4_Gui::pushParentWidget(QWidget *w) { 00047 if (_parentWidget) 00048 _pushedParents.push_back(_parentWidget); 00049 _parentWidget=w; 00050 } 00051 00052 00053 00054 void QT4_Gui::popParentWidget() { 00055 if (!_pushedParents.empty()) { 00056 _parentWidget=_pushedParents.back(); 00057 _pushedParents.pop_back(); 00058 } 00059 else 00060 _parentWidget=NULL; 00061 } 00062 00063 00064 00065 QString QT4_Gui::extractHtml(const char *text) { 00066 const char *p=0; 00067 const char *p2=0; 00068 00069 if (text==NULL) 00070 return QString(""); 00071 00072 /* find begin of HTML area */ 00073 p=text; 00074 while ((p=strchr(p, '<'))) { 00075 const char *t; 00076 00077 t=p; 00078 t++; 00079 if (toupper(*t)=='H') { 00080 t++; 00081 if (toupper(*t)=='T') { 00082 t++; 00083 if (toupper(*t)=='M') { 00084 t++; 00085 if (toupper(*t)=='L') { 00086 t++; 00087 if (toupper(*t)=='>') { 00088 break; 00089 } 00090 } 00091 } 00092 } 00093 } 00094 p++; 00095 } /* while */ 00096 00097 /* find end of HTML area */ 00098 if (p) { 00099 p+=6; /* skip "<html>" */ 00100 p2=p; 00101 while ((p2=strchr(p2, '<'))) { 00102 const char *t; 00103 00104 t=p2; 00105 t++; 00106 if (toupper(*t)=='/') { 00107 t++; 00108 if (toupper(*t)=='H') { 00109 t++; 00110 if (toupper(*t)=='T') { 00111 t++; 00112 if (toupper(*t)=='M') { 00113 t++; 00114 if (toupper(*t)=='L') { 00115 t++; 00116 if (toupper(*t)=='>') { 00117 break; 00118 } 00119 } 00120 } 00121 } 00122 } 00123 } 00124 p2++; 00125 } /* while */ 00126 } 00127 00128 if (p && p2) 00129 return QString("<qt>")+QString::fromUtf8(p, p2-p)+QString("</qt>"); 00130 00131 return QString::fromUtf8(text); 00132 } 00133 00134 00135 00136 int QT4_Gui::execDialog(GWEN_DIALOG *dlg, uint32_t guiid) { 00137 QT4_GuiDialog qt4Dlg(this, dlg); 00138 QWidget *owner=qApp->activeWindow(); 00139 00140 /* setup widget tree for the dialog */ 00141 if (!(qt4Dlg.setup(owner))) { 00142 return GWEN_ERROR_GENERIC; 00143 } 00144 00145 return qt4Dlg.execute(); 00146 } 00147 00148 00149 00150 int QT4_Gui::openDialog(GWEN_DIALOG *dlg, uint32_t guiid) { 00151 QT4_GuiDialog *qt4Dlg; 00152 QWidget *owner=qApp->activeWindow(); 00153 00154 qt4Dlg=new QT4_GuiDialog(this, dlg); 00155 00156 /* setup widget tree for the dialog */ 00157 if (!(qt4Dlg->setup(owner))) { 00158 delete qt4Dlg; 00159 return GWEN_ERROR_GENERIC; 00160 } 00161 00162 return qt4Dlg->openDialog(); 00163 } 00164 00165 00166 00167 int QT4_Gui::closeDialog(GWEN_DIALOG *dlg) { 00168 QT4_GuiDialog *qt4Dlg; 00169 int rv; 00170 00171 qt4Dlg=QT4_GuiDialog::getDialog(dlg); 00172 assert(qt4Dlg); 00173 00174 rv=qt4Dlg->closeDialog(); 00175 delete qt4Dlg; 00176 return rv; 00177 } 00178 00179 00180 00181 int QT4_Gui::runDialog(GWEN_DIALOG *dlg, int untilEnd) { 00182 QT4_GuiDialog *qt4Dlg; 00183 00184 qt4Dlg=QT4_GuiDialog::getDialog(dlg); 00185 assert(qt4Dlg); 00186 00187 return qt4Dlg->runDialog((untilEnd==0)?false:true); 00188 } 00189 00190 00191 00192 int QT4_Gui::getFileName(const char *caption, 00193 GWEN_GUI_FILENAME_TYPE fnt, 00194 uint32_t flags, 00195 const char *patterns, 00196 GWEN_BUFFER *pathBuffer, 00197 uint32_t guiid) { 00198 QString sCaption; 00199 QString sPatterns; 00200 QString sPath; 00201 QString str; 00202 QWidget *owner=qApp->activeWindow(); 00203 00204 if (caption) 00205 sCaption=QString::fromUtf8(caption); 00206 00207 if (patterns) { 00208 const char *s1; 00209 const char *s2; 00210 00211 s1=patterns; 00212 while(s1 && *s1) { 00213 s2=strchr(s1, '\t'); 00214 if (s2) { 00215 str=QString::fromUtf8(s1, s2-s1); 00216 str.replace(',', ' '); 00217 str.replace(';', ' '); 00218 /* skip tab */ 00219 s2++; 00220 } 00221 else { 00222 str=QString::fromUtf8(s1); 00223 str.replace(',', ' '); 00224 str.replace(';', ' '); 00225 s2=NULL; 00226 } 00227 00228 if (!str.isEmpty()) 00229 sPatterns+=";;"; 00230 sPatterns+=str; 00231 00232 s1=s2; 00233 } 00234 } 00235 00236 if (GWEN_Buffer_GetUsedBytes(pathBuffer)) 00237 sPath=QString::fromUtf8(GWEN_Buffer_GetStart(pathBuffer)); 00238 00239 switch(fnt) { 00240 case GWEN_Gui_FileNameType_OpenFileName: 00241 str=QFileDialog::getOpenFileName(owner, sCaption, sPath, sPatterns); 00242 break; 00243 00244 case GWEN_Gui_FileNameType_SaveFileName: 00245 str=QFileDialog::getSaveFileName(owner, sCaption, sPath, sPatterns); 00246 break; 00247 00248 case GWEN_Gui_FileNameType_OpenDirectory: 00249 str=QFileDialog::getExistingDirectory(owner, sCaption, sPath); 00250 break; 00251 } 00252 00253 if (str.isEmpty()) { 00254 DBG_ERROR(GWEN_LOGDOMAIN, "Empty filename returned."); 00255 return GWEN_ERROR_ABORTED; 00256 } 00257 else { 00258 GWEN_Buffer_Reset(pathBuffer); 00259 GWEN_Buffer_AppendString(pathBuffer, str.toUtf8()); 00260 return 0; 00261 } 00262 } 00263 00264 00265 00266 00267 00268 00269 00270 00271