/***************************************************************************
 *   Copyright (C) 2010 by Volker Lanz <vl@fidra.de>                       *
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA            *
 ***************************************************************************/

#if !defined(MAINWINDOW__H)

#define MAINWINDOW__H

#include "ui_mainwindow.h"

#if defined(HAVE_KDE)
#include <kxmlguiwindow.h>
#else
#include <QMainWindow>
#endif

class Profile;
class Activity;
class ImportProgressDialog;
class Importer;
class Sync;
class Exporter;

namespace Veneer
{
	class ActionCollection;
}

class QCloseEvent;
class QPoint;

/** The application's main window.
	@author Volker Lanz <vl@fidra.de>
*/
class MainWindow :
#if defined(HAVE_KDE)
	public KXmlGuiWindow,
#else
	public QMainWindow,
#endif
	public Ui::MainWindow
{
	Q_OBJECT
	Q_DISABLE_COPY(MainWindow)

	public:
		explicit MainWindow(QWidget* parent = NULL);
		~MainWindow();

	protected:
		void init();

		void setupActions();
		void setupConnections();
		void loadConfig();
		void saveConfig() const;
		bool loadProfile(const QString& name);
		bool loadLastProfile();
		void setProfile(Profile* p);

		void closeEvent(QCloseEvent*);

		void doImport(Activities& importedActivities, const QStringList& errorNames);

#if !defined(HAVE_KDE)
		Veneer::ActionCollection* actionCollection() { return m_ActionCollection; }
#endif

	protected slots:
		void onShowStatusbar();
		void onConfigureOptions();
		void onNewProfile();
		void onImport();
		void onSaveProfile();
		void onOpenProfile();
		void onEditProfile();
		void onCloseProfile();
		void onDeleteProfile();
		void onDelete();
		void onExport();
		void onSync();
		void onGoogleEarth();
		void onSelectAll();
#if !defined(HAVE_KDE)
		void onAbout();
#endif

		void onDetailsChanged();
		void on_activityWidget_categoryChanged();

		void enableActions();

		void onAthleteLogChanged();

		void onImportFinished();
		void onSyncFinished();
		void onExportFinished();

		void on_categoriesDockWidget_selectedCategoryChanged(Category* category);

		void on_activityWidget_selectionChanged();

		void on_athleteLogWidget_selectedAthleteLogChanged(AthleteLog*);

		void on_graphDock_visibilityChanged(bool b);
		void on_mapDock_visibilityChanged(bool b);

		void on_tabWidget_currentChanged(int idx);
		void on_activityWidget_contextMenuRequested(const QPoint& p);
		void on_athleteLogWidget_contextMenuRequested(const QPoint& p);

	private:
		Veneer::ActionCollection* m_ActionCollection;
		Profile* m_Profile;
		ImportProgressDialog* m_ImportProgressDialog;
		Importer* m_Importer;
		Sync* m_Sync;
		Exporter* m_Exporter;
};

#endif
