Skip to content

Commit f16ddd9

Browse files
committed
Perl Debugger GUI in separate class
1 parent 3e68554 commit f16ddd9

File tree

7 files changed

+247
-166
lines changed

7 files changed

+247
-166
lines changed

src/page.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,4 @@ QPage::QPage()
139139

140140
lastTargetFrame = currentFrame();
141141
windowCloseRequested = false;
142-
143-
// Signal and slot for the Perl debugger:
144-
#if PERL_DEBUGGER_GUI == 1
145-
QObject::connect(&debuggerHandler, SIGNAL(readyReadStandardOutput()),
146-
this, SLOT(qDebuggerOutputSlot()));
147-
#endif
148142
}

src/page.h

Lines changed: 20 additions & 148 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,14 @@
2323
#include <QUrlQuery>
2424
#include <QWebPage>
2525
#include <QWebFrame>
26-
#include <QProcess>
2726
#include <QTimer>
2827
#include <QJsonDocument>
2928
#include <QJsonObject>
30-
#include <QFileDialog>
3129
#include <QInputDialog>
3230
#include <QMessageBox>
3331

3432
#include "file-reader.h"
33+
#include "perl-debugger-handler.h"
3534
#include "script-handler.h"
3635

3736
// ==============================
@@ -454,149 +453,6 @@ public slots:
454453
emit closeWindowSignal();
455454
}
456455

