cassinidatadownloader.cpp
69 lines
| 2.4 KiB
| text/x-c
|
CppLexer
r5 | #include "cassinidatadownloader.h" | |||
#include "ui_cassinidatadownloader.h" | ||||
#include <filedownloader.h> | ||||
#include <QDir> | ||||
#include <QFileDialog> | ||||
#include <QFile> | ||||
CassiniDataDownloader::CassiniDataDownloader(QWidget *parent) : | ||||
QWidget(parent), | ||||
ui(new Ui::CassiniDataDownloader) | ||||
{ | ||||
ui->setupUi(this); | ||||
m_xmlLoader = new ExpXmlDownLoader(); | ||||
connect(this->ui->calendar,SIGNAL(activated(QDate)),this,SLOT(downloadData(QDate))); | ||||
connect(this->ui->LoadXmlFileQpb,SIGNAL(clicked()),this,SLOT(loadXmlFile())); | ||||
} | ||||
CassiniDataDownloader::~CassiniDataDownloader() | ||||
{ | ||||
delete ui; | ||||
delete m_xmlLoader; | ||||
} | ||||
void CassiniDataDownloader::changeEvent(QEvent *e) | ||||
{ | ||||
QWidget::changeEvent(e); | ||||
switch (e->type()) { | ||||
case QEvent::LanguageChange: | ||||
ui->retranslateUi(this); | ||||
break; | ||||
default: | ||||
break; | ||||
} | ||||
} | ||||
void CassiniDataDownloader::downloadData(const QDate &date) | ||||
{ | ||||
QDate tmpDate; | ||||
QStringList months=QStringList()<< "JAN" << "FEB" << "MAR" << "APR" << "MAY" << "JUN" << "JUI" << "AUG" << "SEP" << "OCT" << "NOV" << "DEC"; | ||||
tmpDate.setDate(date.year(),date.month(),1); | ||||
int firstDayOfMonth=tmpDate.dayOfYear(); | ||||
tmpDate.setDate(tmpDate.year(),tmpDate.month(),tmpDate.daysInMonth()); | ||||
int lastDayOfMonth=tmpDate.dayOfYear(); | ||||
QString link="http://ppi.pds.nasa.gov/ditdos/download?id=pds://PPI/CO-E_SW_J_S-MAG-3-RDR-FULL-RES-V1.0/DATA/" \ | ||||
+ QString("%1").arg(date.year()) +"/" + QString("%1_%2_").arg(firstDayOfMonth,3).arg(lastDayOfMonth,3).replace(' ','0') \ | ||||
+ months.at(date.month()-1) + "/" ; | ||||
qDebug()<<link; | ||||
QString dataFileName= QString("%1%2").arg(date.year()-2000,2).arg(date.dayOfYear(),3).replace(' ','0') + "_FGM_KRTP.TAB"; | ||||
QString headerFileName= QString("%1%2").arg(date.year()-2000,2).arg(date.dayOfYear(),3).replace(' ','0') + "_FGM_KRTP.LBL"; | ||||
// "_FGM_KRTP.TAB" | ||||
FileDownloader::downloadFile(link+dataFileName,QDir::homePath() +"/Téléchargements/"+dataFileName); | ||||
FileDownloader::downloadFile(link+headerFileName,QDir::homePath() +"/Téléchargements/"+headerFileName); | ||||
} | ||||
void CassiniDataDownloader::loadXmlFile() | ||||
{ | ||||
QString file=QFileDialog::getOpenFileName(); | ||||
if(QFile::exists(file)) | ||||
{ | ||||
if(m_xmlLoader->parseXml(file)) | ||||
{ | ||||
QList<QDate> daysToDl = m_xmlLoader->daysToDownload(); | ||||
for(int i=0;i<daysToDl.count();i++) | ||||
{ | ||||
downloadData(daysToDl.at(i)); | ||||
} | ||||
} | ||||
} | ||||
} | ||||