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.

observer.h 7.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /* This file is part of the KDE libraries
  2. Copyright (C) 2000 Matej Koss <koss@miesto.sk>
  3. David Faure <faure@kde.org>
  4. This library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Library General Public
  6. License version 2 as published by the Free Software Foundation.
  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 __tdeio_observer_h__
  17. #define __tdeio_observer_h__
  18. #include <tqobject.h>
  19. #include <dcopobject.h>
  20. #include <tqintdict.h>
  21. #include <tdeio/global.h>
  22. #include <tdeio/authinfo.h>
  23. #include "tdeio/job.h"
  24. #include "tdeio/skipdlg.h"
  25. #include "tdeio/renamedlg.h"
  26. class UIServer_stub;
  27. class KURL;
  28. namespace TDEIO {
  29. class Job;
  30. }
  31. /**
  32. * Observer for TDEIO::Job progress information.
  33. *
  34. * This class, of which there is always only one instance,
  35. * "observes" what jobs do and forwards this information
  36. * to the progress-info server.
  37. *
  38. * It is a DCOP object so that the UI server can call the
  39. * kill method when the user presses Cancel.
  40. *
  41. * Usually jobs are automatically registered by the
  42. * TDEIO::Scheduler, so you do not have to care about that.
  43. *
  44. * @short Observer for TDEIO::Job progress information
  45. * @author David Faure <faure@kde.org>
  46. */
  47. class TDEIO_EXPORT Observer : public TQObject, public DCOPObject {
  48. K_DCOP
  49. Q_OBJECT
  50. public:
  51. /**
  52. * Returns the unique observer object.
  53. * @return the observer object
  54. */
  55. static Observer * self() {
  56. if (!s_pObserver) s_pObserver = new Observer;
  57. return s_pObserver;
  58. }
  59. /**
  60. * Called by the job constructor, to signal its presence to the
  61. * UI Server.
  62. * @param job the new job
  63. * @param showProgress true to show progress, false otherwise
  64. * @return the progress ID assigned by the UI Server to the Job.
  65. */
  66. int newJob( TDEIO::Job * job, bool showProgress );
  67. /**
  68. * Called by the job destructor, to tell the UI Server that
  69. * the job ended.
  70. * @param progressId the progress ID of the job, as returned by newJob()
  71. */
  72. void jobFinished( int progressId );
  73. /**
  74. * @deprecated use TDEIO::AutoInfo
  75. */
  76. bool openPassDlg( const TQString& prompt, TQString& user, TQString& pass,
  77. bool readOnly );
  78. /**
  79. * Opens a password dialog.
  80. * @param info the authentication information
  81. * @return true if successful ("ok" clicked), false otherwise
  82. */
  83. bool openPassDlg( TDEIO::AuthInfo& info );
  84. /**
  85. * Popup a message box. See TDEIO::SlaveBase.
  86. * This doesn't use DCOP anymore, it shows the dialog in the application's process.
  87. * Otherwise, other apps would block when trying to communicate with UIServer.
  88. * @param progressId the progress ID of the job, as returned by newJob()
  89. * @param type the type of the message box
  90. * @param text the text to show
  91. * @param caption the window caption
  92. * @param buttonYes the text of the "Yes" button
  93. * @param buttonNo the text of the "No button
  94. */
  95. static int messageBox( int progressId, int type, const TQString &text, const TQString &caption,
  96. const TQString &buttonYes, const TQString &buttonNo );
  97. /**
  98. * Popup a message box. See TDEIO::SlaveBase.
  99. * This doesn't use DCOP anymore, it shows the dialog in the application's process.
  100. * Otherwise, other apps would block when trying to communicate with UIServer.
  101. * @param progressId the progress ID of the job, as returned by newJob()
  102. * @param type the type of the message box
  103. * @param text the text to show
  104. * @param caption the window caption
  105. * @param buttonYes the text of the "Yes" button
  106. * @param buttonNo the text of the "No button
  107. * @param dontAskAgainName A checkbox is added with which further confirmation can be turned off.
  108. * The string is used to lookup and store the setting in tdeioslaverc.
  109. * @since 3.3
  110. */
  111. static int messageBox( int progressId, int type, const TQString &text, const TQString &caption,
  112. const TQString &buttonYes, const TQString &buttonNo, const TQString &dontAskAgainName );
  113. /**
  114. * @internal
  115. * See renamedlg.h
  116. */
  117. TDEIO::RenameDlg_Result open_RenameDlg( TDEIO::Job * job,
  118. const TQString & caption,
  119. const TQString& src, const TQString & dest,
  120. TDEIO::RenameDlg_Mode mode,
  121. TQString& newDest,
  122. TDEIO::filesize_t sizeSrc = (TDEIO::filesize_t) -1,
  123. TDEIO::filesize_t sizeDest = (TDEIO::filesize_t) -1,
  124. time_t ctimeSrc = (time_t) -1,
  125. time_t ctimeDest = (time_t) -1,
  126. time_t mtimeSrc = (time_t) -1,
  127. time_t mtimeDest = (time_t) -1
  128. );
  129. /**
  130. * @internal
  131. * See skipdlg.h
  132. */
  133. TDEIO::SkipDlg_Result open_SkipDlg( TDEIO::Job * job,
  134. bool multi,
  135. const TQString & error_text );
  136. k_dcop:
  137. /**
  138. * Called by the UI Server (using DCOP) if the user presses cancel.
  139. * @param progressId the progress ID of the job, as returned by newJob()
  140. */
  141. void killJob( int progressId );
  142. /**
  143. * Called by the UI Server (using DCOP) to get all the metadata of the job
  144. * @param progressId the progress IDof the job, as returned by newJob()
  145. */
  146. TDEIO::MetaData metadata( int progressId );
  147. protected:
  148. static Observer * s_pObserver;
  149. Observer();
  150. ~Observer() {}
  151. UIServer_stub * m_uiserver;
  152. TQIntDict< TDEIO::Job > m_dctJobs;
  153. public slots:
  154. void slotTotalSize( TDEIO::Job*, TDEIO::filesize_t size );
  155. void slotTotalFiles( TDEIO::Job*, unsigned long files );
  156. void slotTotalDirs( TDEIO::Job*, unsigned long dirs );
  157. void slotProcessedSize( TDEIO::Job*, TDEIO::filesize_t size );
  158. void slotProcessedFiles( TDEIO::Job*, unsigned long files );
  159. void slotProcessedDirs( TDEIO::Job*, unsigned long dirs );
  160. void slotSpeed( TDEIO::Job*, unsigned long speed );
  161. void slotPercent( TDEIO::Job*, unsigned long percent );
  162. void slotInfoMessage( TDEIO::Job*, const TQString & msg );
  163. void slotCopying( TDEIO::Job*, const KURL& from, const KURL& to );
  164. void slotMoving( TDEIO::Job*, const KURL& from, const KURL& to );
  165. void slotDeleting( TDEIO::Job*, const KURL& url );
  166. /// @since 3.1
  167. void slotTransferring( TDEIO::Job*, const KURL& url );
  168. void slotCreatingDir( TDEIO::Job*, const KURL& dir );
  169. // currently unused
  170. void slotCanResume( TDEIO::Job*, TDEIO::filesize_t offset );
  171. public:
  172. void stating( TDEIO::Job*, const KURL& url );
  173. void mounting( TDEIO::Job*, const TQString & dev, const TQString & point );
  174. void unmounting( TDEIO::Job*, const TQString & point );
  175. protected:
  176. virtual void virtual_hook( int id, void* data );
  177. private:
  178. class ObserverPrivate* d;
  179. };
  180. // -*- mode: c++; c-basic-offset: 2 -*-
  181. #endif