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;
40 class CoreConnection : public QObject {
44 enum ConnectionState {
52 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 void connectToCore(AccountId);
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 &);
88 // This signal MUST be handled synchronously!
89 void userAuthenticationRequired(CoreAccount *, const QString &errorMessage = QString());
91 void handleIgnoreWarnings(bool permanently);
94 void socketStateChanged(QAbstractSocket::SocketState);
95 void coreSocketError(QAbstractSocket::SocketError);
97 void coreSocketConnected();
98 void coreSocketDisconnected();
100 void clientInitAck(const QVariantMap &msg);
103 void networkInitDone();
104 void checkSyncState();
106 void syncToCore(const QVariantMap &sessionState);
107 //void internalSessionStateReceived(const QVariant &packedState);
108 void sessionStateReceived(const QVariantMap &state);
110 void setWarningsHandler(const char *slot);
111 void resetWarningsHandler();
112 void resetConnection();
113 void connectionReady();
114 //void doCoreSetup(const QVariant &setupData);
118 void loginFailed(const QString &errorMessage);
120 void updateProgress(int value, int maximum);
121 void setProgressText(const QString &text);
122 void setProgressValue(int value);
123 void setProgressMinimum(int minimum);
124 void setProgressMaximum(int maximum);
126 void setState(QAbstractSocket::SocketState socketState);
127 void setState(ConnectionState state);
130 CoreAccountModel *_model;
131 CoreAccount _account;
132 QVariantMap _coreMsgBuffer;
134 QPointer<QIODevice> _socket;
136 ConnectionState _state;
138 QSet<Network *> _netsToSync;
140 int _progressMinimum, _progressMaximum, _progressValue;
141 QString _progressText;
143 QString _coreInfoString(const QVariantMap &);
145 inline CoreAccountModel *accountModel() const;
148 Q_DECLARE_METATYPE(CoreConnection::ConnectionState)
151 int CoreConnection::progressMinimum() const { return _progressMinimum; }
152 int CoreConnection::progressMaximum() const { return _progressMaximum; }
153 int CoreConnection::progressValue() const { return _progressValue; }
154 QString CoreConnection::progressText() const { return _progressText; }
156 CoreConnection::ConnectionState CoreConnection::state() const { return _state; }
157 bool CoreConnection::isConnected() const { return state() >= Connected; }
158 CoreAccount CoreConnection::currentAccount() const { return _account; }
159 CoreAccountModel *CoreConnection::accountModel() const { return _model; }