source: libi4uccore/projectspagelogic.vala @ 678078dde9ef6c0bf5b9a1d1ed37b75e22fba696

Revision 678078dde9ef6c0bf5b9a1d1ed37b75e22fba696, 8.2 KB checked in by Matias De la Puente <mfpuente.ar@…>, 3 years ago (diff)

Bind 'current_extra_options' property in GtkFrontend?.BuildersList?

  • Property mode set to 100644
Line 
1/* projectspagelogic.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 */
21using Gee;
22
23public class I4uc.Core.ProjectsPageLogic : GLib.Object
24{
25        private ProjectsPageView _view;
26        private DocumentsLogic _documents_logic;
27        private ArrayList<Project> _projects = new ArrayList<Project> ();
28        private Project _current_project;
29        private string _current_profile;
30
31        public Project current_project
32        {
33                set { _view.current_project = value.uri; }
34                get { return _current_project; }
35        }
36       
37        public Gee.List<Project> projects { owned get { return _projects.read_only_view; } }
38
39        public ProjectsPageLogic (ProjectsPageView view, DocumentsLogic documents_logic)
40        {
41                _view = view;
42                _documents_logic = documents_logic;
43
44                //Configure view
45                _view.tab_title = _("Projects");
46                _view.profiles_check_list_sensitive = false;
47                _view.profiles_check_list_visible = false;
48                _view.builders_list_sensitive = false;
49                _view.builders_list_visible = false;
50                foreach (var builder in I4uc.Core.Settings.instance.builders.keys)
51                        _view.builders_list.add_builder (builder);
52
53                //Connect view signals
54                _view.project_changed.connect (on_project_changed);
55                _view.profile_changed.connect (on_profile_changed);
56                _view.profile_edit_clicked.connect (on_profile_edit_clicked);
57                _view.profile_check_changed.connect (on_profile_check_changed);
58                _view.file_activated.connect (on_file_activated);
59                _view.file_changed.connect (on_file_changed);
60                _view.builders_list.builder_changed.connect (on_builder_changed);
61                _view.builders_list.device_type_changed.connect (on_device_type_changed);
62                _view.builders_list.device_changed.connect (on_device_changed);
63                _view.builders_list.notify["current-extra-options"].connect (on_extra_options_changed);
64        }
65
66        public void add_project (Project project)
67        {
68                if (!(project in _projects))
69                {
70                        _view.add_project (project.uri, project.name);
71                        _projects.add (project);
72                }
73                _view.current_project = project.uri;
74        }
75
76        public void remove_project (Project project)
77        {
78                if (!(project in _projects))
79                        return;
80                _projects.remove (project);
81                _view.remove_project (project.uri);
82                if (_projects.size > 0)
83                        _view.current_project = _projects[0].uri;
84        }
85
86        public void remove_all_projects ()
87        {
88                for (int i = _projects.size-1; i >= 0; i--)
89                {
90                        var project = _projects[i];
91                        _projects.remove (project);
92                        _view.remove_project (project.uri);
93                }
94        }
95
96        public void update_profiles_list ()
97        {
98                var profile = _current_profile;
99                on_project_changed ();
100                if (profile in _current_project.profiles.keys)
101                        _view.current_profile = profile;
102        }
103       
104        public void update_files_list ()
105        {
106                on_profile_changed ();
107        }
108       
109        public void show_current_profile_dialog (bool duplicate_profile=false)
110        {
111                var dialog_view = _view.create_profile_dialog_view ();
112                var profile = _current_project.profiles[_current_profile];
113                var dialog_logic = new ProfileDialogLogic (dialog_view, _current_project, profile, duplicate_profile);
114                if (!dialog_logic.run ())
115                        return;
116                if (_current_profile != profile.name)
117                {
118                        _view.change_profile (_current_profile, profile.name);
119                        _current_profile = profile.name;
120                }
121                on_profile_changed ();
122        }
123
124        private void on_project_changed ()
125        {
126                _view.clear_profiles_list ();
127
128                _current_project = get_project_from_uri (_view.current_project);
129                if (_current_project == null)
130                        return;
131
132                //Load profiles combo
133                _view.add_profile ("__NONE__", _("None"), false);
134                foreach (var profile in _current_project.profiles.values)
135                        _view.add_profile (profile.name);
136                _view.current_profile = "__NONE__";
137        }
138       
139        private void on_profile_changed ()
140        {
141                _view.clear_files_list ();
142                _view.profiles_check_list_sensitive = false;
143                _view.profiles_check_list_visible = false;
144                _view.builders_list_sensitive = false;
145                _view.builders_list_visible = false;
146
147                if (_current_project == null)
148                        return;
149               
150                _current_profile = _view.current_profile;
151                if (_current_profile == null)
152                        return;
153
154                if (_current_profile == "__NONE__")
155                {
156                        foreach (var file in _current_project.files)
157                                _view.add_file (file);
158                        _view.profiles_check_list_visible = true;
159                        return;
160                }
161               
162                var profile = _current_project.profiles[_current_profile];
163               
164                foreach (var file in profile.files)
165                        _view.add_file (file);
166               
167                _view.builders_list.current_builder = profile.builder_id;
168                _view.builders_list.current_device_type = profile.device_type;
169                _view.builders_list.current_device = profile.device;
170                _view.builders_list.current_extra_options = profile.extra_options;
171               
172                _view.builders_list_sensitive = true;
173                _view.builders_list_visible = true;
174        }
175
176        private void on_profile_edit_clicked ()
177        {
178                show_current_profile_dialog ();
179        }
180
181        private void on_profile_check_changed (string profile, bool active)
182        {
183                if (!_view.profiles_check_list_sensitive)
184                        return;
185
186                if (_current_project == null || _view.current_file == null)
187                        return;
188
189                if (active)
190                        _current_project.profiles[profile].files.add (_view.current_file);
191                else
192                        _current_project.profiles[profile].files.remove (_view.current_file);
193                _current_project.save ();
194        }
195
196        private void on_file_activated ()
197        {
198                var document_uri = _current_project.get_file_uri (_view.current_file);
199                _documents_logic.open_document (document_uri);
200        }
201
202        private void on_file_changed ()
203        {
204                _view.profiles_check_list_sensitive = false;
205                _view.uncheck_all_profiles ();
206
207                if (_current_project == null || _view.current_file == null)
208                        return;
209
210                foreach (var profile in _current_project.profiles.values)
211                        _view.check_profile (profile.name, _view.current_file in profile.files);
212                _view.profiles_check_list_sensitive = true;
213        }
214
215        private void on_builder_changed ()
216        {
217                _view.builders_list.clear_device_types_list ();
218
219                if (_current_project == null || _current_profile == null)
220                        return;
221               
222                var current_builder = _view.builders_list.current_builder;
223                if (_view.builders_list_sensitive)
224                {
225                        _current_project.profiles[_current_profile].builder_id = current_builder ?? "";
226                        _current_project.save ();
227                }
228
229                if (current_builder == null)
230                        return;
231               
232                var builder = I4uc.Core.Settings.instance.builders[current_builder];
233                foreach (var device_type in builder.device_types.keys)
234                        _view.builders_list.add_device_type (device_type);
235        }
236
237        private void on_device_type_changed ()
238        {
239                _view.builders_list.clear_devices_list ();
240
241                if (_current_project == null || _current_profile == null)
242                        return;
243               
244                var current_device_type = _view.builders_list.current_device_type;
245                if (_view.builders_list_sensitive)
246                {
247                        _current_project.profiles[_current_profile].device_type = current_device_type ?? "";
248                        _current_project.save ();
249                }
250               
251                if (current_device_type == null)
252                        return;
253
254                var builder = I4uc.Core.Settings.instance.builders[_view.builders_list.current_builder];
255                var device_type = builder.device_types[current_device_type];
256                foreach (var device in device_type.devices)
257                        _view.builders_list.add_device (device);
258        }
259
260        private void on_device_changed ()
261        {
262                if (!_view.builders_list_sensitive)
263                        return;
264
265                if (_current_project == null || _current_profile == null)
266                        return;
267               
268                var current_device = _view.builders_list.current_device;
269                _current_project.profiles[_current_profile].device = current_device ?? "";
270                _current_project.save ();
271        }
272       
273        private void on_extra_options_changed ()
274        {
275                if (!_view.builders_list_sensitive)
276                        return;
277               
278                if (_current_project == null || _current_profile == null)
279                        return;
280               
281                var current_extra_options = _view.builders_list.current_extra_options;
282                _current_project.profiles[_current_profile].extra_options = current_extra_options ?? "";
283                _current_project.save ();
284        }
285
286        private Project? get_project_from_uri (string? project_uri)
287        {
288                foreach (var project in _projects)
289                        if (project.uri == project_uri)
290                                return project;
291                return null;
292        }
293}
Note: See TracBrowser for help on using the repository browser.