~stellarium/stellarium/trunk

« back to all changes in this revision

Viewing changes to src/gui/ConfigurationDialog.cpp

  • Committer: georg-zotti
  • Date: 2016-01-16 17:11:08 UTC
  • mfrom: (7721.1.41 socis2015-de430)
  • Revision ID: georg.zotti@univie.ac.at-20160116171108-rng3giwntia88mnb
Merged in SoCiS2015 project to get planetary positions from JPL DE430 and DE431 ephemerides

Show diffs side-by-side

added added

removed removed

Lines of Context:
59
59
#include "SkyGui.hpp"
60
60
#include "StelJsonParser.hpp"
61
61
#include "StelTranslator.hpp"
 
62
#include "EphemWrapper.hpp"
62
63
 
63
64
#include <QSettings>
64
65
#include <QDebug>
72
73
        : StelDialog(parent)
73
74
        , nextStarCatalogToDownloadIndex(0)
74
75
        , starCatalogsCount(0)
75
 
        , starCatalogDownloadReply(NULL)
 
76
        , downloadReply(NULL)
76
77
        , currentDownloadFile(NULL)
77
78
        , progressBar(NULL)
78
79
        , gui(agui)
 
80
        , hasDownloadedStarCatalog(false)
 
81
        , isDownloadingStarCatalog(false)
 
82
        , isDownloadingEphemData(false)
 
83
        , customDeltaTEquationDialog(NULL)
