Changeset View
Changeset View
Standalone View
Standalone View
krusader/Synchronizer/synchronizedialog.cpp
Show All 13 Lines | |||||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | ||
15 | * GNU General Public License for more details. * | 15 | * GNU General Public License for more details. * | ||
16 | * * | 16 | * * | ||
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 | #include "synchronizedialog.h" | 21 | #include "synchronizedialog.h" | ||
22 | | ||||
22 | #include "../FileSystem/krpermhandler.h" | 23 | #include "../FileSystem/krpermhandler.h" | ||
24 | #include "../defaults.h" | ||||
23 | #include "../krglobal.h" | 25 | #include "../krglobal.h" | ||
24 | #include "../icon.h" | 26 | #include "../icon.h" | ||
25 | #include "../defaults.h" | | |||
26 | 27 | | |||
27 | // QtWidgets | 28 | // QtWidgets | ||
29 | #include <QLabel> | ||||
28 | #include <QLayout> | 30 | #include <QLayout> | ||
29 | #include <QVBoxLayout> | 31 | #include <QVBoxLayout> | ||
30 | #include <QLabel> | | |||
31 | 32 | | |||
32 | #include <KConfigCore/KSharedConfig> | 33 | #include <KConfigCore/KSharedConfig> | ||
33 | #include <KI18n/KLocalizedString> | 34 | #include <KI18n/KLocalizedString> | ||
34 | 35 | | |||
35 | SynchronizeDialog::SynchronizeDialog(QWidget* parent, | 36 | SynchronizeDialog::SynchronizeDialog(QWidget *parent, Synchronizer *sync, int pleftCopyNr, | ||
36 | Synchronizer *sync, int pleftCopyNr, KIO::filesize_t pleftCopySize, | 37 | KIO::filesize_t pleftCopySize, int prightCopyNr, | ||
37 | int prightCopyNr, KIO::filesize_t prightCopySize, int pdeleteNr, | 38 | KIO::filesize_t prightCopySize, int pdeleteNr, | ||
38 | KIO::filesize_t pdeleteSize, int parThreads) : QDialog(parent), | 39 | KIO::filesize_t pdeleteSize, int parThreads) | ||
39 | synchronizer(sync), leftCopyNr(pleftCopyNr), | 40 | : QDialog(parent), synchronizer(sync), leftCopyNr(pleftCopyNr), leftCopySize(pleftCopySize), | ||
40 | leftCopySize(pleftCopySize), rightCopyNr(prightCopyNr), | 41 | rightCopyNr(prightCopyNr), rightCopySize(prightCopySize), deleteNr(pdeleteNr), | ||
41 | rightCopySize(prightCopySize), deleteNr(pdeleteNr), | 42 | deleteSize(pdeleteSize), parallelThreads(parThreads), isPause(true), syncStarted(false) | ||
42 | deleteSize(pdeleteSize), parallelThreads(parThreads), | | |||
43 | isPause(true), syncStarted(false) | | |||
44 | { | 43 | { | ||
45 | setWindowTitle(i18n("Krusader::Synchronize")); | 44 | setWindowTitle(i18n("Krusader::Synchronize")); | ||
46 | setModal(true); | 45 | setModal(true); | ||
47 | 46 | | |||
48 | QVBoxLayout *layout = new QVBoxLayout(this); | 47 | QVBoxLayout *layout = new QVBoxLayout(this); | ||
49 | layout->setContentsMargins(11, 11, 11, 11); | 48 | layout->setContentsMargins(11, 11, 11, 11); | ||
50 | layout->setSpacing(6); | 49 | layout->setSpacing(6); | ||
51 | 50 | | |||
52 | cbRightToLeft = new QCheckBox(i18np("Right to left: Copy 1 file", "Right to left: Copy %1 files", leftCopyNr) + ' ' + | 51 | cbRightToLeft = new QCheckBox( | ||
53 | i18np("(1 byte)", "(%1 bytes)", KRpermHandler::parseSize(leftCopySize).trimmed().toInt()), | 52 | i18np("Right to left: Copy 1 file", "Right to left: Copy %1 files", leftCopyNr) + ' ' + | ||
53 | i18np("(1 byte)", "(%1 bytes)", | ||||
54 | KRpermHandler::parseSize(leftCopySize).trimmed().toInt()), | ||||
54 | this); | 55 | this); | ||
55 | cbRightToLeft->setChecked(leftCopyNr != 0); | 56 | cbRightToLeft->setChecked(leftCopyNr != 0); | ||
56 | cbRightToLeft->setEnabled(leftCopyNr != 0); | 57 | cbRightToLeft->setEnabled(leftCopyNr != 0); | ||
57 | layout->addWidget(cbRightToLeft); | 58 | layout->addWidget(cbRightToLeft); | ||
58 | 59 | | |||
59 | lbRightToLeft = new QLabel(i18np("\tReady: %2/1 file, %3/%4", "\tReady: %2/%1 files, %3/%4", leftCopyNr, 0, | 60 | lbRightToLeft = | ||
61 | new QLabel(i18np("\tReady: %2/1 file, %3/%4", "\tReady: %2/%1 files, %3/%4", leftCopyNr, 0, | ||||
60 | 0, KRpermHandler::parseSize(leftCopySize).trimmed()), | 62 | 0, KRpermHandler::parseSize(leftCopySize).trimmed()), | ||
61 | this); | 63 | this); | ||
62 | lbRightToLeft->setEnabled(leftCopyNr != 0); | 64 | lbRightToLeft->setEnabled(leftCopyNr != 0); | ||
63 | layout->addWidget(lbRightToLeft); | 65 | layout->addWidget(lbRightToLeft); | ||
64 | 66 | | |||
65 | cbLeftToRight = new QCheckBox(i18np("Left to right: Copy 1 file", "Left to right: Copy %1 files", rightCopyNr) + ' ' + | 67 | cbLeftToRight = new QCheckBox( | ||
66 | i18np("(1 byte)", "(%1 bytes)", KRpermHandler::parseSize(rightCopySize).trimmed().toInt()), | 68 | i18np("Left to right: Copy 1 file", "Left to right: Copy %1 files", rightCopyNr) + ' ' + | ||
69 | i18np("(1 byte)", "(%1 bytes)", | ||||
70 | KRpermHandler::parseSize(rightCopySize).trimmed().toInt()), | ||||
67 | this); | 71 | this); | ||
68 | cbLeftToRight->setChecked(rightCopyNr != 0); | 72 | cbLeftToRight->setChecked(rightCopyNr != 0); | ||
69 | cbLeftToRight->setEnabled(rightCopyNr != 0); | 73 | cbLeftToRight->setEnabled(rightCopyNr != 0); | ||
70 | layout->addWidget(cbLeftToRight); | 74 | layout->addWidget(cbLeftToRight); | ||
71 | 75 | | |||
72 | lbLeftToRight = new QLabel(i18np("\tReady: %2/1 file, %3/%4", "\tReady: %2/%1 files, %3/%4", rightCopyNr, 0, | 76 | lbLeftToRight = | ||
77 | new QLabel(i18np("\tReady: %2/1 file, %3/%4", "\tReady: %2/%1 files, %3/%4", rightCopyNr, 0, | ||||
73 | 0, KRpermHandler::parseSize(rightCopySize).trimmed()), | 78 | 0, KRpermHandler::parseSize(rightCopySize).trimmed()), | ||
74 | this); | 79 | this); | ||
75 | lbLeftToRight->setEnabled(rightCopyNr != 0); | 80 | lbLeftToRight->setEnabled(rightCopyNr != 0); | ||
76 | layout->addWidget(lbLeftToRight); | 81 | layout->addWidget(lbLeftToRight); | ||
77 | 82 | | |||
78 | cbDeletable = new QCheckBox(i18np("Left: Delete 1 file", "Left: Delete %1 files", deleteNr) + ' ' + | 83 | cbDeletable = new QCheckBox( | ||
84 | i18np("Left: Delete 1 file", "Left: Delete %1 files", deleteNr) + ' ' + | ||||
79 | i18np("(1 byte)", "(%1 bytes)", KRpermHandler::parseSize(deleteSize).trimmed().toInt()), | 85 | i18np("(1 byte)", "(%1 bytes)", KRpermHandler::parseSize(deleteSize).trimmed().toInt()), | ||
80 | this); | 86 | this); | ||
81 | cbDeletable->setChecked(deleteNr != 0); | 87 | cbDeletable->setChecked(deleteNr != 0); | ||
82 | cbDeletable->setEnabled(deleteNr != 0); | 88 | cbDeletable->setEnabled(deleteNr != 0); | ||
83 | layout->addWidget(cbDeletable); | 89 | layout->addWidget(cbDeletable); | ||
84 | 90 | | |||
85 | lbDeletable = new QLabel(i18np("\tReady: %2/1 file, %3/%4", "\tReady: %2/%1 files, %3/%4", deleteNr, 0, | 91 | lbDeletable = new QLabel(i18np("\tReady: %2/1 file, %3/%4", "\tReady: %2/%1 files, %3/%4", | ||
86 | 0, KRpermHandler::parseSize(deleteSize).trimmed()), | 92 | deleteNr, 0, 0, KRpermHandler::parseSize(deleteSize).trimmed()), | ||
87 | this); | 93 | this); | ||
88 | lbDeletable->setEnabled(deleteNr != 0); | 94 | lbDeletable->setEnabled(deleteNr != 0); | ||
89 | layout->addWidget(lbDeletable); | 95 | layout->addWidget(lbDeletable); | ||
90 | 96 | | |||
91 | progress = new QProgressBar(this); | 97 | progress = new QProgressBar(this); | ||
92 | progress->setMaximum(1000); | 98 | progress->setMaximum(1000); | ||
93 | progress->setMinimum(0); | 99 | progress->setMinimum(0); | ||
94 | progress->setValue(0); | 100 | progress->setValue(0); | ||
95 | progress->setMinimumWidth(400); | 101 | progress->setMinimumWidth(400); | ||
96 | layout->addWidget(progress); | 102 | layout->addWidget(progress); | ||
97 | 103 | | |||
98 | QWidget *hboxWidget = new QWidget(this); | 104 | QWidget *hboxWidget = new QWidget(this); | ||
99 | QHBoxLayout * hbox = new QHBoxLayout(hboxWidget); | 105 | QHBoxLayout *hbox = new QHBoxLayout(hboxWidget); | ||
100 | 106 | | |||
101 | hbox->setSpacing(6); | 107 | hbox->setSpacing(6); | ||
102 | 108 | | |||
103 | cbOverwrite = new QCheckBox(i18n("Confirm overwrites"), this); | 109 | cbOverwrite = new QCheckBox(i18n("Confirm overwrites"), this); | ||
104 | KConfigGroup group(krConfig, "Synchronize"); | 110 | KConfigGroup group(krConfig, "Synchronize"); | ||
105 | cbOverwrite->setChecked(group.readEntry("Confirm overwrites", _ConfirmOverWrites)); | 111 | cbOverwrite->setChecked(group.readEntry("Confirm overwrites", _ConfirmOverWrites)); | ||
106 | layout->addWidget(cbOverwrite); | 112 | layout->addWidget(cbOverwrite); | ||
107 | 113 | | |||
108 | QSpacerItem* spacer = new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); | 114 | QSpacerItem *spacer = new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); | ||
109 | hbox->addItem(spacer); | 115 | hbox->addItem(spacer); | ||
110 | 116 | | |||
111 | btnStart = new QPushButton(hboxWidget); | 117 | btnStart = new QPushButton(hboxWidget); | ||
112 | btnStart->setText(i18n("&Start")); | 118 | btnStart->setText(i18n("&Start")); | ||
113 | btnStart->setIcon(Icon("media-playback-start")); | 119 | btnStart->setIcon(Icon("media-playback-start")); | ||
114 | hbox->addWidget(btnStart); | 120 | hbox->addWidget(btnStart); | ||
115 | 121 | | |||
116 | btnPause = new QPushButton(hboxWidget); | 122 | btnPause = new QPushButton(hboxWidget); | ||
117 | btnPause->setEnabled(false); | 123 | btnPause->setEnabled(false); | ||
118 | btnPause->setText(i18n("&Pause")); | 124 | btnPause->setText(i18n("&Pause")); | ||
119 | btnPause->setIcon(Icon("media-playback-pause")); | 125 | btnPause->setIcon(Icon("media-playback-pause")); | ||
120 | hbox->addWidget(btnPause); | 126 | hbox->addWidget(btnPause); | ||
121 | 127 | | |||
122 | QPushButton *btnClose = new QPushButton(hboxWidget); | 128 | QPushButton *btnClose = new QPushButton(hboxWidget); | ||
123 | btnClose->setText(i18n("&Close")); | 129 | btnClose->setText(i18n("&Close")); | ||
124 | btnClose->setIcon(Icon("dialog-close")); | 130 | btnClose->setIcon(Icon("dialog-close")); | ||
125 | hbox->addWidget(btnClose); | 131 | hbox->addWidget(btnClose); | ||
126 | 132 | | |||
127 | layout->addWidget(hboxWidget); | 133 | layout->addWidget(hboxWidget); | ||
128 | 134 | | |||
129 | connect(btnStart, SIGNAL(clicked()), this, SLOT(startSynchronization())); | 135 | connect(btnStart, SIGNAL(clicked()), this, SLOT(startSynchronization())); | ||
130 | connect(btnPause, SIGNAL(clicked()), this, SLOT(pauseOrResume())); | 136 | connect(btnPause, SIGNAL(clicked()), this, SLOT(pauseOrResume())); | ||
131 | connect(btnClose, SIGNAL(clicked()), this, SLOT(reject())); | 137 | connect(btnClose, SIGNAL(clicked()), this, SLOT(reject())); | ||
132 | 138 | | |||
133 | exec(); | 139 | exec(); | ||
134 | } | 140 | } | ||
135 | 141 | | |||
136 | SynchronizeDialog::~SynchronizeDialog() | 142 | SynchronizeDialog::~SynchronizeDialog() | ||
137 | { | 143 | { | ||
138 | KConfigGroup group(krConfig, "Synchronize"); | 144 | KConfigGroup group(krConfig, "Synchronize"); | ||
139 | group.writeEntry("Confirm overwrites", cbOverwrite->isChecked()); | 145 | group.writeEntry("Confirm overwrites", cbOverwrite->isChecked()); | ||
140 | } | 146 | } | ||
141 | 147 | | |||
142 | void SynchronizeDialog::startSynchronization() | 148 | void SynchronizeDialog::startSynchronization() | ||
143 | { | 149 | { | ||
144 | btnStart->setEnabled(false); | 150 | btnStart->setEnabled(false); | ||
145 | btnPause->setEnabled(syncStarted = true); | 151 | btnPause->setEnabled(syncStarted = true); | ||
146 | connect(synchronizer, SIGNAL(synchronizationFinished()), this, SLOT(synchronizationFinished())); | 152 | connect(synchronizer, SIGNAL(synchronizationFinished()), this, SLOT(synchronizationFinished())); | ||
147 | connect(synchronizer, SIGNAL(processedSizes(int,KIO::filesize_t,int,KIO::filesize_t,int,KIO::filesize_t)), | 153 | connect(synchronizer, SIGNAL(processedSizes(int, KIO::filesize_t, int, KIO::filesize_t, int, | ||
148 | this, SLOT(processedSizes(int,KIO::filesize_t,int,KIO::filesize_t,int,KIO::filesize_t))); | 154 | KIO::filesize_t)), | ||
155 | this, | ||||
156 | SLOT(processedSizes(int, KIO::filesize_t, int, KIO::filesize_t, int, KIO::filesize_t))); | ||||
149 | connect(synchronizer, SIGNAL(pauseAccepted()), this, SLOT(pauseAccepted())); | 157 | connect(synchronizer, SIGNAL(pauseAccepted()), this, SLOT(pauseAccepted())); | ||
150 | 158 | | |||
151 | if (!cbRightToLeft->isChecked()) leftCopySize = 0; | 159 | if (!cbRightToLeft->isChecked()) | ||
152 | if (!cbLeftToRight->isChecked()) rightCopySize = 0; | 160 | leftCopySize = 0; | ||
153 | if (!cbDeletable->isChecked()) deleteSize = 0; | 161 | if (!cbLeftToRight->isChecked()) | ||
162 | rightCopySize = 0; | ||||
163 | if (!cbDeletable->isChecked()) | ||||
164 | deleteSize = 0; | ||||
154 | 165 | | |||
155 | synchronizer->synchronize(this, cbRightToLeft->isChecked(), cbLeftToRight->isChecked(), | 166 | synchronizer->synchronize(this, cbRightToLeft->isChecked(), cbLeftToRight->isChecked(), | ||
156 | cbDeletable->isChecked(), !cbOverwrite->isChecked(), parallelThreads); | 167 | cbDeletable->isChecked(), !cbOverwrite->isChecked(), parallelThreads); | ||
157 | } | 168 | } | ||
158 | 169 | | |||
159 | void SynchronizeDialog::synchronizationFinished() | 170 | void SynchronizeDialog::synchronizationFinished() { QDialog::reject(); } | ||
160 | { | | |||
161 | QDialog::reject(); | | |||
162 | } | | |||
163 | 171 | | |||
164 | void SynchronizeDialog::processedSizes(int leftNr, KIO::filesize_t leftSize, int rightNr, | 172 | void SynchronizeDialog::processedSizes(int leftNr, KIO::filesize_t leftSize, int rightNr, | ||
165 | KIO::filesize_t rightSize, int delNr, KIO::filesize_t delSize) | 173 | KIO::filesize_t rightSize, int delNr, | ||
174 | KIO::filesize_t delSize) | ||||
166 | { | 175 | { | ||
167 | lbRightToLeft->setText(i18np("\tReady: %2/1 file, %3/%4", "\tReady: %2/%1 files, %3/%4", leftCopyNr, leftNr, | 176 | lbRightToLeft->setText(i18np("\tReady: %2/1 file, %3/%4", "\tReady: %2/%1 files, %3/%4", | ||
168 | KRpermHandler::parseSize(leftSize).trimmed(), | 177 | leftCopyNr, leftNr, KRpermHandler::parseSize(leftSize).trimmed(), | ||
169 | KRpermHandler::parseSize(leftCopySize).trimmed())); | 178 | KRpermHandler::parseSize(leftCopySize).trimmed())); | ||
170 | lbLeftToRight->setText(i18np("\tReady: %2/1 file, %3/%4", "\tReady: %2/%1 files, %3/%4", rightCopyNr, rightNr, | 179 | lbLeftToRight->setText(i18np("\tReady: %2/1 file, %3/%4", "\tReady: %2/%1 files, %3/%4", | ||
180 | rightCopyNr, rightNr, | ||||
171 | KRpermHandler::parseSize(rightSize).trimmed(), | 181 | KRpermHandler::parseSize(rightSize).trimmed(), | ||
172 | KRpermHandler::parseSize(rightCopySize).trimmed())); | 182 | KRpermHandler::parseSize(rightCopySize).trimmed())); | ||
173 | lbDeletable->setText(i18np("\tReady: %2/1 file, %3/%4", "\tReady: %2/%1 files, %3/%4", deleteNr, delNr, | 183 | lbDeletable->setText(i18np("\tReady: %2/1 file, %3/%4", "\tReady: %2/%1 files, %3/%4", deleteNr, | ||
174 | KRpermHandler::parseSize(delSize).trimmed(), | 184 | delNr, KRpermHandler::parseSize(delSize).trimmed(), | ||
175 | KRpermHandler::parseSize(deleteSize).trimmed())); | 185 | KRpermHandler::parseSize(deleteSize).trimmed())); | ||
176 | 186 | | |||
177 | KIO::filesize_t totalSum = leftCopySize + rightCopySize + deleteSize; | 187 | KIO::filesize_t totalSum = leftCopySize + rightCopySize + deleteSize; | ||
178 | KIO::filesize_t processedSum = leftSize + rightSize + delSize; | 188 | KIO::filesize_t processedSum = leftSize + rightSize + delSize; | ||
179 | 189 | | |||
180 | if (totalSum == 0) | 190 | if (totalSum == 0) | ||
181 | totalSum++; | 191 | totalSum++; | ||
182 | 192 | | |||
183 | progress->setValue((int)(((double)processedSum / (double)totalSum)*1000)); | 193 | progress->setValue((int)(((double)processedSum / (double)totalSum) * 1000)); | ||
184 | } | 194 | } | ||
185 | 195 | | |||
186 | void SynchronizeDialog::pauseOrResume() | 196 | void SynchronizeDialog::pauseOrResume() | ||
187 | { | 197 | { | ||
188 | if (isPause) { | 198 | if (isPause) { | ||
189 | btnPause->setEnabled(false); | 199 | btnPause->setEnabled(false); | ||
190 | synchronizer->pause(); | 200 | synchronizer->pause(); | ||
191 | } else { | 201 | } else { | ||
192 | btnPause->setText(i18n("Pause")); | 202 | btnPause->setText(i18n("Pause")); | ||
193 | synchronizer->resume(); | 203 | synchronizer->resume(); | ||
194 | isPause = true; | 204 | isPause = true; | ||
195 | } | 205 | } | ||
196 | } | 206 | } | ||
197 | 207 | | |||
198 | void SynchronizeDialog::pauseAccepted() | 208 | void SynchronizeDialog::pauseAccepted() | ||
199 | { | 209 | { | ||
200 | btnPause->setText(i18n("Resume")); | 210 | btnPause->setText(i18n("Resume")); | ||
201 | btnPause->setEnabled(true); | 211 | btnPause->setEnabled(true); | ||
202 | isPause = false; | 212 | isPause = false; | ||
203 | } | 213 | } | ||
204 | |