| 1 | // For license of this file, see <project-root-folder>/LICENSE.md.cxx . . $ `<file>/src/librssguard/network-web/readability.cpp`/ |
| 2 | |
| 3 | #include "network-web/readability.h"cxx . . $ `<file>/src/librssguard/network-web/readability.h`/ |
| 4 | |
| 5 | #include "3rd-party/boolinq/boolinq.h"cxx . . $ `<file>/src/librssguard/3rd-party/boolinq/boolinq.h`/ |
| 6 | #include "exceptions/applicationexception.h"cxx . . $ `<file>/src/librssguard/exceptions/applicationexception.h`/ |
| 7 | #include "miscellaneous/application.h"cxx . . $ `<file>/src/librssguard/miscellaneous/application.h`/ |
| 8 | |
| 9 | #include <QDir> |
| 10 | |
| 11 | #define READABILITY_PACKAGEcxx . . $ `src/librssguard/network-web/readability.cpp:11:9`! "@mozilla/readability" |
| 12 | #define READABILITY_VERSIONcxx . . $ `src/librssguard/network-web/readability.cpp:12:9`! "0.5.0" |
| 13 | |
| 14 | #define JSDOM_PACKAGEcxx . . $ `src/librssguard/network-web/readability.cpp:14:9`! "jsdom" |
| 15 | #define JSDOM_VERSIONcxx . . $ `src/librssguard/network-web/readability.cpp:15:9`! "24.0.0" |
| 16 | |
| 17 | Readabilitycxx . . $ Readability#::Readabilitycxx . . $ Readability#Readability(749de1b6ae65bddd).(QObjectcxx . . $ QObject#* parent) : QObjectcxx . . $ QObject#QObject(749de1b6ae65bddd).{parent}, m_modulesInstallingcxx . . $ Readability#m_modulesInstalling.(false), m_modulesInstalledcxx . . $ Readability#m_modulesInstalled.(false) { |
| 18 | connectcxx . . $ QObject#connect(dad3a9587f3dce3c).(qAppcxx . . $ `src/librssguard/miscellaneous/application.h:30:9`!->nodejscxx . . $ Application#nodejs(37aaef0f1b724263).(), &NodeJscxx . . $ NodeJs#::packageInstalledUpdatedcxx . . $ NodeJs#packageInstalledUpdated(34ac6af3085f0564)., this, &Readabilitycxx . . $ Readability#::onPackageReadycxx . . $ Readability#onPackageReady(34ac6af3085f0564).); |
| 19 | connectcxx . . $ QObject#connect(dad3a9587f3dce3c).(qAppcxx . . $ `src/librssguard/miscellaneous/application.h:30:9`!->nodejscxx . . $ Application#nodejs(37aaef0f1b724263).(), &NodeJscxx . . $ NodeJs#::packageErrorcxx . . $ NodeJs#packageError(c66daf909bbebbbc)., this, &Readabilitycxx . . $ Readability#::onPackageErrorcxx . . $ Readability#onPackageError(c66daf909bbebbbc).); |
| 20 | } |
| 21 | |
| 22 | void Readabilitycxx . . $ Readability#::onPackageReadycxx . . $ Readability#onPackageReady(34ac6af3085f0564).(const QObjectcxx . . $ QObject#* sndr, |
| 23 | const QListcxx . . $ QList#<NodeJscxx . . $ NodeJs#::PackageMetadatacxx . . $ NodeJs#PackageMetadata#>& pkgs, |
| 24 | bool already_up_to_date) { |
| 25 | Q_UNUSEDcxx . . $ `<external>/17563275351362271547/qtpreprocessorsupport.h:20:9`!(already_up_to_date) |
| 26 | |
| 27 | bool concerns_readability = boolinqcxx . . $ boolinq/::fromcxx . . $ boolinq/from(1a44d082b2747720).(pkgs).anycxx . . $ boolinq/Linq#any(992a0234366b9b4f).([cxx . . $ std/function#function(bdc3712e480e4d04).](const NodeJscxx . . $ NodeJs#::PackageMetadatacxx . . $ NodeJs#PackageMetadata#& pkg) { |
| 28 | return pkg.m_namecxx . . $ NodeJs#PackageMetadata#m_name. ==cxx . . $ `operator==`(5bc2975d2d751687). QSLcxx . . $ `src/librssguard/definitions/definitions.h:442:9`!(READABILITY_PACKAGEcxx . . $ `src/librssguard/network-web/readability.cpp:11:9`!); |
| 29 | }); |
| 30 | |
| 31 | if (!concerns_readability) { |
| 32 | return; |
| 33 | } |
| 34 | |
| 35 | m_modulesInstalledcxx . . $ Readability#m_modulesInstalled. = true; |
| 36 | m_modulesInstallingcxx . . $ Readability#m_modulesInstalling. = false; |
| 37 | |
| 38 | qAppcxx . . $ `src/librssguard/miscellaneous/application.h:30:9`!->showGuiMessagecxx . . $ Application#showGuiMessage(cf433640a87c3b52).(Notificationcxx . . $ Notification#::Eventcxx . . $ Notification#Event#::NodePackageUpdatedcxx . . $ Notification#Event#NodePackageUpdated., |
| 39 | {cxx . . $ GuiMessage#GuiMessage(b833bfd374dccacd).trcxx . . $ Readability#tr(75d9f1c324b4579d).("Packages for reader mode are installed"), |
| 40 | trcxx . . $ Readability#tr(75d9f1c324b4579d).("Reload your webpage and then you can use reader mode!"), |
| 41 | QSystemTrayIconcxx . . $ QSystemTrayIcon#::MessageIconcxx . . $ QSystemTrayIcon#MessageIcon#::Informationcxx . . $ QSystemTrayIcon#Information.}, |
| 42 | {cxx . . $ GuiMessageDestination#GuiMessageDestination(9e113dd3a0d25c95).true, true, false}); |
| 43 | |
| 44 | // Emit this just to allow readability again for user. |
| 45 | emitcxx . . $ `<external>/4830994369567095248/qtmetamacros.h:51:10`! errorOnHtmlReadabilitingcxx . . $ Readability#errorOnHtmlReadabiliting(4e4c9b6f049ed725).(sndr, trcxx . . $ Readability#tr(75d9f1c324b4579d).("Packages for reader mode are installed. You can now use reader mode!")); |
| 46 | } |
| 47 | |
| 48 | void Readabilitycxx . . $ Readability#::onPackageErrorcxx . . $ Readability#onPackageError(c66daf909bbebbbc).(const QObjectcxx . . $ QObject#* sndr, |
| 49 | const QListcxx . . $ QList#<NodeJscxx . . $ NodeJs#::PackageMetadatacxx . . $ NodeJs#PackageMetadata#>& pkgs, |
| 50 | const QStringcxx . . $ QString#& error) { |
| 51 | bool concerns_readability = boolinqcxx . . $ boolinq/::fromcxx . . $ boolinq/from(1a44d082b2747720).(pkgs).anycxx . . $ boolinq/Linq#any(992a0234366b9b4f).([cxx . . $ std/function#function(bdc3712e480e4d04).](const NodeJscxx . . $ NodeJs#::PackageMetadatacxx . . $ NodeJs#PackageMetadata#& pkg) { |
| 52 | return pkg.m_namecxx . . $ NodeJs#PackageMetadata#m_name. ==cxx . . $ `operator==`(5bc2975d2d751687). QSLcxx . . $ `src/librssguard/definitions/definitions.h:442:9`!(READABILITY_PACKAGEcxx . . $ `src/librssguard/network-web/readability.cpp:11:9`!); |
| 53 | }); |
| 54 | |
| 55 | if (!concerns_readability) { |
| 56 | return; |
| 57 | } |
| 58 | |
| 59 | m_modulesInstalledcxx . . $ Readability#m_modulesInstalled. = m_modulesInstallingcxx . . $ Readability#m_modulesInstalling. = false; |
| 60 | |
| 61 | qAppcxx . . $ `src/librssguard/miscellaneous/application.h:30:9`!->showGuiMessagecxx . . $ Application#showGuiMessage(cf433640a87c3b52).(Notificationcxx . . $ Notification#::Eventcxx . . $ Notification#Event#::NodePackageUpdatedcxx . . $ Notification#Event#NodePackageUpdated., |
| 62 | {cxx . . $ GuiMessage#GuiMessage(b833bfd374dccacd).trcxx . . $ Readability#tr(75d9f1c324b4579d).("Packages for reader mode are NOT installed"), |
| 63 | trcxx . . $ Readability#tr(75d9f1c324b4579d).("There is error: %1").argcxx . . $ QString#arg(ad0bca07273edcc2).(error), |
| 64 | QSystemTrayIconcxx . . $ QSystemTrayIcon#::MessageIconcxx . . $ QSystemTrayIcon#MessageIcon#::Criticalcxx . . $ QSystemTrayIcon#Critical.}, |
| 65 | {cxx . . $ GuiMessageDestination#GuiMessageDestination(9e113dd3a0d25c95).true, true, false}); |
| 66 | |
| 67 | // Emit this just to allow readability again for user. |
| 68 | emitcxx . . $ `<external>/4830994369567095248/qtmetamacros.h:51:10`! errorOnHtmlReadabilitingcxx . . $ Readability#errorOnHtmlReadabiliting(4e4c9b6f049ed725).(sndr, trcxx . . $ Readability#tr(75d9f1c324b4579d).("Packages for reader mode are NOT installed. There is error: %1").argcxx . . $ QString#arg(ad0bca07273edcc2).(error)); |
| 69 | } |
| 70 | |
| 71 | void Readabilitycxx . . $ Readability#::makeHtmlReadablecxx . . $ Readability#makeHtmlReadable(dfd25243aa336652).(QObjectcxx . . $ QObject#* sndr, const QStringcxx . . $ QString#& html, const QStringcxx . . $ QString#& base_url) { |
| 72 | if (!m_modulesInstalledcxx . . $ Readability#m_modulesInstalled.) { |
| 73 | try { |
| 74 | NodeJscxx . . $ NodeJs#::PackageStatuscxx . . $ NodeJs#PackageStatus# st_readability = |
| 75 | qAppcxx . . $ `src/librssguard/miscellaneous/application.h:30:9`!->nodejscxx . . $ Application#nodejs(37aaef0f1b724263).()->packageStatuscxx . . $ NodeJs#packageStatus(bc4ac2c1878ad842).({QSLcxx . . $ `src/librssguard/definitions/definitions.h:442:9`!(READABILITY_PACKAGEcxx . . $ `src/librssguard/network-web/readability.cpp:11:9`!), QSLcxx . . $ `src/librssguard/definitions/definitions.h:442:9`!(READABILITY_VERSIONcxx . . $ `src/librssguard/network-web/readability.cpp:12:9`!)}); |
| 76 | NodeJscxx . . $ NodeJs#::PackageStatuscxx . . $ NodeJs#PackageStatus# st_jsdom = qAppcxx . . $ `src/librssguard/miscellaneous/application.h:30:9`!->nodejscxx . . $ Application#nodejs(37aaef0f1b724263).()->packageStatuscxx . . $ NodeJs#packageStatus(bc4ac2c1878ad842).({QSLcxx . . $ `src/librssguard/definitions/definitions.h:442:9`!(JSDOM_PACKAGEcxx . . $ `src/librssguard/network-web/readability.cpp:14:9`!), QSLcxx . . $ `src/librssguard/definitions/definitions.h:442:9`!(JSDOM_VERSIONcxx . . $ `src/librssguard/network-web/readability.cpp:15:9`!)}); |
| 77 | |
| 78 | if (st_readability != NodeJscxx . . $ NodeJs#::PackageStatuscxx . . $ NodeJs#PackageStatus#::UpToDatecxx . . $ NodeJs#PackageStatus#UpToDate. || st_jsdom != NodeJscxx . . $ NodeJs#::PackageStatuscxx . . $ NodeJs#PackageStatus#::UpToDatecxx . . $ NodeJs#PackageStatus#UpToDate.) { |
| 79 | if (!m_modulesInstallingcxx . . $ Readability#m_modulesInstalling.) { |
| 80 | // We make sure to update modules. |
| 81 | m_modulesInstallingcxx . . $ Readability#m_modulesInstalling. = true; |
| 82 | qAppcxx . . $ `src/librssguard/miscellaneous/application.h:30:9`!->nodejscxx . . $ Application#nodejs(37aaef0f1b724263).()->installUpdatePackagescxx . . $ NodeJs#installUpdatePackages(b5245139ef44c0df).(sndr, |
| 83 | {cxx . . $ QList#QList(b6da5b9a9f304025).{QSLcxx . . $ `src/librssguard/definitions/definitions.h:442:9`!(READABILITY_PACKAGEcxx . . $ `src/librssguard/network-web/readability.cpp:11:9`!), QSLcxx . . $ `src/librssguard/definitions/definitions.h:442:9`!(READABILITY_VERSIONcxx . . $ `src/librssguard/network-web/readability.cpp:12:9`!)}, |
| 84 | {QSLcxx . . $ `src/librssguard/definitions/definitions.h:442:9`!(JSDOM_PACKAGEcxx . . $ `src/librssguard/network-web/readability.cpp:14:9`!), QSLcxx . . $ `src/librssguard/definitions/definitions.h:442:9`!(JSDOM_VERSIONcxx . . $ `src/librssguard/network-web/readability.cpp:15:9`!)}}); |
| 85 | } |
| 86 | |
| 87 | return; |
| 88 | } |
| 89 | else { |
| 90 | m_modulesInstalledcxx . . $ Readability#m_modulesInstalled. = true; |
| 91 | } |
| 92 | } |
| 93 | catch (const ApplicationExceptioncxx . . $ ApplicationException#& ex) { |
| 94 | qAppcxx . . $ `src/librssguard/miscellaneous/application.h:30:9`!->showGuiMessagecxx . . $ Application#showGuiMessage(cf433640a87c3b52).(Notificationcxx . . $ Notification#::Eventcxx . . $ Notification#Event#::NodePackageUpdatedcxx . . $ Notification#Event#NodePackageUpdated., |
| 95 | {cxx . . $ GuiMessage#GuiMessage(b833bfd374dccacd).trcxx . . $ Readability#tr(75d9f1c324b4579d).("Node.js libraries not installed"), |
| 96 | trcxx . . $ Readability#tr(75d9f1c324b4579d).("Node.js is not configured properly. Go to \"Settings\" -> \"Node.js\" and check " |
| 97 | "if your Node.js is properly configured."), |
| 98 | QSystemTrayIconcxx . . $ QSystemTrayIcon#::MessageIconcxx . . $ QSystemTrayIcon#MessageIcon#::Criticalcxx . . $ QSystemTrayIcon#Critical.}, |
| 99 | {cxx . . $ GuiMessageDestination#GuiMessageDestination(9e113dd3a0d25c95).true, true, false}); |
| 100 | |
| 101 | qCriticalNNcxx . . $ `src/librssguard/definitions/definitions.h:421:9`! <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). LOGSEC_COREcxx . . $ `src/librssguard/definitions/definitions.h:178:9`! <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). "Failed to check for Node.js package status:" <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). QUOTE_W_SPACE_DOTcxx . . $ `src/librssguard/definitions/definitions.h:430:9`!(ex.message()); |
| 102 | |
| 103 | // Emit this just to allow readability again for user. |
| 104 | emitcxx . . $ `<external>/4830994369567095248/qtmetamacros.h:51:10`! |
| 105 | errorOnHtmlReadabilitingcxx . . $ Readability#errorOnHtmlReadabiliting(4e4c9b6f049ed725).(sndr, |
| 106 | trcxx . . $ Readability#tr(75d9f1c324b4579d).("Node.js is not configured properly. Go to \"Settings\" -> \"Node.js\" and check " |
| 107 | "if your Node.js is properly configured.")); |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | QStringcxx . . $ QString# temp_script = |
| 112 | QDircxx . . $ QDir#::toNativeSeparatorscxx . . $ QDir#toNativeSeparators(fd988a2ab94d906b).(IOFactorycxx . . $ IOFactory#::getSystemFoldercxx . . $ IOFactory#getSystemFolder(7d8b34fbb6a9c1bf).(QStandardPathscxx . . $ QStandardPaths#::StandardLocationcxx . . $ QStandardPaths#StandardLocation#::TempLocationcxx . . $ QStandardPaths#TempLocation.)) + |
| 113 | QDircxx . . $ QDir#::separatorcxx . . $ QDir#separator(44eb9225326fcbf5).() + QSLcxx . . $ `src/librssguard/definitions/definitions.h:442:9`!("readabilize-article.js"); |
| 114 | |
| 115 | if (!IOFactorycxx . . $ IOFactory#::copyFilecxx . . $ IOFactory#copyFile(edf9e4f73813982f).(QSLcxx . . $ `src/librssguard/definitions/definitions.h:442:9`!(":/scripts/readability/readabilize-article.js"), temp_script)) { |
| 116 | qWarningNNcxx . . $ `src/librssguard/definitions/definitions.h:417:9`! <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). LOGSEC_ADBLOCKcxx . . $ `src/librssguard/definitions/definitions.h:169:9`! <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). "Failed to copy Readability script to TEMP."; |
| 117 | } |
| 118 | |
| 119 | QProcesscxx . . $ QProcess#* proc = new QProcesscxx . . $ QProcess#QProcess(749de1b6ae65bddd).(this); |
| 120 | |
| 121 | connectcxx . . $ QObject#connect(dad3a9587f3dce3c).(proc, |
| 122 | QOverloadcxx . . $ QOverload#<int, QProcess::ExitStatus>::ofcxx . . $ QOverload#of(8e142c06a530e2ab).(&QProcesscxx . . $ QProcess#::finishedcxx . . $ QProcess#finished(15c350e1a5203cbf).), |
| 123 | this, |
| 124 | [=](int exit_code, QProcesscxx . . $ QProcess#::ExitStatuscxx . . $ QProcess#ExitStatus# exit_status) { |
| 125 | onReadabilityFinishedcxx . . $ Readability#onReadabilityFinished(5525948d392b05e).(sndr, exit_code, exit_status); |
| 126 | }); |
| 127 | |
| 128 | qAppcxx . . $ `src/librssguard/miscellaneous/application.h:30:9`!->nodejscxx . . $ Application#nodejs(37aaef0f1b724263).()->runScriptcxx . . $ NodeJs#runScript(b32167958b67e3d).(proc, temp_script, {cxx . . $ QList#QList(b6da5b9a9f304025).base_url}); |
| 129 | |
| 130 | proc->writecxx . . $ QIODevice#write(4ee2750a0be83987).(html.toUtf8cxx . . $ QString#toUtf8(ef52b713090bc85a).()); |
| 131 | proc->closeWriteChannelcxx . . $ QProcess#closeWriteChannel(49f6e7a06ebc5aa8).(); |
| 132 | } |
| 133 | |
| 134 | void Readabilitycxx . . $ Readability#::onReadabilityFinishedcxx . . $ Readability#onReadabilityFinished(5525948d392b05e).(QObjectcxx . . $ QObject#* sndr, int exit_code, QProcesscxx . . $ QProcess#::ExitStatuscxx . . $ QProcess#ExitStatus# exit_status) { |
| 135 | QProcesscxx . . $ QProcess#* proc = qobject_castcxx . . $ qobject_cast(c988cfc0ca08742e).<QProcesscxx . . $ QProcess#*>(sendercxx . . $ QObject#sender(2dbb680a34285c44).()); |
| 136 | |
| 137 | if (exit_status == QProcesscxx . . $ QProcess#::ExitStatuscxx . . $ QProcess#ExitStatus#::NormalExitcxx . . $ QProcess#NormalExit. && exit_code == EXIT_SUCCESScxx . . $ `<external>/10696550936717951914/stdlib.h:93:9`!) { |
| 138 | emitcxx . . $ `<external>/4830994369567095248/qtmetamacros.h:51:10`! htmlReadabledcxx . . $ Readability#htmlReadabled(4e4c9b6f049ed725).(sndr, QStringcxx . . $ QString#::fromUtf8cxx . . $ QString#fromUtf8(4e15edac36d215be).(proc->readAllStandardOutputcxx . . $ QProcess#readAllStandardOutput(b3c286cec66e09f4).())); |
| 139 | } |
| 140 | else { |
| 141 | QStringcxx . . $ QString# err = QStringcxx . . $ QString#::fromUtf8cxx . . $ QString#fromUtf8(4e15edac36d215be).(proc->readAllStandardErrorcxx . . $ QProcess#readAllStandardError(b3c286cec66e09f4).()); |
| 142 | emitcxx . . $ `<external>/4830994369567095248/qtmetamacros.h:51:10`! errorOnHtmlReadabilitingcxx . . $ Readability#errorOnHtmlReadabiliting(4e4c9b6f049ed725).(sndr, err); |
| 143 | } |
| 144 | |
| 145 | proc->deleteLatercxx . . $ QObject#deleteLater(49f6e7a06ebc5aa8).(); |
| 146 | } |