Use config variable for Freesound download folder location.
[ardour.git] / gtk2_ardour / sfdb_freesound_mootcher.cc
index e46fb12391183ba2b093d3c23e20c46c45e403bd..e8b44ff4a790a9401471811eacf2640f812dce27 100644 (file)
@@ -53,6 +53,7 @@
 #include "i18n.h"\r
 \r
 #include "ardour/audio_library.h"\r
+#include "ardour/rc_configuration.h"\r
 \r
 using namespace PBD;\r
 \r
@@ -63,9 +64,12 @@ static const std::string api_key = "9d77cb8d841b4bcfa960e1aae62224eb"; // ardour
 Mootcher::Mootcher()\r
        : curl(curl_easy_init())\r
 {\r
-       std::string path;\r
-       path = Glib::get_home_dir() + "/Freesound/";\r
-       changeWorkingDir ( path.c_str() );\r
+       cancel_download_btn.set_label (_("Cancel"));\r
+       progress_hbox.pack_start (progress_bar, true, true);\r
+       progress_hbox.pack_end (cancel_download_btn, false, false);\r
+       progress_bar.show();\r
+       cancel_download_btn.show();\r
+       cancel_download_btn.signal_clicked().connect(sigc::mem_fun (*this, &Mootcher::cancelDownload));\r
 };\r
 //------------------------------------------------------------------------\r
 Mootcher:: ~Mootcher()\r
@@ -74,31 +78,25 @@ Mootcher:: ~Mootcher()
 }\r
 \r
 //------------------------------------------------------------------------\r
-void Mootcher::changeWorkingDir(const char *saveLocation)\r
-{\r
-       basePath = saveLocation;\r
-#ifdef __WIN32__\r
-       std::string replace = "/";\r
-       size_t pos = basePath.find("\\");\r
-       while( pos != std::string::npos ){\r
-               basePath.replace(pos, 1, replace);\r
-               pos = basePath.find("\\");\r
-       }\r
-#endif\r
-       //\r
-       size_t pos2 = basePath.find_last_of("/");\r
-       if(basePath.length() != (pos2+1)) basePath += "/";\r
-}\r
 \r
 void Mootcher::ensureWorkingDir ()\r
 {\r
-       std::string p = Glib::build_filename (basePath, "snd");\r
+       std::string p = ARDOUR::Config->get_freesound_download_dir();\r
 \r
        if (!Glib::file_test (p, Glib::FILE_TEST_IS_DIR)) {\r
                if (g_mkdir_with_parents (p.c_str(), 0775) != 0) {\r
                        PBD::error << "Unable to create Mootcher working dir" << endmsg;\r
                }\r
        }\r
+       basePath = p;\r
+#ifdef __WIN32__\r
+       std::string replace = "/";\r
+       size_t pos = basePath.find("\\");\r
+       while( pos != std::string::npos ){\r
+               basePath.replace(pos, 1, replace);\r
+               pos = basePath.find("\\");\r
+       }\r
+#endif\r
 }\r
        \r
 \r
@@ -264,7 +262,7 @@ std::string Mootcher::getSoundResourceFile(std::string ID)
        // get the file name and size from xml file\r
        if (name) {\r
 \r
-               audioFileName = basePath + "snd/" + ID + "-" + name->child("text")->content();\r
+               audioFileName = Glib::build_filename (basePath, ID + "-" + name->child("text")->content());\r
 \r
                //store all the tags in the database\r
                XMLNode *tags = freesound->child("tags");\r
@@ -299,7 +297,7 @@ int audioFileWrite(void *buffer, size_t size, size_t nmemb, void *file)
 std::string Mootcher::getAudioFile(std::string originalFileName, std::string ID, std::string audioURL, SoundFileBrowser *caller)\r
 {\r
        ensureWorkingDir();\r
-       std::string audioFileName = basePath + "snd/" + ID + "-" + originalFileName;\r
+       audioFileName = Glib::build_filename (basePath, ID + "-" + originalFileName);\r
 \r
        // check to see if audio file already exists\r
        FILE *testFile = g_fopen(audioFileName.c_str(), "r");\r