| [63e85bd] | 1 | /* i4ucsettings.vala |
|---|
| 2 | * |
|---|
| 3 | * Copyright (C) 2009-2010 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 Gtk; |
|---|
| [7759ee2] | 22 | using Gee; |
|---|
| [63e85bd] | 23 | |
|---|
| [8b8dc78] | 24 | public class I4uc.Settings : GLib.Object |
|---|
| [63e85bd] | 25 | { |
|---|
| 26 | private const string _I4UC_SETTINGS = "i4uc settings"; |
|---|
| 27 | private const string _DOCUMENTS_SETTINGS = "Documents settings"; |
|---|
| 28 | private const string _PAGE_SETUP_SETTINGS = "Page setup settings"; |
|---|
| 29 | private const string _PRINT_SETTINGS = "Print settings"; |
|---|
| 30 | private const string _PICSTART_PLUS_SETTINGS = "Picstart Plus settings"; |
|---|
| 31 | private const string _PICKIT2_SETTINGS = "Pickit 2 settings"; |
|---|
| 32 | |
|---|
| 33 | private static Settings _instance; |
|---|
| 34 | private string _filename; |
|---|
| [7759ee2] | 35 | private HashMap<string, Builder> _builders = new HashMap<string, Builder> (); |
|---|
| [63e85bd] | 36 | |
|---|
| [b61fc02] | 37 | public bool side_panel_visible { set; get; } |
|---|
| [63e85bd] | 38 | public bool logs_panel_visible { set; get; } |
|---|
| 39 | public string working_folder { set; get; } |
|---|
| 40 | |
|---|
| 41 | public string documents_font { set; get; default = "Monospace 11"; } |
|---|
| 42 | public int documents_tab_width { set; get; default = 8; } |
|---|
| 43 | public bool documents_auto_indent { set; get; } |
|---|
| 44 | public bool documents_highlight_current_line { set; get; } |
|---|
| 45 | public bool documents_insert_spaces_instead_of_tabs { set; get; } |
|---|
| 46 | public bool documents_show_line_numbers { set; get; } |
|---|
| 47 | public bool documents_highlight_matching_brackets { set; get; } |
|---|
| 48 | public bool documents_wrap_mode { set; get; } |
|---|
| 49 | |
|---|
| 50 | public PageSetup page_setup { set; get; default = new PageSetup (); } |
|---|
| 51 | public PrintSettings print_settings { set; get; default = new PrintSettings (); } |
|---|
| 52 | |
|---|
| [7759ee2] | 53 | public Gee.Map<string, Builder> builders { get { return _builders; } } |
|---|
| 54 | |
|---|
| [63e85bd] | 55 | public string picstart_plus_connection_port { set; get; default = ""; } |
|---|
| 56 | public string pickit2_device_file { set; get; default = ""; } |
|---|
| 57 | |
|---|
| 58 | public static Settings instance |
|---|
| 59 | { |
|---|
| 60 | get |
|---|
| 61 | { |
|---|
| 62 | if (_instance == null) |
|---|
| 63 | _instance = new Settings (); |
|---|
| 64 | return _instance; |
|---|
| 65 | } |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| 68 | public Settings () |
|---|
| 69 | { |
|---|
| 70 | _working_folder = Filename.to_uri (Environment.get_home_dir ()); |
|---|
| 71 | } |
|---|
| 72 | |
|---|
| 73 | public void open (string filename) |
|---|
| 74 | { |
|---|
| 75 | _filename = filename; |
|---|
| 76 | var key_file = new KeyFile (); |
|---|
| 77 | |
|---|
| 78 | if (!FileUtils.test (_filename, FileTest.EXISTS) || |
|---|
| 79 | !key_file.load_from_file (_filename, KeyFileFlags.NONE) || |
|---|
| 80 | key_file.get_start_group () != _I4UC_SETTINGS) |
|---|
| 81 | return; |
|---|
| [8884b78] | 82 | |
|---|
| [b61fc02] | 83 | this.side_panel_visible = key_file.get_boolean (_I4UC_SETTINGS, "side_panel_visible"); |
|---|
| [63e85bd] | 84 | this.logs_panel_visible = key_file.get_boolean (_I4UC_SETTINGS, "logs_panel_visible"); |
|---|
| 85 | |
|---|
| 86 | this.documents_font = key_file.get_string (_DOCUMENTS_SETTINGS, "font"); |
|---|
| 87 | this.documents_tab_width = key_file.get_integer (_DOCUMENTS_SETTINGS, "tab_width"); |
|---|
| 88 | this.documents_auto_indent = key_file.get_boolean (_DOCUMENTS_SETTINGS, "auto_indent"); |
|---|
| 89 | this.documents_highlight_current_line = key_file.get_boolean (_DOCUMENTS_SETTINGS, "highlight_current_line"); |
|---|
| 90 | this.documents_insert_spaces_instead_of_tabs = key_file.get_boolean (_DOCUMENTS_SETTINGS, "insert_spaces_instead_of_tabs"); |
|---|
| 91 | this.documents_show_line_numbers = key_file.get_boolean (_DOCUMENTS_SETTINGS, "show_line_numbers"); |
|---|
| 92 | this.documents_highlight_matching_brackets = key_file.get_boolean (_DOCUMENTS_SETTINGS, "highlight_matching_brackets"); |
|---|
| 93 | this.documents_wrap_mode = key_file.get_boolean (_DOCUMENTS_SETTINGS, "wrap_mode"); |
|---|
| 94 | |
|---|
| 95 | if (key_file.has_group (_PAGE_SETUP_SETTINGS)) |
|---|
| 96 | this.page_setup = new PageSetup.from_key_file (key_file, _PAGE_SETUP_SETTINGS); |
|---|
| 97 | |
|---|
| 98 | if (key_file.has_group (_PRINT_SETTINGS)) |
|---|
| 99 | this.print_settings = new PrintSettings.from_key_file (key_file, _PRINT_SETTINGS); |
|---|
| 100 | |
|---|
| 101 | this.picstart_plus_connection_port = key_file.get_string (_PICSTART_PLUS_SETTINGS, "connection_port"); |
|---|
| 102 | this.pickit2_device_file = key_file.get_string (_PICKIT2_SETTINGS, "device_file"); |
|---|
| 103 | } |
|---|
| 104 | |
|---|
| 105 | public void save () |
|---|
| 106 | { |
|---|
| 107 | var key_file = new KeyFile (); |
|---|
| 108 | |
|---|
| [b61fc02] | 109 | key_file.set_boolean (_I4UC_SETTINGS, "side_panel_visible", _side_panel_visible); |
|---|
| [63e85bd] | 110 | key_file.set_boolean (_I4UC_SETTINGS, "logs_panel_visible", _logs_panel_visible); |
|---|
| 111 | |
|---|
| 112 | key_file.set_string (_DOCUMENTS_SETTINGS, "font", _documents_font); |
|---|
| 113 | key_file.set_integer (_DOCUMENTS_SETTINGS, "tab_width", _documents_tab_width); |
|---|
| 114 | key_file.set_boolean (_DOCUMENTS_SETTINGS, "auto_indent", _documents_auto_indent); |
|---|
| 115 | key_file.set_boolean (_DOCUMENTS_SETTINGS, "highlight_current_line", _documents_highlight_current_line); |
|---|
| 116 | key_file.set_boolean (_DOCUMENTS_SETTINGS, "insert_spaces_instead_of_tabs", _documents_insert_spaces_instead_of_tabs); |
|---|
| 117 | key_file.set_boolean (_DOCUMENTS_SETTINGS, "show_line_numbers", _documents_show_line_numbers); |
|---|
| 118 | key_file.set_boolean (_DOCUMENTS_SETTINGS, "highlight_matching_brackets", _documents_highlight_matching_brackets); |
|---|
| 119 | key_file.set_boolean (_DOCUMENTS_SETTINGS, "wrap_mode", _documents_wrap_mode); |
|---|
| 120 | |
|---|
| 121 | _page_setup.to_key_file (key_file, _PAGE_SETUP_SETTINGS); |
|---|
| 122 | _print_settings.to_key_file (key_file, _PRINT_SETTINGS); |
|---|
| 123 | |
|---|
| 124 | key_file.set_string (_PICSTART_PLUS_SETTINGS, "connection_port", _picstart_plus_connection_port); |
|---|
| 125 | key_file.set_string (_PICKIT2_SETTINGS, "device_file", _pickit2_device_file); |
|---|
| 126 | |
|---|
| 127 | size_t len; |
|---|
| 128 | var str = key_file.to_data (out len); |
|---|
| 129 | FileUtils.set_contents (_filename, str, (long)len); |
|---|
| 130 | } |
|---|
| 131 | } |
|---|