diff options
Diffstat (limited to 'src/themes')
-rw-r--r-- | src/themes/theme.vala | 46 |
1 files changed, 43 insertions, 3 deletions
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. ///////////////////////////////////////////////////////////////////// @@ -165,6 +196,15 @@ public class Theme : GLib.Object { } ///////////////////////////////////////////////////////////////////// + /// 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. ///////////////////////////////////////////////////////////////////// |