-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkfilesavethread.cpp
47 lines (40 loc) · 1.39 KB
/
kfilesavethread.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "kfilesavethread.h"
KFileSaveThread::KFileSaveThread(QObject *parent) : QThread(parent)
{
}
KFileSaveThread::KFileSaveThread(const QFileInfoList &fileInfoList, const QString &destDirPath, QObject *parent) :
QThread(parent),
m_fileInfoList(fileInfoList),
m_destDirPath(destDirPath)
{
}
void KFileSaveThread::run()
{
foreach(const QFileInfo &fileInfo, m_fileInfoList)
{
if (fileInfo.isFile())
QFile::copy(fileInfo.absoluteFilePath(), m_destDirPath + '\\' + fileInfo.fileName());
else
copyDirRecursively(QDir(fileInfo.absoluteFilePath()), QDir(m_destDirPath));
}
}
void KFileSaveThread::copyDirRecursively(const QDir &sourceDir, QDir destDir)
{
destDir.mkdir(sourceDir.dirName());
destDir.cd(sourceDir.dirName());
foreach(const QFileInfo &fileInfo, sourceDir.entryInfoList(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot))
{
if (fileInfo.isFile())
QFile::copy(fileInfo.absoluteFilePath(), destDir.absolutePath() + '\\' + fileInfo.fileName());
else
copyDirRecursively(QDir(fileInfo.absoluteFilePath()), destDir);
}
}
void KFileSaveThread::setDestDirPath(const QString &newDestDirPath)
{
m_destDirPath = newDestDirPath;
}
void KFileSaveThread::setFileInfoList(const QFileInfoList &newFileInfoList)
{
m_fileInfoList = newFileInfoList;
}