• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.11.5 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 
43 class KIO::JobUiDelegate::Private
44 {
45 public:
46 };
47 
48 KIO::JobUiDelegate::JobUiDelegate()
49  : d(new Private())
50 {
51 }
52 
53 KIO::JobUiDelegate::~JobUiDelegate()
54 {
55  delete d;
56 }
57 
58 void KIO::JobUiDelegate::setWindow(QWidget *window)
59 {
60  KDialogJobUiDelegate::setWindow(window);
61  KIO::Scheduler::registerWindow(window);
62 }
63 
64 KIO::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  connect(job, SIGNAL(finished(KJob*)), &dlg, SLOT(reject())); // #192976
86  KIO::RenameDialog_Result res = static_cast<RenameDialog_Result>(dlg.exec());
87  if (res == R_AUTO_RENAME) {
88  newDest = dlg.autoDestUrl().path();
89  }
90  else {
91  newDest = dlg.newDestUrl().path();
92  }
93  return res;
94 }
95 
96 KIO::SkipDialog_Result KIO::JobUiDelegate::askSkip(KJob *job,
97  bool multi,
98  const QString & error_text)
99 {
100  // We now do it in process. So this method is a useless wrapper around KIO::open_RenameDialog.
101  KIO::SkipDialog dlg( window(), multi, error_text );
102  connect(job, SIGNAL(finished(KJob*)), &dlg, SLOT(reject())); // #192976
103  return static_cast<KIO::SkipDialog_Result>(dlg.exec());
104 }
105 
106 bool KIO::JobUiDelegate::askDeleteConfirmation(const KUrl::List& urls,
107  DeletionType deletionType,
108  ConfirmationType confirmationType)
109 {
110  QString keyName;
111  bool ask = ( confirmationType == ForceConfirmation );
112  if (!ask) {
113  KSharedConfigPtr kioConfig = KSharedConfig::openConfig("kiorc", KConfig::NoGlobals);
114 
115  switch (deletionType ) {
116  case Delete:
117  keyName = "ConfirmDelete" ;
118  break;
119  case Trash:
120  keyName = "ConfirmTrash" ;
121  break;
122  case EmptyTrash:
123  keyName = "ConfirmEmptyTrash" ;
124  break;
125  }
126 
127  // The default value for confirmations is true (for both delete and trash)
128  // If you change this, update kdebase/apps/konqueror/settings/konq/behaviour.cpp
129  const bool defaultValue = true;
130  ask = kioConfig->group("Confirmations").readEntry(keyName, defaultValue);
131  }
132  if (ask) {
133  QStringList prettyList;
134  Q_FOREACH(const KUrl& url, urls) {
135  if ( url.protocol() == "trash" ) {
136  QString path = url.path();
137  // HACK (#98983): remove "0-foo". Note that it works better than
138  // displaying KFileItem::name(), for files under a subdir.
139  path.remove(QRegExp("^/[0-9]*-"));
140  prettyList.append(path);
141  } else {
142  prettyList.append(url.pathOrUrl());
143  }
144  }
145 
146  QWidget* widget = window();
147  int result;
148  switch(deletionType) {
149  case Delete:
150  result = KMessageBox::warningContinueCancelList(
151  widget,
152  i18np("Do you really want to delete this item?", "Do you really want to delete these %1 items?", prettyList.count()),
153  prettyList,
154  i18n("Delete Files"),
155  KStandardGuiItem::del(),
156  KStandardGuiItem::cancel(),
157  keyName, KMessageBox::Notify);
158  break;
159  case EmptyTrash:
160  result = KMessageBox::warningContinueCancel(
161  widget,
162  i18nc("@info", "Do you want to permanently delete all items from Trash? This action cannot be undone."),
163  QString(),
164  KGuiItem(i18nc("@action:button", "Empty Trash"),
165  KIcon("user-trash")),
166  KStandardGuiItem::cancel(),
167  keyName, KMessageBox::Notify);
168  break;
169  case Trash:
170  default:
171  result = KMessageBox::warningContinueCancelList(
172  widget,
173  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()),
174  prettyList,
175  i18n("Move to Trash"),
176  KGuiItem(i18nc("Verb", "&Trash"), "user-trash"),
177  KStandardGuiItem::cancel(),
178  keyName, KMessageBox::Notify);
179  }
180  if (!keyName.isEmpty()) {
181  // Check kmessagebox setting... erase & copy to konquerorrc.
182  KSharedConfig::Ptr config = KGlobal::config();
183  KConfigGroup notificationGroup(config, "Notification Messages");
184  if (!notificationGroup.readEntry(keyName, true)) {
185  notificationGroup.writeEntry(keyName, true);
186  notificationGroup.sync();
187 
188  KSharedConfigPtr kioConfig = KSharedConfig::openConfig("kiorc", KConfig::NoGlobals);
189  kioConfig->group("Confirmations").writeEntry(keyName, false);
190  }
191  }
192  return (result == KMessageBox::Continue);
193  }
194  return true;
195 }
196 
197 int KIO::JobUiDelegate::requestMessageBox(KIO::JobUiDelegate::MessageBoxType type,
198  const QString& text, const QString& caption,
199  const QString& buttonYes, const QString& buttonNo,
200  const QString& iconYes, const QString& iconNo,
201  const QString& dontAskAgainName,
202  const KIO::MetaData& sslMetaData)
203 {
204  int result = -1;
205 
206  //kDebug() << type << text << "caption=" << caption;
207 
208  KConfig config("kioslaverc");
209  KMessageBox::setDontShowAskAgainConfig(&config);
210 
211  const KGuiItem buttonYesGui (buttonYes, iconYes);
212  const KGuiItem buttonNoGui (buttonNo, iconNo);
213 
214  switch (type) {
215  case QuestionYesNo:
216  result = KMessageBox::questionYesNo(
217  window(), text, caption, buttonYesGui,
218  buttonNoGui, dontAskAgainName);
219  break;
220  case WarningYesNo:
221  result = KMessageBox::warningYesNo(
222  window(), text, caption, buttonYesGui,
223  buttonNoGui, dontAskAgainName);
224  break;
225  case WarningYesNoCancel:
226  result = KMessageBox::warningYesNoCancel(
227  window(), text, caption, buttonYesGui, buttonNoGui,
228  KStandardGuiItem::cancel(), dontAskAgainName);
229  break;
230  case WarningContinueCancel:
231  result = KMessageBox::warningContinueCancel(
232  window(), text, caption, buttonYesGui,
233  KStandardGuiItem::cancel(), dontAskAgainName);
234  break;
235  case Information:
236  KMessageBox::information(window(), text, caption, dontAskAgainName);
237  result = 1; // whatever
238  break;
239  case SSLMessageBox:
240  {
241  QPointer<KSslInfoDialog> kid (new KSslInfoDialog(window()));
242  //### this is boilerplate code and appears in khtml_part.cpp almost unchanged!
243  const QStringList sl = sslMetaData.value(QLatin1String("ssl_peer_chain")).split('\x01', QString::SkipEmptyParts);
244  QList<QSslCertificate> certChain;
245  bool decodedOk = true;
246  foreach (const QString &s, sl) {
247  certChain.append(QSslCertificate(s.toLatin1())); //or is it toLocal8Bit or whatever?
248  if (certChain.last().isNull()) {
249  decodedOk = false;
250  break;
251  }
252  }
253 
254  if (decodedOk) {
255  result = 1; // whatever
256  kid->setSslInfo(certChain,
257  sslMetaData.value(QLatin1String("ssl_peer_ip")),
258  text, // the URL
259  sslMetaData.value(QLatin1String("ssl_protocol_version")),
260  sslMetaData.value(QLatin1String("ssl_cipher")),
261  sslMetaData.value(QLatin1String("ssl_cipher_used_bits")).toInt(),
262  sslMetaData.value(QLatin1String("ssl_cipher_bits")).toInt(),
263  KSslInfoDialog::errorsFromString(sslMetaData.value(QLatin1String("ssl_cert_errors"))));
264  kid->exec();
265  } else {
266  result = -1;
267  KMessageBox::information(window(),
268  i18n("The peer SSL certificate chain appears to be corrupt."),
269  i18n("SSL"));
270  }
271  // KSslInfoDialog deletes itself (Qt::WA_DeleteOnClose).
272  delete kid;
273  break;
274  }
275  default:
276  kWarning() << "Unknown type" << type;
277  result = 0;
278  break;
279  }
280  KMessageBox::setDontShowAskAgainConfig(0);
281  return result;
282 }
283 
284 #include "jobuidelegate.moc"
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Thu Sep 25 2014 04:20:27 by doxygen 1.8.3.1 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.11.5 API Reference

Skip menu "kdelibs-4.11.5 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