bool downloadOSM(QWidget* aParent, const QString& aWeb, const QString& aUser, const QString& aPassword, const CoordBox& aBox , Document* theDocument, Layer* theLayer) { if (checkForConflicts(theDocument)) { QMessageBox::warning(aParent,QApplication::translate("Downloader","Unresolved conflicts"), QApplication::translate("Downloader","Please resolve existing conflicts first")); return false; } Downloader Rcv(aUser, aPassword); QString URL = Rcv.getURLToMap(); if ((fabs(aBox.bottomLeft().x()) < 180.0 && fabs(aBox.topRight().x()) > 180.0) || (fabs(aBox.bottomLeft().x()) > 180.0 && fabs(aBox.topRight().x()) < 180.0)) { /* Check for +-180 meridian, and split query in two if necessary */ int sign = (aBox.bottomLeft().x() > 0) ? 1 : -1; CoordBox q1 = aBox, q2 = aBox; if (aBox.bottomLeft().x() > 0) { q1.setRight(180*sign); q2.setLeft(-180*sign); q2.setRight(q2.right()-360); } else { q1.setLeft(180*sign); q2.setRight(-180*sign); q2.setLeft(q2.left()+360); } return downloadOSM(aParent, aWeb, aUser, aPassword, q1, theDocument, theLayer) && downloadOSM(aParent, aWeb, aUser, aPassword, q2, theDocument, theLayer); } else { /* Normal code path */ URL = URL.arg(aBox.bottomLeft().x(), 0, 'f').arg(aBox.bottomLeft().y(), 0, 'f').arg(aBox.topRight().x(), 0, 'f').arg(aBox.topRight().y(), 0, 'f'); QUrl theUrl(aWeb+URL); return downloadOSM(aParent, theUrl, aUser, aPassword, theDocument, theLayer); } }
bool downloadOSM(QWidget* aParent, const QString& aWeb, const QString& aUser, const QString& aPassword, const CoordBox& aBox , Document* theDocument, Layer* theLayer) { if (checkForConflicts(theDocument)) { QMessageBox::warning(aParent,QApplication::translate("Downloader","Unresolved conflicts"), QApplication::translate("Downloader","Please resolve existing conflicts first")); return false; } Downloader Rcv(aUser, aPassword); QString URL = Rcv.getURLToMap(); URL = URL.arg(aBox.bottomLeft().x(), 0, 'f').arg(aBox.bottomLeft().y(), 0, 'f').arg(aBox.topRight().x(), 0, 'f').arg(aBox.topRight().y(), 0, 'f'); QUrl theUrl(aWeb+URL); return downloadOSM(aParent, theUrl, aUser, aPassword, theDocument, theLayer); }
bool downloadFeatures(MainWindow* Main, const QList<IFeature::FId>& idList , Document* theDocument, Layer* theLayer) { if (!theLayer) { if (!theDocument->getLastDownloadLayer()) { theLayer = new DrawingLayer(QApplication::translate("Downloader","%1 download").arg(QDateTime::currentDateTime().toString(Qt::ISODate))); theDocument->add(theLayer); } else theLayer = (Layer*)theDocument->getLastDownloadLayer(); } QString osmWebsite, osmUser, osmPwd; osmWebsite = M_PREFS->getOsmApiUrl(); osmUser = M_PREFS->getOsmUser(); osmPwd = M_PREFS->getOsmPassword(); if (Main) Main->view()->setUpdatesEnabled(false); bool OK = true; Downloader Rcv(osmUser, osmPwd); for (int i=0; i<idList.size(); ++i) { QString URL = Rcv.getURLToFetchFull(idList[i]); QUrl theUrl(osmWebsite+URL); downloadOSM(Main, theUrl, osmUser, osmPwd, theDocument, theLayer); } if (Main) Main->view()->setUpdatesEnabled(true); if (OK) { if (Main) Main->invalidateView(); } else { if (theLayer != theDocument->getLastDownloadLayer()) { theDocument->remove(theLayer); delete theLayer; } } return OK; }
bool downloadMoreOSM(MainWindow* Main, const CoordBox& aBox , Document* theDocument) { Layer* theLayer; if (!theDocument->getLastDownloadLayer()) { theLayer = new DrawingLayer(QApplication::translate("Downloader","%1 download").arg(QDateTime::currentDateTime().toString(Qt::ISODate))); theDocument->add(theLayer); } else theLayer = (Layer*)theDocument->getLastDownloadLayer(); QString osmWebsite, osmUser, osmPwd; osmWebsite = M_PREFS->getOsmApiUrl(); osmUser = M_PREFS->getOsmUser(); osmPwd = M_PREFS->getOsmPassword(); qDebug() << "Requesting more from " << osmWebsite; Main->view()->setUpdatesEnabled(false); bool OK = true; OK = downloadOSM(Main,osmWebsite,osmUser,osmPwd,aBox,theDocument,theLayer); Main->view()->setUpdatesEnabled(true); if (OK) { theDocument->setLastDownloadLayer(theLayer); theDocument->addDownloadBox(theLayer, aBox); // Don't jump around on Download More // aParent->view()->projection().setViewport(aBox,aParent->view()->rect()); Main->invalidateView(); } else { if (theLayer != theDocument->getLastDownloadLayer()) { theDocument->remove(theLayer); delete theLayer; } } return OK; }
bool downloadOSM(MainWindow* Main, const CoordBox& aBox , Document* theDocument) { QString osmWebsite, osmUser, osmPwd; static bool DownloadRaw = false; QDialog * dlg = new QDialog(Main); osmWebsite = M_PREFS->getOsmApiUrl(); osmUser = M_PREFS->getOsmUser(); osmPwd = M_PREFS->getOsmPassword(); Ui::DownloadMapDialog ui; ui.setupUi(dlg); SlippyMapWidget* SlippyMap = new SlippyMapWidget(ui.groupBox); #ifndef _MOBILE SlippyMap->setMinimumHeight(256); #endif CoordBox Clip(aBox); SlippyMap->setViewportArea(Clip); ui.verticalLayout->addWidget(SlippyMap); QObject::connect(SlippyMap, SIGNAL(redraw()), ui.FromMap, SLOT(toggle())); BookmarkListIterator i(*(M_PREFS->getBookmarks())); while (i.hasNext()) { i.next(); if (i.value().deleted == false) ui.Bookmarks->addItem(i.key()); } ui.edXapiUrl->setText(QString("*[bbox=%1,%2,%3,%4]").arg(aBox.bottomLeft().x(), 0, 'f').arg(aBox.bottomLeft().y(), 0, 'f').arg(aBox.topRight().x(), 0, 'f').arg(aBox.topRight().y(), 0, 'f')); ui.IncludeTracks->setChecked(DownloadRaw); ui.ResolveRelations->setChecked(M_PREFS->getResolveRelations()); bool OK = true, retry = true, directAPI = false; QString directUrl; while (retry) { retry = false; #ifdef _MOBILE dlg->setWindowState(Qt::WindowMaximized); #endif if (dlg->exec() == QDialog::Accepted) { DownloadRaw = false; if (ui.FromBookmark->isChecked()) { Clip = M_PREFS->getBookmarks()->value(ui.Bookmarks->currentText()).Coordinates; } else if (ui.FromView->isChecked()) { Clip = aBox; } else if (ui.FromLink->isChecked()) { QString link = ui.Link->text(); if (link.contains("/api/")) { directAPI=true; directUrl = link; } else if (link.contains("/browse/")) { QString tag("/browse/"); int ix = link.lastIndexOf(tag) + tag.length(); directUrl = M_PREFS->getOsmApiUrl(); if (!directUrl.endsWith("/")) directUrl += "/"; directUrl += link.right(link.length() - ix); if (!directUrl.endsWith("/")) directUrl += "/"; directUrl += "full"; directAPI=true; } else if (link.startsWith("way") || link.startsWith("node") || link.startsWith("relation")) { directUrl = M_PREFS->getOsmApiUrl(); if (!directUrl.endsWith("/")) directUrl += "/"; directUrl += link; directAPI=true; } else { OsmLink ol(link); Clip = ol.getCoordBox(); if (Clip.isNull() || Clip.isEmpty()) retry = true; } } else if (ui.FromXapi->isChecked()) { directAPI = true; directUrl = M_PREFS->getXapiUrl(); if (!directUrl.endsWith("/")) directUrl += "/"; directUrl += ui.edXapiUrl->text(); } else if (ui.FromMap->isChecked()) { QRectF R(SlippyMap->viewArea()); Clip = CoordBox(Coord(R.x(), R.y()), Coord(R.x()+R.width(), R.y()+R.height())); } if (retry) continue; Main->view()->setUpdatesEnabled(false); Layer* theLayer = new DrawingLayer(QApplication::translate("Downloader","%1 download").arg(QDateTime::currentDateTime().toString(Qt::ISODate))); theDocument->add(theLayer); M_PREFS->setResolveRelations(ui.ResolveRelations->isChecked()); if (directAPI) { if (ui.FromXapi->isChecked()) theLayer->setUploadable(false); OK = downloadOSM(Main,QUrl(QUrl::fromEncoded(directUrl.toLatin1())),osmUser,osmPwd,theDocument,theLayer); } else OK = downloadOSM(Main,osmWebsite,osmUser,osmPwd,Clip,theDocument,theLayer); if (OK && ui.IncludeTracks->isChecked()) OK = downloadTracksFromOSM(Main,osmWebsite,osmUser,osmPwd, Clip,theDocument); Main->view()->setUpdatesEnabled(true); if (OK) { theDocument->setLastDownloadLayer(theLayer); theDocument->addDownloadBox(theLayer, Clip); #ifndef _MOBILE if (directAPI) Main->on_viewZoomAllAction_triggered(); else #endif Main->view()->setViewport(Clip,Main->view()->rect()); Main->invalidateView(); } else { retry = true; theDocument->remove(theLayer); SAFE_DELETE(theLayer); } } } delete dlg; return OK; }
bool downloadOSM(QWidget* aParent, const QUrl& theUrl, const QString& aUser, const QString& aPassword, Document* theDocument, Layer* theLayer) { Downloader Rcv(aUser, aPassword); IProgressWindow* aProgressWindow = dynamic_cast<IProgressWindow*>(aParent); if (aProgressWindow) { QProgressDialog* dlg = aProgressWindow->getProgressDialog(); if (dlg) { dlg->setWindowTitle(QApplication::translate("Downloader","Downloading...")); dlg->setWindowFlags(dlg->windowFlags() & ~Qt::WindowContextHelpButtonHint); dlg->setWindowFlags(dlg->windowFlags() | Qt::MSWindowsFixedSizeDialogHint); } QProgressBar* Bar = aProgressWindow->getProgressBar(); Bar->setTextVisible(false); Bar->setMaximum(11); QLabel* Lbl = aProgressWindow->getProgressLabel(); Lbl->setText(QApplication::translate("Downloader","Downloading from OSM (connecting)")); if (dlg) dlg->show(); Rcv.setAnimator(dlg, Lbl, Bar, true); } if (!Rcv.go(theUrl)) { #ifndef _MOBILE aParent->setCursor(QCursor(Qt::ArrowCursor)); #endif return false; } int x = Rcv.resultCode(); switch (x) { case 200: break; case 301: case 302: case 307: { QString aWeb = Rcv.locationText(); if (!aWeb.isEmpty()) { QUrl aURL(aWeb); return downloadOSM(aParent, aURL, aUser, aPassword, theDocument, theLayer); } else { QString msg = QApplication::translate("Downloader","Unexpected http status code (%1)\nServer message is '%2'").arg(x).arg(Rcv.resultText()); if (!Rcv.errorText().isEmpty()) msg += QApplication::translate("Downloader", "\nAPI message is '%1'").arg(Rcv.errorText()); QMessageBox::warning(aParent,QApplication::translate("Downloader","Download failed"), msg); return false; } break; } case 401: QMessageBox::warning(aParent,QApplication::translate("Downloader","Download failed"),QApplication::translate("Downloader","Username/password invalid")); return false; default: QString msg = QApplication::translate("Downloader","Unexpected http status code (%1)\nServer message is '%2'").arg(x).arg(Rcv.resultText()); if (!Rcv.errorText().isEmpty()) msg += QApplication::translate("Downloader", "\nAPI message is '%1'").arg(Rcv.errorText()); QMessageBox::warning(aParent,QApplication::translate("Downloader","Download failed"), msg); return false; } Downloader Down(aUser, aPassword); bool OK = importOSM(aParent, Rcv.content(), theDocument, theLayer, &Down); return OK; }