1/*
2 This file is part of the KDE libraries
3 SPDX-FileCopyrightText: 2000 Stephan Kulow <coolo@kde.org>
4 SPDX-FileCopyrightText: 2000-2009 David Faure <faure@kde.org>
5 SPDX-FileCopyrightText: 2014 Mathias Tillman <master.homer@gmail.com>
6
7 SPDX-License-Identifier: LGPL-2.0-or-later
8*/
9
10#include "filesystemfreespacejob.h"
11#include "job.h"
12#include "job_p.h"
13#include <worker_p.h>
14
15using namespace KIO;
16
17class KIO::FileSystemFreeSpaceJobPrivate : public SimpleJobPrivate
18{
19public:
20 FileSystemFreeSpaceJobPrivate(const QUrl &url, int command, const QByteArray &packedArgs)
21 : SimpleJobPrivate(url, command, packedArgs)
22 {
23 }
24
25 /**
26 * @internal
27 * Called by the scheduler when a @p worker gets to
28 * work on this job.
29 * @param worker the worker that starts working on this job
30 */
31 void start(Worker *worker) override;
32
33 Q_DECLARE_PUBLIC(FileSystemFreeSpaceJob)
34
35 static inline FileSystemFreeSpaceJob *newJob(const QUrl &url, int command, const QByteArray &packedArgs)
36 {
37 FileSystemFreeSpaceJob *job = new FileSystemFreeSpaceJob(*new FileSystemFreeSpaceJobPrivate(url, command, packedArgs));
38 job->setUiDelegate(KIO::createDefaultJobUiDelegate());
39 return job;
40 }
41 KIO::filesize_t size = -1;
42 KIO::filesize_t availableSize = -1;
43};
44
45FileSystemFreeSpaceJob::FileSystemFreeSpaceJob(FileSystemFreeSpaceJobPrivate &dd)
46 : SimpleJob(dd)
47{
48}
49
50FileSystemFreeSpaceJob::~FileSystemFreeSpaceJob()
51{
52}
53KIO::filesize_t FileSystemFreeSpaceJob::size() const
54{
55 Q_D(const FileSystemFreeSpaceJob);
56 return d->size;
57}
58KIO::filesize_t FileSystemFreeSpaceJob::availableSize() const
59{
60 Q_D(const FileSystemFreeSpaceJob);
61 return d->availableSize;
62}
63
64void FileSystemFreeSpaceJobPrivate::start(Worker *worker)
65{
66 SimpleJobPrivate::start(worker);
67}
68
69void FileSystemFreeSpaceJob::slotFinished()
70{
71 Q_D(FileSystemFreeSpaceJob);
72 const QString totalStr = queryMetaData(QStringLiteral("total"));
73 const QString availableStr = queryMetaData(QStringLiteral("available"));
74
75 if (availableStr.isEmpty()) { // CopyJob only cares for available. "total" is optional
76 setError(KIO::ERR_UNSUPPORTED_ACTION);
77 }
78 d->size = totalStr.toULongLong();
79 d->availableSize = availableStr.toULongLong();
80
81 // Return worker to the scheduler
82 SimpleJob::slotFinished();
83}
84
85KIO::FileSystemFreeSpaceJob *KIO::fileSystemFreeSpace(const QUrl &url)
86{
87 KIO_ARGS << url;
88 return FileSystemFreeSpaceJobPrivate::newJob(url, command: CMD_FILESYSTEMFREESPACE, packedArgs);
89}
90
91#include "moc_filesystemfreespacejob.cpp"
92

source code of kio/src/core/filesystemfreespacejob.cpp