| 1 | /* i4ucprojectssidepagepresenter.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 Gee; |
|---|
| 22 | |
|---|
| 23 | public class I4uc.ProjectsSidePagePresenter : GLib.Object |
|---|
| 24 | { |
|---|
| 25 | private ProjectsSidePageViewIface _view; |
|---|
| 26 | private ArrayList<Project> _projects = new ArrayList<Project> (); |
|---|
| 27 | |
|---|
| 28 | public Project current_project |
|---|
| 29 | { |
|---|
| 30 | set { _view.current_project = value.uri; } |
|---|
| 31 | owned get { return get_project_from_uri (_view.current_project); } |
|---|
| 32 | } |
|---|
| 33 | |
|---|
| 34 | public Gee.List<Project> projects { owned get { return _projects.read_only_view; } } |
|---|
| 35 | |
|---|
| 36 | public ProjectsSidePagePresenter (ProjectsSidePageViewIface view) |
|---|
| 37 | { |
|---|
| 38 | _view = view; |
|---|
| 39 | |
|---|
| 40 | //Configure view |
|---|
| 41 | _view.tab_title = _("Projects"); |
|---|
| 42 | |
|---|
| 43 | //Connect view signals |
|---|
| 44 | _view.project_changed.connect (on_project_changed); |
|---|
| 45 | } |
|---|
| 46 | |
|---|
| 47 | public void add_project (Project project) |
|---|
| 48 | { |
|---|
| 49 | if (!(project in _projects)) |
|---|
| 50 | { |
|---|
| 51 | _view.add_project (project.uri, project.name); |
|---|
| 52 | _projects.add (project); |
|---|
| 53 | } |
|---|
| 54 | _view.current_project = project.uri; |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | public void remove_project (Project project) |
|---|
| 58 | { |
|---|
| 59 | if (!(project in _projects)) |
|---|
| 60 | return; |
|---|
| 61 | _projects.remove (project); |
|---|
| 62 | _view.remove_project (project.uri); |
|---|
| 63 | if (_projects.size > 0) |
|---|
| 64 | _view.current_project = _projects[0].uri; |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | private void on_project_changed () |
|---|
| 68 | { |
|---|
| 69 | _view.clear_files_list (); |
|---|
| 70 | _view.clear_profiles_list (); |
|---|
| 71 | |
|---|
| 72 | var current_project = get_project_from_uri (_view.current_project); |
|---|
| 73 | if (current_project == null) |
|---|
| 74 | return; |
|---|
| 75 | |
|---|
| 76 | //Load files list |
|---|
| 77 | foreach (var file in current_project.files) |
|---|
| 78 | _view.add_file (file); |
|---|
| 79 | |
|---|
| 80 | //Load profiles list |
|---|
| 81 | foreach (var profile in current_project.profiles.values) |
|---|
| 82 | { |
|---|
| 83 | _view.add_profile (profile.name); |
|---|
| 84 | foreach (var file in profile.files) |
|---|
| 85 | _view.add_profile_file (profile.name, file); |
|---|
| 86 | } |
|---|
| 87 | } |
|---|
| 88 | |
|---|
| 89 | private Project? get_project_from_uri (string? project_uri) |
|---|
| 90 | { |
|---|
| 91 | foreach (var project in _projects) |
|---|
| 92 | if (project.uri == project_uri) |
|---|
| 93 | return project; |
|---|
| 94 | return null; |
|---|
| 95 | } |
|---|
| 96 | } |
|---|