[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    branches/work/kde4/playground/games/kombination/src
From:       Pino Toscano <toscano.pino () tiscali ! it>
Date:       2005-11-11 19:24:31
Message-ID: 1131737071.358323.18494.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 479789 by pino:

improve the algorithm for searching the right tileset for the current game
language


 M  +18 -3     tilefactory.cpp  


--- branches/work/kde4/playground/games/kombination/src/tilefactory.cpp #479788:479789
@@ -11,6 +11,7 @@
 #include <QFile>
 #include <QStringList>
 
+#include <klocale.h>
 #include <kstandarddirs.h>
 
 #include "tile.h"
@@ -21,11 +22,25 @@
 	QList<tile> tiles;
 	
 	// look for the tileset of the specified language
-	QString basepath("tiles/%1.xml");
+	static QString basepath("tiles/%1.xml");
 	QString path = locate("appdata", basepath.arg(langcode));
 	if (path.isEmpty())
-		// not found, falling back on english tiles
-		path = locate("appdata", basepath.arg("en"));
+	{
+		// not found, so search better (if we can)
+		QString language;
+		QString country;
+		QString charset;
+		KLocale::splitLocale(langcode, language, country, charset);
+		if (!country.isEmpty())
+			// if we are here, then we have a language like en_GB,
+			// and we have no tileset for that language. so, strip
+			// the country part and look for the "base" language
+			path = locate("appdata", basepath.arg(language));
+		if (path.isEmpty())
+			// all the attempts above failed, so the last hope for
+			// us is to use the english tiles
+			path = locate("appdata", basepath.arg("en"));
+	}
 	QFile file(path);
 	if (!file.open(QIODevice::ReadOnly)) return tiles;
 	QDomDocument doc("tiles");
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic