2 Copyright (C) 2010 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 #include "pbd/strsplit.h"
20 #include "pbd/compose.h"
21 #include "pbd/shortpath.h"
23 #include "search_path_option.h"
29 SearchPathOption::SearchPathOption (const string& pathname, const string& label,
30 const string& default_path,
31 sigc::slot<std::string> get, sigc::slot<bool, std::string> set)
32 : Option (pathname, label)
35 , add_chooser (_("Select folder to search for media"), FILE_CHOOSER_ACTION_SELECT_FOLDER)
37 add_chooser.signal_file_set().connect (sigc::mem_fun (*this, &SearchPathOption::path_chosen));
39 HBox* hbox = manage (new HBox);
41 hbox->set_border_width (12);
42 hbox->set_spacing (6);
43 hbox->pack_end (add_chooser, true, true);
44 hbox->pack_end (*manage (new Label (_("Click to add a new location"))), false, false);
47 vbox.pack_start (path_box);
48 vbox.pack_end (*hbox);
50 session_label.set_use_markup (true);
51 session_label.set_markup (string_compose ("<i>%1 (%2)</i>", _("the session folder"), short_path (default_path, 32)));
52 session_label.set_alignment (0.0, 0.5);
53 session_label.show ();
55 path_box.pack_start (session_label);
58 SearchPathOption::~SearchPathOption()
65 SearchPathOption::path_chosen ()
67 string path = add_chooser.get_filename ();
73 SearchPathOption::add_to_page (OptionEditorPage* p)
75 int const n = p->table.property_n_rows();
76 p->table.resize (n + 1, 3);
78 Label* label = manage (new Label);
79 label->set_alignment (0.0, 0.0);
80 label->set_text (string_compose ("%1", _name));
82 p->table.attach (*label, 1, 2, n, n + 1, FILL | EXPAND);
83 p->table.attach (vbox, 2, 3, n, n + 1, FILL | EXPAND);
87 SearchPathOption::clear ()
89 path_box.remove (session_label);
90 for (list<PathEntry*>::iterator p = paths.begin(); p != paths.end(); ++p) {
91 path_box.remove ((*p)->box);
98 SearchPathOption::set_state_from_config ()
100 string str = _get ();
104 path_box.pack_start (session_label);
106 split (str, dirs, G_SEARCHPATH_SEPARATOR);
108 for (vector<string>::iterator d = dirs.begin(); d != dirs.end(); ++d) {
114 SearchPathOption::changed ()
118 for (list<PathEntry*>::iterator p = paths.begin(); p != paths.end(); ++p) {
121 str += G_SEARCHPATH_SEPARATOR;
123 str += (*p)->entry.get_text ();
130 SearchPathOption::add_path (const string& path, bool removable)
132 PathEntry* pe = new PathEntry (path, removable);
133 paths.push_back (pe);
134 path_box.pack_start (pe->box, false, false);
135 pe->remove_button.signal_clicked().connect (sigc::bind (sigc::mem_fun (*this, &SearchPathOption::remove_path), pe));
139 SearchPathOption::remove_path (PathEntry* pe)
141 path_box.remove (pe->box);
147 SearchPathOption::PathEntry::PathEntry (const std::string& path, bool removable)
148 : remove_button (Stock::REMOVE)
150 entry.set_text (path);
154 box.set_homogeneous (false);
155 box.pack_start (entry, true, true);
158 box.pack_start (remove_button, false, false);
159 remove_button.show ();