KIO

skipdialog.cpp
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->setTextFormat(Qt::PlainText);
35 label->setWordWrap(true);
36 layout->addWidget(label);
37
38 QDialogButtonBox *buttonBox = new QDialogButtonBox(this);
39 layout->addWidget(buttonBox);
40
41 const bool isMultiple = options & SkipDialog_MultipleItems;
42 const bool isInvalidChars = options & SkipDialog_Replace_Invalid_Chars;
43 const bool hideRetry = options & SkipDialog_Hide_Retry;
44
45 // Retrying to e.g. copy a file with "*" in the name to a fat32
46 // partition will always fail
47 if (isInvalidChars) {
48 QPushButton *replaceCharButton = new QPushButton(i18n("Replace"));
49 connect(replaceCharButton, &QAbstractButton::clicked, this, [this]() {
51 });
52 buttonBox->addButton(replaceCharButton, QDialogButtonBox::ActionRole);
53 } else if (!hideRetry) {
54 QPushButton *retryButton = new QPushButton(i18n("Retry"));
55 connect(retryButton, &QAbstractButton::clicked, this, &SkipDialog::retryPressed);
56 buttonBox->addButton(retryButton, QDialogButtonBox::ActionRole);
57 }
58
59 if (isMultiple) {
60 if (isInvalidChars) {
61 QPushButton *autoReplaceButton = new QPushButton(i18n("Replace All"));
62 connect(autoReplaceButton, &QAbstractButton::clicked, this, [this]() {
64 });
65 buttonBox->addButton(autoReplaceButton, QDialogButtonBox::ActionRole);
66 }
67
68 QPushButton *skipButton = new QPushButton(i18n("Skip"));
69 connect(skipButton, &QAbstractButton::clicked, this, &SkipDialog::skipPressed);
70 buttonBox->addButton(skipButton, QDialogButtonBox::ActionRole);
71
72 QPushButton *autoSkipButton = new QPushButton(i18n("Skip All"));
73 connect(autoSkipButton, &QAbstractButton::clicked, this, &SkipDialog::autoSkipPressed);
74 buttonBox->addButton(autoSkipButton, QDialogButtonBox::ActionRole);
75 }
76
77 auto *cancelBtn = buttonBox->addButton(QDialogButtonBox::Cancel);
78 // If it's one item and the Retry button is hidden, replace the Cancel
79 // button text with OK
80 if (hideRetry && !isMultiple) {
82 }
83 connect(buttonBox, &QDialogButtonBox::rejected, this, &SkipDialog::cancelPressed);
84
85 resize(sizeHint());
86}
87
88SkipDialog::~SkipDialog()
89{
90}
91
92void SkipDialog::cancelPressed()
93{
94 done(KIO::Result_Cancel);
95}
96
97void SkipDialog::skipPressed()
98{
99 done(KIO::Result_Skip);
100}
101
102void SkipDialog::autoSkipPressed()
103{
104 done(KIO::Result_AutoSkip);
105}
106
107void SkipDialog::retryPressed()
108{
109 done(KIO::Result_Retry);
110}
111
112#include "moc_skipdialog.cpp"
static void assign(QPushButton *button, const KGuiItem &item)
QString i18n(const char *text, const TYPE &arg...)
A namespace for KIO globals.
@ SkipDialog_MultipleItems
Set if the current operation concerns multiple files, so it makes sense to offer buttons that apply t...
@ SkipDialog_Hide_Retry
Set if the current operation cannot be retried.
@ SkipDialog_Replace_Invalid_Chars
Set if the current operation involves copying files/folders with certain characters in their names th...
@ Result_ReplaceAllInvalidChars
The same as Result_ReplaceInvalidChars, but the user selected to automatically replace any invalid ch...
@ Result_ReplaceInvalidChars
Can be returned if the user selects to replace any character disallowed by the destination filesystem...
QFlags< SkipDialog_Option > SkipDialog_Options
Stores a combination of SkipDialog_Option values.
QString label(StandardShortcut id)
void clicked(bool checked)
void addWidget(QWidget *widget, int stretch, Qt::Alignment alignment)
virtual void done(int r)
QPushButton * addButton(StandardButton button)
PlainText
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Apr 11 2025 11:51:43 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.