KonqSidebarPlugin: Get a pointer to the active KHTMLPart

David Faure faure at kde.org
Thu Jul 21 01:36:59 BST 2005


On Wednesday 20 July 2005 21:18, Cristian Boya de Groot wrote:
> First of all, I would like to thank Dawit Alemayehu for his answer to my 
> previous question about a site-specific referer. It worked perfectly!
> 
> Second, I was hoping someone could answer this totally different question.
> 
> I'm trying program a Konqueror Sidebar plugin that needs to get a list of the 
> images, links, etc. of the page that Konqueror is showing.
> 
> I had this working by using the DOM::HTMLDocument of the current page, which I 
> got using the following awkward method:
> 
> From the KonqSidebarPlugin:
> 
> 1. find the KonqMainWindow by doing
>    QObject* konqmainwindow = parent->parent()->parent()->parent()->parent();

Eek. You could use topLevelWidget() instead.

> 2. loop through konqmainwindow->children() until finding a KonqViewManager
> 
> 3. KHTMLPart* page = (KHTMLPart*) konqviewmanager->activePart();

Bad; konqviewmanager is supposed to be private (internal to konq).

myKonqMainWindow->currentView()->part() is already better, but still requires linking to konq's code,
which isn't portable AFAIK.

I guess you could do this using DCOP: getting hold of the KonqViewIface and then 
calling part() to get the dcop interface of the part. And then looking at khtml's dcop interface
for what you want to do. Hmm, might be difficult (once you go to DCOP land, there are
no pointers anymore, only the available DCOP API).

> If not, wouldn't this be a logic thing to have? I mean, the sidebar should be 
> able to interact with the page, right?

Well I'm not sure any sidebar module does that yet. It would also need to be
told when the active view changes (when using split views or tabs) etc....
A new type of event could be added for this.
In fact this would be the cleanest solution. Konqueror could send all views
(including the sidebar) an event when the active view changes, shipping the
pointer to the part, which you can then tentatively downcast to a KHTMLPart
and connect to completed etc.
See libkonq/konq_events.* for the definition of the events, and konq_mainwindow
for where to emit the event....

-- 
David Faure, faure at kde.org, sponsored by Trolltech to work on KDE,
Konqueror (http://www.konqueror.org), and KOffice (http://www.koffice.org).





More information about the kfm-devel mailing list