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);
89 m_new_session_dialog->set_response_sensitive (Gtk::RESPONSE_OK, false);
90 m_new_session_dialog->set_response_sensitive (0, false);
91 m_new_session_dialog->set_default_response (Gtk::RESPONSE_OK);
92 m_notebook->show_all_children();
93 m_notebook->set_current_page(0);
95 Gtk::FileFilter* filter = manage (new (Gtk::FileFilter));
97 filter->add_pattern(X_("*.ardour"));
98 filter->add_pattern(X_("*.ardour.bak"));
99 m_open_filechooser->set_filter (*filter);
101 ///@ todo connect some signals
103 m_name->signal_key_release_event().connect(mem_fun (*this, &NewSessionDialog::entry_key_release));
104 m_notebook->signal_switch_page().connect (mem_fun (*this, &NewSessionDialog::notebook_page_changed));
105 m_treeview->get_selection()->signal_changed().connect (mem_fun (*this, &NewSessionDialog::treeview_selection_changed));
106 m_treeview->signal_row_activated().connect (mem_fun (*this, &NewSessionDialog::recent_row_activated));
107 m_open_filechooser->signal_selection_changed ().connect (mem_fun (*this, &NewSessionDialog::file_chosen));
111 NewSessionDialog::set_session_name(const Glib::ustring& name)
113 m_name->set_text(name);
117 NewSessionDialog::session_name() const
119 std::string str = Glib::filename_from_utf8(m_open_filechooser->get_filename());
120 std::string::size_type position = str.find_last_of ('/');
121 str = str.substr (position+1);
122 position = str.find_last_of ('.');
123 str = str.substr (0, position);
126 XXX what to do if it's a .bak file?
127 load_session doesn't allow it!
129 if ((position = str.rfind(".bak")) != string::npos) {
130 str = str.substr (0, position);
134 if (m_notebook->get_current_page() == 0) {
135 return Glib::filename_from_utf8(m_name->get_text());
137 if (m_treeview->get_selection()->count_selected_rows() == 0) {
138 return Glib::filename_from_utf8(str);
140 Gtk::TreeModel::iterator i = m_treeview->get_selection()->get_selected();
141 return (*i)[recent_columns.visible_name];
146 NewSessionDialog::session_folder() const
148 if (m_notebook->get_current_page() == 0) {
149 return Glib::filename_from_utf8(m_folder->get_current_folder());
152 if (m_treeview->get_selection()->count_selected_rows() == 0) {
153 return Glib::filename_from_utf8(m_open_filechooser->get_current_folder());
155 Gtk::TreeModel::iterator i = m_treeview->get_selection()->get_selected();
156 return (*i)[recent_columns.fullpath];
161 NewSessionDialog::use_session_template() const
163 if(m_template->get_filename().empty() && (m_notebook->get_current_page() == 0)) return false;
168 NewSessionDialog::session_template_name() const
170 return Glib::filename_from_utf8(m_template->get_filename());
174 NewSessionDialog::create_master_bus() const
176 return m_create_master_bus->get_active();
180 NewSessionDialog::master_channel_count() const
182 return m_master_bus_channel_count->get_value_as_int();
186 NewSessionDialog::create_control_bus() const
188 return m_create_control_bus->get_active();
192 NewSessionDialog::control_channel_count() const
194 return m_control_bus_channel_count->get_value_as_int();
198 NewSessionDialog::connect_inputs() const
200 return m_connect_inputs->get_active();
204 NewSessionDialog::limit_inputs_used_for_connection() const
206 return m_limit_input_ports->get_active();
210 NewSessionDialog::input_limit_count() const
212 return m_input_limit_count->get_value_as_int();
216 NewSessionDialog::connect_outputs() const
218 return m_connect_outputs->get_active();
222 NewSessionDialog::limit_outputs_used_for_connection() const
224 return m_limit_output_ports->get_active();
228 NewSessionDialog::output_limit_count() const
230 return m_output_limit_count->get_value_as_int();
234 NewSessionDialog::connect_outs_to_master() const
236 return m_connect_outputs_to_master->get_active();
240 NewSessionDialog::connect_outs_to_physical() const
242 return m_connect_outputs_to_physical->get_active();
246 NewSessionDialog::get_current_page()
248 return m_notebook->get_current_page();
253 NewSessionDialog::reset_name()
255 m_name->set_text(Glib::ustring());
260 NewSessionDialog::entry_key_release (GdkEventKey* ev)
262 if (m_name->get_text() != "") {
263 m_new_session_dialog->set_response_sensitive (Gtk::RESPONSE_OK, true);
264 m_new_session_dialog->set_response_sensitive (0, true);
266 m_new_session_dialog->set_response_sensitive (Gtk::RESPONSE_OK, false);
272 NewSessionDialog::notebook_page_changed (GtkNotebookPage* np, uint pagenum)
275 m_new_session_dialog->set_response_sensitive (0, false);
276 m_okbutton->set_label(_("Open"));
277 m_okbutton->set_image (*(new Gtk::Image (Gtk::Stock::OPEN, Gtk::ICON_SIZE_BUTTON)));
278 if (m_treeview->get_selection()->count_selected_rows() == 0) {
279 m_new_session_dialog->set_response_sensitive (Gtk::RESPONSE_OK, false);
281 m_new_session_dialog->set_response_sensitive (Gtk::RESPONSE_OK, true);
284 if (m_name->get_text() != "") {
285 m_new_session_dialog->set_response_sensitive (0, true);
287 m_okbutton->set_label(_("New"));
288 m_okbutton->set_image (*(new Gtk::Image (Gtk::Stock::NEW, Gtk::ICON_SIZE_BUTTON)));
289 if (m_name->get_text() == "") {
290 m_new_session_dialog->set_response_sensitive (Gtk::RESPONSE_OK, false);
292 m_new_session_dialog->set_response_sensitive (Gtk::RESPONSE_OK, true);
298 NewSessionDialog::treeview_selection_changed ()
300 if (m_treeview->get_selection()->count_selected_rows() == 0) {
301 if (!m_open_filechooser->get_filename().empty()) {
302 m_new_session_dialog->set_response_sensitive (Gtk::RESPONSE_OK, true);
304 m_new_session_dialog->set_response_sensitive (Gtk::RESPONSE_OK, false);
307 m_new_session_dialog->set_response_sensitive (Gtk::RESPONSE_OK, true);
312 NewSessionDialog::file_chosen ()
314 m_treeview->get_selection()->unselect_all();
316 if (m_treeview->get_selection()->count_selected_rows() == 0) {
317 m_new_session_dialog->set_response_sensitive (Gtk::RESPONSE_OK, true);
322 NewSessionDialog::recent_row_activated (const Gtk::TreePath& path, Gtk::TreeViewColumn* col)
324 m_new_session_dialog->response (Gtk::RESPONSE_YES);
329 NewSessionDialog::reset_template()
335 NewSessionDialog::reset_recent()
337 /* Shamelessly ripped from ardour_ui.cc */
338 std::vector<string *> *sessions;
339 std::vector<string *>::iterator i;
340 RecentSessionsSorter cmp;
342 recent_model->clear ();
344 ARDOUR::RecentSessions rs;
345 ARDOUR::read_recent_sessions (rs);
347 /* sort them alphabetically */
348 sort (rs.begin(), rs.end(), cmp);
349 sessions = new std::vector<std::string*>;
351 for (ARDOUR::RecentSessions::iterator i = rs.begin(); i != rs.end(); ++i) {
352 sessions->push_back (new string ((*i).second));
355 for (i = sessions->begin(); i != sessions->end(); ++i) {
357 std::vector<std::string*>* states;
358 std::vector<const gchar*> item;
359 std::string fullpath = *(*i);
361 /* remove any trailing / */
363 if (fullpath[fullpath.length()-1] == '/') {
364 fullpath = fullpath.substr (0, fullpath.length()-1);
367 /* now get available states for this session */
369 if ((states = ARDOUR::Session::possible_states (fullpath)) == 0) {
374 Gtk::TreeModel::Row row = *(recent_model->append());
376 row[recent_columns.visible_name] = PBD::basename (fullpath);
377 row[recent_columns.fullpath] = fullpath;
379 if (states->size() > 1) {
381 /* add the children */
383 for (std::vector<std::string*>::iterator i2 = states->begin(); i2 != states->end(); ++i2) {
385 Gtk::TreeModel::Row child_row = *(recent_model->append (row.children()));
387 child_row[recent_columns.visible_name] = **i2;
388 child_row[recent_columns.fullpath] = fullpath;
400 NewSessionDialog::reset()