add reset paths button to settings (#4384)
This commit is contained in:
parent
1e995cd97c
commit
c8bb8b0aae
4 changed files with 88 additions and 37 deletions
|
@ -43,7 +43,8 @@
|
||||||
|
|
||||||
GeneralSettingsPage::GeneralSettingsPage()
|
GeneralSettingsPage::GeneralSettingsPage()
|
||||||
{
|
{
|
||||||
QString setLanguage = SettingsCache::instance().getLang();
|
SettingsCache &settings = SettingsCache::instance();
|
||||||
|
QString setLanguage = settings.getLang();
|
||||||
QStringList qmFiles = findQmFiles();
|
QStringList qmFiles = findQmFiles();
|
||||||
for (int i = 0; i < qmFiles.size(); i++) {
|
for (int i = 0; i < qmFiles.size(); i++) {
|
||||||
QString langName = languageName(qmFiles[i]);
|
QString langName = languageName(qmFiles[i]);
|
||||||
|
@ -54,34 +55,34 @@ GeneralSettingsPage::GeneralSettingsPage()
|
||||||
}
|
}
|
||||||
|
|
||||||
// updates
|
// updates
|
||||||
QList<ReleaseChannel *> channels = SettingsCache::instance().getUpdateReleaseChannels();
|
QList<ReleaseChannel *> channels = settings.getUpdateReleaseChannels();
|
||||||
foreach (ReleaseChannel *chan, channels) {
|
foreach (ReleaseChannel *chan, channels) {
|
||||||
updateReleaseChannelBox.insertItem(chan->getIndex(), tr(chan->getName().toUtf8()));
|
updateReleaseChannelBox.insertItem(chan->getIndex(), tr(chan->getName().toUtf8()));
|
||||||
}
|
}
|
||||||
updateReleaseChannelBox.setCurrentIndex(SettingsCache::instance().getUpdateReleaseChannel()->getIndex());
|
updateReleaseChannelBox.setCurrentIndex(settings.getUpdateReleaseChannel()->getIndex());
|
||||||
|
|
||||||
updateNotificationCheckBox.setChecked(SettingsCache::instance().getNotifyAboutUpdates());
|
updateNotificationCheckBox.setChecked(settings.getNotifyAboutUpdates());
|
||||||
newVersionOracleCheckBox.setChecked(SettingsCache::instance().getNotifyAboutNewVersion());
|
newVersionOracleCheckBox.setChecked(settings.getNotifyAboutNewVersion());
|
||||||
|
|
||||||
// pixmap cache
|
// pixmap cache
|
||||||
pixmapCacheEdit.setMinimum(PIXMAPCACHE_SIZE_MIN);
|
pixmapCacheEdit.setMinimum(PIXMAPCACHE_SIZE_MIN);
|
||||||
// 2047 is the max value to avoid overflowing of QPixmapCache::setCacheLimit(int size)
|
// 2047 is the max value to avoid overflowing of QPixmapCache::setCacheLimit(int size)
|
||||||
pixmapCacheEdit.setMaximum(PIXMAPCACHE_SIZE_MAX);
|
pixmapCacheEdit.setMaximum(PIXMAPCACHE_SIZE_MAX);
|
||||||
pixmapCacheEdit.setSingleStep(64);
|
pixmapCacheEdit.setSingleStep(64);
|
||||||
pixmapCacheEdit.setValue(SettingsCache::instance().getPixmapCacheSize());
|
pixmapCacheEdit.setValue(settings.getPixmapCacheSize());
|
||||||
pixmapCacheEdit.setSuffix(" MB");
|
pixmapCacheEdit.setSuffix(" MB");
|
||||||
|
|
||||||
showTipsOnStartup.setChecked(SettingsCache::instance().getShowTipsOnStartup());
|
showTipsOnStartup.setChecked(settings.getShowTipsOnStartup());
|
||||||
|
|
||||||
connect(&languageBox, SIGNAL(currentIndexChanged(int)), this, SLOT(languageBoxChanged(int)));
|
connect(&languageBox, SIGNAL(currentIndexChanged(int)), this, SLOT(languageBoxChanged(int)));
|
||||||
connect(&pixmapCacheEdit, SIGNAL(valueChanged(int)), &SettingsCache::instance(), SLOT(setPixmapCacheSize(int)));
|
connect(&pixmapCacheEdit, SIGNAL(valueChanged(int)), &settings, SLOT(setPixmapCacheSize(int)));
|
||||||
connect(&updateReleaseChannelBox, SIGNAL(currentIndexChanged(int)), &SettingsCache::instance(),
|
connect(&updateReleaseChannelBox, SIGNAL(currentIndexChanged(int)), &settings,
|
||||||
SLOT(setUpdateReleaseChannel(int)));
|
SLOT(setUpdateReleaseChannel(int)));
|
||||||
connect(&updateNotificationCheckBox, SIGNAL(stateChanged(int)), &SettingsCache::instance(),
|
connect(&updateNotificationCheckBox, SIGNAL(stateChanged(int)), &settings,
|
||||||
SLOT(setNotifyAboutUpdate(int)));
|
SLOT(setNotifyAboutUpdate(int)));
|
||||||
connect(&newVersionOracleCheckBox, SIGNAL(stateChanged(int)), &SettingsCache::instance(),
|
connect(&newVersionOracleCheckBox, SIGNAL(stateChanged(int)), &settings,
|
||||||
SLOT(setNotifyAboutNewVersion(int)));
|
SLOT(setNotifyAboutNewVersion(int)));
|
||||||
connect(&showTipsOnStartup, SIGNAL(clicked(bool)), &SettingsCache::instance(), SLOT(setShowTipsOnStartup(bool)));
|
connect(&showTipsOnStartup, SIGNAL(clicked(bool)), &settings, SLOT(setShowTipsOnStartup(bool)));
|
||||||
|
|
||||||
auto *personalGrid = new QGridLayout;
|
auto *personalGrid = new QGridLayout;
|
||||||
personalGrid->addWidget(&languageLabel, 0, 0);
|
personalGrid->addWidget(&languageLabel, 0, 0);
|
||||||
|
@ -97,37 +98,38 @@ GeneralSettingsPage::GeneralSettingsPage()
|
||||||
personalGroupBox = new QGroupBox;
|
personalGroupBox = new QGroupBox;
|
||||||
personalGroupBox->setLayout(personalGrid);
|
personalGroupBox->setLayout(personalGrid);
|
||||||
|
|
||||||
deckPathEdit = new QLineEdit(SettingsCache::instance().getDeckPath());
|
deckPathEdit = new QLineEdit(settings.getDeckPath());
|
||||||
deckPathEdit->setReadOnly(true);
|
deckPathEdit->setReadOnly(true);
|
||||||
QPushButton *deckPathButton = new QPushButton("...");
|
QPushButton *deckPathButton = new QPushButton("...");
|
||||||
connect(deckPathButton, SIGNAL(clicked()), this, SLOT(deckPathButtonClicked()));
|
connect(deckPathButton, SIGNAL(clicked()), this, SLOT(deckPathButtonClicked()));
|
||||||
|
|
||||||
replaysPathEdit = new QLineEdit(SettingsCache::instance().getReplaysPath());
|
replaysPathEdit = new QLineEdit(settings.getReplaysPath());
|
||||||
replaysPathEdit->setReadOnly(true);
|
replaysPathEdit->setReadOnly(true);
|
||||||
QPushButton *replaysPathButton = new QPushButton("...");
|
QPushButton *replaysPathButton = new QPushButton("...");
|
||||||
connect(replaysPathButton, SIGNAL(clicked()), this, SLOT(replaysPathButtonClicked()));
|
connect(replaysPathButton, SIGNAL(clicked()), this, SLOT(replaysPathButtonClicked()));
|
||||||
|
|
||||||
picsPathEdit = new QLineEdit(SettingsCache::instance().getPicsPath());
|
picsPathEdit = new QLineEdit(settings.getPicsPath());
|
||||||
picsPathEdit->setReadOnly(true);
|
picsPathEdit->setReadOnly(true);
|
||||||
QPushButton *picsPathButton = new QPushButton("...");
|
QPushButton *picsPathButton = new QPushButton("...");
|
||||||
connect(picsPathButton, SIGNAL(clicked()), this, SLOT(picsPathButtonClicked()));
|
connect(picsPathButton, SIGNAL(clicked()), this, SLOT(picsPathButtonClicked()));
|
||||||
|
|
||||||
cardDatabasePathEdit = new QLineEdit(SettingsCache::instance().getCardDatabasePath());
|
cardDatabasePathEdit = new QLineEdit(settings.getCardDatabasePath());
|
||||||
cardDatabasePathEdit->setReadOnly(true);
|
cardDatabasePathEdit->setReadOnly(true);
|
||||||
QPushButton *cardDatabasePathButton = new QPushButton("...");
|
QPushButton *cardDatabasePathButton = new QPushButton("...");
|
||||||
connect(cardDatabasePathButton, SIGNAL(clicked()), this, SLOT(cardDatabasePathButtonClicked()));
|
connect(cardDatabasePathButton, SIGNAL(clicked()), this, SLOT(cardDatabasePathButtonClicked()));
|
||||||
|
|
||||||
customCardDatabasePathEdit = new QLineEdit(SettingsCache::instance().getCustomCardDatabasePath());
|
customCardDatabasePathEdit = new QLineEdit(settings.getCustomCardDatabasePath());
|
||||||
customCardDatabasePathEdit->setReadOnly(true);
|
customCardDatabasePathEdit->setReadOnly(true);
|
||||||
QPushButton *customCardDatabasePathButton = new QPushButton("...");
|
QPushButton *customCardDatabasePathButton = new QPushButton("...");
|
||||||
connect(customCardDatabasePathButton, SIGNAL(clicked()), this, SLOT(customCardDatabaseButtonClicked()));
|
connect(customCardDatabasePathButton, SIGNAL(clicked()), this, SLOT(customCardDatabaseButtonClicked()));
|
||||||
|
|
||||||
tokenDatabasePathEdit = new QLineEdit(SettingsCache::instance().getTokenDatabasePath());
|
tokenDatabasePathEdit = new QLineEdit(settings.getTokenDatabasePath());
|
||||||
tokenDatabasePathEdit->setReadOnly(true);
|
tokenDatabasePathEdit->setReadOnly(true);
|
||||||
QPushButton *tokenDatabasePathButton = new QPushButton("...");
|
QPushButton *tokenDatabasePathButton = new QPushButton("...");
|
||||||
connect(tokenDatabasePathButton, SIGNAL(clicked()), this, SLOT(tokenDatabasePathButtonClicked()));
|
connect(tokenDatabasePathButton, SIGNAL(clicked()), this, SLOT(tokenDatabasePathButtonClicked()));
|
||||||
|
|
||||||
if (SettingsCache::instance().getIsPortableBuild()) {
|
bool isPortable = settings.getIsPortableBuild();
|
||||||
|
if (isPortable) {
|
||||||
deckPathEdit->setEnabled(false);
|
deckPathEdit->setEnabled(false);
|
||||||
replaysPathEdit->setEnabled(false);
|
replaysPathEdit->setEnabled(false);
|
||||||
picsPathEdit->setEnabled(false);
|
picsPathEdit->setEnabled(false);
|
||||||
|
@ -139,8 +141,13 @@ GeneralSettingsPage::GeneralSettingsPage()
|
||||||
replaysPathButton->setVisible(false);
|
replaysPathButton->setVisible(false);
|
||||||
picsPathButton->setVisible(false);
|
picsPathButton->setVisible(false);
|
||||||
cardDatabasePathButton->setVisible(false);
|
cardDatabasePathButton->setVisible(false);
|
||||||
customCardDatabasePathEdit->setVisible(false);
|
customCardDatabasePathButton->setVisible(false);
|
||||||
tokenDatabasePathButton->setVisible(false);
|
tokenDatabasePathButton->setVisible(false);
|
||||||
|
} else {
|
||||||
|
resetAllPathsButton = new QPushButton(tr("Reset all paths"));
|
||||||
|
connect(resetAllPathsButton, SIGNAL(clicked()), this, SLOT(resetAllPathsClicked()));
|
||||||
|
allPathsResetLabel = new QLabel(tr("All paths have been reset"));
|
||||||
|
allPathsResetLabel->setVisible(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto *pathsGrid = new QGridLayout;
|
auto *pathsGrid = new QGridLayout;
|
||||||
|
@ -162,6 +169,10 @@ GeneralSettingsPage::GeneralSettingsPage()
|
||||||
pathsGrid->addWidget(&tokenDatabasePathLabel, 5, 0);
|
pathsGrid->addWidget(&tokenDatabasePathLabel, 5, 0);
|
||||||
pathsGrid->addWidget(tokenDatabasePathEdit, 5, 1);
|
pathsGrid->addWidget(tokenDatabasePathEdit, 5, 1);
|
||||||
pathsGrid->addWidget(tokenDatabasePathButton, 5, 2);
|
pathsGrid->addWidget(tokenDatabasePathButton, 5, 2);
|
||||||
|
if (!isPortable) {
|
||||||
|
pathsGrid->addWidget(resetAllPathsButton, 6, 0);
|
||||||
|
pathsGrid->addWidget(allPathsResetLabel, 6, 1);
|
||||||
|
}
|
||||||
pathsGroupBox = new QGroupBox;
|
pathsGroupBox = new QGroupBox;
|
||||||
pathsGroupBox->setLayout(pathsGrid);
|
pathsGroupBox->setLayout(pathsGrid);
|
||||||
|
|
||||||
|
@ -251,6 +262,19 @@ void GeneralSettingsPage::tokenDatabasePathButtonClicked()
|
||||||
SettingsCache::instance().setTokenDatabasePath(path);
|
SettingsCache::instance().setTokenDatabasePath(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GeneralSettingsPage::resetAllPathsClicked()
|
||||||
|
{
|
||||||
|
SettingsCache &settings = SettingsCache::instance();
|
||||||
|
settings.resetPaths();
|
||||||
|
deckPathEdit->setText(settings.getDeckPath());
|
||||||
|
replaysPathEdit->setText(settings.getReplaysPath());
|
||||||
|
picsPathEdit->setText(settings.getPicsPath());
|
||||||
|
cardDatabasePathEdit->setText(settings.getCardDatabasePath());
|
||||||
|
customCardDatabasePathEdit->setText(settings.getCustomCardDatabasePath());
|
||||||
|
tokenDatabasePathEdit->setText(settings.getTokenDatabasePath());
|
||||||
|
allPathsResetLabel->setVisible(true);
|
||||||
|
}
|
||||||
|
|
||||||
void GeneralSettingsPage::languageBoxChanged(int index)
|
void GeneralSettingsPage::languageBoxChanged(int index)
|
||||||
{
|
{
|
||||||
SettingsCache::instance().setLang(languageBox.itemData(index).toString());
|
SettingsCache::instance().setLang(languageBox.itemData(index).toString());
|
||||||
|
|
|
@ -44,6 +44,7 @@ private slots:
|
||||||
void cardDatabasePathButtonClicked();
|
void cardDatabasePathButtonClicked();
|
||||||
void customCardDatabaseButtonClicked();
|
void customCardDatabaseButtonClicked();
|
||||||
void tokenDatabasePathButtonClicked();
|
void tokenDatabasePathButtonClicked();
|
||||||
|
void resetAllPathsClicked();
|
||||||
void languageBoxChanged(int index);
|
void languageBoxChanged(int index);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -55,6 +56,8 @@ private:
|
||||||
QLineEdit *cardDatabasePathEdit;
|
QLineEdit *cardDatabasePathEdit;
|
||||||
QLineEdit *customCardDatabasePathEdit;
|
QLineEdit *customCardDatabasePathEdit;
|
||||||
QLineEdit *tokenDatabasePathEdit;
|
QLineEdit *tokenDatabasePathEdit;
|
||||||
|
QPushButton *resetAllPathsButton;
|
||||||
|
QLabel *allPathsResetLabel;
|
||||||
QSpinBox pixmapCacheEdit;
|
QSpinBox pixmapCacheEdit;
|
||||||
QGroupBox *personalGroupBox;
|
QGroupBox *personalGroupBox;
|
||||||
QGroupBox *pathsGroupBox;
|
QGroupBox *pathsGroupBox;
|
||||||
|
|
|
@ -128,7 +128,7 @@ QString SettingsCache::getSafeConfigPath(QString configEntry, QString defaultPat
|
||||||
QString tmp = settings->value(configEntry).toString();
|
QString tmp = settings->value(configEntry).toString();
|
||||||
// if the config settings is empty or refers to a not-existing folder,
|
// if the config settings is empty or refers to a not-existing folder,
|
||||||
// ensure that the defaut path exists and return it
|
// ensure that the defaut path exists and return it
|
||||||
if (!QDir(tmp).exists() || tmp.isEmpty()) {
|
if (tmp.isEmpty() || !QDir(tmp).exists()) {
|
||||||
if (!QDir().mkpath(defaultPath))
|
if (!QDir().mkpath(defaultPath))
|
||||||
qDebug() << "[SettingsCache] Could not create folder:" << defaultPath;
|
qDebug() << "[SettingsCache] Could not create folder:" << defaultPath;
|
||||||
tmp = defaultPath;
|
tmp = defaultPath;
|
||||||
|
@ -156,7 +156,6 @@ SettingsCache::SettingsCache()
|
||||||
// define a dummy context that will be used where needed
|
// define a dummy context that will be used where needed
|
||||||
QString dummy = QT_TRANSLATE_NOOP("i18n", "English");
|
QString dummy = QT_TRANSLATE_NOOP("i18n", "English");
|
||||||
|
|
||||||
QString dataPath = getDataPath();
|
|
||||||
QString settingsPath = getSettingsPath();
|
QString settingsPath = getSettingsPath();
|
||||||
settings = new QSettings(settingsPath + "global.ini", QSettings::IniFormat, this);
|
settings = new QSettings(settingsPath + "global.ini", QSettings::IniFormat, this);
|
||||||
shortcutsSettings = new ShortcutsSettings(settingsPath, this);
|
shortcutsSettings = new ShortcutsSettings(settingsPath, this);
|
||||||
|
@ -190,21 +189,7 @@ SettingsCache::SettingsCache()
|
||||||
seenTips.append(tipNumber.toInt());
|
seenTips.append(tipNumber.toInt());
|
||||||
}
|
}
|
||||||
|
|
||||||
deckPath = getSafeConfigPath("paths/decks", dataPath + "/decks/");
|
loadPaths();
|
||||||
replaysPath = getSafeConfigPath("paths/replays", dataPath + "/replays/");
|
|
||||||
themesPath = getSafeConfigPath("paths/themes", dataPath + "/themes/");
|
|
||||||
picsPath = getSafeConfigPath("paths/pics", dataPath + "/pics/");
|
|
||||||
// this has never been exposed as an user-configurable setting
|
|
||||||
if (picsPath.endsWith("/")) {
|
|
||||||
customPicsPath = getSafeConfigPath("paths/custompics", picsPath + "CUSTOM/");
|
|
||||||
} else {
|
|
||||||
customPicsPath = getSafeConfigPath("paths/custompics", picsPath + "/CUSTOM/");
|
|
||||||
}
|
|
||||||
customCardDatabasePath = getSafeConfigPath("paths/customsets", dataPath + "/customsets/");
|
|
||||||
|
|
||||||
cardDatabasePath = getSafeConfigFilePath("paths/carddatabase", dataPath + "/cards.xml");
|
|
||||||
tokenDatabasePath = getSafeConfigFilePath("paths/tokendatabase", dataPath + "/tokens.xml");
|
|
||||||
spoilerDatabasePath = getSafeConfigFilePath("paths/spoilerdatabase", dataPath + "/spoiler.xml");
|
|
||||||
|
|
||||||
themeName = settings->value("theme/name").toString();
|
themeName = settings->value("theme/name").toString();
|
||||||
|
|
||||||
|
@ -395,6 +380,7 @@ void SettingsCache::setCustomCardDatabasePath(const QString &_customCardDatabase
|
||||||
{
|
{
|
||||||
customCardDatabasePath = _customCardDatabasePath;
|
customCardDatabasePath = _customCardDatabasePath;
|
||||||
settings->setValue("paths/customsets", customCardDatabasePath);
|
settings->setValue("paths/customsets", customCardDatabasePath);
|
||||||
|
emit cardDatabasePathChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingsCache::setPicsPath(const QString &_picsPath)
|
void SettingsCache::setPicsPath(const QString &_picsPath)
|
||||||
|
@ -987,6 +973,41 @@ void SettingsCache::setMaxFontSize(int _max)
|
||||||
settings->setValue("game/maxfontsize", maxFontSize);
|
settings->setValue("game/maxfontsize", maxFontSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SettingsCache::loadPaths()
|
||||||
|
{
|
||||||
|
QString dataPath = getDataPath();
|
||||||
|
deckPath = getSafeConfigPath("paths/decks", dataPath + "/decks/");
|
||||||
|
replaysPath = getSafeConfigPath("paths/replays", dataPath + "/replays/");
|
||||||
|
themesPath = getSafeConfigPath("paths/themes", dataPath + "/themes/");
|
||||||
|
picsPath = getSafeConfigPath("paths/pics", dataPath + "/pics/");
|
||||||
|
// this has never been exposed as an user-configurable setting
|
||||||
|
if (picsPath.endsWith("/")) {
|
||||||
|
customPicsPath = getSafeConfigPath("paths/custompics", picsPath + "CUSTOM/");
|
||||||
|
} else {
|
||||||
|
customPicsPath = getSafeConfigPath("paths/custompics", picsPath + "/CUSTOM/");
|
||||||
|
}
|
||||||
|
customCardDatabasePath = getSafeConfigPath("paths/customsets", dataPath + "/customsets/");
|
||||||
|
|
||||||
|
cardDatabasePath = getSafeConfigFilePath("paths/carddatabase", dataPath + "/cards.xml");
|
||||||
|
tokenDatabasePath = getSafeConfigFilePath("paths/tokendatabase", dataPath + "/tokens.xml");
|
||||||
|
spoilerDatabasePath = getSafeConfigFilePath("paths/spoilerdatabase", dataPath + "/spoiler.xml");
|
||||||
|
}
|
||||||
|
|
||||||
|
void SettingsCache::resetPaths()
|
||||||
|
{
|
||||||
|
QStringList databasePaths{customCardDatabasePath, cardDatabasePath, spoilerDatabasePath, tokenDatabasePath};
|
||||||
|
QString picsPath_ = picsPath;
|
||||||
|
settings->remove("paths"); // removes all keys in paths/*
|
||||||
|
loadPaths();
|
||||||
|
if (databasePaths !=
|
||||||
|
QStringList{customCardDatabasePath, cardDatabasePath, spoilerDatabasePath, tokenDatabasePath}) {
|
||||||
|
emit cardDatabasePathChanged();
|
||||||
|
}
|
||||||
|
if (picsPath_ != picsPath) {
|
||||||
|
emit picsPathChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
SettingsCache &SettingsCache::instance()
|
SettingsCache &SettingsCache::instance()
|
||||||
{
|
{
|
||||||
return *settingsCache;
|
return *settingsCache;
|
||||||
|
|
|
@ -129,6 +129,7 @@ private:
|
||||||
void translateLegacySettings();
|
void translateLegacySettings();
|
||||||
QString getSafeConfigPath(QString configEntry, QString defaultPath) const;
|
QString getSafeConfigPath(QString configEntry, QString defaultPath) const;
|
||||||
QString getSafeConfigFilePath(QString configEntry, QString defaultPath) const;
|
QString getSafeConfigFilePath(QString configEntry, QString defaultPath) const;
|
||||||
|
void loadPaths();
|
||||||
bool rememberGameSettings;
|
bool rememberGameSettings;
|
||||||
QList<ReleaseChannel *> releaseChannels;
|
QList<ReleaseChannel *> releaseChannels;
|
||||||
bool isPortableBuild;
|
bool isPortableBuild;
|
||||||
|
@ -473,6 +474,8 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
static SettingsCache &instance();
|
static SettingsCache &instance();
|
||||||
|
void resetPaths();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setDownloadSpoilerStatus(bool _spoilerStatus);
|
void setDownloadSpoilerStatus(bool _spoilerStatus);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue