19 #include "modcalcjd.moc" 
   23 #include <qradiobutton.h> 
   24 #include <klineedit.h> 
   25 #include <kmessagebox.h> 
   28 #include <QtCore/QTextStream> 
   32 #define MJD0 2400000.5 
   39     connect( DateTimeBox, SIGNAL(dateTimeChanged(
const QDateTime&)), 
this, SLOT(
slotUpdateCalendar()) );
 
   40     connect( JDBox, SIGNAL(editingFinished()), 
this, SLOT(
slotUpdateJD()) );
 
   41     connect( ModJDBox, SIGNAL(editingFinished()), 
this, SLOT(
slotUpdateModJD()) );
 
   42     connect( InputFileBatch, SIGNAL(urlSelected(
const KUrl&)), 
this, SLOT(
slotCheckFiles()) );
 
   43     connect( OutputFileBatch, SIGNAL(urlSelected(
const KUrl&)), 
this, SLOT(
slotCheckFiles()) );
 
   44     connect( RunButtonBatch, SIGNAL(clicked()), 
this, SLOT(
slotRunBatch()) );
 
   45     connect( ViewButtonBatch, SIGNAL(clicked()), 
this, SLOT(
slotViewBatch()) );
 
   47     RunButtonBatch->setEnabled( 
false );
 
   48     ViewButtonBatch->setEnabled( 
false );
 
   61     long double julianDay, modjulianDay;
 
   66     modjulianDay = julianDay - 
MJD0;
 
   67     showMjd(modjulianDay);
 
   72     long double julianDay, modjulianDay;
 
   74     modjulianDay = KGlobal::locale()->readNumber( ModJDBox->text() );
 
   75     julianDay = 
MJD0 + modjulianDay;
 
   77     DateTimeBox->setDateTime( 
KStarsDateTime( julianDay ).dateTime() );
 
   82     long double julianDay, modjulianDay;
 
   83     julianDay = KGlobal::locale()->readNumber( JDBox->text() );
 
   86     DateTimeBox->setDateTime( dt.dateTime() );
 
   88     modjulianDay = julianDay - 
MJD0;
 
   89     showMjd( modjulianDay );
 
   98 void modCalcJD::showJd(
long double julianDay)
 
  100     JDBox->setText(KGlobal::locale()->formatNumber( (
double)julianDay, 5 ) );
 
  103 void modCalcJD::showMjd(
long double modjulianDay)
 
  105     ModJDBox->setText(KGlobal::locale()->formatNumber( (
double)modjulianDay, 5 ) );
 
  109     if ( ! InputFileBatch->lineEdit()->text().isEmpty() && ! OutputFileBatch->lineEdit()->text().isEmpty() ) {
 
  110         RunButtonBatch->setEnabled( 
true );
 
  112         RunButtonBatch->setEnabled( 
false );
 
  117     QString inputFileName = InputFileBatch->url().toLocalFile();
 
  119     if ( QFile::exists(inputFileName) ) {
 
  120         QFile 
f( inputFileName );
 
  121         if ( !f.open( QIODevice::ReadOnly) ) {
 
  122             QString message = i18n( 
"Could not open file %1.", f.fileName() );
 
  123             KMessageBox::sorry( 0, message, i18n( 
"Could Not Open File" ) );
 
  128         processLines( istream, InputComboBatch->currentIndex() );
 
  129         ViewButtonBatch->setEnabled( 
true );
 
  133         QString message = i18n( 
"Invalid file: %1", inputFileName );
 
  134         KMessageBox::sorry( 0, message, i18n( 
"Invalid file" ) );
 
  139 void modCalcJD::processLines( 
QTextStream &istream, 
int inputData ) {
 
  140     QFile fOut( OutputFileBatch->url().toLocalFile() );
 
  141     fOut.open(QIODevice::WriteOnly);
 
  149     while ( ! istream.atEnd() ) {
 
  150         line = istream.readLine();
 
  151         line = line.trimmed();
 
  152         QStringList data = line.split( 
' ', QString::SkipEmptyParts );
 
  154         if ( inputData == 0 ) { 
 
  156             if ( data[0].length() > 10 )
 
  159                 dt = 
KStarsDateTime( QDate::fromString( data[0] ), QTime(0,0,0) );
 
  163             if ( dt.isValid() ) kDebug() << dt.toString();
 
  165             if ( dt.isValid() ) {
 
  167                 if ( data.size() > 1 ) {
 
  169                     if ( s.length() == 4 ) s = 
'0'+s;
 
  170                     QTime t = QTime::fromString( s );
 
  171                     if ( t.isValid() ) dt.
setTime( t );
 
  175                 QTime t = QTime::fromString( data[0] );
 
  179                     if ( data.size() > 1 ) {
 
  180                         QDate 
d = QDate::fromString( data[1] );
 
  181                         if ( d.isValid() ) dt.
setDate( d );
 
  182                         else dt.
setDate( QDate::currentDate() );
 
  187             if ( dt.isValid() ) {
 
  193         } 
else if ( inputData == 1 ) {
 
  195             jd = data[0].toDouble(&ok);
 
  200         } 
else if ( inputData == 2 ) {
 
  202             mjd = data[0].toDouble(&ok);
 
  210         ostream << KGlobal::locale()->formatDateTime( dt, KLocale::LongDate ) << 
"  " 
  211         << QString::number( jd, 
'f', 2 ) << 
"  " 
  212         << QString::number( mjd, 
'f', 2 ) << endl;
 
  220     QFile fOut( OutputFileBatch->url().toLocalFile() );
 
  221     fOut.open(QIODevice::ReadOnly);
 
  225     while ( ! istream.atEnd() )
 
  226         text.append( istream.readLine() );
 
  230     KMessageBox::informationList( 0, i18n(
"Results of Julian day calculation"), text, OutputFileBatch->url().toLocalFile() );
 
static KStarsDateTime fromString(const QString &s)
void setDate(const QDate &d)
Assign the Date according to a QDate object. 
void setTime(const QTime &t)
Assign the Time according to a QTime object. 
static KStarsDateTime currentDateTime(KDateTime::Spec ts=KDateTime::Spec::ClockTime())
Extension of KDateTime for KStars KStarsDateTime can represent the date/time as a Julian Day...
void slotUpdateCalendar()
void showCurrentTime(void)
void setDJD(long double jd)
Assign the (long double) Julian Day value, which includes the time of day encoded in the fractional p...