KIO

restorejob.cpp
1 /*
2  This file is part of the KDE libraries
3  SPDX-FileCopyrightText: 2014 David Faure <[email protected]>
4 
5  SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7 
8 #include "restorejob.h"
9 
10 #include "kiocoredebug.h"
11 #include "job_p.h"
12 #include <kdirnotify.h>
13 
14 #include <QTimer>
15 
16 using namespace KIO;
17 
18 class KIO::RestoreJobPrivate : public KIO::JobPrivate
19 {
20 public:
21  RestoreJobPrivate(const QList<QUrl> &urls, JobFlags flags)
22  : JobPrivate(),
23  m_urls(urls),
24  m_urlsIterator(m_urls.constBegin()),
25  m_progress(0),
26  m_flags(flags)
27  {
28  }
29  QList<QUrl> m_urls;
30  QList<QUrl>::const_iterator m_urlsIterator;
31  int m_progress;
32  JobFlags m_flags;
33 
34  void slotStart();
35  Q_DECLARE_PUBLIC(RestoreJob)
36 
37  static inline RestoreJob *newJob(const QList<QUrl> &urls, JobFlags flags)
38  {
39  RestoreJob *job = new RestoreJob(*new RestoreJobPrivate(urls, flags));
41  if (!(flags & HideProgressInfo)) {
43  }
44  return job;
45  }
46 
47 };
48 
49 RestoreJob::RestoreJob(RestoreJobPrivate &dd)
50  : Job(dd)
51 {
52  QTimer::singleShot(0, this, SLOT(slotStart()));
53 }
54 
55 RestoreJob::~RestoreJob()
56 {
57 }
58 
59 void RestoreJobPrivate::slotStart()
60 {
61  Q_Q(RestoreJob);
62  if (m_urlsIterator == m_urls.constBegin()) { // first time: emit total
63  q->setTotalAmount(KJob::Files, m_urls.count());
64  }
65 
66  if (m_urlsIterator != m_urls.constEnd()) {
67  const QUrl& url = *m_urlsIterator;
68  Q_ASSERT(url.scheme() == QLatin1String("trash"));
69  QByteArray packedArgs;
70  QDataStream stream(&packedArgs, QIODevice::WriteOnly);
71  stream << int(3) << url;
72  KIO::Job* job = KIO::special(url, packedArgs, m_flags);
73  q->addSubjob(job);
74  q->setProcessedAmount(KJob::Files, q->processedAmount(KJob::Files) + 1);
75  } else {
76  org::kde::KDirNotify::emitFilesRemoved(m_urls);
77  q->emitResult();
78  }
79 
80 }
81 
82 void RestoreJob::slotResult(KJob *job)
83 {
84  Q_D(RestoreJob);
85  if (job->error()) {
86  qCDebug(KIO_CORE) << job->errorString();
87  KIO::Job::slotResult(job); // will set the error and emit result(this)
88  return;
89  }
90  removeSubjob(job);
91  // Move on to next one
92  ++d->m_urlsIterator;
93  ++d->m_progress;
94  emitPercent(d->m_progress, d->m_urls.count());
95  d->slotStart();
96 }
97 
98 
100 {
101  return RestoreJobPrivate::newJob(urls, flags);
102 }
103 
104 #include "moc_restorejob.cpp"
void setUiDelegate(KJobUiDelegate *delegate)
A namespace for KIO globals.
Definition: authinfo.h:21
virtual QString errorString() const
KIOCORE_EXPORT SimpleJob * special(const QUrl &url, const QByteArray &data, JobFlags flags=DefaultFlags)
Execute any command that is specific to one slave (protocol).
Definition: simplejob.cpp:374
Hide progress information dialog, i.e.
Definition: job_base.h:275
int count(const T &value) const const
virtual void slotResult(KJob *job)
KIOCORE_EXPORT KJobUiDelegate * createDefaultJobUiDelegate()
Convenience method: use default factory, if there&#39;s one, to create a delegate and return it...
KIOCORE_EXPORT KJobTrackerInterface * getJobTracker()
Returns the job tracker to be used by all KIO jobs (in which HideProgressInfo is not set) ...
Definition: jobtracker.cpp:14
QString scheme() const const
The base class for all jobs.
Definition: job_base.h:45
KIOCORE_EXPORT RestoreJob * restoreFromTrash(const QList< QUrl > &urls, JobFlags flags=DefaultFlags)
Restore a set of trashed files or directories.
Definition: restorejob.cpp:99
virtual void registerJob(KJob *job)
QList::const_iterator constEnd() const const
QList::const_iterator constBegin() const const
RestoreJob is used to restore files from the trash.
Definition: restorejob.h:31
int error() const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Wed Sep 23 2020 23:01:41 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.