(not) Adding a statusbar widget

Koos Vriezen koos.vriezen at xs4all.nl
Thu Jun 2 19:59:49 BST 2005


On Thu, May 19, 2005 at 11:50:33PM +0200, David Faure wrote:
> On Thursday 19 May 2005 23:32, Koos Vriezen wrote:
> > Hi,
> > 
> > I was wondering if from a kpart embedded in khtml, it would be possible
> > to add a widget to konqueror's statusbar.
> > For what I tried, everything seems to be ok(*), only the widget doesn't
> > show up. It does work however, if the part is embeded by konqueror
> > itself. Is this how it suppose to be?
> 
> KHTMLPart doesn't care for the StatusbarExtension of its child parts...
> I think it should look for one, and call setStatusBar in it, to propagate the
> statusbar that was set by konqueror into KHTMLPart's StatusbarExtension.
> Hopefully konq will set it before KHTMLPart gets child parts...
> 
> > I get a valid statusbar
> > pointer (according the code this is from the toplevel window)
> ... which is wrong for konqueror, since in konqueror there's a statusbar per view
> (think of splitted views), instead of the kmainwindow-constructed statusbar.

Ok thanks for your tips. I've attached something that makes kparts able
to add a widget to the khtml's top frame statusbar.

I've also added this for kjas applet's context. Because a page can have
multible applets, this seems to be the right way (though applets still
may use different contexts if they have different codebases/archives,
and will then add multible icons to the statusbar).
The idea is to use this for on-the-fly changable setting, like whether
showing java console.

Anyhow, it works :-).  Commit it?

Koos
-------------- next part --------------
Index: khtml_part.cpp
===================================================================
--- khtml_part.cpp	(revision 421260)
+++ khtml_part.cpp	(working copy)
@@ -4393,6 +4403,9 @@
     if (::qt_cast<KHTMLPart*>(part)) {
       static_cast<KHTMLPart*>(part)->d->m_frame = child;
     } else if (child->m_frame) {
+      KParts::StatusBarExtension *sb = KParts::StatusBarExtension::childObject(part);
+      if (sb)
+          sb->setStatusBar( d->m_statusBarExtension->statusBar() );
       child->m_liveconnect = KParts::LiveConnectExtension::childObject(part);
       if (child->m_liveconnect)
         connect(child->m_liveconnect, SIGNAL(partEvent(const unsigned long, const QString &, const KParts::LiveConnectExtension::ArgList &)), child, SLOT(liveConnectEvent(const unsigned long, const QString&, const KParts::LiveConnectExtension::ArgList &)));
Index: java/kjavaappletcontext.cpp
===================================================================
--- java/kjavaappletcontext.cpp	(revision 421260)
+++ java/kjavaappletcontext.cpp	(working copy)
@@ -26,10 +26,14 @@
 #include <klocale.h>
 #include <kmessagebox.h>
 #include <kdebug.h>
+#include <kstatusbar.h>
+#include <kiconloader.h>
+#include <kparts/statusbarextension.h>
 #include <qmap.h>
 #include <qguardedptr.h>
 #include <qstringlist.h>
 #include <qregexp.h>
+#include <qlabel.h>
 
 // This file was using 6002, but kdebug.areas didn't know about that number
 #define DEBUGAREA 6100
@@ -42,6 +46,8 @@
 friend class KJavaAppletContext;
 private:
     AppletMap applets;
+    QLabel *status_icon;
+    KParts::StatusBarExtension * statusbarExt;
 };
 
 //  Static Factory Functions
@@ -49,10 +55,12 @@
 
 /*  Class Implementation
  */
