00001 /* $Id: language_selection.cpp 26796 2008-05-23 17:33:21Z mordante $ */ 00002 /* 00003 copyright (C) 2008 by mark de wever <koraq@xs4all.nl> 00004 part of the battle for wesnoth project http://www.wesnoth.org/ 00005 00006 this program is free software; you can redistribute it and/or modify 00007 it under the terms of the gnu general public license version 2 00008 or at your option any later version. 00009 this program is distributed in the hope that it will be useful, 00010 but without any warranty. 00011 00012 see the copying file for more details. 00013 */ 00014 00015 #include "gui/dialogs/language_selection.hpp" 00016 00017 #include "foreach.hpp" 00018 #include "gui/widgets/button.hpp" 00019 #include "gui/widgets/listbox.hpp" 00020 #include "gui/widgets/settings.hpp" 00021 #include "gui/widgets/window.hpp" 00022 #include "gui/widgets/window_builder.hpp" 00023 #include "language.hpp" 00024 #include "log.hpp" 00025 #include "preferences.hpp" 00026 #include "video.hpp" 00027 #include "wml_exception.hpp" 00028 00029 #define DBG_GUI LOG_STREAM_INDENT(debug, widget) 00030 #define LOG_GUI LOG_STREAM_INDENT(info, widget) 00031 #define WRN_GUI LOG_STREAM_INDENT(warn, widget) 00032 #define ERR_GUI LOG_STREAM_INDENT(err, widget) 00033 00034 namespace gui2 { 00035 00036 void tlanguage_selection::show(CVideo& video) 00037 { 00038 gui2::init(); 00039 00040 twindow window = build(video, get_id(LANGUAGE_SELECTION)); 00041 00042 tlistbox* list = dynamic_cast<tlistbox*>(window.find_widget("language_list", false)); 00043 VALIDATE(list, "No list defined."); 00044 00045 const std::vector<language_def>& languages = get_languages(); 00046 const language_def& current_language = get_language(); 00047 foreach(const language_def& lang, languages) { 00048 00049 list->add_item(lang.language); 00050 if(lang == current_language) { 00051 list->select_row(list->get_item_count() - 1); 00052 } 00053 00054 list->set_row_active(list->get_item_count() - 1, lang.available()); 00055 } 00056 00057 window.recalculate_size(); 00058 00059 retval_ = window.show(true); 00060 00061 if(retval_ == tbutton::OK) { 00062 const unsigned res = list->get_selected_row(); 00063 00064 ::set_language(languages[res]); 00065 preferences::set_language(languages[res].localename); 00066 } 00067 } 00068 00069 00070 } // namespace gui2
Generated by doxygen 1.5.5 on 23 May 2008 for The Battle for Wesnoth | Gna! | Forum | Wiki | CIA | devdocs |