Client::Client(QObject *parent)
: QObject(parent),
- socket(0),
_signalProxy(new SignalProxy(SignalProxy::Client, this)),
mainUi(0),
_networkModel(0),
p->attachSlot(SIGNAL(networkCreated(NetworkId)), this, SLOT(coreNetworkCreated(NetworkId)));
p->attachSlot(SIGNAL(networkRemoved(NetworkId)), this, SLOT(coreNetworkRemoved(NetworkId)));
- connect(p, SIGNAL(disconnected()), this, SLOT(disconnectFromCore()));
+ connect(p, SIGNAL(disconnected()), this, SLOT(disconnectedFromCore()));
//connect(mainUi, SIGNAL(connectToCore(const QVariantMap &)), this, SLOT(connectToCore(const QVariantMap &)));
connect(mainUi, SIGNAL(disconnectFromCore()), this, SLOT(disconnectFromCore()));
/*** core connection stuff ***/
-void Client::setConnectedToCore(QIODevice *sock, AccountId id) {
- socket = sock;
+void Client::setConnectedToCore(QIODevice *socket, AccountId id) {
+ // if the socket is an orphan, the signalProxy adopts it.
+ // -> we don't need to care about it anymore
+ socket->setParent(0);
signalProxy()->addPeer(socket);
_connectedToCore = true;
setCurrentCoreAccount(id);
}
+void Client::setConnectedToInternalCore() {
+ _connectedToCore = true;
+ setCurrentCoreAccount(AccountId());
+}
+
void Client::setSyncedToCore() {
// create buffersyncer
Q_ASSERT(!_bufferSyncer);
void Client::disconnectFromCore() {
if(!isConnected())
return;
- _connectedToCore = false;
- if(socket) {
- socket->close();
- socket->deleteLater();
- }
+ signalProxy()->removeAllPeers();
+}
+
+void Client::disconnectedFromCore() {
+ _connectedToCore = false;
_syncedToCore = false;
emit disconnected();
emit coreConnectionStateChanged(false);
}
-void Client::setCoreConfiguration(const QVariantMap &settings) {
- SignalProxy::writeDataToDevice(socket, settings);
-}
-
/*** ***/
void Client::networkDestroyed() {
void disconnectFromCore();
- void setCoreConfiguration(const QVariantMap &settings);
-
void bufferRemoved(BufferId bufferId);
void bufferRenamed(BufferId bufferId, const QString &newName);
private slots:
- //void coreSocketError(QAbstractSocket::SocketError);
-
- //void networkConnected(NetworkId);
- //void networkDisconnected(NetworkId);
+ void disconnectedFromCore();
void recvMessage(const Message &message);
void recvStatusMsg(QString network, QString message);
void coreNetworkRemoved(NetworkId);
void setConnectedToCore(QIODevice *socket, AccountId id);
+ void setConnectedToInternalCore();
void setSyncedToCore();
void setSecuredConnection();
static QPointer<Client> instanceptr;
- QPointer<QIODevice> socket;
-
SignalProxy * _signalProxy;
AbstractUi * mainUi;
NetworkModel * _networkModel;
void ClientSyncer::internalSessionStateReceived(const QVariant &packedState) {
QVariantMap state = packedState.toMap();
emit sessionProgress(1, 1);
- // Client::instance()->setConnectedToCore(socket, AccountId());
+ Client::instance()->setConnectedToInternalCore();
syncToCore(state);
}
emit sessionProgress(1, 1);
disconnect(this, SIGNAL(recvPartialItem(quint32, quint32)), this, SIGNAL(sessionProgress(quint32, quint32)));
disconnect(socket, 0, this, 0); // rest of communication happens through SignalProxy
- //Client::signalProxy()->addPeer(socket);
Client::instance()->setConnectedToCore(socket, coreConnectionInfo["AccountId"].value<AccountId>());
syncToCore(state);
}
void ClientSyncer::syncToCore(const QVariantMap &sessionState) {
-
// create identities
foreach(QVariant vid, sessionState["Identities"].toList()) {
Client::instance()->coreIdentityCreated(vid.value<Identity>());
if(!device) {
quError() << "Invoking CoreSession::addClient with a QObject that is not a QIODevice!";
} else {
+ // if the socket is an orphan, the signalProxy adopts it.
+ // -> we don't need to care about it anymore
+ device->setParent(0);
signalProxy()->addPeer(device);
QVariantMap reply;
reply["MsgType"] = "SessionInit";
QTcpSocket *socket = qobject_cast<QTcpSocket *>(iodev);
if(socket)
quInfo() << qPrintable(tr("Client")) << qPrintable(socket->peerAddress().toString()) << qPrintable(tr("disconnected (UserId: %1).").arg(user().toInt()));
- iodev->deleteLater();
}
SignalProxy *CoreSession::signalProxy() const {
#include "qtui.h"
MonolithicApplication::MonolithicApplication(int &argc, char **argv)
- : QtUiApplication(argc, argv)
+ : QtUiApplication(argc, argv),
+ _internalInitDone(false)
{
_internal = new CoreApplicationInternal(); // needed for parser options
setRunMode(Monolithic);
bool MonolithicApplication::init() {
connect(Client::instance(), SIGNAL(newClientSyncer(ClientSyncer *)), this, SLOT(newClientSyncer(ClientSyncer *)));
- if(QtUiApplication::init()) {
- return true;
- }
- return false;
+ return QtUiApplication::init();
}
MonolithicApplication::~MonolithicApplication() {
}
void MonolithicApplication::startInternalCore() {
- _internal->init();
+ if(!_internalInitDone) {
+ _internal->init();
+ }
Core *core = Core::instance();
ClientSyncer *syncer = static_cast<ClientSyncer *>(sender());
connect(syncer, SIGNAL(connectToInternalCore(SignalProxy *)), core, SLOT(setupInternalClientSession(SignalProxy *)));
private:
CoreApplicationInternal *_internal;
+ bool _internalInitDone;
};
#endif