1 /***************************************************************************
2 * Copyright (C) 2005-2020 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 "client-export.h"
25 #include <QNetworkConfigurationManager>
30 #include "coreaccount.h"
31 #include "remotepeer.h"
34 class ClientAuthHandler;
35 class CoreAccountModel;
41 class CLIENT_EXPORT CoreConnection : public QObject
55 CoreConnection(QObject* parent = nullptr);
59 bool isConnected() const;
60 ConnectionState state() const;
61 CoreAccount currentAccount() const;
63 bool isEncrypted() const;
64 bool isLocalConnection() const;
66 int progressMinimum() const;
67 int progressMaximum() const;
68 int progressValue() const;
69 QString progressText() const;
71 //! Check if we consider the last connect as reconnect
72 bool wasReconnect() const { return _wasReconnect; }
74 QPointer<Peer> peer() const;
77 bool connectToCore(AccountId = 0);
78 void reconnectToCore();
79 void disconnectFromCore();
80 void internalSessionStateReceived(const Protocol::SessionState& sessionState);
82 void setupCore(const Protocol::SetupData& setupData);
85 void stateChanged(CoreConnection::ConnectionState);
86 void encrypted(bool isEncrypted = true);
88 void lagUpdated(int msecs);
90 void connectionError(const QString& errorMsg);
91 void connectionErrorPopup(const QString& errorMsg);
92 void connectionMsg(const QString& msg);
95 void progressRangeChanged(int minimum, int maximum);
96 void progressValueChanged(int value);
97 void progressTextChanged(const QString&);
99 void startCoreSetup(const QVariantList& backendInfo, const QVariantList& authenticatorInfo);
100 void coreSetupSuccess();
101 void coreSetupFailed(const QString& error);
103 void connectToInternalCore(QPointer<InternalPeer> connection);
105 // These signals MUST be handled synchronously!
106 void userAuthenticationRequired(CoreAccount*, bool* valid, const QString& errorMessage = QString());
107 void handleNoSslInClient(bool* accepted);
108 void handleNoSslInCore(bool* accepted);
109 void handleSslErrors(const QSslSocket* socket, bool* accepted, bool* permanently);
112 void connectToCurrentAccount();
113 void disconnectFromCore(const QString& errorString, bool wantReconnect = true);
115 void coreSocketError(QAbstractSocket::SocketError error, const QString& errorString);
116 void coreSocketDisconnected();
119 void networkInitDone();
120 void checkSyncState();
122 void loginToCore(const QString& user, const QString& password, bool remember); // for config wizard
123 void syncToCore(const Protocol::SessionState& sessionState);
125 void resetConnection(bool wantReconnect = false);
127 void onConnectionReady();
128 void onLoginSuccessful(const CoreAccount& account);
129 void onHandshakeComplete(RemotePeer* peer, const Protocol::SessionState& sessionState);
131 void updateProgress(int value, int maximum);
132 void setProgressText(const QString& text);
133 void setProgressValue(int value);
134 void setProgressMinimum(int minimum);
135 void setProgressMaximum(int maximum);
137 void setState(ConnectionState state);
139 void networkDetectionModeChanged(const QVariant& mode);
140 void pingTimeoutIntervalChanged(const QVariant& interval);
141 void reconnectIntervalChanged(const QVariant& interval);
142 void reconnectTimeout();
144 void onlineStateChanged(bool isOnline);
147 QPointer<ClientAuthHandler> _authHandler;
148 QPointer<Peer> _peer;
149 ConnectionState _state{Disconnected};
151 QTimer _reconnectTimer;
152 bool _wantReconnect{false};
153 bool _wasReconnect{false};
155 QSet<QObject*> _netsToSync;
157 int _progressMinimum{0}, _progressMaximum{-1}, _progressValue{-1};
158 QString _progressText;
160 bool _resetting{false};
162 CoreAccount _account;
163 CoreAccountModel* accountModel() const;
165 QPointer<QNetworkConfigurationManager> _qNetworkConfigurationManager;
167 friend class CoreConfigWizard;
170 Q_DECLARE_METATYPE(CoreConnection::ConnectionState)
173 inline int CoreConnection::progressMinimum() const
175 return _progressMinimum;
177 inline int CoreConnection::progressMaximum() const
179 return _progressMaximum;
181 inline int CoreConnection::progressValue() const
183 return _progressValue;
185 inline QString CoreConnection::progressText() const
187 return _progressText;
190 inline CoreConnection::ConnectionState CoreConnection::state() const
194 inline bool CoreConnection::isConnected() const
196 return state() >= Connected;
198 inline CoreAccount CoreConnection::currentAccount() const