No-op; fix GPL address and use the explicit-program-name version.
[dcpomatic.git] / src / wx / file_picker_ctrl.cc
1 /*
2     Copyright (C) 2012-2015 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
6     DCP-o-matic is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     DCP-o-matic is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
18
19 */
20
21 #include "file_picker_ctrl.h"
22 #include "wx_util.h"
23 #include <wx/wx.h>
24 #include <wx/stdpaths.h>
25 #include <wx/filepicker.h>
26 #include <boost/filesystem.hpp>
27
28 using namespace std;
29 using namespace boost;
30
31 FilePickerCtrl::FilePickerCtrl (wxWindow* parent, wxString prompt, wxString wildcard)
32         : wxPanel (parent)
33         , _prompt (prompt)
34         , _wildcard (wildcard)
35 {
36         _sizer = new wxBoxSizer (wxHORIZONTAL);
37
38         wxClientDC dc (parent);
39         wxSize size = dc.GetTextExtent (wxT ("This is the length of the file label it should be quite long"));
40         size.SetHeight (-1);
41
42         _file = new wxButton (this, wxID_ANY, _("(None)"), wxDefaultPosition, size, wxBU_LEFT);
43         _sizer->Add (_file, 1, wxEXPAND, 0);
44
45         SetSizerAndFit (_sizer);
46
47         _file->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&FilePickerCtrl::browse_clicked, this));
48 }
49
50 void
51 FilePickerCtrl::SetPath (wxString p)
52 {
53         _path = p;
54
55         if (!_path.IsEmpty ()) {
56                 _file->SetLabel (std_to_wx (filesystem::path (wx_to_std (_path)).leaf().string()));
57         } else {
58                 _file->SetLabel (_("(None)"));
59         }
60
61         wxCommandEvent ev (wxEVT_COMMAND_FILEPICKER_CHANGED, wxID_ANY);
62         GetEventHandler()->ProcessEvent (ev);
63 }
64
65 wxString
66 FilePickerCtrl::GetPath () const
67 {
68         return _path;
69 }
70
71 void
72 FilePickerCtrl::browse_clicked ()
73 {
74         wxFileDialog* d = new wxFileDialog (this, _prompt, wxEmptyString, wxEmptyString, _wildcard);
75         d->SetPath (_path);
76         if (d->ShowModal () == wxID_OK) {
77                 SetPath (d->GetPath ());
78         }
79         d->Destroy ();
80 }