Freeciv-3.1
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-sdl2 */
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{
42 char buf[strlen(directory) + strlen(DIR_SEPARATOR) + strlen(theme_name)
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 */
52 active_theme = NULL;
53
54 fc_snprintf(buf, sizeof(buf), "%s" DIR_SEPARATOR "%s" DIR_SEPARATOR "theme",
55 directory, theme_name);
56
59
61}
62
63/*************************************************************************/
67{
69 /* TRANS: No full stop after the URL, could cause confusion. */
70 log_fatal(_("No Sdl2-client theme was found. For instructions on how to "
71 "get one, please visit %s"), WIKI_URL);
72 exit(EXIT_FAILURE);
73 }
74}
75
76/*************************************************************************/
83{
84 const struct strvec *data_dirs = get_data_dirs();
85 char **directories = fc_malloc(strvec_size(data_dirs) * sizeof(char *));
86 int i = 0;
87
88 *count = strvec_size(data_dirs);
89 strvec_iterate(data_dirs, data_dir) {
90 char buf[strlen(data_dir) + strlen("/themes/gui-sdl2") + 1];
91
92 fc_snprintf(buf, sizeof(buf), "%s/themes/gui-sdl2", data_dir);
93
94 directories[i++] = fc_strdup(buf);
96
97 return directories;
98}
99
100/*************************************************************************/
106char **get_usable_themes_in_directory(const char *directory, int *count)
107{
108 DIR *dir;
109 struct dirent *entry;
110 char **theme_names = fc_malloc(sizeof(char *) * 2);
111 /* Allocated memory size */
112 int t_size = 2;
113
114 *count = 0;
115
116 dir = fc_opendir(directory);
117 if (!dir) {
118 /* This isn't directory or we can't list it */
119 return theme_names;
120 }
121
122 while ((entry = readdir(dir))) {
123 char buf[strlen(directory) + strlen(entry->d_name) + 32];
124 struct stat stat_result;
125
126 fc_snprintf(buf, sizeof(buf),
127 "%s/%s/theme.themespec", directory, entry->d_name);
128
129 if (fc_stat(buf, &stat_result) != 0) {
130 /* File doesn't exist */
131 continue;
132 }
133
134 if (!S_ISREG(stat_result.st_mode)) {
135 /* Not a regular file */
136 continue;
137 }
138
139 /* Otherwise it's ok */
140
141 /* Increase array size if needed */
142 if (*count == t_size) {
143 theme_names = fc_realloc(theme_names, t_size * 2 * sizeof(char *));
144 t_size *= 2;
145 }
146
147 theme_names[*count] = fc_strdup(entry->d_name);
148 (*count)++;
149 }
150
151 closedir(dir);
152
153 return theme_names;
154}
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:109
void gui_clear_theme(void)
Definition themes.c:72
void gui_load_theme(const char *directory, const char *theme_name)
Definition themes.c:43
void update_font_from_theme(int theme_font_size)
Definition gui_main.c:1304
unsigned default_font_size(struct theme *act_theme)
Definition gui_main.c:1295
#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
struct client_options gui_options
Definition options.c:71
const struct strvec * get_data_dirs(void)
Definition shared.c:886
#define DIR_SEPARATOR
Definition shared.h:127
size_t strvec_size(const struct strvec *psv)
#define strvec_iterate(psv, str)
#define strvec_iterate_end
char gui_sdl2_default_theme_name[512]
Definition options.h:375
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:969
int fc_stat(const char *filename, struct stat *buf)
Definition support.c:575
struct theme_directory * directories
get_usable_themes_in_directory
Definition themes_g.h:22
const char * directory
Definition themes_g.h:23
void theme_free(struct theme *ftheme)
Definition themespec.c:316
void theme_load_sprites(struct theme *t)
Definition themespec.c:992
void themespec_try_read(const char *theme_name)
Definition themespec.c:333
struct theme * active_theme
Definition themespec.c:154