QTfrontend/ui/page/pageoptions.cpp
branchwebgl
changeset 8330 aaefa587e277
parent 8284 a874d00df4a4
child 8343 aa4ea3cade3c
child 8346 3443e0de2c9d
equal deleted inserted replaced
8116:d24257910f8d 8330:aaefa587e277
    31 #include <QSignalMapper>
    31 #include <QSignalMapper>
    32 #include <QColorDialog>
    32 #include <QColorDialog>
    33 #include <QStandardItemModel>
    33 #include <QStandardItemModel>
    34 
    34 
    35 #include "pageoptions.h"
    35 #include "pageoptions.h"
       
    36 #include "gameuiconfig.h"
    36 #include "hwconsts.h"
    37 #include "hwconsts.h"
    37 #include "fpsedit.h"
    38 #include "fpsedit.h"
    38 #include "igbox.h"
    39 #include "igbox.h"
    39 #include "DataManager.h"
    40 #include "DataManager.h"
       
    41 #include "LibavInteraction.h"
       
    42 #include "AutoUpdater.h"
       
    43 
       
    44 #ifdef __APPLE__
       
    45 #ifdef SPARKLE_ENABLED
       
    46 #include "SparkleAutoUpdater.h"
       
    47 #endif
       
    48 #endif
    40 
    49 
    41 // TODO cleanup
    50 // TODO cleanup
    42 QLayout * PageOptions::bodyLayoutDefinition()
    51 QLayout * PageOptions::bodyLayoutDefinition()
    43 {
    52 {
    44     QVBoxLayout * pageLayout = new QVBoxLayout();
    53     QVBoxLayout * pageLayout = new QVBoxLayout();
    47     pageLayout->addWidget(tabs);
    56     pageLayout->addWidget(tabs);
    48     QWidget * page1 = new QWidget(this);
    57     QWidget * page1 = new QWidget(this);
    49     QWidget * page2 = new QWidget(this);
    58     QWidget * page2 = new QWidget(this);
    50     tabs->addTab(page1, tr("General"));
    59     tabs->addTab(page1, tr("General"));
    51     tabs->addTab(page2, tr("Advanced"));
    60     tabs->addTab(page2, tr("Advanced"));
       
    61 
       
    62 #ifdef VIDEOREC
       
    63     QWidget * page3 = new QWidget(this);
       
    64     tabs->addTab(page3, tr("Video Recording"));
       
    65 #endif
    52 
    66 
    53     { // page 1
    67     { // page 1
    54         QGridLayout * page1Layout = new QGridLayout(page1);
    68         QGridLayout * page1Layout = new QGridLayout(page1);
    55         //gbTBLayout->setMargin(0);
    69         //gbTBLayout->setMargin(0);
    56         page1Layout->setSpacing(0);
    70         page1Layout->setSpacing(0);
   189             labelLanguage->setText(QLabel::tr("Locale") + " *");
   203             labelLanguage->setText(QLabel::tr("Locale") + " *");
   190             MiscLayout->addWidget(labelLanguage, 0, 0);
   204             MiscLayout->addWidget(labelLanguage, 0, 0);
   191 
   205 
   192             // List of installed languages
   206             // List of installed languages
   193             CBLanguage = new QComboBox(groupMisc);
   207             CBLanguage = new QComboBox(groupMisc);
   194             QDir tmpdir;
   208             QStringList locs = DataManager::instance().entryList("Locale", QDir::Files, QStringList("hedgewars_*.qm"));
   195             tmpdir.cd(cfgdir->absolutePath());
       
   196             tmpdir.cd("Data/Locale");
       
   197             tmpdir.setFilter(QDir::Files);
       
   198             QStringList locs = tmpdir.entryList(QStringList("hedgewars_*.qm"));
       
   199             CBLanguage->addItem(QComboBox::tr("(System default)"), QString(""));
   209             CBLanguage->addItem(QComboBox::tr("(System default)"), QString(""));
   200             for(int i = 0; i < locs.count(); i++)
   210             for(int i = 0; i < locs.count(); i++)
   201             {
   211             {
   202                 QLocale loc(locs[i].replace(QRegExp("hedgewars_(.*)\\.qm"), "\\1"));
   212                 QLocale loc(locs[i].replace(QRegExp("hedgewars_(.*)\\.qm"), "\\1"));
   203                 CBLanguage->addItem(QLocale::languageToString(loc.language()) + " (" + QLocale::countryToString(loc.country()) + ")", loc.name());
   213                 CBLanguage->addItem(QLocale::languageToString(loc.language()) + " (" + QLocale::countryToString(loc.country()) + ")", loc.name());
   204             }
   214             }
   205 
   215 
   206             tmpdir.cd(datadir->absolutePath());
       
   207             tmpdir.cd("Locale");
       
   208             tmpdir.setFilter(QDir::Files);
       
   209             QStringList tmplist = tmpdir.entryList(QStringList("hedgewars_*.qm"));
       
   210             for(int i = 0; i < tmplist.count(); i++)
       
   211             {
       
   212                 if (locs.contains(tmplist[i])) continue;
       
   213                 QLocale loc(tmplist[i].replace(QRegExp("hedgewars_(.*)\\.qm"), "\\1"));
       
   214                 CBLanguage->addItem(QLocale::languageToString(loc.language()) + " (" + QLocale::countryToString(loc.country()) + ")", loc.name());
       
   215             }
       
   216 
       
   217             MiscLayout->addWidget(CBLanguage, 0, 1);
   216             MiscLayout->addWidget(CBLanguage, 0, 1);
   218 
   217 
   219             // Label and field for net nick
   218             // Label and field for net nick
   220             labelNN = new QLabel(groupMisc);
   219             labelNN = new QLabel(groupMisc);
   221             labelNN->setText(QLabel::tr("Nickname"));
   220             labelNN->setText(QLabel::tr("Nickname"));
   237 
   236 
   238     #ifdef __APPLE__
   237     #ifdef __APPLE__
   239     #ifdef SPARKLE_ENABLED
   238     #ifdef SPARKLE_ENABLED
   240             CBAutoUpdate = new QCheckBox(groupMisc);
   239             CBAutoUpdate = new QCheckBox(groupMisc);
   241             CBAutoUpdate->setText(QCheckBox::tr("Check for updates at startup"));
   240             CBAutoUpdate->setText(QCheckBox::tr("Check for updates at startup"));
   242             MiscLayout->addWidget(CBAutoUpdate, 7, 0, 1, 3);
   241             MiscLayout->addWidget(CBAutoUpdate, 7, 0, 1, 1);
       
   242 
       
   243             btnUpdateNow = new QPushButton(groupMisc);
       
   244             connect(btnUpdateNow, SIGNAL(clicked()), this, SLOT(checkForUpdates()));
       
   245             btnUpdateNow->setToolTip(tr("Check for updates"));
       
   246             btnUpdateNow->setText("Check now");
       
   247             btnUpdateNow->setFixedSize(130, 30);
       
   248             MiscLayout->addWidget(btnUpdateNow, 7, 1, 1, 1);
   243     #endif
   249     #endif
   244     #endif
   250     #endif
   245             page1Layout->addWidget(groupMisc, 2, 0);
   251             page1Layout->addWidget(groupMisc, 2, 0);
   246         }
   252         }
   247 
   253 
   251             AGGroupBox->setIcon(QIcon(":/res/graphicsicon.png"));
   257             AGGroupBox->setIcon(QIcon(":/res/graphicsicon.png"));
   252             //AGGroupBox->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
   258             //AGGroupBox->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
   253             AGGroupBox->setTitle(QGroupBox::tr("Audio/Graphic options"));
   259             AGGroupBox->setTitle(QGroupBox::tr("Audio/Graphic options"));
   254 
   260 
   255             QVBoxLayout * GBAlayout = new QVBoxLayout(AGGroupBox);
   261             QVBoxLayout * GBAlayout = new QVBoxLayout(AGGroupBox);
       
   262             QGridLayout * GBAfrontendlayout = new QGridLayout(0);
   256             QHBoxLayout * GBAreslayout = new QHBoxLayout(0);
   263             QHBoxLayout * GBAreslayout = new QHBoxLayout(0);
   257             QHBoxLayout * GBAstereolayout = new QHBoxLayout(0);
   264             QHBoxLayout * GBAstereolayout = new QHBoxLayout(0);
   258             QHBoxLayout * GBAqualayout = new QHBoxLayout(0);
   265             QHBoxLayout * GBAqualayout = new QHBoxLayout(0);
   259 
   266 
       
   267             QLabel * frontend = new QLabel(AGGroupBox);
       
   268             frontend->setText(QLabel::tr("Frontend"));
       
   269             frontend->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
       
   270             GBAfrontendlayout->addWidget(frontend, 0, 0, 1, 2);
       
   271 
   260             CBFrontendFullscreen = new QCheckBox(AGGroupBox);
   272             CBFrontendFullscreen = new QCheckBox(AGGroupBox);
   261             CBFrontendFullscreen->setText(QCheckBox::tr("Frontend fullscreen"));
   273             CBFrontendFullscreen->setText(QCheckBox::tr("Fullscreen"));
   262             GBAlayout->addWidget(CBFrontendFullscreen);
   274             GBAfrontendlayout->addWidget(CBFrontendFullscreen, 1, 0);
   263 
   275 
   264             CBFrontendEffects = new QCheckBox(AGGroupBox);
   276             CBFrontendEffects = new QCheckBox(AGGroupBox);
   265             CBFrontendEffects->setText(QCheckBox::tr("Frontend effects"));
   277             CBFrontendEffects->setText(QCheckBox::tr("Visual effects"));
   266             GBAlayout->addWidget(CBFrontendEffects);
   278             GBAfrontendlayout->addWidget(CBFrontendEffects, 2, 0);
   267 
   279 
   268             CBEnableFrontendSound = new QCheckBox(AGGroupBox);
   280             CBFrontendSound = new QCheckBox(AGGroupBox);
   269             CBEnableFrontendSound->setText(QCheckBox::tr("Enable frontend sounds"));
   281             CBFrontendSound->setText(QCheckBox::tr("Sound"));
   270             GBAlayout->addWidget(CBEnableFrontendSound);
   282             GBAfrontendlayout->addWidget(CBFrontendSound, 1, 1);
   271 
   283 
   272             CBEnableFrontendMusic = new QCheckBox(AGGroupBox);
   284             CBFrontendMusic = new QCheckBox(AGGroupBox);
   273             CBEnableFrontendMusic->setText(QCheckBox::tr("Enable frontend music"));
   285             CBFrontendMusic->setText(QCheckBox::tr("Music"));
   274             GBAlayout->addWidget(CBEnableFrontendMusic);
   286             GBAfrontendlayout->addWidget(CBFrontendMusic, 2, 1);
       
   287 
       
   288             GBAlayout->addLayout(GBAfrontendlayout);
   275 
   289 
   276             QFrame * hr = new QFrame(AGGroupBox);
   290             QFrame * hr = new QFrame(AGGroupBox);
   277             hr->setFrameStyle(QFrame::HLine);
   291             hr->setFrameStyle(QFrame::HLine);
   278             hr->setLineWidth(3);
   292             hr->setLineWidth(3);
   279             hr->setFixedHeight(10);
   293             hr->setFixedHeight(10);
   343             volumeBox = new QSpinBox(AGGroupBox);
   357             volumeBox = new QSpinBox(AGGroupBox);
   344             volumeBox->setRange(0, 100);
   358             volumeBox->setRange(0, 100);
   345             volumeBox->setSingleStep(5);
   359             volumeBox->setSingleStep(5);
   346             GBAvollayout->addWidget(volumeBox, 0, 2);
   360             GBAvollayout->addWidget(volumeBox, 0, 2);
   347 
   361 
   348             CBEnableSound = new QCheckBox(AGGroupBox);
   362             CBSound = new QCheckBox(AGGroupBox);
   349             CBEnableSound->setText(QCheckBox::tr("Enable sound"));
   363             CBSound->setText(QCheckBox::tr("Sound"));
   350             GBAvollayout->addWidget(CBEnableSound, 1, 0, 1, 1);
   364             CBSound->setWhatsThis(QCheckBox::tr("In-game sound effects"));
   351 
   365             GBAvollayout->addWidget(CBSound, 1, 0);
   352             CBEnableMusic = new QCheckBox(AGGroupBox);
   366 
   353             CBEnableMusic->setText(QCheckBox::tr("Enable music"));
   367             CBMusic = new QCheckBox(AGGroupBox);
   354             GBAvollayout->addWidget(CBEnableMusic, 1, 1, 1, 2);
   368             CBMusic->setText(QCheckBox::tr("Music"));
       
   369             CBMusic->setWhatsThis(QCheckBox::tr("In-game music"));
       
   370             GBAvollayout->addWidget(CBMusic, 1, 1, 1, 2);
   355 
   371 
   356             GBAvollayout->setSizeConstraint(QLayout::SetMinimumSize);
   372             GBAvollayout->setSizeConstraint(QLayout::SetMinimumSize);
   357 
   373 
   358             hr = new QFrame(AGGroupBox);
   374             hr = new QFrame(AGGroupBox);
   359             hr->setFrameStyle(QFrame::HLine);
   375             hr->setFrameStyle(QFrame::HLine);
   490             onProxyTypeChanged();
   506             onProxyTypeChanged();
   491         }
   507         }
   492 
   508 
   493         page2Layout->addWidget(new QWidget(this), 2, 0);
   509         page2Layout->addWidget(new QWidget(this), 2, 0);
   494     }
   510     }
       
   511 #ifdef VIDEOREC
       
   512     { // page 3
       
   513         QGridLayout * page3Layout = new QGridLayout(page3);
       
   514 
       
   515         IconedGroupBox* pOptionsGroup = new IconedGroupBox(this);
       
   516         pOptionsGroup->setIcon(QIcon(":/res/Settings.png")); // FIXME
       
   517         pOptionsGroup->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
       
   518         pOptionsGroup->setTitle(QGroupBox::tr("Video recording options"));
       
   519         QGridLayout * pOptLayout = new QGridLayout(pOptionsGroup);
       
   520 
       
   521         // label for format
       
   522         QLabel *labelFormat = new QLabel(pOptionsGroup);
       
   523         labelFormat->setText(QLabel::tr("Format"));
       
   524         pOptLayout->addWidget(labelFormat, 0, 0);
       
   525 
       
   526         // list of supported formats
       
   527         comboAVFormats = new QComboBox(pOptionsGroup);
       
   528         pOptLayout->addWidget(comboAVFormats, 0, 1, 1, 4);
       
   529         LibavInteraction::instance().fillFormats(comboAVFormats);
       
   530 
       
   531         // separator
       
   532         QFrame * hr = new QFrame(pOptionsGroup);
       
   533         hr->setFrameStyle(QFrame::HLine);
       
   534         hr->setLineWidth(3);
       
   535         hr->setFixedHeight(10);
       
   536         pOptLayout->addWidget(hr, 1, 0, 1, 5);
       
   537 
       
   538         // label for audio codec
       
   539         QLabel *labelACodec = new QLabel(pOptionsGroup);
       
   540         labelACodec->setText(QLabel::tr("Audio codec"));
       
   541         pOptLayout->addWidget(labelACodec, 2, 0);
       
   542 
       
   543         // list of supported audio codecs
       
   544         comboAudioCodecs = new QComboBox(pOptionsGroup);
       
   545         pOptLayout->addWidget(comboAudioCodecs, 2, 1, 1, 3);
       
   546 
       
   547         // checkbox 'record audio'
       
   548         checkRecordAudio = new QCheckBox(pOptionsGroup);
       
   549         checkRecordAudio->setText(QCheckBox::tr("Record audio"));
       
   550         pOptLayout->addWidget(checkRecordAudio, 2, 4);
       
   551 
       
   552         // separator
       
   553         hr = new QFrame(pOptionsGroup);
       
   554         hr->setFrameStyle(QFrame::HLine);
       
   555         hr->setLineWidth(3);
       
   556         hr->setFixedHeight(10);
       
   557         pOptLayout->addWidget(hr, 3, 0, 1, 5);
       
   558 
       
   559         // label for video codec
       
   560         QLabel *labelVCodec = new QLabel(pOptionsGroup);
       
   561         labelVCodec->setText(QLabel::tr("Video codec"));
       
   562         pOptLayout->addWidget(labelVCodec, 4, 0);
       
   563 
       
   564         // list of supported video codecs
       
   565         comboVideoCodecs = new QComboBox(pOptionsGroup);
       
   566         pOptLayout->addWidget(comboVideoCodecs, 4, 1, 1, 4);
       
   567 
       
   568         // label for resolution
       
   569         QLabel *labelRes = new QLabel(pOptionsGroup);
       
   570         labelRes->setText(QLabel::tr("Resolution"));
       
   571         pOptLayout->addWidget(labelRes, 5, 0);
       
   572 
       
   573         // width
       
   574         widthEdit = new QLineEdit(pOptionsGroup);
       
   575         widthEdit->setValidator(new QIntValidator(this));
       
   576         pOptLayout->addWidget(widthEdit, 5, 1);
       
   577 
       
   578         // x
       
   579         QLabel *labelX = new QLabel(pOptionsGroup);
       
   580         labelX->setText("X");
       
   581         pOptLayout->addWidget(labelX, 5, 2);
       
   582 
       
   583         // height
       
   584         heightEdit = new QLineEdit(pOptionsGroup);
       
   585         heightEdit->setValidator(new QIntValidator(pOptionsGroup));
       
   586         pOptLayout->addWidget(heightEdit, 5, 3);
       
   587 
       
   588         // checkbox 'use game resolution'
       
   589         checkUseGameRes = new QCheckBox(pOptionsGroup);
       
   590         checkUseGameRes->setText(QCheckBox::tr("Use game resolution"));
       
   591         pOptLayout->addWidget(checkUseGameRes, 5, 4);
       
   592 
       
   593         // label for framerate
       
   594         QLabel *labelFramerate = new QLabel(pOptionsGroup);
       
   595         labelFramerate->setText(QLabel::tr("Framerate"));
       
   596         pOptLayout->addWidget(labelFramerate, 6, 0);
       
   597 
       
   598         framerateBox = new QComboBox(pOptionsGroup);
       
   599         framerateBox->addItem("24 fps", 24);
       
   600         framerateBox->addItem("25 fps", 25);
       
   601         framerateBox->addItem("30 fps", 30);
       
   602         framerateBox->addItem("50 fps", 50);
       
   603         framerateBox->addItem("60 fps", 60);
       
   604         pOptLayout->addWidget(framerateBox, 6, 1);
       
   605 
       
   606         // label for Bitrate
       
   607         QLabel *labelBitrate = new QLabel(pOptionsGroup);
       
   608         labelBitrate->setText(QLabel::tr("Bitrate (Kbps)"));
       
   609         pOptLayout->addWidget(labelBitrate, 6, 2);
       
   610 
       
   611         // bitrate
       
   612         bitrateBox = new QSpinBox(pOptionsGroup);
       
   613         bitrateBox->setRange(100, 5000);
       
   614         bitrateBox->setSingleStep(100);
       
   615         pOptLayout->addWidget(bitrateBox, 6, 3);
       
   616 
       
   617         // button 'set default options'
       
   618         btnDefaults = new QPushButton(pOptionsGroup);
       
   619         btnDefaults->setText(QPushButton::tr("Set default options"));
       
   620         btnDefaults->setWhatsThis(QPushButton::tr("Restore default coding parameters"));
       
   621         pOptLayout->addWidget(btnDefaults, 7, 0, 1, 5);
       
   622 
       
   623         page3Layout->addWidget(pOptionsGroup, 1, 0);
       
   624     }
       
   625 #endif
   495 
   626 
   496     previousQuality = this->SLQuality->value();
   627     previousQuality = this->SLQuality->value();
   497     previousResolutionIndex = this->CBResolution->currentIndex();
   628     previousResolutionIndex = this->CBResolution->currentIndex();
   498     previousFullscreenValue = this->CBFullscreen->isChecked();
   629     previousFullscreenValue = this->CBFullscreen->isChecked();
   499 
   630 
   505     return NULL;
   636     return NULL;
   506 }
   637 }
   507 
   638 
   508 void PageOptions::connectSignals()
   639 void PageOptions::connectSignals()
   509 {
   640 {
       
   641 #ifdef VIDEOREC
       
   642     connect(checkUseGameRes, SIGNAL(stateChanged(int)), this, SLOT(changeUseGameRes(int)));
       
   643     connect(checkRecordAudio, SIGNAL(stateChanged(int)), this, SLOT(changeRecordAudio(int)));
       
   644     connect(comboAVFormats, SIGNAL(currentIndexChanged(int)), this, SLOT(changeAVFormat(int)));
       
   645     connect(btnDefaults, SIGNAL(clicked()), this, SLOT(setDefaultOptions()));
       
   646 #endif
       
   647 
   510     connect(SLQuality, SIGNAL(valueChanged(int)), this, SLOT(setQuality(int)));
   648     connect(SLQuality, SIGNAL(valueChanged(int)), this, SLOT(setQuality(int)));
   511     connect(CBResolution, SIGNAL(currentIndexChanged(int)), this, SLOT(setResolution(int)));
   649     connect(CBResolution, SIGNAL(currentIndexChanged(int)), this, SLOT(setResolution(int)));
   512     connect(CBFullscreen, SIGNAL(stateChanged(int)), this, SLOT(setFullscreen(int)));
   650     connect(CBFullscreen, SIGNAL(stateChanged(int)), this, SLOT(setFullscreen(int)));
   513     connect(CBStereoMode, SIGNAL(currentIndexChanged(int)), this, SLOT(forceFullscreen(int)));
   651     connect(CBStereoMode, SIGNAL(currentIndexChanged(int)), this, SLOT(forceFullscreen(int)));
   514     connect(editNetNick, SIGNAL(editingFinished()), this, SLOT(trimNetNick()));
   652     connect(editNetNick, SIGNAL(editingFinished()), this, SLOT(trimNetNick()));
   515     connect(CBSavePassword, SIGNAL(stateChanged(int)), this, SLOT(savePwdChanged(int)));
   653     connect(CBSavePassword, SIGNAL(stateChanged(int)), this, SLOT(savePwdChanged(int)));
   516 }
   654 }
   517 
   655 
   518 PageOptions::PageOptions(QWidget* parent) : AbstractPage(parent)
   656 PageOptions::PageOptions(QWidget* parent) : AbstractPage(parent), config(0)
   519 {
   657 {
   520     initPage();
   658     initPage();
   521 }
   659 }
   522 
   660 
   523 void PageOptions::forceFullscreen(int index)
   661 void PageOptions::forceFullscreen(int index)
   632     sbProxyPort->setEnabled(b);
   770     sbProxyPort->setEnabled(b);
   633     leProxy->setEnabled(b);
   771     leProxy->setEnabled(b);
   634     leProxyLogin->setEnabled(b);
   772     leProxyLogin->setEnabled(b);
   635     leProxyPassword->setEnabled(b);
   773     leProxyPassword->setEnabled(b);
   636 }
   774 }
       
   775 
       
   776 // Video Recording
       
   777 
       
   778 void PageOptions::setConfig(GameUIConfig * config)
       
   779 {
       
   780     this->config = config;
       
   781 }
       
   782 
       
   783 // user changed file format, we need to update list of codecs
       
   784 void PageOptions::changeAVFormat(int index)
       
   785 {
       
   786     // remember selected codecs
       
   787     QString prevVCodec = videoCodec();
       
   788     QString prevACodec = audioCodec();
       
   789 
       
   790     // clear lists of codecs
       
   791     comboVideoCodecs->clear();
       
   792     comboAudioCodecs->clear();
       
   793 
       
   794     // get list of codecs for specified format
       
   795     LibavInteraction::instance().fillCodecs(comboAVFormats->itemData(index).toString(), comboVideoCodecs, comboAudioCodecs);
       
   796 
       
   797     // disable audio if there is no audio codec
       
   798     if (comboAudioCodecs->count() == 0)
       
   799     {
       
   800         checkRecordAudio->setChecked(false);
       
   801         checkRecordAudio->setEnabled(false);
       
   802     }
       
   803     else
       
   804         checkRecordAudio->setEnabled(true);
       
   805 
       
   806     // restore selected codecs if possible
       
   807     int iVCodec = comboVideoCodecs->findData(prevVCodec);
       
   808     if (iVCodec != -1)
       
   809         comboVideoCodecs->setCurrentIndex(iVCodec);
       
   810     int iACodec = comboAudioCodecs->findData(prevACodec);
       
   811     if (iACodec != -1)
       
   812         comboAudioCodecs->setCurrentIndex(iACodec);
       
   813 }
       
   814 
       
   815 // user switched checkbox 'use game resolution'
       
   816 void PageOptions::changeUseGameRes(int state)
       
   817 {
       
   818     if (state && config)
       
   819     {
       
   820         // set resolution to game resolution
       
   821         QRect resolution = config->vid_Resolution();
       
   822         widthEdit->setText(QString::number(resolution.width()));
       
   823         heightEdit->setText(QString::number(resolution.height()));
       
   824     }
       
   825     widthEdit->setEnabled(!state);
       
   826     heightEdit->setEnabled(!state);
       
   827 }
       
   828 
       
   829 // user switched checkbox 'record audio'
       
   830 void PageOptions::changeRecordAudio(int state)
       
   831 {
       
   832     comboAudioCodecs->setEnabled(!!state);
       
   833 }
       
   834 
       
   835 void PageOptions::setDefaultCodecs()
       
   836 {
       
   837     // VLC should be able to handle any of these configurations
       
   838     // Quicktime X only opens the first one
       
   839     // Windows Media Player TODO
       
   840     if (tryCodecs("mp4", "libx264", "aac"))
       
   841         return;
       
   842     if (tryCodecs("mp4", "libx264", "libfaac"))
       
   843         return;
       
   844     if (tryCodecs("mp4", "libx264", "libmp3lame"))
       
   845         return;
       
   846     if (tryCodecs("mp4", "libx264", "mp2"))
       
   847         return;
       
   848     if (tryCodecs("avi", "libxvid", "libmp3lame"))
       
   849         return;
       
   850     if (tryCodecs("avi", "libxvid", "ac3_fixed"))
       
   851         return;
       
   852     if (tryCodecs("avi", "libxvid", "mp2"))
       
   853         return;
       
   854     if (tryCodecs("avi", "mpeg4", "libmp3lame"))
       
   855         return;
       
   856     if (tryCodecs("avi", "mpeg4", "ac3_fixed"))
       
   857         return;
       
   858     if (tryCodecs("avi", "mpeg4", "mp2"))
       
   859         return;
       
   860 
       
   861     // this shouldn't happen, just in case
       
   862     if (tryCodecs("ogg", "libtheora", "libvorbis"))
       
   863         return;
       
   864     tryCodecs("ogg", "libtheora", "flac");
       
   865 }
       
   866 
       
   867 void PageOptions::setDefaultOptions()
       
   868 {
       
   869     framerateBox->setCurrentIndex(2);
       
   870     bitrateBox->setValue(1000);
       
   871     checkRecordAudio->setChecked(true);
       
   872     checkUseGameRes->setChecked(true);
       
   873     setDefaultCodecs();
       
   874 }
       
   875 
       
   876 void PageOptions::checkForUpdates()
       
   877 {
       
   878     AutoUpdater *updater = NULL;
       
   879 
       
   880 #ifdef __APPLE__
       
   881 #ifdef SPARKLE_ENABLED
       
   882     updater = new SparkleAutoUpdater();
       
   883 #endif
       
   884 #endif
       
   885 
       
   886     if (updater)
       
   887     {
       
   888         updater->checkForUpdatesNow();
       
   889         delete updater;
       
   890     }
       
   891 }
       
   892 
       
   893 bool PageOptions::tryCodecs(const QString & format, const QString & vcodec, const QString & acodec)
       
   894 {
       
   895     // first we should change format
       
   896     int iFormat = comboAVFormats->findData(format);
       
   897     if (iFormat == -1)
       
   898         return false;
       
   899     comboAVFormats->setCurrentIndex(iFormat);
       
   900     // format was changed, so lists of codecs were automatically updated to codecs supported by this format
       
   901 
       
   902     // try to find video codec
       
   903     int iVCodec = comboVideoCodecs->findData(vcodec);
       
   904     if (iVCodec == -1)
       
   905         return false;
       
   906     comboVideoCodecs->setCurrentIndex(iVCodec);
       
   907 
       
   908     // try to find audio codec
       
   909     int iACodec = comboAudioCodecs->findData(acodec);
       
   910     if (iACodec == -1 && checkRecordAudio->isChecked())
       
   911         return false;
       
   912     if (iACodec != -1)
       
   913         comboAudioCodecs->setCurrentIndex(iACodec);
       
   914 
       
   915     return true;
       
   916 }