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 <gtkmm/stock.h>
21 #include "pbd/strsplit.h"
22 #include "pbd/compose.h"
23 #include "pbd/shortpath.h"
25 #include "search_path_option.h"
31 SearchPathOption::SearchPathOption (const string& pathname, const string& label,
32 const string& default_path,
33 sigc::slot<std::string> get, sigc::slot<bool, std::string> set)
34 : Option (pathname, label)
37 , add_chooser (_("Select folder to search for media"), FILE_CHOOSER_ACTION_SELECT_FOLDER)
39 add_chooser.signal_file_set().connect (sigc::mem_fun (*this, &SearchPathOption::path_chosen));
41 HBox* hbox = manage (new HBox);
43 hbox->set_border_width (12);
44 hbox->set_spacing (6);
45 hbox->pack_end (add_chooser, true, true);
46 hbox->pack_end (*manage (new Label (_("Click to add a new location"))), false, false);
49 vbox.pack_start (path_box);
50 vbox.pack_end (*hbox);
52 session_label.set_use_markup (true);
53 session_label.set_markup (string_compose ("<i>%1 (%2)</i>", _("the session folder"), short_path (default_path, 32)));
54 session_label.set_alignment (0.0, 0.5);
55 session_label.show ();
57 path_box.pack_start (session_label);
60 SearchPathOption::~SearchPathOption()
67 SearchPathOption::path_chosen ()
69 string path = add_chooser.get_filename ();
75 SearchPathOption::add_to_page (OptionEditorPage* p)
77 int const n = p->table.property_n_rows();
78 p->table.resize (n + 1, 3);
80 Label* label = manage (new Label);
81 label->set_alignment (0.0, 0.0);
82 label->set_text (string_compose ("%1", _name));
84 p->table.attach (*label, 1, 2, n, n + 1, FILL | EXPAND);
85 p->table.attach (vbox, 2, 3, n, n + 1, FILL | EXPAND);
89 SearchPathOption::clear ()
91 path_box.remove (session_label);
92 for (list<PathEntry*>::iterator p = paths.begin(); p != paths.end(); ++p) {
93 path_box.remove ((*p)->box);
100 SearchPathOption::set_state_from_config ()
102 string str = _get ();
106 path_box.pack_start (session_label);
108 split (str, dirs, G_SEARCHPATH_SEPARATOR);
110 for (vector<string>::iterator d = dirs.begin(); d != dirs.end(); ++d) {
116 SearchPathOption::changed ()
120 for (list<PathEntry*>::iterator p = paths.begin(); p != paths.end(); ++p) {
123 str += G_SEARCHPATH_SEPARATOR;
125 str += (*p)->entry.get_text ();
132 SearchPathOption::add_path (const string& path, bool removable)
134 PathEntry* pe = new PathEntry (path, removable);
135 paths.push_back (pe);
136 path_box.pack_start (pe->box, false, false);
137 pe->remove_button.signal_clicked().connect (sigc::bind (sigc::mem_fun (*this, &SearchPathOption::remove_path), pe));
141 SearchPathOption::remove_path (PathEntry* pe)
143 path_box.remove (pe->box);
149 SearchPathOption::PathEntry::PathEntry (const std::string& path, bool removable)
150 : remove_button (Stock::REMOVE)
152 entry.set_text (path);
156 box.set_homogeneous (false);
157 box.pack_start (entry, true, true);
160 box.pack_start (remove_button, false, false);
161 remove_button.show ();