Reaction to downloading etc.

This commit is contained in:
Martin Rotter 2016-06-09 06:24:39 +02:00
parent fe3a570561
commit 2bb3460689
8 changed files with 45 additions and 11 deletions

View File

@ -77,8 +77,8 @@
#define ENCRYPTION_FILE_NAME "key.private" #define ENCRYPTION_FILE_NAME "key.private"
#define RELOAD_MODEL_BORDER_NUM 10 #define RELOAD_MODEL_BORDER_NUM 10
#define INTERNAL_URL_MESSAGE "rssguard:message" #define INTERNAL_URL_MESSAGE "rssguard.message"
#define INTERNAL_URL_BLANK "rssguard:blank" #define INTERNAL_URL_BLANK "rssguard.blank"
#define INTERNAL_URL_HOST "rssguard" #define INTERNAL_URL_HOST "rssguard"
#define INTERNAL_URL_MESSAGE_PORT "message" #define INTERNAL_URL_MESSAGE_PORT "message"

View File

@ -56,17 +56,26 @@ void MessageBrowser::loadMessages(const QList<Message> &messages) {
QString::number(message.m_id))); QString::number(message.m_id)));
} }
QString layout_wrapper = skin.m_layoutMarkupWrapper.arg(messages.size() == 1 ? messages.at(0).m_title : tr("Newspaper view"), m_messageContents = skin.m_layoutMarkupWrapper.arg(messages.size() == 1 ? messages.at(0).m_title : tr("Newspaper view"),
messages_layout); messages_layout);
bool previously_enabled = isEnabled(); bool previously_enabled = isEnabled();
setEnabled(false); //setEnabled(false);
setHtml(layout_wrapper, QUrl(INTERNAL_URL_MESSAGE)); setHtml(m_messageContents, QUrl(INTERNAL_URL_MESSAGE));
setEnabled(previously_enabled); //load(QUrl(INTERNAL_URL_MESSAGE));
//setEnabled(previously_enabled);
IOFactory::writeTextFile("aa.html", layout_wrapper.toUtf8()); IOFactory::writeTextFile("aa.html", m_messageContents.toUtf8());
} }
void MessageBrowser::loadMessage(const Message &message) { void MessageBrowser::loadMessage(const Message &message) {
loadMessages(QList<Message>() << message); loadMessages(QList<Message>() << message);
} }
void MessageBrowser::clear() {
setHtml("<!DOCTYPE html><html><body</body></html>", QUrl(INTERNAL_URL_BLANK));
}
void MessageBrowser::assignMessageContents() {
setHtml(m_messageContents, QUrl(INTERNAL_URL_MESSAGE));
}

View File

@ -33,9 +33,16 @@ class MessageBrowser : public QWebEngineView {
public slots: public slots:
void loadMessages(const QList<Message> &messages); void loadMessages(const QList<Message> &messages);
void loadMessage(const Message &message); void loadMessage(const Message &message);
void clear();
private:
void assignMessageContents();
signals: signals:
void messageStatusChangeRequested(int message_id, MessageBrowserPage::MessageStatusChange change); void messageStatusChangeRequested(int message_id, MessageBrowserPage::MessageStatusChange change);
private:
QString m_messageContents;
}; };
#endif // MESSAGEBROWSER_H #endif // MESSAGEBROWSER_H

View File

@ -52,14 +52,12 @@ void MessagePreviewer::reloadFontSettings() {
fon.fromString(qApp->settings()->value(GROUP(Messages), fon.fromString(qApp->settings()->value(GROUP(Messages),
SETTING(Messages::PreviewerFontStandard)).toString()); SETTING(Messages::PreviewerFontStandard)).toString());
auto aa = fon.family();
QWebEngineSettings::globalSettings()->setFontFamily(QWebEngineSettings::StandardFont, fon.family()); QWebEngineSettings::globalSettings()->setFontFamily(QWebEngineSettings::StandardFont, fon.family());
QWebEngineSettings::globalSettings()->setFontSize(QWebEngineSettings::DefaultFontSize, fon.pointSize()); QWebEngineSettings::globalSettings()->setFontSize(QWebEngineSettings::DefaultFontSize, fon.pointSize());
} }
void MessagePreviewer::clear() { void MessagePreviewer::clear() {
m_ui->m_webMessage->setHtml("<!DOCTYPE html><html><body</body></html>", QUrl(INTERNAL_URL_BLANK)); m_ui->m_webMessage->clear();
hide(); hide();
} }

