1 /***************************************************************************
2 * Copyright (C) 2005-2014 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 ***************************************************************************/
21 #ifndef CORECONNECTION_H_
22 #define CORECONNECTION_H_
28 # include <QSslSocket>
30 # include <QTcpSocket>
34 # include <Solid/Networking>
37 #include "coreaccount.h"
38 #include "remotepeer.h"
41 class ClientAuthHandler;
42 class CoreAccountModel;
48 class CoreConnection : public QObject
53 enum ConnectionState {
61 CoreConnection(QObject *parent = 0);
65 bool isConnected() const;
66 ConnectionState state() const;
67 CoreAccount currentAccount() const;
69 bool isEncrypted() const;
70 bool isLocalConnection() const;
72 int progressMinimum() const;
73 int progressMaximum() const;
74 int progressValue() const;
75 QString progressText() const;
77 //! Check if we consider the last connect as reconnect
78 bool wasReconnect() const { return _wasReconnect; }
81 bool connectToCore(AccountId = 0);
82 void reconnectToCore();
83 void disconnectFromCore();
85 void setupCore(const Protocol::SetupData &setupData);
88 void stateChanged(CoreConnection::ConnectionState);
89 void encrypted(bool isEncrypted = true);
91 void lagUpdated(int msecs);
93 void connectionError(const QString &errorMsg);
94 void connectionErrorPopup(const QString &errorMsg);
95 void connectionMsg(const QString &msg);
98 void progressRangeChanged(int minimum, int maximum);
99 void progressValueChanged(int value);
100 void progressTextChanged(const QString &);
102 void startCoreSetup(const QVariantList &backendInfo);
103 void coreSetupSuccess();
104 void coreSetupFailed(const QString &error);
106 void startInternalCore();
107 void connectToInternalCore(InternalPeer *connection);
109 // These signals MUST be handled synchronously!
110 void userAuthenticationRequired(CoreAccount *, bool *valid, const QString &errorMessage = QString());
111 void handleNoSslInClient(bool *accepted);
112 void handleNoSslInCore(bool *accepted);
114 void handleSslErrors(const QSslSocket *socket, bool *accepted, bool *permanently);
118 void connectToCurrentAccount();
119 void disconnectFromCore(const QString &errorString, bool wantReconnect = true);
121 void coreSocketError(QAbstractSocket::SocketError error, const QString &errorString);
122 void coreSocketDisconnected();
125 void networkInitDone();
126 void checkSyncState();
128 void loginToCore(const QString &user, const QString &password, bool remember); // for config wizard
129 void syncToCore(const Protocol::SessionState &sessionState);
130 void internalSessionStateReceived(const Protocol::SessionState &sessionState);
132 void resetConnection(bool wantReconnect = false);
134 void onConnectionReady();
135 void onLoginSuccessful(const CoreAccount &account);
136 void onHandshakeComplete(RemotePeer *peer, const Protocol::SessionState &sessionState);
138 void updateProgress(int value, int maximum);
139 void setProgressText(const QString &text);
140 void setProgressValue(int value);
141 void setProgressMinimum(int minimum);
142 void setProgressMaximum(int maximum);
144 void setState(ConnectionState state);
146 void networkDetectionModeChanged(const QVariant &mode);
147 void pingTimeoutIntervalChanged(const QVariant &interval);
148 void reconnectIntervalChanged(const QVariant &interval);
149 void reconnectTimeout();
152 void solidNetworkStatusChanged(Solid::Networking::Status status);
156 QPointer<ClientAuthHandler> _authHandler;
157 QPointer<Peer> _peer;
158 ConnectionState _state;
160 QTimer _reconnectTimer;
164 QSet<QObject *> _netsToSync;
166 int _progressMinimum, _progressMaximum, _progressValue;
167 QString _progressText;
171 CoreAccount _account;
172 CoreAccountModel *accountModel() const;
174 friend class CoreConfigWizard;
178 Q_DECLARE_METATYPE(CoreConnection::ConnectionState)
181 inline int CoreConnection::progressMinimum() const { return _progressMinimum; }
182 inline int CoreConnection::progressMaximum() const { return _progressMaximum; }
183 inline int CoreConnection::progressValue() const { return _progressValue; }
184 inline QString CoreConnection::progressText() const { return _progressText; }
186 inline CoreConnection::ConnectionState CoreConnection::state() const { return _state; }
187 inline bool CoreConnection::isConnected() const { return state() >= Connected; }
188 inline CoreAccount CoreConnection::currentAccount() const { return _account; }