Added About Dialog
[demorecorder] / src / EchoPopUp.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 EchoPopUp : Hildon.Dialog {
21   
22   Gtk.HScale delay_slider;
23   Gtk.HScale feedback_slider;
24   Gtk.HScale intensity_slider;
25   
26   const uint64 MAX_DELAY = 1 * Time.Milliseconds.SECOND;
27   
28   public signal void delay_updated(uint64 val);
29   public signal void feedback_updated(double val);
30   public signal void intensity_updated(double val);
31   
32   public EchoPopUp (string title, Gtk.Widget parent) {
33     this.set_title(title);
34     this.set_parent(parent);
35     
36     construct_interface(SettingsStructures.EchoSettings());
37   }
38   public EchoPopUp.with_settings (string title, Gtk.Widget parent, SettingsStructures.EchoSettings settings) {
39     this.set_title(title);
40     this.set_parent(parent);
41     
42     construct_interface(settings);
43   }
44   
45   public SettingsStructures.EchoSettings get_settings_structure() {
46     SettingsStructures.EchoSettings settings = SettingsStructures.EchoSettings();
47     settings.active = true;
48     settings.max_delay = MAX_DELAY;
49     settings.delay = this.get_delay();
50     settings.feedback = this.get_feedback();
51     settings.intensity = this.get_intensity();
52     return settings;
53   }
54   public void set_settings_structure(SettingsStructures.EchoSettings settings) {
55     // ignore active for now
56     // ignore max_delay for now
57     this.set_delay(settings.delay);
58     this.set_feedback(settings.feedback);
59     this.set_intensity(settings.intensity);
60   }
61   
62   private void construct_interface(SettingsStructures.EchoSettings settings) {
63     
64     this.set_default_response(Gtk.ResponseType.ACCEPT);
65     this.add_button(Gtk.STOCK_CLOSE, Gtk.ResponseType.ACCEPT);
66     
67     Gtk.VBox control_area = (Gtk.VBox)this.get_content_area();
68     
69     Gtk.HBox delay_bar = new Gtk.HBox(false, 4);
70     
71     Gtk.Label delay_label = new Gtk.Label("Delay (ms): ");
72     delay_slider = new Gtk.HScale.with_range(0, MAX_DELAY, Time.Milliseconds.MILLISECOND);
73     delay_slider.set_value_pos(Gtk.PositionType.LEFT);
74     delay_slider.set_value(settings.delay);
75     delay_slider.value_changed.connect((s) => {delay_updated((uint64)(s.get_value()) * Time.Nanoseconds.MILLISECOND);});
76     delay_bar.pack_start(delay_label, false, false, 2);
77     delay_bar.pack_start(delay_slider, true, true, 2);
78     
79     control_area.pack_start(delay_bar, true, true, 2);
80     
81     Gtk.HBox feedback_bar = new Gtk.HBox(false, 4);    
82     
83     Gtk.Label feedback_label = new Gtk.Label("Feedback (ratio): ");
84     feedback_slider = new Gtk.HScale.with_range(0.0, 1.0, 0.05);
85     feedback_slider.set_value_pos(Gtk.PositionType.LEFT);
86     feedback_slider.set_value(settings.feedback);
87     feedback_slider.value_changed.connect((s) => {feedback_updated(s.get_value());});
88     feedback_bar.pack_start(feedback_label, false, false, 2);
89     feedback_bar.pack_start(feedback_slider, true, true, 2);
90     
91     control_area.pack_start(feedback_bar, true, true, 2);
92     
93     Gtk.HBox intensity_bar = new Gtk.HBox(false, 4);    
94     
95     Gtk.Label intensity_label = new Gtk.Label("Intensity (ratio): ");
96     intensity_slider = new Gtk.HScale.with_range(0.0, 1.0, 0.05);
97     intensity_slider.set_value_pos(Gtk.PositionType.LEFT);
98     intensity_slider.set_value(settings.intensity);
99     intensity_slider.value_changed.connect((s) => {intensity_updated(s.get_value());});
100     intensity_bar.pack_start(intensity_label, false, false, 2);
101     intensity_bar.pack_start(intensity_slider, true, true, 2);
102     
103     control_area.pack_start(intensity_bar, true, true, 2);
104     
105     this.show_all();
106   }
107   
108   public uint64 get_delay() {
109     return (uint64) (delay_slider.get_value() * Time.Nanoseconds.MILLISECOND);
110   }
111   public void set_delay(uint64 val) {
112     delay_slider.set_value((double) (val / Time.Nanoseconds.MILLISECOND));
113   }
114   
115   public double get_feedback() {
116     return feedback_slider.get_value();
117   }
118   public void set_feedback(double val) {
119     feedback_slider.set_value(val);
120   }
121   
122   public double get_intensity() {
123     return intensity_slider.get_value();
124   }
125   public void set_intensity(double val) {
126     intensity_slider.set_value(val);
127   }
128
129 }
130
131 }