/******************************************************************************* # # Copyright (C) 2010-2013 Matteo Paonessa # 2021 Gary Wang # # This file is part of the Caesium distribution. # # Caesium is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # Caesium is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with Caesium; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, 5th Floor, Boston, MA 02110-1301 USA. # # Author: Matteo Paonessa # Gary Wang # # ******************************************************************************/ #include "preferences.h" #include "ui_preferences.h" #include "global.h" #include #include #include #include #include #include #include #include Preferences::Preferences(QWidget *parent) : QDialog(parent), ui(new Ui::Preferences) { ui->setupUi(this); #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) settings.setIniCodec("UTF-8"); #endif // QT_VERSION < QT_VERSION_CHECK(6, 0, 0) loadSettings(); loadLanguages(); Preferences::on_pngLevelSlider_valueChanged(settings.value("Preferences/pnglevel").value()); //ui->menuListWidget->item(0)->setSelected(true); connect(ui->menuListWidget, SIGNAL(currentRowChanged(int)), ui->optionStackedWidget, SLOT(setCurrentIndex(int))); ui->pngCompressionCheckBox->setVisible(false); ui->pngLevelLabel->setVisible(false); ui->pngLevelSlider->setVisible(false); ui->levelLabel->setVisible(false); } Preferences::~Preferences() { delete ui; } void Preferences::loadLanguages() { QDir langDir(QDir::currentPath() + "/translations"); QStringList list = langDir.entryList(QStringList("*.qm"), QDir::Files, QDir::NoSort); for (int i = list.length() - 1; i >= 0; i--) { QString fileName = QFileInfo(list.at(i)).baseName(); if (!fileName.startsWith("caesium")) continue; QString langCode = fileName.mid(8); QString langName = QLocale(langCode).nativeLanguageName(); if (langName.isEmpty() || langCode.isEmpty()) continue; QTreeWidgetItem *item = new QTreeWidgetItem({langName, langCode}, 0); ui->languageTreeWidget->insertTopLevelItem(0, item); } ui->languageTreeWidget->sortItems(0, Qt::AscendingOrder); } void Preferences::loadSettings() { ui->useDefaultPathCheckBox->setChecked(settings.value("Preferences/defaultpath").value()); ui->defaultOutputLineEdit->setText(settings.value("Settings/path").value()); if (settings.value("Preferences/imageview").value() == "fit") { ui->fitWindowRadio->setChecked(true); ui->originalSizeRadio->setChecked(false); } else { ui->fitWindowRadio->setChecked(false); ui->originalSizeRadio->setChecked(true); } ui->checkUpdatesCheckBox->setChecked(settings.value("Preferences/startupupdt").value()); ui->keepExifCheckBox->setChecked(settings.value("Preferences/exif").value()); ui->doNotEnlargeCheckBox->setChecked(settings.value("Preferences/noenlarge").value()); ui->deleteCheckBox->setChecked(settings.value("Preferences/delete").value()); ui->keepDateCheckBox->setChecked(settings.value("Preferences/keepdate").value()); ui->scanSubDirCheckBox->setChecked(settings.value("Preferences/scansubdir").value()); ui->promptBeforeExitCheckBox->setChecked(settings.value("Preferences/promptexit").value()); ui->loadLastProfileCheckBox->setChecked(settings.value("Preferences/loadprofile").value()); ui->restoreStateCheckBox->setChecked(settings.value("Preferences/restorelayout").value()); ui->dontExtensionCheckBox->setChecked(settings.value("Preferences/dontextension").value()); ui->styleComboBox->setCurrentIndex(settings.value("Preferences/style_index").value()); ui->pngCompressionCheckBox->setChecked(settings.value("Preferences/pngcompression").value()); ui->pngLevelSlider->setValue(settings.value("Preferences/pnglevel").value()); ui->loadLastListCheckBox->setChecked(settings.value("Preferences/loadlastlist").value()); } void Preferences::on_browseToolButton_clicked() { QString outputPath = QFileDialog::getExistingDirectory(this, tr("Select default output directory"), QDir::homePath(), QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); if (outputPath != "") { ui->defaultOutputLineEdit->setText(outputPath); } } void Preferences::on_OKButton_clicked() { Preferences::on_applyButton_clicked(); this->close(); } void Preferences::on_cancelButton_clicked() { this->close(); } void Preferences::on_applyButton_clicked() { QDir dir(ui->defaultOutputLineEdit->text()); if (ui->defaultOutputLineEdit->text() == "") { ui->useDefaultPathCheckBox->setChecked(false); } else if (!dir.exists() && ui->defaultOutputLineEdit->isEnabled() == true) { dir.mkpath(ui->defaultOutputLineEdit->text()); } settings.setValue("Preferences/defaultpath", ui->useDefaultPathCheckBox->isChecked()); settings.setValue("Settings/path", ui->defaultOutputLineEdit->text()); if (ui->originalSizeRadio->isChecked()) { settings.setValue("Preferences/imageview", "orig"); } else { settings.setValue("Preferences/imageview", "fit"); } settings.setValue("Preferences/startupupdt", ui->checkUpdatesCheckBox->isChecked()); settings.setValue("Preferences/exif", ui->keepExifCheckBox->isChecked()); settings.setValue("Preferences/noenlarge", ui->doNotEnlargeCheckBox->isChecked()); settings.setValue("Preferences/delete", ui->deleteCheckBox->isChecked()); settings.setValue("Preferences/keepdate", ui->keepDateCheckBox->isChecked()); settings.setValue("Preferences/scansubdir", ui->scanSubDirCheckBox->isChecked()); settings.setValue("Preferences/promptexit", ui->promptBeforeExitCheckBox->isChecked()); settings.setValue("Preferences/loadprofile", ui->loadLastProfileCheckBox->isChecked()); settings.setValue("Preferences/restorelayout", ui->restoreStateCheckBox->isChecked()); settings.setValue("Preferences/style_index", ui->styleComboBox->currentIndex()); settings.setValue("Preferences/style", ui->styleComboBox->currentText()); settings.setValue("Preferences/dontextension", ui->dontExtensionCheckBox->isChecked()); settings.setValue("Preferences/pngcompression", ui->pngCompressionCheckBox->isChecked()); settings.setValue("Preferences/pnglevel", ui->pngLevelSlider->value()); settings.setValue("Preferences/loadlastlist", ui->loadLastListCheckBox->isChecked()); if (ui->languageTreeWidget->selectedItems().count() != 0) { settings.setValue("Preferences/language", ui->languageTreeWidget->selectedItems().at(0)->text(1)); QMessageBox::information(this, tr("Information"), tr("You need to restart the application before\nchanges take effect"), QMessageBox::Ok); } QApplication::setStyle(QStyleFactory::create(ui->styleComboBox->currentText())); QApplication::setPalette(QApplication::style()->standardPalette()); } void Preferences::on_pngLevelSlider_valueChanged(int position) { if (position <= 2) { ui->pngLevelLabel->setText("" + tr("Soft (Fastest)") + ""); } else if (position <= 5) { ui->pngLevelLabel->setText(tr("Medium (Average)")); } else { ui->pngLevelLabel->setText("" + tr("Hard (Slowest)") + ""); } }