Smb4K – Samba (SMB) share advanced browser
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.

192 lines
5.3KB

  1. /***************************************************************************
  2. smb4kpreviewer - This class queries a remote share for a preview
  3. -------------------
  4. begin : Mo Mai 28 2007
  5. copyright : (C) 2007 by Alexander Reinholdt
  6. email : dustpuppy@users.berlios.de
  7. ***************************************************************************/
  8. /***************************************************************************
  9. * This program is free software; you can redistribute it and/or modify *
  10. * it under the terms of the GNU General Public License as published by *
  11. * the Free Software Foundation; either version 2 of the License, or *
  12. * (at your option) any later version. *
  13. * *
  14. * This program is distributed in the hope that it will be useful, but *
  15. * WITHOUT ANY WARRANTY; without even the implied warranty of *
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
  17. * General Public License for more details. *
  18. * *
  19. * You should have received a copy of the GNU General Public License *
  20. * along with this program; if not, write to the *
  21. * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, *
  22. * MA 02110-1301 USA *
  23. ***************************************************************************/
  24. #ifndef SMB4KPREVIEWER_H
  25. #define SMB4KPREVIEWER_H
  26. #ifdef HAVE_CONFIG_H
  27. #include <config.h>
  28. #endif
  29. // TQt includes
  30. #include <tqobject.h>
  31. #include <tqstring.h>
  32. #include <tqptrqueue.h>
  33. // KDE includes
  34. #include <kprocess.h>
  35. // forward declarations
  36. class Smb4KPreviewItem;
  37. /**
  38. * This class is part of the core of Smb4K. It queries a remote SMB share for
  39. * a preview and returns the result.
  40. *
  41. * @author Alexander Reinholdt <dustpuppy@users.berlios.de>
  42. */
  43. class Smb4KPreviewer : public TQObject
  44. {
  45. Q_OBJECT
  46. TQ_OBJECT
  47. public:
  48. /**
  49. * The constructor
  50. *
  51. * @param parent The parent object
  52. *
  53. * @param name The name of this object
  54. */
  55. Smb4KPreviewer( TQObject *parent = 0, const char *name = 0 );
  56. /**
  57. * The destructor
  58. */
  59. ~Smb4KPreviewer();
  60. /**
  61. * Get a preview of the contents of @p item.
  62. *
  63. * In the case that @p item represents a 'homes' share, the user will be
  64. * prompted for the user name with which he wants to log in and the share
  65. * name of @p item will be set to the result.
  66. *
  67. * @param item The item for which a preview should be
  68. * requested.
  69. *
  70. * @returns TRUE if einter the share name is not 'homes' or if it could
  71. * successfully be set to a user name. Otherwise it returns FALSE.
  72. */
  73. bool preview( Smb4KPreviewItem *item );
  74. /**
  75. * Using this function, you can find out whether the previewer is running
  76. * at the moment.
  77. *
  78. * @returns TRUE if the previewer is running or FALSE otherwise.
  79. */
  80. bool isRunning() { return m_working; }
  81. /**
  82. * Abort any action the previewer is performing at the moment and clear
  83. * the queue.
  84. */
  85. void abort();
  86. signals:
  87. /**
  88. * Emits the state the previewer is in
  89. *
  90. * @param state The state
  91. */
  92. void state( int state );
  93. /**
  94. * Emits the preview after the process exited successfully. Get the contents
  95. * of the remote share by looping through the Smb4KPreviewItem::contents() list.
  96. *
  97. * @param item The item for which the preview was received.
  98. */
  99. void result( Smb4KPreviewItem *item );
  100. /**
  101. * This signal is emitted if an error occurred.
  102. */
  103. void failed();
  104. protected:
  105. /**
  106. * Reimplemented from TQObject
  107. */
  108. void timerEvent( TQTimerEvent *e );
  109. protected slots:
  110. /**
  111. * This slot receives output from stdout.
  112. *
  113. * @param proc The process
  114. *
  115. * @param buf The buffer
  116. *
  117. * @param len The length of the buffer
  118. */
  119. void slotReceivedStdout( KProcess *proc, char *buf, int len );
  120. /**
  121. * This slot receives output from stderr.
  122. *
  123. * @param proc The process
  124. *
  125. * @param buf The buffer
  126. *
  127. * @param len The length of the buffer
  128. */
  129. void slotReceivedStderr( KProcess *proc, char *buf, int len );
  130. /**
  131. * Is called, when the KProcess exited.
  132. *
  133. * @param proc The process that exited
  134. */
  135. void slotProcessExited( KProcess *proc );
  136. private:
  137. /**
  138. * The KProcess object
  139. */
  140. KProcess *m_proc;
  141. /**
  142. * The output buffer
  143. */
  144. TQString m_buffer;
  145. /**
  146. * This is the pointer to the Smb4KPreviewItem that's
  147. * processed.
  148. */
  149. Smb4KPreviewItem *m_item;
  150. /**
  151. * Indicates whether the previewer is running or not.
  152. */
  153. bool m_working;
  154. /**
  155. * This pointer queue holds the pointers to the Smb4KPreviewItem
  156. * objects that are to be processed.
  157. */
  158. TQPtrQueue<Smb4KPreviewItem> m_queue;
  159. /**
  160. * The timer id
  161. */
  162. int m_timer_id;
  163. };
  164. #endif