diff --git a/apps/launcher/datafilespage.cpp b/apps/launcher/datafilespage.cpp index 2e8cdfbd2..80694f279 100644 --- a/apps/launcher/datafilespage.cpp +++ b/apps/launcher/datafilespage.cpp @@ -163,7 +163,7 @@ void DataFilesPage::setupDataFiles(const QStringList &paths, bool strict) { ESMReader fileReader; QStringList availableMasters; // Will contain all found masters - + fileReader.setEncoding("win1252"); fileReader.open(iter->second.string()); @@ -178,10 +178,13 @@ void DataFilesPage::setupDataFiles(const QStringList &paths, bool strict) if (itemList.isEmpty()) // Master is not yet in the widget { - // TODO: Show warning, missing master mMastersWidget->insertRow(i); + QTableWidgetItem *item = new QTableWidgetItem(currentMaster); - mMastersWidget->setItem(i, 0, item); + item->setForeground(Qt::red); + item->setFlags(item->flags() & ~(Qt::ItemIsSelectable)); + + mMastersWidget->setItem(i, 0, item); } } @@ -190,9 +193,31 @@ void DataFilesPage::setupDataFiles(const QStringList &paths, bool strict) // Now we put the current plugin in the mDataFilesModel under its masters QStandardItem *parent = new QStandardItem(availableMasters.join(",")); - std::string filename = boost::filesystem::path (iter->second.filename()).string(); - QStandardItem *child = new QStandardItem(QString::fromStdString(std::string(filename))); - + QString fileName = QString::fromStdString(boost::filesystem::path (iter->second.filename()).string()); + QStandardItem *child = new QStandardItem(fileName); + + // Tooltip information + QString author = QString::fromStdString(fileReader.getAuthor()); + float version = fileReader.getFVer(); + QString description = QString::fromStdString(fileReader.getDesc()); + + // For the date created/modified + QFileInfo fi(QString::fromStdString(iter->second.string())); + + QString toolTip= QString("Author: %1
\ + Version: %2

\ + Description:
\ + %3

\ + Created on: %4
\ + Last modified: %5") + .arg(author) + .arg(version) + .arg(description) + .arg(fi.created().toString(Qt::TextDate)) + .arg(fi.lastModified().toString(Qt::TextDate)); + + child->setToolTip(toolTip); + const QList masterList = mDataFilesModel->findItems(availableMasters.join(",")); if (masterList.isEmpty()) { // Masters node not yet in the mDataFilesModel @@ -643,7 +668,11 @@ void DataFilesPage::scrollToSelection() void DataFilesPage::showContextMenu(const QPoint &point) { - + // Make sure there are plugins in the view + if (!mPluginsTable->selectionModel()->hasSelection()) { + return; + } + QPoint globalPos = mPluginsTable->mapToGlobal(point); QModelIndexList selectedIndexes = mPluginsTable->selectionModel()->selectedIndexes(); @@ -762,6 +791,7 @@ void DataFilesPage::addPlugins(const QModelIndex &index) if (childIndex.isValid()) { // Now we see if the pluginsmodel already contains this plugin const QString childIndexData = QVariant(mDataFilesModel->data(childIndex)).toString(); + const QString childIndexToolTip = QVariant(mDataFilesModel->data(childIndex, Qt::ToolTipRole)).toString(); const QList itemList = mPluginsModel->findItems(childIndexData); @@ -771,6 +801,7 @@ void DataFilesPage::addPlugins(const QModelIndex &index) QStandardItem *item = new QStandardItem(childIndexData); item->setFlags(item->flags() & ~(Qt::ItemIsDropEnabled)); item->setCheckable(true); + item->setToolTip(childIndexToolTip); mPluginsModel->appendRow(item); } @@ -936,6 +967,11 @@ void DataFilesPage::readConfig() void DataFilesPage::writeConfig(QString profile) { + // Don't overwrite the config if no plugins are found + if (mPluginsModel->rowCount() < 1) { + return; + } + if (profile.isEmpty()) { profile = mProfilesComboBox->currentText(); } diff --git a/apps/launcher/graphicspage.cpp b/apps/launcher/graphicspage.cpp index d97a915c9..c63dbda40 100644 --- a/apps/launcher/graphicspage.cpp +++ b/apps/launcher/graphicspage.cpp @@ -185,9 +185,13 @@ void GraphicsPage::setupOgre() Ogre::LogManager* logMgr = OGRE_NEW Ogre::LogManager; logMgr->createLog("launcherOgre.log", true, false, false); + QString ogreCfg = QString::fromStdString(Files::getPath(Files::Path_ConfigUser, + "openmw", "ogre.cfg")); + file.setFileName(ogreCfg); + try { - mOgre = new Ogre::Root(pluginCfg.toStdString()); + mOgre = new Ogre::Root(pluginCfg.toStdString(), file.fileName().toStdString(), "./launcherOgre.log"); } catch(Ogre::Exception &ex) { @@ -342,95 +346,92 @@ void GraphicsPage::readConfig() void GraphicsPage::writeConfig() { - // Write the config file settings - - // Custom write method: We cannot use QSettings because it does not accept spaces - QFile file(mOgreConfig->fileName()); - - if (!file.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)) { - // File could not be opened, - QMessageBox msgBox; - msgBox.setWindowTitle("Error opening Ogre configuration file"); - msgBox.setIcon(QMessageBox::Critical); - msgBox.setStandardButtons(QMessageBox::Ok); - msgBox.setText(tr("
Could not open %0

\ - Please make sure you have the right permissions and try again.
").arg(file.fileName())); - msgBox.exec(); - return; - } - - QTextStream out(&file); - - out << "Render System=" << mSelectedRenderSystem->getName().c_str() << endl << endl; + mOgre->setRenderSystem(mSelectedRenderSystem); if (mDirect3DRenderSystem) { - QString direct3DName = mDirect3DRenderSystem->getName().c_str(); - direct3DName.prepend("["); - direct3DName.append("]"); - out << direct3DName << endl; - + // Nvidia Performance HUD if (mD3DNvPerfCheckBox->checkState() == Qt::Checked) { - out << "Allow NVPerfHUD=Yes" << endl; + mDirect3DRenderSystem->setConfigOption("Allow NVPerfHUD", "Yes"); } else { - out << "Allow NVPerfHUD=No" << endl; + mDirect3DRenderSystem->setConfigOption("Allow NVPerfHUD", "No"); } - - out << "FSAA=" << mD3DAntiAliasingComboBox->currentText() << endl; - out << "Floating-point mode=" << mD3DFloatingPointComboBox->currentText() << endl; - + + // Antialiasing + mDirect3DRenderSystem->setConfigOption("FSAA", mD3DAntiAliasingComboBox->currentText().toStdString()); + + // Full screen if (mD3DFullScreenCheckBox->checkState() == Qt::Checked) { - out << "Full Screen=Yes" << endl; + mDirect3DRenderSystem->setConfigOption("Full Screen", "Yes"); } else { - out << "Full Screen=No" << endl; + mDirect3DRenderSystem->setConfigOption("Full Screen", "No"); } - - out << "Rendering Device=" << mD3DRenderDeviceComboBox->currentText() << endl; - out << "Resource Creation Policy=Create on all devices" << endl; - + + // Rendering device + mDirect3DRenderSystem->setConfigOption("Rendering Device", mD3DRenderDeviceComboBox->currentText().toStdString()); + + // VSync if (mD3DVSyncCheckBox->checkState() == Qt::Checked) { - out << "VSync=Yes" << endl; + mDirect3DRenderSystem->setConfigOption("VSync", "Yes"); } else { - out << "VSync=No" << endl; + mDirect3DRenderSystem->setConfigOption("VSync", "No"); } - - out << "VSync Interval=1" << endl; - out << "Video Mode=" << mD3DResolutionComboBox->currentText() << endl; - out << "sRGB Gamma Conversion=No" << endl; + + // Resolution + mDirect3DRenderSystem->setConfigOption("Video Mode", mD3DResolutionComboBox->currentText().toStdString()); } - - out << endl; - + if (mOpenGLRenderSystem) { - QString openGLName = mOpenGLRenderSystem->getName().c_str(); - openGLName.prepend("["); - openGLName.append("]"); - out << openGLName << endl; - - out << "Colour Depth=32" << endl; - out << "Display Frequency=" << mOGLFrequencyComboBox->currentText() << endl; - out << "FSAA=" << mOGLAntiAliasingComboBox->currentText() << endl; - + // Display Frequency + mOpenGLRenderSystem->setConfigOption("Display Frequency", mOGLFrequencyComboBox->currentText().toStdString()); + + // Antialiasing + mOpenGLRenderSystem->setConfigOption("FSAA", mOGLAntiAliasingComboBox->currentText().toStdString()); + + // Full screen if (mOGLFullScreenCheckBox->checkState() == Qt::Checked) { - out << "Full Screen=Yes" << endl; + mOpenGLRenderSystem->setConfigOption("Full Screen", "Yes"); } else { - out << "Full Screen=No" << endl; + mOpenGLRenderSystem->setConfigOption("Full Screen", "No"); } - - out << "RTT Preferred Mode=" << mOGLRTTComboBox->currentText() << endl; - + + // RTT mode + mOpenGLRenderSystem->setConfigOption("RTT Preferred Mode", mOGLRTTComboBox->currentText().toStdString()); + + // VSync if (mOGLVSyncCheckBox->checkState() == Qt::Checked) { - out << "VSync=Yes" << endl; + mOpenGLRenderSystem->setConfigOption("VSync", "Yes"); } else { - out << "VSync=No" << endl; + mOpenGLRenderSystem->setConfigOption("VSync", "No"); } - - out << "VSync Interval=1" << endl; - out << "Video Mode=" << mOGLResolutionComboBox->currentText() << endl; - out << "sRGB Gamma Conversion=No" << endl; + + // Resolution + mOpenGLRenderSystem->setConfigOption("Video Mode", mOGLResolutionComboBox->currentText().toStdString()); + } + + // Now we validate the options + QString ogreError = QString::fromStdString(mSelectedRenderSystem->validateConfigOptions()); + + if (!ogreError.isEmpty()) { + QMessageBox msgBox; + msgBox.setWindowTitle("Error validating configuration"); + msgBox.setIcon(QMessageBox::Critical); + msgBox.setStandardButtons(QMessageBox::Ok); + msgBox.setText(tr("
A problem occured while validating the graphics options

\ + The graphics options could not be saved.

\ + Press \"Show Details...\" for more information.
")); + msgBox.setDetailedText(ogreError); + msgBox.exec(); + + Ogre::LogManager::getSingletonPtr()->logMessage( "Caught exception in validateConfigOptions"); + + qCritical("Error validating configuration"); + + std::exit(1); } - file.close(); - + // Write the settings to the config file + mOgre->saveConfig(); + } QString GraphicsPage::getConfigValue(const QString &key, Ogre::RenderSystem *renderer) diff --git a/apps/launcher/maindialog.cpp b/apps/launcher/maindialog.cpp index f51b3b549..c1f6d8b7e 100644 --- a/apps/launcher/maindialog.cpp +++ b/apps/launcher/maindialog.cpp @@ -50,7 +50,6 @@ MainDialog::MainDialog() connect(buttonBox, SIGNAL(rejected()), this, SLOT(close())); connect(buttonBox, SIGNAL(accepted()), this, SLOT(play())); - setupConfig(); createIcons(); createPages(); } @@ -88,52 +87,105 @@ void MainDialog::createIcons() } -void MainDialog::createPages() +QStringList MainDialog::readConfig(const QString &fileName) { - // Various pages - mPlayPage = new PlayPage(this); - mGraphicsPage = new GraphicsPage(this); - mDataFilesPage = new DataFilesPage(this); - - // First we retrieve all data= keys from the config // We can't use QSettings directly because it // does not support multiple keys with the same name - QFile file(mGameConfig->fileName()); - + QFile file(fileName); + if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { QMessageBox msgBox; msgBox.setWindowTitle("Error opening OpenMW configuration file"); msgBox.setIcon(QMessageBox::Critical); msgBox.setStandardButtons(QMessageBox::Ok); msgBox.setText(tr("
Could not open %0

\ - Please make sure you have the right permissions and try again.
").arg(file.fileName())); + Please make sure you have the right permissions and try again.
").arg(file.fileName())); msgBox.exec(); - + QApplication::exit(); // File cannot be opened or created } - + QTextStream in(&file); - QStringList dataDirs; - - // Add each data= value + QString dataLocal; + + // Read the config line by line while (!in.atEnd()) { QString line = in.readLine(); - + if (line.startsWith("data=")) { dataDirs.append(line.remove("data=")); } + + // Read the data-local key, if more than one are found only the last is used + if (line.startsWith("data-local=")) { + dataLocal = line.remove("data-local="); + } + + // Read fs-strict key + if (line.startsWith("fs-strict=")) { + QString value = line.remove("fs-strict="); + + (value.toLower() == QLatin1String("true")) + ? mStrict = true + : mStrict = false; + + } + } - - // Add the data-local= key - QString dataLocal = mGameConfig->value("data-local").toString(); + + // Add the data-local= key to the end of the dataDirs for priority reasons if (!dataLocal.isEmpty()) { dataDirs.append(dataLocal); } + + if (!dataDirs.isEmpty()) + { + // Reset the global datadirs to the newly read entries + // Else return the previous dataDirs because nothing was found in this file; + mDataDirs = dataDirs; + } + + file.close(); + + return mDataDirs; +} + +void MainDialog::createPages() +{ + mPlayPage = new PlayPage(this); + mGraphicsPage = new GraphicsPage(this); + mDataFilesPage = new DataFilesPage(this); + + // Retrieve all data entries from the configs + QStringList dataDirs; + + // Global location + QFile file(QString::fromStdString(Files::getPath(Files::Path_ConfigGlobal, + "openmw", "openmw.cfg"))); + if (file.exists()) { + dataDirs = readConfig(file.fileName()); + } + + // User location + file.setFileName(QString::fromStdString(Files::getPath(Files::Path_ConfigUser, + "openmw", "openmw.cfg"))); + if (file.exists()) { + dataDirs = readConfig(file.fileName()); + } + + // Local location + file.setFileName("./openmw.cfg"); + + if (file.exists()) { + dataDirs = readConfig(file.fileName()); + } + + file.close(); if (!dataDirs.isEmpty()) { // Now pass the datadirs on to the DataFilesPage - mDataFilesPage->setupDataFiles(dataDirs, mGameConfig->value("fs-strict").toBool()); + mDataFilesPage->setupDataFiles(dataDirs, mStrict); } else { QMessageBox msgBox; msgBox.setWindowTitle("Error reading OpenMW configuration file"); @@ -266,23 +318,6 @@ void MainDialog::play() } } -void MainDialog::setupConfig() -{ - // First we read the OpenMW config - QString config = "./openmw.cfg"; - QFile file(config); - - if (!file.exists()) { - config = QString::fromStdString(Files::getPath(Files::Path_ConfigUser, - "openmw", "openmw.cfg")); - } - - file.close(); - - // Open our config file - mGameConfig = new QSettings(config, QSettings::IniFormat); -} - void MainDialog::writeConfig() { // Write the profiles @@ -296,20 +331,21 @@ void MainDialog::writeConfig() QStringList dataFiles = mDataFilesPage->selectedMasters(); dataFiles.append(mDataFilesPage->checkedPlugins()); - // Open the config as a QFile - QFile file(mGameConfig->fileName()); + // Open the config as a QFile + QFile file(QString::fromStdString(Files::getPath(Files::Path_ConfigUser, + "openmw", "openmw.cfg"))); - if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { + if (!file.open(QIODevice::ReadWrite | QIODevice::Text)) { // File cannot be opened or created QMessageBox msgBox; - msgBox.setWindowTitle("Error opening OpenMW configuration file"); + msgBox.setWindowTitle("Error writing OpenMW configuration file"); msgBox.setIcon(QMessageBox::Critical); msgBox.setStandardButtons(QMessageBox::Ok); - msgBox.setText(tr("
Could not open %0

\ + msgBox.setText(tr("
Could not open or create %0

\ Please make sure you have the right permissions and try again.
").arg(file.fileName())); msgBox.exec(); - return; + std::exit(1); } QTextStream in(&file); @@ -335,10 +371,11 @@ void MainDialog::writeConfig() Please make sure you have the right permissions and try again.
").arg(file.fileName())); msgBox.exec(); - return; + std::exit(1);; } file.write(buffer); + QTextStream out(&file); // Write the list of game files to the config diff --git a/apps/launcher/maindialog.hpp b/apps/launcher/maindialog.hpp index c6f22e336..3ed72e0fd 100644 --- a/apps/launcher/maindialog.hpp +++ b/apps/launcher/maindialog.hpp @@ -6,8 +6,9 @@ class QListWidget; class QListWidgetItem; class QStackedWidget; +class QStringList; class QStringListModel; -class QSettings; +class QString; class PlayPage; class GraphicsPage; @@ -32,7 +33,9 @@ private: void setupConfig(); void writeConfig(); void closeEvent(QCloseEvent *event); - + + QStringList readConfig(const QString &fileName); + QListWidget *mIconWidget; QStackedWidget *mPagesWidget; @@ -40,7 +43,8 @@ private: GraphicsPage *mGraphicsPage; DataFilesPage *mDataFilesPage; - QSettings *mGameConfig; + QStringList mDataDirs; + bool mStrict; }; #endif