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