457-
// ==============================
458-
// Perl Debugger GUI:
459-
// Implementation of an idea proposed by Valcho Nedelchev
460-
// ==============================
461-
void qHandlePerlDebugger(QUrl url)
462-
{
463-
#if PERL_DEBUGGER_GUI == 1
464-
QString scriptToDebug;
465-
QString commandLineArguments;
466-
467-
// Select a Perl script for debugging:
468-
if (url.query().contains("action=select-file")) {
469-
QFileDialog selectScriptToDebugDialog(qApp->activeWindow());
470-
selectScriptToDebugDialog
471-
.setFileMode(QFileDialog::ExistingFile);
472-
selectScriptToDebugDialog
473-
.setViewMode(QFileDialog::Detail);
474-
selectScriptToDebugDialog
475-
.setWindowModality(Qt::WindowModal);
476-
477-
scriptToDebug = selectScriptToDebugDialog
478-
.getOpenFileName
479-
(qApp->activeWindow(), "Select Perl File",
480-
QDir::currentPath(), "Perl scripts (*.pl);;All files (*)");
481-
482-
selectScriptToDebugDialog.close();
483-
selectScriptToDebugDialog.deleteLater();
484-
485-
if (scriptToDebug.length() > 1) {
486-
scriptToDebug = QDir::toNativeSeparators(scriptToDebug);
487-
488-
bool ok;
489-
QString input =
490-
QInputDialog::getText(
491-
qApp->activeWindow(),
492-
"Command Line",
493-
"Enter all command line arguments, if any:",
494-
QLineEdit::Normal,
495-
"",
496-
&ok);
497-
498-
if (ok && !input.isEmpty()) {
499-
commandLineArguments = input;
500-
}
501-
502-
// Close any still open Perl debugger session:
503-
debuggerHandler.close();
504-
505-
// Start the Perl debugger:
506-
qDebug() << QDateTime::currentMSecsSinceEpoch()
507-
<< "msecs from epoch: file passed to Perl debugger:"
508-
<< scriptToDebug;
509-
}
510-
}
511-
512-
// Get a Perl debugger command:
513-
QUrlQuery scriptQuery(url);
514-
515-
QString debuggerCommand = scriptQuery
516-
.queryItemValue("command", QUrl::FullyDecoded);
517-
debuggerCommand.replace("+", " ");
518-
519-
// Clean any previous debugger output:
520-
debuggerAccumulatedOutput = "";
521-
522-
if (debuggerHandler.isOpen()) {
523-
if (debuggerCommand.length() > 0) {
524-
qDebug() << QDateTime::currentMSecsSinceEpoch()
525-
<< "msecs from epoch: Perl debugger command:"
526-
<< debuggerCommand;
527-
528-
QByteArray debuggerCommandArray;
529-
debuggerCommandArray.append(debuggerCommand.toLatin1());
530-
debuggerCommandArray.append(QString("\n").toLatin1());
531-
debuggerHandler.write(debuggerCommandArray);
532-
}
533-
} else {
534-
// Sеt the environment for the debugged script:
535-
QProcessEnvironment systemEnvironment =
536-
QProcessEnvironment::systemEnvironment();
537-
systemEnvironment.insert("PERLDB_OPTS", "ReadLine=0");
538-
debuggerHandler.setProcessEnvironment(systemEnvironment);
539-
540-
QFileInfo scriptAbsoluteFilePath(scriptToDebug);
541-
QString scriptDirectory = scriptAbsoluteFilePath.absolutePath();
542-
debuggerHandler.setWorkingDirectory(scriptDirectory);
543-
544-
debuggerHandler.setProcessChannelMode(QProcess::MergedChannels);
545-
debuggerHandler.start(qApp->property("perlInterpreter")
546-
.toString(),
547-
QStringList()
548-
<< "-d"
549-
<< scriptToDebug
550-
<< commandLineArguments,
551-
QProcess::Unbuffered
552-
| QProcess::ReadWrite);
553-
554-
QByteArray debuggerCommandArray;
555-
debuggerCommandArray.append(debuggerCommand.toLatin1());
556-
debuggerCommandArray.append(QString("\n").toLatin1());
557-
debuggerHandler.write(debuggerCommandArray);
558-
}
559-
#endif
560-
}
561-
562-
void qDebuggerOutputSlot()
563-
{
564-
#if PERL_DEBUGGER_GUI == 1
565-
// Read debugger output:
566-
QString debuggerOutput = debuggerHandler.readAllStandardOutput();
567-
568-
// Append last output of the debugger to
569-
// the accumulated debugger output:
570-
debuggerAccumulatedOutput.append(debuggerOutput);
571-
572-
// qDebug() << QDateTime::currentMSecsSinceEpoch()
573-
// << "msecs from epoch:"
574-
// << "Perl debugger raw output:" << endl
575-
// << debuggerOutput;
576-
577-
// Formatting of Perl debugger output is started only after
578-
// the final command prompt comes out of the debugger:
579-
if (debuggerAccumulatedOutput.contains(QRegExp ("DB\\<\\d{1,5}\\>"))) {
580-
QUrl debuggerOutputFormatterUrl =
581-
QUrl::fromLocalFile(
582-
QDir::toNativeSeparators(
583-
QApplication::applicationDirPath()) +
584-
"/perl5dbgui/perl5dbgui.pl");
585-
586-
QByteArray debuggerOutputArray;
587-
debuggerOutputArray.append(debuggerAccumulatedOutput.toLatin1());
588-
589-
// Clean any previous debugger output:
590-
debuggerAccumulatedOutput = "";
591-
592-
qHandleScriptSlot(debuggerOutputFormatterUrl, debuggerOutputArray);
593-
}
594-
#endif
595-
}
596-
597-
public:
598-
QPage();
599-
600456
protected:
601457
// ==============================
602458
// Link clicking management:
@@ -746,7 +602,23 @@ public slots:
746602
navigationType ==
747603
QWebPage::NavigationTypeFormSubmitted) and
748604
request.url().fileName() == "perl-debugger.function") {
749-
qHandlePerlDebugger(request.url());
605+
606+
if (request.url().toString()
607+
.contains("action=select-file")) {
608+
debuggerHandler = new QPerlDebuggerHandler();
609+
610+
QObject::connect(debuggerHandler,
611+
SIGNAL(startDebuggerFormatterSignal(
612+
QUrl,
613+
QByteArray)),
614+
this,
615+
SLOT(qHandleScriptSlot(
616+
QUrl,
617+
QByteArray)));
618+
}
619+
620+
debuggerHandler->qHandleDebuggerSlot(request.url());
621+
750622
return false;
751623
}
752624
#endif
@@ -924,10 +796,10 @@ public slots:
924796
QString yesLabel;
925797
QString noLabel;
926798

927-
QProcess debuggerHandler;
928-
QString debuggerAccumulatedOutput;
799+
QPerlDebuggerHandler *debuggerHandler;
929800

930801
public:
802+
QPage();
931803
QHash<QString, QScriptHandler*> runningScripts;
932804
};
933805

