2 Copyright (C) 2012 Paul Davis
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.
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.
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.
20 /*sfdb_freesound_mootcher.h****************************************************************************
22 Adapted for Ardour by Ben Loftis, March 2008
23 Updated to new Freesound API by Colin Fletcher, November 2011
25 Mootcher Online Access to thefreesoundproject website
26 http://freesound.iua.upf.edu/
29 mail for questions/remarks: mootcher@twistedlemon.nl
30 or go to the freesound website forum
32 *****************************************************************************/
34 #ifndef __gtk_ardour_sfdb_freesound_mootcher_h__
35 #define __gtk_ardour_sfdb_freesound_mootcher_h__
43 #include <gtkmm/progressbar.h>
48 #include "curl/curl.h"
50 //--- struct to store XML file
51 struct SfdbMemoryStruct {
58 sort_duration_desc, // Sort by the duration of the sounds, longest sounds first.
59 sort_duration_asc, // Same as above, but shortest sounds first.
60 sort_created_desc, // Sort by the date of when the sound was added. newest sounds first.
61 sort_created_asc, // Same as above, but oldest sounds first.
62 sort_downloads_desc, // Sort by the number of downloads, most downloaded sounds first.
63 sort_downloads_asc, // Same as above, but least downloaded sounds first.
64 sort_rating_desc, // Sort by the average rating given to the sounds, highest rated first.
65 sort_rating_asc // Same as above, but lowest rated sounds first.
69 class Mootcher: public sigc::trackable, public PBD::ScopedConnectionList
75 bool checkAudioFile(std::string originalFileName, std::string ID);
76 bool fetchAudioFile(std::string originalFileName, std::string ID, std::string audioURL, SoundFileBrowser *caller);
77 std::string searchText(std::string query, int page, std::string filter, enum sortMethod sort);
78 std::string searchSimilar(std::string id);
80 SoundFileBrowser *sfb;
81 std::string audioFileName;
84 /** signal emitted when mootcher reports progress updates during download.
85 * The parameters are current and total numbers of bytes downloaded.
87 PBD::Signal2<void, double, double> Progress;
88 /** signal emitted when the mootcher has finished downloading. */
89 PBD::Signal0<void> Finished;
94 void ensureWorkingDir();
96 std::string doRequest(std::string uri, std::string params);
97 void setcUrlOptions();
99 static size_t WriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void *data);
100 static int progress_callback(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow);
101 std::string sortMethodString(enum sortMethod sort);
102 std::string getSoundResourceFile(std::string ID);
105 char errorBuffer[CURL_ERROR_SIZE]; // storage for cUrl error message
109 void updateProgress(double dlnow, double dltotal);
110 void doneWithMootcher();
112 Gtk::HBox progress_hbox;
113 Gtk::ProgressBar progress_bar;
114 Gtk::Button cancel_download_btn;
116 bool cancel_download;
117 void cancelDownload() {
118 cancel_download = true;
119 progress_hbox.hide();
122 std::string basePath;
123 std::string xmlLocation;
126 #endif // __gtk_ardour_sfdb_freesound_mootcher_h__