+bool
+ARDOUR_UI::save_as_progress_update (float fraction, int64_t cnt, int64_t total, Gtk::Label* label, Gtk::ProgressBar* bar)
+{
+ char buf[256];
+
+ snprintf (buf, sizeof (buf), _("Copied %" PRId64 " of %" PRId64), cnt, total);
+
+ label->set_text (buf);
+ bar->set_fraction (fraction);
+
+ /* process events, redraws, etc. */
+
+ while (gtk_events_pending()) {
+ gtk_main_iteration ();
+ }
+
+ return true; /* continue with save-as */
+}
+
+void
+ARDOUR_UI::save_session_as ()
+{
+ if (!_session) {
+ return;
+ }
+
+ if (!save_as_dialog) {
+ save_as_dialog = new SaveAsDialog;
+ } else {
+ save_as_dialog->clear_name ();
+ }
+
+ int response = save_as_dialog->run ();
+
+ save_as_dialog->hide ();
+
+ switch (response) {
+ case Gtk::RESPONSE_OK:
+ break;
+ default:
+ return;
+ }
+
+
+ Session::SaveAs sa;
+
+ sa.new_parent_folder = save_as_dialog->new_parent_folder ();
+ sa.new_name = save_as_dialog->new_name ();
+ sa.switch_to = save_as_dialog->switch_to();
+ sa.copy_media = save_as_dialog->copy_media();
+ sa.copy_external = save_as_dialog->copy_external();
+ sa.include_media = save_as_dialog->include_media ();
+
+ /* Only bother with a progress dialog if we're going to copy
+ media into the save-as target. Without that choice, this
+ will be very fast because we're only talking about a few kB's to
+ perhaps a couple of MB's of data.
+ */
+
+ ArdourDialog progress_dialog (_("Save As"), true);
+
+ if (sa.include_media && sa.copy_media) {
+
+ Gtk::Label label;
+ Gtk::ProgressBar progress_bar;
+
+ progress_dialog.get_vbox()->pack_start (label);
+ progress_dialog.get_vbox()->pack_start (progress_bar);
+ label.show ();
+ progress_bar.show ();
+
+ /* this signal will be emitted from within this, the calling thread,
+ * after every file is copied. It provides information on percentage
+ * complete (in terms of total data to copy), the number of files
+ * copied so far, and the total number to copy.
+ */
+
+ ScopedConnection c;
+
+ sa.Progress.connect_same_thread (c, boost::bind (&ARDOUR_UI::save_as_progress_update, this, _1, _2, _3, &label, &progress_bar));
+
+ progress_dialog.show_all ();
+ progress_dialog.present ();
+ }
+
+ if (_session->save_as (sa)) {
+ /* ERROR MESSAGE */
+ MessageDialog msg (string_compose (_("Save As failed: %1"), sa.failure_message));
+ msg.run ();
+ }
+
+ if (!sa.include_media) {
+ unload_session (false);
+ load_session (sa.final_session_folder_name, sa.new_name);
+ }
+}
+