[ease/builder] Fixed hack for loading ui files locally.



commit 86d56d201af45fb1a598b085349e11cc12b1e70c
Author: Nate Stedman <natesm gmail com>
Date:   Fri Jul 16 01:46:18 2010 -0400

    Fixed hack for loading ui files locally.
    
    - Also fixes _all_ data loading locally
    - Favors local data (as it is more likely to be up to date)

 src/ease-editor-window.vala  |    3 +-
 src/ease-handle.vala         |   12 ++--------
 src/ease-utilities.vala      |   45 ++++++++++++++++++++++++++++++++++-------
 src/ease-welcome-window.vala |    7 +-----
 4 files changed, 42 insertions(+), 25 deletions(-)
---
diff --git a/src/ease-editor-window.vala b/src/ease-editor-window.vala
index 0289d12..930a013 100644
--- a/src/ease-editor-window.vala
+++ b/src/ease-editor-window.vala
@@ -123,8 +123,7 @@ public class Ease.EditorWindow : Gtk.Window
 		var builder = new Gtk.Builder();
 		try
 		{
-			builder.add_from_file(data_path(Path.build_filename(Temp.TEMP_DIR,
-				                                                Temp.UI_DIR,
+			builder.add_from_file(data_path(Path.build_filename(Temp.UI_DIR,
 				                                                UI_FILE_PATH)));
 		}
 		catch (Error e) { error("Error loading UI: %s", e.message); }
diff --git a/src/ease-handle.vala b/src/ease-handle.vala
index 4f1e8cb..9b6efcd 100644
--- a/src/ease-handle.vala
+++ b/src/ease-handle.vala
@@ -53,9 +53,7 @@ public class Ease.Handle : Clutter.Texture
 		position = pos;
 
 		// load the handle texture
-		filename = data_path(Path.build_filename(Temp.TEMP_DIR,
-		                                         Temp.IMG_DIR,
-		                                         W_PATH));
+		filename = data_path(Path.build_filename(Temp.IMG_DIR, W_PATH));
 
 		// set the handle's anchor
 		set_anchor_point(width / 2, height / 2);
@@ -231,15 +229,11 @@ public class Ease.Handle : Clutter.Texture
 	{
 		if (flipped)
 		{
-			filename = data_path(Path.build_filename(Temp.TEMP_DIR,
-	                                                 Temp.IMG_DIR,
-	                                                 W_PATH));
+			filename = data_path(Path.build_filename(Temp.IMG_DIR, W_PATH));
 		}
 		else
 		{
-			filename = data_path(Path.build_filename(Temp.TEMP_DIR,
-	                                                 Temp.IMG_DIR,
-	                                                 B_PATH));
+			filename = data_path(Path.build_filename(Temp.IMG_DIR, B_PATH));
 		}
 		
 		flipped = !flipped;
diff --git a/src/ease-utilities.vala b/src/ease-utilities.vala
index 3965390..241b88d 100644
--- a/src/ease-utilities.vala
+++ b/src/ease-utilities.vala
@@ -18,6 +18,16 @@
 namespace Ease
 {
 	/**
+	 * The local data path.
+	 */
+	private const string LOCAL_DATA = "data";
+	
+	/**
+	 * The installed data path.
+	 */
+	private const string SYS_DATA = "ease";
+	
+	/**
 	 * Display a simple error message.
 	 *
 	 * @param title The title of the dialog.
@@ -43,20 +53,39 @@ namespace Ease
 	 */
 	public string? data_path(string path)
 	{
-		string[] data_dirs = Environment.get_system_data_dirs();
+		string file;
+		file = query_file(LOCAL_DATA, path);
+		if (file != null) return file;
+		
+		var data_dirs = Environment.get_system_data_dirs();
 		foreach (string dir in data_dirs)
 		{
-			var filename = Path.build_filename(dir, path);
-			var file = File.new_for_path(filename);
-			
-			if (file.query_exists(null))
-			{
-				return filename;
-			}
+			var sys_file = query_file(Path.build_filename(SYS_DATA, dir), path);
+			if (sys_file != null) return sys_file;
 		}
 		
 		return null;
 	}
+	
+	/**
+	 * Queries the given folder for the file, returning it if it is found.
+	 *
+	 * Otherwise, the function returns null.
+	 *
+	 * @param dir The base directory.
+	 * @param path The path to search for.
+	 */
+	private string? query_file(string dir, string path)
+	{
+		var filename = Path.build_filename(dir, path);
+		var file = File.new_for_path(filename);
+		
+		if (file.query_exists(null))
+		{
+			return filename;
+		}
+		return null;
+	}
 
 	public double dmax(double a, double b)
 	{
diff --git a/src/ease-welcome-window.vala b/src/ease-welcome-window.vala
index f651f96..9e55871 100644
--- a/src/ease-welcome-window.vala
+++ b/src/ease-welcome-window.vala
@@ -91,13 +91,8 @@ public class Ease.WelcomeWindow : Gtk.Window
 		
 		var builder = new Gtk.Builder ();
 		try {
-			// FIXME : it's ugly.
-			string ui_path = data_path(Path.build_filename(Temp.TEMP_DIR,
-														   Temp.UI_DIR,
+			string ui_path = data_path(Path.build_filename(Temp.UI_DIR,
 														   "welcome-window.ui"));
-			if (ui_path == null)
-				ui_path = "data/ui/welcome-window.ui";
-
 			builder.add_from_file (ui_path);
 		} catch (Error e) {
 			error ("Unable to load UI : %s", e.message);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]