/*
 *
 * 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.
 */


#include "miscmanager.h"

#include "qvmiscplugin.h"
#include "qtvision.h"
#include <kdebug.h>


MiscManager::MiscManager(QtVision *qtv, QWidget *w) {
	_view = w;
	_qtv = qtv;
	scanPlugins();
}

MiscManager::~MiscManager() {
}


void MiscManager::rescanPlugins() {
	for (QVMiscPlugin *p = _plugs.first(); p; p = _plugs.next()) {
		if (!(p->pluginDescription().enabled)) {
			_plugs.remove(p);
			delete p;
		}
	}

	scanPlugins();
}

void MiscManager::scanPlugins() {
        QPtrList<PluginDesc>& miscPlugins(_qtv->pluginFactory()->miscPlugins());
	bool skip = false;

        for (PluginDesc *plug = miscPlugins.first(); plug;
                                plug = miscPlugins.next()) {
		for (QVMiscPlugin *p = _plugs.first(); p; p = _plugs.next()) {
			if (p->pluginDescription() == *plug) {
				skip = true;
				break;
			}
		}

		if (skip) {
			skip = false;
			continue;
		}

                kdDebug() << "Found a plugin:" << endl;
                kdDebug() << plug->name << endl;
                kdDebug() << plug->author << endl;
                kdDebug() << plug->comment << endl;
                QVMiscPlugin *p = _qtv->pluginFactory()->getMiscPlugin(plug,_view);
		if (p)
			_plugs.append(p);
        }

}

QPtrList<QVMiscPlugin> MiscManager::plugins() {
return _plugs;
}

bool MiscManager::filterNumberKey(int key) {
    for (QVMiscPlugin *p = _plugs.first(); p; p = _plugs.next())
        if (p->filterNumberKey(key))
            return true;
    return false;
}

#include "miscmanager.moc"

