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.

125 lines
4.3KB

  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. #ifndef __scriptclientinterface_h__
  17. #define __scriptclientinterface_h__
  18. #include <tqvariant.h>
  19. class TQString;
  20. //namespace KScriptInterface
  21. //{
  22. /**
  23. * This class is used for allowing feedback to the main system.
  24. * @author Ian Reinhart Geiser <geiseri@kde.org>
  25. *
  26. * To implement KScript in your application you would use this class to interface with the scripting engine.
  27. * There are currently a few implementations of script managers around but developers can implement their own custom
  28. * interfaces with this class.
  29. * @code
  30. * class MyScript : public TQObject, public KScriptClientInterface {
  31. * Q_OBJECT
  32. * public:
  33. *
  34. * MyScript(TQObject *parent)
  35. * {
  36. * // Create your @ref KScriptInterface here.
  37. * m_interface = KParts::ComponentFactory::createInstanceFromQuery<KScriptInterface>(
  38. * "KScriptRunner/KScriptRunner", "([X-TDE-Script-Runner] == 'bash/shell')", this );
  39. * }
  40. *
  41. * virtual ~KScriptAction()
  42. * {
  43. * delete m_interface;
  44. * }
  45. *
  46. * signals:
  47. * void error ( const TQString &msg );
  48. * void warning ( const TQString &msg );
  49. * void output ( const TQString &msg );
  50. * void progress ( int percent );
  51. * void done ( KScriptClientInterface::Result result, const TQVariant &returned );
  52. *
  53. * public slots:
  54. * void activate(const TQVariant &args)
  55. * {
  56. * m_interface->run(parent(), args);
  57. * }
  58. *
  59. * private:
  60. *
  61. * KScriptInterface *m_interface;
  62. * };
  63. * @endcode
  64. * Things to note about this example are that it only handles a single script type and instance. You may wish to
  65. * extend this.
  66. **/
  67. class KScriptClientInterface
  68. {
  69. public:
  70. enum Result { ResultSuccess, ResultFailure, ResultContinue, ResultBreak };
  71. /**
  72. * This function will allow the main application of any errors
  73. * that have occurred during processing of the script.
  74. * For script clients its best to implement this as a signal so feedback
  75. * can be sent to the main application.
  76. */
  77. virtual void error( const TQString &msg ) =0;
  78. /**
  79. * This function will allow the main application of any warnings
  80. * that have occurred during the processing of the script.
  81. * For script clients its best to implement this as a signal so feedback
  82. * can be sent to the main application.
  83. */
  84. virtual void warning( const TQString &msg ) =0;
  85. /**
  86. * This function will allow the main application of any normal
  87. * output that has occurred during the processing of the script.
  88. * For script clients its best to implement this as a signal so feedback
  89. * can be sent to the main application.
  90. */
  91. virtual void output( const TQString &msg ) =0;
  92. /**
  93. * This function will allow feedback to any progress bars in the main
  94. * application as to how far along the script is. This is very useful when
  95. * a script is processing files or doing some long operation that is of a
  96. * known duration.]
  97. * For script clients its best to implement this as a signal so feedback
  98. * can be sent to the main application.
  99. */
  100. virtual void progress( int percent ) =0;
  101. /**
  102. * This function will allow feedback on completion of the script.
  103. * It turns the result as a KScriptInteface::Result, and a return
  104. * value as a QVariant
  105. * For script clients its best to implement this as a signal so feedback
  106. * can be sent to the main application.
  107. */
  108. virtual void done( KScriptClientInterface::Result result, const TQVariant &returned ) =0;
  109. /**
  110. * Returned when the script has finished running.
  111. * For script clients its best to implement this as a signal so feedback
  112. * can be sent to the main application.
  113. **/
  114. //virtual bool isRunning() =0;
  115. };
  116. //};
  117. #endif