Chatterino
Irc2.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <rapidjson/rapidjson.h>
5 
8 
9 class QAbstractTableModel;
10 
11 namespace chatterino {
12 
13 enum class IrcAuthType { Anonymous, Custom, Pass, Sasl };
14 
15 struct IrcServerData {
16  QString host;
17  int port = 6697;
18  bool ssl = true;
19 
20  QString user;
21  QString nick;
22  QString real;
23 
25  void getPassword(QObject *receiver,
26  std::function<void(const QString &)> &&onLoaded) const;
27  void setPassword(const QString &password);
28 
29  QStringList connectCommands;
30 
31  int id;
32 };
33 
34 class Irc
35 {
36 public:
37  Irc();
38 
39  static Irc &instance();
40 
41  static inline void *const noEraseCredentialCaller =
42  reinterpret_cast<void *>(1);
43 
45  QAbstractTableModel *newConnectionModel(QObject *parent);
46 
47  ChannelPtr getOrAddChannel(int serverId, QString name);
48 
49  void save();
50  void load();
51 
52  int uniqueId();
53 
54 private:
55  int currentId_{};
56  bool loaded_{};
57 
58  // Servers have a unique id.
59  // When a server gets changed it gets removed and then added again.
60  // So we store the channels of that server in abandonedChannels_ temporarily.
61  // Or if the server got removed permanently then it's still stored there.
62  std::unordered_map<int, std::unique_ptr<IrcServer>> servers_;
63  std::unordered_map<int, std::vector<std::weak_ptr<Channel>>>
64  abandonedChannels_;
65 };
66 
67 } // namespace chatterino
Definition: SignalVector.hpp:21
QString nick
Definition: Irc2.hpp:21
IrcAuthType
Definition: Irc2.hpp:13
Definition: Irc2.hpp:15
QString user
Definition: Irc2.hpp:20
QString real
Definition: Irc2.hpp:22
QString host
Definition: Irc2.hpp:16
Definition: Application.cpp:48
Definition: Irc2.hpp:34
QStringList connectCommands
Definition: Irc2.hpp:29
int id
Definition: Irc2.hpp:31
SignalVector< IrcServerData > connections
Definition: Irc2.hpp:44
QString name
Definition: Credentials.cpp:94
std::shared_ptr< Channel > ChannelPtr
Definition: Channel.hpp:125
void load(const std::shared_ptr< NetworkData > &data)
Definition: NetworkPrivate.cpp:391