X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=gtk2_ardour%2Fsfdb_freesound_mootcher.cc;h=51c195657b26dbc4914c2ea0b19e1e020d2bb678;hb=e544934780ac4e3afd5878f3cc02e4acacedbd67;hp=c02059ba72b333a9c8a847af3f40a2a4ce2b8e0c;hpb=8ebd8a99abe3b18130c65ff3b3c9c7ed6fdd4c48;p=ardour.git diff --git a/gtk2_ardour/sfdb_freesound_mootcher.cc b/gtk2_ardour/sfdb_freesound_mootcher.cc index c02059ba72..51c195657b 100644 --- a/gtk2_ardour/sfdb_freesound_mootcher.cc +++ b/gtk2_ardour/sfdb_freesound_mootcher.cc @@ -48,9 +48,9 @@ #include #include -#include +#include "pbd/gstdio_compat.h" -#include "i18n.h" +#include "pbd/i18n.h" #include "ardour/audio_library.h" #include "ardour/rc_configuration.h" @@ -100,13 +100,13 @@ void Mootcher::ensureWorkingDir () } #endif } - + //------------------------------------------------------------------------ size_t Mootcher::WriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void *data) { - register int realsize = (int)(size * nmemb); - struct MemoryStruct *mem = (struct MemoryStruct *)data; + int realsize = (int)(size * nmemb); + struct SfdbMemoryStruct *mem = (struct SfdbMemoryStruct *)data; mem->memory = (char *)realloc(mem->memory, mem->size + realsize + 1); @@ -127,7 +127,7 @@ std::string Mootcher::sortMethodString(enum sortMethod sort) // sort the results in the requested way. switch (sort) { - case sort_duration_desc: return "duration_desc"; + case sort_duration_desc: return "duration_desc"; case sort_duration_asc: return "duration_asc"; case sort_created_desc: return "created_desc"; case sort_created_asc: return "created_asc"; @@ -135,22 +135,20 @@ std::string Mootcher::sortMethodString(enum sortMethod sort) case sort_downloads_asc: return "downloads_asc"; case sort_rating_desc: return "rating_desc"; case sort_rating_asc: return "rating_asc"; - default: return ""; + default: return ""; } } //------------------------------------------------------------------------ void Mootcher::setcUrlOptions() { - // basic init for curl - curl_global_init(CURL_GLOBAL_ALL); // some servers don't like requests that are made without a user-agent field, so we provide one curl_easy_setopt(curl, CURLOPT_USERAGENT, "libcurl-agent/1.0"); // setup curl error buffer curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errorBuffer); // Allow redirection curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1); - + // Allow connections to time out (without using signals) curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1); curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 30); @@ -161,7 +159,7 @@ void Mootcher::setcUrlOptions() std::string Mootcher::doRequest(std::string uri, std::string params) { std::string result; - struct MemoryStruct xml_page; + struct SfdbMemoryStruct xml_page; xml_page.memory = NULL; xml_page.size = 0; @@ -180,9 +178,9 @@ std::string Mootcher::doRequest(std::string uri, std::string params) } else { url += "api_key=" + api_key + "&format=xml"; } - + curl_easy_setopt(curl, CURLOPT_URL, url.c_str() ); - + // perform online request CURLcode res = curl_easy_perform(curl); if( res != 0 ) { @@ -194,7 +192,7 @@ std::string Mootcher::doRequest(std::string uri, std::string params) if (xml_page.memory) { result = xml_page.memory; } - + free (xml_page.memory); xml_page.memory = NULL; xml_page.size = 0; @@ -234,7 +232,7 @@ std::string Mootcher::searchText(std::string query, int page, std::string filter params += "&f=" + std::string(ef); free(ef); } - + if (sort) params += "&s=" + sortMethodString(sort); @@ -317,13 +315,13 @@ CURLcode res; res = curl_easy_perform (curl); fclose (theFile); curl_easy_setopt (curl, CURLOPT_NOPROGRESS, 1); // turn off the progress bar - + if (res != CURLE_OK) { /* it's not an error if the user pressed the stop button */ if (res != CURLE_ABORTED_BY_CALLBACK) { error << string_compose (_("curl error %1 (%2)"), res, curl_easy_strerror(res)) << endmsg; } - remove ( (audioFileName+".part").c_str() ); + remove ( (audioFileName+".part").c_str() ); } else { rename ( (audioFileName+".part").c_str(), audioFileName.c_str() ); // now download the tags &c. @@ -332,20 +330,20 @@ CURLcode res; return (void *) res; } - + void Mootcher::doneWithMootcher() { - // update the sound info pane if the selection in the list box is still us + // update the sound info pane if the selection in the list box is still us sfb->refresh_display(ID, audioFileName); delete this; // this should be OK to do as long as Progress and Finished signals are always received in the order in which they are emitted } static void * -freesound_download_thread_func(void *arg) -{ +freesound_download_thread_func(void *arg) +{ Mootcher *thisMootcher = (Mootcher *) arg; void *res; @@ -367,16 +365,16 @@ bool Mootcher::checkAudioFile(std::string originalFileName, std::string theID) // check to see if audio file already exists FILE *testFile = g_fopen(audioFileName.c_str(), "r"); - if (testFile) { + if (testFile) { fseek (testFile , 0 , SEEK_END); if (ftell (testFile) > 256) { fclose (testFile); return true; } - - // else file was small, probably an error, delete it + + // else file was small, probably an error, delete it fclose(testFile); - remove( audioFileName.c_str() ); + remove( audioFileName.c_str() ); } return false; } @@ -397,7 +395,7 @@ bool Mootcher::fetchAudioFile(std::string originalFileName, std::string theID, s if (!theFile) { return false; } - + // create the download url audioURL += "?api_key=" + api_key; @@ -430,8 +428,8 @@ bool Mootcher::fetchAudioFile(std::string originalFileName, std::string theID, s //--------- -void -Mootcher::updateProgress(double dlnow, double dltotal) +void +Mootcher::updateProgress(double dlnow, double dltotal) { if (dltotal > 0) { double fraction = dlnow / dltotal; @@ -445,7 +443,7 @@ Mootcher::updateProgress(double dlnow, double dltotal) } } -int +int Mootcher::progress_callback(void *caller, double dltotal, double dlnow, double /*ultotal*/, double /*ulnow*/) { // It may seem curious to pass a pointer to an instance of an object to a static @@ -453,7 +451,7 @@ Mootcher::progress_callback(void *caller, double dltotal, double dlnow, double / // and we want access to some private members of Mootcher. Mootcher *thisMootcher = (Mootcher *) caller; - + if (thisMootcher->cancel_download) { return -1; }