KIO

filesystemfreespacejob.cpp
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));
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}
54{
56 return d->size;
57}
59{
61 return d->availableSize;
62}
63
64void FileSystemFreeSpaceJobPrivate::start(Worker *worker)
65{
66 SimpleJobPrivate::start(worker);
67}
68
69void FileSystemFreeSpaceJob::slotFinished()
70{
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
83}
84
86{
87 KIO_ARGS << url;
88 return FileSystemFreeSpaceJobPrivate::newJob(url, CMD_FILESYSTEMFREESPACE, packedArgs);
89}
90
91#include "moc_filesystemfreespacejob.cpp"
A KIO job that retrieves the total and available size of a filesystem.
KIO::filesize_t availableSize() const
Get available amount of space.
KIO::filesize_t size() const
Get total amount of space.
QString queryMetaData(const QString &key)
Query meta data received from the worker.
Definition job.cpp:210
A simple job (one url and one command).
virtual void slotFinished()
Called when the worker marks the job as finished.
void setError(int errorCode)
void setUiDelegate(KJobUiDelegate *delegate)
Q_SCRIPTABLE Q_NOREPLY void start()
A namespace for KIO globals.
KIOCORE_EXPORT KJobUiDelegate * createDefaultJobUiDelegate()
Convenience method: use default factory, if there's one, to create a delegate and return it.
KIOCORE_EXPORT FileSystemFreeSpaceJob * fileSystemFreeSpace(const QUrl &url)
Get a filesystem's total and available space.
qulonglong filesize_t
64-bit file size
Definition global.h:35
bool isEmpty() const const
qulonglong toULongLong(bool *ok, int base) const const
Q_D(Todo)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:58:45 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.