21 #include <QTextStream>
23 #include <kcolorbutton.h>
25 #include <kmessagebox.h>
26 #include <knuminput.h>
27 #include <ktemporaryfile.h>
43 QDir::setCurrent( QDir::homePath() );
46 setCaption( i18n(
"Import Catalog" ) );
47 setButtons( KDialog::Help|KDialog::Ok|KDialog::Cancel );
49 connect( acd->DataURL->lineEdit(), SIGNAL( lostFocus() ),
this, SLOT( slotShowDataFile() ) );
50 connect( acd->DataURL, SIGNAL( urlSelected(
const KUrl & ) ),
51 this, SLOT( slotShowDataFile() ) );
52 connect( acd->PreviewButton, SIGNAL( clicked() ),
this, SLOT( slotPreviewCatalog() ) );
53 connect(
this, SIGNAL( okClicked() ),
this, SLOT( slotCreateCatalog() ) );
55 connect(
this,SIGNAL(cancelClicked()),
this,SLOT(slotCancel()));
56 connect(
this,SIGNAL(helpClicked()),
this,SLOT(slotHelp()));
58 acd->FieldList->addItem( i18n(
"ID Number" ) );
59 acd->FieldList->addItem( i18n(
"Right Ascension" ) );
60 acd->FieldList->addItem( i18n(
"Declination" ) );
61 acd->FieldList->addItem( i18n(
"Object Type" ) );
63 acd->FieldPool->addItem( i18n(
"Common Name" ) );
64 acd->FieldPool->addItem( i18n(
"Magnitude" ) );
65 acd->FieldPool->addItem( i18n(
"Flux" ) );
66 acd->FieldPool->addItem( i18n(
"Major Axis" ) );
67 acd->FieldPool->addItem( i18n(
"Minor Axis" ) );
68 acd->FieldPool->addItem( i18n(
"Position Angle" ) );
69 acd->FieldPool->addItem( i18n(
"Ignore" ) );
75 void AddCatDialog::slotOk() {
84 void AddCatDialog::slotHelp() {
86 i18n(
"A valid custom catalog file has one line per object, "
87 "with the following fields in each line:") +
"\n\t" +
88 i18n(
"1. Type identifier. Must be one of: 0 (star), 3 (open cluster), 4 (globular cluster), "
89 "5 (gaseous nebula), 6 (planetary nebula), 7 (supernova remnant), or 8 (galaxy)" ) +
"\n\t" +
90 i18n(
"2. Right Ascension (floating-point value)" ) +
"\n\t" +
91 i18n(
"3. Declination (floating-point value)" ) +
"\n\t" +
92 i18n(
"4. Magnitude (floating-point value)" ) +
"\n\t" +
93 i18n(
"5. Integrated Flux (floating-point value); frequency and units are set separately in the catalog file." ) +
"\n\t" +
94 i18n(
"6. Spectral type (if type=0); otherwise object's catalog name" ) +
"\n\t" +
95 i18n(
"7. Star name (if type=0); otherwise object's common name. [field 7 is optional]" ) +
"\n\n" +
97 i18n(
"The fields should be separated by whitespace. In addition, the catalog "
98 "may contain comment lines beginning with \'#\'." );
100 KMessageBox::information( 0, message, i18n(
"Help on custom catalog file format" ) );
118 bool AddCatDialog::validateDataFile() {
120 CatalogContents = writeCatalogHeader();
123 if (acd->DataURL->url().isEmpty())
127 QFile dataFile( acd->DataURL->url().toLocalFile() );
128 if (dataFile.open( QIODevice::ReadOnly ) ) {
130 CatalogContents += dataStream.readAll();
140 QString AddCatDialog::writeCatalogHeader() {
141 QString name = ( acd->CatalogName->text().isEmpty() ? i18n(
"Custom") : acd->CatalogName->text() );
142 QString pre = ( acd->Prefix->text().isEmpty() ?
"CC" : acd->Prefix->text() );
143 char delimiter = ( acd->CSVButton->isChecked() ?
',' :
' ' );
145 QString h = QString(
"# Delimiter: %1\n").arg( delimiter );
146 h += QString(
"# Name: %1\n").arg( name );
147 h += QString(
"# Prefix: %1\n").arg( pre );
148 h += QString(
"# Color: %1\n").arg( acd->ColorButton->color().name() );
149 h += QString(
"# Epoch: %1\n").arg( acd->Epoch->value() );
152 for (
int i=0; i < acd->FieldList->count(); ++i ) {
153 QString
f = acd->FieldList->item( i )->text();
155 if ( f == i18n(
"ID Number" ) ) {
157 }
else if ( f == i18n(
"Right Ascension" ) ) {
159 }
else if ( f == i18n(
"Declination" ) ) {
161 }
else if ( f == i18n(
"Object Type" ) ) {
163 }
else if ( f == i18n(
"Common Name" ) ) {
165 }
else if ( f == i18n(
"Magnitude" ) ) {
167 }
else if ( f == i18n(
"Flux" ) ) {
169 }
else if ( f == i18n(
"Major Axis" ) ) {
171 }
else if ( f == i18n(
"Minor Axis" ) ) {
173 }
else if ( f == i18n(
"Position Angle" ) ) {
175 }
else if ( f == i18n(
"Ignore" ) ) {
185 void AddCatDialog::slotShowDataFile() {
186 QFile dataFile( acd->DataURL->url().toLocalFile() );
187 if ( ! acd->DataURL->url().isEmpty() && dataFile.open( QIODevice::ReadOnly ) ) {
188 acd->DataFileBox->clear();
190 acd->DataFileBox->addItems( dataStream.readAll().split(
'\n' ) );
195 void AddCatDialog::slotPreviewCatalog() {
196 if ( validateDataFile() ) {
197 KMessageBox::informationList( 0, i18n(
"Preview of %1", acd->CatalogName->text() ),
198 CatalogContents.split(
'\n' ), i18n(
"Catalog Preview" ) );
202 void AddCatDialog::slotCreateCatalog() {
204 if ( validateDataFile() ) {
209 if ( QFile::exists( acd->CatalogURL->url().toLocalFile() ) )
211 KUrl u( acd->CatalogURL->url() );
212 int r=KMessageBox::warningContinueCancel( 0,
213 i18n(
"A file named \"%1\" already exists. "
214 "Overwrite it?", u.fileName() ),
215 i18n(
"Overwrite File?" ),
216 KStandardGuiItem::overwrite() );
218 if(r==KMessageBox::Cancel)
return;
221 QFile OutFile( acd->CatalogURL->url().toLocalFile() );
222 if ( ! OutFile.open( QIODevice::WriteOnly ) ) {
223 KMessageBox::sorry( 0,
224 i18n(
"Could not open the file %1 for writing.", acd->CatalogURL->url().toLocalFile() ),
225 i18n(
"Error Opening Output File" ) );
228 outStream << CatalogContents;
233 emit KDialog::accept();
239 #include "addcatdialog.moc"
static KStarsData * Instance()
This is the main window for KStars.
void addCustomCatalog(const QString &filename, int index)
AddCatDialogUI(QWidget *parent=0)
SkyMapComposite * skyComposite()
~AddCatDialog()
Destructor (empty)
AddCatDialog(KStars *_ks)
Default constructor.