| 1 | /* main.vala |
|---|
| 2 | * |
|---|
| 3 | * Copyright (C) 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; |
|---|
| 22 | using I4uc; |
|---|
| 23 | |
|---|
| 24 | void main (string[] args) |
|---|
| 25 | { |
|---|
| 26 | Gtk.init (ref args); |
|---|
| 27 | |
|---|
| 28 | try |
|---|
| 29 | { |
|---|
| 30 | load_settings (); |
|---|
| 31 | load_builders (); |
|---|
| 32 | load_programmers (); |
|---|
| 33 | load_stock_items (); |
|---|
| 34 | } |
|---|
| 35 | catch (GLib.Error e) |
|---|
| 36 | { |
|---|
| 37 | warning (e.message); |
|---|
| 38 | } |
|---|
| 39 | |
|---|
| 40 | Intl.bindtextdomain (Config.GETTEXT_PACKAGE, Config.LOCALE_DIR); |
|---|
| 41 | Intl.bind_textdomain_codeset (Config.GETTEXT_PACKAGE, "UTF-8"); |
|---|
| 42 | |
|---|
| 43 | var main_window_view = new MainWindowView (); |
|---|
| 44 | main_window_view.show_all (); |
|---|
| 45 | |
|---|
| 46 | var ui_manager = main_window_view.ui_manager; |
|---|
| 47 | var pages_panel = main_window_view.pages_panel; |
|---|
| 48 | var side_panel = main_window_view.side_panel; |
|---|
| 49 | var bottom_panel = main_window_view.bottom_panel; |
|---|
| 50 | |
|---|
| 51 | var documents_view = new DocumentsView (ui_manager, pages_panel, side_panel); |
|---|
| 52 | var projects_view = new ProjectsView (ui_manager, side_panel, bottom_panel); |
|---|
| 53 | var programmers_view = new ProgrammersView (ui_manager, pages_panel, side_panel, bottom_panel); |
|---|
| 54 | |
|---|
| 55 | var main_window_presenter = new MainWindowPresenter (main_window_view); |
|---|
| 56 | var documents_presenter = new DocumentsPresenter (documents_view); |
|---|
| 57 | var projects_presenter = new ProjectsPresenter (projects_view, documents_presenter); |
|---|
| 58 | var programmers_presenter = new ProgrammersPresenter (programmers_view, documents_presenter); |
|---|
| 59 | |
|---|
| 60 | main_window_view.exit_clicked.connect (() => { |
|---|
| 61 | if (!documents_presenter.close_all ()) |
|---|
| 62 | return true; |
|---|
| 63 | projects_presenter.close_all_projects (); |
|---|
| 64 | return false; |
|---|
| 65 | }); |
|---|
| 66 | |
|---|
| 67 | Gtk.main (); |
|---|
| 68 | |
|---|
| 69 | try |
|---|
| 70 | { |
|---|
| 71 | I4uc.Settings.instance.save (); |
|---|
| 72 | } |
|---|
| 73 | catch (GLib.FileError e) |
|---|
| 74 | { |
|---|
| 75 | warning (e.message); |
|---|
| 76 | } |
|---|
| 77 | } |
|---|
| 78 | |
|---|
| 79 | void load_settings () throws GLib.Error, GLib.KeyFileError |
|---|
| 80 | { |
|---|
| 81 | var settings_folder = Path.build_filename (Environment.get_home_dir (), ".i4uc"); |
|---|
| 82 | if (!FileUtils.test (settings_folder, FileTest.EXISTS)) |
|---|
| 83 | DirUtils.create (settings_folder, 0755); |
|---|
| 84 | var settings_filename = Path.build_filename (settings_folder, "i4ucrc"); |
|---|
| 85 | I4uc.Settings.instance.open (settings_filename); |
|---|
| 86 | } |
|---|
| 87 | |
|---|
| 88 | void load_builders () throws GLib.Error, GLib.KeyFileError |
|---|
| 89 | { |
|---|
| 90 | //Load builders in $(pkgdatadir)/builders/ |
|---|
| 91 | var builders_dir = File.new_for_path (Config.BUILDERS_DIR); |
|---|
| 92 | |
|---|
| 93 | var enumerator = builders_dir.enumerate_children (FILE_ATTRIBUTE_STANDARD_NAME, FileQueryInfoFlags.NONE, null); |
|---|
| 94 | FileInfo file_info; |
|---|
| 95 | while ((file_info = enumerator.next_file (null)) != null) |
|---|
| 96 | { |
|---|
| 97 | if (!file_info.get_name ().has_suffix (".i4ucbuilder")) |
|---|
| 98 | continue; |
|---|
| 99 | |
|---|
| 100 | var builder_file = builders_dir.get_child (file_info.get_name ()); |
|---|
| 101 | var builder = new I4uc.Builder (); |
|---|
| 102 | if (builder.open (builder_file.get_uri ())) |
|---|
| 103 | I4uc.Settings.instance.builders[builder.id] = builder; |
|---|
| 104 | } |
|---|
| 105 | |
|---|
| 106 | //check if $(HOME)/.i4uc/builders/ exists. If not, create it |
|---|
| 107 | builders_dir = File.new_for_path (Path.build_filename (Environment.get_home_dir (), ".i4uc", "builders")); |
|---|
| 108 | if (!builders_dir.query_exists (null)) |
|---|
| 109 | builders_dir.make_directory (null); |
|---|
| 110 | |
|---|
| 111 | //Load builders in $(HOME)/.i4uc/builders/ |
|---|
| 112 | enumerator = builders_dir.enumerate_children (FILE_ATTRIBUTE_STANDARD_NAME, FileQueryInfoFlags.NONE, null); |
|---|
| 113 | while ((file_info = enumerator.next_file (null)) != null) |
|---|
| 114 | { |
|---|
| 115 | if (!file_info.get_name ().has_suffix (".i4ucbuilder")) |
|---|
| 116 | continue; |
|---|
| 117 | |
|---|
| 118 | var builder_file = builders_dir.get_child (file_info.get_name ()); |
|---|
| 119 | var builder = new I4uc.Builder (); |
|---|
| 120 | if (builder.open (builder_file.get_uri ())) |
|---|
| 121 | I4uc.Settings.instance.builders[builder.id] = builder; |
|---|
| 122 | } |
|---|
| 123 | } |
|---|
| 124 | |
|---|
| 125 | void load_programmers () throws GLib.Error, GLib.KeyFileError |
|---|
| 126 | { |
|---|
| 127 | //Load programmers in $(pkgdatadir)/programmers/ |
|---|
| 128 | var programmers_dir = File.new_for_path (Config.PROGRAMMERS_DIR); |
|---|
| 129 | |
|---|
| 130 | var enumerator = programmers_dir.enumerate_children (FILE_ATTRIBUTE_STANDARD_NAME, FileQueryInfoFlags.NONE, null); |
|---|
| 131 | FileInfo file_info; |
|---|
| 132 | while ((file_info = enumerator.next_file (null)) != null) |
|---|
| 133 | { |
|---|
| 134 | if (!file_info.get_name ().has_suffix (".i4ucprogrammer")) |
|---|
| 135 | continue; |
|---|
| 136 | |
|---|
| 137 | var programmer_file = programmers_dir.get_child (file_info.get_name ()); |
|---|
| 138 | var programmer = new Programmer (); |
|---|
| 139 | if (programmer.open (programmer_file.get_uri ())) |
|---|
| 140 | I4uc.Settings.instance.programmers[programmer.id] = programmer; |
|---|
| 141 | } |
|---|
| 142 | |
|---|
| 143 | //check if $(HOME)/.i4uc/programmers/ exists. If not, create it |
|---|
| 144 | programmers_dir = File.new_for_path (Path.build_filename (Environment.get_home_dir (), ".i4uc", "programmers")); |
|---|
| 145 | if (!programmers_dir.query_exists (null)) |
|---|
| 146 | programmers_dir.make_directory (null); |
|---|
| 147 | |
|---|
| 148 | //Load programmers in $(HOME)/.i4uc/programmers/ |
|---|
| 149 | enumerator = programmers_dir.enumerate_children (FILE_ATTRIBUTE_STANDARD_NAME, FileQueryInfoFlags.NONE, null); |
|---|
| 150 | while ((file_info = enumerator.next_file (null)) != null) |
|---|
| 151 | { |
|---|
| 152 | if (!file_info.get_name ().has_suffix (".i4ucprogrammer")) |
|---|
| 153 | continue; |
|---|
| 154 | |
|---|
| 155 | var programmer_file = programmers_dir.get_child (file_info.get_name ()); |
|---|
| 156 | var programmer = new Programmer (); |
|---|
| 157 | if (programmer.open (programmer_file.get_uri ())) |
|---|
| 158 | I4uc.Settings.instance.programmers[programmer.id] = programmer; |
|---|
| 159 | } |
|---|
| 160 | } |
|---|
| 161 | |
|---|
| 162 | /* |
|---|
| 163 | Load i4uc stock items located in $(pkgdatadir)/pixmaps |
|---|
| 164 | */ |
|---|
| 165 | void load_stock_items () throws GLib.Error |
|---|
| 166 | { |
|---|
| 167 | var icon_factory = new IconFactory (); |
|---|
| 168 | |
|---|
| 169 | var icon_set = new IconSet.from_pixbuf (new Gdk.Pixbuf.from_file (Path.build_filename (Config.PIXMAPS_DIR, "programmer-icon.svg"))); |
|---|
| 170 | icon_factory.add ("i4uc-programmer-icon", icon_set); |
|---|
| 171 | |
|---|
| 172 | icon_set = new IconSet.from_pixbuf (new Gdk.Pixbuf.from_file (Path.build_filename (Config.PIXMAPS_DIR, "write-flash.svg"))); |
|---|
| 173 | icon_factory.add ("i4uc-write-flash", icon_set); |
|---|
| 174 | |
|---|
| 175 | icon_set = new IconSet.from_pixbuf (new Gdk.Pixbuf.from_file (Path.build_filename (Config.PIXMAPS_DIR, "read-flash.svg"))); |
|---|
| 176 | icon_factory.add ("i4uc-read-flash", icon_set); |
|---|
| 177 | |
|---|
| 178 | icon_set = new IconSet.from_pixbuf (new Gdk.Pixbuf.from_file (Path.build_filename (Config.PIXMAPS_DIR, "verify-flash.svg"))); |
|---|
| 179 | icon_factory.add ("i4uc-verify-flash", icon_set); |
|---|
| 180 | |
|---|
| 181 | icon_set = new IconSet.from_pixbuf (new Gdk.Pixbuf.from_file (Path.build_filename (Config.PIXMAPS_DIR, "erase-flash.svg"))); |
|---|
| 182 | icon_factory.add ("i4uc-erase-flash", icon_set); |
|---|
| 183 | |
|---|
| 184 | icon_factory.add_default (); |
|---|
| 185 | } |
|---|