don't let auditioning make transport buttons inaccessible; delete/rename snapshots...
[ardour.git] / libs / ardour / session_state.cc
index dfa95161a9b0021eff9f747a17126a58777e8067..70d9cd12d79d0d3e65850a3703bd44a1bab31a01 100644 (file)
@@ -593,6 +593,48 @@ Session::remove_pending_capture_state ()
        unlink (xml_path.c_str());
 }
 
+/** Rename a state file.
+ * @param snapshot_name Snapshot name.
+ */
+void
+Session::rename_state (string old_name, string new_name)
+{
+       if (old_name == _current_snapshot_name || old_name == _name) {
+               /* refuse to rename the current snapshot or the "main" one */
+               return;
+       }
+       
+       const string old_xml_path = _path + old_name + _statefile_suffix;
+       const string new_xml_path = _path + new_name + _statefile_suffix;
+
+       if (rename (old_xml_path.c_str(), new_xml_path.c_str()) != 0) {
+               error << string_compose(_("could not rename snapshot %1 to %2"), old_name, new_name) << endmsg;
+       }
+}
+
+/** Remove a state file.
+ * @param snapshot_name Snapshot name.
+ */
+void
+Session::remove_state (string snapshot_name)
+{
+       if (snapshot_name == _current_snapshot_name || snapshot_name == _name) {
+               /* refuse to remove the current snapshot or the "main" one */
+               return;
+       }
+       
+       const string xml_path = _path + snapshot_name + _statefile_suffix;
+
+       /* make a backup copy of the state file */
+       const string bak_path = xml_path + ".bak";
+       if (g_file_test (xml_path.c_str(), G_FILE_TEST_EXISTS)) {
+               copy_file (xml_path, bak_path);
+       }
+
+       /* and delete it */
+       unlink (xml_path.c_str());
+}
+
 int
 Session::save_state (string snapshot_name, bool pending)
 {
@@ -618,10 +660,12 @@ Session::save_state (string snapshot_name, bool pending)
 
        if (!pending) {
 
+               /* proper save: use _statefile_suffix (.ardour in English) */
                xml_path = _path;
                xml_path += snapshot_name;
                xml_path += _statefile_suffix;
 
+               /* make a backup copy of the old file */
                bak_path = xml_path;
                bak_path += ".bak";
                
@@ -631,6 +675,7 @@ Session::save_state (string snapshot_name, bool pending)
 
        } else {
 
+               /* pending save: use _pending_suffix (.pending in English) */
                xml_path = _path;
                xml_path += snapshot_name;
                xml_path += _pending_suffix;