2019-09-08 18:06:43 +02:00
|
|
|
#pragma once
|
|
|
|
|
2019-09-09 22:26:14 +02:00
|
|
|
#include <rapidjson/rapidjson.h>
|
2019-09-08 18:06:43 +02:00
|
|
|
#include <common/SignalVector.hpp>
|
|
|
|
|
2019-09-09 22:26:14 +02:00
|
|
|
#include "providers/irc/IrcChannel2.hpp"
|
|
|
|
#include "providers/irc/IrcServer.hpp"
|
|
|
|
|
2019-09-08 18:06:43 +02:00
|
|
|
class QAbstractTableModel;
|
|
|
|
|
|
|
|
namespace chatterino {
|
|
|
|
|
2019-09-15 13:15:29 +02:00
|
|
|
enum class IrcAuthType { Anonymous, Custom, Pass, Sasl };
|
2019-09-10 23:55:43 +02:00
|
|
|
|
2019-09-11 13:51:48 +02:00
|
|
|
struct IrcServerData {
|
2019-09-08 18:06:43 +02:00
|
|
|
QString host;
|
2019-09-15 11:36:59 +02:00
|
|
|
int port = 6697;
|
|
|
|
bool ssl = true;
|
2019-09-08 18:06:43 +02:00
|
|
|
|
|
|
|
QString user;
|
|
|
|
QString nick;
|
2019-09-10 14:46:43 +02:00
|
|
|
QString real;
|
|
|
|
|
2019-09-15 11:35:17 +02:00
|
|
|
IrcAuthType authType = IrcAuthType::Anonymous;
|
2019-09-14 20:45:01 +02:00
|
|
|
void getPassword(QObject *receiver,
|
|
|
|
std::function<void(const QString &)> &&onLoaded) const;
|
|
|
|
void setPassword(const QString &password);
|
|
|
|
|
2019-09-14 18:38:09 +02:00
|
|
|
QStringList connectCommands;
|
2019-09-08 18:06:43 +02:00
|
|
|
|
|
|
|
int id;
|
|
|
|
};
|
|
|
|
|
|
|
|
class Irc
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Irc();
|
|
|
|
|
|
|
|
static Irc &getInstance();
|
|
|
|
|
2019-09-14 22:58:53 +02:00
|
|
|
static inline void *const noEraseCredentialCaller =
|
|
|
|
reinterpret_cast<void *>(1);
|
|
|
|
|
2019-09-11 13:51:48 +02:00
|
|
|
UnsortedSignalVector<IrcServerData> connections;
|
2019-09-08 18:06:43 +02:00
|
|
|
QAbstractTableModel *newConnectionModel(QObject *parent);
|
|
|
|
|
2019-09-09 22:26:14 +02:00
|
|
|
ChannelPtr getOrAddChannel(int serverId, QString name);
|
|
|
|
|
2019-09-10 23:55:43 +02:00
|
|
|
void save();
|
|
|
|
void load();
|
|
|
|
|
|
|
|
int uniqueId();
|
|
|
|
|
2019-09-09 22:26:14 +02:00
|
|
|
private:
|
2019-09-10 23:55:43 +02:00
|
|
|
int currentId_{};
|
|
|
|
bool loaded_{};
|
|
|
|
|
2019-09-09 22:26:14 +02:00
|
|
|
// Servers have a unique id.
|
|
|
|
// When a server gets changed it gets removed and then added again.
|
|
|
|
// So we store the channels of that server in abandonedChannels_ temporarily.
|
|
|
|
// Or if the server got removed permanently then it's still stored there.
|
|
|
|
std::unordered_map<int, std::unique_ptr<IrcServer>> servers_;
|
|
|
|
std::unordered_map<int, std::vector<std::weak_ptr<Channel>>>
|
|
|
|
abandonedChannels_;
|
2019-09-08 18:06:43 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace chatterino
|