[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kfm-devel
Subject:    Make Konqueror's searchbar plugin work with any KPart based browser
From:       "Dawit A." <adawit () kde ! org>
Date:       2009-09-25 16:02:46
Message-ID: 200909251202.46893.adawit () kde ! org
[Download RAW message or body]

Hello,

Since there is no "Konqueror" or "Konq-plugins" group in reviewboard, I am 
going to post this patch here. As the subject states the attached patch makes 
it possible for the searchbar plugin to be used with rendering engines other 
other than khtml, e.g. webkitpart.

Please CC me when you reply since I am not subscribed to kfm-devel. 

Thanks.

["searchbar.patch" (text/x-patch)]

Index: searchbar.cpp
===================================================================
--- searchbar.cpp	(revision 1027752)
+++ searchbar.cpp	(working copy)
@@ -194,7 +194,7 @@
     if (m_urlEnterLock || search.isEmpty() || !m_part)
         return;
     if (m_searchMode == FindInThisPage) {
-        KHTMLPart *part = dynamic_cast<KHTMLPart*>(m_part);
+        KHTMLPart *part = qobject_cast<KHTMLPart*>(m_part);
         if (part) {
             part->findText(search, 0);
             part->findTextNext();
@@ -292,7 +292,8 @@
 
         m_popupMenu = new QMenu(m_searchCombo);
         m_popupMenu->setObjectName("search selection menu");
-        m_popupMenu->addAction(KIcon("edit-find"), i18n("Find in This Page"), this, \
SLOT(useFindInThisPage())); +        QAction *action = \
m_popupMenu->addAction(KIcon("edit-find"), i18n("Find in This Page"), this, \
SLOT(useFindInThisPage())); +        \
action->setDisabled((qobject_cast<KHTMLPart*>(m_part) == 0));  \
m_popupMenu->addSeparator();  
         int i =- 1;
@@ -458,7 +459,7 @@
 
 void SearchBarPlugin::updateComboVisibility()
 {
-    bool isBrowser = m_part && dynamic_cast<KHTMLPart *>(m_part);
+    bool isBrowser = (m_part && m_part->browserExtension());
 
     m_searchComboAction->setVisible(isBrowser && \
!m_searchComboAction->associatedWidgets().isEmpty());  
@@ -502,33 +503,35 @@
 
 void SearchBarPlugin::HTMLDocLoaded()
 {
-    KHTMLPart *khtmlPart = static_cast<KHTMLPart *>(m_part);
+    KHTMLPart *khtmlPart = qobject_cast<KHTMLPart *>(m_part);
 
-    DOM::HTMLDocument htmlDoc = khtmlPart->htmlDocument();
-    DOM::NodeList headNL = htmlDoc.getElementsByTagName("head");
-    if (headNL.length() < 1) {
-        return;
-    }
+    if (khtmlPart) {
+        DOM::HTMLDocument htmlDoc = khtmlPart->htmlDocument();
+        DOM::NodeList headNL = htmlDoc.getElementsByTagName("head");
+        if (headNL.length() < 1) {
+            return;
+        }
 
-    DOM::Node headNode = headNL.item(0);
-    if (headNode.nodeType() != 1) {
-        return;
-    }
+        DOM::Node headNode = headNL.item(0);
+        if (headNode.nodeType() != 1) {
+            return;
+        }
 
-    DOM::HTMLElement headEl = (DOM::HTMLElement) headNode;
-    DOM::NodeList linkNL = headEl.getElementsByTagName("link");
+        DOM::HTMLElement headEl = (DOM::HTMLElement) headNode;
+        DOM::NodeList linkNL = headEl.getElementsByTagName("link");
 
-    for (unsigned int i = 0; i < linkNL.length(); i++) {
-        if (linkNL.item(i).nodeType() == 1) {
-            DOM::HTMLElement linkEl = (DOM::HTMLElement)linkNL.item(i);
-            if (linkEl.getAttribute("rel") == "search" && \
                linkEl.getAttribute("type") == \
                "application/opensearchdescription+xml") {
-                if (headEl.getAttribute("profile") != \
                "http://a9.com/-/spec/opensearch/1.1/") {
-                    kWarning() << "Warning: there is no profile attribute or wrong \
profile attribute in <head>, as specified by open search specification 1.1"; +        \
for (unsigned int i = 0; i < linkNL.length(); i++) { +            if \
(linkNL.item(i).nodeType() == 1) { +                DOM::HTMLElement linkEl = \
(DOM::HTMLElement)linkNL.item(i); +                if (linkEl.getAttribute("rel") == \
"search" && linkEl.getAttribute("type") == "application/opensearchdescription+xml") { \
+                    if (headEl.getAttribute("profile") != \
"http://a9.com/-/spec/opensearch/1.1/") { +                        kWarning() << \
"Warning: there is no profile attribute or wrong profile attribute in <head>, as \
specified by open search specification 1.1"; +                    }
+
+                    QString title = linkEl.getAttribute("title").string();
+                    QString href = linkEl.getAttribute("href").string();
+                    m_openSearchDescs.insert(title, href);
                 }
-
-                QString title = linkEl.getAttribute("title").string();
-                QString href = linkEl.getAttribute("href").string();
-                m_openSearchDescs.insert(title, href);
             }
         }
     }



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic