void KRemoteModel::setState(ModelState st) { Kwery *kw; st_ = st; switch(st_) { case Getting: kw = new KweryModelGet(modelName_); connect(((KweryModelGet*)kw), SIGNAL(gotModel(int)), this, SLOT(gotModelId(int))); k_->sendKwery(kw); break; case Headers: kw = new KweryModelHeaders(mid_); connect(((KweryModelHeaders*)kw), SIGNAL(gotHeaders(QVariantList)), this, SLOT(gotHeaders(QVariantList))); k_->sendKwery(kw); break; case Fetching: kw = new KweryModelData(mid_); connect(((KweryModelData*)kw), SIGNAL(gotData(QVariantList)), this, SLOT(gotData(QVariantList))); k_->sendKwery(kw); break; case Complete: qDebug() << "Model" << modelName_ << "complete"; qDebug() << hdrs_; qDebug() << data_; default: break; } emit stateChanged(st); }
void WebGetter::update() { lock_guard<mutex>{m}; Connection::run(); auto it = sessions.begin(); while(it != sessions.end()) { auto s = *it; if(s->gotHeaders() && s->isRedirect()) { auto location = s->getHeader("Location"); if(!startsWith(location, "http://")) { location = format("http://%s:%d%s", s->getHost(), s->getPort(), urlencode(location, ":\\?;+ ")); } LOGD("Redirecting to '%s'", location); auto callback = s->getCallback(); it = sessions.erase(it); auto s = make_shared<HttpSession>(location); sessions.push_back(s); s->connect(); s->stream(callback); it = sessions.end(); continue; } if(s->error()) { errorCallback(0, ""); } if(s->done()) { it = sessions.erase(it); LOGD("Session done"); } else it++; } }