Changeset View
Changeset View
Standalone View
Standalone View
src/widgets/renamedialog.cpp
Show All 19 Lines | |||||
20 | */ | 20 | */ | ||
21 | 21 | | |||
22 | #include "kio/renamedialog.h" | 22 | #include "kio/renamedialog.h" | ||
23 | #include "kio_widgets_debug.h" | 23 | #include "kio_widgets_debug.h" | ||
24 | #include "../pathhelpers_p.h" | 24 | #include "../pathhelpers_p.h" | ||
25 | 25 | | |||
26 | #include <QApplication> | 26 | #include <QApplication> | ||
27 | #include <QCheckBox> | 27 | #include <QCheckBox> | ||
28 | #include <QComboBox> | ||||
28 | #include <QDate> | 29 | #include <QDate> | ||
29 | #include <QDebug> | 30 | #include <QDebug> | ||
30 | #include <QDesktopWidget> | 31 | #include <QDesktopWidget> | ||
31 | #include <QDir> | 32 | #include <QDir> | ||
32 | #include <QLabel> | 33 | #include <QLabel> | ||
33 | #include <QLayout> | 34 | #include <QLayout> | ||
34 | #include <QLineEdit> | 35 | #include <QLineEdit> | ||
35 | #include <QMimeDatabase> | 36 | #include <QMimeDatabase> | ||
▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Line(s) | |||||
96 | class Q_DECL_HIDDEN RenameDialog::RenameDialogPrivate | 97 | class Q_DECL_HIDDEN RenameDialog::RenameDialogPrivate | ||
97 | { | 98 | { | ||
98 | public: | 99 | public: | ||
99 | RenameDialogPrivate() | 100 | RenameDialogPrivate() | ||
100 | { | 101 | { | ||
101 | bCancel = nullptr; | 102 | bCancel = nullptr; | ||
102 | bRename = bSkip = bOverwrite = nullptr; | 103 | bRename = bSkip = bOverwrite = nullptr; | ||
103 | bResume = bSuggestNewName = nullptr; | 104 | bResume = bSuggestNewName = nullptr; | ||
104 | bApplyAll = nullptr; | 105 | m_applyOptions = nullptr; | ||
105 | m_pLineEdit = nullptr; | 106 | m_pLineEdit = nullptr; | ||
106 | m_srcPendingPreview = false; | 107 | m_srcPendingPreview = false; | ||
107 | m_destPendingPreview = false; | 108 | m_destPendingPreview = false; | ||
108 | m_srcPreview = nullptr; | 109 | m_srcPreview = nullptr; | ||
109 | m_destPreview = nullptr; | 110 | m_destPreview = nullptr; | ||
110 | m_srcArea = nullptr; | 111 | m_srcArea = nullptr; | ||
111 | m_destArea = nullptr; | 112 | m_destArea = nullptr; | ||
112 | } | 113 | } | ||
113 | 114 | | |||
114 | void setRenameBoxText(const QString &fileName) | 115 | void setRenameBoxText(const QString &fileName) | ||
115 | { | 116 | { | ||
116 | // sets the text in file name line edit box, selecting the filename (but not the extension if there is one). | 117 | // sets the text in file name line edit box, selecting the filename (but not the extension if there is one). | ||
117 | QMimeDatabase db; | 118 | QMimeDatabase db; | ||
118 | const QString extension = db.suffixForFileName(fileName); | 119 | const QString extension = db.suffixForFileName(fileName); | ||
119 | m_pLineEdit->setText(fileName); | 120 | m_pLineEdit->setText(fileName); | ||
120 | 121 | | |||
121 | if (!extension.isEmpty()) { | 122 | if (!extension.isEmpty()) { | ||
122 | const int selectionLength = fileName.length() - extension.length() - 1; | 123 | const int selectionLength = fileName.length() - extension.length() - 1; | ||
123 | m_pLineEdit->setSelection(0, selectionLength); | 124 | m_pLineEdit->setSelection(0, selectionLength); | ||
124 | } else { | 125 | } else { | ||
125 | m_pLineEdit->selectAll(); | 126 | m_pLineEdit->selectAll(); | ||
126 | } | 127 | } | ||
127 | } | 128 | } | ||
128 | 129 | | |||
130 | enum ApplyOptions { | ||||
131 | ApplyCurrent, | ||||
132 | ApplyAll, | ||||
133 | ApplyOldDest, | ||||
134 | ApplyNewDest | ||||
135 | }; | ||||
136 | | ||||
137 | ApplyOptions indexToOption(int index) | ||||
138 | { | ||||
139 | switch (index) { | ||||
140 | case 1: | ||||
141 | return ApplyAll; | ||||
142 | case 2: | ||||
143 | return ApplyOldDest; | ||||
144 | case 3: | ||||
145 | return ApplyNewDest; | ||||
146 | default: | ||||
147 | return ApplyCurrent; | ||||
148 | } | ||||
149 | } | ||||
150 | | ||||
129 | QPushButton *bCancel; | 151 | QPushButton *bCancel; | ||
130 | QPushButton *bRename; | 152 | QPushButton *bRename; | ||
131 | QPushButton *bSkip; | 153 | QPushButton *bSkip; | ||
132 | QPushButton *bOverwrite; | 154 | QPushButton *bOverwrite; | ||
133 | QPushButton *bResume; | 155 | QPushButton *bResume; | ||
134 | QPushButton *bSuggestNewName; | 156 | QPushButton *bSuggestNewName; | ||
135 | QCheckBox *bApplyAll; | 157 | QComboBox *m_applyOptions; | ||
136 | QLineEdit *m_pLineEdit; | 158 | QLineEdit *m_pLineEdit; | ||
137 | QUrl src; | 159 | QUrl src; | ||
138 | QUrl dest; | 160 | QUrl dest; | ||
139 | bool m_srcPendingPreview; | 161 | bool m_srcPendingPreview; | ||
140 | bool m_destPendingPreview; | 162 | bool m_destPendingPreview; | ||
141 | QLabel *m_srcPreview; | 163 | QLabel *m_srcPreview; | ||
142 | QLabel *m_destPreview; | 164 | QLabel *m_destPreview; | ||
143 | QScrollArea *m_srcArea; | 165 | QScrollArea *m_srcArea; | ||
Show All 20 Lines | 181 | { | |||
164 | 186 | | |||
165 | setWindowTitle(_caption); | 187 | setWindowTitle(_caption); | ||
166 | 188 | | |||
167 | d->bCancel = new QPushButton(this); | 189 | d->bCancel = new QPushButton(this); | ||
168 | KGuiItem::assign(d->bCancel, KStandardGuiItem::cancel()); | 190 | KGuiItem::assign(d->bCancel, KStandardGuiItem::cancel()); | ||
169 | connect(d->bCancel, &QAbstractButton::clicked, this, &RenameDialog::cancelPressed); | 191 | connect(d->bCancel, &QAbstractButton::clicked, this, &RenameDialog::cancelPressed); | ||
170 | 192 | | |||
171 | if (_options & RenameDialog_MultipleItems) { | 193 | if (_options & RenameDialog_MultipleItems) { | ||
172 | d->bApplyAll = new QCheckBox(i18n("Appl&y to All"), this); | 194 | d->m_applyOptions = new QComboBox(this); | ||
173 | d->bApplyAll->setToolTip((_options & RenameDialog_IsDirectory) ? i18n("When this is checked the button pressed will be applied to all subsequent folder conflicts for the remainder of the current job.\nUnless you press Skip you will still be prompted in case of a conflict with an existing file in the directory.") | 195 | d->m_applyOptions->addItem(i18n("Apply to Current")); | ||
174 | : i18n("When this is checked the button pressed will be applied to all subsequent conflicts for the remainder of the current job.")); | 196 | d->m_applyOptions->addItem(i18n("Apply to All")); | ||
175 | connect(d->bApplyAll, &QAbstractButton::clicked, this, &RenameDialog::applyAllPressed); | 197 | d->m_applyOptions->addItem(i18n("Apply to Older Dest")); | ||
198 | d->m_applyOptions->addItem(i18n("Apply to Newer Dest")); | ||||
199 | | ||||
200 | auto applyOptionToolTipSuffix = [](int index) -> QString { | ||||
201 | switch (index) { | ||||
202 | case 1: | ||||
203 | return i18n("all subsequent conflicts"); | ||||
204 | case 2: | ||||
205 | return i18n("all subsequent conflicts with an older version of destination"); | ||||
206 | case 3: | ||||
207 | return i18n("all subsequent conflicts with a newer version of destination"); | ||||
208 | default: | ||||
209 | return i18n("current conflict"); | ||||
210 | } | ||||
211 | }; | ||||
212 | for (int i=0; i<=3; i++) { | ||||
213 | d->m_applyOptions->setItemData(i, i18n("When this is selected the button pressed will be applied to %1 for the remainder of the current job.", applyOptionToolTipSuffix(i)), Qt::ToolTipRole); | ||||
214 | } | ||||
215 | | ||||
216 | connect(d->m_applyOptions, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &RenameDialog::applyOptionChanged); | ||||
217 | d->m_applyOptions->setCurrentIndex(RenameDialogPrivate::ApplyCurrent); | ||||
176 | } | 218 | } | ||
177 | 219 | | |||
178 | if (!(_options & RenameDialog_NoRename)) { | 220 | if (!(_options & RenameDialog_NoRename)) { | ||
179 | d->bRename = new QPushButton(i18n("&Rename"), this); | 221 | d->bRename = new QPushButton(i18n("&Rename"), this); | ||
180 | d->bRename->setEnabled(false); | 222 | d->bRename->setEnabled(false); | ||
181 | d->bSuggestNewName = new QPushButton(i18n("Suggest New &Name"), this); | 223 | d->bSuggestNewName = new QPushButton(i18n("Suggest New &Name"), this); | ||
182 | connect(d->bSuggestNewName, &QAbstractButton::clicked, this, &RenameDialog::suggestNewNamePressed); | 224 | connect(d->bSuggestNewName, &QAbstractButton::clicked, this, &RenameDialog::suggestNewNamePressed); | ||
183 | connect(d->bRename, &QAbstractButton::clicked, this, &RenameDialog::renamePressed); | 225 | connect(d->bRename, &QAbstractButton::clicked, this, &RenameDialog::renamePressed); | ||
▲ Show 20 Lines • Show All 172 Lines • ▼ Show 20 Line(s) | |||||
356 | KSeparator *separator = new KSeparator(this); | 398 | KSeparator *separator = new KSeparator(this); | ||
357 | pLayout->addWidget(separator); | 399 | pLayout->addWidget(separator); | ||
358 | 400 | | |||
359 | QHBoxLayout *layout = new QHBoxLayout(); | 401 | QHBoxLayout *layout = new QHBoxLayout(); | ||
360 | pLayout->addLayout(layout); | 402 | pLayout->addLayout(layout); | ||
361 | 403 | | |||
362 | layout->addStretch(1); | 404 | layout->addStretch(1); | ||
363 | 405 | | |||
364 | if (d->bApplyAll) { | 406 | if (d->m_applyOptions) { | ||
365 | layout->addWidget(d->bApplyAll); | 407 | layout->addWidget(d->m_applyOptions); | ||
366 | setTabOrder(d->bApplyAll, d->bCancel); | 408 | setTabOrder(d->m_applyOptions, d->bCancel); | ||
367 | } | 409 | } | ||
368 | 410 | | |||
369 | if (d->bRename) { | 411 | if (d->bRename) { | ||
370 | layout->addWidget(d->bRename); | 412 | layout->addWidget(d->bRename); | ||
371 | setTabOrder(d->bRename, d->bCancel); | 413 | setTabOrder(d->bRename, d->bCancel); | ||
372 | } | 414 | } | ||
373 | 415 | | |||
374 | if (d->bSkip) { | 416 | if (d->bSkip) { | ||
▲ Show 20 Lines • Show All 71 Lines • ▼ Show 20 Line(s) | |||||
446 | 488 | | |||
447 | // Rename | 489 | // Rename | ||
448 | void RenameDialog::renamePressed() | 490 | void RenameDialog::renamePressed() | ||
449 | { | 491 | { | ||
450 | if (d->m_pLineEdit->text().isEmpty()) { | 492 | if (d->m_pLineEdit->text().isEmpty()) { | ||
451 | return; | 493 | return; | ||
452 | } | 494 | } | ||
453 | 495 | | |||
454 | if (d->bApplyAll && d->bApplyAll->isChecked()) { | 496 | if (d->m_applyOptions && d->m_applyOptions->currentIndex() == RenameDialogPrivate::ApplyAll) { | ||
455 | done(Result_AutoRename); | 497 | done(Result_AutoRename); | ||
456 | } else { | 498 | } else { | ||
457 | const QUrl u = newDestUrl(); | 499 | const QUrl u = newDestUrl(); | ||
458 | if (!u.isValid()) { | 500 | if (!u.isValid()) { | ||
459 | KMessageBox::error(this, i18n("Malformed URL\n%1", u.errorString())); | 501 | KMessageBox::error(this, i18n("Malformed URL\n%1", u.errorString())); | ||
460 | qCWarning(KIO_WIDGETS) << u.errorString(); | 502 | qCWarning(KIO_WIDGETS) << u.errorString(); | ||
461 | return; | 503 | return; | ||
462 | } | 504 | } | ||
Show All 18 Lines | 519 | { | |||
481 | } | 523 | } | ||
482 | 524 | | |||
483 | QUrl destDirectory = d->dest.adjusted(QUrl::RemoveFilename | QUrl::StripTrailingSlash); | 525 | QUrl destDirectory = d->dest.adjusted(QUrl::RemoveFilename | QUrl::StripTrailingSlash); | ||
484 | d->setRenameBoxText(KIO::suggestName(destDirectory, d->m_pLineEdit->text())); | 526 | d->setRenameBoxText(KIO::suggestName(destDirectory, d->m_pLineEdit->text())); | ||
485 | } | 527 | } | ||
486 | 528 | | |||
487 | void RenameDialog::skipPressed() | 529 | void RenameDialog::skipPressed() | ||
488 | { | 530 | { | ||
489 | if (d->bApplyAll && d->bApplyAll->isChecked()) { | 531 | if (d->m_applyOptions && d->m_applyOptions->currentIndex() == RenameDialogPrivate::ApplyAll) { | ||
490 | done(Result_AutoSkip); | 532 | done(Result_AutoSkip); | ||
491 | } else { | 533 | } else { | ||
492 | done(Result_Skip); | 534 | done(Result_Skip); | ||
493 | } | 535 | } | ||
494 | } | 536 | } | ||
495 | 537 | | |||
496 | void RenameDialog::autoSkipPressed() | 538 | void RenameDialog::autoSkipPressed() | ||
497 | { | 539 | { | ||
498 | done(Result_AutoSkip); | 540 | done(Result_AutoSkip); | ||
499 | } | 541 | } | ||
500 | 542 | | |||
501 | void RenameDialog::overwritePressed() | 543 | void RenameDialog::overwritePressed() | ||
502 | { | 544 | { | ||
503 | if (d->bApplyAll && d->bApplyAll->isChecked()) { | 545 | if (d->m_applyOptions) { | ||
546 | RenameDialogPrivate::ApplyOptions opt = d->indexToOption(d->m_applyOptions->currentIndex()); | ||||
547 | if (opt == RenameDialogPrivate::ApplyAll) { | ||||
504 | done(Result_OverwriteAll); | 548 | done(Result_OverwriteAll); | ||
549 | } else if (opt == RenameDialogPrivate::ApplyOldDest) { | ||||
550 | done(Result_OverwriteOldDest); | ||||
551 | } else if (opt == RenameDialogPrivate::ApplyNewDest) { | ||||
552 | done(Result_OverwriteNewDest); | ||||
553 | } | ||||
505 | } else { | 554 | } else { | ||
506 | done(Result_Overwrite); | 555 | done(Result_Overwrite); | ||
507 | } | 556 | } | ||
508 | } | 557 | } | ||
509 | 558 | | |||
510 | void RenameDialog::overwriteAllPressed() | 559 | void RenameDialog::overwriteAllPressed() | ||
511 | { | 560 | { | ||
512 | done(Result_OverwriteAll); | 561 | done(Result_OverwriteAll); | ||
513 | } | 562 | } | ||
514 | 563 | | |||
515 | void RenameDialog::resumePressed() | 564 | void RenameDialog::resumePressed() | ||
516 | { | 565 | { | ||
517 | if (d->bApplyAll && d->bApplyAll->isChecked()) { | 566 | if (d->m_applyOptions && d->m_applyOptions->currentIndex() == RenameDialogPrivate::ApplyAll) { | ||
518 | done(Result_ResumeAll); | 567 | done(Result_ResumeAll); | ||
519 | } else { | 568 | } else { | ||
520 | done(Result_Resume); | 569 | done(Result_Resume); | ||
521 | } | 570 | } | ||
522 | } | 571 | } | ||
523 | 572 | | |||
524 | void RenameDialog::resumeAllPressed() | 573 | void RenameDialog::resumeAllPressed() | ||
525 | { | 574 | { | ||
526 | done(Result_ResumeAll); | 575 | done(Result_ResumeAll); | ||
527 | } | 576 | } | ||
528 | 577 | | |||
529 | void RenameDialog::applyAllPressed() | 578 | void RenameDialog::applyOptionChanged(int index) | ||
530 | { | 579 | { | ||
531 | if (d->bApplyAll && d->bApplyAll->isChecked()) { | 580 | RenameDialogPrivate::ApplyOptions opt = d->indexToOption(index); | ||
581 | if (opt != RenameDialogPrivate::ApplyCurrent) { | ||||
532 | d->m_pLineEdit->setText(KIO::decodeFileName(d->dest.fileName())); | 582 | d->m_pLineEdit->setText(KIO::decodeFileName(d->dest.fileName())); | ||
533 | d->m_pLineEdit->setEnabled(false); | 583 | d->m_pLineEdit->setEnabled(false); | ||
534 | 584 | | |||
585 | const bool applyAll = opt == RenameDialogPrivate::ApplyAll; | ||||
535 | if (d->bRename) { | 586 | if (d->bRename) { | ||
536 | d->bRename->setEnabled(true); | 587 | d->bRename->setEnabled(applyAll); | ||
537 | } | 588 | } | ||
538 | 589 | | |||
539 | if (d->bSuggestNewName) { | 590 | if (d->bSuggestNewName) { | ||
540 | d->bSuggestNewName->setEnabled(false); | 591 | d->bSuggestNewName->setEnabled(applyAll); | ||
592 | } | ||||
593 | | ||||
594 | if (d->bSkip) { | ||||
595 | d->bSkip->setEnabled(applyAll); | ||||
541 | } | 596 | } | ||
542 | } else { | 597 | } else { | ||
543 | d->m_pLineEdit->setEnabled(true); | 598 | d->m_pLineEdit->setEnabled(true); | ||
544 | 599 | | |||
545 | if (d->bRename) { | 600 | if (d->bRename) { | ||
546 | d->bRename->setEnabled(false); | 601 | d->bRename->setEnabled(false); | ||
547 | } | 602 | } | ||
548 | 603 | | |||
549 | if (d->bSuggestNewName) { | 604 | if (d->bSuggestNewName) { | ||
550 | d->bSuggestNewName->setEnabled(true); | 605 | d->bSuggestNewName->setEnabled(true); | ||
551 | } | 606 | } | ||
607 | | ||||
608 | if (d->bSkip) { | ||||
609 | d->bSkip->setEnabled(true); | ||||
610 | } | ||||
552 | } | 611 | } | ||
553 | } | 612 | } | ||
554 | 613 | | |||
555 | void RenameDialog::showSrcIcon(const KFileItem &fileitem) | 614 | void RenameDialog::showSrcIcon(const KFileItem &fileitem) | ||
556 | { | 615 | { | ||
557 | // The preview job failed, show a standard file icon. | 616 | // The preview job failed, show a standard file icon. | ||
558 | d->m_srcPendingPreview = false; | 617 | d->m_srcPendingPreview = false; | ||
559 | 618 | | |||
▲ Show 20 Lines • Show All 116 Lines • Show Last 20 Lines |