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