Changeset View
Changeset View
Standalone View
Standalone View
krusader/Synchronizer/synchronizer.h
Show All 16 Lines | |||||
17 | * You should have received a copy of the GNU General Public License * | 17 | * You should have received a copy of the GNU General Public License * | ||
18 | * along with Krusader. If not, see [http://www.gnu.org/licenses/]. * | 18 | * along with Krusader. If not, see [http://www.gnu.org/licenses/]. * | ||
19 | *****************************************************************************/ | 19 | *****************************************************************************/ | ||
20 | 20 | | |||
21 | #ifndef SYNCHRONIZER_H | 21 | #ifndef SYNCHRONIZER_H | ||
22 | #define SYNCHRONIZER_H | 22 | #define SYNCHRONIZER_H | ||
23 | 23 | | |||
24 | // QtCore | 24 | // QtCore | ||
25 | #include <QObject> | | |||
26 | #include <QMap> | | |||
27 | #include <QList> | 25 | #include <QList> | ||
26 | #include <QMap> | ||||
27 | #include <QObject> | ||||
28 | // QtGui | 28 | // QtGui | ||
29 | #include <QColor> | 29 | #include <QColor> | ||
30 | // QtWidgets | 30 | // QtWidgets | ||
31 | #include <QDialog> | 31 | #include <QDialog> | ||
32 | 32 | | |||
33 | #include <KIO/Job> | 33 | #include <KIO/Job> | ||
34 | 34 | | |||
35 | # include "synchronizertask.h" | | |||
36 | #include "synchronizerfileitem.h" | 35 | #include "synchronizerfileitem.h" | ||
36 | #include "synchronizertask.h" | ||||
37 | 37 | | |||
38 | class KRQuery; | | |||
39 | class FileItem; | 38 | class FileItem; | ||
39 | class KRQuery; | ||||
40 | 40 | | |||
41 | class Synchronizer : public QObject | 41 | class Synchronizer : public QObject | ||
42 | { | 42 | { | ||
43 | Q_OBJECT | 43 | Q_OBJECT | ||
44 | 44 | | |||
45 | private: | 45 | private: | ||
46 | int displayUpdateCount; // the display is refreshed after every x-th change | 46 | int displayUpdateCount; // the display is refreshed after every x-th change | ||
47 | 47 | | |||
48 | public: | 48 | public: | ||
49 | Synchronizer(); | 49 | Synchronizer(); | ||
50 | ~Synchronizer(); | 50 | ~Synchronizer(); | ||
51 | int compare(QString leftURL, QString rightURL, KRQuery *query, bool subDirs, bool symLinks, | 51 | | ||
52 | bool igDate, bool asymm, bool cmpByCnt, bool igCase, bool autoSc, QStringList &selFiles, | 52 | int compare(const QUrl &left, const QUrl &right, KRQuery *query, bool subDirs, bool symLinks, | ||
53 | int equThres, int timeOffs, int parThreads, bool hiddenFiles); | 53 | bool igDate, bool asymm, bool cmpByCnt, bool igCase, bool autoSc, | ||
54 | void stop() { | 54 | QStringList &selFiles, int equThres, int timeOffs, int parThreads, | ||
55 | stopped = true; | 55 | bool hiddenFiles); | ||
56 | } | 56 | void stop() { stopped = true; } | ||
57 | void setMarkFlags(bool left, bool equal, bool differs, bool right, bool dup, bool sing, bool del); | 57 | void setMarkFlags(bool left, bool equal, bool differs, bool right, bool dup, bool sing, | ||
58 | bool del); | ||||
58 | int refresh(bool nostatus = false); | 59 | int refresh(bool nostatus = false); | ||
59 | bool totalSizes(int *, KIO::filesize_t *, int *, KIO::filesize_t *, int *, KIO::filesize_t *); | 60 | bool totalSizes(int *, KIO::filesize_t *, int *, KIO::filesize_t *, int *, KIO::filesize_t *); | ||
60 | void synchronize(QWidget *, bool leftCopyEnabled, bool rightCopyEnabled, bool deleteEnabled, | 61 | | ||
61 | bool overWrite, int parThreads); | 62 | void synchronize(QWidget *syncDialog, bool leftCopyEnabled, bool rightCopyEnabled, | ||
63 | bool deleteEnabled, bool overWrite, int parThreads); | ||||
64 | /** | ||||
65 | * Execute sync with KGet. | ||||
66 | * | ||||
67 | * This is only supported for downloading files from one remote side other local side. | ||||
68 | * Local destination files (if exist) are removed before downloading! | ||||
69 | */ | ||||
62 | void synchronizeWithKGet(); | 70 | void synchronizeWithKGet(); | ||
71 | | ||||
63 | void setScrolling(bool scroll); | 72 | void setScrolling(bool scroll); | ||
64 | void pause(); | 73 | void pause(); | ||
65 | void resume(); | 74 | void resume(); | ||
66 | void swapSides(); | 75 | void swapSides(); | ||
67 | void reset(); | 76 | void reset(); | ||
68 | void clearLists(); | 77 | void clearLists(); | ||
69 | 78 | | |||
70 | void exclude(SynchronizerFileItem *); | 79 | void exclude(SynchronizerFileItem *); | ||
71 | void restore(SynchronizerFileItem *); | 80 | void restore(SynchronizerFileItem *); | ||
72 | void reverseDirection(SynchronizerFileItem *); | 81 | void reverseDirection(SynchronizerFileItem *); | ||
73 | void copyToLeft(SynchronizerFileItem *); | 82 | void copyToLeft(SynchronizerFileItem *); | ||
74 | void copyToRight(SynchronizerFileItem *); | 83 | void copyToRight(SynchronizerFileItem *); | ||
75 | void deleteLeft(SynchronizerFileItem *); | 84 | void deleteLeft(SynchronizerFileItem *); | ||
76 | 85 | | |||
77 | QString leftBaseDirectory(); | 86 | const QUrl leftBaseDirectory() { return leftBaseDir; } | ||
78 | QString rightBaseDirectory(); | 87 | const QUrl rightBaseDirectory() { return rightBaseDir; } | ||
88 | | ||||
89 | static QUrl pathAppend(const QUrl &url, const QString &fileName); | ||||
90 | static QUrl pathAppend(const QUrl &url, const QString &dirName, const QString &fileName); | ||||
91 | | ||||
79 | static QString getTaskTypeName(TaskType taskType); | 92 | static QString getTaskTypeName(TaskType taskType); | ||
80 | static QUrl fsUrl(QString strUrl); | 93 | | ||
81 | 94 | | |||
82 | SynchronizerFileItem *getItemAt(unsigned ndx); | 95 | SynchronizerFileItem *getItemAt(unsigned ndx); | ||
83 | 96 | | |||
84 | void setParentWidget(QWidget * widget) { | 97 | void setParentWidget(QWidget *widget) { parentWidget = widget; } | ||
85 | parentWidget = widget; | | |||
86 | } | | |||
87 | void compareContentResult(SynchronizerFileItem * item, bool result); | 98 | void compareContentResult(SynchronizerFileItem *item, bool result); | ||
88 | 99 | | |||
89 | signals: | 100 | signals: | ||
90 | void comparedFileData(SynchronizerFileItem *); | 101 | void comparedFileData(SynchronizerFileItem *); | ||
91 | void markChanged(SynchronizerFileItem *, bool); | 102 | void markChanged(SynchronizerFileItem *, bool); | ||
92 | void synchronizationFinished(); | 103 | void synchronizationFinished(); | ||
93 | void processedSizes(int, KIO::filesize_t, int, KIO::filesize_t, int, KIO::filesize_t); | 104 | void processedSizes(int, KIO::filesize_t, int, KIO::filesize_t, int, KIO::filesize_t); | ||
94 | void pauseAccepted(); | 105 | void pauseAccepted(); | ||
95 | void statusInfo(QString); | 106 | void statusInfo(QString); | ||
96 | 107 | | |||
97 | public slots: | 108 | public slots: | ||
98 | void slotTaskFinished(KJob*); | 109 | void slotTaskFinished(KJob *); | ||
99 | void slotProcessedSize(KJob * , qulonglong); | 110 | void slotProcessedSize(KJob *, qulonglong); | ||
100 | 111 | | |||
101 | private: | 112 | private: | ||
102 | bool isDir(const FileItem * file); | 113 | bool isDir(const FileItem *file); | ||
103 | QString readLink(const FileItem * file); | | |||
104 | 114 | | |||
105 | void compareDirectory(SynchronizerFileItem *, SynchronizerDirList *, SynchronizerDirList *, | 115 | void compareDirectory(SynchronizerFileItem *, SynchronizerDirList *, SynchronizerDirList *, | ||
106 | const QString &leftDir, const QString &rightDir); | 116 | const QString &leftDir, const QString &rightDir); | ||
117 | | ||||
118 | SynchronizerFileItem *addItem(FileItem *leftFile, FileItem *rightFile, | ||||
119 | SynchronizerFileItem *parent, const QString &leftDir, | ||||
120 | const QString &rightDir, TaskType tsk, bool isTemp); | ||||
121 | | ||||
122 | SynchronizerFileItem *addLeftOnlyItem(FileItem *leftFile, SynchronizerFileItem *parent, | ||||
123 | const QString &dir, bool isTemp = false); | ||||
124 | SynchronizerFileItem *addRightOnlyItem(FileItem *rightFile, SynchronizerFileItem *parent, | ||||
125 | const QString &dir, bool isTemp = false); | ||||
126 | SynchronizerFileItem *addDuplicateItem(FileItem *leftFile, FileItem *rightFile, | ||||
127 | SynchronizerFileItem *parent, | ||||
128 | const QString &leftDir, const QString &rightDir, | ||||
129 | bool isTemp = false); | ||||
107 | void addSingleDirectory(SynchronizerFileItem *, SynchronizerDirList *, const QString &, bool); | 130 | void addSingleDirectory(SynchronizerFileItem *, SynchronizerDirList *, const QString &, bool); | ||
108 | SynchronizerFileItem * addItem(SynchronizerFileItem *, const QString &, const QString &, | 131 | | ||
109 | const QString &, const QString &, bool, bool, KIO::filesize_t, | | |||
110 | KIO::filesize_t, time_t, time_t, const QString &, const QString &, | | |||
111 | const QString &, const QString &, const QString &, const QString &, | | |||
112 | mode_t, mode_t, const QString &, const QString &, TaskType, bool, bool); | | |||
113 | SynchronizerFileItem * addLeftOnlyItem(SynchronizerFileItem *, const QString &, const QString &, | | |||
114 | KIO::filesize_t, time_t, const QString &, const QString &, | | |||
115 | const QString &, mode_t, const QString &, bool isDir = false, bool isTemp = false); | | |||
116 | SynchronizerFileItem * addRightOnlyItem(SynchronizerFileItem *, const QString &, const QString &, | | |||
117 | KIO::filesize_t, time_t, const QString &, const QString &, | | |||
118 | const QString &, mode_t, const QString &, bool isDir = false, bool isTemp = false); | | |||
119 | SynchronizerFileItem * addDuplicateItem(SynchronizerFileItem *, const QString &, const QString &, | | |||
120 | const QString &, const QString &, KIO::filesize_t, | | |||
121 | KIO::filesize_t, time_t, time_t, const QString &, | | |||
122 | const QString &, const QString &, const QString &, | | |||
123 | const QString &, const QString &, mode_t, mode_t, const QString &, | | |||
124 | const QString &, bool isDir = false, bool isTemp = false); | | |||
125 | bool isMarked(TaskType task, bool dupl); | 132 | bool isMarked(TaskType task, bool dupl); | ||
126 | bool markParentDirectories(SynchronizerFileItem *); | 133 | bool markParentDirectories(SynchronizerFileItem *); | ||
127 | void synchronizeLoop(); | 134 | void synchronizeLoop(); | ||
128 | SynchronizerFileItem * getNextTask(); | 135 | SynchronizerFileItem *getNextTask(); | ||
129 | void executeTask(SynchronizerFileItem * task); | 136 | void executeTask(SynchronizerFileItem *task); | ||
137 | KJob *createJob(SynchronizerFileItem *task, const QUrl &src, const QUrl &url, const QString &link); | ||||
130 | void setPermanent(SynchronizerFileItem *); | 138 | void setPermanent(SynchronizerFileItem *); | ||
131 | void operate(SynchronizerFileItem *item, void (*)(SynchronizerFileItem *)); | 139 | void operate(SynchronizerFileItem *item, void (*)(SynchronizerFileItem *)); | ||
132 | void compareLoop(); | 140 | void compareLoop(); | ||
133 | 141 | | |||
134 | static void excludeOperation(SynchronizerFileItem *item); | 142 | static void excludeOperation(SynchronizerFileItem *item); | ||
135 | static void restoreOperation(SynchronizerFileItem *item); | 143 | static void restoreOperation(SynchronizerFileItem *item); | ||
136 | static void reverseDirectionOperation(SynchronizerFileItem *item); | 144 | static void reverseDirectionOperation(SynchronizerFileItem *item); | ||
137 | static void copyToLeftOperation(SynchronizerFileItem *item); | 145 | static void copyToLeftOperation(SynchronizerFileItem *item); | ||
138 | static void copyToRightOperation(SynchronizerFileItem *item); | 146 | static void copyToRightOperation(SynchronizerFileItem *item); | ||
139 | static void deleteLeftOperation(SynchronizerFileItem *item); | 147 | static void deleteLeftOperation(SynchronizerFileItem *item); | ||
140 | 148 | | |||
141 | protected: | 149 | protected: | ||
142 | bool recurseSubDirs; // walk through subdirectories also | 150 | bool recurseSubDirs; // walk through subdirectories also | ||
143 | bool followSymLinks; // follow the symbolic links | 151 | bool followSymLinks; // follow the symbolic links | ||
144 | bool ignoreDate; // don't use date info at comparing | 152 | bool ignoreDate; // don't use date info at comparing | ||
145 | bool asymmetric; // asymmetric directory update | 153 | bool asymmetric; // asymmetric directory update | ||
146 | bool cmpByContent; // compare the files by content | 154 | bool cmpByContent; // compare the files by content | ||
147 | bool ignoreCase; // case insensitive synchronization for Windows fs | 155 | bool ignoreCase; // case insensitive synchronization for Windows fs | ||
148 | bool autoScroll; // automatic update of the directory | 156 | bool autoScroll; // automatic update of the directory | ||
149 | QList<SynchronizerFileItem *> resultList; // the found files | 157 | QList<SynchronizerFileItem *> resultList; // the found files | ||
150 | QList<SynchronizerFileItem *> temporaryList; // temporary files | 158 | QList<SynchronizerFileItem *> temporaryList; // temporary files | ||
151 | QString leftBaseDir; // the left-side base directory | 159 | QUrl leftBaseDir; // the left-side base directory | ||
152 | QString rightBaseDir; // the right-side base directory | 160 | QUrl rightBaseDir; // the right-side base directory | ||
153 | QStringList excludedPaths; // list of the excluded paths | 161 | QStringList excludedPaths; // list of the excluded paths | ||
154 | KRQuery *query; // the filter used for the query | 162 | KRQuery *query; // the filter used for the query | ||
155 | bool stopped; // 'Stop' button was pressed | 163 | bool stopped; // 'Stop' button was pressed | ||
156 | 164 | | |||
157 | int equalsThreshold;// threshold to treat files equal | 165 | int equalsThreshold; // threshold to treat files equal | ||
158 | int timeOffset; // time offset between the left and right sides | 166 | int timeOffset; // time offset between the left and right sides | ||
159 | bool ignoreHidden; // ignores the hidden files | 167 | bool ignoreHidden; // ignores the hidden files | ||
160 | 168 | | |||
161 | bool markEquals; // show the equal files | 169 | bool markEquals; // show the equal files | ||
162 | bool markDiffers; // show the different files | 170 | bool markDiffers; // show the different files | ||
163 | bool markCopyToLeft; // show the files to copy from right to left | 171 | bool markCopyToLeft; // show the files to copy from right to left | ||
164 | bool markCopyToRight;// show the files to copy from left to right | 172 | bool markCopyToRight; // show the files to copy from left to right | ||
165 | bool markDeletable; // show the files to be deleted | 173 | bool markDeletable; // show the files to be deleted | ||
166 | bool markDuplicates; // show the duplicated items | 174 | bool markDuplicates; // show the duplicated items | ||
167 | bool markSingles; // show the single items | 175 | bool markSingles; // show the single items | ||
168 | 176 | | |||
169 | bool leftCopyEnabled;// copy to left is enabled at synchronize | 177 | bool leftCopyEnabled; // copy to left is enabled at synchronize | ||
170 | bool rightCopyEnabled;// copy to right is enabled at synchronize | 178 | bool rightCopyEnabled; // copy to right is enabled at synchronize | ||
171 | bool deleteEnabled; // delete is enabled at synchronize | 179 | bool deleteEnabled; // delete is enabled at synchronize | ||
172 | bool overWrite; // overwrite or query each modification | 180 | bool overWrite; // overwrite or query each modification | ||
173 | bool autoSkip; // automatic skipping | 181 | bool autoSkip; // automatic skipping | ||
174 | bool paused; // pause flag | 182 | bool paused; // pause flag | ||
175 | bool disableNewTasks;// at mkdir the further task creation is disabled | 183 | bool disableNewTasks; // at mkdir the further task creation is disabled | ||
176 | 184 | | |||
177 | int leftCopyNr; // the file number copied to left | 185 | int leftCopyNr; // the file number copied to left | ||
178 | int rightCopyNr; // the file number copied to right | 186 | int rightCopyNr; // the file number copied to right | ||
179 | int deleteNr; // the number of the deleted files | 187 | int deleteNr; // the number of the deleted files | ||
180 | int parallelThreads;// the number of the parallel procesing threads | 188 | int parallelThreads; // the number of the parallel procesing threads | ||
181 | KIO::filesize_t leftCopySize; // the total size copied to left | 189 | KIO::filesize_t leftCopySize; // the total size copied to left | ||
182 | KIO::filesize_t rightCopySize; // the total size copied to right | 190 | KIO::filesize_t rightCopySize; // the total size copied to right | ||
183 | KIO::filesize_t deleteSize; // the size of the deleted files | 191 | KIO::filesize_t deleteSize; // the size of the deleted files | ||
184 | 192 | | |||
185 | int comparedDirs; // the number of the compared directories | 193 | int comparedDirs; // the number of the compared directories | ||
186 | int fileCount; // the number of counted files | 194 | int fileCount; // the number of counted files | ||
187 | 195 | | |||
188 | private: | 196 | private: | ||
189 | QList<SynchronizerTask *> stack; // stack for comparing | 197 | QList<SynchronizerTask *> stack; // stack for comparing | ||
190 | QMap<KJob *, SynchronizerFileItem *> jobMap; // job maps | 198 | QMap<KJob *, SynchronizerFileItem *> jobMap; // job maps | ||
191 | QMap<KJob *, KIO::filesize_t> receivedMap; // the received file size | 199 | QMap<KJob *, KIO::filesize_t> receivedMap; // the received file size | ||
192 | SynchronizerFileItem *lastTask; // reference to the last stack | 200 | SynchronizerFileItem *lastTask; // reference to the last stack | ||
193 | int inTaskFinished; // counter of quasy 'threads' in slotTaskFinished | 201 | int inTaskFinished; // counter of quasy 'threads' in slotTaskFinished | ||
194 | 202 | | |||
195 | QStringList selectedFiles; // the selected files to compare | 203 | QStringList selectedFiles; // the selected files to compare | ||
196 | QWidget *parentWidget; // the parent widget | 204 | QWidget *parentWidget; // the parent widget | ||
197 | QWidget *syncDlgWidget; // the synchronizer dialog widget | 205 | QWidget *syncDlgWidget; // the synchronizer dialog widget | ||
198 | QListIterator<SynchronizerFileItem *> resultListIt; // iterator for result list | 206 | QListIterator<SynchronizerFileItem *> resultListIt; // iterator for result list | ||
199 | }; | 207 | }; | ||
200 | 208 | | |||
201 | class QProgressBar; | 209 | class QProgressBar; | ||
202 | 210 | | |||
203 | class KgetProgressDialog : public QDialog | 211 | class KgetProgressDialog : public QDialog | ||
204 | { | 212 | { | ||
205 | Q_OBJECT | 213 | Q_OBJECT | ||
206 | 214 | | |||
207 | public: | 215 | public: | ||
208 | explicit KgetProgressDialog(QWidget *parent = 0, const QString &caption = QString(), | 216 | explicit KgetProgressDialog(QWidget *parent = 0, const QString &caption = QString(), | ||
209 | const QString &text = QString(), bool modal = false); | 217 | const QString &text = QString(), bool modal = false); | ||
210 | 218 | | |||
211 | QProgressBar *progressBar() { | 219 | QProgressBar *progressBar() { return mProgressBar; } | ||
212 | return mProgressBar; | | |||
213 | } | | |||
214 | 220 | | |||
215 | public slots: | 221 | public slots: | ||
216 | void slotPause(); | 222 | void slotPause(); | ||
217 | void slotCancel(); | 223 | void slotCancel(); | ||
218 | 224 | | |||
219 | bool wasCancelled() { | 225 | bool wasCancelled() { return mCancelled; } | ||
220 | return mCancelled; | 226 | bool isPaused() { return mPaused; } | ||
221 | } | | |||
222 | bool isPaused() { | | |||
223 | return mPaused; | | |||
224 | } | | |||
225 | 227 | | |||
226 | private: | 228 | private: | ||
227 | QProgressBar *mProgressBar; | 229 | QProgressBar *mProgressBar; | ||
228 | QPushButton *mPauseButton; | 230 | QPushButton *mPauseButton; | ||
229 | bool mCancelled; | 231 | bool mCancelled; | ||
230 | bool mPaused; | 232 | bool mPaused; | ||
231 | }; | 233 | }; | ||
232 | 234 | | |||
233 | #endif /* __SYNCHRONIZER_H__ */ | 235 | #endif /* __SYNCHRONIZER_H__ */ |