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 // (C) 2010 Underground Software
8 // JLH = James L. Hammons <jlhamm@acm.org>
11 // --- ---------- -----------------------------------------------------------
12 // JLH 06/02/2010 Added this text. :-)
15 #include "rs_scriptlist.h"
17 #include "rs_system.h"
19 RS_ScriptList * RS_ScriptList::uniqueInstance = NULL;
22 * Default constructor.
24 RS_ScriptList::RS_ScriptList(): scriptIterator(scripts)
26 //Should be dealt with...
27 //#warning "!!! Need to deal with setAutoDelete() Qt3->Qt4 !!!"
28 // scripts.setAutoDelete(true);
30 //scriptListListeners.setAutoDelete(false);
31 //activeScript = NULL;
34 /*virtual*/ RS_ScriptList::~RS_ScriptList()
36 while (!scripts.isEmpty())
37 delete scripts.takeFirst();
41 * @return Instance to the unique script list.
43 /*static*/ RS_ScriptList * RS_ScriptList::instance()
45 if (uniqueInstance == NULL)
46 uniqueInstance = new RS_ScriptList();
48 return uniqueInstance;
52 * Initializes the script list by creating RS_Script
53 * objects, one for each script that could be found.
55 void RS_ScriptList::init()
57 RS_DEBUG->print("RS_ScriptList::initScripts");
60 QStringList list = RS_SYSTEM->getScriptList();
63 for(QStringList::Iterator it=list.begin(); it!=list.end(); ++it)
65 RS_DEBUG->print("script: %s:", (*it).toLatin1().data());
68 script = new RS_Script(fi.baseName(), fi.absoluteFilePath());
69 scripts.append(script);
71 RS_DEBUG->print("base: %s", fi.baseName().toLatin1().data());
72 RS_DEBUG->print("path: %s", fi.absoluteFilePath().toLatin1().data());
75 //RS_Script* f = new RS_Script("normal");
80 * Removes all scripts in the scriptlist.
82 void RS_ScriptList::clearScripts()
87 int RS_ScriptList::countScripts()
89 return scripts.count();
93 * Removes a script from the list.
94 * Listeners are notified after the script was removed from
95 * the list but before it gets deleted.
97 void RS_ScriptList::removeScript(RS_Script * script)
99 RS_DEBUG->print("RS_ScriptList::removeScript()");
101 // here the script is removed from the list but not deleted
102 // scripts.remove(script);
103 // We have to delete it since AutoDelete does not exist in QList<T>
104 int i = scripts.indexOf(script);
107 delete scripts.takeAt(i);
109 //for (uint i=0; i<scriptListListeners.count(); ++i) {
110 // RS_ScriptListListener* l = scriptListListeners.at(i);
111 // l->scriptRemoved(script);
114 // activate an other script if necessary:
115 //if (activeScript==script) {
116 // activateScript(scripts.first());
119 // now it's save to delete the script
124 * @return Pointer to the script with the given name or
125 * \p NULL if no such script was found. The script will be loaded into
126 * memory if it's not already.
128 RS_Script * RS_ScriptList::requestScript(const QString & name)
130 RS_DEBUG->print("RS_ScriptList::requestScript %s", name.toLatin1().data());
132 QString name2 = name.toLower();
133 RS_Script * foundScript = NULL;
135 RS_DEBUG->print("name2: %s", name2.toLatin1().data());
137 // Search our list of available scripts:
138 // for(RS_Script * s=scripts.first(); s!=NULL; s=scripts.next())
139 for(int i=0; i<scripts.size(); i++)
141 RS_Script * s = scripts[i];
143 if (s->getName() == name2)
154 //! @return First script of the list.
155 RS_Script * RS_ScriptList::firstScript()
157 // return scripts.first();
158 scriptIterator.toFront();
159 return scriptIterator.next();
162 /** @return Next script from the list after
163 * calling firstScript() or nextScript().
165 RS_Script * RS_ScriptList::nextScript()
167 // return scripts.next();
168 return scriptIterator.next();
172 * @return Pointer to the script with the given name or
173 * \p NULL if no such script was found.
175 //RS_Script* RS_ScriptList::loadScript(const QString& name) {
179 * Tests the script list and its ability to load scripts.
181 bool RS_ScriptList::test()
183 //RS_ScriptList* l = RS_ScriptList::instance();
185 //std::cout << "RS_ScriptList: " << *l << std::endl;