| 1 | /* i4ucprojectspresenter.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 | |
|---|
| 22 | public class I4uc.ProjectsPresenter : GLib.Object |
|---|
| 23 | { |
|---|
| 24 | private ProjectsViewIface _view; |
|---|
| 25 | private ProjectsSidePagePresenter _projects_side_page_presenter; |
|---|
| 26 | |
|---|
| 27 | public ProjectsPresenter (ProjectsViewIface view) |
|---|
| 28 | { |
|---|
| 29 | _view = view; |
|---|
| 30 | |
|---|
| 31 | _projects_side_page_presenter = new ProjectsSidePagePresenter (_view.projects_side_page_view); |
|---|
| 32 | |
|---|
| 33 | //Configure view |
|---|
| 34 | _view.close_sensitive = false; |
|---|
| 35 | |
|---|
| 36 | //Connect view signals |
|---|
| 37 | _view.new_clicked.connect (on_new_clicked); |
|---|
| 38 | _view.open_clicked.connect (on_open_clicked); |
|---|
| 39 | _view.close_clicked.connect (on_close_clicked); |
|---|
| 40 | _view.projects_side_page_view.project_changed.connect (on_project_changed); |
|---|
| 41 | } |
|---|
| 42 | |
|---|
| 43 | public void open_project (string project_uri) |
|---|
| 44 | { |
|---|
| 45 | var project = new Project (); |
|---|
| 46 | if (project.open (project_uri)) |
|---|
| 47 | _projects_side_page_presenter.add_project (project); |
|---|
| 48 | else |
|---|
| 49 | _view.show_error_message (_("Error trying to open <<%s>>").printf (project_uri)); |
|---|
| 50 | } |
|---|
| 51 | |
|---|
| 52 | public void close_all_projects () |
|---|
| 53 | { |
|---|
| 54 | _projects_side_page_presenter.remove_all_projects (); |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | private void on_new_clicked () |
|---|
| 58 | { |
|---|
| 59 | string project_uri; |
|---|
| 60 | string project_name; |
|---|
| 61 | Gee.List<string> authors; |
|---|
| 62 | if (_view.show_new_dialog (out project_uri, out project_name, out authors) == Gtk.ResponseType.OK) |
|---|
| 63 | { |
|---|
| 64 | var project = new Project (); |
|---|
| 65 | project.name = project_name; |
|---|
| 66 | project.authors.add_all (authors); |
|---|
| 67 | |
|---|
| 68 | var main_profile = new ProjectProfile (); |
|---|
| 69 | main_profile.name = "main"; |
|---|
| 70 | project.profiles["main"] = main_profile; |
|---|
| 71 | |
|---|
| 72 | project.save (project_uri); |
|---|
| 73 | _projects_side_page_presenter.add_project (project); |
|---|
| 74 | } |
|---|
| 75 | } |
|---|
| 76 | |
|---|
| 77 | private void on_open_clicked () |
|---|
| 78 | { |
|---|
| 79 | var folder_uri = I4uc.Settings.instance.working_folder; |
|---|
| 80 | Gee.List<string> projects; |
|---|
| 81 | _view.show_open_dialog (ref folder_uri, out projects); |
|---|
| 82 | I4uc.Settings.instance.working_folder = folder_uri; |
|---|
| 83 | foreach (var project in projects) |
|---|
| 84 | open_project (project); |
|---|
| 85 | } |
|---|
| 86 | |
|---|
| 87 | private void on_close_clicked () |
|---|
| 88 | { |
|---|
| 89 | _projects_side_page_presenter.remove_project (_projects_side_page_presenter.current_project); |
|---|
| 90 | } |
|---|
| 91 | |
|---|
| 92 | private void on_project_changed () |
|---|
| 93 | { |
|---|
| 94 | _view.close_sensitive = _projects_side_page_presenter.current_project != null; |
|---|
| 95 | } |
|---|
| 96 | } |
|---|