/*
 *
 * Copyright (C) 2002 George Staikos <staikos@kde.org>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library 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
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public License
 * along with this library; see the file COPYING.LIB.  If not, write to
 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */



#ifndef _PLUGINFACTORY_H
#define _PLUGINFACTORY_H

#include <qstring.h>

#include <qwidget.h>
#include <qmap.h>
#include <qptrlist.h>

#include <kservice.h>

class QVSourcePlugin;
class QVMixerPlugin;
class QVOSDPlugin;
class QVMiscPlugin;
class ChannelIOFormat;
class PluginDescPrivate;

/*
 * Internal description of a plugin
 */
class PluginDesc
{
public:

    typedef enum { UNKNOWN, VIDEO, CHANNEL, MIXER, OSD, MISC, IMAGEFILTER } PluginType;
    PluginDesc();
    PluginDesc(const PluginDesc& copy);

    int id;
    QString name;
    QString author;
    QString comment;
    QString icon;
    QString lib;
    QString factory;
    KService::Ptr service;
    PluginType type;
    bool configurable;
    bool enabled;

    friend int operator<(const PluginDesc& l, const PluginDesc& r);
    friend int operator>(const PluginDesc& l, const PluginDesc& r);
    friend int operator==(const PluginDesc& l, const PluginDesc& r);
    friend int operator!=(const PluginDesc& l, const PluginDesc& r);

private:
    PluginDescPrivate *d;
};


class KConfig;

/**
 * The factory where all the plugins come from.
 */
class PluginFactory
{
public:
    QPtrList<PluginDesc>& videoPlugins();
    /* you get to keep this object*/
    QVSourcePlugin* getVideoPlugin(const PluginDesc *plugin, QWidget *w);

    QPtrList<PluginDesc>& channelPlugins();
    ChannelIOFormat* getChannelPlugin(const PluginDesc *plugin);

    QPtrList<PluginDesc>& mixerPlugins();
    QVMixerPlugin* getMixerPlugin(const PluginDesc *plugin);

    QPtrList<PluginDesc>& miscPlugins();
    QVMiscPlugin* getMiscPlugin(const PluginDesc *plugin, QWidget *w);

    QPtrList<PluginDesc>& osdPlugins();
    /* this object will be destroyed on shutdown */
    QVOSDPlugin* getOSDPlugin(const PluginDesc *plugin, QWidget *w);


    /* you probably don't ever want to call this */
    virtual void scanForPlugins();

protected:
    friend class QtVision;
    PluginFactory(QtVision *qtv);
    virtual ~PluginFactory();

    void doScan(KService::List& plugs, QPtrList<PluginDesc>& list, PluginDesc::PluginType type);

private:
    static int _upid;

    QPtrList<PluginDesc> _videoPlugins;
    QPtrList<PluginDesc> _mixerPlugins;
    QPtrList<PluginDesc> _osdPlugins;
    QPtrList<PluginDesc> _channelPlugins;
    QPtrList<PluginDesc> _miscPlugins;

    KConfig *_cfg;
    QtVision *_qtv;
};



#endif

