+++ /dev/null
-// scriptlist.cpp
-//
-// Part of the Architektonas Project
-// Originally part of QCad Community Edition by Andrew Mustun
-// Extensively rewritten and refactored by James L. Hammons
-// Portions copyright (C) 2001-2003 RibbonSoft
-// Copyright (C) 2010 Underground Software
-// See the README and GPLv2 files for licensing and warranty information
-//
-// JLH = James L. Hammons <jlhamm@acm.org>
-//
-// Who When What
-// --- ---------- -----------------------------------------------------------
-// JLH 06/02/2010 Added this text. :-)
-//
-
-#include "scriptlist.h"
-
-#include "system.h"
-
-ScriptList * ScriptList::uniqueInstance = NULL;
-
-/**
- * Default constructor.
- */
-ScriptList::ScriptList(): scriptIterator(scripts)
-{
-//Should be dealt with...
-//#warning "!!! Need to deal with setAutoDelete() Qt3->Qt4 !!!"
-// scripts.setAutoDelete(true);
- //init();
- //scriptListListeners.setAutoDelete(false);
- //activeScript = NULL;
-}
-
-/*virtual*/ ScriptList::~ScriptList()
-{
- while (!scripts.isEmpty())
- delete scripts.takeFirst();
-}
-
-/**
- * @return Instance to the unique script list.
- */
-/*static*/ ScriptList * ScriptList::instance()
-{
- if (uniqueInstance == NULL)
- uniqueInstance = new ScriptList();
-
- return uniqueInstance;
-}
-
-/**
- * Initializes the script list by creating Script
- * objects, one for each script that could be found.
- */
-void ScriptList::init()
-{
- DEBUG->print("ScriptList::initScripts");
-
- scripts.clear();
- QStringList list = SYSTEM->getScriptList();
- Script * script;
-
- for(QStringList::Iterator it=list.begin(); it!=list.end(); ++it)
- {
- DEBUG->print("script: %s:", (*it).toLatin1().data());
-
- QFileInfo fi(*it);
- script = new Script(fi.baseName(), fi.absoluteFilePath());
- scripts.append(script);
-
- DEBUG->print("base: %s", fi.baseName().toLatin1().data());
- DEBUG->print("path: %s", fi.absoluteFilePath().toLatin1().data());
- }
-
- //Script* f = new Script("normal");
- //scripts.append(f);
-}
-
-/**
- * Removes all scripts in the scriptlist.
- */
-void ScriptList::clearScripts()
-{
- scripts.clear();
-}
-
-int ScriptList::countScripts()
-{
- return scripts.count();
-}
-
-/**
- * Removes a script from the list.
- * Listeners are notified after the script was removed from
- * the list but before it gets deleted.
- */
-void ScriptList::removeScript(Script * script)
-{
- DEBUG->print("ScriptList::removeScript()");
-
- // here the script is removed from the list but not deleted
-// scripts.remove(script);
- // We have to delete it since AutoDelete does not exist in QList<T>
- int i = scripts.indexOf(script);
-
- if (i != -1)
- delete scripts.takeAt(i);
-
- //for (uint i=0; i<scriptListListeners.count(); ++i) {
- // ScriptListListener* l = scriptListListeners.at(i);
- // l->scriptRemoved(script);
- //}
-
- // activate an other script if necessary:
- //if (activeScript==script) {
- // activateScript(scripts.first());
- //}
-
- // now it's save to delete the script
- //delete script;
-}
-
-/**
- * @return Pointer to the script with the given name or
- * \p NULL if no such script was found. The script will be loaded into
- * memory if it's not already.
- */
-Script * ScriptList::requestScript(const QString & name)
-{
- DEBUG->print("ScriptList::requestScript %s", name.toLatin1().data());
-
- QString name2 = name.toLower();
- Script * foundScript = NULL;
-
- DEBUG->print("name2: %s", name2.toLatin1().data());
-
- // Search our list of available scripts:
-// for(Script * s=scripts.first(); s!=NULL; s=scripts.next())
- for(int i=0; i<scripts.size(); i++)
- {
- Script * s = scripts[i];
-
- if (s->getName() == name2)
- {
- foundScript = s;
- break;
- }
- }
-
- // Script not found:
- return foundScript;
-}
-
-//! @return First script of the list.
-Script * ScriptList::firstScript()
-{
-// return scripts.first();
- scriptIterator.toFront();
- return scriptIterator.next();
-}
-
-/** @return Next script from the list after
- * calling firstScript() or nextScript().
- */
-Script * ScriptList::nextScript()
-{
-// return scripts.next();
- return scriptIterator.next();
-}
-
-/**
- * @return Pointer to the script with the given name or
- * \p NULL if no such script was found.
- */
-//Script* ScriptList::loadScript(const QString& name) {
-//}
-
-/**
- * Tests the script list and its ability to load scripts.
- */
-bool ScriptList::test()
-{
- //ScriptList* l = ScriptList::instance();
-
- //std::cout << "ScriptList: " << *l << std::endl;
-
- return true;
-}