mirror-chatterino2/src/controllers/commands/CommandController.hpp

55 lines
1.4 KiB
C++
Raw Normal View History

#pragma once
#include "common/ChatterinoSetting.hpp"
#include "common/SignalVector.hpp"
2018-07-07 11:41:01 +02:00
#include "common/Singleton.hpp"
#include "controllers/commands/Command.hpp"
2018-07-07 11:41:01 +02:00
#include <QMap>
#include <pajlada/settings.hpp>
#include <memory>
2018-06-05 18:51:14 +02:00
#include <mutex>
namespace chatterino {
2018-08-02 14:23:27 +02:00
class Settings;
class Paths;
class Channel;
class CommandModel;
2018-08-02 14:23:27 +02:00
class CommandController final : public Singleton
{
public:
UnsortedSignalVector<Command> items_;
2018-08-06 21:17:03 +02:00
QString execCommand(const QString &text, std::shared_ptr<Channel> channel,
bool dryRun);
QStringList getDefaultTwitchCommandList();
virtual void initialize(Settings &, Paths &paths) override;
2018-07-07 11:41:01 +02:00
virtual void save() override;
CommandModel *createModel(QObject *parent);
private:
2018-08-02 14:23:27 +02:00
void load(Paths &paths);
2018-07-07 11:41:01 +02:00
QMap<QString, Command> commandsMap_;
std::mutex mutex_;
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);
};
} // namespace chatterino