Freesound tweaks from colinf (#4761).
[ardour.git] / gtk2_ardour / sfdb_freesound_mootcher.h
1 /*sfdb_freesound_mootcher.h****************************************************************************\r
2 \r
3         Adapted for Ardour by Ben Loftis, March 2008\r
4         Updated to new Freesound API by Colin Fletcher, November 2011\r
5 \r
6         Mootcher Online Access to thefreesoundproject website\r
7         http://freesound.iua.upf.edu/\r
8 \r
9         GPL 2005 Jorn Lemon\r
10         mail for questions/remarks: mootcher@twistedlemon.nl\r
11         or go to the freesound website forum\r
12 \r
13 *****************************************************************************/\r
14 \r
15 #include <string>\r
16 #include <fstream>\r
17 #include <iostream>\r
18 #include <stdio.h>\r
19 #include <cstring>\r
20 #include <string>\r
21 #include <sstream>\r
22 #include <vector>\r
23 #include <gtkmm/progressbar.h>\r
24 //#include <ctime>\r
25 \r
26 #include "sfdb_ui.h"\r
27 \r
28 #include "curl/curl.h"\r
29 \r
30 //--- struct to store XML file\r
31 struct MemoryStruct {\r
32         char *memory;\r
33         size_t size;\r
34 };\r
35 \r
36 enum sortMethod {\r
37         sort_none,              // no sort\r
38         sort_duration_desc,     // Sort by the duration of the sounds, longest sounds first.\r
39         sort_duration_asc,      // Same as above, but shortest sounds first.\r
40         sort_created_desc,      // Sort by the date of when the sound was added. newest sounds first.\r
41         sort_created_asc,       // Same as above, but oldest sounds first.\r
42         sort_downloads_desc,    // Sort by the number of downloads, most downloaded sounds first.\r
43         sort_downloads_asc,     // Same as above, but least downloaded sounds first.\r
44         sort_rating_desc,       // Sort by the average rating given to the sounds, highest rated first.\r
45         sort_rating_asc         // Same as above, but lowest rated sounds first.\r
46 };\r
47 \r
48 \r
49 class Mootcher\r
50 {\r
51 public:\r
52         Mootcher();\r
53         ~Mootcher();\r
54 \r
55         std::string     getAudioFile(std::string originalFileName, std::string ID, std::string audioURL, SoundFileBrowser *caller);\r
56         std::string     searchText(std::string query, int page, std::string filter, enum sortMethod sort);\r
57 \r
58 private:\r
59 \r
60         void            changeWorkingDir(const char *saveLocation);\r
61         void            ensureWorkingDir();\r
62 \r
63         std::string     doRequest(std::string uri, std::string params);\r
64         void            setcUrlOptions();\r
65 \r
66         static size_t   WriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void *data);\r
67         static int      progress_callback(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow);\r
68         std::string     sortMethodString(enum sortMethod sort);\r
69         std::string     getSoundResourceFile(std::string ID);\r
70 \r
71         CURL *curl;\r
72         char errorBuffer[CURL_ERROR_SIZE];      // storage for cUrl error message\r
73 \r
74         std::string basePath;\r
75         std::string xmlLocation;\r
76 };\r
77 \r