[Kde-games-devel] Draft for the core KgTheme API
Parker Coates
coates at kde.org
Thu Mar 15 03:22:54 UTC 2012
On Wed, Mar 14, 2012 at 19:23, Stefan Majewsky wrote:
> this evening, when without internet connection, I finally sat down to
> write the UI-independent core of the KgTheme API. For an early API
> review, I have attached kgtheme.h and kgthemeprovider.h plus a patch
> on kgamerenderer.h for integration. There is also an implementation
> for this, but I won't post a review until I got kdegames to compile
> again. This fails at the moment because of source-incompatible changes
> in KGameRenderer.
>
> The main difference between KGameTheme and KgTheme is that there are
> two classes: KgTheme is a single theme, KgThemeProvider is a set of
> themes. The provider is responsible for maintaining the theme
> selection and communicating that to KGameRenderer. This development is
> identical to KgDifficulty, where (compared to KGameDifficulty) the
> responsibility for storing the difficulty selection has moved into the
> library.
>
> End of the braindump. Any thoughts on anything?
Rather than comment too much on specifics of your API, I'll point you
to what I created when I needed such classes for card deck themes. See
kdegames/kpat/libkcardgame/kcardtheme.h. Obviously it's not an apples
to apples comparison, but there's plenty of common requirements. Don't
judge too harshly, though as I have some in improvements in progress
in a work branch. :)
The main highlights:
* KCardTheme objects have no non-const methods (including setters). I
couldn't find a use case in which a theme object ever needed to change
after its creation.
* KCardTheme objects are implicitly shared, so they are always passed
by value. Because pointers are never used, one never needs to worry
about who "owns" the theme object and needs to delete it. As a bonus,
because all methods are const, copies never detach.
* Finding themes is done with a single static method and there's no
notion of a provider. KgThemeProvider mainly provides methods for
setting and getting the current and default themes, but personally I'd
much rather use KConfig(XT) for this.
Parker
More information about the kde-games-devel
mailing list