79
84
{
80
85
        ui = new Ui_configurationDialogForm;
81
 
        customDeltaTEquationDialog = NULL;
82
 
        hasDownloadedStarCatalog = false;
83
 
        isDownloadingStarCatalog = false;
 
86
 
84
87
        savedProjectionType = StelApp::getInstance().getCore()->getCurrentProjectionType();
85
88
        // Get info about operating system
86
89
        QString platform = StelUtils::getOperatingSystemInfo();
170
173
        connect(ui->getStarsButton, SIGNAL(clicked()), this, SLOT(downloadStars()));
171
174
        connect(ui->downloadCancelButton, SIGNAL(clicked()), this, SLOT(cancelDownload()));
172
175
        connect(ui->downloadRetryButton, SIGNAL(clicked()), this, SLOT(downloadStars()));
173
 
        resetStarCatalogControls();
 
176
        
174
177
        ui->nutationCheckBox->setChecked(core->getUseNutation());
175
178
        connect(ui->nutationCheckBox, SIGNAL(toggled(bool)), core, SLOT(setUseNutation(bool)));
176
179
        ui->topocentricCheckBox->setChecked(core->getUseTopocentricCoordinates());
177
180
        connect(ui->topocentricCheckBox, SIGNAL(toggled(bool)), core, SLOT(setUseTopocentricCoordinates(bool)));
 
181
 
 
182
        connect(ui->de430checkBox, SIGNAL(clicked()), this, SLOT(de430ButtonClicked()));
 
183
        connect(ui->de431checkBox, SIGNAL(clicked()), this, SLOT(de431ButtonClicked()));
 
184
        
 
185
        resetStarCatalogControls();
 
186
        resetEphemControls();
 
187
 
178
188
#ifdef Q_OS_WIN
179
189
        //Kinetic scrolling for tablet pc and pc
180
190
        QList<QWidget *> addscroll;
1077
1087
void ConfigurationDialog::cancelDownload(void)
1078
1088
{
1079
1089
        Q_ASSERT(currentDownloadFile);
1080
 
        Q_ASSERT(starCatalogDownloadReply);
 
1090
        Q_ASSERT(downloadReply);
1081
1091
        qWarning() << "Aborting download";
1082
 
        starCatalogDownloadReply->abort();
 
1092
        downloadReply->abort();
1083
1093
}
1084
1094
 
1085
1095
void ConfigurationDialog::newStarCatalogData()
1086
1096
{
1087
1097
        Q_ASSERT(currentDownloadFile);
1088
 
        Q_ASSERT(starCatalogDownloadReply);
 
1098
        Q_ASSERT(downloadReply);
1089
1099
        Q_ASSERT(progressBar);
1090
1100
 
1091
 
        int size = starCatalogDownloadReply->bytesAvailable();
 
1101
        int size = downloadReply->bytesAvailable();
1092
1102
        progressBar->setValue((float)progressBar->getValue()+(float)size/1024);
1093
 
        currentDownloadFile->write(starCatalogDownloadReply->read(size));
 
1103
        currentDownloadFile->write(downloadReply->read(size));
1094
1104
}
1095
1105
 
1096
1106
void ConfigurationDialog::downloadStars()
1097
1107
{
1098
1108
        Q_ASSERT(!nextStarCatalogToDownload.isEmpty());
1099
1109
        Q_ASSERT(!isDownloadingStarCatalog);
1100
 
        Q_ASSERT(starCatalogDownloadReply==NULL);
 
1110
        Q_ASSERT(downloadReply==NULL);
1101
1111
        Q_ASSERT(currentDownloadFile==NULL);
1102
1112
        Q_ASSERT(progressBar==NULL);
1103
1113
 
1112
1122
                ui->downloadRetryButton->setVisible(true);
1113
1123
                return;
1114
1124
        }
1115
 
 
 
1125
        isDownloading = true;
1116
1126
        isDownloadingStarCatalog = true;
1117
1127
        updateStarCatalogControlsText();
1118
1128
        ui->downloadCancelButton->setVisible(true);
1124
1134
        req.setAttribute(QNetworkRequest::CacheSaveControlAttribute, false);
1125
1135
        req.setAttribute(QNetworkRequest::RedirectionTargetAttribute, false);
1126
1136
        req.setRawHeader("User-Agent", userAgent.toLatin1());
1127
 
        starCatalogDownloadReply = StelApp::getInstance().getNetworkAccessManager()->get(req);
1128
 
        starCatalogDownloadReply->setReadBufferSize(1024*1024*2);       
1129
 
        connect(starCatalogDownloadReply, SIGNAL(finished()), this, SLOT(downloadFinished()));
1130
 
        connect(starCatalogDownloadReply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(downloadError(QNetworkReply::NetworkError)));
 
1137
        downloadReply = StelApp::getInstance().getNetworkAccessManager()->get(req);
 
1138
        downloadReply->setReadBufferSize(1024*1024*2);  
 
1139
        connect(downloadReply, SIGNAL(finished()), this, SLOT(starsDownloadFinished()));
 
1140
        connect(downloadReply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(downloadError(QNetworkReply::NetworkError)));
1131
1141
 
1132
1142
        progressBar = StelApp::getInstance().addProgressBar();
1133
1143
        progressBar->setValue(0);
1137
1147
        qDebug() << "Downloading file" << nextStarCatalogToDownload.value("url").toString();
1138
1148
}
1139
1149
 
 
1150
void ConfigurationDialog::de430ButtonClicked()
 
1151
{
 
1152
        QSettings* conf = StelApp::getInstance().getSettings();
 
1153
        Q_ASSERT(conf);
 
1154
 
 
1155
        StelApp::getInstance().getCore()->setDe430Active(!StelApp::getInstance().getCore()->de430IsActive());
 
1156
        conf->setValue("astro/flag_use_de430", StelApp::getInstance().getCore()->de430IsActive());
 
1157
 
 
1158
        resetEphemControls(); //refresh labels
 
1159
}
 
1160
 
 
1161
void ConfigurationDialog::de431ButtonClicked()
 
1162
{
 
1163
        QSettings* conf = StelApp::getInstance().getSettings();
 
1164
        Q_ASSERT(conf);
 
1165
 
 
1166
        StelApp::getInstance().getCore()->setDe431Active(!StelApp::getInstance().getCore()->de431IsActive());
 
1167
        conf->setValue("astro/flag_use_de431", StelApp::getInstance().getCore()->de431IsActive());
 
1168
 
 
1169
        resetEphemControls(); //refresh labels
 
1170
}
 
