15
15
* GNU General Public License for more details.
16
16
* You should have received a copy of the GNU General Public License
17
17
* along with this program. If not, see <http://www.gnu.org/licenses/>.
23
#include "applet-struct.h"
24
#include "applet-dnd2share.h"
25
#include "applet-backend-custom.h"
28
static const gchar *s_UrlLabels[NB_URLS] = {"DirectLink"};
31
static void upload (const gchar *cFilePath)
33
g_return_if_fail (myConfig.cCustomScripts[myData.iCurrentFileType] != NULL);
35
// On lance la commande d'upload.
36
gchar *cCommand = g_strdup_printf ("%s '%s'", myConfig.cCustomScripts[myData.iCurrentFileType], cFilePath);
37
gchar *cResult = cairo_dock_launch_command_sync (cCommand);
39
if (cResult == NULL || *cResult == '\0')
44
if (cResult[strlen(cResult)-1] == '\r')
45
cResult[strlen(cResult)-1] = '\0';
46
if (cResult[strlen(cResult)-1] == '\n')
47
cResult[strlen(cResult)-1] = '\0';
49
// On prend la derniere ligne, au cas ou le script aurait blablate sur la sortie.
50
gchar *str = strrchr (cResult, '\n');
56
if (! cairo_dock_string_is_adress (str))
57
cd_warning ("this adress (%s) seems not valid !\nThe output was : '%s'", str, cResult);
59
// Enfin on remplit la memoire partagee avec nos URLs.
60
myData.cResultUrls[0] = g_strdup (str);
65
void cd_dnd2share_register_custom_backends (void)
68
for (t = 0; t < CD_NB_FILE_TYPES; t ++)
70
cd_dnd2share_register_new_backend (t,
23
#include "applet-struct.h"
24
#include "applet-dnd2share.h"
25
#include "applet-backend-custom.h"
28
static const gchar *s_UrlLabels[NB_URLS] = {"DirectLink"};
31
static void _upload (CDFileType iCurrentFileType, const gchar *cFilePath, gchar *cDropboxDir, gboolean bAnonymous, gint iLimitRate, gchar **cResultUrls)
33
g_return_if_fail (iCurrentFileType < CD_NB_FILE_TYPES && myConfig.cCustomScripts[iCurrentFileType] != NULL);
35
// On lance la commande d'upload.
36
gchar *cCommand = g_strdup_printf ("%s '%s'", myConfig.cCustomScripts[iCurrentFileType], cFilePath);
37
gchar *cResult = cairo_dock_launch_command_sync (cCommand);
39
if (cResult == NULL || *cResult == '\0')
44
if (cResult[strlen(cResult)-1] == '\r')
45
cResult[strlen(cResult)-1] = '\0';
46
if (cResult[strlen(cResult)-1] == '\n')
47
cResult[strlen(cResult)-1] = '\0';
49
// On prend la derniere ligne, au cas ou le script aurait blablate sur la sortie.
50
gchar *str = strrchr (cResult, '\n');
56
if (! cairo_dock_string_is_adress (str))
57
cd_warning ("this adress (%s) seems not valid !\nThe output was : '%s'", str, cResult);
59
// Enfin on remplit la memoire partagee avec nos URLs.
60
cResultUrls[0] = g_strdup (str);
64
static void upload_text (const gchar *cFilePath, gchar *cDropboxDir, gboolean bAnonymous, gint iLimitRate, gchar **cResultUrls)
66
_upload (CD_TYPE_TEXT, cFilePath, cDropboxDir, bAnonymous, iLimitRate, cResultUrls);
69
static void upload_image (const gchar *cFilePath, gchar *cDropboxDir, gboolean bAnonymous, gint iLimitRate, gchar **cResultUrls)
71
_upload (CD_TYPE_IMAGE, cFilePath, cDropboxDir, bAnonymous, iLimitRate, cResultUrls);
74
static void upload_video (const gchar *cFilePath, gchar *cDropboxDir, gboolean bAnonymous, gint iLimitRate, gchar **cResultUrls)
76
_upload (CD_TYPE_VIDEO, cFilePath, cDropboxDir, bAnonymous, iLimitRate, cResultUrls);
79
static void upload_file (const gchar *cFilePath, gchar *cDropboxDir, gboolean bAnonymous, gint iLimitRate, gchar **cResultUrls)
81
_upload (CD_TYPE_FILE, cFilePath, cDropboxDir, bAnonymous, iLimitRate, cResultUrls);
84
static const CDUploadFunc upload_funcs[CD_NB_FILE_TYPES] = {upload_text, upload_image, upload_video, upload_file};
86
void cd_dnd2share_register_custom_backends (void)
89
for (t = 0; t < CD_NB_FILE_TYPES; t ++)
91
cd_dnd2share_register_new_backend (t,