| 1 |
/** |
| 2 |
* This file is a part of the Cairo-Dock project |
| 3 |
* |
| 4 |
* Copyright : (C) see the 'copyright' file. |
| 5 |
* E-mail : see the 'copyright' file. |
| 6 |
* |
| 7 |
* This program is free software; you can redistribute it and/or |
| 8 |
* modify it under the terms of the GNU General Public License |
| 9 |
* as published by the Free Software Foundation; either version 3 |
| 10 |
* of the License, or (at your option) any later version. |
| 11 |
* |
| 12 |
* This program is distributed in the hope that it will be useful, |
| 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
* GNU General Public License for more details. |
| 16 |
* You should have received a copy of the GNU General Public License |
| 17 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 |
*/ |
| 19 |
|
| 20 |
#define _BSD_SOURCE |
| 21 |
#include <stdlib.h> |
| 22 |
#include <math.h> |
| 23 |
#include <unistd.h> |
| 24 |
#include <glib/gstdio.h> |
| 25 |
#include <string.h> |
| 26 |
|
| 27 |
#include "applet-struct.h" |
| 28 |
#include "applet-dnd2share.h" |
| 29 |
#include "applet-backend-imagebin.h" |
| 30 |
|
| 31 |
#define NB_URLS 1 |
| 32 |
static const gchar *s_UrlLabels[NB_URLS] = {N_("Direct Link")}; |
| 33 |
|
| 34 |
|
| 35 |
static void upload (const gchar *cFilePath, gchar *cLocalDir, gboolean bAnonymous, gint iLimitRate, gchar **cResultUrls, GError **pError) |
| 36 |
{ |
| 37 |
// Upload the file |
| 38 |
gchar *cCommand = g_strdup_printf ("curl -L --connect-timeout 5 --retry 2 --limit-rate %dk http://imagebin.ca/upload.php -F file=@\"%s\"", iLimitRate, cFilePath); |
| 39 |
cd_debug ("%s", cCommand); |
| 40 |
gchar *cContent = cairo_dock_launch_command_sync (cCommand); |
| 41 |
g_free (cCommand); |
| 42 |
|
| 43 |
if (! cContent) |
| 44 |
{ |
| 45 |
DND2SHARE_SET_GENERIC_ERROR_WEBSITE ("ImageBin"); |
| 46 |
return; |
| 47 |
} |
| 48 |
|
| 49 |
// We have the content, now we can extract data |
| 50 |
gchar *cURL = NULL; |
| 51 |
gchar *str = strstr (cContent, "url:"); |
| 52 |
if (str != NULL) |
| 53 |
{ |
| 54 |
str += 4; |
| 55 |
gchar *end; |
| 56 |
if ((end = strchr (str, '\n')) != NULL |
| 57 |
|| (end = strchr (str, '\0')) != NULL) |
| 58 |
{ |
| 59 |
*end = '\0'; |
| 60 |
cURL = g_strdup (str); |
| 61 |
} |
| 62 |
} |
| 63 |
g_free (cContent); |
| 64 |
|
| 65 |
if (cURL == NULL) |
| 66 |
{ |
| 67 |
DND2SHARE_SET_GENERIC_ERROR_WEBSITE ("ImageBin"); |
| 68 |
return; |
| 69 |
} |
| 70 |
|
| 71 |
cResultUrls[0] = cURL; |
| 72 |
} |
| 73 |
|
| 74 |
|
| 75 |
void cd_dnd2share_register_imagebin_backend (void) |
| 76 |
{ |
| 77 |
cd_dnd2share_register_new_backend (CD_TYPE_IMAGE, |
| 78 |
"imagebin.ca", |
| 79 |
NB_URLS, |
| 80 |
s_UrlLabels, |
| 81 |
0, |
| 82 |
upload); |
| 83 |
} |