|
libsax 7.2
|
00001 /************** 00002 FILE : import.cpp 00003 *************** 00004 PROJECT : SaX2 - library interface 00005 : 00006 AUTHOR : Marcus Schäfer <ms@suse.de> 00007 : 00008 BELONGS TO : SaX2 - SuSE advanced X11 configuration 00009 : 00010 : 00011 DESCRIPTION : native C++ class library to access SaX2 00012 : functionality. Easy to use interface for 00013 : //.../ 00014 : - importing/exporting X11 configurations 00015 : - modifying/creating X11 configurations 00016 : --- 00017 : 00018 : 00019 STATUS : Status: Development 00020 **************/ 00021 #include "import.h" 00022 00023 namespace SaX { 00024 //==================================== 00025 // Constructor... 00026 //------------------------------------ 00027 SaXImport::SaXImport (int section) { 00028 // .../ 00032 // ---- 00033 mOptions.append ((const char*)"-l"); 00034 switch (section) { 00035 case SAX_CARD: 00036 mSectionName = "Card"; 00037 mOptions.append ((const char*)mSectionName.latin1()); 00038 break; 00039 case SAX_DESKTOP: 00040 mSectionName = "Desktop"; 00041 mOptions.append ((const char*)mSectionName.latin1()); 00042 break; 00043 case SAX_POINTERS: 00044 mSectionName = "Pointers"; 00045 mOptions.append ((const char*)"Mouse"); 00046 break; 00047 case SAX_KEYBOARD: 00048 mSectionName = "Keyboard"; 00049 mOptions.append ((const char*)mSectionName.latin1()); 00050 break; 00051 case SAX_LAYOUT: 00052 mSectionName = "Layout"; 00053 mOptions.append ((const char*)mSectionName.latin1()); 00054 break; 00055 case SAX_PATH: 00056 mSectionName = "Path"; 00057 mOptions.append ((const char*)mSectionName.latin1()); 00058 break; 00059 case SAX_EXTENSIONS: 00060 mSectionName = "Extensions"; 00061 mOptions.append ((const char*)mSectionName.latin1()); 00062 break; 00063 default: 00064 excImportSectionFailed(); 00065 qError (errorString(),EXC_IMPORTSECTIONFAILED); 00066 mSectionName = "Undefined"; 00067 break; 00068 } 00069 mSection = section; 00070 } 00071 00072 //==================================== 00073 // doImport... 00074 //------------------------------------ 00075 void SaXImport::doImport (void) { 00076 // .../ 00079 // ---- 00080 start (mOptions); 00081 } 00082 00083 //==================================== 00084 // setSource... 00085 //------------------------------------ 00086 void SaXImport::setSource (int s) { 00087 // .../ 00092 // ---- 00093 if ( s == SAX_AUTO_PROBE ) { 00094 mOptions.append ((const char*)"-b"); 00095 } 00096 } 00097 00098 //==================================== 00099 // getSectionID... 00100 //------------------------------------ 00101 int SaXImport::getSectionID (void) { 00102 // .../ 00104 // ---- 00105 return mSection; 00106 } 00107 00108 //==================================== 00109 // getSectionName... 00110 //------------------------------------ 00111 QString SaXImport::getSectionName (void) { 00112 // .../ 00114 // ---- 00115 return mSectionName; 00116 } 00117 00118 //==================================== 00119 // Constructor... 00120 //------------------------------------ 00121 SaXImportSysp::SaXImportSysp (int section) { 00122 // .../ 00126 // ---- 00127 mOptions.append ((const char*)"-q"); 00128 switch (section) { 00129 case SYSP_MOUSE: 00130 mSectionName = "Mouse"; 00131 mOptions.append ((const char*)"mouse"); 00132 break; 00133 case SYSP_KEYBOARD: 00134 mSectionName = "Keyboard"; 00135 mOptions.append ((const char*)"keyboard"); 00136 break; 00137 case SYSP_CARD: 00138 mSectionName = "Card"; 00139 mOptions.append ((const char*)"server"); 00140 break; 00141 case SYSP_DESKTOP: 00142 mSectionName = "Desktop"; 00143 mOptions.append ((const char*)"xstuff"); 00144 break; 00145 case SYSP_3D: 00146 mSectionName = "3D"; 00147 mOptions.append ((const char*)"3d"); 00148 break; 00149 default: 00150 excImportSectionFailed(); 00151 qError (errorString(),EXC_IMPORTSECTIONFAILED); 00152 mSectionName = "Undefined"; 00153 break; 00154 } 00155 mSection = section; 00156 } 00157 00158 //==================================== 00159 // doImport... 00160 //------------------------------------ 00161 void SaXImportSysp::doImport (void) { 00162 // .../ 00165 // ---- 00166 start ( mOptions,SAX_SYSP ); 00167 } 00168 00169 //==================================== 00170 // getSectionID... 00171 //------------------------------------ 00172 int SaXImportSysp::getSectionID (void) { 00173 // .../ 00175 // ---- 00176 return mSection; 00177 } 00178 00179 //==================================== 00180 // getSectionName... 00181 //------------------------------------ 00182 QString SaXImportSysp::getSectionName (void) { 00183 // .../ 00185 // ---- 00186 return mSectionName; 00187 } 00188 00189 //==================================== 00190 // Constructor... 00191 //------------------------------------ 00192 SaXImportCDB::SaXImportCDB (int fileID) { 00193 // .../ 00197 // ---- 00198 mID = fileID; 00199 } 00200 00201 //==================================== 00202 // doImport... 00203 //------------------------------------ 00204 void SaXImportCDB::doImport (void) { 00205 // .../ 00208 // ---- 00209 start (mID); 00210 } 00211 00212 //==================================== 00213 // Constructor... 00214 //------------------------------------ 00215 SaXImportProfile::SaXImportProfile (const QString & p) { 00216 // .../ 00221 // ---- 00222 QFileInfo info (p); 00223 if (! info.exists()) { 00224 excProfileNotFound(); 00225 qError (errorString(),EXC_PROFILENOTFOUND); 00226 return; 00227 } 00228 QString profile(p); 00229 mOptions.append ((const char*)"-p"); 00230 mOptions.append ((const char*)profile.latin1()); 00231 mDesktop = 0; 00232 mCard = 0; 00233 mPointers= 0; 00234 mLayout = 0; 00235 } 00236 00237 //==================================== 00238 // doImport... 00239 //------------------------------------ 00240 void SaXImportProfile::doImport (void) { 00241 // .../ 00247 // ---- 00248 start ( mOptions,SAX_PROF ); 00249 splitImport(); 00250 } 00251 00252 //==================================== 00253 // splitImport... 00254 //------------------------------------ 00255 void SaXImportProfile::splitImport (void) { 00256 // .../ 00268 // ---- 00269 for (int n=0;n < getCount();n++) { 00270 Q3Dict<QString>* table = getTablePointer ( n ); 00271 Q3DictIterator<QString> it (*table); 00272 for (; it.current(); ++it) { 00273 QStringList tokens = QStringList::split ( ":", *it.current() ); 00274 QString section = tokens.last(); 00275 tokens.pop_back(); 00276 QString value = tokens.join(":"); 00277 if (section == "Layout") { 00278 if (! mLayout) { 00279 mLayout = new SaXImport (SAX_LAYOUT); 00280 } 00281 mLayout -> addID (n); 00282 mLayout -> setItem (it.currentKey(),value); 00283 } 00284 if (section == "Desktop") { 00285 if (! mDesktop) { 00286 mDesktop = new SaXImport (SAX_DESKTOP); 00287 } 00288 mDesktop -> addID (n); 00289 mDesktop -> setItem (it.currentKey(),value); 00290 } 00291 if (section == "Card") { 00292 if (! mCard) { 00293 mCard = new SaXImport (SAX_CARD); 00294 } 00295 mCard -> addID (n); 00296 mCard -> setItem (it.currentKey(),value); 00297 } 00298 if (section == "Mouse") { 00299 if (! mPointers) { 00300 mPointers = new SaXImport (SAX_POINTERS); 00301 } 00302 mPointers -> addID (n); 00303 mPointers -> setItem (it.currentKey(),value); 00304 } 00305 } 00306 } 00307 } 00308 00309 //==================================== 00310 // setDevice... 00311 //------------------------------------ 00312 void SaXImportProfile::setDevice (int dev) { 00313 // .../ 00317 // ---- 00318 QString device; 00319 device.sprintf ("%d",dev); 00320 mOptions.append ((const char*)"-d"); 00321 mOptions.append ((const char*)device.latin1()); 00322 } 00323 00324 //==================================== 00325 // getImport... 00326 //------------------------------------ 00327 SaXImport* SaXImportProfile::getImport (int section) { 00328 // .../ 00332 // ---- 00333 SaXImport* obj = NULL; 00334 switch (section) { 00335 case SAX_CARD: 00336 obj = mCard; 00337 break; 00338 case SAX_DESKTOP: 00339 obj = mDesktop; 00340 break; 00341 case SAX_LAYOUT: 00342 obj = mLayout; 00343 break; 00344 case SAX_POINTERS: 00345 obj = mPointers; 00346 break; 00347 default: 00348 excProfileUndefined (section); 00349 qError (errorString(),EXC_PROFILEUNDEFINED); 00350 break; 00351 } 00352 return obj; 00353 } 00354 } // end namespace
1.7.3