[SCM] ktp-text-ui packaging branch, master, updated. debian/15.12.1-1-1918-gdf4b0ec

Maximiliano Curia maxy at moszumanska.debian.org
Sat May 28 00:24:26 UTC 2016


Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-text-ui.git;a=commitdiff;h=aa0439a

The following commit has been merged in the master branch:
commit aa0439a3095a75916e3baf8cacf496786cf446ca
Author: Diane Trout <diane at ghic.org>
Date:   Wed Mar 5 22:03:46 2014 -0800

    Add AdiumThemeViewProxy to allow the theme javascript to report when its finished initializing.
    
    It does this by replacing the body onload event with a call to the Qt bridge
    signal.
    
    To make this compatible with various themes, during the template load
    phase it finds the body tag, extracts the current onload event, saves any
    javascript and replaces it with the call to the proxy object.
    
    Then when javascript finishes initialising and tells Qt it's done,
    and Qt can call the original event javascript.
---
 config/appearance-config-tab.cpp |  4 +---
 lib/adium-theme-view.cpp         | 44 ++++++++++++++++++++++++++++++++++++++--
 lib/adium-theme-view.h           | 13 ++++++++++++
 3 files changed, 56 insertions(+), 5 deletions(-)

diff --git a/config/appearance-config-tab.cpp b/config/appearance-config-tab.cpp
index ffef4f6..1e2666a 100644
--- a/config/appearance-config-tab.cpp
+++ b/config/appearance-config-tab.cpp
@@ -49,7 +49,7 @@ AppearanceConfigTab::AppearanceConfigTab(QWidget *parent, TabMode mode)
     //loading theme settings.
     loadTab();
 
-    connect(ui->chatView, SIGNAL(loadFinished(bool)), SLOT(sendDemoMessages()));
+    connect(ui->chatView, SIGNAL(viewReady()), SLOT(sendDemoMessages()));
     connect(ui->styleComboBox, SIGNAL(activated(int)), SLOT(onStyleSelected(int)));
     connect(ui->variantComboBox, SIGNAL(activated(QString)), SLOT(onVariantSelected(QString)));
     connect(ui->showHeader, SIGNAL(clicked(bool)), SLOT(onShowHeaderChanged(bool)));
@@ -57,8 +57,6 @@ AppearanceConfigTab::AppearanceConfigTab(QWidget *parent, TabMode mode)
     connect(ui->fontFamily, SIGNAL(currentFontChanged(QFont)), SLOT(onFontFamilyChanged(QFont)));
     connect(ui->fontSize, SIGNAL(valueChanged(int)), SLOT(onFontSizeChanged(int)));
     connect(ui->showPresenceCheckBox, SIGNAL(stateChanged(int)), SLOT(onShowPresenceChangesChanged(int)));
-
-    sendDemoMessages();
 }
 
 AppearanceConfigTab::~AppearanceConfigTab()
diff --git a/lib/adium-theme-view.cpp b/lib/adium-theme-view.cpp
index 635a877..5d1b709 100644
--- a/lib/adium-theme-view.cpp
+++ b/lib/adium-theme-view.cpp
@@ -54,7 +54,8 @@ AdiumThemeView::AdiumThemeView(QWidget *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())
 {
     //blocks QWebView functionality which allows you to change page by dragging a URL onto it.
     setAcceptDrops(false);
@@ -68,7 +69,9 @@ AdiumThemeView::AdiumThemeView(QWidget *parent)
             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);
 }
@@ -120,6 +123,18 @@ void AdiumThemeView::load(ChatType chatType) {
     m_showPresenceChanges = appearanceConfig.readEntry("showPresenceChanges", true);
 }
 
+void AdiumThemeView::viewLoadFinished()
+{
+    if (themeOnLoadJS.length()) {
+        page()->mainFrame()->evaluateJavaScript(themeOnLoadJS);
+    }
+    viewReady();
+}
+
+void AdiumThemeView::injectProxyIntoJavascript()
+{
+    page()->mainFrame()->addToJavaScriptWindowObject(QLatin1String("AdiumThemeViewProxy"), jsproxy);
+}
 
 void AdiumThemeView::contextMenuEvent(QContextMenuEvent *event)
 {
@@ -252,6 +267,31 @@ 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);
+            //kDebug() << "Captured js onLoad" << themeOnLoadJS;
+            templateHtml.replace(body.pos(1), body.cap(1).length(), onload);
+        }
+    }
     //kDebug() << templateHtml;
 
     setHtml(templateHtml);
diff --git a/lib/adium-theme-view.h b/lib/adium-theme-view.h
index 8d17f9d..3ec51b2 100644
--- a/lib/adium-theme-view.h
+++ b/lib/adium-theme-view.h
@@ -40,6 +40,13 @@ class QContextMenuEvent;
 
 class KAction;
 
+class AdiumThemeViewProxy : public QObject
+{
+    Q_OBJECT
+Q_SIGNALS:
+    void viewReady();
+};
+
 class KDE_TELEPATHY_CHAT_EXPORT AdiumThemeView : public KWebView
 {
     Q_OBJECT
@@ -98,9 +105,11 @@ public Q_SLOTS:
     void addStatusMessage(const QString &text, const QDateTime &time=QDateTime::currentDateTime());
     void onOpenLinkActionTriggered();
     virtual void onLinkClicked(const QUrl &);
+    void injectProxyIntoJavascript();
 
     void addAdiumContentMessage(const AdiumThemeContentInfo&);
     void addAdiumStatusMessage(const AdiumThemeStatusInfo&);
+    void viewLoadFinished();
 
 protected:
     virtual void contextMenuEvent(QContextMenuEvent *event);
@@ -110,6 +119,7 @@ protected:
 Q_SIGNALS:
     void zoomFactorChanged(qreal zoomFactor);
     void textPasted();
+    void viewReady();
 
 private:
     ChatWindowStyle *m_chatStyle;
@@ -141,6 +151,9 @@ private:
 
 
     bool m_webInspector;
+
+    AdiumThemeViewProxy *jsproxy;
+    QString themeOnLoadJS;
 };
 
 #endif // ADIUMTHEMEVIEW_H

-- 
ktp-text-ui packaging



More information about the pkg-kde-commits mailing list