• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.11.3 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"
KIO::JobUiDelegate::setWindow
virtual void setWindow(QWidget *window)
Associate this job with a window given by window.
Definition: jobuidelegate.cpp:58
KStandardGuiItem::cancel
KGuiItem cancel()
Information
i18n
QString i18n(const char *text)
KSharedPtr< KSharedConfig >
KIO::filesize_t
qulonglong filesize_t
64-bit file size
Definition: global.h:56
KMessageBox::Continue
KIO::JobUiDelegate::askSkip
virtual SkipDialog_Result askSkip(KJob *job, bool multi, const QString &error_text)
Definition: jobuidelegate.cpp:96
ksslinfodialog.h
KIO::JobUiDelegate::ConfirmationType
ConfirmationType
ForceConfirmation: always ask the user for confirmation DefaultConfirmation: don&#39;t ask the user if he...
Definition: jobuidelegate.h:116
kdebug.h
KSslInfoDialog::errorsFromString
static QList< QList< KSslError::Error > > errorsFromString(const QString &s)
Definition: ksslinfodialog.cpp:232
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))
i18np
QString i18np(const char *sing, const char *plur, const A1 &a1)
KMessageBox::information
static void information(QWidget *parent, const QString &text, const QString &caption=QString(), const QString &dontShowAgainName=QString(), Options options=Notify)
QWidget
KMessageBox::setDontShowAskAgainConfig
static void setDontShowAskAgainConfig(KConfig *cfg)
KConfig::group
KConfigGroup group(const QByteArray &group)
KConfigGroup::writeEntry
void writeEntry(const QString &key, const QVariant &value, WriteConfigFlags pFlags=Normal)
QString
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:197
klocale.h
KIO::JobUiDelegate::askDeleteConfirmation
bool askDeleteConfirmation(const KUrl::List &urls, DeletionType deletionType, ConfirmationType confirmationType)
Ask for confirmation before deleting/trashing urls.
Definition: jobuidelegate.cpp:106
KIO::MetaData
MetaData is a simple map of key/value strings.
Definition: global.h:383
KIO::RenameDialog::autoDestUrl
KUrl autoDestUrl() const
Definition: renamedialog.cpp:382
KUrl
KStandardGuiItem::del
KGuiItem del()
i18nc
QString i18nc(const char *ctxt, const char *text)
config
KSharedConfigPtr config()
KIO::SkipDialog_Result
SkipDialog_Result
Definition: skipdialog.h:29
scheduler.h
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)
KSslInfoDialog
KDE SSL Information Dialog.
Definition: ksslinfodialog.h:43
netwm.h
KConfig::NoGlobals
Delete
KGuiItem
KUrl::protocol
QString protocol() const
QStringList
KMessageBox::Notify
KUrl::pathOrUrl
QString pathOrUrl() const
KIcon
KIO::JobUiDelegate::JobUiDelegate
JobUiDelegate()
Constructs a new KIO Job UI delegate.
Definition: jobuidelegate.cpp:48
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))
Definition: jobuidelegate.cpp:64
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
ksharedconfig.h
KUrl::path
QString path(AdjustPathOption trailing=LeaveTrailingSlash) const
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
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)
jobuidelegate.h
KConfigGroup
KUrl::List
KConfig
KIO::R_AUTO_RENAME
Definition: renamedialog.h:61
KIO::JobUiDelegate::~JobUiDelegate
virtual ~JobUiDelegate()
Destroys the KIO Job UI delegate.
Definition: jobuidelegate.cpp:53
KIO::JobUiDelegate::MessageBoxType
MessageBoxType
Message box types.
Definition: jobuidelegate.h:141
KIO::RenameDialog_Result
RenameDialog_Result
The result of open_RenameDialog().
Definition: renamedialog.h:61
kWarning
static QDebug kWarning(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
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)
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
KDialogJobUiDelegate::setWindow
virtual void setWindow(QWidget *window)
kjob.h
KConfigGroup::sync
void sync()
KIO::RenameDialog
The dialog shown when a CopyJob realizes that a destination file already exists, and wants to offer t...
Definition: renamedialog.h:70
KSharedConfig::openConfig
static KSharedConfig::Ptr openConfig(const QString &fileName=QString(), OpenFlags mode=FullConfig, const char *resourceType="config")
kmessagebox.h
KIO::SkipDialog
Definition: skipdialog.h:35
kmessage.h
KConfigGroup::readEntry
T readEntry(const QString &key, const T &aDefault) const
KIO::RenameDialog::newDestUrl
KUrl newDestUrl()
Definition: renamedialog.cpp:372
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)
KJob
QList< QSslCertificate >
defaultValue
QString defaultValue(const QString &t)
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Thu Dec 12 2013 08:01:59 by doxygen 1.8.5 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.3 API Reference

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