|
|
|
#include <QtGui>
|
|
|
|
|
|
|
|
#include "settings/gamesettings.hpp"
|
|
|
|
#include "settings/graphicssettings.hpp"
|
|
|
|
|
|
|
|
#include "utils/profilescombobox.hpp"
|
|
|
|
|
|
|
|
#include "maindialog.hpp"
|
|
|
|
#include "playpage.hpp"
|
|
|
|
#include "graphicspage.hpp"
|
|
|
|
#include "datafilespage.hpp"
|
|
|
|
|
|
|
|
MainDialog::MainDialog(GameSettings &gameSettings,
|
|
|
|
GraphicsSettings &graphicsSettings)
|
|
|
|
: mGameSettings(gameSettings)
|
|
|
|
, mGraphicsSettings(graphicsSettings)
|
|
|
|
|
|
|
|
{
|
|
|
|
QWidget *centralWidget = new QWidget(this);
|
|
|
|
setCentralWidget(centralWidget);
|
|
|
|
|
|
|
|
mIconWidget = new QListWidget(centralWidget);
|
|
|
|
mIconWidget->setObjectName("IconWidget");
|
|
|
|
mIconWidget->setViewMode(QListView::IconMode);
|
|
|
|
mIconWidget->setWrapping(false);
|
|
|
|
mIconWidget->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); // Just to be sure
|
|
|
|
mIconWidget->setIconSize(QSize(48, 48));
|
|
|
|
mIconWidget->setMovement(QListView::Static);
|
|
|
|
|
|
|
|
mIconWidget->setMinimumWidth(400);
|
|
|
|
mIconWidget->setFixedHeight(80);
|
|
|
|
mIconWidget->setSpacing(4);
|
|
|
|
mIconWidget->setCurrentRow(0);
|
|
|
|
mIconWidget->setFlow(QListView::LeftToRight);
|
|
|
|
|
|
|
|
QGroupBox *groupBox = new QGroupBox(centralWidget);
|
|
|
|
QVBoxLayout *groupLayout = new QVBoxLayout(groupBox);
|
|
|
|
|
|
|
|
mPagesWidget = new QStackedWidget(groupBox);
|
|
|
|
groupLayout->addWidget(mPagesWidget);
|
|
|
|
|
|
|
|
QPushButton *playButton = new QPushButton(tr("Play"));
|
|
|
|
|
|
|
|
QDialogButtonBox *buttonBox = new QDialogButtonBox(centralWidget);
|
|
|
|
buttonBox->setStandardButtons(QDialogButtonBox::Close);
|
|
|
|
buttonBox->addButton(playButton, QDialogButtonBox::AcceptRole);
|
|
|
|
|
|
|
|
QVBoxLayout *dialogLayout = new QVBoxLayout(centralWidget);
|
|
|
|
dialogLayout->addWidget(mIconWidget);
|
|
|
|
dialogLayout->addWidget(groupBox);
|
|
|
|
dialogLayout->addWidget(buttonBox);
|
|
|
|
|
|
|
|
setWindowTitle(tr("OpenMW Launcher"));
|
|
|
|
setWindowIcon(QIcon(":/images/openmw.png"));
|
|
|
|
// Remove what's this? button
|
|
|
|
setWindowFlags(this->windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
|
|
|
setMinimumSize(QSize(575, 575));
|
|
|
|
|
|
|
|
// Install the stylesheet font
|
|
|
|
QFile file;
|
|
|
|
QFontDatabase fontDatabase;
|
|
|
|
|
|
|
|
const QStringList fonts = fontDatabase.families();
|
|
|
|
|
|
|
|
// Check if the font is installed
|
|
|
|
if (!fonts.contains("EB Garamond")) {
|
|
|
|
|
|
|
|
QString font = QString::fromStdString((mCfgMgr.getGlobalDataPath() / "resources/mygui/EBGaramond-Regular.ttf").string());
|
|
|
|
file.setFileName(font);
|
|
|
|
|
|
|
|
if (!file.exists()) {
|
|
|
|
font = QString::fromStdString((mCfgMgr.getLocalPath() / "resources/mygui/EBGaramond-Regular.ttf").string());
|
|
|
|
}
|
|
|
|
|
|
|
|
fontDatabase.addApplicationFont(font);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load the stylesheet
|
|
|
|
QString config = QString::fromStdString((mCfgMgr.getGlobalDataPath() / "resources/launcher.qss").string());
|
|
|
|
file.setFileName(config);
|
|
|
|
|
|
|
|
if (!file.exists()) {
|
|
|
|
file.setFileName(QString::fromStdString((mCfgMgr.getLocalPath() / "launcher.qss").string()));
|
|
|
|
}
|
|
|
|
|
|
|
|
file.open(QFile::ReadOnly);
|
|
|
|
QString styleSheet = QLatin1String(file.readAll());
|
|
|
|
qApp->setStyleSheet(styleSheet);
|
|
|
|
file.close();
|
|
|
|
|
|
|
|
connect(buttonBox, SIGNAL(rejected()), this, SLOT(close()));
|
|
|
|
connect(buttonBox, SIGNAL(accepted()), this, SLOT(play()));
|
|
|
|
|
|
|
|
createIcons();
|
|
|
|
createPages();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainDialog::createIcons()
|
|
|
|
{
|
|
|
|
if (!QIcon::hasThemeIcon("document-new")) {
|
|
|
|
QIcon::setThemeName("tango");
|
|
|
|
}
|
|
|
|
|
|
|
|
// We create a fallback icon because the default fallback doesn't work
|
|
|
|
QIcon graphicsIcon = QIcon(":/icons/tango/video-display.png");
|
|
|
|
|
|
|
|
QListWidgetItem *playButton = new QListWidgetItem(mIconWidget);
|
|
|
|
playButton->setIcon(QIcon(":/images/openmw.png"));
|
|
|
|
playButton->setText(tr("Play"));
|
|
|
|
playButton->setTextAlignment(Qt::AlignCenter);
|
|
|
|
playButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
|
|
|
|
|
|
|
|
QListWidgetItem *graphicsButton = new QListWidgetItem(mIconWidget);
|
|
|
|
graphicsButton->setIcon(QIcon::fromTheme("video-display", graphicsIcon));
|
|
|
|
graphicsButton->setText(tr("Graphics"));
|
|
|
|
graphicsButton->setTextAlignment(Qt::AlignHCenter | Qt::AlignBottom | Qt::AlignAbsolute);
|
|
|
|
graphicsButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
|
|
|
|
|
|
|
|
QListWidgetItem *dataFilesButton = new QListWidgetItem(mIconWidget);
|
|
|
|
dataFilesButton->setIcon(QIcon(":/images/openmw-plugin.png"));
|
|
|
|
dataFilesButton->setText(tr("Data Files"));
|
|
|
|
dataFilesButton->setTextAlignment(Qt::AlignHCenter | Qt::AlignBottom);
|
|
|
|
dataFilesButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
|
|
|
|
|
|
|
|
connect(mIconWidget,
|
|
|
|
SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)),
|
|
|
|
this, SLOT(changePage(QListWidgetItem*,QListWidgetItem*)));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainDialog::createPages()
|
|
|
|
{
|
|
|
|
mPlayPage = new PlayPage(this);
|
|
|
|
mGraphicsPage = new GraphicsPage(mCfgMgr, mGraphicsSettings, this);
|
|
|
|
mDataFilesPage = new DataFilesPage(mCfgMgr, mGameSettings, this);
|
|
|
|
|
|
|
|
// Set the combobox of the play page to imitate the combobox on the datafilespage
|
|
|
|
mPlayPage->mProfilesComboBox->setModel(mDataFilesPage->mProfilesComboBox->model());
|
|
|
|
mPlayPage->mProfilesComboBox->setCurrentIndex(mDataFilesPage->mProfilesComboBox->currentIndex());
|
|
|
|
|
|
|
|
// Add the pages to the stacked widget
|
|
|
|
mPagesWidget->addWidget(mPlayPage);
|
|
|
|
mPagesWidget->addWidget(mGraphicsPage);
|
|
|
|
mPagesWidget->addWidget(mDataFilesPage);
|
|
|
|
|
|
|
|
// Select the first page
|
|
|
|
mIconWidget->setCurrentItem(mIconWidget->item(0), QItemSelectionModel::Select);
|
|
|
|
|
|
|
|
connect(mPlayPage->mPlayButton, SIGNAL(clicked()), this, SLOT(play()));
|
|
|
|
|
|
|
|
connect(mPlayPage->mProfilesComboBox,
|
|
|
|
SIGNAL(currentIndexChanged(int)),
|
|
|
|
mDataFilesPage->mProfilesComboBox, SLOT(setCurrentIndex(int)));
|
|
|
|
|
|
|
|
connect(mDataFilesPage->mProfilesComboBox,
|
|
|
|
SIGNAL(currentIndexChanged(int)),
|
|
|
|
mPlayPage->mProfilesComboBox, SLOT(setCurrentIndex(int)));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool MainDialog::setup()
|
|
|
|
{
|
|
|
|
// Setup the Graphics page
|
|
|
|
if (!mGraphicsPage->setupOgre()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Setup the Data Files page
|
|
|
|
/*
|
|
|
|
if (!mDataFilesPage->setupDataFiles()) {
|
|
|
|
return false;
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainDialog::changePage(QListWidgetItem *current, QListWidgetItem *previous)
|
|
|
|
{
|
|
|
|
if (!current)
|
|
|
|
current = previous;
|
|
|
|
|
|
|
|
mPagesWidget->setCurrentIndex(mIconWidget->row(current));
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainDialog::closeEvent(QCloseEvent *event)
|
|
|
|
{
|
|
|
|
// Now write all config files
|
|
|
|
mDataFilesPage->writeConfig();
|
|
|
|
mGraphicsPage->saveSettings();
|
|
|
|
|
|
|
|
QString userPath = QString::fromStdString(mCfgMgr.getUserPath().string());
|
|
|
|
QDir dir(userPath);
|
|
|
|
|
|
|
|
if (!dir.exists()) {
|
|
|
|
if (!dir.mkpath(userPath)) {
|
|
|
|
QMessageBox msgBox;
|
|
|
|
msgBox.setWindowTitle("Error creating OpenMW configuration directory");
|
|
|
|
msgBox.setIcon(QMessageBox::Critical);
|
|
|
|
msgBox.setStandardButtons(QMessageBox::Ok);
|
|
|
|
msgBox.setText(tr("<br><b>Could not create %0</b><br><br> \
|
|
|
|
Please make sure you have the right permissions \
|
|
|
|
and try again.<br>").arg(userPath));
|
|
|
|
msgBox.exec();
|
|
|
|
event->accept();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Game settings
|
|
|
|
QFile file(userPath + QString("openmw.cfg"));
|
|
|
|
|
|
|
|
if (!file.open(QIODevice::ReadWrite | QIODevice::Text | QIODevice::Truncate)) {
|
|
|
|
// File cannot be opened or created
|
|
|
|
QMessageBox msgBox;
|
|
|
|
msgBox.setWindowTitle("Error writing OpenMW configuration file");
|
|
|
|
msgBox.setIcon(QMessageBox::Critical);
|
|
|
|
msgBox.setStandardButtons(QMessageBox::Ok);
|
|
|
|
msgBox.setText(tr("<br><b>Could not open or create %0 for writing</b><br><br> \
|
|
|
|
Please make sure you have the right permissions \
|
|
|
|
and try again.<br>").arg(file.fileName()));
|
|
|
|
msgBox.exec();
|
|
|
|
event->accept();
|
|
|
|
}
|
|
|
|
|
|
|
|
QTextStream stream(&file);
|
|
|
|
stream.setCodec(QTextCodec::codecForName("UTF-8"));
|
|
|
|
|
|
|
|
mGameSettings.writeFile(stream);
|
|
|
|
file.close();
|
|
|
|
|
|
|
|
// Graphics settings
|
|
|
|
file.setFileName(userPath + QString("settings.cfg"));
|
|
|
|
|
|
|
|
if (!file.open(QIODevice::ReadWrite | QIODevice::Text | QIODevice::Truncate)) {
|
|
|
|
// File cannot be opened or created
|
|
|
|
QMessageBox msgBox;
|
|
|
|
msgBox.setWindowTitle("Error writing OpenMW configuration file");
|
|
|
|
msgBox.setIcon(QMessageBox::Critical);
|
|
|
|
msgBox.setStandardButtons(QMessageBox::Ok);
|
|
|
|
msgBox.setText(tr("<br><b>Could not open or create %0 for writing</b><br><br> \
|
|
|
|
Please make sure you have the right permissions \
|
|
|
|
and try again.<br>").arg(file.fileName()));
|
|
|
|
msgBox.exec();
|
|
|
|
event->accept();
|
|
|
|
}
|
|
|
|
|
|
|
|
stream.setDevice(&file);
|
|
|
|
stream.setCodec(QTextCodec::codecForName("UTF-8"));
|
|
|
|
|
|
|
|
mGraphicsSettings.writeFile(stream);
|
|
|
|
|
|
|
|
event->accept();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainDialog::play()
|
|
|
|
{
|
|
|
|
// First do a write of all the configs, just to be sure
|
|
|
|
mDataFilesPage->writeConfig();
|
|
|
|
//mGraphicsPage->writeConfig();
|
|
|
|
|
|
|
|
// Save user settings
|
|
|
|
const std::string settingspath = (mCfgMgr.getUserPath() / "settings.cfg").string();
|
|
|
|
mSettings.saveUser(settingspath);
|
|
|
|
|
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
QString game = "./openmw.exe";
|
|
|
|
QFile file(game);
|
|
|
|
#elif defined(Q_OS_MAC)
|
|
|
|
QDir dir(QCoreApplication::applicationDirPath());
|
|
|
|
QString game = dir.absoluteFilePath("openmw");
|
|
|
|
QFile file(game);
|
|
|
|
game = "\"" + game + "\"";
|
|
|
|
#else
|
|
|
|
QString game = "./openmw";
|
|
|
|
QFile file(game);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
QProcess process;
|
|
|
|
QFileInfo info(file);
|
|
|
|
|
|
|
|
if (!file.exists()) {
|
|
|
|
QMessageBox msgBox;
|
|
|
|
msgBox.setWindowTitle("Error starting OpenMW");
|
|
|
|
msgBox.setIcon(QMessageBox::Warning);
|
|
|
|
msgBox.setStandardButtons(QMessageBox::Ok);
|
|
|
|
msgBox.setText(tr("<br><b>Could not find OpenMW</b><br><br> \
|
|
|
|
The OpenMW application is not found.<br> \
|
|
|
|
Please make sure OpenMW is installed correctly and try again.<br>"));
|
|
|
|
msgBox.exec();
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!info.isExecutable()) {
|
|
|
|
QMessageBox msgBox;
|
|
|
|
msgBox.setWindowTitle("Error starting OpenMW");
|
|
|
|
msgBox.setIcon(QMessageBox::Warning);
|
|
|
|
msgBox.setStandardButtons(QMessageBox::Ok);
|
|
|
|
msgBox.setText(tr("<br><b>Could not start OpenMW</b><br><br> \
|
|
|
|
The OpenMW application is not executable.<br> \
|
|
|
|
Please make sure you have the right permissions and try again.<br>"));
|
|
|
|
msgBox.exec();
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Start the game
|
|
|
|
if (!process.startDetached(game)) {
|
|
|
|
QMessageBox msgBox;
|
|
|
|
msgBox.setWindowTitle("Error starting OpenMW");
|
|
|
|
msgBox.setIcon(QMessageBox::Critical);
|
|
|
|
msgBox.setStandardButtons(QMessageBox::Ok);
|
|
|
|
msgBox.setText(tr("<br><b>Could not start OpenMW</b><br><br> \
|
|
|
|
An error occurred while starting OpenMW.<br><br> \
|
|
|
|
Press \"Show Details...\" for more information.<br>"));
|
|
|
|
msgBox.setDetailedText(process.errorString());
|
|
|
|
msgBox.exec();
|
|
|
|
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
qApp->quit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|