Use SSE/veclib/whatever for AudioBuffer::accumulate_from
[ardour.git] / libs / gtkmm2ext / pathlist.cc
1 /*
2     Copyright (C) 2006 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
20 #include <gtkmm2ext/pathlist.h>
21
22 #include "i18n.h"
23
24 using namespace std;
25 using namespace Gtkmm2ext;
26
27 PathList::PathList ()
28         :
29         add_btn(_("+")),
30         subtract_btn(_("-")),
31         path_columns(),
32         _store(Gtk::ListStore::create(path_columns)),
33         _view(_store)
34 {
35         _view.append_column(_("Paths"), path_columns.paths);
36         _view.set_size_request(-1, 100);
37         _view.set_headers_visible (false);
38         
39         Gtk::ScrolledWindow* scroll = manage(new Gtk::ScrolledWindow);
40         scroll->set_policy (Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
41         scroll->add(_view);
42         
43         add (*scroll);
44         
45         Gtk::HBox* btn_box = manage(new Gtk::HBox);
46         btn_box->add(add_btn);
47         btn_box->add(subtract_btn);
48
49         add (*btn_box);
50         
51         add_btn.signal_clicked().connect (mem_fun(*this, &PathList::add_btn_clicked));
52         subtract_btn.signal_clicked().connect (mem_fun(*this, &PathList::subtract_btn_clicked));
53         _view.get_selection()->signal_changed().connect (mem_fun(*this, &PathList::selection_changed));
54 }
55
56 vector<string>
57 PathList::get_paths ()
58 {
59         vector<string> paths;
60         
61         Gtk::TreeModel::Children children(_store->children());
62         
63         for (Gtk::TreeIter iter = children.begin(); iter != children.end(); ++iter) {
64                 Gtk::ListStore::Row row = *iter;
65                 
66                 paths.push_back(row[path_columns.paths]);
67         }
68         
69         return paths;
70 }
71
72 void
73 PathList::set_paths (vector<string> paths)
74 {
75         _store->clear();
76         
77         for (vector<string>::iterator i = paths.begin(); i != paths.end(); ++i) {
78                 Gtk::ListStore::iterator iter = _store->append();
79                 Gtk::ListStore::Row row = *iter;
80                 row[path_columns.paths] = *i;
81         }
82 }
83
84 void
85 PathList::add_btn_clicked ()
86 {
87         Gtk::FileChooserDialog path_chooser (_("Path Chooser"), Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER);
88         
89         path_chooser.add_button (Gtk::Stock::ADD, Gtk::RESPONSE_OK);
90         path_chooser.add_button (Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
91         
92         int result = path_chooser.run ();
93         
94         if (result == Gtk::RESPONSE_OK) {
95                 string pathname = path_chooser.get_filename();
96                 
97                 if (pathname.length ()) {
98                         Gtk::ListStore::iterator iter = _store->append ();
99                         Gtk::ListStore::Row row = *iter;
100                         row[path_columns.paths] = pathname;
101                         
102                         PathsUpdated (); // EMIT_SIGNAL
103                 }
104         }
105 }
106
107 void
108 PathList::subtract_btn_clicked ()
109 {
110         Gtk::ListStore::iterator iter = _view.get_selection()->get_selected();
111         _store->erase (iter);
112         
113         PathsUpdated (); // EMIT_SIGNAL
114 }
115
116 void
117 PathList::selection_changed ()
118 {
119         if (_view.get_selection()->count_selected_rows ()) {
120                 subtract_btn.set_sensitive (true);
121         } else {
122                 subtract_btn.set_sensitive (false);
123         }
124 }