1 /****************************************************************************
2 ** $Id: rs_scriptlist.cpp 1960 2005-03-12 12:22:01Z andrew $
4 ** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
6 ** This file is part of the qcadlib Library project.
8 ** This file may be distributed and/or modified under the terms of the
9 ** GNU General Public License version 2 as published by the Free Software
10 ** Foundation and appearing in the file LICENSE.GPL included in the
11 ** packaging of this file.
13 ** Licensees holding valid qcadlib Professional Edition licenses may use
14 ** this file in accordance with the qcadlib Commercial License
15 ** Agreement provided with the Software.
17 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
18 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 ** See http://www.ribbonsoft.com for further details.
22 ** Contact info@ribbonsoft.com if any conditions of this licensing are
25 **********************************************************************/
27 #include "rs_scriptlist.h"
29 #include "rs_system.h"
31 RS_ScriptList * RS_ScriptList::uniqueInstance = NULL;
34 * Default constructor.
36 RS_ScriptList::RS_ScriptList(): scriptIterator(scripts)
38 //Should be dealt with...
39 //#warning "!!! Need to deal with setAutoDelete() Qt3->Qt4 !!!"
40 // scripts.setAutoDelete(true);
42 //scriptListListeners.setAutoDelete(false);
43 //activeScript = NULL;
46 /*virtual*/ RS_ScriptList::~RS_ScriptList()
48 while (!scripts.isEmpty())
49 delete scripts.takeFirst();
53 * @return Instance to the unique script list.
55 /*static*/ RS_ScriptList * RS_ScriptList::instance()
57 if (uniqueInstance == NULL)
58 uniqueInstance = new RS_ScriptList();
60 return uniqueInstance;
64 * Initializes the script list by creating RS_Script
65 * objects, one for each script that could be found.
67 void RS_ScriptList::init()
69 RS_DEBUG->print("RS_ScriptList::initScripts");
72 QStringList list = RS_SYSTEM->getScriptList();
75 for(QStringList::Iterator it=list.begin(); it!=list.end(); ++it)
77 RS_DEBUG->print("script: %s:", (*it).toLatin1().data());
80 script = new RS_Script(fi.baseName(), fi.absoluteFilePath());
81 scripts.append(script);
83 RS_DEBUG->print("base: %s", fi.baseName().toLatin1().data());
84 RS_DEBUG->print("path: %s", fi.absoluteFilePath().toLatin1().data());
87 //RS_Script* f = new RS_Script("normal");
92 * Removes all scripts in the scriptlist.
94 void RS_ScriptList::clearScripts()
99 int RS_ScriptList::countScripts()
101 return scripts.count();
105 * Removes a script from the list.
106 * Listeners are notified after the script was removed from
107 * the list but before it gets deleted.
109 void RS_ScriptList::removeScript(RS_Script * script)
111 RS_DEBUG->print("RS_ScriptList::removeScript()");
113 // here the script is removed from the list but not deleted
114 // scripts.remove(script);
115 // We have to delete it since AutoDelete does not exist in QList<T>
116 int i = scripts.indexOf(script);
119 delete scripts.takeAt(i);
121 //for (uint i=0; i<scriptListListeners.count(); ++i) {
122 // RS_ScriptListListener* l = scriptListListeners.at(i);
123 // l->scriptRemoved(script);
126 // activate an other script if necessary:
127 //if (activeScript==script) {
128 // activateScript(scripts.first());
131 // now it's save to delete the script
136 * @return Pointer to the script with the given name or
137 * \p NULL if no such script was found. The script will be loaded into
138 * memory if it's not already.
140 RS_Script * RS_ScriptList::requestScript(const QString & name)
142 RS_DEBUG->print("RS_ScriptList::requestScript %s", name.toLatin1().data());
144 QString name2 = name.toLower();
145 RS_Script * foundScript = NULL;
147 RS_DEBUG->print("name2: %s", name2.toLatin1().data());
149 // Search our list of available scripts:
150 // for(RS_Script * s=scripts.first(); s!=NULL; s=scripts.next())
151 for(int i=0; i<scripts.size(); i++)
153 RS_Script * s = scripts[i];
155 if (s->getName() == name2)
166 //! @return First script of the list.
167 RS_Script * RS_ScriptList::firstScript()
169 // return scripts.first();
170 scriptIterator.toFront();
171 return scriptIterator.next();
174 /** @return Next script from the list after
175 * calling firstScript() or nextScript().
177 RS_Script * RS_ScriptList::nextScript()
179 // return scripts.next();
180 return scriptIterator.next();
184 * @return Pointer to the script with the given name or
185 * \p NULL if no such script was found.
187 //RS_Script* RS_ScriptList::loadScript(const QString& name) {
191 * Tests the script list and its ability to load scripts.
193 bool RS_ScriptList::test()
195 //RS_ScriptList* l = RS_ScriptList::instance();
197 //std::cout << "RS_ScriptList: " << *l << std::endl;