2022-01-08 16:39:51 +06:00
|
|
|
#include <QDebug>
|
|
|
|
|
|
2021-12-28 16:47:10 +06:00
|
|
|
#include "qt_progsettings.hpp"
|
|
|
|
|
#include "ui_qt_progsettings.h"
|
|
|
|
|
#include "qt_mainwindow.hpp"
|
|
|
|
|
#include "ui_qt_mainwindow.h"
|
|
|
|
|
#include "qt_machinestatus.hpp"
|
|
|
|
|
|
|
|
|
|
#include <QMap>
|
|
|
|
|
#include <QDir>
|
|
|
|
|
#include <QFile>
|
2022-01-08 16:39:51 +06:00
|
|
|
#include <QLibraryInfo>
|
2021-12-28 16:47:10 +06:00
|
|
|
|
|
|
|
|
extern "C"
|
|
|
|
|
{
|
|
|
|
|
#include <86box/86box.h>
|
|
|
|
|
#include <86box/config.h>
|
|
|
|
|
#include <86box/plat.h>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static QMap<QString, QString> iconset_to_qt;
|
|
|
|
|
extern MainWindow* main_window;
|
|
|
|
|
|
2022-01-08 16:39:51 +06:00
|
|
|
ProgSettings::CustomTranslator* ProgSettings::translator = nullptr;
|
|
|
|
|
QTranslator* ProgSettings::qtTranslator = nullptr;
|
2021-12-28 16:47:10 +06:00
|
|
|
QString ProgSettings::getIconSetPath()
|
|
|
|
|
{
|
|
|
|
|
QString roms_root;
|
|
|
|
|
if (rom_path[0])
|
|
|
|
|
roms_root = rom_path;
|
|
|
|
|
else {
|
|
|
|
|
roms_root = QString("%1/roms").arg(exe_path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (iconset_to_qt.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
iconset_to_qt.insert("", ":/settings/win/icons");
|
|
|
|
|
QDir dir(roms_root + "/icons/");
|
|
|
|
|
if (dir.isReadable())
|
|
|
|
|
{
|
|
|
|
|
auto dirList = dir.entryList(QDir::AllDirs | QDir::Executable | QDir::Readable);
|
|
|
|
|
for (auto &curIconSet : dirList)
|
|
|
|
|
{
|
|
|
|
|
if (curIconSet == "." || curIconSet == "..") continue;
|
|
|
|
|
iconset_to_qt.insert(curIconSet, (dir.canonicalPath() + '/') + curIconSet);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return iconset_to_qt[icon_set];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ProgSettings::ProgSettings(QWidget *parent) :
|
|
|
|
|
QDialog(parent),
|
|
|
|
|
ui(new Ui::ProgSettings)
|
|
|
|
|
{
|
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
(void)getIconSetPath();
|
|
|
|
|
ui->comboBox->setItemData(0, "");
|
|
|
|
|
ui->comboBox->setCurrentIndex(0);
|
|
|
|
|
for (auto i = iconset_to_qt.begin(); i != iconset_to_qt.end(); i++)
|
|
|
|
|
{
|
|
|
|
|
if (i.key() == "") continue;
|
|
|
|
|
QFile iconfile(i.value() + "/iconinfo.txt");
|
|
|
|
|
iconfile.open(QFile::ReadOnly);
|
|
|
|
|
QString friendlyName;
|
|
|
|
|
QString iconsetinfo(iconfile.readAll());
|
|
|
|
|
iconfile.close();
|
|
|
|
|
if (iconsetinfo.isEmpty()) friendlyName = i.key();
|
|
|
|
|
else friendlyName = iconsetinfo.split('\n')[0];
|
|
|
|
|
ui->comboBox->addItem(friendlyName, i.key());
|
|
|
|
|
if (strcmp(icon_set, i.key().toUtf8().data()) == 0)
|
|
|
|
|
{
|
|
|
|
|
ui->comboBox->setCurrentIndex(ui->comboBox->findData(i.key()));
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-01-08 16:39:51 +06:00
|
|
|
ui->comboBox->setItemData(0, '(' + tr("Default") + ')', Qt::DisplayRole);
|
|
|
|
|
|
|
|
|
|
ui->comboBoxLanguage->setItemData(0, 0xFFFF);
|
|
|
|
|
for (auto i = lcid_langcode.begin() + 1; i != lcid_langcode.end(); i++)
|
|
|
|
|
{
|
|
|
|
|
if (i.key() == 0xFFFF) continue;
|
|
|
|
|
ui->comboBoxLanguage->addItem(lcid_langcode[i.key()].second, i.key());
|
|
|
|
|
if (i.key() == lang_id)
|
|
|
|
|
{
|
|
|
|
|
ui->comboBoxLanguage->setCurrentIndex(ui->comboBoxLanguage->findData(i.key()));
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-12-28 16:47:10 +06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ProgSettings::accept()
|
|
|
|
|
{
|
|
|
|
|
strcpy(icon_set, ui->comboBox->currentData().toString().toUtf8().data());
|
2022-01-08 16:39:51 +06:00
|
|
|
lang_id = ui->comboBoxLanguage->currentData().toUInt();
|
2021-12-28 16:47:10 +06:00
|
|
|
|
2022-01-08 16:39:51 +06:00
|
|
|
loadTranslators(QCoreApplication::instance());
|
|
|
|
|
reloadStrings();
|
|
|
|
|
update_mouse_msg();
|
|
|
|
|
main_window->ui->retranslateUi(main_window);
|
2021-12-28 16:47:10 +06:00
|
|
|
QString msg = main_window->status->getMessage();
|
|
|
|
|
main_window->status.reset(new MachineStatus(main_window));
|
|
|
|
|
main_window->refreshMediaMenu();
|
|
|
|
|
main_window->status->message(msg);
|
2021-12-29 23:49:09 +06:00
|
|
|
connect(main_window, &MainWindow::updateStatusBarTip, main_window->status.get(), &MachineStatus::updateTip);
|
|
|
|
|
connect(main_window, &MainWindow::updateStatusBarActivity, main_window->status.get(), &MachineStatus::setActivity);
|
|
|
|
|
connect(main_window, &MainWindow::updateStatusBarEmpty, main_window->status.get(), &MachineStatus::setEmpty);
|
|
|
|
|
connect(main_window, &MainWindow::statusBarMessage, main_window->status.get(), &MachineStatus::message);
|
2021-12-28 16:47:10 +06:00
|
|
|
QDialog::accept();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ProgSettings::~ProgSettings()
|
|
|
|
|
{
|
|
|
|
|
delete ui;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ProgSettings::on_pushButton_released()
|
|
|
|
|
{
|
|
|
|
|
ui->comboBox->setCurrentIndex(0);
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-08 16:39:51 +06:00
|
|
|
void ProgSettings::loadTranslators(QObject *parent)
|
|
|
|
|
{
|
|
|
|
|
if (qtTranslator)
|
|
|
|
|
{
|
|
|
|
|
QApplication::removeTranslator(qtTranslator);
|
|
|
|
|
qtTranslator = nullptr;
|
|
|
|
|
}
|
|
|
|
|
if (translator)
|
|
|
|
|
{
|
|
|
|
|
QApplication::removeTranslator(translator);
|
|
|
|
|
translator = nullptr;
|
|
|
|
|
}
|
|
|
|
|
qtTranslator = new QTranslator(parent);
|
|
|
|
|
translator = new CustomTranslator(parent);
|
|
|
|
|
QString localetofilename = "";
|
|
|
|
|
if (lang_id == 0xFFFF || lcid_langcode.contains(lang_id) == false)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < QLocale::system().uiLanguages().size(); i++)
|
|
|
|
|
{
|
|
|
|
|
localetofilename = QLocale::system().uiLanguages()[i];
|
|
|
|
|
if (translator->load(QLatin1String("86box_") + localetofilename, QLatin1String(":/")))
|
|
|
|
|
{
|
|
|
|
|
qDebug() << "Translations loaded.\n";
|
|
|
|
|
QCoreApplication::installTranslator(translator);
|
|
|
|
|
qtTranslator->load(QLatin1String("qtbase_") + localetofilename.replace('-', '_'), QLibraryInfo::location(QLibraryInfo::TranslationsPath));
|
|
|
|
|
if (QApplication::installTranslator(qtTranslator))
|
|
|
|
|
{
|
|
|
|
|
qDebug() << "Qt translations loaded." << "\n";
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
translator->load(QLatin1String("86box_") + lcid_langcode[lang_id].first, QLatin1String(":/"));
|
|
|
|
|
QCoreApplication::installTranslator(translator);
|
|
|
|
|
qtTranslator->load(QLatin1String("qtbase_") + QString(lcid_langcode[lang_id].first).replace('-', '_'), QLibraryInfo::location(QLibraryInfo::TranslationsPath));
|
|
|
|
|
QCoreApplication::installTranslator(qtTranslator);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ProgSettings::on_pushButtonLanguage_released()
|
|
|
|
|
{
|
|
|
|
|
ui->comboBoxLanguage->setCurrentIndex(0);
|
|
|
|
|
}
|
|
|
|
|
|