mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-17 07:52:16 -07:00
Change the filters path to not be hardcoded anymore.
This commit is contained in:
parent
f326f74b5e
commit
c9f95e1df1
9 changed files with 67 additions and 30 deletions
|
|
@ -1,15 +1,15 @@
|
||||||
#include "visual_database_display_filter_save_load_widget.h"
|
#include "visual_database_display_filter_save_load_widget.h"
|
||||||
|
|
||||||
#include "../../../../game/filters/filter_tree.h"
|
#include "../../../../game/filters/filter_tree.h"
|
||||||
|
#include "../../../../settings/cache_settings.h"
|
||||||
|
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
#include <QJsonArray>
|
#include <QJsonArray>
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
|
|
||||||
VisualDatabaseDisplayFilterSaveLoadWidget::VisualDatabaseDisplayFilterSaveLoadWidget(QWidget *parent,
|
VisualDatabaseDisplayFilterSaveLoadWidget::VisualDatabaseDisplayFilterSaveLoadWidget(QWidget *parent,
|
||||||
FilterTreeModel *_filterModel,
|
FilterTreeModel *_filterModel)
|
||||||
const QString &savePath)
|
: QWidget(parent), filterModel(_filterModel)
|
||||||
: QWidget(parent), filterModel(_filterModel), saveDirectory(savePath)
|
|
||||||
{
|
{
|
||||||
setMinimumWidth(300);
|
setMinimumWidth(300);
|
||||||
setMaximumHeight(300);
|
setMaximumHeight(300);
|
||||||
|
|
@ -40,7 +40,7 @@ void VisualDatabaseDisplayFilterSaveLoadWidget::saveFilter()
|
||||||
if (filename.isEmpty())
|
if (filename.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QString filePath = saveDirectory + QDir::separator() + filename + ".json";
|
QString filePath = SettingsCache::instance().getFiltersPath() + QDir::separator() + filename + ".json";
|
||||||
|
|
||||||
// Serialize the filter model to JSON
|
// Serialize the filter model to JSON
|
||||||
QJsonArray filtersArray;
|
QJsonArray filtersArray;
|
||||||
|
|
@ -65,7 +65,7 @@ void VisualDatabaseDisplayFilterSaveLoadWidget::saveFilter()
|
||||||
|
|
||||||
void VisualDatabaseDisplayFilterSaveLoadWidget::loadFilter(const QString &filename)
|
void VisualDatabaseDisplayFilterSaveLoadWidget::loadFilter(const QString &filename)
|
||||||
{
|
{
|
||||||
QString filePath = saveDirectory + "/" + filename;
|
QString filePath = SettingsCache::instance().getFiltersPath() + "/" + filename;
|
||||||
|
|
||||||
QFile file(filePath);
|
QFile file(filePath);
|
||||||
if (!file.open(QIODevice::ReadOnly))
|
if (!file.open(QIODevice::ReadOnly))
|
||||||
|
|
@ -111,7 +111,7 @@ void VisualDatabaseDisplayFilterSaveLoadWidget::refreshFilterList()
|
||||||
}
|
}
|
||||||
fileButtons.clear();
|
fileButtons.clear();
|
||||||
|
|
||||||
QDir dir(saveDirectory);
|
QDir dir(SettingsCache::instance().getFiltersPath());
|
||||||
QStringList filterFiles = dir.entryList(QStringList() << "*.json", QDir::Files, QDir::Time);
|
QStringList filterFiles = dir.entryList(QStringList() << "*.json", QDir::Files, QDir::Time);
|
||||||
|
|
||||||
for (const QString &filename : filterFiles) {
|
for (const QString &filename : filterFiles) {
|
||||||
|
|
|
||||||
|
|
@ -19,9 +19,7 @@ class VisualDatabaseDisplayFilterSaveLoadWidget : public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit VisualDatabaseDisplayFilterSaveLoadWidget(QWidget *parent,
|
explicit VisualDatabaseDisplayFilterSaveLoadWidget(QWidget *parent, FilterTreeModel *filterModel);
|
||||||
FilterTreeModel *filterModel,
|
|
||||||
const QString &savePath);
|
|
||||||
|
|
||||||
void saveFilter();
|
void saveFilter();
|
||||||
void loadFilter(const QString &filename);
|
void loadFilter(const QString &filename);
|
||||||
|
|
@ -29,7 +27,6 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FilterTreeModel *filterModel;
|
FilterTreeModel *filterModel;
|
||||||
QString saveDirectory;
|
|
||||||
|
|
||||||
QVBoxLayout *layout;
|
QVBoxLayout *layout;
|
||||||
QLineEdit *filenameInput;
|
QLineEdit *filenameInput;
|
||||||
|
|
|
||||||
|
|
@ -91,8 +91,7 @@ VisualDatabaseDisplayWidget::VisualDatabaseDisplayWidget(QWidget *parent,
|
||||||
|
|
||||||
quickFilterWidget = new SettingsButtonWidget(this);
|
quickFilterWidget = new SettingsButtonWidget(this);
|
||||||
|
|
||||||
saveLoadWidget =
|
saveLoadWidget = new VisualDatabaseDisplayFilterSaveLoadWidget(this, filterModel);
|
||||||
new VisualDatabaseDisplayFilterSaveLoadWidget(this, filterModel, "/home/ascor/Cockatrice_presets/");
|
|
||||||
nameFilterWidget = new VisualDatabaseDisplayNameFilterWidget(this, deckEditor, filterModel);
|
nameFilterWidget = new VisualDatabaseDisplayNameFilterWidget(this, deckEditor, filterModel);
|
||||||
mainTypeFilterWidget = new VisualDatabaseDisplayMainTypeFilterWidget(this, filterModel);
|
mainTypeFilterWidget = new VisualDatabaseDisplayMainTypeFilterWidget(this, filterModel);
|
||||||
subTypeFilterWidget = new VisualDatabaseDisplaySubTypeFilterWidget(this, filterModel);
|
subTypeFilterWidget = new VisualDatabaseDisplaySubTypeFilterWidget(this, filterModel);
|
||||||
|
|
|
||||||
|
|
@ -101,6 +101,11 @@ GeneralSettingsPage::GeneralSettingsPage()
|
||||||
QPushButton *deckPathButton = new QPushButton("...");
|
QPushButton *deckPathButton = new QPushButton("...");
|
||||||
connect(deckPathButton, SIGNAL(clicked()), this, SLOT(deckPathButtonClicked()));
|
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 = new QLineEdit(settings.getReplaysPath());
|
||||||
replaysPathEdit->setReadOnly(true);
|
replaysPathEdit->setReadOnly(true);
|
||||||
QPushButton *replaysPathButton = new QPushButton("...");
|
QPushButton *replaysPathButton = new QPushButton("...");
|
||||||
|
|
@ -132,6 +137,7 @@ GeneralSettingsPage::GeneralSettingsPage()
|
||||||
bool isPortable = settings.getIsPortableBuild();
|
bool isPortable = settings.getIsPortableBuild();
|
||||||
if (isPortable) {
|
if (isPortable) {
|
||||||
deckPathEdit->setEnabled(false);
|
deckPathEdit->setEnabled(false);
|
||||||
|
filtersPathEdit->setEnabled(false);
|
||||||
replaysPathEdit->setEnabled(false);
|
replaysPathEdit->setEnabled(false);
|
||||||
picsPathEdit->setEnabled(false);
|
picsPathEdit->setEnabled(false);
|
||||||
cardDatabasePathEdit->setEnabled(false);
|
cardDatabasePathEdit->setEnabled(false);
|
||||||
|
|
@ -154,24 +160,27 @@ GeneralSettingsPage::GeneralSettingsPage()
|
||||||
pathsGrid->addWidget(&deckPathLabel, 0, 0);
|
pathsGrid->addWidget(&deckPathLabel, 0, 0);
|
||||||
pathsGrid->addWidget(deckPathEdit, 0, 1);
|
pathsGrid->addWidget(deckPathEdit, 0, 1);
|
||||||
pathsGrid->addWidget(deckPathButton, 0, 2);
|
pathsGrid->addWidget(deckPathButton, 0, 2);
|
||||||
pathsGrid->addWidget(&replaysPathLabel, 1, 0);
|
pathsGrid->addWidget(&filtersPathLabel, 1, 0);
|
||||||
pathsGrid->addWidget(replaysPathEdit, 1, 1);
|
pathsGrid->addWidget(filtersPathEdit, 1, 1);
|
||||||
pathsGrid->addWidget(replaysPathButton, 1, 2);
|
pathsGrid->addWidget(filtersPathButton, 1, 2);
|
||||||
pathsGrid->addWidget(&picsPathLabel, 2, 0);
|
pathsGrid->addWidget(&replaysPathLabel, 2, 0);
|
||||||
pathsGrid->addWidget(picsPathEdit, 2, 1);
|
pathsGrid->addWidget(replaysPathEdit, 2, 1);
|
||||||
pathsGrid->addWidget(picsPathButton, 2, 2);
|
pathsGrid->addWidget(replaysPathButton, 2, 2);
|
||||||
pathsGrid->addWidget(&cardDatabasePathLabel, 3, 0);
|
pathsGrid->addWidget(&picsPathLabel, 3, 0);
|
||||||
pathsGrid->addWidget(cardDatabasePathEdit, 3, 1);
|
pathsGrid->addWidget(picsPathEdit, 3, 1);
|
||||||
pathsGrid->addWidget(cardDatabasePathButton, 3, 2);
|
pathsGrid->addWidget(picsPathButton, 3, 2);
|
||||||
pathsGrid->addWidget(&customCardDatabasePathLabel, 4, 0);
|
pathsGrid->addWidget(&cardDatabasePathLabel, 4, 0);
|
||||||
pathsGrid->addWidget(customCardDatabasePathEdit, 4, 1);
|
pathsGrid->addWidget(cardDatabasePathEdit, 4, 1);
|
||||||
pathsGrid->addWidget(customCardDatabasePathButton, 4, 2);
|
pathsGrid->addWidget(cardDatabasePathButton, 4, 2);
|
||||||
pathsGrid->addWidget(&tokenDatabasePathLabel, 5, 0);
|
pathsGrid->addWidget(&customCardDatabasePathLabel, 5, 0);
|
||||||
pathsGrid->addWidget(tokenDatabasePathEdit, 5, 1);
|
pathsGrid->addWidget(customCardDatabasePathEdit, 5, 1);
|
||||||
pathsGrid->addWidget(tokenDatabasePathButton, 5, 2);
|
pathsGrid->addWidget(customCardDatabasePathButton, 5, 2);
|
||||||
|
pathsGrid->addWidget(&tokenDatabasePathLabel, 6, 0);
|
||||||
|
pathsGrid->addWidget(tokenDatabasePathEdit, 6, 1);
|
||||||
|
pathsGrid->addWidget(tokenDatabasePathButton, 6, 2);
|
||||||
if (!isPortable) {
|
if (!isPortable) {
|
||||||
pathsGrid->addWidget(resetAllPathsButton, 6, 0);
|
pathsGrid->addWidget(resetAllPathsButton, 7, 0);
|
||||||
pathsGrid->addWidget(allPathsResetLabel, 6, 1);
|
pathsGrid->addWidget(allPathsResetLabel, 7, 1);
|
||||||
}
|
}
|
||||||
pathsGroupBox = new QGroupBox;
|
pathsGroupBox = new QGroupBox;
|
||||||
pathsGroupBox->setLayout(pathsGrid);
|
pathsGroupBox->setLayout(pathsGrid);
|
||||||
|
|
@ -226,6 +235,16 @@ void GeneralSettingsPage::deckPathButtonClicked()
|
||||||
SettingsCache::instance().setDeckPath(path);
|
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()
|
void GeneralSettingsPage::replaysPathButtonClicked()
|
||||||
{
|
{
|
||||||
QString path = QFileDialog::getExistingDirectory(this, tr("Choose path"), replaysPathEdit->text());
|
QString path = QFileDialog::getExistingDirectory(this, tr("Choose path"), replaysPathEdit->text());
|
||||||
|
|
@ -307,6 +326,7 @@ void GeneralSettingsPage::retranslateUi()
|
||||||
advertiseTranslationPageLabel.setText(
|
advertiseTranslationPageLabel.setText(
|
||||||
QString("<a href='%1'>%2</a>").arg(WIKI_TRANSLATION_FAQ).arg(tr("How to help with translations")));
|
QString("<a href='%1'>%2</a>").arg(WIKI_TRANSLATION_FAQ).arg(tr("How to help with translations")));
|
||||||
deckPathLabel.setText(tr("Decks directory:"));
|
deckPathLabel.setText(tr("Decks directory:"));
|
||||||
|
filtersPathLabel.setText(tr("Filters directory:"));
|
||||||
replaysPathLabel.setText(tr("Replays directory:"));
|
replaysPathLabel.setText(tr("Replays directory:"));
|
||||||
picsPathLabel.setText(tr("Pictures directory:"));
|
picsPathLabel.setText(tr("Pictures directory:"));
|
||||||
cardDatabasePathLabel.setText(tr("Card database:"));
|
cardDatabasePathLabel.setText(tr("Card database:"));
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,7 @@ public:
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void deckPathButtonClicked();
|
void deckPathButtonClicked();
|
||||||
|
void filtersPathButtonClicked();
|
||||||
void replaysPathButtonClicked();
|
void replaysPathButtonClicked();
|
||||||
void picsPathButtonClicked();
|
void picsPathButtonClicked();
|
||||||
void cardDatabasePathButtonClicked();
|
void cardDatabasePathButtonClicked();
|
||||||
|
|
@ -58,6 +59,7 @@ private:
|
||||||
QStringList findQmFiles();
|
QStringList findQmFiles();
|
||||||
QString languageName(const QString &lang);
|
QString languageName(const QString &lang);
|
||||||
QLineEdit *deckPathEdit;
|
QLineEdit *deckPathEdit;
|
||||||
|
QLineEdit *filtersPathEdit;
|
||||||
QLineEdit *replaysPathEdit;
|
QLineEdit *replaysPathEdit;
|
||||||
QLineEdit *picsPathEdit;
|
QLineEdit *picsPathEdit;
|
||||||
QLineEdit *cardDatabasePathEdit;
|
QLineEdit *cardDatabasePathEdit;
|
||||||
|
|
@ -74,6 +76,7 @@ private:
|
||||||
QComboBox updateReleaseChannelBox;
|
QComboBox updateReleaseChannelBox;
|
||||||
QLabel languageLabel;
|
QLabel languageLabel;
|
||||||
QLabel deckPathLabel;
|
QLabel deckPathLabel;
|
||||||
|
QLabel filtersPathLabel;
|
||||||
QLabel replaysPathLabel;
|
QLabel replaysPathLabel;
|
||||||
QLabel picsPathLabel;
|
QLabel picsPathLabel;
|
||||||
QLabel cardDatabasePathLabel;
|
QLabel cardDatabasePathLabel;
|
||||||
|
|
|
||||||
|
|
@ -451,6 +451,12 @@ void SettingsCache::setDeckPath(const QString &_deckPath)
|
||||||
settings->setValue("paths/decks", 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)
|
void SettingsCache::setReplaysPath(const QString &_replaysPath)
|
||||||
{
|
{
|
||||||
replaysPath = _replaysPath;
|
replaysPath = _replaysPath;
|
||||||
|
|
@ -1312,6 +1318,7 @@ void SettingsCache::loadPaths()
|
||||||
{
|
{
|
||||||
QString dataPath = getDataPath();
|
QString dataPath = getDataPath();
|
||||||
deckPath = getSafeConfigPath("paths/decks", dataPath + "/decks/");
|
deckPath = getSafeConfigPath("paths/decks", dataPath + "/decks/");
|
||||||
|
filtersPath = getSafeConfigPath("paths/filters", dataPath + "/filters/");
|
||||||
replaysPath = getSafeConfigPath("paths/replays", dataPath + "/replays/");
|
replaysPath = getSafeConfigPath("paths/replays", dataPath + "/replays/");
|
||||||
themesPath = getSafeConfigPath("paths/themes", dataPath + "/themes/");
|
themesPath = getSafeConfigPath("paths/themes", dataPath + "/themes/");
|
||||||
picsPath = getSafeConfigPath("paths/pics", dataPath + "/pics/");
|
picsPath = getSafeConfigPath("paths/pics", dataPath + "/pics/");
|
||||||
|
|
|
||||||
|
|
@ -103,7 +103,7 @@ private:
|
||||||
QByteArray tokenDialogGeometry;
|
QByteArray tokenDialogGeometry;
|
||||||
QByteArray setsDialogGeometry;
|
QByteArray setsDialogGeometry;
|
||||||
QString lang;
|
QString lang;
|
||||||
QString deckPath, replaysPath, picsPath, redirectCachePath, customPicsPath, cardDatabasePath,
|
QString deckPath, filtersPath, replaysPath, picsPath, redirectCachePath, customPicsPath, cardDatabasePath,
|
||||||
customCardDatabasePath, themesPath, spoilerDatabasePath, tokenDatabasePath, themeName;
|
customCardDatabasePath, themesPath, spoilerDatabasePath, tokenDatabasePath, themeName;
|
||||||
bool tabVisualDeckStorageOpen, tabServerOpen, tabAccountOpen, tabDeckStorageOpen, tabReplaysOpen, tabAdminOpen,
|
bool tabVisualDeckStorageOpen, tabServerOpen, tabAccountOpen, tabDeckStorageOpen, tabReplaysOpen, tabAdminOpen,
|
||||||
tabLogOpen;
|
tabLogOpen;
|
||||||
|
|
@ -233,6 +233,10 @@ public:
|
||||||
{
|
{
|
||||||
return deckPath;
|
return deckPath;
|
||||||
}
|
}
|
||||||
|
QString getFiltersPath() const
|
||||||
|
{
|
||||||
|
return filtersPath;
|
||||||
|
}
|
||||||
QString getReplaysPath() const
|
QString getReplaysPath() const
|
||||||
{
|
{
|
||||||
return replaysPath;
|
return replaysPath;
|
||||||
|
|
@ -754,6 +758,7 @@ public slots:
|
||||||
void setShowTipsOnStartup(bool _showTipsOnStartup);
|
void setShowTipsOnStartup(bool _showTipsOnStartup);
|
||||||
void setSeenTips(const QList<int> &_seenTips);
|
void setSeenTips(const QList<int> &_seenTips);
|
||||||
void setDeckPath(const QString &_deckPath);
|
void setDeckPath(const QString &_deckPath);
|
||||||
|
void setFiltersPath(const QString &_filtersPath);
|
||||||
void setReplaysPath(const QString &_replaysPath);
|
void setReplaysPath(const QString &_replaysPath);
|
||||||
void setThemesPath(const QString &_themesPath);
|
void setThemesPath(const QString &_themesPath);
|
||||||
void setCustomCardDatabasePath(const QString &_customCardDatabasePath);
|
void setCustomCardDatabasePath(const QString &_customCardDatabasePath);
|
||||||
|
|
|
||||||
|
|
@ -106,6 +106,9 @@ void SettingsCache::setSeenTips(const QList<int> & /* _seenTips */)
|
||||||
void SettingsCache::setDeckPath(const QString & /* _deckPath */)
|
void SettingsCache::setDeckPath(const QString & /* _deckPath */)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
void SettingsCache::setFiltersPath(const QString & /*_filtersPath */)
|
||||||
|
{
|
||||||
|
}
|
||||||
void SettingsCache::setReplaysPath(const QString & /* _replaysPath */)
|
void SettingsCache::setReplaysPath(const QString & /* _replaysPath */)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -110,6 +110,9 @@ void SettingsCache::setSeenTips(const QList<int> & /* _seenTips */)
|
||||||
void SettingsCache::setDeckPath(const QString & /* _deckPath */)
|
void SettingsCache::setDeckPath(const QString & /* _deckPath */)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
void SettingsCache::setFiltersPath(const QString & /*_filtersPath */)
|
||||||
|
{
|
||||||
|
}
|
||||||
void SettingsCache::setReplaysPath(const QString & /* _replaysPath */)
|
void SettingsCache::setReplaysPath(const QString & /* _replaysPath */)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue