1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
|
/************************************************************************
**
** Copyright (C) 2019-2022 Kevin B. Hendricks, Stratford Ontario Canada
** Copyright (C) 2011 John Schember <john@nachtimwald.com>
**
** This file is part of PageEdit.
**
** PageEdit 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 3 of the License, or
** (at your option) any later version.
**
** PageEdit 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 PageEdit. If not, see <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#include "GeneralSettings.h"
#include "SettingsStore.h"
#include "UILanguage.h"
#include "UIDictionary.h"
#include <QString>
#include <QStringList>
GeneralSettings::GeneralSettings():
m_disable_gpu(false)
{
ui.setupUi(this);
// set up supported user interface languages
QStringList ui_language_names;
foreach(QString language_code, UILanguage::GetUILanguages()) {
// Convert standard language codes to those used for translations.
QString std_language_code = language_code;
std_language_code.replace("_", "-");
QString language_name;
if (language_name.isEmpty()) {
language_name = language_code;
}
ui_language_names.append(language_name);
}
ui_language_names.sort();
foreach(QString ui_language_name, ui_language_names) {
ui.cbUILanguage->addItem(ui_language_name);
}
// set up supported spellcheck dictionaries
QStringList ui_dictionary_names;
foreach(QString dictionary_name, UIDictionary::GetUIDictionaries()) {
ui_dictionary_names.append(dictionary_name);
}
ui_dictionary_names.sort();
foreach(QString dict_name, ui_dictionary_names) {
ui.cbUIDictionary->addItem(dict_name);
}
readSettings();
}
PreferencesWidget::ResultActions GeneralSettings::saveSettings()
{
SettingsStore settings;
int new_use_prettify = 0;
if (ui.UsePrettify->isChecked()) {
new_use_prettify = 1;
}
settings.setUsePrettify(new_use_prettify);
int new_use_wsprewrap = 0;
if (ui.UseWSPreWrap->isChecked()) {
new_use_wsprewrap = 1;
}
settings.setUseWSPreWrap(new_use_wsprewrap);
int new_remote_on_level = 0;
if (ui.AllowRemote->isChecked()) {
new_remote_on_level = 1;
}
settings.setRemoteOn(new_remote_on_level);
bool new_disable_gpu = false;
if (ui.DisableGPU->isChecked()) {
new_disable_gpu = true;
}
settings.setDisableGPU(new_disable_gpu);
int new_javascript_on_level = 0;
if (ui.AllowJavascript->isChecked()) {
new_javascript_on_level = 1;
}
settings.setJavascriptOn(new_javascript_on_level);
settings.setUIDictionary(ui.cbUIDictionary->currentText());
settings.setUILanguage(ui.cbUILanguage->currentText().replace("-", "_"));
PreferencesWidget::ResultActions results = PreferencesWidget::ResultAction_None;
if (ui.cbUILanguage->currentText() != m_UILanguage) {
results = results | PreferencesWidget::ResultAction_RestartPageEdit;
}
// if you change disable_gpu setting you need to restart PageEdit to see the change
if (new_disable_gpu != m_disable_gpu) {
results = results | PreferencesWidget::ResultAction_RestartPageEdit;
}
results = results & PreferencesWidget::ResultAction_Mask;
return results;
}
void GeneralSettings::readSettings()
{
SettingsStore settings;
// handle user interface language
QString language_code = settings.uiLanguage();
language_code.replace("_","-");
// UI Language
int index = ui.cbUILanguage->findText(language_code);
if (index == -1) {
index = ui.cbUILanguage->findText("en");
if (index == -1) {
index = 0;
}
}
ui.cbUILanguage->setCurrentIndex(index);
m_UILanguage = ui.cbUILanguage->currentText();
// handle spellcheck dictionary
QString dictionary_name = settings.uiDictionary();
int pos = ui.cbUIDictionary->findText(dictionary_name);
if (pos == -1) {
pos = ui.cbUIDictionary->findText("en_US");
if (pos == -1) {
pos = 0;
}
}
ui.cbUIDictionary->setCurrentIndex(pos);
int remoteOn = settings.remoteOn();
ui.AllowRemote->setChecked(remoteOn);
int javascriptOn = settings.javascriptOn();
ui.AllowJavascript->setChecked(javascriptOn);
int usePrettify = settings.usePrettify();
ui.UsePrettify->setChecked(usePrettify);
int useWSPreWrap = settings.useWSPreWrap();
ui.UseWSPreWrap->setChecked(useWSPreWrap);
ui.UseNBSp->setChecked(1-useWSPreWrap);
m_disable_gpu = settings.disableGPU();
ui.DisableGPU->setChecked(m_disable_gpu);
}
|