forked from zl0i/QtAutoTools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlupdate.cpp
109 lines (90 loc) · 3.13 KB
/
lupdate.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
#include "lupdate.h"
Lupdate::Lupdate(QObject *parent) : QProcess(parent)
{
QHash<int, QByteArray> hash;
hash.insert(Qt::UserRole+1, "file");
filesModel->setItemRoleNames(hash);
filesModel->insertColumn(0);
filesModel->insertRow(0);
filesModel->setData(filesModel->index(0, 0), "", Qt::UserRole+1);
connect(this, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
this, QOverload<int>::of(&Lupdate::slotFinished));
connect(this, &QProcess::readyRead, this, &Lupdate::slotReadChanel);
}
void Lupdate::slotReadChanel() {
setReadChannel(QProcess::StandardError);
QByteArray error = readAll();
if(!error.isEmpty())
emit newErrorData(error);
setReadChannel(QProcess::StandardOutput);
QByteArray output = readAll();
if(!output.isEmpty())
emit newOutputData(output);
}
void Lupdate::removeFile(int row)
{
if(filesModel->rowCount() > 1)
filesModel->removeRow(row);
}
void Lupdate::addFile() {
filesModel->insertRow(filesModel->rowCount());
QModelIndex index = filesModel->index(filesModel->rowCount()-1, 0);
filesModel->setData(index, "", Qt::UserRole+1);
}
void Lupdate::setFile(int row, QString url) {
QModelIndex index = filesModel->index(row, 0);
filesModel->setData(index, url, Qt::UserRole+1);
}
void Lupdate::setLanguage(QString list) {
this->langList = list.split(" ", QString::SkipEmptyParts);
}
QString Lupdate::getStringFileTs(QString url) {
QStringList listPath = url.split("/");
QString file = listPath.last();
listPath.removeLast();
QString path = listPath.join("/");
QStringList name = file.split(".");
QStringList tsFile;
for(int i = 0; i < langList.count(); i++) {
tsFile.append(path + "/" + name.at(0) + "_" + langList.at(i) + ".ts");
}
return tsFile.join(" ");
}
void Lupdate::createTs() {
translatorList.clear();
QStringList arguments;
for(int i = 0; i < filesModel->rowCount()-1; i++) {
QModelIndex index = filesModel->index(i ,0);
arguments.append(filesModel->data(index, Qt::UserRole+1).toString());
}
arguments.append("-ts");
for(int i = 0; i < filesModel->rowCount()-1; i++) {
QModelIndex index = filesModel->index(i ,0);
translatorList.append(getStringFileTs(filesModel->data(index, Qt::UserRole+1).toString()));
arguments.append(translatorList.last());
}
QString program = Worker::getInstance()->compilerPath() + "/bin/lupdate " + arguments.join(" ");
QFile *file = Worker::prepareBatFile();
if(file) {
file->write(program.toLocal8Bit());
file->close();
file->deleteLater();
start("temp.bat");
}
}
void Lupdate::runLinguist() {
if(translatorList.count() != 0) {
startDetached(Worker::getInstance()->compilerPath() + "/bin/linguist " + translatorList.join(" "));
}
else {
startDetached(Worker::getInstance()->compilerPath() + "/bin/linguist");
}
}
void Lupdate::slotFinished(int code) {
if(code > 0) {
emit newErrorData(readAllStandardError());
} else {
emit newOutputData("Done!");
}
Worker::removeBatFile();
}