2 #include <core/repository.h>
4 #include "builtinvariants.h"
6 extern "C" Repository
* taguachess_initrepo(IVariantLoader
*);
7 extern "C" Repository
* taguachess5x5_initrepo(IVariantLoader
*);
8 extern "C" Repository
* taguacrazyhouse_initrepo(IVariantLoader
*);
9 extern "C" Repository
* taguashogi_initrepo(IVariantLoader
*);
11 // FIXME: a KDE plugin willing to reuse a builtin one crashes
14 * Hardcoded definition of builtin variants.
16 static const struct builtin
{
18 Repository
* (*init_func
)(IVariantLoader
*);
19 const char* theme_proxy
;
21 { "Chess", taguachess_initrepo
, "Chess" },
22 { "Chess 5x5", taguachess5x5_initrepo
, "Chess" },
23 { "Crazyhouse", taguacrazyhouse_initrepo
, "Chess" },
24 { "Shogi", taguashogi_initrepo
, "Shogi" },
27 static const struct builtin
* const get_builtin(QString name
) {
28 for (unsigned i
=0; i
< sizeof(builtins
)/sizeof(builtins
[0]); i
++)
29 if (name
.compare(builtins
[i
].name
, Qt::CaseInsensitive
) == 0)
34 BuiltinVariants::BuiltinVariants() {
35 for (unsigned i
=0; i
< sizeof(builtins
)/sizeof(builtins
[0]); i
++)
36 m_allvariants
<< builtins
[i
].name
;
39 BuiltinVariants
& BuiltinVariants::self() {
40 static BuiltinVariants inst
;
44 Variant
* BuiltinVariants::create(const QString
& name
) {
45 Repository
* repo
= getRepository(name
);
47 const struct builtin
* const builtin
= get_builtin(name
);
49 kFatal() << "builtin not properly registered" << name
;
50 return new Variant(name
, repo
, builtin
->theme_proxy
);
55 QStringList
BuiltinVariants::all() const {
59 Repository
* BuiltinVariants::getRepository(const QString
& variant
) {
60 if (m_variants
.contains(variant
))
61 return m_variants
[variant
];
63 Repository
* repo
= NULL
;
64 const struct builtin
* const builtin
= get_builtin(variant
);
66 repo
= builtin
->init_func(this);
68 m_variants
[builtin
->name
] = repo
;
70 kError() << "could not load builtin variant" << variant
;