• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.10.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 
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.
10 
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.
15 
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.
20 */
21 
22 #include "jobuidelegate.h"
23 
24 #include <kdebug.h>
25 #include <kjob.h>
26 #include <klocale.h>
27 #include <kmessagebox.h>
28 #include <ksharedconfig.h>
29 
30 #include <QPointer>
31 #include <QWidget>
32 
33 #include "kio/scheduler.h"
34 
35 #if defined Q_WS_X11
36 #include <QX11Info>
37 #include <netwm.h>
38 #endif
39 
40 class KIO::JobUiDelegate::Private
41 {
42 public:
43 };
44 
45 KIO::JobUiDelegate::JobUiDelegate()
46  : d(new Private())
47 {
48 }
49 
50 KIO::JobUiDelegate::~JobUiDelegate()
51 {
52  delete d;
53 }
54 
55 void KIO::JobUiDelegate::setWindow(QWidget *window)
56 {
57  KDialogJobUiDelegate::setWindow(window);
58  KIO::Scheduler::registerWindow(window);
59 }
60 
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)
73 {
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  connect(job, SIGNAL(finished(KJob*)), &dlg, SLOT(reject())); // #192976
83  KIO::RenameDialog_Result res = static_cast<RenameDialog_Result>(dlg.exec());
84  if (res == R_AUTO_RENAME) {
85  newDest = dlg.autoDestUrl().path();
86  }
87  else {
88  newDest = dlg.newDestUrl().path();
89  }
90  return res;
91 }
92 
93 KIO::SkipDialog_Result KIO::JobUiDelegate::askSkip(KJob *job,
94  bool multi,
95  const QString & error_text)
96 {
97  // We now do it in process. So this method is a useless wrapper around KIO::open_RenameDialog.
98  KIO::SkipDialog dlg( window(), multi, error_text );
99  connect(job, SIGNAL(finished(KJob*)), &dlg, SLOT(reject())); // #192976
100  return static_cast<KIO::SkipDialog_Result>(dlg.exec());
101 }
102 
103 bool KIO::JobUiDelegate::askDeleteConfirmation(const KUrl::List& urls,
104  DeletionType deletionType,
105  ConfirmationType confirmationType)
106 {
107  QString keyName;
108  bool ask = ( confirmationType == ForceConfirmation );
109  if (!ask) {
110  KSharedConfigPtr kioConfig = KSharedConfig::openConfig("kiorc", KConfig::NoGlobals);
111 
112  switch (deletionType ) {
113  case Delete:
114  keyName = "ConfirmDelete" ;
115  break;
116  case Trash:
117  keyName = "ConfirmTrash" ;
118  break;
119  case EmptyTrash:
120  keyName = "ConfirmEmptyTrash" ;
121  break;
122  }
123 
124  // The default value for confirmations is true (for both delete and trash)
125  // If you change this, update kdebase/apps/konqueror/settings/konq/behaviour.cpp
126  const bool defaultValue = true;
127  ask = kioConfig->group("Confirmations").readEntry(keyName, defaultValue);
128  }
129  if (ask) {
130  QStringList prettyList;
131  Q_FOREACH(const KUrl& url, urls) {
132  if ( url.protocol() == "trash" ) {
133  QString path = url.path();
134  // HACK (#98983): remove "0-foo". Note that it works better than
135  // displaying KFileItem::name(), for files under a subdir.
136  path.remove(QRegExp("^/[0-9]*-"));
137  prettyList.append(path);
138  } else {
139  prettyList.append(url.pathOrUrl());
140  }
141  }
142 
143  QWidget* widget = window();
144  int result;
145  switch(deletionType) {
146  case Delete:
147  result = KMessageBox::warningContinueCancelList(
148  widget,
149  i18np("Do you really want to delete this item?", "Do you really want to delete these %1 items?", prettyList.count()),
150  prettyList,
151  i18n("Delete Files"),
152  KStandardGuiItem::del(),
153  KStandardGuiItem::cancel(),
154  keyName, KMessageBox::Notify);
155  break;
156  case EmptyTrash:
157  result = KMessageBox::warningContinueCancel(
158  widget,
159  i18nc("@info", "Do you want to permanently delete all items from Trash? This action cannot be undone."),
160  QString(),
161  KGuiItem(i18nc("@action:button", "Empty Trash"),
162  KIcon("user-trash")),
163  KStandardGuiItem::cancel(),
164  keyName, KMessageBox::Notify);
165  break;
166  case Trash:
167  default:
168  result = KMessageBox::warningContinueCancelList(
169  widget,
170  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()),
171  prettyList,
172  i18n("Move to Trash"),
173  KGuiItem(i18nc("Verb", "&Trash"), "user-trash"),
174  KStandardGuiItem::cancel(),
175  keyName, KMessageBox::Notify);
176  }
177  if (!keyName.isEmpty()) {
178  // Check kmessagebox setting... erase & copy to konquerorrc.
179  KSharedConfig::Ptr config = KGlobal::config();
180  KConfigGroup notificationGroup(config, "Notification Messages");
181  if (!notificationGroup.readEntry(keyName, true)) {
182  notificationGroup.writeEntry(keyName, true);
183  notificationGroup.sync();
184 
185  KSharedConfigPtr kioConfig = KSharedConfig::openConfig("kiorc", KConfig::NoGlobals);
186  kioConfig->group("Confirmations").writeEntry(keyName, false);
187  }
188  }
189  return (result == KMessageBox::Continue);
190  }
191  return true;
192 }
193 
194 #include "jobuidelegate.moc"
KIO::JobUiDelegate::setWindow
virtual void setWindow(QWidget *window)
Associate this job with a window given by window.
Definition: jobuidelegate.cpp:55
KStandardGuiItem::cancel
KGuiItem cancel()
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:93
KIO::JobUiDelegate::ConfirmationType
ConfirmationType
ForceConfirmation: always ask the user for confirmation DefaultConfirmation: don&#39;t ask the user if he...
Definition: jobuidelegate.h:114
kdebug.h
i18np
QString i18np(const char *sing, const char *plur, const A1 &a1)
QWidget
KConfig::group
KConfigGroup group(const QByteArray &group)
KConfigGroup::writeEntry
void writeEntry(const QString &key, const QVariant &value, WriteConfigFlags pFlags=Normal)
QString
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:103
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
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:45
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:61
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:107
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
jobuidelegate.h
KConfigGroup
KUrl::List
KIO::R_AUTO_RENAME
Definition: renamedialog.h:61
KIO::JobUiDelegate::~JobUiDelegate
virtual ~JobUiDelegate()
Destroys the KIO Job UI delegate.
Definition: jobuidelegate.cpp:50
KIO::RenameDialog_Result
RenameDialog_Result
The result of open_RenameDialog().
Definition: renamedialog.h:61
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:865
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
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
defaultValue
QString defaultValue(const QString &t)
This file is part of the KDE documentation.
Documentation copyright © 1996-2015 The KDE developers.
Generated on Tue Jul 28 2015 13:46:06 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.10.5 API Reference

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