TDE core libraries
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

scriptloader.cpp 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /* This file is part of the KDE project
  2. Copyright (C) 2001 Ian Reinhart Geiser (geiseri@kde.org)
  3. This library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Library General Public
  5. License as published by the Free Software Foundation; either
  6. version 2 of the License, or (at your option) any later version.
  7. This library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Library General Public License for more details.
  11. You should have received a copy of the GNU Library General Public License
  12. along with this library; see the file COPYING.LIB. If not, write to
  13. the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  14. Boston, MA 02110-1301, USA.
  15. */
  16. #include "scriptloader.h"
  17. #include <tdeapplication.h>
  18. #include <tdeparts/part.h>
  19. #include <tdeparts/componentfactory.h>
  20. #include <tdeglobal.h>
  21. #include <tdelocale.h>
  22. #include <tdeconfig.h>
  23. #include <kdesktopfile.h>
  24. #include <kstandarsdirs.h>
  25. #include <tdestdaccel.h>
  26. #include <kdebug.h>
  27. #include <tqdir.h>
  28. #include <tqfileinfo.h>
  29. ScriptLoader::ScriptLoader(TDEMainWindow *parent) : TQObject (parent)
  30. {
  31. m_parent = parent;
  32. m_scripts.clear();
  33. m_theAction = new TDESelectAction ( i18n("KDE Scripts"),
  34. 0,
  35. this,
  36. TQT_SLOT(runAction()),
  37. m_parent->actionCollection(),
  38. "scripts");
  39. }
  40. ScriptLoader::~ScriptLoader()
  41. {
  42. // Clean out the list
  43. m_scripts.clear();
  44. }
  45. TDESelectAction * ScriptLoader::getScripts()
  46. {
  47. // Get the available scripts for this application.
  48. TQStringList pluginList = "";
  49. // Find plugins
  50. TQString searchPath = kapp->name();
  51. searchPath += "/scripts/";
  52. TQDir d(locate( "data", searchPath));
  53. kdDebug() << "loading plugin from " << locate( "data", searchPath) << endl;
  54. const QFileInfoList *fileList = d.entryInfoList("*.desktop");
  55. QFileInfoListIterator it ( *fileList );
  56. TQFileInfo *fi;
  57. // Find all available script desktop files
  58. while( (fi=it.current()))
  59. {
  60. // Query each desktop file
  61. if(KDesktopFile::isDesktopFile(fi->absFilePath()))
  62. {
  63. KDesktopFile desktop((fi->absFilePath()), true);
  64. kdDebug () << "Trying to load script type: " << desktop.readType() << endl;
  65. KScriptInterface *tmpIface = KParts::ComponentFactory::createInstanceFromQuery<KScriptInterface>(desktop.readType() );
  66. if( tmpIface != 0 )
  67. {
  68. m_scripts.append(tmpIface);
  69. m_scripts.current()->setScript(desktop.readURL());
  70. //if(m_parent != 0)
  71. //m_scripts.current()->setParent(m_parent);
  72. pluginList.append(desktop.readName());
  73. }
  74. else
  75. kdDebug() << desktop.readName() << " could not be loaded!" << endl;
  76. }
  77. ++it;
  78. }
  79. m_theAction->clear();
  80. m_theAction->setItems(pluginList);
  81. return m_theAction;
  82. }
  83. void ScriptLoader::runAction()
  84. {
  85. TQString scriptName = m_theAction->currentText();
  86. }
  87. void ScriptLoader::stopAction()
  88. {
  89. }
  90. #include "scriptloader.moc"