spek

Acoustic spectrum analyser
git clone http://git.hanabi.in/repos/spek.git
Log | Files | Refs | README

commit 40096483971a5678372729adce322778216cb1f4
parent 093e80037d03cc50a95124e4882c445596f2f003
Author: Alexander Kojevnikov <alexander@kojevnikov.com>
Date:   Sat, 11 Aug 2012 14:46:39 -0700

Open file

Diffstat:
Msrc/spek-window.cc | 55++++++++++++++++++++++++++++++++++++++++++++++++++++++-
Msrc/spek-window.vala | 40----------------------------------------
2 files changed, 54 insertions(+), 41 deletions(-)

diff --git a/src/spek-window.cc b/src/spek-window.cc @@ -75,20 +75,73 @@ SpekWindow::SpekWindow(const wxString& title) : wxFrame(NULL, -1, title) toolbar->Realize(); } +// TODO: s/audio/media/ +static const char *audio_extensions[] = { + "3gp", + "aac", + "aif", + "aifc", + "aiff", + "amr", + "awb", + "ape", + "au", + "dts", + "flac", + "gsm", + "m4a", + "m4p", + "mp3", + "mp4", + "mp+", + "mpc", + "mpp", + "oga", + "ogg", + "ra", + "ram", + "snd", + "wav", + "wma", + "wv", + NULL +}; + void SpekWindow::OnOpen(wxCommandEvent& WXUNUSED(event)) { static wxString cur_dir = wxGetHomeDir(); + static wxString filters = wxEmptyString; + static int filter_index = 1; + + if (filters.IsEmpty()) { + filters.Alloc(1024); + filters += _("All files"); + filters += wxT("|*.*|"); + filters += _("Audio files"); + filters += wxT("|"); + for (int i = 0; audio_extensions[i]; ++i) { + if (i) { + filters += wxT(";"); + } + filters += wxT("*."); + filters += wxString::FromAscii(audio_extensions[i]); + } + filters.Shrink(); + } + wxFileDialog *dlg = new wxFileDialog( this, _("Open File"), cur_dir, wxEmptyString, - wxT("*.*"), + filters, wxFD_OPEN ); + dlg->SetFilterIndex(filter_index); if (dlg->ShowModal() == wxID_OK) { cur_dir = dlg->GetDirectory(); + filter_index = dlg->GetFilterIndex(); Open(dlg->GetPath()); } diff --git a/src/spek-window.vala b/src/spek-window.vala @@ -51,19 +51,10 @@ namespace Spek { info_bar.response.connect(() => info_bar.hide()); spectrogram = new Spectrogram (); - cur_dir = Environment.get_home_dir (); - filter_all = new FileFilter (); - filter_all.set_name (_("All files")); - filter_all.add_pattern ("*"); filter_png = new FileFilter (); filter_png.set_name (_("PNG images")); filter_png.add_pattern ("*.png"); - filter_audio = new FileFilter (); - filter_audio.set_name (_("Audio files")); - foreach (var ext in audio_extensions) { - filter_audio.add_pattern (ext); - } var vbox = new VBox (false, 0); vbox.pack_start (info_bar, false, true, 0); @@ -202,37 +193,6 @@ namespace Spek { Platform.show_uri (link); } - // TODO: s/audio/media/ - private string[] audio_extensions = { - "*.3gp", - "*.aac", - "*.aif", - "*.aifc", - "*.aiff", - "*.amr", - "*.awb", - "*.ape", - "*.au", - "*.dts", - "*.flac", - "*.gsm", - "*.m4a", - "*.m4p", - "*.mp3", - "*.mp4", - "*.mp+", - "*.mpc", - "*.mpp", - "*.oga", - "*.ogg", - "*.ra", - "*.ram", - "*.snd", - "*.wav", - "*.wma", - "*.wv" - }; - private void * check_version () { // Does the user want to check for updates? var prefs = Preferences.instance;