mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-13 05:20:00 -08:00
[Settings] Store server profiles with QSettings arrays (#7629)
The server list used hand-numbered saveName%1/server%1 keys and an O(n) shift loop to delete entries. Store the profiles with beginReadArray and beginWriteArray instead, and migrate the legacy keys once in the constructor so existing profiles and saved passwords survive. SettingsManager::batchWrite no longer disables atomic sync, so a batch is still written through QSettings' atomic save. Add tests for add, update, remove, password updates and the legacy migration. Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
parent
b37c8b828f
commit
5134e72eb4
9 changed files with 566 additions and 209 deletions
|
|
@ -9,9 +9,11 @@
|
|||
|
||||
#include "settings_manager.h"
|
||||
|
||||
#include <QList>
|
||||
#include <QLoggingCategory>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <optional>
|
||||
#include <qtmetamacros.h>
|
||||
|
||||
class QObject;
|
||||
|
|
@ -27,6 +29,22 @@ class ServersSettings : public SettingsManager
|
|||
friend class SettingsCache;
|
||||
|
||||
public:
|
||||
struct ServerEntry
|
||||
{
|
||||
QString saveName;
|
||||
QString host;
|
||||
QString port;
|
||||
QString username;
|
||||
QString password;
|
||||
bool savePassword = false;
|
||||
QString site;
|
||||
};
|
||||
|
||||
explicit ServersSettings(const QString &settingPath, QObject *parent = nullptr);
|
||||
|
||||
QList<ServerEntry> getServers() const;
|
||||
std::optional<ServerEntry> getServer(int index) const;
|
||||
|
||||
int getPreviousHostLogin() const;
|
||||
int getPrevioushostindex(const QString &) const;
|
||||
QStringList getPreviousHostList() const;
|
||||
|
|
@ -88,8 +106,11 @@ public:
|
|||
bool getClearDebugLogStatus(bool abDefaultValue) const;
|
||||
|
||||
private:
|
||||
explicit ServersSettings(const QString &settingPath, QObject *parent = nullptr);
|
||||
ServersSettings(const ServersSettings & /*other*/);
|
||||
|
||||
QList<ServerEntry> loadServers() const;
|
||||
void storeServers(const QList<ServerEntry> &servers);
|
||||
void migrateLegacyServers();
|
||||
};
|
||||
|
||||
#endif // SERVERSSETTINGS_H
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue