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);
56 inline ConnectionState state() const;
57 inline bool isConnected() const;
58 inline CoreAccount currentAccount() const;
60 inline int progressMinimum() const;
61 inline int progressMaximum() const;
62 inline int progressValue() const;
63 inline QString progressText() const;
66 bool connectToCore(AccountId = 0);
67 void reconnectToCore();
68 void disconnectFromCore();
70 // void useInternalCore();
73 void stateChanged(CoreConnection::ConnectionState);
76 void connectionError(const QString &errorMsg);
77 void connectionWarnings(const QStringList &warnings);
78 void connectionMsg(const QString &msg);
81 void progressRangeChanged(int minimum, int maximum);
82 void progressValueChanged(int value);
83 void progressTextChanged(const QString &);
85 void startCoreSetup(const QVariantList &);
87 // This signal MUST be handled synchronously!
88 void userAuthenticationRequired(CoreAccount *, const QString &errorMessage = QString());
90 void handleIgnoreWarnings(bool permanently);
93 void connectToCurrentAccount();
95 void socketStateChanged(QAbstractSocket::SocketState);
96 void coreSocketError(QAbstractSocket::SocketError);
98 void coreSocketConnected();
99 void coreSocketDisconnected();
101 void clientInitAck(const QVariantMap &msg);
104 void networkInitDone();
105 void checkSyncState();
107 void syncToCore(const QVariantMap &sessionState);
108 //void internalSessionStateReceived(const QVariant &packedState);
109 void sessionStateReceived(const QVariantMap &state);
111 void setWarningsHandler(const char *slot);
112 void resetWarningsHandler();
113 void resetConnection();
114 void connectionReady();
115 //void doCoreSetup(const QVariant &setupData);
119 void loginFailed(const QString &errorMessage);
121 void updateProgress(int value, int maximum);
122 void setProgressText(const QString &text);
123 void setProgressValue(int value);
124 void setProgressMinimum(int minimum);
125 void setProgressMaximum(int maximum);
127 void setState(QAbstractSocket::SocketState socketState);
128 void setState(ConnectionState state);
131 CoreAccountModel *_model;
132 CoreAccount _account;
133 QVariantMap _coreMsgBuffer;
135 QPointer<QIODevice> _socket;
137 ConnectionState _state;
139 QSet<Network *> _netsToSync;
141 int _progressMinimum, _progressMaximum, _progressValue;
142 QString _progressText;
144 QString _coreInfoString(const QVariantMap &);
146 inline CoreAccountModel *accountModel() const;
149 Q_DECLARE_METATYPE(CoreConnection::ConnectionState)
152 int CoreConnection::progressMinimum() const { return _progressMinimum; }
153 int CoreConnection::progressMaximum() const { return _progressMaximum; }
154 int CoreConnection::progressValue() const { return _progressValue; }
155 QString CoreConnection::progressText() const { return _progressText; }
157 CoreConnection::ConnectionState CoreConnection::state() const { return _state; }
158 bool CoreConnection::isConnected() const { return state() >= Connected; }
159 CoreAccount CoreConnection::currentAccount() const { return _account; }
160 CoreAccountModel *CoreConnection::accountModel() const { return _model; }