add copyright comments
[ardour.git] / gtk2_ardour / sfdb_freesound_mootcher.h
1 /*
2     Copyright (C) 2012 Paul Davis 
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 /*sfdb_freesound_mootcher.h****************************************************************************\r
21 \r
22         Adapted for Ardour by Ben Loftis, March 2008\r
23         Updated to new Freesound API by Colin Fletcher, November 2011\r
24 \r
25         Mootcher Online Access to thefreesoundproject website\r
26         http://freesound.iua.upf.edu/\r
27 \r
28         GPL 2005 Jorn Lemon\r
29         mail for questions/remarks: mootcher@twistedlemon.nl\r
30         or go to the freesound website forum\r
31 \r
32 *****************************************************************************/\r
33 \r
34 #include <string>\r
35 #include <fstream>\r
36 #include <iostream>\r
37 #include <stdio.h>\r
38 #include <cstring>\r
39 #include <string>\r
40 #include <sstream>\r
41 #include <vector>\r
42 #include <gtkmm/progressbar.h>\r
43 //#include <ctime>\r
44 \r
45 #include "sfdb_ui.h"\r
46 \r
47 #include "curl/curl.h"\r
48 \r
49 //--- struct to store XML file\r
50 struct MemoryStruct {\r
51         char *memory;\r
52         size_t size;\r
53 };\r
54 \r
55 enum sortMethod {\r
56         sort_none,              // no sort\r
57         sort_duration_desc,     // Sort by the duration of the sounds, longest sounds first.\r
58         sort_duration_asc,      // Same as above, but shortest sounds first.\r
59         sort_created_desc,      // Sort by the date of when the sound was added. newest sounds first.\r
60         sort_created_asc,       // Same as above, but oldest sounds first.\r
61         sort_downloads_desc,    // Sort by the number of downloads, most downloaded sounds first.\r
62         sort_downloads_asc,     // Same as above, but least downloaded sounds first.\r
63         sort_rating_desc,       // Sort by the average rating given to the sounds, highest rated first.\r
64         sort_rating_asc         // Same as above, but lowest rated sounds first.\r
65 };\r
66 \r
67 \r
68 class Mootcher\r
69 {\r
70 public:\r
71         Mootcher();\r
72         ~Mootcher();\r
73 \r
74         std::string     getAudioFile(std::string originalFileName, std::string ID, std::string audioURL, SoundFileBrowser *caller);\r
75         std::string     searchText(std::string query, int page, std::string filter, enum sortMethod sort);\r
76 \r
77 private:\r
78 \r
79         void            changeWorkingDir(const char *saveLocation);\r
80         void            ensureWorkingDir();\r
81 \r
82         std::string     doRequest(std::string uri, std::string params);\r
83         void            setcUrlOptions();\r
84 \r
85         static size_t   WriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void *data);\r
86         static int      progress_callback(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow);\r
87         std::string     sortMethodString(enum sortMethod sort);\r
88         std::string     getSoundResourceFile(std::string ID);\r
89 \r
90         CURL *curl;\r
91         char errorBuffer[CURL_ERROR_SIZE];      // storage for cUrl error message\r
92 \r
93         std::string basePath;\r
94         std::string xmlLocation;\r
95 };\r
96 \r