Move settings into a separate JSON file.

This will unfortunately mean losing your commands, but they can be restored by
converting the old commands.txt format into the commands.json file

Fix #372
This commit is contained in:
Rasmus Karlsson
2018-11-03 13:37:09 +01:00
parent 221ec4f1e8
commit a4fd7b5366
5 changed files with 110 additions and 64 deletions
+15 -8
View File
@@ -1,14 +1,16 @@
#pragma once
#include "common/ChatterinoSetting.hpp"
#include "common/SignalVector.hpp"
#include "common/Singleton.hpp"
#include "controllers/commands/Command.hpp"
#include <QMap>
#include <pajlada/settings.hpp>
#include <memory>
#include <mutex>
#include "common/SignalVector.hpp"
#include "controllers/commands/Command.hpp"
namespace chatterino {
class Settings;
@@ -20,26 +22,31 @@ class CommandModel;
class CommandController final : public Singleton
{
public:
CommandController();
UnsortedSignalVector<Command> items_;
QString execCommand(const QString &text, std::shared_ptr<Channel> channel,
bool dryRun);
QStringList getDefaultTwitchCommandList();
virtual void initialize(Settings &settings, Paths &paths) override;
virtual void initialize(Settings &, Paths &paths) override;
virtual void save() override;
CommandModel *createModel(QObject *parent);
UnsortedSignalVector<Command> items;
private:
void load(Paths &paths);
QMap<QString, Command> commandsMap_;
std::mutex mutex_;
QString filePath_;
std::shared_ptr<pajlada::Settings::SettingManager> sm_;
// Because the setting manager is not initialized until the initialize
// function is called (and not in the constructor), we have to
// late-initialize the setting, which is why we're storing it as a
// unique_ptr
std::unique_ptr<pajlada::Settings::Setting<std::vector<Command>>>
commandsSetting_;
QString execCustomCommand(const QStringList &words, const Command &command);
};