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 inline int progressMinimum() const;
62 inline int progressMaximum() const;
63 inline int progressValue() const;
64 inline QString progressText() const;
67 bool connectToCore(AccountId = 0);
68 void reconnectToCore();
69 void disconnectFromCore();
71 // void useInternalCore();
74 void stateChanged(CoreConnection::ConnectionState);
77 void connectionError(const QString &errorMsg);
78 void connectionWarnings(const QStringList &warnings);
79 void connectionMsg(const QString &msg);
82 void progressRangeChanged(int minimum, int maximum);
83 void progressValueChanged(int value);
84 void progressTextChanged(const QString &);
86 void startCoreSetup(const QVariantList &);
87 void startInternalCore();
88 void connectToInternalCore(SignalProxy *proxy);
90 // This signal MUST be handled synchronously!
91 void userAuthenticationRequired(CoreAccount *, bool *valid, const QString &errorMessage = QString());
93 void handleIgnoreWarnings(bool permanently);
96 void connectToCurrentAccount();
98 void socketStateChanged(QAbstractSocket::SocketState);
99 void coreSocketError(QAbstractSocket::SocketError);
101 void coreSocketConnected();
102 void coreSocketDisconnected();
104 void clientInitAck(const QVariantMap &msg);
107 void networkInitDone();
108 void checkSyncState();
110 void syncToCore(const QVariantMap &sessionState);
111 void internalSessionStateReceived(const QVariant &packedState);
112 void sessionStateReceived(const QVariantMap &state);
114 void setWarningsHandler(const char *slot);
115 void resetWarningsHandler();
116 void resetConnection();
117 void connectionReady();
118 //void doCoreSetup(const QVariant &setupData);
120 void loginToCore(const QString &previousError = QString());
122 void loginFailed(const QString &errorMessage);
124 void updateProgress(int value, int maximum);
125 void setProgressText(const QString &text);
126 void setProgressValue(int value);
127 void setProgressMinimum(int minimum);
128 void setProgressMaximum(int maximum);
130 void setState(QAbstractSocket::SocketState socketState);
131 void setState(ConnectionState state);
134 CoreAccountModel *_model;
135 CoreAccount _account;
136 QVariantMap _coreMsgBuffer;
138 QPointer<QIODevice> _socket;
140 ConnectionState _state;
142 QSet<Network *> _netsToSync;
144 int _progressMinimum, _progressMaximum, _progressValue;
145 QString _progressText;
147 QString _coreInfoString(const QVariantMap &);
149 inline CoreAccountModel *accountModel() const;
152 Q_DECLARE_METATYPE(CoreConnection::ConnectionState)
155 int CoreConnection::progressMinimum() const { return _progressMinimum; }
156 int CoreConnection::progressMaximum() const { return _progressMaximum; }
157 int CoreConnection::progressValue() const { return _progressValue; }
158 QString CoreConnection::progressText() const { return _progressText; }
160 CoreConnection::ConnectionState CoreConnection::state() const { return _state; }
161 bool CoreConnection::isConnected() const { return state() >= Connected; }
162 CoreAccount CoreConnection::currentAccount() const { return _account; }
163 CoreAccountModel *CoreConnection::accountModel() const { return _model; }