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

« back to all changes in this revision

Viewing changes to dnd2share/src/applet-backend-custom.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthieu Baerts (matttbe)
  • Date: 2011-04-20 20:46:51 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20110420204651-ftnpzesj6uc7qeul
Tags: 2.3.0~1-0ubuntu1
* New Upstream Version (LP: #723995)
* Upstream short ChangeLog (since 2.3.0~0rc1):
 - Updated translations
 - Updated the integration of the new versions of kwin and compiz
    (Switcher, ShowDesktop, etc.)
 - Removed a lot of useless g_print
 - Updated a few plug-ins to fit with the new version of the API (gldit)
 - Fixed a few bugs
 - Updated MeMenu, MessagingMenu and Status-Notifier to works
    with the latest version of dbusmenu, etc.
* Switch to dpkg-source 3.0 (quilt) format
* debian/cairo-dock-plug-ins.install:
 - Added new files (interfaces for python, ruby, vala and mono)
* debian/control:
 - Added new dependences for new applets (sensors and zeitgeist)
    and new interfaces (python, valac, ruby and mono)
 - Updated the version of cairo-dock build-dependences
* debian/rules:
 - Added a new CMake flag to install python interface in debian/tmp
* Updated debian/watch

Show diffs side-by-side

added added

removed removed

Lines of Context:
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/>.
18
 
*/
19
 
 
20
 
#include <stdlib.h>
21
 
#include <string.h>
22
 
 
23
 
#include "applet-struct.h"
24
 
#include "applet-dnd2share.h"
25
 
#include "applet-backend-custom.h"
26
 
 
27
 
#define NB_URLS 1
28
 
static const gchar *s_UrlLabels[NB_URLS] = {"DirectLink"};
29
 
 
30
 
 
31
 
static void upload (const gchar *cFilePath)
32
 
{
33
 
        g_return_if_fail (myConfig.cCustomScripts[myData.iCurrentFileType] != NULL);
34
 
        
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);
38
 
        g_free (cCommand);
39
 
        if (cResult == NULL || *cResult == '\0')
40
 
        {
41
 
                return ;
42
 
        }
43
 
        
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';
48
 
        
49
 
        // On prend la derniere ligne, au cas ou le script aurait blablate sur la sortie.
50
 
        gchar *str = strrchr (cResult, '\n');
51
 
        if (str != NULL)
52
 
                str ++;
53
 
        else
54
 
                str = cResult;
55
 
        
56
 
        if (! cairo_dock_string_is_adress (str))
57
 
                cd_warning ("this adress (%s) seems not valid !\nThe output was : '%s'", str, cResult);
58
 
        
59
 
        // Enfin on remplit la memoire partagee avec nos URLs.
60
 
        myData.cResultUrls[0] = g_strdup (str);
61
 
        g_free (cResult);
62
 
}
63
 
 
64
 
 
65
 
void cd_dnd2share_register_custom_backends (void)
66
 
{
67
 
        CDFileType t;
68
 
        for (t = 0; t < CD_NB_FILE_TYPES; t ++)
69
 
        {
70
 
                cd_dnd2share_register_new_backend (t,
71
 
                        "custom",
72
 
                        NB_URLS,
73
 
                        s_UrlLabels,
74
 
                        0,
75
 
                        upload);
76
 
        }
77
 
}
 
18
*/
 
19
 
 
20
#include <stdlib.h>
 
21
#include <string.h>
 
22
 
 
23
#include "applet-struct.h"
 
24
#include "applet-dnd2share.h"
 
25
#include "applet-backend-custom.h"
 
26
 
 
27
#define NB_URLS 1
 
28
static const gchar *s_UrlLabels[NB_URLS] = {"DirectLink"};
 
29
 
 
30
 
 
31
static void _upload (CDFileType iCurrentFileType, const gchar *cFilePath, gchar *cDropboxDir, gboolean bAnonymous, gint iLimitRate, gchar **cResultUrls)
 
32
{
 
33
        g_return_if_fail (iCurrentFileType < CD_NB_FILE_TYPES && myConfig.cCustomScripts[iCurrentFileType] != NULL);
 
34
        
 
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);
 
38
        g_free (cCommand);
 
39
        if (cResult == NULL || *cResult == '\0')
 
40
        {
 
41
                return ;
 
42
        }
 
43
        
 
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';
 
48
        
 
49
        // On prend la derniere ligne, au cas ou le script aurait blablate sur la sortie.
 
50
        gchar *str = strrchr (cResult, '\n');
 
51
        if (str != NULL)
 
52
                str ++;
 
53
        else
 
54
                str = cResult;
 
55
        
 
56
        if (! cairo_dock_string_is_adress (str))
 
57
                cd_warning ("this adress (%s) seems not valid !\nThe output was : '%s'", str, cResult);
 
58
        
 
59
        // Enfin on remplit la memoire partagee avec nos URLs.
 
60
        cResultUrls[0] = g_strdup (str);
 
61
        g_free (cResult);
 
62
}
 
63
 
 
64
static void upload_text (const gchar *cFilePath, gchar *cDropboxDir, gboolean bAnonymous, gint iLimitRate, gchar **cResultUrls)
 
65
{
 
66
        _upload (CD_TYPE_TEXT, cFilePath, cDropboxDir, bAnonymous, iLimitRate, cResultUrls);
 
67
}
 
68
 
 
69
static void upload_image (const gchar *cFilePath, gchar *cDropboxDir, gboolean bAnonymous, gint iLimitRate, gchar **cResultUrls)
 
70
{
 
71
        _upload (CD_TYPE_IMAGE, cFilePath, cDropboxDir, bAnonymous, iLimitRate, cResultUrls);
 
72
}
 
73
 
 
74
static void upload_video (const gchar *cFilePath, gchar *cDropboxDir, gboolean bAnonymous, gint iLimitRate, gchar **cResultUrls)
 
75
{
 
76
        _upload (CD_TYPE_VIDEO, cFilePath, cDropboxDir, bAnonymous, iLimitRate, cResultUrls);
 
77
}
 
78
 
 
79
static void upload_file (const gchar *cFilePath, gchar *cDropboxDir, gboolean bAnonymous, gint iLimitRate, gchar **cResultUrls)
 
80
{
 
81
        _upload (CD_TYPE_FILE, cFilePath, cDropboxDir, bAnonymous, iLimitRate, cResultUrls);
 
82
}
 
83
 
 
84
static const CDUploadFunc upload_funcs[CD_NB_FILE_TYPES] = {upload_text, upload_image, upload_video, upload_file};
 
85
 
 
86
void cd_dnd2share_register_custom_backends (void)
 
87
{
 
88
        CDFileType t;
 
89
        for (t = 0; t < CD_NB_FILE_TYPES; t ++)
 
90
        {
 
91
                cd_dnd2share_register_new_backend (t,
 
92
                        "custom",
 
93
                        NB_URLS,
 
94
                        s_UrlLabels,
 
95
                        0,
 
96
                        upload_funcs[t]);
 
97
        }
 
98
}