bool SolarSystemEditor::replaceSolarSystemConfigurationFileWith(QString filePath) { if (!QFile::exists(filePath)) { //TODO: Message return false; } //Is it a valid configuration file? QSettings settings(filePath, QSettings::IniFormat); if (settings.status() != QSettings::NoError) { qWarning() << QDir::toNativeSeparators(filePath) << "is not a valid configuration file."; return false; } //Remove the existingfile if (QFile::exists(customSolarSystemFilePath)) { if(!QFile::remove(customSolarSystemFilePath)) { //TODO: Message return false; } } //Copy the new file //If the copy fails, reset to the default configuration if (QFile::copy(filePath, customSolarSystemFilePath)) { solarSystemManager->reloadPlanets(); emit solarSystemChanged(); return true; } else { //TODO: Message if (cloneSolarSystemConfigurationFile()) { solarSystemManager->reloadPlanets(); emit solarSystemChanged(); return true; } else { //TODO: Message return false; } } }
void SolarSystemEditor::resetSolarSystemToDefault() { if (isInitialized) { if (resetSolarSystemConfigurationFile()) { //Deselect all currently selected objects StelObjectMgr * objectManager = GETSTELMODULE(StelObjectMgr); //TODO objectManager->unSelect(); solarSystemManager->reloadPlanets(); emit solarSystemChanged(); } } }
void SolarSystemManagerWindow::createDialogContent() { ui->setupUi(dialog); #ifdef Q_OS_WIN //Kinetic scrolling for tablet pc and pc QList<QWidget *> addscroll; addscroll << ui->listWidgetObjects; installKineticScrolling(addscroll); #endif //Signals connect(&StelApp::getInstance(), SIGNAL(languageChanged()), this, SLOT(retranslate())); connect(ui->closeStelWindow, SIGNAL(clicked()), this, SLOT(close())); connect(ui->TitleBar, SIGNAL(movedTo(QPoint)), this, SLOT(handleMovedTo(QPoint))); connect(ui->pushButtonCopyFile, SIGNAL(clicked()), this, SLOT(copyConfiguration())); connect(ui->pushButtonReplaceFile, SIGNAL(clicked()), this, SLOT(replaceConfiguration())); connect(ui->pushButtonRemove, SIGNAL(clicked()), this, SLOT(removeObject())); connect(ui->pushButtonImportMPC, SIGNAL(clicked()), this, SLOT(newImportMPC())); //connect(ui->pushButtonManual, SIGNAL(clicked()), this, SLOT(newImportManual())); connect(ssoManager, SIGNAL(solarSystemChanged()), this, SLOT(populateSolarSystemList())); connect(ui->pushButtonReset, SIGNAL(clicked()), ssoManager, SLOT(resetSolarSystemToDefault())); // bug #1350669 (https://bugs.launchpad.net/stellarium/+bug/1350669) connect(ui->listWidgetObjects, SIGNAL(currentRowChanged(int)), ui->listWidgetObjects, SLOT(repaint())); updateTexts(); Q_ASSERT(mpcImportWindow); //Rebuild the list if any planets have been imported connect(mpcImportWindow, SIGNAL(objectsImported()), this, SLOT(populateSolarSystemList())); ui->lineEditUserFilePath->setText(ssoManager->getCustomSolarSystemFilePath()); populateSolarSystemList(); }
void MpcImportWindow::addObjects() { disconnect(ssoManager, SIGNAL(solarSystemChanged()), this, SLOT(resetDialog())); QList<QString> checkedObjectsNames; //Extract the marked objects //TODO: Something smarter? for (int row = 0; row < candidateObjectsModel->rowCount(); row++) { QStandardItem * item = candidateObjectsModel->item(row); if (item->checkState() == Qt::Checked) { checkedObjectsNames.append(item->text()); } } //qDebug() << "Checked:" << checkedObjectsNames; QList<SsoElements> approvedForAddition; for (int i = 0; i < candidatesForAddition.count(); i++) { QString name = candidatesForAddition.at(i).value("name").toString(); if (checkedObjectsNames.contains(name)) approvedForAddition.append(candidatesForAddition.at(i)); } bool overwrite = ui->radioButtonOverwrite->isChecked(); QList<SsoElements> approvedForUpdate; for (int j = 0; j < candidatesForUpdate.count(); j++) { QString name = candidatesForUpdate.at(j).value("name").toString(); if (checkedObjectsNames.contains(name)) { if (overwrite) { approvedForAddition.append(candidatesForUpdate.at(j)); } else { approvedForUpdate.append(candidatesForUpdate.at(j)); } } } //Write to file ssoManager->appendToSolarSystemConfigurationFile(approvedForAddition); if (ui->radioButtonUpdate->isChecked()) { SolarSystemEditor::UpdateFlags flags(SolarSystemEditor::UpdateNameAndNumber | SolarSystemEditor::UpdateOrbitalElements); if (!ui->checkBoxOnlyOrbitalElements->isChecked()) { flags |= SolarSystemEditor::UpdateType; flags |= SolarSystemEditor::UpdateMagnitudeParameters; } ssoManager->updateSolarSystemConfigurationFile(approvedForUpdate, flags); } //Refresh the Solar System GETSTELMODULE(SolarSystem)->reloadPlanets(); resetDialog(); emit objectsImported(); }