public class AppSettings : Object { // what are we going to have as settings? public string roo_html_dir { get; set; } public AppSettings() { this.notify.connect(() => { this.save(); }); } public static AppSettings factory() { var setting_file = BuilderApplication.configDirectory() + "/builder.settings"; if (!FileUtils.test(setting_file, FileTest.EXISTS)) { return new AppSettings(); } string data; FileUtils.get_contents(setting_file, out data); return Json.gobject_from_data (typeof (AppSettings), data) as AppSettings; } public void save() { var dirname = GLib.Environment.get_home_dir() + "/.Builder"; var setting_file = dirname + "/builder.settings"; string data = Json.gobject_to_data (this, null); print("saving application settings\n"); FileUtils.set_contents(setting_file, data); } } public static BuilderApplication application = null; public class BuilderApplication : Gtk.Application { // options - used when builder is run as a compiler // we have to spawn ourself as a compiler as just running libvala // as a task to check syntax causes memory leakage.. // const OptionEntry[] options = { { "project", 0, 0, OptionArg.STRING, ref opt_compile_project, "Compile a project", null }, { "target", 0, 0, OptionArg.STRING, ref opt_compile_target, "Target to build", null }, { "skip-file", 0, 0, OptionArg.STRING, ref opt_compile_skip ,"For test compiles do not add this (usually used in conjunction with add-file ", null }, { "add-file", 0, 0, OptionArg.STRING, ref opt_compile_add, "Add this file to compile list", null }, { "output", 0, 0, OptionArg.STRING, ref opt_compile_output, "output binary file path", null }, { "debug", 0, 0, OptionArg.NONE, ref opt_debug, "Show debug messages", null }, // some testing code. { "list-projects", 0, 0, OptionArg.NONE, ref opt_list_projects, "List Projects", null }, { "list-files", 0, 0, OptionArg.NONE, ref opt_list_files, "List Files (in a project", null}, { "bjs", 0, 0, OptionArg.STRING, ref opt_bjs_compile, "convert bjs file", null }, { "bjs-target", 0, 0, OptionArg.STRING, ref opt_bjs_compile_target, "convert bjs file to tareet : vala / js", null }, { null } }; public static string opt_compile_project; public static string opt_compile_target; public static string opt_compile_skip; public static string opt_compile_add; public static string opt_compile_output; public static string opt_bjs_compile; public static string opt_bjs_compile_target; public static bool opt_debug = false; public static bool opt_list_projects = false; public static bool opt_list_files = false; public static string _self; enum Target { INT32, STRING, ROOTWIN } public const Gtk.TargetEntry[] targetList = { { "INTEGER", 0, Target.INT32 }, { "STRING", 0, Target.STRING }, { "application/json", 0, Target.STRING }, { "text/plain", 0, Target.STRING }, { "application/x-rootwindow-drop", 0, Target.ROOTWIN } }; public AppSettings settings = null; public BuilderApplication ( string[] args) { _self = FileUtils.read_link("/proc/self/exe"); GLib.debug("SELF = %s", _self); Object( application_id: "org.roojs.app-builder", flags: ApplicationFlags.FLAGS_NONE ); configDirectory(); this.settings = AppSettings.factory(); var opt_context = new OptionContext ("Application Builder"); try { opt_context.set_help_enabled (true); opt_context.add_main_entries (options, null); opt_context.parse (ref args); } catch (OptionError e) { stdout.printf ("error: %s\n", e.message); stdout.printf ("Run '%s --help' to see a full list of available command line options.\n %s", args[0], opt_context.get_help(true,null)); GLib.Process.exit(Posix.EXIT_FAILURE); } } public static BuilderApplication singleton( string[] args) { if (application==null) { application = new BuilderApplication( args); } return application; } public static string configDirectory() { var dirname = GLib.Environment.get_home_dir() + "/.Builder"; if (!FileUtils.test(dirname,FileTest.IS_DIR)) { var dir = File.new_for_path(dirname); dir.make_directory(); } if (!FileUtils.test(dirname + "/resources",FileTest.IS_DIR)) { var dir = File.new_for_path(dirname + "/resources"); dir.make_directory(); } return dirname; } }