The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
language_selection.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2016 by Mark de Wever <[email protected]>
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #define GETTEXT_DOMAIN "wesnoth-lib"
16 
18 
20 #ifdef GUI2_EXPERIMENTAL_LISTBOX
21 #include "gui/widgets/list.hpp"
22 #else
23 #include "gui/widgets/listbox.hpp"
24 #endif
25 #include "gui/widgets/settings.hpp"
26 #include "gui/widgets/window.hpp"
27 #include "language.hpp"
28 #include "preferences.hpp"
29 
30 namespace gui2
31 {
32 
33 /*WIKI
34  * @page = GUIWindowDefinitionWML
35  * @order = 2_language_selection
36  *
37  * == Language selection ==
38  *
39  * This shows the dialog to select the language to use. When the dialog is
40  * closed with the OK button it also updates the selected language in the
41  * preferences.
42  *
43  * @begin{table}{dialog_widgets}
44  *
45  * language_list & & listbox & m &
46  * This listbox contains the list with available languages. $
47  *
48  * - & & control & o &
49  * Show the name of the language in the current row. $
50  *
51  * @end{table}
52  */
53 
54 /**
55  * @todo show we also reset the translations and is the tips of day call
56  * really needed?
57  */
58 
59 REGISTER_DIALOG(language_selection)
60 
61 void tlanguage_selection::pre_show(twindow& window)
62 {
63  tlistbox& list = find_widget<tlistbox>(&window, "language_list", false);
64  window.keyboard_capture(&list);
65 
66  const std::vector<language_def>& languages = get_languages();
67  const language_def& current_language = get_language();
68  for(const auto & lang : languages)
69  {
70  string_map item;
71  item.insert(std::make_pair("label", lang.language));
72 
73  list.add_row(item);
74  if(lang == current_language) {
75  list.select_row(list.get_item_count() - 1);
76  }
77  }
78 }
79 
81 {
82  if(get_retval() == twindow::OK) {
83  const int res = find_widget<tlistbox>(&window, "language_list", false)
84  .get_selected_row();
85 
86  assert(res != -1);
87 
88  const std::vector<language_def>& languages = get_languages();
89  ::set_language(languages[res]);
90  preferences::set_language(languages[res].localename);
91  }
92 }
93 
94 } // namespace gui2
GLvoid **typedef void(GLAPIENTRY *PFNGLGETVERTEXATTRIBDVPROC)(GLuint
Definition: glew.h:1806
int get_retval() const
Definition: dialog.hpp:161
This file contains the window object, this object is a top level container which has the event manage...
bool select_row(const unsigned row, const bool select=true)
Selectes a row.
Definition: listbox.cpp:228
REGISTER_DIALOG(label_settings)
void post_show(twindow &window)
Inherited from tdialog.
void set_language(const std::string &slocale, const std::vector< std::string > *alternates)
Definition: gettext.cpp:126
base class of top level items, the only item which needs to store the final canvases to draw on ...
Definition: window.hpp:62
A class inherited from ttext_box that displays its input as stars.
Definition: field-fwd.hpp:23
Dialog is closed with ok button.
Definition: window.hpp:125
This file contains the settings handling of the widget library.
unsigned get_item_count() const
Returns the number of items in the listbox.
Definition: listbox.cpp:138
void add_row(const string_map &item, const int index=-1)
When an item in the list is selected by the user we need to update the state.
Definition: listbox.cpp:74
std::map< std::string, t_string > string_map
Definition: generator.hpp:23
GLuint res
Definition: glew.h:9258
const language_def & get_language()
Definition: language.cpp:251
The listbox class.
Definition: listbox.hpp:39
language_list get_languages()
Definition: language.cpp:118
void set_language(const std::string &s)