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>
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA.
22 #include "jobuidelegate.h"
27 #include <kmessagebox.h>
28 #include <ksharedconfig.h>
33 #include "kio/scheduler.h"
40 class KIO::JobUiDelegate::Private
45 KIO::JobUiDelegate::JobUiDelegate()
50 KIO::JobUiDelegate::~JobUiDelegate()
55 void KIO::JobUiDelegate::setWindow(QWidget
*window
)
57 KDialogJobUiDelegate::setWindow(window
);
58 KIO::Scheduler::registerWindow(window
);
61 KIO::RenameDialog_Result
KIO::JobUiDelegate::askFileRename(KJob
* job
,
62 const QString
& caption
,
65 KIO::RenameDialog_Mode mode
,
67 KIO::filesize_t sizeSrc
,
68 KIO::filesize_t sizeDest
,
75 //kDebug() << "job=" << job;
76 // We now do it in process, so that opening the rename dialog
77 // doesn't start uiserver for nothing if progressId=0 (e.g. F2 in konq)
78 KIO::RenameDialog
dlg( window(), caption
, src
, dest
, mode
,
80 ctimeSrc
, ctimeDest
, mtimeSrc
,
82 KIO::RenameDialog_Result res
= static_cast<RenameDialog_Result
>(dlg
.exec());
83 newDest
= dlg
.newDestUrl().toLocalFile();
87 KIO::SkipDialog_Result
KIO::JobUiDelegate::askSkip(KJob
*,
89 const QString
& error_text
)
91 // We now do it in process. So this method is a useless wrapper around KIO::open_RenameDialog.
92 KIO::SkipDialog
dlg( window(), multi
, error_text
);
93 return static_cast<KIO::SkipDialog_Result
>(dlg
.exec());
96 bool KIO::JobUiDelegate::askDeleteConfirmation(const KUrl::List
& urls
,
97 DeletionType deletionType
,
98 ConfirmationType confirmationType
)
101 bool ask
= ( confirmationType
== ForceConfirmation
);
103 KSharedConfigPtr kioConfig
= KSharedConfig::openConfig("kiorc", KConfig::NoGlobals
);
104 keyName
= (deletionType
== Delete
? "ConfirmDelete" : "ConfirmTrash");
105 // The default value for confirmations is true (for both delete and trash)
106 // If you change this, update kdebase/apps/konqueror/settings/konq/behaviour.cpp
107 const bool defaultValue
= true;
108 ask
= kioConfig
->group("Confirmations").readEntry(keyName
, defaultValue
);
111 QStringList prettyList
;
112 Q_FOREACH(const KUrl
& url
, urls
) {
113 if ( url
.protocol() == "trash" ) {
114 QString path
= url
.path();
115 // HACK (#98983): remove "0-foo". Note that it works better than
116 // displaying KFileItem::name(), for files under a subdir.
117 path
.remove(QRegExp("^/[0-9]*-"));
118 prettyList
.append(path
);
120 prettyList
.append(url
.pathOrUrl());
124 QWidget
* widget
= window();
126 switch(deletionType
) {
128 result
= KMessageBox::warningContinueCancelList(
130 i18np("Do you really want to delete this item?", "Do you really want to delete these %1 items?", prettyList
.count()),
132 i18n("Delete Files"),
133 KStandardGuiItem::del(),
134 KStandardGuiItem::cancel(),
135 keyName
, KMessageBox::Notify
);
140 result
= KMessageBox::warningContinueCancelList(
142 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()),
144 i18n("Move to Trash"),
145 KGuiItem(i18nc("Verb", "&Trash"), "user-trash"),
146 KStandardGuiItem::cancel(),
147 keyName
, KMessageBox::Notify
);
149 if (!keyName
.isEmpty()) {
150 // Check kmessagebox setting... erase & copy to konquerorrc.
151 KSharedConfig::Ptr config
= KGlobal::config();
152 KConfigGroup
notificationGroup(config
, "Notification Messages");
153 if (!notificationGroup
.readEntry(keyName
, true)) {
154 notificationGroup
.writeEntry(keyName
, true);
155 notificationGroup
.sync();
157 KSharedConfigPtr kioConfig
= KSharedConfig::openConfig("kiorc", KConfig::NoGlobals
);
158 kioConfig
->group("Confirmations").writeEntry(keyName
, false);
161 return (result
== KMessageBox::Continue
);
166 #include "jobuidelegate.moc"