In KDE's infrastructure, kioslaves handle the transfer of data between applications and remote servers using common protocols such as http and ftp, but they also handle more mundane protocols like the file protocol for local files. Many of the mainstream protocols provided in the standard KDE distribution are implemented in C++, although some, like the finger kioslave, rely on support scripts to handle various aspects of their functionality. Since PyKDE provides Python implementations (or wrappers) for the relevant classes in the kio library, it is possible to write kioslaves almost completely in Python; a simple C++ handling function is only required for dynamic linking purposes and to set up the interpreter.
Much of the currently available documentation about kioslaves provides C++ examples of the appropriate classes in use. When read alongside some of the kioslaves distributed in KDE's kdebase package, these tutorials provide most of the information required to write a kioslave in Python. However, it may be useful to provide a Python-specific example to complement existing material and to fill any gaps in the existing documentation. Additions and corrections to this document are most welcome.
A working kioslave needs the following resources:
Additionally, a Python kioslave requires a place to store the Python source code and possibly storage for any packages which are not situated in the standard Python library directory.
Five examples are provided to demonstrate the possibilities allowed by writing kioslaves in Python. Although each kioslave has a fairly specific purpose, they all share a fair amount of common code.
Disk images from ADFS floppy disks can be opened and displayed through this kioslave which uses an existing Python module to provide read-only access to the ADFS filesystem. The ADFSlib module is supplied with the kioslave.
This example presents the user's bookmarks for Konqueror as a filesystem and allows limited manipulation of the contents.
The Package kioslave allows you to create XML descriptions of packages that can be assembled using a simple command line tool. Each package file contains references to files on the local filing system, and allows them to be named and positioned independently of their initial locations.
When the supplied package-components.py tool is used to process a package, the files are copied from their locations into a new directory that can then be archived as required.
This example presents the Python objects used in the kioslave itself as the contents of a filing system. Any object that has a __dict__ attribute containing a non-zero number of items is presented as a directory; all other items are presented as text files that can be examined using a text editor.
This kioslave is sufficiently simple enough to use as the subject of the kioslaves tutorial.
Using data obtained through a Python module, this example enables Acorn (or RISC OS) Spritefiles to be displayed in Konqueror as a read-only filesystem. This allows each image stored in the file to be accessed individually and, since they are represented as PNG format files, they are automatically displayed as thumbnails by the standard thumbnail generators.
You will need to have installed the spritefile module to be able to use this kioslave.