Warning, file /utilities/krusader/app/Synchronizer/synchronizer.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002     SPDX-FileCopyrightText: 2003 Csaba Karai <krusader@users.sourceforge.net>
0003     SPDX-FileCopyrightText: 2004-2022 Krusader Krew <https://krusader.org>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #ifndef SYNCHRONIZER_H
0009 #define SYNCHRONIZER_H
0010 
0011 // QtCore
0012 #include <QList>
0013 #include <QMap>
0014 #include <QObject>
0015 // QtGui
0016 #include <QColor>
0017 // QtWidgets
0018 #include <QDialog>
0019 
0020 #include <KIO/Job>
0021 
0022 #include "synchronizerfileitem.h"
0023 #include "synchronizertask.h"
0024 
0025 class KrQuery;
0026 class FileItem;
0027 
0028 class Synchronizer : public QObject
0029 {
0030     Q_OBJECT
0031 
0032 private:
0033     int displayUpdateCount; // the display is refreshed after every x-th change
0034 
0035 public:
0036     Synchronizer();
0037     ~Synchronizer() override;
0038     int compare(QString leftURL,
0039                 QString rightURL,
0040                 KrQuery *query,
0041                 bool subDirs,
0042                 bool symLinks,
0043                 bool igDate,
0044                 bool asymm,
0045                 bool cmpByCnt,
0046                 bool igCase,
0047                 bool autoSc,
0048                 QStringList &selFiles,
0049                 int equThres,
0050                 int timeOffs,
0051                 int parThreads,
0052                 bool hiddenFiles);
0053     void stop()
0054     {
0055         stopped = true;
0056     }
0057     void setMarkFlags(bool left, bool equal, bool differs, bool right, bool dup, bool sing, bool del);
0058     int refresh(bool nostatus = false);
0059     bool totalSizes(int *, KIO::filesize_t *, int *, KIO::filesize_t *, int *, KIO::filesize_t *);
0060     void synchronize(QWidget *, bool leftCopyEnabled, bool rightCopyEnabled, bool deleteEnabled, bool overWrite, int parThreads);
0061     void synchronizeWithKGet();
0062     void setScrolling(bool scroll);
0063     void pause();
0064     void resume();
0065     void swapSides();
0066     void reset();
0067     void clearLists();
0068 
0069     void exclude(SynchronizerFileItem *);
0070     void restore(SynchronizerFileItem *);
0071     void reverseDirection(SynchronizerFileItem *);
0072     void copyToLeft(SynchronizerFileItem *);
0073     void copyToRight(SynchronizerFileItem *);
0074     void deleteLeft(SynchronizerFileItem *);
0075 
0076     QString leftBaseDirectory();
0077     QString rightBaseDirectory();
0078     static QString getTaskTypeName(TaskType taskType);
0079     static QUrl fsUrl(const QString &strUrl);
0080 
0081     SynchronizerFileItem *getItemAt(unsigned ndx);
0082 
0083     void setParentWidget(QWidget *widget)
0084     {
0085         parentWidget = widget;
0086     }
0087     void compareContentResult(SynchronizerFileItem *item, bool result);
0088 
0089 signals:
0090     void comparedFileData(SynchronizerFileItem *);
0091     void markChanged(SynchronizerFileItem *, bool);
0092     void synchronizationFinished();
0093     void processedSizes(int, KIO::filesize_t, int, KIO::filesize_t, int, KIO::filesize_t);
0094     void pauseAccepted();
0095     void statusInfo(QString);
0096 
0097 public slots:
0098     void slotTaskFinished(KJob *);
0099     void slotProcessedSize(KJob *, qulonglong);
0100 
0101 private:
0102     bool isDir(const FileItem *file);
0103     QString readLink(const FileItem *file);
0104 
0105     void compareDirectory(SynchronizerFileItem *, SynchronizerDirList *, SynchronizerDirList *, const QString &leftDir, const QString &rightDir);
0106     void addSingleDirectory(SynchronizerFileItem *, SynchronizerDirList *, const QString &, bool);
0107     SynchronizerFileItem *addItem(SynchronizerFileItem *,
0108                                   const QString &,
0109                                   const QString &,
0110                                   const QString &,
0111                                   const QString &,
0112                                   bool,
0113                                   bool,
0114                                   KIO::filesize_t,
0115                                   KIO::filesize_t,
0116                                   time_t,
0117                                   time_t,
0118                                   const QString &,
0119                                   const QString &,
0120                                   const QString &,
0121                                   const QString &,
0122                                   const QString &,
0123                                   const QString &,
0124                                   mode_t,
0125                                   mode_t,
0126                                   const QString &,
0127                                   const QString &,
0128                                   TaskType,
0129                                   bool,
0130                                   bool);
0131     SynchronizerFileItem *addLeftOnlyItem(SynchronizerFileItem *,
0132                                           const QString &,
0133                                           const QString &,
0134                                           KIO::filesize_t,
0135                                           time_t,
0136                                           const QString &,
0137                                           const QString &,
0138                                           const QString &,
0139                                           mode_t,
0140                                           const QString &,
0141                                           bool isDir = false,
0142                                           bool isTemp = false);
0143     SynchronizerFileItem *addRightOnlyItem(SynchronizerFileItem *,
0144                                            const QString &,
0145                                            const QString &,
0146                                            KIO::filesize_t,
0147                                            time_t,
0148                                            const QString &,
0149                                            const QString &,
0150                                            const QString &,
0151                                            mode_t,
0152                                            const QString &,
0153                                            bool isDir = false,
0154                                            bool isTemp = false);
0155     SynchronizerFileItem *addDuplicateItem(SynchronizerFileItem *,
0156                                            const QString &,
0157                                            const QString &,
0158                                            const QString &,
0159                                            const QString &,
0160                                            KIO::filesize_t,
0161                                            KIO::filesize_t,
0162                                            time_t,
0163                                            time_t,
0164                                            const QString &,
0165                                            const QString &,
0166                                            const QString &,
0167                                            const QString &,
0168                                            const QString &,
0169                                            const QString &,
0170                                            mode_t,
0171                                            mode_t,
0172                                            const QString &,
0173                                            const QString &,
0174                                            bool isDir = false,
0175                                            bool isTemp = false);
0176     bool isMarked(TaskType task, bool dupl);
0177     bool markParentDirectories(SynchronizerFileItem *);
0178     void synchronizeLoop();
0179     SynchronizerFileItem *getNextTask();
0180     void executeTask(SynchronizerFileItem *task);
0181     void setPermanent(SynchronizerFileItem *);
0182     void operate(SynchronizerFileItem *item, void (*)(SynchronizerFileItem *));
0183     void compareLoop();
0184 
0185     static void excludeOperation(SynchronizerFileItem *item);
0186     static void restoreOperation(SynchronizerFileItem *item);
0187     static void reverseDirectionOperation(SynchronizerFileItem *item);
0188     static void copyToLeftOperation(SynchronizerFileItem *item);
0189     static void copyToRightOperation(SynchronizerFileItem *item);
0190     static void deleteLeftOperation(SynchronizerFileItem *item);
0191 
0192 protected:
0193     bool recurseSubDirs; // walk through subdirectories also
0194     bool followSymLinks; // follow the symbolic links
0195     bool ignoreDate; // don't use date info at comparing
0196     bool asymmetric; // asymmetric directory update
0197     bool cmpByContent; // compare the files by content
0198     bool ignoreCase; // case insensitive synchronization for Windows fs
0199     bool autoScroll; // automatic update of the directory
0200     QList<SynchronizerFileItem *> resultList; // the found files
0201     QList<SynchronizerFileItem *> temporaryList; // temporary files
0202     QString leftBaseDir; // the left-side base directory
0203     QString rightBaseDir; // the right-side base directory
0204     QStringList excludedPaths; // list of the excluded paths
0205     KrQuery *query; // the filter used for the query
0206     bool stopped; // 'Stop' button was pressed
0207 
0208     int equalsThreshold; // threshold to treat files equal
0209     int timeOffset; // time offset between the left and right sides
0210     bool ignoreHidden; // ignores the hidden files
0211 
0212     bool markEquals; // show the equal files
0213     bool markDiffers; // show the different files
0214     bool markCopyToLeft; // show the files to copy from right to left
0215     bool markCopyToRight; // show the files to copy from left to right
0216     bool markDeletable; // show the files to be deleted
0217     bool markDuplicates; // show the duplicated items
0218     bool markSingles; // show the single items
0219 
0220     bool leftCopyEnabled; // copy to left is enabled at synchronize
0221     bool rightCopyEnabled; // copy to right is enabled at synchronize
0222     bool deleteEnabled; // delete is enabled at synchronize
0223     bool overWrite; // overwrite or query each modification
0224     bool autoSkip; // automatic skipping
0225     bool paused; // pause flag
0226     bool disableNewTasks; // at mkdir the further task creation is disabled
0227 
0228     int leftCopyNr; // the file number copied to left
0229     int rightCopyNr; // the file number copied to right
0230     int deleteNr; // the number of the deleted files
0231     int parallelThreads; // the number of the parallel processing threads
0232     KIO::filesize_t leftCopySize; // the total size copied to left
0233     KIO::filesize_t rightCopySize; // the total size copied to right
0234     KIO::filesize_t deleteSize; // the size of the deleted files
0235 
0236     int comparedDirs; // the number of the compared directories
0237     int fileCount; // the number of counted files
0238 
0239 private:
0240     QList<SynchronizerTask *> stack; // stack for comparing
0241     QMap<KJob *, SynchronizerFileItem *> jobMap; // job maps
0242     QMap<KJob *, KIO::filesize_t> receivedMap; // the received file size
0243     SynchronizerFileItem *lastTask; // reference to the last stack
0244     int inTaskFinished; // counter of quasy 'threads' in slotTaskFinished
0245 
0246     QStringList selectedFiles; // the selected files to compare
0247     QWidget *parentWidget; // the parent widget
0248     QWidget *syncDlgWidget; // the synchronizer dialog widget
0249     QListIterator<SynchronizerFileItem *> resultListIt; // iterator for result list
0250 };
0251 
0252 class QProgressBar;
0253 
0254 class KgetProgressDialog : public QDialog
0255 {
0256     Q_OBJECT
0257 
0258 public:
0259     explicit KgetProgressDialog(QWidget *parent = nullptr, const QString &caption = QString(), const QString &text = QString(), bool modal = false);
0260 
0261     QProgressBar *progressBar()
0262     {
0263         return mProgressBar;
0264     }
0265 
0266 public slots:
0267     void slotPause();
0268     void slotCancel();
0269 
0270     bool wasCancelled()
0271     {
0272         return mCancelled;
0273     }
0274     bool isPaused()
0275     {
0276         return mPaused;
0277     }
0278 
0279 private:
0280     QProgressBar *mProgressBar;
0281     QPushButton *mPauseButton;
0282     bool mCancelled;
0283     bool mPaused;
0284 };
0285 
0286 #endif /* __SYNCHRONIZER_H__ */