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

« back to all changes in this revision

Viewing changes to dnd2share/src/applet-backend-imageshack.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
 
#define _BSD_SOURCE
21
 
#include <stdlib.h>
22
 
#include <math.h>
23
 
#include <unistd.h>
24
 
#include <glib/gstdio.h>
25
 
 
26
 
#include "applet-struct.h"
27
 
#include "applet-dnd2share.h"
28
 
#include "applet-backend-uppix.h"
29
 
 
30
 
#define NB_URLS 2
31
 
static const gchar *s_UrlLabels[NB_URLS] = {"DirectLink", "Thumbnail"};
32
 
 
33
 
 
34
 
static void upload (const gchar *cFilePath)
35
 
{
36
 
        // On cree un fichier de log temporaire.
37
 
        gchar *cLogFile = g_strdup ("/tmp/dnd2share-log.XXXXXX");
38
 
        int fds = mkstemp (cLogFile);
39
 
        if (fds == -1)
40
 
        {
41
 
                g_free (cLogFile);
42
 
                return ;
43
 
        }
44
 
        close(fds);
45
 
        
46
 
        // On lance la commande d'upload.
47
 
        gchar *cCommand = NULL;
48
 
        cCommand = g_strdup_printf ("curl --connect-timeout 5 --retry 2 --limit-rate %dk http://imageshack.us -F xml=yes -F tags=Cairo-Dock -F fileupload=@'%s' -o '%s'", myConfig.iLimitRate, cFilePath, cLogFile);
49
 
        cd_debug ("%s\n", cCommand);
50
 
        int r = system (cCommand);
51
 
        g_free (cCommand);
52
 
        
53
 
        // On récupère l'URL dans le log :
54
 
        gchar *cURL = NULL, *cThumbnail = NULL;
55
 
        gchar *cContent = NULL;
56
 
        gsize length = 0;
57
 
        g_file_get_contents (cLogFile, &cContent, &length, NULL);
58
 
        
59
 
        gchar *str = g_strstr_len (cContent, -1, "<image_link>");
60
 
        if (str != NULL)
61
 
        {
62
 
                str += 12;  // <image_link>http://bla/bla/bla.png</image_link>
63
 
                gchar *end = g_strstr_len (str, -1, "</image_link>");
64
 
                if (end != NULL)
65
 
                {
66
 
                        cURL = g_strndup (str, end - str);
67
 
                }
68
 
        }
69
 
        
70
 
        str = g_strstr_len (cContent, -1, "<thumb_link>");
71
 
        if (str != NULL)
72
 
        {
73
 
                str += 12;  // <thumb_link>http://bla/bla/bla.png</thumb_link>
74
 
                gchar *end = g_strstr_len (str, -1, "</thumb_link>");
75
 
                if (end != NULL)
76
 
                {
77
 
                        cThumbnail = g_strndup (str, end - str);
78
 
                }
79
 
        }       
80
 
        
81
 
        g_free (cContent);
82
 
        g_remove (cLogFile);
83
 
        g_free (cLogFile);
84
 
        
85
 
        if (cURL == NULL)
86
 
        {
87
 
                return ;
88
 
        }
89
 
        
90
 
        // Enfin on remplit la memoire partagee avec nos URLs.
91
 
        myData.cResultUrls[0] = cURL;
92
 
        myData.cResultUrls[1] = cThumbnail;
93
 
}
94
 
 
95
 
 
96
 
void cd_dnd2share_register_imageshack_backend (void)
97
 
{
98
 
        cd_dnd2share_register_new_backend (CD_TYPE_IMAGE,
99
 
                "imageshack.us",
100
 
                NB_URLS,
101
 
                s_UrlLabels,
102
 
                0,
103
 
                upload);
104
 
}
 
18
*/
 
19
 
 
20
#define _BSD_SOURCE
 
21
#include <stdlib.h>
 
22
#include <math.h>
 
23
#include <unistd.h>
 
24
#include <glib/gstdio.h>
 
25
 
 
26
#include "applet-struct.h"
 
27
#include "applet-dnd2share.h"
 
28
#include "applet-backend-uppix.h"
 
29
 
 
30
#define NB_URLS 2
 
31
static const gchar *s_UrlLabels[NB_URLS] = {"DirectLink", "Thumbnail"};
 
32
 
 
33
 
 
34
static void upload (const gchar *cFilePath, gchar *cDropboxDir, gboolean bAnonymous, gint iLimitRate, gchar **cResultUrls)
 
35
{
 
36
        // On cree un fichier de log temporaire.
 
37
        gchar *cLogFile = g_strdup ("/tmp/dnd2share-log.XXXXXX");
 
38
        int fds = mkstemp (cLogFile);
 
39
        if (fds == -1)
 
40
        {
 
41
                g_free (cLogFile);
 
42
                return ;
 
43
        }
 
44
        close(fds);
 
45
        
 
46
        // On lance la commande d'upload.
 
47
        gchar *cCommand = NULL;
 
48
        cCommand = g_strdup_printf ("curl --connect-timeout 5 --retry 2 --limit-rate %dk http://imageshack.us -F xml=yes -F tags=Cairo-Dock -F fileupload=@\"%s\" -o \"%s\"", iLimitRate, cFilePath, cLogFile);
 
49
        cd_debug ("%s", cCommand);
 
50
        int r = system (cCommand);
 
51
        g_free (cCommand);
 
52
        
 
53
        // On récupère l'URL dans le log :
 
54
        gchar *cURL = NULL, *cThumbnail = NULL;
 
55
        gchar *cContent = NULL;
 
56
        gsize length = 0;
 
57
        g_file_get_contents (cLogFile, &cContent, &length, NULL);
 
58
        
 
59
        gchar *str = g_strstr_len (cContent, -1, "<image_link>");
 
60
        if (str != NULL)
 
61
        {
 
62
                str += 12;  // <image_link>http://bla/bla/bla.png</image_link>
 
63
                gchar *end = g_strstr_len (str, -1, "</image_link>");
 
64
                if (end != NULL)
 
65
                {
 
66
                        cURL = g_strndup (str, end - str);
 
67
                }
 
68
        }
 
69
        
 
70
        str = g_strstr_len (cContent, -1, "<thumb_link>");
 
71
        if (str != NULL)
 
72
        {
 
73
                str += 12;  // <thumb_link>http://bla/bla/bla.png</thumb_link>
 
74
                gchar *end = g_strstr_len (str, -1, "</thumb_link>");
 
75
                if (end != NULL)
 
76
                {
 
77
                        cThumbnail = g_strndup (str, end - str);
 
78
                }
 
79
        }       
 
80
        
 
81
        g_free (cContent);
 
82
        g_remove (cLogFile);
 
83
        g_free (cLogFile);
 
84
        
 
85
        if (cURL == NULL)
 
86
        {
 
87
                return ;
 
88
        }
 
89
        
 
90
        // Enfin on remplit la memoire partagee avec nos URLs.
 
91
        cResultUrls[0] = cURL;
 
92
        cResultUrls[1] = cThumbnail;
 
93
}
 
94
 
 
95
 
 
96
void cd_dnd2share_register_imageshack_backend (void)
 
97
{
 
98
        cd_dnd2share_register_new_backend (CD_TYPE_IMAGE,
 
99
                "imageshack.us",
 
100
                NB_URLS,
 
101
                s_UrlLabels,
 
102
                0,
 
103
                upload);
 
104
}