2 Copyright (C) 2005 Paul Davis
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.
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.
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.
22 #include "new_session_dialog.h"
23 #include "glade_path.h"
25 #include <ardour/recent_sessions.h>
26 #include <ardour/session.h>
28 #include <pbd/basename.h>
30 #include <gtkmm/entry.h>
31 #include <gtkmm/filechooserbutton.h>
32 #include <gtkmm/spinbutton.h>
33 #include <gtkmm/checkbutton.h>
34 #include <gtkmm/radiobutton.h>
35 #include <gtkmm/filefilter.h>
36 #include <gtkmm/stock.h>
39 const char* NewSessionDialogFactory::s_m_top_level_widget_name = X_("NewSessionDialog");
40 const char* NewSessionDialogFactory::top_level_widget_name() { return s_m_top_level_widget_name; }
42 Glib::RefPtr<Gnome::Glade::Xml>
43 NewSessionDialogFactory::create()
45 return GladeFactory::create(GladePath::path(X_("new_session_dialog.glade")));
49 NewSessionDialog::NewSessionDialog(BaseObjectType* cobject,
50 const Glib::RefPtr<Gnome::Glade::Xml>& xml)
51 : Gtk::Dialog(cobject)
53 // look up the widgets we care about.
54 xml->get_widget(X_("NewSessionDialog"), m_new_session_dialog);
55 xml->get_widget(X_("SessionNameEntry"), m_name);
56 xml->get_widget(X_("SessionFolderChooser"), m_folder);
57 xml->get_widget(X_("SessionTemplateChooser"), m_template);
59 xml->get_widget(X_("CreateMasterBus"), m_create_master_bus);
60 xml->get_widget(X_("MasterChannelCount"), m_master_bus_channel_count);
62 xml->get_widget(X_("CreateControlBus"), m_create_control_bus);
63 xml->get_widget(X_("ControlChannelCount"), m_control_bus_channel_count);
65 xml->get_widget(X_("ConnectInputs"), m_connect_inputs);
66 xml->get_widget(X_("LimitInputPorts"), m_limit_input_ports);
67 xml->get_widget(X_("InputLimitCount"), m_input_limit_count);
69 xml->get_widget(X_("ConnectOutputs"), m_connect_outputs);
70 xml->get_widget(X_("LimitOutputPorts"), m_limit_output_ports);
71 xml->get_widget(X_("OutputLimitCount"), m_output_limit_count);
72 xml->get_widget(X_("ConnectOutsToMaster"), m_connect_outputs_to_master);
73 xml->get_widget(X_("ConnectOutsToPhysical"), m_connect_outputs_to_physical);
75 xml->get_widget(X_("OpenFilechooserButton"), m_open_filechooser);
76 xml->get_widget(X_("TheNotebook"), m_notebook);
77 xml->get_widget(X_("TheTreeview"), m_treeview);
78 xml->get_widget(X_("OkButton"), m_okbutton);
81 recent_model = Gtk::TreeStore::create (recent_columns);
82 m_treeview->set_model (recent_model);
83 m_treeview->append_column (_("Recent Sessions"), recent_columns.visible_name);
84 m_treeview->set_headers_visible (false);
85 m_treeview->get_selection()->set_mode (Gtk::SELECTION_SINGLE);
88 std::string path = ARDOUR::get_user_ardour_path() + X_("templates/");
89 if (path == Glib::ustring()) {
90 path = ARDOUR::get_system_data_path() + X_("templates/");
92 if (path != Glib::ustring()) {
93 m_template->set_current_folder (path);
95 m_template->set_show_hidden (true);
96 m_new_session_dialog->set_response_sensitive (Gtk::RESPONSE_OK, false);
97 m_new_session_dialog->set_response_sensitive (0, false);
98 m_notebook->show_all_children();
99 m_notebook->set_current_page(0);
101 Gtk::FileFilter* filter = manage (new (Gtk::FileFilter));
103 filter->add_pattern(X_("*.ardour"));
104 filter->add_pattern(X_("*.ardour.bak"));
105 m_open_filechooser->set_filter (*filter);
107 ///@ todo connect some signals
109 m_name->signal_key_release_event().connect(mem_fun (*this, &NewSessionDialog::entry_key_release));
110 m_notebook->signal_switch_page().connect (mem_fun (*this, &NewSessionDialog::notebook_page_changed));
111 m_treeview->get_selection()->signal_changed().connect (mem_fun (*this, &NewSessionDialog::treeview_selection_changed));
112 m_treeview->signal_row_activated().connect (mem_fun (*this, &NewSessionDialog::recent_row_activated));
113 m_open_filechooser->signal_selection_changed ().connect (mem_fun (*this, &NewSessionDialog::file_chosen));
114 m_template->signal_selection_changed ().connect (mem_fun (*this, &NewSessionDialog::template_chosen));
115 m_name->grab_focus();
119 NewSessionDialog::set_session_name(const Glib::ustring& name)
121 m_name->set_text(name);
125 NewSessionDialog::session_name() const
127 std::string str = Glib::filename_from_utf8(m_open_filechooser->get_filename());
128 std::string::size_type position = str.find_last_of ('/');
129 str = str.substr (position+1);
130 position = str.find_last_of ('.');
131 str = str.substr (0, position);
134 XXX what to do if it's a .bak file?
135 load_session doesn't allow it!
137 if ((position = str.rfind(".bak")) != string::npos) {
138 str = str.substr (0, position);
142 if (m_notebook->get_current_page() == 0) {
143 return Glib::filename_from_utf8(m_name->get_text());
145 if (m_treeview->get_selection()->count_selected_rows() == 0) {
146 return Glib::filename_from_utf8(str);
148 Gtk::TreeModel::iterator i = m_treeview->get_selection()->get_selected();
149 return (*i)[recent_columns.visible_name];
154 NewSessionDialog::session_folder() const
156 if (m_notebook->get_current_page() == 0) {
157 return Glib::filename_from_utf8(m_folder->get_current_folder());
160 if (m_treeview->get_selection()->count_selected_rows() == 0) {
161 return Glib::filename_from_utf8(m_open_filechooser->get_current_folder());
163 Gtk::TreeModel::iterator i = m_treeview->get_selection()->get_selected();
164 return (*i)[recent_columns.fullpath];
169 NewSessionDialog::use_session_template() const
171 if(m_template->get_filename().empty() && (m_notebook->get_current_page() == 0)) return false;
176 NewSessionDialog::session_template_name() const
178 return Glib::filename_from_utf8(m_template->get_filename());
182 NewSessionDialog::create_master_bus() const
184 return m_create_master_bus->get_active();
188 NewSessionDialog::master_channel_count() const
190 return m_master_bus_channel_count->get_value_as_int();
194 NewSessionDialog::create_control_bus() const
196 return m_create_control_bus->get_active();
200 NewSessionDialog::control_channel_count() const
202 return m_control_bus_channel_count->get_value_as_int();
206 NewSessionDialog::connect_inputs() const
208 return m_connect_inputs->get_active();
212 NewSessionDialog::limit_inputs_used_for_connection() const
214 return m_limit_input_ports->get_active();
218 NewSessionDialog::input_limit_count() const
220 return m_input_limit_count->get_value_as_int();
224 NewSessionDialog::connect_outputs() const
226 return m_connect_outputs->get_active();
230 NewSessionDialog::limit_outputs_used_for_connection() const
232 return m_limit_output_ports->get_active();
236 NewSessionDialog::output_limit_count() const
238 return m_output_limit_count->get_value_as_int();
242 NewSessionDialog::connect_outs_to_master() const
244 return m_connect_outputs_to_master->get_active();
248 NewSessionDialog::connect_outs_to_physical() const
250 return m_connect_outputs_to_physical->get_active();
254 NewSessionDialog::get_current_page()
256 return m_notebook->get_current_page();
261 NewSessionDialog::reset_name()
263 m_name->set_text(Glib::ustring());
264 m_new_session_dialog->set_response_sensitive (Gtk::RESPONSE_OK, false);
269 NewSessionDialog::entry_key_release (GdkEventKey* ev)
271 if (m_name->get_text() != "") {
272 m_new_session_dialog->set_response_sensitive (Gtk::RESPONSE_OK, true);
273 m_new_session_dialog->set_response_sensitive (0, true);
275 m_new_session_dialog->set_response_sensitive (Gtk::RESPONSE_OK, false);
281 NewSessionDialog::notebook_page_changed (GtkNotebookPage* np, uint pagenum)
284 m_new_session_dialog->set_response_sensitive (0, false);
285 m_okbutton->set_label(_("Open"));
286 m_okbutton->set_image (*(new Gtk::Image (Gtk::Stock::OPEN, Gtk::ICON_SIZE_BUTTON)));
287 if (m_treeview->get_selection()->count_selected_rows() == 0) {
288 m_new_session_dialog->set_response_sensitive (Gtk::RESPONSE_OK, false);
290 m_new_session_dialog->set_response_sensitive (Gtk::RESPONSE_OK, true);
293 if (m_name->get_text() != "") {
294 m_new_session_dialog->set_response_sensitive (0, true);
296 m_okbutton->set_label(_("New"));
297 m_okbutton->set_image (*(new Gtk::Image (Gtk::Stock::NEW, Gtk::ICON_SIZE_BUTTON)));
298 if (m_name->get_text() == "") {
299 m_new_session_dialog->set_response_sensitive (Gtk::RESPONSE_OK, false);
301 m_new_session_dialog->set_response_sensitive (Gtk::RESPONSE_OK, true);
307 NewSessionDialog::treeview_selection_changed ()
309 if (m_treeview->get_selection()->count_selected_rows() == 0) {
310 if (!m_open_filechooser->get_filename().empty()) {
311 m_new_session_dialog->set_response_sensitive (Gtk::RESPONSE_OK, true);
313 m_new_session_dialog->set_response_sensitive (Gtk::RESPONSE_OK, false);
316 m_new_session_dialog->set_response_sensitive (Gtk::RESPONSE_OK, true);
321 NewSessionDialog::file_chosen ()
323 m_treeview->get_selection()->unselect_all();
325 if (m_treeview->get_selection()->count_selected_rows() == 0) {
326 m_new_session_dialog->set_response_sensitive (Gtk::RESPONSE_OK, true);
331 NewSessionDialog::template_chosen ()
333 if (m_template->get_filename() != "" ) {;
334 m_new_session_dialog->set_response_sensitive (0, true);
336 m_new_session_dialog->set_response_sensitive (0, false);
342 NewSessionDialog::recent_row_activated (const Gtk::TreePath& path, Gtk::TreeViewColumn* col)
344 m_new_session_dialog->response (Gtk::RESPONSE_YES);
348 NewSessionDialog::reset_template()
350 m_template->set_filename("");
354 NewSessionDialog::reset_recent()
356 /* Shamelessly ripped from ardour_ui.cc */
357 std::vector<string *> *sessions;
358 std::vector<string *>::iterator i;
359 RecentSessionsSorter cmp;
361 recent_model->clear ();
363 ARDOUR::RecentSessions rs;
364 ARDOUR::read_recent_sessions (rs);
366 /* sort them alphabetically */
367 sort (rs.begin(), rs.end(), cmp);
368 sessions = new std::vector<std::string*>;
370 for (ARDOUR::RecentSessions::iterator i = rs.begin(); i != rs.end(); ++i) {
371 sessions->push_back (new string ((*i).second));
374 for (i = sessions->begin(); i != sessions->end(); ++i) {
376 std::vector<std::string*>* states;
377 std::vector<const gchar*> item;
378 std::string fullpath = *(*i);
380 /* remove any trailing / */
382 if (fullpath[fullpath.length()-1] == '/') {
383 fullpath = fullpath.substr (0, fullpath.length()-1);
386 /* now get available states for this session */
388 if ((states = ARDOUR::Session::possible_states (fullpath)) == 0) {
393 Gtk::TreeModel::Row row = *(recent_model->append());
395 row[recent_columns.visible_name] = PBD::basename (fullpath);
396 row[recent_columns.fullpath] = fullpath;
398 if (states->size() > 1) {
400 /* add the children */
402 for (std::vector<std::string*>::iterator i2 = states->begin(); i2 != states->end(); ++i2) {
404 Gtk::TreeModel::Row child_row = *(recent_model->append (row.children()));
406 child_row[recent_columns.visible_name] = **i2;
407 child_row[recent_columns.fullpath] = fullpath;
419 NewSessionDialog::reset()