Adding first code drop
[demorecorder] / src / MixdownPopUp.vala
diff --git a/src/MixdownPopUp.vala b/src/MixdownPopUp.vala
new file mode 100644 (file)
index 0000000..4e3d8ce
--- /dev/null
@@ -0,0 +1,217 @@
+/*  Demo Recorder for MAEMO 5
+*   Copyright (C) 2010 Dru Moore <usr@dru-id.co.uk>
+*   This program is free software; you can redistribute it and/or modify
+*   it under the terms of the GNU General Public License version 2,
+*   or (at your option) any later version, as published by the Free
+*   Software Foundation
+*
+*   This program is distributed in the hope that it will be useful,
+*   but WITHOUT ANY WARRANTY; without even the implied warranty of
+*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+*   GNU General Public License for more details
+*
+*   You should have received a copy of the GNU General Public
+*   License along with this program; if not, write to the
+*   Free Software Foundation, Inc.,
+*   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+*/
+namespace IdWorks {
+
+public class MixdownPopUp : Hildon.Dialog {
+  
+  Hildon.TouchSelector encoder_selector;
+  Hildon.TouchSelector quality_selector;
+  Hildon.Entry title_entry;
+  Hildon.Entry artist_entry;
+  Hildon.Entry album_entry;
+  //Hildon.Entry description_entry;
+  Hildon.Button location_btn;
+  
+  public SettingsStructures.MixdownSettings get_settings_structure() {
+    SettingsStructures.MixdownSettings settings = SettingsStructures.MixdownSettings();
+    settings.location = location_btn.get_value();
+    settings.encoder = encoder_selector.get_current_text();
+    settings.quality = quality_selector.get_current_text();
+    settings.title = title_entry.get_text();
+    settings.album = album_entry.get_text();
+    settings.artist = artist_entry.get_text();
+    return settings;
+  }
+  public void set_settings_structure(SettingsStructures.MixdownSettings settings) {
+    location_btn.set_value(settings.location);
+    this.set_encoder(settings.encoder);
+    this.set_quality(settings.quality);
+    title_entry.set_text(settings.title);
+    album_entry.set_text(settings.album);
+    artist_entry.set_text(settings.artist);
+  }
+  
+  private void set_encoder(string encoder) {
+    int idx = 0;
+    switch (encoder) {
+      case "vorbisenc":
+        idx = 0;
+        break;
+      case "wavenc":
+        idx = 1;
+        break;
+      case "nokiaaacenc":
+        idx = 2;
+        break;
+      case "mpegaudio":
+        idx = 3;
+        break;
+      case "lame":
+        idx = 4;
+        break;
+      default:
+        idx = 0;
+        break;
+    }
+    encoder_selector.set_active(0, idx);
+  }
+  
+  private void set_quality(string quality) {
+    int idx = 0;
+    switch (quality) {
+      case "high":
+        idx = 0;
+        break;
+      case "medium":
+        idx = 1;
+        break;
+      case "low":
+        idx = 2;
+        break;
+      default:
+        idx = 0;
+        break;
+    }
+    quality_selector.set_active(0, idx);
+  }
+  
+  public MixdownPopUp(string title, Gtk.Widget parent) {
+    this.set_title(title);
+    this.set_parent(parent);    
+    construct_interface(SettingsStructures.MixdownSettings());
+  }
+  public MixdownPopUp.with_settings(string title, Gtk.Widget parent, SettingsStructures.MixdownSettings settings) {
+    this.set_title(title);
+    this.set_parent(parent);
+    construct_interface(settings);
+  }
+  
+  private void construct_interface(SettingsStructures.MixdownSettings settings) {
+    this.set_default_response(Gtk.ResponseType.CANCEL);
+    this.add_button(Gtk.STOCK_OK, Gtk.ResponseType.OK);
+    this.add_button(Gtk.STOCK_CLOSE, Gtk.ResponseType.CANCEL);
+    
+    Gtk.VBox control_area = (Gtk.VBox)this.get_content_area();
+    
+    // location
+    location_btn = new Hildon.Button.with_text(Hildon.SizeType.FINGER_HEIGHT | Hildon.SizeType.HALFSCREEN_WIDTH, Hildon.ButtonArrangement.VERTICAL, "Location", settings.location);
+    location_btn.set_style(Hildon.ButtonStyle.PICKER);
+    location_btn.set_alignment(0, 0, 1, 1);
+    location_btn.clicked.connect(select_location);
+    control_area.pack_start(location_btn, true, true, 2);
+    
+    Gtk.HButtonBox button_bar = new Gtk.HButtonBox();
+    button_bar.set_layout(Gtk.ButtonBoxStyle.START);
+    button_bar.set_homogeneous(false);
+    button_bar.set_spacing(4);
+    
+    // encoder
+    encoder_selector = new Hildon.TouchSelector.text();
+    encoder_selector.append_text("vorbisenc");
+    encoder_selector.append_text("wavenc");
+    encoder_selector.append_text("nokiaaacenc");
+    encoder_selector.append_text("mpegaudio");
+    encoder_selector.append_text("lame");
+    this.set_encoder(settings.encoder);
+    Hildon.PickerButton encoder_picker = new Hildon.PickerButton(Hildon.SizeType.FINGER_HEIGHT | Hildon.SizeType.AUTO_WIDTH, Hildon.ButtonArrangement.VERTICAL);
+    encoder_picker.set_title("Encoder");
+    encoder_picker.set_selector(encoder_selector);
+    //encoder_picker.value_changed.connect( (s) => { this.settings.encoder = s.get_selector().get_current_text(); } );
+    button_bar.pack_start(encoder_picker, true, true, 2);
+    
+    // quality
+    quality_selector = new Hildon.TouchSelector.text();
+    quality_selector.append_text("high");
+    quality_selector.append_text("medium");
+    quality_selector.append_text("low");
+    this.set_quality(settings.quality);
+    Hildon.PickerButton quality_picker = new Hildon.PickerButton(Hildon.SizeType.FINGER_HEIGHT | Hildon.SizeType.AUTO_WIDTH, Hildon.ButtonArrangement.VERTICAL);
+    quality_picker.set_title("Quality");
+    quality_picker.set_selector(quality_selector);
+    //quality_picker.value_changed.connect( (s) => { this.settings.quality = s.get_selector().get_current_text(); } );
+    button_bar.pack_start(quality_picker, true, true, 2);
+    
+    control_area.pack_start(button_bar, true, true, 2);
+    // artist
+    
+    Gtk.HBox artist_bar = new Gtk.HBox(false, 4);
+    
+    Gtk.Label artist_label = new Gtk.Label("Artist");
+    artist_bar.pack_start(artist_label, false, false, 2);
+    artist_entry = new Hildon.Entry(Hildon.SizeType.HALFSCREEN_WIDTH);
+    artist_entry.set_text(settings.artist);
+    artist_entry.set_placeholder("Unknown Artist");
+    artist_bar.pack_start(artist_entry, true, true, 2);
+    
+    control_area.pack_start(artist_bar, true, true, 2);
+        
+    // title
+    Gtk.HBox title_bar = new Gtk.HBox(false, 4);
+    
+    Gtk.Label title_label = new Gtk.Label("Title");
+    title_bar.pack_start(title_label, false, false, 2);
+    title_entry = new Hildon.Entry(Hildon.SizeType.HALFSCREEN_WIDTH);
+    title_entry.set_text(settings.title);
+    title_entry.set_placeholder("Untitled");
+    title_bar.pack_start(title_entry, true, true, 2);
+    
+    control_area.pack_start(title_bar, true, true, 2);
+    
+    // album
+    Gtk.HBox album_bar = new Gtk.HBox(false, 4);
+    
+    Gtk.Label album_label = new Gtk.Label("Album");
+    album_bar.pack_start(album_label, false, false, 2);
+    album_entry = new Hildon.Entry(Hildon.SizeType.HALFSCREEN_WIDTH);
+    album_entry.set_text(settings.album);
+    album_entry.set_placeholder("Untitled");
+    album_bar.pack_start(album_entry, true, true, 2);
+    
+    control_area.pack_start(album_bar, true, true, 2);
+    
+    
+    // description
+    /*Gtk.HBox description_bar = new Gtk.HBox(false, 4);
+    
+    Gtk.Label description_label = new Gtk.Label("Description");
+    description_bar.pack_start(description_label, false, false, 2);
+    description_entry = new Hildon.Entry();
+    description_entry.truncate_multiline = false;
+    description_entry.text = "";
+    description_bar.pack_start(description_entry, true, true, 2);
+    
+    control_area.pack_start(description_bar, true, true, 2);
+    */
+    
+    this.show_all();
+  }
+  
+  private void select_location() {
+    // get a filename
+    Hildon.FileChooserDialog file_chooser = new Hildon.FileChooserDialog(this, Gtk.FileChooserAction.SAVE);
+    file_chooser.set_show_upnp(false);
+    Gtk.ResponseType ret = (Gtk.ResponseType) file_chooser.run();
+    if (Gtk.ResponseType.OK == ret) {
+      this.location_btn.value = file_chooser.get_filename();
+    }
+    file_chooser.destroy ();
+  }
+
+}
+
+}
\ No newline at end of file