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 "search_path_option.h"
27 SearchPathOption::SearchPathOption (const string
& pathname
, const string
& label
,
28 sigc::slot
<std::string
> get
, sigc::slot
<bool, std::string
> set
)
29 : Option (pathname
, label
)
32 , add_chooser (_("Select folder to search for media"), FILE_CHOOSER_ACTION_SELECT_FOLDER
)
34 add_chooser
.signal_file_set().connect (sigc::mem_fun (*this, &SearchPathOption::path_chosen
));
36 HBox
* hbox
= manage (new HBox
);
38 hbox
->set_border_width (12);
39 hbox
->set_spacing (6);
40 hbox
->pack_end (add_chooser
, true, true);
41 hbox
->pack_end (*manage (new Label (_("Click to add a new location"))), false, false);
44 vbox
.pack_start (path_box
);
45 vbox
.pack_end (*hbox
);
47 session_label
.set_use_markup (true);
48 session_label
.set_markup (string_compose ("<i>%1</i>", _("the session folder")));
49 session_label
.set_alignment (0.0, 0.5);
50 session_label
.show ();
52 path_box
.pack_start (session_label
);
55 SearchPathOption::~SearchPathOption()
62 SearchPathOption::path_chosen ()
64 string path
= add_chooser
.get_filename ();
70 SearchPathOption::add_to_page (OptionEditorPage
* p
)
72 int const n
= p
->table
.property_n_rows();
73 p
->table
.resize (n
+ 1, 3);
75 Label
* label
= manage (new Label
);
76 label
->set_alignment (0.0, 0.0);
77 label
->set_markup (string_compose ("%1", _name
));
79 p
->table
.attach (*label
, 1, 2, n
, n
+ 1, FILL
| EXPAND
);
80 p
->table
.attach (vbox
, 2, 3, n
, n
+ 1, FILL
| EXPAND
);
84 SearchPathOption::clear ()
86 path_box
.remove (session_label
);
87 for (list
<PathEntry
*>::iterator p
= paths
.begin(); p
!= paths
.end(); ++p
) {
88 path_box
.remove ((*p
)->box
);
95 SearchPathOption::set_state_from_config ()
101 path_box
.pack_start (session_label
);
103 split (str
, dirs
, ':');
105 for (vector
<string
>::iterator d
= dirs
.begin(); d
!= dirs
.end(); ++d
) {
111 SearchPathOption::changed ()
115 for (list
<PathEntry
*>::iterator p
= paths
.begin(); p
!= paths
.end(); ++p
) {
120 str
+= (*p
)->entry
.get_text ();
127 SearchPathOption::add_path (const string
& path
, bool removable
)
129 PathEntry
* pe
= new PathEntry (path
, removable
);
130 paths
.push_back (pe
);
131 path_box
.pack_start (pe
->box
, false, false);
132 pe
->remove_button
.signal_clicked().connect (sigc::bind (sigc::mem_fun (*this, &SearchPathOption::remove_path
), pe
));
136 SearchPathOption::remove_path (PathEntry
* pe
)
138 path_box
.remove (pe
->box
);
144 SearchPathOption::PathEntry::PathEntry (const std::string
& path
, bool removable
)
145 : remove_button (Stock::REMOVE
)
147 entry
.set_text (path
);
151 box
.set_homogeneous (false);
152 box
.pack_start (entry
, true, true);
155 box
.pack_start (remove_button
, false, false);
156 remove_button
.show ();