File indexing completed on 2024-12-01 06:51:47

0001 /***************************************************************************
0002                           cscriptlist.cpp  -  list of scripts
0003                              -------------------
0004     begin                : Pi dec 13 2002
0005     copyright            : (C) 2002-2009 by Tomas Mecir
0006     email                : kmuddy@kmuddy.com
0007  ***************************************************************************/
0008 
0009 /***************************************************************************
0010  *                                                                         *
0011  *   This program is free software; you can redistribute it and/or modify  *
0012  *   it under the terms of the GNU General Public License as published by  *
0013  *   the Free Software Foundation; either version 2 of the License, or     *
0014  *   (at your option) any later version.                                   *
0015  *                                                                         *
0016  ***************************************************************************/
0017 
0018 #include "cscriptlist.h"
0019 
0020 #include "cactionmanager.h"
0021 #include "crunninglist.h"
0022 #include "crunningscript.h"
0023 #include "cscript.h"
0024 #include "cscripteditor.h"
0025 
0026 #include <KLocalizedString>
0027 
0028 struct cScriptList::Private {
0029   QString nameToFind;
0030   bool nameFound;
0031   QString paramList;
0032 };
0033 
0034 cScriptList::cScriptList () : cList ("scripts")
0035 {
0036   d = new Private;
0037 
0038   addStringProperty ("command", "Command to execute");
0039   addStringProperty ("work-directory", "Working directory");
0040   addBoolProperty ("send-user-commands", "Send user commands to the script", false);
0041   addBoolProperty ("adv-comunication", "Enable advanced communication", false);
0042   addBoolProperty ("flow-control", "Enable flow control", true);
0043   addBoolProperty ("enable-variables", "Enable variable server", false);
0044   addBoolProperty ("single-instance", "Single-instance script", false);
0045 }
0046 
0047 cScriptList::~cScriptList ()
0048 {
0049   delete d;
0050 }
0051 
0052 cListObject *cScriptList::newObject ()
0053 {
0054   return new cScript (this);
0055 }
0056 
0057 cListEditor *cScriptList::editor (QWidget *parent)
0058 {
0059   return new cScriptEditor (parent);
0060 }
0061 
0062 QString cScriptList::nameToFind ()
0063 {
0064   return d->nameToFind;
0065 }
0066 
0067 void cScriptList::setNameFound ()
0068 {
0069   d->nameFound = true;
0070 }
0071 
0072 bool cScriptList::nameExists (const QString &name)
0073 {
0074   d->nameToFind = name;
0075   d->nameFound = false;
0076   traverse (SCRIPT_FIND);
0077   return d->nameFound;
0078 }
0079 
0080 bool cScriptList::runScript (QString name, const QString &paramlist)
0081 {
0082   d->paramList = paramlist;
0083   d->nameToFind = name;
0084   d->nameFound = false;
0085   traverse (SCRIPT_EXECUTE);
0086   if (!d->nameFound)
0087     cActionManager::self()->invokeEvent ("message", session(), i18n ("Such external script does not exist!"));
0088   return d->nameFound;
0089 }
0090 
0091 bool cScriptList::runScript (cScript *script)
0092 {
0093   if (script == 0) return false;
0094   cRunningScript *rs = script->prepareToLaunch (d->paramList);
0095   if (rs != 0)
0096   {
0097     cRunningList *rl = dynamic_cast<cRunningList *>(cActionManager::self()->object ("runninglist", session()));
0098     rl->addScript (rs);
0099     rs->launch (rl->fcState());
0100     return true;
0101   }
0102   return false;
0103 }
0104