[ease] [general] Get the data file path from Autotools, not GLib
- From: Nate Stedman <natesm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ease] [general] Get the data file path from Autotools, not GLib
- Date: Tue, 24 Aug 2010 06:50:49 +0000 (UTC)
commit f38e7004c92d01332138fc940b8454af659c410b
Author: Nate Stedman <natesm gmail com>
Date: Tue Aug 24 02:47:38 2010 -0400
[general] Get the data file path from Autotools, not GLib
GLib's data paths are always the system paths, so this won't work
if the user specified a prefix that doesn't fall into one of those.
Should fix bug 627729.
https://bugzilla.gnome.org/show_bug.cgi?id=627729
ease-core/Makefile.am | 1 +
ease-core/ease-utilities.vala | 87 ++++++++++++++++++++++++++++++++++++-----
ease/Makefile.am | 1 +
ease/ease-welcome-window.vala | 56 +++++++++++++++++---------
4 files changed, 116 insertions(+), 29 deletions(-)
---
diff --git a/ease-core/Makefile.am b/ease-core/Makefile.am
index 42f5230..177fb1f 100644
--- a/ease-core/Makefile.am
+++ b/ease-core/Makefile.am
@@ -82,6 +82,7 @@ libease_core_ EASE_CORE_VERSION@_la_LIBADD = \
libease_core_ EASE_CORE_VERSION@_la_CFLAGS = \
$(EASE_CFLAGS) \
-w \
+ -DEASE_DATA_DIR=\"$(datadir)\" \
-include $(top_srcdir)/config.h \
-I$(top_srcdir)/flutter \
$(NULL)
diff --git a/ease-core/ease-utilities.vala b/ease-core/ease-utilities.vala
index 183cd47..11e5ae1 100644
--- a/ease-core/ease-utilities.vala
+++ b/ease-core/ease-utilities.vala
@@ -28,6 +28,18 @@ namespace Ease
private const string SYS_DATA = "ease";
/**
+ * The autotools-determined data path.
+ */
+ private extern const string DATA_DIR;
+
+ private string[] get_data_dirs()
+ {
+ return { LOCAL_DATA,
+ Path.build_filename(DATA_DIR, SYS_DATA) };
+ }
+
+
+ /**
* Display a simple error message.
*
* @param title The title of the dialog.
@@ -53,14 +65,9 @@ namespace Ease
*/
public string? data_path(string path)
{
- 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)
+ foreach (string dir in get_data_dirs())
{
- var sys_file = query_file(Path.build_filename(dir, SYS_DATA), path);
+ var sys_file = query_file(dir, path);
if (sys_file != null) return sys_file;
}
@@ -80,11 +87,71 @@ namespace Ease
var filename = Path.build_filename(dir, path);
var file = File.new_for_path(filename);
- if (file.query_exists(null))
+ return file.query_exists(null) ? filename : null;
+ }
+
+ /**
+ * Returns a list containing every directory in the data directories.
+ */
+ public Gee.LinkedList<string> data_contents()
+ {
+ var list = new Gee.LinkedList<string>();
+
+ foreach (var dir in get_data_dirs())
{
- return filename;
+ // don't open nonexistent directories
+ var test = File.new_for_path(dir);
+ if (!test.query_exists(null)) continue;
+
+ var directory = GLib.Dir.open(dir, 0);
+ string name = directory.read_name();
+ while (name != null)
+ {
+ list.add(Path.build_filename(dir, name));
+ name = directory.read_name();
+ }
}
- return null;
+
+ return list;
+ }
+
+ /**
+ * Returns a list containing all contents of folders in the data directory
+ * with the specified name.
+ */
+ public Gee.LinkedList<string> data_contents_folder(string folder)
+ {
+ var list = new Gee.LinkedList<string>();
+
+ foreach (var dir in get_data_dirs())
+ {
+ // don't open nonexistent directories
+ var test = File.new_for_path(dir);
+ if (!test.query_exists(null)) continue;
+
+ var directory = Dir.open(dir, 0);
+ string name = directory.read_name();
+ while (name != null)
+ {
+ if (name == folder)
+ {
+ // don't open nonexistent directories
+ test = File.new_for_path(Path.build_filename(dir, name));
+ if (!test.query_exists(null)) continue;
+
+ var child = Dir.open(Path.build_filename(dir, name), 0);
+ string child_name = child.read_name();
+ while (child_name != null)
+ {
+ list.add(Path.build_filename(dir, folder, child_name));
+ child_name = child.read_name();
+ }
+ }
+ name = directory.read_name();
+ }
+ }
+
+ return list;
}
/**
diff --git a/ease/Makefile.am b/ease/Makefile.am
index db77d73..d57a9ac 100644
--- a/ease/Makefile.am
+++ b/ease/Makefile.am
@@ -42,6 +42,7 @@ ease_VALAFLAGS = \
ease_CFLAGS = \
$(EASE_CFLAGS) \
-w \
+ -DEASE_DATA_DIR=\"$(datadir)\" \
-I$(top_srcdir)/ease-core \
-I$(top_srcdir)/flutter \
-include $(top_srcdir)/config.h
diff --git a/ease/ease-welcome-window.vala b/ease/ease-welcome-window.vala
index 5e56400..2d070fd 100644
--- a/ease/ease-welcome-window.vala
+++ b/ease/ease-welcome-window.vala
@@ -186,26 +186,17 @@ internal class Ease.WelcomeWindow : Gtk.Window
preview_background = new Clutter.Rectangle.with_color (Clutter.Color.from_string ("black"));
preview_container.add_actor(preview_background);
- try {
- unowned string[] data_dirs = Environment.get_system_data_dirs ();
- foreach (string dir in data_dirs) {
- var filename = Path.build_filename (dir,
- Temp.TEMP_DIR,
- Temp.THEME_DIR);
- var file = File.new_for_path (filename);
-
- if (file.query_exists(null)) {
- var directory = GLib.Dir.open (filename, 0);
- string name = directory.read_name ();
- while (name != null) {
- var path = Path.build_filename (filename, name);
- themes.add (new Theme(path));
- name = directory.read_name ();
- }
- }
+ try
+ {
+ var list = locate_themes();
+ foreach (var path in list)
+ {
+ themes.add(new Theme(path));
}
- } catch (Error e) {
- error_dialog("Error loading themes : %s", e.message);
+ }
+ catch (Error e)
+ {
+ error_dialog("Error loading themes: %s", e.message);
}
// create the previews
@@ -415,4 +406,31 @@ internal class Ease.WelcomeWindow : Gtk.Window
preview_background.height = embed.height;
}
}
+
+ private extern const string DATA_DIR;
+ private Gee.LinkedList<string> locate_themes() throws GLib.Error
+ {
+ var list = new Gee.LinkedList<string>();
+ foreach (var item in data_contents_folder("themes"))
+ {
+ var f = File.new_for_path(Path.build_filename(item, "Theme.json"));
+ if (f.query_exists(null) && theme_not_redundant(item, list))
+ {
+ list.add(item);
+ }
+ }
+ return list;
+ }
+
+ // TODO: this isn't a very smart method. add versions to themes, check those
+ private bool theme_not_redundant(string item, Gee.List<string> list)
+ {
+ foreach (var str in list)
+ {
+ if (File.new_for_path(str).get_basename() ==
+ File.new_for_path(item).get_basename())
+ return false;
+ }
+ return true;
+ }
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]