~ubuntu-branches/ubuntu/quantal/cairo-dock-plug-ins/quantal-201208191523

« back to all changes in this revision

Viewing changes to .pc/01-ubuntuone-fix_upstream-version-2.3.0~2.1.patch/dnd2share/src/applet-backend-ubuntuone.c

  • Committer: Kees Cook
  • Date: 2011-06-09 21:09:19 UTC
  • mfrom: (17.1.1 cairo-dock-plug-ins)
  • Revision ID: kees@outflux.net-20110609210919-r5awvo9dyhe8rvw6
* New upstream release. (LP: #786105)
* Upstream ChangeLog:
 - Fixed a typo in CMakeLists.txt about Ruby interface
 - CMakeLists.txt: Added the status of applets (stable / unstable
    / unsupported) to help packagers to not include unstable or
    unsupported applets on Cairo-Dock packages for stable distributions
* debian/patches:
 - Added two upstream's patches:
  + to avoid a crash of u1sdtool (dnd2share)
  + to prevent a crash with Weather (LP: #788437) 
* debian/control:
 - Removed libgvfscommon-dev (not used and no longer available)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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-ubuntuone.h"
 
30
 
 
31
#define NB_URLS 1
 
32
static const gchar *s_UrlLabels[NB_URLS] = {"DirectLink"};
 
33
 
 
34
 
 
35
static void upload (const gchar *cFilePath, gchar *cDropboxDir, gboolean bAnonymous, gint iLimitRate, gchar **cResultUrls)
 
36
{
 
37
        // On lance la commande d'upload.
 
38
        gchar *cFileName = g_path_get_basename (cFilePath);
 
39
        gchar *cLocalFilePath;
 
40
        if (cDropboxDir)
 
41
                cLocalFilePath = g_strdup_printf ("%s/%s", cDropboxDir, cFileName);
 
42
        else
 
43
                cLocalFilePath = g_strdup_printf ("/home/%s/Ubuntu One/%s", g_getenv ("USER"), cFileName);
 
44
        g_free (cFileName);
 
45
        
 
46
        gchar *cCommand = g_strdup_printf ("cp \"%s\" \"%s\"", cFilePath, cLocalFilePath);
 
47
        cd_debug ("commande u1 : %s", cCommand);
 
48
        int r = system (cCommand);
 
49
        g_free (cCommand);
 
50
        if (r != 0)
 
51
        {
 
52
                cd_warning ("couldn't copy the file to %s", cLocalFilePath);
 
53
                g_free (cLocalFilePath);
 
54
                return;
 
55
        }
 
56
        
 
57
        // On recupere l'URL (dispo tout de suite, sinon il faudra boucler en testant 'dropbox status' jusqu'a avoir 'Idle').
 
58
        cCommand= g_strdup_printf ("u1sdtool --publish-file \"%s\"", cLocalFilePath);
 
59
        cd_debug ("commande u2 : %s", cCommand);
 
60
        gchar *cResult = cairo_dock_launch_command_sync (cCommand);
 
61
        g_free (cCommand);
 
62
        g_free (cLocalFilePath);
 
63
        if (cResult == NULL || *cResult == '\0')
 
64
        {
 
65
                cd_warning ("is u1sdtool installed?");
 
66
                return ;
 
67
        }
 
68
        
 
69
        if (cResult[strlen(cResult)-1] == '\r')
 
70
                cResult[strlen(cResult)-1] = '\0';
 
71
        if (cResult[strlen(cResult)-1] == '\n')
 
72
                cResult[strlen(cResult)-1] = '\0';
 
73
        
 
74
        // Enfin on remplit la memoire partagee avec nos URLs.
 
75
        gchar *str = strstr (cResult, "http");  // File is published at http://ubuntuone.com/x/y
 
76
        if (! str)
 
77
        {
 
78
                cd_warning ("couldn't publish this file: %s", cResult);
 
79
                g_free (cResult);
 
80
                return ;
 
81
        }
 
82
        cResultUrls[0] = g_strdup (str);
 
83
        g_free (cResult);
 
84
}
 
85
 
 
86
 
 
87
void cd_dnd2share_register_ubuntuone_backend (void)
 
88
{
 
89
        cd_dnd2share_register_new_backend (CD_TYPE_FILE,
 
90
                "UbuntuOne",
 
91
                NB_URLS,
 
92
                s_UrlLabels,
 
93
                0,
 
94
                upload);
 
95
}