1 /***************************************************************************
2 * Copyright (C) 2009 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 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
21 #ifndef CORECONNECTION_H_
22 #define CORECONNECTION_H_
24 // TODO: support system application proxy (new in Qt 4.6)
29 # include <QSslSocket>
31 # include <QTcpSocket>
34 #include "coreaccount.h"
37 class CoreAccountModel;
41 class CoreConnection : public QObject {
45 enum ConnectionState {
53 CoreConnection(CoreAccountModel *model, QObject *parent = 0);
57 inline ConnectionState state() const;
58 inline bool isConnected() const;
59 inline CoreAccount currentAccount() const;
61 bool isEncrypted() const;
63 inline int progressMinimum() const;
64 inline int progressMaximum() const;
65 inline int progressValue() const;
66 inline QString progressText() const;
69 inline const QSslSocket *sslSocket() const;
73 bool connectToCore(AccountId = 0);
74 void reconnectToCore();
75 void disconnectFromCore(const QString &errorString = QString());
78 void stateChanged(CoreConnection::ConnectionState);
79 void encrypted(bool isEncrypted = true);
82 void connectionError(const QString &errorMsg);
83 void connectionErrorPopup(const QString &errorMsg);
84 void connectionWarnings(const QStringList &warnings);
85 void connectionMsg(const QString &msg);
88 void progressRangeChanged(int minimum, int maximum);
89 void progressValueChanged(int value);
90 void progressTextChanged(const QString &);
92 void startCoreSetup(const QVariantList &);
93 void coreSetupSuccess();
94 void coreSetupFailed(const QString &error);
96 void startInternalCore();
97 void connectToInternalCore(SignalProxy *proxy);
99 // These signals MUST be handled synchronously!
100 void userAuthenticationRequired(CoreAccount *, bool *valid, const QString &errorMessage = QString());
101 void handleNoSslInClient(bool *accepted);
102 void handleNoSslInCore(bool *accepted);
104 void handleSslErrors(const QSslSocket *socket, bool *accepted, bool *permanently);
108 void connectToCurrentAccount();
110 void socketStateChanged(QAbstractSocket::SocketState);
111 void coreSocketError(QAbstractSocket::SocketError);
113 void coreSocketConnected();
114 void coreSocketDisconnected();
116 void clientInitAck(const QVariantMap &msg);
119 void networkInitDone();
120 void checkSyncState();
122 void syncToCore(const QVariantMap &sessionState);
123 void internalSessionStateReceived(const QVariant &packedState);
124 void sessionStateReceived(const QVariantMap &state);
126 void resetConnection();
127 void connectionReady();
129 void loginToCore(const QString &user, const QString &password, bool remember); // for config wizard
130 void loginToCore(const QString &previousError = QString());
132 void loginFailed(const QString &errorMessage);
134 void doCoreSetup(const QVariant &setupData);
136 void updateProgress(int value, int maximum);
137 void setProgressText(const QString &text);
138 void setProgressValue(int value);
139 void setProgressMinimum(int minimum);
140 void setProgressMaximum(int maximum);
142 void setState(QAbstractSocket::SocketState socketState);
143 void setState(ConnectionState state);
146 void sslSocketEncrypted();
151 CoreAccountModel *_model;
152 CoreAccount _account;
153 QVariantMap _coreMsgBuffer;
155 QPointer<QIODevice> _socket;
157 ConnectionState _state;
159 QSet<Network *> _netsToSync;
161 int _progressMinimum, _progressMaximum, _progressValue;
162 QString _progressText;
164 QString _coreInfoString(const QVariantMap &);
166 inline CoreAccountModel *accountModel() const;
168 friend class CoreConfigWizard;
171 Q_DECLARE_METATYPE(CoreConnection::ConnectionState)
174 int CoreConnection::progressMinimum() const { return _progressMinimum; }
175 int CoreConnection::progressMaximum() const { return _progressMaximum; }
176 int CoreConnection::progressValue() const { return _progressValue; }
177 QString CoreConnection::progressText() const { return _progressText; }
179 CoreConnection::ConnectionState CoreConnection::state() const { return _state; }
180 bool CoreConnection::isConnected() const { return state() >= Connected; }
181 CoreAccount CoreConnection::currentAccount() const { return _account; }
182 CoreAccountModel *CoreConnection::accountModel() const { return _model; }
185 const QSslSocket *CoreConnection::sslSocket() const { return qobject_cast<QSslSocket *>(_socket); }