/***************************************************************************
                          cumulusapp.h  -  main application object
                             -------------------
    begin                : Sun Jul 21 2002
    copyright            : (C) 2002 by Andre Somers
    email                : andre@kflog.org

	This file is distributed under the terms of the General Public
    Licence. See the file COPYING for more information.

    $Id: cumulusapp.h,v 1.42 2005/02/21 22:08:59 andre Exp $

 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef CUMULUSAPP_H
#define CUMULUSAPP_H

#include <qapp.h>
#include <qmainwindow.h>
#include <qaction.h>
#include <qmenubar.h>
#include <qpopupmenu.h>
#include <qevent.h>
#include <qaccel.h>
#include <qtabwidget.h>

#include "mapview.h"
#include "waypointlistview.h"
#include "airfieldlistview.h"
#include "reachpointlistview.h"
#include "tasklistview.h"
#include "waypointcatalog.h"
#include "wpinfowidget.h"
#include "gpsnmea.h"
#include "preflightdialog.h"
#include "gliderflightdialog.h"
#include "altimetermodedialog.h"
#include "variomodedialog.h"
#include "mapinfobox.h"
#include "waitscreen.h"

/**This class provides the main application for Cumulus.
  *@author Andre Somers
  */
class MapView;
class WPInfoWidget;
class WaypointListView;
class CumulusApp : public QMainWindow
{
   Q_OBJECT
public:
  enum appView {mapView=0, wpView=1,  infoView=2, rpView=3, apView=4, tpView=5};

  CumulusApp(QWidget *parent=0, const char *name=0);
  virtual ~CumulusApp();
  /** Write property of int view. */
  virtual void setView (const appView& _newVal, const wayPoint* wp = 0);
  /** Read property of int view. */
  virtual const appView getView();

public: // Public attributes
  /** Reference to the Map page */
  MapView *viewMap;
  WaypointListView *viewWP;
  AirfieldListView *viewAP;
  ReachpointListView *viewRP;
  TaskListView *viewTP;
  WPInfoWidget *viewInfo;
  QTabWidget *listViewTabs;

  WaypointCatalog *WpCatalog;

  QAccel *accApView;
  QAccel *accInfoView;
  QAccel *accManualNav;
  QAccel *accGpsNav;
//  QAccel *accMcSet;
  QAccel *accRpView;
  QAccel *accTpView;
  QAccel *accWpView;
  
  /** play some sound */
  static void playSound(const QString *name=0);

  bool eventFilter(QObject*, QEvent*);

protected:
  /** No descriptions */
  void initSurfaces();
  /** No descriptions */
  void initTypes();

  /** Make sure the user really wants to quit */
  virtual void closeEvent (QCloseEvent*);
  
  /** contains the currently selected viewmode */
  appView view;

  PreFlightDialog* _preFlightDialog;

  GliderFlightDialog* _gliderFlightDlg;

  AltimeterModeDialog* _altimeterModeDlg;

  VarioModeDialog* _varioModeDlg;
  
  bool _taskListVisible;

public slots: // Public slots
  /** Switches to the WaypointList View */
  void slotSwitchToWPListView();
  void slotSwitchToAPListView();
  void slotSwitchToReachListView();
  void slotSwitchToTaskListView();
  void slotRememberWaypoint ();
  void slotNavigateHome();
  
public slots: // Public slots
  void slotFileQuit();
  /** Switches to mapview. */
  void slotSwitchToMapView();
  /** This slot is called to switch to the info view. */
  void slotSwitchToInfoView();
  /** @ee This slot is called to switch to the info view with selected waypoint. */
  void slotSwitchToInfoView(wayPoint*);
  /** Opens the configdialog. */
  void slotConfig();
  /** Opens the inflight glider settings dialog. */
  void slotGliderFlight();
  /** Opens the inflight Altimeter settings dialog. */
  void slotAltimeterMode();
  /** Called if inflight Altimeter settings have changed */
  void slotNewAltimeterMode();
  /** Opens the Variometer settings dialog. */
  void slotVarioMode();
  /** This slot is called if the configuration has changed and at the start of the program to read the initial configuration. */
  void slot_readconfig();
  /** shows version and copyright. */
  void slotVersion();
  /** Called if the status of the GPS changes, and controls the availability of manual navigation. */
  void slotGpsStatus(GPSNMEA::connectedStatus status);
  /** Opens the taskselection dialog */
  void slotSelectTask();
  /** Opens the pre flight dialog */
  void slotPreFlight();
  /** shows airspace warnings */
  void airspaceWarning (const QString&);
  /** updates the list of rechable points  */
  void slot_newReachList();
  /** shows the GPS status dialog */
  void slotGpsStatusDialog();
  
  
private slots: // Private slots
  /** This slot is called if the user presses C in manual navigation mode. It centers the map on the current waypoint. */
  void slotCenterToWaypoint();
  /** Called if the user pressed V in mapview. Adjusts the zoomfactor so that the currently selected waypoint is displayed as good as possible. */
  void slotEnsureVisible();
  void slotToggleMenu(bool toggle);
  void slotViewStatusBar(bool toggle);
  /** Called if the logging is actually toggled */
  void slot_Logging (bool logging);
 /** Called if the label displaying is actually toggled */
  void slotToggleWpLabels (bool toggle);
 /** Called if the extra label info displaying is actually toggled */
  void slotToggleWpLabelsExtraInfo (bool toggle);
 /** Called if new prefight data were set */
  void slotPreFlightDataChanged();
  /** Called if the user clicks on a tab to select a different list-type view */
  void slot_tabChanged(QWidget *);
//  void slotHelp();
protected:
  void initActions();
  void initMenuBar();
private:

  // @AP: store content of /proc/sys/vm/freepg_signal_proc file
  char freepgContent[128];
  uint freepgContentLen;

  QAction* actionToggleMenu;
  QAction* actionFileQuit;
  QAction* actionViewInfo;
  QAction* actionViewWaypoints;
  QAction* actionViewAirports;
  QAction* actionViewReachpoints;
  QAction* actionViewTaskpoints;
  QAction* actionViewGPSStatus;
  QAction* actionToggleStatusbar;
  QAction* actionZoomInZ;
  QAction* actionZoomIn;
  QAction* actionZoomOutZ;
  QAction* actionZoomOut;
  QAction* actionToggleWpLabels;
  QAction* actionToggleWpLabelsEI;
  QAction* actionToggleLogging;
  QAction* actionEnsureVisible;
  QAction* actionSelectTask;
  QAction* actionPreFlight;
  QAction* actionRememberWaypoint;
  QAction* actionSetupConfig;
  QAction* actionSetupInFlight;
  QAction* actionHelp;
  QAction* actionHelpAboutApp;
  QAction* actionWhatsThis;
  /** file_menu contains all items of the menubar entry "File" */
  QPopupMenu *fileMenu;
  /** view_menu contains all items of the menubar entry "View" */
  QPopupMenu *viewMenu;
  /** view_menu contains all items of the menubar entry "Map" */
  QPopupMenu *mapMenu;
  /** setupMenu contains all items of the menubar entry "Setup" */
  QPopupMenu *setupMenu;
  /** view_menu contains all items of the menubar entry "Help" */
  QPopupMenu *helpMenu;
  // Wait screen
  WaitScreen *ws;
};

#endif
