]> git.sven.stormbind.net Git - sven/vym.git/blob - src/xsltproc.cpp
Replace Pierre as the maintainer
[sven/vym.git] / src / xsltproc.cpp
1 #include "xsltproc.h"
2
3 #include <QDebug>
4 #include <QMessageBox>
5 #include <iostream>
6
7 #include "vymprocess.h"
8
9 extern bool debug;
10
11 XSLTProc::XSLTProc()
12 {
13     xsltprocessor = "xsltproc";
14     showOutput = false;
15     dia = new ShowTextDialog;
16 }
17
18 XSLTProc::~XSLTProc() { delete (dia); }
19
20 void XSLTProc::addStringParam(const QString &k, const QString &v)
21 {
22     stringParamKey.append(k);
23     stringParamVal.append(v);
24 }
25
26 void XSLTProc::setOutputFile(const QString &s) { outputFile = s; }
27
28 void XSLTProc::setXSLFile(const QString &s) { xslFile = s; }
29
30 void XSLTProc::setInputFile(const QString &s) { inputFile = s; }
31
32 void XSLTProc::addOutput(const QString &s) { dia->append(s); }
33
34 void XSLTProc::process()
35 {
36     ShowTextDialog dia;
37     dia.useFixedFont(true);
38     QStringList args;
39     VymProcess *xsltProc = new VymProcess();
40
41     QStringList::Iterator itk;
42     QStringList::Iterator itv = stringParamVal.begin();
43
44     for (itk = stringParamKey.begin(); itk != stringParamKey.end(); ++itk) {
45         args << "--stringparam";
46         args << *itk;
47         args << *itv;
48         ++itv;
49     }
50
51     args << "--output";
52     args << outputFile;
53     args << xslFile;
54     args << inputFile;
55     QString com = xsltprocessor + " " + args.join(" ");
56     if (debug)
57         qDebug() << "xsltproc executing:\n" << qPrintable(com);
58     dia.append("vym is executing: \n" + com);
59     xsltProc->start(xsltprocessor, args);
60     if (!xsltProc->waitForStarted()) {
61         QMessageBox::critical(
62             0, QObject::tr("Critical Error"),
63             QObject::tr("Could not start %1").arg(xsltprocessor));
64     }
65     else {
66         if (!xsltProc->waitForFinished()) {
67             QMessageBox::critical(
68                 0, QObject::tr("Critical Error"),
69                 QObject::tr("%1 didn't exit normally").arg(xsltprocessor) +
70                     xsltProc->getErrout());
71             if (xsltProc->exitStatus() > 0)
72                 showOutput = true;
73         }
74     }
75     dia.append("\n");
76     dia.append(xsltProc->getErrout());
77     dia.append(xsltProc->getStdout());
78
79     if (showOutput)
80         dia.exec();
81 }