#
#
# add_file "src/monotone/MonotoneProcess.cpp"
# content [f218f01a822ed67b7837910662367f519c718631]
#
# add_file "src/monotone/MonotoneProcess.h"
# content [5eafbef157ea2e63b4d57be4d9272488370112e8]
#
============================================================
--- src/monotone/MonotoneProcess.cpp f218f01a822ed67b7837910662367f519c718631
+++ src/monotone/MonotoneProcess.cpp f218f01a822ed67b7837910662367f519c718631
@@ -0,0 +1,122 @@
+/***************************************************************************
+ * Copyright (C) 2010 by Thomas Keller *
+ * address@hidden *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation, either version 3 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program. If not, see . *
+ ***************************************************************************/
+
+#include "MonotoneProcess.h"
+#include "Settings.h"
+#include "MonotoneUtil.h"
+#include "vocab.h"
+
+MonotoneProcess::MonotoneProcess(const QString & ws)
+{
+ setWorkingDirectory(ws);
+ setProcessChannelMode(QProcess::MergedChannels);
+
+ connect(
+ this, SIGNAL(readyReadStandardOutput()),
+ this, SLOT(readOutput())
+ );
+
+ connect(
+ this, SIGNAL(readyReadStandardError()),
+ this, SLOT(readOutput())
+ );
+
+ connect(
+ this, SIGNAL(error(QProcess::ProcessError)),
+ this, SLOT(processError(QProcess::ProcessError))
+ );
+}
+
+MonotoneProcess::~MonotoneProcess()
+{
+ if (state() != NotRunning)
+ {
+ close();
+ terminate();
+ waitForFinished();
+ }
+}
+
+void MonotoneProcess::start(const QStringList & params)
+{
+ QString mtnBinary = Settings::getMtnBinaryPath();
+
+ L(QString("starting external monotone process %1 %2")
+ .arg(mtnBinary).arg(params.join(" ")));
+
+ QProcess::start(mtnBinary, params);
+}
+
+void MonotoneProcess::readOutput()
+{
+ QByteArray out = readLine();
+ if (out.isEmpty())
+ return;
+ emit output(MonotoneUtil::stripMtnPrefix(QString::fromUtf8(out)));
+}
+
+void MonotoneProcess::processError(QProcess::ProcessError processError)
+{
+ QString message = QString::fromUtf8(readAllStandardError());
+
+ // what follows is largely copied from MonotoneManager::abort
+ QString mtnError = MonotoneUtil::stripMtnPrefix(message);
+ QString processErrorTranslated;
+
+ switch (processError)
+ {
+ case QProcess::FailedToStart:
+ processErrorTranslated = tr("failed to start");
+ break;
+ case QProcess::Crashed:
+ processErrorTranslated = tr("crashed");
+ break;
+ case QProcess::Timedout:
+ processErrorTranslated = tr("timed out waiting for data");
+ break;
+ case QProcess::WriteError:
+ processErrorTranslated = tr("failed to read");
+ break;
+ case QProcess::ReadError:
+ processErrorTranslated = tr("failed to write");
+ break;
+ case QProcess::UnknownError:
+ processErrorTranslated = tr("unknown error");
+ break;
+ default: I(false);
+ }
+
+ // log something reasonable
+ C(QString("process died (%1) - stderr was %2")
+ .arg(processErrorTranslated).arg(mtnError));
+
+ // display something understandable to the user
+ QString userMessage(tr(
+ "The monotone process for '%1' died (%2). "
+ "If you think this is a bug in guitone, "
+ "please report it to the author!"
+ ).arg(workingDirectory()).arg(processErrorTranslated));
+
+ if (!mtnError.isEmpty())
+ {
+ userMessage.append(tr("\n\nLast error output was:\n%1").arg(mtnError));
+ }
+
+ emit error(userMessage);
+}
+
============================================================
--- src/monotone/MonotoneProcess.h 5eafbef157ea2e63b4d57be4d9272488370112e8
+++ src/monotone/MonotoneProcess.h 5eafbef157ea2e63b4d57be4d9272488370112e8
@@ -0,0 +1,43 @@
+/***************************************************************************
+ * Copyright (C) 2010 by Thomas Keller *
+ * address@hidden *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation, either version 3 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program. If not, see . *
+ ***************************************************************************/
+
+#ifndef MONOTONE_PROCESS_H
+#define MONOTONE_PROCESS_H
+
+#include
+#include
+
+class MonotoneProcess : public QProcess
+{
+ Q_OBJECT
+public:
+ MonotoneProcess(const QString &);
+ virtual ~MonotoneProcess();
+
+ void start(const QStringList &);
+
+signals:
+ void output(const QString &);
+ void error(const QString &);
+
+private slots:
+ void readOutput();
+ void processError(QProcess::ProcessError);
+};
+
+#endif