• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

kstars

  • sources
  • kde-4.12
  • kdeedu
  • kstars
  • kstars
  • tools
observinglist.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  observinglist.cpp - K Desktop Planetarium
3  -------------------
4  begin : 29 Nov 2004
5  copyright : (C) 2004 by Jeff Woods, Jason Harris
6  email : jcwoods@bellsouth.net, jharris@30doradus.org
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #include "observinglist.h"
19 #include "sessionsortfilterproxymodel.h"
20 
21 #include <cstdio>
22 
23 #include <QFile>
24 #include <QDir>
25 #include <QFrame>
26 #include <QTextStream>
27 #include <QStandardItemModel>
28 #include <QSortFilterProxyModel>
29 #include <QHeaderView>
30 #include <QDirIterator>
31 
32 #include <kpushbutton.h>
33 #include <kstatusbar.h>
34 #include <ktextedit.h>
35 #include <kinputdialog.h>
36 #include <kicon.h>
37 #include <kio/netaccess.h>
38 #include <kmessagebox.h>
39 #include <kfiledialog.h>
40 #include <ktemporaryfile.h>
41 #include <klineedit.h>
42 #include <kplotobject.h>
43 #include <kplotaxis.h>
44 #include <kplotwidget.h>
45 #include <kio/copyjob.h>
46 #include <kstandarddirs.h>
47 
48 #include "ksalmanac.h"
49 #include "obslistwizard.h"
50 #include "kstars.h"
51 #include "kstarsdata.h"
52 #include "ksutils.h"
53 #include "dialogs/locationdialog.h"
54 #include "skyobjects/skyobject.h"
55 #include "skyobjects/starobject.h"
56 #include "skycomponents/skymapcomposite.h"
57 #include "skymap.h"
58 #include "dialogs/detaildialog.h"
59 #include "dialogs/finddialog.h"
60 #include "tools/altvstime.h"
61 #include "tools/wutdialog.h"
62 #include "Options.h"
63 #include "imageviewer.h"
64 #include "thumbnailpicker.h"
65 #include "obslistpopupmenu.h"
66 #include "oal/log.h"
67 #include "oal/oal.h"
68 #include "oal/execute.h"
69 
70 #include <config-kstars.h>
71 
72 #ifdef HAVE_INDI_H
73 #include <basedevice.h>
74 #include "indi/indilistener.h"
75 #include "indi/drivermanager.h"
76 #include "indi/driverinfo.h"
77 #endif
78 
79 //
80 // ObservingListUI
81 // ---------------------------------
82 ObservingListUI::ObservingListUI( QWidget *p ) : QFrame( p ) {
83  setupUi( this );
84 }
85 
86 //
87 // ObservingList
88 // ---------------------------------
89 ObservingList::ObservingList( KStars *_ks )
90  : KDialog( (QWidget*)_ks ),
91  ks( _ks ), LogObject(0), m_CurrentObject(0),
92  isModified(false), bIsLarge(true)
93 {
94  ui = new ObservingListUI( this );
95  setMainWidget( ui );
96  setCaption( i18n( "Observation Planner" ) );
97  setButtons( KDialog::Close );
98  dt = KStarsDateTime::currentDateTime();
99  setFocusPolicy(Qt::StrongFocus);
100  geo = ks->data()->geo();
101  sessionView = false;
102  FileName = "";
103  pmenu = new ObsListPopupMenu();
104  //Set up the Table Views
105  m_Model = new QStandardItemModel( 0, 5, this );
106  m_Session = new QStandardItemModel( 0, 5 );
107  m_Model->setHorizontalHeaderLabels( QStringList() << i18n( "Name" )
108  << i18n( "Alternate Name" )
109  << i18nc( "Right Ascension", "RA" )
110  << i18nc( "Declination", "Dec" )
111  << i18nc( "Magnitude", "Mag" )
112  << i18n( "Type" ) );
113  m_Session->setHorizontalHeaderLabels( QStringList() << i18n( "Name" )
114  << i18n( "Alternate Name" )
115  << i18nc( "Right Ascension", "RA" )
116  << i18nc( "Declination", "Dec" )
117  << i18nc( "Magnitude", "Mag" )
118  << i18n( "Type" )
119  << i18n( "Time" )
120  << i18nc( "Altitude", "Alt" )
121  << i18nc( "Azimuth", "Az" ));
122  m_SortModel = new QSortFilterProxyModel( this );
123  m_SortModel->setSourceModel( m_Model );
124  m_SortModel->setDynamicSortFilter( true );
125  ui->TableView->setModel( m_SortModel );
126  ui->TableView->horizontalHeader()->setStretchLastSection( true );
127  ui->TableView->horizontalHeader()->setResizeMode( QHeaderView::ResizeToContents );
128  m_SortModelSession = new SessionSortFilterProxyModel;
129  m_SortModelSession->setSourceModel( m_Session );
130  m_SortModelSession->setDynamicSortFilter( true );
131  ui->SessionView->setModel( m_SortModelSession );
132  ui->SessionView->horizontalHeader()->setStretchLastSection( true );
133  ui->SessionView->horizontalHeader()->setResizeMode( QHeaderView::ResizeToContents );
134  ksal = new KSAlmanac;
135  ksal->setLocation(geo);
136  ui->View->setSunRiseSetTimes(ksal->getSunRise(),ksal->getSunSet());
137  ui->View->setLimits( -12.0, 12.0, -90.0, 90.0 );
138  ui->View->axis(KPlotWidget::BottomAxis)->setTickLabelFormat( 't' );
139  ui->View->axis(KPlotWidget::BottomAxis)->setLabel( i18n( "Local Time" ) );
140  ui->View->axis(KPlotWidget::TopAxis)->setTickLabelFormat( 't' );
141  ui->View->axis(KPlotWidget::TopAxis)->setTickLabelsShown( true );
142  ui->DateEdit->setDate(dt.date());
143  ui->SetLocation->setText( geo -> fullName() );
144  ui->ImagePreview->installEventFilter( this );
145  ui->TableView->viewport()->installEventFilter( this );
146  ui->TableView->installEventFilter( this );
147  ui->SessionView->viewport()->installEventFilter( this );
148  ui->SessionView->installEventFilter( this );
149  // setDefaultImage();
150  //Connections
151  connect( this, SIGNAL( closeClicked() ), this, SLOT( slotClose() ) );
152  connect( ui->TableView, SIGNAL( doubleClicked( const QModelIndex& ) ),
153  this, SLOT( slotCenterObject() ) );
154  connect( ui->TableView->selectionModel(),
155  SIGNAL( selectionChanged(const QItemSelection&, const QItemSelection&) ),
156  this, SLOT( slotNewSelection() ) );
157  connect( ui->SessionView->selectionModel(),
158  SIGNAL( selectionChanged(const QItemSelection&, const QItemSelection&) ),
159  this, SLOT( slotNewSelection() ) );
160  connect( ui->WUTButton, SIGNAL( clicked() ),
161  this, SLOT( slotWUT() ) );
162  connect( ui->FindButton, SIGNAL( clicked() ),
163  this, SLOT( slotFind() ) );
164  connect( ui->OpenButton, SIGNAL( clicked() ),
165  this, SLOT( slotOpenList() ) );
166  connect( ui->SaveButton, SIGNAL( clicked() ),
167  this, SLOT( slotSaveSession() ) );
168  connect( ui->SaveAsButton, SIGNAL( clicked() ),
169  this, SLOT( slotSaveSessionAs() ) );
170  connect( ui->WizardButton, SIGNAL( clicked() ),
171  this, SLOT( slotWizard() ) );
172  connect( ui->MiniButton, SIGNAL( clicked() ),
173  this, SLOT( slotToggleSize() ) );
174  connect( ui->SetLocation, SIGNAL( clicked() ),
175  this, SLOT( slotLocation() ) );
176  connect( ui->Update, SIGNAL( clicked() ),
177  this, SLOT( slotUpdate() ) );
178  connect( ui->SaveImage, SIGNAL( clicked() ),
179  this, SLOT( slotSaveImage() ) );
180  connect( ui->DeleteImage, SIGNAL( clicked() ),
181  this, SLOT( slotDeleteCurrentImage() ) );
182  connect( ui->GoogleImage, SIGNAL( clicked() ),
183  this, SLOT( slotGoogleImage() ) );
184  connect( ui->SetTime, SIGNAL( clicked() ),
185  this, SLOT( slotSetTime() ) );
186  connect( ui->tabWidget, SIGNAL( currentChanged(int) ),
187  this, SLOT( slotChangeTab(int) ) );
188  connect( ui->saveImages, SIGNAL( clicked() ),
189  this, SLOT( slotSaveAllImages() ) );
190  connect( ui->DeleteAllImages, SIGNAL( clicked() ),
191  this, SLOT( slotDeleteAllImages() ) );
192  connect( ui->OALExport, SIGNAL( clicked() ),
193  this, SLOT( slotOALExport() ) );
194  //Add icons to Push Buttons
195  ui->OpenButton->setIcon( KIcon("document-open") );
196  ui->SaveButton->setIcon( KIcon("document-save") );
197  ui->SaveAsButton->setIcon( KIcon("document-save-as") );
198  ui->WizardButton->setIcon( KIcon("games-solve") ); //is there a better icon for this button?
199  ui->MiniButton->setIcon( KIcon("view-restore") );
200  noSelection = true;
201  showScope = false;
202  ui->NotesLabel->setEnabled( false );
203  ui->NotesEdit->setEnabled( false );
204  ui->SetTime->setEnabled( false );
205  ui->TimeEdit->setEnabled( false );
206  ui->GoogleImage->setEnabled( false );
207  ui->saveImages->setEnabled( false );
208  ui->SaveImage->setEnabled( false );
209  ui->DeleteImage->setEnabled( false );
210  ui->OALExport->setEnabled( false );
211 
212  slotLoadWishList(); //Load the wishlist from disk if present
213  m_CurrentObject = 0;
214  setSaveImagesButton();
215  //Hide the MiniButton until I can figure out how to resize the Dialog!
216 // ui->MiniButton->hide();
217 }
218 
219 ObservingList::~ObservingList()
220 {
221  delete ksal;
222 }
223 
224 //SLOTS
225 
226 void ObservingList::slotAddObject( SkyObject *obj, bool session, bool update ) {
227  bool addToWishList=true;
228  if( ! obj )
229  obj = ks->map()->clickedObject();
230 
231  if ( !obj ) {
232  kWarning() << "Trying to add null object to observing list!";
233  }
234 
235  if( obj->name() == "star" ) {
236  KMessageBox::sorry(0, i18n( "Unnamed stars are not supported in the observing lists"));
237  return;
238  }
239 
240  //First, make sure object is not already in the list
241  if ( obsList().contains( obj ) ) {
242  addToWishList = false;
243  if( ! session ) {
244  ks->statusBar()->changeItem( i18n( "%1 is already in your wishlist.", obj->name() ), 0 );
245  return;
246  }
247  }
248 
249  if ( session && sessionList().contains( obj ) ) {
250  ks->statusBar()->changeItem( i18n( "%1 is already in the session plan.", obj->name() ), 0 );
251  return;
252  }
253 
254  QString smag = "--";
255  if ( - 30.0 < obj->mag() && obj->mag() < 90.0 )
256  smag = QString::number( obj->mag(), 'g', 2 ); // The lower limit to avoid display of unrealistic comet magnitudes
257 
258  SkyPoint p = obj->recomputeCoords( dt, geo );
259 
260  //Insert object in the Wish List
261  if( addToWishList ) {
262  m_ObservingList.append( obj );
263  m_CurrentObject = obj;
264  QList<QStandardItem*> itemList;
265 
266  QString ra, dec;
267 
268  if(obj->name() == "star" ) {
269  ra = obj->ra0().toHMSString();
270  dec = obj->dec0().toDMSString();
271  }
272  else {
273  ra = p.ra().toHMSString();
274  dec = p.dec().toDMSString();
275  }
276 
277  itemList << new QStandardItem( obj->translatedName() )
278  << new QStandardItem( obj->translatedLongName() )
279  << new QStandardItem( ra )
280  << new QStandardItem( dec )
281  << new QStandardItem( smag )
282  << new QStandardItem( obj->typeName() );
283 
284  m_Model->appendRow( itemList );
285  //Note addition in statusbar
286  ks->statusBar()->changeItem( i18n( "Added %1 to observing list.", obj->name() ), 0 );
287  ui->TableView->resizeColumnsToContents();
288  if( ! update ) slotSaveList();
289  }
290  //Insert object in the Session List
291  if( session ){
292  m_SessionList.append(obj);
293  dt.setTime( TimeHash.value( obj->name(), obj->transitTime( dt, geo ) ) );
294  dms lst(geo->GSTtoLST( dt.gst() ));
295  p.EquatorialToHorizontal( &lst, geo->lat() );
296  QList<QStandardItem*> itemList;
297 
298  QString ra, dec, time = "--", alt = "--", az = "--";
299 
300  QStandardItem *BestTime = new QStandardItem();
301  if(obj->name() == "star" ) {
302  ra = obj->ra0().toHMSString();
303  dec = obj->dec0().toDMSString();
304  BestTime->setData( QString( "--" ), Qt::DisplayRole );
305  }
306  else {
307  ra = p.ra().toHMSString();
308  dec = p.dec().toDMSString();
309  BestTime->setData( TimeHash.value( obj->name(), obj->transitTime( dt, geo ) ), Qt::DisplayRole );
310  alt = p.alt().toDMSString();
311  az = p.az().toDMSString();
312  }
313  // TODO: Change the rest of the parameters to their appropriate datatypes.
314  itemList << new QStandardItem( obj->translatedName() )
315  << new QStandardItem( obj->translatedLongName() )
316  << new QStandardItem( ra )
317  << new QStandardItem( dec )
318  << new QStandardItem( smag )
319  << new QStandardItem( obj->typeName() )
320  << BestTime
321  << new QStandardItem( alt )
322  << new QStandardItem( az );
323 
324  m_Session->appendRow( itemList );
325  //Adding an object should trigger the modified flag
326  isModified = true;
327  ui->SessionView->resizeColumnsToContents();
328  //Note addition in statusbar
329  ks->statusBar()->changeItem( i18n( "Added %1 to session list.", obj->name() ), 0 );
330  }
331  setSaveImagesButton();
332 }
333 
334 void ObservingList::slotRemoveObject( SkyObject *o, bool session, bool update ) {
335  if( ! update ) {
336  if ( ! o )
337  o = ks->map()->clickedObject();
338  else if( sessionView ) //else if is needed as clickedObject should not be removed from the session list.
339  session = true;
340  }
341 
342  QStandardItemModel *currentModel;
343 
344  int k;
345  if (! session) {
346  currentModel = m_Model;
347  k = obsList().indexOf( o );
348  }
349  else {
350  currentModel = m_Session;
351  k = sessionList().indexOf( o );
352  }
353 
354  if ( o == LogObject ) saveCurrentUserLog();
355  //Remove row from the TableView model
356  if ( o->name() == "star" ) {
357  //Find object in table by RA and Dec
358  for ( int irow = 0; irow < currentModel->rowCount(); ++irow ) {
359  QString ra = currentModel->item(irow, 1)->text();
360  QString dc = currentModel->item(irow, 2)->text();
361  if ( o->ra0().toHMSString() == ra && o->dec0().toDMSString() == dc ) {
362  currentModel->removeRow(irow);
363  break;
364  }
365  }
366  } else { // name is not "star"
367  //Find object in table by name
368  for ( int irow = 0; irow < currentModel->rowCount(); ++irow ) {
369  QString name = currentModel->item(irow, 0)->text();
370  if ( o->translatedName() == name ) {
371  currentModel->removeRow(irow);
372  break;
373  }
374  }
375  }
376 
377  if( ! session ) {
378  obsList().removeAt(k);
379  ui->View->removeAllPlotObjects();
380  ui->TableView->resizeColumnsToContents();
381  if( ! update )
382  slotSaveList();
383  } else {
384  if( ! update )
385  TimeHash.remove( o->name() );
386  sessionList().removeAt(k); //Remove from the session list
387  isModified = true; //Removing an object should trigger the modified flag
388  ui->View->removeAllPlotObjects();
389  ui->SessionView->resizeColumnsToContents();
390  }
391 }
392 
393 void ObservingList::slotRemoveSelectedObjects() {
394  QStandardItemModel *currentModel;
395 // ObservingListUI local_ui;
396  if ( sessionView )
397  currentModel = m_Session;
398  else
399  currentModel = m_Model;
400 
401  //Find each object by name in the session list, and remove it
402  //Go backwards so item alignment doesn't get screwed up as rows are removed.
403  for ( int irow = currentModel->rowCount()-1; irow >= 0; --irow ) {
404  bool rowSelected;
405  if ( sessionView )
406  rowSelected = ui->SessionView->selectionModel()->isRowSelected( irow, QModelIndex() );
407  else
408  rowSelected = ui->TableView->selectionModel()->isRowSelected( irow, QModelIndex() );
409 
410  if ( rowSelected ) {
411  QList<SkyObject*> currList;
412  QModelIndex mSortIndex, mIndex;
413  if ( sessionView ) {
414  mSortIndex = m_SortModelSession->index( irow, 0 );
415  mIndex = m_SortModelSession->mapToSource( mSortIndex );
416  currList = sessionList();
417  } else {
418  mSortIndex = m_SortModel->index( irow, 0 );
419  mIndex = m_SortModel->mapToSource( mSortIndex );
420  currList = obsList();
421  }
422 
423  int irow = mIndex.row();
424  QString ra = currentModel->item(irow, 1)->text();
425  QString dc = currentModel->item(irow, 2)->text();
426 
427  foreach ( SkyObject *o, currList ) {
428  //Stars named "star" must be matched by coordinates
429  if ( o->name() == "star" ) {
430  if ( o->ra0().toHMSString() == ra && o->dec0().toDMSString() == dc ) {
431  slotRemoveObject(o, sessionView);
432  break;
433  }
434  } else {
435  if ( o->translatedName() == mIndex.data().toString() ) {
436  slotRemoveObject(o, sessionView);
437  break;
438  }
439  }
440  }
441  }
442  }
443 
444  if (sessionView) {
445  //we've removed all selected objects, so clear the selection
446  ui->SessionView->selectionModel()->clear();
447  //Update the lists in the Execute window as well
448  ks->getExecute()->init();
449  }
450 
451  setSaveImagesButton();
452  ui->ImagePreview->setCursor( Qt::ArrowCursor );
453 }
454 
455 void ObservingList::slotNewSelection() {
456  bool found = false;
457  singleSelection = false;
458  noSelection = false;
459  showScope = false;
460  ui->ImagePreview->clearPreview();
461  ui->ImagePreview->setCursor( Qt::ArrowCursor );
462  QModelIndexList selectedItems;
463  QString newName;
464  SkyObject *o;
465  ui->SaveImage->setEnabled( false );
466  ui->DeleteImage->setEnabled( false );
467 
468  QStandardItemModel *currentModel;
469  QList<SkyObject*> currList;
470 
471  if ( sessionView ) {
472  selectedItems = m_SortModelSession->mapSelectionToSource( ui->SessionView->selectionModel()->selection() ).indexes();
473  currentModel = m_Session;
474  currList = sessionList();
475  } else {
476  selectedItems = m_SortModel->mapSelectionToSource( ui->TableView->selectionModel()->selection() ).indexes();
477  currentModel = m_Model;
478  currList = obsList();
479  }
480 
481  if ( selectedItems.size() == currentModel->columnCount() ) {
482  newName = selectedItems[0].data().toString();
483  singleSelection = true;
484  //Find the selected object in the SessionList,
485  //then break the loop. Now SessionList.current()
486  //points to the new selected object (until now it was the previous object)
487  foreach ( o, currList ) {
488  if ( o->translatedName() == newName ) {
489  found = true;
490  break;
491  }
492  }
493  }
494 
495  if( singleSelection ) {
496  //Enable buttons
497  ui->ImagePreview->setCursor( Qt::PointingHandCursor );
498  #ifdef HAVE_INDI_H
499  showScope = true;
500  #endif
501  setDefaultImage();
502  if ( found ) {
503  m_CurrentObject = o;
504  QPoint pos(0,0);
505  plot( o );
506  //Change the CurrentImage, DSS/SDSS Url to correspond to the new object
507  setCurrentImage( o );
508  ui->GoogleImage->setEnabled( true );
509  if ( newName != i18n( "star" ) ) {
510  //Display the current object's user notes in the NotesEdit
511  //First, save the last object's user log to disk, if necessary
512  saveCurrentUserLog(); //uses LogObject, which is still the previous obj.
513  //set LogObject to the new selected object
514  LogObject = currentObject();
515  ui->NotesLabel->setEnabled( true );
516  ui->NotesEdit->setEnabled( true );
517  ui->NotesLabel->setText( i18n( "observing notes for %1:", LogObject->translatedName() ) );
518  if ( LogObject->userLog().isEmpty() ) {
519  ui->NotesEdit->setPlainText( i18n( "Record here observation logs and/or data on %1.", LogObject->translatedName() ) );
520  } else {
521  ui->NotesEdit->setPlainText( LogObject->userLog() );
522  }
523  if( sessionView ) {
524  ui->TimeEdit->setEnabled( true );
525  ui->SetTime->setEnabled( true );
526  ui->TimeEdit->setTime( TimeHash.value( o->name(), o->transitTime( dt, geo ) ) );
527  }
528  } else { //selected object is named "star"
529  //clear the log text box
530  saveCurrentUserLog();
531  ui->NotesLabel->setText( i18n( "observing notes (disabled for unnamed star)" ) );
532  ui->NotesLabel->setEnabled( false );
533  ui->NotesEdit->clear();
534  ui->NotesEdit->setEnabled( false );
535  ui->GoogleImage->setEnabled( false );
536  }
537  if( QFile( KStandardDirs::locateLocal( "appdata", CurrentImage ) ).size() > 13000 ) {//If the image is present, show it!
538  ui->ImagePreview->showPreview( KUrl( KStandardDirs::locateLocal( "appdata", CurrentImage ) ) );
539  ui->ImagePreview->show();
540  ui->SaveImage->setEnabled( false );
541  ui->DeleteImage->setEnabled( true );
542  } else if( QFile( KStandardDirs::locateLocal( "appdata", "Temp_" + CurrentImage ) ).size() > 13000 ) {
543  ui->ImagePreview->showPreview( KUrl( KStandardDirs::locateLocal( "appdata","Temp_" + CurrentImage ) ) );
544  ui->ImagePreview->show();
545  ui->SaveImage->setEnabled( true );
546  ui->DeleteImage->setEnabled( true );
547  }
548  } else {
549  kDebug() << i18n( "Object %1 not found in list.", newName );
550  }
551  } else {
552  if ( selectedItems.size() == 0 ) {//Nothing selected
553  //Disable buttons
554  noSelection = true;
555  ui->NotesLabel->setText( i18n( "Select an object to record notes on it here:" ) );
556  ui->NotesLabel->setEnabled( false );
557  ui->NotesEdit->setEnabled( false );
558  m_CurrentObject = 0;
559  ui->TimeEdit->setEnabled( false );
560  ui->SetTime->setEnabled( false );
561  ui->GoogleImage->setEnabled( false );
562  //Clear the user log text box.
563  saveCurrentUserLog();
564  ui->NotesEdit->setPlainText("");
565  //Clear the plot in the AVTPlotwidget
566  ui->View->removeAllPlotObjects();
567  } else { //more than one object selected.
568  ui->NotesLabel->setText( i18n( "Select a single object to record notes on it here:" ) );
569  ui->NotesLabel->setEnabled( false );
570  ui->NotesEdit->setEnabled( false );
571  ui->TimeEdit->setEnabled( false );
572  ui->SetTime->setEnabled( false );
573  ui->GoogleImage->setEnabled( false );
574  m_CurrentObject = 0;
575  //Clear the plot in the AVTPlotwidget
576  ui->View->removeAllPlotObjects();
577  //Clear the user log text box.
578  saveCurrentUserLog();
579  ui->NotesEdit->setPlainText("");
580  }
581  }
582 }
583 
584 void ObservingList::slotCenterObject() {
585  QModelIndexList selectedItems;
586  if (sessionView) {
587  selectedItems = ui->SessionView->selectionModel()->selectedRows();
588  } else {
589  selectedItems = ui->TableView->selectionModel()->selectedRows();
590  }
591 
592  if (selectedItems.size() == 1) {
593  ks->map()->setClickedObject( currentObject() );
594  ks->map()->setClickedPoint( currentObject() );
595  ks->map()->slotCenter();
596  }
597 }
598 
599 void ObservingList::slotSlewToObject()
600 {
601 #ifdef HAVE_INDI_H
602 
603  if (INDIListener::Instance()->size() == 0)
604  {
605  KMessageBox::sorry(0, i18n("KStars did not find any active telescopes."));
606  return;
607  }
608 
609  foreach(ISD::GDInterface *gd, INDIListener::Instance()->getDevices())
610  {
611  INDI::BaseDevice *bd = gd->getBaseDevice();
612 
613  if (gd->getType() != KSTARS_TELESCOPE)
614  continue;
615 
616  if (bd == NULL)
617  continue;
618 
619  if (bd->isConnected() == false)
620  {
621  KMessageBox::error(0, i18n("Telescope %1 is offline. Please connect and retry again.", gd->getDeviceName()));
622  return;
623  }
624 
625 
626  ISD::GDSetCommand SlewCMD(INDI_SWITCH, "ON_COORD_SET", "SLEW", ISS_ON, this);
627 
628  gd->setProperty(&SlewCMD);
629  gd->runCommand(INDI_SEND_COORDS, currentObject());
630 
631  return;
632 
633  }
634 
635  KMessageBox::sorry(0, i18n("KStars did not find any active telescopes."));
636 
637 #endif
638 }
639 
640 //FIXME: This will open multiple Detail windows for each object;
641 //Should have one window whose target object changes with selection
642 void ObservingList::slotDetails() {
643  if ( currentObject() ) {
644  QPointer<DetailDialog> dd = new DetailDialog( currentObject(), ks->data()->lt(), geo, ks );
645  dd->exec();
646  delete dd;
647  }
648 }
649 
650 void ObservingList::slotWUT() {
651  KStarsDateTime lt = dt;
652  lt.setTime( QTime(8,0,0) );
653  QPointer<WUTDialog> w = new WUTDialog( ks, sessionView, geo, lt );
654  w->exec();
655  delete w;
656 }
657 
658 void ObservingList::slotAddToSession() {
659  QModelIndexList selectedItems = m_SortModel->mapSelectionToSource( ui->TableView->selectionModel()->selection() ).indexes();
660  if ( selectedItems.size() ) {
661  foreach ( const QModelIndex &i, selectedItems ) {
662  foreach ( SkyObject *o, obsList() ) {
663  if ( o->translatedName() == i.data().toString() )
664  slotAddObject( o, true );
665  }
666  }
667  }
668 }
669 
670 void ObservingList::slotFind() {
671  QPointer<FindDialog> fd = new FindDialog( ks );
672  if ( fd->exec() == QDialog::Accepted ) {
673  SkyObject *o = fd->selectedObject();
674  if( o != 0 ) {
675  slotAddObject( o, sessionView );
676  }
677  }
678  delete fd;
679 }
680 
681 void ObservingList::slotAVT() {
682  QModelIndexList selectedItems;
683  // TODO: Think and see if there's a more effecient way to do this. I can't seem to think of any, but this code looks like it could be improved. - Akarsh
684  if( sessionView ) {
685  QPointer<AltVsTime> avt = new AltVsTime( ks );//FIXME KStars class is singleton, so why pass it?
686  for ( int irow = m_Session->rowCount()-1; irow >= 0; --irow ) {
687  if ( ui->SessionView->selectionModel()->isRowSelected( irow, QModelIndex() ) ) {
688  QModelIndex mSortIndex = m_SortModelSession->index( irow, 0 );
689  QModelIndex mIndex = m_SortModelSession->mapToSource( mSortIndex );
690  int irow = mIndex.row();
691  QString ra = m_Session->item(irow, 1)->text();
692  QString dc = m_Session->item(irow, 2)->text();
693  foreach ( SkyObject *o, sessionList() ) {
694  //Stars named "star" must be matched by coordinates
695  if ( o->name() == "star" ) {
696  if ( o->ra0().toHMSString() == ra && o->dec0().toDMSString() == dc ) {
697  avt->processObject( o );
698  break;
699  }
700 
701  } else if ( o->translatedName() == mIndex.data().toString() ) {
702  avt->processObject( o );
703  break;
704  }
705  }
706  }
707  }
708  avt->exec();
709  delete avt;
710  } else {
711  selectedItems = m_SortModel->mapSelectionToSource( ui->TableView->selectionModel()->selection() ).indexes();
712  if ( selectedItems.size() ) {
713  QPointer<AltVsTime> avt = new AltVsTime( ks );//FIXME KStars class is singleton, so why pass it?
714  foreach ( const QModelIndex &i, selectedItems ) {
715  foreach ( SkyObject *o, obsList() )
716  if ( o->translatedName() == i.data().toString() )
717  avt->processObject( o );
718  }
719  avt->exec();
720  delete avt;
721  }
722  }
723 }
724 
725 //FIXME: On close, we will need to close any open Details/AVT windows
726 void ObservingList::slotClose() {
727  //Save the current User log text
728  saveCurrentUserLog();
729  ui->View->removeAllPlotObjects();
730  slotNewSelection();
731  saveCurrentList();
732  hide();
733 }
734 
735 void ObservingList::saveCurrentUserLog() {
736  if ( ! ui->NotesEdit->toPlainText().isEmpty() &&
737  ui->NotesEdit->toPlainText() !=
738  i18n( "Record here observation logs and/or data on %1.", LogObject->translatedName() ) ) {
739  LogObject->saveUserLog( ui->NotesEdit->toPlainText() );
740  ui->NotesEdit->clear();
741  ui->NotesLabel->setText( i18n( "Observing notes for object:" ) );
742  LogObject = NULL;
743  }
744 }
745 
746 void ObservingList::slotOpenList() {
747  KUrl fileURL = KFileDialog::getOpenUrl( QDir::homePath(), "*.obslist|KStars Observing List (*.obslist)" );
748  QFile f;
749  if ( fileURL.isValid() ) {
750  if ( ! fileURL.isLocalFile() ) {
751  //Save remote list to a temporary local file
752  KTemporaryFile tmpfile;
753  tmpfile.setAutoRemove(false);
754  tmpfile.open();
755  FileName = tmpfile.fileName();
756  if( KIO::NetAccess::download( fileURL, FileName, this ) )
757  f.setFileName( FileName );
758 
759  } else {
760  FileName = fileURL.toLocalFile();
761  f.setFileName( FileName );
762  }
763 
764  if ( ! f.open( QIODevice::ReadOnly) ) {
765  QString message = i18n( "Could not open file %1", f.fileName() );
766  KMessageBox::sorry( 0, message, i18n( "Could Not Open File" ) );
767  return;
768  }
769  saveCurrentList();//See if the current list needs to be saved before opening the new one
770  ui->tabWidget->setCurrentIndex(1);
771  slotChangeTab(1);
772  sessionList().clear();
773  TimeHash.clear();
774  m_CurrentObject = 0;
775  m_Session->removeRows( 0, m_Session->rowCount() );
776  //First line is the name of the list. The rest of the file is
777  //object names, one per line. With the TimeHash value if present
778  QTextStream istream( &f );
779  QString input;
780  input = istream.readAll();
781  OAL::Log logObject;
782  logObject.readBegin( input );
783  //Set the New TimeHash
784  TimeHash = logObject.timeHash();
785  geo = logObject.geoLocation();
786  dt = logObject.dateTime();
787  foreach( SkyObject *o, *( logObject.targetList() ) )
788  slotAddObject( o, true );
789  //Update the location and user set times from file
790  slotUpdate();
791  //Newly-opened list should not trigger isModified flag
792  isModified = false;
793  f.close();
794  } else if ( ! fileURL.path().isEmpty() ) {
795  KMessageBox::sorry( 0 , i18n( "The specified file is invalid" ) );
796  }
797 }
798 
799 void ObservingList::saveCurrentList() {
800  //Before loading a new list, do we need to save the current one?
801  //Assume that if the list is empty, then there's no need to save
802  if ( sessionList().size() ) {
803  if ( isModified ) {
804  QString message = i18n( "Do you want to save the current session?" );
805  if ( KMessageBox::questionYesNo( this, message,
806  i18n( "Save Current session?" ), KStandardGuiItem::save(), KStandardGuiItem::discard() ) == KMessageBox::Yes )
807  slotSaveSession();
808  }
809  }
810 }
811 
812 void ObservingList::slotSaveSessionAs(bool nativeSave) {
813  KUrl fileURL = KFileDialog::getSaveUrl( QDir::homePath(), "*.obslist|KStars Observing List (*.obslist)" );
814  if ( fileURL.isValid() ) {
815  FileName = fileURL.path();
816  slotSaveSession(nativeSave);
817  }
818 }
819 
820 void ObservingList::slotSaveList() {
821  QFile f;
822  f.setFileName( KStandardDirs::locateLocal( "appdata", "wishlist.obslist" ) );
823  if ( ! f.open( QIODevice::WriteOnly ) ) {
824  kDebug() << "Cannot write list to file";
825  return;
826  }
827  QTextStream ostream( &f );
828  foreach ( SkyObject* o, obsList() ) {
829  if ( !o ) {
830  kWarning() << "Null entry in observing wishlist!";
831  continue;
832  }
833  if ( o->name() == "star" ) {
834  ostream << o->name() << " " << o->ra0().Hours() << " " << o->dec0().Degrees() << endl;
835  } else if ( o->type() == SkyObject::STAR ) {
836  StarObject *s = (StarObject*)o;
837  if ( s->name() == s->gname() )
838  ostream << s->name2() << endl;
839  else
840  ostream << s->name() << endl;
841  } else {
842  ostream << o->name() << endl;
843  }
844  }
845  f.close();
846 }
847 
848 void ObservingList::slotLoadWishList() {
849  QFile f;
850  f.setFileName( KStandardDirs::locateLocal( "appdata", "wishlist.obslist" ) );
851  if ( ! f.open( QIODevice::ReadOnly) ) {
852  kDebug() << "No WishList Saved yet";
853  return;
854  }
855  QTextStream istream( &f );
856  QString line;
857  while ( ! istream.atEnd() ) {
858  line = istream.readLine();
859  //If the object is named "star", add it by coordinates
860  SkyObject *o;
861  if ( line.startsWith( QLatin1String( "star" ) ) ) {
862  QStringList fields = line.split( ' ', QString::SkipEmptyParts );
863  dms ra = dms::fromString( fields[1], false ); //false = hours
864  dms dc = dms::fromString( fields[2], true ); //true = degrees
865  SkyPoint p( ra, dc );
866  double maxrad = 1000.0/Options::zoomFactor();
867  o = ks->data()->skyComposite()->starNearest( &p, maxrad );
868  } else {
869  o = ks->data()->objectNamed( line );
870  }
871  //If we haven't identified the object, try interpreting the
872  //name as a star's genetive name (with ascii letters)
873  if ( ! o ) o = ks->data()->skyComposite()->findStarByGenetiveName( line );
874  if ( o ) slotAddObject( o, false, true );
875  }
876  f.close();
877 }
878 
879 void ObservingList::slotSaveSession(bool nativeSave) {
880  if ( FileName.isEmpty() ) {
881  slotSaveSessionAs(nativeSave);
882  return;
883  }
884  QFile f( FileName );
885  if( ! f.open( QIODevice::WriteOnly ) ) {
886  QString message = i18n( "Could not open file %1. Try a different filename?", f.fileName() );
887  if ( KMessageBox::warningYesNo( 0, message, i18n( "Could Not Open File" ), KGuiItem(i18n("Try Different")), KGuiItem(i18n("Do Not Try")) ) == KMessageBox::Yes ) {
888  FileName.clear();
889  slotSaveSessionAs(nativeSave);
890  }
891  return;
892  }
893  QTextStream ostream( &f );
894  OAL::Log log;
895  ostream<< log.writeLog( nativeSave );
896  f.close();
897  isModified = false;//We've saved the session, so reset the modified flag.
898 }
899 
900 void ObservingList::slotWizard() {
901  QPointer<ObsListWizard> wizard = new ObsListWizard( ks );
902  if ( wizard->exec() == QDialog::Accepted ) {
903  foreach ( SkyObject *o, wizard->obsList() ) {
904  slotAddObject( o );
905  }
906  }
907  delete wizard;
908 }
909 
910 void ObservingList::plot( SkyObject *o ) {
911  if( !o )
912  return;
913  float DayOffset = 0;
914  if( TimeHash.value( o->name(), o->transitTime( dt, geo ) ).hour() > 12 )
915  DayOffset = 1;
916  KStarsDateTime ut = dt; // This is still local time; we must convert it to UT.
917  ut.setTime(QTime());
918  ut = geo->LTtoUT(ut); // We convert it to UT. Now it makes sense.
919  ut = ut.addSecs( ( 0.5 + DayOffset ) * 86400.0 );
920 
921  double h1 = geo->GSTtoLST( ut.gst() ).Hours();
922  if ( h1 > 12.0 )
923  h1 -= 24.0;
924 
925  ui->View->setSecondaryLimits( h1, h1 + 24.0, -90.0, 90.0 );
926  ksal->setLocation(geo);
927  ksal->setDate( &ut );
928  ui->View->setSunRiseSetTimes( ksal->getSunRise(), ksal->getSunSet() );
929  ui->View->setDawnDuskTimes( ksal->getDawnAstronomicalTwilight(), ksal->getDuskAstronomicalTwilight() );
930  ui->View->update();
931  KPlotObject *po = new KPlotObject( Qt::white, KPlotObject::Lines, 2.0 );
932  for ( double h = -12.0; h <= 12.0; h += 0.5 ) {
933  po->addPoint( h, findAltitude( o, ( h + DayOffset * 24.0 ) ) );
934  }
935  ui->View->removeAllPlotObjects();
936  ui->View->addPlotObject( po );
937 }
938 
939 double ObservingList::findAltitude( SkyPoint *p, double hour ) {
940  KStarsDateTime ut = dt;
941  ut.setTime( QTime() );
942  ut = geo->LTtoUT( ut );
943  ut= ut.addSecs( hour*3600.0 );
944  dms LST = geo->GSTtoLST( ut.gst() );
945  p->EquatorialToHorizontal( &LST, geo->lat() );
946  return p->alt().Degrees();
947 }
948 
949 void ObservingList::slotToggleSize() {
950  if ( isLarge() ) {
951  ui->MiniButton->setIcon( KIcon("view-fullscreen") );
952  //Abbreviate text on each button
953  ui->FindButton->setText( i18nc( "First letter in 'Find'", "F" ) );
954  //Hide columns 1-5
955  ui->TableView->hideColumn(1);
956  ui->TableView->hideColumn(2);
957  ui->TableView->hideColumn(3);
958  ui->TableView->hideColumn(4);
959  ui->TableView->hideColumn(5);
960  //Hide the headers
961  ui->TableView->horizontalHeader()->hide();
962  ui->TableView->verticalHeader()->hide();
963  //Hide Observing notes
964  ui->NotesLabel->hide();
965  ui->NotesEdit->hide();
966  ui->View->hide();
967  //Set the width of the Table to be the width of 5 toolbar buttons,
968  //or the width of column 1, whichever is larger
969  int w = 5*ui->MiniButton->width();
970  if ( ui->TableView->columnWidth(0) > w ) {
971  w = ui->TableView->columnWidth(0);
972  } else {
973  ui->TableView->setColumnWidth(0, w);
974  }
975  int left, right, top, bottom;
976  ui->layout()->getContentsMargins( &left, &top, &right, &bottom );
977  resize( w + left + right, height() );
978  bIsLarge = false;
979  } else {
980  ui->MiniButton->setIcon( KIcon( "view-restore" ) );
981  //Show columns 1-5
982  ui->TableView->showColumn(1);
983  ui->TableView->showColumn(2);
984  ui->TableView->showColumn(3);
985  ui->TableView->showColumn(4);
986  ui->TableView->showColumn(5);
987  //Show the horizontal header
988  ui->TableView->horizontalHeader()->show();
989  //Expand text on each button
990  ui->WUTButton->setText( i18n( "WUT") );
991  ui->FindButton->setText( i18n( "Find &Object") );
992  //Show Observing notes
993  ui->NotesLabel->show();
994  ui->NotesEdit->show();
995  ui->View->show();
996  adjustSize();
997  bIsLarge = true;
998  }
999 }
1000 
1001 void ObservingList::slotChangeTab(int index) {
1002  noSelection = true;
1003  saveCurrentUserLog();
1004  ui->NotesLabel->setText( i18n( "Select an object to record notes on it here:" ) );
1005  ui->NotesLabel->setEnabled( false );
1006  ui->NotesEdit->setEnabled( false );
1007  ui->TimeEdit->setEnabled( false );
1008  ui->SetTime->setEnabled( false );
1009  ui->GoogleImage->setEnabled( false );
1010  ui->SaveImage->setEnabled( false );
1011  ui->DeleteImage->setEnabled( false );
1012  m_CurrentObject = 0;
1013  sessionView = index != 0;
1014  setSaveImagesButton();
1015  ui->WizardButton->setEnabled( ! sessionView );//wizard adds only to the Wish List
1016  ui->OALExport->setEnabled( sessionView );
1017  //Clear the selection in the Tables
1018  ui->TableView->clearSelection();
1019  ui->SessionView->clearSelection();
1020  //Clear the user log text box.
1021  saveCurrentUserLog();
1022  ui->NotesEdit->setPlainText("");
1023  ui->View->removeAllPlotObjects();
1024 }
1025 
1026 void ObservingList::slotLocation() {
1027  QPointer<LocationDialog> ld = new LocationDialog( this );
1028  if ( ld->exec() == QDialog::Accepted ) {
1029  geo = ld->selectedCity();
1030  ui->SetLocation -> setText( geo -> fullName() );
1031  }
1032  delete ld;
1033 }
1034 
1035 void ObservingList::slotUpdate() {
1036  dt.setDate( ui->DateEdit->date() );
1037  ui->View->removeAllPlotObjects();
1038  //Creating a copy of the lists, we can't use the original lists as they'll keep getting modified as the loop iterates
1039  QList<SkyObject*> _obsList=m_ObservingList, _SessionList=m_SessionList;
1040  foreach ( SkyObject *o, _obsList ) {
1041  if( o->name() != "star" ) {
1042  slotRemoveObject( o, false, true );
1043  slotAddObject( o, false, true );
1044  }
1045  }
1046  foreach ( SkyObject *obj, _SessionList ) {
1047  if( obj->name() != "star" ) {
1048  slotRemoveObject( obj, true, true );
1049  slotAddObject( obj, true, true );
1050  }
1051  }
1052 }
1053 
1054 void ObservingList::slotSetTime() {
1055  SkyObject *o = currentObject();
1056  slotRemoveObject( o, true );
1057  TimeHash [o->name()] = ui->TimeEdit->time();
1058  slotAddObject( o, true, true );
1059 }
1060 
1061 void ObservingList::slotGetImage( bool _dss ) {
1062  dss = _dss;
1063  ui->GoogleImage->setEnabled( false );
1064  ui->ImagePreview->clearPreview();
1065  if( ! QFile::exists( KStandardDirs::locateLocal( "appdata", CurrentImage ) ) )
1066  setCurrentImage( currentObject(), true );
1067  QFile::remove( KStandardDirs::locateLocal( "appdata", CurrentImage ) );
1068  KUrl url;
1069  if( dss ) {
1070  url.setUrl( DSSUrl );
1071  } else {
1072  url.setUrl( SDSSUrl );
1073  }
1074  downloadJob = KIO::copy ( url, KUrl( KStandardDirs::locateLocal( "appdata", CurrentImage ) ) );
1075  connect ( downloadJob, SIGNAL ( result (KJob *) ), SLOT ( downloadReady() ) );
1076 }
1077 
1078 void ObservingList::downloadReady() {
1079  // set downloadJob to 0, but don't delete it - the job will be deleted automatically
1080  downloadJob = 0;
1081  if( QFile( KStandardDirs::locateLocal( "appdata", CurrentImage ) ).size() > 13000 ) {//The default image is around 8689 bytes
1082  ui->ImagePreview->showPreview( KUrl( KStandardDirs::locateLocal( "appdata", CurrentImage ) ) );
1083  saveThumbImage();
1084  ui->ImagePreview->show();
1085  ui->ImagePreview->setCursor( Qt::PointingHandCursor );
1086  if( CurrentImage.contains( "Temp" ) ) {
1087  ImageList.append( CurrentImage );
1088  ui->SaveImage->setEnabled( true );
1089  }
1090  ui->DeleteImage->setEnabled( true );
1091  }
1092  else if( ! dss )
1093  slotGetImage( true );
1094 }
1095 
1096 void ObservingList::setCurrentImage( const SkyObject *o, bool temp ) {
1097  // TODO: Remove code duplication -- we have the same stuff
1098  // implemented in SkyMap::slotDSS in skymap.cpp; must try to
1099  // de-duplicate as much as possible.
1100 
1101  if( temp )
1102  CurrentImage = "Temp_Image_" + o->name().remove(' ');
1103  else
1104  CurrentImage = "Image_" + o->name().remove(' ');
1105  ThumbImage = "thumb-" + o->name().toLower().remove(' ') + ".png";
1106  if( o->name() == "star" ) {
1107  QString RAString( o->ra0().toHMSString() );
1108  QString DecString( o->dec0().toDMSString() );
1109  if( temp )
1110  CurrentImage = "Temp_Image" + RAString.remove(' ') + DecString.remove(' ');
1111  else
1112  CurrentImage = "Image" + RAString.remove(' ') + DecString.remove(' ');
1113  QChar decsgn = ( (o->dec0().Degrees() < 0.0 ) ? '-' : '+' );
1114  CurrentImage = CurrentImage.remove('+').remove('-') + decsgn;
1115  }
1116  CurrentImagePath = KStandardDirs::locateLocal( "appdata" , CurrentImage );
1117  CurrentTempPath = KStandardDirs::locateLocal( "appdata", "Temp_" + CurrentImage ); // FIXME: Eh? -- asimha
1118  DSSUrl = KSUtils::getDSSURL( o );
1119  QString UrlPrefix("http://casjobs.sdss.org/ImgCutoutDR6/getjpeg.aspx?");
1120  QString UrlSuffix("&scale=1.0&width=600&height=600&opt=GST&query=SR(10,20)");
1121 
1122  QString RA, Dec;
1123  RA = RA.sprintf( "ra=%f", o->ra0().Degrees() );
1124  Dec = Dec.sprintf( "&dec=%f", o->dec0().Degrees() );
1125 
1126  SDSSUrl = UrlPrefix + RA + Dec + UrlSuffix;
1127 }
1128 
1129 void ObservingList::slotSaveAllImages() {
1130  ui->GoogleImage->setEnabled( false );
1131  ui->SaveImage->setEnabled( false );
1132  ui->DeleteImage->setEnabled( false );
1133  m_CurrentObject = 0;
1134  //Clear the selection in the Tables
1135  ui->TableView->clearSelection();
1136  ui->SessionView->clearSelection();
1137 
1138  QList<SkyObject*> currList;
1139  if ( sessionView )
1140  currList = sessionList();
1141  else
1142  currList = obsList();
1143 
1144  foreach( SkyObject *o, currList ) {
1145  setCurrentImage( o );
1146  QString img( CurrentImagePath );
1147  KUrl url( ( Options::obsListPreferDSS() ) ? DSSUrl : SDSSUrl );
1148  if( ! o->isSolarSystem() )//TODO find a way for adding support for solar system images
1149  saveImage( url, img );
1150  }
1151 }
1152 
1153 void ObservingList::saveImage( KUrl url, QString filename ) {
1154  if( ! QFile::exists( CurrentImagePath ) && ! QFile::exists( CurrentTempPath ) ) {
1155  if( KIO::NetAccess::download( url, filename, mainWidget() ) ) {
1156  if( QFile( CurrentImagePath ).size() < 13000 ) {//The default image is around 8689 bytes FIXME: This seems to have changed
1157  url = KUrl( DSSUrl );
1158  KIO::NetAccess::download( url, filename, mainWidget() );
1159  }
1160  saveThumbImage();
1161  }
1162  } else if( QFile::exists( CurrentTempPath ) ) {
1163  QFile f( CurrentTempPath );
1164  f.rename( CurrentImagePath );
1165  }
1166 }
1167 
1168 void ObservingList::slotSaveImage() {
1169  setCurrentImage( currentObject() );
1170  QFile f( CurrentTempPath);
1171  f.rename( CurrentImagePath );
1172  ui->SaveImage->setEnabled( false );
1173 }
1174 
1175 void ObservingList::slotImageViewer() {
1176  ImageViewer *iv = 0;
1177  if( QFile::exists( CurrentImagePath ) )
1178  iv = new ImageViewer( CurrentImagePath, this );
1179  else if( QFile::exists( CurrentTempPath ) )
1180  iv = new ImageViewer( CurrentTempPath, this );
1181 
1182  if( iv )
1183  iv->show();
1184 }
1185 
1186 void ObservingList::slotDeleteAllImages() {
1187  if( KMessageBox::warningYesNo( 0, i18n( "This will delete all saved images. Are you sure you want to do this?" ), i18n( "Delete All Images" ) ) == KMessageBox::No )
1188  return;
1189  ui->ImagePreview->setCursor( Qt::ArrowCursor );
1190  ui->GoogleImage->setEnabled( false );
1191  ui->SaveImage->setEnabled( false );
1192  ui->DeleteImage->setEnabled( false );
1193  m_CurrentObject = 0;
1194  //Clear the selection in the Tables
1195  ui->TableView->clearSelection();
1196  ui->SessionView->clearSelection();
1197  ui->ImagePreview->clearPreview();
1198  QDirIterator iterator( KStandardDirs::locateLocal( "appdata", "" ) );
1199  while( iterator.hasNext() )
1200  {
1201  // TODO: Probably, there should be a different directory for cached images in the observing list.
1202  if( iterator.fileName().contains( "Image" ) && ( ! iterator.fileName().contains( "dat" ) ) && ( ! iterator.fileName().contains( "obslist" ) ) ) {
1203  QFile file( iterator.filePath() );
1204  file.remove();
1205  }
1206  iterator.next();
1207  }
1208 }
1209 
1210 void ObservingList::setSaveImagesButton() {
1211  ui->saveImages->setEnabled(
1212  (sessionView && !sessionList().isEmpty()) ||
1213  !obsList().isEmpty()
1214  );
1215 }
1216 
1217 // FIXME: Is there a reason to implement these as an event filter,
1218 // instead of as a signal-slot connection? Shouldn't we just use slots
1219 // to subscribe to various events from the Table / Session view?
1220 
1221 bool ObservingList::eventFilter( QObject *obj, QEvent *event ) {
1222  if( obj == ui->ImagePreview ) {
1223  if( event->type() == QEvent::MouseButtonRelease ) {
1224  if( currentObject() ) {
1225  if( ( ( QFile( CurrentImagePath ).size() < 13000 ) && ( QFile( CurrentTempPath ).size() < 13000 ) ) ) { // FIXME: This size estimate is unreliable.
1226  if( ! currentObject()->isSolarSystem() )
1227  slotGetImage( Options::obsListPreferDSS() );
1228  else
1229  slotGoogleImage();
1230  }
1231  else
1232  slotImageViewer();
1233  }
1234  return true;
1235  }
1236  }
1237  if( obj == ui->TableView->viewport() && ! noSelection ) {
1238  if( event->type() == QEvent::MouseButtonRelease ) {
1239  QMouseEvent *mouseEvent = static_cast<QMouseEvent* >(event);
1240  if( mouseEvent->button() == Qt::RightButton ) {
1241  QPoint pos( mouseEvent->globalX() , mouseEvent->globalY() );
1242  if( singleSelection )
1243  pmenu->initPopupMenu( true, true, true, showScope, true, true );
1244  else
1245  pmenu->initPopupMenu( true, false, false, false, true );
1246  pmenu->popup( pos );
1247  return true;
1248  }
1249  }
1250  }
1251 
1252  if( obj == ui->SessionView->viewport() && ! noSelection ) {
1253  if( event->type() == QEvent::MouseButtonRelease ) {
1254  QMouseEvent *mouseEvent = static_cast<QMouseEvent* >(event);
1255  if( mouseEvent->button() == Qt::RightButton ) {
1256  QPoint pos( mouseEvent->globalX() , mouseEvent->globalY() );
1257  if( singleSelection )
1258  pmenu->initPopupMenu( false, true, true, showScope, true, true, true );
1259  else
1260  pmenu->initPopupMenu( false, false, false, false, true, false, true );
1261  pmenu->popup( pos );
1262  return true;
1263  }
1264  }
1265  }
1266 
1267  if( obj == ui->TableView || obj == ui->SessionView)
1268  {
1269  if (event->type() == QEvent::KeyPress)
1270  {
1271  QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
1272  if (keyEvent->key() == Qt::Key_Delete) {
1273  slotRemoveSelectedObjects();
1274  return true;
1275  }
1276  }
1277 
1278  }
1279 
1280  return false;
1281 }
1282 
1283 void ObservingList::slotGoogleImage() {
1284  QPixmap *pm = new QPixmap;
1285  QPointer<ThumbnailPicker> tp = new ThumbnailPicker( currentObject(), *pm, this, 600, 600, i18n( "Image Chooser" ) );
1286  if ( tp->exec() == QDialog::Accepted ) {
1287  QFile f( CurrentImagePath );
1288 
1289  //If a real image was set, save it.
1290  if ( tp->imageFound() ) {
1291  tp->image()->save( f.fileName(), "PNG" );
1292  ui->ImagePreview->showPreview( KUrl( f.fileName() ) );
1293  saveThumbImage();
1294  slotNewSelection();
1295  }
1296  }
1297  delete tp;
1298 }
1299 
1300 void ObservingList::slotDeleteCurrentImage() {
1301  QFile::remove( CurrentImagePath );
1302  QFile::remove( CurrentTempPath );
1303  slotNewSelection();
1304 }
1305 
1306 void ObservingList::saveThumbImage() {
1307  if( ! QFile::exists( KStandardDirs::locateLocal( "appdata", ThumbImage ) ) ) {
1308  QImage img( CurrentImagePath );
1309  img = img.scaled( 200, 200, Qt::IgnoreAspectRatio, Qt::SmoothTransformation );
1310  img.save( KStandardDirs::locateLocal( "appdata", ThumbImage ) );
1311  }
1312 }
1313 
1314 void ObservingList::slotOALExport() {
1315  slotSaveSessionAs(false);
1316 }
1317 
1318 void ObservingList::slotAddVisibleObj() {
1319  KStarsDateTime lt = dt;
1320  lt.setTime( QTime(8,0,0) );
1321  QPointer<WUTDialog> w = new WUTDialog( ks, sessionView, geo, lt );
1322  w->init();
1323  QModelIndexList selectedItems;
1324  selectedItems = m_SortModel->mapSelectionToSource( ui->TableView->selectionModel()->selection() ).indexes();
1325  if ( selectedItems.size() )
1326  foreach ( const QModelIndex &i, selectedItems ) {
1327  foreach ( SkyObject *o, obsList() )
1328  if ( o->translatedName() == i.data().toString() && w->checkVisibility( o ) )
1329  slotAddObject( o, true );
1330  }
1331  delete w;
1332 }
1333 
1334 SkyObject* ObservingList::findObjectByName( QString name ) {
1335  foreach( SkyObject* o, sessionList() )
1336  if( o->name() == name )
1337  return o;
1338  return NULL;
1339 }
1340 
1341 void ObservingList::selectObject( const SkyObject *o ) {
1342  ui->tabWidget->setCurrentIndex( 1 );
1343  ui->SessionView->selectionModel()->clear();
1344  for ( int irow = m_Session->rowCount()-1; irow >= 0; --irow ) {
1345  QModelIndex mSortIndex = m_SortModelSession->index( irow, 0 );
1346  QModelIndex mIndex = m_SortModelSession->mapToSource( mSortIndex );
1347  int idxrow = mIndex.row();
1348  if( m_Session->item(idxrow, 0)->text() == o->translatedName() )
1349  ui->SessionView->selectRow( idxrow );
1350  slotNewSelection();
1351  }
1352 }
1353 
1354 void ObservingList::setDefaultImage() {
1355  QFile file;
1356  if ( KSUtils::openDataFile( file, "noimage.png" ) ) {
1357  file.close();
1358  ui->ImagePreview->showPreview( KUrl( file.fileName() ) );
1359  } else
1360  ui->ImagePreview->hide();
1361 }
1362 
1363 #include "observinglist.moc"
SessionSortFilterProxyModel
Sort best observation times by reimplementing lessThan() to work on the transit times of objects...
Definition: sessionsortfilterproxymodel.h:37
ObservingList::slotSaveAllImages
void slotSaveAllImages()
Downloads the images of all the objects in the session list Note: This downloads the SDSS image...
Definition: observinglist.cpp:1129
ObservingList::setSaveImagesButton
void setSaveImagesButton()
decides on whether to enable the SaveImages button or not
Definition: observinglist.cpp:1210
LocationDialog
Dialog for changing the geographic location of the observer.
Definition: locationdialog.h:57
SkyPoint::ra
const dms & ra() const
Definition: skypoint.h:171
DetailDialog
window showing detailed information for a selected object.
Definition: detaildialog.h:88
OAL::Log::writeLog
QString writeLog(bool native=true)
Definition: log.cpp:42
imageviewer.h
SkyPoint::dec0
const dms & dec0() const
Definition: skypoint.h:168
indilistener.h
ObservingList::slotAddVisibleObj
void slotAddVisibleObj()
Definition: observinglist.cpp:1318
SkyPoint::az
const dms & az() const
Definition: skypoint.h:177
ObservingList::slotImageViewer
void slotImageViewer()
Shows the image in a ImageViewer window.
Definition: observinglist.cpp:1175
ObservingList::slotSaveSessionAs
void slotSaveSessionAs(bool nativeSave=true)
save the current observing session plan to disk, specify filename.
Definition: observinglist.cpp:812
SkyObject::translatedName
QString translatedName() const
Definition: skyobject.h:129
OAL::Log::targetList
QList< SkyObject * > * targetList()
Definition: log.h:56
ISD::GDInterface::runCommand
virtual bool runCommand(int command, void *ptr=NULL)=0
OAL::Log::dateTime
KStarsDateTime dateTime()
Definition: log.h:109
INDIListener::Instance
static INDIListener * Instance()
Definition: indilistener.cpp:46
detaildialog.h
skyobject.h
ISD::GDInterface::getBaseDevice
virtual INDI::BaseDevice * getBaseDevice()=0
QWidget
dms::Degrees
const double & Degrees() const
Definition: dms.h:98
ISD::GDInterface::getDeviceName
virtual const char * getDeviceName()=0
obslistpopupmenu.h
ISD::GDSetCommand
Definition: indistd.h:34
ObservingListUI::ObservingListUI
ObservingListUI(QWidget *parent)
Cunstructor.
Definition: observinglist.cpp:82
KStarsDateTime::setDate
void setDate(const QDate &d)
Assign the Date according to a QDate object.
Definition: kstarsdatetime.cpp:119
KDialog
KSAlmanac
A class that implements methods to find sun rise, sun set, twilight begin / end times, moon rise and moon set times.
Definition: ksalmanac.h:42
ObservingList::slotSaveSession
void slotSaveSession(bool nativeSave=true)
save the current session
Definition: observinglist.cpp:879
KStarsData::geo
GeoLocation * geo()
Definition: kstarsdata.h:164
ObsListPopupMenu
The Popup Menu for the observing list in KStars.
Definition: obslistpopupmenu.h:30
QObject
altvstime.h
SkyObject::transitTime
QTime transitTime(const KStarsDateTime &dt, const GeoLocation *geo)
The same iteration technique described in riseSetTime() is used here.
Definition: skyobject.cpp:241
KStars
This is the main window for KStars.
Definition: kstars.h:94
SkyPoint::ra0
const dms & ra0() const
Definition: skypoint.h:165
ObservingList::slotFind
void slotFind()
Open the Find Dialog.
Definition: observinglist.cpp:670
ObservingList::slotAddToSession
void slotAddToSession()
Add the object to the Session List.
Definition: observinglist.cpp:658
ObservingList::slotSlewToObject
void slotSlewToObject()
slew the telescope to the selected object
Definition: observinglist.cpp:599
ObservingList::slotToggleSize
void slotToggleSize()
toggle between the large and small window states
Definition: observinglist.cpp:949
KStarsDateTime::setTime
void setTime(const QTime &t)
Assign the Time according to a QTime object.
Definition: kstarsdatetime.cpp:133
OAL::Log::timeHash
QHash< QString, QTime > timeHash()
Definition: log.h:108
ObservingList::findAltitude
double findAltitude(SkyPoint *p, double hour=0)
Return the altitude of the given SkyObject for the given hour.
Definition: observinglist.cpp:939
ObservingList::slotWizard
void slotWizard()
construct a new observing list using the wizard.
Definition: observinglist.cpp:900
KSUtils::openDataFile
bool openDataFile(QFile &file, const QString &filename)
Attempt to open the data file named filename, using the QFile object "file".
ObservingList::slotOpenList
void slotOpenList()
load an observing list from disk.
Definition: observinglist.cpp:746
ThumbImage
Definition: thumbimage.h:24
ObservingListUI
Definition: observinglist.h:40
ObservingList::slotGoogleImage
void slotGoogleImage()
Definition: observinglist.cpp:1283
NaN::f
const float f
Definition: nan.h:36
driverinfo.h
ObservingList::~ObservingList
~ObservingList()
Destuctor (empty)
Definition: observinglist.cpp:219
oal.h
ObservingList::eventFilter
bool eventFilter(QObject *obj, QEvent *event)
This is the declaration of the event filter function which is installed on the KImageFilePreview and ...
Definition: observinglist.cpp:1221
SkyPoint
The sky coordinates of a point in the sky.
Definition: skypoint.h:50
ImageViewer
Image viewer window for KStars.
Definition: imageviewer.h:61
KSAlmanac::getSunRise
double getSunRise()
All the functions returns the fraction of the day as their return value.
Definition: ksalmanac.h:63
skymapcomposite.h
ObservingList::ObservingList
ObservingList(KStars *_ks)
Constructor.
Definition: observinglist.cpp:89
ObservingList::slotClose
void slotClose()
Definition: observinglist.cpp:726
ObservingList::saveImage
void saveImage(KUrl url, QString filename)
saves the image syncronously from a given URL into a given file url the url from which the image has ...
Definition: observinglist.cpp:1153
locationdialog.h
KSUtils::getDSSURL
QString getDSSURL(const SkyPoint *const p)
Create a URL to obtain a DSS image for a given SkyPoint.
KStarsDateTime::currentDateTime
static KStarsDateTime currentDateTime(KDateTime::Spec ts=KDateTime::Spec::ClockTime())
Definition: kstarsdatetime.cpp:67
ObservingList::setDefaultImage
void setDefaultImage()
set the default image in the image preview.
Definition: observinglist.cpp:1354
ObservingList::slotAVT
void slotAVT()
Show the Altitude vs Time for selecteld objects.
Definition: observinglist.cpp:681
KStarsDateTime::addSecs
KStarsDateTime addSecs(double s) const
Definition: kstarsdatetime.cpp:127
skymap.h
i18nc
i18nc("string from libindi, used in the config dialog","100x")
ObservingList::selectObject
void selectObject(const SkyObject *o)
make a selection in the session view
Definition: observinglist.cpp:1341
ObservingList::slotDeleteAllImages
void slotDeleteAllImages()
Removes all the save DSS/SDSS images from the disk.
Definition: observinglist.cpp:1186
OAL::Log::geoLocation
GeoLocation * geoLocation()
Definition: log.h:110
ObservingList::slotSaveList
void slotSaveList()
save the current observing list to disk.
Definition: observinglist.cpp:820
ObservingList::slotNewSelection
void slotNewSelection()
Tasks needed when changing the selected object Save the user log of the previous selected object...
Definition: observinglist.cpp:455
execute.h
KStarsDateTime
Extension of KDateTime for KStars KStarsDateTime can represent the date/time as a Julian Day...
Definition: kstarsdatetime.h:45
SkyObject::isSolarSystem
bool isSolarSystem() const
Definition: skyobject.h:197
Options::obsListPreferDSS
static bool obsListPreferDSS()
Get Prefer Digitized Sky Survey imagery in the observing list.
Definition: Options.h:2835
SkyObject::translatedLongName
QString translatedLongName() const
Definition: skyobject.h:145
ObservingList::slotSetTime
void slotSetTime()
Takes the time from the QTimeEdit box and sets it as the time parameter in the tableview of the Sessi...
Definition: observinglist.cpp:1054
ObservingList::saveCurrentUserLog
void saveCurrentUserLog()
Save the user log text to a file.
Definition: observinglist.cpp:735
dms
An angle, stored as degrees, but expressible in many ways.
Definition: dms.h:42
ObservingList::slotGetImage
void slotGetImage(bool _dss=false)
Downloads the corresponding DSS or SDSS image from the web and displays it.
Definition: observinglist.cpp:1061
ObservingList::slotAddObject
void slotAddObject(SkyObject *o=NULL, bool session=false, bool update=false)
add a new object to list o pointer to the object to add to the list session flag toggle adding the ob...
Definition: observinglist.cpp:226
SkyPoint::dec
const dms & dec() const
Definition: skypoint.h:174
dms::Hours
double Hours() const
Definition: dms.h:125
ObservingList::slotWUT
void slotWUT()
Open the WUT dialog.
Definition: observinglist.cpp:650
ObservingList::saveThumbImage
void saveThumbImage()
saves a thumbnail image for the details dialog from the downloaded image
Definition: observinglist.cpp:1306
QSortFilterProxyModel
ObservingList::slotChangeTab
void slotChangeTab(int index)
toggle the setEnabled flags according to current view set the m_currentItem to NULL and clear selecti...
Definition: observinglist.cpp:1001
SkyPoint::EquatorialToHorizontal
void EquatorialToHorizontal(const dms *LST, const dms *lat)
Determine the (Altitude, Azimuth) coordinates of the SkyPoint from its (RA, Dec) coordinates, given the local sidereal time and the observer's latitude.
Definition: skypoint.cpp:55
sessionsortfilterproxymodel.h
Options.h
SkyObject::name2
QString name2(void) const
Definition: skyobject.h:132
SkyObject::mag
float mag(void) const
Definition: skyobject.h:182
ISD::GDInterface::getType
virtual DeviceFamily getType()=0
QTextStream
ksalmanac.h
ObservingList::slotRemoveObject
void slotRemoveObject(SkyObject *o=NULL, bool session=false, bool update=false)
Remove skyobject from the observing list.
Definition: observinglist.cpp:334
SkyObject::recomputeCoords
SkyPoint recomputeCoords(const KStarsDateTime &dt, const GeoLocation *geo=0)
The coordinates for the object on date dt are computed and returned, but the object's internal coordi...
Definition: skyobject.cpp:296
SkyObject::type
int type(void) const
Definition: skyobject.h:164
finddialog.h
KSAlmanac::getSunSet
double getSunSet()
Definition: ksalmanac.h:64
ObservingList::slotSaveImage
void slotSaveImage()
saves the temporary image permanently
Definition: observinglist.cpp:1168
ObservingList::findObjectByName
SkyObject * findObjectByName(QString name)
return the object with the name as the passed QString from the Session List, return null otherwise ...
Definition: observinglist.cpp:1334
thumbnailpicker.h
NaN::ld
const long double ld
Definition: nan.h:37
Options::zoomFactor
static double zoomFactor()
Get Zoom Factor, in pixels per radian.
Definition: Options.h:2531
ObservingList::slotUpdate
void slotUpdate()
Updates the tableviews for the new geolocation and date.
Definition: observinglist.cpp:1035
ISD::GDInterface::setProperty
virtual bool setProperty(QObject *)=0
ObservingList::slotOALExport
void slotOALExport()
Export a target list to the oal compliant format.
Definition: observinglist.cpp:1314
starobject.h
ObservingList::saveCurrentList
void saveCurrentList()
If the current list has unsaved changes, ask the user about saving it.
Definition: observinglist.cpp:799
KStars::data
KStarsData * data() const
Definition: kstars.h:131
obslistwizard.h
ObservingList::plot
void plot(SkyObject *o)
Plot the SkyObject's Altitude vs Time in the AVTPlotWidget.
Definition: observinglist.cpp:910
kstarsdata.h
OAL::Log
Definition: log.h:41
ObservingList::slotDetails
void slotDetails()
Show the details window for the selected object.
Definition: observinglist.cpp:642
SkyPoint::alt
const dms & alt() const
Definition: skypoint.h:180
ObservingList::setCurrentImage
void setCurrentImage(const SkyObject *o, bool temp=false)
Sets the image parameters for the current object o The passed object for setting the parameters temp ...
Definition: observinglist.cpp:1096
SkyObject::name
virtual QString name(void) const
Definition: skyobject.h:124
KSTARS_TELESCOPE
Definition: indicommon.h:66
StarObject::name
virtual QString name(void) const
If star is unnamed return "star" otherwise return the name.
Definition: starobject.h:131
log.h
ObservingList::slotRemoveSelectedObjects
void slotRemoveSelectedObjects()
Remove skyobjects which are highlighted in the observing list tool from the observing list...
Definition: observinglist.cpp:393
OAL::Log::readBegin
void readBegin(QString input)
Definition: log.cpp:382
INDI_SEND_COORDS
Definition: indicommon.h:72
ObservingList::slotCenterObject
void slotCenterObject()
center the selected object in the display
Definition: observinglist.cpp:584
StarObject::gname
QString gname(bool useGreekChars=true) const
Returns the genetive name of the star.
Definition: starobject.cpp:349
ksutils.h
StarObject
This is a subclass of SkyObject.
Definition: starobject.h:41
KStarsDateTime::gst
dms gst() const
Definition: kstarsdatetime.cpp:138
SkyObject::STAR
Definition: skyobject.h:108
SkyObject::typeName
static QString typeName(const int t)
Definition: skyobject.cpp:319
SkyObject
Provides all necessary information about an object in the sky: its coordinates, name(s), type, magnitude, and QStringLists of URLs for images and webpages regarding the object.
Definition: skyobject.h:46
QFrame
ObservingList::slotDeleteCurrentImage
void slotDeleteCurrentImage()
Remove the current image.
Definition: observinglist.cpp:1300
ObservingList::slotLoadWishList
void slotLoadWishList()
Load the Wish list from disk.
Definition: observinglist.cpp:848
ObservingList::downloadReady
void downloadReady()
Definition: observinglist.cpp:1078
kstars.h
ISD::GDInterface
Definition: indistd.h:48
ObservingList::slotLocation
void slotLocation()
Opens the Location dialog to set the GeoLocation for the sessionlist.
Definition: observinglist.cpp:1026
wutdialog.h
drivermanager.h
observinglist.h
QList
KSAlmanac::setLocation
void setLocation(GeoLocation *m_geo)
Set the location for computations to the given location.
Definition: ksalmanac.cpp:135
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:36:20 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kstars

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

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal