/* template.vala * * Copyright (C) 2008 Nicolas Joseph * * 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. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * Author: * Nicolas Joseph */ public class Valide.Template : GLib.Object { /** * @todo Change URI */ private MarkupDomNode xml; private GLib.SList _files; private string name_; private string desc_; private Gdk.Pixbuf icon_; private const string directory = "./data/template/"; public string filename { set { /** * @bug[valac] Undeclared inner_error in C source. */ GLib.Error inner_error = null; this.xml = MarkupDom.load (value); if (this.xml != null) { MarkupDomNode tmp = this.xml.get_element_by_name ("file"); while (tmp != null) { this._files.append (tmp.content); tmp = tmp.next; } tmp = this.xml.get_element_by_name ("name"); if (tmp != null) { this.name_ = tmp.content; } tmp = this.xml.get_element_by_name ("description"); if (tmp != null) { this.desc_ = tmp.content; } this.icon_ = new Gdk.Pixbuf.from_file (GLib.Path.get_dirname (value) + "/icon.png"); } } } public Gdk.Pixbuf icon { get { return this.icon_; } } public string name { get { return this.name_; } } public string desc { get { return this.desc_; } } public GLib.SList files { get { return this._files; } } public Template (string! filename) { this.filename = filename; } public static GLib.List get_list () { string filename = null; GLib.List list = new GLib.List (); try { GLib.Dir dir = GLib.Dir.open (Template.directory); while ((filename = dir.read_name ()) != null) { string file = Template.directory + filename + "/template.xml"; if (GLib.FileUtils.test (file, GLib.FileTest.EXISTS)) { list.append (file); } } list.first (); } catch (GLib.Error e) { GLib.critical (e.message); } return list; } }