From 7556967bf57453d412a8f18633599f38806f8620 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Sun, 4 Oct 2015 13:00:51 +0200 Subject: Imported Upstream version 0.6.7 --- src/themes/theme.vala | 46 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 3 deletions(-) (limited to 'src/themes/theme.vala') diff --git a/src/themes/theme.vala b/src/themes/theme.vala index 98e8994..2e256f9 100644 --- a/src/themes/theme.vala +++ b/src/themes/theme.vala @@ -87,14 +87,44 @@ public class Theme : GLib.Object { this.active_slice_layers.clear(); this.inactive_slice_layers.clear(); + if (!GLib.File.new_for_path(this.directory).query_exists()) { + return false; + } + + string config_file = this.directory + "/theme.xml"; + + if (!GLib.File.new_for_path(config_file).query_exists()) { + try { + // detect whether theme is one directory deeper + string child; + bool success = false; + + // load global themes + var d = Dir.open(this.directory); + while ((child = d.read_name()) != null && !success) { + config_file = this.directory + "/" + child + "/theme.xml"; + if (GLib.File.new_for_path(config_file).query_exists()) { + this.directory = this.directory + "/" + child; + success = true; + } + } + + if (!success) { + return false; + } + } catch (Error e) { + warning (e.message); + return false; + } + } + this.preview_icon = new Icon(this.directory + "/preview.png", 36); Xml.Parser.init(); - string path = this.directory + "/theme.xml"; - Xml.Doc* themeXML = Xml.Parser.parse_file(path); + Xml.Doc* themeXML = Xml.Parser.parse_file(config_file); if (themeXML == null) { - warning("Failed to add theme: \"" + path + "\" not found!"); + warning("Failed to add theme: \"" + config_file + "\" not found!"); return false; } @@ -151,6 +181,7 @@ public class Theme : GLib.Object { } } + ///////////////////////////////////////////////////////////////////// /// Loads all images of the theme. ///////////////////////////////////////////////////////////////////// @@ -164,6 +195,15 @@ public class Theme : GLib.Object { layer.load_image(); } + ///////////////////////////////////////////////////////////////////// + /// Returns true if the theme is installed to the local themes + /// directory. + ///////////////////////////////////////////////////////////////////// + + public bool is_local() { + return this.directory.has_prefix(Paths.local_themes); + } + ///////////////////////////////////////////////////////////////////// /// The following methods parse specific parts of the theme file. /// Nothing special here, just some boring code. -- cgit v1.2.3