1171
 
 
1172
void ConfigurationDialog::resetEphemControls()
 
1173
{
 
1174
        ui->de430checkBox->setEnabled(StelApp::getInstance().getCore()->de430IsAvailable());
 
1175
        ui->de431checkBox->setEnabled(StelApp::getInstance().getCore()->de431IsAvailable());
 
1176
        ui->de430checkBox->setChecked(StelApp::getInstance().getCore()->de430IsActive());
 
1177
        ui->de431checkBox->setChecked(StelApp::getInstance().getCore()->de431IsActive());
 
1178
 
 
1179
        if(StelApp::getInstance().getCore()->de430IsActive())
 
1180
                ui->de430label->setText(q_("1550...2650"));
 
1181
        else
 
1182
        {
 
1183
                if (StelApp::getInstance().getCore()->de430IsAvailable())
 
1184
                        ui->de430label->setText(q_("Available"));
 
1185
                else
 
1186
                        ui->de430label->setText(q_("Not Available"));
 
1187
        }
 
1188
        if(StelApp::getInstance().getCore()->de431IsActive())
 
1189
                ui->de431label->setText(q_("-13.000...17.000"));
 
1190
        else
 
1191
        {
 
1192
                if (StelApp::getInstance().getCore()->de431IsAvailable())
 
1193
                        ui->de431label->setText(q_("Available"));
 
1194
                else
 
1195
                        ui->de431label->setText(q_("Not Available"));
 
1196
        }
 
1197
}
 
1198
 
 
1199
void ConfigurationDialog::downloadEphemData()
 
1200
{
 
1201
        // TODO in connection with the download manager!
 
1202
        resetEphemControls();
 
1203
}
 
1204
 
1140
1205
void ConfigurationDialog::downloadError(QNetworkReply::NetworkError)
1141
1206
{
1142
1207
        Q_ASSERT(currentDownloadFile);
1143
 
        Q_ASSERT(starCatalogDownloadReply);
1144
 
 
1145
 
        isDownloadingStarCatalog = false;
1146
 
        qWarning() << "Error downloading file" << starCatalogDownloadReply->url() << ": " << starCatalogDownloadReply->errorString();
1147
 
        ui->downloadLabel->setText(q_("Error downloading %1:\n%2").arg(nextStarCatalogToDownload.value("id").toString()).arg(starCatalogDownloadReply->errorString()));
 
1208
        Q_ASSERT(downloadReply);
 
1209
 
 
1210
        isDownloading = false;
 
1211
    if(isDownloadingStarCatalog)
 
1212
    {
 
1213
        isDownloadingStarCatalog = false;
 
1214
        ui->getStarsButton->setVisible(false);
 
1215
                ui->getStarsButton->setEnabled(true);
 
1216
    }
 
1217
 
 
1218
        qWarning() << "Error downloading file" << downloadReply->url() << ": " << downloadReply->errorString();
 
1219
        ui->downloadLabel->setText(q_("Error downloading %1:\n%2").arg(nextStarCatalogToDownload.value("id").toString()).arg(downloadReply->errorString()));
1148
1220
        ui->downloadCancelButton->setVisible(false);
1149
1221
        ui->downloadRetryButton->setVisible(true);
1150
 
        ui->getStarsButton->setVisible(false);
1151
 
        ui->getStarsButton->setEnabled(true);
1152
 
}
1153
 
 
1154
 
void ConfigurationDialog::downloadFinished()
 
1222
        
 
1223
}
 
1224
 
 
1225
void ConfigurationDialog::ephemDataDownloadFinished()
 
1226
{
 
1227
        // TODO in connection with the download manager!
 
1228
 
 
1229
}
 
