• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • interfaces
 

interfaces

  • interfaces
  • tdescript
scriptmanager.cpp
1#include "scriptmanager.h"
2#include <tdeparts/part.h>
3#include <tdeparts/componentfactory.h>
4#include <tdeapplication.h>
5#include <kdesktopfile.h>
6#include <tdestandarddirs.h>
7
8#include <tdelocale.h>
9#include <tdemessagebox.h>
10#include <kdebug.h>
11
12//using namespace KScriptInterface;
13class ScriptInfo
14{
15 public:
16 TQString scriptType;
17 TQString scriptFile;
18 TQString scriptMethod;
19 ScriptInfo();
20 ~ScriptInfo(){}
21};
22ScriptInfo::ScriptInfo()
23{
24 scriptType = "";
25 scriptFile = "";
26 scriptMethod = "";
27}
28KScriptManager::KScriptManager(TQObject *parent, const char *name) :
29 TQObject(parent,name), KScriptClientInterface()
30{
31
32}
33KScriptManager::~KScriptManager()
34{
35 m_scripts.setAutoDelete(true);
36 m_scriptCache.setAutoDelete(true);
37
38}
39bool KScriptManager::addScript( const TQString &scriptDesktopFile)
40{
41 //m_scriptNames.append(scriptName);
42 // lets get some information about the script we are going to run...
43 bool success = false;
44 TQString tmpScriptType = "";
45 TQString tmpScriptFile = "";
46 TQString tmpScriptMethod = "";
47 // Read the desktop file
48
49 if(KDesktopFile::isDesktopFile(scriptDesktopFile))
50 {
51 KDesktopFile desktop(scriptDesktopFile, true);
52 m_scripts.insert(desktop.readName(), new ScriptInfo());
53 m_scripts[desktop.readName()]->scriptType = desktop.readType();
54 TQString localpath = TQString(tdeApp->name()) + "/scripts/" + desktop.readEntry("X-TDE-ScriptName", "");
55 m_scripts[desktop.readName()]->scriptFile = locate("data", localpath);
56// m_scripts[desktop.readName()]->scriptMethod = tmpScriptMethod;
57 success = true;
58 }
59 return success;
60}
61bool KScriptManager::removeScript( const TQString &scriptName )
62{
63 bool result = m_scriptCache.remove(scriptName);
64 result = m_scripts.remove(scriptName);
65 return result;
66}
67TQStringList KScriptManager::scripts()
68{
69 TQDictIterator<ScriptInfo> it( m_scripts );
70// return m_scriptNames;
71 TQStringList scriptList;
72 while ( it.current() )
73 {
74 scriptList.append(it.currentKey());
75 ++it;
76 }
77 return scriptList;
78}
79void KScriptManager::clear()
80{
81 m_scriptCache.clear();
82 m_scripts.clear();
83}
84void KScriptManager::runScript( const TQString &scriptName, TQObject *context, const TQVariant &arg)
85{
86 ScriptInfo *newScript = m_scripts[scriptName];
87 if (newScript)
88 {
89 TQString scriptType = "([X-TDE-Script-Runner] == '" + newScript->scriptType + "')";
90 kdDebug()<<"running script, type = '"<<scriptType<<"'"<<endl;
91 // See if the script is already cached...
92 if ( !m_scriptCache[scriptName] )
93 {
94 // via some magic we will let the old script engine go away after
95 // some minutes...
96 // currently i am thinking a TQTimer that will throw a signal in 10 minutes
97 // to remove m_scriptCache[m_currentScript]
98 KScriptInterface *ksif = KParts::ComponentFactory::createInstanceFromQuery<KScriptInterface>( "KScriptRunner/KScriptRunner", scriptType, this );
99 if ( ksif )
100 {
101 m_scriptCache.insert( scriptName, ksif );
102
103 }
104 else
105 {
106 KMessageBox::sorry(0, i18n("Unable to get KScript Runner for type \"%1\".").arg(newScript->scriptType), i18n("KScript Error"));
107 return;
108 }
109 }
110 m_currentScript = scriptName;
111
112 if ( m_scriptCache[m_currentScript] )
113 {
114 m_scriptCache[m_currentScript]->ScriptClientInterface = this;
115 if (!newScript->scriptMethod.isEmpty())
116 m_scriptCache[m_currentScript]->setScript( newScript->scriptFile, newScript->scriptMethod );
117 else
118 m_scriptCache[m_currentScript]->setScript( newScript->scriptFile );
119 m_scriptCache[m_currentScript]->run(context, arg);
120 }
121 else
122 {
123 // Dialog and say we cant go on...
124 // This is also a broken script so we need to remove it
125 m_scriptCache.remove(m_currentScript);
126 }
127 }
128 else
129 KMessageBox::sorry(0, i18n("Unable find script \"%1\".").arg(scriptName), i18n("KScript Error"));
130}
131#include "scriptmanager.moc"
132#include "scriptinterface.moc"
KDesktopFile
KDesktopFile::isDesktopFile
static bool isDesktopFile(const TQString &path)
KDesktopFile::readType
TQString readType() const
KDesktopFile::readName
TQString readName() const
KMessageBox::sorry
static void sorry(TQWidget *parent, const TQString &text, const TQString &caption=TQString::null, int options=Notify)
KScriptClientInterface
This class is used for allowing feedback to the main system.
Definition: scriptclientinterface.h:74
KScriptInterface
This class is the base for all script engines.
Definition: scriptinterface.h:48
KScriptManager::removeScript
bool removeScript(const TQString &scriptName)
Remove a script instance from the script engine.
Definition: scriptmanager.cpp:61
KScriptManager::clear
void clear()
Clear all script intstances in memory.
Definition: scriptmanager.cpp:79
KScriptManager::scripts
TQStringList scripts()
Access the names of script instances from the script engine.
Definition: scriptmanager.cpp:67
KScriptManager::addScript
bool addScript(const TQString &scriptDesktopFile)
Add a new script instance to the script engine.
Definition: scriptmanager.cpp:39
KScriptManager::KScriptManager
KScriptManager(TQObject *parent, const char *name)
Create a new instance of the script engine.
Definition: scriptmanager.cpp:28
KScriptManager::runScript
void runScript(const TQString &scriptName, TQObject *context=0, const TQVariant &arg=0)
Run the selected script.
Definition: scriptmanager.cpp:84
KScriptManager::~KScriptManager
virtual ~KScriptManager()
Destroy the current script engine.
Definition: scriptmanager.cpp:33
TDEConfigBase::readEntry
TQString readEntry(const TQString &pKey, const TQString &aDefault=TQString::null) const
endl
kndbgstream & endl(kndbgstream &s)
kdDebug
kdbgstream kdDebug(int area=0)
locate
TQString locate(const char *type, const TQString &filename, const TDEInstance *instance=TDEGlobal::instance())
tdelocale.h

interfaces

Skip menu "interfaces"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

interfaces

Skip menu "interfaces"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for interfaces by doxygen 1.9.4
This website is maintained by Timothy Pearson.