~cairo-dock-team/ubuntu/precise/cairo-dock-plug-ins/3.0.0.1

« back to all changes in this revision

Viewing changes to dnd2share/src/applet-notifications.c

  • Committer: Bazaar Package Importer
  • Author(s): Julien Lavergne, Matthieu Baerts (matttbe), Julien Lavergne
  • Date: 2009-10-05 19:27:17 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20091005192717-mvqvb395guktr401
Tags: 2.0.9-0ubuntu1
[ Matthieu Baerts (matttbe) ]
* New upstream release (LP: #435590)
* debian/control: 
 - Remove ${shlibs:Depends} for integration plug-ins to avoid
   pulling shared libraries which are detected automatically.
 - Added curl as depends for cairo-dock-plug-ins
* debian/rules:
 - Add --enable-dnd2share and --enable-musicplayer to enable new applets.
 - Remove --enable-rhythmbox and --enable-nvidia to remove those applets,
   not maintained upstream.
* Update *.install to take all generated applets.

[ Julien Lavergne ]
* Adjust changelog with Daniel Holbach suggestions.
* cairo-dock-plug-ins.changelogs:  Install specific changelog for 2.0.9
* Build-depends on cairo-dock-dev (>= 2.0.9)

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
#include <stdlib.h>
 
21
#include <string.h>
 
22
 
 
23
#include "applet-struct.h"
 
24
#include "applet-notifications.h"
 
25
#include "applet-dnd2share.h"
 
26
 
 
27
static void _clear_history (GtkMenuItem *menu_item, gpointer *data)
 
28
{       
 
29
        int iAnswer = cairo_dock_ask_question_and_wait (D_("Clear the list of the recently uploaded files ?"), myIcon, myContainer);
 
30
        if (iAnswer == GTK_RESPONSE_YES)
 
31
        {
 
32
                cd_dnd2share_clear_working_directory ();
 
33
                cd_dnd2share_clear_history ();
 
34
        }
 
35
}
 
36
 
 
37
static void _show_local_file (GtkMenuItem *menu_item, CDUploadedItem *pItem)
 
38
{
 
39
        if (pItem->iFileType == CD_TYPE_TEXT)
 
40
        {
 
41
                cd_dnd2share_copy_url_to_clipboard (pItem->cLocalPath);
 
42
                if (myConfig.bEnableDialogs)
 
43
                {
 
44
                        cairo_dock_remove_dialog_if_any (myIcon);
 
45
                        cairo_dock_show_temporary_dialog_with_icon (D_("The text has been pasted in the clipboard.\nYou can retrieve it with CTRL+v."),
 
46
                                myIcon,
 
47
                                myContainer,
 
48
                                myConfig.dTimeDialogs,
 
49
                                MY_APPLET_SHARE_DATA_DIR"/"MY_APPLET_ICON_FILE);
 
50
                }
 
51
        }
 
52
        else
 
53
        {
 
54
                if (g_file_test (pItem->cLocalPath, G_FILE_TEST_EXISTS))
 
55
                        cairo_dock_fm_launch_uri (pItem->cLocalPath);
 
56
                else
 
57
                {
 
58
                        gchar *cPreviewPath = g_strdup_printf ("%s/%s", myData.cWorkingDirPath, pItem->cItemName);
 
59
                        if (g_file_test (cPreviewPath, G_FILE_TEST_EXISTS))
 
60
                        {
 
61
                                cairo_dock_fm_launch_uri (cPreviewPath);
 
62
                        }
 
63
                        else
 
64
                        {
 
65
                                cd_warning ("couldn't find the orignial file nor a preview of it");
 
66
                                cairo_dock_remove_dialog_if_any (myIcon);
 
67
                                cairo_dock_show_temporary_dialog_with_icon (D_("Sorry, couldn't find the orignial file nor a preview of it."),
 
68
                                        myIcon,
 
69
                                        myContainer,
 
70
                                        myConfig.dTimeDialogs,
 
71
                                        MY_APPLET_SHARE_DATA_DIR"/"MY_APPLET_ICON_FILE);
 
72
                        }
 
73
                        g_free (cPreviewPath);
 
74
                }
 
75
        }
 
76
}
 
77
static void _remove_from_history (GtkMenuItem *menu_item, CDUploadedItem *pItem)
 
78
{
 
79
        cd_dnd2share_remove_one_item (pItem);
 
80
}
 
81
 
 
82
static void _copy_url_into_clipboard (GtkMenuItem *menu_item, const gchar *cURL)
 
83
{
 
84
        cd_dnd2share_copy_url_to_clipboard (cURL);
 
85
        if (myConfig.bEnableDialogs)
 
86
        {
 
87
                cairo_dock_remove_dialog_if_any (myIcon);
 
88
                cairo_dock_show_temporary_dialog_with_icon (D_("The URL has been stored into the clipboard.\nJust use 'CTRL+v' to paste it anywhere."),
 
89
                        myIcon,
 
90
                        myContainer,
 
91
                        myConfig.dTimeDialogs,
 
92
                        MY_APPLET_SHARE_DATA_DIR"/"MY_APPLET_ICON_FILE);
 
93
        }
 
94
 
95
 
 
96
static void _store_last_url (gboolean bIntoClipboard)
 
97
{
 
98
        if (myData.cLastURL == NULL)
 
99
        {
 
100
                cairo_dock_remove_dialog_if_any (myIcon);
 
101
                cairo_dock_show_temporary_dialog_with_icon (myConfig.iNbItems != 0 ?
 
102
                        D_("No uploaded file available\n.Just drag'n drop a file on the icon to upload it") :
 
103
                        D_("No uploaded file available\n.Consider activating the history if you want the applet remembers previous uploads."),
 
104
                myIcon,
 
105
                myContainer,
 
106
                myConfig.dTimeDialogs,
 
107
                MY_APPLET_SHARE_DATA_DIR"/"MY_APPLET_ICON_FILE);
 
108
        }
 
109
        else
 
110
        {
 
111
                if (bIntoClipboard)
 
112
                        cd_dnd2share_copy_url_to_clipboard (myData.cLastURL);
 
113
                else
 
114
                        cd_dnd2share_copy_url_to_primary (myData.cLastURL);
 
115
                
 
116
                if (myConfig.bEnableDialogs)
 
117
                {
 
118
                        cairo_dock_remove_dialog_if_any (myIcon);
 
119
                        cairo_dock_show_temporary_dialog_with_icon (bIntoClipboard ? 
 
120
                                        D_("The current URL has been stored into the clipboard.\nJust use 'CTRL+v' to paste it anywhere.") :
 
121
                                        D_("The current URL has been stored into the selection.\nJust middle-click to paste it anywhere."),
 
122
                                myIcon,
 
123
                                myContainer,
 
124
                                myConfig.dTimeDialogs,
 
125
                                MY_APPLET_SHARE_DATA_DIR"/"MY_APPLET_ICON_FILE);
 
126
                }
 
127
        }
 
128
}
 
129
 
 
130
//\___________ Define here the action to be taken when the user left-clicks on your icon or on its subdock or your desklet. The icon and the container that were clicked are available through the macros CD_APPLET_CLICKED_ICON and CD_APPLET_CLICKED_CONTAINER. CD_APPLET_CLICKED_ICON may be NULL if the user clicked in the container but out of icons.
 
131
CD_APPLET_ON_CLICK_BEGIN
 
132
        _store_last_url (TRUE);
 
133
CD_APPLET_ON_CLICK_END
 
134
 
 
135
 
 
136
CD_APPLET_ON_DROP_DATA_BEGIN
 
137
        g_print  ("DND2SHARE : drop de '%s'\n", CD_APPLET_RECEIVED_DATA);
 
138
        CDFileType iFileType = CD_UNKNOWN_TYPE;
 
139
        
 
140
        gchar *cFilePath = NULL;
 
141
        if( strncmp(CD_APPLET_RECEIVED_DATA, "file://", 7) == 0)
 
142
        {
 
143
                // Les formats supportés par Uppix.net sont : GIF, JPEG, PNG, Flash (SWF or SWC), BMP, PSD, TIFF, JP2, JPX,
 
144
                // JB2, JPC, WBMP, and XBM.
 
145
                // ... mais l'applet ne prendra en charge que les plus utilisés :
 
146
                
 
147
                cFilePath = g_filename_from_uri (CD_APPLET_RECEIVED_DATA, NULL, NULL);  // on passe en encodage UTF-8.
 
148
                if (cFilePath == NULL)
 
149
                        return  CAIRO_DOCK_LET_PASS_NOTIFICATION;
 
150
                
 
151
                guint64 iSize;
 
152
                time_t iLastModificationTime;
 
153
                gchar *cMimeType = NULL;
 
154
                int iUID, iGID, iPermissionsMask;
 
155
                if (cairo_dock_fm_get_file_properties (CD_APPLET_RECEIVED_DATA, &iSize, &iLastModificationTime, &cMimeType, &iUID, &iGID, &iPermissionsMask))
 
156
                {
 
157
                        if (cMimeType != NULL)
 
158
                        {
 
159
                                g_print ("cMimeType : %s (%s)\n", cMimeType, CD_APPLET_RECEIVED_DATA);
 
160
                                if (strncmp (cMimeType, "image", 5) == 0)
 
161
                                        iFileType = CD_TYPE_IMAGE;
 
162
                                else if (strncmp (cMimeType, "video", 5) == 0)
 
163
                                        iFileType = CD_TYPE_VIDEO;
 
164
                        }
 
165
                        g_free (cMimeType);
 
166
                }
 
167
                
 
168
                if (iFileType == CD_UNKNOWN_TYPE)
 
169
                {
 
170
                        if (g_str_has_suffix(CD_APPLET_RECEIVED_DATA,"jpg") 
 
171
                                || g_str_has_suffix(CD_APPLET_RECEIVED_DATA,"JPG")
 
172
                                || g_str_has_suffix(CD_APPLET_RECEIVED_DATA,"jpeg")
 
173
                                || g_str_has_suffix(CD_APPLET_RECEIVED_DATA,"JPEG")
 
174
                                || g_str_has_suffix(CD_APPLET_RECEIVED_DATA,"GIF")
 
175
                                || g_str_has_suffix(CD_APPLET_RECEIVED_DATA,"gif")
 
176
                                || g_str_has_suffix(CD_APPLET_RECEIVED_DATA,"PNG")
 
177
                                || g_str_has_suffix(CD_APPLET_RECEIVED_DATA,"png")
 
178
                                || g_str_has_suffix(CD_APPLET_RECEIVED_DATA,"BMP")
 
179
                                || g_str_has_suffix(CD_APPLET_RECEIVED_DATA,"bmp")
 
180
                                || g_str_has_suffix(CD_APPLET_RECEIVED_DATA,"TIFF")
 
181
                                || g_str_has_suffix(CD_APPLET_RECEIVED_DATA,"tiff"))
 
182
                                iFileType = CD_TYPE_IMAGE;
 
183
                        else if (g_str_has_suffix(CD_APPLET_RECEIVED_DATA,"avi") 
 
184
                                || g_str_has_suffix(CD_APPLET_RECEIVED_DATA,"AVI")
 
185
                                || g_str_has_suffix(CD_APPLET_RECEIVED_DATA,"mov")
 
186
                                || g_str_has_suffix(CD_APPLET_RECEIVED_DATA,"ogg")
 
187
                                || g_str_has_suffix(CD_APPLET_RECEIVED_DATA,"mp4"))
 
188
                                iFileType = CD_TYPE_VIDEO;
 
189
                }
 
190
        }
 
191
        else  // c'est du texte.
 
192
        {
 
193
                g_print ("TEXT\n");
 
194
                iFileType = CD_TYPE_TEXT;
 
195
        }
 
196
        
 
197
        if (iFileType == CD_UNKNOWN_TYPE)
 
198
        {
 
199
                iFileType = CD_TYPE_FILE;
 
200
                g_print ("we'll consider this as an archive.");
 
201
        }
 
202
        cd_dnd2share_launch_upload (cFilePath ? cFilePath : CD_APPLET_RECEIVED_DATA, iFileType);
 
203
        g_free (cFilePath);
 
204
        
 
205
CD_APPLET_ON_DROP_DATA_END
 
206
 
 
207
 
 
208
CD_APPLET_ON_SCROLL_BEGIN
 
209
        if (myData.pUpoadedItems == NULL)
 
210
                return CAIRO_DOCK_LET_PASS_NOTIFICATION;
 
211
        
 
212
        CDUploadedItem *pItem;
 
213
        if (CD_APPLET_SCROLL_DOWN)
 
214
        {
 
215
                myData.iCurrentItemNum ++;  // item suivant.
 
216
                pItem = g_list_nth_data (myData.pUpoadedItems, myData.iCurrentItemNum);
 
217
                if (pItem == NULL)
 
218
                {
 
219
                        pItem = myData.pUpoadedItems->data;
 
220
                        myData.iCurrentItemNum = 0;
 
221
                }
 
222
        }
 
223
        else if (CD_APPLET_SCROLL_UP)
 
224
        {
 
225
                myData.iCurrentItemNum --;  // item precedent.
 
226
                pItem = g_list_nth_data (myData.pUpoadedItems, myData.iCurrentItemNum);
 
227
                if (pItem == NULL)
 
228
                {
 
229
                        pItem = g_list_last (myData.pUpoadedItems)->data;
 
230
                        myData.iCurrentItemNum = g_list_length (myData.pUpoadedItems) - 1;
 
231
                }
 
232
        }
 
233
        g_free (myData.cLastURL);
 
234
        myData.cLastURL = NULL;
 
235
        
 
236
        g_return_val_if_fail (pItem != NULL, CAIRO_DOCK_LET_PASS_NOTIFICATION);  // parano
 
237
        
 
238
        myData.cLastURL = g_strdup (cd_dnd2share_get_prefered_url_from_item (pItem));
 
239
        if (myConfig.bDisplayLastImage)
 
240
        {
 
241
                gchar *cPreview = g_strdup_printf ("%s/%s", myData.cWorkingDirPath, pItem->cItemName);
 
242
                if (g_file_test (cPreview, G_FILE_TEST_EXISTS))
 
243
                {
 
244
                        CD_APPLET_SET_IMAGE_ON_MY_ICON (cPreview);
 
245
                        g_free (cPreview);
 
246
                }
 
247
                else
 
248
                {
 
249
                        cPreview = pItem->cLocalPath;
 
250
                        if (g_file_test (cPreview, G_FILE_TEST_EXISTS))
 
251
                        {
 
252
                                CD_APPLET_SET_IMAGE_ON_MY_ICON (cPreview);
 
253
                        }
 
254
                        else
 
255
                        {
 
256
                                CD_APPLET_SET_IMAGE_ON_MY_ICON (MY_APPLET_SHARE_DATA_DIR"/"MY_APPLET_ICON_FILE);
 
257
                        }
 
258
                }
 
259
                CD_APPLET_REDRAW_MY_ICON;
 
260
        }
 
261
        
 
262
        if (myConfig.bEnableDialogs)
 
263
        {
 
264
                cairo_dock_remove_dialog_if_any (myIcon);
 
265
                cairo_dock_show_temporary_dialog ("%s '%s' (n°%d):\n%s",
 
266
                        myIcon,
 
267
                        myContainer,
 
268
                        myConfig.dTimeDialogs,
 
269
                        (pItem->iFileType == CD_TYPE_TEXT ? D_("Text") : D_("File")),
 
270
                        pItem->cFileName,
 
271
                        myData.iCurrentItemNum,
 
272
                        D_("Click on the icon to copy the URL into the clipboard."));
 
273
        }
 
274
CD_APPLET_ON_SCROLL_END
 
275
 
 
276
 
 
277
CD_APPLET_ON_MIDDLE_CLICK_BEGIN
 
278
        _store_last_url (FALSE);
 
279
CD_APPLET_ON_MIDDLE_CLICK_END
 
280
 
 
281
 
 
282
//\___________ Define here the entries you want to add to the menu when the user right-clicks on your icon or on its subdock or your desklet. The icon and the container that were clicked are available through the macros CD_APPLET_CLICKED_ICON and CD_APPLET_CLICKED_CONTAINER. CD_APPLET_CLICKED_ICON may be NULL if the user clicked in the container but out of icons. The menu where you can add your entries is available throught the macro CD_APPLET_MY_MENU; you can add sub-menu to it if you want.
 
283
CD_APPLET_ON_BUILD_MENU_BEGIN
 
284
        GtkWidget *pModuleSubMenu = CD_APPLET_CREATE_MY_SUB_MENU ();
 
285
        
 
286
        if (myData.pUpoadedItems != NULL)
 
287
                CD_APPLET_ADD_IN_MENU (D_("Clear History"), _clear_history, CD_APPLET_MY_MENU);
 
288
        
 
289
        CDSiteBackend *pBackend;
 
290
        CDUploadedItem *pItem;
 
291
        GtkWidget *pItemSubMenu;
 
292
        gchar *str;
 
293
        gchar *cName = NULL, *cURI = NULL, *cIconName = NULL;
 
294
        gboolean bIsDirectory;
 
295
        int iVolumeID;
 
296
        double fOrder;
 
297
        int i;
 
298
        GList *it;
 
299
        for (it = myData.pUpoadedItems; it != NULL; it = it->next)
 
300
        {
 
301
                pItem = it->data;
 
302
                
 
303
                // on cherche une miniature a mettre dans le menu.
 
304
                gchar *cPreview = NULL;
 
305
                if (pItem->iFileType == CD_TYPE_IMAGE)
 
306
                {
 
307
                        cPreview = g_strdup_printf ("%s/%s", myData.cWorkingDirPath, pItem->cItemName);
 
308
                        if (! g_file_test (cPreview, G_FILE_TEST_EXISTS))
 
309
                        {
 
310
                                g_free (cPreview);
 
311
                                cPreview = cairo_dock_search_icon_s_path ("image-x-generic");;
 
312
                        }
 
313
                }
 
314
                else if (pItem->iFileType == CD_TYPE_TEXT)
 
315
                {
 
316
                        cPreview = cairo_dock_search_icon_s_path ("text-x-generic");
 
317
                }
 
318
                else if (pItem->iFileType == CD_TYPE_VIDEO)
 
319
                {
 
320
                        cPreview = cairo_dock_search_icon_s_path ("video-x-generic");
 
321
                }
 
322
                if (cPreview == NULL)
 
323
                {
 
324
                        cairo_dock_fm_get_file_info (pItem->cLocalPath, &cName, &cURI, &cPreview, &bIsDirectory, &iVolumeID, &fOrder, 0);
 
325
                        g_free (cName);
 
326
                        cName = NULL;
 
327
                        g_free (cURI);
 
328
                        cURI = NULL;
 
329
                }
 
330
                
 
331
                // on cree un sous-menu pour ce fichier.
 
332
                str = strchr (pItem->cFileName, '\n');
 
333
                if (str)
 
334
                        *str = '\0';
 
335
                pItemSubMenu = CD_APPLET_ADD_SUB_MENU_WITH_IMAGE (pItem->cFileName, pModuleSubMenu, cPreview);
 
336
                if (str)
 
337
                        *str = '\n';
 
338
                g_free (cPreview);
 
339
                
 
340
                // on le peuple avec les liens.
 
341
                pBackend = &myData.backends[pItem->iFileType][pItem->iSiteID];
 
342
                for (i = 0; i < pBackend->iNbUrls; i ++)
 
343
                {
 
344
                        //g_print ("%d) %s : ", i, pBackend->cUrlLabels[i]);
 
345
                        //g_print (" + %s\n", pItem->cDistantUrls[i]);
 
346
                        CD_APPLET_ADD_IN_MENU_WITH_DATA (pBackend->cUrlLabels[i], _copy_url_into_clipboard, pItemSubMenu, pItem->cDistantUrls[i]);
 
347
                }
 
348
                if (pItem->iFileType != CD_TYPE_TEXT)
 
349
                        CD_APPLET_ADD_IN_MENU_WITH_DATA (D_("Open file"), _show_local_file, pItemSubMenu, pItem);
 
350
                else
 
351
                        CD_APPLET_ADD_IN_MENU_WITH_DATA (D_("Get text"), _show_local_file, pItemSubMenu, pItem);
 
352
                
 
353
                CD_APPLET_ADD_IN_MENU_WITH_STOCK_AND_DATA (D_("Remove from history"), GTK_STOCK_REMOVE, _remove_from_history, pItemSubMenu, pItem);
 
354
        }
 
355
        
 
356
        CD_APPLET_ADD_ABOUT_IN_MENU (CD_APPLET_MY_MENU);
 
357
CD_APPLET_ON_BUILD_MENU_END