Dynamic library with an add-on

Paul Chitescu Paul.Chitescu at IMC-Group.org
Fri Jun 13 19:27:01 CEST 2003


OK, as of now (Friday 13th :) Konq/E KONQE_1_0_BRANCH supports having
dynamic add-ons and also offers some support for building them.

I modified the Flash add-on so that is linked statically or built as a
dynamic add-on depending if the support is configured in. Look carefully at
that example, especially at the linker flags. It took me two days and a few
changes to figure out how to build everything conditionally. I didn't yet
manage to persuade automake to install the library in the proper place (see
below).

The magic word you want to say to configure is --enable-dlopen-addons

The add-on shared libraries can be loaded in two ways:


1. Place them in a directory and let the executable detect and load them.
The directories are those returned by locate("data","konq-embed/add-ons/"),
that is:
    $KDEHOME/share/apps/konq-embed/add-ons/
or
    $KDEDIR/share/apps/konq-embed/add-ons/
Note that if the first directory exists the second isn't searched at all.

Each library must be named like libFoo.so (replace Foo with whatever
appropriate but with no dots) and must be marked executable on non-windows
platforms (chmod +x). Each library is loaded early (after statically linked
add-ons) and the entry point konqe_register_libFoo is called. The
declaration should look like this:

    extern "C" void konqe_register_libFoo()


2. For add-ons that implement parts (something derived from
KParts::ReadOnlyPart) you can use the configuration file konq-embedrc and in
the [MIME Handlers] section write something like:

application/x-my-readonly-part=!/path/to/libmyviewer.so
application/x-my-readwrite-part=!!/path/to/libmyreadwritepart.so

The library will be loaded late - at the first request to load data with
that MIME type. The function called is similar to what KDE normally
requires - see KLibrary::factory() - but you have to return a pointer to a
KParts::Factory

    extern "C" void* init_libmyviewer()
    extern "C" void* init_libmyreadwritepart()


Again, look at the example at the end of add-ons/kflashpart/kflashpart.cpp
which implements both methods presented above.

As a side note now konqueror will no longer export its symbols
unnecessarilly, that is if neither --enable-dlopen-addons
or --with-javascript=dynamic are specified. There is no need to export
symbols for --enable-dynamic-ssl (the previous description --dynamic-ssl was
wrong, I fixed it) but only to support dlopen.


Good luck.

--
 Paul Chitescu
 pchitescu at null.ro   http://pchitescu.null.ro/   ICQ:22641673
 Any spammers will be painfully squeezed into /dev/null




More information about the konq-e mailing list