1 #include "scriptmanager.h"
2 #include <kparts/part.h>
3 #include <kparts/componentfactory.h>
4 #include <kapplication.h>
5 #include <kdesktopfile.h>
6 #include <kstandarddirs.h>
9 #include <kmessagebox.h>
18 TQString scriptMethod;
22 ScriptInfo::ScriptInfo()
35 m_scripts.setAutoDelete(
true);
36 m_scriptCache.setAutoDelete(
true);
44 TQString tmpScriptType =
"";
45 TQString tmpScriptFile =
"";
46 TQString tmpScriptMethod =
"";
52 m_scripts.insert(desktop.
readName(),
new ScriptInfo());
54 TQString localpath = TQString(kapp->name()) +
"/scripts/" + desktop.
readEntry(
"X-KDE-ScriptName",
"");
55 m_scripts[desktop.
readName()]->scriptFile =
locate(
"data", localpath);
63 bool result = m_scriptCache.remove(scriptName);
64 result = m_scripts.remove(scriptName);
69 TQDictIterator<ScriptInfo> it( m_scripts );
71 TQStringList scriptList;
72 while ( it.current() )
74 scriptList.append(it.currentKey());
81 m_scriptCache.clear();
86 ScriptInfo *newScript = m_scripts[scriptName];
89 TQString scriptType =
"([X-KDE-Script-Runner] == '" + newScript->scriptType +
"')";
90 kdDebug()<<
"running script, type = '"<<scriptType<<
"'"<<
endl;
92 if ( !m_scriptCache[scriptName] )
98 KScriptInterface *ksif = KParts::ComponentFactory::createInstanceFromQuery<KScriptInterface>(
"KScriptRunner/KScriptRunner", scriptType, this );
101 m_scriptCache.insert( scriptName, ksif );
106 KMessageBox::sorry(0, i18n(
"Unable to get KScript Runner for type \"%1\".").arg(newScript->scriptType), i18n(
"KScript Error"));
110 m_currentScript = scriptName;
112 if ( m_scriptCache[m_currentScript] )
114 m_scriptCache[m_currentScript]->ScriptClientInterface =
this;
115 if (!newScript->scriptMethod.isEmpty())
116 m_scriptCache[m_currentScript]->setScript( newScript->scriptFile, newScript->scriptMethod );
118 m_scriptCache[m_currentScript]->setScript( newScript->scriptFile );
119 m_scriptCache[m_currentScript]->run(context, arg);
125 m_scriptCache.remove(m_currentScript);
129 KMessageBox::sorry(0, i18n(
"Unable find script \"%1\".").arg(scriptName), i18n(
"KScript Error"));
131 #include "scriptmanager.moc"
132 #include "scriptinterface.moc"