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_fileinfo.h"
30 #include "rs_stringlist.h"
31 #include "rs_system.h"
33 RS_ScriptList* RS_ScriptList::uniqueInstance = NULL;
36 * Default constructor.
38 RS_ScriptList::RS_ScriptList() {
39 scripts.setAutoDelete(true);
41 //scriptListListeners.setAutoDelete(false);
42 //activeScript = NULL;
47 * Initializes the script list by creating RS_Script
48 * objects, one for each script that could be found.
50 void RS_ScriptList::init() {
52 RS_DEBUG->print("RS_ScriptList::initScripts");
55 RS_StringList list = RS_SYSTEM->getScriptList();
58 for ( RS_StringList::Iterator it = list.begin();
59 it != list.end(); ++it ) {
60 RS_DEBUG->print("script: %s:", (*it).latin1());
63 script = new RS_Script(fi.baseName(), fi.absFilePath());
64 scripts.append(script);
66 RS_DEBUG->print("base: %s", fi.baseName().latin1());
67 RS_DEBUG->print("path: %s", fi.absFilePath().latin1());
70 //RS_Script* f = new RS_Script("normal");
76 * Removes all scripts in the scriptlist.
78 void RS_ScriptList::clearScripts() {
85 * Removes a script from the list.
86 * Listeners are notified after the script was removed from
87 * the list but before it gets deleted.
89 void RS_ScriptList::removeScript(RS_Script* script) {
90 RS_DEBUG->print("RS_ScriptList::removeScript()");
92 // here the script is removed from the list but not deleted
93 scripts.remove(script);
95 //for (uint i=0; i<scriptListListeners.count(); ++i) {
96 // RS_ScriptListListener* l = scriptListListeners.at(i);
97 // l->scriptRemoved(script);
100 // activate an other script if necessary:
101 //if (activeScript==script) {
102 // activateScript(scripts.first());
105 // now it's save to delete the script
112 * @return Pointer to the script with the given name or
113 * \p NULL if no such script was found. The script will be loaded into
114 * memory if it's not already.
116 RS_Script* RS_ScriptList::requestScript(const RS_String& name) {
117 RS_DEBUG->print("RS_ScriptList::requestScript %s", name.latin1());
119 RS_String name2 = name.lower();
120 RS_Script* foundScript = NULL;
122 RS_DEBUG->print("name2: %s", name2.latin1());
124 // Search our list of available scripts:
125 for (RS_Script* s=scripts.first();
129 if (s->getName()==name2) {
142 * @return Pointer to the script with the given name or
143 * \p NULL if no such script was found.
145 //RS_Script* RS_ScriptList::loadScript(const RS_String& name) {
150 * Tests the script list and its ability to load scripts.
152 bool RS_ScriptList::test() {
154 //RS_ScriptList* l = RS_ScriptList::instance();
156 //std::cout << "RS_ScriptList: " << *l << std::endl;