fix hover-expand mode for a couple of treeviews; make solo/rec/mute MIDI bindable...
[ardour.git] / gtk2_ardour / new_session_dialog.cc
1 /*
2     Copyright (C) 2005 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     $Id$
19 */
20
21 #include "i18n.h"
22 #include "new_session_dialog.h"
23
24 #include <ardour/recent_sessions.h>
25 #include <ardour/session.h>
26
27 #include <gtkmm/entry.h>
28 #include <gtkmm/filechooserbutton.h>
29 #include <gtkmm/spinbutton.h>
30 #include <gtkmm/checkbutton.h>
31 #include <gtkmm/radiobutton.h>
32 #include <gtkmm/filefilter.h>
33 #include <gtkmm/stock.h>
34 #include <gdkmm/cursor.h>
35
36 #include "opts.h"
37
38 NewSessionDialog::NewSessionDialog()
39         : ArdourDialog ("session control")
40 {
41         session_name_label = Gtk::manage(new class Gtk::Label(_("Name :")));
42         m_name = Gtk::manage(new class Gtk::Entry());
43         m_name->set_text(GTK_ARDOUR::session_name);
44
45         chan_count_label_1 = Gtk::manage(new class Gtk::Label(_("channels")));
46         chan_count_label_2 = Gtk::manage(new class Gtk::Label(_("channels")));
47         chan_count_label_3 = Gtk::manage(new class Gtk::Label(_("channels")));
48         chan_count_label_4 = Gtk::manage(new class Gtk::Label(_("channels")));
49
50         chan_count_label_1->set_alignment(0,0.5);
51         chan_count_label_1->set_padding(0,0);
52         chan_count_label_1->set_line_wrap(false);
53
54         chan_count_label_2->set_alignment(0,0.5);
55         chan_count_label_2->set_padding(0,0);
56         chan_count_label_2->set_line_wrap(false);
57
58         chan_count_label_3->set_alignment(0,0.5);
59         chan_count_label_3->set_padding(0,0);
60         chan_count_label_3->set_line_wrap(false);
61
62         chan_count_label_4->set_alignment(0,0.5);
63         chan_count_label_4->set_padding(0,0);
64         chan_count_label_4->set_line_wrap(false);
65
66         bus_label = Gtk::manage(new class Gtk::Label(_("<b>Busses</b>")));
67         input_label = Gtk::manage(new class Gtk::Label(_("<b>Inputs</b>")));
68         output_label = Gtk::manage(new class Gtk::Label(_("<b>Outputs</b>")));
69
70         session_location_label = Gtk::manage(new class Gtk::Label(_("Create Folder In :")));
71         m_folder = Gtk::manage(new class Gtk::FileChooserButton(Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER));
72         session_template_label = Gtk::manage(new class Gtk::Label(_("Template :")));
73         m_template = Gtk::manage(new class Gtk::FileChooserButton());
74         m_create_control_bus = Gtk::manage(new class Gtk::CheckButton(_("Create Monitor Bus")));
75         
76         Gtk::Adjustment *m_control_bus_channel_count_adj = Gtk::manage(new class Gtk::Adjustment(2, 0, 100, 1, 10, 10));
77         m_control_bus_channel_count = Gtk::manage(new class Gtk::SpinButton(*m_control_bus_channel_count_adj, 1, 0));
78         
79         Gtk::Adjustment *m_master_bus_channel_count_adj = Gtk::manage(new class Gtk::Adjustment(2, 0, 100, 1, 10, 10));
80         m_master_bus_channel_count = Gtk::manage(new class Gtk::SpinButton(*m_master_bus_channel_count_adj, 1, 0));
81         m_create_master_bus = Gtk::manage(new class Gtk::CheckButton(_("Create Master Bus")));
82         advanced_table = Gtk::manage(new class Gtk::Table(2, 2, true));
83         m_connect_inputs = Gtk::manage(new class Gtk::CheckButton(_("Automatically Connect to Physical Inputs")));
84         m_limit_input_ports = Gtk::manage(new class Gtk::CheckButton(_("Use only")));
85         
86         Gtk::Adjustment *m_input_limit_count_adj = Gtk::manage(new class Gtk::Adjustment(1, 0, 100, 1, 10, 10));
87         m_input_limit_count = Gtk::manage(new class Gtk::SpinButton(*m_input_limit_count_adj, 1, 0));
88         input_port_limit_hbox = Gtk::manage(new class Gtk::HBox(false, 0));
89         input_port_vbox = Gtk::manage(new class Gtk::VBox(false, 0));
90         input_table = Gtk::manage(new class Gtk::Table(2, 2, false));
91
92         bus_frame = Gtk::manage(new class Gtk::Frame());
93         bus_table = Gtk::manage (new Gtk::Table (2, 3, false));
94
95         input_frame = Gtk::manage(new class Gtk::Frame());
96         m_connect_outputs = Gtk::manage(new class Gtk::CheckButton(_("Automatically Connect Outputs")));
97         m_limit_output_ports = Gtk::manage(new class Gtk::CheckButton(_("Use only")));
98         
99         Gtk::Adjustment *m_output_limit_count_adj = Gtk::manage(new class Gtk::Adjustment(1, 0, 100, 1, 10, 10));
100         m_output_limit_count = Gtk::manage(new class Gtk::SpinButton(*m_output_limit_count_adj, 1, 0));
101         output_port_limit_hbox = Gtk::manage(new class Gtk::HBox(false, 0));
102         output_port_vbox = Gtk::manage(new class Gtk::VBox(false, 0));
103         
104         Gtk::RadioButton::Group _RadioBGroup_m_connect_outputs_to_master;
105         m_connect_outputs_to_master = Gtk::manage(new class Gtk::RadioButton(_RadioBGroup_m_connect_outputs_to_master, _("... to Master Bus")));
106         m_connect_outputs_to_physical = Gtk::manage(new class Gtk::RadioButton(_RadioBGroup_m_connect_outputs_to_master, _("... to Physical Outputs")));
107         output_conn_vbox = Gtk::manage(new class Gtk::VBox(false, 0));
108         output_vbox = Gtk::manage(new class Gtk::VBox(false, 0));
109
110         output_frame = Gtk::manage(new class Gtk::Frame());
111         advanced_vbox = Gtk::manage(new class Gtk::VBox(false, 0));
112         advanced_label = Gtk::manage(new class Gtk::Label(_("Advanced Options")));
113         advanced_expander = Gtk::manage(new class Gtk::Expander());
114         new_session_table = Gtk::manage(new class Gtk::Table(2, 2, false));
115         m_open_filechooser = Gtk::manage(new class Gtk::FileChooserButton());
116         open_session_hbox = Gtk::manage(new class Gtk::HBox(false, 0));
117         m_treeview = Gtk::manage(new class Gtk::TreeView());
118         recent_scrolledwindow = Gtk::manage(new class Gtk::ScrolledWindow());
119
120         recent_sesion_label = Gtk::manage(new class Gtk::Label(_("Recent:")));
121         recent_frame = Gtk::manage(new class Gtk::Frame());
122         open_session_vbox = Gtk::manage(new class Gtk::VBox(false, 0));
123         m_notebook = Gtk::manage(new class Gtk::Notebook());
124         session_name_label->set_alignment(0, 0.5);
125         session_name_label->set_padding(6,0);
126         session_name_label->set_line_wrap(false);
127         session_name_label->set_selectable(false);
128         m_name->set_editable(true);
129         m_name->set_max_length(0);
130         m_name->set_has_frame(true);
131         m_name->set_activates_default(true);
132         m_name->set_width_chars (40);
133         session_location_label->set_alignment(0,0.5);
134         session_location_label->set_padding(6,0);
135         session_location_label->set_line_wrap(false);
136         session_location_label->set_selectable(false);
137         session_template_label->set_alignment(0,0.5);
138         session_template_label->set_padding(6,0);
139         session_template_label->set_line_wrap(false);
140         session_template_label->set_selectable(false);
141         m_create_control_bus->set_flags(Gtk::CAN_FOCUS);
142         m_create_control_bus->set_relief(Gtk::RELIEF_NORMAL);
143         m_create_control_bus->set_mode(true);
144         m_create_control_bus->set_active(false);
145         m_create_control_bus->set_border_width(0);
146         m_control_bus_channel_count->set_flags(Gtk::CAN_FOCUS);
147         m_control_bus_channel_count->set_update_policy(Gtk::UPDATE_ALWAYS);
148         m_control_bus_channel_count->set_numeric(true);
149         m_control_bus_channel_count->set_digits(0);
150         m_control_bus_channel_count->set_wrap(false);
151         m_control_bus_channel_count->set_sensitive(false);
152         m_master_bus_channel_count->set_flags(Gtk::CAN_FOCUS);
153         m_master_bus_channel_count->set_update_policy(Gtk::UPDATE_ALWAYS);
154         m_master_bus_channel_count->set_numeric(true);
155         m_master_bus_channel_count->set_digits(0);
156         m_master_bus_channel_count->set_wrap(false);
157         open_session_file_label = Gtk::manage(new class Gtk::Label(_("Browse:")));
158         open_session_file_label->set_alignment(0, 0.5);
159         m_create_master_bus->set_flags(Gtk::CAN_FOCUS);
160         m_create_master_bus->set_relief(Gtk::RELIEF_NORMAL);
161         m_create_master_bus->set_mode(true);
162         m_create_master_bus->set_active(true);
163         m_create_master_bus->set_border_width(0);
164         advanced_table->set_row_spacings(0);
165         advanced_table->set_col_spacings(0);
166
167         m_connect_inputs->set_flags(Gtk::CAN_FOCUS);
168         m_connect_inputs->set_relief(Gtk::RELIEF_NORMAL);
169         m_connect_inputs->set_mode(true);
170         m_connect_inputs->set_active(true);
171         m_connect_inputs->set_border_width(0);
172
173         m_limit_input_ports->set_flags(Gtk::CAN_FOCUS);
174         m_limit_input_ports->set_relief(Gtk::RELIEF_NORMAL);
175         m_limit_input_ports->set_mode(true);
176         m_limit_input_ports->set_sensitive(true);
177         m_limit_input_ports->set_border_width(0);
178         m_input_limit_count->set_flags(Gtk::CAN_FOCUS);
179         m_input_limit_count->set_update_policy(Gtk::UPDATE_ALWAYS);
180         m_input_limit_count->set_numeric(true);
181         m_input_limit_count->set_digits(0);
182         m_input_limit_count->set_wrap(false);
183         m_input_limit_count->set_sensitive(false);
184
185         bus_hbox = Gtk::manage (new Gtk::HBox (false, 0));
186         bus_hbox->pack_start (*bus_table, Gtk::PACK_SHRINK, 18);
187
188         bus_label->set_alignment(0, 0.5);
189         bus_label->set_padding(0,0);
190         bus_label->set_line_wrap(false);
191         bus_label->set_selectable(false);
192         bus_label->set_use_markup(true);
193         bus_frame->set_shadow_type(Gtk::SHADOW_NONE);
194         bus_frame->set_label_align(0,0.5);
195         bus_frame->add(*bus_hbox);
196         bus_frame->set_label_widget(*bus_label);
197         
198         bus_table->set_row_spacings (0);
199         bus_table->set_col_spacings (0);
200         bus_table->attach (*m_create_master_bus, 0, 1, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
201         bus_table->attach (*m_master_bus_channel_count, 1, 2, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
202         bus_table->attach (*chan_count_label_1, 2, 3, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 6, 0);
203         bus_table->attach (*m_create_control_bus, 0, 1, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
204         bus_table->attach (*m_control_bus_channel_count, 1, 2, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
205         bus_table->attach (*chan_count_label_2, 2, 3, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 6, 0);
206
207         input_port_limit_hbox->pack_start(*m_limit_input_ports, Gtk::PACK_SHRINK, 6);
208         input_port_limit_hbox->pack_start(*m_input_limit_count, Gtk::PACK_SHRINK, 0);
209         input_port_limit_hbox->pack_start(*chan_count_label_3, Gtk::PACK_SHRINK, 6);
210         input_port_vbox->pack_start(*m_connect_inputs, Gtk::PACK_SHRINK, 0);
211         input_port_vbox->pack_start(*input_port_limit_hbox, Gtk::PACK_EXPAND_PADDING, 0);
212         input_table->set_row_spacings(0);
213         input_table->set_col_spacings(0);
214         input_table->attach(*input_port_vbox, 0, 1, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 6, 6);
215
216         input_hbox = Gtk::manage (new Gtk::HBox (false, 0));
217         input_hbox->pack_start (*input_table, Gtk::PACK_SHRINK, 18);
218
219         input_label->set_alignment(0, 0.5);
220         input_label->set_padding(0,0);
221         input_label->set_line_wrap(false);
222         input_label->set_selectable(false);
223         input_label->set_use_markup(true);
224         input_frame->set_shadow_type(Gtk::SHADOW_NONE);
225         input_frame->set_label_align(0,0.5);
226         input_frame->add(*input_hbox);
227         input_frame->set_label_widget(*input_label);
228
229         m_connect_outputs->set_flags(Gtk::CAN_FOCUS);
230         m_connect_outputs->set_relief(Gtk::RELIEF_NORMAL);
231         m_connect_outputs->set_mode(true);
232         m_connect_outputs->set_active(true);
233         m_connect_outputs->set_border_width(0);
234         m_limit_output_ports->set_flags(Gtk::CAN_FOCUS);
235         m_limit_output_ports->set_relief(Gtk::RELIEF_NORMAL);
236         m_limit_output_ports->set_mode(true);
237         m_limit_output_ports->set_sensitive(true);
238         m_limit_output_ports->set_border_width(0);
239         m_output_limit_count->set_flags(Gtk::CAN_FOCUS);
240         m_output_limit_count->set_update_policy(Gtk::UPDATE_ALWAYS);
241         m_output_limit_count->set_numeric(false);
242         m_output_limit_count->set_digits(0);
243         m_output_limit_count->set_wrap(false);
244         m_output_limit_count->set_sensitive(false);
245         output_port_limit_hbox->pack_start(*m_limit_output_ports, Gtk::PACK_SHRINK, 6);
246         output_port_limit_hbox->pack_start(*m_output_limit_count, Gtk::PACK_SHRINK, 0);
247         output_port_limit_hbox->pack_start(*chan_count_label_4, Gtk::PACK_SHRINK, 6);
248         m_connect_outputs_to_master->set_flags(Gtk::CAN_FOCUS);
249         m_connect_outputs_to_master->set_relief(Gtk::RELIEF_NORMAL);
250         m_connect_outputs_to_master->set_mode(true);
251         m_connect_outputs_to_master->set_active(false);
252         m_connect_outputs_to_master->set_border_width(0);
253         m_connect_outputs_to_physical->set_flags(Gtk::CAN_FOCUS);
254         m_connect_outputs_to_physical->set_relief(Gtk::RELIEF_NORMAL);
255         m_connect_outputs_to_physical->set_mode(true);
256         m_connect_outputs_to_physical->set_active(false);
257         m_connect_outputs_to_physical->set_border_width(0);
258         output_conn_vbox->pack_start(*m_connect_outputs, Gtk::PACK_SHRINK, 0);
259         output_conn_vbox->pack_start(*m_connect_outputs_to_master, Gtk::PACK_SHRINK, 0);
260         output_conn_vbox->pack_start(*m_connect_outputs_to_physical, Gtk::PACK_SHRINK, 0);
261         output_vbox->set_border_width(6);
262
263         output_port_vbox->pack_start(*output_port_limit_hbox, Gtk::PACK_SHRINK, 0);
264
265         output_vbox->pack_start(*output_conn_vbox);
266         output_vbox->pack_start(*output_port_vbox);
267
268         output_label->set_alignment(0, 0.5);
269         output_label->set_padding(0,0);
270         output_label->set_line_wrap(false);
271         output_label->set_selectable(false);
272         output_label->set_use_markup(true);
273         output_frame->set_shadow_type(Gtk::SHADOW_NONE);
274         output_frame->set_label_align(0,0.5);
275
276         output_hbox = Gtk::manage (new Gtk::HBox (false, 0));
277         output_hbox->pack_start (*output_vbox, Gtk::PACK_SHRINK, 18);
278
279         output_frame->add(*output_hbox);
280         output_frame->set_label_widget(*output_label);
281
282         advanced_vbox->pack_start(*advanced_table, Gtk::PACK_SHRINK, 0);
283         advanced_vbox->pack_start(*bus_frame, Gtk::PACK_SHRINK, 6);
284         advanced_vbox->pack_start(*input_frame, Gtk::PACK_SHRINK, 6);
285         advanced_vbox->pack_start(*output_frame, Gtk::PACK_SHRINK, 0);
286         advanced_label->set_padding(0,0);
287         advanced_label->set_line_wrap(false);
288         advanced_label->set_selectable(false);
289         advanced_label->set_alignment(0, 0.5);
290         advanced_expander->set_flags(Gtk::CAN_FOCUS);
291         advanced_expander->set_border_width(0);
292         advanced_expander->set_expanded(false);
293         advanced_expander->set_spacing(0);
294         advanced_expander->add(*advanced_vbox);
295         advanced_expander->set_label_widget(*advanced_label);
296         new_session_table->set_border_width(12);
297         new_session_table->set_row_spacings(6);
298         new_session_table->set_col_spacings(0);
299         new_session_table->attach(*session_name_label, 0, 1, 0, 1, Gtk::FILL, Gtk::FILL, 0, 0);
300         new_session_table->attach(*m_name, 1, 2, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::FILL, 0, 0);
301         new_session_table->attach(*session_location_label, 0, 1, 1, 2, Gtk::FILL, Gtk::FILL, 0, 0);
302         new_session_table->attach(*m_folder, 1, 2, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::FILL, 0, 0);
303         new_session_table->attach(*session_template_label, 0, 1, 2, 3, Gtk::FILL, Gtk::FILL, 0, 0);
304         new_session_table->attach(*m_template, 1, 2, 2, 3, Gtk::EXPAND|Gtk::FILL, Gtk::FILL, 0, 0);
305         new_session_table->attach(*advanced_expander, 0, 2, 3, 4, Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 6);
306
307         open_session_hbox->pack_start(*open_session_file_label, false, false, 12);
308         open_session_hbox->pack_start(*m_open_filechooser, true, true, 12);
309         m_treeview->set_flags(Gtk::CAN_FOCUS);
310         m_treeview->set_headers_visible(true);
311         m_treeview->set_rules_hint(false);
312         m_treeview->set_reorderable(false);
313         m_treeview->set_enable_search(true);
314         m_treeview->set_fixed_height_mode(false);
315         m_treeview->set_hover_selection(false);
316         m_treeview->set_size_request(-1, 150);
317         recent_scrolledwindow->set_flags(Gtk::CAN_FOCUS);
318         recent_scrolledwindow->set_border_width(6);
319         recent_scrolledwindow->set_shadow_type(Gtk::SHADOW_IN);
320         recent_scrolledwindow->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
321         recent_scrolledwindow->property_window_placement().set_value(Gtk::CORNER_TOP_LEFT);
322         recent_scrolledwindow->add(*m_treeview);
323
324         recent_sesion_label->set_padding(0,0);
325         recent_sesion_label->set_line_wrap(false);
326         recent_sesion_label->set_selectable(false);
327         recent_frame->set_border_width(12);
328         recent_frame->set_shadow_type(Gtk::SHADOW_NONE);
329         recent_frame->add(*recent_scrolledwindow);
330         recent_frame->set_label_widget(*recent_sesion_label);
331         open_session_vbox->pack_start(*recent_frame, Gtk::PACK_EXPAND_WIDGET, 0);
332         open_session_vbox->pack_start(*open_session_hbox, Gtk::PACK_SHRINK, 12);
333         m_notebook->set_flags(Gtk::CAN_FOCUS);
334         m_notebook->set_scrollable(true);
335         m_notebook->append_page(*new_session_table, _("New Session"));
336         m_notebook->pages().back().set_tab_label_packing(false, true, Gtk::PACK_START);
337         m_notebook->append_page(*open_session_vbox, _("Open Session"));
338         m_notebook->pages().back().set_tab_label_packing(false, true, Gtk::PACK_START);
339         get_vbox()->set_homogeneous(false);
340         get_vbox()->set_spacing(0);
341         get_vbox()->pack_start(*m_notebook, Gtk::PACK_SHRINK, 0);
342         set_title(_("ardour: session control"));
343         //set_modal(false);
344         //property_window_position().set_value(Gtk::WIN_POS_NONE);
345         set_resizable(false);
346         //property_destroy_with_parent().set_value(false);
347         set_has_separator(false);
348         // add_button(Gtk::Stock::HELP, Gtk::RESPONSE_HELP);
349         add_button(Gtk::Stock::QUIT, Gtk::RESPONSE_CANCEL);
350         add_button(Gtk::Stock::CLEAR, Gtk::RESPONSE_NONE);
351         m_okbutton = add_button(Gtk::Stock::NEW, Gtk::RESPONSE_OK);
352
353         recent_model = Gtk::TreeStore::create (recent_columns);
354         m_treeview->set_model (recent_model);
355         m_treeview->append_column (_("Recent Sessions"), recent_columns.visible_name);
356         m_treeview->set_headers_visible (false);
357         m_treeview->get_selection()->set_mode (Gtk::SELECTION_SINGLE);
358
359         std::string path = ARDOUR::get_user_ardour_path();
360         if (path.empty()) {
361                 path = ARDOUR::get_system_data_path();
362         }
363         if (!path.empty()) {
364                 m_template->set_current_folder (path + X_("templates/"));
365         }
366
367         const std::string sys_templates_dir = ARDOUR::get_system_data_path() + X_("templates");
368         if (Glib::file_test(sys_templates_dir, Glib::FILE_TEST_IS_DIR))
369                 m_template->add_shortcut_folder(sys_templates_dir);
370         
371         m_template->set_title(_("select template"));
372         Gtk::FileFilter* session_filter = manage (new (Gtk::FileFilter));
373         session_filter->add_pattern(X_("*.ardour"));
374         session_filter->add_pattern(X_("*.ardour.bak"));
375         m_open_filechooser->set_filter (*session_filter);
376         m_open_filechooser->set_current_folder(getenv ("HOME"));
377         m_open_filechooser->set_title(_("select session file"));
378
379         Gtk::FileFilter* template_filter = manage (new (Gtk::FileFilter));
380         template_filter->add_pattern(X_("*.ardour"));
381         template_filter->add_pattern(X_("*.ardour.bak"));
382         template_filter->add_pattern(X_("*.template"));
383         m_template->set_filter (*template_filter);
384
385         m_folder->set_current_folder(getenv ("HOME"));
386         m_folder->set_title(_("select directory"));
387
388         on_new_session_page = true;
389         m_notebook->set_current_page(0);
390         m_notebook->show();
391         m_notebook->show_all_children();
392
393
394         set_default_response (Gtk::RESPONSE_OK);
395         if (!GTK_ARDOUR::session_name.length()) {
396                 set_response_sensitive (Gtk::RESPONSE_OK, false);
397                 set_response_sensitive (Gtk::RESPONSE_NONE, false);
398         } else {
399                 set_response_sensitive (Gtk::RESPONSE_OK, true);
400                 set_response_sensitive (Gtk::RESPONSE_NONE, true);
401         }
402
403         ///@ connect some signals
404
405         m_connect_inputs->signal_clicked().connect (mem_fun (*this, &NewSessionDialog::connect_inputs_clicked));
406         m_connect_outputs->signal_clicked().connect (mem_fun (*this, &NewSessionDialog::connect_outputs_clicked));
407         m_limit_input_ports->signal_clicked().connect (mem_fun (*this, &NewSessionDialog::limit_inputs_clicked));
408         m_limit_output_ports->signal_clicked().connect (mem_fun (*this, &NewSessionDialog::limit_outputs_clicked));
409         m_create_master_bus->signal_clicked().connect (mem_fun (*this, &NewSessionDialog::master_bus_button_clicked));
410         m_create_control_bus->signal_clicked().connect (mem_fun (*this, &NewSessionDialog::monitor_bus_button_clicked));
411         m_name->signal_key_release_event().connect(mem_fun (*this, &NewSessionDialog::entry_key_release));
412         m_notebook->signal_switch_page().connect (mem_fun (*this, &NewSessionDialog::notebook_page_changed));
413         m_treeview->get_selection()->signal_changed().connect (mem_fun (*this, &NewSessionDialog::treeview_selection_changed));
414         m_treeview->signal_row_activated().connect (mem_fun (*this, &NewSessionDialog::recent_row_activated));
415         m_open_filechooser->signal_selection_changed ().connect (mem_fun (*this, &NewSessionDialog::file_chosen));
416         m_template->signal_selection_changed ().connect (mem_fun (*this, &NewSessionDialog::template_chosen));
417         m_name->grab_focus();
418 }
419
420 void
421 NewSessionDialog::set_session_name(const Glib::ustring& name)
422 {
423         m_name->set_text(name);
424 }
425
426 std::string
427 NewSessionDialog::session_name() const
428 {
429         std::string str = Glib::filename_from_utf8(m_open_filechooser->get_filename());
430         std::string::size_type position = str.find_last_of ('/');
431         str = str.substr (position+1);
432         position = str.find_last_of ('.');
433         str = str.substr (0, position);
434
435         /*
436           XXX what to do if it's a .bak file?
437           load_session doesn't allow it!
438
439         if ((position = str.rfind(".bak")) != string::npos) {
440                 str = str.substr (0, position);
441         }         
442         */
443
444         if (m_notebook->get_current_page() == 0) {
445                 return Glib::filename_from_utf8(m_name->get_text());
446         } else {
447                 if (m_treeview->get_selection()->count_selected_rows() == 0) {
448                         return Glib::filename_from_utf8(str);
449                 }
450                 Gtk::TreeModel::iterator i = m_treeview->get_selection()->get_selected();
451                 return (*i)[recent_columns.visible_name];
452         }
453 }
454
455 std::string
456 NewSessionDialog::session_folder() const
457 {
458         if (m_notebook->get_current_page() == 0) {
459                 return Glib::filename_from_utf8(m_folder->get_current_folder());
460         } else {
461                
462                 if (m_treeview->get_selection()->count_selected_rows() == 0) {
463                         return Glib::filename_from_utf8(m_open_filechooser->get_current_folder());
464                 }
465                 Gtk::TreeModel::iterator i = m_treeview->get_selection()->get_selected();
466                 return (*i)[recent_columns.fullpath];
467         }
468 }
469
470 bool
471 NewSessionDialog::use_session_template() const
472 {
473         if(m_template->get_filename().empty() && (m_notebook->get_current_page() == 0)) return false;
474         return true;
475 }
476
477 std::string
478 NewSessionDialog::session_template_name() const
479 {
480         return Glib::filename_from_utf8(m_template->get_filename());
481 }
482
483 bool
484 NewSessionDialog::create_master_bus() const
485 {
486         return m_create_master_bus->get_active();
487 }
488
489 int
490 NewSessionDialog::master_channel_count() const
491 {
492         return m_master_bus_channel_count->get_value_as_int();
493 }
494
495 bool
496 NewSessionDialog::create_control_bus() const
497 {
498         return m_create_control_bus->get_active();
499 }
500
501 int
502 NewSessionDialog::control_channel_count() const
503 {
504         return m_control_bus_channel_count->get_value_as_int();
505 }
506
507 bool
508 NewSessionDialog::connect_inputs() const
509 {
510         return m_connect_inputs->get_active();
511 }
512
513 bool
514 NewSessionDialog::limit_inputs_used_for_connection() const
515 {
516         return m_limit_input_ports->get_active();
517 }
518
519 int
520 NewSessionDialog::input_limit_count() const
521 {
522         return m_input_limit_count->get_value_as_int();
523 }
524
525 bool
526 NewSessionDialog::connect_outputs() const
527 {
528         return m_connect_outputs->get_active();
529 }
530
531 bool
532 NewSessionDialog::limit_outputs_used_for_connection() const
533 {
534         return m_limit_output_ports->get_active();
535 }
536
537 int
538 NewSessionDialog::output_limit_count() const
539 {
540         return m_output_limit_count->get_value_as_int();
541 }
542
543 bool
544 NewSessionDialog::connect_outs_to_master() const
545 {
546         return m_connect_outputs_to_master->get_active();
547 }
548
549 bool
550 NewSessionDialog::connect_outs_to_physical() const
551 {
552         return m_connect_outputs_to_physical->get_active();
553 }
554
555 int
556 NewSessionDialog::get_current_page()
557 {
558         return m_notebook->get_current_page();
559         
560 }
561
562 void
563 NewSessionDialog::reset_name()
564 {
565         m_name->set_text("");
566         set_response_sensitive (Gtk::RESPONSE_OK, false);
567         
568 }
569
570 bool
571 NewSessionDialog::entry_key_release (GdkEventKey* ev)
572 {
573         if (m_name->get_text() != "") {
574                 set_response_sensitive (Gtk::RESPONSE_OK, true);
575                 set_response_sensitive (Gtk::RESPONSE_NONE, true);
576         } else {
577                 set_response_sensitive (Gtk::RESPONSE_OK, false);
578         }
579         return true;
580 }
581
582 void
583 NewSessionDialog::notebook_page_changed (GtkNotebookPage* np, uint pagenum)
584 {
585         if (pagenum == 1) {
586                 on_new_session_page = false;
587                 m_okbutton->set_label(_("Open"));
588                 set_response_sensitive (Gtk::RESPONSE_NONE, false);
589                 m_okbutton->set_image (*(new Gtk::Image (Gtk::Stock::OPEN, Gtk::ICON_SIZE_BUTTON)));
590                 if (m_treeview->get_selection()->count_selected_rows() == 0) {
591                         set_response_sensitive (Gtk::RESPONSE_OK, false);
592                 } else {
593                         set_response_sensitive (Gtk::RESPONSE_OK, true);
594                 }
595         } else {
596                 on_new_session_page = true;
597                 if (m_name->get_text() != "") {
598                         set_response_sensitive (Gtk::RESPONSE_NONE, true);
599                 }
600                 m_okbutton->set_label(_("New"));
601                 m_okbutton->set_image (*(new Gtk::Image (Gtk::Stock::NEW, Gtk::ICON_SIZE_BUTTON)));
602                 if (m_name->get_text() == "") {
603                         set_response_sensitive (Gtk::RESPONSE_OK, false);
604                 } else {
605                         set_response_sensitive (Gtk::RESPONSE_OK, true);
606                 }
607         }
608 }
609
610 void
611 NewSessionDialog::treeview_selection_changed ()
612 {
613         if (m_treeview->get_selection()->count_selected_rows() == 0) {
614                 if (!m_open_filechooser->get_filename().empty()) {
615                         set_response_sensitive (Gtk::RESPONSE_OK, true);
616                 } else {
617                         set_response_sensitive (Gtk::RESPONSE_OK, false);
618                 }
619         } else {
620                 set_response_sensitive (Gtk::RESPONSE_OK, true);
621         }
622 }
623
624 void
625 NewSessionDialog::file_chosen ()
626 {
627         if (on_new_session_page) return;
628
629         m_treeview->get_selection()->unselect_all();
630
631         get_window()->set_cursor(Gdk::Cursor(Gdk::WATCH));
632
633         if (!m_open_filechooser->get_filename().empty()) {
634                 set_response_sensitive (Gtk::RESPONSE_OK, true);
635                 response (Gtk::RESPONSE_OK);
636         } else {
637                 set_response_sensitive (Gtk::RESPONSE_OK, false);
638         }
639 }
640
641 void
642 NewSessionDialog::template_chosen ()
643 {
644         if (m_template->get_filename() != "" ) {;
645                 set_response_sensitive (Gtk::RESPONSE_NONE, true);
646         } else {
647                 set_response_sensitive (Gtk::RESPONSE_NONE, false);
648         }
649 }
650
651 void
652 NewSessionDialog::recent_row_activated (const Gtk::TreePath& path, Gtk::TreeViewColumn* col)
653 {
654         response (Gtk::RESPONSE_YES);
655 }
656
657 void
658 NewSessionDialog::connect_inputs_clicked ()
659 {
660         m_limit_input_ports->set_sensitive(m_connect_inputs->get_active());
661
662                 if (m_connect_inputs->get_active() && m_limit_input_ports->get_active()) {
663                 m_input_limit_count->set_sensitive(true);
664                 } else {
665                 m_input_limit_count->set_sensitive(false);
666                 }
667 }
668
669 void
670 NewSessionDialog::connect_outputs_clicked ()
671 {
672         m_limit_output_ports->set_sensitive(m_connect_outputs->get_active());
673
674                 if (m_connect_outputs->get_active() && m_limit_output_ports->get_active()) {
675                 m_output_limit_count->set_sensitive(true);
676                 } else {
677                 m_output_limit_count->set_sensitive(false);
678                 }
679 }
680
681 void
682 NewSessionDialog::limit_inputs_clicked ()
683 {
684         m_input_limit_count->set_sensitive(m_limit_input_ports->get_active());
685 }
686
687 void
688 NewSessionDialog::limit_outputs_clicked ()
689 {
690         m_output_limit_count->set_sensitive(m_limit_output_ports->get_active());
691 }
692
693 void
694 NewSessionDialog::master_bus_button_clicked ()
695 {
696         m_master_bus_channel_count->set_sensitive(m_create_master_bus->get_active());
697 }
698
699 void
700 NewSessionDialog::monitor_bus_button_clicked ()
701 {
702         m_control_bus_channel_count->set_sensitive(m_create_control_bus->get_active());
703 }
704
705 void
706 NewSessionDialog::reset_template()
707 {
708         m_template->set_filename("");
709 }
710
711 void
712 NewSessionDialog::reset_recent()
713 {
714         /* Shamelessly ripped from ardour_ui.cc */
715         std::vector<string *> *sessions;
716         std::vector<string *>::iterator i;
717         RecentSessionsSorter cmp;
718         
719         recent_model->clear ();
720
721         ARDOUR::RecentSessions rs;
722         ARDOUR::read_recent_sessions (rs);
723         
724         /* sort them alphabetically */
725         sort (rs.begin(), rs.end(), cmp);
726         sessions = new std::vector<std::string*>;
727         
728         for (ARDOUR::RecentSessions::iterator i = rs.begin(); i != rs.end(); ++i) {
729                 sessions->push_back (new string ((*i).second));
730         }
731         
732         for (i = sessions->begin(); i != sessions->end(); ++i) {
733
734                 std::vector<std::string*>* states;
735                 std::vector<const gchar*> item;
736                 std::string fullpath = *(*i);
737                 
738                 /* remove any trailing / */
739                 
740                 if (fullpath[fullpath.length()-1] == '/') {
741                         fullpath = fullpath.substr (0, fullpath.length()-1);
742                 }
743             
744                 /* now get available states for this session */
745                   
746                 if ((states = ARDOUR::Session::possible_states (fullpath)) == 0) {
747                         /* no state file? */
748                         continue;
749                 }
750             
751                 Gtk::TreeModel::Row row = *(recent_model->append());
752                 
753                 row[recent_columns.visible_name] = Glib::path_get_basename (fullpath);
754                 row[recent_columns.fullpath] = fullpath;
755                 
756                 if (states->size()) {
757                     
758                         /* add the children */
759                     
760                         for (std::vector<std::string*>::iterator i2 = states->begin(); i2 != states->end(); ++i2) {
761
762                                 Gtk::TreeModel::Row child_row = *(recent_model->append (row.children()));
763                                 
764                                 child_row[recent_columns.visible_name] = **i2;
765                                 child_row[recent_columns.fullpath] = fullpath;
766                                 
767                                 delete *i2;
768                         }
769                 }
770
771                 delete states;
772         }
773         delete sessions;
774 }
775
776 void
777 NewSessionDialog::reset()
778 {
779         reset_name();
780         reset_template();
781         set_response_sensitive (Gtk::RESPONSE_NONE, false);
782 }