72
73
: StelDialog(parent)
73
74
, nextStarCatalogToDownloadIndex(0)
74
75
, starCatalogsCount(0)
75
, starCatalogDownloadReply(NULL)
76
77
, currentDownloadFile(NULL)
77
78
, progressBar(NULL)
80
, hasDownloadedStarCatalog(false)
81
, isDownloadingStarCatalog(false)
82
, isDownloadingEphemData(false)
83
, customDeltaTEquationDialog(NULL)
80
85
ui = new Ui_configurationDialogForm;
81
customDeltaTEquationDialog = NULL;
82
hasDownloadedStarCatalog = false;
83
isDownloadingStarCatalog = false;
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();
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)));
182
connect(ui->de430checkBox, SIGNAL(clicked()), this, SLOT(de430ButtonClicked()));
183
connect(ui->de431checkBox, SIGNAL(clicked()), this, SLOT(de431ButtonClicked()));
185
resetStarCatalogControls();
186
resetEphemControls();
179
189
//Kinetic scrolling for tablet pc and pc
180
190
QList<QWidget *> addscroll;
1077
1087
void ConfigurationDialog::cancelDownload(void)
1079
1089
Q_ASSERT(currentDownloadFile);
1080
Q_ASSERT(starCatalogDownloadReply);
1090
Q_ASSERT(downloadReply);
1081
1091
qWarning() << "Aborting download";
1082
starCatalogDownloadReply->abort();
1092
downloadReply->abort();
1085
1095
void ConfigurationDialog::newStarCatalogData()
1087
1097
Q_ASSERT(currentDownloadFile);
1088
Q_ASSERT(starCatalogDownloadReply);
1098
Q_ASSERT(downloadReply);
1089
1099
Q_ASSERT(progressBar);
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));
1096
1106
void ConfigurationDialog::downloadStars()
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);
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)));
1132
1142
progressBar = StelApp::getInstance().addProgressBar();
1133
1143
progressBar->setValue(0);
1137
1147
qDebug() << "Downloading file" << nextStarCatalogToDownload.value("url").toString();
1150
void ConfigurationDialog::de430ButtonClicked()
1152
QSettings* conf = StelApp::getInstance().getSettings();
1155
StelApp::getInstance().getCore()->setDe430Active(!StelApp::getInstance().getCore()->de430IsActive());
1156
conf->setValue("astro/flag_use_de430", StelApp::getInstance().getCore()->de430IsActive());
1158
resetEphemControls(); //refresh labels
1161
void ConfigurationDialog::de431ButtonClicked()
1163
QSettings* conf = StelApp::getInstance().getSettings();
1166
StelApp::getInstance().getCore()->setDe431Active(!StelApp::getInstance().getCore()->de431IsActive());
1167
conf->setValue("astro/flag_use_de431", StelApp::getInstance().getCore()->de431IsActive());
1169
resetEphemControls(); //refresh labels
1172
void ConfigurationDialog::resetEphemControls()
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());
1179
if(StelApp::getInstance().getCore()->de430IsActive())
1180
ui->de430label->setText(q_("1550...2650"));
1183
if (StelApp::getInstance().getCore()->de430IsAvailable())
1184
ui->de430label->setText(q_("Available"));
1186
ui->de430label->setText(q_("Not Available"));
1188
if(StelApp::getInstance().getCore()->de431IsActive())
1189
ui->de431label->setText(q_("-13.000...17.000"));
1192
if (StelApp::getInstance().getCore()->de431IsAvailable())
1193
ui->de431label->setText(q_("Available"));
1195
ui->de431label->setText(q_("Not Available"));
1199
void ConfigurationDialog::downloadEphemData()
1201
// TODO in connection with the download manager!
1202
resetEphemControls();
1140
1205
void ConfigurationDialog::downloadError(QNetworkReply::NetworkError)
1142
1207
Q_ASSERT(currentDownloadFile);
1143
Q_ASSERT(starCatalogDownloadReply);
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);
1210
isDownloading = false;
1211
if(isDownloadingStarCatalog)
1213
isDownloadingStarCatalog = false;
1214
ui->getStarsButton->setVisible(false);
1215
ui->getStarsButton->setEnabled(true);
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);
1154
void ConfigurationDialog::downloadFinished()
1225
void ConfigurationDialog::ephemDataDownloadFinished()
1227
// TODO in connection with the download manager!
1231
void ConfigurationDialog::starsDownloadFinished()
1156
1233
Q_ASSERT(currentDownloadFile);
1157
Q_ASSERT(starCatalogDownloadReply);
1234
Q_ASSERT(downloadReply);
1158
1235
Q_ASSERT(progressBar);
1160
if (starCatalogDownloadReply->error()!=QNetworkReply::NoError)
1237
if (downloadReply->error()!=QNetworkReply::NoError)
1162
starCatalogDownloadReply->deleteLater();
1163
starCatalogDownloadReply = NULL;
1239
downloadReply->deleteLater();
1240
downloadReply = NULL;
1164
1241
currentDownloadFile->close();
1165
1242
currentDownloadFile->deleteLater();
1166
1243
currentDownloadFile = NULL;
1172
const QVariant& redirect = starCatalogDownloadReply->attribute(QNetworkRequest::RedirectionTargetAttribute);
1249
Q_ASSERT(downloadReply->bytesAvailable()==0);
1251
const QVariant& redirect = downloadReply->attribute(QNetworkRequest::RedirectionTargetAttribute);
1173
1252
if (!redirect.isNull())
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)));
1189
Q_ASSERT(starCatalogDownloadReply->bytesAvailable()==0);
1268
Q_ASSERT(downloadReply->bytesAvailable()==0);
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;