-KJavaAppletContext::KJavaAppletContext()
+KJavaAppletContext::KJavaAppletContext( KParts::StatusBarExtension * sb )
     : QObject()
 {
     d = new KJavaAppletContextPrivate;
+    d->status_icon = 0L;
+    d->statusbarExt = sb;
     server = KJavaAppletServer::allocateJavaServer();
     connect(server->javaProcess(), SIGNAL(exited(int)), this, SLOT(javaProcessExited(int)));
 
@@ -66,6 +74,8 @@
 {
     server->destroyContext( id );
     KJavaAppletServer::freeJavaServer();
+    if (d->status_icon)
+        d->statusbarExt->removeStatusBarItem( d->status_icon );
     delete d;
 }
 
@@ -89,6 +99,14 @@
 
 bool KJavaAppletContext::create( KJavaApplet* applet )
 {
+    if (!d->status_icon) {
+        KStatusBar *sb = d->statusbarExt->statusBar();
+        if (sb) {
+            d->status_icon = new QLabel( sb );
+            d->status_icon->setPixmap( SmallIcon( QString( "source_java" ) ) );
+            d->statusbarExt->addStatusBarItem( d->status_icon, 0, false );
+        }
+    }
     return server->createApplet( id, applet->appletId(),
                                 applet->appletName(),
                                 applet->appletClass(),
Index: java/kjavaappletviewer.cpp
===================================================================
--- java/kjavaappletviewer.cpp	(revision 421260)
+++ java/kjavaappletviewer.cpp	(working copy)
@@ -71,7 +71,7 @@
     KJavaServerMaintainer () { }
     ~KJavaServerMaintainer ();
 
-    KJavaAppletContext * getContext (QObject*, const QString &);
+    KJavaAppletContext * getContext (QObject*, const QString &, KParts::StatusBarExtension *);
     void releaseContext (QObject*, const QString &);
     void setServer (KJavaAppletServer * s);
 private:
@@ -85,14 +85,14 @@
     delete server;
 }
 
-KJavaAppletContext * KJavaServerMaintainer::getContext (QObject * w, const QString & doc) {
+KJavaAppletContext * KJavaServerMaintainer::getContext (QObject * w, const QString & doc, KParts::StatusBarExtension * sb) {
     ContextMap::key_type key = qMakePair (w, doc);
     ContextMap::iterator it = m_contextmap.find (key);
     if (it != m_contextmap.end ()) {
         ++((*it).second);
         return (*it).first;
     }
-    KJavaAppletContext* const context = new KJavaAppletContext ();
+    KJavaAppletContext* const context = new KJavaAppletContext (sb);
     m_contextmap.insert (key, qMakePair(context, 1));
     return context;
 }
@@ -198,6 +198,7 @@
  : KParts::ReadOnlyPart (parent, name),
    m_browserextension (new KJavaAppletViewerBrowserExtension (this)),
    m_liveconnect (new KJavaAppletViewerLiveConnectExtension (this)),
+   m_statusbar (new KParts::StatusBarExtension (this)),
    m_closed (true)
 {
     if (!serverMaintainer) {
@@ -288,7 +289,7 @@
     if (kapp->authorizeURLAction("redirect", KURL(baseurl), newURL))
         applet->setCodeBase (newURL.url());
     applet->setAppletClass (classname);
-    KJavaAppletContext* const cxt = serverMaintainer->getContext (parent, baseurl);
+    KJavaAppletContext* const cxt = serverMaintainer->getContext (parent, baseurl, m_statusbar);
     applet->setAppletContext (cxt);
 
     KJavaAppletServer* const server = cxt->getServer ();
Index: java/kjavaappletcontext.h
===================================================================
--- java/kjavaappletcontext.h	(revision 421260)
+++ java/kjavaappletcontext.h	(working copy)
@@ -37,7 +37,7 @@
  * @author Wynn Wilkes, wynnw at caldera.com
  */
 
-
+namespace KParts { class StatusBarExtension; }
 class KJavaAppletServer;
 class KJavaApplet;
 class KJavaAppletContextPrivate;
@@ -47,7 +47,7 @@
 Q_OBJECT
 
 public:
-    KJavaAppletContext();
+    KJavaAppletContext( KParts::StatusBarExtension * sb );
     ~KJavaAppletContext();
 
     /**
Index: java/kjavaappletviewer.h
===================================================================
--- java/kjavaappletviewer.h	(revision 421260)
+++ java/kjavaappletviewer.h	(working copy)
@@ -25,6 +25,7 @@
 
 #include <kparts/part.h>
 #include <kparts/browserextension.h>
+#include <kparts/statusbarextension.h>
 #include <kparts/factory.h>
 #include <kdialogbase.h>
 #include <kurl.h>
@@ -109,6 +110,7 @@
     KJavaProcess * process;
     KJavaAppletViewerBrowserExtension * m_browserextension;
     KJavaAppletViewerLiveConnectExtension * m_liveconnect;
+    KParts::StatusBarExtension * m_statusbar;
     QString baseurl;
     bool m_closed;
 };


More information about the kfm-devel mailing list