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-trashes-manager.h"
25
#include "applet-notifications.h"
27
static void _cd_dustbin_delete_trash (GtkMenuItem *menu_item, CairoDockModuleInstance *myApplet)
29
int iAnswer = GTK_RESPONSE_YES;
30
if (myConfig.bAskBeforeDelete)
32
iAnswer = cairo_dock_ask_question_and_wait (D_("You're about to delete all files in all dustbins. Sure ?"), myIcon, myContainer);
35
if (iAnswer == GTK_RESPONSE_YES)
36
cairo_dock_fm_empty_trash ();
39
static void _cd_dustbin_show_trash (GtkMenuItem *menu_item, CairoDockModuleInstance *myApplet)
41
cairo_dock_fm_launch_uri ("trash:/"/**myData.cDustbinPath*/); // on force l'utilisation de trash:/ ici, car on sait que tous les backends sauront l'ouvrir.
45
static void _free_info_dialog (CairoDockModuleInstance *myApplet)
47
myData.pInfoDialog = NULL;
48
if (myData.pInfoTask != NULL)
50
cairo_dock_discard_task (myData.pInfoTask);
51
myData.pInfoTask = NULL;
54
static void _measure_trash (CairoDockModuleInstance *myApplet)
56
myData._iInfoMeasure = cairo_dock_fm_measure_diretory (myData.cDustbinPath, (myConfig.iQuickInfoType == CD_DUSTBIN_INFO_WEIGHT ? 0 : 1), TRUE, &myData.pInfoTask->bDiscard);
58
static gboolean _display_result (CairoDockModuleInstance *myApplet)
60
if (myData.pInfoDialog != NULL)
62
int iSize=-1, iNbFiles=-1, iTrashes=-1;
63
if (myConfig.iQuickInfoType == CD_DUSTBIN_INFO_WEIGHT)
65
iSize = myData.iMeasure;
66
iNbFiles = myData._iInfoMeasure;
70
iSize = myData._iInfoMeasure;
71
if (myConfig.iQuickInfoType == CD_DUSTBIN_INFO_NB_FILES)
72
iNbFiles = myData.iMeasure;
76
iTrashes = cairo_dock_fm_measure_diretory (myData.cDustbinPath, 0, FALSE, &iCancel); // ca c'est rapide.
80
cairo_dock_set_dialog_message_printf (myData.pInfoDialog, "%s :\n %d %s\n %.2f %s", D_("The trash contains"),
81
iNbFiles > -1 ? iNbFiles : iTrashes,
82
iNbFiles > -1 ? D_("files") : D_("elements"),
83
(iSize > 1e6 ? (iSize >> 10) / 1024. : iSize / 1024.),
84
(iSize > 1e6 ? D_("Mo") : D_("Ko")));
87
static void _cd_dustbin_show_info (GtkMenuItem *menu_item, CairoDockModuleInstance *myApplet)
89
gsize iSize, iNbFiles;
92
if (myData.pInfoDialog != NULL)
93
cairo_dock_dialog_unreference (myData.pInfoDialog);
94
if (myData.pInfoTask != NULL)
95
cairo_dock_discard_task (myData.pInfoTask);
97
CairoDialogAttribute attr;
98
memset (&attr, 0, sizeof (CairoDialogAttribute));
99
attr.cImageFilePath = "same icon";
100
attr.cText = g_strdup_printf ("%s ...\n\n", D_("Counting total size and files number..."));
101
attr.pFreeDataFunc = (GFreeFunc)_free_info_dialog;
102
attr.pUserData = myApplet;
103
myData.pInfoDialog = cairo_dock_build_dialog (&attr, myIcon, myContainer);
105
// launch the task and update the dialog when finished.
106
myData.pInfoTask = cairo_dock_new_task (0,
107
(CairoDockGetDataAsyncFunc) _measure_trash,
108
(CairoDockUpdateSyncFunc) _display_result,
110
cairo_dock_launch_task (myData.pInfoTask);
113
CD_APPLET_ON_BUILD_MENU_BEGIN
114
GtkWidget *pModuleSubMenu = CD_APPLET_CREATE_MY_SUB_MENU ();
117
CD_APPLET_ADD_IN_MENU_WITH_STOCK_AND_DATA (D_("Show Trash (click)"), GTK_STOCK_OPEN, _cd_dustbin_show_trash, CD_APPLET_MY_MENU, NULL);
118
gchar *cLabel = g_strdup_printf ("%s (%s)", D_("Empty Trash"), D_("middle-click"));
119
CD_APPLET_ADD_IN_MENU_WITH_STOCK_AND_DATA (cLabel, GTK_STOCK_DELETE, _cd_dustbin_delete_trash, CD_APPLET_MY_MENU, NULL);
122
CD_APPLET_ADD_IN_MENU_WITH_STOCK (D_("Display dustbins information"), GTK_STOCK_INFO, _cd_dustbin_show_info, CD_APPLET_MY_MENU);
125
CD_APPLET_ADD_ABOUT_IN_MENU (pModuleSubMenu);
126
CD_APPLET_ON_BUILD_MENU_END
129
static void _cd_dustbin_action_after_unmount (gboolean bMounting, gboolean bSuccess, const gchar *cName, gpointer data)
131
g_return_if_fail (myIcon != NULL && ! bMounting);
135
cMessage = g_strdup_printf (D_("%s successfully unmounted"), cName);
139
cMessage = g_strdup_printf (D_("failed to unmount %s"), cName);
142
cairo_dock_remove_dialog_if_any (myIcon);
143
cairo_dock_show_temporary_dialog (cMessage, myIcon, myContainer, 4000);
146
CD_APPLET_ON_DROP_DATA_BEGIN
147
cd_message (" '%s' --> a la poubelle !", CD_APPLET_RECEIVED_DATA);
148
gchar *cName=NULL, *cURI=NULL, *cIconName=NULL;
149
gboolean bIsDirectory;
152
if (cairo_dock_fm_get_file_info (CD_APPLET_RECEIVED_DATA,
163
cairo_dock_show_temporary_dialog_with_icon (D_("Unmouting this volume ..."), myIcon, myContainer, 15000., "same icon"); // le dialogue sera enleve lorsque le volume sera demonte.
164
cairo_dock_fm_unmount_full (cURI, iVolumeID, (CairoDockFMMountCallback) _cd_dustbin_action_after_unmount, myApplet);
167
cairo_dock_fm_delete_file (cURI, FALSE);
171
cd_warning ("can't get info for '%s'", CD_APPLET_RECEIVED_DATA);
176
CD_APPLET_ON_DROP_DATA_END
179
CD_APPLET_ON_CLICK_BEGIN
180
_cd_dustbin_show_trash (NULL, myApplet);
181
CD_APPLET_ON_CLICK_END
184
CD_APPLET_ON_MIDDLE_CLICK_BEGIN
185
_cd_dustbin_delete_trash (NULL, myApplet);
186
CD_APPLET_ON_MIDDLE_CLICK_END