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->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(replaceCharButton, &QAbstractButton::clicked, this, [this]() {
50 });
51 buttonBox->addButton(replaceCharButton, QDialogButtonBox::ActionRole);
52 } else if (!hideRetry) {
53 QPushButton *retryButton = new QPushButton(i18n("Retry"));
54 connect(retryButton, &QAbstractButton::clicked, this, &SkipDialog::retryPressed);
55 buttonBox->addButton(retryButton, QDialogButtonBox::ActionRole);
56 }
57
58 if (isMultiple) {
59 if (isInvalidChars) {
60 QPushButton *autoReplaceButton = new QPushButton(i18n("Replace All"));
61 connect(autoReplaceButton, &QAbstractButton::clicked, this, [this]() {
63 });
64 buttonBox->addButton(autoReplaceButton, QDialogButtonBox::ActionRole);
65 }
66
67 QPushButton *skipButton = new QPushButton(i18n("Skip"));
68 connect(skipButton, &QAbstractButton::clicked, this, &SkipDialog::skipPressed);
69 buttonBox->addButton(skipButton, QDialogButtonBox::ActionRole);
70
71 QPushButton *autoSkipButton = new QPushButton(i18n("Skip All"));
72 connect(autoSkipButton, &QAbstractButton::clicked, this, &SkipDialog::autoSkipPressed);
73 buttonBox->addButton(autoSkipButton, QDialogButtonBox::ActionRole);
74 }
75
76 auto *cancelBtn = buttonBox->addButton(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) {
81 }
82 connect(buttonBox, &QDialogButtonBox::rejected, this, &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"
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...
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)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 20 2024 11:49:56 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.