/***************************************************************************
 *   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(SYNC__H)

#define SYNC__H

#include "core/types.h"

#include <QThread>
#include <QList>
#include <QMap>

class QString;
class QStringList;

namespace Veneer {
	 class Device;
}

class Sync : public QThread
{
	Q_OBJECT

	public:
		enum SyncStatus
		{
			Success = 0,
			ReadError = 1
		};

	public:
		Sync();
		~Sync();

	signals:
		void totalSteps(int i);
		void progress(int i);
		void runSyncOnPath(const QString&);

	public:
		const QList<SyncSource*> sources() { return m_Sources; }

		void setActiveSource(SyncSource* source) { m_ActiveSource = source; }
		SyncSource* activeSource() { return m_ActiveSource; }

		Activities& activities() { return m_Activities; }
		const QStringList errorNames() const;

		SyncStatus status() const { return m_Status; }
		static QString errorMsg(SyncStatus s);

		void scan();

		void addDevice(const Veneer::Device& device);

	protected:
		virtual void run();

	private:
		QList<SyncSource*> m_Sources;
		Activities m_Activities;
		SyncInterfaces m_SyncInterfaces;
		SyncInterface* m_RunningInterface;
		SyncSource* m_ActiveSource;
		SyncStatus m_Status;
};

#endif
