1 /***************************************************************************
2 * Copyright (C) 2005-2018 by the Quassel Project *
3 * devel@quassel-irc.org *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) version 3. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
23 #include <QNetworkConfigurationManager>
28 # include <QSslSocket>
30 # include <QTcpSocket>
33 #include "coreaccount.h"
34 #include "remotepeer.h"
37 class ClientAuthHandler;
38 class CoreAccountModel;
44 class CoreConnection : public QObject
49 enum ConnectionState {
57 CoreConnection(QObject *parent = 0);
61 bool isConnected() const;
62 ConnectionState state() const;
63 CoreAccount currentAccount() const;
65 bool isEncrypted() const;
66 bool isLocalConnection() const;
68 int progressMinimum() const;
69 int progressMaximum() const;
70 int progressValue() const;
71 QString progressText() const;
73 //! Check if we consider the last connect as reconnect
74 bool wasReconnect() const { return _wasReconnect; }
76 QPointer<Peer> peer() const;
79 bool connectToCore(AccountId = 0);
80 void reconnectToCore();
81 void disconnectFromCore();
83 void setupCore(const Protocol::SetupData &setupData);
86 void stateChanged(CoreConnection::ConnectionState);
87 void encrypted(bool isEncrypted = true);
89 void lagUpdated(int msecs);
91 void connectionError(const QString &errorMsg);
92 void connectionErrorPopup(const QString &errorMsg);
93 void connectionMsg(const QString &msg);
96 void progressRangeChanged(int minimum, int maximum);
97 void progressValueChanged(int value);
98 void progressTextChanged(const QString &);
100 void startCoreSetup(const QVariantList &backendInfo, const QVariantList &authenticatorInfo);
101 void coreSetupSuccess();
102 void coreSetupFailed(const QString &error);
104 void connectToInternalCore(QPointer<InternalPeer> connection);
106 // These signals MUST be handled synchronously!
107 void userAuthenticationRequired(CoreAccount *, bool *valid, const QString &errorMessage = QString());
108 void handleNoSslInClient(bool *accepted);
109 void handleNoSslInCore(bool *accepted);
111 void handleSslErrors(const QSslSocket *socket, bool *accepted, bool *permanently);
115 void connectToCurrentAccount();
116 void disconnectFromCore(const QString &errorString, bool wantReconnect = true);
118 void coreSocketError(QAbstractSocket::SocketError error, const QString &errorString);
119 void coreSocketDisconnected();
122 void networkInitDone();
123 void checkSyncState();
125 void loginToCore(const QString &user, const QString &password, bool remember); // for config wizard
126 void syncToCore(const Protocol::SessionState &sessionState);
127 void internalSessionStateReceived(const Protocol::SessionState &sessionState);
129 void resetConnection(bool wantReconnect = false);
131 void onConnectionReady();
132 void onLoginSuccessful(const CoreAccount &account);
133 void onHandshakeComplete(RemotePeer *peer, const Protocol::SessionState &sessionState);
135 void updateProgress(int value, int maximum);
136 void setProgressText(const QString &text);
137 void setProgressValue(int value);
138 void setProgressMinimum(int minimum);
139 void setProgressMaximum(int maximum);
141 void setState(ConnectionState state);
143 void networkDetectionModeChanged(const QVariant &mode);
144 void pingTimeoutIntervalChanged(const QVariant &interval);
145 void reconnectIntervalChanged(const QVariant &interval);
146 void reconnectTimeout();
148 void onlineStateChanged(bool isOnline);
151 QPointer<ClientAuthHandler> _authHandler;
152 QPointer<Peer> _peer;
153 ConnectionState _state;
155 QTimer _reconnectTimer;
159 QSet<QObject *> _netsToSync;
161 int _progressMinimum, _progressMaximum, _progressValue;
162 QString _progressText;
166 CoreAccount _account;
167 CoreAccountModel *accountModel() const;
169 QPointer<QNetworkConfigurationManager> _qNetworkConfigurationManager;
171 friend class CoreConfigWizard;
175 Q_DECLARE_METATYPE(CoreConnection::ConnectionState)
178 inline int CoreConnection::progressMinimum() const { return _progressMinimum; }
179 inline int CoreConnection::progressMaximum() const { return _progressMaximum; }
180 inline int CoreConnection::progressValue() const { return _progressValue; }
181 inline QString CoreConnection::progressText() const { return _progressText; }
183 inline CoreConnection::ConnectionState CoreConnection::state() const { return _state; }
184 inline bool CoreConnection::isConnected() const { return state() >= Connected; }
185 inline CoreAccount CoreConnection::currentAccount() const { return _account; }