2
* This file is a part of the Cairo-Dock project
4
* Copyright : (C) see the 'copyright' file.
5
* E-mail : see the 'copyright' file.
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.
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/>.
23
#include "applet-struct.h"
24
#include "applet-notifications.h"
25
#include "applet-dnd2share.h"
27
static void _clear_history (GtkMenuItem *menu_item, gpointer *data)
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)
32
cd_dnd2share_clear_working_directory ();
33
cd_dnd2share_clear_history ();
37
static void _show_local_file (GtkMenuItem *menu_item, CDUploadedItem *pItem)
39
if (pItem->iFileType == CD_TYPE_TEXT)
41
cd_dnd2share_copy_url_to_clipboard (pItem->cLocalPath);
42
if (myConfig.bEnableDialogs)
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."),
48
myConfig.dTimeDialogs,
49
MY_APPLET_SHARE_DATA_DIR"/"MY_APPLET_ICON_FILE);
54
if (g_file_test (pItem->cLocalPath, G_FILE_TEST_EXISTS))
55
cairo_dock_fm_launch_uri (pItem->cLocalPath);
58
gchar *cPreviewPath = g_strdup_printf ("%s/%s", myData.cWorkingDirPath, pItem->cItemName);
59
if (g_file_test (cPreviewPath, G_FILE_TEST_EXISTS))
61
cairo_dock_fm_launch_uri (cPreviewPath);
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."),
70
myConfig.dTimeDialogs,
71
MY_APPLET_SHARE_DATA_DIR"/"MY_APPLET_ICON_FILE);
73
g_free (cPreviewPath);
77
static void _remove_from_history (GtkMenuItem *menu_item, CDUploadedItem *pItem)
79
cd_dnd2share_remove_one_item (pItem);
82
static void _copy_url_into_clipboard (GtkMenuItem *menu_item, const gchar *cURL)
84
cd_dnd2share_copy_url_to_clipboard (cURL);
85
if (myConfig.bEnableDialogs)
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."),
91
myConfig.dTimeDialogs,
92
MY_APPLET_SHARE_DATA_DIR"/"MY_APPLET_ICON_FILE);
96
static void _store_last_url (gboolean bIntoClipboard)
98
if (myData.cLastURL == NULL)
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."),
106
myConfig.dTimeDialogs,
107
MY_APPLET_SHARE_DATA_DIR"/"MY_APPLET_ICON_FILE);
112
cd_dnd2share_copy_url_to_clipboard (myData.cLastURL);
114
cd_dnd2share_copy_url_to_primary (myData.cLastURL);
116
if (myConfig.bEnableDialogs)
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."),
124
myConfig.dTimeDialogs,
125
MY_APPLET_SHARE_DATA_DIR"/"MY_APPLET_ICON_FILE);
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
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;
140
gchar *cFilePath = NULL;
141
if( strncmp(CD_APPLET_RECEIVED_DATA, "file://", 7) == 0)
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 :
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;
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))
157
if (cMimeType != NULL)
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;
168
if (iFileType == CD_UNKNOWN_TYPE)
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;
191
else // c'est du texte.
194
iFileType = CD_TYPE_TEXT;
197
if (iFileType == CD_UNKNOWN_TYPE)
199
iFileType = CD_TYPE_FILE;
200
g_print ("we'll consider this as an archive.");
202
cd_dnd2share_launch_upload (cFilePath ? cFilePath : CD_APPLET_RECEIVED_DATA, iFileType);
205
CD_APPLET_ON_DROP_DATA_END
208
CD_APPLET_ON_SCROLL_BEGIN
209
if (myData.pUpoadedItems == NULL)
210
return CAIRO_DOCK_LET_PASS_NOTIFICATION;
212
CDUploadedItem *pItem;
213
if (CD_APPLET_SCROLL_DOWN)
215
myData.iCurrentItemNum ++; // item suivant.
216
pItem = g_list_nth_data (myData.pUpoadedItems, myData.iCurrentItemNum);
219
pItem = myData.pUpoadedItems->data;
220
myData.iCurrentItemNum = 0;
223
else if (CD_APPLET_SCROLL_UP)
225
myData.iCurrentItemNum --; // item precedent.
226
pItem = g_list_nth_data (myData.pUpoadedItems, myData.iCurrentItemNum);
229
pItem = g_list_last (myData.pUpoadedItems)->data;
230
myData.iCurrentItemNum = g_list_length (myData.pUpoadedItems) - 1;
233
g_free (myData.cLastURL);
234
myData.cLastURL = NULL;
236
g_return_val_if_fail (pItem != NULL, CAIRO_DOCK_LET_PASS_NOTIFICATION); // parano
238
myData.cLastURL = g_strdup (cd_dnd2share_get_prefered_url_from_item (pItem));
239
if (myConfig.bDisplayLastImage)
241
gchar *cPreview = g_strdup_printf ("%s/%s", myData.cWorkingDirPath, pItem->cItemName);
242
if (g_file_test (cPreview, G_FILE_TEST_EXISTS))
244
CD_APPLET_SET_IMAGE_ON_MY_ICON (cPreview);
249
cPreview = pItem->cLocalPath;
250
if (g_file_test (cPreview, G_FILE_TEST_EXISTS))
252
CD_APPLET_SET_IMAGE_ON_MY_ICON (cPreview);
256
CD_APPLET_SET_IMAGE_ON_MY_ICON (MY_APPLET_SHARE_DATA_DIR"/"MY_APPLET_ICON_FILE);
259
CD_APPLET_REDRAW_MY_ICON;
262
if (myConfig.bEnableDialogs)
264
cairo_dock_remove_dialog_if_any (myIcon);
265
cairo_dock_show_temporary_dialog ("%s '%s' (n°%d):\n%s",
268
myConfig.dTimeDialogs,
269
(pItem->iFileType == CD_TYPE_TEXT ? D_("Text") : D_("File")),
271
myData.iCurrentItemNum,
272
D_("Click on the icon to copy the URL into the clipboard."));
274
CD_APPLET_ON_SCROLL_END
277
CD_APPLET_ON_MIDDLE_CLICK_BEGIN
278
_store_last_url (FALSE);
279
CD_APPLET_ON_MIDDLE_CLICK_END
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 ();
286
if (myData.pUpoadedItems != NULL)
287
CD_APPLET_ADD_IN_MENU (D_("Clear History"), _clear_history, CD_APPLET_MY_MENU);
289
CDSiteBackend *pBackend;
290
CDUploadedItem *pItem;
291
GtkWidget *pItemSubMenu;
293
gchar *cName = NULL, *cURI = NULL, *cIconName = NULL;
294
gboolean bIsDirectory;
299
for (it = myData.pUpoadedItems; it != NULL; it = it->next)
303
// on cherche une miniature a mettre dans le menu.
304
gchar *cPreview = NULL;
305
if (pItem->iFileType == CD_TYPE_IMAGE)
307
cPreview = g_strdup_printf ("%s/%s", myData.cWorkingDirPath, pItem->cItemName);
308
if (! g_file_test (cPreview, G_FILE_TEST_EXISTS))
311
cPreview = cairo_dock_search_icon_s_path ("image-x-generic");;
314
else if (pItem->iFileType == CD_TYPE_TEXT)
316
cPreview = cairo_dock_search_icon_s_path ("text-x-generic");
318
else if (pItem->iFileType == CD_TYPE_VIDEO)
320
cPreview = cairo_dock_search_icon_s_path ("video-x-generic");
322
if (cPreview == NULL)
324
cairo_dock_fm_get_file_info (pItem->cLocalPath, &cName, &cURI, &cPreview, &bIsDirectory, &iVolumeID, &fOrder, 0);
331
// on cree un sous-menu pour ce fichier.
332
str = strchr (pItem->cFileName, '\n');
335
pItemSubMenu = CD_APPLET_ADD_SUB_MENU_WITH_IMAGE (pItem->cFileName, pModuleSubMenu, cPreview);
340
// on le peuple avec les liens.
341
pBackend = &myData.backends[pItem->iFileType][pItem->iSiteID];
342
for (i = 0; i < pBackend->iNbUrls; i ++)
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]);
348
if (pItem->iFileType != CD_TYPE_TEXT)
349
CD_APPLET_ADD_IN_MENU_WITH_DATA (D_("Open file"), _show_local_file, pItemSubMenu, pItem);
351
CD_APPLET_ADD_IN_MENU_WITH_DATA (D_("Get text"), _show_local_file, pItemSubMenu, pItem);
353
CD_APPLET_ADD_IN_MENU_WITH_STOCK_AND_DATA (D_("Remove from history"), GTK_STOCK_REMOVE, _remove_from_history, pItemSubMenu, pItem);
356
CD_APPLET_ADD_ABOUT_IN_MENU (CD_APPLET_MY_MENU);
357
CD_APPLET_ON_BUILD_MENU_END