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