KIO

filesystemfreespacejob.cpp
1 /* This file is part of the KDE libraries
2  Copyright (C) 2000 Stephan Kulow <[email protected]>
3  2000-2009 David Faure <[email protected]>
4  2014 Mathias Tillman <[email protected]>
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 "filesystemfreespacejob.h"
23 #include "job.h"
24 #include "job_p.h"
25 #include <slave.h>
26 
27 using namespace KIO;
28 
29 class KIO::FileSystemFreeSpaceJobPrivate: public SimpleJobPrivate
30 {
31 public:
32  FileSystemFreeSpaceJobPrivate(const QUrl &url, int command, const QByteArray &packedArgs)
33  : SimpleJobPrivate(url, command, packedArgs)
34  { }
35 
42  void start(Slave *slave) override;
43 
44  Q_DECLARE_PUBLIC(FileSystemFreeSpaceJob)
45 
46  static inline FileSystemFreeSpaceJob *newJob(const QUrl &url, int command, const QByteArray &packedArgs)
47  {
48  FileSystemFreeSpaceJob *job = new FileSystemFreeSpaceJob(*new FileSystemFreeSpaceJobPrivate(url, command, packedArgs));
50  return job;
51  }
52 };
53 
54 FileSystemFreeSpaceJob::FileSystemFreeSpaceJob(FileSystemFreeSpaceJobPrivate &dd)
55  : SimpleJob(dd)
56 {
57 }
58 
59 FileSystemFreeSpaceJob::~FileSystemFreeSpaceJob()
60 {
61 }
62 
63 void FileSystemFreeSpaceJobPrivate::start(Slave *slave)
64 {
65  SimpleJobPrivate::start(slave);
66 }
67 
68 void FileSystemFreeSpaceJob::slotFinished()
69 {
70  const QString totalStr = queryMetaData(QStringLiteral("total"));
71  const QString availableStr = queryMetaData(QStringLiteral("available"));
72 
73  if (availableStr.isEmpty()) { // CopyJob only cares for available. "total" is optional
74  setError(KIO::ERR_UNSUPPORTED_ACTION);
75  }
76  const KIO::filesize_t total = totalStr.toULongLong();
77  const KIO::filesize_t available = availableStr.toULongLong();
78  emit result(this, total, available);
79 
80  // Return slave to the scheduler
82 }
83 
85 {
86  KIO_ARGS << url;
87  return FileSystemFreeSpaceJobPrivate::newJob(url, CMD_FILESYSTEMFREESPACE, packedArgs);
88 }
89 
90 #include "moc_filesystemfreespacejob.cpp"
qulonglong filesize_t
64-bit file size
Definition: global.h:51
KIOCORE_EXPORT FileSystemFreeSpaceJob * fileSystemFreeSpace(const QUrl &url)
Get a filesystem&#39;s total and available space.
void setUiDelegate(KJobUiDelegate *delegate)
const QUrl & url() const
Returns the SimpleJob&#39;s URL.
Definition: simplejob.cpp:82
A namespace for KIO globals.
Definition: authinfo.h:34
void setError(int errorCode)
QString queryMetaData(const QString &key)
Query meta data received from the slave.
Definition: job.cpp:232
A KIO job that retrieves the total and available size of a filesystem.
bool isEmpty() const const
KIOCORE_EXPORT KJobUiDelegate * createDefaultJobUiDelegate()
Convenience method: use default factory, if there&#39;s one, to create a delegate and return it...
qulonglong toULongLong(bool *ok, int base) const const
virtual void slotFinished()
Called when the slave marks the job as finished.
Definition: simplejob.cpp:206
void result(KJob *job)
A simple job (one url and one command).
Definition: simplejob.h:39
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sat Jul 11 2020 23:00:25 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.