2 * Copyright (C) 2010-2011 Carl Hetherington <carl@carlh.net>
3 * Copyright (C) 2010-2016 Paul Davis <paul@linuxaudiosystems.com>
4 * Copyright (C) 2014 John Emmas <john@creativepost.co.uk>
5 * Copyright (C) 2017-2019 Robin Gareus <robin@gareus.org>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include <gtkmm/stock.h>
24 #include "pbd/strsplit.h"
25 #include "pbd/compose.h"
26 #include "pbd/shortpath.h"
28 #include "gtkmm2ext/utils.h"
30 #include "search_path_option.h"
36 SearchPathOption::SearchPathOption (const string& pathname, const string& label,
37 const string& default_path,
38 sigc::slot<std::string> get, sigc::slot<bool, std::string> set)
39 : Option (pathname, label)
42 , add_chooser (_("Select folder to search for media"), FILE_CHOOSER_ACTION_SELECT_FOLDER)
44 Gtkmm2ext::add_volume_shortcuts (add_chooser);
45 add_chooser.signal_file_set().connect (sigc::mem_fun (*this, &SearchPathOption::path_chosen));
47 HBox* hbox = manage (new HBox);
49 hbox->set_border_width (12);
50 hbox->set_spacing (6);
51 hbox->pack_end (add_chooser, true, true);
52 hbox->pack_end (*manage (new Label (_("Click to add a new location"))), false, false);
55 vbox.pack_start (path_box);
56 vbox.pack_end (*hbox);
58 session_label.set_use_markup (true);
59 session_label.set_markup (string_compose ("<i>%1 (%2)</i>", _("the session folder"), short_path (default_path, 32)));
60 session_label.set_alignment (0.0, 0.5);
61 session_label.show ();
63 path_box.pack_start (session_label);
66 SearchPathOption::~SearchPathOption()
73 SearchPathOption::path_chosen ()
75 string path = add_chooser.get_filename ();
81 SearchPathOption::add_to_page (OptionEditorPage* p)
83 int const n = p->table.property_n_rows();
84 p->table.resize (n + 1, 3);
86 Label* label = manage (new Label);
87 label->set_alignment (0.0, 0.0);
88 label->set_text (string_compose ("%1", _name));
90 p->table.attach (*label, 1, 2, n, n + 1, FILL | EXPAND);
91 p->table.attach (vbox, 2, 3, n, n + 1, FILL | EXPAND);
95 SearchPathOption::clear ()
97 path_box.remove (session_label);
98 for (list<PathEntry*>::iterator p = paths.begin(); p != paths.end(); ++p) {
99 path_box.remove ((*p)->box);
106 SearchPathOption::set_state_from_config ()
108 string str = _get ();
112 path_box.pack_start (session_label);
114 split (str, dirs, G_SEARCHPATH_SEPARATOR);
116 for (vector<string>::iterator d = dirs.begin(); d != dirs.end(); ++d) {
122 SearchPathOption::changed ()
126 for (list<PathEntry*>::iterator p = paths.begin(); p != paths.end(); ++p) {
129 str += G_SEARCHPATH_SEPARATOR;
131 str += (*p)->entry.get_text ();
138 SearchPathOption::add_path (const string& path, bool removable)
140 PathEntry* pe = new PathEntry (path, removable);
141 paths.push_back (pe);
142 path_box.pack_start (pe->box, false, false);
143 pe->remove_button.signal_clicked().connect (sigc::bind (sigc::mem_fun (*this, &SearchPathOption::remove_path), pe));
147 SearchPathOption::remove_path (PathEntry* pe)
149 path_box.remove (pe->box);
155 SearchPathOption::PathEntry::PathEntry (const std::string& path, bool removable)
156 : remove_button (Stock::REMOVE)
158 entry.set_text (path);
162 box.set_homogeneous (false);
163 box.pack_start (entry, true, true);
166 box.pack_start (remove_button, false, false);
167 remove_button.show ();