make readability aware of which sender requested, fixes #1300
This commit is contained in:
parent
31a598c5d7
commit
60da2d916d
4 changed files with 27 additions and 26 deletions
|
@ -163,7 +163,7 @@ void WebBrowser::loadMessages(const QList<Message>& messages, RootItem* root) {
|
|||
|
||||
void WebBrowser::readabilePage() {
|
||||
m_actionReadabilePage->setEnabled(false);
|
||||
qApp->web()->readability()->makeHtmlReadable(m_webView->html(), m_webView->url().toString());
|
||||
qApp->web()->readability()->makeHtmlReadable(this, m_webView->html(), m_webView->url().toString());
|
||||
}
|
||||
|
||||
bool WebBrowser::eventFilter(QObject* watched, QEvent* event) {
|
||||
|
@ -264,19 +264,16 @@ void WebBrowser::newWindowRequested(WebViewer* viewer) {
|
|||
qApp->mainForm()->tabWidget()->addBrowser(false, false, browser);
|
||||
}
|
||||
|
||||
void WebBrowser::setReadabledHtml(const QString& better_html) {
|
||||
if (!better_html.isEmpty()) {
|
||||
void WebBrowser::setReadabledHtml(QObject* sndr, const QString& better_html) {
|
||||
if (sndr == this && !better_html.isEmpty()) {
|
||||
m_webView->setReadabledHtml(better_html, m_webView->url());
|
||||
}
|
||||
}
|
||||
|
||||
void WebBrowser::readabilityFailed(const QString& error) {
|
||||
MsgBox::show({},
|
||||
QMessageBox::Icon::Critical,
|
||||
tr("Reader mode failed for this website"),
|
||||
tr("Reader mode cannot be applied to current page."),
|
||||
{},
|
||||
error);
|
||||
void WebBrowser::readabilityFailed(QObject* sndr, const QString& error) {
|
||||
if (sndr == this && !error.isEmpty()) {
|
||||
m_webView->setReadabledHtml(error, m_webView->url());
|
||||
}
|
||||
}
|
||||
|
||||
void WebBrowser::initializeLayout() {
|
||||
|
|
|
@ -70,8 +70,8 @@ class WebBrowser : public TabContent {
|
|||
void newWindowRequested(WebViewer* viewer);
|
||||
|
||||
void readabilePage();
|
||||
void setReadabledHtml(const QString& better_html);
|
||||
void readabilityFailed(const QString& error);
|
||||
void setReadabledHtml(QObject *sndr, const QString& better_html);
|
||||
void readabilityFailed(QObject *sndr, const QString& error);
|
||||
|
||||
signals:
|
||||
void windowCloseRequested();
|
||||
|
|
|
@ -35,12 +35,12 @@ void Readability::onPackageReady(const QList<NodeJs::PackageMetadata>& pkgs, boo
|
|||
|
||||
qApp->showGuiMessage(Notification::Event::NodePackageUpdated,
|
||||
{tr("Packages for reader mode are installed"),
|
||||
tr("You can now use reader mode!"),
|
||||
tr("Reload your webpage and then you can use reader mode!"),
|
||||
QSystemTrayIcon::MessageIcon::Information},
|
||||
{true, true, false});
|
||||
|
||||
// Emit this just to allow readability again for user.
|
||||
emit htmlReadabled({});
|
||||
emit htmlReadabled(nullptr, tr("Packages for reader mode are installed. You can now use reader mode!"));
|
||||
}
|
||||
|
||||
void Readability::onPackageError(const QList<NodeJs::PackageMetadata>& pkgs, const QString& error) {
|
||||
|
@ -61,10 +61,10 @@ void Readability::onPackageError(const QList<NodeJs::PackageMetadata>& pkgs, con
|
|||
{true, true, false});
|
||||
|
||||
// Emit this just to allow readability again for user.
|
||||
emit htmlReadabled({});
|
||||
emit htmlReadabled(nullptr, tr("Packages for reader mode are NOT installed. There is error: %1").arg(error));
|
||||
}
|
||||
|
||||
void Readability::makeHtmlReadable(const QString& html, const QString& base_url) {
|
||||
void Readability::makeHtmlReadable(QObject* sndr, const QString& html, const QString& base_url) {
|
||||
if (!m_modulesInstalled) {
|
||||
try {
|
||||
NodeJs::PackageStatus stReadability =
|
||||
|
@ -104,7 +104,9 @@ void Readability::makeHtmlReadable(const QString& html, const QString& base_url)
|
|||
qCriticalNN << LOGSEC_CORE << "Failed to check for Node.js package status:" << QUOTE_W_SPACE_DOT(ex.message());
|
||||
|
||||
// Emit this just to allow readability again for user.
|
||||
emit htmlReadabled({});
|
||||
emit htmlReadabled(sndr,
|
||||
tr("Node.js is not configured properly. Go to \"Settings\" -> \"Node.js\" and check "
|
||||
"if your Node.js is properly configured."));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -121,7 +123,9 @@ void Readability::makeHtmlReadable(const QString& html, const QString& base_url)
|
|||
connect(proc,
|
||||
QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
|
||||
this,
|
||||
&Readability::onReadabilityFinished);
|
||||
[=](int exit_code, QProcess::ExitStatus exit_status) {
|
||||
onReadabilityFinished(sndr, exit_code, exit_status);
|
||||
});
|
||||
|
||||
qApp->nodejs()->runScript(proc, temp_script, {base_url});
|
||||
|
||||
|
@ -129,15 +133,15 @@ void Readability::makeHtmlReadable(const QString& html, const QString& base_url)
|
|||
proc->closeWriteChannel();
|
||||
}
|
||||
|
||||
void Readability::onReadabilityFinished(int exit_code, QProcess::ExitStatus exit_status) {
|
||||
void Readability::onReadabilityFinished(QObject* sndr, int exit_code, QProcess::ExitStatus exit_status) {
|
||||
QProcess* proc = qobject_cast<QProcess*>(sender());
|
||||
|
||||
if (exit_status == QProcess::ExitStatus::NormalExit && exit_code == EXIT_SUCCESS) {
|
||||
emit htmlReadabled(QString::fromUtf8(proc->readAllStandardOutput()));
|
||||
emit htmlReadabled(sndr, QString::fromUtf8(proc->readAllStandardOutput()));
|
||||
}
|
||||
else {
|
||||
QString err = QString::fromUtf8(proc->readAllStandardError());
|
||||
emit errorOnHtmlReadabiliting(err);
|
||||
emit errorOnHtmlReadabiliting(sndr, err);
|
||||
}
|
||||
|
||||
proc->deleteLater();
|
||||
|
|
|
@ -10,21 +10,21 @@
|
|||
#include <QProcess>
|
||||
|
||||
class Readability : public QObject {
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit Readability(QObject* parent = nullptr);
|
||||
|
||||
void makeHtmlReadable(const QString& html, const QString& base_url = {});
|
||||
void makeHtmlReadable(QObject* sndr, const QString& html, const QString& base_url = {});
|
||||
|
||||
private slots:
|
||||
void onReadabilityFinished(int exit_code, QProcess::ExitStatus exit_status);
|
||||
void onReadabilityFinished(QObject* sndr, int exit_code, QProcess::ExitStatus exit_status);
|
||||
void onPackageReady(const QList<NodeJs::PackageMetadata>& pkgs, bool already_up_to_date);
|
||||
void onPackageError(const QList<NodeJs::PackageMetadata>& pkgs, const QString& error);
|
||||
|
||||
signals:
|
||||
void htmlReadabled(const QString& better_html);
|
||||
void errorOnHtmlReadabiliting(const QString& error);
|
||||
void htmlReadabled(QObject* sndr, const QString& better_html);
|
||||
void errorOnHtmlReadabiliting(QObject* sndr, const QString& error);
|
||||
|
||||
private:
|
||||
bool m_modulesInstalling;
|
||||
|
|
Loading…
Add table
Reference in a new issue