• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

KIO

  • kio
  • kio
jobuidelegate.cpp
Go to the documentation of this file.
1/* This file is part of the KDE libraries
2 Copyright (C) 2000 Stephan Kulow <coolo@kde.org>
3 David Faure <faure@kde.org>
4 Copyright (C) 2006 Kevin Ottens <ervin@kde.org>
5 Copyright (C) 2013 Dawit Alemayehu <adawit@kde.org>
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details.
16
17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA.
21*/
22
23#include "jobuidelegate.h"
24
25#include <kdebug.h>
26#include <kjob.h>
27#include <klocale.h>
28#include <kmessagebox.h>
29#include <ksharedconfig.h>
30#include <ksslinfodialog.h>
31#include <kmessage.h>
32
33#include <QPointer>
34#include <QWidget>
35
36#include "kio/scheduler.h"
37
38#if defined Q_WS_X11
39#include <QX11Info>
40#include <netwm.h>
41#endif
42
43class KIO::JobUiDelegate::Private
44{
45public:
46};
47
48KIO::JobUiDelegate::JobUiDelegate()
49 : d(new Private())
50{
51}
52
53KIO::JobUiDelegate::~JobUiDelegate()
54{
55 delete d;
56}
57
58void KIO::JobUiDelegate::setWindow(QWidget *window)
59{
60 KDialogJobUiDelegate::setWindow(window);
61 KIO::Scheduler::registerWindow(window);
62}
63
64KIO::RenameDialog_Result KIO::JobUiDelegate::askFileRename(KJob * job,
65 const QString & caption,
66 const QString& src,
67 const QString & dest,
68 KIO::RenameDialog_Mode mode,
69 QString& newDest,
70 KIO::filesize_t sizeSrc,
71 KIO::filesize_t sizeDest,
72 time_t ctimeSrc,
73 time_t ctimeDest,
74 time_t mtimeSrc,
75 time_t mtimeDest)
76{
77 Q_UNUSED(job);
78 //kDebug() << "job=" << job;
79 // We now do it in process, so that opening the rename dialog
80 // doesn't start uiserver for nothing if progressId=0 (e.g. F2 in konq)
81 KIO::RenameDialog dlg( window(), caption, src, dest, mode,
82 sizeSrc, sizeDest,
83 ctimeSrc, ctimeDest, mtimeSrc,
84 mtimeDest);
85 dlg.setWindowModality(Qt::WindowModal);
86 connect(job, SIGNAL(finished(KJob*)), &dlg, SLOT(reject())); // #192976
87 KIO::RenameDialog_Result res = static_cast<RenameDialog_Result>(dlg.exec());
88 if (res == R_AUTO_RENAME) {
89 newDest = dlg.autoDestUrl().path();
90 }
91 else {
92 newDest = dlg.newDestUrl().path();
93 }
94 return res;
95}
96
97KIO::SkipDialog_Result KIO::JobUiDelegate::askSkip(KJob *job,
98 bool multi,
99 const QString & error_text)
100{
101 // We now do it in process. So this method is a useless wrapper around KIO::open_RenameDialog.
102 KIO::SkipDialog dlg( window(), multi, error_text );
103 dlg.setWindowModality(Qt::WindowModal);
104 connect(job, SIGNAL(finished(KJob*)), &dlg, SLOT(reject())); // #192976
105 return static_cast<KIO::SkipDialog_Result>(dlg.exec());
106}
107
108bool KIO::JobUiDelegate::askDeleteConfirmation(const KUrl::List& urls,
109 DeletionType deletionType,
110 ConfirmationType confirmationType)
111{
112 QString keyName;
113 bool ask = ( confirmationType == ForceConfirmation );
114 if (!ask) {
115 KSharedConfigPtr kioConfig = KSharedConfig::openConfig("kiorc", KConfig::NoGlobals);
116
117 switch (deletionType ) {
118 case Delete:
119 keyName = "ConfirmDelete" ;
120 break;
121 case Trash:
122 keyName = "ConfirmTrash" ;
123 break;
124 case EmptyTrash:
125 keyName = "ConfirmEmptyTrash" ;
126 break;
127 }
128
129 // The default value for confirmations is true (for both delete and trash)
130 // If you change this, update kdebase/apps/konqueror/settings/konq/behaviour.cpp
131 const bool defaultValue = true;
132 ask = kioConfig->group("Confirmations").readEntry(keyName, defaultValue);
133 }
134 if (ask) {
135 QStringList prettyList;
136 Q_FOREACH(const KUrl& url, urls) {
137 if ( url.protocol() == "trash" ) {
138 QString path = url.path();
139 // HACK (#98983): remove "0-foo". Note that it works better than
140 // displaying KFileItem::name(), for files under a subdir.
141 path.remove(QRegExp("^/[0-9]*-"));
142 prettyList.append(path);
143 } else {
144 prettyList.append(url.pathOrUrl());
145 }
146 }
147
148 int result;
149 QWidget* widget = window();
150 const KMessageBox::Options options = KMessageBox::Notify | KMessageBox::WindowModal;
151 switch(deletionType) {
152 case Delete:
153 result = KMessageBox::warningContinueCancelList(
154 widget,
155 i18np("Do you really want to delete this item?", "Do you really want to delete these %1 items?", prettyList.count()),
156 prettyList,
157 i18n("Delete Files"),
158 KStandardGuiItem::del(),
159 KStandardGuiItem::cancel(),
160 keyName, options);
161 break;
162 case EmptyTrash:
163 result = KMessageBox::warningContinueCancel(
164 widget,
165 i18nc("@info", "Do you want to permanently delete all items from Trash? This action cannot be undone."),
166 QString(),
167 KGuiItem(i18nc("@action:button", "Empty Trash"),
168 KIcon("user-trash")),
169 KStandardGuiItem::cancel(),
170 keyName, options);
171 break;
172 case Trash:
173 default:
174 result = KMessageBox::warningContinueCancelList(
175 widget,
176 i18np("Do you really want to move this item to the trash?", "Do you really want to move these %1 items to the trash?", prettyList.count()),
177 prettyList,
178 i18n("Move to Trash"),
179 KGuiItem(i18nc("Verb", "&Trash"), "user-trash"),
180 KStandardGuiItem::cancel(),
181 keyName, options);
182 }
183 if (!keyName.isEmpty()) {
184 // Check kmessagebox setting... erase & copy to konquerorrc.
185 KSharedConfig::Ptr config = KGlobal::config();
186 KConfigGroup notificationGroup(config, "Notification Messages");
187 if (!notificationGroup.readEntry(keyName, true)) {
188 notificationGroup.writeEntry(keyName, true);
189 notificationGroup.sync();
190
191 KSharedConfigPtr kioConfig = KSharedConfig::openConfig("kiorc", KConfig::NoGlobals);
192 kioConfig->group("Confirmations").writeEntry(keyName, false);
193 }
194 }
195 return (result == KMessageBox::Continue);
196 }
197 return true;
198}
199
200int KIO::JobUiDelegate::requestMessageBox(KIO::JobUiDelegate::MessageBoxType type,
201 const QString& text, const QString& caption,
202 const QString& buttonYes, const QString& buttonNo,
203 const QString& iconYes, const QString& iconNo,
204 const QString& dontAskAgainName,
205 const KIO::MetaData& sslMetaData)
206{
207 int result = -1;
208
209 //kDebug() << type << text << "caption=" << caption;
210
211 KConfig config("kioslaverc");
212 KMessageBox::setDontShowAskAgainConfig(&config);
213
214 const KGuiItem buttonYesGui (buttonYes, iconYes);
215 const KGuiItem buttonNoGui (buttonNo, iconNo);
216 KMessageBox::Options options = (KMessageBox::Notify | KMessageBox::WindowModal);
217
218 switch (type) {
219 case QuestionYesNo:
220 result = KMessageBox::questionYesNo(
221 window(), text, caption, buttonYesGui,
222 buttonNoGui, dontAskAgainName, options);
223 break;
224 case WarningYesNo:
225 result = KMessageBox::warningYesNo(
226 window(), text, caption, buttonYesGui,
227 buttonNoGui, dontAskAgainName,
228 options | KMessageBox::Dangerous);
229 break;
230 case WarningYesNoCancel:
231 result = KMessageBox::warningYesNoCancel(
232 window(), text, caption, buttonYesGui, buttonNoGui,
233 KStandardGuiItem::cancel(), dontAskAgainName, options);
234 break;
235 case WarningContinueCancel:
236 result = KMessageBox::warningContinueCancel(
237 window(), text, caption, buttonYesGui,
238 KStandardGuiItem::cancel(), dontAskAgainName, options);
239 break;
240 case Information:
241 KMessageBox::information(window(), text, caption, dontAskAgainName, options);
242 result = 1; // whatever
243 break;
244 case SSLMessageBox:
245 {
246 QPointer<KSslInfoDialog> kid (new KSslInfoDialog(window()));
247 //### this is boilerplate code and appears in khtml_part.cpp almost unchanged!
248 const QStringList sl = sslMetaData.value(QLatin1String("ssl_peer_chain")).split('\x01', QString::SkipEmptyParts);
249 QList<QSslCertificate> certChain;
250 bool decodedOk = true;
251 foreach (const QString &s, sl) {
252 certChain.append(QSslCertificate(s.toLatin1())); //or is it toLocal8Bit or whatever?
253 if (certChain.last().isNull()) {
254 decodedOk = false;
255 break;
256 }
257 }
258
259 if (decodedOk) {
260 result = 1; // whatever
261 kid->setSslInfo(certChain,
262 sslMetaData.value(QLatin1String("ssl_peer_ip")),
263 text, // the URL
264 sslMetaData.value(QLatin1String("ssl_protocol_version")),
265 sslMetaData.value(QLatin1String("ssl_cipher")),
266 sslMetaData.value(QLatin1String("ssl_cipher_used_bits")).toInt(),
267 sslMetaData.value(QLatin1String("ssl_cipher_bits")).toInt(),
268 KSslInfoDialog::errorsFromString(sslMetaData.value(QLatin1String("ssl_cert_errors"))));
269 kid->exec();
270 } else {
271 result = -1;
272 KMessageBox::information(window(),
273 i18n("The peer SSL certificate chain appears to be corrupt."),
274 i18n("SSL"), QString(), options);
275 }
276 // KSslInfoDialog deletes itself (Qt::WA_DeleteOnClose).
277 delete kid;
278 break;
279 }
280 default:
281 kWarning() << "Unknown type" << type;
282 result = 0;
283 break;
284 }
285 KMessageBox::setDontShowAskAgainConfig(0);
286 return result;
287}
288
289#include "jobuidelegate.moc"
KConfigGroup
KConfigGroup::writeEntry
void writeEntry(const char *key, const char *value, WriteConfigFlags pFlags=Normal)
KConfigGroup::readEntry
QString readEntry(const char *key, const char *aDefault=0) const
KConfigGroup::sync
void sync()
KConfig
KConfig::NoGlobals
NoGlobals
KDialogJobUiDelegate::setWindow
virtual void setWindow(QWidget *window)
KGuiItem
KIO::JobUiDelegate::askDeleteConfirmation
bool askDeleteConfirmation(const KUrl::List &urls, DeletionType deletionType, ConfirmationType confirmationType)
Ask for confirmation before deleting/trashing urls.
Definition: jobuidelegate.cpp:108
KIO::JobUiDelegate::~JobUiDelegate
virtual ~JobUiDelegate()
Destroys the KIO Job UI delegate.
Definition: jobuidelegate.cpp:53
KIO::JobUiDelegate::JobUiDelegate
JobUiDelegate()
Constructs a new KIO Job UI delegate.
Definition: jobuidelegate.cpp:48
KIO::JobUiDelegate::ConfirmationType
ConfirmationType
ForceConfirmation: always ask the user for confirmation DefaultConfirmation: don't ask the user if he...
Definition: jobuidelegate.h:116
KIO::JobUiDelegate::DeletionType
DeletionType
The type of deletion: real deletion, moving the files to the trash or emptying the trash Used by askD...
Definition: jobuidelegate.h:109
KIO::JobUiDelegate::setWindow
virtual void setWindow(QWidget *window)
Associate this job with a window given by window.
Definition: jobuidelegate.cpp:58
KIO::JobUiDelegate::requestMessageBox
int requestMessageBox(MessageBoxType type, const QString &text, const QString &caption, const QString &buttonYes, const QString &buttonNo, const QString &iconYes=QString(), const QString &iconNo=QString(), const QString &dontAskAgainName=QString(), const KIO::MetaData &sslMetaData=KIO::MetaData())
This function allows for the delegation user prompts from the ioslaves.
Definition: jobuidelegate.cpp:200
KIO::JobUiDelegate::askSkip
virtual SkipDialog_Result askSkip(KJob *job, bool multi, const QString &error_text)
Definition: jobuidelegate.cpp:97
KIO::JobUiDelegate::askFileRename
virtual RenameDialog_Result askFileRename(KJob *job, const QString &caption, const QString &src, const QString &dest, KIO::RenameDialog_Mode mode, QString &newDest, KIO::filesize_t sizeSrc=KIO::filesize_t(-1), KIO::filesize_t sizeDest=KIO::filesize_t(-1), time_t ctimeSrc=time_t(-1), time_t ctimeDest=time_t(-1), time_t mtimeSrc=time_t(-1), time_t mtimeDest=time_t(-1))
Construct a modal, parent-less "rename" dialog, and return a result code, as well as the new dest.
Definition: jobuidelegate.cpp:64
KIO::JobUiDelegate::MessageBoxType
MessageBoxType
Message box types.
Definition: jobuidelegate.h:141
KIO::MetaData
MetaData is a simple map of key/value strings.
Definition: global.h:397
KIO::RenameDialog
The dialog shown when a CopyJob realizes that a destination file already exists, and wants to offer t...
Definition: renamedialog.h:71
KIO::RenameDialog::autoDestUrl
KUrl autoDestUrl() const
Definition: renamedialog.cpp:382
KIO::RenameDialog::newDestUrl
KUrl newDestUrl()
Definition: renamedialog.cpp:372
KIO::Scheduler::registerWindow
static void registerWindow(QWidget *wid)
Register the mainwindow wid with the KIO subsystem Do not call this, it is called automatically from ...
Definition: scheduler.cpp:861
KIO::SkipDialog
Definition: skipdialog.h:36
KIcon
KJob
KMessageBox::warningYesNoCancel
static int warningYesNoCancel(QWidget *parent, const QString &text, const QString &caption=QString(), const KGuiItem &buttonYes=KStandardGuiItem::yes(), const KGuiItem &buttonNo=KStandardGuiItem::no(), const KGuiItem &buttonCancel=KStandardGuiItem::cancel(), const QString &dontAskAgainName=QString(), Options options=Notify)
KMessageBox::warningContinueCancelList
static int warningContinueCancelList(QWidget *parent, const QString &text, const QStringList &strlist, const QString &caption=QString(), const KGuiItem &buttonContinue=KStandardGuiItem::cont(), const KGuiItem &buttonCancel=KStandardGuiItem::cancel(), const QString &dontAskAgainName=QString(), Options options=Notify)
KMessageBox::setDontShowAskAgainConfig
static void setDontShowAskAgainConfig(KConfig *cfg)
KMessageBox::warningContinueCancel
static int warningContinueCancel(QWidget *parent, const QString &text, const QString &caption=QString(), const KGuiItem &buttonContinue=KStandardGuiItem::cont(), const KGuiItem &buttonCancel=KStandardGuiItem::cancel(), const QString &dontAskAgainName=QString(), Options options=Notify)
KMessageBox::Continue
Continue
KMessageBox::information
static void information(QWidget *parent, const QString &text, const QString &caption=QString(), const QString &dontShowAgainName=QString(), Options options=Notify)
KMessageBox::Notify
Notify
KMessageBox::WindowModal
WindowModal
KMessageBox::Dangerous
Dangerous
KMessageBox::questionYesNo
static int questionYesNo(QWidget *parent, const QString &text, const QString &caption=QString(), const KGuiItem &buttonYes=KStandardGuiItem::yes(), const KGuiItem &buttonNo=KStandardGuiItem::no(), const QString &dontAskAgainName=QString(), Options options=Notify)
KMessageBox::warningYesNo
static int warningYesNo(QWidget *parent, const QString &text, const QString &caption=QString(), const KGuiItem &buttonYes=KStandardGuiItem::yes(), const KGuiItem &buttonNo=KStandardGuiItem::no(), const QString &dontAskAgainName=QString(), Options options=Options(Notify|Dangerous))
KSharedConfig::openConfig
static KSharedConfig::Ptr openConfig(const KComponentData &componentData, const QString &fileName=QString(), OpenFlags mode=FullConfig, const char *resourceType="config")
KSharedPtr< KSharedConfig >
KSslInfoDialog
KDE SSL Information Dialog.
Definition: ksslinfodialog.h:43
KSslInfoDialog::errorsFromString
static QList< QList< KSslError::Error > > errorsFromString(const QString &s)
Definition: ksslinfodialog.cpp:232
KUrl::List
KUrl
KUrl::pathOrUrl
QString pathOrUrl() const
KUrl::path
QString path(AdjustPathOption trailing=LeaveTrailingSlash) const
KUrl::protocol
QString protocol() const
QList
QWidget
kWarning
#define kWarning
jobuidelegate.h
defaultValue
QString defaultValue(const QString &t)
kdebug.h
kjob.h
klocale.h
i18n
QString i18n(const char *text)
i18np
QString i18np(const char *sing, const char *plur, const A1 &a1)
i18nc
QString i18nc(const char *ctxt, const char *text)
kmessage.h
kmessagebox.h
ksharedconfig.h
ksslinfodialog.h
caption
QString caption()
config
KSharedConfigPtr config()
KIO::SkipDialog_Result
SkipDialog_Result
Definition: skipdialog.h:29
KIO::RenameDialog_Result
RenameDialog_Result
The result of open_RenameDialog().
Definition: renamedialog.h:61
KIO::R_AUTO_RENAME
@ R_AUTO_RENAME
Definition: renamedialog.h:61
KIO::RenameDialog_Mode
RenameDialog_Mode
M_OVERWRITE: We have an existing dest, show details about it and offer to overwrite it.
Definition: renamedialog.h:56
KIO::filesize_t
qulonglong filesize_t
64-bit file size
Definition: global.h:57
Information
Information
KStandardGuiItem::cancel
KGuiItem cancel()
KStandardGuiItem::del
KGuiItem del()
Delete
Delete
netwm.h
scheduler.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KIO

Skip menu "KIO"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal