]> git.sven.stormbind.net Git - sven/vym.git/blobdiff - src/vymprocess.cpp
New upstream version 2.9.22
[sven/vym.git] / src / vymprocess.cpp
diff --git a/src/vymprocess.cpp b/src/vymprocess.cpp
new file mode 100644 (file)
index 0000000..f87c20a
--- /dev/null
@@ -0,0 +1,67 @@
+#include "vymprocess.h"
+#include <cstdlib>
+
+#include <QDebug>
+#include <QMessageBox>
+
+extern bool debug;
+
+/////////////////////////////////////////////////////////////////
+// Process
+/////////////////////////////////////////////////////////////////
+VymProcess::VymProcess()
+{
+    connect(this, SIGNAL(readyReadStandardError()), this,
+            SLOT(readProcErrout()));
+    connect(this, SIGNAL(readyReadStandardOutput()), this,
+            SLOT(readProcStdout()));
+    clear();
+}
+
+VymProcess::~VymProcess() {}
+
+void VymProcess::clear()
+{
+    errOut = "";
+    stdOut = "";
+}
+
+void VymProcess::runScript(QString spath, QString fpath)
+{
+    spath.replace("%f", fpath);
+    QStringList args = spath.split(' ');
+    spath = args.takeFirst();
+
+    if (debug)
+        qDebug() << "Process::runScript : " + spath + " " + args.join(" ");
+
+    start(spath, args);
+    if (!waitForStarted()) {
+        QMessageBox::critical(0, tr("Critical Error"),
+                              tr("Could not start %1").arg(spath));
+    }
+    else {
+        if (!waitForFinished())
+            QMessageBox::critical(0, tr("Critical Error"),
+                                  tr("%1 didn't exit normally").arg(spath) +
+                                      getErrout());
+        //     else
+        //         if (exitStatus()>0) showOutput=true;
+    }
+    /* TODO output for Process::runScript
+    qDebug()<<readAllStandardOutput();
+    qDebug()<<getStdout();
+    qDebug()<<getErrout();
+    addOutput ("\n");
+    addOutput (getErrout());
+    addOutput (getStdout());
+    */
+}
+
+void VymProcess::readProcErrout() { errOut += readAllStandardError(); }
+
+void VymProcess::readProcStdout() { stdOut += readAllStandardOutput(); }
+
+QString VymProcess::getErrout() { return errOut; }
+
+QString VymProcess::getStdout() { return stdOut; }