00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "desktop.h"
00022
00023 namespace SaX {
00024
00025
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
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
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
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
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
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
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 ("%d %d",x,y);
00176 mDesktop -> setItem ( key,val );
00177 }
00178
00179
00180
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
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
00215
00216 bool SaXManipulateDesktop::is3DCard (void) {
00217
00220
00221 if ((! mDesktop) || (! mCard) || (! mPath)) {
00222 return false;
00223 }
00224
00225
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
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
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
00266
00267 excEmptyCDBGroup ( mCardName.data() );
00268 qError (errorString(),EXC_EMPTYCDBGROUP);
00269 return false;
00270 }
00271
00272
00273
00274
00275 QString SaXManipulateDesktop::getDualHeadProfile ( void ) {
00276
00282
00283 if ((! mDesktop) || (! mCard) || (! mPath)) {
00284 return QString();
00285 }
00286
00287
00288
00289 QDict<QString> metaData = getMetaData();
00290 if (metaData["SAX_NO_CDB_CHECK"]) {
00291 QString driver = mCard -> getItem ("Driver");
00292 QString profile = getDriverOptionsDualHeadProfile ( driver );
00293 return profile;
00294 }
00295
00296
00297
00298 QString result;
00299 SaXManipulateCard cardInfo (mCard);
00300 if (cardInfo.isNoteBook()) {
00301 QString driver = mCard -> getItem ("Driver");
00302 result = getDriverOptionsDualHeadProfile ( driver );
00303 return result;
00304 }
00305
00306
00307
00308 SaXImportSysp* pCard = new SaXImportSysp (SYSP_CARD);
00309 pCard -> doImport();
00310 if (! pCard -> setID ( mDesktopID )) {
00311 return QString();
00312 }
00313 QString mCardName;
00314 QTextOStream (&mCardName) <<
00315 pCard->getItem("Vendor") << ":" << pCard->getItem("Device");
00316
00317
00318
00319 SaXProcess* CDBCards = new SaXProcess ();
00320 CDBCards -> start (CDB_CARDS);
00321 QDict< QDict<QString> > CDBData = CDBCards -> getTablePointerCDB ();
00322 QDict<QString>* cardData = CDBData.find ( mCardName );
00323 if ( cardData ) {
00324 QString* profile = cardData -> find ("Profile");
00325 if ((profile) && (profile->contains("DualHead_DriverOptions"))) {
00326
00327
00328
00329 QString syspDriver = pCard -> getItem ("Module");
00330 QString* CDB2DDriver = cardData -> find ("Driver");
00331 QString* CDB3DDriver = cardData -> find ("3DDriver");
00332 if (
00333 ((CDB2DDriver) && (syspDriver == *CDB2DDriver)) ||
00334 ((CDB3DDriver) && (syspDriver == *CDB2DDriver))
00335 ) {
00336 QTextOStream (&result) << PROFILE_DIR << *profile;
00337 return result;
00338 }
00339
00340
00341
00342 result = getDriverOptionsDualHeadProfile ( syspDriver );
00343 return result;
00344 }
00345 }
00346
00347
00348
00349 excEmptyCDBGroup ( mCardName.data() );
00350 qError (errorString(),EXC_EMPTYCDBGROUP);
00351 return QString();
00352 }
00353
00354
00355
00356
00357 bool SaXManipulateDesktop::isXineramaMode (void) {
00358
00359
00360
00361
00362
00363 QDict<QString> metaData = getMetaData();
00364 if (metaData["SAX_NO_DUAL_MODE"]) {
00365 return true;
00366 }
00367 return false;
00368 }
00369
00370
00371
00372
00373 bool SaXManipulateDesktop::isDualHeadCard (void) {
00374
00378
00379 if ((! mDesktop) || (! mCard) || (! mPath)) {
00380 return false;
00381 }
00382
00383
00384
00385 QDict<QString> metaData = getMetaData();
00386 if (metaData["SAX_NO_CDB_CHECK"]) {
00387 QString driver = mCard -> getItem ("Driver");
00388 QString profile = getDriverOptionsDualHeadProfile ( driver );
00389 if (! profile.isEmpty()) {
00390 return true;
00391 }
00392 return false;
00393 }
00394
00395
00396
00397 SaXImportSysp* pCard = new SaXImportSysp (SYSP_CARD);
00398 pCard -> doImport();
00399 if (! pCard -> setID ( mDesktopID )) {
00400 return false;
00401 }
00402 QString mCardName;
00403 QTextOStream (&mCardName) <<
00404 pCard->getItem("Vendor") << ":" << pCard->getItem("Device");
00405
00406
00407
00408 SaXProcess* CDBCards = new SaXProcess ();
00409 CDBCards -> start (CDB_CARDS);
00410 QDict< QDict<QString> > CDBData = CDBCards -> getTablePointerCDB ();
00411 QDict<QString>* cardData = CDBData.find ( mCardName );
00412 if ( cardData ) {
00413 QString* profile = cardData -> find ("Profile");
00414 if ((profile) && (profile->contains("DualHead_DriverOptions"))) {
00415
00416
00417
00418 QString syspDriver = pCard -> getItem ("Module");
00419 QString* CDB2DDriver = cardData -> find ("Driver");
00420 QString* CDB3DDriver = cardData -> find ("3DDriver");
00421 if (
00422 ((CDB2DDriver) && (syspDriver != *CDB2DDriver)) &&
00423 ((CDB3DDriver) && (syspDriver != *CDB2DDriver))
00424 ) {
00425 *profile = getDriverOptionsDualHeadProfile ( syspDriver );
00426 }
00427 if (profile->isEmpty()) {
00428 return false;
00429 }
00430
00431
00432
00433 SaXProcessCall* proc = new SaXProcessCall ();
00434 proc -> addArgument ( SAX_PROFILE_CHECK );
00435 proc -> addArgument ( *profile );
00436 if ( ! proc -> start() ) {
00437 excProcessFailed();
00438 qError (errorString(),EXC_PROCESSFAILED);
00439 return false;
00440 }
00441 if (proc->exitStatus() == 0) {
00442 return true;
00443 }
00444 return false;
00445 }
00446 return false;
00447 }
00448
00449
00450
00451 excEmptyCDBGroup ( mCardName.data() );
00452 qError (errorString(),EXC_EMPTYCDBGROUP);
00453 return false;
00454 }
00455
00456
00457
00458
00459 bool SaXManipulateDesktop::enable3D (void) {
00460
00469
00470 if ((! mDesktop) || (! mCard) || (! mPath)) {
00471 return false;
00472 }
00473
00474
00475
00476 SaXImportSysp* pCard = new SaXImportSysp (SYSP_CARD);
00477 pCard -> doImport();
00478 if (! pCard -> setID ( mDesktopID )) {
00479 return false;
00480 }
00481 QString mCardName;
00482 QTextOStream (&mCardName) <<
00483 pCard->getItem("Vendor") << ":" << pCard->getItem("Device");
00484
00485
00486
00487
00488 SaXProcess* CDBCards = new SaXProcess ();
00489 CDBCards -> start (CDB_CARDS);
00490 QDict< QDict<QString> > CDBData = CDBCards -> getTablePointerCDB ();
00491
00492
00493
00494
00495 SaXManipulateCard cardInfo (mCard,mDesktopID);
00496 QDict<QString>* cardData = CDBData.find ( mCardName );
00497 if ( cardData ) {
00498 QString* driver3D= cardData -> find ("3DDriver");
00499 QString* driver2D= cardData -> find ("Driver");
00500 QString* extends = cardData -> find ("Extension");
00501 QString* flag = cardData -> find ("Flag");
00502
00503
00504
00505 if (! flag) {
00506 return false;
00507 }
00508
00509
00510
00511 if ((driver3D) && (*driver3D == "nvidia")) {
00512 bool foundBinaryNVidiaDriver = false;
00513 if ((getVendorForDriver(*driver3D)) == "NVIDIA Corporation") {
00514 foundBinaryNVidiaDriver = true;
00515 }
00516 if (! foundBinaryNVidiaDriver) {
00517 excNvidiaDriverMissing();
00518 qError (errorString(),EXC_NVIDIADRIVERMISSING);
00519 return false;
00520 }
00521 }
00522
00523
00524
00525 if (extends) {
00526 SaXManipulatePath pathInfo (mPath);
00527 pathInfo.removeLoadableModule (*extends);
00528 pathInfo.addLoadableModule (*extends);
00529 }
00530
00531
00532
00533 if (driver3D) {
00534 QString currentDriver = cardInfo.getCardDriver();
00535 if ((currentDriver != *driver3D) && (currentDriver != *driver2D)) {
00536 excDriverMismatch (driver3D->ascii(),currentDriver.ascii());
00537 qError (errorString(),EXC_DRIVERMISMATCH);
00538 } else {
00539 cardInfo.setCardDriver (*driver3D);
00540 }
00541 }
00542 }
00543
00544
00545
00546 if (cardData) {
00547 QStringList profiles;
00548 QString* profile3D = cardData -> find ("3DProfile");
00549 if ((profile3D) && (! profile3D->contains("DualHead"))) {
00550 profiles += *profile3D;
00551 }
00552 SaXFile mapHandle (MAP_DIR + QString("Driver.map"));
00553 QDict<QString> driverMap = mapHandle.readDict();
00554 QString driver = cardInfo.getCardDriver();
00555 if ((! driver.isEmpty()) && (driverMap[driver])) {
00556 QStringList items = QStringList::split ( ",", *driverMap[driver] );
00557 profiles += items;
00558 }
00559 for (
00560 QStringList::Iterator it=profiles.begin();
00561 it != profiles.end(); ++it
00562 ) {
00563 QString profile (*it);
00564 SaXImportProfile* pProfile = new SaXImportProfile (
00565 PROFILE_DIR + profile
00566 );
00567 pProfile -> doImport();
00568
00569
00570
00571 SaXImport* mImportCard = pProfile -> getImport ( SAX_CARD );
00572 if ( mImportCard ) {
00573 QDict<QString> profileDriverOptions;
00574 SaXManipulateCard saxProfileCard ( mImportCard );
00575 profileDriverOptions = saxProfileCard.getOptions();
00576 QDictIterator<QString> it ( profileDriverOptions );
00577 for (; it.current(); ++it) {
00578 QString key = it.currentKey();
00579 QString val = *it.current();
00580 cardInfo.addCardOption (key,val);
00581 }
00582 }
00583
00584
00585
00586 SaXImport* mImportDesktop = pProfile -> getImport ( SAX_DESKTOP );
00587 if ( mImportDesktop ) {
00588 QDict<QString> profileDriverOptions;
00589 SaXManipulateDesktop saxProfileDesktop (
00590 mImportDesktop,mCard,mPath
00591 );
00592
00593
00594
00595 QString color = saxProfileDesktop.getColorDepth();
00596 if (! color.isEmpty()) {
00597 setColorDepth (color.toInt());
00598 }
00599 }
00600 }
00601 return true;
00602 }
00603
00604
00605
00606 excEmptyCDBGroup ( mCardName.data() );
00607 qError (errorString(),EXC_EMPTYCDBGROUP);
00608 return false;
00609 }
00610
00611
00612
00613
00614 bool SaXManipulateDesktop::disable3D (void) {
00615
00621
00622 if ((! mDesktop) || (! mCard) || (! mPath)) {
00623 return false;
00624 }
00625
00626
00627
00628 SaXImportSysp* pCard = new SaXImportSysp (SYSP_CARD);
00629 pCard -> doImport();
00630 if (! pCard -> setID ( mDesktopID )) {
00631 return false;
00632 }
00633 QString mCardName;
00634 QTextOStream (&mCardName) <<
00635 pCard->getItem("Vendor") << ":" << pCard->getItem("Device");
00636
00637
00638
00639
00640 SaXProcess* CDBCards = new SaXProcess ();
00641 CDBCards -> start (CDB_CARDS);
00642 QDict< QDict<QString> > CDBData = CDBCards -> getTablePointerCDB ();
00643
00644
00645
00646
00647 SaXManipulateCard cardInfo (mCard);
00648 QDict<QString>* cardData = CDBData.find ( mCardName );
00649 if ( cardData ) {
00650 QString* driver3D= cardData -> find ("3DDriver");
00651 QString* driver2D= cardData -> find ("Driver");
00652 QString* extends = cardData -> find ("Extension");
00653 QString* flag = cardData -> find ("Flag");
00654
00655
00656
00657 if (! flag) {
00658 return false;
00659 }
00660
00661
00662
00663 if ((driver3D) && (*driver3D == "nvidia")) {
00664 if ((getVendorForDriver(*driver3D)) == "NVIDIA Corporation") {
00665 excNvidiaDriverInstalled();
00666 qError (errorString(),EXC_NVIDIADRIVERINSTALLED);
00667 return false;
00668 }
00669 }
00670
00671
00672
00673 if (extends) {
00674 SaXManipulatePath pathInfo (mPath);
00675 pathInfo.removeLoadableModule (*extends);
00676 }
00677
00678
00679
00680 if ((driver2D) && (driver3D)) {
00681 QString currentDriver = cardInfo.getCardDriver();
00682 if ((currentDriver != *driver3D) && (currentDriver != *driver2D)) {
00683 excDriverMismatch (driver2D->ascii(),currentDriver.ascii());
00684 qError (errorString(),EXC_DRIVERMISMATCH);
00685 } else {
00686 cardInfo.setCardDriver (*driver2D);
00687 }
00688 }
00689 }
00690
00691
00692
00693 if (cardData) {
00694 QStringList profiles;
00695 QString* profile3D = cardData -> find ("3DProfile");
00696 QString* driver3D = cardData -> find ("3DDriver");
00697 if ((profile3D) && (! profile3D->contains("DualHead"))) {
00698 profiles += *profile3D;
00699 }
00700 SaXFile mapHandle (MAP_DIR + QString("Driver.map"));
00701 QDict<QString> driverMap = mapHandle.readDict();
00702 if ((driver3D) && (driverMap[*driver3D])) {
00703 QStringList items = QStringList::split ( ",", *driverMap[*driver3D] );
00704 profiles += items;
00705 }
00706 for (
00707 QStringList::Iterator it=profiles.begin();
00708 it != profiles.end(); ++it
00709 ) {
00710 QString profile (*it);
00711 SaXImportProfile* pProfile = new SaXImportProfile (
00712 PROFILE_DIR + profile
00713 );
00714 pProfile -> doImport();
00715
00716
00717
00718 SaXImport* mImportCard = pProfile -> getImport ( SAX_CARD );
00719 if ( mImportCard ) {
00720 QDict<QString> profileDriverOptions;
00721 SaXManipulateCard saxProfileCard ( mImportCard );
00722 profileDriverOptions = saxProfileCard.getOptions();
00723 QDictIterator<QString> it ( profileDriverOptions );
00724 for (; it.current(); ++it) {
00725 QString key = it.currentKey();
00726 cardInfo.removeCardOption (key);
00727 }
00728 }
00729 }
00730 return true;
00731 }
00732
00733
00734
00735 excEmptyCDBGroup ( mCardName.data() );
00736 qError (errorString(),EXC_EMPTYCDBGROUP);
00737 return false;
00738 }
00739
00740
00741
00742
00743 void SaXManipulateDesktop::setDisplaySize (int width,int height) {
00744
00747
00748 if ((! mDesktop) || (! mCard) || (! mPath)) {
00749 return;
00750 }
00751 QString size;
00752 size.sprintf ("%d %d",width,height);
00753 mDesktop -> setItem ( "DisplaySize",size );
00754 }
00755
00756
00757
00758
00759 void SaXManipulateDesktop::setDisplayRatioAndTraversal (
00760 double traversal,int aspect, int ratio
00761 ) {
00762
00765
00766 if ((! mDesktop) || (! mCard) || (! mPath)) {
00767 return;
00768 }
00769 traversal = traversal * 25.4;
00770 double ar = (double)aspect / (double)ratio;
00771 double y = sqrt ( (traversal * traversal) / (ar * ar + 1.0) );
00772 double x = ar * y;
00773 setDisplaySize (
00774 (int)(round(x)),(int)(round(y))
00775 );
00776 }
00777
00778
00779
00780
00781 void SaXManipulateDesktop::setHsyncRange (double hsmin,double hsmax) {
00782
00785
00786 if ((! mDesktop) || (! mCard) || (! mPath)) {
00787 return;
00788 }
00789 QString range;
00790 range.sprintf ("%.0f-%.0f",hsmin,hsmax);
00791 mDesktop -> setItem ( "HorizSync",range );
00792 }
00793
00794
00795
00796
00797 void SaXManipulateDesktop::setVsyncRange (double vsmin,double vsmax) {
00798
00801
00802 if ((! mDesktop) || (! mCard) || (! mPath)) {
00803 return;
00804 }
00805 QString range;
00806 range.sprintf ("%.0f-%.0f",vsmin,vsmax);
00807 mDesktop -> setItem ( "VertRefresh",range );
00808 }
00809
00810
00811
00812
00813 void SaXManipulateDesktop::enableDPMS (void) {
00814
00818
00819 if ((! mDesktop) || (! mCard) || (! mPath)) {
00820 return;
00821 }
00822 mDesktop -> setItem ( "MonitorOptions","DPMS" );
00823 }
00824
00825
00826
00827
00828 void SaXManipulateDesktop::disableDPMS (void) {
00829
00832
00833 if ((! mDesktop) || (! mCard) || (! mPath)) {
00834 return;
00835 }
00836 mDesktop -> setItem ( "MonitorOptions","" );
00837 }
00838
00839
00840
00841
00842 void SaXManipulateDesktop::setMonitorVendor (const QString& vendor) {
00843
00846
00847 if ((! mDesktop) || (! mCard) || (! mPath)) {
00848 return;
00849 }
00850 mDesktop -> setItem ( "VendorName",vendor );
00851 }
00852
00853
00854
00855
00856 void SaXManipulateDesktop::setMonitorName (const QString& name) {
00857
00860
00861 if ((! mDesktop) || (! mCard) || (! mPath)) {
00862 return;
00863 }
00864 mDesktop -> setItem ( "ModelName",name );
00865 }
00866
00867
00868
00869
00870 bool SaXManipulateDesktop::is3DEnabled (void) {
00871
00876
00877 if ((! mDesktop) || (! mCard) || (! mPath)) {
00878 return false;
00879 }
00880 if ( mCard -> getCount() > 1 ) {
00881 return false;
00882 }
00883 QString driver = mCard -> getItem ("Driver");
00884 if (driver == "nvidia") {
00885 QString vendor = getVendorForDriver ( driver );
00886 if (vendor == "NVIDIA Corporation") {
00887 return true;
00888 }
00889 return false;
00890 }
00891 SaXManipulatePath pathInfo (mPath);
00892 QList<QString> modules = pathInfo.getModules();
00893 QListIterator<QString> it (modules);
00894 for (; it.current();++it) {
00895 if (*it.current() == "dri") {
00896 return true;
00897 }
00898 }
00899 return false;
00900 }
00901
00902
00903
00904
00905 QList<QString> SaXManipulateDesktop::getResolutions (int color) {
00906
00910
00911 if ((! mDesktop) || (! mCard) || (! mPath)) {
00912 return QList<QString>();
00913 }
00914 QString modes;
00915 modes.sprintf ("Modes:%d",color);
00916 QString resolutions = mDesktop -> getItem (modes);
00917 if (resolutions.isEmpty()) {
00918 return QList<QString>();
00919 }
00920 QList<QString> result;
00921 QStringList resList = QStringList::split ( ",", resolutions );
00922 for (QStringList::Iterator it=resList.begin(); it!=resList.end();++ it) {
00923 QString* data = new QString (*it);
00924 result.append (data);
00925 }
00926 return result;
00927 }
00928
00929
00930
00931
00932 QList<QString> SaXManipulateDesktop::getResolutionFromServer ( void ) {
00933
00938
00939 if ((! mDesktop) || (! mCard) || (! mPath)) {
00940 return QList<QString>();
00941 }
00942 QList<QString> defaultList;
00943 defaultList.append (new QString("800x600"));
00944 SaXProcessCall* proc = new SaXProcessCall();
00945 proc -> addArgument ( XQUERY );
00946 proc -> addArgument ( "-r" );
00947 if ( ! proc -> start() ) {
00948 return defaultList;
00949 }
00950 QList<QString> data = proc->readStdout();
00951 QListIterator<QString> in (data);
00952 for (; in.current(); ++in) {
00953 QRegExp modeExp ("(\\d+) (.*)");
00954 int rpos = modeExp.search (*in.current(),0);
00955 if (rpos >= 0) {
00956 int id = modeExp.cap(1).toInt();
00957 if (id == mDesktopID) {
00958 QList<QString> result;
00959 result.append (new QString (modeExp.cap(2)));
00960 return result;
00961 }
00962 }
00963 }
00964 return defaultList;
00965 }
00966
00967
00968
00969
00970 QList<QString> SaXManipulateDesktop::getDisplaySize (void) {
00971
00977
00978 if ((! mDesktop) || (! mCard) || (! mPath)) {
00979 return QList<QString>();
00980 }
00981 QString size = mDesktop -> getItem ("DisplaySize");
00982 if (size.isEmpty()) {
00983 return QList<QString>();
00984 }
00985 QList<QString> result;
00986 QStringList sizeList = QStringList::split ( " ", size );
00987 result.append (
00988 new QString(sizeList.first())
00989 );
00990 result.append (
00991 new QString(sizeList.last())
00992 );
00993 return result;
00994 }
00995
00996
00997
00998
00999 QString SaXManipulateDesktop::getDisplayTraversal (void) {
01000
01003
01004 if ((! mDesktop) || (! mCard) || (! mPath)) {
01005 return QString();
01006 }
01007 QList<QString> size = getDisplaySize();
01008 if (size.isEmpty()) {
01009 return QString();
01010 }
01011 int x = size.at(0)->toInt();
01012 int y = size.at(1)->toInt();
01013 double traversal = sqrt (x*x + y*y) / 25.4;
01014 QString result;
01015 QTextOStream (&result) << traversal;
01016 return result;
01017 }
01018
01019
01020
01021
01022 QList<QString> SaXManipulateDesktop::getDisplayRatio (void) {
01023
01026
01027 if ((! mDesktop) || (! mCard) || (! mPath)) {
01028 return QList<QString>();
01029 }
01030 QString* setX = new QString ("4");
01031 QString* setY = new QString ("3");
01032 QList<QString> result;
01033 QList<QString> size = getDisplaySize();
01034 if (size.isEmpty()) {
01035 return QList<QString>();
01036 }
01037 int x = size.at(0)->toInt();
01038 int y = size.at(1)->toInt();
01039 double ar = (double)x / (double)y;
01040 if ( ar > 1.4 ) {
01041 *setX = "16";
01042 *setY = "10";
01043 } else if (( ar <= 1.4 ) && ( ar > 1.3 )) {
01044 *setX = "4";
01045 *setY = "3";
01046 } else if ( ar <= 1.3 ) {
01047 *setX = "5";
01048 *setY = "4";
01049 }
01050 result.append (setX);
01051 result.append (setY);
01052 return result;
01053 }
01054
01055
01056
01057
01058 QList<QString> SaXManipulateDesktop::getHsyncRange (void) {
01059
01063
01064 if ((! mDesktop) || (! mCard) || (! mPath)) {
01065 return QList<QString>();
01066 }
01067 QString range = mDesktop -> getItem ("HorizSync");
01068 if (range.isEmpty()) {
01069 return QList<QString>();
01070 }
01071 QList<QString> result;
01072 QStringList rangeList = QStringList::split ( "-", range );
01073 result.append (
01074 new QString(rangeList.first())
01075 );
01076 result.append (
01077 new QString(rangeList.last())
01078 );
01079 return result;
01080 }
01081
01082
01083
01084
01085 QList<QString> SaXManipulateDesktop::getVsyncRange (void) {
01086
01090
01091 if ((! mDesktop) || (! mCard) || (! mPath)) {
01092 return QList<QString>();
01093 }
01094 QString range = mDesktop -> getItem ("VertRefresh");
01095 if (range.isEmpty()) {
01096 return QList<QString>();
01097 }
01098 QList<QString> result;
01099 QStringList rangeList = QStringList::split ( "-", range );
01100 result.append (
01101 new QString(rangeList.first())
01102 );
01103 result.append (
01104 new QString(rangeList.last())
01105 );
01106 return result;
01107 }
01108
01109
01110
01111
01112 bool SaXManipulateDesktop::DPMSEnabled (void) {
01113
01117
01118 if ((! mDesktop) || (! mCard) || (! mPath)) {
01119 return false;
01120 }
01121 QString options = mDesktop -> getItem ("MonitorOptions");
01122 if (options == "DPMS") {
01123 return true;
01124 }
01125 return false;
01126 }
01127
01128
01129
01130
01131 QString SaXManipulateDesktop::getMonitorVendor (void) {
01132
01135
01136 if ((! mDesktop) || (! mCard) || (! mPath)) {
01137 return QString();
01138 }
01139 return mDesktop -> getItem ("VendorName");
01140 }
01141
01142
01143
01144
01145 QString SaXManipulateDesktop::getMonitorName (void) {
01146
01149
01150 if ((! mDesktop) || (! mCard) || (! mPath)) {
01151 return QString();
01152 }
01153 return mDesktop -> getItem ("ModelName");
01154 }
01155
01156
01157
01158
01159 QString SaXManipulateDesktop::getColorDepth (void) {
01160
01163
01164 if ((! mDesktop) || (! mCard) || (! mPath)) {
01165 return QString();
01166 }
01167 return mDesktop -> getItem ("ColorDepth");
01168 }
01169
01170
01171
01172
01173 QString SaXManipulateDesktop::getModelineAlgorithm (void) {
01174
01176
01177 if ((! mDesktop) || (! mCard) || (! mPath)) {
01178 return QString();
01179 }
01180 return mDesktop -> getItem ("CalcAlgorithm");
01181 }
01182
01183
01184
01185
01186 bool SaXManipulateDesktop::willCalculateModelines (void) {
01187
01190
01191 if ((! mDesktop) || (! mCard) || (! mPath)) {
01192 return false;
01193 }
01194 QString calculate = mDesktop -> getItem ("CalcModelines");
01195 if ((calculate == "on") || (calculate == "yes")) {
01196 return true;
01197 }
01198 return false;
01199 }
01200
01201
01202
01203
01204 QString SaXManipulateDesktop::getVirtualResolution (int color) {
01205
01209
01210 if ((! mDesktop) || (! mCard) || (! mPath)) {
01211 return QString();
01212 }
01213 QString key;
01214 QString val;
01215 key.sprintf ("Virtual:%d",color);
01216 val = mDesktop -> getItem (key);
01217 if (val.isEmpty()) {
01218 return QString();
01219 }
01220 QStringList resList = QStringList::split ( " ", val );
01221 QString result (resList.join("x"));
01222 return result;
01223 }
01224
01225
01226
01227
01228 void SaXManipulateDesktop::setCDBMonitor ( const QString& group ) {
01229
01233
01234 if ( ! mCDBMonitors ) {
01235 mCDBMonitors = new SaXProcess ();
01236 mCDBMonitors -> start (CDB_MONITORS);
01237 }
01238 QList< QDict<QString> > data;
01239 data = mCDBMonitors -> getTablePointerCDB_DATA (
01240 group
01241 );
01242 if (data.isEmpty()) {
01243 excCDBRecordNotFound (group);
01244 qError (errorString(),EXC_CDBRECORDNOTFOUND);
01245 return;
01246 }
01247 QStringList nameList = QStringList::split ( ":", group );
01248 setMonitorVendor ( nameList.first() );
01249 setMonitorName ( nameList.last() );
01250 mDesktop -> merge ( data );
01251 }
01252
01253
01254
01255
01256 QList<QString> SaXManipulateDesktop::getCDBMonitorVendorList ( void ) {
01257
01260
01261 mCDBMonitorList.clear();
01262 if ( ! mCDBMonitors ) {
01263 mCDBMonitors = new SaXProcess ();
01264 mCDBMonitors -> start (CDB_MONITORS);
01265 }
01266 QDict< QDict<QString> > CDBData = mCDBMonitors -> getTablePointerCDB ();
01267 QDictIterator< QDict<QString> > it (CDBData);
01268 for (; it.current(); ++it) {
01269 QStringList vnlist = QStringList::split ( ":", it.currentKey() );
01270 QString* vendorName = new QString (vnlist.first());
01271 int hasVendor = false;
01272 QListIterator<QString> io (mCDBMonitorList);
01273 for (; io.current(); ++io) {
01274 if ( *io.current() == *vendorName ) {
01275 hasVendor = true;
01276 break;
01277 }
01278 }
01279 if (! hasVendor ) {
01280 mCDBMonitorList.append ( vendorName );
01281 }
01282 }
01283 return mCDBMonitorList;
01284 }
01285
01286
01287
01288
01289 QList<QString> SaXManipulateDesktop::getCDBMonitorModelList (
01290 const QString& vendor
01291 ) {
01292
01295
01296 mCDBMonitorList.clear();
01297 if ( ! mCDBMonitors ) {
01298 mCDBMonitors = new SaXProcess ();
01299 mCDBMonitors -> start (CDB_MONITORS);
01300 }
01301 QDict< QDict<QString> > CDBData = mCDBMonitors -> getTablePointerCDB ();
01302 QDictIterator< QDict<QString> > it (CDBData);
01303 for (; it.current(); ++it) {
01304 QStringList vnlist = QStringList::split ( ":", it.currentKey() );
01305 QString vendorName = vnlist.first();
01306 QString* modelName = new QString (vnlist.last());
01307 if ( vendorName == vendor ) {
01308 mCDBMonitorList.append ( modelName );
01309 }
01310 }
01311 return mCDBMonitorList;
01312 }
01313
01314
01315
01316
01317 QDict<QString> SaXManipulateDesktop::getCDBMonitorData (
01318 const QString& vendor, const QString& name
01319 ) {
01320
01323
01324 QString key;
01325 QTextOStream (&key) << vendor << ":" << name;
01326 mCDBMonitorData.clear();
01327 if ( ! mCDBMonitors ) {
01328 mCDBMonitors = new SaXProcess ();
01329 mCDBMonitors -> start (CDB_MONITORS);
01330 }
01331 QDict< QDict<QString> > CDBData = mCDBMonitors -> getTablePointerCDB ();
01332 QDictIterator< QDict<QString> > it (CDBData);
01333 for (; it.current(); ++it) {
01334 if ( it.currentKey() == key ) {
01335 mCDBMonitorData = *it.current();
01336 break;
01337 }
01338 }
01339 return mCDBMonitorData;
01340 }
01341
01342
01343
01344 QDict<QString> SaXManipulateDesktop::getCDBMonitorIDData (
01345 const QString& id
01346 ) {
01347
01350
01351 mCDBMonitorData.clear();
01352 if ( ! mCDBMonitors ) {
01353 mCDBMonitors = new SaXProcess ();
01354 mCDBMonitors -> start (CDB_MONITORS);
01355 }
01356 QDict< QDict<QString> > CDBData = mCDBMonitors -> getTablePointerCDB ();
01357 QDictIterator< QDict<QString> > it (CDBData);
01358 bool found = false;
01359 for (; it.current(); ++it) {
01360 mCDBMonitorData = *it.current();
01361 if ((mCDBMonitorData["DDC"]) && (*mCDBMonitorData["DDC"] == id)) {
01362 mCDBMonitorData.insert ("Name",new QString(it.currentKey()));
01363 found = true;
01364 break;
01365 }
01366 }
01367 if (! found) {
01368 mCDBMonitorData.clear();
01369 }
01370 return mCDBMonitorData;
01371 }
01372
01373
01374
01375 void SaXManipulateDesktop::setCDBMonitorData (
01376 const QString& vendor, const QString& name,
01377 const QString& key, const QString& value
01378 ) {
01379
01384
01385 QString group;
01386 QTextOStream (&group) << vendor << ":" << name;
01387 if ( ! mCDBMonitors ) {
01388 mCDBMonitors = new SaXProcess ();
01389 mCDBMonitors -> start (CDB_MONITORS);
01390 }
01391 mCDBMonitors -> addGroup (
01392 group,key,value
01393 );
01394 }
01395
01396
01397
01398 QString SaXManipulateDesktop::getVendorForDriver ( const QString& driver ) {
01399
01402
01403 SaXProcessCall* proc = new SaXProcessCall ();
01404 proc -> addArgument ( SYSP_VENDOR );
01405 proc -> addArgument ( driver );
01406 if ( ! proc -> start() ) {
01407 excProcessFailed();
01408 qError (errorString(),EXC_PROCESSFAILED);
01409 }
01410 QList<QString> data = proc -> readStdout();
01411 return *data.first();
01412 }
01413
01414
01415
01416 void SaXManipulateDesktop::setExtraModelineString (
01417 const QString & mode
01418 ) {
01419
01422
01423
01424 if ((! mDesktop) || (! mCard) || (! mPath)) {
01425 return;
01426 }
01427 mDesktop -> setItem ( "SpecialModeline",mode );
01428 }
01429
01430
01431
01432 void SaXManipulateDesktop::setExtraModeline (
01433 int x,int y,int refresh,int hsync
01434 ) {
01435
01439
01440 if ((! mDesktop) || (! mCard) || (! mPath)) {
01441 return;
01442 }
01443 QString mode = calculateModeline ( x,y,refresh,hsync );
01444 mDesktop -> setItem ( "SpecialModeline",mode );
01445 }
01446
01447
01448
01449 void SaXManipulateDesktop::addExtraModeline (
01450 int x,int y,int refresh,int hsync
01451 ) {
01452
01456
01457 if ((! mDesktop) || (! mCard) || (! mPath)) {
01458 return;
01459 }
01460 QString val;
01461 QString key = "SpecialModeline";
01462 QString mode = calculateModeline ( x,y,refresh,hsync );
01463 if (! mDesktop -> getItem (key).isEmpty()) {
01464 val = mDesktop -> getItem (key);
01465 }
01466 QTextOStream (&val) << val << "," << mode;
01467 val.replace (QRegExp("^,"),"");
01468 mDesktop -> setItem ( key,val );
01469 }
01470
01471
01472
01473 void SaXManipulateDesktop::removeExtraModeline ( int x,int y) {
01474
01477
01478 if ((! mDesktop) || (! mCard) || (! mPath)) {
01479 return;
01480 }
01481 QString val;
01482 QString key = "SpecialModeline";
01483 val.sprintf ("\"%dx%d\"",x,y);
01484 QString current = mDesktop -> getItem (key);
01485 QStringList lines = QStringList::split ( ",", current );
01486 for (
01487 QStringList::Iterator it=lines.begin();
01488 it != lines.end(); ++it
01489 ) {
01490 QString mode (*it);
01491 if (mode.contains (val)) {
01492 mDesktop -> removeItem (key,mode);
01493 }
01494 }
01495 }
01496
01497
01498
01499 QString SaXManipulateDesktop::calculateModeline (
01500 int x,int y,int refresh,int hsync
01501 ) {
01502
01506
01507 QString result;
01508 for (int r=refresh;r >= 50;r--) {
01509 SaXProcessCall* proc = new SaXProcessCall ();
01510 proc -> addArgument ( XMODE );
01511 proc -> addArgument ( "-x" );
01512 proc -> addArgument ( x );
01513 proc -> addArgument ( "-y" );
01514 proc -> addArgument ( y );
01515 proc -> addArgument ( "-r" );
01516 proc -> addArgument ( r + 2 );
01517 if ( ! proc -> start() ) {
01518 excProcessFailed();
01519 qError (errorString(),EXC_PROCESSFAILED);
01520 }
01521 QList<QString> data = proc->readStdout();
01522 int hs = data.at(0)->toInt();
01523 result = *data.at(2);
01524 if (hs <= hsync) {
01525 break;
01526 }
01527 }
01528 result.replace (QRegExp("^Modeline "),"");
01529 return result;
01530 }
01531
01532
01533
01534 QString SaXManipulateDesktop::getDriverOptionsDualHeadProfile (
01535 const QString& driver
01536 ) {
01537
01541
01542 QString result;
01543 if ((driver == "i810") || (driver == "i915")) {
01544 QTextOStream (&result)
01545 << PROFILE_DIR << "Intel_DualHead_DriverOptions";
01546 }
01547 if (driver == "nvidia") {
01548 QTextOStream (&result)
01549 << PROFILE_DIR << "NVidia_DualHead_DriverOptions";
01550 }
01551 if (driver == "radeon") {
01552 QTextOStream (&result)
01553 << PROFILE_DIR << "Radeon_DualHead_DriverOptions";
01554 }
01555 if (driver == "fglrx") {
01556 QTextOStream (&result)
01557 << PROFILE_DIR << "FGLRX_DualHead_DriverOptions";
01558 }
01559 if (driver == "mga") {
01560 QTextOStream (&result)
01561 << PROFILE_DIR << "Matrox_DualHead_DriverOptions";
01562 }
01563 return result;
01564 }
01565
01566
01567
01568 QDict<QString> SaXManipulateDesktop::getMetaData ( void ) {
01569
01575 QString cardID;
01576 QTextOStream (&cardID) << mDesktopID;
01577 QList<char> metaOptions;
01578 metaOptions.append ( "-c" );
01579 metaOptions.append ( cardID.ascii() );
01580 SaXProcess* proc = new SaXProcess ();
01581 proc->start ( metaOptions , SAX_META );
01582 QDict<QString> metaData = proc->getCurrentTable();
01583 return metaData;
01584 }
01585 }