MpcImportWindow.cpp   MpcImportWindow.cpp 
skipping to change at line 18 skipping to change at line 18
* as published by the Free Software Foundation; either version 2 * as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. * of the License, or (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, U SA. * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
*/ */
#include "SolarSystemEditor.hpp" #include "SolarSystemEditor.hpp"
#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 "SolarSystem.hpp" #include "SolarSystem.hpp"
#include <QApplication> #include <QApplication>
#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>
skipping to change at line 73 skipping to change at line 74
bookmarks.insert(MpcComets, cometBookmarks); bookmarks.insert(MpcComets, cometBookmarks);
bookmarks.insert(MpcMinorPlanets, asteroidBookmarks); bookmarks.insert(MpcMinorPlanets, asteroidBookmarks);
candidateObjectsModel = new QStandardItemModel(this); candidateObjectsModel = new QStandardItemModel(this);
} }
MpcImportWindow::~MpcImportWindow() MpcImportWindow::~MpcImportWindow()
{ {
delete ui; delete ui;
delete countdownTimer; delete countdownTimer;
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(); downloadProgressBar->deleteLater();
if (queryProgressBar) if (queryProgressBar)
queryProgressBar->deleteLater(); queryProgressBar->deleteLater();
} }
void MpcImportWindow::createDialogContent() void MpcImportWindow::createDialogContent()
{ {
ui->setupUi(dialog); ui->setupUi(dialog);
//Signals //Signals
connect(&StelApp::getInstance(), SIGNAL(languageChanged()), this, SL OT(languageChanged())); 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())) ;
connect(ui->pushButtonAcquire, SIGNAL(clicked()), connect(ui->pushButtonAcquire, SIGNAL(clicked()),
this, SLOT(acquireObjectData())); this, SLOT(acquireObjectData()));
connect(ui->pushButtonAbortDownload, SIGNAL(clicked()), connect(ui->pushButtonAbortDownload, SIGNAL(clicked()),
this, SLOT(abortDownload())); this, SLOT(abortDownload()));
connect(ui->pushButtonAdd, SIGNAL(clicked()), this, SLOT(addObjects( ))); connect(ui->pushButtonAdd, SIGNAL(clicked()), this, SLOT(addObjects( )));
connect(ui->pushButtonDiscard, SIGNAL(clicked()), connect(ui->pushButtonDiscard, SIGNAL(clicked()),
this, SLOT(discardObjects())); this, SLOT(discardObjects()));
connect(ui->pushButtonBrowse, SIGNAL(clicked()), this, SLOT(selectFi le())); connect(ui->pushButtonBrowse, SIGNAL(clicked()), this, SLOT(selectFi le()));
connect(ui->pushButtonPasteURL, SIGNAL(clicked()),
this, SLOT(pasteClipboardURL()));
connect(ui->comboBoxBookmarks, SIGNAL(currentIndexChanged(QString)), connect(ui->comboBoxBookmarks, SIGNAL(currentIndexChanged(QString)),
this, SLOT(bookmarkSelected(QString))); this, SLOT(bookmarkSelected(QString)));
connect(ui->radioButtonFile, SIGNAL(toggled(bool)), connect(ui->radioButtonFile, SIGNAL(toggled(bool)),
ui->frameFile, SLOT(setVisible(bool))); ui->frameFile, SLOT(setVisible(bool)));
connect(ui->radioButtonURL, SIGNAL(toggled(bool)), connect(ui->radioButtonURL, SIGNAL(toggled(bool)),
ui->frameURL, SLOT(setVisible(bool))); ui->frameURL, SLOT(setVisible(bool)));
connect(ui->radioButtonAsteroids, SIGNAL(toggled(bool)), connect(ui->radioButtonAsteroids, SIGNAL(toggled(bool)),
this, SLOT(switchImportType(bool))); this, SLOT(switchImportType(bool)));
skipping to change at line 138 skipping to change at line 138
connect(countdownTimer, SIGNAL(timeout()), this, SLOT(updateCountdow n())); connect(countdownTimer, SIGNAL(timeout()), this, SLOT(updateCountdow n()));
QSortFilterProxyModel * filterProxyModel = new QSortFilterProxyModel (this); QSortFilterProxyModel * filterProxyModel = new QSortFilterProxyModel (this);
filterProxyModel->setSourceModel(candidateObjectsModel); filterProxyModel->setSourceModel(candidateObjectsModel);
filterProxyModel->setFilterCaseSensitivity(Qt::CaseInsensitive); filterProxyModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
ui->listViewObjects->setModel(filterProxyModel); ui->listViewObjects->setModel(filterProxyModel);
connect(ui->lineEditSearch, SIGNAL(textChanged(const QString&)), connect(ui->lineEditSearch, SIGNAL(textChanged(const QString&)),
filterProxyModel, SLOT(setFilterFixedString(const QString&)) ); filterProxyModel, SLOT(setFilterFixedString(const QString&)) );
loadBookmarks(); loadBookmarks();
updateTexts();
resetCountdown(); resetCountdown();
resetDialog(); resetDialog();
} }
void MpcImportWindow::updateTexts()
{
QString linkText("<a href=\"http://www.minorplanetcenter.net/iau/MPE
ph/MPEph.html\">Minor Planet &amp; Comet Ephemeris Service</a>");
// TRANSLATORS: A link showing the text "Minor Planet & Comet Epheme
ris Service" is inserted.
QString queryString(q_("Query the MPC's %1:"));
ui->labelQueryLink->setText(QString(queryString).arg(linkText));
QString firstLine(q_("Only one result will be returned if the query
is successful."));
QString secondLine(q_("Both comets and asteroids can be identified w
ith their number, name (in English) or provisional designation."));
QString cPrefix("<b>C/</b>");
QString pPrefix("<b>P/</b>");
QString cometQuery("<tt>C/Halley</tt>");
QString cometName("1P/Halley");
QString asteroidQuery("<tt>Halley</tt>");
QString asteroidName("(2688) Halley");
QString nameWarning(q_("Comet <i>names</i> need to be prefixed with
%1 or %2. If more than one comet matches a name, only the first result will
be returned. For example, searching for \"%3\" will return %4, Halley's Co
met, but a search for \"%5\" will return the asteroid %6."));
QString thirdLine = QString(nameWarning).arg(cPrefix, pPrefix, comet
Query,
cometName, asteroidQuer
y,
asteroidName);
ui->labelQueryInstructions->setText(QString("%1<br/>%2<br/>%3").arg(
firstLine, secondLine, thirdLine));
}
void MpcImportWindow::resetDialog() void MpcImportWindow::resetDialog()
{ {
ui->stackedWidget->setCurrentIndex(0); ui->stackedWidget->setCurrentIndex(0);
//ui->tabWidget->setCurrentIndex(0); //ui->tabWidget->setCurrentIndex(0);
ui->groupBoxType->setVisible(true); ui->groupBoxType->setVisible(true);
ui->radioButtonAsteroids->setChecked(true); ui->radioButtonAsteroids->setChecked(true);
ui->radioButtonURL->setChecked(true); ui->radioButtonURL->setChecked(true);
ui->frameFile->setVisible(false); ui->frameFile->setVisible(false);
skipping to change at line 177 skipping to change at line 200
//Resetting the dialog should not reset the timer //Resetting the dialog should not reset the timer
//resetCountdown(); //resetCountdown();
resetNotFound(); resetNotFound();
enableInterface(true); enableInterface(true);
} }
void MpcImportWindow::populateBookmarksList() void MpcImportWindow::populateBookmarksList()
{ {
ui->comboBoxBookmarks->clear(); ui->comboBoxBookmarks->clear();
ui->comboBoxBookmarks->addItem("Select bookmark..."); ui->comboBoxBookmarks->addItem("Select bookmark...");
QStringList bookmarkTitles(bookmarks.value(importType).keys()); QStringList bookmarkTitles(bookmarks.value(importType).keys());
bookmarkTitles.sort(); bookmarkTitles.sort();
ui->comboBoxBookmarks->addItems(bookmarkTitles); ui->comboBoxBookmarks->addItems(bookmarkTitles);
} }
void MpcImportWindow::languageChanged() void MpcImportWindow::retranslate()
{ {
if (dialog) if (dialog)
{
ui->retranslateUi(dialog); ui->retranslateUi(dialog);
updateTexts();
}
} }
void MpcImportWindow::acquireObjectData() void MpcImportWindow::acquireObjectData()
{ {
if (ui->radioButtonFile->isChecked()) if (ui->radioButtonFile->isChecked())
{ {
QString filePath = ui->lineEditFilePath->text(); QString filePath = ui->lineEditFilePath->text();
if (filePath.isEmpty()) if (filePath.isEmpty())
return; return;
skipping to change at line 296 skipping to change at line 322
void MpcImportWindow::pasteClipboardURL() void MpcImportWindow::pasteClipboardURL()
{ {
ui->lineEditURL->setText(QApplication::clipboard()->text()); ui->lineEditURL->setText(QApplication::clipboard()->text());
} }
void MpcImportWindow::selectFile() void MpcImportWindow::selectFile()
{ {
QString directory = QDesktopServices::storageLocation(QDesktopServic es::DesktopLocation); QString directory = QDesktopServices::storageLocation(QDesktopServic es::DesktopLocation);
if (directory.isEmpty()) if (directory.isEmpty())
directory = QDesktopServices::storageLocation(QDesktopServic es::HomeLocation); directory = QDesktopServices::storageLocation(QDesktopServic es::HomeLocation);
QString filePath = QFileDialog::getOpenFileName(NULL, "Select a text file", directory); QString filePath = QFileDialog::getOpenFileName(NULL, "Select a tex 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 675 skipping to change at line 701
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().getGui()->addProgressBar() ;
queryProgressBar->setValue(0); queryProgressBar->setValue(0);
queryProgressBar->setMaximum(0); queryProgressBar->setMaximum(0);
queryProgressBar->setFormat("Searching..."); queryProgressBar->setFormat("Searching...");
queryProgressBar->setVisible(true); 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"));
skipping to change at line 798 skipping to change at line 824
QString contentType = reply->header(QNetworkRequest::ContentTypeHead er).toString(); QString contentType = reply->header(QNetworkRequest::ContentTypeHead er).toString();
QString contentDisposition = reply->rawHeader(QByteArray("Content-di sposition")); QString contentDisposition = reply->rawHeader(QByteArray("Content-di sposition"));
if (contentType == "text/ascii" && if (contentType == "text/ascii" &&
contentDisposition == "attachment; filename=elements.txt") contentDisposition == "attachment; filename=elements.txt")
{ {
readQueryReply(reply); readQueryReply(reply);
} }
else else
{ {
ui->labelQueryMessage->setText("Object not found."); ui->labelQueryMessage->setText("Object not found.");
ui->labelQueryMessage->setVisible(true); ui->labelQueryMessage->setVisible(true);
enableInterface(true); enableInterface(true);
} }
reply->deleteLater(); reply->deleteLater();
queryReply = 0; queryReply = 0;
} }
void MpcImportWindow::readQueryReply(QNetworkReply * reply) void MpcImportWindow::readQueryReply(QNetworkReply * reply)
{ {
skipping to change at line 887 skipping to change at line 913
{ {
//Stop the timer //Stop the timer
if (countdownTimer->isActive()) if (countdownTimer->isActive())
{ {
countdownTimer->stop(); countdownTimer->stop();
//If the query is still active, kill it //If the query is still active, kill it
if (queryReply != 0 && queryReply->isRunning()) if (queryReply != 0 && queryReply->isRunning())
{ {
abortQuery(); abortQuery();
ui->labelQueryMessage->setText("The query timed out. You can try again, now or later."); ui->labelQueryMessage->setText("The query timed out . You can try again, now or later.");
ui->labelQueryMessage->setVisible(true); ui->labelQueryMessage->setVisible(true);
} }
} }
//Reset the counter //Reset the counter
countdown = 60; countdown = 60;
//Enable the interface //Enable the interface
ui->lineEditQuery->setEnabled(true); ui->lineEditQuery->setEnabled(true);
ui->pushButtonSendQuery->setEnabled(true); ui->pushButtonSendQuery->setEnabled(true);
 End of changes. 15 change blocks. 
10 lines changed or deleted 46 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/