Add basic CIO(Cutefish IO)
This commit is contained in:
parent
60884f1366
commit
5e18359d6f
8 changed files with 227 additions and 24 deletions
|
@ -27,6 +27,9 @@ add_executable(cutefish-filemanager
|
||||||
model/dirlister.cpp
|
model/dirlister.cpp
|
||||||
model/positioner.cpp
|
model/positioner.cpp
|
||||||
|
|
||||||
|
cio/cfilejob.cpp
|
||||||
|
cio/cfilesizejob.cpp
|
||||||
|
|
||||||
dialogs/createfolderdialog.cpp
|
dialogs/createfolderdialog.cpp
|
||||||
dialogs/filepropertiesdialog.cpp
|
dialogs/filepropertiesdialog.cpp
|
||||||
dialogs/openwithdialog.cpp
|
dialogs/openwithdialog.cpp
|
||||||
|
|
7
cio/cfilejob.cpp
Normal file
7
cio/cfilejob.cpp
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
#include "cfilejob.h"
|
||||||
|
|
||||||
|
CFileJob::CFileJob(QObject *parent)
|
||||||
|
: QThread(parent)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
17
cio/cfilejob.h
Normal file
17
cio/cfilejob.h
Normal file
|
@ -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
|
113
cio/cfilesizejob.cpp
Normal file
113
cio/cfilesizejob.cpp
Normal file
|
@ -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();
|
||||||
|
}
|
55
cio/cfilesizejob.h
Normal file
55
cio/cfilesizejob.h
Normal file
|
@ -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
|
|
@ -64,10 +64,10 @@ FilePropertiesDialog::FilePropertiesDialog(const QUrl &url, QQuickView *parent)
|
||||||
|
|
||||||
FilePropertiesDialog::~FilePropertiesDialog()
|
FilePropertiesDialog::~FilePropertiesDialog()
|
||||||
{
|
{
|
||||||
if (m_dirSizeJob) {
|
if (m_sizeJob) {
|
||||||
m_dirSizeJob->kill();
|
m_sizeJob->stop();
|
||||||
m_dirSizeJob->deleteLater();
|
m_sizeJob->deleteLater();
|
||||||
m_dirSizeJob = nullptr;
|
m_sizeJob = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,6 +107,12 @@ void FilePropertiesDialog::accept(const QString &text)
|
||||||
|
|
||||||
void FilePropertiesDialog::reject()
|
void FilePropertiesDialog::reject()
|
||||||
{
|
{
|
||||||
|
if (m_sizeJob) {
|
||||||
|
m_sizeJob->stop();
|
||||||
|
m_sizeJob->deleteLater();
|
||||||
|
m_sizeJob = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
this->destroy();
|
this->destroy();
|
||||||
this->deleteLater();
|
this->deleteLater();
|
||||||
}
|
}
|
||||||
|
@ -181,17 +187,17 @@ void FilePropertiesDialog::init()
|
||||||
setSource(QUrl("qrc:/qml/Dialogs/PropertiesDialog.qml"));
|
setSource(QUrl("qrc:/qml/Dialogs/PropertiesDialog.qml"));
|
||||||
|
|
||||||
m_multiple = m_items.count() > 1;
|
m_multiple = m_items.count() > 1;
|
||||||
m_dirSizeJob = KIO::directorySize(m_items);
|
|
||||||
|
|
||||||
// Update
|
QList<QUrl> list;
|
||||||
m_dirSizeUpdateTimer = new QTimer(this);
|
for (KFileItem item : m_items) {
|
||||||
connect(m_dirSizeUpdateTimer, &QTimer::timeout, this, [=] {
|
list.append(item.url());
|
||||||
m_size = KIO::convertSize(m_dirSizeJob->totalSize());
|
}
|
||||||
emit fileSizeChanged();
|
|
||||||
});
|
|
||||||
m_dirSizeUpdateTimer->start(500);
|
|
||||||
|
|
||||||
connect(m_dirSizeJob, &KIO::DirectorySizeJob::result, this, &FilePropertiesDialog::slotDirSizeFinished);
|
m_sizeJob = std::shared_ptr<CFileSizeJob>(new CFileSizeJob);
|
||||||
|
m_sizeJob->start(list);
|
||||||
|
|
||||||
|
connect(m_sizeJob.get(), &CFileSizeJob::sizeChanged, this, &FilePropertiesDialog::updateTotalSize);
|
||||||
|
connect(m_sizeJob.get(), &CFileSizeJob::result, this, &FilePropertiesDialog::updateTotalSize);
|
||||||
|
|
||||||
if (!m_multiple) {
|
if (!m_multiple) {
|
||||||
KFileItem item = m_items.first();
|
KFileItem item = m_items.first();
|
||||||
|
@ -236,16 +242,11 @@ void FilePropertiesDialog::init()
|
||||||
emit isWritableChanged();
|
emit isWritableChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FilePropertiesDialog::slotDirSizeFinished(KJob *job)
|
void FilePropertiesDialog::updateTotalSize()
|
||||||
{
|
{
|
||||||
if (job->error())
|
if (!m_sizeJob)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_dirSizeUpdateTimer->stop();
|
m_size = KIO::convertSize(m_sizeJob->totalSize());
|
||||||
m_size = KIO::convertSize(m_dirSizeJob->totalSize());
|
|
||||||
|
|
||||||
m_dirSizeJob = 0;
|
|
||||||
|
|
||||||
emit fileSizeChanged();
|
emit fileSizeChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,10 +23,13 @@
|
||||||
#include <QQuickView>
|
#include <QQuickView>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
#include <QSharedPointer>
|
||||||
|
|
||||||
#include <KFileItem>
|
#include <KFileItem>
|
||||||
#include <KIO/DirectorySizeJob>
|
#include <KIO/DirectorySizeJob>
|
||||||
|
|
||||||
|
#include "cio/cfilesizejob.h"
|
||||||
|
|
||||||
class FilePropertiesDialog : public QQuickView
|
class FilePropertiesDialog : public QQuickView
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -82,7 +85,7 @@ private:
|
||||||
void init();
|
void init();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void slotDirSizeFinished(KJob *job);
|
void updateTotalSize();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
KFileItemList m_items;
|
KFileItemList m_items;
|
||||||
|
@ -95,8 +98,7 @@ private:
|
||||||
QString m_modifiedTime;
|
QString m_modifiedTime;
|
||||||
QString m_accessedTime;
|
QString m_accessedTime;
|
||||||
|
|
||||||
QTimer *m_dirSizeUpdateTimer = nullptr;
|
std::shared_ptr<CFileSizeJob> m_sizeJob;
|
||||||
KIO::DirectorySizeJob *m_dirSizeJob;
|
|
||||||
|
|
||||||
bool m_multiple;
|
bool m_multiple;
|
||||||
bool m_isWritable;
|
bool m_isWritable;
|
||||||
|
|
|
@ -41,6 +41,11 @@ OpenWithDialog::OpenWithDialog(const QUrl &url, QQuickView *parent)
|
||||||
QRect rect = geometry();
|
QRect rect = geometry();
|
||||||
setMinimumSize(rect.size());
|
setMinimumSize(rect.size());
|
||||||
setMaximumSize(rect.size());
|
setMaximumSize(rect.size());
|
||||||
|
|
||||||
|
connect(this, &QQuickView::visibleChanged, this, [=] {
|
||||||
|
if (!this->isVisible())
|
||||||
|
this->deleteLater();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
QString OpenWithDialog::url() const
|
QString OpenWithDialog::url() const
|
||||||
|
|
Loading…
Reference in a new issue