File indexing completed on 2024-05-12 03:54:56

0001 /*
0002     This file is part of the KDE project
0003 
0004     SPDX-FileCopyrightText: 2007 Kevin Ottens <ervin@kde.org>
0005 
0006     SPDX-License-Identifier: LGPL-2.0-or-later
0007 */
0008 
0009 #ifndef KJOBTRACKERINTERFACE_H
0010 #define KJOBTRACKERINTERFACE_H
0011 
0012 #include <kcoreaddons_export.h>
0013 #include <kjob.h>
0014 
0015 #include <QObject>
0016 #include <QPair>
0017 
0018 #include <memory>
0019 
0020 /**
0021  * @class KJobTrackerInterface kjobtrackerinterface.h KJobTrackerInterface
0022  *
0023  * The interface to implement to track the progresses of a job.
0024  */
0025 class KCOREADDONS_EXPORT KJobTrackerInterface : public QObject
0026 {
0027     Q_OBJECT
0028 
0029 public:
0030     /**
0031      * Creates a new KJobTrackerInterface
0032      *
0033      * @param parent the parent object
0034      */
0035     explicit KJobTrackerInterface(QObject *parent = nullptr);
0036 
0037     /**
0038      * Destroys a KJobTrackerInterface
0039      */
0040     ~KJobTrackerInterface() override;
0041 
0042 public Q_SLOTS:
0043     /**
0044      * Register a new job in this tracker.
0045      * The default implementation connects the following KJob signals
0046      * to the respective protected slots of this class:
0047      *  - finished() (also connected to the unregisterJob() slot)
0048      *  - suspended()
0049      *  - resumed()
0050      *  - description()
0051      *  - infoMessage()
0052      *  - totalAmount()
0053      *  - processedAmount()
0054      *  - percent()
0055      *  - speed()
0056      *
0057      * If you re-implement this method, you may want to call the default
0058      * implementation or add at least:
0059      *
0060      * @code
0061      * connect(job, &KJob::finished, this, &MyJobTracker::unregisterJob);
0062      * @endcode
0063      *
0064      * so that you won't have to manually call unregisterJob().
0065      *
0066      * @param job the job to register
0067      * @see unregisterJob()
0068      */
0069     virtual void registerJob(KJob *job);
0070 
0071     /**
0072      * Unregister a job from this tracker.
0073      * @note You need to manually call this method only if you re-implemented
0074      * registerJob() without connecting KJob::finished to this slot.
0075      *
0076      * @param job the job to unregister
0077      * @see registerJob()
0078      */
0079     virtual void unregisterJob(KJob *job);
0080 
0081 protected Q_SLOTS:
0082     /**
0083      * Called when a job is finished, in any case. It is used to notify
0084      * that the job is terminated and that progress UI (if any) can be hidden.
0085      *
0086      * @param job the job that emitted this signal
0087      */
0088     virtual void finished(KJob *job);
0089 
0090     /**
0091      * Called when a job is suspended.
0092      *
0093      * @param job the job that emitted this signal
0094      */
0095     virtual void suspended(KJob *job);
0096 
0097     /**
0098      * Called when a job is resumed.
0099      *
0100      * @param job the job that emitted this signal
0101      */
0102     virtual void resumed(KJob *job);
0103 
0104     /**
0105      * Called to display general description of a job. A description has
0106      * a title and two optional fields which can be used to complete the
0107      * description.
0108      *
0109      * Examples of titles are "Copying", "Creating resource", etc.
0110      * The fields of the description can be "Source" with an URL, and,
0111      * "Destination" with an URL for a "Copying" description.
0112      * @param job the job that emitted this signal
0113      * @param title the general description of the job
0114      * @param field1 first field (localized name and value)
0115      * @param field2 second field (localized name and value)
0116      */
0117     virtual void description(KJob *job, const QString &title, const QPair<QString, QString> &field1, const QPair<QString, QString> &field2);
0118 
0119     /**
0120      * Called to display state information about a job.
0121      * Examples of message are "Resolving host", "Connecting to host...", etc.
0122      *
0123      * @param job the job that emitted this signal
0124      * @param message the info message
0125      */
0126     virtual void infoMessage(KJob *job, const QString &message);
0127 
0128     /**
0129      * Emitted to display a warning about a job.
0130      *
0131      * @param job the job that emitted this signal
0132      * @param message the warning message
0133      */
0134     virtual void warning(KJob *job, const QString &message);
0135 
0136     /**
0137      * Called when we know the amount a job will have to process. The unit of this
0138      * amount is provided too. It can be called several times for a given job if the job
0139      * manages several different units.
0140      *
0141      * @param job the job that emitted this signal
0142      * @param unit the unit of the total amount
0143      * @param amount the total amount
0144      */
0145     virtual void totalAmount(KJob *job, KJob::Unit unit, qulonglong amount);
0146 
0147     /**
0148      * Regularly called to show the progress of a job by giving the current amount.
0149      * The unit of this amount is provided too. It can be called several times for a given
0150      * job if the job manages several different units.
0151      *
0152      * @param job the job that emitted this signal
0153      * @param unit the unit of the processed amount
0154      * @param amount the processed amount
0155      */
0156     virtual void processedAmount(KJob *job, KJob::Unit unit, qulonglong amount);
0157 
0158     /**
0159      * Called to show the overall progress of the job.
0160      * Note that this is not called for finished jobs.
0161      *
0162      * @param job the job that emitted this signal
0163      * @param percent the percentage
0164      */
0165     virtual void percent(KJob *job, unsigned long percent);
0166 
0167     /**
0168      * Called to show the speed of the job.
0169      *
0170      * @param job the job that emitted this signal
0171      * @param value the current speed of the job
0172      */
0173     virtual void speed(KJob *job, unsigned long value);
0174 
0175 private:
0176     std::unique_ptr<class KJobTrackerInterfacePrivate> const d;
0177 };
0178 
0179 #endif