This repository has been archived by the owner on Nov 9, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ConvertAllEps.cpp
136 lines (85 loc) · 3.12 KB
/
ConvertAllEps.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
// Copyright (C) 2012-2015, Ali Baharev
// All rights reserved.
// This code is published under the GNU Lesser General Public License.
#include <QDebug>
#include <QDir>
#include <QFileInfo>
#include <QStatusBar>
#include "ConvertAllEps.hpp"
#include "ConvertEPS2PDF.hpp"
#include "ErrorMsg.hpp"
#include "GlobalSettings.hpp"
ConvertAllEps::ConvertAllEps(QObject *parent, QStatusBar *mainWindowStatusBar)
: QObject(parent),
statusBar(mainWindowStatusBar)
{
converter = new ConvertEPS2PDF;
directories = new QFileInfoList;
eps_files = new QFileInfoList;
currentFile = new QFileInfo;
connect(converter, SIGNAL(finished(bool)), SLOT(onSingleFileConversionFinished(bool)));
}
ConvertAllEps::~ConvertAllEps() {
delete converter;
delete directories;
delete eps_files;
delete currentFile;
}
void ConvertAllEps::run(const QString& project_directory) {
projectFolder = project_directory;
// TODO Another magic constant
QVector<QString> dirs = QVector<QString>();
dirs.append(projectFolder+"/5_PS_SEPARATED/");
dirs.append(projectFolder+"/6_WELL_PS_SEPARATED/");
findAllFiles(dirs);
loop();
}
void ConvertAllEps::findAllFiles(const QVector<QString>& dirs) {
directories->clear();
eps_files->clear();
foreach(QString dirName, dirs) {
qDebug() << "Searching" << dirName << "for subdirectories";
QDir dir = QDir(dirName);
*directories = dir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name);
for (QList<QFileInfo>::iterator subdir=directories->begin(); subdir!=directories->end(); ++subdir) {
QString subDirPath = subdir->filePath();
qDebug() << "Searching" << subDirPath << "for eps files";
eps_files->append( QDir(subDirPath).entryInfoList(QStringList("*.eps"), QDir::Files, QDir::Name) );
}
}
qDebug() << "Found" << eps_files->size() << "eps files to convert";
}
void ConvertAllEps::loop() {
if (eps_files->empty()) {
statusBar->clearMessage();
emit finished(true);
return;
}
*currentFile = eps_files->first();
eps_files->removeFirst();
QString directory = currentFile->canonicalPath();
QString eps_file_name = currentFile->fileName();
// Compare with MainWindow closeEvent(), checking for this message
statusBar->showMessage("Converting "+eps_file_name, 0);
converter->convert(directory, eps_file_name);
}
void ConvertAllEps::onSingleFileConversionFinished(bool success) {
success = success && doubleCheckPdfExistence();
if (success) {
if (opts().getDeleteEpsOnSuccess()) {
QFile::remove(currentFile->filePath());
}
loop();
}
else {
showErrorMsg("converting "+QDir::toNativeSeparators(currentFile->filePath())+" to PDF failed");
statusBar->clearMessage();
emit finished(false);
}
}
bool ConvertAllEps::doubleCheckPdfExistence() const {
const QString epsName = currentFile->filePath();
const QString pdfName = epsName.left(epsName.size()-4) + ".pdf";
qDebug() << "PDF name:" << pdfName;
return QFile::exists(pdfName);
}