interfaces
scriptloader.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "scriptloader.h"
00020
00021 #include <kapplication.h>
00022 #include <kparts/part.h>
00023 #include <kparts/componentfactory.h>
00024 #include <kglobal.h>
00025 #include <klocale.h>
00026 #include <kconfig.h>
00027 #include <kdesktopfile.h>
00028 #include <kstandarsdirs.h>
00029 #include <kstdaccel.h>
00030 #include <kdebug.h>
00031
00032 #include <qdir.h>
00033 #include <qfileinfo.h>
00034
00035
00036 ScriptLoader::ScriptLoader(KMainWindow *parent) : QObject (parent)
00037 {
00038 m_parent = parent;
00039 m_scripts.clear();
00040 m_theAction = new KSelectAction ( i18n("KDE Scripts"),
00041 0,
00042 this,
00043 SLOT(runAction()),
00044 m_parent->actionCollection(),
00045 "scripts");
00046 }
00047
00048 ScriptLoader::~ScriptLoader()
00049 {
00050
00051 m_scripts.clear();
00052 }
00053
00054 KSelectAction * ScriptLoader::getScripts()
00055 {
00056
00057 QStringList pluginList = "";
00058
00059 QString searchPath = kapp->name();
00060 searchPath += "/scripts/";
00061 QDir d(locate( "data", searchPath));
00062 kdDebug() << "loading plugin from " << locate( "data", searchPath) << endl;
00063 const QFileInfoList *fileList = d.entryInfoList("*.desktop");
00064 QFileInfoListIterator it ( *fileList );
00065 QFileInfo *fi;
00066
00067 while( (fi=it.current()))
00068 {
00069
00070 if(KDesktopFile::isDesktopFile(fi->absFilePath()))
00071 {
00072 KDesktopFile desktop((fi->absFilePath()), true);
00073 kdDebug () << "Trying to load script type: " << desktop.readType() << endl;
00074 KScriptInterface *tmpIface = KParts::ComponentFactory::createInstanceFromQuery<KScriptInterface>(desktop.readType() );
00075 if( tmpIface != 0 )
00076 {
00077 m_scripts.append(tmpIface);
00078 m_scripts.current()->setScript(desktop.readURL());
00079
00080
00081 pluginList.append(desktop.readName());
00082 }
00083 else
00084 kdDebug() << desktop.readName() << " could not be loaded!" << endl;
00085 }
00086 ++it;
00087 }
00088 m_theAction->clear();
00089 m_theAction->setItems(pluginList);
00090 return m_theAction;
00091 }
00092
00093 void ScriptLoader::runAction()
00094 {
00095 QString scriptName = m_theAction->currentText();
00096
00097 }
00098
00099 void ScriptLoader::stopAction()
00100 {
00101
00102 }
00103
00104 #include "scriptloader.moc"