navigator.plugins and kparts for konqueror
Koos Vriezen
koos.vriezen at xs4all.nl
Fri Feb 13 14:52:12 GMT 2004
On Fri, Feb 13, 2004 at 11:31:21AM +0100, Koos Vriezen wrote:
> A bug was entered for kmplayer http://bugs.kde.org/show_bug.cgi?id=75108
> and it's about a page
> http://www-306.ibm.com/e-business/doc/content/ondemand/tvspot.html
> that uses navigator.plugins to determine if a certain movie player is
> installed (see http://www-306.ibm.com/e-business/doc/content/ondemand/popups.js)
> Currently ecma/kjs_navigator.cpp only looks in
> .kde/share/apps/nsplugins/pluginsinfo for that array, not including
> plugins like kjas and kmplayer (unacceptable of course :-).
> So what we could do is assign a rc or directory for it in share/apps/khtml,
> or return an array of all registered mime types that have an embedded app
> assigned...actually I like the last option.
Rob Buis pointed me to a patch he posted in Oct last year and it does
pretty much the above. I changed it a little bit, less kdebug, strip original
nsplugin config stuff and no special case for inode.
Checked the contents of plugins and mimeTypes array with
<html><head><script>
function printObjectArray(arrayname,props) {
array = eval(arrayname);
document.write(arrayname + " has " + array.length + " elements<br>");
for(var i = 0; i < array.length; i++) {
document.write("+ " + arrayname + "[" + i + "]<br>");
for (var j = 0; j < props.length; j++)
document.write("L__ " + props[j] + "=" + array[i][props[j]] + "<br>");
}
}
</script></head><body>
<script>
printObjectArray("navigator.mimeTypes", ["type","description","suffixes","enabledPlugin"]);
printObjectArray("navigator.plugins",["name","filename","description","length"]);
</script></body></html>
script and all the original mimes are there, although some descriptions are
different (eg. FutureSplash Player becomes Netscape Shockwave Flash) and
mimeTypes[i].suffixes are pattern (like *.avi). Maybe that should be changed too.
Btw, not that this makes the tvspot.html working because of a case
sensitive search ugh.
>
> Koos
>
-------------- next part --------------
Index: kjs_navigator.cpp
===================================================================
RCS file: /home/kde/kdelibs/khtml/ecma/kjs_navigator.cpp,v
retrieving revision 1.66
diff -u -3 -p -r1.66 kjs_navigator.cpp
--- kjs_navigator.cpp 16 Oct 2003 22:50:03 -0000 1.66
+++ kjs_navigator.cpp 13 Feb 2004 14:47:03 -0000
@@ -28,6 +28,9 @@
#include <kdebug.h>
#include <kio/kprotocolmanager.h>
+#include <kio/kmimetype.h>
+#include <kio/kservice.h>
+#include <kio/ktrader.h>
#include "kjs_navigator.h"
#include "kjs/lookup.h"
#include "kjs_binding.h"
@@ -232,51 +235,42 @@ PluginBase::PluginBase(ExecState *exec)
plugins->setAutoDelete( true );
mimes->setAutoDelete( true );
- // read configuration
- KConfig c(KGlobal::dirs()->saveLocation("data","nsplugins")+"/pluginsinfo");
- unsigned num = (unsigned int)c.readNumEntry("number");
- // FIXME: add domain support here
- KConfig kc("konquerorrc", true);
- bool enabled = KConfigGroup(&kc, "Java/JavaScript Settings").readBoolEntry("EnablePlugins", true);
- for ( unsigned n = 0; enabled && n < num; n++ ) {
-
- c.setGroup( QString::number(n) );
+ // read in using KTrader
+ KTrader::OfferList offers = KTrader::self()->query("Browser/View");
+ KTrader::OfferList::iterator it;
+ for ( it = offers.begin(); it != offers.end(); ++it ) {
PluginInfo *plugin = new PluginInfo;
- plugin->name = c.readEntry("name");
- plugin->file = c.readPathEntry("file");
- plugin->desc = c.readEntry("description");
-
- //kdDebug(6070) << "plugin : " << plugin->name << " - " << plugin->desc << endl;
+ plugin->name = (**it).name();
+ plugin->file = (**it).library();
+ plugin->desc = (**it).comment();
plugins->append( plugin );
// get mime types from string
- QStringList types = QStringList::split( ';', c.readEntry("mime") );
+ QStringList types = (**it).serviceTypes();
QStringList::Iterator type;
for ( type=types.begin(); type!=types.end(); ++type ) {
// get mime information
QStringList tokens = QStringList::split(':', *type, true);
- if ( tokens.count() < 3 ) // we need 3 items
- continue;
-
- MimeClassInfo *mime = new MimeClassInfo;
- QStringList::Iterator token = tokens.begin();
- mime->type = (*token).lower();
- //kdDebug(6070) << "mime->type=" << mime->type << endl;
- ++token;
-
- mime->suffixes = *token;
- ++token;
-
- mime->desc = *token;
- ++token;
-
- mime->plugin = plugin;
-
- mimes->append( mime );
- plugin->mimes.append( mime );
+ QStringList::Iterator token;
+ for ( token=tokens.begin(); token!=tokens.end(); ++token ) {
+ KMimeType::Ptr mimePtr = KMimeType::mimeType(*token);
+ QString name = (*mimePtr).name();
+ if ( name != KMimeType::defaultMimeType() )
+ {
+ MimeClassInfo *mime = new MimeClassInfo;
+ mime->type = name;
+ mime->suffixes = (*mimePtr).patterns().join(", ");
+ mime->desc = (*mimePtr).comment();
+
+ mime->plugin = plugin;
+
+ mimes->append( mime );
+ plugin->mimes.append( mime );
+ }
+ }
}
}
}
More information about the kfm-devel
mailing list