1230
 
 
1231
void ConfigurationDialog::starsDownloadFinished()
1155
1232
{
1156
1233
        Q_ASSERT(currentDownloadFile);
1157
 
        Q_ASSERT(starCatalogDownloadReply);
 
1234
        Q_ASSERT(downloadReply);
1158
1235
        Q_ASSERT(progressBar);
1159
1236
 
1160
 
        if (starCatalogDownloadReply->error()!=QNetworkReply::NoError)
 
1237
        if (downloadReply->error()!=QNetworkReply::NoError)
1161
1238
        {
1162
 
                starCatalogDownloadReply->deleteLater();
1163
 
                starCatalogDownloadReply = NULL;
 
1239
                downloadReply->deleteLater();
 
1240
                downloadReply = NULL;
1164
1241
                currentDownloadFile->close();
1165
1242
                currentDownloadFile->deleteLater();
1166
1243
                currentDownloadFile = NULL;
1169
1246
                return;
1170
1247
        }
1171
1248
 
1172
 
        const QVariant& redirect = starCatalogDownloadReply->attribute(QNetworkRequest::RedirectionTargetAttribute);
 
1249
        Q_ASSERT(downloadReply->bytesAvailable()==0);
 
1250
 
 
1251
        const QVariant& redirect = downloadReply->attribute(QNetworkRequest::RedirectionTargetAttribute);
1173
1252
        if (!redirect.isNull())
1174
1253
        {
1175
1254
                // We got a redirection, we need to follow
1176
 
                starCatalogDownloadReply->deleteLater();
 
1255
                downloadReply->deleteLater();
1177
1256
                QNetworkRequest req(redirect.toUrl());
1178
1257
                req.setAttribute(QNetworkRequest::CacheSaveControlAttribute, false);
1179
1258
                req.setAttribute(QNetworkRequest::RedirectionTargetAttribute, false);
1180
1259
                req.setRawHeader("User-Agent", userAgent.toLatin1());
1181
 
                starCatalogDownloadReply = StelApp::getInstance().getNetworkAccessManager()->get(req);
1182
 
                starCatalogDownloadReply->setReadBufferSize(1024*1024*2);
1183
 
                connect(starCatalogDownloadReply, SIGNAL(readyRead()), this, SLOT(newStarCatalogData()));
1184
 
                connect(starCatalogDownloadReply, SIGNAL(finished()), this, SLOT(downloadFinished()));
1185
 
                connect(starCatalogDownloadReply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(downloadError(QNetworkReply::NetworkError)));
 
1260
                downloadReply = StelApp::getInstance().getNetworkAccessManager()->get(req);
 
1261
                downloadReply->setReadBufferSize(1024*1024*2);
 
1262
                connect(downloadReply, SIGNAL(readyRead()), this, SLOT(newStarCatalogData()));
 
1263
                connect(downloadReply, SIGNAL(finished()), this, SLOT(starsDownloadFinished()));
 
1264
                connect(downloadReply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(downloadError(QNetworkReply::NetworkError)));
1186
1265
                return;
1187
1266
        }
1188
1267
 
1189
 
        Q_ASSERT(starCatalogDownloadReply->bytesAvailable()==0);
 
1268
        Q_ASSERT(downloadReply->bytesAvailable()==0);
1190
1269
 
1191
1270
        isDownloadingStarCatalog = false;
 
1271
        isDownloading = false;
1192
1272
        currentDownloadFile->close();
1193
1273
        currentDownloadFile->deleteLater();
1194
1274
        currentDownloadFile = NULL;
1195
 
        starCatalogDownloadReply->deleteLater();
1196
 
        starCatalogDownloadReply = NULL;
 
1275
        downloadReply->deleteLater();
 
1276
        downloadReply = NULL;
1197
1277
        StelApp::getInstance().removeProgressBar(progressBar);
1198
1278
        progressBar=NULL;
1199
1279