7 #include "modcalcsidtime.h"
9 #include "kstarsdata.h"
10 #include "kstarsdatetime.h"
11 #include "ksnotification.h"
12 #include "dialogs/locationdialog.h"
16 #include <QTextStream>
19 #include <qtskipemptyparts.h>
21 modCalcSidTime::modCalcSidTime(
QWidget *parent) :
QFrame(parent)
26 showCurrentTimeAndLocation();
29 connect(LocationButton, SIGNAL(clicked()),
this, SLOT(slotChangeLocation()));
30 connect(Date, SIGNAL(dateChanged(
QDate)),
this, SLOT(slotChangeDate()));
34 connect(LocationCheckBatch, SIGNAL(clicked()),
this, SLOT(slotLocationChecked()));
35 connect(DateCheckBatch, SIGNAL(clicked()),
this, SLOT(slotDateChecked()));
36 connect(LocationCheckBatch, SIGNAL(clicked()),
this, SLOT(slotHelpLabel()));
37 connect(DateCheckBatch, SIGNAL(clicked()),
this, SLOT(slotHelpLabel()));
38 connect(ComputeComboBatch, SIGNAL(currentIndexChanged(
int)),
this, SLOT(slotHelpLabel()));
40 connect(InputFileBatch, SIGNAL(urlSelected(
QUrl)),
this, SLOT(slotCheckFiles()));
41 connect(OutputFileBatch, SIGNAL(urlSelected(
QUrl)),
this, SLOT(slotCheckFiles()));
42 connect(LocationButtonBatch, SIGNAL(clicked()),
this, SLOT(slotLocationBatch()));
43 connect(RunButtonBatch, SIGNAL(clicked()),
this, SLOT(slotRunBatch()));
44 connect(ViewButtonBatch, SIGNAL(clicked()),
this, SLOT(slotViewBatch()));
46 RunButtonBatch->setEnabled(
false);
47 ViewButtonBatch->setEnabled(
false);
52 void modCalcSidTime::showCurrentTimeAndLocation()
55 LT->setTime(data->
lt().
time());
56 Date->setDate(data->
lt().
date());
59 LocationButton->setText(geo->
fullName());
60 geoBatch = data->
geo();
61 LocationButtonBatch->setText(geoBatch->
fullName());
63 slotConvertST(LT->time());
66 void modCalcSidTime::slotChangeLocation()
76 LocationButton->setText(geo->
fullName());
79 slotConvertST(LT->time());
85 void modCalcSidTime::slotChangeDate()
87 slotConvertST(LT->time());
90 void modCalcSidTime::slotConvertST(
const QTime <)
93 ST->blockSignals(
true);
94 ST->setTime(computeLTtoST(lt));
95 ST->blockSignals(
false);
98 void modCalcSidTime::slotConvertLT(
const QTime &st)
101 LT->blockSignals(
true);
102 LT->setTime(computeSTtoLT(st));
103 LT->blockSignals(
false);
109 dms st = geo->GSTtoLST(utdt.
gst());
118 dms gst = geo->LSTtoGST(lst);
123 void modCalcSidTime::slotDateChecked()
125 DateBatch->setEnabled(!DateCheckBatch->isChecked());
128 void modCalcSidTime::slotLocationChecked()
130 LocationButtonBatch->setEnabled(!LocationCheckBatch->isChecked());
132 if (LocationCheckBatch->isChecked())
135 "comma-separated names of the city, province and country. "
136 "If the string contains spaces, enclose it in quotes so it "
137 "gets parsed properly.");
140 "DontShowLocationStringMessageBox");
144 void modCalcSidTime::slotHelpLabel()
147 if (ComputeComboBatch->currentIndex() == 0)
155 if (LocationCheckBatch->checkState() ==
Qt::Checked)
158 QString inListString = inList[0];
159 if (inList.
size() == 2)
160 inListString =
i18n(
"%1 and %2", inList[0], inList[1]);
161 if (inList.
size() == 3)
162 inListString =
i18n(
"%1, %2 and %3", inList[0], inList[1], inList[2]);
164 HelpLabel->setText(
i18n(
"Specify %1 in the input file.", inListString));
167 void modCalcSidTime::slotLocationBatch()
177 LocationButtonBatch->setText(geoBatch->
fullName());
183 void modCalcSidTime::slotCheckFiles()
185 if (!InputFileBatch->lineEdit()->text().isEmpty() && !OutputFileBatch->lineEdit()->text().isEmpty())
187 RunButtonBatch->setEnabled(
true);
191 RunButtonBatch->setEnabled(
false);
195 void modCalcSidTime::slotRunBatch()
197 QString inputFileName = InputFileBatch->url().toLocalFile();
201 QFile f(inputFileName);
205 KSNotification::sorry(
message,
i18n(
"Could Not Open File"));
206 inputFileName.
clear();
211 processLines(istream);
213 ViewButtonBatch->setEnabled(
true);
220 KSNotification::sorry(
message,
i18n(
"Invalid file"));
221 inputFileName.
clear();
226 void modCalcSidTime::processLines(
QTextStream &istream)
228 QFile fOut(OutputFileBatch->url().toLocalFile());
234 QTime inTime, outTime;
237 if (!DateCheckBatch->isChecked())
238 dt = DateBatch->date();
240 while (!istream.
atEnd())
248 if (LocationCheckBatch->isChecked())
254 if (line.
count(q) == 2)
257 int iEnd = line.
indexOf(q, iStart + 1);
258 QString locationString = line.
mid(iStart, iEnd - iStart + 1);
259 line.
remove(locationString);
264 for (
int i = 0; i < locationFields.
size(); i++)
265 locationFields[i] = locationFields[i].trimmed();
267 if (locationFields.
size() == 1)
268 locationFields.
insert(1,
"");
269 if (locationFields.
size() == 2)
270 locationFields.
insert(1,
"");
271 if (locationFields.
size() != 3)
273 qDebug() << Q_FUNC_INFO <<
"Error: could not parse location string: " << locationString;
277 geoBatch = KStarsData::Instance()->locationNamed(locationFields[0], locationFields[1],
279 if (geoBatch ==
nullptr)
281 qDebug() << Q_FUNC_INFO <<
"Error: location not found in database: " << locationString;
287 if (DateCheckBatch->isChecked())
290 for (
auto &s : fields)
298 qDebug() << Q_FUNC_INFO <<
"Error: did not find a valid date string in: " << line;
304 for (
auto &s : fields)
315 qDebug() << Q_FUNC_INFO <<
"Error: did not find a valid time string in: " << line;
319 if (geoBatch !=
nullptr)
321 if (ComputeComboBatch->currentIndex() == 0)
325 ksdt = geoBatch->LTtoUT(ksdt);
326 dms lst = geoBatch->GSTtoLST(ksdt.gst());
335 QTime ut = ksdt.GSTtoUT(geoBatch->LSTtoGST(lst));
337 ksdt = geoBatch->UTtoLT(ksdt);
338 outTime = ksdt.time();
350 void modCalcSidTime::slotViewBatch()
352 QFile fOut(OutputFileBatch->url().toLocalFile());
357 while (!istream.
atEnd())
363 OutputFileBatch->url().toLocalFile());