| 1 | /* settings.vala |
|---|
| 2 | * |
|---|
| 3 | * Copyright (C) 2009-2011 Matias De la Puente |
|---|
| 4 | * |
|---|
| 5 | * This program is free software: you can redistribute it and/or modify |
|---|
| 6 | * it under the terms of the GNU General Public License as published by |
|---|
| 7 | * the Free Software Foundation, either version 3 of the License, or |
|---|
| 8 | * (at your option) any later version. |
|---|
| 9 | * |
|---|
| 10 | * This program is distributed in the hope that it will be useful, |
|---|
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 13 | * GNU General Public License for more details. |
|---|
| 14 | * |
|---|
| 15 | * You should have received a copy of the GNU General Public License |
|---|
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
|---|
| 17 | * |
|---|
| 18 | * Author: |
|---|
| 19 | * Matias De la Puente <mfpuente.ar@gmail.com> |
|---|
| 20 | */ |
|---|
| 21 | using Gee; |
|---|
| 22 | |
|---|
| 23 | public class OptionSettings : GLib.Object |
|---|
| 24 | { |
|---|
| 25 | public string name { set; get; } |
|---|
| 26 | public string value { set; get; } |
|---|
| 27 | public bool active { set; get; } |
|---|
| 28 | |
|---|
| 29 | public string to_xml (size_t tab_width) |
|---|
| 30 | { |
|---|
| 31 | var prefix = string.nfill (tab_width, '\t'); |
|---|
| 32 | var xml_str = "<option_value name=\"%s\" value=\"%s\" active=\"%s\"/>\n"; |
|---|
| 33 | return prefix + xml_str.printf (_name, _value, _active.to_string ()); |
|---|
| 34 | } |
|---|
| 35 | } |
|---|
| 36 | |
|---|
| 37 | public class ProgrammerSettings : GLib.Object |
|---|
| 38 | { |
|---|
| 39 | private HashMap<string, OptionSettings> _options = new HashMap<string, OptionSettings> (); |
|---|
| 40 | |
|---|
| 41 | public string name { set; get; } |
|---|
| 42 | public Gee.Map<string, OptionSettings> options { get { return _options; } } |
|---|
| 43 | |
|---|
| 44 | public string to_xml (size_t tab_width) |
|---|
| 45 | { |
|---|
| 46 | var prefix = string.nfill (tab_width, '\t'); |
|---|
| 47 | var xml_str = prefix + "<programmer name=\"%s\">\n".printf (_name); |
|---|
| 48 | foreach (var option_settings in _options.values) |
|---|
| 49 | xml_str += option_settings.to_xml (tab_width+1); |
|---|
| 50 | xml_str += prefix + "</programmer>\n"; |
|---|
| 51 | return xml_str; |
|---|
| 52 | } |
|---|
| 53 | } |
|---|
| 54 | |
|---|
| 55 | public class I4uc.Core.Settings : GLib.Object |
|---|
| 56 | { |
|---|
| 57 | private HashMap<string, ProgrammerSettings> _programmers = new HashMap<string, ProgrammerSettings> (); |
|---|
| 58 | |
|---|
| 59 | public string working_folder { set; get; } |
|---|
| 60 | |
|---|
| 61 | // MainWindow Settings |
|---|
| 62 | public int width { set; get; default = 320; } |
|---|
| 63 | public int height { set; get; default = 240; } |
|---|
| 64 | public bool maximized { set; get; default = false; } |
|---|
| 65 | public bool side_panel_visible { set; get; } |
|---|
| 66 | public bool bottom_panel_visible { set; get; } |
|---|
| 67 | |
|---|
| 68 | // Documents Settings |
|---|
| 69 | public string font { set; get; default = "Monospace 10"; } |
|---|
| 70 | public int tab_width { set; get; default = 8; } |
|---|
| 71 | public bool auto_indent { set; get; } |
|---|
| 72 | public bool highlight_current_line { set; get; } |
|---|
| 73 | public bool insert_spaces_instead_of_tabs { set; get; } |
|---|
| 74 | public bool show_line_numbers { set; get; } |
|---|
| 75 | public bool highlight_matching_brackets { set; get; } |
|---|
| 76 | public bool wrap_mode { set; get; } |
|---|
| 77 | |
|---|
| 78 | // Programmers settings |
|---|
| 79 | public string programmer { set; get; default = ""; } |
|---|
| 80 | public Gee.Map<string, ProgrammerSettings> programmers { get { return _programmers; } } |
|---|
| 81 | |
|---|
| 82 | public Settings () |
|---|
| 83 | { |
|---|
| 84 | _working_folder = File.new_for_path (Environment.get_home_dir ()).get_uri (); |
|---|
| 85 | } |
|---|
| 86 | |
|---|
| 87 | public string to_xml () |
|---|
| 88 | { |
|---|
| 89 | var xml_str = "<settings>\n"; |
|---|
| 90 | |
|---|
| 91 | // MainWindow settings |
|---|
| 92 | xml_str += @"\t<width>$(_width)</width>\n"; |
|---|
| 93 | xml_str += @"\t<height>$(_height)</height>\n"; |
|---|
| 94 | xml_str += @"\t<maximized>$(_maximized)</maximized>\n"; |
|---|
| 95 | xml_str += @"\t<side_panel_visible>$(_side_panel_visible)</side_panel_visible>\n"; |
|---|
| 96 | xml_str += @"\t<bottom_panel_visible>$(_bottom_panel_visible)</bottom_panel_visible>\n"; |
|---|
| 97 | |
|---|
| 98 | // Documents settings |
|---|
| 99 | xml_str += @"\t<font>$(_font)</font>\n"; |
|---|
| 100 | xml_str += @"\t<tab_width>$(_tab_width)</tab_width>\n"; |
|---|
| 101 | xml_str += @"\t<auto_indent>$(_auto_indent)</auto_indent>\n"; |
|---|
| 102 | xml_str += @"\t<highlight_current_line>$(_highlight_current_line)</highlight_current_line>\n"; |
|---|
| 103 | xml_str += @"\t<insert_spaces_instead_of_tabs>$(_insert_spaces_instead_of_tabs)</insert_spaces_instead_of_tabs>\n"; |
|---|
| 104 | xml_str += @"\t<show_line_numbers>$(_show_line_numbers)</show_line_numbers>\n"; |
|---|
| 105 | xml_str += @"\t<highlight_matching_brackets>$(_highlight_matching_brackets)</highlight_matching_brackets>\n"; |
|---|
| 106 | xml_str += @"\t<wrap_mode>$(_wrap_mode)</wrap_mode>\n"; |
|---|
| 107 | |
|---|
| 108 | // Programmers settings |
|---|
| 109 | xml_str += @"\t<current_programmer>$(_programmer)</current_programmer>\n"; |
|---|
| 110 | |
|---|
| 111 | xml_str += "\t<programmers>\n"; |
|---|
| 112 | foreach (var programmer in _programmers.values) |
|---|
| 113 | xml_str += programmer.to_xml (2); |
|---|
| 114 | xml_str += "\t</programmers>\n"; |
|---|
| 115 | |
|---|
| 116 | return xml_str + "</settings>"; |
|---|
| 117 | } |
|---|
| 118 | } |
|---|