/*
 * portmgr.h
 *
 * Copyright (c) 2002, 2003 Frerich Raabe <raabe@kde.org>
 *
 * 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. For licensing and distribution details, check the
 * accompanying file 'COPYING'.
 */
#ifndef PORTMGR_H
#define PORTMGR_H

#include <qobject.h>
#include <qstring.h>

class QDateTime;
class QStringList;
template <class T> class QValueList;

namespace Barry
{
	class DatabaseWrapper;

	class Port;
	typedef QValueList<Port> PortList;

	class ConcretePort;
	class PortMgr : public QObject
	{
		Q_OBJECT
		friend class Port;
		friend class ConcretePort;
		public:
			~PortMgr();
			static PortMgr &self();

			QStringList prefixes() const;

			QStringList categories() const;

			PortList ports( const QString &category ) const;
			PortList allPorts() const;
			PortList installedPorts() const;

			QString portRootDir() const { return m_portRootDir; }
			QString pkgRootDir() const { return m_pkgRootDir; }

			DatabaseWrapper &portDb() { return *m_portDb; }
			DatabaseWrapper &pkgDb() { return *m_pkgDb; }

			QDateTime portDatabaseTimestamp() const;
			QDateTime packageDatabaseTimestamp() const;

			bool load();

		public slots:
			void reparseConfig();

		private:
			PortMgr();
			PortMgr( const PortMgr &rhs );
			PortMgr &operator=( const PortMgr &rhs );

			void determineAllPorts() const;
			void determineInstalledPorts() const;
			bool loadPortDb();
			bool loadPkgDb();
			void checkDatabase() const;
			QString getMkVariable( const QString &key ) const;
			QStringList getMkVariables( const QStringList &keys ) const;

			static PortMgr *m_instance;
			mutable PortList m_allPorts;
			mutable PortList m_installedPorts;
			QString m_portRootDir;
			QString m_pkgRootDir;
			DatabaseWrapper *m_portDb;
			DatabaseWrapper *m_pkgDb;
	};
};

#endif // PORTMGR_H
// vim:ts=4:sw=4:noet:list
