Ardour  9.0-pre0-582-g084a23a80d
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 <sstream>
44 #include <vector>
45 #include <gtkmm/progressbar.h>
46 //#include <ctime>
47 
48 #include "sfdb_ui.h"
49 
50 #include "curl/curl.h"
51 
52 //--- struct to store XML file
54  char *memory;
55  size_t size;
56 };
57 
58 enum sortMethod {
59  sort_none, // no sort
60  sort_duration_descending, // Sort by the duration of the sounds, longest sounds first.
61  sort_duration_ascending, // Same as above, but shortest sounds first.
62  sort_created_descending, // Sort by the date of when the sound was added. newest sounds first.
63  sort_created_ascending, // Same as above, but oldest sounds first.
64  sort_downloads_descending, // Sort by the number of downloads, most downloaded sounds first.
65  sort_downloads_ascending, // Same as above, but least downloaded sounds first.
66  sort_rating_descending, // Sort by the average rating given to the sounds, highest rated first.
67  sort_rating_ascending // Same as above, but lowest rated sounds first.
68 };
69 
70 
71 class Mootcher: public sigc::trackable, public PBD::ScopedConnectionList
72 {
73 public:
74  Mootcher(const std::string &token);
76 
77  bool checkAudioFile(std::string originalFileName, std::string ID);
78  bool fetchAudioFile(std::string originalFileName, std::string ID, std::string audioURL, SoundFileBrowser *caller, std::string &token);
79  std::string searchText(std::string query, int page, std::string filter, enum sortMethod sort);
80  std::string searchSimilar(std::string id);
81  void* threadFunc();
83  std::string audioFileName;
84  std::string ID;
85 
89  PBD::Signal<void(double, double)> Progress;
92 
93 
94 private:
96 
98  std::string auth_code_to_oauth_token(const std::string &auth_code);
99 
100  std::string doRequest(std::string uri, std::string params);
102 
103  static size_t WriteMemoryCallback (void *ptr, size_t size, size_t nmemb, void *data);
104  static int progress_callback (void *clientp, double dltotal, double dlnow, double ultotal, double ulnow);
105  std::string sortMethodString (enum sortMethod sort);
106  std::string getSoundResourceFile (std::string ID);
107 
108  CURL *curl;
109  char errorBuffer[CURL_ERROR_SIZE]; // storage for cUrl error message
110 
112 
113  void updateProgress(double dlnow, double dltotal);
115  void report_login_error(const std::string &msg);
116 
120 
122  void cancelDownload() {
123  cancel_download = true;
125  }
126 
127  std::string basePath;
128  std::string xmlLocation;
129  std::string oauth_token;
130  struct curl_slist *custom_headers;
131 };
132 
static size_t WriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void *data)
std::string audioFileName
Mootcher(const std::string &token)
std::string basePath
static int progress_callback(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow)
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
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