1 /***************************************************************************** 2 * Copyright (C) 2006 Csaba Karai <krusader@users.sourceforge.net> * 3 * Copyright (C) 2006-2019 Krusader Krew [https://krusader.org] * 4 * * 5 * This file is part of Krusader [https://krusader.org]. * 6 * * 7 * Krusader is free software: you can redistribute it and/or modify * 8 * it under the terms of the GNU General Public License as published by * 9 * the Free Software Foundation, either version 2 of the License, or * 10 * (at your option) any later version. * 11 * * 12 * Krusader is distributed in the hope that it will be useful, * 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 15 * GNU General Public License for more details. * 16 * * 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/]. * 19 *****************************************************************************/ 20 21 #ifndef SYNCHRONIZERFILEITEM_H 22 #define SYNCHRONIZERFILEITEM_H 23 24 // QtCore 25 #include <QString> 26 27 #include <KIO/Global> 28 29 typedef enum { 30 TT_EQUALS = 0, // the files are equals -> do nothing 31 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 33 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 35 TT_UNKNOWN = 5, // (5-9) the type of the task is not yet known 36 TT_MAX = 10 // the maximum number of task types 37 } TaskType; 38 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 56 { 57 private: 58 QString m_leftName; // the left file name 59 QString m_rightName; // the right file name 60 QString m_leftDirectory;// the left relative directory path from the base 61 QString m_rightDirectory;// the left relative directory path from the base 62 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 80 bool m_isDir; // flag, indicates that the file is a directory 81 SynchronizerFileItem *m_parent; // pointer to the parent directory item or 0 82 void *m_userData; // user data 83 bool m_overWrite; // overwrite flag 84 QString m_destination; // the destination URL at rename 85 bool m_temporary; // flag indicates temporary directory 86 TaskType m_originalTask; // the original task type 87 88 public: SynchronizerFileItem(const QString & leftNam,const QString & rightNam,const QString & leftDir,const QString & rightDir,bool mark,bool exL,bool exR,KIO::filesize_t leftSize,KIO::filesize_t rightSize,time_t leftDate,time_t rightDate,const QString & leftLink,const QString & rightLink,const QString & leftOwner,const QString & rightOwner,const QString & leftGroup,const QString & rightGroup,mode_t leftMode,mode_t rightMode,const QString & leftACL,const QString & rightACL,TaskType tsk,bool isDir,bool tmp,SynchronizerFileItem * parent)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 isMarked()106 inline bool isMarked() { 107 return m_marked; 108 } setMarked(bool flag)109 inline void setMarked(bool flag) { 110 m_marked = flag; 111 } leftName()112 inline const QString & leftName() { 113 return m_leftName; 114 } rightName()115 inline const QString & rightName() { 116 return m_rightName; 117 } leftDirectory()118 inline const QString & leftDirectory() { 119 return m_leftDirectory; 120 } rightDirectory()121 inline const QString & rightDirectory() { 122 return m_rightDirectory; 123 } existsInLeft()124 inline bool existsInLeft() { 125 return m_existsLeft; 126 } existsInRight()127 inline bool existsInRight() { 128 return m_existsRight; 129 } overWrite()130 inline bool overWrite() { 131 return m_overWrite; 132 } leftSize()133 inline KIO::filesize_t leftSize() { 134 return m_leftSize; 135 } rightSize()136 inline KIO::filesize_t rightSize() { 137 return m_rightSize; 138 } leftDate()139 inline time_t leftDate() { 140 return m_leftDate; 141 } rightDate()142 inline time_t rightDate() { 143 return m_rightDate; 144 } leftLink()145 inline const QString & leftLink() { 146 return m_leftLink; 147 } rightLink()148 inline const QString & rightLink() { 149 return m_rightLink; 150 } leftOwner()151 inline const QString & leftOwner() { 152 return m_leftOwner; 153 } rightOwner()154 inline const QString & rightOwner() { 155 return m_rightOwner; 156 } leftGroup()157 inline const QString & leftGroup() { 158 return m_leftGroup; 159 } rightGroup()160 inline const QString & rightGroup() { 161 return m_rightGroup; 162 } leftMode()163 inline mode_t leftMode() { 164 return m_leftMode; 165 } rightMode()166 inline mode_t rightMode() { 167 return m_rightMode; 168 } leftACL()169 inline const QString & leftACL() { 170 return m_leftACL; 171 } rightACL()172 inline const QString & rightACL() { 173 return m_rightACL; 174 } task()175 inline TaskType task() { 176 return m_task; 177 } compareContentResult(bool res)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 } isDir()184 inline bool isDir() { 185 return m_isDir; 186 } parent()187 inline SynchronizerFileItem * parent() { 188 return m_parent; 189 } userData()190 inline void * userData() { 191 return m_userData; 192 } setUserData(void * ud)193 inline void setUserData(void *ud) { 194 m_userData = ud; 195 } setOverWrite()196 inline void setOverWrite() { 197 m_overWrite = true; 198 } destination()199 inline const QString & destination() { 200 return m_destination; 201 } setDestination(QString d)202 inline void setDestination(QString d) { 203 m_destination = d; 204 } isTemporary()205 inline bool isTemporary() { 206 return m_temporary; 207 } setPermanent()208 inline void setPermanent() { 209 m_temporary = false; 210 } originalTask()211 inline TaskType originalTask() { 212 return m_originalTask; 213 } restoreOriginalTask()214 inline void restoreOriginalTask() { 215 m_task = m_originalTask; 216 } setTask(TaskType t)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 }; 234 235 #endif /* __SYNCHRONIZER_FILE_ITEM_H__ */ 236