Changeset View
Changeset View
Standalone View
Standalone View
krusader/Synchronizer/synchronizerfileitem.cpp
- This file was added.
1 | /***************************************************************************** | ||||
---|---|---|---|---|---|
2 | * Copyright (C) 2017 Krusader Krew * | ||||
3 | * * | ||||
4 | * This program is free software; you can redistribute it and/or modify * | ||||
5 | * it under the terms of the GNU General Public License as published by * | ||||
6 | * the Free Software Foundation; either version 2 of the License, or * | ||||
7 | * (at your option) any later version. * | ||||
8 | * * | ||||
9 | * This package is distributed in the hope that it will be useful, * | ||||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * | ||||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | ||||
12 | * GNU General Public License for more details. * | ||||
13 | * * | ||||
14 | * You should have received a copy of the GNU General Public License * | ||||
15 | * along with this package; if not, write to the Free Software * | ||||
16 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * | ||||
17 | *****************************************************************************/ | ||||
18 | | ||||
19 | #include <synchronizerfileitem.h> | ||||
20 | | ||||
21 | #define SWAP(A, B, TYPE) \ | ||||
22 | { \ | ||||
23 | TYPE TMP = A; \ | ||||
24 | A = B; \ | ||||
25 | B = TMP; \ | ||||
26 | } | ||||
27 | | ||||
28 | SynchronizerFileItem::SynchronizerFileItem(const FileItem &leftFile, const FileItem &rightFile, | ||||
29 | const QString &leftDir, const QString &rightDir, | ||||
30 | bool mark, TaskType tsk, bool tmp, | ||||
31 | SynchronizerFileItem *parent) | ||||
32 | : m_leftFile(leftFile), m_rightFile(rightFile), m_leftDirectory(leftDir), | ||||
33 | m_rightDirectory(rightDir), m_marked(mark), m_task(tsk), m_parent(parent), m_viewItem(0), | ||||
34 | m_overWrite(false), m_destination(QUrl()), m_temporary(tmp), m_originalTask(tsk) | ||||
35 | { | ||||
36 | } | ||||
37 | | ||||
38 | void SynchronizerFileItem::compareContentResult(bool res) | ||||
39 | { | ||||
40 | if (res == true) | ||||
41 | m_task = m_originalTask = TT_EQUALS; | ||||
42 | else if (m_originalTask >= TT_UNKNOWN) | ||||
43 | m_task = m_originalTask = (TaskType)(m_originalTask - TT_UNKNOWN); | ||||
44 | } | ||||
45 | | ||||
46 | void SynchronizerFileItem::swap(bool asym) | ||||
47 | { | ||||
48 | SWAP(m_leftFile, m_rightFile, FileItem); | ||||
49 | SWAP(m_leftDirectory, m_rightDirectory, QString); | ||||
50 | reverseTask(m_originalTask, asym); | ||||
51 | reverseTask(m_task, asym); | ||||
52 | } | ||||
53 | | ||||
54 | void SynchronizerFileItem::reverseTask(TaskType &taskType, bool asym) | ||||
55 | { | ||||
56 | switch (taskType) { | ||||
57 | case TT_COPY_TO_LEFT: | ||||
58 | if (asym) | ||||
59 | taskType = !existsRight() ? TT_DELETE : TT_COPY_TO_LEFT; | ||||
60 | else | ||||
61 | taskType = TT_COPY_TO_RIGHT; | ||||
62 | break; | ||||
63 | case TT_COPY_TO_RIGHT: | ||||
64 | case TT_DELETE: | ||||
65 | taskType = TT_COPY_TO_LEFT; | ||||
66 | default: | ||||
67 | break; | ||||
68 | } | ||||
69 | } |