Ardour  9.0-rc2-55-gf3e581be0d
sfdb_freesound_mootcher.h
Go to the documentation of this file.
1 /*
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>
7  *
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.
12  *
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.
17  *
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.
21  */
22 
23 /*sfdb_freesound_mootcher.h****************************************************************************
24 
25  Adapted for Ardour by Ben Loftis, March 2008
26  Updated to new Freesound API by Colin Fletcher, November 2011
27 
28  Mootcher Online Access to thefreesoundproject website
29  http://freesound.iua.upf.edu/
30 
31  GPL 2005 Jorn Lemon
32  mail for questions/remarks: mootcher@twistedlemon.nl
33  or go to the freesound website forum
34 
35 *****************************************************************************/
36 
37 #pragma once
38 
39 #include <string>
40 #include <stdio.h>
41 #include <cstring>
42 #include <string>
43 #include <ytkmm/progressbar.h>
44 //#include <ctime>
45 
46 #include "sfdb_ui.h"
47 
48 #include "pbd/ccurl.h"
49 
50 //--- struct to store XML file
52  char *memory;
53  size_t size;
54 };
55 
56 enum sortMethod {
57  sort_none, // no sort
58  sort_duration_descending, // Sort by the duration of the sounds, longest sounds first.
59  sort_duration_ascending, // Same as above, but shortest sounds first.
60  sort_created_descending, // Sort by the date of when the sound was added. newest sounds first.
61  sort_created_ascending, // Same as above, but oldest sounds first.
62  sort_downloads_descending, // Sort by the number of downloads, most downloaded sounds first.
63  sort_downloads_ascending, // Same as above, but least downloaded sounds first.
64  sort_rating_descending, // Sort by the average rating given to the sounds, highest rated first.
65  sort_rating_ascending // Same as above, but lowest rated sounds first.
66 };
67 
68 
69 class Mootcher: public sigc::trackable, public PBD::ScopedConnectionList
70 {
71 public:
72  Mootcher(const std::string &token);
74 
75  bool checkAudioFile(std::string originalFileName, std::string ID);
76  bool fetchAudioFile(std::string originalFileName, std::string ID, std::string audioURL, SoundFileBrowser *caller, std::string &token);
77  std::string searchText(std::string query, int page, std::string filter, enum sortMethod sort);
78  std::string searchSimilar(std::string id);
79  void* threadFunc();
81  std::string audioFileName;
82  std::string ID;
83 
87  PBD::Signal<void(double, double)> Progress;
90 
91 
92 private:
94 
96  std::string auth_code_to_oauth_token(const std::string &auth_code);
97 
98  std::string doRequest(std::string uri, std::string params);
100 
101  static size_t WriteMemoryCallback (void *ptr, size_t size, size_t nmemb, void *data);
102  static int progress_callback (void *clientp, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow);
103  std::string sortMethodString (enum sortMethod sort);
104  std::string getSoundResourceFile (std::string ID);
105 
107  char errorBuffer[CURL_ERROR_SIZE]; // storage for cUrl error message
108 
110 
111  void updateProgress(double dlnow, double dltotal);
113  void report_login_error(const std::string &msg);
114 
118 
120  void cancelDownload() {
121  cancel_download = true;
123  }
124 
125  std::string basePath;
126  std::string xmlLocation;
127  std::string oauth_token;
128  struct curl_slist *custom_headers;
129 };
130 
static size_t WriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void *data)
std::string audioFileName
Mootcher(const std::string &token)
static int progress_callback(void *clientp, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow)
std::string basePath
std::string doRequest(std::string uri, std::string params)
PBD::Signal< void(double, double)> Progress
void * threadFunc()
Gtk::Button cancel_download_btn
std::string searchText(std::string query, int page, std::string filter, enum sortMethod sort)
void ensureWorkingDir()
bool fetchAudioFile(std::string originalFileName, std::string ID, std::string audioURL, SoundFileBrowser *caller, std::string &token)
std::string searchSimilar(std::string id)
SoundFileBrowser * sfb
std::string sortMethodString(enum sortMethod sort)
std::string getSoundResourceFile(std::string ID)
std::string oauth_token
PBD::Signal< void()> Finished
std::string xmlLocation
Gtk::ProgressBar progress_bar
std::string auth_code_to_oauth_token(const std::string &auth_code)
void updateProgress(double dlnow, double dltotal)
char errorBuffer[CURL_ERROR_SIZE]
void report_login_error(const std::string &msg)
void setcUrlOptions()
bool checkAudioFile(std::string originalFileName, std::string ID)
void doneWithMootcher()
Gtk::HBox progress_hbox
bool get_oauth_token()
struct curl_slist * custom_headers
std::list< ScopedConnectionList * >::size_type size() const
Definition: signals.h:295
GTKMM_API const Gtk::BuiltinStockID FILE
@ sort_created_descending
@ sort_rating_descending
@ sort_downloads_descending
@ sort_duration_descending
@ sort_rating_ascending
@ sort_duration_ascending
@ sort_downloads_ascending
@ sort_created_ascending