Clone in a terminal:
Commit c8283b4
Johan Mattsson - 2013-07-15T10:49:31+00:00
c8283b429e515ab7a41872d4795984b1ce6315b7johan.mattsson.m@gmail.com

move all paths to SearchPath.vala

Changed files (4)

Diff

diff --git a/libbirdfont/BirdFont.vala b/libbirdfont/BirdFont.valaindex 50e13db..3778559 100644--- a/libbirdfont/BirdFont.vala+++ b/libbirdfont/BirdFont.vala@@ -269,51 +269,10 @@ public class BirdFont { 	}  	static void init_gettext () {-		File f;-+		string locale_directory = SearchPaths.get_locale_directory (); 		Intl.setlocale (LocaleCategory.MESSAGES, ""); 		Intl.bind_textdomain_codeset (GETTEXT_PACKAGE, "utf-8");--		f = File.new_for_path (BirdFont.exec_path + "/Contents/Resources/locale/sv/LC_MESSAGES/birdfont.mo");-		if (f.query_exists ()) {-			Intl.bindtextdomain (GETTEXT_PACKAGE, BirdFont.exec_path + "/Contents/Resources/locale");-			return;-		}-		-		f = File.new_for_path ("./build/locale/sv/LC_MESSAGES/birdfont.mo");-		if (f.query_exists ()) {-			Intl.bindtextdomain (GETTEXT_PACKAGE, "./build/locale");-			return;-		}--		f = File.new_for_path (".\\locale\\sv\\LC_MESSAGES\\birdfont.mo");-		if (f.query_exists ()) {-			Intl.bindtextdomain (GETTEXT_PACKAGE, ".\\locale");-			return;-		}--		f = File.new_for_path (PREFIX + "/share/locale/sv/LC_MESSAGES/birdfont.mo");-		if (f.query_exists ()) {-			Intl.bindtextdomain (GETTEXT_PACKAGE, PREFIX + "/share/locale");-			return;-		}-						-		f = File.new_for_path ("/usr/local/share/locale/sv/LC_MESSAGES/birdfont.mo");-		if (f.query_exists ()) {-			Intl.bindtextdomain (GETTEXT_PACKAGE, "/usr/local/share/locale");-			return;-		}		--		f = File.new_for_path ("/usr/share/locale/sv/LC_MESSAGES/birdfont.mo");-		if (f.query_exists ()) {-			Intl.bindtextdomain (GETTEXT_PACKAGE, "/usr/share/locale");-			return;-		}-		-		// FIXME: look the FontDisplay paths too, because it will be in -		// resources on Mac OS X-		-		warning ("translations not found");+		Intl.bindtextdomain (GETTEXT_PACKAGE, locale_directory); 	} 	 	public static Font get_current_font () {diff --git a/libbirdfont/CharDatabase.vala b/libbirdfont/CharDatabase.valaindex e2e6270..fd0a216 100644--- a/libbirdfont/CharDatabase.vala+++ b/libbirdfont/CharDatabase.vala@@ -206,31 +206,7 @@ class CharDatabase { 	} 	 	static File get_unicode_database () {-		File f;--		f = (!) File.new_for_path (PREFIX + "/share/unicode/NamesList.txt");-		if (f.query_exists ()) {-			return f;-		}--		f = (!) File.new_for_path (PREFIX + "/share/unicode/ucd/NamesList.txt");-		if (f.query_exists ()) {-			return f;-		}-		-		f = (!) File.new_for_path (".\\NamesList.txt");-		if (f.query_exists ()) {-			return f;-		}-			-		f = (!) File.new_for_path ("/usr/share/unicode/NamesList.txt");-		if (f.query_exists ()) {-			return f;-		}--		f = (!) File.new_for_path ("/usr/share/unicode/ucd/NamesList.txt");--		return f;+		return SearchPaths.get_char_database (); 	} } diff --git a/libbirdfont/FontDisplay.vala b/libbirdfont/FontDisplay.valaindex c30e387..5d50eab 100644--- a/libbirdfont/FontDisplay.vala+++ b/libbirdfont/FontDisplay.vala@@ -193,56 +193,7 @@ public abstract class FontDisplay : GLib.Object { 	}  	public static File find_file (string? dir, string name) {-		File f;-		string d = (dir == null) ? "" : (!) dir;--		f = get_file (BirdFont.exec_path + "/" + d + "/", name);-		if (likely (f.query_exists ())) return f;-		-		f = get_file (BirdFont.exec_path + "/", name + "/");-		if (likely (f.query_exists ())) return f;--		f = get_file (BirdFont.exec_path + "/Contents/Resources/", d + "/" + name);-		if (likely (f.query_exists ())) return f;--		f = get_file (BirdFont.exec_path + "/Contents/Resources/", name + "/");-		if (likely (f.query_exists ())) return f;-		-		f = get_file ("./" + d + "/", name);-		if (likely (f.query_exists ())) return f;		--		f = get_file ("../" + d + "/", name);-		if (likely (f.query_exists ())) return f;--		f = get_file (".\\" + d + "\\", name);-		if (likely (f.query_exists ())) return f;--		f = get_file ("", name);-		if (likely (f.query_exists ())) return f;--		f = get_file (d + "\\", name);-		if (likely (f.query_exists ())) return f;--		f = get_file (@"$PREFIX/share/birdfont/" + d + "/", name);-		if (likely (f.query_exists ())) return f;--		f = get_file ("/usr/local/share/birdfont/" + d + "/", name);-		if (likely (f.query_exists ())) return f;--		f = get_file ("/usr/share/birdfont/" + d + "/", name);-		if (likely (f.query_exists ())) return f;-				-		warning (@"Did not find file $name in $d");-			-		return f;		-	}--	public static File get_file (string? path, string name) {-		StringBuilder fn = new StringBuilder ();-		string p = (path == null) ? "" : (!) path;-		fn.append (p);-		fn.append ((!) name);-		return File.new_for_path (fn.str);+		return SearchPaths.find_file (dir, name);	 	} } diff --git a/libbirdfont/SearchPaths.vala b/libbirdfont/SearchPaths.valanew file mode 100644index 0000000..10c41cf--- /dev/null+++ b/libbirdfont/SearchPaths.vala@@ -0,0 +1,148 @@+/*+    Copyright (C) 2012 Johan Mattsson++    This library is free software; you can redistribute it and/or modify +    it under the terms of the GNU Lesser General Public License as +    published by the Free Software Foundation; either version 3 of the +    License, or (at your option) any later version.++    This library is distributed in the hope that it will be useful, but +    WITHOUT ANY WARRANTY; without even the implied warranty of +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +    Lesser General Public License for more details.+*/++namespace BirdFont {++/** Look for files in default folders on different operating systems. */+public class SearchPaths {+	+	public static File find_file (string? dir, string name) {+		File f;+		string d = (dir == null) ? "" : (!) dir;++		f = get_file (BirdFont.exec_path + "/" + d + "/", name);+		if (likely (f.query_exists ())) return f;+		+		f = get_file (BirdFont.exec_path + "/", name + "/");+		if (likely (f.query_exists ())) return f;++		f = get_file (BirdFont.exec_path + "/Contents/Resources/", d + "/" + name);+		if (likely (f.query_exists ())) return f;++		f = get_file (BirdFont.exec_path + "/Contents/Resources/", name + "/");+		if (likely (f.query_exists ())) return f;+		+		f = get_file ("./" + d + "/", name);+		if (likely (f.query_exists ())) return f;		++		f = get_file ("../" + d + "/", name);+		if (likely (f.query_exists ())) return f;++		f = get_file (".\\" + d + "\\", name);+		if (likely (f.query_exists ())) return f;++		f = get_file ("", name);+		if (likely (f.query_exists ())) return f;++		f = get_file (d + "\\", name);+		if (likely (f.query_exists ())) return f;++		f = get_file (@"$PREFIX/share/birdfont/" + d + "/", name);+		if (likely (f.query_exists ())) return f;++		f = get_file ("/usr/share/birdfont/" + d + "/", name);+		if (likely (f.query_exists ())) return f;+				+		warning (@"Did not find file $name in $d");+			+		return f;		+	}+		+	public static string get_locale_directory () {+		string f = "";+		+		f = BirdFont.exec_path + "/Contents/Resources/locale/sv/LC_MESSAGES/birdfont.mo";+		if (exists (f)) {+			return BirdFont.exec_path + "/Contents/Resources/locale";+		}+		+		f = "./build/locale/sv/LC_MESSAGES/birdfont.mo";+		if (exists (f)) {+			return  "./build/locale";+		}++		f = ".\\locale\\sv\\LC_MESSAGES\\birdfont.mo";+		if (exists (f)) {+			return ".\\locale";+		}++		f = PREFIX + "/share/locale/sv/LC_MESSAGES/birdfont.mo";+		if (exists (f)) {+			return f;+		}++		f = "/usr/share/locale/sv/LC_MESSAGES/birdfont.mo";+		if (exists (f)) {+			return "/usr/share/locale";+		}+		+		f = BirdFont.exec_path + "/Contents/Resources/locale";+		if (exists (f)) {+			return BirdFont.exec_path + "/Contents/Resources/locale";+		}+		+		warning ("translations not found");+		return "/usr/share/locale";+	}+++	public static File get_char_database () {+		File f;+		+		f = (!) File.new_for_path (PREFIX + "/share/unicode/NamesList.txt");+		if (f.query_exists ()) {+			return f;+		}++		f = (!) File.new_for_path (PREFIX + "/share/unicode/ucd/NamesList.txt");+		if (f.query_exists ()) {+			return f;+		}+		+		f = (!) File.new_for_path (".\\NamesList.txt");+		if (f.query_exists ()) {+			return f;+		}+			+		f = (!) File.new_for_path ("/usr/share/unicode/NamesList.txt");+		if (f.query_exists ()) {+			return f;+		}++		f = (!) File.new_for_path (BirdFont.exec_path + "/Contents/Resources/NamesList.txt");+		if (f.query_exists ()) {+			return f;+		}+		+		f = (!) File.new_for_path ("/usr/share/unicode/ucd/NamesList.txt");+		warning ("ucd not found");+		+		return f;+	}+		+	static File get_file (string? path, string name) {+		StringBuilder fn = new StringBuilder ();+		string p = (path == null) ? "" : (!) path;+		fn.append (p);+		fn.append ((!) name);+		return File.new_for_path (fn.str);+	}+	+	static bool exists (string file) {+		File f = File.new_for_path (file);+		return f.query_exists ();+	}+}++}

Contact

Email: johan.mattsson.m@gmail.com
Mastodon: typo.social/@birdfont
GitHub: johanmattssonm
LinkedIn: johan-mattsson-2ab324112