Remove unused variable
[ardour.git] / libs / ardour / export_filename.cc
index 8186982384e130f80907bfe733370fff57b2b692..511db44a6b3f2ca562f585e121d73f26387749fa 100644 (file)
@@ -24,8 +24,9 @@
 #include <glibmm/fileutils.h>
 
 #include "pbd/xml++.h"
-#include "pbd/convert.h"
+#include "pbd/string_convert.h"
 #include "pbd/enumwriter.h"
+#include "pbd/localtime_r.h"
 
 #include "ardour/libardour_visibility.h"
 #include "ardour/session.h"
@@ -36,7 +37,7 @@
 #include "ardour/export_timespan.h"
 #include "ardour/utils.h"
 
-#include "i18n.h"
+#include "pbd/i18n.h"
 
 using namespace PBD;
 using namespace Glib;
@@ -48,6 +49,7 @@ namespace ARDOUR
 ExportFilename::ExportFilename (Session & session) :
   include_label (false),
   include_session (false),
+  use_session_snapshot_name (false),
   include_revision (false),
   include_channel_config (false),
   include_format_name (false),
@@ -62,7 +64,7 @@ ExportFilename::ExportFilename (Session & session) :
 {
        time_t rawtime;
        std::time (&rawtime);
-       time_struct = localtime (&rawtime);
+       localtime_r (&rawtime, &time_struct);
 
        folder = session.session_directory().export_path();
 
@@ -85,17 +87,19 @@ ExportFilename::get_state ()
 
        FieldPair dir = analyse_folder();
        child = node->add_child ("Folder");
-       child->add_property ("relative", dir.first ? "true" : "false");
-       child->add_property ("path", dir.second);
+       child->set_property ("relative", dir.first);
+       child->set_property ("path", dir.second);
 
        add_field (node, "label", include_label, label);
        add_field (node, "session", include_session);
+       add_field (node, "snapshot", use_session_snapshot_name);
+       add_field (node, "timespan", include_timespan);
        add_field (node, "revision", include_revision);
        add_field (node, "time", include_time, enum_2_string (time_format));
        add_field (node, "date", include_date, enum_2_string (date_format));
 
        XMLNode * extra_node = new XMLNode ("ExportRevision");
-       extra_node->add_property ("revision", to_string (revision, std::dec));
+       extra_node->set_property ("revision", revision);
        session.add_extra_xml (*extra_node);
 
        return *node;
@@ -105,7 +109,6 @@ int
 ExportFilename::set_state (const XMLNode & node)
 {
        XMLNode * child;
-       XMLProperty * prop;
        FieldPair pair;
 
        child = node.child ("Folder");
@@ -113,15 +116,14 @@ ExportFilename::set_state (const XMLNode & node)
 
        folder = "";
 
-       if ((prop = child->property ("relative"))) {
-               if (string_is_affirmative (prop->value())) {
-                       folder = session.session_directory().root_path();
-               }
+       bool is_relative;
+       if (child->get_property ("relative", is_relative) && is_relative) {
+               folder = session.session_directory ().root_path ();
        }
 
-       if ((prop = child->property ("path"))) {
-               std::string tmp;
-               tmp = Glib::build_filename (folder, prop->value());
+       std::string tmp;
+       if (child->get_property ("path", tmp)) {
+               tmp = Glib::build_filename (folder, tmp);
                if (!Glib::file_test (tmp, Glib::FILE_TEST_EXISTS)) {
                        warning << string_compose (_("Existing export folder for this session (%1) does not exist - ignored"), tmp) << endmsg;
                } else {
@@ -129,7 +131,7 @@ ExportFilename::set_state (const XMLNode & node)
                }
        }
 
-       if (folder.empty()) {
+       if (folder.empty() || !Glib::file_test (folder, FileTest (FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR))) {
                folder = session.session_directory().export_path();
        }
 
@@ -140,6 +142,12 @@ ExportFilename::set_state (const XMLNode & node)
        pair = get_field (node, "session");
        include_session = pair.first;
 
+       pair = get_field (node, "snapshot");
+       use_session_snapshot_name = pair.first;
+
+       pair = get_field (node, "timespan");
+       include_timespan = pair.first;
+
        pair = get_field (node, "revision");
        include_revision = pair.first;
 
@@ -157,8 +165,8 @@ ExportFilename::set_state (const XMLNode & node)
                extra_node = session.instant_xml ("ExportRevision");
        }
 
-       if (extra_node && (prop = extra_node->property ("revision"))) {
-               revision = atoi (prop->value());
+       if (extra_node) {
+               extra_node->get_property ("revision", revision);
        }
 
        return 0;
@@ -177,14 +185,17 @@ ExportFilename::get_path (ExportFormatSpecPtr format) const
                        && !include_timespan
                        && !include_channel_config
                        && !include_channel
-                       && !include_date
-                       && !include_format_name) {
+                       && !include_date) {
                with_timespan = true;
        }
 
        if (include_session) {
                path += filename_empty ? "" : "_";
-               path += session.name();
+               if (use_session_snapshot_name) {
+                       path += session.snap_name();
+               } else {
+                       path += session.name();
+               }
                filename_empty = false;
        }
 
@@ -197,7 +208,7 @@ ExportFilename::get_path (ExportFormatSpecPtr format) const
        if (include_revision) {
                path += filename_empty ? "" : "_";
                path += "r";
-               path += to_string (revision, std::dec);
+               path += to_string (revision);
                filename_empty = false;
        }
 
@@ -216,7 +227,7 @@ ExportFilename::get_path (ExportFormatSpecPtr format) const
        if (include_channel) {
                path += filename_empty ? "" : "_";
                path += "channel";
-               path += to_string (channel, std::dec);
+               path += to_string (channel);
                filename_empty = false;
        }
 
@@ -335,7 +346,7 @@ string
 ExportFilename::get_formatted_time (string const & format) const
 {
        char buffer [80];
-       strftime (buffer, 80, format.c_str(), time_struct);
+       strftime (buffer, 80, format.c_str(), &time_struct);
 
        string return_value (buffer);
        return return_value;
@@ -351,10 +362,10 @@ ExportFilename::add_field (XMLNode * node, string const & name, bool enabled, st
                return;
        }
 
-       child->add_property ("name", name);
-       child->add_property ("enabled", enabled ? "true" : "false");
+       child->set_property ("name", name);
+       child->set_property ("enabled", enabled);
        if (!value.empty()) {
-               child->add_property ("value", value);
+               child->set_property ("value", value);
        }
 }
 
@@ -367,20 +378,11 @@ ExportFilename::get_field (XMLNode const & node, string const & name)
        XMLNodeList children = node.children();
 
        for (XMLNodeList::iterator it = children.begin(); it != children.end(); ++it) {
-               XMLProperty * prop = (*it)->property ("name");
-               if (prop && !prop->value().compare (name)) {
-
-                       prop = (*it)->property ("enabled");
-                       if (prop && !prop->value().compare ("true")) {
-                               pair.first = true;
-                       } else {
-                               pair.first = false;
-                       }
-
-                       prop = (*it)->property ("value");
-                       if (prop) {
-                               pair.second = prop->value();
-                       }
+               std::string str;
+               if ((*it)->get_property ("name", str) && name == str) {
+
+                       (*it)->get_property ("enabled", pair.first);
+                       (*it)->get_property ("value", pair.second);
 
                        return pair;
                }