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