Controller.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*
  2. * Controller.h
  3. * nirc
  4. *
  5. * Created by Niklas Bölter on 03.02.10.
  6. * Copyright 2010 Frubar Corporation.
  7. *
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. *
  15. *
  16. */
  17. #ifndef NIRC_PARSER_H
  18. #define NIRC_PARSER_H
  19. #include <QDir>
  20. #include <QObject>
  21. #include <QString>
  22. #include <QStringList>
  23. #include <QHash>
  24. #include <QTextDocument>
  25. #include <QMetaObject>
  26. #include <QSound>
  27. #include <QDateTime>
  28. #include "MainWindow.h"
  29. #include "Connection.h"
  30. #include "Numerics.h"
  31. #include "UserLists.h"
  32. struct TabRef
  33. {
  34. int cid;
  35. QString identifier;
  36. QString name;
  37. };
  38. struct Prefix
  39. {
  40. bool isServer;
  41. QString nickname; // When isServer is true, this is the prefix and the rest is null
  42. QString username;
  43. QString hostname;
  44. };
  45. Q_DECLARE_METATYPE(Prefix);
  46. class Controller : public QObject
  47. {
  48. Q_OBJECT
  49. public:
  50. Controller(MainWindow *mw);
  51. void setup();
  52. signals:
  53. void gotJoin(int cid, QStringList params, Prefix prefix);
  54. void gotPart(int cid, QStringList params, Prefix prefix);
  55. void gotQuit(int cid, QStringList params, Prefix prefix);
  56. void gotKick(int cid, QStringList params, Prefix prefix);
  57. void gotPrivmsg(int cid, QStringList params, Prefix prefix);
  58. void gotPing(int cid, QStringList params, Prefix prefix);
  59. void gotNick(int cid, QStringList params, Prefix prefix);
  60. void gotNotice(int cid, QStringList params, Prefix prefix);
  61. void gotMode(int cid, QStringList params, Prefix prefix);
  62. void got001(int cid, QStringList params, Prefix prefix);
  63. void got002(int cid, QStringList params, Prefix prefix);
  64. void got003(int cid, QStringList params, Prefix prefix);
  65. void got004(int cid, QStringList params, Prefix prefix);
  66. void got005(int cid, QStringList params, Prefix prefix);
  67. void got332(int cid, QStringList params, Prefix prefix);
  68. void got353(int cid, QStringList params, Prefix prefix);
  69. void got366(int cid, QStringList params, Prefix prefix);
  70. private:
  71. // We control all connections and the main window
  72. MainWindow *mw;
  73. QList<Connection *> connections;
  74. // Settings
  75. QSettings settings;
  76. QList<ConnectionSettings> connectionsettings;
  77. // Content of Tabs, Channel User Lists
  78. QHash<QString, QTextCursor *> tabs;
  79. UserLists *userlists;
  80. QHash<QString, QString> titlebars;
  81. // List of Connections, each having a channel name hash which points to a hash of nickname -> NamesEntry
  82. // My own nicks
  83. QHash<int, QString> mynicks;
  84. // Helper Stuff for Parsing
  85. QList<bool> registered;
  86. QSet<QString> namreply; // This tells us that a NAMREPLY is currently active for that channel, removed when we receive an ENDOFNAMES
  87. bool isServer(QString prefix);
  88. void parseISupportPrefix(int cid, QString prefix);
  89. void parseISupportChanmodes(int cid, QString prefix);
  90. void parseChannelModes(int cid, QStringList params);
  91. void parseUserModes(int cid, QStringList params);
  92. QList<QHash<QChar, QChar> > support_prefix; // ISUPPORT PREFIX argument
  93. QList<QHash<QChar, QChar> > support_prefix_reverse;
  94. QList<QList<QChar> > support_prefix_order;
  95. QList<QStringList> support_chanmodes; // ISUPPORT CHANMODES argument
  96. QList<QSet<QString> > channels;
  97. // User Input Parsing stuff
  98. void parseInputCommand(QString line);
  99. // Tab Stuff
  100. TabRef tab; // Stores the currently viewed tab - probably move to MainWindow :?
  101. void addTab(QString key, quint16 maximumBlockCount);
  102. void renameTab(int cid, QString oldName, QString newName);
  103. void delTab(QString key);
  104. QTextCursor* getTab(int cid); // getTab() returns 0 when there is no matching tab(!)
  105. QTextCursor* getTab(int cid, QString name); // getTab() returns 0 when there is no matching tab(!)
  106. QTextCursor* getTab(QString identifier); // getTab() returns 0 when there is no matching tab(!)
  107. void updateChannelList();
  108. void updateTitleBar();
  109. // Content Stuff
  110. void addLine(QTextCursor *cursor, QString line);
  111. void replaceHTML(QString & line);
  112. // Connection Stuff
  113. void openConnections();
  114. void sendLine(int cid, QString line);
  115. private slots:
  116. void parse(int cid, QString line);
  117. void readInput(QString line);
  118. void connected(int cid);
  119. void disconnected(int cid);
  120. void socketmessage(int cid, QString message);
  121. void tabChanged(QString identifier);
  122. void dataReady(int cid);
  123. /* move these out later */
  124. void handleJoin(int cid, QStringList params, Prefix prefix);
  125. void handlePart(int cid, QStringList params, Prefix prefix);
  126. void handleQuit(int cid, QStringList params, Prefix prefix);
  127. void handleKick(int cid, QStringList params, Prefix prefix);
  128. void handlePrivmsg(int cid, QStringList params, Prefix prefix);
  129. void handlePing(int cid, QStringList params, Prefix prefix);
  130. void handleNick(int cid, QStringList params, Prefix prefix);
  131. void handleNotice(int cid, QStringList params, Prefix prefix);
  132. void handleMode(int cid, QStringList params, Prefix prefix);
  133. void handle001(int cid, QStringList params, Prefix prefix);
  134. void handle002(int cid, QStringList params, Prefix prefix);
  135. void handle003(int cid, QStringList params, Prefix prefix);
  136. void handle004(int cid, QStringList params, Prefix prefix);
  137. void handle005(int cid, QStringList params, Prefix prefix);
  138. void handle332(int cid, QStringList params, Prefix prefix);
  139. void handle353(int cid, QStringList params, Prefix prefix);
  140. void handle366(int cid, QStringList params, Prefix prefix);
  141. };
  142. #endif