-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper.cpp
95 lines (76 loc) · 2.83 KB
/
helper.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
This Program was written by Eric Baudach <[email protected]>
and is licensed under the GPL version 3 or newer versions of GPL.
<Copyright (C) 2010-2012 Eric Baudach>
*/
#include "helper.h"
#include <QProcess>
#include "widget.h"
helper::helper(QWidget *parent) :
QThread(parent)
{
QObject::moveToThread(this);
}
void helper::run()
{
exec();
}
void helper::Remove_File_thumb(const QStringList & Files){
if(Files.length() != 0){
Q_EMIT(ImageSaved(true));
Q_FOREACH(QString file, Files) {
QString thumb = QFileInfo(file).absolutePath() + "/.thumb_" + QFileInfo(file).fileName();
QFile::remove(thumb);
}
Q_EMIT(ImageSaved(false));
}
}
void helper::Remove_Dir_thumb(int recursive, const QStringList & Paths) {
Q_EMIT(ImageSaved(true));
if(recursive == 2){
if(Paths.length() != 0){
Q_FOREACH(QString path, Paths) {
QDir tempDir = QDir(path);
QString path_bash_conform = tempDir.canonicalPath().replace(" ", "\ ");
QString find = "find \""+path_bash_conform+"\" -type f -name .thumb_* -print -exec rm {} \;";
qDebug() << find;
QProcess process;
process.setProcessChannelMode(QProcess::MergedChannels);
process.start(find ,QIODevice::ReadOnly);
// Continue reading the data until EOF reached
QByteArray data;
while(process.waitForReadyRead())
data.append(process.readAll());
// Output the data
qDebug( "%s", data.data() );
qDebug("Done!");
if(data.length() != 0){
Q_EMIT(RemoveFromUI_signal(data));
}
}
}
}else{
if(Paths.length() != 0){
Q_FOREACH(QString path, Paths) {
QDir tempDir = QDir(path);
QString path_bash_conform = tempDir.canonicalPath().replace(" ", "\ ");
QString find = "find \""+path_bash_conform+"\" -maxdepth 1 -type f -name .thumb_* -print -exec rm {} \;";
qDebug() << find;
QProcess process;
process.setProcessChannelMode(QProcess::MergedChannels);
process.start(find ,QIODevice::ReadOnly);
// Continue reading the data until EOF reached
QByteArray data;
while(process.waitForReadyRead())
data.append(process.readAll());
// Output the data
qDebug( "%s", data.data() );
qDebug("Done!");
if(data.length() != 0){
Q_EMIT(RemoveFromUI_signal(data));
}
}
}
}
Q_EMIT(ImageSaved(false));
}