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#include <sys/types.h>
23#include <unistd.h>
24
25#include <gtk/gtk.h>
26
27/* utility */
28#include "fc_dirent.h"
29#include "mem.h"
30#include "string_vector.h"
31
32/* client */
33#include "themes_common.h"
34
35/* gui-gtk-4.0 */
36#include "gui_main.h"
37
38#include "themes_g.h"
39
41
42/*************************************************************************/
45void gui_load_theme(const char *directory, const char *theme_name)
46{
47 char buf[strlen(directory) + strlen(theme_name) + 32];
48
49 if (theme_provider == NULL) {
55 }
56
57 /* Gtk theme is a directory containing gtk-4.0/gtk.css file */
58 fc_snprintf(buf, sizeof(buf), "%s/%s/gtk-4.0/gtk.css", directory,
60
62}
63
64/*************************************************************************/
68{
69 bool theme_loaded;
70
71 /* Try to load user defined theme */
73
74 /* No user defined theme loaded -> try to load Freeciv default theme */
75 if (!theme_loaded) {
77 if (theme_loaded) {
79 }
80 }
81
82 /* Still no theme loaded -> drop theme provider */
83 if (!theme_loaded && theme_provider != NULL) {
88 }
89}
90
91/*************************************************************************/
100{
102 char *home_dir;
103 const struct strvec *data_dirs = get_data_dirs();
105 * sizeof(char *));
106
107 *count = 0;
108
109 /* Freeciv-specific GTK4 themes directories */
111 char buf[strlen(dir_name) + strlen("/themes/gtk4") + 1];
112
113 fc_snprintf(buf, sizeof(buf), "%s/themes/gtk4", dir_name);
114
115 directories[(*count)++] = fc_strdup(buf);
117
118 /* standard GTK themes directory */
119#ifdef CROSSER
120 standard_dir = "../share/themes";
121#else /* CROSSER */
122 standard_dir = "/usr/share/themes";
123#endif /* CROSSER */
124 directories[(*count)++] = fc_strdup(standard_dir);
125
126 /* user GTK themes directory (~/.themes) */
128 if (home_dir) {
129 char buf[strlen(home_dir) + 16];
130
131 fc_snprintf(buf, sizeof(buf), "%s/.themes/", home_dir);
132 directories[(*count)++] = fc_strdup(buf);
133 }
134
135 return directories;
136}
137
138/*************************************************************************/
144char **get_usable_themes_in_directory(const char *directory, int *count)
145{
146 DIR *dir;
147 struct dirent *entry;
148 char **theme_names = fc_malloc(sizeof(char *) * 2);
149 /* Allocated memory size */
150 int t_size = 2;
151
152
153 *count = 0;
154
155 dir = fc_opendir(directory);
156 if (!dir) {
157 /* This isn't directory or we can't list it */
158 return theme_names;
159 }
160
161 while ((entry = readdir(dir))) {
162 char buf[strlen(directory) + strlen(entry->d_name) + 32];
163 struct stat stat_result;
164
165 fc_snprintf(buf, sizeof(buf),
166 "%s/%s/gtk-4.0/gtk.css", directory, entry->d_name);
167
168 if (fc_stat(buf, &stat_result) != 0) {
169 /* File doesn't exist */
170 continue;
171 }
172
173 if (!S_ISREG(stat_result.st_mode)) {
174 /* Not a regular file */
175 continue;
176 }
177
178 /* Otherwise it's ok */
179
180 /* Increase array size if needed */
181 if (*count == t_size) {
182 theme_names = fc_realloc(theme_names, t_size * 2 * sizeof(char *));
183 t_size *= 2;
184 }
185
186 theme_names[*count] = fc_strdup(entry->d_name);
187 (*count)++;
188 }
189
190 closedir(dir);
191
192 return theme_names;
193}
char * incite_cost
Definition comments.c:75
DIR * fc_opendir(const char *dir_to_open)
Definition fc_dirent.c:29
GtkWidget * toplevel
Definition gui_main.c:125
#define GUI_GTK_DEFAULT_THEME_NAME
Definition gui_main.h:27
#define GUI_GTK_OPTION(optname)
Definition gui_main.h:25
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
static GtkCssProvider * theme_provider
Definition themes.c:40
void gui_load_theme(const char *directory, const char *theme_name)
Definition themes.c:45
#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
char * user_home_dir(void)
Definition shared.c:634
const struct strvec * get_data_dirs(void)
Definition shared.c:893
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
#define sz_strlcpy(dest, src)
Definition support.h:195
struct theme_directory * directories
get_usable_themes_in_directory
Definition themes_g.h:22
const char * directory
Definition themes_g.h:23