fix tricky regression noticed by Vyacheslav Tokarev on Google Reader.
[kdelibs.git] / kio / kio / jobuidelegate.cpp
blob24bd58f0d7f85a69ca3a31f82e408f1faf6a93f9
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"
24 #include <kdebug.h>
25 #include <kjob.h>
26 #include <klocale.h>
27 #include <kmessagebox.h>
28 #include <ksharedconfig.h>
30 #include <QPointer>
31 #include <QWidget>
33 #include "kio/scheduler.h"
35 #if defined Q_WS_X11
36 #include <QX11Info>
37 #include <netwm.h>
38 #endif
40 class KIO::JobUiDelegate::Private
42 public:
45 KIO::JobUiDelegate::JobUiDelegate()
46 : d(new Private())
50 KIO::JobUiDelegate::~JobUiDelegate()
52 delete d;
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,
63 const QString& src,
64 const QString & dest,
65 KIO::RenameDialog_Mode mode,
66 QString& newDest,
67 KIO::filesize_t sizeSrc,
68 KIO::filesize_t sizeDest,
69 time_t ctimeSrc,
70 time_t ctimeDest,
71 time_t mtimeSrc,
72 time_t mtimeDest)
74 Q_UNUSED(job);
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,
79 sizeSrc, sizeDest,
80 ctimeSrc, ctimeDest, mtimeSrc,
81 mtimeDest);
82 KIO::RenameDialog_Result res = static_cast<RenameDialog_Result>(dlg.exec());
83 newDest = dlg.newDestUrl().toLocalFile();
84 return res;
87 KIO::SkipDialog_Result KIO::JobUiDelegate::askSkip(KJob *,
88 bool multi,
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)
100 QString keyName;
101 bool ask = ( confirmationType == ForceConfirmation );
102 if (!ask) {
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);
110 if (ask) {
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);
119 } else {
120 prettyList.append(url.pathOrUrl());
124 QWidget* widget = window();
125 int result;
126 switch(deletionType) {
127 case Delete:
128 result = KMessageBox::warningContinueCancelList(
129 widget,
130 i18np("Do you really want to delete this item?", "Do you really want to delete these %1 items?", prettyList.count()),
131 prettyList,
132 i18n("Delete Files"),
133 KStandardGuiItem::del(),
134 KStandardGuiItem::cancel(),
135 keyName, KMessageBox::Notify);
136 break;
138 case Trash:
139 default:
140 result = KMessageBox::warningContinueCancelList(
141 widget,
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()),
143 prettyList,
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);
163 return true;
166 #include "jobuidelegate.moc"