1 /* Gnome Music Player Client (GMPC) 2 * Copyright (C) 2004-2011 Qball Cow <qball@gmpclient.org> 3 * Project homepage: http://gmpclient.org/ 4 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 2 of the License, or 8 * (at your option) any later version. 9 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 15 * You should have received a copy of the GNU General Public License along 16 * with this program; if not, write to the Free Software Foundation, Inc., 17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 */ 19 20 #ifndef __GMPC_EASY_DOWNLOAD_H__ 21 #define __GMPC_EASY_DOWNLOAD_H__ 22 /** 23 * Async easy download api 24 * This is based on libsoup 25 */ 26 27 typedef struct _GEADAsyncHandler GEADAsyncHandler; 28 typedef enum { 29 GEAD_DONE, 30 GEAD_PROGRESS, 31 GEAD_FAILED, 32 GEAD_CANCELLED 33 } GEADStatus; 34 35 typedef void (*GEADAsyncCallback) (const GEADAsyncHandler * handle, GEADStatus status, gpointer user_data); 36 typedef void (*GEADAsyncCallbackVala) (const GEADAsyncHandler * handle, GEADStatus status, gpointer user_data, 37 gpointer userdata_callback); 38 /** 39 * @param uri the http uri to download 40 * @param callback the callback function. Giving status updates on the download. 41 * @param user_data Data to pass along to callback. 42 * 43 * returns: a GEADAsyncHandler (or NULL on failure), remember you need to free this. This can be done f.e. in the callback. (same Handler get passed) 44 */ 45 GEADAsyncHandler *gmpc_easy_async_downloader(const gchar * uri, GEADAsyncCallback callback, gpointer user_data); 46 47 GEADAsyncHandler *gmpc_easy_async_downloader_with_headers(const gchar * uri, 48 GEADAsyncCallback callback, gpointer user_data, ...); 49 /** 50 * Cancel download, triggers GEAD_CANCEL in callback 51 */ 52 void gmpc_easy_async_cancel(const GEADAsyncHandler * handle); 53 54 /** 55 * Get the size of the download, usefull for progressbar 56 */ 57 goffset gmpc_easy_handler_get_content_size(const GEADAsyncHandler * handle); 58 const char *gmpc_easy_handler_get_uri(const GEADAsyncHandler * handle); 59 60 const char *gmpc_easy_handler_get_data(const GEADAsyncHandler * handle, goffset * length); 61 62 const guchar *gmpc_easy_handler_get_data_vala_wrap(const GEADAsyncHandler * handle, gint * length); 63 /** 64 * Get the data as a string. 65 * If you know it will be a text. This function will return the data \0 66 * terminated. (if you need length, without the trailing \0 use get_data 67 * This can be usefull for f.e. vala that might copy the 'raw'data and remove 68 * the trailing '\0'. 69 */ 70 const char *gmpc_easy_handler_get_data_as_string(const GEADAsyncHandler * handle); 71 72 void gmpc_easy_handler_set_user_data(const GEADAsyncHandler *handle, gpointer user_data); 73 gpointer gmpc_easy_handler_get_user_data(const GEADAsyncHandler *handle); 74 75 76 char *gmpc_easy_download_uri_escape(const char *part); 77 GEADAsyncHandler * gmpc_easy_async_downloader_vala(const char *path, gpointer user_data2, GEADAsyncCallbackVala callback, 78 gpointer user_data 79 ); 80 #endif 81 /* vim: set noexpandtab ts=4 sw=4 sts=4 tw=120: */ 82