|
| 1 | +/* |
| 2 | + Perl Executing Browser |
| 3 | + |
| 4 | + This program is free software; |
| 5 | + you can redistribute it and/or modify it under the terms of the |
| 6 | + GNU Lesser General Public License, |
| 7 | + as published by the Free Software Foundation; |
| 8 | + either version 3 of the License, or (at your option) any later version. |
| 9 | + This program is distributed in the hope that it will be useful, |
| 10 | + but WITHOUT ANY WARRANTY; |
| 11 | + without even the implied warranty of MERCHANTABILITY or |
| 12 | + FITNESS FOR A PARTICULAR PURPOSE. |
| 13 | + Dimitar D. Mitov, 2013 - 2017 |
| 14 | + Valcho Nedelchev, 2014 - 2016 |
| 15 | + https://github.com/ddmitov/perl-executing-browser |
| 16 | +*/ |
| 17 | + |
| 18 | +#ifndef PERLDEBUGGERHANDLER_H |
| 19 | +#define PERLDEBUGGERHANDLER_H |
| 20 | + |
| 21 | +#include <QApplication> |
| 22 | +#include <QDir> |
| 23 | +#include <QDateTime> |
| 24 | +#include <QDebug> |
| 25 | +#include <QFileDialog> |
| 26 | +#include <QInputDialog> |
| 27 | +#include <QProcess> |
| 28 | +#include <QUrl> |
| 29 | +#include <QUrlQuery> |
| 30 | + |
| 31 | +// ============================== |
| 32 | +// PERL DEBUGGER HANDLER CONSTRUCTOR: |
| 33 | +// Implementation of an idea proposed by Valcho Nedelchev |
| 34 | +// ============================== |
| 35 | +class QPerlDebuggerHandler : public QObject |
| 36 | +{ |
| 37 | + Q_OBJECT |
| 38 | + |
| 39 | +signals: |
| 40 | + void startDebuggerFormatterSignal(QUrl debuggerOutputFormatterUrl, |
| 41 | + QByteArray debuggerOutputArray); |
| 42 | + |
| 43 | +public slots: |
| 44 | + void qHandleDebuggerSlot(QUrl url) |
| 45 | + { |
| 46 | + // Get a Perl debugger command: |
| 47 | + QUrlQuery scriptQuery(url); |
| 48 | + |
| 49 | + QString debuggerCommand = scriptQuery |
| 50 | + .queryItemValue("command", QUrl::FullyDecoded); |
| 51 | + debuggerCommand.replace("+", " "); |
| 52 | + |
| 53 | + if (debuggerHandler.isOpen()) { |
| 54 | + if (debuggerCommand.length() > 0) { |
| 55 | + qDebug() << QDateTime::currentMSecsSinceEpoch() |
| 56 | + << "msecs from epoch: Perl debugger command:" |
| 57 | + << debuggerCommand; |
| 58 | + |
| 59 | + QByteArray debuggerCommandArray; |
| 60 | + debuggerCommandArray.append(debuggerCommand.toLatin1()); |
| 61 | + debuggerCommandArray.append(QString("\n").toLatin1()); |
| 62 | + debuggerHandler.write(debuggerCommandArray); |
| 63 | + } |
| 64 | + } |
| 65 | + } |
| 66 | + |
| 67 | + void qDebuggerOutputSlot() |
| 68 | + { |
| 69 | + // Read debugger output: |
| 70 | + QString debuggerOutput = debuggerHandler.readAllStandardOutput(); |
| 71 | + |
| 72 | + // Append last output of the debugger to |
| 73 | + // the accumulated debugger output: |
| 74 | + debuggerAccumulatedOutput.append(debuggerOutput); |
| 75 | + |
| 76 | + // qDebug() << QDateTime::currentMSecsSinceEpoch() |
| 77 | + // << "msecs from epoch:" |
| 78 | + // << "Perl debugger raw output:" << endl |
| 79 | + // << debuggerOutput; |
| 80 | + |
| 81 | + // Formatting of Perl debugger output is started only after |
| 82 | + // the final command prompt comes out of the debugger: |
| 83 | + if (debuggerAccumulatedOutput.contains(QRegExp ("DB\\<\\d{1,5}\\>"))) { |
| 84 | + |
| 85 | + QString debuggerOutputFormatterFilePath = |
| 86 | + "http://" + |
| 87 | + QString(qApp->property("pseudoDomain").toString()) + |
| 88 | + "/perl5dbgui/perl5dbgui.pl"; |
| 89 | + |
| 90 | + QByteArray debuggerOutputArray; |
| 91 | + debuggerOutputArray.append(debuggerAccumulatedOutput.toLatin1()); |
| 92 | + |
| 93 | + |
| 94 | + startDebuggerFormatterSignal(QUrl(debuggerOutputFormatterFilePath), |
| 95 | + debuggerOutputArray); |
| 96 | + |
| 97 | + // Clean any previous debugger output: |
| 98 | + debuggerAccumulatedOutput = ""; |
| 99 | + } |
| 100 | + } |
| 101 | +private: |
| 102 | + QProcess debuggerHandler; |
| 103 | + QString debuggerAccumulatedOutput; |
| 104 | + |
| 105 | +public: |
| 106 | + QPerlDebuggerHandler(); |
| 107 | +}; |
| 108 | + |
| 109 | +#endif // PERLDEBUGGERHANDLER_H |
0 commit comments