File 0001-Revert-Port-to-QWebEngine.patch of Package ktp-text-ui
From 9d7305631808bf8686d459570a50e6aef129739c Mon Sep 17 00:00:00 2001
From: Luca Beltrame <lbeltrame@kde.org>
Date: Sat, 15 Apr 2017 15:52:27 +0200
Subject: [PATCH 1/1] Revert "Port to QWebEngine"
This reverts commit 06f9110dd1f4fdc8552d48ed3d10277d4e44a152.
---
CMakeLists.txt | 4 +-
adiumxtra-protocol-handler/CMakeLists.txt | 2 +-
app/CMakeLists.txt | 2 +-
config/appearance/CMakeLists.txt | 2 +-
config/appearance/appearance-config-tab.cpp | 3 +-
lib/CMakeLists.txt | 3 +-
lib/adium-theme-view.cpp | 167 +++++++++++++++++-----------
lib/adium-theme-view.h | 28 ++---
lib/chat-search-bar.cpp | 7 +-
lib/chat-search-bar.h | 12 +-
lib/chat-widget.cpp | 24 ++--
lib/chat-widget.h | 8 +-
logviewer/CMakeLists.txt | 1 +
logviewer/log-viewer.cpp | 1 +
logviewer/message-view.cpp | 71 ++++++------
logviewer/message-view.h | 3 +-
16 files changed, 187 insertions(+), 151 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 22f5dc0..81b2eb8 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -15,9 +15,9 @@ set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR})
find_package (KF5 REQUIRED COMPONENTS Archive Sonnet WidgetsAddons Service Emoticons
KIO KCMUtils NotifyConfig Notifications I18n
- WindowSystem XmlGui ItemViews TextWidgets
+ WebKit WindowSystem XmlGui ItemViews TextWidgets
IconThemes DBusAddons)
-set(QT_REQUIRED_VERSION 5.7.0)
+find_package (Qt5 REQUIRED COMPONENTS WebKitWidgets)
find_package(Qt5 ${QT_REQUIRED_VERSION} REQUIRED COMPONENTS WebEngine WebEngineWidgets)
find_package(Qt5 ${QT_REQUIRED_VERSION} OPTIONAL_COMPONENTS TextToSpeech)
if (NOT Qt5TextToSpeech_FOUND)
diff --git a/adiumxtra-protocol-handler/CMakeLists.txt b/adiumxtra-protocol-handler/CMakeLists.txt
index 72c04a7..f78a62f 100644
--- a/adiumxtra-protocol-handler/CMakeLists.txt
+++ b/adiumxtra-protocol-handler/CMakeLists.txt
@@ -11,7 +11,7 @@ set(ktp-adiumxtra-protocol-handler_SRCS
add_executable(ktp-adiumxtra-protocol-handler ${ktp-adiumxtra-protocol-handler_SRCS})
target_link_libraries(ktp-adiumxtra-protocol-handler
- Qt5::WebEngine
+ Qt5::WebKit
KF5::Emoticons
Qt5::Xml
KF5::KIOWidgets
diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt
index 836b88e..9a90cec 100644
--- a/app/CMakeLists.txt
+++ b/app/CMakeLists.txt
@@ -12,7 +12,7 @@ set(ktp-text-ui_SRCS
)
set (ktp-text-ui_LIBS
- Qt5::WebEngine
+ Qt5::WebKit
KF5::CoreAddons
KF5::I18n
KF5::KIOWidgets
diff --git a/config/appearance/CMakeLists.txt b/config/appearance/CMakeLists.txt
index e8794ab..dfb5d04 100644
--- a/config/appearance/CMakeLists.txt
+++ b/config/appearance/CMakeLists.txt
@@ -7,7 +7,7 @@ ki18n_wrap_ui(kcm_ktp_chat_appearance_SRCS ${kcm_ktp_chat_appearance_UI})
add_library(kcm_ktp_chat_appearance MODULE ${kcm_ktp_chat_appearance_SRCS})
target_link_libraries(kcm_ktp_chat_appearance
- Qt5::WebEngineWidgets
+ Qt5::WebKitWidgets
KF5::KCMUtils
KF5::WidgetsAddons
KF5::IconThemes
diff --git a/config/appearance/appearance-config-tab.cpp b/config/appearance/appearance-config-tab.cpp
index d5f053c..f2f298b 100644
--- a/config/appearance/appearance-config-tab.cpp
+++ b/config/appearance/appearance-config-tab.cpp
@@ -31,7 +31,6 @@
#include <KIconLoader>
#include <QFontDatabase>
-#include <QWebEngineSettings>
AppearanceConfigTab::AppearanceConfigTab(QWidget *parent, TabMode mode)
: QWidget(parent),
@@ -339,7 +338,7 @@ void AppearanceConfigTab::defaultTab()
ui->customFontBox->setChecked(false);
ui->chatView->setUseCustomFont(false);
ui->fontFamily->setCurrentFont(QFontDatabase::systemFont(QFontDatabase::GeneralFont));
- ui->fontSize->setValue(QWebEngineSettings::DefaultFontSize);
+ ui->fontSize->setValue(QWebSettings::DefaultFontSize);
ui->showPresenceCheckBox->setChecked(!m_groupChat);
ui->showJoinLeaveCheckBox->setChecked(!m_groupChat);
diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
index e9b73b8..5294521 100644
--- a/lib/CMakeLists.txt
+++ b/lib/CMakeLists.txt
@@ -39,6 +39,7 @@ target_link_libraries(ktpchat
KF5::KIOWidgets
KF5::KIOCore
KF5::I18n
+ KF5::WebKit
KF5::Emoticons
KF5::IconThemes
KF5::Archive
@@ -53,7 +54,7 @@ target_link_libraries(ktpchat
KTp::Logger
KTp::OTR
KTp::Widgets
- Qt5::WebEngineWidgets
+ Qt5::WebKitWidgets
ktpimagesharer
)
install(TARGETS ktpchat ${INSTALL_TARGETS_DEFAULT_ARGS})
diff --git a/lib/adium-theme-view.cpp b/lib/adium-theme-view.cpp
index 3b37285..d1c93f4 100644
--- a/lib/adium-theme-view.cpp
+++ b/lib/adium-theme-view.cpp
@@ -35,68 +35,54 @@
#include <QFontDatabase>
#include <QMenu>
#include <QDesktopWidget>
-#include <QWebEngineContextMenuData>
-#include <QWebEngineProfile>
-#include <QWebEngineSettings>
+#include <QWebFrame>
+#include <QWebElement>
+#include <QWebInspector>
+#include <QWebSettings>
#include <QApplication>
#include <QAction>
#include <QLocale>
-#include <QDesktopServices>
#include <KEmoticonsTheme>
#include <KSharedConfig>
#include <KConfig>
#include <KConfigGroup>
#include <KMessageBox>
+#include <KToolInvocation>
#include <KIconLoader>
#include <KProtocolInfo>
#include <KLocalizedString>
-AdiumThemePage::AdiumThemePage(QObject *parent)
- : QWebEnginePage(parent)
-{
-}
-
-bool AdiumThemePage::acceptNavigationRequest(const QUrl &url, QWebEnginePage::NavigationType navigationType, bool isMainFrame)
-{
- if (!isMainFrame && navigationType == QWebEnginePage::NavigationTypeLinkClicked) {
- /* This might be an iframe (e. g. for the YouTube plugin) */
- return true;
- }
-
- if (url.fragment() == QLatin1String("x-nextConversation")) {
- Q_EMIT nextConversation();
- } else if (url.fragment() == QLatin1String("x-prevConversation")) {
- Q_EMIT prevConversation();
- } else {
- QDesktopServices::openUrl(url);
- }
-
- // don't let QWebEngineView handle the links, we do
- return false;
-}
-
AdiumThemeView::AdiumThemeView(QWidget *parent)
- : QWebEngineView(parent),
+ : KWebView(parent),
// check iconPath docs for minus sign in -KIconLoader::SizeLarge
m_defaultAvatar(KIconLoader::global()->iconPath(QLatin1String("im-user"),-KIconLoader::SizeLarge)),
- m_displayHeader(true)
+ m_displayHeader(true),
+ jsproxy(new AdiumThemeViewProxy())
{
- AdiumThemePage *adiumPage = new AdiumThemePage(this);
- setPage(adiumPage);
-
- //blocks QWebEngineView functionality which allows you to change page by dragging a URL onto it.
+ //blocks QWebView functionality which allows you to change page by dragging a URL onto it.
setAcceptDrops(false);
- setFocusPolicy(Qt::NoFocus);
+ // don't let QWebView handle the links, we do
+ page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);
+
+ QAction *defaultOpenLinkAction = pageAction(QWebPage::OpenLink);
+ m_openLinkAction = new QAction(defaultOpenLinkAction->text(), this);
+ connect(m_openLinkAction, SIGNAL(triggered()),
+ this, SLOT(onOpenLinkActionTriggered()));
+
+ connect(this, SIGNAL(linkClicked(QUrl)), this, SLOT(onLinkClicked(QUrl)));
+ connect(page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()),
+ this, SLOT(injectProxyIntoJavascript()));
+ connect(jsproxy, SIGNAL(viewReady()), this, SLOT(viewLoadFinished()));
+ QWebSettings *ws = settings();
+ ws->setAttribute(QWebSettings::ZoomTextOnly, true);
KConfigGroup config(KSharedConfig::openConfig(), "KTpStyleDebug");
bool disableCache = config.readEntry("disableStyleCache", false);
if (disableCache) {
- page()->profile()->setHttpCacheType(QWebEngineProfile::NoCache);
+ ws->setObjectCacheCapacities(0, 0, 0);
}
-
- connect(page(), &AdiumThemePage::loadFinished, this, &AdiumThemeView::viewLoadFinished);
}
void AdiumThemeView::load(ChatType chatType) {
@@ -136,33 +122,45 @@ void AdiumThemeView::load(ChatType chatType) {
m_displayHeader = appearanceConfig.readEntry("displayHeader", true);
+ //special HTML debug mode. Debugging/Profiling only (or theme creating) should have no visible way to turn this flag on.
+ m_webInspector = appearanceConfig.readEntry("debug", false);
+
m_useCustomFont = appearanceConfig.readEntry("useCustomFont", false);
- m_fontFamily = appearanceConfig.readEntry("fontFamily", QWebEngineSettings::globalSettings()->fontFamily(QWebEngineSettings::StandardFont));
- m_fontSize = appearanceConfig.readEntry("fontSize", QWebEngineSettings::globalSettings()->fontSize(QWebEngineSettings::DefaultFontSize));
+ m_fontFamily = appearanceConfig.readEntry("fontFamily", QWebSettings::globalSettings()->fontFamily(QWebSettings::StandardFont));
+ m_fontSize = appearanceConfig.readEntry("fontSize", QWebSettings::globalSettings()->fontSize(QWebSettings::DefaultFontSize));
m_showPresenceChanges = appearanceConfig.readEntry("showPresenceChanges", true);
m_showJoinLeaveChanges = appearanceConfig.readEntry("showJoinLeaveChanges", true);
}
-void AdiumThemeView::viewLoadFinished(bool ok)
+void AdiumThemeView::viewLoadFinished()
{
- if (ok) {
- viewReady();
+ if (themeOnLoadJS.length()) {
+ page()->mainFrame()->evaluateJavaScript(themeOnLoadJS);
}
+ viewReady();
+}
+
+void AdiumThemeView::injectProxyIntoJavascript()
+{
+ page()->mainFrame()->addToJavaScriptWindowObject(QLatin1String("AdiumThemeViewProxy"), jsproxy);
}
void AdiumThemeView::contextMenuEvent(QContextMenuEvent *event)
{
- QMenu *menu = new QMenu(this);
- if (page()->contextMenuData().linkUrl().isValid()) {
- menu->addAction(page()->action(QWebEnginePage::OpenLinkInThisWindow));
- menu->addAction(page()->action(QWebEnginePage::CopyLinkToClipboard));
- }
- if (!page()->contextMenuData().selectedText().isEmpty()) {
- menu->addAction(page()->action(QWebEnginePage::Copy));
+ QWebHitTestResult r = page()->mainFrame()->hitTestContent(event->pos());
+ QUrl url = r.linkUrl();
+ if (!url.isEmpty()) {
+ // save current link url in openLinkAction
+ m_openLinkAction->setData(url);
+
+ QMenu menu(this);
+ menu.addAction(m_openLinkAction);
+ menu.addAction(pageAction(QWebPage::CopyLinkToClipboard));
+ menu.exec(mapToGlobal(event->pos()));
+ } else {
+ QWebView::contextMenuEvent(event);
}
- connect(menu, &QMenu::aboutToHide, menu, &QObject::deleteLater);
- menu->popup(event->globalPos());
}
void AdiumThemeView::wheelEvent(QWheelEvent* event)
@@ -182,7 +180,7 @@ void AdiumThemeView::wheelEvent(QWheelEvent* event)
return;
}
- QWebEngineView::wheelEvent(event);
+ QWebView::wheelEvent(event);
}
void AdiumThemeView::mouseReleaseEvent(QMouseEvent *event)
@@ -192,7 +190,7 @@ void AdiumThemeView::mouseReleaseEvent(QMouseEvent *event)
event->accept();
return;
}
- QWebEngineView::mouseReleaseEvent(event);
+ QWebView::mouseReleaseEvent(event);
}
void AdiumThemeView::initialise(const AdiumThemeHeaderInfo &chatInfo)
@@ -220,11 +218,11 @@ void AdiumThemeView::initialise(const AdiumThemeHeaderInfo &chatInfo)
// set fontFamily and fontSize
if (m_useCustomFont) {
// use user specified fontFamily and Size
- settings()->setFontFamily(QWebEngineSettings::StandardFont, m_fontFamily);
+ settings()->setFontFamily(QWebSettings::StandardFont, m_fontFamily);
// We get desktop's DPI and divide it 96, which is the DPI that WebKit has hardcoded in
// Then we can just scale the fonts using the obtained coefficient and they should look
// good/better on high-dpi screens
- settings()->setFontSize(QWebEngineSettings::DefaultFontSize, m_fontSize * (QApplication::desktop()->logicalDpiY() / 96.0 ));
+ settings()->setFontSize(QWebSettings::DefaultFontSize, m_fontSize * (QApplication::desktop()->logicalDpiY() / 96.0 ));
// since some themes are pretty odd and hardcode fonts to the css we need to override that
// with some extra css. this may not work for all themes!
@@ -240,9 +238,14 @@ void AdiumThemeView::initialise(const AdiumThemeHeaderInfo &chatInfo)
<< fontDB.families().contains(m_chatStyle->defaultFontFamily());
// use theme fontFamily/Size, if not existent, it falls back to systems default font
- settings()->setFontFamily(QWebEngineSettings::StandardFont, m_chatStyle->defaultFontFamily());
+ settings()->setFontFamily(QWebSettings::StandardFont, m_chatStyle->defaultFontFamily());
// Computing the font size can result in floats and have some rounding errors, so add 0.5 and floor
- settings()->setFontSize(QWebEngineSettings::DefaultFontSize, qFloor(0.5 + m_chatStyle->defaultFontSize() * (QApplication::desktop()->logicalDpiY() / 96.0 )));
+ settings()->setFontSize(QWebSettings::DefaultFontSize, qFloor(0.5 + m_chatStyle->defaultFontSize() * (QApplication::desktop()->logicalDpiY() / 96.0 )));
+ }
+
+ //hidden HTML debugging mode. Should have no visible way to turn it on.
+ if (m_webInspector) {
+ QWebSettings::globalSettings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, true);
}
//The templateHtml is in a horrific NSString format.
@@ -282,9 +285,34 @@ void AdiumThemeView::initialise(const AdiumThemeHeaderInfo &chatInfo)
index = templateHtml.indexOf(QLatin1String("</head>"));
templateHtml.insert(index, KTp::MessageProcessor::instance()->header());
+ // The purpose of this regular expression is to find the body tag in the template
+ // and make it possible to replace the onload event.
+ // The [^>]* expression is to match things that are not the end tag
+ // the (onload=\"...\")? expression is to make easy for me to do
+ // a string replace and replace the entire onload event (as cap(1).
+ // the trailing ? makes it optional in case a theme doesn't actually
+ // use the onload event.
+ // the inner ([^\"]*) expression attempts to match the javascript
+ // that is actually being called by the onLoad event so after we replace
+ // it with our C++ function that can call whatever javascript code the theme
+ // actually intended.
+ // Note: styles that use \" or > in unexpected places in their body tag will break
+ // this regexp.
+ QRegExp body(QLatin1String("<body[^>]*(onload=\"([^\"]*)\")?[^>]*>"), Qt::CaseInsensitive);
+ const QString onload(QLatin1String(" onload=\"AdiumThemeViewProxy.viewReady();\" "));
+ index = templateHtml.indexOf(body);
+ if (0 <= index ) {
+ if (body.cap(1).length() == 0) {
+ templateHtml.insert(index + 5, onload);
+ } else {
+ themeOnLoadJS = body.cap(2);
+ //qCDebug(KTP_TEXTUI_LIB) << "Captured js onLoad" << themeOnLoadJS;
+ templateHtml.replace(body.pos(1), body.cap(1).length(), onload);
+ }
+ }
//qCDebug(KTP_TEXTUI_LIB) << templateHtml;
- setHtml(templateHtml, QUrl::fromLocalFile(m_chatStyle->getStyleBaseHref()));
+ setHtml(templateHtml);
m_service = chatInfo.service();
m_serviceIconPath = chatInfo.serviceIconPath();
@@ -387,8 +415,8 @@ void AdiumThemeView::setHeaderDisplayed(bool displayHeader)
void AdiumThemeView::clear()
{
- if (!page()->url().isEmpty()) {
- page()->setHtml(QString());
+ if (!page()->mainFrame()->url().isEmpty()) {
+ page()->mainFrame()->setHtml(QString());
}
}
@@ -548,7 +576,7 @@ void AdiumThemeView::addAdiumStatusMessage(const AdiumThemeStatusInfo& statusMes
QString AdiumThemeView::appendScript(AdiumThemeView::AppendMode mode)
{
- //by making the JS return false runJavaScript is a _lot_ faster, as it has nothing to convert to QVariant.
+ //by making the JS return false evaluateJavaScript is a _lot_ faster, as it has nothing to convert to QVariant.
//escape quotes, and merge HTML onto one line.
switch (mode) {
case AppendMessageWithScroll:
@@ -620,13 +648,24 @@ void AdiumThemeView::appendMessage(QString &html, const QString &script, AppendM
.replace(QLatin1Char('\"'), QLatin1String("\\\"")) /* replace " with \" */
.replace(QLatin1Char('\n'), QLatin1String(""))); /* remove new lines */
- page()->runJavaScript(js);
+ page()->mainFrame()->evaluateJavaScript(js);
if (!script.isEmpty()) {
- page()->runJavaScript(script);
+ page()->mainFrame()->evaluateJavaScript(script);
}
}
+void AdiumThemeView::onLinkClicked(const QUrl &url)
+{
+ KToolInvocation::invokeBrowser(url.toString());
+}
+
+void AdiumThemeView::onOpenLinkActionTriggered()
+{
+ QUrl url = m_openLinkAction->data().toUrl();
+ onLinkClicked(url);
+}
+
/** Private */
QString AdiumThemeView::replaceHeaderKeywords(QString htmlTemplate, const AdiumThemeHeaderInfo & info)
diff --git a/lib/adium-theme-view.h b/lib/adium-theme-view.h
index 621bc39..5a0c2e6 100644
--- a/lib/adium-theme-view.h
+++ b/lib/adium-theme-view.h
@@ -20,7 +20,7 @@
#ifndef ADIUMTHEMEVIEW_H
#define ADIUMTHEMEVIEW_H
-#include <QWebEngineView>
+#include <KWebView>
#include "adium-theme-header-info.h"
#include "adium-theme-content-info.h"
@@ -35,30 +35,21 @@ class AdiumThemeContentInfo;
class AdiumThemeHeaderInfo;
class AdiumThemeStatusInfo;
class ChatWindowStyle;
-class ChatWidget;
class QContextMenuEvent;
class QAction;
-class KDE_TELEPATHY_CHAT_EXPORT AdiumThemePage : public QWebEnginePage
+class AdiumThemeViewProxy : public QObject
{
Q_OBJECT
-public:
- AdiumThemePage(QObject *parent = 0);
-
-protected:
- virtual bool acceptNavigationRequest(const QUrl &url, QWebEnginePage::NavigationType navigationType, bool isMainFrame);
-
Q_SIGNALS:
- void nextConversation();
- void prevConversation();
+ void viewReady();
};
-class KDE_TELEPATHY_CHAT_EXPORT AdiumThemeView : public QWebEngineView
+class KDE_TELEPATHY_CHAT_EXPORT AdiumThemeView : public KWebView
{
Q_OBJECT
- friend class ChatWidget;
public:
enum ChatType {
@@ -116,10 +107,13 @@ public Q_SLOTS:
void addStatusMessage(const QString &text,
const QString &sender=QString(),
const QDateTime &time=QDateTime::currentDateTime());
+ void onOpenLinkActionTriggered();
+ virtual void onLinkClicked(const QUrl &);
+ void injectProxyIntoJavascript();
void addAdiumContentMessage(const AdiumThemeContentInfo&);
void addAdiumStatusMessage(const AdiumThemeStatusInfo&);
- void viewLoadFinished(bool ok);
+ void viewLoadFinished();
protected:
virtual void contextMenuEvent(QContextMenuEvent *event);
@@ -158,9 +152,15 @@ private:
QString m_defaultAvatar;
AdiumThemeContentInfo m_lastContent;
bool m_displayHeader;
+ QAction *m_openLinkAction;
QString m_service;
QString m_serviceIconPath;
+
+ bool m_webInspector;
+
+ AdiumThemeViewProxy *jsproxy;
+ QString themeOnLoadJS;
};
#endif // ADIUMTHEMEVIEW_H
diff --git a/lib/chat-search-bar.cpp b/lib/chat-search-bar.cpp
index 8c0bb34..484975a 100644
--- a/lib/chat-search-bar.cpp
+++ b/lib/chat-search-bar.cpp
@@ -90,12 +90,13 @@ void ChatSearchBar::enableSearchButtons(bool enable)
Q_EMIT enableSearchButtonsSignal(enable);
}
-QWebEnginePage::FindFlags ChatSearchBar::findFlags()
+QWebPage::FindFlags ChatSearchBar::findFlags()
{
- QWebEnginePage::FindFlags flags;
+ QWebPage::FindFlags flags;
+ flags |= QWebPage::FindWrapsAroundDocument;
if(m_caseSensitive) {
- flags |= QWebEnginePage::FindCaseSensitively;
+ flags |= QWebPage::FindCaseSensitively;
}
return flags;
}
diff --git a/lib/chat-search-bar.h b/lib/chat-search-bar.h
index f5eaba2..c8c5118 100644
--- a/lib/chat-search-bar.h
+++ b/lib/chat-search-bar.h
@@ -22,7 +22,7 @@
#include "ktpchat_export.h"
-#include <QWebEnginePage>
+#include <QWebPage>
#include <QWidget>
class QLineEdit;
@@ -66,12 +66,12 @@ private Q_SLOTS:
void toggleCaseSensitive(bool toggle);
Q_SIGNALS:
- void findTextSignal(const QString &text, QWebEnginePage::FindFlags flags);
- void findNextSignal(const QString &text, QWebEnginePage::FindFlags flags);
- void findPreviousSignal(const QString &text, QWebEnginePage::FindFlags flags);
+ void findTextSignal(const QString &text, QWebPage::FindFlags flags);
+ void findNextSignal(const QString &text, QWebPage::FindFlags flags);
+ void findPreviousSignal(const QString &text, QWebPage::FindFlags flags);
/** emitted when search criteria is changed by user and updates current view */
- void flagsChangedSignal(const QString &, QWebEnginePage::FindFlags flags);
+ void flagsChangedSignal(const QString &, QWebPage::FindFlags flags);
/** send signal to mainwindow to enable/disable search buttons */
void enableSearchButtonsSignal(bool enable);
@@ -81,7 +81,7 @@ private:
void enableSearchButtons(bool enable);
/** returns selected search criteria chosen by user */
- QWebEnginePage::FindFlags findFlags();
+ QWebPage::FindFlags findFlags();
QLineEdit *m_searchInput;
QToolButton *m_closeButton;
diff --git a/lib/chat-widget.cpp b/lib/chat-widget.cpp
index 504aa2b..fdc9c1e 100644
--- a/lib/chat-widget.cpp
+++ b/lib/chat-widget.cpp
@@ -243,10 +243,10 @@ ChatWidget::ChatWidget(const Tp::TextChannelPtr & channel, const Tp::AccountPtr
connect(d->ui.sendMessageBox, SIGNAL(returnKeyPressed()), SLOT(sendMessage()));
- connect(d->ui.searchBar, &ChatSearchBar::findTextSignal, this, &ChatWidget::findTextInChat);
- connect(d->ui.searchBar, &ChatSearchBar::findNextSignal, this, &ChatWidget::findNextTextInChat);
- connect(d->ui.searchBar, &ChatSearchBar::findPreviousSignal, this, &ChatWidget::findPreviousTextInChat);
- connect(d->ui.searchBar, &ChatSearchBar::flagsChangedSignal, this, &ChatWidget::findTextInChat);
+ connect(d->ui.searchBar, SIGNAL(findTextSignal(QString,QWebPage::FindFlags)), this, SLOT(findTextInChat(QString,QWebPage::FindFlags)));
+ connect(d->ui.searchBar, SIGNAL(findNextSignal(QString,QWebPage::FindFlags)), this, SLOT(findNextTextInChat(QString,QWebPage::FindFlags)));
+ connect(d->ui.searchBar, SIGNAL(findPreviousSignal(QString,QWebPage::FindFlags)), this, SLOT(findPreviousTextInChat(QString,QWebPage::FindFlags)));
+ connect(d->ui.searchBar, SIGNAL(flagsChangedSignal(QString,QWebPage::FindFlags)), this, SLOT(findTextInChat(QString,QWebPage::FindFlags)));
connect(this, SIGNAL(searchTextComplete(bool)), d->ui.searchBar, SLOT(onSearchTextComplete(bool)));
@@ -386,7 +386,7 @@ Tp::TextChannelPtr ChatWidget::textChannel() const
void ChatWidget::keyPressEvent(QKeyEvent *e)
{
if (e->matches(QKeySequence::Copy)) {
- d->ui.chatArea->triggerPageAction(QWebEnginePage::Copy);
+ d->ui.chatArea->triggerPageAction(QWebPage::Copy);
return;
}
@@ -1273,23 +1273,27 @@ void ChatWidget::onInputBoxChanged()
}
}
-void ChatWidget::findTextInChat(const QString& text, QWebEnginePage::FindFlags flags)
+void ChatWidget::findTextInChat(const QString& text, QWebPage::FindFlags flags)
{
// reset highlights
d->ui.chatArea->findText(QString(), flags);
- d->ui.chatArea->findText(text, flags, [&] (bool found) { Q_EMIT searchTextComplete(found); });
+ if(d->ui.chatArea->findText(text, flags)) {
+ Q_EMIT searchTextComplete(true);
+ } else {
+ Q_EMIT searchTextComplete(false);
+ }
}
-void ChatWidget::findNextTextInChat(const QString& text, QWebEnginePage::FindFlags flags)
+void ChatWidget::findNextTextInChat(const QString& text, QWebPage::FindFlags flags)
{
d->ui.chatArea->findText(text, flags);
}
-void ChatWidget::findPreviousTextInChat(const QString& text, QWebEnginePage::FindFlags flags)
+void ChatWidget::findPreviousTextInChat(const QString& text, QWebPage::FindFlags flags)
{
// for "backwards" search
- flags |= QWebEnginePage::FindBackward;
+ flags |= QWebPage::FindBackward;
d->ui.chatArea->findText(text, flags);
}
diff --git a/lib/chat-widget.h b/lib/chat-widget.h
index 752e1fd..588407c 100644
--- a/lib/chat-widget.h
+++ b/lib/chat-widget.h
@@ -28,7 +28,7 @@
#include <QtCore/QString>
#include <QWidget>
-#include <QWebEnginePage>
+#include <QWebPage>
#include <QIcon>
#include <KColorScheme>
@@ -213,9 +213,9 @@ Q_SIGNALS:
private Q_SLOTS:
/** received when user changes search criteria or when searching for text */
- void findTextInChat(const QString &text, QWebEnginePage::FindFlags flags);
- void findNextTextInChat(const QString &text, QWebEnginePage::FindFlags flags);
- void findPreviousTextInChat(const QString &text, QWebEnginePage::FindFlags flags);
+ void findTextInChat(const QString &text, QWebPage::FindFlags flags);
+ void findNextTextInChat(const QString &text, QWebPage::FindFlags flags);
+ void findPreviousTextInChat(const QString &text, QWebPage::FindFlags flags);
void onHistoryFetched(const QList<KTp::Message> &messages);
void onChatPausedTimerExpired();
void currentPresenceChanged(const Tp::Presence &presence);
diff --git a/logviewer/CMakeLists.txt b/logviewer/CMakeLists.txt
index 28bbe7e..c36157c 100644
--- a/logviewer/CMakeLists.txt
+++ b/logviewer/CMakeLists.txt
@@ -29,6 +29,7 @@ target_link_libraries(ktp-log-viewer
KF5::KIOWidgets
KF5::Emoticons
KF5::KCMUtils
+ KF5::WebKit
KTp::CommonInternals
KTp::Logger
KTp::Models
diff --git a/logviewer/log-viewer.cpp b/logviewer/log-viewer.cpp
index bcdfdfd..b1dad26 100644
--- a/logviewer/log-viewer.cpp
+++ b/logviewer/log-viewer.cpp
@@ -35,6 +35,7 @@
#include <KTp/Models/contacts-model.h>
+#include <QWebFrame>
#include <QMenu>
#include <QAction>
#include <QLineEdit>
diff --git a/logviewer/message-view.cpp b/logviewer/message-view.cpp
index 6d222a4..1b3bbe4 100644
--- a/logviewer/message-view.cpp
+++ b/logviewer/message-view.cpp
@@ -39,6 +39,7 @@ MessageView::MessageView(QWidget *parent) :
AdiumThemeView(parent),
m_infoLabel(new QLabel(this))
{
+
loadSettings();
QFont font = m_infoLabel->font();
@@ -46,13 +47,7 @@ MessageView::MessageView(QWidget *parent) :
m_infoLabel->setFont(font);
m_infoLabel->setAlignment(Qt::AlignCenter);
- connect(this, &MessageView::loadFinished, this, &MessageView::processStoredEvents);
-
- AdiumThemePage *adiumThemePage = dynamic_cast<AdiumThemePage *>(page());
- if (adiumThemePage) {
- connect(adiumThemePage, &AdiumThemePage::nextConversation, this, &MessageView::switchNext);
- connect(adiumThemePage, &AdiumThemePage::prevConversation, this, &MessageView::switchPrev);
- }
+ connect(this, SIGNAL(loadFinished(bool)), SLOT(processStoredEvents()));
}
void MessageView::loadLog(const Tp::AccountPtr &account, const KTp::LogEntity &entity,
@@ -107,7 +102,7 @@ void MessageView::resizeEvent(QResizeEvent* e)
{
m_infoLabel->setGeometry(0, 0, e->size().width(), e->size().height());
- QWebEngineView::resizeEvent(e);
+ QWebView::resizeEvent(e);
}
void MessageView::setHighlightText(const QString &text)
@@ -154,22 +149,17 @@ bool logMessageNewerThan(const KTp::LogMessage &e1, const KTp::LogMessage &e2)
void MessageView::processStoredEvents()
{
- AdiumThemePage *adiumThemePage = dynamic_cast<AdiumThemePage *>(page());
- if (!adiumThemePage) {
- return;
- }
-
AdiumThemeStatusInfo prevConversation;
if (m_prev.isValid()) {
prevConversation = AdiumThemeStatusInfo(AdiumThemeMessageInfo::HistoryStatus);
- prevConversation.setMessage(QString(QLatin1String("<a href=\"file:///invalid#x-prevConversation\"><<< %1</a>")).arg(i18n("Older conversation")));
+ prevConversation.setMessage(QString(QLatin1String("<a href=\"#x-prevConversation\"><<< %1</a>")).arg(i18n("Older conversation")));
prevConversation.setTime(QDateTime(m_prev));
}
AdiumThemeStatusInfo nextConversation;
if (m_next.isValid()) {
nextConversation = AdiumThemeStatusInfo(AdiumThemeMessageInfo::HistoryStatus);
- nextConversation.setMessage(QString(QLatin1String("<a href=\"file:///invalid#x-nextConversation\">%1 >>></a>")).arg(i18n("Newer conversation")));
+ nextConversation.setMessage(QString(QLatin1String("<a href=\"#x-nextConversation\">%1 >>></a>")).arg(i18n("Newer conversation")));
nextConversation.setTime(QDateTime(m_next));
}
@@ -207,6 +197,30 @@ void MessageView::processStoredEvents()
QTimer::singleShot(100, this, SLOT(doHighlightText()));
}
+void MessageView::onLinkClicked(const QUrl &link)
+{
+ // Don't emit the signal directly, KWebView does not like when we reload the
+ // page from an event handler (and then chain up) and we can't guarantee
+ // that everyone will use QueuedConnection when connecting to
+ // conversationSwitchRequested() slot
+
+ if (link.fragment() == QLatin1String("x-nextConversation")) {
+ // Q_EMIT conversationSwitchRequested(m_next)
+ QMetaObject::invokeMethod(this, "conversationSwitchRequested", Qt::QueuedConnection,
+ Q_ARG(QDate, m_next));
+ return;
+ }
+
+ if (link.fragment() == QLatin1String("x-prevConversation")) {
+ // Q_EMIT conversationSwitchRequested(m_prev)
+ QMetaObject::invokeMethod(this, "conversationSwitchRequested", Qt::QueuedConnection,
+ Q_ARG(QDate, m_prev));
+ return;
+ }
+
+ AdiumThemeView::onLinkClicked(link);
+}
+
void MessageView::loadSettings()
{
const KConfig config(QLatin1String("ktelepathyrc"));
@@ -224,30 +238,7 @@ void MessageView::doHighlightText()
{
findText(QString());
if (!m_highlightedText.isEmpty()) {
- findText(m_highlightedText);
+ findText(m_highlightedText, QWebPage::HighlightAllOccurrences |
+ QWebPage::FindWrapsAroundDocument);
}
}
-
-void MessageView::switchPrev()
-{
- // Don't emit the signal directly, QWebEngineView does not like when we reload the
- // page from an event handler (and then chain up) and we can't guarantee
- // that everyone will use QueuedConnection when connecting to
- // conversationSwitchRequested() slot
-
- // Q_EMIT conversationSwitchRequested(m_prev)
- QMetaObject::invokeMethod(this, "conversationSwitchRequested", Qt::QueuedConnection,
- Q_ARG(QDate, m_prev));
-}
-
-void MessageView::switchNext()
-{
- // Don't emit the signal directly, QWebEngineView does not like when we reload the
- // page from an event handler (and then chain up) and we can't guarantee
- // that everyone will use QueuedConnection when connecting to
- // conversationSwitchRequested() slot
-
- // Q_EMIT conversationSwitchRequested(m_next)
- QMetaObject::invokeMethod(this, "conversationSwitchRequested", Qt::QueuedConnection,
- Q_ARG(QDate, m_next));
-}
diff --git a/logviewer/message-view.h b/logviewer/message-view.h
index f9bbd6a..ec592c7 100644
--- a/logviewer/message-view.h
+++ b/logviewer/message-view.h
@@ -51,14 +51,13 @@ public:
void showInfoMessage(const QString &message);
public Q_SLOTS:
+ void onLinkClicked(const QUrl &link);
void reloadTheme();
private Q_SLOTS:
void onEventsLoaded(KTp::PendingLoggerOperation* po);
void doHighlightText();
void processStoredEvents();
- void switchPrev();
- void switchNext();
Q_SIGNALS:
void conversationSwitchRequested(const QDate &date);
--
2.12.2