- }
-
- QVariantMap clientLogin;
- clientLogin["MsgType"] = "ClientLogin";
- clientLogin["User"] = currentAccount().user();
- clientLogin["Password"] = currentAccount().password();
- SignalProxy::writeDataToDevice(_socket, clientLogin);
-}
-
-void CoreConnection::loginFailed(const QString &error) {
- emit userAuthenticationRequired(&_account, error); // *must* be a synchronous call
- if(currentAccount().user().isEmpty() || currentAccount().password().isEmpty()) {
- disconnectFromCore();
- return;
- }
- loginToCore();
-}
-
-void CoreConnection::loginSuccess() {
- updateProgress(0, 0);
- setProgressText(tr("Receiving session state"));
- setState(Synchronizing);
- emit connectionMsg(tr("Synchronizing to %1...").arg(currentAccount().accountName()));
-}
-
-void CoreConnection::sessionStateReceived(const QVariantMap &state) {
- updateProgress(100, 100);
-
- // rest of communication happens through SignalProxy...
- disconnect(_socket, SIGNAL(readyRead()), this, 0);
- disconnect(_socket, SIGNAL(connected()), this, 0);
-
- //Client::instance()->setConnectedToCore(currentAccount().accountId(), _socket);
- syncToCore(state);
-}
-
-void CoreConnection::syncToCore(const QVariantMap &sessionState) {
- setProgressText(tr("Receiving network states"));
- updateProgress(0, 100);
-
- // create identities
- foreach(QVariant vid, sessionState["Identities"].toList()) {
- Client::instance()->coreIdentityCreated(vid.value<Identity>());
- }
-
- // create buffers
- // FIXME: get rid of this crap -- why?
- QVariantList bufferinfos = sessionState["BufferInfos"].toList();
- NetworkModel *networkModel = Client::networkModel();
- Q_ASSERT(networkModel);
- foreach(QVariant vinfo, bufferinfos)
- networkModel->bufferUpdated(vinfo.value<BufferInfo>()); // create BufferItems
-
- QVariantList networkids = sessionState["NetworkIds"].toList();
-
- // prepare sync progress thingys...
- // FIXME: Care about removal of networks
- _numNetsToSync = networkids.count();
- updateProgress(0, _numNetsToSync);
-
- // create network objects
- foreach(QVariant networkid, networkids) {
- NetworkId netid = networkid.value<NetworkId>();
- if(Client::network(netid))
- continue;
- Network *net = new Network(netid, Client::instance());
- _netsToSync.insert(net);
- connect(net, SIGNAL(initDone()), SLOT(networkInitDone()));
- connect(net, SIGNAL(destroyed()), SLOT(networkInitDone()));
- Client::addNetwork(net);
- }
- checkSyncState();
-}
-
-void CoreConnection::networkInitDone() {
- Network *net = qobject_cast<Network *>(sender());
- Q_ASSERT(net);
- disconnect(net, 0, this, 0);
- _netsToSync.remove(net);
- updateProgress(_numNetsToSync - _netsToSync.count(), _numNetsToSync);
- checkSyncState();
-}
-
-void CoreConnection::checkSyncState() {
- if(_netsToSync.isEmpty()) {
- setState(Synchronized);
- setProgressText(QString());
- setProgressMaximum(-1);
- emit synchronized();
- }