View File

@ -36,6 +36,8 @@
#include <QSessionManager> #include <QSessionManager>
#include <QThread> #include <QThread>
#include <QProcess> #include <QProcess>
#include <QWebEngineProfile>
#include <QWebEngineDownloadItem>
Application::Application(const QString &id, int &argc, char **argv) Application::Application(const QString &id, int &argc, char **argv)
@ -46,6 +48,8 @@ Application::Application(const QString &id, int &argc, char **argv)
connect(this, SIGNAL(aboutToQuit()), this, SLOT(onAboutToQuit())); connect(this, SIGNAL(aboutToQuit()), this, SLOT(onAboutToQuit()));
connect(this, SIGNAL(commitDataRequest(QSessionManager&)), this, SLOT(onCommitData(QSessionManager&))); connect(this, SIGNAL(commitDataRequest(QSessionManager&)), this, SLOT(onCommitData(QSessionManager&)));
connect(this, SIGNAL(saveStateRequest(QSessionManager&)), this, SLOT(onSaveState(QSessionManager&))); connect(this, SIGNAL(saveStateRequest(QSessionManager&)), this, SLOT(onSaveState(QSessionManager&)));
connect(QWebEngineProfile::defaultProfile(), SIGNAL(downloadRequested(QWebEngineDownloadItem*)),
this, SLOT(downloadRequested(QWebEngineDownloadItem*)));
} }
Application::~Application() { Application::~Application() {
@ -291,3 +295,8 @@ void Application::onAboutToQuit() {
qDebug("Close lock timed-out."); qDebug("Close lock timed-out.");
} }
} }
void Application::downloadRequested(QWebEngineDownloadItem *download_item) {
downloadManager()->download(download_item->url());
download_item->cancel();
}

View File

@ -45,6 +45,7 @@ class FormMain;
class IconFactory; class IconFactory;
class QAction; class QAction;
class Mutex; class Mutex;
class QWebEngineDownloadItem;
class Application : public QtSingleApplication { class Application : public QtSingleApplication {
Q_OBJECT Q_OBJECT
@ -167,6 +168,7 @@ class Application : public QtSingleApplication {
void onCommitData(QSessionManager &manager); void onCommitData(QSessionManager &manager);
void onSaveState(QSessionManager &manager); void onSaveState(QSessionManager &manager);
void onAboutToQuit(); void onAboutToQuit();
void downloadRequested(QWebEngineDownloadItem*download_item);
private: private:
void eliminateFirstRun(); void eliminateFirstRun();

View File

@ -18,6 +18,7 @@
#include "network-web/messagebrowserpage.h" #include "network-web/messagebrowserpage.h"
#include "definitions/definitions.h" #include "definitions/definitions.h"
#include "gui/messagebrowser.h"
#include <QStringList> #include <QStringList>
#include <QString> #include <QString>
@ -26,6 +27,9 @@
MessageBrowserPage::MessageBrowserPage(QObject *parent) : QWebEnginePage(parent) { MessageBrowserPage::MessageBrowserPage(QObject *parent) : QWebEnginePage(parent) {
} }
MessageBrowser *MessageBrowserPage::view() const {
return qobject_cast<MessageBrowser*>(QWebEnginePage::view());
}
void MessageBrowserPage::javaScriptAlert(const QUrl &securityOrigin, const QString &msg) { void MessageBrowserPage::javaScriptAlert(const QUrl &securityOrigin, const QString &msg) {
if (securityOrigin.isEmpty()) { if (securityOrigin.isEmpty()) {

View File

@ -21,6 +21,8 @@
#include <QWebEnginePage> #include <QWebEnginePage>
class MessageBrowser;
class MessageBrowserPage : public QWebEnginePage { class MessageBrowserPage : public QWebEnginePage {
Q_OBJECT Q_OBJECT
@ -34,6 +36,9 @@ class MessageBrowserPage : public QWebEnginePage {
explicit MessageBrowserPage(QObject *parent = 0); explicit MessageBrowserPage(QObject *parent = 0);
MessageBrowser *view() const;
protected: protected:
void javaScriptAlert(const QUrl &securityOrigin, const QString &msg); void javaScriptAlert(const QUrl &securityOrigin, const QString &msg);
bool acceptNavigationRequest(const QUrl &url, NavigationType type, bool isMainFrame); bool acceptNavigationRequest(const QUrl &url, NavigationType type, bool isMainFrame);