make use of "use random server to connect"-setting and cycle through available server...
[quassel.git] / src / core / networkconnection.h
index a7aa1fd..649171d 100644 (file)
@@ -43,7 +43,7 @@ class NetworkConnection : public QObject {
   Q_OBJECT
 
 public:
-  NetworkConnection(Network *network, CoreSession *session, const QVariant &previousState = QVariant());
+  NetworkConnection(Network *network, CoreSession *session);
   ~NetworkConnection();
 
   NetworkId networkId() const;
@@ -59,39 +59,47 @@ public:
   UserInputHandler *userInputHandler() const;
   CtcpHandler *ctcpHandler() const;
 
-  //! Return data necessary to restore the connection state upon core restart
-  QVariant state() const;
-
   //! Decode a string using the server (network) decoding.
   QString serverDecode(const QByteArray &string) const;
 
-  //! Decode a string using a buffer-specific encoding if one is set (and use the server encoding else).
-  QString bufferDecode(const QString &bufferName, const QByteArray &string) const;
+  //! Decode a string using a channel-specific encoding if one is set (and use the standard encoding else).
+  QString channelDecode(const QString &channelName, const QByteArray &string) const;
 
-  //! Decode a string using a IrcUser specific encoding, if one exists (using the server encoding else).
+  //! Decode a string using an IrcUser-specific encoding, if one exists (using the standaed encoding else).
   QString userDecode(const QString &userNick, const QByteArray &string) const;
 
   //! Encode a string using the server (network) encoding.
   QByteArray serverEncode(const QString &string) const;
 
-  //! Encode a string using the buffer-specific encoding, if set, and use the server encoding else.
-  QByteArray bufferEncode(const QString &bufferName, const QString &string) const;
+  //! Encode a string using the channel-specific encoding, if set, and use the standard encoding else.
+  QByteArray channelEncode(const QString &channelName, const QString &string) const;
 
-  //! Encode a string using the user-specific encoding, if set, and use the server encoding else.
+  //! Encode a string using the user-specific encoding, if set, and use the standard encoding else.
   QByteArray userEncode(const QString &userNick, const QString &string) const;
 
+  inline QString channelKey(const QString &channel) const { return _channelKeys.value(channel.toLower(), QString()); }
+  inline QStringList persistentChannels() const { return _channelKeys.keys(); }
+
 public slots:
   // void setServerOptions();
-  void connectToIrc();
-  void disconnectFromIrc();
+  void connectToIrc(bool reconnecting = false);
+  void disconnectFromIrc(bool requested = true);
   void userInput(BufferInfo bufferInfo, QString msg);
 
   void putRawLine(QByteArray input);
   void putCmd(const QString &cmd, const QVariantList &params, const QByteArray &prefix = QByteArray());
 
+  void setChannelJoined(const QString &channel);
+  void setChannelParted(const QString &channel);
+  void addChannelKey(const QString &channel, const QString &key);
+  void removeChannelKey(const QString &channel);
 
 private slots:
   void sendPerform();
+  void autoReconnectSettingsChanged();
+  void doAutoReconnect();
+  void sendWho();
+  void nickChanged(const QString &newNick, const QString &oldNick); // this signal is inteded to rename query buffers in the storage backend
 
 signals:
   // #void networkState(QString net, QVariantMap data);
@@ -105,8 +113,12 @@ signals:
   void connectionInitialized(); ///< Emitted after receipt of 001 to indicate that we can now send data to the IRC server
   void connectionError(const QString &errorMsg);
 
-  //void queryRequested(QString network, QString nick);
+  void quitRequested(NetworkId networkId);
 
+  //void queryRequested(QString network, QString nick);
+  void nickChanged(const NetworkId &networkId, const QString &newNick, const QString &oldNick); // this signal is inteded to rename query buffers in the storage backend
+  void channelJoined(NetworkId, const QString &channel, const QString &key = QString());
+  void channelParted(NetworkId, const QString &channel);
 
 private slots:
   void socketHasData();
@@ -123,13 +135,22 @@ private:
 
   Network *_network;
   CoreSession *_coreSession;
+  BufferInfo _statusBufferInfo;
 
   IrcServerHandler *_ircServerHandler;
   UserInputHandler *_userInputHandler;
   CtcpHandler *_ctcpHandler;
 
-  QVariant _previousState;
+  QHash<QString, QString> _channelKeys;  // stores persistent channels and their passwords, if any
+
+  QTimer _autoReconnectTimer;
+  int _autoReconnectCount;
+
+  QTimer _whoTimer;
 
+  bool _previousConnectionAttemptFailed;
+  int _lastUsedServerlistIndex;
+  
   class ParseError : public Exception {
   public:
     ParseError(QString cmd, QString prefix, QStringList params);
@@ -139,7 +160,6 @@ private:
   public:
     UnknownCmdError(QString cmd, QString prefix, QStringList params);
   };
-    
 };
 
 #endif