

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:
The macro K_EXPORT_COMPONENT_FACTORY is declared in
kgenericfactory.h. Onwards to the constructor!
Since this is a very simple plugin, the constructor is pretty
straightforward.
Example 5.3. Plugin constructor
Theme2k::Theme2k( QWidget *parent, const char *name, const QStringList &args
)
:ThemeEngine( parent, name, args )
{
readSettings();
initUi();
}
The method readSettings() illustrates the
proper way to obtain your theme settings. (You do want people to use your
plugins
in their themes, don't you?)
Example 5.4. Obtaining theme settings
void Theme2k::readSettings()
{
if( !mTheme )
return;
KConfig *cfg = mTheme->themeConfig();
if( !cfg )
return;
cfg->setGroup( QString("KSplash Theme: %1").arg(mTheme->theme()) );
QColor DefaultTBgColor( Qt::darkBlue );
QColor DefaultTFgColor( Qt::white );
mTBgColor = cfg->readColorEntry( "Title Background Color",
&DefaultTBgColor );
mTFgColor = cfg->readColorEntry( "Title Foreground Color",
&DefaultTFgColor );
mStatusColor = cfg->readColorEntry("Status Text Color", &mTBgColor );
QColor DefaultRot1( Qt::darkBlue );
QColor DefaultRot2( Qt::cyan );
mRotColor1 = cfg->readColorEntry( "Rotator Color 1", &DefaultRot1 );
mRotColor2 = cfg->readColorEntry( "Rotator Color 2", &DefaultRot2 );
mRotSpeed = cfg->readNumEntry( "Rotator Speed", 30 );
mWndTitle = cfg->readEntry( "Window Title", i18n("Please wait...") );
mLogoFile = cfg->readEntry( "Logo File", QString::null );
}
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
initUI() method is
not very interesting, as it merely builds up the widgets. Please see the
appendix for details.