Freeciv21
Develop your civilization from humble roots to a global empire
themes_common.cpp
Go to the documentation of this file.
1 /*
2 _ ._ Copyright (c) 1996-2021 Freeciv21 and Freeciv contributors.
3  \ | This file is part of Freeciv21. Freeciv21 is free software: you
4  \_| can redistribute it and/or modify it under the terms of the
5  .' '. GNU General Public License as published by the Free
6  :O O: Software Foundation, either version 3 of the License,
7  '/ \' or (at your option) any later version. You should have
8  :X: received a copy of the GNU General Public License along with
9  :X: Freeciv21. If not, see https://www.gnu.org/licenses/.
10  */
11 
12 // utility
13 #include "log.h"
14 #include "support.h"
15 
16 /* client/include */
17 #include "themes_g.h"
18 
19 // client
20 #include "options.h"
21 #include "qtg_cxxside.h"
22 #include "themes_common.h"
23 
25 
26 
41 // A directory containing a list of usable themes
43  // Path on the filesystem
44  QString path;
45  // Array of theme names
46  QStringList themes;
47 };
48 
49 // List of all directories with themes
50 static int num_directories;
52 
57 {
58  int i;
59 
60  // get GUI-specific theme directories
61  QStringList gui_directories =
63 
65 
66  for (i = 0; i < num_directories; i++) {
67  directories[i].path = gui_directories.at(i);
68 
69  // get useable themes in this directory
70  directories[i].themes =
72  }
73 }
74 
78 const QVector<QString> *get_themes_list(const struct option *poption)
79 {
80  if (themes_list->isEmpty()) {
81  for (int i = 0; i < num_directories; i++) {
82  for (const auto &theme : qAsConst(directories[i].themes)) {
83  bool found = false;
84  for (int k = 0; k < themes_list->count(); k++) {
85  if (themes_list->at(k) == theme) {
86  found = true;
87  break;
88  }
89  }
90  if (!found) {
91  themes_list->append(theme);
92  }
93  }
94  }
95  }
96 
97  return themes_list;
98 }
99 
104 bool load_theme(const QString &theme_name)
105 {
106  for (int i = 0; i < num_directories; i++) {
107  for (const auto &theme : directories[i].themes) {
108  if (theme_name == theme) {
109  gui_load_theme(directories[i].path, theme);
110  return true;
111  }
112  }
113  }
114  return false;
115 }
116 
120 void theme_reread_callback(struct option *poption)
121 {
122  const char *theme_name = option_str_get(poption);
123 
124  fc_assert_ret(nullptr != theme_name && theme_name[0] != '\0');
125  load_theme(theme_name);
126 }
#define fc_assert_ret(condition)
Definition: log.h:112
const char * option_str_get(const struct option *poption)
Returns the current value of this string option.
Definition: options.cpp:553
QStringList get_gui_specific_themes_directories(int *count)
Each gui has its own themes directories.
Definition: themes.cpp:197
Q_GLOBAL_STATIC(QVector< QString >, future_name_translation)
The base class for options.
Definition: options.cpp:209
QStringList themes
void theme_reread_callback(struct option *poption)
Wrapper for load_theme.
struct theme_directory * directories
bool load_theme(const QString &theme_name)
Loads a theme with the given name.
static int num_directories
const QVector< QString > * get_themes_list(const struct option *poption)
Return a static string vector of useable theme names.
void init_themes()
Initialized themes data.
QStringList get_useable_themes_in_directory(QString &directory)
Return an array of names of usable themes in the given directory.
Definition: themes.cpp:215
void gui_load_theme(const QString &directory, const QString &theme_name)
Loads a qt theme directory/theme_name.
Definition: themes.cpp:120