desktop.cpp

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) << 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         QDict< QDict<QString> > CDBData = CDBCards -> getTablePointerCDB ();
00244         QDict<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.data() );
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                 return QString();
00288         }
00289         //===================================
00290         // Check SaXMeta data...
00291         //-----------------------------------
00292         QDict<QString> metaData = getMetaData();
00293         if (metaData["SAX_NO_CDB_CHECK"]) {
00294                 QString driver  = mCard -> getItem ("Driver");
00295                 QString profile = getDriverOptionsDualHeadProfile ( driver );
00296                 return profile;
00297         }
00298         //====================================
00299         // check special laptop case
00300         //------------------------------------
00301         QString result;
00302         SaXManipulateCard cardInfo (mCard);
00303         if (cardInfo.isNoteBook()) {
00304                 QString driver = mCard -> getItem ("Driver");
00305                 result = getDriverOptionsDualHeadProfile ( driver );
00306                 return result;
00307         }
00308         //====================================
00309         // get sysp card name
00310         //------------------------------------
00311         SaXImportSysp* pCard = new SaXImportSysp (SYSP_CARD);
00312         pCard -> doImport();
00313         if (! pCard -> setID ( mDesktopID )) {
00314                 return QString();
00315         }
00316         QString mCardName;
00317         QTextOStream (&mCardName) <<
00318                 pCard->getItem("Vendor") << ":" << pCard->getItem("Device");
00319         //====================================
00320         // retrieve CDB card list
00321         //------------------------------------
00322         SaXProcess* CDBCards = new SaXProcess ();
00323         CDBCards -> start (CDB_CARDS);
00324         QDict< QDict<QString> > CDBData = CDBCards -> getTablePointerCDB ();
00325         QDict<QString>* cardData = CDBData.find ( mCardName );
00326         if ( cardData ) {
00327                 QString* profile = cardData -> find ("Profile");
00328                 if ((profile) && (profile->contains("DualHead_DriverOptions"))) {
00329                         //====================================
00330                         // check if drivers do match...
00331                         //------------------------------------
00332                         QString syspDriver = pCard -> getItem ("Module");
00333                         QString* CDB2DDriver = cardData -> find ("Driver");
00334                         QString* CDB3DDriver = cardData -> find ("3DDriver");
00335                         if (
00336                                 ((CDB2DDriver) && (syspDriver == *CDB2DDriver)) ||
00337                                 ((CDB3DDriver) && (syspDriver == *CDB2DDriver))
00338                         ) {
00339                                 QTextOStream (&result) << PROFILE_DIR << *profile;
00340                                 return result;
00341                         }
00342                         //====================================
00343                         // drivers don't match check driver...
00344                         //------------------------------------
00345                         result = getDriverOptionsDualHeadProfile ( syspDriver );
00346                         return result;
00347                 }
00348         }
00349         //====================================
00350         // No CDB record found for cardName
00351         //------------------------------------
00352         excEmptyCDBGroup ( mCardName.data() );
00353         qError (errorString(),EXC_EMPTYCDBGROUP);
00354         return QString();
00355 }
00356 
00357 //====================================
00358 // isXineramaMode
00359 //------------------------------------
00360 bool SaXManipulateDesktop::isXineramaMode (void) {
00361         // .../
00362         // check the meta data information if the configuration
00363         // workflow requested to use Xinerama instead of the
00364         // default dual mode workflow based on MergedFB
00365         // ----
00366         QDict<QString> metaData = getMetaData();
00367         if (metaData["SAX_NO_DUAL_MODE"]) {
00368                 return true;
00369         }
00370         return false;
00371 }
00372 
00373 //====================================
00374 // isDualHeadCard
00375 //------------------------------------
00376 bool SaXManipulateDesktop::isDualHeadCard (void) {
00377         // .../
00381         // ----
00382         if ((! mDesktop) || (! mCard) || (! mPath)) {
00383                 return false;
00384         }
00385         //===================================
00386         // Check SaXMeta data...
00387         //-----------------------------------
00388         QDict<QString> metaData = getMetaData();
00389         if (metaData["SAX_NO_CDB_CHECK"]) {
00390                 QString driver  = mCard -> getItem ("Driver");
00391                 QString profile = getDriverOptionsDualHeadProfile ( driver );
00392                 if (! profile.isEmpty()) {
00393                         return true;
00394                 }
00395                 return false;
00396         }
00397         //====================================
00398         // get sysp card name
00399         //------------------------------------
00400         SaXImportSysp* pCard = new SaXImportSysp (SYSP_CARD);
00401         pCard -> doImport();
00402         if (! pCard -> setID ( mDesktopID )) {
00403                 return false;
00404         }
00405         QString mCardName;
00406         QTextOStream (&mCardName) <<
00407                 pCard->getItem("Vendor") << ":" << pCard->getItem("Device");
00408         //====================================
00409         // retrieve CDB card list
00410         //------------------------------------
00411         SaXProcess* CDBCards = new SaXProcess ();
00412         CDBCards -> start (CDB_CARDS);
00413         QDict< QDict<QString> > CDBData = CDBCards -> getTablePointerCDB ();
00414         QDict<QString>* cardData = CDBData.find ( mCardName );
00415         if ( cardData ) {
00416                 QString* profile = cardData -> find ("Profile");
00417                 if ((profile) && (profile->contains("DualHead_DriverOptions"))) {
00418                         //====================================
00419                         // check if drivers do match...
00420                         //------------------------------------
00421                         QString syspDriver = pCard -> getItem ("Module");
00422                         QString* CDB2DDriver = cardData -> find ("Driver");
00423                         QString* CDB3DDriver = cardData -> find ("3DDriver");
00424                         if (
00425                                 ((CDB2DDriver) && (syspDriver != *CDB2DDriver)) &&
00426                                 ((CDB3DDriver) && (syspDriver != *CDB2DDriver))
00427                         ) {
00428                                 *profile = getDriverOptionsDualHeadProfile ( syspDriver );
00429                         }
00430                         if (profile->isEmpty()) {
00431                                 return false;
00432                         }
00433                         //====================================
00434                         // ask profile for changes if dynamic
00435                         //------------------------------------
00436                         SaXProcessCall* proc = new SaXProcessCall ();
00437                         proc -> addArgument ( SAX_PROFILE_CHECK );
00438                         proc -> addArgument ( *profile );
00439                         if ( ! proc -> start() ) {
00440                                 excProcessFailed();
00441                                 qError (errorString(),EXC_PROCESSFAILED);
00442                                 return false;
00443                         }
00444                         if (proc->exitStatus() == 0) {
00445                                 return true;
00446                         }
00447                         return false;
00448                 }
00449                 return false;
00450         }
00451         //====================================
00452         // No CDB record found for cardName
00453         //------------------------------------
00454         excEmptyCDBGroup ( mCardName.data() );
00455         qError (errorString(),EXC_EMPTYCDBGROUP);
00456         return false;
00457 }
00458 
00459 //====================================
00460 // enable3D
00461 //------------------------------------
00462 bool SaXManipulateDesktop::enable3D (void) {
00463         // .../
00472         // ----
00473         if ((! mDesktop) || (! mCard) || (! mPath)) {
00474                 return false;
00475         }
00476         //====================================
00477         // get sysp card name
00478         //------------------------------------
00479         SaXImportSysp* pCard = new SaXImportSysp (SYSP_CARD);
00480         pCard -> doImport();
00481         if (! pCard -> setID ( mDesktopID )) {
00482                 return false;
00483         }
00484         QString mCardName;
00485         QTextOStream (&mCardName) <<
00486                 pCard->getItem("Vendor") << ":" << pCard->getItem("Device");
00487 
00488         //====================================
00489         // retrieve CDB card list
00490         //------------------------------------
00491         SaXProcess* CDBCards = new SaXProcess ();
00492         CDBCards -> start (CDB_CARDS);
00493         QDict< QDict<QString> > CDBData = CDBCards -> getTablePointerCDB ();
00494 
00495         //====================================
00496         // get Extensions for the active card
00497         //------------------------------------
00498         SaXManipulateCard cardInfo (mCard,mDesktopID);
00499         QDict<QString>* cardData = CDBData.find ( mCardName );
00500         if ( cardData ) {
00501                 QString* driver3D= cardData -> find ("3DDriver");
00502                 QString* driver2D= cardData -> find ("Driver");
00503                 QString* extends = cardData -> find ("Extension");
00504                 QString* flag    = cardData -> find ("Flag");
00505                 //========================================
00506                 // check 3D flag
00507                 //----------------------------------------
00508                 if (! flag) {
00509                         return false;
00510                 }               
00511                 //========================================
00512                 // nvidia drv. needed, check if installed
00513                 //----------------------------------------
00514                 if ((driver3D) && (*driver3D == "nvidia")) {
00515                         bool foundBinaryNVidiaDriver = false;
00516                         if ((getVendorForDriver(*driver3D)) == "NVIDIA Corporation") {
00517                                 foundBinaryNVidiaDriver = true;
00518                         }
00519                         if (! foundBinaryNVidiaDriver) {
00520                                 excNvidiaDriverMissing();
00521                                 qError (errorString(),EXC_NVIDIADRIVERMISSING);
00522                                 return false;
00523                         }
00524                 }
00525                 //========================================
00526                 // have extension, add it
00527                 //----------------------------------------
00528                 if (extends) {
00529                         SaXManipulatePath pathInfo (mPath);
00530                         pathInfo.removeLoadableModule (*extends);
00531                         pathInfo.addLoadableModule (*extends);
00532                 }
00533                 //========================================
00534                 // set driver to use with 3D
00535                 //----------------------------------------
00536                 if (driver3D) {
00537                         QString currentDriver = cardInfo.getCardDriver();
00538                         if ((currentDriver != *driver3D) && (currentDriver != *driver2D)) {
00539                                 excDriverMismatch (driver3D->ascii(),currentDriver.ascii());
00540                                 qError (errorString(),EXC_DRIVERMISMATCH);
00541                         } else {
00542                                 cardInfo.setCardDriver (*driver3D);
00543                         }
00544                 }
00545         }
00546         //====================================
00547         // Import profiles if there are any
00548         //------------------------------------
00549         if (cardData) {
00550                 QStringList profiles;
00551                 QString* profile3D = cardData -> find ("3DProfile");
00552                 QString* driver3D  = cardData -> find ("3DDriver");
00553                 QString* driver2D  = cardData -> find ("Driver");
00554                 if ((profile3D) && (! profile3D->contains("DualHead"))) {
00555                         profiles += *profile3D;
00556                 }
00557                 if ((driver3D) && (*driver2D != *driver3D)) {
00558                         SaXFile mapHandle (MAP_DIR + QString("Driver.map"));
00559                         QDict<QString> driverMap = mapHandle.readDict();
00560                         QString driver = cardInfo.getCardDriver();
00561                         if ((! driver.isEmpty()) && (driverMap[driver])) {
00562                                 QStringList items = QStringList::split ( ",", *driverMap[driver] );
00563                                 profiles += items;
00564                         }
00565                 }
00566                 for (
00567                         QStringList::Iterator it=profiles.begin();
00568                         it != profiles.end(); ++it
00569                 ) {
00570                         QString profile (*it);
00571                         SaXImportProfile* pProfile = new SaXImportProfile (
00572                                 PROFILE_DIR + profile
00573                         );
00574                         pProfile -> doImport();
00575                         //====================================
00576                         // handle Card Options
00577                         //------------------------------------
00578                         SaXImport* mImportCard = pProfile -> getImport ( SAX_CARD );
00579                         if ( mImportCard ) {
00580                                 QDict<QString> profileDriverOptions;
00581                                 SaXManipulateCard saxProfileCard ( mImportCard );
00582                                 profileDriverOptions = saxProfileCard.getOptions();
00583                                 QDictIterator<QString> it ( profileDriverOptions );
00584                                 for (; it.current(); ++it) {
00585                                         QString key = it.currentKey();
00586                                         QString val = *it.current();
00587                                         cardInfo.addCardOption (key,val);
00588                                 }
00589                         }
00590                         //====================================
00591                         // handle Desktop Options
00592                         //------------------------------------
00593                         SaXImport* mImportDesktop = pProfile -> getImport ( SAX_DESKTOP );
00594                         if ( mImportDesktop ) {
00595                                 QDict<QString> profileDriverOptions;
00596                                 SaXManipulateDesktop saxProfileDesktop (
00597                                         mImportDesktop,mCard,mPath
00598                                 );
00599                                 //====================================
00600                                 // Colordepth...
00601                                 //------------------------------------
00602                                 QString color = saxProfileDesktop.getColorDepth();
00603                                 if (! color.isEmpty()) {
00604                                         setColorDepth (color.toInt());
00605                                 }
00606                         }
00607                 }
00608                 return true;
00609         }
00610         //====================================
00611         // No CDB record found for mCardName
00612         //------------------------------------
00613         excEmptyCDBGroup ( mCardName.data() );
00614         qError (errorString(),EXC_EMPTYCDBGROUP);
00615         return false;
00616 }
00617 
00618 //====================================
00619 // disable3D
00620 //------------------------------------
00621 bool SaXManipulateDesktop::disable3D (void) {
00622         // ....
00628         // ----
00629         if ((! mDesktop) || (! mCard) || (! mPath)) {
00630                 return false;
00631         }
00632         //====================================
00633         // get sysp card name
00634         //------------------------------------
00635         SaXImportSysp* pCard = new SaXImportSysp (SYSP_CARD);
00636         pCard -> doImport();
00637         if (! pCard -> setID ( mDesktopID )) {
00638                 return false;
00639         }
00640         QString mCardName;
00641         QTextOStream (&mCardName) <<
00642                 pCard->getItem("Vendor") << ":" << pCard->getItem("Device");
00643 
00644         //====================================
00645         // retrieve CDB card list
00646         //------------------------------------
00647         SaXProcess* CDBCards = new SaXProcess ();
00648         CDBCards -> start (CDB_CARDS);
00649         QDict< QDict<QString> > CDBData = CDBCards -> getTablePointerCDB ();
00650 
00651         //====================================
00652         // get Extensions for the active card
00653         //------------------------------------
00654         SaXManipulateCard cardInfo (mCard);
00655         QDict<QString>* cardData = CDBData.find ( mCardName );
00656         if ( cardData ) {
00657                 QString* driver3D= cardData -> find ("3DDriver");
00658                 QString* driver2D= cardData -> find ("Driver");
00659                 QString* extends = cardData -> find ("Extension");
00660                 QString* flag    = cardData -> find ("Flag");
00661                 //========================================
00662                 // check 3D flag
00663                 //----------------------------------------
00664                 if (! flag) {
00665                         return false;
00666                 }
00667                 //========================================
00668                 // nvidia drv. needed, check if installed
00669                 //----------------------------------------
00670                 if ((driver3D) && (*driver3D == "nvidia")) {
00671                         if ((getVendorForDriver(*driver3D)) == "NVIDIA Corporation") {
00672                                 excNvidiaDriverInstalled();
00673                                 qError (errorString(),EXC_NVIDIADRIVERINSTALLED);
00674                                 return false;
00675                         }
00676                 }
00677                 //========================================
00678                 // have extension, remove it
00679                 //----------------------------------------
00680                 if (extends) {
00681                         SaXManipulatePath pathInfo (mPath);
00682                         pathInfo.removeLoadableModule (*extends);
00683                 }
00684                 //========================================
00685                 // set driver to use with 2D
00686                 //----------------------------------------
00687                 if ((driver2D) && (driver3D)) {
00688                         QString currentDriver = cardInfo.getCardDriver();
00689                         if ((currentDriver != *driver3D) && (currentDriver != *driver2D)) {
00690                                 excDriverMismatch (driver2D->ascii(),currentDriver.ascii());
00691                                 qError (errorString(),EXC_DRIVERMISMATCH);
00692                         } else {
00693                                 cardInfo.setCardDriver (*driver2D);
00694                         }
00695                 }
00696         }
00697         //====================================
00698         // Reset profiles if there are any
00699         //------------------------------------
00700         if (cardData) {
00701                 QStringList profiles;
00702                 QString* profile3D = cardData -> find ("3DProfile");
00703                 QString* driver3D  = cardData -> find ("3DDriver");
00704                 QString* driver2D  = cardData -> find ("Driver");
00705                 if ((profile3D) && (! profile3D->contains("DualHead"))) {
00706                         profiles += *profile3D;
00707                 }
00708                 if ((driver3D) && (*driver2D != *driver3D)) {
00709                         SaXFile mapHandle (MAP_DIR + QString("Driver.map"));
00710                         QDict<QString> driverMap = mapHandle.readDict();
00711                         if ((driver3D) && (driverMap[*driver3D])) {
00712                                 QStringList items = QStringList::split ( ",",*driverMap[*driver3D] );
00713                                 profiles += items;
00714                         }
00715                 }
00716                 for (
00717                         QStringList::Iterator it=profiles.begin();
00718                         it != profiles.end(); ++it
00719                 ) {
00720                         QString profile (*it);
00721                         SaXImportProfile* pProfile = new SaXImportProfile (
00722                                 PROFILE_DIR + profile
00723                         );
00724                         pProfile -> doImport();
00725                         //====================================
00726                         // remove Card Options
00727                         //------------------------------------
00728                         SaXImport* mImportCard = pProfile -> getImport ( SAX_CARD );
00729                         if ( mImportCard ) {
00730                                 QDict<QString> profileDriverOptions;
00731                                 SaXManipulateCard saxProfileCard ( mImportCard );
00732                                 profileDriverOptions = saxProfileCard.getOptions();
00733                                 QDictIterator<QString> it ( profileDriverOptions );
00734                                 for (; it.current(); ++it) {
00735                                         QString key = it.currentKey();
00736                                         cardInfo.removeCardOption (key);
00737                                 }
00738                         }
00739                 }
00740                 return true;
00741         }
00742         //====================================
00743         // No CDB record found for mCardName
00744         //------------------------------------
00745         excEmptyCDBGroup ( mCardName.data() );
00746         qError (errorString(),EXC_EMPTYCDBGROUP);
00747         return false;
00748 }
00749 
00750 //====================================
00751 // setDisplaySize
00752 //------------------------------------
00753 void SaXManipulateDesktop::setDisplaySize (int width,int height) {
00754         // .../
00757         // ----
00758         if ((! mDesktop) || (! mCard) || (! mPath)) {
00759                 return;
00760         }
00761         QString size;
00762         size.sprintf ("%d %d",width,height);
00763         mDesktop -> setItem ( "DisplaySize",size );
00764 }
00765 
00766 //====================================
00767 // setDisplayRatioAndTraversal
00768 //------------------------------------
00769 void SaXManipulateDesktop::setDisplayRatioAndTraversal (
00770         double traversal,int aspect, int ratio
00771 ) {
00772         // .../
00775         // ----
00776         if ((! mDesktop) || (! mCard) || (! mPath)) {
00777                 return;
00778         }
00779         traversal = traversal * 25.4;
00780         double ar = (double)aspect / (double)ratio;
00781         double y = sqrt ( (traversal * traversal) / (ar * ar + 1.0) );
00782         double x = ar * y;
00783         setDisplaySize (
00784                 (int)(round(x)),(int)(round(y))
00785         );
00786 }
00787 
00788 //====================================
00789 // setHsyncRange
00790 //------------------------------------
00791 void SaXManipulateDesktop::setHsyncRange (double hsmin,double hsmax) {
00792         // .../
00795         // ----
00796         if ((! mDesktop) || (! mCard) || (! mPath)) {
00797                 return;
00798         }
00799         QString range;
00800         range.sprintf ("%.0f-%.0f",hsmin,hsmax);
00801         mDesktop -> setItem ( "HorizSync",range );
00802 }
00803 
00804 //====================================
00805 // setVsyncRange
00806 //------------------------------------
00807 void SaXManipulateDesktop::setVsyncRange (double vsmin,double vsmax) {
00808         // .../
00811         // ----
00812         if ((! mDesktop) || (! mCard) || (! mPath)) {
00813                 return;
00814         }
00815         QString range;
00816         range.sprintf ("%.0f-%.0f",vsmin,vsmax);
00817         mDesktop -> setItem ( "VertRefresh",range );
00818 }
00819 
00820 //====================================
00821 // enableDPMS
00822 //------------------------------------
00823 void SaXManipulateDesktop::enableDPMS (void) {
00824         // .../
00828         // ----
00829         if ((! mDesktop) || (! mCard) || (! mPath)) {
00830                 return;
00831     }
00832         mDesktop -> setItem ( "MonitorOptions","DPMS" );
00833 }
00834 
00835 //====================================
00836 // disableDPMS
00837 //------------------------------------
00838 void SaXManipulateDesktop::disableDPMS (void) {
00839         // .../
00842         // ----
00843         if ((! mDesktop) || (! mCard) || (! mPath)) {
00844                 return;
00845         }
00846         mDesktop -> setItem ( "MonitorOptions","" );
00847 }
00848 
00849 //====================================
00850 // setMonitorVendor
00851 //------------------------------------
00852 void SaXManipulateDesktop::setMonitorVendor (const QString& vendor) {
00853         // .../
00856         // ----
00857         if ((! mDesktop) || (! mCard) || (! mPath)) {
00858                 return;
00859         }
00860         mDesktop -> setItem ( "VendorName",vendor );
00861 }
00862 
00863 //====================================
00864 // setMonitorName
00865 //------------------------------------
00866 void SaXManipulateDesktop::setMonitorName (const QString& name) {
00867         // .../
00870         // ----
00871         if ((! mDesktop) || (! mCard) || (! mPath)) {
00872                 return;
00873         }
00874         mDesktop -> setItem ( "ModelName",name );
00875 }
00876 
00877 //====================================
00878 // is3DEnabled
00879 //------------------------------------
00880 bool SaXManipulateDesktop::is3DEnabled (void) {
00881         // .../
00886         // ----
00887         if ((! mDesktop) || (! mCard) || (! mPath)) {
00888                 return false;
00889         }
00890         if ( mCard -> getCount() > 1 ) {
00891                 return false;
00892         }
00893         QString driver = mCard -> getItem ("Driver");
00894         if (driver == "nvidia") {
00895                 QString vendor = getVendorForDriver ( driver );
00896                 if (vendor == "NVIDIA Corporation") {
00897                         return true;
00898                 }
00899                 return false;
00900         }
00901         SaXManipulatePath pathInfo (mPath);
00902         QList<QString> modules = pathInfo.getModules();
00903         QListIterator<QString> it (modules);
00904         for (; it.current();++it) {
00905         if (*it.current() == "dri") {
00906                 return true;
00907         }
00908         }
00909         return false;
00910 }
00911 
00912 //====================================
00913 // getResolutions
00914 //------------------------------------
00915 QList<QString> SaXManipulateDesktop::getResolutions (int color) {
00916         // .../
00920         // ----
00921         if ((! mDesktop) || (! mCard) || (! mPath)) {
00922                 return QList<QString>();
00923         }
00924         QString modes;
00925         modes.sprintf ("Modes:%d",color);
00926         QString resolutions = mDesktop -> getItem (modes);
00927         if (resolutions.isEmpty()) {
00928                 return QList<QString>();
00929         }
00930         QList<QString> result;
00931         QStringList resList = QStringList::split ( ",", resolutions );
00932         for (QStringList::Iterator it=resList.begin(); it!=resList.end();++ it) {
00933                 QString* data = new QString (*it);
00934                 result.append (data);
00935         }
00936         return result;
00937 }
00938 
00939 //====================================
00940 // getResolutionsFromServer
00941 //------------------------------------
00942 QList<QString> SaXManipulateDesktop::getResolutionFromServer ( void ) {
00943         // .../
00948         // ----
00949         if ((! mDesktop) || (! mCard) || (! mPath)) {
00950                 return QList<QString>();
00951         }
00952         QList<QString> defaultList;
00953         defaultList.append (new QString("800x600"));
00954         SaXProcessCall* proc = new SaXProcessCall();
00955         proc -> addArgument ( XQUERY );
00956         proc -> addArgument ( "-r" );
00957         if ( ! proc -> start() ) {
00958                 return defaultList;
00959         }
00960         QList<QString> data = proc->readStdout();
00961         QListIterator<QString> in (data);
00962         for (; in.current(); ++in) {
00963                 QRegExp modeExp ("(\\d+) (.*)");
00964                 int rpos = modeExp.search (*in.current(),0);
00965                 if (rpos >= 0) {
00966                         int id = modeExp.cap(1).toInt();
00967                         if (id == mDesktopID) {
00968                                 QList<QString> result;
00969                                 result.append (new QString (modeExp.cap(2)));
00970                                 return result;
00971                         }
00972                 }
00973         }
00974         return defaultList;
00975 }
00976 
00977 //====================================
00978 // getColorDepthFromServer
00979 //------------------------------------
00980 int SaXManipulateDesktop::getColorDepthFromServer (void) {
00981         Display* dpy = XOpenDisplay (0);
00982         return DisplayPlanes( dpy,0 );
00983 }
00984 
00985 //====================================
00986 // getFBKernelMode
00987 //------------------------------------
00988 int SaXManipulateDesktop::getFBKernelMode (const QString& res,int depth) {
00989         if (! mSyspDesktop) {
00990                 mSyspDesktop = new SaXImportSysp (SYSP_DESKTOP);
00991         }
00992         mSyspDesktop -> setID    ( mDesktopID );
00993         mSyspDesktop -> doImport ();
00994         if (! mSyspDesktop->getItem("FBBoot")) {
00995                 return 0;
00996         }
00997         QString val = mSyspDesktop->getItem("FBBoot");
00998         QStringList items = QStringList::split ( ",", val );
00999         for (
01000                 QStringList::Iterator it=items.begin();
01001                 it != items.end(); ++it
01002         ) {
01003                 QString* resolution = new QString();
01004                 QString mode (*it);
01005                 QStringList record = QStringList::split ( " ", mode );
01006                 QTextOStream (resolution) << *record.at(0) << "x" << *record.at(1);
01007                 QString color = *record.at(2);
01008                 if ((*resolution == res) && (color.toInt() == depth)) {
01009                         QString mode = *record.at(3);
01010                         return mode.toInt();
01011                 }
01012         }
01013         return 0;
01014 }
01015 
01016 //====================================
01017 // setFBKernelMode
01018 //------------------------------------
01019 int SaXManipulateDesktop::setFBKernelMode (int mode) {
01020         QString* modeString = new QString();
01021         QTextOStream (modeString) << mode;
01022         SaXProcessCall* proc = new SaXProcessCall ();
01023         proc -> addArgument ( SAX_GRUB_UPDATE );
01024         proc -> addArgument ( *modeString );
01025         if ( ! proc -> start() ) {
01026                 excProcessFailed();
01027                 qError (errorString(),EXC_PROCESSFAILED);
01028                 return false;
01029         }
01030         if (proc->exitStatus() == 0) {
01031                 return true;
01032         }
01033         return false;
01034 }
01035 
01036 //====================================
01037 // getResolutionsFromDDC
01038 //------------------------------------
01039 QList<QString> SaXManipulateDesktop::getResolutionsFromDDC (const QString& key) {
01040         QList<QString> result;
01041         QDict<QString> hashed;
01042         SaXImportSysp* desktop = new SaXImportSysp (SYSP_DESKTOP);
01043         desktop -> setID    ( mDesktopID );
01044         desktop -> doImport ();
01045         if (! desktop->getItem(key)) {
01046                 return QList<QString>();
01047         }
01048         if (desktop->getItem("DDC") == "<undefined>") {
01049                 return QList<QString>();
01050         }
01051         QString val = desktop->getItem(key);
01052         QStringList items = QStringList::split ( ",", val );
01053         for (
01054                 QStringList::Iterator it=items.begin();
01055                 it != items.end(); ++it
01056         ) {
01057                 QString* data = new QString();
01058                 QString mode (*it);
01059                 QStringList resolution = QStringList::split ( " ", mode );
01060                 QTextOStream (data) << *resolution.at(0) << "x" << *resolution.at(1);
01061                 if (! hashed[*data]) {
01062                         hashed.insert (*data,data);
01063                 }
01064         }
01065         QString* default1 = new QString ("800x600");
01066         QString* default2 = new QString ("1024x768");
01067         hashed.insert (*default1,default1);
01068         hashed.insert (*default2,default2);
01069         QDictIterator<QString> ir (hashed);
01070         for (; ir.current(); ++ir) {
01071                 result.append (ir.current());
01072         }
01073         return result;
01074 }
01075 
01076 //====================================
01077 // getResolutionsFromDDC1
01078 //------------------------------------
01079 QList<QString> SaXManipulateDesktop::getResolutionsFromDDC1 (void) {
01080         return getResolutionsFromDDC ("Vesa");
01081 }
01082 
01083 //====================================
01084 // getResolutionsFromDDC2
01085 //------------------------------------
01086 QList<QString> SaXManipulateDesktop::getResolutionsFromDDC2 (void) {
01087         return getResolutionsFromDDC ("Vesa[2]");
01088 }
01089 
01090 //====================================
01091 // getResolutionsFromFrameBuffer
01092 //------------------------------------
01093 QList<QString> SaXManipulateDesktop::getResolutionsFromFrameBuffer (void) {
01094         return getResolutionsFromDDC ("FBBoot");
01095 }
01096 
01097 //====================================
01098 // getDisplaySize
01099 //------------------------------------
01100 QList<QString> SaXManipulateDesktop::getDisplaySize (void) {
01101         // .../
01107         // ----
01108         if ((! mDesktop) || (! mCard) || (! mPath)) {
01109                 return QList<QString>();
01110         }
01111         QString size = mDesktop -> getItem ("DisplaySize");
01112         if (size.isEmpty()) {
01113                 return QList<QString>();
01114         }
01115         QList<QString> result;
01116         QStringList sizeList = QStringList::split ( " ", size );
01117         result.append (
01118                 new QString(sizeList.first())
01119         );
01120         result.append (
01121                 new QString(sizeList.last())
01122         );
01123         return result;
01124 }
01125 
01126 //====================================
01127 // getDisplayTraversal
01128 //------------------------------------
01129 QString SaXManipulateDesktop::getDisplayTraversal (void) {
01130         // .../
01133         // ----
01134         if ((! mDesktop) || (! mCard) || (! mPath)) {
01135                 return QString();
01136         }
01137         QList<QString> size = getDisplaySize();
01138         if (size.isEmpty()) {
01139                 return QString();
01140         }
01141         int x = size.at(0)->toInt();
01142         int y = size.at(1)->toInt();
01143         double traversal = sqrt (x*x + y*y) / 25.4;
01144         QString result;
01145         QTextOStream (&result) << traversal;
01146         return result;
01147 }
01148 
01149 //====================================
01150 // getDisplayRatio
01151 //------------------------------------
01152 QList<QString> SaXManipulateDesktop::getDisplayRatio (void) {
01153         // .../
01156         // ----
01157         if ((! mDesktop) || (! mCard) || (! mPath)) {
01158                 return QList<QString>();
01159         }
01160         QString* setX = new QString ("4");
01161         QString* setY = new QString ("3");
01162         QList<QString> result;
01163         QList<QString> size = getDisplaySize();
01164         if (size.isEmpty()) {
01165                 return QList<QString>();
01166         }
01167         int x = size.at(0)->toInt();
01168         int y = size.at(1)->toInt();
01169         double ar = (double)x / (double)y;
01170         if ( ar > 1.4 ) {
01171                 *setX = "16";
01172                 *setY = "10";
01173         } else if (( ar <= 1.4 ) && ( ar > 1.3 )) {
01174                 *setX = "4";
01175                 *setY = "3";
01176         } else if ( ar <= 1.3 ) {
01177                 *setX = "5";
01178                 *setY = "4";
01179         }
01180         result.append (setX);
01181         result.append (setY);
01182         return result;
01183 }
01184 
01185 //====================================
01186 // getHsyncRange
01187 //------------------------------------
01188 QList<QString> SaXManipulateDesktop::getHsyncRange (void) {
01189         // .../
01193         // ----
01194         if ((! mDesktop) || (! mCard) || (! mPath)) {
01195                 return QList<QString>();
01196         }
01197         QString range = mDesktop -> getItem ("HorizSync");
01198         if (range.isEmpty()) {
01199                 return QList<QString>();
01200         }
01201         QList<QString> result;
01202         QStringList rangeList = QStringList::split ( "-", range );
01203         result.append (
01204                 new QString(rangeList.first())
01205         );
01206         result.append (
01207                 new QString(rangeList.last())
01208         );
01209         return result;
01210 }
01211 
01212 //====================================
01213 // getVsyncRange
01214 //------------------------------------
01215 QList<QString> SaXManipulateDesktop::getVsyncRange (void) {
01216         // .../
01220         // ----
01221         if ((! mDesktop) || (! mCard) || (! mPath)) {
01222                 return QList<QString>();
01223         }
01224         QString range = mDesktop -> getItem ("VertRefresh");
01225         if (range.isEmpty()) {
01226                 return QList<QString>();
01227         }
01228         QList<QString> result;
01229         QStringList rangeList = QStringList::split ( "-", range );
01230         result.append (
01231                 new QString(rangeList.first())
01232         );
01233         result.append (
01234                 new QString(rangeList.last())
01235         );
01236         return result;
01237 }
01238 
01239 //====================================
01240 // DPMSEnabled
01241 //------------------------------------
01242 bool SaXManipulateDesktop::DPMSEnabled (void) {
01243         // .../
01247         // ----
01248         if ((! mDesktop) || (! mCard) || (! mPath)) {
01249                 return false;
01250         }
01251         QString options = mDesktop -> getItem ("MonitorOptions");
01252         if (options == "DPMS") {
01253                 return true;
01254         }
01255         return false;
01256 }
01257 
01258 //====================================
01259 // getMonitorVendor
01260 //------------------------------------
01261 QString SaXManipulateDesktop::getMonitorVendor (void) {
01262         // .../
01265         // ----
01266         if ((! mDesktop) || (! mCard) || (! mPath)) {
01267                 return QString();
01268         }
01269         return mDesktop -> getItem ("VendorName");
01270 }
01271 
01272 //====================================
01273 // getMonitorName
01274 //------------------------------------
01275 QString SaXManipulateDesktop::getMonitorName (void) {
01276         // .../
01279         // ----
01280         if ((! mDesktop) || (! mCard) || (! mPath)) {
01281                 return QString();
01282         }
01283         return mDesktop -> getItem ("ModelName");
01284 }
01285 
01286 //====================================
01287 // getColorDepth
01288 //------------------------------------
01289 QString SaXManipulateDesktop::getColorDepth (void) {
01290         // .../
01293         // ----
01294         if ((! mDesktop) || (! mCard) || (! mPath)) {
01295                 return QString();
01296         }
01297         return mDesktop -> getItem ("ColorDepth");
01298 }
01299 
01300 //====================================
01301 // getModelineAlgorithm
01302 //------------------------------------
01303 QString SaXManipulateDesktop::getModelineAlgorithm (void) {
01304         // .../
01306         // ----
01307         if ((! mDesktop) || (! mCard) || (! mPath)) {
01308                 return QString();
01309         }
01310         return mDesktop -> getItem ("CalcAlgorithm");
01311 }
01312 
01313 //====================================
01314 // willCalculateModelines
01315 //------------------------------------
01316 bool SaXManipulateDesktop::willCalculateModelines (void) {
01317         // .../
01320         // ----
01321         if ((! mDesktop) || (! mCard) || (! mPath)) {
01322                 return false;
01323         }
01324         QString calculate = mDesktop -> getItem ("CalcModelines");
01325         if ((calculate == "on") || (calculate == "yes")) {
01326                 return true;
01327         }
01328         return false;
01329 }
01330 
01331 //====================================
01332 //getVirtualResolution
01333 //------------------------------------
01334 QString SaXManipulateDesktop::getVirtualResolution (int color) {
01335         // .../
01339         // ----
01340         if ((! mDesktop) || (! mCard) || (! mPath)) {
01341                 return QString();
01342         }
01343         QString key;
01344         QString val;
01345         key.sprintf ("Virtual:%d",color);
01346         val = mDesktop -> getItem (key);
01347         if (val.isEmpty()) {
01348                 return QString();
01349         }
01350         QStringList resList = QStringList::split ( " ", val );
01351         QString result (resList.join("x"));
01352         return result;
01353 }
01354 
01355 //====================================
01356 // set monitor record from the CDB
01357 //------------------------------------
01358 void SaXManipulateDesktop::setCDBMonitor ( const QString& group ) {
01359         // .../
01363         // ----
01364         if ( ! mCDBMonitors ) {
01365                 mCDBMonitors = new SaXProcess ();
01366                 mCDBMonitors -> start (CDB_MONITORS);
01367         }
01368         QList< QDict<QString> > data;
01369         data = mCDBMonitors -> getTablePointerCDB_DATA (
01370                 group
01371         );
01372         if (data.isEmpty()) {
01373                 excCDBRecordNotFound (group);
01374                 qError (errorString(),EXC_CDBRECORDNOTFOUND);
01375                 return;
01376         }
01377         QStringList nameList = QStringList::split ( ":", group );
01378         setMonitorVendor ( nameList.first() );
01379         setMonitorName   ( nameList.last() );
01380         mDesktop -> merge ( data );
01381 }
01382 
01383 //====================================
01384 // get list of CDB monitors
01385 //------------------------------------
01386 QList<QString> SaXManipulateDesktop::getCDBMonitorVendorList ( void ) {
01387         // .../
01390         // ----
01391         mCDBMonitorList.clear();
01392         if ( ! mCDBMonitors ) {
01393                 mCDBMonitors = new SaXProcess ();
01394                 mCDBMonitors -> start (CDB_MONITORS);
01395         }
01396         QDict< QDict<QString> > CDBData = mCDBMonitors -> getTablePointerCDB ();
01397         QDictIterator< QDict<QString> > it (CDBData);
01398         for (; it.current(); ++it) {
01399                 QStringList vnlist = QStringList::split ( ":", it.currentKey() );
01400                 QString* vendorName = new QString (vnlist.first());
01401                 int hasVendor = false;
01402                 QListIterator<QString> io (mCDBMonitorList);
01403                 for (; io.current(); ++io) {
01404                 if ( *io.current() == *vendorName ) {
01405                         hasVendor = true;
01406                         break;
01407                 }
01408                 }
01409                 if (! hasVendor ) {
01410                         mCDBMonitorList.append ( vendorName );
01411                 }
01412         }
01413         return mCDBMonitorList;
01414 }
01415 
01416 //====================================
01417 // get CDB monitor models per vendor
01418 //------------------------------------
01419 QList<QString> SaXManipulateDesktop::getCDBMonitorModelList (
01420         const QString& vendor
01421 ) {
01422         // .../
01425         // ----
01426         mCDBMonitorList.clear();
01427         if ( ! mCDBMonitors ) {
01428                 mCDBMonitors = new SaXProcess ();
01429                 mCDBMonitors -> start (CDB_MONITORS);
01430         }
01431         QDict< QDict<QString> > CDBData = mCDBMonitors -> getTablePointerCDB ();
01432         QDictIterator< QDict<QString> > it (CDBData);
01433         for (; it.current(); ++it) {
01434                 QStringList vnlist = QStringList::split ( ":", it.currentKey() );
01435                 QString vendorName = vnlist.first();
01436                 QString* modelName = new QString (vnlist.last());
01437                 if ( vendorName == vendor ) {
01438                         mCDBMonitorList.append ( modelName );
01439                 }
01440         }
01441         return mCDBMonitorList;
01442 }
01443 
01444 //====================================
01445 // get data dict for a CDB monitor
01446 //------------------------------------
01447 QDict<QString> SaXManipulateDesktop::getCDBMonitorData (
01448         const QString& vendor, const QString& name
01449 ) {
01450         // .../
01453         // ----
01454         QString key;
01455         QTextOStream (&key) << vendor << ":" << name;
01456         mCDBMonitorData.clear();
01457         if ( ! mCDBMonitors ) {
01458                 mCDBMonitors = new SaXProcess ();
01459                 mCDBMonitors -> start (CDB_MONITORS);
01460         }
01461         QDict< QDict<QString> > CDBData = mCDBMonitors -> getTablePointerCDB ();
01462         QDictIterator< QDict<QString> > it (CDBData);
01463         for (; it.current(); ++it) {
01464                 if ( it.currentKey() == key ) {
01465                         mCDBMonitorData = *it.current();
01466                         break;
01467                 }
01468         }
01469         return mCDBMonitorData;
01470 }
01471 //====================================
01472 // get data dict for a CDB monitor
01473 //------------------------------------
01474 QDict<QString> SaXManipulateDesktop::getCDBMonitorIDData (
01475         const QString& id
01476 ) {
01477         // .../
01480         // ----
01481         mCDBMonitorData.clear();
01482         if ( ! mCDBMonitors ) {
01483                 mCDBMonitors = new SaXProcess ();
01484                 mCDBMonitors -> start (CDB_MONITORS);
01485         }
01486         QDict< QDict<QString> > CDBData = mCDBMonitors -> getTablePointerCDB ();
01487         QDictIterator< QDict<QString> > it (CDBData);
01488         bool found = false;
01489         for (; it.current(); ++it) {
01490                 mCDBMonitorData = *it.current();
01491                 if ((mCDBMonitorData["DDC"]) && (*mCDBMonitorData["DDC"] == id)) {
01492                         mCDBMonitorData.insert ("Name",new QString(it.currentKey()));
01493                         found = true;
01494                         break;
01495                 }
01496         }
01497         if (! found) {
01498                 mCDBMonitorData.clear();
01499         }
01500         return mCDBMonitorData;
01501 }
01502 //====================================
01503 // add data dict to CDB (temporarly)
01504 //------------------------------------
01505 void SaXManipulateDesktop::setCDBMonitorData (
01506         const QString& vendor, const QString& name,
01507         const QString& key, const QString& value
01508 ) {
01509         // .../
01514         // ----
01515         QString group;
01516         QTextOStream (&group) << vendor << ":" << name;
01517         if ( ! mCDBMonitors ) {
01518                 mCDBMonitors = new SaXProcess ();
01519                 mCDBMonitors -> start (CDB_MONITORS);
01520         }
01521         mCDBMonitors -> addGroup (
01522                 group,key,value
01523         );
01524 }
01525 //====================================
01526 // getVendorForDriver
01527 //------------------------------------
01528 QString SaXManipulateDesktop::getVendorForDriver ( const QString& driver ) {
01529         // .../
01532         // ----
01533         SaXProcessCall* proc = new SaXProcessCall ();
01534         proc -> addArgument ( SYSP_VENDOR );
01535         proc -> addArgument ( driver );
01536         if ( ! proc -> start() ) {
01537                 excProcessFailed();
01538                 qError (errorString(),EXC_PROCESSFAILED);
01539         }
01540         QList<QString> data = proc -> readStdout();
01541         return *data.first();
01542 }
01543 //====================================
01544 // setExtraModelineString
01545 //------------------------------------
01546 void SaXManipulateDesktop::setExtraModelineString (
01547         const QString & mode
01548 ) {
01549         // .../
01552         // This method should be used carefully
01553         // ----
01554         if ((! mDesktop) || (! mCard) || (! mPath)) {
01555                 return;
01556         }
01557         mDesktop -> setItem ( "SpecialModeline",mode );
01558 }
01559 //====================================
01560 // setExtraModeline
01561 //------------------------------------
01562 void SaXManipulateDesktop::setExtraModeline (
01563         int x,int y,int refresh,int hsync
01564 ) {
01565         // .../
01569         // ----
01570         if ((! mDesktop) || (! mCard) || (! mPath)) {
01571                 return;
01572         }
01573         QString mode = calculateModeline ( x,y,refresh,hsync );
01574         mDesktop -> setItem ( "SpecialModeline",mode );
01575 }
01576 //====================================
01577 // addExtraModeline
01578 //------------------------------------
01579 void SaXManipulateDesktop::addExtraModeline (
01580         int x,int y,int refresh,int hsync
01581 ) {
01582         // .../
01586         // ----
01587         if ((! mDesktop) || (! mCard) || (! mPath)) {
01588                 return;
01589         }
01590         QString val;
01591         QString key = "SpecialModeline";
01592         QString mode = calculateModeline ( x,y,refresh,hsync );
01593         if (! mDesktop -> getItem (key).isEmpty()) {
01594                 val = mDesktop -> getItem (key);
01595         }
01596         QTextOStream (&val) << val << "," << mode;
01597         val.replace (QRegExp("^,"),"");
01598         mDesktop -> setItem ( key,val );
01599 }
01600 //====================================
01601 // removeExtraModeline
01602 //------------------------------------
01603 void SaXManipulateDesktop::removeExtraModeline ( int x,int y) {
01604         // .../
01607         // ----
01608         if ((! mDesktop) || (! mCard) || (! mPath)) {
01609                 return;
01610         }
01611         QString val;
01612         QString key = "SpecialModeline";
01613         val.sprintf ("\"%dx%d\"",x,y);
01614         QString current = mDesktop -> getItem (key);
01615         QStringList lines = QStringList::split ( ",", current );
01616         for (
01617                 QStringList::Iterator it=lines.begin();
01618                 it != lines.end(); ++it
01619         ) {
01620                 QString mode (*it);
01621                 if (mode.contains (val)) {
01622                         mDesktop -> removeItem (key,mode);
01623                 }
01624         }
01625 }
01626 //====================================
01627 // calculateModeline
01628 //------------------------------------
01629 QString SaXManipulateDesktop::calculateModeline (
01630         int x,int y,int refresh,int hsync
01631 ) {
01632         // .../
01636         // ----
01637         QString result;
01638         for (int r=refresh;r >= 50;r--) {
01639                 SaXProcessCall* proc = new SaXProcessCall ();
01640                 proc -> addArgument ( XMODE );
01641                 proc -> addArgument ( "-x" );
01642                 proc -> addArgument ( x );
01643                 proc -> addArgument ( "-y" );
01644                 proc -> addArgument ( y );
01645                 proc -> addArgument ( "-r" );
01646                 proc -> addArgument ( r + 2 );
01647                 if ( ! proc -> start() ) {
01648                         excProcessFailed();
01649                         qError (errorString(),EXC_PROCESSFAILED);
01650                 }
01651                 QList<QString> data = proc->readStdout();
01652                 int hs = data.at(0)->toInt();
01653                 result = *data.at(2);
01654                 if (hs <= hsync) {
01655                         break;
01656                 }
01657         }
01658         result.replace (QRegExp("^Modeline "),"");
01659         return result;
01660 }
01661 //====================================
01662 // getDriverOptionsDualHeadProfile
01663 //------------------------------------
01664 QString SaXManipulateDesktop::getDriverOptionsDualHeadProfile (
01665         const QString& driver
01666 ) {
01667         // .../
01671         // ----
01672         QString result;
01673         if ((driver == "i810") || (driver == "i915")) {
01674                 QTextOStream (&result)
01675                         << PROFILE_DIR << "Intel_DualHead_DriverOptions";
01676         }
01677         if (driver == "intel") {
01678                 QTextOStream (&result)
01679                         << PROFILE_DIR << "IntelNext_DualHead_DriverOptions";
01680         }
01681         if (driver == "nvidia") {
01682                 QTextOStream (&result)
01683                         << PROFILE_DIR << "NVidia_DualHead_DriverOptions";
01684         }
01685         if (driver == "radeon") {
01686                 QTextOStream (&result)
01687                         << PROFILE_DIR << "Radeon_DualHead_DriverOptions";
01688         }
01689         if (driver == "fglrx") {
01690                 QTextOStream (&result)
01691                         << PROFILE_DIR << "FGLRX_DualHead_DriverOptions";
01692         }
01693         if (driver == "mga") {
01694                 QTextOStream (&result)
01695                         << PROFILE_DIR << "Matrox_DualHead_DriverOptions";
01696         }
01697         if (driver == "sis") {
01698                 QTextOStream (&result)
01699                         << PROFILE_DIR << "SiS_DualHead_DriverOptions";
01700         }
01701         return result;
01702 }
01703 //====================================
01704 // getMetaData
01705 //------------------------------------
01706 QDict<QString> SaXManipulateDesktop::getMetaData ( void ) {
01707         // .../
01713         QString cardID;
01714         QTextOStream (&cardID) << mDesktopID;
01715         QList<char> metaOptions;
01716         metaOptions.append ( "-c" );
01717         metaOptions.append ( cardID.ascii() );
01718         SaXProcess* proc = new SaXProcess ();
01719         proc->start ( metaOptions , SAX_META );
01720         QDict<QString> metaData = proc->getCurrentTable();
01721         return metaData;
01722 }
01723 } // end namespace

Generated on Tue Sep 25 20:18:16 2007 for libsax by  doxygen 1.5.3