4
* Copyright (C) 2010 Bogdan Marinov (add/remove landscapes feature)
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20
#include "AddRemoveLandscapesDialog.hpp"
21
#include "ui_addRemoveLandscapesDialog.h"
24
#include "LandscapeMgr.hpp"
25
#include "StelApp.hpp"
26
#include "StelModuleMgr.hpp"
27
#include "StelLocaleMgr.hpp"
30
#include <QFileDialog>
33
AddRemoveLandscapesDialog::AddRemoveLandscapesDialog()
35
ui = new Ui_addRemoveLandscapesDialogForm;
37
landscapeManager = GETSTELMODULE(LandscapeMgr);
39
lastUsedDirectoryPath = QDir::homePath();
41
//TODO: Find a way to have this initialized from CMake
42
defaultLandscapeIDs = (QStringList() << "guereins" << "trees" << "moon" << "hurricane" << "ocean" << "garching" << "mars" << "saturn");
45
AddRemoveLandscapesDialog::~AddRemoveLandscapesDialog()
50
void AddRemoveLandscapesDialog::languageChanged()
53
ui->retranslateUi(dialog);
56
// Initialize the dialog widgets and connect the signals/slots
57
void AddRemoveLandscapesDialog::createDialogContent()
61
//Connect all signals and slots here: sender, signal, receiver, method
62
connect(ui->closeStelWindow, SIGNAL(clicked()), this, SLOT(close()));
64
connect(ui->pushButtonAdd, SIGNAL(clicked()), this, SLOT(buttonAddClicked()));
65
connect(ui->listWidgetUserLandscapes, SIGNAL(currentRowChanged(int)), this, SLOT(landscapeListCurrentRowChanged(int)));
66
connect(ui->pushButtonRemove, SIGNAL(clicked()), this, SLOT(buttonRemoveClicked()));
67
connect(ui->pushButtonMessageOK, SIGNAL(clicked()), this, SLOT(messageAcknowledged()));
69
connect(landscapeManager, SIGNAL(landscapesChanged()), this, SLOT(populateLists()));
71
ui->groupBoxMessage->setVisible(false);
76
void AddRemoveLandscapesDialog::populateLists()
78
ui->listWidgetUserLandscapes->clear();
79
QStringList landscapes = landscapeManager->getAllLandscapeIDs();
80
foreach (QString landscapeID, defaultLandscapeIDs)
82
landscapes.removeAll(landscapeID);
84
if (!landscapes.isEmpty())
87
ui->listWidgetUserLandscapes->addItems(landscapes);
88
if((ui->listWidgetUserLandscapes->findItems(landscapeManager->getCurrentLandscapeID(), Qt::MatchExactly).isEmpty()))
90
//If the current landscape is not in the list, simply select the first row
91
ui->listWidgetUserLandscapes->setCurrentRow(0);
95
ui->listWidgetUserLandscapes->setCurrentItem(ui->listWidgetUserLandscapes->findItems(landscapeManager->getCurrentLandscapeID(), Qt::MatchExactly).first());
100
//Force disabling the side pane
101
landscapeListCurrentRowChanged(-1);
105
void AddRemoveLandscapesDialog::buttonAddClicked()
107
QString sourceArchivePath = QFileDialog::getOpenFileName(NULL, "Select a ZIP archive containing a Stellarium landscape...", lastUsedDirectoryPath, "ZIP archives (*.zip)");
108
bool useLandscape = ui->checkBoxUseLandscape->isChecked();
109
if (!sourceArchivePath.isEmpty() && QFile::exists(sourceArchivePath))
111
QString newLandscapeID = landscapeManager->installLandscapeFromArchive(sourceArchivePath, useLandscape);
112
if(!newLandscapeID.isEmpty())
115
displayMessage("Add", "Landscape installed successfully.");
116
ui->groupBoxAdd->setVisible(false);
117
//Make the new landscape selected in the list
118
//populateLists(); //No longer needed after the migration to signals/slots
119
ui->listWidgetUserLandscapes->setCurrentItem((ui->listWidgetUserLandscapes->findItems(newLandscapeID, Qt::MatchExactly)).first());
123
//Show an error message
124
displayMessage("Error!", "Landscape was not installed.");
125
ui->groupBoxAdd->setVisible(false);
130
void AddRemoveLandscapesDialog::buttonRemoveClicked()
132
QString landscapeID = ui->listWidgetUserLandscapes->currentItem()->data(0).toString();
133
if(landscapeManager->removeLandscape(landscapeID))
135
//populateLists();//No longer needed after the migration to signals/slots
136
//TODO: Display messages instead
141
void AddRemoveLandscapesDialog::landscapeListCurrentRowChanged(int newRow)
143
bool displaySidePane = (newRow >= 0);
144
ui->labelLandscapeName->setVisible(displaySidePane);
145
ui->labelLandscapeSize->setVisible(displaySidePane);
146
ui->pushButtonRemove->setEnabled(displaySidePane);
147
ui->labelWarning->setEnabled(displaySidePane);
149
if (!displaySidePane)
152
QString landscapeID = ui->listWidgetUserLandscapes->item(newRow)->data(0).toString();
154
ui->labelLandscapeName->setText("<h3>"+landscapeManager->loadLandscapeName(landscapeID)+"</h3>");
156
double landscapeSize = landscapeManager->loadLandscapeSize(landscapeID) / (double)(1024*1024);
157
ui->labelLandscapeSize->setText(QString("Size on disk: %1 MiB").arg(landscapeSize, 0, 'f', 2));
160
void AddRemoveLandscapesDialog::messageAcknowledged()
162
ui->groupBoxMessage->setVisible(false);
163
ui->groupBoxAdd->setVisible(true);
164
ui->labelMessage->clear();
167
void AddRemoveLandscapesDialog::displayMessage(QString title, QString message)
169
ui->labelMessage->setText(message);
170
ui->groupBoxMessage->setTitle(title);
171
ui->groupBoxMessage->setVisible(true);