Changeset View
Changeset View
Standalone View
Standalone View
krusader/Synchronizer/synchronizerfileitem.h
Show All 17 Lines | |||||
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 SYNCHRONIZERFILEITEM_H | 21 | #ifndef SYNCHRONIZERFILEITEM_H | ||
22 | #define SYNCHRONIZERFILEITEM_H | 22 | #define SYNCHRONIZERFILEITEM_H | ||
23 | 23 | | |||
24 | // QtCore | 24 | // QtCore | ||
25 | #include <QString> | 25 | #include <QString> | ||
26 | #include <QUrl> | ||||
26 | 27 | | |||
27 | #include <KIO/Global> | 28 | #include <KIO/Global> | ||
28 | 29 | | |||
30 | #include "../FileSystem/fileitem.h" | ||||
31 | | ||||
32 | class SyncViewItem; | ||||
33 | | ||||
29 | typedef enum { | 34 | typedef enum { | ||
30 | TT_EQUALS = 0, // the files are equals -> do nothing | 35 | TT_EQUALS = 0, // the files are equals -> do nothing | ||
31 | TT_DIFFERS = 1, // the files are differents -> don't know what to do | 36 | TT_DIFFERS = 1, // the files are differents -> don't know what to do | ||
32 | TT_COPY_TO_LEFT = 2, // the right file is newer -> copy from right to left | 37 | TT_COPY_TO_LEFT = 2, // the right file is newer -> copy from right to left | ||
33 | TT_COPY_TO_RIGHT = 3, // the left file is newer -> copy from left to right | 38 | TT_COPY_TO_RIGHT = 3, // the left file is newer -> copy from left to right | ||
34 | TT_DELETE = 4, // the left file is single -> delete it | 39 | TT_DELETE = 4, // the left file is single -> delete it | ||
35 | TT_UNKNOWN = 5, // (5-9) the type of the task is not yet known | 40 | TT_UNKNOWN = 5, // (5-9) the type of the task is not yet known | ||
36 | TT_MAX = 10 // the maximum number of task types | 41 | TT_MAX = 10 // the maximum number of task types | ||
37 | } TaskType; | 42 | } TaskType; | ||
38 | 43 | | |||
39 | #define SWAP( A, B, TYPE ) {TYPE TMP = A; A = B; B = TMP;} | | |||
40 | #define REVERSE_TASK( A, asym ) {switch( A ) \ | | |||
41 | { \ | | |||
42 | case TT_COPY_TO_LEFT: \ | | |||
43 | if( asym ) \ | | |||
44 | A = !m_existsRight ? TT_DELETE : TT_COPY_TO_LEFT; \ | | |||
45 | else \ | | |||
46 | A = TT_COPY_TO_RIGHT; \ | | |||
47 | break; \ | | |||
48 | case TT_COPY_TO_RIGHT: \ | | |||
49 | case TT_DELETE: \ | | |||
50 | A = TT_COPY_TO_LEFT; \ | | |||
51 | default: \ | | |||
52 | break; \ | | |||
53 | }}; | | |||
54 | | ||||
55 | class SynchronizerFileItem | 44 | class SynchronizerFileItem | ||
56 | { | 45 | { | ||
46 | public: | ||||
47 | SynchronizerFileItem(const FileItem &leftFile, const FileItem &rightFile, | ||||
48 | const QString &leftDir, const QString &rightDir, | ||||
49 | bool mark, TaskType tsk, bool tmp, SynchronizerFileItem *parent); | ||||
50 | | ||||
51 | inline bool existsLeft() const { return !m_leftFile.getName().isNull(); } | ||||
52 | inline bool existsRight() const { return !m_rightFile.getName().isNull(); } | ||||
53 | inline bool isDir() const | ||||
54 | { | ||||
55 | return !m_leftFile.getName().isNull() ? m_leftFile.isDir() : m_rightFile.isDir(); | ||||
56 | } | ||||
57 | | ||||
58 | inline const QString &leftName() const | ||||
59 | { | ||||
60 | return existsLeft() ? m_leftFile.getName() : m_rightFile.getName(); | ||||
61 | } | ||||
62 | inline const QString &rightName() const | ||||
63 | { | ||||
64 | return existsRight() ? m_rightFile.getName() : m_leftFile.getName(); | ||||
65 | } | ||||
66 | inline KIO::filesize_t leftSize() const { return m_leftFile.getSize(); } | ||||
67 | inline KIO::filesize_t rightSize() const { return m_rightFile.getSize(); } | ||||
68 | inline time_t leftDate() const { return m_leftFile.getTime_t(); } | ||||
69 | inline time_t rightDate() const { return m_rightFile.getTime_t(); } | ||||
70 | inline const QString &leftLink() const { return m_leftFile.getSymDest(); } | ||||
71 | inline const QString &rightLink() const { return m_rightFile.getSymDest(); } | ||||
72 | inline const QString &leftOwner() const { return m_leftFile.getOwner(); } | ||||
73 | inline const QString &rightOwner() const { return m_rightFile.getOwner(); } | ||||
74 | inline const QString &leftGroup() const { return m_leftFile.getGroup(); } | ||||
75 | inline const QString &rightGroup() const { return m_rightFile.getGroup(); } | ||||
76 | inline mode_t leftMode() const { return m_leftFile.getMode(); } | ||||
77 | inline mode_t rightMode() const { return m_rightFile.getMode(); } | ||||
78 | inline const QString &leftACL() { return m_leftFile.getACL(); } | ||||
79 | inline const QString &rightACL() { return m_rightFile.getACL(); } | ||||
80 | | ||||
81 | inline bool isMarked() const { return m_marked; } | ||||
82 | inline const QString &leftDirectory() const { return m_leftDirectory; } | ||||
83 | inline const QString &rightDirectory() const { return m_rightDirectory; } | ||||
84 | inline bool overWrite() const { return m_overWrite; } | ||||
85 | inline TaskType task() const { return m_task; } | ||||
86 | inline SynchronizerFileItem *parent() const { return m_parent; } | ||||
87 | inline SyncViewItem *viewItem() const { return m_viewItem; } | ||||
88 | inline const QUrl &destination() const { return m_destination; } | ||||
89 | inline bool isTemporary() const { return m_temporary; } | ||||
90 | inline TaskType originalTask() const { return m_originalTask; } | ||||
91 | | ||||
92 | inline void setMarked(bool flag) { m_marked = flag; } | ||||
93 | inline void setPermanent() { m_temporary = false; } | ||||
94 | inline void restoreOriginalTask() { m_task = m_originalTask; } | ||||
95 | inline void setViewItem(SyncViewItem *viewItem) { m_viewItem = viewItem; } | ||||
96 | inline void setOverWrite() { m_overWrite = true; } | ||||
97 | inline void setDestination(QUrl d) { m_destination = d; } | ||||
98 | inline void setTask(TaskType t) { m_task = t; } | ||||
99 | | ||||
100 | void compareContentResult(bool res); | ||||
101 | void swap(bool asym = false); | ||||
102 | | ||||
57 | private: | 103 | private: | ||
58 | QString m_leftName; // the left file name | 104 | void reverseTask(TaskType &taskType, bool asym); | ||
59 | QString m_rightName; // the right file name | 105 | | ||
106 | FileItem m_leftFile; | ||||
107 | FileItem m_rightFile; | ||||
60 | QString m_leftDirectory;// the left relative directory path from the base | 108 | QString m_leftDirectory; // the left relative directory path from the base | ||
61 | QString m_rightDirectory;// the left relative directory path from the base | 109 | QString m_rightDirectory; // the left relative directory path from the base | ||
110 | | ||||
62 | bool m_marked; // flag, indicates to show the file | 111 | bool m_marked; // flag, indicates to show the file | ||
63 | bool m_existsLeft; // flag, the file exists in the left directory | | |||
64 | bool m_existsRight; // flag, the file exists in the right directory | | |||
65 | KIO::filesize_t m_leftSize; // the file size at the left directory | | |||
66 | KIO::filesize_t m_rightSize; // the file size at the right directory | | |||
67 | time_t m_leftDate; // the file date at the left directory | | |||
68 | time_t m_rightDate; // the file date at the left directory | | |||
69 | QString m_leftLink; // the left file's symbolic link destination | | |||
70 | QString m_rightLink; // the right file's symbolic link destination | | |||
71 | QString m_leftOwner; // the left file's owner | | |||
72 | QString m_rightOwner; // the right file's owner | | |||
73 | QString m_leftGroup; // the left file's group | | |||
74 | QString m_rightGroup; // the right file's group | | |||
75 | mode_t m_leftMode; // mode for left | | |||
76 | mode_t m_rightMode; // mode for right | | |||
77 | QString m_leftACL; // ACL of the left file | | |||
78 | QString m_rightACL; // ACL of the right file | | |||
79 | TaskType m_task; // the task with the file | 112 | TaskType m_task; // the task with the file | ||
80 | bool m_isDir; // flag, indicates that the file is a directory | | |||
81 | SynchronizerFileItem *m_parent; // pointer to the parent directory item or 0 | 113 | SynchronizerFileItem *m_parent; // pointer to the parent directory item or 0 | ||
82 | void *m_userData; // user data | 114 | SyncViewItem *m_viewItem; // user data | ||
83 | bool m_overWrite; // overwrite flag | 115 | bool m_overWrite; // overwrite flag | ||
84 | QString m_destination; // the destination URL at rename | 116 | QUrl m_destination; // the destination URL at rename | ||
85 | bool m_temporary; // flag indicates temporary directory | 117 | bool m_temporary; // flag indicates temporary directory | ||
86 | TaskType m_originalTask; // the original task type | 118 | TaskType m_originalTask; // the original task type | ||
87 | | ||||
88 | public: | | |||
89 | SynchronizerFileItem(const QString &leftNam, const QString &rightNam, const QString &leftDir, | | |||
90 | const QString &rightDir, bool mark, bool exL, bool exR, KIO::filesize_t leftSize, | | |||
91 | KIO::filesize_t rightSize, time_t leftDate, time_t rightDate, | | |||
92 | const QString &leftLink, const QString &rightLink, const QString &leftOwner, | | |||
93 | const QString &rightOwner, const QString &leftGroup, const QString &rightGroup, | | |||
94 | mode_t leftMode, mode_t rightMode, const QString &leftACL, const QString &rightACL, | | |||
95 | TaskType tsk, bool isDir, bool tmp, SynchronizerFileItem *parent) : | | |||
96 | m_leftName(leftNam), m_rightName(rightNam), m_leftDirectory(leftDir), m_rightDirectory(rightDir), | | |||
97 | m_marked(mark), m_existsLeft(exL), m_existsRight(exR), m_leftSize(leftSize), | | |||
98 | m_rightSize(rightSize), m_leftDate(leftDate), m_rightDate(rightDate), | | |||
99 | m_leftLink(leftLink), m_rightLink(rightLink), m_leftOwner(leftOwner), | | |||
100 | m_rightOwner(rightOwner), m_leftGroup(leftGroup), m_rightGroup(rightGroup), | | |||
101 | m_leftMode(leftMode), m_rightMode(rightMode), m_leftACL(leftACL), | | |||
102 | m_rightACL(rightACL), m_task(tsk), m_isDir(isDir), m_parent(parent), | | |||
103 | m_userData(0), m_overWrite(false), m_destination(QString()), | | |||
104 | m_temporary(tmp), m_originalTask(tsk) {} | | |||
105 | | ||||
106 | inline bool isMarked() { | | |||
107 | return m_marked; | | |||
108 | } | | |||
109 | inline void setMarked(bool flag) { | | |||
110 | m_marked = flag; | | |||
111 | } | | |||
112 | inline const QString & leftName() { | | |||
113 | return m_leftName; | | |||
114 | } | | |||
115 | inline const QString & rightName() { | | |||
116 | return m_rightName; | | |||
117 | } | | |||
118 | inline const QString & leftDirectory() { | | |||
119 | return m_leftDirectory; | | |||
120 | } | | |||
121 | inline const QString & rightDirectory() { | | |||
122 | return m_rightDirectory; | | |||
123 | } | | |||
124 | inline bool existsInLeft() { | | |||
125 | return m_existsLeft; | | |||
126 | } | | |||
127 | inline bool existsInRight() { | | |||
128 | return m_existsRight; | | |||
129 | } | | |||
130 | inline bool overWrite() { | | |||
131 | return m_overWrite; | | |||
132 | } | | |||
133 | inline KIO::filesize_t leftSize() { | | |||
134 | return m_leftSize; | | |||
135 | } | | |||
136 | inline KIO::filesize_t rightSize() { | | |||
137 | return m_rightSize; | | |||
138 | } | | |||
139 | inline time_t leftDate() { | | |||
140 | return m_leftDate; | | |||
141 | } | | |||
142 | inline time_t rightDate() { | | |||
143 | return m_rightDate; | | |||
144 | } | | |||
145 | inline const QString & leftLink() { | | |||
146 | return m_leftLink; | | |||
147 | } | | |||
148 | inline const QString & rightLink() { | | |||
149 | return m_rightLink; | | |||
150 | } | | |||
151 | inline const QString & leftOwner() { | | |||
152 | return m_leftOwner; | | |||
153 | } | | |||
154 | inline const QString & rightOwner() { | | |||
155 | return m_rightOwner; | | |||
156 | } | | |||
157 | inline const QString & leftGroup() { | | |||
158 | return m_leftGroup; | | |||
159 | } | | |||
160 | inline const QString & rightGroup() { | | |||
161 | return m_rightGroup; | | |||
162 | } | | |||
163 | inline mode_t leftMode() { | | |||
164 | return m_leftMode; | | |||
165 | } | | |||
166 | inline mode_t rightMode() { | | |||
167 | return m_rightMode; | | |||
168 | } | | |||
169 | inline const QString & leftACL() { | | |||
170 | return m_leftACL; | | |||
171 | } | | |||
172 | inline const QString & rightACL() { | | |||
173 | return m_rightACL; | | |||
174 | } | | |||
175 | inline TaskType task() { | | |||
176 | return m_task; | | |||
177 | } | | |||
178 | inline void compareContentResult(bool res) { | | |||
179 | if (res == true) | | |||
180 | m_task = m_originalTask = TT_EQUALS; | | |||
181 | else if (m_originalTask >= TT_UNKNOWN) | | |||
182 | m_task = m_originalTask = (TaskType)(m_originalTask - TT_UNKNOWN); | | |||
183 | } | | |||
184 | inline bool isDir() { | | |||
185 | return m_isDir; | | |||
186 | } | | |||
187 | inline SynchronizerFileItem * parent() { | | |||
188 | return m_parent; | | |||
189 | } | | |||
190 | inline void * userData() { | | |||
191 | return m_userData; | | |||
192 | } | | |||
193 | inline void setUserData(void *ud) { | | |||
194 | m_userData = ud; | | |||
195 | } | | |||
196 | inline void setOverWrite() { | | |||
197 | m_overWrite = true; | | |||
198 | } | | |||
199 | inline const QString & destination() { | | |||
200 | return m_destination; | | |||
201 | } | | |||
202 | inline void setDestination(QString d) { | | |||
203 | m_destination = d; | | |||
204 | } | | |||
205 | inline bool isTemporary() { | | |||
206 | return m_temporary; | | |||
207 | } | | |||
208 | inline void setPermanent() { | | |||
209 | m_temporary = false; | | |||
210 | } | | |||
211 | inline TaskType originalTask() { | | |||
212 | return m_originalTask; | | |||
213 | } | | |||
214 | inline void restoreOriginalTask() { | | |||
215 | m_task = m_originalTask; | | |||
216 | } | | |||
217 | inline void setTask(TaskType t) { | | |||
218 | m_task = t; | | |||
219 | } | | |||
220 | inline void swap(bool asym = false) { | | |||
221 | SWAP(m_existsLeft, m_existsRight, bool); | | |||
222 | SWAP(m_leftName, m_rightName, QString); | | |||
223 | SWAP(m_leftDirectory, m_rightDirectory, QString); | | |||
224 | SWAP(m_leftSize, m_rightSize, KIO::filesize_t); | | |||
225 | SWAP(m_leftDate, m_rightDate, time_t); | | |||
226 | SWAP(m_leftLink, m_rightLink, QString); | | |||
227 | SWAP(m_leftOwner, m_rightOwner, QString); | | |||
228 | SWAP(m_leftGroup, m_rightGroup, QString); | | |||
229 | SWAP(m_leftACL, m_rightACL, QString); | | |||
230 | REVERSE_TASK(m_originalTask, asym); | | |||
231 | REVERSE_TASK(m_task, asym); | | |||
232 | } | | |||
233 | }; | 119 | }; | ||
234 | 120 | | |||
235 | #endif /* __SYNCHRONIZER_FILE_ITEM_H__ */ | 121 | #endif /* __SYNCHRONIZER_FILE_ITEM_H__ */ |