MpcImportWindow.cpp   MpcImportWindow.cpp 
skipping to change at line 32 skipping to change at line 32
#include "MpcImportWindow.hpp" #include "MpcImportWindow.hpp"
#include "ui_mpcImportWindow.h" #include "ui_mpcImportWindow.h"
#include "StelApp.hpp" #include "StelApp.hpp"
#include "StelFileMgr.hpp" #include "StelFileMgr.hpp"
#include "StelJsonParser.hpp" #include "StelJsonParser.hpp"
#include "StelModuleMgr.hpp" #include "StelModuleMgr.hpp"
#include "StelTranslator.hpp" #include "StelTranslator.hpp"
#include "SolarSystem.hpp" #include "SolarSystem.hpp"
#include "StelProgressController.hpp"
#include <QApplication> #include <QGuiApplication>
#include <QClipboard> #include <QClipboard>
#include <QDesktopServices> #include <QDesktopServices>
#include <QFileDialog> #include <QFileDialog>
#include <QSortFilterProxyModel> #include <QSortFilterProxyModel>
#include <QHash> #include <QHash>
#include <QList> #include <QList>
#include <QNetworkAccessManager> #include <QNetworkAccessManager>
#include <QNetworkRequest> #include <QNetworkRequest>
#include <QNetworkReply> #include <QNetworkReply>
#include <QStandardItemModel> #include <QStandardItemModel>
#include <QString> #include <QString>
#include <QTemporaryFile> #include <QTemporaryFile>
#include <QTimer> #include <QTimer>
#include <QUrl> #include <QUrl>
#include <QUrlQuery>
#include <QDir> #include <QDir>
MpcImportWindow::MpcImportWindow() : MpcImportWindow::MpcImportWindow()
downloadReply(0), : importType(ImportType())
queryReply(0), , downloadReply(0)
downloadProgressBar(0), , queryReply(0)
queryProgressBar(0) , downloadProgressBar(0)
, queryProgressBar(0)
, countdown(0)
{ {
ui = new Ui_mpcImportWindow(); ui = new Ui_mpcImportWindow();
ssoManager = GETSTELMODULE(SolarSystemEditor); ssoManager = GETSTELMODULE(SolarSystemEditor);
networkManager = StelApp::getInstance().getNetworkAccessManager(); networkManager = StelApp::getInstance().getNetworkAccessManager();
countdownTimer = new QTimer(this); countdownTimer = new QTimer(this);
QHash<QString,QString> asteroidBookmarks; QHash<QString,QString> asteroidBookmarks;
QHash<QString,QString> cometBookmarks; QHash<QString,QString> cometBookmarks;
skipping to change at line 82 skipping to change at line 86
{ {
delete ui; delete ui;
delete countdownTimer; delete countdownTimer;
candidateObjectsModel->clear(); candidateObjectsModel->clear();
delete candidateObjectsModel; delete candidateObjectsModel;
if (downloadReply) if (downloadReply)
downloadReply->deleteLater(); downloadReply->deleteLater();
if (queryReply) if (queryReply)
queryReply->deleteLater(); queryReply->deleteLater();
if (downloadProgressBar) if (downloadProgressBar)
downloadProgressBar->deleteLater(); StelApp::getInstance().removeProgressBar(downloadProgressBar );
if (queryProgressBar) if (queryProgressBar)
queryProgressBar->deleteLater(); StelApp::getInstance().removeProgressBar(queryProgressBar);
} }
void MpcImportWindow::createDialogContent() void MpcImportWindow::createDialogContent()
{ {
ui->setupUi(dialog); ui->setupUi(dialog);
//Signals //Signals
connect(&StelApp::getInstance(), SIGNAL(languageChanged()), this, SL OT(retranslate())); connect(&StelApp::getInstance(), SIGNAL(languageChanged()), this, SL OT(retranslate()));
connect(ui->closeStelWindow, SIGNAL(clicked()), this, SLOT(close())) ; connect(ui->closeStelWindow, SIGNAL(clicked()), this, SLOT(close())) ;
skipping to change at line 315 skipping to change at line 319
emit objectsImported(); emit objectsImported();
} }
void MpcImportWindow::discardObjects() void MpcImportWindow::discardObjects()
{ {
resetDialog(); resetDialog();
} }
void MpcImportWindow::pasteClipboardURL() void MpcImportWindow::pasteClipboardURL()
{ {
ui->lineEditURL->setText(QApplication::clipboard()->text()); ui->lineEditURL->setText(QGuiApplication::clipboard()->text());
} }
void MpcImportWindow::selectFile() void MpcImportWindow::selectFile()
{ {
QString directory = QDesktopServices::storageLocation(QDesktopServic QStringList directories = QStandardPaths::standardLocations(QStandar
es::DesktopLocation); dPaths::DesktopLocation) +
if (directory.isEmpty()) QStandardPaths::st
directory = QDesktopServices::storageLocation(QDesktopServic andardLocations(QStandardPaths::HomeLocation) << "/";
es::HomeLocation); QString filePath = QFileDialog::getOpenFileName(NULL, "Select a text
QString filePath = QFileDialog::getOpenFileName(NULL, "Select a tex file", directories[0]);
t file", directory);
ui->lineEditFilePath->setText(filePath); ui->lineEditFilePath->setText(filePath);
} }
void MpcImportWindow::bookmarkSelected(QString bookmarkTitle) void MpcImportWindow::bookmarkSelected(QString bookmarkTitle)
{ {
if (bookmarkTitle.isEmpty() || bookmarkTitle == "Select bookmark..." ) if (bookmarkTitle.isEmpty() || bookmarkTitle == "Select bookmark..." )
{ {
ui->lineEditURL->clear(); ui->lineEditURL->clear();
return; return;
} }
skipping to change at line 442 skipping to change at line 445
ui->pushButtonAcquire->setEnabled(enable); ui->pushButtonAcquire->setEnabled(enable);
} }
SsoElements MpcImportWindow::readElementsFromString (QString elements) SsoElements MpcImportWindow::readElementsFromString (QString elements)
{ {
Q_ASSERT(ssoManager); Q_ASSERT(ssoManager);
switch (importType) switch (importType)
{ {
case MpcComets: case MpcComets:
return ssoManager->readMpcOneLineCometElements(elements); return ssoManager->readMpcOneLineCometElements(eleme
case MpcMinorPlanets: nts);
default: case MpcMinorPlanets:
return ssoManager->readMpcOneLineMinorPlanetElements(element default:
s); return ssoManager->readMpcOneLineMinorPlanetElements
(elements);
} }
} }
QList<SsoElements> MpcImportWindow::readElementsFromFile(ImportType type, Q String filePath) QList<SsoElements> MpcImportWindow::readElementsFromFile(ImportType type, Q String filePath)
{ {
Q_ASSERT(ssoManager); Q_ASSERT(ssoManager);
switch (type) switch (type)
{ {
case MpcComets: case MpcComets:
return ssoManager->readMpcOneLineCometElementsFromFile(fileP return ssoManager->readMpcOneLineCometElementsFromFi
ath); le(filePath);
case MpcMinorPlanets: case MpcMinorPlanets:
default: default:
return ssoManager->readMpcOneLineMinorPlanetElementsFromFile return ssoManager->readMpcOneLineMinorPlanetElements
(filePath); FromFile(filePath);
} }
} }
void MpcImportWindow::switchImportType(bool) void MpcImportWindow::switchImportType(bool)
{ {
if (ui->radioButtonAsteroids->isChecked()) if (ui->radioButtonAsteroids->isChecked())
{ {
importType = MpcMinorPlanets; importType = MpcMinorPlanets;
} }
else else
skipping to change at line 531 skipping to change at line 534
return; return;
int currentValue = 0; int currentValue = 0;
int endValue = 0; int endValue = 0;
if (bytesTotal > -1 && bytesReceived <= bytesTotal) if (bytesTotal > -1 && bytesReceived <= bytesTotal)
{ {
//Round to the greatest possible derived unit //Round to the greatest possible derived unit
while (bytesTotal > 1024) while (bytesTotal > 1024)
{ {
bytesReceived = std::floor(bytesReceived / 1024); bytesReceived = std::floor(bytesReceived / 1024.);
bytesTotal = std::floor(bytesTotal / 1024); bytesTotal = std::floor(bytesTotal / 1024.);
} }
currentValue = bytesReceived; currentValue = bytesReceived;
endValue = bytesTotal; endValue = bytesTotal;
} }
downloadProgressBar->setValue(currentValue); downloadProgressBar->setValue(currentValue);
downloadProgressBar->setMaximum(endValue); downloadProgressBar->setRange(0, endValue);
} }
void MpcImportWindow::updateQueryProgress(qint64, qint64) void MpcImportWindow::updateQueryProgress(qint64, qint64)
{ {
if (queryProgressBar == NULL) if (queryProgressBar == NULL)
return; return;
//Just show activity //Just show activity
queryProgressBar->setValue(0); queryProgressBar->setValue(0);
queryProgressBar->setMaximum(0); queryProgressBar->setRange(0, 0);
} }
void MpcImportWindow::startDownload(QString urlString) void MpcImportWindow::startDownload(QString urlString)
{ {
if (downloadReply) if (downloadReply)
{ {
//There's already an operation in progress? //There's already an operation in progress?
//TODO //TODO
return; return;
} }
skipping to change at line 571 skipping to change at line 574
QUrl url(urlString); QUrl url(urlString);
if (!url.isValid() || url.isRelative() || url.scheme() != "http") if (!url.isValid() || url.isRelative() || url.scheme() != "http")
{ {
qWarning() << "Invalid URL:" << urlString; qWarning() << "Invalid URL:" << urlString;
return; return;
} }
//qDebug() << url.toString(); //qDebug() << url.toString();
//TODO: Interface changes! //TODO: Interface changes!
downloadProgressBar = StelApp::getInstance().getGui()->addProgressBa r(); downloadProgressBar = StelApp::getInstance().addProgressBar();
downloadProgressBar->setValue(0); downloadProgressBar->setValue(0);
downloadProgressBar->setMaximum(0); downloadProgressBar->setRange(0, 0);
//downloadProgressBar->setFormat("%v/%m");
downloadProgressBar->setVisible(true);
//TODO: Better handling of the interface //TODO: Better handling of the interface
//dialog->setVisible(false); //dialog->setVisible(false);
enableInterface(false); enableInterface(false);
ui->pushButtonAbortDownload->setVisible(true); ui->pushButtonAbortDownload->setVisible(true);
connect(networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT (downloadComplete(QNetworkReply*))); connect(networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT (downloadComplete(QNetworkReply*)));
downloadReply = networkManager->get(QNetworkRequest(url)); downloadReply = networkManager->get(QNetworkRequest(url));
connect(downloadReply, SIGNAL(downloadProgress(qint64,qint64)), this , SLOT(updateDownloadProgress(qint64,qint64))); connect(downloadReply, SIGNAL(downloadProgress(qint64,qint64)), this , SLOT(updateDownloadProgress(qint64,qint64)));
} }
skipping to change at line 683 skipping to change at line 684
//while there is a list, it should be reset. //while there is a list, it should be reset.
connect(ssoManager, SIGNAL(solarSystemChanged()), this, SLOT(resetDi alog())); connect(ssoManager, SIGNAL(solarSystemChanged()), this, SLOT(resetDi alog()));
} }
void MpcImportWindow::deleteDownloadProgressBar() void MpcImportWindow::deleteDownloadProgressBar()
{ {
disconnect(this, SLOT(updateDownloadProgress(qint64,qint64))); disconnect(this, SLOT(updateDownloadProgress(qint64,qint64)));
if (downloadProgressBar) if (downloadProgressBar)
{ {
downloadProgressBar->setVisible(false); StelApp::getInstance().removeProgressBar(downloadProgressBar
downloadProgressBar->deleteLater(); );
downloadProgressBar = NULL; downloadProgressBar = NULL;
} }
} }
void MpcImportWindow::sendQuery() void MpcImportWindow::sendQuery()
{ {
if (queryReply != 0) if (queryReply != 0)
return; return;
query = ui->lineEditQuery->text().trimmed(); query = ui->lineEditQuery->text().trimmed();
if (query.isEmpty()) if (query.isEmpty())
return; return;
//Progress bar //Progress bar
queryProgressBar = StelApp::getInstance().getGui()->addProgressBar() ; queryProgressBar = StelApp::getInstance().addProgressBar();
queryProgressBar->setValue(0); queryProgressBar->setValue(0);
queryProgressBar->setMaximum(0); queryProgressBar->setRange(0, 0);
queryProgressBar->setFormat("Searching..."); queryProgressBar->setFormat("Searching...");
queryProgressBar->setVisible(true);
//TODO: Better handling of the interface //TODO: Better handling of the interface
enableInterface(false); enableInterface(false);
ui->labelQueryMessage->setVisible(false); ui->labelQueryMessage->setVisible(false);
startCountdown(); startCountdown();
ui->pushButtonAbortQuery->setVisible(true); ui->pushButtonAbortQuery->setVisible(true);
sendQueryToUrl(QUrl("http://stellarium.org/mpc-mpeph")); sendQueryToUrl(QUrl("http://stellarium.org/mpc-mpeph"));
//sendQueryToUrl(QUrl("http://scully.cfa.harvard.edu/cgi-bin/mpeph2. cgi")); //sendQueryToUrl(QUrl("http://scully.cfa.harvard.edu/cgi-bin/mpeph2. cgi"));
} }
void MpcImportWindow::sendQueryToUrl(QUrl url) void MpcImportWindow::sendQueryToUrl(QUrl url)
{ {
//QUrl url; QUrlQuery q(url);
url.addQueryItem("ty","e");//Type: ephemerides q.addQueryItem("ty","e");//Type: ephemerides
url.addQueryItem("TextArea", query);//Object name query q.addQueryItem("TextArea", query);//Object name query
//url.addQueryItem("e", "-1");//Elements format: MPC 1-line //q.addQueryItem("e", "-1");//Elements format: MPC 1-line
//XEphem's format is used instead because it doesn't truncate object names. //XEphem's format is used instead because it doesn't truncate object names.
url.addQueryItem("e", "3");//Elements format: XEphem q.addQueryItem("e", "3");//Elements format: XEphem
//Yes, all of the rest are necessary //Yes, all of the rest are necessary
url.addQueryItem("d",""); q.addQueryItem("d","");
url.addQueryItem("l",""); q.addQueryItem("l","");
url.addQueryItem("i",""); q.addQueryItem("i","");
url.addQueryItem("u","d"); q.addQueryItem("u","d");
url.addQueryItem("uto", "0"); q.addQueryItem("uto", "0");
url.addQueryItem("c", ""); q.addQueryItem("c", "");
url.addQueryItem("long", ""); q.addQueryItem("long", "");
url.addQueryItem("lat", ""); q.addQueryItem("lat", "");
url.addQueryItem("alt", ""); q.addQueryItem("alt", "");
url.addQueryItem("raty", "a"); q.addQueryItem("raty", "a");
url.addQueryItem("s", "t"); q.addQueryItem("s", "t");
url.addQueryItem("m", "m"); q.addQueryItem("m", "m");
url.addQueryItem("adir", "S"); q.addQueryItem("adir", "S");
url.addQueryItem("oed", ""); q.addQueryItem("oed", "");
url.addQueryItem("resoc", ""); q.addQueryItem("resoc", "");
url.addQueryItem("tit", ""); q.addQueryItem("tit", "");
url.addQueryItem("bu", ""); q.addQueryItem("bu", "");
url.addQueryItem("ch", "c"); q.addQueryItem("ch", "c");
url.addQueryItem("ce", "f"); q.addQueryItem("ce", "f");
url.addQueryItem("js", "f"); q.addQueryItem("js", "f");
url.setQuery(q);
QNetworkRequest request(url); QNetworkRequest request(url);
request.setHeader(QNetworkRequest::ContentTypeHeader, request.setHeader(QNetworkRequest::ContentTypeHeader,
"application/x-www-form-urlencoded");//Is this rea lly necessary? "application/x-www-form-urlencoded");//Is this rea lly necessary?
request.setHeader(QNetworkRequest::ContentLengthHeader, request.setHeader(QNetworkRequest::ContentLengthHeader,
url.encodedQuery().length()); url.query(QUrl::FullyEncoded).length());
connect(networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT (receiveQueryReply(QNetworkReply*))); connect(networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT (receiveQueryReply(QNetworkReply*)));
queryReply = networkManager->post(request, url.encodedQuery()); queryReply = networkManager->post(request, url.query(QUrl::FullyEnco ded).toUtf8());
connect(queryReply, SIGNAL(downloadProgress(qint64,qint64)), this, S LOT(updateQueryProgress(qint64,qint64))); connect(queryReply, SIGNAL(downloadProgress(qint64,qint64)), this, S LOT(updateQueryProgress(qint64,qint64)));
} }
void MpcImportWindow::abortQuery() void MpcImportWindow::abortQuery()
{ {
if (queryReply == 0) if (queryReply == 0)
return; return;
disconnect(networkManager, SIGNAL(finished(QNetworkReply*)), this, S LOT(receiveQueryReply(QNetworkReply*))); disconnect(networkManager, SIGNAL(finished(QNetworkReply*)), this, S LOT(receiveQueryReply(QNetworkReply*)));
deleteQueryProgressBar(); deleteQueryProgressBar();
skipping to change at line 887 skipping to change at line 887
populateCandidateObjects(objects); populateCandidateObjects(objects);
ui->stackedWidget->setCurrentIndex(1); ui->stackedWidget->setCurrentIndex(1);
} }
} }
void MpcImportWindow::deleteQueryProgressBar() void MpcImportWindow::deleteQueryProgressBar()
{ {
disconnect(this, SLOT(updateQueryProgress(qint64,qint64))); disconnect(this, SLOT(updateQueryProgress(qint64,qint64)));
if (queryProgressBar) if (queryProgressBar)
{ {
queryProgressBar->setVisible(false); StelApp::getInstance().removeProgressBar(queryProgressBar);
queryProgressBar->deleteLater();
queryProgressBar = NULL; queryProgressBar = NULL;
} }
} }
void MpcImportWindow::startCountdown() void MpcImportWindow::startCountdown()
{ {
if (!countdownTimer->isActive()) if (!countdownTimer->isActive())
countdownTimer->start(1000);//1 second countdownTimer->start(1000);//1 second
//Disable the interface //Disable the interface
skipping to change at line 975 skipping to change at line 974
if (!bookmarks.value(MpcComets).isEmpty() && !bookma rks[MpcMinorPlanets].isEmpty()) if (!bookmarks.value(MpcComets).isEmpty() && !bookma rks[MpcMinorPlanets].isEmpty())
return; return;
} }
} }
qDebug() << "Bookmarks file can't be read. Hard-coded bookmarks will be used."; qDebug() << "Bookmarks file can't be read. Hard-coded bookmarks will be used.";
//Initialize with hard-coded values //Initialize with hard-coded values
bookmarks[MpcMinorPlanets].insert("MPC's list of bright minor planet s at opposition in 2011", "http://www.minorplanetcenter.net/iau/Ephemerides /Bright/2011/Soft00Bright.txt"); bookmarks[MpcMinorPlanets].insert("MPC's list of bright minor planet s at opposition in 2011", "http://www.minorplanetcenter.net/iau/Ephemerides /Bright/2011/Soft00Bright.txt");
bookmarks[MpcMinorPlanets].insert("MPC's list of bright minor planet s at opposition in 2013", "http://www.minorplanetcenter.net/iau/Ephemerides /Bright/2013/Soft00Bright.txt"); bookmarks[MpcMinorPlanets].insert("MPC's list of bright minor planet s at opposition in 2013", "http://www.minorplanetcenter.net/iau/Ephemerides /Bright/2013/Soft00Bright.txt");
bookmarks[MpcMinorPlanets].insert("MPC's list of bright minor planet s at opposition in 2014", "http://www.minorplanetcenter.net/iau/Ephemerides /Bright/2014/Soft00Bright.txt");
bookmarks[MpcMinorPlanets].insert("MPC's list of observable distant minor planets", "http://www.minorplanetcenter.net/iau/Ephemerides/Distant/S oft00Distant.txt"); bookmarks[MpcMinorPlanets].insert("MPC's list of observable distant minor planets", "http://www.minorplanetcenter.net/iau/Ephemerides/Distant/S oft00Distant.txt");
bookmarks[MpcMinorPlanets].insert("MPCORB: near-Earth asteroids (NEA s)", "http://www.minorplanetcenter.net/iau/MPCORB/NEA.txt"); bookmarks[MpcMinorPlanets].insert("MPCORB: near-Earth asteroids (NEA s)", "http://www.minorplanetcenter.net/iau/MPCORB/NEA.txt");
bookmarks[MpcMinorPlanets].insert("MPCORB: potentially hazardous ast eroids (PHAs)", "http://www.minorplanetcenter.net/iau/MPCORB/PHA.txt"); bookmarks[MpcMinorPlanets].insert("MPCORB: potentially hazardous ast eroids (PHAs)", "http://www.minorplanetcenter.net/iau/MPCORB/PHA.txt");
bookmarks[MpcMinorPlanets].insert("MPCORB: TNOs, Centaurs and SDOs", "http://www.minorplanetcenter.net/iau/MPCORB/Distant.txt"); bookmarks[MpcMinorPlanets].insert("MPCORB: TNOs, Centaurs and SDOs", "http://www.minorplanetcenter.net/iau/MPCORB/Distant.txt");
bookmarks[MpcMinorPlanets].insert("MPCORB: other unusual objects", " http://www.minorplanetcenter.net/iau/MPCORB/Unusual.txt"); bookmarks[MpcMinorPlanets].insert("MPCORB: other unusual objects", " http://www.minorplanetcenter.net/iau/MPCORB/Unusual.txt");
bookmarks[MpcMinorPlanets].insert("MPCORB: orbits from the latest DO U MPEC", "http://www.minorplanetcenter.net/iau/MPCORB/DAILY.DAT"); bookmarks[MpcMinorPlanets].insert("MPCORB: orbits from the latest DO U MPEC", "http://www.minorplanetcenter.net/iau/MPCORB/DAILY.DAT");
bookmarks[MpcComets].insert("MPC's list of observable comets", "http ://www.minorplanetcenter.net/iau/Ephemerides/Comets/Soft00Cmt.txt"); bookmarks[MpcComets].insert("MPC's list of observable comets", "http ://www.minorplanetcenter.net/iau/Ephemerides/Comets/Soft00Cmt.txt");
bookmarks[MpcComets].insert("MPCORB: comets", "http://www.minorplane tcenter.net/iau/MPCORB/CometEls.txt"); bookmarks[MpcComets].insert("MPCORB: comets", "http://www.minorplane tcenter.net/iau/MPCORB/CometEls.txt");
//Try to save them to a file //Try to save them to a file
 End of changes. 25 change blocks. 
72 lines changed or deleted 74 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/