mirror-chatterino2/src/providers/irc/Irc2.hpp

65 lines
1.5 KiB
C++
Raw Normal View History

2019-09-08 18:06:43 +02:00
#pragma once
#include <rapidjson/rapidjson.h>
2019-09-08 18:06:43 +02:00
#include <common/SignalVector.hpp>
#include "providers/irc/IrcChannel2.hpp"
#include "providers/irc/IrcServer.hpp"
2019-09-08 18:06:43 +02:00
class QAbstractTableModel;
namespace chatterino {
//enum IrcAuthType { Anonymous, /*Sals,*/ Pass, MsgNickServ, NickServ };
struct IrcServerData {
2019-09-08 18:06:43 +02:00
QString host;
int port = 6667;
bool ssl = false;
2019-09-08 18:06:43 +02:00
QString user;
QString nick;
QString real;
// IrcAuthType authType = 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();
UnsortedSignalVector<IrcServerData> connections;
2019-09-08 18:06:43 +02:00
QAbstractTableModel *newConnectionModel(QObject *parent);
ChannelPtr getOrAddChannel(int serverId, QString name);
void save();
void load();
int uniqueId();
private:
int currentId_{};
bool loaded_{};
// 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