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);
82 /* Shamelessly ripped from ardour_ui.cc */
83 std::vector<string *> *sessions;
84 std::vector<string *>::iterator i;
85 RecentSessionsSorter cmp;
87 recent_model = Gtk::TreeStore::create (recent_columns);
88 m_treeview->set_model (recent_model);
89 m_treeview->append_column (_("Recent Sessions"), recent_columns.visible_name);
90 m_treeview->set_headers_visible (false);
91 m_treeview->get_selection()->set_mode (Gtk::SELECTION_SINGLE);
93 recent_model->clear ();
95 ARDOUR::RecentSessions rs;
96 ARDOUR::read_recent_sessions (rs);
98 /* sort them alphabetically */
99 sort (rs.begin(), rs.end(), cmp);
100 sessions = new std::vector<std::string*>;
102 for (ARDOUR::RecentSessions::iterator i = rs.begin(); i != rs.end(); ++i) {
103 sessions->push_back (new string ((*i).second));
106 for (i = sessions->begin(); i != sessions->end(); ++i) {
108 std::vector<std::string*>* states;
109 std::vector<const gchar*> item;
110 std::string fullpath = *(*i);
112 /* remove any trailing / */
114 if (fullpath[fullpath.length()-1] == '/') {
115 fullpath = fullpath.substr (0, fullpath.length()-1);
118 /* now get available states for this session */
120 if ((states = ARDOUR::Session::possible_states (fullpath)) == 0) {
125 Gtk::TreeModel::Row row = *(recent_model->append());
127 row[recent_columns.visible_name] = PBD::basename (fullpath);
128 row[recent_columns.fullpath] = fullpath;
130 if (states->size() > 1) {
132 /* add the children */
134 for (std::vector<std::string*>::iterator i2 = states->begin(); i2 != states->end(); ++i2) {
136 Gtk::TreeModel::Row child_row = *(recent_model->append (row.children()));
138 child_row[recent_columns.visible_name] = **i2;
139 child_row[recent_columns.fullpath] = fullpath;
150 m_new_session_dialog->set_response_sensitive (Gtk::RESPONSE_OK, false);
151 m_new_session_dialog->set_default_response (Gtk::RESPONSE_OK);
152 m_notebook->show_all_children();
153 m_notebook->set_current_page(0);
155 Gtk::FileFilter* filter = manage (new (Gtk::FileFilter));
157 filter->add_pattern(X_("*.ardour"));
158 filter->add_pattern(X_("*.ardour.bak"));
159 m_open_filechooser->set_filter (*filter);
161 ///@ todo connect some signals
163 m_name->signal_key_release_event().connect(mem_fun (*this, &NewSessionDialog::entry_key_release));
164 m_notebook->signal_switch_page().connect (mem_fun (*this, &NewSessionDialog::notebook_page_changed));
165 m_treeview->get_selection()->signal_changed().connect (mem_fun (*this, &NewSessionDialog::treeview_selection_changed));
166 m_treeview->signal_row_activated().connect (mem_fun (*this, &NewSessionDialog::recent_row_activated));
167 m_open_filechooser->signal_selection_changed ().connect (mem_fun (*this, &NewSessionDialog::file_chosen));
171 NewSessionDialog::set_session_name(const Glib::ustring& name)
173 m_name->set_text(name);
177 NewSessionDialog::session_name() const
179 std::string str = Glib::filename_from_utf8(m_open_filechooser->get_filename());
180 std::string::size_type position = str.find_last_of ('/');
181 str = str.substr (position+1);
182 position = str.find_last_of ('.');
183 str = str.substr (0, position);
186 XXX what to do if it's a .bak file?
187 load_session doesn't allow it!
189 if ((position = str.rfind(".bak")) != string::npos) {
190 str = str.substr (0, position);
194 if (m_notebook->get_current_page() == 0) {
195 return Glib::filename_from_utf8(m_name->get_text());
197 if (m_treeview->get_selection()->count_selected_rows() == 0) {
198 return Glib::filename_from_utf8(str);
200 Gtk::TreeModel::iterator i = m_treeview->get_selection()->get_selected();
201 return (*i)[recent_columns.visible_name];
206 NewSessionDialog::session_folder() const
208 if (m_notebook->get_current_page() == 0) {
209 return Glib::filename_from_utf8(m_folder->get_current_folder());
212 if (m_treeview->get_selection()->count_selected_rows() == 0) {
213 return Glib::filename_from_utf8(m_open_filechooser->get_current_folder());
215 Gtk::TreeModel::iterator i = m_treeview->get_selection()->get_selected();
216 return (*i)[recent_columns.fullpath];
221 NewSessionDialog::use_session_template() const
223 if(m_template->get_filename().empty() && (m_notebook->get_current_page() == 0)) return false;
228 NewSessionDialog::session_template_name() const
230 return Glib::filename_from_utf8(m_template->get_filename());
234 NewSessionDialog::create_master_bus() const
236 return m_create_master_bus->get_active();
240 NewSessionDialog::master_channel_count() const
242 return m_master_bus_channel_count->get_value_as_int();
246 NewSessionDialog::create_control_bus() const
248 return m_create_control_bus->get_active();
252 NewSessionDialog::control_channel_count() const
254 return m_control_bus_channel_count->get_value_as_int();
258 NewSessionDialog::connect_inputs() const
260 return m_connect_inputs->get_active();
264 NewSessionDialog::limit_inputs_used_for_connection() const
266 return m_limit_input_ports->get_active();
270 NewSessionDialog::input_limit_count() const
272 return m_input_limit_count->get_value_as_int();
276 NewSessionDialog::connect_outputs() const
278 return m_connect_outputs->get_active();
282 NewSessionDialog::limit_outputs_used_for_connection() const
284 return m_limit_output_ports->get_active();
288 NewSessionDialog::output_limit_count() const
290 return m_output_limit_count->get_value_as_int();
294 NewSessionDialog::connect_outs_to_master() const
296 return m_connect_outputs_to_master->get_active();
300 NewSessionDialog::connect_outs_to_physical() const
302 return m_connect_outputs_to_physical->get_active();
306 NewSessionDialog::get_current_page()
308 return m_notebook->get_current_page();
313 NewSessionDialog::reset_name()
315 m_name->set_text(Glib::ustring());
320 NewSessionDialog::entry_key_release (GdkEventKey* ev)
322 if (m_name->get_text() != "") {
323 m_new_session_dialog->set_response_sensitive (Gtk::RESPONSE_OK, true);
325 m_new_session_dialog->set_response_sensitive (Gtk::RESPONSE_OK, false);
331 NewSessionDialog::notebook_page_changed (GtkNotebookPage* np, uint pagenum)
334 m_okbutton->set_label(_("Open"));
335 m_okbutton->set_image (*(new Gtk::Image (Gtk::Stock::OPEN, Gtk::ICON_SIZE_BUTTON)));
336 if (m_treeview->get_selection()->count_selected_rows() == 0) {
337 m_new_session_dialog->set_response_sensitive (Gtk::RESPONSE_OK, false);
339 m_new_session_dialog->set_response_sensitive (Gtk::RESPONSE_OK, true);
342 m_okbutton->set_label(_("New"));
343 m_okbutton->set_image (*(new Gtk::Image (Gtk::Stock::NEW, Gtk::ICON_SIZE_BUTTON)));
344 if (m_name->get_text() == "") {
345 m_new_session_dialog->set_response_sensitive (Gtk::RESPONSE_OK, false);
347 m_new_session_dialog->set_response_sensitive (Gtk::RESPONSE_OK, true);
353 NewSessionDialog::treeview_selection_changed ()
355 if (m_treeview->get_selection()->count_selected_rows() == 0) {
356 if (!m_open_filechooser->get_filename().empty()) {
357 m_new_session_dialog->set_response_sensitive (Gtk::RESPONSE_OK, true);
359 m_new_session_dialog->set_response_sensitive (Gtk::RESPONSE_OK, false);
362 m_new_session_dialog->set_response_sensitive (Gtk::RESPONSE_OK, true);
367 NewSessionDialog::file_chosen ()
369 m_treeview->get_selection()->unselect_all();
371 if (m_treeview->get_selection()->count_selected_rows() == 0) {
372 m_new_session_dialog->set_response_sensitive (Gtk::RESPONSE_OK, true);
377 NewSessionDialog::recent_row_activated (const Gtk::TreePath& path, Gtk::TreeViewColumn* col)
379 m_new_session_dialog->response (Gtk::RESPONSE_YES);
384 NewSessionDialog::reset_template()
390 NewSessionDialog::reset()