void UpdateChecker::gotReplyFromUserRequest() { qDebug("UpdateChecker::gotReplyFromUserRequest"); QNetworkReply *reply = qobject_cast<QNetworkReply*>(sender()); if (reply) { if (reply->error() == QNetworkReply::NoError) { QRegExp rx_version("^latest_version=(.*)"); QString version; while (reply->canReadLine()) { QByteArray line = reply->readLine().trimmed(); if (rx_version.indexIn(line) != -1) { version = rx_version.cap(1); break; } } if (!version.isEmpty()) { if ((formattedVersion(version) > formattedVersion(Version::with_revision()))) { qDebug("UpdateChecker::gotReplyFromUserRequest: new version found: %s", version.toUtf8().constData()); emit newVersionFound(version); } else { emit noNewVersionFound(version); } } else { emit errorOcurred(1, tr("Failed to get the latest version number") ); } } else { int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); qDebug("UpdateChecker::gotReplyFromUserRequest: status: %d", status); emit errorOcurred((int)reply->error(), reply->errorString()); } reply->deleteLater(); } }
void TileLoader::finishedRequest(QNetworkReply *reply) { const QNetworkRequest request = reply->request(); // find corresponding tile const std::vector<MapTile>::iterator it = std::find_if(tiles_.begin(), tiles_.end(), [&](const MapTile &tile) { return tile.reply() == reply; }); if (it == tiles_.end()) { // removed from list already, ignore this reply return; } MapTile &tile = *it; if (reply->error() == QNetworkReply::NoError) { // decode an image QImageReader reader(reply); if (reader.canRead()) { QImage image = reader.read(); tile.setImage(image); image.save(cachedPathForTile(tile.x(), tile.y(), tile.z()), "JPEG"); emit receivedImage(request); } else { // probably not an image QString err; err = "Unable to decode image at " + request.url().toString(); emit errorOcurred(err); } } else { const QString err = "Failed loading " + request.url().toString() + " with code " + QString::number(reply->error()); emit errorOcurred(err); } checkIfLoadingComplete(); }
void AerialMapDisplay::loadImagery() { if (loader_) { // cancel current imagery, if any loader_->abort(); delete loader_; loader_ = 0; } if (!received_msg_) { // no message received from publisher return; } if (object_uri_.empty()) { setStatus(StatusProperty::Error, "Message", "Received message but object URI is not set"); } const std::string service = object_uri_; try { loader_ = new TileLoader(service, ref_lat_, ref_lon_, zoom_, blocks_, this); } catch (std::exception &e) { setStatus(StatusProperty::Error, "Message", QString(e.what())); return; } QObject::connect(loader_, SIGNAL(errorOcurred(QString)), this, SLOT(errorOcurred(QString))); QObject::connect(loader_, SIGNAL(finishedLoading()), this, SLOT(finishedLoading())); QObject::connect(loader_, SIGNAL(initiatedRequest(QNetworkRequest)), this, SLOT(initiatedRequest(QNetworkRequest))); QObject::connect(loader_, SIGNAL(receivedImage(QNetworkRequest)), this, SLOT(receivedImage(QNetworkRequest))); // start loading images loader_->start(); }
void LoadPage::gotResponse() { qDebug() << "LoadPage::gotResponse"; QNetworkReply *reply = qobject_cast<QNetworkReply*>(sender()); if (reply->error() == QNetworkReply::NoError) { int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); qDebug() << "LoadPage::gotResponse: status:" << status; QString r_url; switch (status) { case 301: case 302: case 307: r_url = reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl().toString(); qDebug() << "LoadPage::gotResponse: redirected:" << r_url; fetchPage(r_url); break; default: qDebug() << "LoadPage::gotResponse: emit pageLoaded"; emit pageLoaded(reply->readAll()); } } else { qDebug() << "LoadPage::gotResponse: error:" << reply->error() << ":" << reply->errorString(); emit errorOcurred((int)reply->error(), reply->errorString()); } reply->deleteLater(); }
void Task::processTemplate() { Template* temp = readTemplate(*_templateName); std::vector<string> subtasks = temp->subTaskList(); int subId = 1; for (std::vector<string>::iterator iterSub = subtasks.begin(); iterSub != subtasks.end(); iterSub++) { string subtask = *iterSub; int posPar = subtask.find('('); int posFin = subtask.find(')'); string tempSub = subtask.substr(posPar + 1, posFin - posPar - 1); string subTaskName = subtask.substr(0, posPar); Task* sub = new Task(_project); std::stringstream ssId; ssId << *id() << "." << subId++; sub->setId(new string(ssId.str())); sub->setDuration(Duration(1, 0, 0)); sub->setEndDate(endDate()); sub->setShortDescription(new string(subTaskName)); sub->setStartDate(startDate()); sub->setStatus(status()); sub->setTemplateName(new string(tempSub)); _project->addTask(sub); if (errorOcurred()) { return; } sub->processTemplate(); } }
/* * @Brief Initialize Timer peripheral * @param timerNumber: Timer number, 0 to 3 * @param ticks: Number of ticks required to finish the cycle. * @param voidFunctionPointer: function to be executed at the end of the timer cycle * @return nothing * @note For the 'ticks' parameter, see function Timer_microsecondsToTicks */ void Timer_Init( uint8_t timerNumber, uint32_t ticks, voidFunctionPointer_t voidFunctionPointer){ /* Source: http://docs.lpcware.com/lpcopen/v1.03/lpc18xx__43xx_2examples_2periph_2periph__blinky_2blinky_8c_source.html */ /*If timer period = CompareMatch0 Period = 0 => ERROR*/ if (ticks==0){ errorOcurred(); } /* Enable timer clock and reset it */ Chip_TIMER_Init(timer_sd[timerNumber].name); Chip_RGU_TriggerReset(timer_sd[timerNumber].RGU); while (Chip_RGU_InReset(timer_sd[timerNumber].RGU)) {} Chip_TIMER_Reset(timer_sd[timerNumber].name); /* Update the defalut function pointer name of the Compare match 0*/ timer_dd[timerNumber].timerCompareMatchFunctionPointer[TIMERCOMPAREMATCH0] = voidFunctionPointer; /* Initialize compare match with the specified ticks (number of counts needed to clear the match counter) */ Chip_TIMER_MatchEnableInt(timer_sd[timerNumber].name, TIMERCOMPAREMATCH0); Chip_TIMER_SetMatch(timer_sd[timerNumber].name, TIMERCOMPAREMATCH0, ticks); /* Makes Timer Match 0 period the timer period*/ Chip_TIMER_ResetOnMatchEnable(timer_sd[timerNumber].name, TIMERCOMPAREMATCH0); /*Enable timer*/ Chip_TIMER_Enable(timer_sd[timerNumber].name); /* Enable timer interrupt */ NVIC_SetPriority(timer_sd[timerNumber].IRQn, MAX_SYSCALL_INTERRUPT_PRIORITY+1); NVIC_EnableIRQ(timer_sd[timerNumber].IRQn); NVIC_ClearPendingIRQ(timer_sd[timerNumber].IRQn); }
void DownloadFile::emitError(QNetworkReply::NetworkError error) { if(error != QNetworkReply::ContentOperationNotPermittedError) { file->close(); emit errorOcurred((int)error); } /* else qDebug() << "Hello Darling"; */ }
void TileLoader::finishedRequest(QNetworkReply *reply) { const QNetworkRequest request = reply->request(); // find corresponding tile MapTile *tile = 0; for (MapTile &t : tiles_) { if (t.reply() == reply) { tile = &t; } } if (!tile) { // removed from list already, ignore this reply return; } if (reply->error() == QNetworkReply::NoError) { // decode an image QImageReader reader(reply); if (reader.canRead()) { QImage image = reader.read(); tile->setImage(image); emit receivedImage(request); } else { // probably not an image QString err; err = "Unable to decode image at " + request.url().toString(); emit errorOcurred(err); } } else { QString err; err = "Failed loading " + request.url().toString(); err += " with code " + QString::number(reply->error()); emit errorOcurred(err); } emit finishedLoading(); }
bool AllneticImportHandler::startElement(const QString& namespaceURI, const QString& localName, const QString& qName, const QXmlAttributes& atts) { if (qName.compare(QString("project")) == 0) { _currentProject = parseProject(atts); _projects->push_back(_currentProject); } if (qName.compare(QString("task")) == 0) { _currentTask = parseTask(atts); _currentProject->addTask(_currentTask); if (errorOcurred()) { return false; } } if (qName.compare(QString("period")) == 0) { TaskLog* log = parseTaskLog(atts); _currentTask->addLog(log); } return true; }
void CodeDownloader::gotResponse(QNetworkReply* reply) { if (reply->error() == QNetworkReply::NoError) { int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); qDebug("CodeDownloader::gotResponse: status: %d", status); switch (status) { case 301: case 302: case 307: QString r_url = reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl().toString(); qDebug("CodeDownloader::gotResponse: redirected: %s", r_url.toLatin1().constData()); download(r_url); return; } } else { emit errorOcurred((int)reply->error(), reply->errorString()); return; } emit downloadFinished(); save(reply->readAll()); }
int main(int argc, char *argv[]) { // initialize resources, if needed // Q_INIT_RESOURCE(resfile); QtSingleApplication app(argc, argv); #ifndef TESTING if (app.isRunning()) { app.sendMessage(QString("wake")); return 0; } #endif // QPixmap pixmap(":/img/splash.png"); // QSplashScreen splash(pixmap); // splash.show(); // app.processEvents(); checkConfigFile(); if (errorOcurred()) { QMessageBox::critical(NULL, "d-jon", lastErrorDescription(), QMessageBox::Ok, QMessageBox::Cancel); qApp->quit(); return 1; } MainWindow mainWindow; QObject::connect(&app, SIGNAL(messageReceived(const QString&)), &mainWindow, SLOT(restoreWindowState())); mainWindow.show(); // qApp->processEvents(); // splash.showMessage("Loading..."); // splash.finish(&mainWindow); try { return app.exec(); } catch (std::out_of_range& e) { std::cout << "Out of range: " << e.what() << "\n"; } }