<othercredit role="translator"><firstname>Jonathan</firstname><surname>Riddell</surname><affiliation><address><email>kde-en-gb@jriddell.org</email></address></affiliation><contrib>Conversion to British English</contrib></othercredit>
<para>&ksplash; is a nice splash screen that shows the progress of an application that is loading. Please report any problems or feature requests to the &kde; mailing lists. The principal features of &ksplash;: </para>
<para>This handbook will show you how to create themes for use with plugins that are already available. If none of the plugins available satisfy your tastes, you can learn how to customise the appearance of &ksplash; completely by writing a plugin in C++. </para>
<para>To use themes from <ulink url="http://www.kde-look.org">KDE-Look</ulink>, extract them to <filename>~/.trinity/share/apps/ksplash/Themes/</filename> for a single user, or to <filename>$<envar>TDEDIR</envar>/share/apps/ksplash/Themes/</filename> to make them available to all users of your system.</para>
<para>You can also use the <guilabel>Splash Screen</guilabel> module under <guilabel>Appearance</guilabel> in the &kde; control centre to do this automatically.</para>
<para>This module allows you to install, test and remove &ksplash; themes.</para>
<para>Down the side of the module is a list of currently available &ksplash; themes. As you select one, a preview will display in the main part of the window. When you have selected the one you wish to use, press <guibutton>OK</guibutton> or <guibutton>Apply</guibutton>. Press <guibutton>Cancel</guibutton> to exit the module without making changes, and <guibutton>Defaults</guibutton> to restore the system default splash screen.</para>
<para>To install new modules, press <guibutton>Add...</guibutton>, and find the theme on your computer. You do not have to unpack theme files, you can safely select the compressed theme file. Installing a theme does not make it the theme in use until you select it in the list and press either <guibutton>OK</guibutton> or <guibutton>Apply</guibutton>.</para>
<para>Although you can see a preview of the splash screen, you may like to see how it looks in real use, for instance to see what the animation looks like. You can test themes by selecting them in the list and clicking the <guibutton>Test</guibutton> button.</para>
<para>You can also remove themes you no longer wish to use, by selecting them and pressing the <guibutton>Remove</guibutton> button. Note that your user account may not have the right to remove themes installed system-wide. It is also recommended you do not uninstall the <guilabel>Default</guilabel> splash screen.</para>
<para>Making your own themes for &ksplash; is easy. After you have finished your themes you can post them on the <ulink url="http://www.kde-look.org">KDE-Look</ulink> so that others can use it.</para>
<para>Let us create a theme called <literal>MyCoolTheme</literal>. For the theme to be recognised by &ksplash;, it should be stored in a folder called <filename class="directory">MyCoolTheme</filename> under <filename class="directory">~/.trinity/apps/ksplash/Themes/</filename>. It should have a file called <filename>Theme.rc</filename>, containing the settings of the theme. You can specify large numbers of special things to theme, change the plugin engine to use, and so on. You do not have to use all the settings available; usually, the settings have an acceptable default value. The basic syntax for entries in the <filename>Theme.rc</filename> file is <literal>[option] = [value]</literal> You can find the definitions of the various options in the following sections.</para>
<para>After specifying the name, the description and the author of the theme, you should first choose a theme engine (also known as a plugin). Then, you can customise various features of the theme engine by assigning key-value pairs as in the example file above.</para>
<para>It is important that the name of the directory under which the theme files are stored (<filename class="directory">~/.trinity/apps/ksplash/Themes/MyCoolTheme</filename> in our case) and the identifier (<literal>[KSplash Theme: MyCoolTheme] </literal> in our case) of the theme in the <filename>Theme.rc</filename> file are identical. Otherwise, &ksplash; will not recognise the theme. </para>
<para>When &ksplash; starts, it tries to find a background image for your current screen resolution, if the theme engine uses one. The background image file should be named in the following format: <filename>Background-<replaceable>WWWxHHH</replaceable>.png</filename>.</para>
<para>For example, you might use a file called <filename>Background-1024x768</filename>. If the background image for your screen resolution cannot be found, it tries to resize the original <filename>Background.png</filename> or the file specified in <filename>Theme.rc</filename> to suit the current resolution. Resizing on-the-fly will certainly take some time, so you should provide background images for at least the following sizes: 1280x1024, 1024x768 and 800x600.</para>
<para>In this chapter, we describe a simple method for using &ksplash; as the splash screen for your &kde; application. If you do not develop applications for &kde;, you can skip this chapter.</para>
<para>Your &kde; application must be &DCOP;-aware. &DCOP; is the &kde; technology used to communicate between applications. If you use the standard <ulink url="http://developer.kde.org">&kde; application framework</ulink>, this is taken care of automatically. For information about &DCOP; and related &kde; technologies, please visit the <ulink url="http://developer.kde.org">&kde; developers' corner</ulink>.</para>
<para>We will assume that there is only one instance of &ksplash; running. Other cases are slightly more complex. Please see the &DCOP; documentation for further details.</para>
<para>Before you show any messages, you need to set up the number of steps you will show. For example, the &kde; startup procedure uses 7 steps.</para>
<para>Each time you call <constant>programStarted</constant>, the steps completed is incremented. When your program has finished its startup, do the following to make the splash screen go away:</para>
<para>Writing new &ksplash; plugins is not difficult. In this chapter, we will write a simple plugin that will emulate the splash screen of a well known operating system. This tutorial assumes that you know the basics of C++, and a little bit of KDE/Qt programming.</para>
<para>We will create a plugin called <literal>2k</literal>. The plugin name is used in various places, and is important that you consistently use it so that the plugin is recognised by &ksplash;. &ksplash; plugins are actually dynamically loadable libraries with the following naming convention: </para>
<member>The library should be named as <filename>ksplash+lowercasethemename</filename>. For our theme, it will be <filename>ksplash2k</filename>.</member>
<member>It should have a corresponding desktop file which is named as <filename>ksplash+lowercasethemename.desktop</filename>. For our theme, it will be <filename>ksplash2k.desktop</filename>. </member>
<member>Finally, the object that is returned by the library should be a class which is named <literal>Theme+themename</literal>. For our example, it will be <literal>Theme2k</literal>.</member>
<para>Do not worry about it if you don't understand all of the above. We will consider each of those points in detail later. The other very important detail is that the plugin class should be derived from <literal>ThemeEngine</literal>. </para>
<para>We will use the &kde; application framework which will take care of building the plugin and will provide us with platform independence without any work on our part. To do that, make sure you have the <filename>tdesdk</filename> package installed. Run the command <literal>kapptemplate</literal> to produce an application named "2k". It will create a toplevel folder which contains generic files such as AUTHORS, &etc;. We are most interested in the subfolder called <filename class="directory">2k</filename>. Go into that subfolder and delete all the files there. Now we have the skeleton we require. </para>
<para>The next step is to create a <filename>.desktop</filename> file which, when installed, will tell &ksplash; that our plugin is available. Consistent with the naming conventions laid out in <link linkend="basic-requirements">the preceding section</link>, create a file called <filename>ksplash2k.desktop</filename> in that folder. It should contain the following lines: </para>
<para>The <literal>Encoding</literal>, <literal>Type</literal>, <literal>Comment</literal> and <literal>ServiceTypes</literal> are the same for all plugins. The plugin name and the library name follow the conventions noted earlier. The entry <literal>X-KSplash-Default</literal> takes a boolean value which determines whether it is shown in the control panel configuration module by default. Except for some very rare cases, it should be <constant>true</constant>. </para>
<para>Now that we have the preliminary work done, let us get into the actual fun part - creating a class that will provide the behaviour we want. While we are free to make this class do almost anything we want it to do, there are a few restrictions.</para>
<listitem><para>Plugin classes must inherit the <constant>ThemeEngine</constant> class.</para></listitem>
<listitem><para>Plugin classes must be named according to the rule: <classname>Theme+PluginName</classname>.</para></listitem>
<listitem><para>Plugin classes should provide a <literal>static</literal> function called <function>names</function> that returns a list of names by which it can be invoked.</para></listitem>
<listitem><para>If the plugin can be configured in the control centre module, it should provide a <literal>ThemeEngineConfig</literal>-based class for the configuration.</para></listitem>
<listitem><para>Plugin classes must override at least one of the virtual functions <function>slotSetText</function>, <function>slotSetPixmap</function>, <function>slotUpdateProgress</function> and <function>slotUpdateSteps</function> to make it usable.</para></listitem>
<listitem><para>The constructor should take the form <literal>ThemeEngine( TQWidget *parent, const char *name, const QStringList &args )</literal> so that it can be used with <classname>KGenericFactory</classname>.</para></listitem>
<para>The last requirement may seem complicated, but, as we will see later, by adding a single line to your source files, you can usually ignore it.</para>
<para>Let us analyse the listing above. The <classname>Theme2k</classname> class satisfies the naming conventions, and is inherited from <classname>ThemeEngine</classname>. It provides a <methodname>Theme2k::names()</methodname>, and has a constructor that takes the required parameters: <function>Theme2k( TQWidget *, const char *, const QStringList& );</function> and also provides a simple <methodname>Theme2k::slotSetText()</methodname> method. For the moment, do not worry about the <classname>RotWidget</classname> class. It is a small widget that provides some eye candy for the user. Our plugin is very simple and does not display any icons or show a progressbar. If you would like to display icons, override the <function>slotSetPixmap</function> function. Similar functions exist for setting the progressbar range (<function>slotUpdateSteps</function>) and incrementing(<function>slotUpdateProgress</function>) the current step. </para>
<para>We will examine only the relevant parts of the implementation. For a listing of the whole implementation, please see the appendix. The first thing we will do is to get the library requirement out of the way:</para>
<para>The macro <constant>K_EXPORT_COMPONENT_FACTORY</constant> is declared in <filename>kgenericfactory.h</filename>. Onwards to the constructor! Since this is a very simple plugin, the constructor is pretty straightforward.</para>
<para>The method <function>readSettings()</function> illustrates the proper way to obtain your theme settings. (You do want people to use your plugins in their themes, don't you?)</para>
<para>Since we like our users, we provide sensible defaults for parameters that are not present in the theme file. Note that we should always set our group to "KSplash Theme: themename" to remain compatible with future theme specifications. The <function>initUI()</function> method is not very interesting, as it merely builds up the widgets. Please see the appendix for details. </para>
<para>Since we decided to use the &kde; framework for compiling the plugin, we need to create a <filename>Makefile.am</filename>. It should look like this:</para>
<para>For more information on writing <filename>Makefile.am</filename> files for &kde;, please see the &kde; developers' <ulink url="http://developer.kde.org/documentation/other/makefile_am_howto.html">website</ulink>. The only thing of note is that we provide a default theme based on this plugin, and provide a preview image for it. As a matter of courtesy to your users, you should provide an example <filename>Theme.rc</filename> file illustrating the use of the various options.</para>
<para>You probably don't have the correct plugins for the theme. The plugins are in the <literal>kde-artwork</literal> package. Download and install it, and try then again.</para>
<para><filename>Theme.rc</filename> is the file where you can specify a theme's settings. For more information, take a look at <link linkend="themes">How to make themes for &ksplash;</link>. </para>
<para>In order to successfully use &ksplash;, you need &kde; version 3.2 or higher. Some themes may require specific plugins. If a theme does not work, please contact the theme author to find out where to obtain the appropriate plugin.</para>