1 /*
2  * Copyright (C) 2010-2011 Carl Hetherington <carl@carlh.net>
3  * Copyright (C) 2011-2016 Paul Davis <paul@linuxaudiosystems.com>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 #include <gtkmm/stock.h>
21 #include "new_plugin_preset_dialog.h"
22 #include "pbd/i18n.h"
23 
24 using namespace std;
25 using namespace Gtk;
26 
NewPluginPresetDialog(boost::shared_ptr<ARDOUR::Plugin> p,std::string title,bool favorite_btn)27 NewPluginPresetDialog::NewPluginPresetDialog (boost::shared_ptr<ARDOUR::Plugin> p, std::string title, bool favorite_btn)
28 	: ArdourDialog (title)
29 	, _replace (_("Replace existing preset with this name"))
30 {
31 	HBox* h = manage (new HBox);
32 	h->set_spacing (6);
33 	h->pack_start (*manage (new Label (_("Name of new preset"))));
34 	h->pack_start (_name);
35 
36 	get_vbox()->set_spacing (6);
37 	get_vbox()->pack_start (*h);
38 
39 	get_vbox()->pack_start (_replace);
40 
41 	add_button (Stock::CANCEL, RESPONSE_CANCEL);
42 	if (favorite_btn) {
43 		add_button (_("New Favorite Only"), RESPONSE_NO);
44 	}
45 	_add = add_button (Stock::ADD, RESPONSE_ACCEPT);
46 	set_default_response (RESPONSE_ACCEPT);
47 	_name.set_activates_default(true);
48 
49 
50 	show_all ();
51 
52 	_presets = p->get_presets ();
53 
54 	_name.signal_changed().connect (sigc::mem_fun (*this, &NewPluginPresetDialog::setup_sensitivity));
55 	_replace.signal_toggled().connect (sigc::mem_fun (*this, &NewPluginPresetDialog::setup_sensitivity));
56 
57 	setup_sensitivity ();
58 }
59 
60 void
setup_sensitivity()61 NewPluginPresetDialog::setup_sensitivity ()
62 {
63 	if (_name.get_text().empty()) {
64 		_replace.set_sensitive (false);
65 		_add->set_sensitive (false);
66 		return;
67 	}
68 
69 	vector<ARDOUR::Plugin::PresetRecord>::const_iterator i = _presets.begin ();
70 	while (i != _presets.end() && i->label != _name.get_text()) {
71 		++i;
72 	}
73 
74 	if (i != _presets.end ()) {
75 		_replace.set_sensitive (true);
76 		_add->set_sensitive (_replace.get_active ());
77 	} else {
78 		_replace.set_sensitive (false);
79 		_add->set_sensitive (true);
80 	}
81 }
82 
83 string
name() const84 NewPluginPresetDialog::name () const
85 {
86 	return _name.get_text ();
87 }
88 
89 bool
replace() const90 NewPluginPresetDialog::replace () const
91 {
92 	return _replace.get_active ();
93 }
94 
95