Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members

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 
00023 namespace SaX {
00024 //====================================
00025 // Constructor...
00026 //------------------------------------
00027 SaXManipulateDesktop::SaXManipulateDesktop (
00028         SaXImport* desktop, SaXImport* card , SaXImport* path, int desktopID
00029 ) {
00030         // .../
00033         // ----
00034         if ( (! desktop) || (! card) ) {
00035                 excNullPointerArgument ();
00036                 qError (errorString(),EXC_NULLPOINTERARGUMENT);
00037                 return;
00038         }
00039         if ( desktop->getSectionID() != SAX_DESKTOP ) {
00040                 excDesktopImportBindFailed ( desktop->getSectionID() );
00041                 qError (errorString(),EXC_DESKTOPIMPORTBINDFAILED);
00042                 return;
00043         }
00044         if ( card->getSectionID() != SAX_CARD ) {
00045                 excCardImportBindFailed ( card->getSectionID() );
00046                 qError (errorString(),EXC_CARDIMPORTBINDFAILED);
00047                 return;
00048         }
00049         if ( path->getSectionID() != SAX_PATH ) {
00050                 excPathImportBindFailed ( path->getSectionID() );
00051                 qError (errorString(),EXC_PATHIMPORTBINDFAILED);
00052                 return;
00053         }
00054         mDesktopID = desktopID;
00055         mDesktop   = desktop;
00056         mCard      = card;
00057         mPath      = path;
00058         mDesktop -> setID ( mDesktopID );
00059         mCard    -> setID ( mDesktopID );
00060         mPath    -> setID ( 0 );
00061         mCDBMonitors = 0;
00062 }
00063 
00064 //====================================
00065 // set desktop ID
00066 //------------------------------------
00067 bool SaXManipulateDesktop::selectDesktop (int desktop) {
00068         // .../
00071         // ----
00072         if ((! mDesktop) || (! mCard) || (! mPath)) {
00073                 return false;
00074         }
00075         if ( (mDesktop->setID (desktop)) && (mCard->setID (desktop)) ) {
00076                 mDesktopID = desktop;
00077                 return true;
00078         }
00079         return false;
00080 }
00081 
00082 //====================================
00083 // calculateModelines
00084 //------------------------------------
00085 void SaXManipulateDesktop::calculateModelines (bool calc) {
00086         // .../
00090         // ----
00091         if ((! mDesktop) || (! mCard) || (! mPath)) {
00092                 return;
00093         }
00094         QString val ("no");
00095         if (calc) {
00096                 val = "on";
00097         }
00098         mDesktop -> setItem ( "CalcModelines",val );
00099 }
00100 
00101 //====================================
00102 // setResolution
00103 //------------------------------------
00104 void SaXManipulateDesktop::setResolution (int c,int x,int y) {
00105         // .../
00108         // ----
00109         if ((! mDesktop) || (! mCard) || (! mPath)) {
00110                 return;
00111         }
00112         QString key;
00113         QString val;
00114         key.sprintf ("Modes:%d",c);
00115         val.sprintf ("%dx%d",x,y);
00116         mDesktop -> setItem ( key,val );
00117 }
00118 
00119 //====================================
00120 // addResolution
00121 //------------------------------------
00122 void SaXManipulateDesktop::addResolution (int c,int x,int y) {
00123         // .../
00126         // ----
00127         if ((! mDesktop) || (! mCard) || (! mPath)) {
00128                 return;
00129         }
00130         QString key;
00131         QString val;
00132         key.sprintf ("Modes:%d",c);
00133         if (! mDesktop -> getItem (key).isEmpty()) {
00134                 val = mDesktop -> getItem (key);
00135         }
00136         QTextOStream (&val) << val << "," << x << "x" << y;
00137         val.replace (QRegExp("^,"),"");
00138         mDesktop -> setItem ( key,val );
00139 }
00140 
00141 //====================================
00142 // removeResolution
00143 //------------------------------------
00144 void SaXManipulateDesktop::removeResolution (int c,int x,int y) {
00145         // .../
00148         // ----
00149         if ((! mDesktop) || (! mCard) || (! mPath)) {
00150                 return;
00151         }
00152         QString key;
00153         QString val;
00154         key.sprintf ("Modes:%d",c);
00155         val.sprintf ("%dx%d",x,y);
00156         if (! mDesktop -> getItem (key).isEmpty()) {
00157                 mDesktop -> removeItem (key,val);
00158         }
00159 }
00160 
00161 //====================================
00162 // setVirtualResolution
00163 //------------------------------------
00164 void SaXManipulateDesktop::setVirtualResolution (int c,int x,int y) {
00165         // .../
00168         // ----
00169         if ((! mDesktop) || (! mCard) || (! mPath)) {
00170                 return;
00171         }
00172         QString key;
00173         QString val;
00174         key.sprintf ("Virtual:%d",c);
00175         val.sprintf ("%dx%d",x,y);
00176         mDesktop -> setItem ( key,val );
00177 }
00178 
00179 //====================================
00180 // removeVirtualResolution
00181 //------------------------------------
00182 void SaXManipulateDesktop::removeVirtualResolution (int c) {
00183         // .../
00186         // ----
00187         if ((! mDesktop) || (! mCard) || (! mPath)) {
00188                 return;
00189         }
00190         QString key;
00191         key.sprintf ("Virtual:%d",c);
00192         if (! mDesktop -> getItem (key).isEmpty()) {
00193                 mDesktop -> setItem (key,"");
00194         }
00195 }
00196 
00197 //====================================
00198 // setColorDepth
00199 //------------------------------------
00200 void SaXManipulateDesktop::setColorDepth (int c) {
00201         // .../
00204         // ----
00205         if ((! mDesktop) || (! mCard) || (! mPath)) {
00206                 return;
00207         }
00208         QString color;
00209         color.sprintf ("%d",c);
00210         mDesktop -> setItem ( "ColorDepth",color );
00211 }
00212 
00213 //====================================
00214 // is3DCard
00215 //------------------------------------
00216 bool SaXManipulateDesktop::is3DCard (void) {
00217         // .../
00220         // ----
00221         if ((! mDesktop) || (! mCard) || (! mPath)) {
00222                 return false;
00223         }
00224         //====================================
00225         // get sysp card name
00226         //------------------------------------
00227         SaXImportSysp* pCard = new SaXImportSysp (SYSP_CARD);
00228         pCard -> doImport();
00229         if (! pCard -> setID ( mDesktopID )) {
00230                 return false;
00231         }
00232         QString mCardName;
00233         QTextOStream (&mCardName) <<
00234                 pCard->getItem("Vendor") << ":" << pCard->getItem("Device");
00235         //====================================
00236         // retrieve CDB card list
00237         //------------------------------------
00238         SaXProcess* CDBCards = new SaXProcess ();
00239         CDBCards -> start (CDB_CARDS);
00240         QDict< QDict<QString> > CDBData = CDBCards -> getTablePointerCDB ();
00241         QDict<QString>* cardData = CDBData.find ( mCardName );
00242         if ( cardData ) {
00243                 QString* flag = cardData -> find ("Flag");
00244                 if (flag) {
00245                         QString  driver = mCard -> getItem ("Driver");
00246                         QString* driver3D = cardData -> find ("3DDriver");
00247                         if ((driver3D) && (driver == *driver3D)) {
00248                                 //====================================
00249                                 // check 3D driver installation
00250                                 //------------------------------------
00251                                 if ( driver == "nvidia") {
00252                                         QString vendor = getVendorForDriver ( driver );
00253                                         if (vendor == "NVIDIA Corporation") {
00254                                                 return true;
00255                                         }
00256                                         return false;
00257                                 }
00258                                 return true;
00259                         }
00260                         return false;
00261                 }
00262                 return false;
00263         }
00264         //====================================
00265         // No CDB record found for cardName
00266         //------------------------------------
00267         excEmptyCDBGroup ( mCardName.data() );
00268         qError (errorString(),EXC_EMPTYCDBGROUP);
00269         return false;
00270 }
00271 
00272 //====================================
00273 // getDualHeadProfile
00274 //------------------------------------
00275 QString SaXManipulateDesktop::getDualHeadProfile ( void ) {
00276         // .../
00282         // ----
00283         if ((! mDesktop) || (! mCard) || (! mPath)) {
00284                 return QString();
00285         }
00286         //====================================
00287         // check special laptop case
00288         //------------------------------------
00289         QString result;
00290         SaXManipulateCard cardInfo (mCard);
00291         if (cardInfo.isNoteBook()) {
00292                 QString driver = mCard -> getItem ("Driver");
00293                 if ((driver == "i810") || (driver == "i915")) {
00294                         QTextOStream (&result)
00295                                 << PROFILE_DIR << "Intel_DualHead_DriverOptions";
00296                 }
00297                 if (driver == "nvidia") {
00298                         QTextOStream (&result)
00299                                 << PROFILE_DIR << "NVidia_DualHead_DriverOptions";
00300                 }
00301                 if (driver == "radeon") {
00302                         QTextOStream (&result)
00303                                 << PROFILE_DIR << "Radeon_DualHead_DriverOptions";
00304                 }
00305                 if (driver == "fglrx") {
00306                         QTextOStream (&result)
00307                                 << PROFILE_DIR << "FGLRX_DualHead_DriverOptions";
00308                 }
00309                 return result;
00310         }
00311         //====================================
00312         // get sysp card name
00313         //------------------------------------
00314         SaXImportSysp* pCard = new SaXImportSysp (SYSP_CARD);
00315         pCard -> doImport();
00316         if (! pCard -> setID ( mDesktopID )) {
00317                 return QString();
00318         }
00319         QString mCardName;
00320         QTextOStream (&mCardName) <<
00321                 pCard->getItem("Vendor") << ":" << pCard->getItem("Device");
00322         //====================================
00323         // retrieve CDB card list
00324         //------------------------------------
00325         SaXProcess* CDBCards = new SaXProcess ();
00326         CDBCards -> start (CDB_CARDS);
00327         QDict< QDict<QString> > CDBData = CDBCards -> getTablePointerCDB ();
00328         QDict<QString>* cardData = CDBData.find ( mCardName );
00329         if ( cardData ) {
00330                 QString* profile = cardData -> find ("Profile");
00331                 if ((profile) && (profile->contains("DualHead_DriverOptions"))) {
00332                         QTextOStream (&result)
00333                                 << PROFILE_DIR << *profile;
00334                         return result;
00335                 }
00336         }
00337         //====================================
00338         // No CDB record found for cardName
00339         //------------------------------------
00340         excEmptyCDBGroup ( mCardName.data() );
00341         qError (errorString(),EXC_EMPTYCDBGROUP);
00342         return QString();
00343 }
00344 
00345 //====================================
00346 // isDualHeadCard
00347 //------------------------------------
00348 bool SaXManipulateDesktop::isDualHeadCard (void) {
00349         // .../
00353         // ----
00354         if ((! mDesktop) || (! mCard) || (! mPath)) {
00355                 return false;
00356         }
00357         //====================================
00358         // get sysp card name
00359         //------------------------------------
00360         SaXImportSysp* pCard = new SaXImportSysp (SYSP_CARD);
00361         pCard -> doImport();
00362         if (! pCard -> setID ( mDesktopID )) {
00363                 return false;
00364         }
00365         QString mCardName;
00366         QTextOStream (&mCardName) <<
00367                 pCard->getItem("Vendor") << ":" << pCard->getItem("Device");
00368         //====================================
00369         // retrieve CDB card list
00370         //------------------------------------
00371         SaXProcess* CDBCards = new SaXProcess ();
00372         CDBCards -> start (CDB_CARDS);
00373         QDict< QDict<QString> > CDBData = CDBCards -> getTablePointerCDB ();
00374         QDict<QString>* cardData = CDBData.find ( mCardName );
00375         if ( cardData ) {
00376                 QString* profile = cardData -> find ("Profile");
00377                 if ((profile) && (profile->contains("DualHead_DriverOptions"))) {
00378                         //====================================
00379                         // ask profile for changes if dynamic
00380                         //------------------------------------
00381                         SaXProcessCall* proc = new SaXProcessCall ();
00382                         proc -> addArgument ( SAX_PROFILE_CHECK );
00383                         proc -> addArgument ( *profile );
00384                         if ( ! proc -> start() ) {
00385                                 excProcessFailed();
00386                                 qError (errorString(),EXC_PROCESSFAILED);
00387                                 return false;
00388                         }
00389                         if (proc->exitStatus() == 0) {
00390                                 return true;
00391                         }
00392                         return false;
00393                 }
00394                 return false;
00395         }
00396         //====================================
00397         // No CDB record found for cardName
00398         //------------------------------------
00399         excEmptyCDBGroup ( mCardName.data() );
00400         qError (errorString(),EXC_EMPTYCDBGROUP);
00401         return false;
00402 }
00403 
00404 //====================================
00405 // enable3D
00406 //------------------------------------
00407 bool SaXManipulateDesktop::enable3D (void) {
00408         // .../
00417         // ----
00418         if ((! mDesktop) || (! mCard) || (! mPath)) {
00419                 return false;
00420         }
00421         //====================================
00422         // get sysp card name
00423         //------------------------------------
00424         SaXImportSysp* pCard = new SaXImportSysp (SYSP_CARD);
00425         pCard -> doImport();
00426         if (! pCard -> setID ( mDesktopID )) {
00427                 return false;
00428         }
00429         QString mCardName;
00430         QTextOStream (&mCardName) <<
00431                 pCard->getItem("Vendor") << ":" << pCard->getItem("Device");
00432 
00433         //====================================
00434         // retrieve CDB card list
00435         //------------------------------------
00436         SaXProcess* CDBCards = new SaXProcess ();
00437         CDBCards -> start (CDB_CARDS);
00438         QDict< QDict<QString> > CDBData = CDBCards -> getTablePointerCDB ();
00439 
00440         //====================================
00441         // get Extensions for the active card
00442         //------------------------------------
00443         SaXManipulateCard cardInfo (mCard,mDesktopID);
00444         QDict<QString>* cardData = CDBData.find ( mCardName );
00445         if ( cardData ) {
00446                 QString* driver3D= cardData -> find ("3DDriver");
00447                 QString* driver2D= cardData -> find ("Driver");
00448                 QString* extends = cardData -> find ("Extension");
00449                 QString* flag    = cardData -> find ("Flag");
00450                 //========================================
00451                 // check 3D flag
00452                 //----------------------------------------
00453                 if (! flag) {
00454                         return false;
00455                 }               
00456                 //========================================
00457                 // nvidia drv. needed, check if installed
00458                 //----------------------------------------
00459                 if ((driver3D) && (*driver3D == "nvidia")) {
00460                         SaXProcessCall* proc = new SaXProcessCall ();
00461                         proc -> addArgument ( XSLOAD );
00462                         proc -> addArgument ( "-vendor" );
00463                         if ( ! proc -> start() ) {
00464                                 excProcessFailed();
00465                                 qError (errorString(),EXC_PROCESSFAILED);
00466                         }
00467                         bool foundBinaryNVidiaDriver = false;
00468                         QList<QString> data = proc->readStdout();
00469                         QListIterator<QString> in (data);
00470                         for (; in.current(); ++in) {
00471                                 QString line (*in.current());
00472                                 if (line = "nvidia:NVIDIA Corporation") {
00473                                         foundBinaryNVidiaDriver = true;
00474                                 } 
00475                         }
00476                         if (! foundBinaryNVidiaDriver) {
00477                                 excNvidiaDriverMissing();
00478                                 qError (errorString(),EXC_NVIDIADRIVERMISSING);
00479                                 return false;
00480                         }
00481                 }
00482                 //========================================
00483                 // have extension, add it
00484                 //----------------------------------------
00485                 if (extends) {
00486                         SaXManipulatePath pathInfo (mPath);
00487                         pathInfo.removeLoadableModule (*extends);
00488                         pathInfo.addLoadableModule (*extends);
00489                 }
00490                 //========================================
00491                 // set driver to use with 3D
00492                 //----------------------------------------
00493                 if (driver3D) {
00494                         QString currentDriver = cardInfo.getCardDriver();
00495                         if ((currentDriver != *driver3D) && (currentDriver != *driver2D)) {
00496                                 excDriverMismatch (driver3D->ascii(),currentDriver.ascii());
00497                                 qError (errorString(),EXC_DRIVERMISMATCH);
00498                         } else {
00499                                 cardInfo.setCardDriver (*driver3D);
00500                         }
00501                 }
00502         }
00503         //====================================
00504         // Import profiles if there are any
00505         //------------------------------------
00506         if (cardData) {
00507                 QStringList profiles;
00508                 QString* profile3D = cardData -> find ("3DProfile");
00509                 if ((profile3D) && (! profile3D->contains("DualHead"))) {
00510                         profiles += *profile3D;
00511                 }
00512                 SaXFile mapHandle (MAP_DIR + QString("Driver.map"));
00513                 QDict<QString> driverMap = mapHandle.readDict();
00514                 QString driver = cardInfo.getCardDriver();
00515                 if ((! driver.isEmpty()) && (driverMap[driver])) {
00516                         QStringList items = QStringList::split ( ",", *driverMap[driver] );
00517                         profiles += items;
00518                 }
00519                 for (
00520                         QStringList::Iterator it=profiles.begin();
00521                         it != profiles.end(); ++it
00522                 ) {
00523                         QString profile (*it);
00524                         SaXImportProfile* pProfile = new SaXImportProfile (
00525                                 PROFILE_DIR + profile
00526                         );
00527                         pProfile -> doImport();
00528                         //====================================
00529                         // handle Card Options
00530                         //------------------------------------
00531                         SaXImport* mImportCard = pProfile -> getImport ( SAX_CARD );
00532                         if ( mImportCard ) {
00533                                 QDict<QString> profileDriverOptions;
00534                                 SaXManipulateCard saxProfileCard ( mImportCard );
00535                                 profileDriverOptions = saxProfileCard.getOptions();
00536                                 QDictIterator<QString> it ( profileDriverOptions );
00537                                 for (; it.current(); ++it) {
00538                                         QString key = it.currentKey();
00539                                         QString val = *it.current();
00540                                         cardInfo.addCardOption (key,val);
00541                                 }
00542                         }
00543                         //====================================
00544                         // handle Desktop Options
00545                         //------------------------------------
00546                         SaXImport* mImportDesktop = pProfile -> getImport ( SAX_DESKTOP );
00547                         if ( mImportDesktop ) {
00548                                 QDict<QString> profileDriverOptions;
00549                                 SaXManipulateDesktop saxProfileDesktop (
00550                                         mImportDesktop,mCard,mPath
00551                                 );
00552                                 //====================================
00553                                 // Colordepth...
00554                                 //------------------------------------
00555                                 QString color = saxProfileDesktop.getColorDepth();
00556                                 setColorDepth (color.toInt());
00557                         }
00558                 }
00559                 return true;
00560         }
00561         //====================================
00562         // No CDB record found for mCardName
00563         //------------------------------------
00564         excEmptyCDBGroup ( mCardName.data() );
00565         qError (errorString(),EXC_EMPTYCDBGROUP);
00566         return false;
00567 }
00568 
00569 //====================================
00570 // disable3D
00571 //------------------------------------
00572 bool SaXManipulateDesktop::disable3D (void) {
00573         // ....
00579         // ----
00580         if ((! mDesktop) || (! mCard) || (! mPath)) {
00581                 return false;
00582         }
00583         //====================================
00584         // get sysp card name
00585         //------------------------------------
00586         SaXImportSysp* pCard = new SaXImportSysp (SYSP_CARD);
00587         pCard -> doImport();
00588         if (! pCard -> setID ( mDesktopID )) {
00589                 return false;
00590         }
00591         QString mCardName;
00592         QTextOStream (&mCardName) <<
00593                 pCard->getItem("Vendor") << ":" << pCard->getItem("Device");
00594 
00595         //====================================
00596         // retrieve CDB card list
00597         //------------------------------------
00598         SaXProcess* CDBCards = new SaXProcess ();
00599         CDBCards -> start (CDB_CARDS);
00600         QDict< QDict<QString> > CDBData = CDBCards -> getTablePointerCDB ();
00601 
00602         //====================================
00603         // get Extensions for the active card
00604         //------------------------------------
00605         SaXManipulateCard cardInfo (mCard);
00606         QDict<QString>* cardData = CDBData.find ( mCardName );
00607         if ( cardData ) {
00608                 QString* driver3D= cardData -> find ("3DDriver");
00609                 QString* driver2D= cardData -> find ("Driver");
00610                 QString* extends = cardData -> find ("Extension");
00611                 QString* flag    = cardData -> find ("Flag");
00612                 //========================================
00613                 // check 3D flag
00614                 //----------------------------------------
00615                 if (! flag) {
00616                         return false;
00617                 }
00618                 //========================================
00619                 // nvidia drv. needed, check if installed
00620                 //----------------------------------------
00621                 if ((driver3D) && (*driver3D == "nvidia")) {
00622                         SaXProcessCall* proc = new SaXProcessCall ();
00623                         proc -> addArgument ( XSLOAD );
00624                         proc -> addArgument ( "-vendor" );
00625                         if ( ! proc -> start() ) {
00626                                 excProcessFailed();
00627                                 qError (errorString(),EXC_PROCESSFAILED);
00628                         }
00629                         QList<QString> data = proc->readStdout();
00630                         QListIterator<QString> in (data);
00631                         for (; in.current(); ++in) {
00632                                 QString line (*in.current());
00633                                 if (line = "nvidia:NVIDIA Corporation") {
00634                                         excNvidiaDriverInstalled();
00635                                         qError (errorString(),EXC_NVIDIADRIVERINSTALLED);
00636                                         return false;
00637                                 }
00638                         }
00639                 }
00640                 //========================================
00641                 // have extension, remove it
00642                 //----------------------------------------
00643                 if (extends) {
00644                         SaXManipulatePath pathInfo (mPath);
00645                         pathInfo.removeLoadableModule (*extends);
00646                 }
00647                 //========================================
00648                 // set driver to use with 2D
00649                 //----------------------------------------
00650                 if ((driver2D) && (driver3D)) {
00651                         QString currentDriver = cardInfo.getCardDriver();
00652                         if ((currentDriver != *driver3D) && (currentDriver != *driver2D)) {
00653                                 excDriverMismatch (driver2D->ascii(),currentDriver.ascii());
00654                                 qError (errorString(),EXC_DRIVERMISMATCH);
00655                         } else {
00656                                 cardInfo.setCardDriver (*driver2D);
00657                         }
00658                 }
00659         }
00660         //====================================
00661         // Reset profiles if there are any
00662         //------------------------------------
00663         if (cardData) {
00664                 QStringList profiles;
00665                 QString* profile3D = cardData -> find ("3DProfile");
00666                 if ((profile3D) && (! profile3D->contains("DualHead"))) {
00667                         profiles += *profile3D;
00668                 }
00669                 SaXFile mapHandle (MAP_DIR + QString("Driver.map"));
00670                 QDict<QString> driverMap = mapHandle.readDict();
00671                 QString driver = cardInfo.getCardDriver();
00672                 if ((! driver.isEmpty()) && (driverMap[driver])) {
00673                         QStringList items = QStringList::split ( ",", *driverMap[driver] );
00674                         profiles += items;
00675                 }
00676                 for (
00677                         QStringList::Iterator it=profiles.begin();
00678                         it != profiles.end(); ++it
00679                 ) {
00680                         QString profile (*it);
00681                         SaXImportProfile* pProfile = new SaXImportProfile (
00682                                 PROFILE_DIR + profile
00683                         );
00684                         pProfile -> doImport();
00685                         //====================================
00686                         // remove Card Options
00687                         //------------------------------------
00688                         SaXImport* mImportCard = pProfile -> getImport ( SAX_CARD );
00689                         if ( mImportCard ) {
00690                                 QDict<QString> profileDriverOptions;
00691                                 SaXManipulateCard saxProfileCard ( mImportCard );
00692                                 profileDriverOptions = saxProfileCard.getOptions();
00693                                 QDictIterator<QString> it ( profileDriverOptions );
00694                                 for (; it.current(); ++it) {
00695                                         QString key = it.currentKey();
00696                                         cardInfo.removeCardOption (key);
00697                                 }
00698                         }
00699                 }
00700                 return true;
00701         }
00702         //====================================
00703         // No CDB record found for mCardName
00704         //------------------------------------
00705         excEmptyCDBGroup ( mCardName.data() );
00706         qError (errorString(),EXC_EMPTYCDBGROUP);
00707         return false;
00708 }
00709 
00710 //====================================
00711 // setDisplaySize
00712 //------------------------------------
00713 void SaXManipulateDesktop::setDisplaySize (int width,int height) {
00714         // .../
00717         // ----
00718         if ((! mDesktop) || (! mCard) || (! mPath)) {
00719                 return;
00720         }
00721         QString size;
00722         size.sprintf ("%d %d",width,height);
00723         mDesktop -> setItem ( "DisplaySize",size );
00724 }
00725 
00726 //====================================
00727 // setHsyncRange
00728 //------------------------------------
00729 void SaXManipulateDesktop::setHsyncRange (double hsmin,double hsmax) {
00730         // .../
00733         // ----
00734         if ((! mDesktop) || (! mCard) || (! mPath)) {
00735                 return;
00736         }
00737         QString range;
00738         range.sprintf ("%.0f-%.0f",hsmin,hsmax);
00739         mDesktop -> setItem ( "HorizSync",range );
00740 }
00741 
00742 //====================================
00743 // setVsyncRange
00744 //------------------------------------
00745 void SaXManipulateDesktop::setVsyncRange (double vsmin,double vsmax) {
00746         // .../
00749         // ----
00750         if ((! mDesktop) || (! mCard) || (! mPath)) {
00751                 return;
00752         }
00753         QString range;
00754         range.sprintf ("%.0f-%.0f",vsmin,vsmax);
00755         mDesktop -> setItem ( "VertRefresh",range );
00756 }
00757 
00758 //====================================
00759 // enableDPMS
00760 //------------------------------------
00761 void SaXManipulateDesktop::enableDPMS (void) {
00762         // .../
00766         // ----
00767         if ((! mDesktop) || (! mCard) || (! mPath)) {
00768                 return;
00769     }
00770         mDesktop -> setItem ( "MonitorOptions","DPMS" );
00771 }
00772 
00773 //====================================
00774 // disableDPMS
00775 //------------------------------------
00776 void SaXManipulateDesktop::disableDPMS (void) {
00777         // .../
00780         // ----
00781         if ((! mDesktop) || (! mCard) || (! mPath)) {
00782                 return;
00783         }
00784         mDesktop -> setItem ( "MonitorOptions","" );
00785 }
00786 
00787 //====================================
00788 // setMonitorVendor
00789 //------------------------------------
00790 void SaXManipulateDesktop::setMonitorVendor (const QString& vendor) {
00791         // .../
00794         // ----
00795         if ((! mDesktop) || (! mCard) || (! mPath)) {
00796                 return;
00797         }
00798         mDesktop -> setItem ( "VendorName",vendor );
00799 }
00800 
00801 //====================================
00802 // setMonitorName
00803 //------------------------------------
00804 void SaXManipulateDesktop::setMonitorName (const QString& name) {
00805         // .../
00808         // ----
00809         if ((! mDesktop) || (! mCard) || (! mPath)) {
00810                 return;
00811         }
00812         mDesktop -> setItem ( "ModelName",name );
00813 }
00814 
00815 //====================================
00816 // is3DEnabled
00817 //------------------------------------
00818 bool SaXManipulateDesktop::is3DEnabled (void) {
00819         // .../
00824         // ----
00825         if ((! mDesktop) || (! mCard) || (! mPath)) {
00826                 return false;
00827         }
00828         if ( mCard -> getCount() > 1 ) {
00829                 return false;
00830         }
00831         QString driver = mCard -> getItem ("Driver");
00832         if (driver == "nvidia") {
00833                 QString vendor = getVendorForDriver ( driver );
00834                 if (vendor == "NVIDIA Corporation") {
00835                         return true;
00836                 }
00837                 return false;
00838         }
00839         SaXManipulatePath pathInfo (mPath);
00840         QList<QString> modules = pathInfo.getModules();
00841         QListIterator<QString> it (modules);
00842         for (; it.current();++it) {
00843         if (*it.current() == "dri") {
00844                 return true;
00845         }
00846         }
00847         return false;
00848 }
00849 
00850 //====================================
00851 // getResolutions
00852 //------------------------------------
00853 QList<QString> SaXManipulateDesktop::getResolutions (int color) {
00854         // .../
00858         // ----
00859         if ((! mDesktop) || (! mCard) || (! mPath)) {
00860                 return QList<QString>();
00861         }
00862         QString modes;
00863         modes.sprintf ("Modes:%d",color);
00864         QString resolutions = mDesktop -> getItem (modes);
00865         if (resolutions.isEmpty()) {
00866                 return QList<QString>();
00867         }
00868         QList<QString> result;
00869         QStringList resList = QStringList::split ( ",", resolutions );
00870         for (QStringList::Iterator it=resList.begin(); it!=resList.end();++ it) {
00871                 QString* data = new QString (*it);
00872                 result.append (data);
00873         }
00874         return result;
00875 }
00876 
00877 //====================================
00878 // getDisplaySize
00879 //------------------------------------
00880 QList<QString> SaXManipulateDesktop::getDisplaySize (void) {
00881         // .../
00887         // ----
00888         if ((! mDesktop) || (! mCard) || (! mPath)) {
00889                 return QList<QString>();
00890         }
00891         QString size = mDesktop -> getItem ("DisplaySize");
00892         if (size.isEmpty()) {
00893                 return QList<QString>();
00894         }
00895         QList<QString> result;
00896         QStringList sizeList = QStringList::split ( " ", size );
00897         result.append (
00898                 new QString(sizeList.first())
00899         );
00900         result.append (
00901                 new QString(sizeList.last())
00902         );
00903         return result;
00904 }
00905 
00906 //====================================
00907 // getHsyncRange
00908 //------------------------------------
00909 QList<QString> SaXManipulateDesktop::getHsyncRange (void) {
00910         // .../
00914         // ----
00915         if ((! mDesktop) || (! mCard) || (! mPath)) {
00916                 return QList<QString>();
00917         }
00918         QString range = mDesktop -> getItem ("HorizSync");
00919         if (range.isEmpty()) {
00920                 return QList<QString>();
00921         }
00922         QList<QString> result;
00923         QStringList rangeList = QStringList::split ( "-", range );
00924         result.append (
00925                 new QString(rangeList.first())
00926         );
00927         result.append (
00928                 new QString(rangeList.last())
00929         );
00930         return result;
00931 }
00932 
00933 //====================================
00934 // getVsyncRange
00935 //------------------------------------
00936 QList<QString> SaXManipulateDesktop::getVsyncRange (void) {
00937         // .../
00941         // ----
00942         if ((! mDesktop) || (! mCard) || (! mPath)) {
00943                 return QList<QString>();
00944         }
00945         QString range = mDesktop -> getItem ("VertRefresh");
00946         if (range.isEmpty()) {
00947                 return QList<QString>();
00948         }
00949         QList<QString> result;
00950         QStringList rangeList = QStringList::split ( "-", range );
00951         result.append (
00952                 new QString(rangeList.first())
00953         );
00954         result.append (
00955                 new QString(rangeList.last())
00956         );
00957         return result;
00958 }
00959 
00960 //====================================
00961 // DPMSEnabled
00962 //------------------------------------
00963 bool SaXManipulateDesktop::DPMSEnabled (void) {
00964         // .../
00968         // ----
00969         if ((! mDesktop) || (! mCard) || (! mPath)) {
00970                 return false;
00971         }
00972         QString options = mDesktop -> getItem ("MonitorOptions");
00973         if (options == "DPMS") {
00974                 return true;
00975         }
00976         return false;
00977 }
00978 
00979 //====================================
00980 // getMonitorVendor
00981 //------------------------------------
00982 QString SaXManipulateDesktop::getMonitorVendor (void) {
00983         // .../
00986         // ----
00987         if ((! mDesktop) || (! mCard) || (! mPath)) {
00988                 return QString();
00989         }
00990         return mDesktop -> getItem ("VendorName");
00991 }
00992 
00993 //====================================
00994 // getMonitorName
00995 //------------------------------------
00996 QString SaXManipulateDesktop::getMonitorName (void) {
00997         // .../
01000         // ----
01001         if ((! mDesktop) || (! mCard) || (! mPath)) {
01002                 return QString();
01003         }
01004         return mDesktop -> getItem ("ModelName");
01005 }
01006 
01007 //====================================
01008 // getColorDepth
01009 //------------------------------------
01010 QString SaXManipulateDesktop::getColorDepth (void) {
01011         // .../
01014         // ----
01015         if ((! mDesktop) || (! mCard) || (! mPath)) {
01016                 return QString();
01017         }
01018         return mDesktop -> getItem ("ColorDepth");
01019 }
01020 
01021 //====================================
01022 // getModelineAlgorithm
01023 //------------------------------------
01024 QString SaXManipulateDesktop::getModelineAlgorithm (void) {
01025         // .../
01027         // ----
01028         if ((! mDesktop) || (! mCard) || (! mPath)) {
01029                 return QString();
01030         }
01031         return mDesktop -> getItem ("CalcAlgorithm");
01032 }
01033 
01034 //====================================
01035 // willCalculateModelines
01036 //------------------------------------
01037 bool SaXManipulateDesktop::willCalculateModelines (void) {
01038         // .../
01041         // ----
01042         if ((! mDesktop) || (! mCard) || (! mPath)) {
01043                 return false;
01044         }
01045         QString calculate = mDesktop -> getItem ("CalcModelines");
01046         if ((calculate == "on") || (calculate == "yes")) {
01047                 return true;
01048         }
01049         return false;
01050 }
01051 
01052 //====================================
01053 //getVirtualResolution
01054 //------------------------------------
01055 QString SaXManipulateDesktop::getVirtualResolution (int color) {
01056         // .../
01060         // ----
01061         if ((! mDesktop) || (! mCard) || (! mPath)) {
01062                 return QString();
01063         }
01064         QString key;
01065         QString val;
01066         key.sprintf ("Virtual:%d",color);
01067         val = mDesktop -> getItem (key);
01068         if (val.isEmpty()) {
01069                 return QString();
01070         }
01071         QStringList resList = QStringList::split ( " ", val );
01072         QString result (resList.join("x"));
01073         return result;
01074 }
01075 
01076 //====================================
01077 // set monitor record from the CDB
01078 //------------------------------------
01079 void SaXManipulateDesktop::setCDBMonitor ( const QString& group ) {
01080         // .../
01084         // ----
01085         if ( ! mCDBMonitors ) {
01086                 mCDBMonitors = new SaXProcess ();
01087                 mCDBMonitors -> start (CDB_MONITORS);
01088         }
01089         QList< QDict<QString> > data;
01090         data = mCDBMonitors -> getTablePointerCDB_DATA (
01091                 group
01092         );
01093         if (data.isEmpty()) {
01094                 excCDBRecordNotFound (group);
01095                 qError (errorString(),EXC_CDBRECORDNOTFOUND);
01096                 return;
01097         }
01098         QStringList nameList = QStringList::split ( ":", group );
01099         setMonitorVendor ( nameList.first() );
01100         setMonitorName   ( nameList.last() );
01101         mDesktop -> merge ( data );
01102 }
01103 
01104 //====================================
01105 // get list of CDB monitors
01106 //------------------------------------
01107 QList<QString> SaXManipulateDesktop::getCDBMonitorVendorList ( void ) {
01108         // .../
01111         // ----
01112         mCDBMonitorList.clear();
01113         if ( ! mCDBMonitors ) {
01114                 mCDBMonitors = new SaXProcess ();
01115                 mCDBMonitors -> start (CDB_MONITORS);
01116         }
01117         QDict< QDict<QString> > CDBData = mCDBMonitors -> getTablePointerCDB ();
01118         QDictIterator< QDict<QString> > it (CDBData);
01119         for (; it.current(); ++it) {
01120                 QStringList vnlist = QStringList::split ( ":", it.currentKey() );
01121                 QString* vendorName = new QString (vnlist.first());
01122                 int hasVendor = false;
01123                 QListIterator<QString> io (mCDBMonitorList);
01124                 for (; io.current(); ++io) {
01125                 if ( *io.current() == *vendorName ) {
01126                         hasVendor = true;
01127                         break;
01128                 }
01129                 }
01130                 if (! hasVendor ) {
01131                         mCDBMonitorList.append ( vendorName );
01132                 }
01133         }
01134         return mCDBMonitorList;
01135 }
01136 
01137 //====================================
01138 // get CDB monitor models per vendor
01139 //------------------------------------
01140 QList<QString> SaXManipulateDesktop::getCDBMonitorModelList (
01141         const QString& vendor
01142 ) {
01143         // .../
01146         // ----
01147         mCDBMonitorList.clear();
01148         if ( ! mCDBMonitors ) {
01149                 mCDBMonitors = new SaXProcess ();
01150                 mCDBMonitors -> start (CDB_MONITORS);
01151         }
01152         QDict< QDict<QString> > CDBData = mCDBMonitors -> getTablePointerCDB ();
01153         QDictIterator< QDict<QString> > it (CDBData);
01154         for (; it.current(); ++it) {
01155                 QStringList vnlist = QStringList::split ( ":", it.currentKey() );
01156                 QString vendorName = vnlist.first();
01157                 QString* modelName = new QString (vnlist.last());
01158                 if ( vendorName == vendor ) {
01159                         mCDBMonitorList.append ( modelName );
01160                 }
01161         }
01162         return mCDBMonitorList;
01163 }
01164 
01165 //====================================
01166 // get data dict for a CDB monitor
01167 //------------------------------------
01168 QDict<QString> SaXManipulateDesktop::getCDBMonitorData (
01169         const QString& vendor, const QString& name
01170 ) {
01171         // .../
01174         // ----
01175         QString key;
01176         QTextOStream (&key) << vendor << ":" << name;
01177         mCDBMonitorData.clear();
01178         if ( ! mCDBMonitors ) {
01179                 mCDBMonitors = new SaXProcess ();
01180                 mCDBMonitors -> start (CDB_MONITORS);
01181         }
01182         QDict< QDict<QString> > CDBData = mCDBMonitors -> getTablePointerCDB ();
01183         QDictIterator< QDict<QString> > it (CDBData);
01184         for (; it.current(); ++it) {
01185                 if ( it.currentKey() == key ) {
01186                         mCDBMonitorData = *it.current();
01187                         break;
01188                 }
01189         }
01190         return mCDBMonitorData;
01191 }
01192 //====================================
01193 // add data dict to CDB (temporarly)
01194 //------------------------------------
01195 void SaXManipulateDesktop::setCDBMonitorData (
01196         const QString& vendor, const QString& name,
01197         const QString& key, const QString& value
01198 ) {
01199         // .../
01204         // ----
01205         QString group;
01206         QTextOStream (&group) << vendor << ":" << name;
01207         if ( ! mCDBMonitors ) {
01208                 mCDBMonitors = new SaXProcess ();
01209                 mCDBMonitors -> start (CDB_MONITORS);
01210         }
01211         mCDBMonitors -> addGroup (
01212                 group,key,value
01213         );
01214 }
01215 //====================================
01216 // getVendorForDriver
01217 //------------------------------------
01218 QString SaXManipulateDesktop::getVendorForDriver ( const QString& driver ) {
01219         // .../
01222         // ----
01223         SaXProcessCall* proc = new SaXProcessCall ();
01224         proc -> addArgument ( SYSP_VENDOR );
01225         proc -> addArgument ( driver );
01226         if ( ! proc -> start() ) {
01227                 excProcessFailed();
01228                 qError (errorString(),EXC_PROCESSFAILED);
01229         }
01230         QList<QString> data = proc -> readStdout();
01231         return *data.first();
01232 }
01233 //====================================
01234 // setExtraModeline
01235 //------------------------------------
01236 void SaXManipulateDesktop::setExtraModeline (
01237         int x,int y,int refresh,int hsync
01238 ) {
01239         // .../
01243         // ----
01244         if ((! mDesktop) || (! mCard) || (! mPath)) {
01245                 return;
01246         }
01247         QString mode = calculateModeline ( x,y,refresh,hsync );
01248         mDesktop -> setItem ( "SpecialModeline",mode );
01249 }
01250 //====================================
01251 // addExtraModeline
01252 //------------------------------------
01253 void SaXManipulateDesktop::addExtraModeline (
01254         int x,int y,int refresh,int hsync
01255 ) {
01256         // .../
01260         // ----
01261         if ((! mDesktop) || (! mCard) || (! mPath)) {
01262                 return;
01263         }
01264         QString val;
01265         QString key = "SpecialModeline";
01266         QString mode = calculateModeline ( x,y,refresh,hsync );
01267         if (! mDesktop -> getItem (key).isEmpty()) {
01268                 val = mDesktop -> getItem (key);
01269         }
01270         QTextOStream (&val) << val << "," << mode;
01271         val.replace (QRegExp("^,"),"");
01272         mDesktop -> setItem ( key,val );
01273 }
01274 //====================================
01275 // removeExtraModeline
01276 //------------------------------------
01277 void SaXManipulateDesktop::removeExtraModeline ( int x,int y) {
01278         // .../
01281         // ----
01282         if ((! mDesktop) || (! mCard) || (! mPath)) {
01283                 return;
01284         }
01285         QString val;
01286         QString key = "SpecialModeline";
01287         val.sprintf ("\"%dx%d\"",x,y);
01288         QString current = mDesktop -> getItem (key);
01289         QStringList lines = QStringList::split ( ",", current );
01290         for (
01291                 QStringList::Iterator it=lines.begin();
01292                 it != lines.end(); ++it
01293         ) {
01294                 QString mode (*it);
01295                 if (mode.contains (val)) {
01296                         mDesktop -> removeItem (key,mode);
01297                 }
01298         }
01299 }
01300 //====================================
01301 // calculateModeline
01302 //------------------------------------
01303 QString SaXManipulateDesktop::calculateModeline (
01304         int x,int y,int refresh,int hsync
01305 ) {
01306         // .../
01310         // ----
01311         QString result;
01312         for (int r=refresh;r >= 50;r--) {
01313                 SaXProcessCall* proc = new SaXProcessCall ();
01314                 proc -> addArgument ( XMODE );
01315                 proc -> addArgument ( "-x" );
01316                 proc -> addArgument ( x );
01317                 proc -> addArgument ( "-y" );
01318                 proc -> addArgument ( y );
01319                 proc -> addArgument ( "-r" );
01320                 proc -> addArgument ( r + 2 );
01321                 if ( ! proc -> start() ) {
01322                         excProcessFailed();
01323                         qError (errorString(),EXC_PROCESSFAILED);
01324                 }
01325                 QList<QString> data = proc->readStdout();
01326                 int hs = data.at(0)->toInt();
01327                 result = *data.at(2);
01328                 if (hs <= hsync) {
01329                         break;
01330                 }
01331         }
01332         result.replace (QRegExp("^Modeline "),"");
01333         return result;
01334 }
01335 } // end namespace

Generated on Wed Sep 14 10:27:01 2005 for libsax by  doxygen 1.4.4