Author: mordante
Date: Sun May 18 11:34:19 2008
New Revision: 26686

URL: http://svn.gna.org/viewcvs/wesnoth?rev=26686&view=rev
Log:
Added a new experimental feature in the new widget library. This feature
disables languages not available on the system. It has only been tested on Linux
and it can use more testing on other platforms. (bug #11212)

Modified:
    trunk/RELEASE_NOTES
    trunk/changelog
    trunk/src/gui/dialogs/language_selection.cpp
    trunk/src/language.cpp
    trunk/src/language.hpp

Modified: trunk/RELEASE_NOTES
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/RELEASE_NOTES?rev=26686&r1=26685&r2=26686&view=diff
==============================================================================
--- trunk/RELEASE_NOTES (original)
+++ trunk/RELEASE_NOTES Sun May 18 11:34:19 2008
@@ -10,3 +10,8 @@
 
 The release team should empty this file after each release.
 
+
+There is a new experimental function to gray out not available languages in the
+language selection dialog. This feature is available when Wesnoth is started
+with the --new-widgets parameter. Packagers of various platforms are encouraged
+to test this feature and report bugs when found. 

Modified: trunk/changelog
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/changelog?rev=26686&r1=26685&r2=26686&view=diff
==============================================================================
--- trunk/changelog (original)
+++ trunk/changelog Sun May 18 11:34:19 2008
@@ -17,10 +17,14 @@
  * graphics:
    * new ford graphics from Syntax_Error
    * added a sea serpent portrait by Pic
+   * various improvements to the new widget library
  * language and i18n:
    * new translations: Friulian, Macedonian
    * updated translations: Chinese, Czech, Danish, Finnish, French, German, 
Italian,
      Polish, Russian, Slovak, Spanish, Turkish
+   * the new widget library supports disabling of rows in a listbox, this is
+     used to deactivate not available languages. This feature is experimental
+     and only available when started with --new-widgets (bug #11212)
  * multiplayer:
    * revised maps: Den of Onis
  * Python AI:

Modified: trunk/src/gui/dialogs/language_selection.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/dialogs/language_selection.cpp?rev=26686&r1=26685&r2=26686&view=diff
==============================================================================
--- trunk/src/gui/dialogs/language_selection.cpp (original)
+++ trunk/src/gui/dialogs/language_selection.cpp Sun May 18 11:34:19 2008
@@ -51,6 +51,8 @@
                        std::cerr << "select row " << list->get_item_count() - 
1 << ".\n";
                        list->select_row(list->get_item_count() - 1);
                }
+
+               list->set_row_active(list->get_item_count() - 1, 
lang.available());
        }
 
        window.recalculate_size();

Modified: trunk/src/language.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/language.cpp?rev=26686&r1=26685&r2=26686&view=diff
==============================================================================
--- trunk/src/language.cpp (original)
+++ trunk/src/language.cpp Sun May 18 11:34:19 2008
@@ -17,6 +17,7 @@
 
 #include "config.hpp"
 #include "filesystem.hpp"
+#include "foreach.hpp"
 #include "game_config.hpp"
 #include "gettext.hpp"
 #include "language.hpp"
@@ -35,6 +36,41 @@
 #include <cstdlib>
 #include <cstring>
 #include <iostream>
+#include <stdexcept>
+
+/** Tests one locale to be available. */
+static bool has_locale(const char* s) {
+       try {
+               // The way to find out whether a locale is available is to set 
it and
+               // hope not runtime error gets thrown.
+               std::locale dummy(s);
+               std::cerr << "Locale : " << s << " found.\n";
+               return true;
+       } catch (std::runtime_error&) {
+               std::cerr << "Locale : " << s << " not found.\n";
+               return false;
+       }
+}              
+
+/** Test the locale for a language and it's utf-8 variations. */
+static bool has_language(const std::string& language)
+{
+       if(has_locale(language.c_str())) {
+               return true;
+       }
+
+       std::string utf = language + ".utf-8";
+       if(has_locale(utf.c_str())) {
+               return true;
+       }
+
+       utf = language + ".UTF-8";
+       if(has_locale(utf.c_str())) {
+               return true;
+       }
+       
+       return false;
+}
 
 namespace {
        language_def current_language;
@@ -56,6 +92,25 @@
 bool language_def::operator== (const language_def& a) const
 {
        return ((language == a.language) /* && (localename == a.localename) */ 
);
+}
+
+bool language_def::available() const
+{
+#ifdef USE_DUMMYLOCALES
+       // Dummy has every language available.
+       return true;
+#else
+       if(has_language(localename)) {
+               return true;
+       } else {
+               foreach(const std::string& lang, alternates) {
+                       if(has_language(lang)) {
+                               return true;
+                       }
+               }
+       }
+       return false;
+#endif
 }
 
 symbol_table string_table;

Modified: trunk/src/language.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/language.hpp?rev=26686&r1=26685&r2=26686&view=diff
==============================================================================
--- trunk/src/language.hpp (original)
+++ trunk/src/language.hpp Sun May 18 11:34:19 2008
@@ -50,6 +50,13 @@
        t_string language;
        bool rtl;               // A right to left language? (e.g: Hebrew)
        bool operator== (const language_def&) const;
+       
+       /**
+        * Is the locale available on the system?
+        *
+        * If the dummy locales are selected we always return true.
+        */
+       bool available() const;
 };
 
 std::string languagedef_name (const language_def& def);


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to