KCoreAddons

kjob.h
1/*
2 This file is part of the KDE project
3
4 SPDX-FileCopyrightText: 2000 Stephan Kulow <coolo@kde.org>
5 SPDX-FileCopyrightText: 2000 David Faure <faure@kde.org>
6 SPDX-FileCopyrightText: 2006 Kevin Ottens <ervin@kde.org>
7
8 SPDX-License-Identifier: LGPL-2.0-or-later
9*/
10
11#ifndef KJOB_H
12#define KJOB_H
13
14#include <QObject>
15#include <QPair>
16#include <kcoreaddons_export.h>
17#include <memory>
18
19class KJobUiDelegate;
20
21class KJobPrivate;
22/**
23 * @class KJob kjob.h KJob
24 *
25 * The base class for all jobs.
26 * For all jobs created in an application, the code looks like
27 *
28 * \code
29 * void SomeClass::methodWithAsynchronousJobCall()
30 * {
31 * KJob *job = someoperation(some parameters);
32 * connect(job, &KJob::result, this, &SomeClass::handleResult);
33 * job->start();
34 * }
35 * \endcode
36 * (other connects, specific to the job)
37 *
38 * And handleResult is usually at least:
39 *
40 * \code
41 * void SomeClass::handleResult(KJob *job)
42 * {
43 * if (job->error()) {
44 * doSomething();
45 * }
46 * }
47 * \endcode
48 *
49 * With the synchronous interface the code looks like
50 *
51 * \code
52 * void SomeClass::methodWithSynchronousJobCall()
53 * {
54 * KJob *job = someoperation( some parameters );
55 * if (!job->exec()) {
56 * // An error occurred
57 * } else {
58 * // Do something
59 * }
60 * }
61 * \endcode
62 *
63 * Subclasses must implement start(), which should trigger the execution of
64 * the job (although the work should be done asynchronously). errorString()
65 * should also be reimplemented by any subclasses that introduce new error
66 * codes.
67 *
68 * @note KJob and its subclasses are meant to be used in a fire-and-forget way.
69 * Jobs will delete themselves when they finish using deleteLater() (although
70 * this behaviour can be changed), so a job instance will disappear after the
71 * next event loop run.
72 */
73class KCOREADDONS_EXPORT KJob : public QObject
74{
76 Q_PROPERTY(int error READ error NOTIFY result)
77 Q_PROPERTY(QString errorText READ errorText NOTIFY result)
78 Q_PROPERTY(QString errorString READ errorString NOTIFY result)
79 Q_PROPERTY(ulong percent READ percent NOTIFY percentChanged) // KF6 TODO: make "int", is enough
80 Q_PROPERTY(Capabilities capabilities READ capabilities CONSTANT)
81
82public:
83 /**
84 * Describes the unit used in the methods that handle reporting the job progress info.
85 * @see totalAmount
86 */
87 enum Unit {
88 Bytes = 0, ///< Directory and file sizes in bytes
89 Files, ///< The number of files handled by the job
90 Directories, ///< The number of directories handled by the job
91 Items, ///< The number of items (e.g. both directories and files) handled by the job
92 ///< @since 5.72
93
94 UnitsCount, ///< @internal since 5.87, used internally only, do not use.
95 };
96 Q_ENUM(Unit)
97
98 /**
99 * @see Capabilities
100 */
102 NoCapabilities = 0x0000, ///< None of the capabilities exist
103 Killable = 0x0001, ///< The job can be killed
104 Suspendable = 0x0002, ///< The job can be suspended
105 };
106 Q_ENUM(Capability)
107
108 /**
109 * Stores a combination of #Capability values.
110 */
111 Q_DECLARE_FLAGS(Capabilities, Capability)
113
114 /**
115 * Creates a new KJob object.
116 *
117 * @param parent the parent QObject
118 */
119 explicit KJob(QObject *parent = nullptr);
120
121 /**
122 * Destroys a KJob object.
123 */
124 ~KJob() override;
125
126 /**
127 * Attach a UI delegate to this job.
128 *
129 * If the job had another UI delegate, it's automatically deleted. Once
130 * attached to the job, the UI delegate will be deleted with the job.
131 *
132 * @param delegate the new UI delegate to use
133 * @see KJobUiDelegate
134 */
135 void setUiDelegate(KJobUiDelegate *delegate);
136
137 /**
138 * Retrieves the delegate attached to this job.
139 *
140 * @return the delegate attached to this job, or @c nullptr if there's no such delegate
141 */
142 KJobUiDelegate *uiDelegate() const;
143
144 /**
145 * Returns the capabilities of this job.
146 *
147 * @return the capabilities that this job supports
148 * @see setCapabilities()
149 */
150 Capabilities capabilities() const;
151
152 /**
153 * Returns if the job was suspended with the suspend() call.
154 *
155 * @return if the job was suspended
156 * @see suspend() resume()
157 */
158 bool isSuspended() const;
159
160 /**
161 * Starts the job asynchronously.
162 *
163 * When the job is finished, result() is emitted.
164 *
165 * Warning: Never implement any synchronous workload in this method. This method
166 * should just trigger the job startup, not do any work itself. It is expected to
167 * be non-blocking.
168 *
169 * This is the method all subclasses need to implement.
170 * It should setup and trigger the workload of the job. It should not do any
171 * work itself. This includes all signals and terminating the job, e.g. by
172 * emitResult(). The workload, which could be another method of the
173 * subclass, is to be triggered using the event loop, e.g. by code like:
174 * \code
175 * void ExampleJob::start()
176 * {
177 * QTimer::singleShot(0, this, &ExampleJob::doWork);
178 * }
179 * \endcode
180 */
181 // TODO KF7 make it non-virtual and expose a doStart protected instead
182 Q_SCRIPTABLE virtual void start() = 0;
183
184 enum KillVerbosity {
185 Quietly,
186 EmitResult,
187 };
188 Q_ENUM(KillVerbosity)
189
190public Q_SLOTS:
191 /**
192 * Aborts this job.
193 *
194 * This kills and deletes the job.
195 *
196 * @param verbosity if equals to EmitResult, Job will emit signal result
197 * and ask uiserver to close the progress window.
198 * @p verbosity is set to EmitResult for subjobs. Whether applications
199 * should call with Quietly or EmitResult depends on whether they rely
200 * on result being emitted or not. Please notice that if @p verbosity is
201 * set to Quietly, signal result will NOT be emitted.
202 * @return true if the operation is supported and succeeded, false otherwise
203 */
204 bool kill(KJob::KillVerbosity verbosity = KJob::Quietly);
205
206 /**
207 * Suspends this job.
208 * The job should be kept in a state in which it is possible to resume it.
209 *
210 * @return true if the operation is supported and succeeded, false otherwise
211 */
212 bool suspend();
213
214 /**
215 * Resumes this job.
216 *
217 * @return true if the operation is supported and succeeded, false otherwise
218 */
219 bool resume();
220
221protected:
222 /**
223 * Aborts this job quietly.
224 *
225 * This simply kills the job, no error reporting or job deletion should be involved.
226 *
227 * @return true if the operation is supported and succeeded, false otherwise
228 */
229 virtual bool doKill();
230
231 /**
232 * Suspends this job.
233 *
234 * @return true if the operation is supported and succeeded, false otherwise
235 */
236 virtual bool doSuspend();
237
238 /**
239 * Resumes this job.
240 *
241 * @return true if the operation is supported and succeeded, false otherwise
242 */
243 virtual bool doResume();
244
245 /**
246 * Sets the capabilities for this job.
247 *
248 * @param capabilities are the capabilities supported by this job
249 * @see capabilities()
250 */
251 void setCapabilities(Capabilities capabilities);
252
253public:
254 /**
255 * Executes the job synchronously.
256 *
257 * This will start a nested QEventLoop internally. Nested event loop can be dangerous and
258 * can have unintended side effects, you should avoid calling exec() whenever you can and use the
259 * asynchronous interface of KJob instead.
260 *
261 * Should you indeed call this method, you need to make sure that all callers are reentrant,
262 * so that events delivered by the inner event loop don't cause non-reentrant functions to be
263 * called, which usually wreaks havoc.
264 *
265 * Note that the event loop started by this method does not process user input events, which means
266 * your user interface will effectively be blocked. Other events like paint or network events are
267 * still being processed. The advantage of not processing user input events is that the chance of
268 * accidental reentrance is greatly reduced. Still you should avoid calling this function.
269 *
270 * @return true if the job has been executed without error, false otherwise
271 */
272 bool exec();
273
274 enum {
275 /*** Indicates there is no error */
276 NoError = 0,
277 /*** Indicates the job was killed */
278 KilledJobError = 1,
279 /*** Subclasses should define error codes starting at this value */
280 UserDefinedError = 100,
281 };
282
283 /**
284 * Returns the error code, if there has been an error.
285 *
286 * Only call this method from the slot connected to result().
287 *
288 * @return the error code for this job, 0 if no error.
289 */
290 int error() const;
291
292 /**
293 * Returns the error text if there has been an error.
294 *
295 * Only call if error is not 0.
296 *
297 * This is usually some extra data associated with the error,
298 * such as a URL. Use errorString() to get a human-readable,
299 * translated message.
300 *
301 * @return a string to help understand the error
302 */
303 QString errorText() const;
304
305 /**
306 * A human-readable error message.
307 *
308 * This provides a translated, human-readable description of the
309 * error. Only call if error is not 0.
310 *
311 * Subclasses should implement this to create a translated
312 * error message from the error code and error text.
313 * For example:
314 * \code
315 * if (error() == ReadFailed) {
316 * i18n("Could not read \"%1\"", errorText());
317 * }
318 * \endcode
319 *
320 * @return a translated error message, providing error() is 0
321 */
322 virtual QString errorString() const;
323
324 /**
325 * Returns the processed amount of a given unit for this job.
326 *
327 * @param unit the unit of the requested amount
328 * @return the processed size
329 */
330 Q_SCRIPTABLE qulonglong processedAmount(Unit unit) const;
331
332 /**
333 * Returns the total amount of a given unit for this job.
334 *
335 * @param unit the unit of the requested amount
336 * @return the total size
337 */
338 Q_SCRIPTABLE qulonglong totalAmount(Unit unit) const;
339
340 /**
341 * Returns the overall progress of this job.
342 *
343 * @return the overall progress of this job
344 */
345 unsigned long percent() const;
346
347 /**
348 * Sets the auto-delete property of the job. If @p autodelete is
349 * set to @c false the job will not delete itself once it is finished.
350 *
351 * The default for any KJob is to automatically delete itself, which
352 * implies that the job was created on the heap (using <tt>new</tt>).
353 * If the job is created on the stack (which isn't the typical use-case
354 * for a job) then you must set auto-delete to @c false, otherwise you
355 * could get a crash when the job finishes and tries to delete itself.
356 *
357 * @note If you set auto-delete to @c false then you need to kill the
358 * job manually, ideally by calling kill().
359 *
360 * @param autodelete set to @c false to disable automatic deletion
361 * of the job.
362 */
363 void setAutoDelete(bool autodelete);
364
365 /**
366 * Returns whether this job automatically deletes itself once
367 * the job is finished.
368 *
369 * @return whether the job is deleted automatically after
370 * finishing.
371 */
372 bool isAutoDelete() const;
373
374 /**
375 * This method can be used to indicate to classes listening to signals from a job
376 * that they should ideally show a progress bar, but not a finished notification.
377 *
378 * For example when opening a remote URL, a job will emit the progress of the
379 * download, which can be used to show a progress dialog or a Plasma notification,
380 * then when the job is done it'll emit e.g. the finished signal. Showing the user the
381 * progress dialog is useful, however the dialog/notification about the download being
382 * finished isn't of much interest, because the user can see the application that invoked
383 * the job opening the actual file that was downloaded.
384 *
385 * @since 5.92
386 */
387 void setFinishedNotificationHidden(bool hide = true);
388
389 /**
390 * Whether to <em>not</em> show a finished notification when a job's finished
391 * signal is emitted.
392 *
393 * @see setFinishedNotificationHidden()
394 *
395 * @since 5.92
396 */
397 bool isFinishedNotificationHidden() const;
398
399 /**
400 * Returns @c true if this job was started with exec(), which starts a nested event-loop
401 * (with QEventLoop::ExcludeUserInputEvents, which blocks the GUI), otherwise returns
402 * @c false which indicates this job was started asynchronously with start().
403 *
404 * This is useful for code that for example shows a dialog to ask the user a question,
405 * and that would be no-op since the user cannot interact with the dialog.
406 *
407 * @since 5.95
408 */
409 bool isStartedWithExec() const;
410
411 /**
412 * The number of milliseconds the job has been running for.
413 * Starting from the last `start()` call.
414 *
415 * Sub-classes must call startElapsedTimer() from their `start()` implementation, to get `elapsedTime()` measurement.
416 * Otherwise this method will always return 0.
417 *
418 * The time when paused is excluded.
419 *
420 * @since 6.8
421 */
422 qint64 elapsedTime() const;
423
424Q_SIGNALS:
425 /**
426 * Emitted when the job is finished, in any case. It is used to notify
427 * observers that the job is terminated and that progress can be hidden.
428 *
429 * Since 5.75 this signal is guaranteed to be emitted exactly once.
430 *
431 * This is a private signal, it can't be emitted directly by subclasses of
432 * KJob, use emitResult() instead.
433 *
434 * In general, to be notified of a job's completion, client code should connect to result()
435 * rather than finished(), so that kill(Quietly) is indeed quiet.
436 * However if you store a list of jobs and they might get killed silently,
437 * then you must connect to this instead of result(), to avoid dangling pointers in your list.
438 *
439 * @param job the job that emitted this signal
440 * @internal
441 *
442 * @see result
443 */
444 void finished(KJob *job
445#if !defined(K_DOXYGEN)
446 ,
447 QPrivateSignal
448#endif
449 );
450
451 /**
452 * Emitted when the job is suspended.
453 *
454 * This is a private signal, it can't be emitted directly by subclasses of
455 * KJob.
456 *
457 * @param job the job that emitted this signal
458 */
459 void suspended(KJob *job
460#if !defined(K_DOXYGEN)
461 ,
462 QPrivateSignal
463#endif
464 );
465
466 /**
467 * Emitted when the job is resumed.
468 *
469 * This is a private signal, it can't be emitted directly by subclasses of
470 * KJob.
471 *
472 * @param job the job that emitted this signal
473 */
474 void resumed(KJob *job
475#if !defined(K_DOXYGEN)
476 ,
477 QPrivateSignal
478#endif
479 );
480
481 /**
482 * Emitted when the job is finished (except when killed with KJob::Quietly).
483 *
484 * Since 5.75 this signal is guaranteed to be emitted at most once.
485 *
486 * Use error to know if the job was finished with error.
487 *
488 * This is a private signal, it can't be emitted directly by subclasses of
489 * KJob, use emitResult() instead.
490 *
491 * Please connect to this signal instead of finished.
492 *
493 * @param job the job that emitted this signal
494 *
495 * @see kill
496 */
497 void result(KJob *job
498#if !defined(K_DOXYGEN)
499 ,
500 QPrivateSignal
501#endif
502 );
503
504 /**
505 * Emitted to display general description of this job. A description has
506 * a title and two optional fields which can be used to complete the
507 * description.
508 *
509 * Examples of titles are "Copying", "Creating resource", etc.
510 * The fields of the description can be "Source" with an URL, and,
511 * "Destination" with an URL for a "Copying" description.
512 * @param job the job that emitted this signal
513 * @param title the general description of the job
514 * @param field1 first field (localized name and value)
515 * @param field2 second field (localized name and value)
516 */
517 void description(KJob *job,
518 const QString &title,
519 const QPair<QString, QString> &field1 = QPair<QString, QString>(),
520 const QPair<QString, QString> &field2 = QPair<QString, QString>());
521 /**
522 * Emitted to display state information about this job.
523 * Examples of message are "Resolving host", "Connecting to host...", etc.
524 *
525 * @param job the job that emitted this signal
526 * @param message the info message
527 */
528 void infoMessage(KJob *job, const QString &message);
529
530 /**
531 * Emitted to display a warning about this job.
532 *
533 * @param job the job that emitted this signal
534 * @param message the warning message
535 */
536 void warning(KJob *job, const QString &message);
537
539 // These signals must be connected from KIO::KCoreDirLister (among others),
540 // therefore they must be public.
541 /**
542 * Emitted when we know the amount the job will have to process. The unit of this
543 * amount is sent too. It can be emitted several times if the job manages several
544 * different units.
545 *
546 * @note This is a private signal, it shouldn't be emitted directly by subclasses of
547 * KJob, use setTotalAmount() instead.
548 *
549 * @param job the job that emitted this signal
550 * @param unit the unit of the total amount
551 * @param amount the total amount
552 *
553 * @since 5.80
554 */
556 KJob::Unit unit,
557 qulonglong amount
558#if !defined(K_DOXYGEN)
559 ,
560 QPrivateSignal
561#endif
562 );
563
564 /**
565 * Regularly emitted to show the progress of this job by giving the current amount.
566 * The unit of this amount is sent too. It can be emitted several times if the job
567 * manages several different units.
568 *
569 * @note This is a private signal, it shouldn't be emitted directly by subclasses of
570 * KJob, use setProcessedAmount() instead.
571 *
572 * @param job the job that emitted this signal
573 * @param unit the unit of the processed amount
574 * @param amount the processed amount
575 *
576 * @since 5.80
577 */
579 KJob::Unit unit,
580 qulonglong amount
581#if !defined(K_DOXYGEN)
582 ,
583 QPrivateSignal
584#endif
585 );
586
587 /**
588 * Emitted when we know the size of this job (data size in bytes for transfers,
589 * number of entries for listings, etc).
590 *
591 * @note This is a private signal, it shouldn't be emitted directly by subclasses of
592 * KJob, use setTotalAmount() instead.
593 *
594 * @param job the job that emitted this signal
595 * @param size the total size
596 */
597 void totalSize(KJob *job, qulonglong size);
598
599 /**
600 * Regularly emitted to show the progress of this job
601 * (current data size in bytes for transfers, entries listed, etc.).
602 *
603 * @note This is a private signal, it shouldn't be emitted directly by subclasses of
604 * KJob, use setProcessedAmount() instead.
605 *
606 * @param job the job that emitted this signal
607 * @param size the processed size
608 */
609 void processedSize(KJob *job, qulonglong size);
610
611 /**
612 * Progress signal showing the overall progress of the job. This is
613 * valid for any kind of job, and allows using a progress bar very
614 * easily. (see KProgressBar).
615 *
616 * Note that this signal is not emitted for finished jobs.
617 *
618 * @note This is a private signal, it shouldn't be emitted directly
619 * by subclasses of KJob, use emitPercent(), setPercent() setTotalAmount()
620 * or setProcessedAmount() instead.
621 *
622 * @param job the job that emitted this signal
623 * @param percent the percentage
624 *
625 * @since 5.80
626 */
628 unsigned long percent
629#if !defined(K_DOXYGEN)
630 ,
631 QPrivateSignal
632#endif
633 );
634
635 /**
636 * Emitted to display information about the speed of this job.
637 *
638 * @note This is a private signal, it shouldn't be emitted directly by subclasses of
639 * KJob, use emitSpeed() instead.
640 *
641 * @param job the job that emitted this signal
642 * @param speed the speed in bytes/s
643 */
644 void speed(KJob *job, unsigned long speed);
645
646protected:
647 /**
648 * Returns if the job has been finished and has emitted the finished() signal.
649 *
650 * @return if the job has been finished
651 * @see finished()
652 * @since 5.75
653 */
654 // KF6 TODO: make public. Useful at least for unittests that run multiple jobs in parallel.
655 bool isFinished() const;
656
657 /**
658 * Sets the error code.
659 *
660 * It should be called when an error
661 * is encountered in the job, just before calling emitResult().
662 *
663 * You should define an (anonymous) enum of error codes,
664 * with values starting at KJob::UserDefinedError, and use
665 * those. For example,
666 * @code
667 * enum {
668 * InvalidFoo = UserDefinedError,
669 * BarNotFound,
670 * };
671 * @endcode
672 *
673 * @param errorCode the error code
674 * @see emitResult()
675 */
676 void setError(int errorCode);
677
678 /**
679 * Sets the error text.
680 *
681 * It should be called when an error
682 * is encountered in the job, just before calling emitResult().
683 *
684 * Provides extra information about the error that cannot be
685 * determined directly from the error code. For example, a
686 * URL or filename. This string is not normally translatable.
687 *
688 * @param errorText the error text
689 * @see emitResult(), errorString(), setError()
690 */
691 void setErrorText(const QString &errorText);
692
693 /**
694 * Sets the processed size. The processedAmount() and percent() signals
695 * are emitted if the values changed. The percent() signal is emitted
696 * only for the progress unit.
697 *
698 * @param unit the unit of the new processed amount
699 * @param amount the new processed amount
700 */
701 void setProcessedAmount(Unit unit, qulonglong amount);
702
703 /**
704 * Sets the total size. The totalSize() and percent() signals
705 * are emitted if the values changed. The percent() signal is emitted
706 * only for the progress unit.
707 *
708 * @param unit the unit of the new total amount
709 * @param amount the new total amount
710 */
711 void setTotalAmount(Unit unit, qulonglong amount);
712
713 /**
714 * Sets the unit that will be used internally to calculate
715 * the progress percentage.
716 * The default progress unit is Bytes.
717 * @since 5.76
718 */
719 void setProgressUnit(Unit unit);
720
721 /**
722 * Sets the overall progress of the job. The percent() signal
723 * is emitted if the value changed.
724 *
725 * The job takes care of this if you call setProcessedAmount
726 * in Bytes (or the unit set by setProgressUnit).
727 * This method allows you to set your own progress, as an alternative.
728 *
729 * @param percentage the new overall progress
730 */
731 void setPercent(unsigned long percentage);
732
733 /**
734 * Utility function to emit the result signal, and end this job.
735 * It first notifies the observers to hide the progress for this job using
736 * the finished() signal.
737 *
738 * @note Deletes this job using deleteLater().
739 *
740 * @see result()
741 * @see finished()
742 */
743 void emitResult();
744
745 /**
746 * Utility function for inherited jobs.
747 * Emits the percent signal if bigger than previous value,
748 * after calculating it from the parameters.
749 *
750 * @param processedAmount the processed amount
751 * @param totalAmount the total amount
752 * @see percent()
753 */
754 void emitPercent(qulonglong processedAmount, qulonglong totalAmount);
755
756 /**
757 * Utility function for inherited jobs.
758 * Emits the speed signal and starts the timer for removing that info
759 *
760 * @param speed the speed in bytes/s
761 */
762 void emitSpeed(unsigned long speed);
763
764 /**
765 * Starts the internal elapsed time measurement timer.
766 *
767 * Sub-classes must call startElapsedTimer() from their `start()` implementation, to get `elapsedTime()` measurement.
768 * Otherwise `elapsedTimer()` method will always return 0.
769 *
770 * @since 6.8
771 */
772 void startElapsedTimer();
773
774protected:
775 std::unique_ptr<KJobPrivate> const d_ptr;
776
777 KCOREADDONS_NO_EXPORT KJob(KJobPrivate &dd, QObject *parent);
778
779private:
780 KCOREADDONS_NO_EXPORT void finishJob(bool emitResult);
781
782 Q_DECLARE_PRIVATE(KJob)
783};
784
785Q_DECLARE_OPERATORS_FOR_FLAGS(KJob::Capabilities)
786
787#endif
The base class for all KJob UI delegate.
void resumed(KJob *job)
Emitted when the job is resumed.
void setErrorText(const QString &errorText)
Sets the error text.
Definition kjob.cpp:285
Unit
Describes the unit used in the methods that handle reporting the job progress info.
Definition kjob.h:87
@ UnitsCount
Definition kjob.h:94
@ Files
The number of files handled by the job.
Definition kjob.h:89
@ Bytes
Directory and file sizes in bytes.
Definition kjob.h:88
@ Directories
The number of directories handled by the job.
Definition kjob.h:90
@ Items
The number of items (e.g.
Definition kjob.h:91
void description(KJob *job, const QString &title, const QPair< QString, QString > &field1=QPair< QString, QString >(), const QPair< QString, QString > &field2=QPair< QString, QString >())
Emitted to display general description of this job.
void setTotalAmount(Unit unit, qulonglong amount)
Sets the total size.
Definition kjob.cpp:315
void emitResult()
Utility function to emit the result signal, and end this job.
Definition kjob.cpp:354
Q_SCRIPTABLE qulonglong totalAmount(Unit unit) const
Returns the total amount of a given unit for this job.
Definition kjob.cpp:259
bool isFinished() const
Returns if the job has been finished and has emitted the finished() signal.
Definition kjob.cpp:274
void startElapsedTimer()
Starts the internal elapsed time measurement timer.
Definition kjob.cpp:76
void processedSize(KJob *job, qulonglong size)
Regularly emitted to show the progress of this job (current data size in bytes for transfers,...
void result(KJob *job)
Emitted when the job is finished (except when killed with KJob::Quietly).
bool isSuspended() const
Returns if the job was suspended with the suspend() call.
Definition kjob.cpp:96
void totalAmountChanged(KJob *job, KJob::Unit unit, qulonglong amount)
Emitted when we know the amount the job will have to process.
void finished(KJob *job)
Emitted when the job is finished, in any case.
void warning(KJob *job, const QString &message)
Emitted to display a warning about this job.
Q_SCRIPTABLE qulonglong processedAmount(Unit unit) const
Returns the processed amount of a given unit for this job.
Definition kjob.cpp:249
void setPercent(unsigned long percentage)
Sets the overall progress of the job.
Definition kjob.cpp:345
void setError(int errorCode)
Sets the error code.
Definition kjob.cpp:279
KJobUiDelegate * uiDelegate() const
Retrieves the delegate attached to this job.
Definition kjob.cpp:86
void infoMessage(KJob *job, const QString &message)
Emitted to display state information about this job.
void totalSize(KJob *job, qulonglong size)
Emitted when we know the size of this job (data size in bytes for transfers, number of entries for li...
void setProgressUnit(Unit unit)
Sets the unit that will be used internally to calculate the progress percentage.
Definition kjob.cpp:339
void processedAmountChanged(KJob *job, KJob::Unit unit, qulonglong amount)
Regularly emitted to show the progress of this job by giving the current amount.
void suspended(KJob *job)
Emitted when the job is suspended.
void emitPercent(qulonglong processedAmount, qulonglong totalAmount)
Utility function for inherited jobs.
Definition kjob.cpp:361
virtual Q_SCRIPTABLE void start()=0
Starts the job asynchronously.
Capability
Definition kjob.h:101
@ Suspendable
The job can be suspended.
Definition kjob.h:104
@ Killable
The job can be killed.
Definition kjob.h:103
@ NoCapabilities
None of the capabilities exist.
Definition kjob.h:102
KJob(QObject *parent=nullptr)
Creates a new KJob object.
Definition kjob.cpp:29
void setProcessedAmount(Unit unit, qulonglong amount)
Sets the processed size.
Definition kjob.cpp:291
void setUiDelegate(KJobUiDelegate *delegate)
Attach a UI delegate to this job.
Definition kjob.cpp:54
void emitSpeed(unsigned long speed)
Utility function for inherited jobs.
Definition kjob.cpp:368
void percentChanged(KJob *job, unsigned long percent)
Progress signal showing the overall progress of the job.
void speed(KJob *job, unsigned long speed)
Emitted to display information about the speed of this job.
QFlags< Capability > Capabilities
Stores a combination of Capability values.
Definition kjob.h:111
void suspend()
void error(QWidget *parent, const QString &text, const QString &title, const KGuiItem &buttonOk, Options options=Notify)
QObject(QObject *parent)
Q_ENUM(...)
Q_FLAG(...)
Q_OBJECTQ_OBJECT
Q_PROPERTY(...)
Q_SIGNALSQ_SIGNALS
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Jan 24 2025 11:55:52 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.