|
23 | 23 | #include <QUrlQuery> |
24 | 24 | #include <QWebPage> |
25 | 25 | #include <QWebFrame> |
26 | | -#include <QProcess> |
27 | 26 | #include <QTimer> |
28 | 27 | #include <QJsonDocument> |
29 | 28 | #include <QJsonObject> |
30 | | -#include <QFileDialog> |
31 | 29 | #include <QInputDialog> |
32 | 30 | #include <QMessageBox> |
33 | 31 |
|
34 | 32 | #include "file-reader.h" |
| 33 | +#include "perl-debugger-handler.h" |
35 | 34 | #include "script-handler.h" |
36 | 35 |
|
37 | 36 | // ============================== |
@@ -454,149 +453,6 @@ public slots: |
454 | 453 | emit closeWindowSignal(); |
455 | 454 | } |
456 | 455 |
|
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 | | - |
600 | 456 | protected: |
601 | 457 | // ============================== |
602 | 458 | // Link clicking management: |
@@ -746,7 +602,23 @@ public slots: |
746 | 602 | navigationType == |
747 | 603 | QWebPage::NavigationTypeFormSubmitted) and |
748 | 604 | 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 | + |
750 | 622 | return false; |
751 | 623 | } |
752 | 624 | #endif |
@@ -924,10 +796,10 @@ public slots: |
924 | 796 | QString yesLabel; |
925 | 797 | QString noLabel; |
926 | 798 |
|
927 | | - QProcess debuggerHandler; |
928 | | - QString debuggerAccumulatedOutput; |
| 799 | + QPerlDebuggerHandler *debuggerHandler; |
929 | 800 |
|
930 | 801 | public: |
| 802 | + QPage(); |
931 | 803 | QHash<QString, QScriptHandler*> runningScripts; |
932 | 804 | }; |
933 | 805 |
|
|
0 commit comments