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 "search_path_option.h"
25 SearchPathOption::SearchPathOption (const string
& pathname
, const string
& label
,
26 sigc::slot
<std::string
> get
, sigc::slot
<bool, std::string
> set
)
27 : Option (pathname
, label
)
30 , add_chooser (_("Select folder to search for media"), FILE_CHOOSER_ACTION_SELECT_FOLDER
)
32 add_chooser
.signal_file_set().connect (sigc::mem_fun (*this, &SearchPathOption::path_chosen
));
34 HBox
* hbox
= manage (new HBox
);
36 hbox
->set_border_width (12);
37 hbox
->set_spacing (6);
38 hbox
->pack_end (add_chooser
, true, true);
39 hbox
->pack_end (*manage (new Label (_("Click to add a new location"))), false, false);
42 vbox
.pack_start (path_box
);
43 vbox
.pack_end (*hbox
);
45 session_label
.set_use_markup (true);
46 session_label
.set_markup (string_compose ("<i>%1</i>", _("the session folder")));
47 session_label
.set_alignment (0.0, 0.5);
48 session_label
.show ();
50 path_box
.pack_start (session_label
);
53 SearchPathOption::~SearchPathOption()
60 SearchPathOption::path_chosen ()
62 string path
= add_chooser
.get_filename ();
68 SearchPathOption::add_to_page (OptionEditorPage
* p
)
70 int const n
= p
->table
.property_n_rows();
71 p
->table
.resize (n
+ 1, 3);
73 Label
* label
= manage (new Label
);
74 label
->set_alignment (0.0, 0.0);
75 label
->set_markup (string_compose ("%1", _name
));
77 p
->table
.attach (*label
, 1, 2, n
, n
+ 1, FILL
| EXPAND
);
78 p
->table
.attach (vbox
, 2, 3, n
, n
+ 1, FILL
| EXPAND
);
82 SearchPathOption::clear ()
84 path_box
.remove (session_label
);
85 for (list
<PathEntry
*>::iterator p
= paths
.begin(); p
!= paths
.end(); ++p
) {
86 path_box
.remove ((*p
)->box
);
93 SearchPathOption::set_state_from_config ()
99 path_box
.pack_start (session_label
);
101 split (str
, dirs
, ':');
103 for (vector
<string
>::iterator d
= dirs
.begin(); d
!= dirs
.end(); ++d
) {
109 SearchPathOption::changed ()
113 for (list
<PathEntry
*>::iterator p
= paths
.begin(); p
!= paths
.end(); ++p
) {
118 str
+= (*p
)->entry
.get_text ();
125 SearchPathOption::add_path (const string
& path
, bool removable
)
127 PathEntry
* pe
= new PathEntry (path
, removable
);
128 paths
.push_back (pe
);
129 path_box
.pack_start (pe
->box
, false, false);
130 pe
->remove_button
.signal_clicked().connect (sigc::bind (sigc::mem_fun (*this, &SearchPathOption::remove_path
), pe
));
134 SearchPathOption::remove_path (PathEntry
* pe
)
136 path_box
.remove (pe
->box
);
142 SearchPathOption::PathEntry::PathEntry (const std::string
& path
, bool removable
)
143 : remove_button (Stock::REMOVE
)
145 entry
.set_text (path
);
149 box
.set_homogeneous (false);
150 box
.pack_start (entry
, true, true);
153 box
.pack_start (remove_button
, false, false);
154 remove_button
.show ();