Skip to content

Commit

Permalink
Handle all file operations in FileWorker
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewvogt committed Jul 7, 2016
1 parent 3d76f55 commit 922370c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
12 changes: 3 additions & 9 deletions src/fileengine.cpp
Expand Up @@ -172,24 +172,19 @@ bool FileEngine::exists(QString fileName)

bool FileEngine::mkdir(QString path, QString name)
{
QDir dir(path);

if (!dir.mkdir(name)) {
if (!m_fileWorker->mkdir(path, name)) {
emit error(ErrorFolderCreationFailed, name);
return false;
}

return true;
}

bool FileEngine::rename(QString fullOldFileName, QString newName)
{
QFile file(fullOldFileName);
QFileInfo fileInfo(fullOldFileName);
QDir dir = fileInfo.absoluteDir();
QString fullNewFileName = dir.absoluteFilePath(newName);

if (!file.rename(fullNewFileName)) {
if (!m_fileWorker->rename(fullOldFileName, fullNewFileName)) {
emit error(ErrorRenameFailed, fileInfo.fileName());
return false;
}
Expand All @@ -201,7 +196,6 @@ bool FileEngine::chmod(QString path,
bool groupRead, bool groupWrite, bool groupExecute,
bool othersRead, bool othersWrite, bool othersExecute)
{
QFile file(path);
QFileDevice::Permissions p;
if (ownerRead) p |= QFileDevice::ReadOwner;
if (ownerWrite) p |= QFileDevice::WriteOwner;
Expand All @@ -212,7 +206,7 @@ bool FileEngine::chmod(QString path,
if (othersRead) p |= QFileDevice::ReadOther;
if (othersWrite) p |= QFileDevice::WriteOther;
if (othersExecute) p |= QFileDevice::ExeOther;
if (!file.setPermissions(p)) {
if (!m_fileWorker->setPermissions(path, p)) {
emit error(ErrorChmodFailed, path);
return false;
}
Expand Down
19 changes: 19 additions & 0 deletions src/fileworker.cpp
Expand Up @@ -121,6 +121,24 @@ void FileWorker::cancel()
m_cancelled.storeRelease(Cancelled);
}

bool FileWorker::mkdir(QString path, QString name)
{
QDir dir(path);
return dir.mkdir(name);
}

bool FileWorker::rename(QString oldPath, QString newPath)
{
QFile file(oldPath);
return file.rename(newPath);
}

bool FileWorker::setPermissions(QString path, QFileDevice::Permissions p)
{
QFile file(path);
return file.setPermissions(p);
}

void FileWorker::run()
{
switch (m_mode) {
Expand Down Expand Up @@ -335,3 +353,4 @@ bool FileWorker::copyOverwrite(QString src, QString dest)
QFile sfile(src);
return sfile.copy(dest);
}

5 changes: 5 additions & 0 deletions src/fileworker.h
Expand Up @@ -55,6 +55,11 @@ class FileWorker : public QThread

void cancel();

// synchronous functions
bool mkdir(QString path, QString name);
bool rename(QString oldPath, QString newPath);
bool setPermissions(QString path, QFileDevice::Permissions p);

FileEngine::Mode mode() const;

signals:
Expand Down

0 comments on commit 922370c

Please sign in to comment.