|
libsax 7.2
|
00001 /************** 00002 FILE : desktop.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 "desktop.h" 00022 #include <X11/Xcms.h> 00023 #include <X11/extensions/scrnsaver.h> 00024 00025 namespace SaX { 00026 //==================================== 00027 // Constructor... 00028 //------------------------------------ 00029 SaXManipulateDesktop::SaXManipulateDesktop ( 00030 SaXImport* desktop, SaXImport* card , SaXImport* path, int desktopID 00031 ) { 00032 // .../ 00035 // ---- 00036 if ( (! desktop) || (! card) ) { 00037 excNullPointerArgument (); 00038 qError (errorString(),EXC_NULLPOINTERARGUMENT); 00039 return; 00040 } 00041 if ( desktop->getSectionID() != SAX_DESKTOP ) { 00042 excDesktopImportBindFailed ( desktop->getSectionID() ); 00043 qError (errorString(),EXC_DESKTOPIMPORTBINDFAILED); 00044 return; 00045 } 00046 if ( card->getSectionID() != SAX_CARD ) { 00047 excCardImportBindFailed ( card->getSectionID() ); 00048 qError (errorString(),EXC_CARDIMPORTBINDFAILED); 00049 return; 00050 } 00051 if ( path->getSectionID() != SAX_PATH ) { 00052 excPathImportBindFailed ( path->getSectionID() ); 00053 qError (errorString(),EXC_PATHIMPORTBINDFAILED); 00054 return; 00055 } 00056 mDesktopID = desktopID; 00057 mDesktop = desktop; 00058 mCard = card; 00059 mPath = path; 00060 mDesktop -> setID ( mDesktopID ); 00061 mCard -> setID ( mDesktopID ); 00062 mPath -> setID ( 0 ); 00063 mCDBMonitors = 0; 00064 mSyspDesktop = 0; 00065 } 00066 00067 //==================================== 00068 // set desktop ID 00069 //------------------------------------ 00070 bool SaXManipulateDesktop::selectDesktop (int desktop) { 00071 // .../ 00074 // ---- 00075 if ((! mDesktop) || (! mCard) || (! mPath)) { 00076 return false; 00077 } 00078 if ( (mDesktop->setID (desktop)) && (mCard->setID (desktop)) ) { 00079 mDesktopID = desktop; 00080 return true; 00081 } 00082 return false; 00083 } 00084 00085 //==================================== 00086 // calculateModelines 00087 //------------------------------------ 00088 void SaXManipulateDesktop::calculateModelines (bool calc) { 00089 // .../ 00093 // ---- 00094 if ((! mDesktop) || (! mCard) || (! mPath)) { 00095 return; 00096 } 00097 QString val ("no"); 00098 if (calc) { 00099 val = "on"; 00100 } 00101 mDesktop -> setItem ( "CalcModelines",val ); 00102 } 00103 00104 //==================================== 00105 // setResolution 00106 //------------------------------------ 00107 void SaXManipulateDesktop::setResolution (int c,int x,int y) { 00108 // .../ 00111 // ---- 00112 if ((! mDesktop) || (! mCard) || (! mPath)) { 00113 return; 00114 } 00115 QString key; 00116 QString val; 00117 key.sprintf ("Modes:%d",c); 00118 val.sprintf ("%dx%d",x,y); 00119 mDesktop -> setItem ( key,val ); 00120 } 00121 00122 //==================================== 00123 // addResolution 00124 //------------------------------------ 00125 void SaXManipulateDesktop::addResolution (int c,int x,int y) { 00126 // .../ 00129 // ---- 00130 if ((! mDesktop) || (! mCard) || (! mPath)) { 00131 return; 00132 } 00133 QString key; 00134 QString val; 00135 key.sprintf ("Modes:%d",c); 00136 if (! mDesktop -> getItem (key).isEmpty()) { 00137 val = mDesktop -> getItem (key); 00138 } 00139 QTextOStream (&val) << "," << x << "x" << y; 00140 val.replace (QRegExp("^,"),""); 00141 mDesktop -> setItem ( key,val ); 00142 } 00143 00144 //==================================== 00145 // removeResolution 00146 //------------------------------------ 00147 void SaXManipulateDesktop::removeResolution (int c,int x,int y) { 00148 // .../ 00151 // ---- 00152 if ((! mDesktop) || (! mCard) || (! mPath)) { 00153 return; 00154 } 00155 QString key; 00156 QString val; 00157 key.sprintf ("Modes:%d",c); 00158 val.sprintf ("%dx%d",x,y); 00159 if (! mDesktop -> getItem (key).isEmpty()) { 00160 mDesktop -> removeItem (key,val); 00161 } 00162 } 00163 00164 //==================================== 00165 // setVirtualResolution 00166 //------------------------------------ 00167 void SaXManipulateDesktop::setVirtualResolution (int c,int x,int y) { 00168 // .../ 00171 // ---- 00172 if ((! mDesktop) || (! mCard) || (! mPath)) { 00173 return; 00174 } 00175 QString key; 00176 QString val; 00177 key.sprintf ("Virtual:%d",c); 00178 val.sprintf ("%d %d",x,y); 00179 mDesktop -> setItem ( key,val ); 00180 } 00181 00182 //==================================== 00183 // removeVirtualResolution 00184 //------------------------------------ 00185 void SaXManipulateDesktop::removeVirtualResolution (int c) { 00186 // .../ 00189 // ---- 00190 if ((! mDesktop) || (! mCard) || (! mPath)) { 00191 return; 00192 } 00193 QString key; 00194 key.sprintf ("Virtual:%d",c); 00195 if (! mDesktop -> getItem (key).isEmpty()) { 00196 mDesktop -> setItem (key,""); 00197 } 00198 } 00199 00200 //==================================== 00201 // setColorDepth 00202 //------------------------------------ 00203 void SaXManipulateDesktop::setColorDepth (int c) { 00204 // .../ 00207 // ---- 00208 if ((! mDesktop) || (! mCard) || (! mPath)) { 00209 return; 00210 } 00211 QString color; 00212 color.sprintf ("%d",c); 00213 mDesktop -> setItem ( "ColorDepth",color ); 00214 } 00215 00216 //==================================== 00217 // is3DCard 00218 //------------------------------------ 00219 bool SaXManipulateDesktop::is3DCard (void) { 00220 // .../ 00223 // ---- 00224 if ((! mDesktop) || (! mCard) || (! mPath)) { 00225 return false; 00226 } 00227 //==================================== 00228 // get sysp card name 00229 //------------------------------------ 00230 SaXImportSysp* pCard = new SaXImportSysp (SYSP_CARD); 00231 pCard -> doImport(); 00232 if (! pCard -> setID ( mDesktopID )) { 00233 return false; 00234 } 00235 QString mCardName; 00236 QTextOStream (&mCardName) << 00237 pCard->getItem("Vendor") << ":" << pCard->getItem("Device"); 00238 //==================================== 00239 // retrieve CDB card list 00240 //------------------------------------ 00241 SaXProcess* CDBCards = new SaXProcess (); 00242 CDBCards -> start (CDB_CARDS); 00243 Q3Dict< Q3Dict<QString> > CDBData = CDBCards -> getTablePointerCDB (); 00244 Q3Dict<QString>* cardData = CDBData.find( mCardName ); 00245 if ( cardData ) { 00246 QString* flag = cardData -> find ("Flag"); 00247 if (flag) { 00248 QString driver = mCard -> getItem ("Driver"); 00249 QString* driver3D = cardData -> find ("3DDriver"); 00250 if ((driver3D) && (driver == *driver3D)) { 00251 //==================================== 00252 // check 3D driver installation 00253 //------------------------------------ 00254 if ( driver == "nvidia") { 00255 QString vendor = getVendorForDriver ( driver ); 00256 if (vendor == "NVIDIA Corporation") { 00257 return true; 00258 } 00259 return false; 00260 } 00261 return true; 00262 } 00263 return false; 00264 } 00265 return false; 00266 } 00267 //==================================== 00268 // No CDB record found for cardName 00269 //------------------------------------ 00270 excEmptyCDBGroup ( mCardName.latin1() ); 00271 qError (errorString(),EXC_EMPTYCDBGROUP); 00272 return false; 00273 } 00274 00275 //==================================== 00276 // getDualHeadProfile 00277 //------------------------------------ 00278 QString SaXManipulateDesktop::getDualHeadProfile ( void ) { 00279 // .../ 00285 // ---- 00286 if ((! mDesktop) || (! mCard) || (! mPath)) { 00287 QString* nope = new QString; 00288 return *nope; 00289 } 00290 //=================================== 00291 // Check SaXMeta data... 00292 //----------------------------------- 00293 Q3Dict<QString> metaData = getMetaData(); 00294 if (metaData["SAX_NO_CDB_CHECK"]) { 00295 QString driver = mCard -> getItem ("Driver"); 00296 QString profile = getDriverOptionsDualHeadProfile ( driver ); 00297 return profile; 00298 } 00299 //==================================== 00300 // check special laptop case 00301 //------------------------------------ 00302 QString result; 00303 SaXManipulateCard cardInfo (mCard); 00304 if (cardInfo.isNoteBook()) { 00305 QString driver = mCard -> getItem ("Driver"); 00306 result = getDriverOptionsDualHeadProfile ( driver ); 00307 return result; 00308 } 00309 //==================================== 00310 // get sysp card name 00311 //------------------------------------ 00312 SaXImportSysp* pCard = new SaXImportSysp (SYSP_CARD); 00313 pCard -> doImport(); 00314 if (! pCard -> setID ( mDesktopID )) { 00315 QString* nope = new QString; 00316 return *nope; 00317 } 00318 QString mCardName; 00319 QTextOStream (&mCardName) << 00320 pCard->getItem("Vendor") << ":" << pCard->getItem("Device"); 00321 //==================================== 00322 // retrieve CDB card list 00323 //------------------------------------ 00324 SaXProcess* CDBCards = new SaXProcess (); 00325 CDBCards -> start (CDB_CARDS); 00326 Q3Dict< Q3Dict<QString> > CDBData = CDBCards -> getTablePointerCDB (); 00327 Q3Dict<QString>* cardData = CDBData.find ( mCardName ); 00328 if ( cardData ) { 00329 QString* profile = cardData -> find ("Profile"); 00330 if ((profile) && (profile->contains("DualHead_DriverOptions"))) { 00331 //==================================== 00332 // check if drivers do match... 00333 //------------------------------------ 00334 QString syspDriver = pCard -> getItem ("Module"); 00335 QString* CDB2DDriver = cardData -> find ("Driver"); 00336 QString* CDB3DDriver = cardData -> find ("3DDriver"); 00337 if ( 00338 ((CDB2DDriver) && (syspDriver == *CDB2DDriver)) || 00339 ((CDB3DDriver) && (syspDriver == *CDB2DDriver)) 00340 ) { 00341 QTextOStream (&result) << PROFILE_DIR << profile; 00342 return result; 00343 } 00344 //==================================== 00345 // drivers don't match check driver... 00346 //------------------------------------ 00347 result = getDriverOptionsDualHeadProfile ( syspDriver ); 00348 return result; 00349 } 00350 } 00351 //==================================== 00352 // No CDB record found for cardName 00353 //------------------------------------ 00354 excEmptyCDBGroup ( mCardName.latin1() ); 00355 qError (errorString(),EXC_EMPTYCDBGROUP); 00356 QString* nope = new QString; 00357 return *nope; 00358 } 00359 00360 //==================================== 00361 // isXineramaMode 00362 //------------------------------------ 00363 bool SaXManipulateDesktop::isXineramaMode (void) { 00364 // .../ 00365 // check the meta data information if the configuration 00366 // workflow requested to use Xinerama instead of the 00367 // default dual mode workflow based on MergedFB 00368 // ---- 00369 Q3Dict<QString> metaData = getMetaData(); 00370 if (metaData["SAX_NO_DUAL_MODE"]) { 00371 return true; 00372 } 00373 return false; 00374 } 00375 00376 //==================================== 00377 // isDualHeadCard 00378 //------------------------------------ 00379 bool SaXManipulateDesktop::isDualHeadCard (void) { 00380 // .../ 00384 // ---- 00385 if ((! mDesktop) || (! mCard) || (! mPath)) { 00386 return false; 00387 } 00388 //=================================== 00389 // Check SaXMeta data... 00390 //----------------------------------- 00391 Q3Dict<QString> metaData = getMetaData(); 00392 if (metaData["SAX_NO_CDB_CHECK"]) { 00393 QString driver = mCard -> getItem ("Driver"); 00394 QString profile = getDriverOptionsDualHeadProfile ( driver ); 00395 if (! profile.isEmpty()) { 00396 return true; 00397 } 00398 return false; 00399 } 00400 //==================================== 00401 // get sysp card name 00402 //------------------------------------ 00403 SaXImportSysp* pCard = new SaXImportSysp (SYSP_CARD); 00404 pCard -> doImport(); 00405 if (! pCard -> setID ( mDesktopID )) { 00406 return false; 00407 } 00408 QString mCardName; 00409 QTextOStream (&mCardName) << 00410 pCard->getItem("Vendor") << ":" << pCard->getItem("Device"); 00411 //==================================== 00412 // retrieve CDB card list 00413 //------------------------------------ 00414 SaXProcess* CDBCards = new SaXProcess (); 00415 CDBCards -> start (CDB_CARDS); 00416 Q3Dict< Q3Dict<QString> > CDBData = CDBCards -> getTablePointerCDB (); 00417 Q3Dict<QString>* cardData = CDBData.find ( mCardName ); 00418 if ( cardData ) { 00419 QString* profile = cardData -> find ("Profile"); 00420 if ((profile) && (profile->contains("DualHead_DriverOptions"))) { 00421 //==================================== 00422 // check if drivers do match... 00423 //------------------------------------ 00424 QString syspDriver = pCard -> getItem ("Module"); 00425 QString* CDB2DDriver = cardData -> find ("Driver"); 00426 QString* CDB3DDriver = cardData -> find ("3DDriver"); 00427 if ( 00428 ((CDB2DDriver) && (syspDriver != *CDB2DDriver)) && 00429 ((CDB3DDriver) && (syspDriver != *CDB2DDriver)) 00430 ) { 00431 *profile = getDriverOptionsDualHeadProfile ( syspDriver ); 00432 } 00433 if (profile->isEmpty()) { 00434 return false; 00435 } 00436 //==================================== 00437 // ask profile for changes if dynamic 00438 //------------------------------------ 00439 SaXProcessCall* proc = new SaXProcessCall (); 00440 proc -> addArgument ( SAX_PROFILE_CHECK ); 00441 proc -> addArgument ( *profile ); 00442 if ( ! proc -> start() ) { 00443 excProcessFailed(); 00444 qError (errorString(),EXC_PROCESSFAILED); 00445 return false; 00446 } 00447 if (proc->exitStatus() == 0) { 00448 return true; 00449 } 00450 return false; 00451 } 00452 return false; 00453 } 00454 //==================================== 00455 // No CDB record found for cardName 00456 //------------------------------------ 00457 excEmptyCDBGroup ( mCardName.latin1() ); 00458 qError (errorString(),EXC_EMPTYCDBGROUP); 00459 return false; 00460 } 00461 00462 //==================================== 00463 // enable3D 00464 //------------------------------------ 00465 bool SaXManipulateDesktop::enable3D (void) { 00466 // .../ 00475 // ---- 00476 if ((! mDesktop) || (! mCard) || (! mPath)) { 00477 return false; 00478 } 00479 //==================================== 00480 // get sysp card name 00481 //------------------------------------ 00482 SaXImportSysp* pCard = new SaXImportSysp (SYSP_CARD); 00483 pCard -> doImport(); 00484 if (! pCard -> setID ( mDesktopID )) { 00485 return false; 00486 } 00487 QString mCardName; 00488 QTextOStream (&mCardName) << 00489 pCard->getItem("Vendor") << ":" << pCard->getItem("Device"); 00490 00491 //==================================== 00492 // retrieve CDB card list 00493 //------------------------------------ 00494 SaXProcess* CDBCards = new SaXProcess (); 00495 CDBCards -> start (CDB_CARDS); 00496 Q3Dict< Q3Dict<QString> > CDBData = CDBCards -> getTablePointerCDB (); 00497 00498 //==================================== 00499 // get Extensions for the active card 00500 //------------------------------------ 00501 SaXManipulateCard cardInfo (mCard,mDesktopID); 00502 Q3Dict<QString>* cardData = CDBData.find ( mCardName ); 00503 if ( cardData ) { 00504 QString* driver3D= cardData -> find ("3DDriver"); 00505 QString* driver2D= cardData -> find ("Driver"); 00506 QString* extends = cardData -> find ("Extension"); 00507 QString* flag = cardData -> find ("Flag"); 00508 //======================================== 00509 // check 3D flag 00510 //---------------------------------------- 00511 if (! flag) { 00512 return false; 00513 } 00514 //======================================== 00515 // nvidia drv. needed, check if installed 00516 //---------------------------------------- 00517 if ((driver3D) && (*driver3D == "nvidia")) { 00518 bool foundBinaryNVidiaDriver = false; 00519 if ((getVendorForDriver(*driver3D)) == "NVIDIA Corporation") { 00520 foundBinaryNVidiaDriver = true; 00521 } 00522 if (! foundBinaryNVidiaDriver) { 00523 excNvidiaDriverMissing(); 00524 qError (errorString(),EXC_NVIDIADRIVERMISSING); 00525 return false; 00526 } 00527 } 00528 //======================================== 00529 // have extension, add it 00530 //---------------------------------------- 00531 if (extends) { 00532 SaXManipulatePath pathInfo (mPath); 00533 pathInfo.removeDisableModule (*extends); 00534 pathInfo.removeLoadableModule (*extends); 00535 pathInfo.addLoadableModule (*extends); 00536 } 00537 //======================================== 00538 // set driver to use with 3D 00539 //---------------------------------------- 00540 if (driver3D) { 00541 QString currentDriver = cardInfo.getCardDriver(); 00542 if ((currentDriver != *driver3D) && (currentDriver != *driver2D)) { 00543 excDriverMismatch (driver3D->ascii(),currentDriver.ascii()); 00544 qError (errorString(),EXC_DRIVERMISMATCH); 00545 } else { 00546 cardInfo.setCardDriver (*driver3D); 00547 } 00548 } 00549 } 00550 //==================================== 00551 // Import profiles if there are any 00552 //------------------------------------ 00553 if (cardData) { 00554 QStringList profiles; 00555 QString* profile3D = cardData -> find ("3DProfile"); 00556 QString* driver3D = cardData -> find ("3DDriver"); 00557 QString* driver2D = cardData -> find ("Driver"); 00558 if ((profile3D) && (! profile3D->contains("DualHead"))) { 00559 profiles += *profile3D; 00560 } 00561 if ((driver3D) && (*driver2D != *driver3D)) { 00562 SaXFile mapHandle (MAP_DIR + QString("Driver.map")); 00563 Q3Dict<QString> driverMap = mapHandle.readDict(); 00564 QString driver = cardInfo.getCardDriver(); 00565 if ((! driver.isEmpty()) && (driverMap[driver])) { 00566 QStringList items = QStringList::split ( ",", *driverMap[driver] ); 00567 profiles += items; 00568 } 00569 } 00570 for ( 00571 QStringList::Iterator it=profiles.begin(); 00572 it != profiles.end(); ++it 00573 ) { 00574 QString profile (*it); 00575 SaXImportProfile* pProfile = new SaXImportProfile ( 00576 PROFILE_DIR + profile 00577 ); 00578 pProfile -> doImport(); 00579 //==================================== 00580 // handle Card Options 00581 //------------------------------------ 00582 SaXImport* mImportCard = pProfile -> getImport ( SAX_CARD ); 00583 if ( mImportCard ) { 00584 Q3Dict<QString> profileDriverOptions; 00585 SaXManipulateCard saxProfileCard ( mImportCard ); 00586 profileDriverOptions = saxProfileCard.getOptions(); 00587 Q3DictIterator<QString> it ( profileDriverOptions ); 00588 for (; it.current(); ++it) { 00589 QString key = it.currentKey(); 00590 QString val = *it.current(); 00591 cardInfo.addCardOption (key,val); 00592 } 00593 } 00594 //==================================== 00595 // handle Desktop Options 00596 //------------------------------------ 00597 SaXImport* mImportDesktop = pProfile -> getImport ( SAX_DESKTOP ); 00598 if ( mImportDesktop ) { 00599 Q3Dict<QString> profileDriverOptions; 00600 SaXManipulateDesktop saxProfileDesktop ( 00601 mImportDesktop,mCard,mPath 00602 ); 00603 //==================================== 00604 // Colordepth... 00605 //------------------------------------ 00606 QString color = saxProfileDesktop.getColorDepth(); 00607 if (! color.isEmpty()) { 00608 setColorDepth (color.toInt()); 00609 } 00610 } 00611 } 00612 return true; 00613 } 00614 //==================================== 00615 // No CDB record found for mCardName 00616 //------------------------------------ 00617 excEmptyCDBGroup ( mCardName.latin1() ); 00618 qError (errorString(),EXC_EMPTYCDBGROUP); 00619 return false; 00620 } 00621 00622 //==================================== 00623 // disable3D 00624 //------------------------------------ 00625 bool SaXManipulateDesktop::disable3D (void) { 00626 // .... 00632 // ---- 00633 if ((! mDesktop) || (! mCard) || (! mPath)) { 00634 return false; 00635 } 00636 //==================================== 00637 // get sysp card name 00638 //------------------------------------ 00639 SaXImportSysp* pCard = new SaXImportSysp (SYSP_CARD); 00640 pCard -> doImport(); 00641 if (! pCard -> setID ( mDesktopID )) { 00642 return false; 00643 } 00644 QString mCardName; 00645 QTextOStream (&mCardName) << 00646 pCard->getItem("Vendor") << ":" << pCard->getItem("Device"); 00647 00648 //==================================== 00649 // retrieve CDB card list 00650 //------------------------------------ 00651 SaXProcess* CDBCards = new SaXProcess (); 00652 CDBCards -> start (CDB_CARDS); 00653 Q3Dict< Q3Dict<QString> > CDBData = CDBCards -> getTablePointerCDB (); 00654 00655 //==================================== 00656 // get Extensions for the active card 00657 //------------------------------------ 00658 SaXManipulateCard cardInfo (mCard); 00659 Q3Dict<QString>* cardData = CDBData.find ( mCardName ); 00660 if ( cardData ) { 00661 QString* driver3D= cardData -> find ("3DDriver"); 00662 QString* driver2D= cardData -> find ("Driver"); 00663 QString* extends = cardData -> find ("Extension"); 00664 QString* flag = cardData -> find ("Flag"); 00665 //======================================== 00666 // check 3D flag 00667 //---------------------------------------- 00668 if (! flag) { 00669 return false; 00670 } 00671 //======================================== 00672 // nvidia drv. needed, check if installed 00673 //---------------------------------------- 00674 if ((driver3D) && (*driver3D == "nvidia")) { 00675 if ((getVendorForDriver(*driver3D)) == "NVIDIA Corporation") { 00676 excNvidiaDriverInstalled(); 00677 qError (errorString(),EXC_NVIDIADRIVERINSTALLED); 00678 return false; 00679 } 00680 } 00681 //======================================== 00682 // have extension, remove it 00683 //---------------------------------------- 00684 if (extends) { 00685 SaXManipulatePath pathInfo (mPath); 00686 pathInfo.removeLoadableModule (*extends); 00687 pathInfo.removeDisableModule (*extends); 00688 pathInfo.addDisableModule (*extends); 00689 } 00690 //======================================== 00691 // set driver to use with 2D 00692 //---------------------------------------- 00693 if ((driver2D) && (driver3D)) { 00694 QString currentDriver = cardInfo.getCardDriver(); 00695 if ((currentDriver != *driver3D) && (currentDriver != *driver2D)) { 00696 excDriverMismatch (driver2D->ascii(),currentDriver.ascii()); 00697 qError (errorString(),EXC_DRIVERMISMATCH); 00698 } else { 00699 cardInfo.setCardDriver (*driver2D); 00700 } 00701 } 00702 } 00703 //==================================== 00704 // Reset profiles if there are any 00705 //------------------------------------ 00706 if (cardData) { 00707 QStringList profiles; 00708 QString* profile3D = cardData -> find ("3DProfile"); 00709 QString* driver3D = cardData -> find ("3DDriver"); 00710 QString* driver2D = cardData -> find ("Driver"); 00711 if ((profile3D) && (! profile3D->contains("DualHead"))) { 00712 profiles += *profile3D; 00713 } 00714 if ((driver3D) && (*driver2D != *driver3D)) { 00715 SaXFile mapHandle (MAP_DIR + QString("Driver.map")); 00716 Q3Dict<QString> driverMap = mapHandle.readDict(); 00717 if ((driver3D) && (driverMap[*driver3D])) { 00718 QStringList items = QStringList::split ( ",",*driverMap[*driver3D] ); 00719 profiles += items; 00720 } 00721 } 00722 for ( 00723 QStringList::Iterator it=profiles.begin(); 00724 it != profiles.end(); ++it 00725 ) { 00726 QString profile (*it); 00727 SaXImportProfile* pProfile = new SaXImportProfile ( 00728 PROFILE_DIR + profile 00729 ); 00730 pProfile -> doImport(); 00731 //==================================== 00732 // remove Card Options 00733 //------------------------------------ 00734 SaXImport* mImportCard = pProfile -> getImport ( SAX_CARD ); 00735 if ( mImportCard ) { 00736 Q3Dict<QString> profileDriverOptions; 00737 SaXManipulateCard saxProfileCard ( mImportCard ); 00738 profileDriverOptions = saxProfileCard.getOptions(); 00739 Q3DictIterator<QString> it ( profileDriverOptions ); 00740 for (; it.current(); ++it) { 00741 QString key = it.currentKey(); 00742 cardInfo.removeCardOption (key); 00743 } 00744 } 00745 } 00746 return true; 00747 } 00748 //==================================== 00749 // No CDB record found for mCardName 00750 //------------------------------------ 00751 excEmptyCDBGroup ( mCardName.latin1() ); 00752 qError (errorString(),EXC_EMPTYCDBGROUP); 00753 return false; 00754 } 00755 00756 //==================================== 00757 // setDisplaySize 00758 //------------------------------------ 00759 void SaXManipulateDesktop::setDisplaySize (int width,int height) { 00760 // .../ 00763 // ---- 00764 if ((! mDesktop) || (! mCard) || (! mPath)) { 00765 return; 00766 } 00767 QString size; 00768 size.sprintf ("%d %d",width,height); 00769 mDesktop -> setItem ( "DisplaySize",size ); 00770 } 00771 00772 //==================================== 00773 // setDisplayRatioAndTraversal 00774 //------------------------------------ 00775 void SaXManipulateDesktop::setDisplayRatioAndTraversal ( 00776 double traversal,int aspect, int ratio 00777 ) { 00778 // .../ 00781 // ---- 00782 if ((! mDesktop) || (! mCard) || (! mPath)) { 00783 return; 00784 } 00785 traversal = traversal * 25.4; 00786 double ar = (double)aspect / (double)ratio; 00787 double y = sqrt ( (traversal * traversal) / (ar * ar + 1.0) ); 00788 double x = ar * y; 00789 setDisplaySize ( 00790 (int)(round(x)),(int)(round(y)) 00791 ); 00792 } 00793 00794 //==================================== 00795 // setHsyncRange 00796 //------------------------------------ 00797 void SaXManipulateDesktop::setHsyncRange (double hsmin,double hsmax) { 00798 // .../ 00801 // ---- 00802 if ((! mDesktop) || (! mCard) || (! mPath)) { 00803 return; 00804 } 00805 QString range; 00806 range.sprintf ("%.0f-%.0f",hsmin,hsmax); 00807 mDesktop -> setItem ( "HorizSync",range ); 00808 } 00809 00810 //==================================== 00811 // setVsyncRange 00812 //------------------------------------ 00813 void SaXManipulateDesktop::setVsyncRange (double vsmin,double vsmax) { 00814 // .../ 00817 // ---- 00818 if ((! mDesktop) || (! mCard) || (! mPath)) { 00819 return; 00820 } 00821 QString range; 00822 range.sprintf ("%.0f-%.0f",vsmin,vsmax); 00823 mDesktop -> setItem ( "VertRefresh",range ); 00824 } 00825 00826 //==================================== 00827 // setPreferredMode 00828 //------------------------------------ 00829 void SaXManipulateDesktop::setPreferredMode (const QString& mode) { 00830 // .../ 00833 // ---- 00834 if ((! mDesktop) || (! mCard) || (! mPath)) { 00835 return; 00836 } 00837 mDesktop -> setItem ( "PreferredMode",mode); 00838 } 00839 00840 //==================================== 00841 // enableDPMS 00842 //------------------------------------ 00843 void SaXManipulateDesktop::enableDPMS (void) { 00844 // .../ 00848 // ---- 00849 if ((! mDesktop) || (! mCard) || (! mPath)) { 00850 return; 00851 } 00852 mDesktop -> setItem ( "MonitorOptions","DPMS" ); 00853 } 00854 00855 //==================================== 00856 // disableDPMS 00857 //------------------------------------ 00858 void SaXManipulateDesktop::disableDPMS (void) { 00859 // .../ 00862 // ---- 00863 if ((! mDesktop) || (! mCard) || (! mPath)) { 00864 return; 00865 } 00866 mDesktop -> setItem ( "MonitorOptions","" ); 00867 } 00868 00869 //==================================== 00870 // setMonitorVendor 00871 //------------------------------------ 00872 void SaXManipulateDesktop::setMonitorVendor (const QString& vendor) { 00873 // .../ 00876 // ---- 00877 if ((! mDesktop) || (! mCard) || (! mPath)) { 00878 return; 00879 } 00880 mDesktop -> setItem ( "VendorName",vendor ); 00881 } 00882 00883 //==================================== 00884 // setMonitorName 00885 //------------------------------------ 00886 void SaXManipulateDesktop::setMonitorName (const QString& name) { 00887 // .../ 00890 // ---- 00891 if ((! mDesktop) || (! mCard) || (! mPath)) { 00892 return; 00893 } 00894 mDesktop -> setItem ( "ModelName",name ); 00895 } 00896 00897 //==================================== 00898 // is3DEnabled 00899 //------------------------------------ 00900 bool SaXManipulateDesktop::is3DEnabled (void) { 00901 // .../ 00906 // ---- 00907 if ((! mDesktop) || (! mCard) || (! mPath)) { 00908 return false; 00909 } 00910 if ( mCard -> getCount() > 1 ) { 00911 return false; 00912 } 00913 QString driver = mCard -> getItem ("Driver"); 00914 if (driver == "nvidia") { 00915 QString vendor = getVendorForDriver ( driver ); 00916 if (vendor == "NVIDIA Corporation") { 00917 return true; 00918 } 00919 return false; 00920 } 00921 SaXManipulatePath pathInfo (mPath); 00922 QList<QString> modules = pathInfo.getModules(); 00923 QString it; 00924 foreach (it,modules) { 00925 if (it == "dri") { 00926 return true; 00927 } 00928 } 00929 return false; 00930 } 00931 00932 //==================================== 00933 // getResolutions 00934 //------------------------------------ 00935 QList<QString> SaXManipulateDesktop::getResolutions (int color) { 00936 // .../ 00940 // ---- 00941 if ((! mDesktop) || (! mCard) || (! mPath)) { 00942 QList<QString>* nope = new QList<QString>; 00943 return *nope; 00944 } 00945 QString modes; 00946 modes.sprintf ("Modes:%d",color); 00947 QString resolutions = mDesktop -> getItem (modes); 00948 if (resolutions.isEmpty()) { 00949 QList<QString>* nope = new QList<QString>; 00950 return *nope; 00951 } 00952 QList<QString> result; 00953 QStringList resList = QStringList::split ( ",", resolutions ); 00954 for (QStringList::Iterator it=resList.begin(); it!=resList.end();++ it) { 00955 result.append (*it); 00956 } 00957 return result; 00958 } 00959 00960 //==================================== 00961 // getResolutionsFromServer 00962 //------------------------------------ 00963 QList<QString> SaXManipulateDesktop::getResolutionFromServer ( void ) { 00964 // .../ 00969 // ---- 00970 if ((! mDesktop) || (! mCard) || (! mPath)) { 00971 QList<QString>* nope = new QList<QString>; 00972 return *nope; 00973 } 00974 QList<QString> defaultList; 00975 defaultList.append (QString("800x600")); 00976 SaXProcessCall* proc = new SaXProcessCall(); 00977 proc -> addArgument ( XQUERY ); 00978 proc -> addArgument ( "-r" ); 00979 if ( ! proc -> start() ) { 00980 return defaultList; 00981 } 00982 QList<QString> data = proc->readStdout(); 00983 QString in; 00984 foreach (in,data) { 00985 QRegExp modeExp ("(\\d+) (.*)"); 00986 int rpos = modeExp.search (in,0); 00987 if (rpos >= 0) { 00988 int id = modeExp.cap(1).toInt(); 00989 if (id == mDesktopID) { 00990 QList<QString> result; 00991 result.append (QString (modeExp.cap(2))); 00992 return result; 00993 } 00994 } 00995 } 00996 return defaultList; 00997 } 00998 00999 //==================================== 01000 // getColorDepthFromServer 01001 //------------------------------------ 01002 int SaXManipulateDesktop::getColorDepthFromServer (void) { 01003 Display* dpy = XOpenDisplay (0); 01004 return DisplayPlanes( dpy,0 ); 01005 } 01006 01007 //==================================== 01008 // getFBKernelMode 01009 //------------------------------------ 01010 int SaXManipulateDesktop::getFBKernelMode (const QString& res,int depth) { 01011 if (! mSyspDesktop) { 01012 mSyspDesktop = new SaXImportSysp (SYSP_DESKTOP); 01013 } 01014 mSyspDesktop -> setID ( mDesktopID ); 01015 mSyspDesktop -> doImport (); 01016 if ( mSyspDesktop->getItem("FBBoot").isNull()) { 01017 return 0; 01018 } 01019 QString val = mSyspDesktop->getItem("FBBoot"); 01020 QStringList items = QStringList::split ( ",", val ); 01021 for ( 01022 QStringList::Iterator it=items.begin(); 01023 it != items.end(); ++it 01024 ) { 01025 QString* resolution = new QString(); 01026 QString mode (*it); 01027 QStringList record = QStringList::split ( " ", mode ); 01028 QTextOStream (resolution) << record.at(0) << "x" << record.at(1); 01029 QString color = record.at(2); 01030 if ((*resolution == res) && (color.toInt() == depth)) { 01031 QString mode = record.at(3); 01032 return mode.toInt(); 01033 } 01034 } 01035 return 0; 01036 } 01037 01038 //==================================== 01039 // setFBKernelMode 01040 //------------------------------------ 01041 int SaXManipulateDesktop::setFBKernelMode (int mode) { 01042 QString* modeString = new QString(); 01043 QTextOStream (modeString) << mode; 01044 SaXProcessCall* proc = new SaXProcessCall (); 01045 proc -> addArgument ( SAX_GRUB_UPDATE ); 01046 proc -> addArgument ( *modeString ); 01047 if ( ! proc -> start() ) { 01048 excProcessFailed(); 01049 qError (errorString(),EXC_PROCESSFAILED); 01050 return false; 01051 } 01052 if (proc->exitStatus() == 0) { 01053 return true; 01054 } 01055 return false; 01056 } 01057 01058 //==================================== 01059 // setFBKernelMode 01060 //------------------------------------ 01061 bool SaXManipulateDesktop::getKMSStatus(void) 01062 { 01063 SaXProcessCall* proc = new SaXProcessCall (); 01064 proc -> addArgument ( SAX_KMS_STATUS ); 01065 if ( ! proc -> start() ) { 01066 excProcessFailed(); 01067 qError (errorString(),EXC_PROCESSFAILED); 01068 return false; 01069 } 01070 if (proc->exitStatus() == 0) { 01071 return true; 01072 } 01073 return false; 01074 } 01075 01076 //==================================== 01077 // getResolutionsFromDDC 01078 //------------------------------------ 01079 QList<QString> SaXManipulateDesktop::getResolutionsFromDDC (const QString& key) { 01080 QList<QString> result; 01081 Q3Dict<QString> hashed; 01082 SaXImportSysp* desktop = new SaXImportSysp (SYSP_DESKTOP); 01083 desktop -> setID ( mDesktopID ); 01084 desktop -> doImport (); 01085 if ( desktop->getItem(key).isNull()) { 01086 QList<QString>* nope = new QList<QString>; 01087 return *nope; 01088 } 01089 if ((key != "FBBoot") && (desktop->getItem("DDC") == "<undefined>")) { 01090 QList<QString>* nope = new QList<QString>; 01091 return *nope; 01092 } 01093 QString val = desktop->getItem(key); 01094 QStringList items = QStringList::split ( ",", val ); 01095 for ( 01096 QStringList::Iterator it=items.begin(); 01097 it != items.end(); ++it 01098 ) { 01099 QString* data = new QString(); 01100 QString mode (*it); 01101 QStringList resolution = QStringList::split (" ", mode); 01102 QTextOStream (data) << resolution.at(0) << "x" << resolution.at(1); 01103 if (! hashed[*data]) { 01104 hashed.insert (*data,data); 01105 } 01106 } 01107 QString* default1 = new QString ("800x600"); 01108 QString* default2 = new QString ("1024x768"); 01109 hashed.insert (*default1,default1); 01110 hashed.insert (*default2,default2); 01111 Q3DictIterator<QString> ir (hashed); 01112 for (; ir.current(); ++ir) { 01113 result.append (*ir.current()); 01114 } 01115 return result; 01116 } 01117 01118 //==================================== 01119 // getResolutionsFromDDC1 01120 //------------------------------------ 01121 QList<QString> SaXManipulateDesktop::getResolutionsFromDDC1 (void) { 01122 return getResolutionsFromDDC ("Vesa"); 01123 } 01124 01125 //==================================== 01126 // getResolutionsFromDDC2 01127 //------------------------------------ 01128 QList<QString> SaXManipulateDesktop::getResolutionsFromDDC2 (void) { 01129 return getResolutionsFromDDC ("Vesa[2]"); 01130 } 01131 01132 //==================================== 01133 // getResolutionsFromFrameBuffer 01134 //------------------------------------ 01135 QList<QString> SaXManipulateDesktop::getResolutionsFromFrameBuffer (void) { 01136 return getResolutionsFromDDC ("FBBoot"); 01137 } 01138 01139 //==================================== 01140 // getDisplaySize 01141 //------------------------------------ 01142 QList<QString> SaXManipulateDesktop::getDisplaySize (void) { 01143 // .../ 01149 // ---- 01150 if ((! mDesktop) || (! mCard) || (! mPath)) { 01151 QList<QString>* nope = new QList<QString>; 01152 return *nope; 01153 } 01154 QString size = mDesktop -> getItem ("DisplaySize"); 01155 if (size.isEmpty()) { 01156 QList<QString>* nope = new QList<QString>; 01157 return *nope; 01158 } 01159 QList<QString> result; 01160 QStringList sizeList = QStringList::split ( " ", size ); 01161 result.append ( 01162 QString(sizeList.first()) 01163 ); 01164 result.append ( 01165 QString(sizeList.last()) 01166 ); 01167 return result; 01168 } 01169 01170 //==================================== 01171 // getDisplayTraversal 01172 //------------------------------------ 01173 QString SaXManipulateDesktop::getDisplayTraversal (void) { 01174 // .../ 01177 // ---- 01178 if ((! mDesktop) || (! mCard) || (! mPath)) { 01179 QString* nope = new QString; 01180 return *nope; 01181 } 01182 QList<QString> size = getDisplaySize(); 01183 if (size.isEmpty()) { 01184 QString* nope = new QString; 01185 return *nope; 01186 } 01187 int x = size.at(0).toInt(); 01188 int y = size.at(1).toInt(); 01189 double traversal = sqrt (x*x + y*y) / 25.4; 01190 QString result; 01191 QTextOStream (&result) << traversal; 01192 return result; 01193 } 01194 01195 //==================================== 01196 // getDisplayRatio 01197 //------------------------------------ 01198 QList<QString> SaXManipulateDesktop::getDisplayRatio (void) { 01199 // .../ 01202 // ---- 01203 if ((! mDesktop) || (! mCard) || (! mPath)) { 01204 QList<QString>* nope = new QList<QString>; 01205 return *nope; 01206 } 01207 QString* setX = new QString ("4"); 01208 QString* setY = new QString ("3"); 01209 QList<QString> result; 01210 QList<QString> size = getDisplaySize(); 01211 if (size.isEmpty()) { 01212 QList<QString>* nope = new QList<QString>; 01213 return *nope; 01214 } 01215 int x = size.at(0).toInt(); 01216 int y = size.at(1).toInt(); 01217 double ar = (double)x / (double)y; 01218 if ( ar > 1.7) { 01219 *setX = "16"; 01220 *setY = "9"; 01221 } else if (( ar <= 1.7 ) && ( ar > 1.4 )) { 01222 *setX = "16"; 01223 *setY = "10"; 01224 } else if (( ar <= 1.4 ) && ( ar > 1.3 )) { 01225 *setX = "4"; 01226 *setY = "3"; 01227 } else if ( ar <= 1.3 ) { 01228 *setX = "5"; 01229 *setY = "4"; 01230 } 01231 result.append (*setX); 01232 result.append (*setY); 01233 return result; 01234 } 01235 01236 //==================================== 01237 // getHsyncRange 01238 //------------------------------------ 01239 QList<QString> SaXManipulateDesktop::getHsyncRange (void) { 01240 // .../ 01244 // ---- 01245 if ((! mDesktop) || (! mCard) || (! mPath)) { 01246 QList<QString>* nope = new QList<QString>; 01247 return *nope; 01248 } 01249 QString range = mDesktop -> getItem ("HorizSync"); 01250 if (range.isEmpty()) { 01251 QList<QString>* nope = new QList<QString>; 01252 return *nope; 01253 } 01254 QList<QString> result; 01255 QStringList rangeList = QStringList::split ( "-", range ); 01256 result.append ( 01257 QString(rangeList.first()) 01258 ); 01259 result.append ( 01260 QString(rangeList.last()) 01261 ); 01262 return result; 01263 } 01264 01265 //==================================== 01266 // getVsyncRange 01267 //------------------------------------ 01268 QList<QString> SaXManipulateDesktop::getVsyncRange (void) { 01269 // .../ 01273 // ---- 01274 if ((! mDesktop) || (! mCard) || (! mPath)) { 01275 QList<QString>* nope = new QList<QString>; 01276 return *nope; 01277 } 01278 QString range = mDesktop -> getItem ("VertRefresh"); 01279 if (range.isEmpty()) { 01280 QList<QString>* nope = new QList<QString>; 01281 return *nope; 01282 } 01283 QList<QString> result; 01284 QStringList rangeList = QStringList::split ( "-", range ); 01285 result.append ( 01286 QString(rangeList.first()) 01287 ); 01288 result.append ( 01289 QString(rangeList.last()) 01290 ); 01291 return result; 01292 } 01293 01294 //==================================== 01295 // DPMSEnabled 01296 //------------------------------------ 01297 bool SaXManipulateDesktop::DPMSEnabled (void) { 01298 // .../ 01302 // ---- 01303 if ((! mDesktop) || (! mCard) || (! mPath)) { 01304 return false; 01305 } 01306 QString options = mDesktop -> getItem ("MonitorOptions"); 01307 if (options == "DPMS") { 01308 return true; 01309 } 01310 return false; 01311 } 01312 01313 //==================================== 01314 // getMonitorVendor 01315 //------------------------------------ 01316 QString SaXManipulateDesktop::getMonitorVendor (void) { 01317 // .../ 01320 // ---- 01321 if ((! mDesktop) || (! mCard) || (! mPath)) { 01322 QString* nope = new QString; 01323 return *nope; 01324 } 01325 return mDesktop -> getItem ("VendorName"); 01326 } 01327 01328 //==================================== 01329 // getMonitorName 01330 //------------------------------------ 01331 QString SaXManipulateDesktop::getMonitorName (void) { 01332 // .../ 01335 // ---- 01336 if ((! mDesktop) || (! mCard) || (! mPath)) { 01337 QString* nope = new QString; 01338 return *nope; 01339 } 01340 return mDesktop -> getItem ("ModelName"); 01341 } 01342 01343 //==================================== 01344 // getColorDepth 01345 //------------------------------------ 01346 QString SaXManipulateDesktop::getColorDepth (void) { 01347 // .../ 01350 // ---- 01351 if ((! mDesktop) || (! mCard) || (! mPath)) { 01352 QString* nope = new QString; 01353 return *nope; 01354 } 01355 return mDesktop -> getItem ("ColorDepth"); 01356 } 01357 01358 //==================================== 01359 // getModelineAlgorithm 01360 //------------------------------------ 01361 QString SaXManipulateDesktop::getModelineAlgorithm (void) { 01362 // .../ 01364 // ---- 01365 if ((! mDesktop) || (! mCard) || (! mPath)) { 01366 QString* nope = new QString; 01367 return *nope; 01368 } 01369 return mDesktop -> getItem ("CalcAlgorithm"); 01370 } 01371 01372 //==================================== 01373 // willCalculateModelines 01374 //------------------------------------ 01375 bool SaXManipulateDesktop::willCalculateModelines (void) { 01376 // .../ 01379 // ---- 01380 if ((! mDesktop) || (! mCard) || (! mPath)) { 01381 return false; 01382 } 01383 QString calculate = mDesktop -> getItem ("CalcModelines"); 01384 if ((calculate == "on") || (calculate == "yes")) { 01385 return true; 01386 } 01387 return false; 01388 } 01389 01390 //==================================== 01391 //getVirtualResolution 01392 //------------------------------------ 01393 QString SaXManipulateDesktop::getVirtualResolution (int color) { 01394 // .../ 01398 // ---- 01399 if ((! mDesktop) || (! mCard) || (! mPath)) { 01400 QString* nope = new QString; 01401 return *nope; 01402 } 01403 QString key; 01404 QString val; 01405 key.sprintf ("Virtual:%d",color); 01406 val = mDesktop -> getItem (key); 01407 if (val.isEmpty()) { 01408 QString* nope = new QString; 01409 return *nope; 01410 } 01411 QStringList resList = QStringList::split ( " ", val ); 01412 QString result (resList.join("x")); 01413 return result; 01414 } 01415 01416 //==================================== 01417 // set monitor record from the CDB 01418 //------------------------------------ 01419 void SaXManipulateDesktop::setCDBMonitor ( const QString& group ) { 01420 // .../ 01424 // ---- 01425 if ( ! mCDBMonitors ) { 01426 mCDBMonitors = new SaXProcess (); 01427 mCDBMonitors -> start (CDB_MONITORS); 01428 } 01429 Q3PtrList< Q3Dict<QString> > data; 01430 data = mCDBMonitors -> getTablePointerCDB_DATA (group); 01431 if (data.isEmpty()) { 01432 excCDBRecordNotFound (group); 01433 qError (errorString(),EXC_CDBRECORDNOTFOUND); 01434 return; 01435 } 01436 QStringList nameList = QStringList::split ( ":", group ); 01437 setMonitorVendor ( nameList.first() ); 01438 setMonitorName ( nameList.last() ); 01439 mDesktop -> merge ( data ); 01440 } 01441 01442 //==================================== 01443 // get list of CDB monitors 01444 //------------------------------------ 01445 QList<QString> SaXManipulateDesktop::getCDBMonitorVendorList ( void ) { 01446 // .../ 01449 // ---- 01450 mCDBMonitorList.clear(); 01451 if ( ! mCDBMonitors ) { 01452 mCDBMonitors = new SaXProcess (); 01453 mCDBMonitors -> start (CDB_MONITORS); 01454 } 01455 Q3Dict< Q3Dict<QString> > CDBData = mCDBMonitors -> getTablePointerCDB (); 01456 Q3DictIterator< Q3Dict<QString> > it (CDBData); 01457 for (; it.current(); ++it) { 01458 QStringList vnlist = QStringList::split ( ":", it.currentKey() ); 01459 QString* vendorName = new QString (vnlist.first()); 01460 int hasVendor = false; 01461 QString io; 01462 foreach(io,mCDBMonitorList) { 01463 if (io == *vendorName ) { 01464 hasVendor = true; 01465 break; 01466 } 01467 } 01468 if (! hasVendor ) { 01469 mCDBMonitorList.append ( *vendorName ); 01470 } 01471 } 01472 return mCDBMonitorList; 01473 } 01474 01475 //==================================== 01476 // get CDB monitor models per vendor 01477 //------------------------------------ 01478 QList<QString> SaXManipulateDesktop::getCDBMonitorModelList ( 01479 const QString& vendor 01480 ) { 01481 // .../ 01484 // ---- 01485 mCDBMonitorList.clear(); 01486 if ( ! mCDBMonitors ) { 01487 mCDBMonitors = new SaXProcess (); 01488 mCDBMonitors -> start (CDB_MONITORS); 01489 } 01490 Q3Dict< Q3Dict<QString> > CDBData = mCDBMonitors -> getTablePointerCDB (); 01491 Q3DictIterator< Q3Dict<QString> > it (CDBData); 01492 for (; it.current(); ++it) { 01493 QStringList vnlist = QStringList::split ( ":", it.currentKey() ); 01494 QString vendorName = vnlist.first(); 01495 QString* modelName = new QString (vnlist.last()); 01496 if ( vendorName == vendor ) { 01497 mCDBMonitorList.append ( *modelName ); 01498 } 01499 } 01500 return mCDBMonitorList; 01501 } 01502 01503 //==================================== 01504 // get data dict for a CDB monitor 01505 //------------------------------------ 01506 Q3Dict<QString> SaXManipulateDesktop::getCDBMonitorData ( 01507 const QString& vendor, const QString& name 01508 ) { 01509 // .../ 01512 // ---- 01513 QString key; 01514 QTextOStream (&key) << vendor << ":" << name; 01515 mCDBMonitorData.clear(); 01516 if ( ! mCDBMonitors ) { 01517 mCDBMonitors = new SaXProcess (); 01518 mCDBMonitors -> start (CDB_MONITORS); 01519 } 01520 Q3Dict< Q3Dict<QString> > CDBData = mCDBMonitors -> getTablePointerCDB (); 01521 Q3DictIterator< Q3Dict<QString> > it (CDBData); 01522 for (; it.current(); ++it) { 01523 if ( it.currentKey() == key ) { 01524 mCDBMonitorData = *it.current(); 01525 break; 01526 } 01527 } 01528 return mCDBMonitorData; 01529 } 01530 //==================================== 01531 // get data dict for a CDB monitor 01532 //------------------------------------ 01533 Q3Dict<QString> SaXManipulateDesktop::getCDBMonitorIDData ( 01534 const QString& id 01535 ) { 01536 // .../ 01539 // ---- 01540 mCDBMonitorData.clear(); 01541 if ( ! mCDBMonitors ) { 01542 mCDBMonitors = new SaXProcess (); 01543 mCDBMonitors -> start (CDB_MONITORS); 01544 } 01545 Q3Dict< Q3Dict<QString> > CDBData = mCDBMonitors -> getTablePointerCDB (); 01546 Q3DictIterator< Q3Dict<QString> > it (CDBData); 01547 bool found = false; 01548 for (; it.current(); ++it) { 01549 mCDBMonitorData = *it.current(); 01550 if ((mCDBMonitorData["DDC"]) && (*mCDBMonitorData["DDC"] == id)) { 01551 mCDBMonitorData.insert ("Name",new QString(it.currentKey())); 01552 found = true; 01553 break; 01554 } 01555 } 01556 if (! found) { 01557 mCDBMonitorData.clear(); 01558 } 01559 return mCDBMonitorData; 01560 } 01561 //==================================== 01562 // add data dict to CDB (temporarly) 01563 //------------------------------------ 01564 void SaXManipulateDesktop::setCDBMonitorData ( 01565 const QString& vendor, const QString& name, 01566 const QString& key, const QString& value 01567 ) { 01568 // .../ 01573 // ---- 01574 QString group; 01575 QTextOStream (&group) << vendor << ":" << name; 01576 if ( ! mCDBMonitors ) { 01577 mCDBMonitors = new SaXProcess (); 01578 mCDBMonitors -> start (CDB_MONITORS); 01579 } 01580 mCDBMonitors -> addGroup ( 01581 group,key,value 01582 ); 01583 } 01584 //==================================== 01585 // getVendorForDriver 01586 //------------------------------------ 01587 QString SaXManipulateDesktop::getVendorForDriver ( const QString& driver ) { 01588 // .../ 01591 // ---- 01592 SaXProcessCall* proc = new SaXProcessCall (); 01593 proc -> addArgument ( SYSP_VENDOR ); 01594 proc -> addArgument ( driver ); 01595 if ( ! proc -> start() ) { 01596 excProcessFailed(); 01597 qError (errorString(),EXC_PROCESSFAILED); 01598 } 01599 QList<QString> data = proc -> readStdout(); 01600 return data.first(); 01601 } 01602 //==================================== 01603 // setExtraModelineString 01604 //------------------------------------ 01605 void SaXManipulateDesktop::setExtraModelineString ( 01606 const QString & mode 01607 ) { 01608 // .../ 01611 // This method should be used carefully 01612 // ---- 01613 if ((! mDesktop) || (! mCard) || (! mPath)) { 01614 return; 01615 } 01616 mDesktop -> setItem ( "SpecialModeline",mode ); 01617 } 01618 //==================================== 01619 // setExtraModeline 01620 //------------------------------------ 01621 void SaXManipulateDesktop::setExtraModeline ( 01622 int x,int y,int refresh,int hsync 01623 ) { 01624 // .../ 01628 // ---- 01629 if ((! mDesktop) || (! mCard) || (! mPath)) { 01630 return; 01631 } 01632 QString mode = calculateModeline ( x,y,refresh,hsync ); 01633 mDesktop -> setItem ( "SpecialModeline",mode ); 01634 } 01635 //==================================== 01636 // addExtraModeline 01637 //------------------------------------ 01638 void SaXManipulateDesktop::addExtraModeline ( 01639 int x,int y,int refresh,int hsync 01640 ) { 01641 // .../ 01645 // ---- 01646 if ((! mDesktop) || (! mCard) || (! mPath)) { 01647 return; 01648 } 01649 QString val; 01650 QString key = "SpecialModeline"; 01651 QString mode = calculateModeline ( x,y,refresh,hsync ); 01652 if (! mDesktop -> getItem (key).isEmpty()) { 01653 val = mDesktop -> getItem (key); 01654 } 01655 QTextOStream (&val) << "," << mode; 01656 val.replace (QRegExp("^,"),""); 01657 mDesktop -> setItem ( key,val ); 01658 } 01659 //==================================== 01660 // removeExtraModeline 01661 //------------------------------------ 01662 void SaXManipulateDesktop::removeExtraModeline ( int x,int y) { 01663 // .../ 01666 // ---- 01667 if ((! mDesktop) || (! mCard) || (! mPath)) { 01668 return; 01669 } 01670 QString val; 01671 QString key = "SpecialModeline"; 01672 val.sprintf ("\"%dx%d\"",x,y); 01673 QString current = mDesktop -> getItem (key); 01674 QStringList lines = QStringList::split ( ",", current ); 01675 for ( 01676 QStringList::Iterator it=lines.begin(); 01677 it != lines.end(); ++it 01678 ) { 01679 QString mode (*it); 01680 if (mode.contains (val)) { 01681 mDesktop -> removeItem (key,mode); 01682 } 01683 } 01684 } 01685 //==================================== 01686 // calculateModeline 01687 //------------------------------------ 01688 QString SaXManipulateDesktop::calculateModeline ( 01689 int x,int y,int refresh,int hsync 01690 ) { 01691 // .../ 01695 // ---- 01696 QString result; 01697 for (int r=refresh;r >= 50;r--) { 01698 SaXProcessCall* proc = new SaXProcessCall (); 01699 proc -> addArgument ( XMODE ); 01700 proc -> addArgument ( "-x" ); 01701 proc -> addArgument ( x ); 01702 proc -> addArgument ( "-y" ); 01703 proc -> addArgument ( y ); 01704 proc -> addArgument ( "-r" ); 01705 proc -> addArgument ( r + 2 ); 01706 if ( ! proc -> start() ) { 01707 excProcessFailed(); 01708 qError (errorString(),EXC_PROCESSFAILED); 01709 } 01710 QList<QString> data = proc->readStdout(); 01711 int hs = data.at(0).toInt(); 01712 result = *data.at(2); 01713 if (hs <= hsync) { 01714 break; 01715 } 01716 } 01717 result.replace (QRegExp("^Modeline "),""); 01718 return result; 01719 } 01720 //==================================== 01721 // getDriverOptionsDualHeadProfile 01722 //------------------------------------ 01723 QString SaXManipulateDesktop::getDriverOptionsDualHeadProfile ( 01724 const QString& driver 01725 ) { 01726 // .../ 01730 // ---- 01731 QString result; 01732 if ((driver == "i810") || (driver == "i915")) { 01733 QTextOStream (&result) 01734 << PROFILE_DIR << "Intel_DualHead_DriverOptions"; 01735 } 01736 if (driver == "intel") { 01737 QTextOStream (&result) 01738 << PROFILE_DIR << "IntelNext_DualHead_DriverOptions"; 01739 } 01740 if (driver == "nvidia") { 01741 QTextOStream (&result) 01742 << PROFILE_DIR << "NVidia_DualHead_DriverOptions"; 01743 } 01744 if (driver == "radeonhd") { 01745 QTextOStream (&result) 01746 << PROFILE_DIR << "RadeonHD_DualHead_DriverOptions"; 01747 } 01748 if (driver == "radeon") { 01749 QTextOStream (&result) 01750 << PROFILE_DIR << "Radeon_DualHead_DriverOptions"; 01751 } 01752 if (driver == "fglrx") { 01753 QTextOStream (&result) 01754 << PROFILE_DIR << "FGLRX_DualHead_DriverOptions"; 01755 } 01756 if (driver == "mga") { 01757 QTextOStream (&result) 01758 << PROFILE_DIR << "Matrox_DualHead_DriverOptions"; 01759 } 01760 if (driver == "sis") { 01761 QTextOStream (&result) 01762 << PROFILE_DIR << "SiS_DualHead_DriverOptions"; 01763 } 01764 return result; 01765 } 01766 //==================================== 01767 // getMetaData 01768 //------------------------------------ 01769 Q3Dict<QString> SaXManipulateDesktop::getMetaData ( void ) { 01770 // .../ 01776 QString cardID; 01777 QTextOStream (&cardID) << mDesktopID; 01778 QList<const char*> metaOptions; 01779 metaOptions.append ((const char*) "-c" ); 01780 metaOptions.append ( (const char*)cardID.latin1() ); 01781 SaXProcess* proc = new SaXProcess (); 01782 proc->start ( metaOptions , SAX_META ); 01783 Q3Dict<QString> metaData = proc->getCurrentTable(); 01784 return metaData; 01785 } 01786 } // end namespace
1.7.3