Freeciv-3.2
Loading...
Searching...
No Matches
themes.c
Go to the documentation of this file.
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)
6 any later version.
7
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***********************************************************************/
13#ifdef HAVE_CONFIG_H
14#include <fc_config.h>
15#endif
16
17#ifdef FREECIV_HAVE_DIRENT_H
18#include <dirent.h>
19#endif
20
21#include <sys/stat.h>
22
23/* utility */
24#include "fc_dirent.h"
25#include "fcintl.h"
26#include "log.h"
27#include "mem.h"
28#include "string_vector.h"
29
30/* client/gui-sdl3 */
31#include "gui_main.h"
32#include "themespec.h"
33
34#include "themes_common.h"
35#include "themes_g.h"
36
37/*************************************************************************/
40void gui_load_theme(const char *directory, const char *theme_name)
41{
43 + strlen(DIR_SEPARATOR "theme") + 1];
44
45 if (active_theme != NULL) {
46 /* We don't support changing theme once it has been loaded */
47 return;
48 }
49
50 /* Free previous loaded theme, if any */
53
54 fc_snprintf(buf, sizeof(buf), "%s" DIR_SEPARATOR "%s" DIR_SEPARATOR "theme",
56
59
61}
62
63/*************************************************************************/
67{
69 /* TRANS: No full stop after the URL, could cause confusion. */
70 log_fatal(_("No Sdl3-client theme was found. For instructions on how to "
71 "get one, please visit %s"), HOMEPAGE_URL);
72
74 }
75}
76
77/*************************************************************************/
84{
85 const struct strvec *data_dirs = get_data_dirs();
86 char **directories = fc_malloc(strvec_size(data_dirs) * sizeof(char *));
87 int i = 0;
88
89 *count = strvec_size(data_dirs);
91 char buf[strlen(data_dir) + strlen("/themes/gui-sdl3") + 1];
92
93 fc_snprintf(buf, sizeof(buf), "%s/themes/gui-sdl3", data_dir);
94
97
98 return directories;
99}
100
101/*************************************************************************/
107char **get_usable_themes_in_directory(const char *directory, int *count)
108{
109 DIR *dir;
110 struct dirent *entry;
111 char **theme_names = fc_malloc(sizeof(char *) * 2);
112 /* Allocated memory size */
113 int t_size = 2;
114
115 *count = 0;
116
117 dir = fc_opendir(directory);
118 if (!dir) {
119 /* This isn't directory or we can't list it */
120 return theme_names;
121 }
122
123 while ((entry = readdir(dir))) {
124 char buf[strlen(directory) + strlen(entry->d_name) + 32];
125 struct stat stat_result;
126
127 fc_snprintf(buf, sizeof(buf),
128 "%s/%s/theme.themespec", directory, entry->d_name);
129
130 if (fc_stat(buf, &stat_result) != 0) {
131 /* File doesn't exist */
132 continue;
133 }
134
135 if (!S_ISREG(stat_result.st_mode)) {
136 /* Not a regular file */
137 continue;
138 }
139
140 /* Otherwise it's ok */
141
142 /* Increase array size if needed */
143 if (*count == t_size) {
144 theme_names = fc_realloc(theme_names, t_size * 2 * sizeof(char *));
145 t_size *= 2;
146 }
147
148 theme_names[*count] = fc_strdup(entry->d_name);
149 (*count)++;
150 }
151
152 closedir(dir);
153
154 return theme_names;
155}
char * incite_cost
Definition comments.c:75
DIR * fc_opendir(const char *dir_to_open)
Definition fc_dirent.c:29
#define _(String)
Definition fcintl.h:67
static bool load_theme
Definition theme_dlg.c:30
char ** get_gui_specific_themes_directories(int *count)
Definition themes.c:104
void gui_clear_theme(void)
Definition themes.c:72
void gui_load_theme(const char *directory, const char *theme_name)
Definition themes.c:45
void update_font_from_theme(int theme_font_size)
Definition gui_main.c:1323
unsigned default_font_size(struct theme *act_theme)
Definition gui_main.c:1313
#define GUI_SDL_OPTION(optname)
Definition gui_main.h:37
void theme_free(struct theme *ftheme)
Definition themespec.c:317
void theme_load_sprites(struct theme *t)
Definition themespec.c:990
void themespec_try_read(const char *theme_name)
Definition themespec.c:334
struct theme * active_theme
Definition themespec.c:154
#define log_fatal(message,...)
Definition log.h:100
#define fc_strdup(str)
Definition mem.h:43
#define fc_realloc(ptr, sz)
Definition mem.h:36
#define fc_malloc(sz)
Definition mem.h:34
const struct strvec * get_data_dirs(void)
Definition shared.c:893
#define DIR_SEPARATOR
Definition shared.h:127
size_t strvec_size(const struct strvec *psv)
#define strvec_iterate(psv, str)
#define strvec_iterate_end
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:974
int fc_stat(const char *filename, struct stat *buf)
Definition support.c:576
struct theme_directory * directories
get_usable_themes_in_directory
Definition themes_g.h:22
const char * directory
Definition themes_g.h:23