void QuickOpenFunctionDialog::gotoFile( QString name ) { FunctionModel *fmodel; FunctionList funcList; FunctionDom fdom; for( FunctionList::ConstIterator it = m_functionDefList.begin() ; it!=m_functionDefList.end() ; ++it ){ fdom = *it; fmodel = fdom.data(); if( fmodel->name() == name ){ funcList.append( fdom ); } } if( funcList.count() == 1 ){ fdom = funcList.first(); fmodel = fdom.data(); QString fileNameStr = fmodel->fileName(); int startline, startcol; fmodel->getStartPosition( &startline, &startcol ); m_part->partController()->editDocument( KURL( fileNameStr), startline, startcol ); selectClassViewItem( ItemDom(&(*fmodel)) ); }else if( funcList.count() > 1 ){ QString fileStr; QuickOpenFunctionChooseForm fdlg( this, name.ascii() ); for( FunctionList::Iterator it = funcList.begin() ; it!=funcList.end() ; ++it ){ fmodel = (*it).data(); fdlg.argBox->insertItem( m_part->languageSupport()->formatModelItem(fmodel) + (fmodel->scope().isEmpty() ? "" : " (in " + fmodel->scope().join("::") + ")")); fileStr = KURL( fmodel->fileName() ).fileName(); KURL full_url( fmodel->fileName() ); KURL base_url( part()->project()->projectDirectory()+"/" ); fdlg.setRelativePath(fdlg.fileBox->count(), KURL::relativeURL( base_url, full_url )); fdlg.fileBox->insertItem(fileStr); } if( fdlg.exec() ){ int id = fdlg.argBox->currentItem(); if( id>-1 && id < (int) funcList.count() ){ FunctionModel *model = funcList[id].data(); int line, col; model->getStartPosition( &line, &col ); selectClassViewItem( ItemDom(&(*model)) ); QString fileNameStr = model->fileName(); m_part->partController()->editDocument( KURL(fileNameStr), line ); } } } else{ KMessageBox::error( this, i18n("Error: cannot find matching name function.") ); } accept(); }
std::string Arome_grib_downloader::get_last_available_run_time(const std::string &run_date) { std::string run_time = "-1"; std::string base_url(METEO_FRANCE_DL_URL); // Based on the current date, check if run from 18:00 exists, if not check 12:00, etc... std::cout << "Looking for the latest run:" << std::endl; if (this->url_exists(base_url + "&time=00H&referencetime=" + run_date + "T18:00:00Z") == true) run_time = "18"; else if (this->url_exists(base_url + "&time=00H&referencetime=" + run_date + "T12:00:00Z") == true) run_time = "12"; else if (this->url_exists(base_url + "&time=00H&referencetime=" + run_date + "T06:00:00Z") == true) run_time = "06"; else if (this->url_exists(base_url + "&time=00H&referencetime=" + run_date + "T03:00:00Z") == true) run_time = "03"; else if (this->url_exists(base_url + "&time=00H&referencetime=" + run_date + "T00:00:00Z") == true) run_time = "00"; std::cout << "Use run " << run_time << "H" << std::endl; return run_time; }
bool Arome_grib_downloader::run() { bool result = true; // Find the last available meteo files. std::string tmp_dir = this->orig_dir + "/" + TMP_DIR; exec("rm -rf " + tmp_dir); exec("mkdir " + tmp_dir); if (chdir(tmp_dir.c_str()) != 0) { std::cout << "ERROR: Can not change directory to " << tmp_dir << std::endl; return false; } std::string base_url(METEO_FRANCE_DL_URL); time_t today = time(0); std::string run_date = this->get_date_str(today, "%Y%m%d"); std::string run_date_dash = this->get_date_str(today, "%Y-%m-%d"); std::string run_time = this->get_last_available_run_time(run_date_dash); //run_time = "18"; if (run_time == "-1") { // Try downloading the previous day if the current day is still not available. std::tm prev_day = *std::localtime(&today); prev_day.tm_mday = prev_day.tm_mday - 1; time_t prev_day_t = mktime(&prev_day); run_date = this->get_date_str(prev_day_t, "%Y%m%d"); run_date_dash = this->get_date_str(prev_day_t, "%Y-%m-%d"); run_time = this->get_last_available_run_time(run_date_dash); } if (run_time == "-1") { std::cout << "ERROR: Can not download GRIB files from Meteo France server." << std::endl; return false; } if (chdir(this->orig_dir.c_str()) != 0) { std::cout << "ERROR: Can not change directory to " << this->orig_dir << std::endl; return false; } // Store the run date/time. std::tm run_date_time = *std::localtime(&today); run_date_time.tm_min = 0; run_date_time.tm_sec = 0; run_date_time.tm_hour = std::stoi(run_time); this->run_date_time = mktime(&run_date_time); // Download all files from the last run. if (result == true) { this->dl_dir = this->dl_dir + "-" + run_date + "-" + run_time + "00"; exec("mkdir " + this->dl_dir); if (chdir(this->dl_dir.c_str()) != 0) { std::cout << "ERROR: Can not change directory to " << this->dl_dir << std::endl; return false; } // Prepare a list of URLs to download. std::vector<std::string> urls; for (int i = 0; i <= METEO_FRANCE_NB_HOUR_OFFSET; i++) { std::string offset = std::to_string(i); if (offset.length() == 1) offset = '0' + offset; // Download only if it does not exists. if (!std::ifstream("AROME_0.01_SP1_" + offset + "H_" + run_date + run_time + "00.grib2")) { urls.push_back(base_url + "&time=" + offset + "H&referencetime=" + run_date_dash + "T" + run_time + ":00:00Z"); } } // Download all URLs. std::cout << std::endl; std::cout << "Downloading AROME files:" << std::endl; if (urls.size() == 0) { std::cout << "Nothing to download" << std::endl; } int max_retry = 5; while ((max_retry > 0) && (this->get_file_list().size() <= METEO_FRANCE_NB_HOUR_OFFSET)) // Hack: because sometimes files exists but are not retrived by the server, then try again. { #if 1 // parallel QtConcurrent::blockingMapped<std::vector<std::string>>(urls, dl_file_static); #else // sequential for (auto &u : urls) { dl_file_static(u); } #endif max_retry--; } // Switch back to original dir. if (chdir(this->orig_dir.c_str()) != 0) { std::cout << "ERROR: Can not change directory to " << this->orig_dir << std::endl; return false; } } return result; }
std::list<Maj> WebConnection::getMaj(std::list<Log>& logs) { std::list<Maj> results; QUrl base_url(Config::getUrl().c_str()); QUrl relative_url(majUrl().c_str()); QUrl url = base_url.resolved(relative_url); request.setUrl(url); QNetworkReply* reply = networkManager.get(request); // GET QEventLoop loop; QObject::connect(reply, SIGNAL(finished()), &loop, SLOT(quit())); loop.exec(); if (reply->error() != QNetworkReply::NoError) { QMessageBox::warning(nullptr,"Error","Immpossible to connect to the url:\n"+url.toString()); delete reply; return results; } QString data = (QString) reply->readAll(); delete reply; QJsonDocument jsonResponse = QJsonDocument::fromJson(data.toUtf8()); QJsonObject json = jsonResponse.object(); int status = json.value("status").toVariant().value<int>(); switch(status) //0:ok, 1:not soft, 2:not src version, 3:no destionation, 4:lastest { case 0: //all is good { }break; case 4 : //lastes { return results; }break; default: { QString msg = json.value("message").toString(); QMessageBox::warning(nullptr,"Error","Recive error code:"+QString::number(status) +"\nMessage:"+msg); return results; }break; } QJsonObject datas = json.value("datas").toObject(); QJsonArray files = datas.value("files").toArray(); int _size = files.size(); for(int i=0;i<_size;++i) { QJsonObject file = files.at(i).toObject(); results.emplace_back(file.value("action").toVariant().value<int>(), file.value("filename").toString().toStdString(), file.value("url").toString().toStdString()); } Config::setVersion(datas.value("version").toVariant().value<int>()); Config::makeFile(); ///LOGS QJsonArray qlogs = datas.value("logs").toArray(); _size = qlogs.size(); for(int i=0;i<_size;++i) { QJsonObject log = qlogs.at(i).toObject(); logs.emplace_back(log.value("version").toVariant().value<int>(), log.value("msg").toString().toStdString()); } return results; }