2 * Copyright (C) 2008-2015 Paul Davis <paul@linuxaudiosystems.com>
3 * Copyright (C) 2011-2012 Carl Hetherington <carl@carlh.net>
4 * Copyright (C) 2013 Colin Fletcher <colin.m.fletcher@googlemail.com>
5 * Copyright (C) 2015-2016 Tim Mayberry <mojofunk@gmail.com>
6 * Copyright (C) 2015-2019 Robin Gareus <robin@gareus.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 /*sfdb_freesound_mootcher.h****************************************************************************
25 Adapted for Ardour by Ben Loftis, March 2008
26 Updated to new Freesound API by Colin Fletcher, November 2011
28 Mootcher Online Access to thefreesoundproject website
29 http://freesound.iua.upf.edu/
32 mail for questions/remarks: mootcher@twistedlemon.nl
33 or go to the freesound website forum
35 *****************************************************************************/
37 #ifndef __gtk_ardour_sfdb_freesound_mootcher_h__
38 #define __gtk_ardour_sfdb_freesound_mootcher_h__
46 #include <gtkmm/progressbar.h>
51 #include "curl/curl.h"
53 //--- struct to store XML file
54 struct SfdbMemoryStruct {
61 sort_duration_desc, // Sort by the duration of the sounds, longest sounds first.
62 sort_duration_asc, // Same as above, but shortest sounds first.
63 sort_created_desc, // Sort by the date of when the sound was added. newest sounds first.
64 sort_created_asc, // Same as above, but oldest sounds first.
65 sort_downloads_desc, // Sort by the number of downloads, most downloaded sounds first.
66 sort_downloads_asc, // Same as above, but least downloaded sounds first.
67 sort_rating_desc, // Sort by the average rating given to the sounds, highest rated first.
68 sort_rating_asc // Same as above, but lowest rated sounds first.
72 class Mootcher: public sigc::trackable, public PBD::ScopedConnectionList
78 bool checkAudioFile(std::string originalFileName, std::string ID);
79 bool fetchAudioFile(std::string originalFileName, std::string ID, std::string audioURL, SoundFileBrowser *caller);
80 std::string searchText(std::string query, int page, std::string filter, enum sortMethod sort);
81 std::string searchSimilar(std::string id);
83 SoundFileBrowser *sfb;
84 std::string audioFileName;
87 /** signal emitted when mootcher reports progress updates during download.
88 * The parameters are current and total numbers of bytes downloaded.
90 PBD::Signal2<void, double, double> Progress;
91 /** signal emitted when the mootcher has finished downloading. */
92 PBD::Signal0<void> Finished;
96 void ensureWorkingDir ();
98 std::string doRequest (std::string uri, std::string params);
99 void setcUrlOptions ();
101 static size_t WriteMemoryCallback (void *ptr, size_t size, size_t nmemb, void *data);
102 static int progress_callback (void *clientp, double dltotal, double dlnow, double ultotal, double ulnow);
103 std::string sortMethodString (enum sortMethod sort);
104 std::string getSoundResourceFile (std::string ID);
107 char errorBuffer[CURL_ERROR_SIZE]; // storage for cUrl error message
111 void updateProgress(double dlnow, double dltotal);
112 void doneWithMootcher();
114 Gtk::HBox progress_hbox;
115 Gtk::ProgressBar progress_bar;
116 Gtk::Button cancel_download_btn;
118 bool cancel_download;
119 void cancelDownload() {
120 cancel_download = true;
121 progress_hbox.hide();
124 std::string basePath;
125 std::string xmlLocation;
128 #endif // __gtk_ardour_sfdb_freesound_mootcher_h__