Making a KDE style plugin

Once you have either a KStyle or KThemeStyle derived class completed it is very easy to make a plugin. Here we will go over the three things you need to do: provide a few routines to identify and load the plugin, make a theme config file that uses the new style, and make a automake for it.

Routines Needed To Load The Style

KDE uses shared libraries and dynamic loading to load and unload KDE styles, so you need to provide a few routines for it to resolve. When you make your own style usually you will make a .cpp file for the style and a plugin.cpp file for the routines needed to load it. Let's say you have a style named "MosfetStyle" that is defined in mosfetstyle.h. You would then make the following plugin.cpp file:


#include "mosfetstyle.h"
#include < klocale.h >

extern "C" {
KStyle* allocate();
int minor_version();
int major_version();
const char *description();
}

KStyle* allocate()
{
return(new MosfetStyle);
}

int minor_version()
{
return(0);
}

int major_version()
{
return(1);
}

const char *description()
{
return(i18n("Mosfet's plugin"));
}


This is all you need to do to make KDE be able to resolve and load your new style.

The theme config file

As noted in previous sections, KDE uses the widgetStyle key to load a style. In order to use your new style you need to make a theme configuration that uses it. Using the example above, let's assume it's an unthemed style derived from KStyle. Then we only need to provide something like the following and install it in KDE's share/apps/kstyle/themes directory:


[Misc]
Name=Mosfet
Comment=Mosfet's unthemed style.
[KDE]
widgetStyle=mosfetstyle.la

This will tell KDE what the name of the style is, a comment to use in KDE Control Center, and what library to dynamically load in order to use it. If you have a fully themed style derived from KThemeStyle then you would need to provide a full theme configuration as described in this tutorial while setting the widgetStyle key to your plugin name instead of basicstyle.la.

An example automake file

The final step is of course making an automake file to install your neat new style. Following the above let's assume your style header is mosfetstyle.h, the C++ file is mosfetstyle.cpp, and the plugin routines are in plugin.cpp. To configure and install it we would use something like the following Makefile.am:


INCLUDES= $(all_includes)
METASOURCES=USE_AUTOMOC
noinst_HEADERS = mosfetstyle.h
lib_LTLIBRARIES = mosfetstyle.la
mosfetstyle_la_LDFLAGS = $(all_libraries) -module -avoid-version
mosfetstyle_la_SOURCES = mosfetstyle.cpp plugin.cpp

That's it :)

<< Previous Page | Next Page >>

Mail Mosfet