summaryrefslogtreecommitdiffstats
path: root/tdeio/tdeio/observer.h
blob: 1864f9977068998f47f6a2044f6e1af99ab8b6af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
/* This file is part of the KDE libraries
   Copyright (C) 2000 Matej Koss <koss@miesto.sk>
                      David Faure <faure@kde.org>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License version 2 as published by the Free Software Foundation.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
*/
#ifndef __tdeio_observer_h__
#define __tdeio_observer_h__

#include <tqobject.h>
#include <dcopobject.h>
#include <tqintdict.h>

#include <tdeio/global.h>
#include <tdeio/authinfo.h>
#include "tdeio/job.h"
#include "tdeio/skipdlg.h"
#include "tdeio/renamedlg.h"

class UIServer_stub;
class KURL;

namespace TDEIO {
  class Job;
}

/**
 * Observer for TDEIO::Job progress information.
 *
 * This class, of which there is always only one instance,
 * "observes" what jobs do and forwards this information
 * to the progress-info server.
 *
 * It is a DCOP object so that the UI server can call the
 * kill method when the user presses Cancel.
 *
 * Usually jobs are automatically registered by the
 * TDEIO::Scheduler, so you do not have to care about that.
 *
 * @short Observer for TDEIO::Job progress information
 * @author David Faure <faure@kde.org>
 */
class TDEIO_EXPORT Observer : public TQObject, public DCOPObject {

  K_DCOP
  Q_OBJECT

public:

  /**
   * Returns the unique observer object.
   * @return the observer object
   */
  static Observer * self() {
      if (!s_pObserver) s_pObserver = new Observer;
      return s_pObserver;
  }

  /**
   * Called by the job constructor, to signal its presence to the
   * UI Server.
   * @param job the new job
   * @param showProgress true to show progress, false otherwise
   * @return the progress ID assigned by the UI Server to the Job.
   */
  int newJob( TDEIO::Job * job, bool showProgress );

  /**
   * Called by the job destructor, to tell the UI Server that
   * the job ended.
   * @param progressId the progress ID of the job, as returned by newJob()
   */
  void jobFinished( int progressId );

  /**
   * @deprecated use TDEIO::AutoInfo
   */
  bool openPassDlg( const TQString& prompt, TQString& user, TQString& pass,
                    bool readOnly );

  /**
   * Opens a password dialog.
   * @param info the authentication information
   * @return true if successful ("ok" clicked), false otherwise
   */
  bool openPassDlg( TDEIO::AuthInfo& info );

  /**
   * Popup a message box. See TDEIO::SlaveBase.
   * This doesn't use DCOP anymore, it shows the dialog in the application's process.
   * Otherwise, other apps would block when trying to communicate with UIServer.
   * @param progressId the progress ID of the job, as returned by newJob()
   * @param type the type of the message box
   * @param text the text to show
   * @param caption the window caption
   * @param buttonYes the text of the "Yes" button
   * @param buttonNo the text of the "No button
   */
  static int messageBox( int progressId, int type, const TQString &text, const TQString &caption,
                         const TQString &buttonYes, const TQString &buttonNo );

  /**
   * Popup a message box. See TDEIO::SlaveBase.
   * This doesn't use DCOP anymore, it shows the dialog in the application's process.
   * Otherwise, other apps would block when trying to communicate with UIServer.
   * @param progressId the progress ID of the job, as returned by newJob()
   * @param type the type of the message box
   * @param text the text to show
   * @param caption the window caption
   * @param buttonYes the text of the "Yes" button
   * @param buttonNo the text of the "No button
   * @param dontAskAgainName A checkbox is added with which further confirmation can be turned off.
   *        The string is used to lookup and store the setting in tdeioslaverc.
   * @since 3.3
   */
  static int messageBox( int progressId, int type, const TQString &text, const TQString &caption,
                         const TQString &buttonYes, const TQString &buttonNo, const TQString &dontAskAgainName );

  /**
   * @internal
   * See renamedlg.h
   */
  TDEIO::RenameDlg_Result open_RenameDlg( TDEIO::Job * job,
                                        const TQString & caption,
                                        const TQString& src, const TQString & dest,
                                        TDEIO::RenameDlg_Mode mode,
                                        TQString& newDest,
                                        TDEIO::filesize_t sizeSrc = (TDEIO::filesize_t) -1,
                                        TDEIO::filesize_t sizeDest = (TDEIO::filesize_t) -1,
                                        time_t ctimeSrc = (time_t) -1,
                                        time_t ctimeDest = (time_t) -1,
                                        time_t mtimeSrc = (time_t) -1,
                                        time_t mtimeDest = (time_t) -1
                                        );

  /**
   * @internal
   * See skipdlg.h
   */
  TDEIO::SkipDlg_Result open_SkipDlg( TDEIO::Job * job,
                                    bool multi,
                                    const TQString & error_text );

k_dcop:
  /**
   * Called by the UI Server (using DCOP) if the user presses cancel.
   * @param progressId the progress ID of the job, as returned by newJob()
   */
  void killJob( int progressId );

  /**
   * Called by the UI Server (using DCOP) to get all the metadata of the job
   * @param progressId the progress IDof the job, as returned by newJob()
   */
  TDEIO::MetaData metadata( int progressId );

protected:

  static Observer * s_pObserver;
  Observer();
  ~Observer() {}

  UIServer_stub * m_uiserver;

  TQIntDict< TDEIO::Job > m_dctJobs;

public slots:

  void slotTotalSize( TDEIO::Job*, TDEIO::filesize_t size );
  void slotTotalFiles( TDEIO::Job*, unsigned long files );
  void slotTotalDirs( TDEIO::Job*, unsigned long dirs );

  void slotProcessedSize( TDEIO::Job*, TDEIO::filesize_t size );
  void slotProcessedFiles( TDEIO::Job*, unsigned long files );
  void slotProcessedDirs( TDEIO::Job*, unsigned long dirs );

  void slotSpeed( TDEIO::Job*, unsigned long speed );
  void slotPercent( TDEIO::Job*, unsigned long percent );
  void slotInfoMessage( TDEIO::Job*, const TQString & msg );

  void slotCopying( TDEIO::Job*, const KURL& from, const KURL& to );
  void slotMoving( TDEIO::Job*, const KURL& from, const KURL& to );
  void slotDeleting( TDEIO::Job*, const KURL& url );
  /// @since 3.1
  void slotTransferring( TDEIO::Job*, const KURL& url );
  void slotCreatingDir( TDEIO::Job*, const KURL& dir );
  // currently unused
  void slotCanResume( TDEIO::Job*, TDEIO::filesize_t offset );

public:
  void stating( TDEIO::Job*, const KURL& url );
  void mounting( TDEIO::Job*, const TQString & dev, const TQString & point );
  void unmounting( TDEIO::Job*, const TQString & point );
protected:
  virtual void virtual_hook( int id, void* data );
private:
  class ObserverPrivate* d;
};
#endif