1/*
2 This file is part of the KDE libraries
3 SPDX-FileCopyrightText: 2000 David Faure <faure@kde.org>
4
5 SPDX-License-Identifier: LGPL-2.0-only
6*/
7
8#include "kio/skipdialog.h"
9
10#include <assert.h>
11#include <stdio.h>
12
13#include <QDialogButtonBox>
14#include <QLabel>
15#include <QPushButton>
16#include <QVBoxLayout>
17#include <QWidget>
18
19#include <KGuiItem>
20#include <KLocalizedString>
21#include <KStandardGuiItem>
22
23using namespace KIO;
24
25SkipDialog::SkipDialog(QWidget *parent, KIO::SkipDialog_Options options, const QString &_error_text)
26 : QDialog(parent)
27 , d(nullptr)
28{
29 setWindowTitle(i18n("Information"));
30
31 QVBoxLayout *layout = new QVBoxLayout(this);
32
33 auto *label = new QLabel(_error_text, this);
34 label->setWordWrap(true);
35 layout->addWidget(label);
36
37 QDialogButtonBox *buttonBox = new QDialogButtonBox(this);
38 layout->addWidget(buttonBox);
39
40 const bool isMultiple = options & SkipDialog_MultipleItems;
41 const bool isInvalidChars = options & SkipDialog_Replace_Invalid_Chars;
42 const bool hideRetry = options & SkipDialog_Hide_Retry;
43
44 // Retrying to e.g. copy a file with "*" in the name to a fat32
45 // partition will always fail
46 if (isInvalidChars) {
47 QPushButton *replaceCharButton = new QPushButton(i18n("Replace"));
48 connect(sender: replaceCharButton, signal: &QAbstractButton::clicked, context: this, slot: [this]() {
49 done(KIO::Result_ReplaceInvalidChars);
50 });
51 buttonBox->addButton(button: replaceCharButton, role: QDialogButtonBox::ActionRole);
52 } else if (!hideRetry) {
53 QPushButton *retryButton = new QPushButton(i18n("Retry"));
54 connect(sender: retryButton, signal: &QAbstractButton::clicked, context: this, slot: &SkipDialog::retryPressed);
55 buttonBox->addButton(button: retryButton, role: QDialogButtonBox::ActionRole);
56 }
57
58 if (isMultiple) {
59 if (isInvalidChars) {
60 QPushButton *autoReplaceButton = new QPushButton(i18n("Replace All"));
61 connect(sender: autoReplaceButton, signal: &QAbstractButton::clicked, context: this, slot: [this]() {
62 done(KIO::Result_ReplaceAllInvalidChars);
63 });
64 buttonBox->addButton(button: autoReplaceButton, role: QDialogButtonBox::ActionRole);
65 }
66
67 QPushButton *skipButton = new QPushButton(i18n("Skip"));
68 connect(sender: skipButton, signal: &QAbstractButton::clicked, context: this, slot: &SkipDialog::skipPressed);
69 buttonBox->addButton(button: skipButton, role: QDialogButtonBox::ActionRole);
70
71 QPushButton *autoSkipButton = new QPushButton(i18n("Skip All"));
72 connect(sender: autoSkipButton, signal: &QAbstractButton::clicked, context: this, slot: &SkipDialog::autoSkipPressed);
73 buttonBox->addButton(button: autoSkipButton, role: QDialogButtonBox::ActionRole);
74 }
75
76 auto *cancelBtn = buttonBox->addButton(button: QDialogButtonBox::Cancel);
77 // If it's one item and the Retry button is hidden, replace the Cancel
78 // button text with OK
79 if (hideRetry && !isMultiple) {
80 KGuiItem::assign(button: cancelBtn, item: KStandardGuiItem::ok());
81 }
82 connect(sender: buttonBox, signal: &QDialogButtonBox::rejected, context: this, slot: &SkipDialog::cancelPressed);
83
84 resize(sizeHint());
85}
86
87SkipDialog::~SkipDialog()
88{
89}
90
91void SkipDialog::cancelPressed()
92{
93 done(KIO::Result_Cancel);
94}
95
96void SkipDialog::skipPressed()
97{
98 done(KIO::Result_Skip);
99}
100
101void SkipDialog::autoSkipPressed()
102{
103 done(KIO::Result_AutoSkip);
104}
105
106void SkipDialog::retryPressed()
107{
108 done(KIO::Result_Retry);
109}
110
111#include "moc_skipdialog.cpp"
112

source code of kio/src/widgets/skipdialog.cpp