Reworked track settings.
[demorecorder] / src / MixdownPopUp.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 MixdownPopUp : Hildon.Dialog {
21   
22   Hildon.TouchSelector encoder_selector;
23   Hildon.TouchSelector quality_selector;
24   Hildon.Entry title_entry;
25   Hildon.Entry artist_entry;
26   Hildon.Entry album_entry;
27   //Hildon.Entry description_entry;
28   Hildon.Button location_btn;
29   
30   public SettingsStructures.MixdownSettings get_settings_structure() {
31     SettingsStructures.MixdownSettings settings = SettingsStructures.MixdownSettings();
32     settings.location = location_btn.get_value();
33     settings.encoder = encoder_selector.get_current_text();
34     settings.quality = quality_selector.get_current_text();
35     settings.title = title_entry.get_text();
36     settings.album = album_entry.get_text();
37     settings.artist = artist_entry.get_text();
38     return settings;
39   }
40   public void set_settings_structure(SettingsStructures.MixdownSettings settings) {
41     location_btn.set_value(settings.location);
42     this.set_encoder(settings.encoder);
43     this.set_quality(settings.quality);
44     title_entry.set_text(settings.title);
45     album_entry.set_text(settings.album);
46     artist_entry.set_text(settings.artist);
47   }
48   
49   private void set_encoder(string encoder) {
50     int idx = 0;
51     switch (encoder) {
52       case "vorbisenc":
53         idx = 0;
54         break;
55       case "wavenc":
56         idx = 1;
57         break;
58       case "nokiaaacenc":
59         idx = 2;
60         break;
61       case "mpegaudio":
62         idx = 3;
63         break;
64       case "lame":
65         idx = 4;
66         break;
67       default:
68         idx = 0;
69         break;
70     }
71     encoder_selector.set_active(0, idx);
72   }
73   
74   private void set_quality(string quality) {
75     int idx = 0;
76     switch (quality) {
77       case "high":
78         idx = 0;
79         break;
80       case "medium":
81         idx = 1;
82         break;
83       case "low":
84         idx = 2;
85         break;
86       default:
87         idx = 0;
88         break;
89     }
90     quality_selector.set_active(0, idx);
91   }
92   
93   public MixdownPopUp(string title, Gtk.Widget parent) {
94     this.set_title(title);
95     this.set_parent(parent);    
96     construct_interface(SettingsStructures.MixdownSettings());
97   }
98   public MixdownPopUp.with_settings(string title, Gtk.Widget parent, SettingsStructures.MixdownSettings settings) {
99     this.set_title(title);
100     this.set_parent(parent);
101     construct_interface(settings);
102   }
103   
104   private void construct_interface(SettingsStructures.MixdownSettings settings) {
105     this.set_default_response(Gtk.ResponseType.CANCEL);
106     this.add_button(Gtk.STOCK_OK, Gtk.ResponseType.OK);
107     this.add_button(Gtk.STOCK_CLOSE, Gtk.ResponseType.CANCEL);
108     
109     Gtk.VBox control_area = (Gtk.VBox)this.get_content_area();
110     
111     // location
112     location_btn = new Hildon.Button.with_text(Hildon.SizeType.FINGER_HEIGHT | Hildon.SizeType.HALFSCREEN_WIDTH, Hildon.ButtonArrangement.VERTICAL, "Location", settings.location);
113     location_btn.set_style(Hildon.ButtonStyle.PICKER);
114     location_btn.set_alignment(0, 0, 1, 1);
115     location_btn.clicked.connect(select_location);
116     control_area.pack_start(location_btn, true, true, 2);
117     
118     Gtk.HButtonBox button_bar = new Gtk.HButtonBox();
119     button_bar.set_layout(Gtk.ButtonBoxStyle.START);
120     button_bar.set_homogeneous(false);
121     button_bar.set_spacing(4);
122     
123     // encoder
124     encoder_selector = new Hildon.TouchSelector.text();
125     encoder_selector.append_text("vorbisenc");
126     encoder_selector.append_text("wavenc");
127     encoder_selector.append_text("nokiaaacenc");
128     encoder_selector.append_text("mpegaudio");
129     encoder_selector.append_text("lame");
130     this.set_encoder(settings.encoder);
131     Hildon.PickerButton encoder_picker = new Hildon.PickerButton(Hildon.SizeType.FINGER_HEIGHT | Hildon.SizeType.AUTO_WIDTH, Hildon.ButtonArrangement.VERTICAL);
132     encoder_picker.set_title("Encoder");
133     encoder_picker.set_selector(encoder_selector);
134     //encoder_picker.value_changed.connect( (s) => { this.settings.encoder = s.get_selector().get_current_text(); } );
135     button_bar.pack_start(encoder_picker, true, true, 2);
136     
137     // quality
138     quality_selector = new Hildon.TouchSelector.text();
139     quality_selector.append_text("high");
140     quality_selector.append_text("medium");
141     quality_selector.append_text("low");
142     this.set_quality(settings.quality);
143     Hildon.PickerButton quality_picker = new Hildon.PickerButton(Hildon.SizeType.FINGER_HEIGHT | Hildon.SizeType.AUTO_WIDTH, Hildon.ButtonArrangement.VERTICAL);
144     quality_picker.set_title("Quality");
145     quality_picker.set_selector(quality_selector);
146     //quality_picker.value_changed.connect( (s) => { this.settings.quality = s.get_selector().get_current_text(); } );
147     button_bar.pack_start(quality_picker, true, true, 2);
148     
149     control_area.pack_start(button_bar, true, true, 2);
150     // artist
151     
152     Gtk.HBox artist_bar = new Gtk.HBox(false, 4);
153     
154     Gtk.Label artist_label = new Gtk.Label("Artist");
155     artist_bar.pack_start(artist_label, false, false, 2);
156     artist_entry = new Hildon.Entry(Hildon.SizeType.HALFSCREEN_WIDTH);
157     artist_entry.set_text(settings.artist);
158     artist_entry.set_placeholder("Unknown Artist");
159     artist_bar.pack_start(artist_entry, true, true, 2);
160     
161     control_area.pack_start(artist_bar, true, true, 2);
162         
163     // title
164     Gtk.HBox title_bar = new Gtk.HBox(false, 4);
165     
166     Gtk.Label title_label = new Gtk.Label("Title");
167     title_bar.pack_start(title_label, false, false, 2);
168     title_entry = new Hildon.Entry(Hildon.SizeType.HALFSCREEN_WIDTH);
169     title_entry.set_text(settings.title);
170     title_entry.set_placeholder("Untitled");
171     title_bar.pack_start(title_entry, true, true, 2);
172     
173     control_area.pack_start(title_bar, true, true, 2);
174     
175     // album
176     Gtk.HBox album_bar = new Gtk.HBox(false, 4);
177     
178     Gtk.Label album_label = new Gtk.Label("Album");
179     album_bar.pack_start(album_label, false, false, 2);
180     album_entry = new Hildon.Entry(Hildon.SizeType.HALFSCREEN_WIDTH);
181     album_entry.set_text(settings.album);
182     album_entry.set_placeholder("Untitled");
183     album_bar.pack_start(album_entry, true, true, 2);
184     
185     control_area.pack_start(album_bar, true, true, 2);
186     
187     
188     // description
189     /*Gtk.HBox description_bar = new Gtk.HBox(false, 4);
190     
191     Gtk.Label description_label = new Gtk.Label("Description");
192     description_bar.pack_start(description_label, false, false, 2);
193     description_entry = new Hildon.Entry();
194     description_entry.truncate_multiline = false;
195     description_entry.text = "";
196     description_bar.pack_start(description_entry, true, true, 2);
197     
198     control_area.pack_start(description_bar, true, true, 2);
199     */
200     
201     this.show_all();
202   }
203   
204   private void select_location() {
205     // get a filename
206     Hildon.FileChooserDialog file_chooser = new Hildon.FileChooserDialog(this, Gtk.FileChooserAction.SAVE);
207     file_chooser.set_show_upnp(false);
208     Gtk.ResponseType ret = (Gtk.ResponseType) file_chooser.run();
209     if (Gtk.ResponseType.OK == ret) {
210       this.location_btn.value = file_chooser.get_filename();
211     }
212     file_chooser.destroy ();
213   }
214
215 }
216
217 }