MpcImportWindow.cpp   MpcImportWindow.cpp 
skipping to change at line 34 skipping to change at line 34
#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 "SolarSystem.hpp" #include "SolarSystem.hpp"
#include <QApplication> #include <QApplication>
#include <QClipboard> #include <QClipboard>
#include <QDesktopServices>
#include <QFileDialog> #include <QFileDialog>
#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 <QString> #include <QString>
#include <QTemporaryFile> #include <QTemporaryFile>
#include <QTimer> #include <QTimer>
#include <QUrl> #include <QUrl>
MpcImportWindow::MpcImportWindow() : MpcImportWindow::MpcImportWindow() :
downloadReply(0), downloadReply(0),
queryReply(0), queryReply(0),
downloadProgressBar(0), downloadProgressBar(0),
queryProgressBar(0) queryProgressBar(0)
skipping to change at line 62 skipping to change at line 65
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;
bookmarks.insert(MpcComets, cometBookmarks); bookmarks.insert(MpcComets, cometBookmarks);
bookmarks.insert(MpcMinorPlanets, asteroidBookmarks); bookmarks.insert(MpcMinorPlanets, asteroidBookmarks);
candidateObjectsModel = new QStandardItemModel(this);
} }
MpcImportWindow::~MpcImportWindow() MpcImportWindow::~MpcImportWindow()
{ {
delete ui; delete ui;
delete countdownTimer; delete countdownTimer;
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(languageChanged()));
connect(ui->closeStelWindow, SIGNAL(clicked()), this, SLOT(close())) ; connect(ui->closeStelWindow, SIGNAL(clicked()), this, SLOT(close())) ;
connect(ui->pushButtonAcquire, SIGNAL(clicked()), this, SLOT(acquire connect(ui->pushButtonAcquire, SIGNAL(clicked()),
ObjectData())); this, SLOT(acquireObjectData()));
connect(ui->pushButtonAbortDownload, SIGNAL(clicked()), this, SLOT(a connect(ui->pushButtonAbortDownload, SIGNAL(clicked()),
bortDownload())); this, SLOT(abortDownload()));
connect(ui->pushButtonAdd, SIGNAL(clicked()), this, SLOT(addObjects( ))); connect(ui->pushButtonAdd, SIGNAL(clicked()), this, SLOT(addObjects( )));
connect(ui->pushButtonDiscard, SIGNAL(clicked()), this, SLOT(discard connect(ui->pushButtonDiscard, SIGNAL(clicked()),
Objects())); 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(pasteC connect(ui->pushButtonPasteURL, SIGNAL(clicked()),
lipboardURL())); 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->radioButtonSingle, SIGNAL(toggled(bool)), ui->frameSin connect(ui->radioButtonFile, SIGNAL(toggled(bool)),
gle, SLOT(setVisible(bool))); ui->frameFile, SLOT(setVisible(bool)));
connect(ui->radioButtonFile, SIGNAL(toggled(bool)), ui->frameFile, S connect(ui->radioButtonURL, SIGNAL(toggled(bool)),
LOT(setVisible(bool))); ui->frameURL, SLOT(setVisible(bool)));
connect(ui->radioButtonURL, SIGNAL(toggled(bool)), ui->frameURL, SLO
T(setVisible(bool))); connect(ui->radioButtonAsteroids, SIGNAL(toggled(bool)),
this, SLOT(switchImportType(bool)));
connect(ui->radioButtonAsteroids, SIGNAL(toggled(bool)), this, SLOT( connect(ui->radioButtonComets, SIGNAL(toggled(bool)),
switchImportType(bool))); this, SLOT(switchImportType(bool)));
connect(ui->radioButtonComets, SIGNAL(toggled(bool)), this, SLOT(swi
tchImportType(bool))); connect(ui->pushButtonMarkAll, SIGNAL(clicked()),
this, SLOT(markAll()));
connect(ui->pushButtonMarkAll, SIGNAL(clicked()), this, SLOT(markAll connect(ui->pushButtonMarkNone, SIGNAL(clicked()),
())); this, SLOT(unmarkAll()));
connect(ui->pushButtonMarkNone, SIGNAL(clicked()), this, SLOT(unmark
All())); connect(ui->pushButtonSendQuery, SIGNAL(clicked()),
this, SLOT(sendQuery()));
connect(ui->pushButtonSendQuery, SIGNAL(clicked()), this, SLOT(sendQ connect(ui->pushButtonAbortQuery, SIGNAL(clicked()),
uery())); this, SLOT(abortQuery()));
connect(ui->pushButtonAbortQuery, SIGNAL(clicked()), this, SLOT(abor connect(ui->lineEditQuery, SIGNAL(textEdited(QString)),
tQuery())); this, SLOT(resetNotFound()));
connect(ui->lineEditQuery, SIGNAL(textEdited(QString)), this, SLOT(r
esetNotFound()));
//connect(ui->lineEditQuery, SIGNAL(editingFinished()), this, SLOT(s endQuery())); //connect(ui->lineEditQuery, SIGNAL(editingFinished()), this, SLOT(s endQuery()));
connect(countdownTimer, SIGNAL(timeout()), this, SLOT(updateCountdow n())); connect(countdownTimer, SIGNAL(timeout()), this, SLOT(updateCountdow n()));
QSortFilterProxyModel * filterProxyModel = new QSortFilterProxyModel
(this);
filterProxyModel->setSourceModel(candidateObjectsModel);
filterProxyModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
ui->listViewObjects->setModel(filterProxyModel);
connect(ui->lineEditSearch, SIGNAL(textChanged(const QString&)),
filterProxyModel, SLOT(setFilterFixedString(const QString&))
);
loadBookmarks(); loadBookmarks();
resetCountdown(); resetCountdown();
resetDialog(); resetDialog();
} }
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->radioButtonFile->setChecked(true); ui->radioButtonURL->setChecked(true);
ui->frameURL->setVisible(false); ui->frameFile->setVisible(false);
ui->lineEditFilePath->clear(); ui->lineEditFilePath->clear();
ui->lineEditQuery->clear(); ui->lineEditQuery->clear();
ui->lineEditURL->setText("http://"); ui->lineEditURL->setText("http://");
ui->checkBoxAddBookmark->setChecked(false); ui->checkBoxAddBookmark->setChecked(false);
ui->frameBookmarkTitle->setVisible(false); ui->frameBookmarkTitle->setVisible(false);
ui->comboBoxBookmarks->setCurrentIndex(0); ui->comboBoxBookmarks->setCurrentIndex(0);
ui->radioButtonUpdate->setChecked(true); ui->radioButtonUpdate->setChecked(true);
ui->checkBoxOnlyOrbitalElements->setChecked(true); ui->checkBoxOnlyOrbitalElements->setChecked(true);
skipping to change at line 196 skipping to change at line 222
//close(); //close();
} }
void MpcImportWindow::addObjects() void MpcImportWindow::addObjects()
{ {
disconnect(ssoManager, SIGNAL(solarSystemChanged()), this, SLOT(rese tDialog())); disconnect(ssoManager, SIGNAL(solarSystemChanged()), this, SLOT(rese tDialog()));
QList<QString> checkedObjectsNames; QList<QString> checkedObjectsNames;
//Extract the marked objects //Extract the marked objects
while (ui->listWidgetObjects->count() > 0) //TODO: Something smarter?
for (int row = 0; row < candidateObjectsModel->rowCount(); row++)
{ {
QListWidgetItem * item = ui->listWidgetObjects->takeItem(0); QStandardItem * item = candidateObjectsModel->item(row);
if (item->checkState() == Qt::Checked) if (item->checkState() == Qt::Checked)
{ {
checkedObjectsNames.append(item->text()); checkedObjectsNames.append(item->text());
} }
delete item;
} }
//qDebug() << "Checked:" << checkedObjectsNames; //qDebug() << "Checked:" << checkedObjectsNames;
QList<SsoElements> approvedForAddition; QList<SsoElements> approvedForAddition;
for (int i = 0; i < candidatesForAddition.count(); i++) for (int i = 0; i < candidatesForAddition.count(); i++)
{ {
QString name = candidatesForAddition.at(i).value("name").toS tring(); QString name = candidatesForAddition.at(i).value("name").toS tring();
if (checkedObjectsNames.contains(name)) if (checkedObjectsNames.contains(name))
approvedForAddition.append(candidatesForAddition.at( i)); approvedForAddition.append(candidatesForAddition.at( i));
} }
skipping to change at line 267 skipping to change at line 293
resetDialog(); resetDialog();
} }
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 filePath = QFileDialog::getOpenFileName(NULL, "Select a text QString directory = QDesktopServices::storageLocation(QDesktopServic
file", StelFileMgr::getDesktopDir()); es::DesktopLocation);
if (directory.isEmpty())
directory = QDesktopServices::storageLocation(QDesktopServic
es::HomeLocation);
QString filePath = QFileDialog::getOpenFileName(NULL, "Select a text
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 296 skipping to change at line 325
//Get a list of the current objects //Get a list of the current objects
QHash<QString,QString> defaultSsoIdentifiers = ssoManager->getDefaul tSsoIdentifiers(); QHash<QString,QString> defaultSsoIdentifiers = ssoManager->getDefaul tSsoIdentifiers();
QHash<QString,QString> loadedSsoIdentifiers = ssoManager->listAllLoa dedSsoIdentifiers(); QHash<QString,QString> loadedSsoIdentifiers = ssoManager->listAllLoa dedSsoIdentifiers();
//Separating the objects into visual groups in the list //Separating the objects into visual groups in the list
int newDefaultSsoIndex = 0; int newDefaultSsoIndex = 0;
int newLoadedSsoIndex = 0; int newLoadedSsoIndex = 0;
int newNovelSsoIndex = 0; int newNovelSsoIndex = 0;
int insertionIndex = 0; int insertionIndex = 0;
QListWidget * list = ui->listWidgetObjects; QStandardItemModel * model = candidateObjectsModel;
list->clear(); model->clear();
model->setColumnCount(1);
foreach (SsoElements object, objects) foreach (SsoElements object, objects)
{ {
QString name = object.value("name").toString(); QString name = object.value("name").toString();
if (name.isEmpty()) if (name.isEmpty())
continue; continue;
QString group = object.value("section_name").toString(); QString group = object.value("section_name").toString();
if (group.isEmpty()) if (group.isEmpty())
continue; continue;
//Prevent name conflicts between asteroids and moons //Prevent name conflicts between asteroids and moons
if (loadedSsoIdentifiers.contains(name)) if (loadedSsoIdentifiers.contains(name))
{ {
if (loadedSsoIdentifiers.value(name) != group) if (loadedSsoIdentifiers.value(name) != group)
{ {
name.append('*'); name.append('*');
object.insert("name", name); object.insert("name", name);
} }
} }
QListWidgetItem * item = new QListWidgetItem(); QStandardItem * item = new QStandardItem();
item->setText(name); item->setText(name);
item->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled); item->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
item->setCheckState(Qt::Unchecked); item->setCheckState(Qt::Unchecked);
if (defaultSsoIdentifiers.contains(name)) if (defaultSsoIdentifiers.contains(name))
{ {
//Duplicate of a default solar system object //Duplicate of a default solar system object
QFont itemFont(item->font()); QFont itemFont(item->font());
itemFont.setBold(true); itemFont.setBold(true);
item->setFont(itemFont); item->setFont(itemFont);
skipping to change at line 358 skipping to change at line 389
newNovelSsoIndex++; newNovelSsoIndex++;
} }
else else
{ {
candidatesForAddition.append(object); candidatesForAddition.append(object);
insertionIndex = newNovelSsoIndex; insertionIndex = newNovelSsoIndex;
newNovelSsoIndex++; newNovelSsoIndex++;
} }
list->insertItem(insertionIndex, item); model->insertRow(insertionIndex, item);
} }
//Select the first item //Scroll to the first items
if (list->count() > 0) ui->listViewObjects->scrollToTop();
list->setCurrentRow(0);
} }
void MpcImportWindow::enableInterface(bool enable) void MpcImportWindow::enableInterface(bool enable)
{ {
ui->groupBoxType->setVisible(enable); ui->groupBoxType->setVisible(enable);
ui->frameFile->setEnabled(enable); ui->frameFile->setEnabled(enable);
ui->frameURL->setEnabled(enable); ui->frameURL->setEnabled(enable);
ui->radioButtonFile->setEnabled(enable); ui->radioButtonFile->setEnabled(enable);
skipping to change at line 431 skipping to change at line 461
//ui->lineEditSingle->clear(); //ui->lineEditSingle->clear();
ui->lineEditFilePath->clear(); ui->lineEditFilePath->clear();
ui->lineEditURL->clear(); ui->lineEditURL->clear();
//If one of the options is selected, show the rest of the dialog //If one of the options is selected, show the rest of the dialog
ui->groupBoxSource->setVisible(true); ui->groupBoxSource->setVisible(true);
} }
void MpcImportWindow::markAll() void MpcImportWindow::markAll()
{ {
QListWidget * const list = ui->listWidgetObjects; int rowCount = candidateObjectsModel->rowCount();
int rowCount = list->count();
if (rowCount < 1) if (rowCount < 1)
return; return;
for (int row = 0; row < rowCount; row++) for (int row = 0; row < rowCount; row++)
{ {
QListWidgetItem * item = list->item(row); QStandardItem * item = candidateObjectsModel->item(row);
if (item) if (item)
{ {
item->setCheckState(Qt::Checked); item->setCheckState(Qt::Checked);
} }
} }
} }
void MpcImportWindow::unmarkAll() void MpcImportWindow::unmarkAll()
{ {
QListWidget * const list = ui->listWidgetObjects; int rowCount = candidateObjectsModel->rowCount();
int rowCount = list->count();
if (rowCount < 1) if (rowCount < 1)
return; return;
for (int row = 0; row < rowCount; row++) for (int row = 0; row < rowCount; row++)
{ {
QListWidgetItem * item = list->item(row); QStandardItem * item = candidateObjectsModel->item(row);
if (item) if (item)
{ {
item->setCheckState(Qt::Unchecked); item->setCheckState(Qt::Unchecked);
} }
} }
} }
void MpcImportWindow::updateDownloadProgress(qint64 bytesReceived, qint64 b ytesTotal) void MpcImportWindow::updateDownloadProgress(qint64 bytesReceived, qint64 b ytesTotal)
{ {
if (downloadProgressBar == NULL) if (downloadProgressBar == NULL)
 End of changes. 22 change blocks. 
54 lines changed or deleted 71 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/