Skip to content

Commit 2c8ef6b

Browse files
committed
use correct working directory
1 parent c4b1c92 commit 2c8ef6b

File tree

3 files changed

+32
-10
lines changed

3 files changed

+32
-10
lines changed

main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ int main(int argc, char *argv[]) {
1313
KAboutData aboutData(
1414
QStringLiteral("livetikz"),
1515
i18n("LiveTikZ"),
16-
QStringLiteral("0.1"),
16+
QStringLiteral("0.2"),
1717
i18n("A TikZ editor with live preview."),
1818
KAboutLicense::GPL,
19-
i18n("(c) 2017 Michael Schwarz"),
19+
i18n("(c) 2017-2018 Michael Schwarz"),
2020
"",
2121
"https://misc0110.net"
2222
);

mainwindow.cpp

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,27 @@ void MainWindow::compile() {
6060
QSettings settings;
6161
QString program = settings.value("compiler", "pdflatex").toString();
6262
QStringList arguments;
63+
QTemporaryDir tmpdir;
64+
tmpdir.setAutoRemove(true);
65+
6366
if (program == "pdflatex") {
6467
arguments << "-halt-on-error";
6568
}
66-
arguments << "main.tex";
69+
if(dir->path() == "") {
70+
return;
71+
}
72+
if(texdir.absolutePath() == "") {
73+
std::cout << "need a temporary directory" << std::endl;
74+
texdir = QFileInfo(tmpdir.path());
75+
}
76+
77+
arguments << dir->filePath("_livetikz_preview.tex");
6778

79+
std::cout << "Arguments: " << dir->filePath("_livetikz_preview.tex").toStdString() << std::endl;
80+
std::cout << "WD: " << texdir.absolutePath().toStdString() << std::endl;
81+
6882
renderProcess = new QProcess(this);
69-
renderProcess->setWorkingDirectory(dir->path());
83+
renderProcess->setWorkingDirectory(texdir.absolutePath());
7084
renderProcess->start(program, arguments);
7185

7286
log->setText("Compiling...");
@@ -81,11 +95,13 @@ void MainWindow::compile() {
8195
}
8296

8397
void MainWindow::refresh() {
84-
dir = new QTemporaryDir();
85-
dir->setAutoRemove(false);
98+
if(!dir) {
99+
dir = new QTemporaryDir();
100+
dir->setAutoRemove(false);
101+
}
86102

87103
if (dir->isValid()) {
88-
QFile file(dir->path() + QString("/main.tex"));
104+
QFile file(dir->filePath("_livetikz_preview.tex"));
89105

90106
if (file.open(QIODevice::ReadWrite | QIODevice::Text)) {
91107
QTextStream out(&file);
@@ -163,9 +179,10 @@ void MainWindow::renderFinished(int code) {
163179
delete currentDoc;
164180
currentDoc = NULL;
165181

166-
QFile pdf_file(dir->path() + "/main.pdf");
182+
QFile pdf_file(QDir::cleanPath(texdir.absolutePath() + QDir::separator() + "_livetikz_preview.pdf"));
167183
if (pdf_file.exists()) {
168-
currentDoc = Poppler::Document::load(dir->path() + "/main.pdf");
184+
QFile::rename(QDir::cleanPath(texdir.absolutePath() + QDir::separator() + "_livetikz_preview.pdf"), dir->filePath("_livetikz_preview.pdf"));
185+
currentDoc = Poppler::Document::load(dir->filePath("_livetikz_preview.pdf"));
169186
if (currentDoc) {
170187
currentDoc->setRenderHint(Poppler::Document::TextAntialiasing);
171188
currentDoc->setRenderHint(Poppler::Document::Antialiasing);
@@ -192,6 +209,7 @@ MainWindow::MainWindow() : currentDoc(NULL), renderProcess(NULL), currentPage(0)
192209
setupMenu();
193210
setupUI();
194211

212+
dir = NULL;
195213
templateFile = QUrl(settings.value("template", "").toString());
196214
templateLabel->setText(templateFile.url(QUrl::PreferLocalFile));
197215

@@ -227,7 +245,10 @@ void MainWindow::showCompilerSelection() {
227245

228246
MainWindow::~MainWindow() {}
229247

230-
void MainWindow::load(const QUrl &url) { katePart->openUrl(url); }
248+
void MainWindow::load(const QUrl &url) {
249+
texdir = QFileInfo(url.toLocalFile());
250+
katePart->openUrl(url);
251+
}
231252

232253
void MainWindow::setupActions() {
233254
KStandardAction::open(this, SLOT(load()), actionCollection());

mainwindow.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public slots:
7070
KTextEditor::View *view;
7171
KTextEditor::Document *doc;
7272
ZoomScrollImage *display;
73+
QFileInfo texdir;
7374
QTemporaryDir* dir;
7475
Poppler::Document *currentDoc;
7576

0 commit comments

Comments
 (0)