ardour
search_path_option.cc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2010 Paul Davis
3 
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.
8 
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.
13 
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.
17 */
18 
19 #include "pbd/strsplit.h"
20 #include "pbd/compose.h"
21 #include "pbd/shortpath.h"
22 
23 #include "search_path_option.h"
24 #include "i18n.h"
25 
26 using namespace std;
27 using namespace Gtk;
28 
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)
33  , _get (get)
34  , _set (set)
35  , add_chooser (_("Select folder to search for media"), FILE_CHOOSER_ACTION_SELECT_FOLDER)
36 {
37  add_chooser.signal_file_set().connect (sigc::mem_fun (*this, &SearchPathOption::path_chosen));
38 
39  HBox* hbox = manage (new HBox);
40 
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);
45  hbox->show_all ();
46 
47  vbox.pack_start (path_box);
48  vbox.pack_end (*hbox);
49 
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 ();
54 
55  path_box.pack_start (session_label);
56 }
57 
59 {
60 
61 
62 }
63 
64 void
66 {
67  string path = add_chooser.get_filename ();
68  add_path (path);
69  changed ();
70 }
71 
72 void
74 {
75  int const n = p->table.property_n_rows();
76  p->table.resize (n + 1, 3);
77 
78  Label* label = manage (new Label);
79  label->set_alignment (0.0, 0.0);
80  label->set_text (string_compose ("%1", _name));
81 
82  p->table.attach (*label, 1, 2, n, n + 1, FILL | EXPAND);
83  p->table.attach (vbox, 2, 3, n, n + 1, FILL | EXPAND);
84 }
85 
86 void
88 {
89  path_box.remove (session_label);
90  for (list<PathEntry*>::iterator p = paths.begin(); p != paths.end(); ++p) {
91  path_box.remove ((*p)->box);
92  delete *p;
93  }
94  paths.clear ();
95 }
96 
97 void
99 {
100  string str = _get ();
101  vector<string> dirs;
102 
103  clear ();
104  path_box.pack_start (session_label);
105 
106  split (str, dirs, G_SEARCHPATH_SEPARATOR);
107 
108  for (vector<string>::iterator d = dirs.begin(); d != dirs.end(); ++d) {
109  add_path (*d);
110  }
111 }
112 
113 void
115 {
116  string str;
117 
118  for (list<PathEntry*>::iterator p = paths.begin(); p != paths.end(); ++p) {
119 
120  if (!str.empty()) {
121  str += G_SEARCHPATH_SEPARATOR;
122  }
123  str += (*p)->entry.get_text ();
124  }
125 
126  _set (str);
127 }
128 
129 void
130 SearchPathOption::add_path (const string& path, bool removable)
131 {
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));
136 }
137 
138 void
140 {
141  path_box.remove (pe->box);
142  paths.remove (pe);
143  delete pe;
144  changed ();
145 }
146 
147 SearchPathOption::PathEntry::PathEntry (const std::string& path, bool removable)
148  : remove_button (Stock::REMOVE)
149 {
150  entry.set_text (path);
151  entry.show ();
152 
153  box.set_spacing (6);
154  box.set_homogeneous (false);
155  box.pack_start (entry, true, true);
156 
157  if (removable) {
158  box.pack_start (remove_button, false, false);
159  remove_button.show ();
160  }
161 
162  box.show ();
163 }
Gtk::FileChooserButton add_chooser
LIBPBD_API void split(std::string, std::vector< std::string > &, char)
Definition: ardour_ui.h:130
PathEntry(const std::string &path, bool removable=true)
SearchPathOption(const std::string &pathname, const std::string &label, const std::string &default_path, sigc::slot< std::string >, sigc::slot< bool, std::string >)
Definition: Beats.hpp:239
#define _(Text)
Definition: i18n.h:11
Gtk::Table table
void add_to_page(OptionEditorPage *)
void add_path(const std::string &path, bool removable=true)
void remove_path(PathEntry *)
std::string _name
LIBPBD_API Glib::ustring short_path(const Glib::ustring &path, Glib::ustring::size_type target_characters)
std::list< PathEntry * > paths
Gtk::Label session_label
sigc::slot< std::string > _get
slot to get the configuration variable's value
sigc::slot< bool, std::string > _set
slot to set the configuration variable's value
std::string string_compose(const std::string &fmt, const T1 &o1)
Definition: compose.h:208