ManaPlus
langlistmodel.h
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2009-2010 Andrei Karas
4  * Copyright (C) 2011-2017 The ManaPlus Developers
5  *
6  * This file is part of The ManaPlus Client.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 #ifndef GUI_MODELS_LANGLISTMODEL_H
23 #define GUI_MODELS_LANGLISTMODEL_H
24 
26 
28 
29 #include "utils/gettext.h"
30 
31 #include "localconsts.h"
32 
34 {
36 
37  std::string name;
38  std::string value;
39  std::string icon;
40 };
41 
42 const int langs_count = 22;
43 
44 const Language LANG_NAME[langs_count] =
45 {
46  // TRANSLATORS: language
47  {N_("(default)"), "", ""},
48  // TRANSLATORS: language
49  {N_("Catalan"), "ca_ES", "ca.png"},
50  // TRANSLATORS: language
51  {N_("Chinese (China)"), "zh_CN", "cn.png"},
52  // TRANSLATORS: language
53  {N_("Chinese (Hong Kong)"), "zh_HK", "hk.png"},
54  // TRANSLATORS: language
55  {N_("Czech"), "cs_CZ", "cz.png"},
56  // TRANSLATORS: language
57  {N_("Dutch (Belgium/Flemish)"), "nl_BE", "nl_BE.png"},
58  // TRANSLATORS: language
59  {N_("English"), "C", "en.png"},
60  // TRANSLATORS: language
61  {N_("Finnish"), "fi_FI", "fi.png"},
62  // TRANSLATORS: language
63  {N_("French"), "fr_FR", "fr.png"},
64  // TRANSLATORS: language
65  {N_("German"), "de_DE", "de.png"},
66  // TRANSLATORS: language
67  {N_("Indonesian"), "id_ID", "id.png"},
68  // TRANSLATORS: language
69  {N_("Italian"), "it_IT", "it.png"},
70  // TRANSLATORS: language
71  {N_("Japanese"), "ja_JP", "jp.png"},
72  // TRANSLATORS: language
73  {N_("Polish"), "pl_PL", "pl.png"},
74  // TRANSLATORS: language
75  {N_("Portuguese"), "pt_PT", "pt.png"},
76  // TRANSLATORS: language
77  {N_("Portuguese (Brazilian)"), "pt_BR", "pt_BR.png"},
78  // TRANSLATORS: language
79  {N_("Russian"), "ru_RU", "ru.png"},
80  // TRANSLATORS: language
81  {N_("Spanish (Castilian)"), "es_ES", "es.png"},
82  // TRANSLATORS: language
83  {N_("Swedish (Sweden)"), "sv_SE", "se.png"},
84  // TRANSLATORS: language
85  {N_("Turkish"), "tr_TR", "tr.png"},
86  // TRANSLATORS: language
87  {N_("Ukrainian"), "uk_UA", "ua.png"},
88  // TRANSLATORS: language
89  {N_("Esperanto"), "eo", "eo.png"}
90 };
91 
93 {
94  public:
96  {
97  for (int f = 0; f < langs_count; f ++)
98  {
99  const std::string icon = LANG_NAME[f].icon;
100  if (!icon.empty())
101  {
102  mIcons[f] = Loader::getImage("graphics/flags/"
103  + icon);
104  }
105  else
106  {
107  mIcons[f] = nullptr;
108  }
109  }
110  }
111 
113 
115  {
116  for (int f = 0; f < langs_count; f ++)
117  {
118  Image *const img = mIcons[f];
119  if (img != nullptr)
120  img->decRef();
121  }
122  }
123 
125  { return langs_count; }
126 
127  std::string getElementAt(int i) override final A_WARN_UNUSED
128  {
129  if (i >= getNumberOfElements() || i < 0)
130  return "???";
131 
132  return gettext(LANG_NAME[i].name.c_str());
133  }
134 
135  const Image *getImageAt(int i) override final A_WARN_UNUSED
136  {
137  if (i >= getNumberOfElements() || i < 0)
138  return nullptr;
139  return mIcons[i];
140  }
141 
143 };
144 
145 #endif // GUI_MODELS_LANGLISTMODEL_H
#define A_DELETE_COPY(func)
Definition: localconsts.h:52
#define A_NONNULLPOINTER
Definition: localconsts.h:294
#define N_(s)
Definition: gettext.h:35
#define A_WARN_UNUSED
Definition: localconsts.h:172
#define final
Definition: localconsts.h:45
std::string icon
Definition: langlistmodel.h:39
#define A_DEFAULT_COPY(func)
Definition: localconsts.h:40
Image * getImage(const std::string &idPath)
Definition: imageloader.cpp:85
int getNumberOfElements()
std::string getElementAt(int i)
std::map< int, std::string > mIcons
Definition: languagedb.cpp:35
const int langs_count
Definition: langlistmodel.h:42
const Image * getImageAt(int i)
std::string name
Definition: langlistmodel.h:37
Definition: image.h:61
#define override
Definition: localconsts.h:46
const Language LANG_NAME[langs_count]
Definition: langlistmodel.h:44
std::string value
Definition: langlistmodel.h:38
void decRef()
Definition: image.cpp:521