source: libi4uccore/profiledialoglogic.vala @ a3064c545a538bf213389eae184e543f06f7f8e1

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

Projects: Improve profile dialog

  • Property mode set to 100644
Line 
1/* profiledialoglogic.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
22public class I4uc.Core.ProfileDialogLogic : GLib.Object
23{
24        private ProfileDialogView _view;
25        private Project _project;
26        private ProjectProfile _profile;
27        private bool _duplicate_profile;
28       
29        public ProfileDialogLogic (ProfileDialogView view, Project project, ProjectProfile profile, bool duplicate_profile=false)
30        {
31                _view = view;
32                _project = project;
33                _profile = profile;
34                _duplicate_profile = duplicate_profile;
35               
36                //Configure view
37                _view.warning_message_visible = false;
38                _view.title = _duplicate_profile ? _("Duplicate profile") : _("Edit profile");
39                if (!_duplicate_profile)
40                        _view.profile_name = _profile.name;
41                _view.is_public = _profile.is_public;
42                foreach (var file in _project.files)
43                        _view.add_file (file, file in _profile.files);
44                on_profile_name_changed ();
45               
46                //Connect view signals
47                _view.notify["profile-name"].connect (on_profile_name_changed);
48        }
49       
50        public bool run ()
51        {
52                if (_view.run () == Gtk.ResponseType.CANCEL)
53                        return false;
54               
55                if (_duplicate_profile)
56                        return true;
57                       
58                if (_profile.name != _view.profile_name ||
59                    _profile.is_public != _view.is_public ||
60                    !_view.activated_files.contains_all (_profile.files) ||
61                    !_profile.files.contains_all (_view.activated_files))
62                        return true;
63               
64                return false;
65        }
66       
67        public void close ()
68        {
69                _view.close_dialog ();
70        }
71       
72        private void on_profile_name_changed ()
73        {
74                _view.accept_sensitive = false;
75                if (_view.profile_name == "" || _view.profile_name == null)
76                        return;
77                if ((_duplicate_profile && _view.profile_name == _profile.name) ||
78                    (_view.profile_name != _profile.name && _view.profile_name in _project.profiles.keys))
79                {
80                        _view.warning_message = _("There's already a profile with that name");
81                        _view.warning_message_visible = true;
82                        return;
83                }
84                _view.warning_message_visible = false;
85                _view.accept_sensitive = true;
86        }
87}
Note: See TracBrowser for help on using the repository browser.