File indexing completed on 2024-04-21 12:30:40

0001 /*
0002     This is the new synchronizer of Smb4K.
0003 
0004     SPDX-FileCopyrightText: 2011-2023 Alexander Reinholdt <alexander.reinholdt@kdemail.net>
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #ifndef SMB4KSYNCHRONIZER_H
0009 #define SMB4KSYNCHRONIZER_H
0010 
0011 // application specific includes
0012 #include "smb4kglobal.h"
0013 
0014 // Qt includes
0015 #include <QScopedPointer>
0016 #include <QString>
0017 
0018 // KDE includes
0019 #include <KCompositeJob>
0020 
0021 // forward declarations
0022 class Smb4KSynchronizerPrivate;
0023 
0024 class Q_DECL_EXPORT Smb4KSynchronizer : public KCompositeJob
0025 {
0026     Q_OBJECT
0027 
0028     friend class Smb4KSynchronizerPrivate;
0029 
0030 public:
0031     /**
0032      * The constructor
0033      */
0034     explicit Smb4KSynchronizer(QObject *parent = nullptr);
0035 
0036     /**
0037      * The destructor
0038      */
0039     ~Smb4KSynchronizer();
0040 
0041     /**
0042      * This function returns a static pointer to this class.
0043      *
0044      * @returns a static pointer to the Smb4KSynchronizer class.
0045      */
0046     static Smb4KSynchronizer *self();
0047 
0048     /**
0049      * Sets the URL for the source and destination and start the
0050      * synchronization.
0051      *
0052      * @param sourceUrl         The source URL
0053      *
0054      * @param destinationUrl    The destination URL
0055      */
0056     void synchronize(const QUrl &sourceUrl, const QUrl &destinationUrl);
0057 
0058     /**
0059      * This function tells you whether the synchronizer is running
0060      * or not.
0061      *
0062      * @returns TRUE if the synchronizer is running and FALSE otherwise
0063      */
0064     bool isRunning();
0065 
0066     /**
0067      * With this function you can test whether a synchronization job
0068      * for a certain @param sourceUrl is already running.
0069      *
0070      * @returns TRUE if a synchronization process is already running
0071      */
0072     bool isRunning(const QUrl &sourceUrl);
0073 
0074     /**
0075      * This function either aborts the synchronization for a certain
0076      * URL or aborts all running processes.
0077      *
0078      * @param share         The Smb4KShare object
0079      */
0080     void abort(const QUrl &sourceUrl = QUrl());
0081 
0082     /**
0083      * This function starts the composite job
0084      */
0085     void start() override;
0086 
0087 Q_SIGNALS:
0088     /**
0089      * This signal is emitted when a job is started. The emitted path
0090      * is the one of the destination.
0091      *
0092      * @param dest        The destination's URL
0093      */
0094     void aboutToStart(const QString &dest);
0095 
0096     /**
0097      * This signal is emitted when a job has finished. The emitted
0098      * URL is the one of the destination.
0099      *
0100      * @param dest        The destination's URL
0101      */
0102     void finished(const QString &dest);
0103 
0104 protected Q_SLOTS:
0105     /**
0106      * Invoked by start() function
0107      */
0108     void slotStartJobs();
0109 
0110     /**
0111      * Invoked when a job finished
0112      */
0113     void slotJobFinished(KJob *job);
0114 
0115     /**
0116      * Invoked when the application goes down
0117      */
0118     void slotAboutToQuit();
0119 
0120 private:
0121     /**
0122      * Pointer to Smb4KSearchPrivate class
0123      */
0124     const QScopedPointer<Smb4KSynchronizerPrivate> d;
0125 };
0126 
0127 #endif