• Skip to content
  • Skip to link menu
KDE 3.5 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

kstars

observinglist.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                           observinglist.cpp  -  K Desktop Planetarium
00003                              -------------------
00004     begin                : 29 Nov 2004
00005     copyright            : (C) 2004 by Jeff Woods, Jason Harris
00006     email                : jcwoods@bellsouth.net, jharris@30doradus.org
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #include <stdio.h>
00019 #include <qfile.h>
00020 #include <qdir.h>
00021 #include <qlabel.h>
00022 #include <qlayout.h>
00023 #include <qstringlist.h>
00024 #include <qwidgetstack.h>
00025 #include <klistview.h>
00026 #include <kpushbutton.h>
00027 #include <kstatusbar.h>
00028 #include <ktextedit.h>
00029 #include <kinputdialog.h>
00030 #include <kicontheme.h>
00031 #include <kiconloader.h>
00032 #include <kio/netaccess.h>
00033 #include <kmessagebox.h>
00034 #include <kfiledialog.h>
00035 #include <ktempfile.h>
00036 #include <klineedit.h>
00037 
00038 #include "observinglist.h"
00039 #include "observinglistui.h"
00040 #include "obslistwizard.h"
00041 #include "kstars.h"
00042 #include "kstarsdata.h"
00043 #include "skyobject.h"
00044 #include "starobject.h"
00045 #include "skymap.h"
00046 #include "detaildialog.h"
00047 #include "tools/altvstime.h"
00048 
00049 #include "indimenu.h"
00050 #include "indielement.h"
00051 #include "indiproperty.h"
00052 #include "indidevice.h"
00053 #include "devicemanager.h"
00054 #include "indistd.h"
00055 
00056 ObservingList::ObservingList( KStars *_ks, QWidget* parent )
00057         : KDialogBase( KDialogBase::Plain, i18n( "Observing List" ), 
00058                 Close, Close, parent, "observinglist", false ), ks( _ks ), LogObject(0), oCurrent(0), 
00059                 noNameStars(0), isModified(false), bIsLarge(true)
00060 {
00061     QFrame *page = plainPage();
00062     QVBoxLayout *vlay = new QVBoxLayout( page, 0, 0 );
00063     ui = new ObservingListUI( page );
00064     vlay->addWidget( ui );
00065 
00066     //FIXME: enable MiniButton when I figure out how to resize the window correctly
00067     ui->MiniButton->hide();
00068 
00069     //Connections
00070     connect( this, SIGNAL( closeClicked() ), this, SLOT( slotClose() ) );
00071     connect( ui->TableStack, SIGNAL( aboutToShow( QWidget* ) ), 
00072             this, SLOT( slotPrepTable( QWidget* ) ) );
00073     connect( ui->FullTable, SIGNAL( selectionChanged() ), 
00074             this, SLOT( slotNewSelection() ) );
00075     connect( ui->TinyTable, SIGNAL( selectionChanged() ), 
00076             this, SLOT( slotNewSelection() ) );
00077     connect( ui->FullTable, SIGNAL( doubleClicked( QListViewItem*, const QPoint&, int) ), 
00078             this, SLOT( slotCenterObject() ) );
00079     connect( ui->TinyTable, SIGNAL( doubleClicked( QListBoxItem* ) ), 
00080             this, SLOT( slotCenterObject() ) );
00081     connect( ui->RemoveButton, SIGNAL( clicked() ), 
00082             this, SLOT( slotRemoveObjects() ) );
00083     connect( ui->CenterButton, SIGNAL( clicked() ), 
00084             this, SLOT( slotCenterObject() ) );
00085     connect( ui->ScopeButton, SIGNAL( clicked() ), 
00086             this, SLOT( slotSlewToObject() ) );
00087     connect( ui->DetailsButton, SIGNAL( clicked() ), 
00088             this, SLOT( slotDetails() ) );
00089     connect( ui->AVTButton, SIGNAL( clicked() ), 
00090             this, SLOT( slotAVT() ) );
00091 
00092     connect( ui->OpenButton, SIGNAL( clicked() ), 
00093             this, SLOT( slotOpenList() ) );
00094     connect( ui->SaveButton, SIGNAL( clicked() ),
00095             this, SLOT( slotSaveList() ) );
00096     connect( ui->SaveAsButton, SIGNAL( clicked() ),
00097             this, SLOT( slotSaveListAs() ) );
00098     connect( ui->WizardButton, SIGNAL( clicked() ),
00099             this, SLOT( slotWizard() ) );
00100 
00101     //FIXME: enable MiniButton
00102 //  connect( ui->MiniButton, SIGNAL( clicked() ),
00103 //          this, SLOT( slotToggleSize() ) );
00104 
00105     obsList.setAutoDelete( false ); //do NOT delete removed pointers!
00106     
00107     //Add icons to Push Buttons
00108     KIconLoader *icons = KGlobal::iconLoader();
00109     ui->OpenButton->setPixmap( icons->loadIcon( "fileopen", KIcon::Toolbar ) );
00110     ui->SaveButton->setPixmap( icons->loadIcon( "filesave", KIcon::Toolbar ) );
00111     ui->SaveAsButton->setPixmap( icons->loadIcon( "filesaveas", KIcon::Toolbar ) );
00112     ui->WizardButton->setPixmap( icons->loadIcon( "wizard", KIcon::Toolbar ) );
00113     ui->MiniButton->setPixmap( icons->loadIcon( "window_nofullscreen", KIcon::Toolbar ) );
00114 
00115     ui->CenterButton->setEnabled( false );
00116     ui->ScopeButton->setEnabled( false );
00117     ui->DetailsButton->setEnabled( false );
00118     ui->AVTButton->setEnabled( false );
00119     ui->RemoveButton->setEnabled( false );
00120     ui->NotesLabel->setEnabled( false );
00121     ui->NotesEdit->setEnabled( false );
00122 }
00123 
00124 bool ObservingList::contains( const SkyObject *q ) {
00125     for ( SkyObject* o = obsList.first(); o; o = obsList.next() ) {
00126         if ( o == q ) return true;
00127     }
00128 
00129     return false;
00130 }
00131 
00132 
00133 //SLOTS
00134 void ObservingList::slotPrepTable( QWidget *tab ) {
00135     if ( tab == ui->FullTable ) {
00136     } else {
00137     }
00138 }
00139 
00140 void ObservingList::slotAddObject( SkyObject *obj ) {
00141     if ( ! obj ) obj = ks->map()->clickedObject();
00142 
00143     //First, make sure object is not already in the list
00144     for ( SkyObject *o = obsList.first(); o; o = obsList.next() ) {
00145         if ( obj == o ) {
00146             //FIXME STRINGS FREEZE
00147             //ks->statusBar()->changeItem( i18n( "%1 is already in the observing list." ).arg( obj->name() ), 0 );
00148             return;
00149         }
00150     }
00151 
00152     //Insert object in obsList
00153     obsList.append( obj );
00154     if ( ! isModified ) isModified = true; 
00155 
00156     //Insert object entry in FullTable and TinyTable
00157     QString smag("--");
00158     if ( obj->mag() < 90.0 ) smag = QString::number( obj->mag(), 'g', 2 );
00159     new KListViewItem( ui->FullTable, obj->translatedName(), 
00160             obj->ra()->toHMSString(),
00161             obj->dec()->toDMSString(),
00162             smag,
00163             obj->typeName() );
00164     ui->TinyTable->insertItem( obj->translatedName() );
00165 
00166     //Note addition in statusbar
00167     ks->statusBar()->changeItem( i18n( "Added %1 to observing list." ).arg( obj->name() ), 0 );
00168 }
00169 
00170 void ObservingList::slotRemoveObject( SkyObject *o ) {
00171     if ( !o ) 
00172         o = ks->map()->clickedObject();
00173     
00174     obsList.remove(o);
00175     if ( ! isModified ) isModified = true;
00176 
00177     if ( o == LogObject ) 
00178         saveCurrentUserLog();
00179         
00180     //Remove entry from FullTable
00181     bool objectFound = false;
00182     QListViewItemIterator it( ui->FullTable );
00183     while ( it.current() ) {
00184         QListViewItem *item = it.current();
00185 
00186         //If the object is named "star" then match coordinates instead of name
00187         if ( o->translatedName() == i18n( "star" ) ) {
00188             if ( item->text(1) == o->ra()->toHMSString() 
00189                             && item->text(2) == o->dec()->toDMSString() ) {
00190                 delete item;
00191                 objectFound = true;
00192                 break;
00193                             }
00194         } else if ( item->text( 0 ) == o->translatedName() ) {
00195             delete item;
00196             objectFound = true;
00197             break;
00198         }
00199         ++it;
00200     }
00201 
00202     if ( ! objectFound ) {
00203         kdDebug() << i18n( "Cannot remove Object %1; not found in table." ).arg(o->translatedName()) << endl;
00204     } else {
00205         //Remove object from TinyTable
00206         for ( uint i=0; i < ui->TinyTable->count(); i++ ) {
00207             if ( o->translatedName() == ui->TinyTable->text(i) ) {
00208                 ui->TinyTable->removeItem(i);
00209                 break;
00210             }
00211         }
00212     }
00213 }
00214 
00215 void ObservingList::slotRemoveObjects() {
00216     if ( SelectedObjects.count() == 0) return;
00217     
00218     for ( SkyObject *o = SelectedObjects.first(); o; o = SelectedObjects.next() ) 
00219         slotRemoveObject( o );
00220 
00221     slotNewSelection();
00222 }
00223 
00224 void ObservingList::slotNewSelection() {
00225     //If the TinyTable is visible, we need to sync the selection in the FullTable
00226     if ( sender() == ui->TinyTable ) syncTableSelection();
00227 
00228     //Construct list of selected objects
00229     SelectedObjects.clear();
00230     QListViewItemIterator it( ui->FullTable, QListViewItemIterator::Selected ); //loop over selected items
00231     while ( it.current() ) {
00232         for ( SkyObject *o = obsList.first(); o; o = obsList.next() ) {
00233             if ( it.current()->text(0) == i18n("star") ) {
00234                 if ( it.current()->text(1) == o->ra()->toHMSString() 
00235                         && it.current()->text(2) == o->dec()->toDMSString() ) {
00236                     SelectedObjects.append(o);
00237                     break;
00238                 }
00239             } else if ( o->translatedName() == it.current()->text(0) ) {
00240                 SelectedObjects.append( o );
00241                 break;
00242             }
00243         }
00244         it++;
00245     }
00246     
00247     //Enable widgets when one object selected
00248     if ( SelectedObjects.count() == 1 ) {
00249         QString newName( SelectedObjects.first()->translatedName() );
00250         QString oldName( obsList.current()->translatedName() );
00251         
00252         //Enable buttons
00253         ui->CenterButton->setEnabled( true );
00254         ui->ScopeButton->setEnabled( true );
00255         ui->DetailsButton->setEnabled( true );
00256         ui->AVTButton->setEnabled( true );
00257         ui->RemoveButton->setEnabled( true );
00258         
00259         //Find the selected object in the obsList,
00260         //then break the loop.  Now obsList.current()
00261         //points to the new selected object (until now it was the previous object)
00262         bool found( false );
00263         for ( SkyObject* o = obsList.first(); o; o = obsList.next() ) {
00264             if ( o->translatedName() == newName ) {
00265                 found = true;
00266                 break;
00267             }
00268         }
00269 
00270         if ( ! found ) { 
00271             kdDebug() << i18n( "Object %1 not found in obsList." ).arg( newName ) << endl;
00272         } else if ( newName != i18n( "star" ) ) {
00273             //Display the object's current user notes in the NotesEdit
00274             //First, save the last object's user log to disk, if necessary
00275             saveCurrentUserLog();
00276             
00277             //set LogObject to the new selected object
00278             LogObject = obsList.current();
00279             
00280             ui->NotesLabel->setEnabled( true );
00281             ui->NotesEdit->setEnabled( true );
00282             
00283             ui->NotesLabel->setText( i18n( "observing notes for %1:" ).arg( LogObject->translatedName() ) );
00284             if ( LogObject->userLog.isEmpty() ) {
00285                 ui->NotesEdit->setText( i18n("Record here observation logs and/or data on %1.").arg( LogObject->translatedName() ) );
00286             } else {
00287                 ui->NotesEdit->setText( LogObject->userLog );
00288             }
00289         } else { //selected object is named "star"
00290             //clear the log text box
00291             saveCurrentUserLog();
00292             ui->NotesLabel->setEnabled( false );
00293             ui->NotesEdit->setEnabled( false );
00294         }
00295 
00296         //This shouldn't be necessary.  For some reason, obsList.current() 
00297         //is valid here, but in subsequent functions (such as slotCenterObject) 
00298         //called *right after* this one, obsList.current()==NULL.  No idea why.
00299         oCurrent = obsList.current();
00300 
00301     } else if ( SelectedObjects.count() == 0 ) {
00302         //Disable buttons
00303         ui->CenterButton->setEnabled( false );
00304         ui->ScopeButton->setEnabled( false );
00305         ui->DetailsButton->setEnabled( false );
00306         ui->AVTButton->setEnabled( false );
00307         ui->RemoveButton->setEnabled( false );
00308         ui->NotesLabel->setEnabled( false );
00309         ui->NotesEdit->setEnabled( false );
00310         oCurrent = 0;
00311         
00312         //Clear the user log text box.
00313         saveCurrentUserLog();
00314     } else { //more than one object selected.
00315         ui->CenterButton->setEnabled( false );
00316         ui->ScopeButton->setEnabled( false );
00317         ui->DetailsButton->setEnabled( false );
00318         ui->AVTButton->setEnabled( true );
00319         ui->RemoveButton->setEnabled( true );
00320         ui->NotesLabel->setEnabled( false );
00321         ui->NotesEdit->setEnabled( false );
00322         oCurrent = 0;
00323 
00324         //Clear the user log text box.
00325         saveCurrentUserLog();
00326     }
00327 
00328 }
00329 
00330 void ObservingList::slotCenterObject() {
00331     if ( oCurrent ) {
00332         ks->map()->setClickedObject( oCurrent );
00333         ks->map()->setClickedPoint( oCurrent );
00334         ks->map()->slotCenter();
00335     }
00336 }
00337 
00338 void ObservingList::slotSlewToObject()
00339 {
00340 
00341   INDI_D *indidev(NULL);
00342   INDI_P *prop(NULL), *onset(NULL);
00343   INDI_E *RAEle(NULL), *DecEle(NULL), *AzEle(NULL), *AltEle(NULL), *ConnectEle(NULL), *nameEle(NULL);
00344   bool useJ2000( false);
00345   int selectedCoord(0);
00346   SkyPoint sp;
00347   
00348   // Find the first device with EQUATORIAL_EOD_COORD or EQUATORIAL_COORD and with SLEW element
00349   // i.e. the first telescope we find!
00350   
00351   INDIMenu *imenu = ks->getINDIMenu();
00352 
00353   
00354   for (unsigned int i=0; i < imenu->mgr.count() ; i++)
00355   {
00356     for (unsigned int j=0; j < imenu->mgr.at(i)->indi_dev.count(); j++)
00357     {
00358        indidev = imenu->mgr.at(i)->indi_dev.at(j);
00359        indidev->stdDev->currentObject = NULL;
00360        prop = indidev->findProp("EQUATORIAL_EOD_COORD");
00361         if (prop == NULL)
00362     {
00363           prop = indidev->findProp("EQUATORIAL_COORD");
00364           if (prop == NULL)
00365                   {
00366                     prop = indidev->findProp("HORIZONTAL_COORD");
00367                     if (prop == NULL)
00368                 continue;
00369                     else
00370                         selectedCoord = 1;      /* Select horizontal */
00371                   }
00372           else
00373                 useJ2000 = true;
00374     }
00375 
00376        ConnectEle = indidev->findElem("CONNECT");
00377        if (!ConnectEle) continue;
00378        
00379        if (ConnectEle->state == PS_OFF)
00380        {
00381      KMessageBox::error(0, i18n("Telescope %1 is offline. Please connect and retry again.").arg(indidev->label));
00382      return;
00383        }
00384 
00385         switch (selectedCoord)
00386         {
00387           // Equatorial
00388           case 0:
00389            if (prop->perm == PP_RO) continue;
00390            RAEle  = prop->findElement("RA");
00391            if (!RAEle) continue;
00392        DecEle = prop->findElement("DEC");
00393        if (!DecEle) continue;
00394            break;
00395 
00396          // Horizontal
00397          case 1:
00398           if (prop->perm == PP_RO) continue;
00399           AzEle = prop->findElement("AZ");
00400           if (!AzEle) continue;
00401           AltEle = prop->findElement("ALT");
00402           if (!AltEle) continue;
00403           break;
00404         }
00405    
00406         onset = indidev->findProp("ON_COORD_SET");
00407         if (!onset) continue;
00408        
00409         onset->activateSwitch("SLEW");
00410 
00411         indidev->stdDev->currentObject = oCurrent;
00412 
00413       /* Send object name if available */
00414       if (indidev->stdDev->currentObject)
00415          {
00416              nameEle = indidev->findElem("OBJECT_NAME");
00417              if (nameEle && nameEle->pp->perm != PP_RO)
00418              {
00419                  nameEle->write_w->setText(indidev->stdDev->currentObject->name());
00420                  nameEle->pp->newText();
00421              }
00422           }
00423 
00424        switch (selectedCoord)
00425        {
00426          case 0:
00427             if (indidev->stdDev->currentObject)
00428         sp.set (indidev->stdDev->currentObject->ra(), indidev->stdDev->currentObject->dec());
00429             else
00430                 sp.set (ks->map()->clickedPoint()->ra(), ks->map()->clickedPoint()->dec());
00431 
00432         if (useJ2000)
00433         sp.apparentCoord(ks->data()->ut().djd(), (long double) J2000);
00434 
00435            RAEle->write_w->setText(QString("%1:%2:%3").arg(sp.ra()->hour()).arg(sp.ra()->minute()).arg(sp.ra()->second()));
00436        DecEle->write_w->setText(QString("%1:%2:%3").arg(sp.dec()->degree()).arg(sp.dec()->arcmin()).arg(sp.dec()->arcsec()));
00437 
00438           break;
00439 
00440        case 1:
00441          if (indidev->stdDev->currentObject)
00442          {
00443            sp.setAz(*indidev->stdDev->currentObject->az());
00444            sp.setAlt(*indidev->stdDev->currentObject->alt());
00445          }
00446          else
00447          {
00448            sp.setAz(*ks->map()->clickedPoint()->az());
00449            sp.setAlt(*ks->map()->clickedPoint()->alt());
00450          }
00451 
00452           AzEle->write_w->setText(QString("%1:%2:%3").arg(sp.az()->degree()).arg(sp.az()->arcmin()).arg(sp.az()->arcsec()));
00453           AltEle->write_w->setText(QString("%1:%2:%3").arg(sp.alt()->degree()).arg(sp.alt()->arcmin()).arg(sp.alt()->arcsec()));
00454 
00455          break;
00456        }
00457 
00458        prop->newText();
00459        
00460        return;
00461     }
00462   }
00463        
00464   // We didn't find any telescopes
00465   KMessageBox::sorry(0, i18n("KStars did not find any active telescopes."));
00466   
00467 }
00468 
00469 //FIXME: This will open multiple Detail windows for each object;
00470 //Should have one window whose target object changes with selection
00471 void ObservingList::slotDetails() {
00472     if ( oCurrent ) {
00473         DetailDialog dd( oCurrent, ks->data()->lt(), ks->geo(), ks );
00474         dd.exec();
00475     }
00476 }
00477 
00478 void ObservingList::slotAVT() {
00479     if ( SelectedObjects.count() ) {
00480         AltVsTime avt( ks );
00481         for ( SkyObject *o = SelectedObjects.first(); o; o = SelectedObjects.next() ) {
00482             avt.processObject( o );
00483         }
00484         
00485         avt.exec();
00486     }
00487 }
00488 
00489 //FIXME: On close, we will need to close any open Details/AVT windows
00490 void ObservingList::slotClose() {
00491     //Save the current User log text
00492     if ( oCurrent && ! ui->NotesEdit->text().isEmpty() && ui->NotesEdit->text() 
00493                     != i18n("Record here observation logs and/or data on %1.").arg( oCurrent->name()) ) {
00494         oCurrent->saveUserLog( ui->NotesEdit->text() );
00495     }
00496     
00497     hide();
00498 }
00499 
00500 void ObservingList::saveCurrentUserLog() {
00501     if ( ! ui->NotesEdit->text().isEmpty() && 
00502                 ui->NotesEdit->text() != 
00503                     i18n("Record here observation logs and/or data on %1.").arg( LogObject->translatedName() ) ) {
00504         LogObject->saveUserLog( ui->NotesEdit->text() );
00505         
00506         ui->NotesEdit->clear();
00507         ui->NotesLabel->setText( i18n( "Observing notes for object:" ) );
00508         LogObject = NULL;
00509     }
00510 }
00511 
00512 void ObservingList::slotOpenList() {
00513     KURL fileURL = KFileDialog::getOpenURL( QDir::homeDirPath(), "*.obslist|KStars Observing List (*.obslist)" );
00514     QFile f;
00515 
00516     if ( fileURL.isValid() ) {
00517         if ( ! fileURL.isLocalFile() ) {
00518             //Save remote list to a temporary local file
00519             KTempFile tmpfile;
00520             tmpfile.setAutoDelete(true);
00521             FileName = tmpfile.name();
00522             if( KIO::NetAccess::download( fileURL, FileName, this ) ) 
00523                 f.setName( FileName );
00524 
00525         } else {
00526             FileName = fileURL.path();
00527             f.setName( FileName );
00528         }
00529 
00530         if ( !f.open( IO_ReadOnly) ) {
00531             QString message = i18n( "Could not open file %1" ).arg( f.name() );
00532             KMessageBox::sorry( 0, message, i18n( "Could Not Open File" ) );
00533             return;
00534         }
00535 
00536         saveCurrentList();
00537         //First line is the name of the list.  The rest of the file should 
00538         //be object names, one per line.
00539         QTextStream istream(&f);
00540         QString line;
00541         ListName = istream.readLine();
00542 
00543         while ( ! istream.eof() ) {
00544             line = istream.readLine();
00545             //DEBUG
00546             kdDebug() << line << endl;
00547 
00548             //If the object is named "star", add it by coordinates
00549             SkyObject *o = 0;
00550             if ( line.startsWith( "star" ) ) {
00551                 QStringList fields = QStringList::split( " ", line );
00552                 //DEBUG
00553                 kdDebug() << fields << endl;
00554 
00555                 double ra = dms::fromString( fields[1], false ).Degrees(); //false = hours
00556                 double dc = dms::fromString( fields[2], true ).Degrees();  //true  = degrees
00557 
00558                 //Identify the star with these coordinates
00559                 double rmax = 1.; 
00560                 for ( uint i=0; i < ks->data()->starList.count(); ++i ) {
00561                     SkyObject *s = (SkyObject*)(ks->data()->starList.at(i));
00562                     double dra = fabs( ra - s->ra()->Degrees() );
00563                     double ddc = fabs( dc - s->dec()->Degrees() );
00564                     if ( dra < rmax && ddc < rmax ) {
00565                         o = s;
00566                         rmax = sqrt( dra*dra + ddc*ddc );
00567                     }
00568                 }
00569             } else {
00570                 o = ks->data()->objectNamed( line );
00571             }
00572 
00573             if ( o ) slotAddObject( o );
00574         }
00575 
00576         //Newly-opened list should not trigger isModified flag
00577         isModified = false;
00578 
00579         f.close();
00580 
00581     } else if ( fileURL.path() != "" ) {
00582         QString message = i18n( "The specified file is invalid.  Try another file?" );
00583         if ( KMessageBox::warningYesNo( this, message, i18n("Invalid File"), i18n("Try Another"), i18n("Do Not Try") ) == KMessageBox::Yes ) {
00584             slotOpenList();
00585         }
00586     }
00587 }
00588 
00589 void ObservingList::saveCurrentList() {
00590     //Before loading a new list, do we need to save the current one?
00591     //Assume that if the list is empty, then there's no need to save
00592     if ( obsList.count() ) {
00593         if ( isModified ) {
00594             QString message = i18n( "Do you want to save the current list before opening a new list?" );
00595             if ( KMessageBox::questionYesNo( this, message, 
00596                     i18n( "Save Current List?" ), KStdGuiItem::save(), KStdGuiItem::discard() ) == KMessageBox::Yes )
00597                 slotSaveList();
00598         }
00599 
00600         //If we ever allow merging the loaded list with 
00601         //the existing one, that code would go here
00602         obsList.clear();
00603         ui->FullTable->clear();
00604     }
00605 }
00606 
00607 void ObservingList::slotSaveListAs() {
00608     bool ok(false);
00609     ListName = KInputDialog::getText( i18n( "Enter List Name" ), 
00610             i18n( "List name:" ), "", &ok );
00611 
00612     if ( ok ) {
00613         KURL fileURL = KFileDialog::getSaveURL( QDir::homeDirPath(), "*.obslist|KStars Observing List (*.obslist)" );
00614 
00615         if ( fileURL.isValid() ) 
00616             FileName = fileURL.path();
00617 
00618         slotSaveList();
00619     }
00620 }
00621 
00622 void ObservingList::slotSaveList() {
00623     if ( ListName.isEmpty() || FileName.isEmpty() ) {
00624         slotSaveListAs();
00625         return;
00626     }
00627 
00628     QFile f( FileName );
00629     if ( !f.open( IO_WriteOnly) ) {
00630         QString message = i18n( "Could not open file %1.  Try a different filename?" ).arg( f.name() );
00631         
00632         if ( KMessageBox::warningYesNo( 0, message, i18n( "Could Not Open File" ), i18n("Try Different"), i18n("Do Not Try") ) == KMessageBox::Yes ) {
00633             FileName == "";
00634             slotSaveList();
00635         }
00636         return;
00637     }
00638     
00639     QTextStream ostream(&f);
00640     ostream << ListName << endl;
00641 
00642     //Save objects to the list using their name.  If it's a star with a genetive name 
00643     //(i.e., "sigma orionis"), save the name with ascii characters, not greek letters.
00644     //If it's an unnamed star, save "star" and the star's coordinates.
00645     for ( SkyObject* o = obsList.first(); o; o = obsList.next() ) {
00646         if ( o->name() == "star" ) {
00647             ostream << o->name() << "  " << o->ra()->Hours() << "  " << o->dec()->Degrees() << endl;
00648         } else if ( o->type() == SkyObject::STAR ) {
00649             StarObject *s = (StarObject*)o;
00650 
00651             if ( s->name() == s->gname() ) {
00652                 ostream << s->gname( false ) << endl;
00653             } else {
00654                 ostream << o->name() << endl;
00655             }           
00656         } else {
00657             ostream << o->name() << endl;
00658         }
00659     }
00660 
00661     f.close();
00662     isModified = false;
00663 }
00664 
00665 void ObservingList::slotWizard() {
00666     ObsListWizard wizard( ks );
00667     if ( wizard.exec() == QDialog::Accepted ) {
00668         //Make sure current list is saved
00669         saveCurrentList();
00670 
00671         for ( SkyObject *o = wizard.obsList().first(); o; o = wizard.obsList().next() ) {
00672             slotAddObject( o );
00673         }
00674     }
00675 }
00676 
00677 void ObservingList::slotToggleSize() {
00678     if ( isLarge() ) {
00679         ui->MiniButton->setPixmap( KGlobal::iconLoader()->loadIcon( "window_fullscreen", KIcon::Toolbar ) );
00680 
00681         //switch widget stack to show TinyTable
00682         ui->TableStack->raiseWidget( ui->TinyTable );
00683 
00684         //Abbreviate text on each button
00685         ui->CenterButton->setText( i18n( "First letter in 'Center'", "C" ) );
00686         ui->ScopeButton->setText( i18n( "First letter in 'Scope'", "S" ) );
00687         ui->DetailsButton->setText( i18n( "First letter in 'Details'", "D" ) );
00688         ui->AVTButton->setText( i18n( "First letter in 'Alt vs Time'", "A" ) );
00689         ui->RemoveButton->setText( i18n( "First letter in 'Remove'", "R" ) );
00690 
00691         //Hide Observing notes
00692         ui->NotesLabel->hide();
00693         ui->NotesEdit->hide();
00694 
00695         syncTableSelection( false ); //sync TinyTable with FullTable
00696         adjustSize();
00697         bIsLarge = false;
00698 
00699     } else {
00700         ui->MiniButton->setPixmap( KGlobal::iconLoader()->loadIcon( "window_nofullscreen", KIcon::Toolbar ) );
00701 
00702         //switch widget stack to show FullTable
00703         ui->TableStack->raiseWidget( ui->FullTable );
00704 
00705         //Expand text on each button
00706         ui->CenterButton->setText( i18n( "Center" ) );
00707         ui->ScopeButton->setText( i18n( "Scope" ) );
00708         ui->DetailsButton->setText( i18n( "Details" ) );
00709         ui->AVTButton->setText( i18n( "Alt vs Time" ) );
00710         ui->RemoveButton->setText( i18n( "Remove" ) );
00711 
00712         //Show Observing notes
00713         ui->NotesLabel->show();
00714         ui->NotesEdit->show();
00715 
00716         syncTableSelection( true ); //sync FullTable with TinyTable
00717         adjustSize();
00718         bIsLarge = true;
00719     }
00720 }
00721 
00722 void ObservingList::syncTableSelection( bool syncFullTable ) {
00723     if ( syncFullTable ) {
00724         int i=0;
00725         QListViewItem *it =  ui->FullTable->firstChild();
00726         while ( it ) {
00727             it->setSelected( ui->TinyTable->isSelected( i++ ) );
00728             it->nextSibling();
00729         }
00730     } else {
00731         int i=0;
00732         QListViewItem *it =  ui->FullTable->firstChild();
00733         while ( it ) {
00734             ui->TinyTable->setSelected( i++, it->isSelected() );
00735             it->nextSibling();
00736         }
00737     }   
00738 }
00739 
00740 #include "observinglist.moc"

kstars

Skip menu "kstars"
  • Main Page
  • Modules
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

API Reference

Skip menu "API Reference"
  • keduca
  • kstars
Generated for API Reference by doxygen 1.5.9
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal