1 /**********************************************************************
2 Freeciv - Copyright (C) 2005 The Freeciv Team
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12 ***********************************************************************/
14 #include <fc_config.h>
25 #include "string_vector.h"
32 #include "themes_common.h"
34 /***************************************************************************
35 A theme is a portion of client data, which for following reasons should
36 be separated from a tileset:
37 - Theme is not only graphic related
38 - Theme can be changed independently from tileset
39 - Theme implementation is gui specific and most themes can not be shared
40 between different guis.
41 Theme is recognized by its name.
43 Theme is stored in a directory called like the theme. The directory contains
44 some data files. Each gui defines its own format in the
45 get_useable_themes_in_directory() function.
46 ****************************************************************************/
48 /* A directory containing a list of usable themes */
49 struct theme_directory
{
50 /* Path on the filesystem */
52 /* Array of theme names */
54 /* Themes array length */
58 /* List of all directories with themes */
59 static int num_directories
;
60 struct theme_directory
*directories
;
62 /****************************************************************************
63 Initialized themes data
64 ****************************************************************************/
65 void init_themes(void)
69 /* get GUI-specific theme directories */
70 char **gui_directories
=
71 get_gui_specific_themes_directories(&num_directories
);
74 fc_malloc(sizeof(struct theme_directory
) * num_directories
);
76 for (i
= 0; i
< num_directories
; i
++) {
77 directories
[i
].path
= gui_directories
[i
];
79 /* get useable themes in this directory */
80 directories
[i
].themes
=
81 get_useable_themes_in_directory(directories
[i
].path
,
82 &(directories
[i
].num_themes
));
86 /****************************************************************************
87 Return a static string vector of useable theme names.
88 ****************************************************************************/
89 const struct strvec
*get_themes_list(void)
91 static struct strvec
*themes_list
= NULL
;
93 if (NULL
== themes_list
) {
96 themes_list
= strvec_new();
97 for (i
= 0; i
< num_directories
; i
++) {
98 for (j
= 0; j
< directories
[i
].num_themes
; j
++) {
99 for (k
= 0; k
< strvec_size(themes_list
); k
++) {
100 if (strcmp(strvec_get(themes_list
, k
),
101 directories
[i
].themes
[j
]) == 0) {
105 if (k
== strvec_size(themes_list
)) {
106 strvec_append(themes_list
, directories
[i
].themes
[j
]);
115 /****************************************************************************
116 Loads a theme with the given name. First matching directory will be used.
117 If there's no such theme the function returns FALSE.
118 ****************************************************************************/
119 bool load_theme(const char *theme_name
)
122 for (i
= 0; i
< num_directories
; i
++) {
123 for (j
= 0; j
< directories
[i
].num_themes
; j
++) {
124 if (strcmp(theme_name
, directories
[i
].themes
[j
]) == 0) {
125 gui_load_theme(directories
[i
].path
, directories
[i
].themes
[j
]);
133 /****************************************************************************
134 Wrapper for load_theme. It's is used by local options dialog
135 ****************************************************************************/
136 void theme_reread_callback(struct option
*poption
)
138 const char *theme_name
= option_str_get(poption
);
140 fc_assert_ret(NULL
!= theme_name
&& theme_name
[0] != '\0');
141 load_theme(theme_name
);