3 // Part of the Architektonas Project
4 // Originally part of QCad Community Edition by Andrew Mustun
5 // Extensively rewritten and refactored by James L. Hammons
6 // Portions copyright (C) 2001-2003 RibbonSoft
7 // Copyright (C) 2010 Underground Software
8 // See the README and GPLv2 files for licensing and warranty information
10 // JLH = James L. Hammons <jlhamm@acm.org>
13 // --- ---------- -----------------------------------------------------------
14 // JLH 06/02/2010 Added this text. :-)
17 #include "scriptlist.h"
21 ScriptList * ScriptList::uniqueInstance = NULL;
24 * Default constructor.
26 ScriptList::ScriptList(): scriptIterator(scripts)
28 //Should be dealt with...
29 //#warning "!!! Need to deal with setAutoDelete() Qt3->Qt4 !!!"
30 // scripts.setAutoDelete(true);
32 //scriptListListeners.setAutoDelete(false);
33 //activeScript = NULL;
36 /*virtual*/ ScriptList::~ScriptList()
38 while (!scripts.isEmpty())
39 delete scripts.takeFirst();
43 * @return Instance to the unique script list.
45 /*static*/ ScriptList * ScriptList::instance()
47 if (uniqueInstance == NULL)
48 uniqueInstance = new ScriptList();
50 return uniqueInstance;
54 * Initializes the script list by creating Script
55 * objects, one for each script that could be found.
57 void ScriptList::init()
59 DEBUG->print("ScriptList::initScripts");
62 QStringList list = SYSTEM->getScriptList();
65 for(QStringList::Iterator it=list.begin(); it!=list.end(); ++it)
67 DEBUG->print("script: %s:", (*it).toLatin1().data());
70 script = new Script(fi.baseName(), fi.absoluteFilePath());
71 scripts.append(script);
73 DEBUG->print("base: %s", fi.baseName().toLatin1().data());
74 DEBUG->print("path: %s", fi.absoluteFilePath().toLatin1().data());
77 //Script* f = new Script("normal");
82 * Removes all scripts in the scriptlist.
84 void ScriptList::clearScripts()
89 int ScriptList::countScripts()
91 return scripts.count();
95 * Removes a script from the list.
96 * Listeners are notified after the script was removed from
97 * the list but before it gets deleted.
99 void ScriptList::removeScript(Script * script)
101 DEBUG->print("ScriptList::removeScript()");
103 // here the script is removed from the list but not deleted
104 // scripts.remove(script);
105 // We have to delete it since AutoDelete does not exist in QList<T>
106 int i = scripts.indexOf(script);
109 delete scripts.takeAt(i);
111 //for (uint i=0; i<scriptListListeners.count(); ++i) {
112 // ScriptListListener* l = scriptListListeners.at(i);
113 // l->scriptRemoved(script);
116 // activate an other script if necessary:
117 //if (activeScript==script) {
118 // activateScript(scripts.first());
121 // now it's save to delete the script
126 * @return Pointer to the script with the given name or
127 * \p NULL if no such script was found. The script will be loaded into
128 * memory if it's not already.
130 Script * ScriptList::requestScript(const QString & name)
132 DEBUG->print("ScriptList::requestScript %s", name.toLatin1().data());
134 QString name2 = name.toLower();
135 Script * foundScript = NULL;
137 DEBUG->print("name2: %s", name2.toLatin1().data());
139 // Search our list of available scripts:
140 // for(Script * s=scripts.first(); s!=NULL; s=scripts.next())
141 for(int i=0; i<scripts.size(); i++)
143 Script * s = scripts[i];
145 if (s->getName() == name2)
156 //! @return First script of the list.
157 Script * ScriptList::firstScript()
159 // return scripts.first();
160 scriptIterator.toFront();
161 return scriptIterator.next();
164 /** @return Next script from the list after
165 * calling firstScript() or nextScript().
167 Script * ScriptList::nextScript()
169 // return scripts.next();
170 return scriptIterator.next();
174 * @return Pointer to the script with the given name or
175 * \p NULL if no such script was found.
177 //Script* ScriptList::loadScript(const QString& name) {
181 * Tests the script list and its ability to load scripts.
183 bool ScriptList::test()
185 //ScriptList* l = ScriptList::instance();
187 //std::cout << "ScriptList: " << *l << std::endl;