• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.10.2 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"
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Sat Apr 20 2013 06:03:09 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.10.2 API Reference

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