summaryrefslogtreecommitdiffstats
path: root/kio/kio/progressbase.h
blob: cbcab06bee182cf3da3a5fb14622e08d82c3edc2 (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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
/* This file is part of the KDE libraries
   Copyright (C) 2000 Matej Koss <koss@miesto.sk>

   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 __progressbase_h__
#define __progressbase_h__


#include <tqwidget.h>

#include <kio/global.h>

class KURL;
namespace TDEIO {
  class Job;
  class CopyJob;
  class DeleteJob;
}

namespace TDEIO
{
  enum Progress {
    DEFAULT = 1,
    STATUSBAR = 2,
    LIST = 3
  };

/**
* This class does all initialization stuff for progress,
* like connecting signals to slots.
* All slots are implemented as pure virtual methods.
*
* All custom IO progress dialog should inherit this class.
* Add your GUI code to the constructor and implemement those virtual
* methods which you need in order to display progress.
*
* E.g. StatusbarProgress only implements slotTotalSize(),
* slotPercent() and slotSpeed().
*
* Custom progress dialog will be used like this :
* \code
* // create job
* CopyJob* job = TDEIO::copy(...);
* // create a dialog
* MyCustomProgress *customProgress;
* customProgress = new MyCustomProgress();
* // connect progress with job
* customProgress->setJob( job );
* ...
* \endcode
*
* There is a special method setStopOnClose() that controls the behavior of
* the dialog.
* @short Base class for IO progress dialogs.
* @author Matej Koss <koss@miesto.sk>
*/
class KIO_EXPORT ProgressBase : public TQWidget {

  Q_OBJECT

public:

  /**
   * Creates a new progress dialog.
   * @param parent the parent of this dialog window, or 0
   */
  ProgressBase( TQWidget *parent );
  ~ProgressBase() {}

  /**
   * Assign a TDEIO::Job to this progress dialog.
   * @param job the job to assign
   */
  void setJob( TDEIO::Job *job );
  /**
   * Assign a TDEIO::Job to this progress dialog.
   * @param job the job to assign
   */
  void setJob( TDEIO::CopyJob *job );
  /**
   * Assign a TDEIO::Job to this progress dialog.
   * @param job the job to assign
   */
  void setJob( TDEIO::DeleteJob *job );

  // should we stop the job when the dialog is closed ?
  void setStopOnClose( bool stopOnClose ) { m_bStopOnClose = stopOnClose; }
  bool stopOnClose() const { return m_bStopOnClose; }

  // should we delete the dialog or just clean it when the job is finished ?
  /**
   * This controls whether the dialog should be deleted or only cleaned when
   * the TDEIO::Job is finished (or canceled).
   *
   * If your dialog is an embedded widget and not a separate window, you should
   * setOnlyClean(true) in the constructor of your custom dialog.
   *
   * @param onlyClean If true the dialog will only call method slotClean.
   * If false the dialog will be deleted.
   * @see onlyClean()
   */
  void setOnlyClean( bool onlyClean ) { m_bOnlyClean = onlyClean; }

  /**
   * Checks whether the dialog should be deleted or cleaned.
   * @return true if the dialog only calls slotClean, false if it will be
   *         deleted
   * @see setOnlyClean()
   */
  bool onlyClean() const { return m_bOnlyClean; }

  /**
   * Call when the operation finished.
   * @since 3.1
   */
  void finished();

public slots:
  /**
   * This method should be called for correct cancellation of IO operation
   * Connect this to the progress widgets buttons etc.
   */
  void slotStop();
  /**
   * This method is called when the widget should be cleaned (after job is finished).
   * redefine this for custom behavior.
   */
  virtual void slotClean();

  // progress slots
  /**
   * Called to set the total size.
   * @param job the TDEIO::Job
   * @param size the total size in bytes
   */
  virtual void slotTotalSize( TDEIO::Job* job, TDEIO::filesize_t size ) {
    Q_UNUSED(job);Q_UNUSED(size);}
  /**
   * Called to set the total number of files.
   * @param job the TDEIO::Job
   * @param files the number of files
   */
  virtual void slotTotalFiles( TDEIO::Job* job, unsigned long files ) {
    Q_UNUSED(job);Q_UNUSED(files);}
  /**
   * Called to set the total number of directories.
   * @param job the TDEIO::Job
   * @param dirs the number of directories
   */
  virtual void slotTotalDirs( TDEIO::Job* job, unsigned long dirs ) {
    Q_UNUSED(job);Q_UNUSED(dirs);}

  /**
   * Called to set the processed size.
   * @param job the TDEIO::Job
   * @param bytes the processed size in bytes
   */
  virtual void slotProcessedSize( TDEIO::Job* job, TDEIO::filesize_t bytes ) {
    Q_UNUSED(job);Q_UNUSED(bytes);}
  /**
   * Called to set the number of processed files.
   * @param job the TDEIO::Job
   * @param files the number of files
   */
  virtual void slotProcessedFiles( TDEIO::Job* job, unsigned long files ) {
    Q_UNUSED(job);Q_UNUSED(files);}
  /**
   * Called to set the number of processed directories.
   * @param job the TDEIO::Job
   * @param dirs the number of directories
   */
  virtual void slotProcessedDirs( TDEIO::Job* job, unsigned long dirs ) {
    Q_UNUSED(job);Q_UNUSED(dirs);}

  /**
   * Called to set the speed.
   * @param job the TDEIO::Job
   * @param speed the speed in bytes/second
   */
  virtual void slotSpeed( TDEIO::Job* job, unsigned long speed ) {
    Q_UNUSED(job);Q_UNUSED(speed);}

  /**
   * Called to set the percentage.
   * @param job the TDEIO::Job
   * @param percent the percentage
   */
  virtual void slotPercent( TDEIO::Job* job, unsigned long percent ) {
    Q_UNUSED(job);Q_UNUSED(percent);}

  /**
   * Called when the job is copying.
   * @param job the TDEIO::Job
   * @param src the source of the operation
   * @param dest the destination of the operation
   */
  virtual void slotCopying( TDEIO::Job* job, const KURL& src, const KURL& dest ) {
    Q_UNUSED(job);Q_UNUSED(src);Q_UNUSED(dest);}
  /**
   * Called when the job is moving.
   * @param job the TDEIO::Job
   * @param src the source of the operation
   * @param dest the destination of the operation
   */
  virtual void slotMoving( TDEIO::Job* job, const KURL& src, const KURL& dest ) {
    Q_UNUSED(job);Q_UNUSED(src);Q_UNUSED(dest);}
  /**
   * Called when the job is deleting.
   * @param job the TDEIO::Job
   * @param url the URL to delete
   */
  virtual void slotDeleting( TDEIO::Job* job, const KURL& url) {
    Q_UNUSED(job);Q_UNUSED(url);}
  /**
   * Called when the job is creating a directory.
   * @param job the TDEIO::Job
   * @param dir the URL of the directory to create
   */
  virtual void slotCreatingDir( TDEIO::Job* job, const KURL& dir ) {
    Q_UNUSED(job);Q_UNUSED(dir);}

  /**
   * Called when the job is resuming..
   * @param job the TDEIO::Job
   * @param from the position to resume from in bytes
   */
  virtual void slotCanResume( TDEIO::Job* job, TDEIO::filesize_t from) {
    Q_UNUSED(job);Q_UNUSED(from);}

signals:
  /**
   * Called when the operation stopped.
   */
  void stopped();

protected slots:
  void slotFinished( TDEIO::Job* );

protected:

  virtual void closeEvent( TQCloseEvent * );

  TDEIO::Job* m_pJob;

private:
  bool m_bOnlyClean;
  bool m_bStopOnClose;


protected:
    virtual void virtual_hook( int id, void* data );
private:
    class ProgressBasePrivate* d;
};

} /* namespace */

#endif // __progressbase_h__