qspexecwebengineurlschemehandler.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #include "qspexecwebengineurlschemehandler.h"
  2. #include <QString>
  3. #include <QBuffer>
  4. #include <QUrl>
  5. #include <QMessageBox>
  6. #include <qsp_default.h>
  7. #include "callbacks_gui.h"
  8. #include "comtools.h"
  9. QspExecWebEngineUrlSchemeHandler::QspExecWebEngineUrlSchemeHandler(QObject *parent) : QWebEngineUrlSchemeHandler(parent)
  10. {
  11. }
  12. void QspExecWebEngineUrlSchemeHandler::requestStarted(QWebEngineUrlRequestJob *request)
  13. {
  14. url = request->requestUrl();
  15. QTimer::singleShot(0, this, SLOT(QspLinkClicked()));
  16. }
  17. void QspExecWebEngineUrlSchemeHandler::QspLinkClicked()
  18. {
  19. emit qspLinkClicked(url);
  20. }
  21. void QspExecWebEngineUrlSchemeHandler::legacyLinkClicked(QWebEngineUrlRequestJob *request)
  22. {
  23. url = request->requestUrl();
  24. QString href;
  25. href = QByteArray::fromPercentEncoding(url.toString().toUtf8());
  26. QString string = href.mid(5);
  27. if (!QSPExecString(qspStringFromQString(string), QSP_TRUE))
  28. {
  29. QString errorMessage;
  30. QSP_CHAR *loc;
  31. int code, actIndex, line;
  32. QSPGetLastErrorData(&code, &loc, &actIndex, &line);
  33. QString desc = QSPTools::qspStrToQt(QSPGetErrorDesc(code));
  34. if (loc)
  35. errorMessage = QString("Location: %1\nArea: %2\nLine: %3\nCode: %4\nDesc: %5")
  36. .arg(QSPTools::qspStrToQt(loc))
  37. .arg(actIndex < 0 ? QString("on visit") : QString("on action"))
  38. .arg(line)
  39. .arg(code)
  40. .arg(desc);
  41. else
  42. errorMessage = QString("Code: %1\nDesc: %2")
  43. .arg(code)
  44. .arg(desc);
  45. QMessageBox dialog(QMessageBox::Critical, tr("Error"), errorMessage, QMessageBox::Ok);
  46. dialog.exec();
  47. QSPCallBacks::RefreshInt(QSP_FALSE);
  48. }
  49. //request->redirect(QUrl("qsp:/"));
  50. }