Add basic CIO(Cutefish IO)
parent
60884f1366
commit
5e18359d6f
@ -0,0 +1,7 @@
|
|||||||
|
#include "cfilejob.h"
|
||||||
|
|
||||||
|
CFileJob::CFileJob(QObject *parent)
|
||||||
|
: QThread(parent)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,17 @@
|
|||||||
|
#ifndef CFILEJOB_H
|
||||||
|
#define CFILEJOB_H
|
||||||
|
|
||||||
|
#include <QThread>
|
||||||
|
|
||||||
|
class CFileJob : public QThread
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit CFileJob(QObject *parent = nullptr);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // CFILEJOB_H
|
||||||
@ -0,0 +1,113 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2021 CutefishOS Team.
|
||||||
|
*
|
||||||
|
* Author: Reion Wong <reionwong@gmail.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "cfilesizejob.h"
|
||||||
|
#include <QQueue>
|
||||||
|
#include <QDir>
|
||||||
|
#include <QDirIterator>
|
||||||
|
#include <QFileInfo>
|
||||||
|
#include <QDebug>
|
||||||
|
#include <KIO/CopyJob>
|
||||||
|
|
||||||
|
CFileSizeJob::CFileSizeJob(QObject *parent)
|
||||||
|
: QThread(parent)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
CFileSizeJob::~CFileSizeJob()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
qint64 CFileSizeJob::totalSize() const
|
||||||
|
{
|
||||||
|
return m_totalSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CFileSizeJob::start(const QList<QUrl> &urls)
|
||||||
|
{
|
||||||
|
if (urls.isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_urls = urls;
|
||||||
|
m_running = true;
|
||||||
|
|
||||||
|
QThread::start();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CFileSizeJob::stop()
|
||||||
|
{
|
||||||
|
m_running = false;
|
||||||
|
|
||||||
|
QThread::wait();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CFileSizeJob::run()
|
||||||
|
{
|
||||||
|
m_totalSize = 0;
|
||||||
|
m_filesCount = 0;
|
||||||
|
m_directoryCount = 0;
|
||||||
|
|
||||||
|
for (QUrl &url : m_urls) {
|
||||||
|
if (!m_running)
|
||||||
|
return;
|
||||||
|
|
||||||
|
QFileInfo i(url.toLocalFile());
|
||||||
|
|
||||||
|
if (i.filePath() == "/proc/kcore" || i.filePath() == "/dev/core")
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (i.isSymLink() && i.symLinkTarget() == "/proc/kcore")
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (i.isFile()) {
|
||||||
|
m_totalSize += i.size();
|
||||||
|
m_filesCount++;
|
||||||
|
emit sizeChanged();
|
||||||
|
} else if (i.isDir()) {
|
||||||
|
m_directoryCount++;
|
||||||
|
|
||||||
|
QDirIterator it(url.toLocalFile(), QDir::AllEntries | QDir::Hidden | QDir::System | QDir::NoDotAndDotDot, QDirIterator::Subdirectories);
|
||||||
|
|
||||||
|
while (it.hasNext()) {
|
||||||
|
if (!m_running)
|
||||||
|
return;
|
||||||
|
|
||||||
|
QFileInfo info(it.next());
|
||||||
|
|
||||||
|
if (info.filePath() == "/proc/kcore" || info.filePath() == "/dev/core")
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (info.isSymLink())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (info.isFile())
|
||||||
|
m_filesCount++;
|
||||||
|
else if (info.isDir())
|
||||||
|
m_directoryCount++;
|
||||||
|
|
||||||
|
m_totalSize += info.size();
|
||||||
|
|
||||||
|
emit sizeChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
emit result();
|
||||||
|
}
|
||||||
@ -0,0 +1,55 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2021 CutefishOS Team.
|
||||||
|
*
|
||||||
|
* Author: Reion Wong <reionwong@gmail.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef CFILESIZEJOB_H
|
||||||
|
#define CFILESIZEJOB_H
|
||||||
|
|
||||||
|
#include <QThread>
|
||||||
|
#include <QList>
|
||||||
|
#include <QUrl>
|
||||||
|
|
||||||
|
class CFileSizeJob : public QThread
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit CFileSizeJob(QObject *parent = nullptr);
|
||||||
|
~CFileSizeJob();
|
||||||
|
|
||||||
|
qint64 totalSize() const;
|
||||||
|
|
||||||
|
void start(const QList<QUrl> &urls);
|
||||||
|
void stop();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void sizeChanged();
|
||||||
|
void result();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void run() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool m_running;
|
||||||
|
QList<QUrl> m_urls;
|
||||||
|
qint64 m_totalSize;
|
||||||
|
int m_filesCount;
|
||||||
|
int m_directoryCount;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // CFILESIZEJOB_H
|
||||||
Loading…
Reference in New Issue