src/peb.pro

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,17 @@ equals (QT_MAJOR_VERSION, 5) {
121121
# Printing support:
122122
QT += printsupport
123123

124+
# Source files:
125+
SOURCES += \
126+
main.cpp \
127+
file-reader.cpp \
128+
exit-handler.cpp \
129+
local-reply.cpp \
130+
main-window.cpp \
131+
page.cpp \
132+
script-handler.cpp \
133+
view.cpp
134+
124135
# Header files:
125136
HEADERS += \
126137
access-manager.h \
@@ -132,16 +143,15 @@ equals (QT_MAJOR_VERSION, 5) {
132143
script-handler.h \
133144
view.h
134145

135-
# Source files:
136-
SOURCES += \
137-
main.cpp \
138-
file-reader.cpp \
139-
exit-handler.cpp \
140-
local-reply.cpp \
141-
main-window.cpp \
142-
page.cpp \
143-
script-handler.cpp \
144-
view.cpp
146+
equals (PERL_DEBUGGER_GUI, 1) {
147+
# Perl Debugger GUI source file:
148+
SOURCES += \
149+
perl-debugger-handler.cpp
150+
151+
# Perl Debugger GUI header file:
152+
HEADERS += \
153+
perl-debugger-handler.h
154+
}
145155

146156
# Resources:
147157
RESOURCES += resources/peb.qrc

src/perl-debugger-handler.cpp

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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+
#include "perl-debugger-handler.h"
19+
20+
// ==============================
21+
// PERL DEBUGGER HANDLER CLASS CONSTRUCTOR:
22+
// Implementation of an idea proposed by Valcho Nedelchev
23+
// ==============================
24+
QPerlDebuggerHandler::QPerlDebuggerHandler()
25+
: QObject(0)
26+
{
27+
// Select a Perl script for debugging:
28+
QFileDialog selectScriptToDebugDialog(qApp->activeWindow());
29+
selectScriptToDebugDialog
30+
.setFileMode(QFileDialog::ExistingFile);
31+
selectScriptToDebugDialog
32+
.setViewMode(QFileDialog::Detail);
33+
selectScriptToDebugDialog
34+
.setWindowModality(Qt::WindowModal);
35+
36+
QString scriptToDebug = selectScriptToDebugDialog
37+
.getOpenFileName
38+
(qApp->activeWindow(), "Select Perl File",
39+
QDir::currentPath(), "Perl scripts (*.pl);;All files (*)");
40+
41+
selectScriptToDebugDialog.close();
42+
selectScriptToDebugDialog.deleteLater();
43+
44+
QString commandLineArguments;
45+
46+
if (scriptToDebug.length() > 1) {
47+
scriptToDebug = QDir::toNativeSeparators(scriptToDebug);
48+
49+
// Get all command-line arguments for the debugged Perl script:
50+
bool ok;
51+
QString input =
52+
QInputDialog::getText(
53+
qApp->activeWindow(),
54+
"Command Line",
55+
"Enter all command line arguments, if any:",
56+
QLineEdit::Normal,
57+
"",
58+
&ok);
59+
60+
if (ok && !input.isEmpty()) {
61+
commandLineArguments = input;
62+
}
63+
64+
qDebug() << QDateTime::currentMSecsSinceEpoch()
65+
<< "msecs from epoch: file passed to Perl debugger:"
66+
<< scriptToDebug;
67+
}
68+
69+
// Signal and slot for reading the Perl debugger output:
70+
QObject::connect(&debuggerHandler, SIGNAL(readyReadStandardOutput()),
71+
this, SLOT(qDebuggerOutputSlot()));
72+
73+
// Sеt the environment for the debugged script:
74+
QProcessEnvironment systemEnvironment =
75+
QProcessEnvironment::systemEnvironment();
76+
systemEnvironment.insert("PERLDB_OPTS", "ReadLine=0");
77+
debuggerHandler.setProcessEnvironment(systemEnvironment);
78+
79+
QFileInfo scriptAbsoluteFilePath(scriptToDebug);
80+
QString scriptDirectory = scriptAbsoluteFilePath.absolutePath();
81+
debuggerHandler.setWorkingDirectory(scriptDirectory);
82+
83+
debuggerHandler.setProcessChannelMode(QProcess::MergedChannels);
84+
85+
debuggerHandler.start(qApp->property("perlInterpreter")
86+
.toString(),
87+
QStringList()
88+
<< "-d"
89+
<< scriptToDebug
90+
<< commandLineArguments,
91+
QProcess::Unbuffered
92+
| QProcess::ReadWrite);
93+
}

0 commit comments

Comments
 (0)