Reworked track settings.
[demorecorder] / src / TrackDetailsDialog.vala
1 /*  Demo Recorder for MAEMO 5
2 *   Copyright (C) 2010 Dru Moore <usr@dru-id.co.uk>
3 *   This program is free software; you can redistribute it and/or modify
4 *   it under the terms of the GNU General Public License version 2,
5 *   or (at your option) any later version, as published by the Free
6 *   Software Foundation
7 *
8 *   This program is distributed in the hope that it will be useful,
9 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
10 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 *   GNU General Public License for more details
12 *
13 *   You should have received a copy of the GNU General Public
14 *   License along with this program; if not, write to the
15 *   Free Software Foundation, Inc.,
16 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17 */
18 namespace IdWorks {
19   
20   public class TrackDetailsDialog : Hildon.Dialog {
21     
22     Hildon.Entry name_entry;
23     
24     public string get_name() {
25       return name_entry.get_text();
26     }
27     public void set_name(string name) {
28       name_entry.set_text(name);
29       validate();
30     }
31     
32     public TrackDetailsDialog(Gtk.Widget parent, string title) {
33       this.set_parent(parent);
34       this.set_title(title);
35       this.set_default_response(Gtk.ResponseType.CANCEL);
36       construct_interface("");
37     }
38     
39     public TrackDetailsDialog.with_values(Gtk.Widget parent, string title, string name) {
40       this.set_parent(parent);
41       this.set_title(title);
42       this.set_default_response(Gtk.ResponseType.CANCEL);
43       construct_interface(name);
44     }
45     
46     private void construct_interface(string name) {
47       this.add_button(Gtk.STOCK_OK, Gtk.ResponseType.OK);
48       
49       Gtk.VBox control_area = (Gtk.VBox)this.get_content_area();
50       
51       Gtk.HBox name_bar = new Gtk.HBox(false, 4);
52       
53       Gtk.Label name_label = new Gtk.Label("Name");
54       name_bar.pack_start(name_label, false, false, 2);
55       name_entry = new Hildon.Entry(Hildon.SizeType.HALFSCREEN_WIDTH);
56       name_entry.set_text(name);
57       name_entry.set_placeholder("Project name");
58       name_entry.changed.connect(name_entry_changed);
59       name_bar.pack_start(name_entry, true, true, 2);
60       
61       control_area.pack_start(name_bar, true, true, 4);
62       
63       validate();
64       
65       this.show_all();
66     }
67     
68     private void name_entry_changed() {
69       validate();
70     }
71     
72     private void validate() {
73       bool good = true;
74       good &= (0 < get_name().length);
75       this.set_response_sensitive(Gtk.ResponseType.OK, good);
76     }
77     
78   }
79   
80 }