Change the filters path to not be hardcoded anymore.

This commit is contained in:
Lukas Brübach 2025-03-07 15:05:31 +01:00
parent f326f74b5e
commit c9f95e1df1
9 changed files with 67 additions and 30 deletions

View file

@ -1,15 +1,15 @@
#include "visual_database_display_filter_save_load_widget.h"
#include "../../../../game/filters/filter_tree.h"
#include "../../../../settings/cache_settings.h"
#include <QHBoxLayout>
#include <QJsonArray>
#include <QJsonObject>
VisualDatabaseDisplayFilterSaveLoadWidget::VisualDatabaseDisplayFilterSaveLoadWidget(QWidget *parent,
FilterTreeModel *_filterModel,
const QString &savePath)
: QWidget(parent), filterModel(_filterModel), saveDirectory(savePath)
FilterTreeModel *_filterModel)
: QWidget(parent), filterModel(_filterModel)
{
setMinimumWidth(300);
setMaximumHeight(300);
@ -40,7 +40,7 @@ void VisualDatabaseDisplayFilterSaveLoadWidget::saveFilter()
if (filename.isEmpty())
return;
QString filePath = saveDirectory + QDir::separator() + filename + ".json";
QString filePath = SettingsCache::instance().getFiltersPath() + QDir::separator() + filename + ".json";
// Serialize the filter model to JSON
QJsonArray filtersArray;
@ -65,7 +65,7 @@ void VisualDatabaseDisplayFilterSaveLoadWidget::saveFilter()
void VisualDatabaseDisplayFilterSaveLoadWidget::loadFilter(const QString &filename)
{
QString filePath = saveDirectory + "/" + filename;
QString filePath = SettingsCache::instance().getFiltersPath() + "/" + filename;
QFile file(filePath);
if (!file.open(QIODevice::ReadOnly))
@ -111,7 +111,7 @@ void VisualDatabaseDisplayFilterSaveLoadWidget::refreshFilterList()
}
fileButtons.clear();
QDir dir(saveDirectory);
QDir dir(SettingsCache::instance().getFiltersPath());
QStringList filterFiles = dir.entryList(QStringList() << "*.json", QDir::Files, QDir::Time);
for (const QString &filename : filterFiles) {

View file

@ -19,9 +19,7 @@ class VisualDatabaseDisplayFilterSaveLoadWidget : public QWidget
{
Q_OBJECT
public:
explicit VisualDatabaseDisplayFilterSaveLoadWidget(QWidget *parent,
FilterTreeModel *filterModel,
const QString &savePath);
explicit VisualDatabaseDisplayFilterSaveLoadWidget(QWidget *parent, FilterTreeModel *filterModel);
void saveFilter();
void loadFilter(const QString &filename);
@ -29,7 +27,6 @@ public:
private:
FilterTreeModel *filterModel;
QString saveDirectory;
QVBoxLayout *layout;
QLineEdit *filenameInput;

View file

@ -91,8 +91,7 @@ VisualDatabaseDisplayWidget::VisualDatabaseDisplayWidget(QWidget *parent,
quickFilterWidget = new SettingsButtonWidget(this);
saveLoadWidget =
new VisualDatabaseDisplayFilterSaveLoadWidget(this, filterModel, "/home/ascor/Cockatrice_presets/");
saveLoadWidget = new VisualDatabaseDisplayFilterSaveLoadWidget(this, filterModel);
nameFilterWidget = new VisualDatabaseDisplayNameFilterWidget(this, deckEditor, filterModel);
mainTypeFilterWidget = new VisualDatabaseDisplayMainTypeFilterWidget(this, filterModel);
subTypeFilterWidget = new VisualDatabaseDisplaySubTypeFilterWidget(this, filterModel);

View file

@ -101,6 +101,11 @@ GeneralSettingsPage::GeneralSettingsPage()
QPushButton *deckPathButton = new QPushButton("...");
connect(deckPathButton, SIGNAL(clicked()), this, SLOT(deckPathButtonClicked()));
filtersPathEdit = new QLineEdit(settings.getFiltersPath());
filtersPathEdit->setReadOnly(true);
QPushButton *filtersPathButton = new QPushButton("...");
connect(filtersPathButton, SIGNAL(clicked()), this, SLOT(filtersPathButtonClicked()));
replaysPathEdit = new QLineEdit(settings.getReplaysPath());
replaysPathEdit->setReadOnly(true);
QPushButton *replaysPathButton = new QPushButton("...");
@ -132,6 +137,7 @@ GeneralSettingsPage::GeneralSettingsPage()
bool isPortable = settings.getIsPortableBuild();
if (isPortable) {
deckPathEdit->setEnabled(false);
filtersPathEdit->setEnabled(false);
replaysPathEdit->setEnabled(false);
picsPathEdit->setEnabled(false);
cardDatabasePathEdit->setEnabled(false);
@ -154,24 +160,27 @@ GeneralSettingsPage::GeneralSettingsPage()
pathsGrid->addWidget(&deckPathLabel, 0, 0);
pathsGrid->addWidget(deckPathEdit, 0, 1);
pathsGrid->addWidget(deckPathButton, 0, 2);
pathsGrid->addWidget(&replaysPathLabel, 1, 0);
pathsGrid->addWidget(replaysPathEdit, 1, 1);
pathsGrid->addWidget(replaysPathButton, 1, 2);
pathsGrid->addWidget(&picsPathLabel, 2, 0);
pathsGrid->addWidget(picsPathEdit, 2, 1);
pathsGrid->addWidget(picsPathButton, 2, 2);
pathsGrid->addWidget(&cardDatabasePathLabel, 3, 0);
pathsGrid->addWidget(cardDatabasePathEdit, 3, 1);
pathsGrid->addWidget(cardDatabasePathButton, 3, 2);
pathsGrid->addWidget(&customCardDatabasePathLabel, 4, 0);
pathsGrid->addWidget(customCardDatabasePathEdit, 4, 1);
pathsGrid->addWidget(customCardDatabasePathButton, 4, 2);
pathsGrid->addWidget(&tokenDatabasePathLabel, 5, 0);
pathsGrid->addWidget(tokenDatabasePathEdit, 5, 1);
pathsGrid->addWidget(tokenDatabasePathButton, 5, 2);
pathsGrid->addWidget(&filtersPathLabel, 1, 0);
pathsGrid->addWidget(filtersPathEdit, 1, 1);
pathsGrid->addWidget(filtersPathButton, 1, 2);
pathsGrid->addWidget(&replaysPathLabel, 2, 0);
pathsGrid->addWidget(replaysPathEdit, 2, 1);
pathsGrid->addWidget(replaysPathButton, 2, 2);
pathsGrid->addWidget(&picsPathLabel, 3, 0);
pathsGrid->addWidget(picsPathEdit, 3, 1);
pathsGrid->addWidget(picsPathButton, 3, 2);
pathsGrid->addWidget(&cardDatabasePathLabel, 4, 0);
pathsGrid->addWidget(cardDatabasePathEdit, 4, 1);
pathsGrid->addWidget(cardDatabasePathButton, 4, 2);
pathsGrid->addWidget(&customCardDatabasePathLabel, 5, 0);
pathsGrid->addWidget(customCardDatabasePathEdit, 5, 1);
pathsGrid->addWidget(customCardDatabasePathButton, 5, 2);
pathsGrid->addWidget(&tokenDatabasePathLabel, 6, 0);
pathsGrid->addWidget(tokenDatabasePathEdit, 6, 1);
pathsGrid->addWidget(tokenDatabasePathButton, 6, 2);
if (!isPortable) {
pathsGrid->addWidget(resetAllPathsButton, 6, 0);
pathsGrid->addWidget(allPathsResetLabel, 6, 1);
pathsGrid->addWidget(resetAllPathsButton, 7, 0);
pathsGrid->addWidget(allPathsResetLabel, 7, 1);
}
pathsGroupBox = new QGroupBox;
pathsGroupBox->setLayout(pathsGrid);
@ -226,6 +235,16 @@ void GeneralSettingsPage::deckPathButtonClicked()
SettingsCache::instance().setDeckPath(path);
}
void GeneralSettingsPage::filtersPathButtonClicked()
{
QString path = QFileDialog::getExistingDirectory(this, tr("Choose path"), filtersPathEdit->text());
if (path.isEmpty())
return;
filtersPathEdit->setText(path);
SettingsCache::instance().setFiltersPath(path);
}
void GeneralSettingsPage::replaysPathButtonClicked()
{
QString path = QFileDialog::getExistingDirectory(this, tr("Choose path"), replaysPathEdit->text());
@ -307,6 +326,7 @@ void GeneralSettingsPage::retranslateUi()
advertiseTranslationPageLabel.setText(
QString("<a href='%1'>%2</a>").arg(WIKI_TRANSLATION_FAQ).arg(tr("How to help with translations")));
deckPathLabel.setText(tr("Decks directory:"));
filtersPathLabel.setText(tr("Filters directory:"));
replaysPathLabel.setText(tr("Replays directory:"));
picsPathLabel.setText(tr("Pictures directory:"));
cardDatabasePathLabel.setText(tr("Card database:"));

View file

@ -46,6 +46,7 @@ public:
private slots:
void deckPathButtonClicked();
void filtersPathButtonClicked();
void replaysPathButtonClicked();
void picsPathButtonClicked();
void cardDatabasePathButtonClicked();
@ -58,6 +59,7 @@ private:
QStringList findQmFiles();
QString languageName(const QString &lang);
QLineEdit *deckPathEdit;
QLineEdit *filtersPathEdit;
QLineEdit *replaysPathEdit;
QLineEdit *picsPathEdit;
QLineEdit *cardDatabasePathEdit;
@ -74,6 +76,7 @@ private:
QComboBox updateReleaseChannelBox;
QLabel languageLabel;
QLabel deckPathLabel;
QLabel filtersPathLabel;
QLabel replaysPathLabel;
QLabel picsPathLabel;
QLabel cardDatabasePathLabel;

View file

@ -451,6 +451,12 @@ void SettingsCache::setDeckPath(const QString &_deckPath)
settings->setValue("paths/decks", deckPath);
}
void SettingsCache::setFiltersPath(const QString &_filtersPath)
{
filtersPath = _filtersPath;
settings->setValue("paths/filters", filtersPath);
}
void SettingsCache::setReplaysPath(const QString &_replaysPath)
{
replaysPath = _replaysPath;
@ -1312,6 +1318,7 @@ void SettingsCache::loadPaths()
{
QString dataPath = getDataPath();
deckPath = getSafeConfigPath("paths/decks", dataPath + "/decks/");
filtersPath = getSafeConfigPath("paths/filters", dataPath + "/filters/");
replaysPath = getSafeConfigPath("paths/replays", dataPath + "/replays/");
themesPath = getSafeConfigPath("paths/themes", dataPath + "/themes/");
picsPath = getSafeConfigPath("paths/pics", dataPath + "/pics/");

View file

@ -103,7 +103,7 @@ private:
QByteArray tokenDialogGeometry;
QByteArray setsDialogGeometry;
QString lang;
QString deckPath, replaysPath, picsPath, redirectCachePath, customPicsPath, cardDatabasePath,
QString deckPath, filtersPath, replaysPath, picsPath, redirectCachePath, customPicsPath, cardDatabasePath,
customCardDatabasePath, themesPath, spoilerDatabasePath, tokenDatabasePath, themeName;
bool tabVisualDeckStorageOpen, tabServerOpen, tabAccountOpen, tabDeckStorageOpen, tabReplaysOpen, tabAdminOpen,
tabLogOpen;
@ -233,6 +233,10 @@ public:
{
return deckPath;
}
QString getFiltersPath() const
{
return filtersPath;
}
QString getReplaysPath() const
{
return replaysPath;
@ -754,6 +758,7 @@ public slots:
void setShowTipsOnStartup(bool _showTipsOnStartup);
void setSeenTips(const QList<int> &_seenTips);
void setDeckPath(const QString &_deckPath);
void setFiltersPath(const QString &_filtersPath);
void setReplaysPath(const QString &_replaysPath);
void setThemesPath(const QString &_themesPath);
void setCustomCardDatabasePath(const QString &_customCardDatabasePath);

View file

@ -106,6 +106,9 @@ void SettingsCache::setSeenTips(const QList<int> & /* _seenTips */)
void SettingsCache::setDeckPath(const QString & /* _deckPath */)
{
}
void SettingsCache::setFiltersPath(const QString & /*_filtersPath */)
{
}
void SettingsCache::setReplaysPath(const QString & /* _replaysPath */)
{
}

View file

@ -110,6 +110,9 @@ void SettingsCache::setSeenTips(const QList<int> & /* _seenTips */)
void SettingsCache::setDeckPath(const QString & /* _deckPath */)
{
}
void SettingsCache::setFiltersPath(const QString & /*_filtersPath */)
{
}
void SettingsCache::setReplaysPath(const QString & /* _replaysPath */)
{
}