Freeciv-3.3
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-3.22 */
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 GError *error = NULL;
48 char buf[strlen(directory) + strlen(theme_name) + 32];
49
50 if (theme_provider == NULL) {
56 }
57
58 /* Gtk theme is a directory containing gtk-3.0/gtk.css file */
59 fc_snprintf(buf, sizeof(buf), "%s/%s/gtk-3.0/gtk.css", directory,
61
63
64 if (error != NULL) {
65 g_warning("%s\n", error->message);
66 }
67}
68
69/*************************************************************************/
73{
74 bool theme_loaded;
75
76 /* Try to load user defined theme */
78
79 /* No user defined theme loaded -> try to load Freeciv default theme */
80 if (!theme_loaded) {
82 if (theme_loaded) {
84 }
85 }
86
87 /* Still no theme loaded -> load system default theme */
88 if (!theme_loaded && theme_provider != NULL) {
93 }
94}
95
96/*************************************************************************/
105{
107 char *home_dir;
108 const struct strvec *data_dirs = get_data_dirs();
110 * sizeof(char *));
111
112 *count = 0;
113
114 /* Freeciv-specific GTK3.22 themes directories */
116 char buf[strlen(dir_name) + strlen("/themes/gtk3.22") + 1];
117
118 fc_snprintf(buf, sizeof(buf), "%s/themes/gtk3.22", dir_name);
119
120 directories[(*count)++] = fc_strdup(buf);
122
123 /* standard GTK+ themes directory */
124#ifdef CROSSER
125 standard_dir = "../share/themes";
126#else /* CROSSER */
127 standard_dir = "/usr/share/themes";
128#endif /* CROSSER */
129 directories[(*count)++] = fc_strdup(standard_dir);
130
131 /* user GTK+ themes directory (~/.themes) */
133 if (home_dir) {
134 char buf[strlen(home_dir) + 16];
135
136 fc_snprintf(buf, sizeof(buf), "%s/.themes/", home_dir);
137 directories[(*count)++] = fc_strdup(buf);
138 }
139
140 return directories;
141}
142
143/*************************************************************************/
149char **get_usable_themes_in_directory(const char *directory, int *count)
150{
151 DIR *dir;
152 struct dirent *entry;
153 char **theme_names = fc_malloc(sizeof(char *) * 2);
154 /* Allocated memory size */
155 int t_size = 2;
156
157
158 *count = 0;
159
160 dir = fc_opendir(directory);
161 if (!dir) {
162 /* This isn't directory or we can't list it */
163 return theme_names;
164 }
165
166 while ((entry = readdir(dir))) {
167 char buf[strlen(directory) + strlen(entry->d_name) + 32];
168 struct stat stat_result;
169
170 fc_snprintf(buf, sizeof(buf),
171 "%s/%s/gtk-3.0/gtk.css", directory, entry->d_name);
172
173 if (fc_stat(buf, &stat_result) != 0) {
174 /* File doesn't exist */
175 continue;
176 }
177
178 if (!S_ISREG(stat_result.st_mode)) {
179 /* Not a regular file */
180 continue;
181 }
182
183 /* Otherwise it's ok */
184
185 /* Increase array size if needed */
186 if (*count == t_size) {
187 theme_names = fc_realloc(theme_names, t_size * 2 * sizeof(char *));
188 t_size *= 2;
189 }
190
191 theme_names[*count] = fc_strdup(entry->d_name);
192 (*count)++;
193 }
194
195 closedir(dir);
196
197 return theme_names;
198}
char * incite_cost
Definition comments.c:76
DIR * fc_opendir(const char *dir_to_open)
Definition fc_dirent.c:29
GtkWidget * toplevel
Definition gui_main.c:126
#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:627
const struct strvec * get_data_dirs(void)
Definition shared.c:886
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:960
int fc_stat(const char *filename, struct stat *buf)
Definition support.c:574
#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