aboutsummaryrefslogtreecommitdiff
path: root/launcher/settings
diff options
context:
space:
mode:
authorRachel Powers <508861+Ryex@users.noreply.github.com>2023-02-15 22:01:27 -0700
committerRachel Powers <508861+Ryex@users.noreply.github.com>2023-03-20 14:56:32 -0700
commit1ca2c59f2ed7739b4b7d50c7212e292a4432da93 (patch)
treecaf24466c26cd86ce0f1f0d31cb02c7302fe44a2 /launcher/settings
parent3ec92acfe7a843a34018fc142439888c4ca5dba0 (diff)
downloadPrismLauncher-1ca2c59f2ed7739b4b7d50c7212e292a4432da93.tar.gz
PrismLauncher-1ca2c59f2ed7739b4b7d50c7212e292a4432da93.tar.bz2
PrismLauncher-1ca2c59f2ed7739b4b7d50c7212e292a4432da93.zip
feat: track instance copies that use links
confirm deleations when other instances link to it Signed-off-by: Rachel Powers <508861+Ryex@users.noreply.github.com>
Diffstat (limited to 'launcher/settings')
-rw-r--r--launcher/settings/INIFile.cpp18
-rw-r--r--launcher/settings/INIFile.h35
-rw-r--r--launcher/settings/SettingsObject.cpp13
-rw-r--r--launcher/settings/SettingsObject.h41
4 files changed, 107 insertions, 0 deletions
diff --git a/launcher/settings/INIFile.cpp b/launcher/settings/INIFile.cpp
index 733cd444..e48e6f47 100644
--- a/launcher/settings/INIFile.cpp
+++ b/launcher/settings/INIFile.cpp
@@ -183,3 +183,21 @@ void INIFile::set(QString key, QVariant val)
{
this->operator[](key) = val;
}
+
+void INIFile::setList(QString key, QVariantList val)
+{
+ QString stringList = QJsonDocument(QVariant(val).toJsonArray()).toJson(QJsonDocument::Compact);
+
+ this->operator[](key) = stringList;
+}
+
+QVariantList INIFile::getList(QString key, QVariantList def) const
+{
+ if (this->contains(key)) {
+ auto src = this->operator[](key);
+
+ return QJsonDocument::fromJson(src.toByteArray()).toVariant().toList();
+ }
+
+ return def;
+}
diff --git a/launcher/settings/INIFile.h b/launcher/settings/INIFile.h
index 4313e829..86bf0898 100644
--- a/launcher/settings/INIFile.h
+++ b/launcher/settings/INIFile.h
@@ -19,6 +19,9 @@
#include <QVariant>
#include <QIODevice>
+#include <QJsonDocument>
+#include <QJsonArray>
+
// Sectionless INI parser (for instance config files)
class INIFile : public QMap<QString, QVariant>
{
@@ -33,4 +36,36 @@ public:
void set(QString key, QVariant val);
static QString unescape(QString orig);
static QString escape(QString orig);
+
+ void setList(QString key, QVariantList val);
+ template <typename T> void setList(QString key, QList<T> val)
+ {
+ QVariantList variantList;
+ variantList.reserve(val.size());
+ for (const T& v : val)
+ {
+ variantList.append(v);
+ }
+
+ this->setList(key, variantList);
+ }
+
+ QVariantList getList(QString key, QVariantList def) const;
+ template <typename T> QList<T> getList(QString key, QList<T> def) const
+ {
+ if (this->contains(key)) {
+ QVariant src = this->operator[](key);
+ QVariantList variantList = QJsonDocument::fromJson(src.toByteArray()).toVariant().toList();
+
+ QList<T>TList;
+ TList.reserve(variantList.size());
+ for (const QVariant& v : variantList)
+ {
+ TList.append(v.value<T>());
+ }
+ return TList;
+ }
+
+ return def;
+ }
};
diff --git a/launcher/settings/SettingsObject.cpp b/launcher/settings/SettingsObject.cpp
index 8a0bc045..4c51d6e9 100644
--- a/launcher/settings/SettingsObject.cpp
+++ b/launcher/settings/SettingsObject.cpp
@@ -121,6 +121,19 @@ bool SettingsObject::contains(const QString &id)
return m_settings.contains(id);
}
+bool SettingsObject::setList(const QString &id, QVariantList value)
+{
+ QString stringList = QJsonDocument(QVariant(value).toJsonArray()).toJson(QJsonDocument::Compact);
+
+ return set(id, stringList);
+}
+
+QVariantList SettingsObject::getList(const QString &id)
+{
+ QVariant value = this->get(id);
+ return QJsonDocument::fromJson(value.toByteArray()).toVariant().toList();
+}
+
bool SettingsObject::reload()
{
for (auto setting : m_settings.values())
diff --git a/launcher/settings/SettingsObject.h b/launcher/settings/SettingsObject.h
index 6200bc3a..ff430172 100644
--- a/launcher/settings/SettingsObject.h
+++ b/launcher/settings/SettingsObject.h
@@ -19,6 +19,8 @@
#include <QMap>
#include <QStringList>
#include <QVariant>
+#include <QJsonDocument>
+#include <QJsonArray>
#include <memory>
class Setting;
@@ -143,6 +145,45 @@ public:
bool contains(const QString &id);
/*!
+ * \brief Sets the value of the setting with the given ID with a json list.
+ * If no setting with the given ID exists, returns false
+ * \param id The ID of the setting to change.
+ * \param value The new value of the setting.
+ */
+ bool setList(const QString &id, QVariantList value);
+ template <typename T> bool setList(const QString &id, QList<T> val)
+ {
+ QVariantList variantList;
+ variantList.reserve(val.size());
+ for (const T& v : val)
+ {
+ variantList.append(v);
+ }
+
+ return setList(id, variantList);
+ }
+
+ /**
+ * \brief Gets the value of the setting with the given ID as if it were a json list.
+ * \param id The ID of the setting to change.
+ * \return The setting's value as a QVariantList.
+ * If no setting with the given ID exists, returns an empty QVariantList.
+ */
+ QVariantList getList(const QString &id);
+ template <typename T> QList<T> getList(const QString &id)
+ {
+ QVariantList variantList = this->getList(id);
+
+ QList<T>TList;
+ TList.reserve(variantList.size());
+ for (const QVariant& v : variantList)
+ {
+ TList.append(v.value<T>());
+ }
+ return TList;
+ }
+
+ /*!
* \brief Reloads the settings and emit signals for changed settings
* \return True if reloading was successful
*/