diff -r d24257910f8d -r aaefa587e277 QTfrontend/ui/page/pageoptions.cpp --- a/QTfrontend/ui/page/pageoptions.cpp Sun Dec 02 00:03:16 2012 +0100 +++ b/QTfrontend/ui/page/pageoptions.cpp Tue Dec 25 04:45:22 2012 +0100 @@ -33,10 +33,19 @@ #include #include "pageoptions.h" +#include "gameuiconfig.h" #include "hwconsts.h" #include "fpsedit.h" #include "igbox.h" #include "DataManager.h" +#include "LibavInteraction.h" +#include "AutoUpdater.h" + +#ifdef __APPLE__ +#ifdef SPARKLE_ENABLED +#include "SparkleAutoUpdater.h" +#endif +#endif // TODO cleanup QLayout * PageOptions::bodyLayoutDefinition() @@ -50,6 +59,11 @@ tabs->addTab(page1, tr("General")); tabs->addTab(page2, tr("Advanced")); +#ifdef VIDEOREC + QWidget * page3 = new QWidget(this); + tabs->addTab(page3, tr("Video Recording")); +#endif + { // page 1 QGridLayout * page1Layout = new QGridLayout(page1); //gbTBLayout->setMargin(0); @@ -191,11 +205,7 @@ // List of installed languages CBLanguage = new QComboBox(groupMisc); - QDir tmpdir; - tmpdir.cd(cfgdir->absolutePath()); - tmpdir.cd("Data/Locale"); - tmpdir.setFilter(QDir::Files); - QStringList locs = tmpdir.entryList(QStringList("hedgewars_*.qm")); + QStringList locs = DataManager::instance().entryList("Locale", QDir::Files, QStringList("hedgewars_*.qm")); CBLanguage->addItem(QComboBox::tr("(System default)"), QString("")); for(int i = 0; i < locs.count(); i++) { @@ -203,17 +213,6 @@ CBLanguage->addItem(QLocale::languageToString(loc.language()) + " (" + QLocale::countryToString(loc.country()) + ")", loc.name()); } - tmpdir.cd(datadir->absolutePath()); - tmpdir.cd("Locale"); - tmpdir.setFilter(QDir::Files); - QStringList tmplist = tmpdir.entryList(QStringList("hedgewars_*.qm")); - for(int i = 0; i < tmplist.count(); i++) - { - if (locs.contains(tmplist[i])) continue; - QLocale loc(tmplist[i].replace(QRegExp("hedgewars_(.*)\\.qm"), "\\1")); - CBLanguage->addItem(QLocale::languageToString(loc.language()) + " (" + QLocale::countryToString(loc.country()) + ")", loc.name()); - } - MiscLayout->addWidget(CBLanguage, 0, 1); // Label and field for net nick @@ -239,7 +238,14 @@ #ifdef SPARKLE_ENABLED CBAutoUpdate = new QCheckBox(groupMisc); CBAutoUpdate->setText(QCheckBox::tr("Check for updates at startup")); - MiscLayout->addWidget(CBAutoUpdate, 7, 0, 1, 3); + MiscLayout->addWidget(CBAutoUpdate, 7, 0, 1, 1); + + btnUpdateNow = new QPushButton(groupMisc); + connect(btnUpdateNow, SIGNAL(clicked()), this, SLOT(checkForUpdates())); + btnUpdateNow->setToolTip(tr("Check for updates")); + btnUpdateNow->setText("Check now"); + btnUpdateNow->setFixedSize(130, 30); + MiscLayout->addWidget(btnUpdateNow, 7, 1, 1, 1); #endif #endif page1Layout->addWidget(groupMisc, 2, 0); @@ -253,25 +259,33 @@ AGGroupBox->setTitle(QGroupBox::tr("Audio/Graphic options")); QVBoxLayout * GBAlayout = new QVBoxLayout(AGGroupBox); + QGridLayout * GBAfrontendlayout = new QGridLayout(0); QHBoxLayout * GBAreslayout = new QHBoxLayout(0); QHBoxLayout * GBAstereolayout = new QHBoxLayout(0); QHBoxLayout * GBAqualayout = new QHBoxLayout(0); + QLabel * frontend = new QLabel(AGGroupBox); + frontend->setText(QLabel::tr("Frontend")); + frontend->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + GBAfrontendlayout->addWidget(frontend, 0, 0, 1, 2); + CBFrontendFullscreen = new QCheckBox(AGGroupBox); - CBFrontendFullscreen->setText(QCheckBox::tr("Frontend fullscreen")); - GBAlayout->addWidget(CBFrontendFullscreen); + CBFrontendFullscreen->setText(QCheckBox::tr("Fullscreen")); + GBAfrontendlayout->addWidget(CBFrontendFullscreen, 1, 0); CBFrontendEffects = new QCheckBox(AGGroupBox); - CBFrontendEffects->setText(QCheckBox::tr("Frontend effects")); - GBAlayout->addWidget(CBFrontendEffects); + CBFrontendEffects->setText(QCheckBox::tr("Visual effects")); + GBAfrontendlayout->addWidget(CBFrontendEffects, 2, 0); - CBEnableFrontendSound = new QCheckBox(AGGroupBox); - CBEnableFrontendSound->setText(QCheckBox::tr("Enable frontend sounds")); - GBAlayout->addWidget(CBEnableFrontendSound); + CBFrontendSound = new QCheckBox(AGGroupBox); + CBFrontendSound->setText(QCheckBox::tr("Sound")); + GBAfrontendlayout->addWidget(CBFrontendSound, 1, 1); - CBEnableFrontendMusic = new QCheckBox(AGGroupBox); - CBEnableFrontendMusic->setText(QCheckBox::tr("Enable frontend music")); - GBAlayout->addWidget(CBEnableFrontendMusic); + CBFrontendMusic = new QCheckBox(AGGroupBox); + CBFrontendMusic->setText(QCheckBox::tr("Music")); + GBAfrontendlayout->addWidget(CBFrontendMusic, 2, 1); + + GBAlayout->addLayout(GBAfrontendlayout); QFrame * hr = new QFrame(AGGroupBox); hr->setFrameStyle(QFrame::HLine); @@ -345,13 +359,15 @@ volumeBox->setSingleStep(5); GBAvollayout->addWidget(volumeBox, 0, 2); - CBEnableSound = new QCheckBox(AGGroupBox); - CBEnableSound->setText(QCheckBox::tr("Enable sound")); - GBAvollayout->addWidget(CBEnableSound, 1, 0, 1, 1); + CBSound = new QCheckBox(AGGroupBox); + CBSound->setText(QCheckBox::tr("Sound")); + CBSound->setWhatsThis(QCheckBox::tr("In-game sound effects")); + GBAvollayout->addWidget(CBSound, 1, 0); - CBEnableMusic = new QCheckBox(AGGroupBox); - CBEnableMusic->setText(QCheckBox::tr("Enable music")); - GBAvollayout->addWidget(CBEnableMusic, 1, 1, 1, 2); + CBMusic = new QCheckBox(AGGroupBox); + CBMusic->setText(QCheckBox::tr("Music")); + CBMusic->setWhatsThis(QCheckBox::tr("In-game music")); + GBAvollayout->addWidget(CBMusic, 1, 1, 1, 2); GBAvollayout->setSizeConstraint(QLayout::SetMinimumSize); @@ -492,6 +508,121 @@ page2Layout->addWidget(new QWidget(this), 2, 0); } +#ifdef VIDEOREC + { // page 3 + QGridLayout * page3Layout = new QGridLayout(page3); + + IconedGroupBox* pOptionsGroup = new IconedGroupBox(this); + pOptionsGroup->setIcon(QIcon(":/res/Settings.png")); // FIXME + pOptionsGroup->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + pOptionsGroup->setTitle(QGroupBox::tr("Video recording options")); + QGridLayout * pOptLayout = new QGridLayout(pOptionsGroup); + + // label for format + QLabel *labelFormat = new QLabel(pOptionsGroup); + labelFormat->setText(QLabel::tr("Format")); + pOptLayout->addWidget(labelFormat, 0, 0); + + // list of supported formats + comboAVFormats = new QComboBox(pOptionsGroup); + pOptLayout->addWidget(comboAVFormats, 0, 1, 1, 4); + LibavInteraction::instance().fillFormats(comboAVFormats); + + // separator + QFrame * hr = new QFrame(pOptionsGroup); + hr->setFrameStyle(QFrame::HLine); + hr->setLineWidth(3); + hr->setFixedHeight(10); + pOptLayout->addWidget(hr, 1, 0, 1, 5); + + // label for audio codec + QLabel *labelACodec = new QLabel(pOptionsGroup); + labelACodec->setText(QLabel::tr("Audio codec")); + pOptLayout->addWidget(labelACodec, 2, 0); + + // list of supported audio codecs + comboAudioCodecs = new QComboBox(pOptionsGroup); + pOptLayout->addWidget(comboAudioCodecs, 2, 1, 1, 3); + + // checkbox 'record audio' + checkRecordAudio = new QCheckBox(pOptionsGroup); + checkRecordAudio->setText(QCheckBox::tr("Record audio")); + pOptLayout->addWidget(checkRecordAudio, 2, 4); + + // separator + hr = new QFrame(pOptionsGroup); + hr->setFrameStyle(QFrame::HLine); + hr->setLineWidth(3); + hr->setFixedHeight(10); + pOptLayout->addWidget(hr, 3, 0, 1, 5); + + // label for video codec + QLabel *labelVCodec = new QLabel(pOptionsGroup); + labelVCodec->setText(QLabel::tr("Video codec")); + pOptLayout->addWidget(labelVCodec, 4, 0); + + // list of supported video codecs + comboVideoCodecs = new QComboBox(pOptionsGroup); + pOptLayout->addWidget(comboVideoCodecs, 4, 1, 1, 4); + + // label for resolution + QLabel *labelRes = new QLabel(pOptionsGroup); + labelRes->setText(QLabel::tr("Resolution")); + pOptLayout->addWidget(labelRes, 5, 0); + + // width + widthEdit = new QLineEdit(pOptionsGroup); + widthEdit->setValidator(new QIntValidator(this)); + pOptLayout->addWidget(widthEdit, 5, 1); + + // x + QLabel *labelX = new QLabel(pOptionsGroup); + labelX->setText("X"); + pOptLayout->addWidget(labelX, 5, 2); + + // height + heightEdit = new QLineEdit(pOptionsGroup); + heightEdit->setValidator(new QIntValidator(pOptionsGroup)); + pOptLayout->addWidget(heightEdit, 5, 3); + + // checkbox 'use game resolution' + checkUseGameRes = new QCheckBox(pOptionsGroup); + checkUseGameRes->setText(QCheckBox::tr("Use game resolution")); + pOptLayout->addWidget(checkUseGameRes, 5, 4); + + // label for framerate + QLabel *labelFramerate = new QLabel(pOptionsGroup); + labelFramerate->setText(QLabel::tr("Framerate")); + pOptLayout->addWidget(labelFramerate, 6, 0); + + framerateBox = new QComboBox(pOptionsGroup); + framerateBox->addItem("24 fps", 24); + framerateBox->addItem("25 fps", 25); + framerateBox->addItem("30 fps", 30); + framerateBox->addItem("50 fps", 50); + framerateBox->addItem("60 fps", 60); + pOptLayout->addWidget(framerateBox, 6, 1); + + // label for Bitrate + QLabel *labelBitrate = new QLabel(pOptionsGroup); + labelBitrate->setText(QLabel::tr("Bitrate (Kbps)")); + pOptLayout->addWidget(labelBitrate, 6, 2); + + // bitrate + bitrateBox = new QSpinBox(pOptionsGroup); + bitrateBox->setRange(100, 5000); + bitrateBox->setSingleStep(100); + pOptLayout->addWidget(bitrateBox, 6, 3); + + // button 'set default options' + btnDefaults = new QPushButton(pOptionsGroup); + btnDefaults->setText(QPushButton::tr("Set default options")); + btnDefaults->setWhatsThis(QPushButton::tr("Restore default coding parameters")); + pOptLayout->addWidget(btnDefaults, 7, 0, 1, 5); + + page3Layout->addWidget(pOptionsGroup, 1, 0); + } +#endif previousQuality = this->SLQuality->value(); previousResolutionIndex = this->CBResolution->currentIndex(); @@ -507,6 +638,13 @@ void PageOptions::connectSignals() { +#ifdef VIDEOREC + connect(checkUseGameRes, SIGNAL(stateChanged(int)), this, SLOT(changeUseGameRes(int))); + connect(checkRecordAudio, SIGNAL(stateChanged(int)), this, SLOT(changeRecordAudio(int))); + connect(comboAVFormats, SIGNAL(currentIndexChanged(int)), this, SLOT(changeAVFormat(int))); + connect(btnDefaults, SIGNAL(clicked()), this, SLOT(setDefaultOptions())); +#endif + connect(SLQuality, SIGNAL(valueChanged(int)), this, SLOT(setQuality(int))); connect(CBResolution, SIGNAL(currentIndexChanged(int)), this, SLOT(setResolution(int))); connect(CBFullscreen, SIGNAL(stateChanged(int)), this, SLOT(setFullscreen(int))); @@ -515,7 +653,7 @@ connect(CBSavePassword, SIGNAL(stateChanged(int)), this, SLOT(savePwdChanged(int))); } -PageOptions::PageOptions(QWidget* parent) : AbstractPage(parent) +PageOptions::PageOptions(QWidget* parent) : AbstractPage(parent), config(0) { initPage(); } @@ -634,3 +772,145 @@ leProxyLogin->setEnabled(b); leProxyPassword->setEnabled(b); } + +// Video Recording + +void PageOptions::setConfig(GameUIConfig * config) +{ + this->config = config; +} + +// user changed file format, we need to update list of codecs +void PageOptions::changeAVFormat(int index) +{ + // remember selected codecs + QString prevVCodec = videoCodec(); + QString prevACodec = audioCodec(); + + // clear lists of codecs + comboVideoCodecs->clear(); + comboAudioCodecs->clear(); + + // get list of codecs for specified format + LibavInteraction::instance().fillCodecs(comboAVFormats->itemData(index).toString(), comboVideoCodecs, comboAudioCodecs); + + // disable audio if there is no audio codec + if (comboAudioCodecs->count() == 0) + { + checkRecordAudio->setChecked(false); + checkRecordAudio->setEnabled(false); + } + else + checkRecordAudio->setEnabled(true); + + // restore selected codecs if possible + int iVCodec = comboVideoCodecs->findData(prevVCodec); + if (iVCodec != -1) + comboVideoCodecs->setCurrentIndex(iVCodec); + int iACodec = comboAudioCodecs->findData(prevACodec); + if (iACodec != -1) + comboAudioCodecs->setCurrentIndex(iACodec); +} + +// user switched checkbox 'use game resolution' +void PageOptions::changeUseGameRes(int state) +{ + if (state && config) + { + // set resolution to game resolution + QRect resolution = config->vid_Resolution(); + widthEdit->setText(QString::number(resolution.width())); + heightEdit->setText(QString::number(resolution.height())); + } + widthEdit->setEnabled(!state); + heightEdit->setEnabled(!state); +} + +// user switched checkbox 'record audio' +void PageOptions::changeRecordAudio(int state) +{ + comboAudioCodecs->setEnabled(!!state); +} + +void PageOptions::setDefaultCodecs() +{ + // VLC should be able to handle any of these configurations + // Quicktime X only opens the first one + // Windows Media Player TODO + if (tryCodecs("mp4", "libx264", "aac")) + return; + if (tryCodecs("mp4", "libx264", "libfaac")) + return; + if (tryCodecs("mp4", "libx264", "libmp3lame")) + return; + if (tryCodecs("mp4", "libx264", "mp2")) + return; + if (tryCodecs("avi", "libxvid", "libmp3lame")) + return; + if (tryCodecs("avi", "libxvid", "ac3_fixed")) + return; + if (tryCodecs("avi", "libxvid", "mp2")) + return; + if (tryCodecs("avi", "mpeg4", "libmp3lame")) + return; + if (tryCodecs("avi", "mpeg4", "ac3_fixed")) + return; + if (tryCodecs("avi", "mpeg4", "mp2")) + return; + + // this shouldn't happen, just in case + if (tryCodecs("ogg", "libtheora", "libvorbis")) + return; + tryCodecs("ogg", "libtheora", "flac"); +} + +void PageOptions::setDefaultOptions() +{ + framerateBox->setCurrentIndex(2); + bitrateBox->setValue(1000); + checkRecordAudio->setChecked(true); + checkUseGameRes->setChecked(true); + setDefaultCodecs(); +} + +void PageOptions::checkForUpdates() +{ + AutoUpdater *updater = NULL; + +#ifdef __APPLE__ +#ifdef SPARKLE_ENABLED + updater = new SparkleAutoUpdater(); +#endif +#endif + + if (updater) + { + updater->checkForUpdatesNow(); + delete updater; + } +} + +bool PageOptions::tryCodecs(const QString & format, const QString & vcodec, const QString & acodec) +{ + // first we should change format + int iFormat = comboAVFormats->findData(format); + if (iFormat == -1) + return false; + comboAVFormats->setCurrentIndex(iFormat); + // format was changed, so lists of codecs were automatically updated to codecs supported by this format + + // try to find video codec + int iVCodec = comboVideoCodecs->findData(vcodec); + if (iVCodec == -1) + return false; + comboVideoCodecs->setCurrentIndex(iVCodec); + + // try to find audio codec + int iACodec = comboAudioCodecs->findData(acodec); + if (iACodec == -1 && checkRecordAudio->isChecked()) + return false; + if (iACodec != -1) + comboAudioCodecs->setCurrentIndex(iACodec); + + return true; +}