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 _on_answer_delete_trash (int iClickedButton, GtkWidget *pInteractiveWidget, gpointer data, CairoDialog *pDialog)
30
if (iClickedButton == 0 || iClickedButton == -1) // ok button or Enter.
32
cairo_dock_fm_empty_trash ();
36
static void _cd_dustbin_delete_trash (GtkMenuItem *menu_item, GldiModuleInstance *myApplet)
38
if (myConfig.bAskBeforeDelete)
40
gldi_dialog_show_with_question (D_("You're about to delete all files in all dustbins. Sure ?"),
43
(CairoDockActionOnAnswerFunc) _on_answer_delete_trash, NULL, (GFreeFunc)NULL);
47
cairo_dock_fm_empty_trash ();
51
static void _cd_dustbin_show_trash (GtkMenuItem *menu_item, GldiModuleInstance *myApplet)
53
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.
57
static void _free_info_dialog (GldiModuleInstance *myApplet)
59
myData.pInfoDialog = NULL;
60
if (myData.pInfoTask != NULL)
62
gldi_task_discard (myData.pInfoTask);
63
myData.pInfoTask = NULL;
67
static void _free_shared_memory (CDSharedMemory *pSharedMemory)
69
cd_debug ("free dustbin SM");
70
g_free (pSharedMemory->cDustbinPath);
71
g_free (pSharedMemory);
73
static void _measure_trash (CDSharedMemory *pSharedMemory)
75
pSharedMemory->iMeasure = cairo_dock_fm_measure_diretory (pSharedMemory->cDustbinPath,
76
(pSharedMemory->iQuickInfoType == CD_DUSTBIN_INFO_WEIGHT ? 0 : 1),
78
pSharedMemory->bDiscard);
80
static gboolean _display_result (CDSharedMemory *pSharedMemory)
82
if (myData.pInfoDialog != NULL)
84
int iSize=-1, iNbFiles=-1, iTrashes=-1;
85
if (pSharedMemory->iQuickInfoType == CD_DUSTBIN_INFO_WEIGHT)
87
iSize = myData.iMeasure;
88
iNbFiles = pSharedMemory->iMeasure;
92
iSize = pSharedMemory->iMeasure;
93
if (pSharedMemory->iQuickInfoType == CD_DUSTBIN_INFO_NB_FILES)
94
iNbFiles = myData.iMeasure;
98
iTrashes = cairo_dock_fm_measure_diretory (myData.cDustbinPath, 0, FALSE, &iCancel); // ca c'est rapide.
102
gldi_dialog_set_message_printf (myData.pInfoDialog, "%s :\n %d %s\n %.2f %s",
103
D_("The trash contains"),
104
iNbFiles > -1 ? iNbFiles : iTrashes,
105
iNbFiles > -1 ? D_("files") : D_("elements"),
106
(iSize > 1e6 ? (iSize >> 10) / 1024. : iSize / 1024.),
107
(iSize > 1e6 ? D_("Mo") : D_("Ko")));
109
gldi_task_discard (myData.pInfoTask);
110
myData.pInfoTask = NULL;
114
static void _cd_dustbin_show_info (GtkMenuItem *menu_item, GldiModuleInstance *myApplet)
116
if (myData.pInfoDialog != NULL)
118
gldi_object_unref (GLDI_OBJECT(myData.pInfoDialog));
119
myData.pInfoDialog = NULL;
121
g_return_if_fail (myData.pInfoTask == NULL);
123
CairoDialogAttr attr;
124
memset (&attr, 0, sizeof (CairoDialogAttr));
125
attr.cImageFilePath = "same icon";
126
attr.cText = g_strdup_printf ("%s ...\n\n", D_("Counting total size and files number..."));
127
attr.pFreeDataFunc = (GFreeFunc)_free_info_dialog;
129
attr.pContainer = myContainer;
130
attr.pUserData = myApplet;
131
myData.pInfoDialog = gldi_dialog_new (&attr);
133
// launch the task and update the dialog when finished.
134
CDSharedMemory *pSharedMemory = g_new0 (CDSharedMemory, 1);
135
pSharedMemory->cDustbinPath = g_strdup (myData.cDustbinPath);
136
pSharedMemory->iQuickInfoType = myConfig.iQuickInfoType;
137
myData.pInfoTask = gldi_task_new_full (0,
138
(GldiGetDataAsyncFunc) _measure_trash,
139
(GldiUpdateSyncFunc) _display_result,
140
(GFreeFunc) _free_shared_memory,
142
pSharedMemory->bDiscard = &myData.pInfoTask->bDiscard;
144
gldi_task_launch (myData.pInfoTask);
147
CD_APPLET_ON_BUILD_MENU_BEGIN
148
CD_APPLET_ADD_IN_MENU_WITH_STOCK_AND_DATA (D_("Show Trash (click)"), GLDI_ICON_NAME_OPEN, _cd_dustbin_show_trash, CD_APPLET_MY_MENU, NULL);
149
gchar *cLabel = g_strdup_printf ("%s (%s)", D_("Empty Trash"), D_("middle-click"));
150
CD_APPLET_ADD_IN_MENU_WITH_STOCK_AND_DATA (cLabel, GLDI_ICON_NAME_DELETE, _cd_dustbin_delete_trash, CD_APPLET_MY_MENU, NULL);
153
CD_APPLET_ADD_IN_MENU_WITH_STOCK (D_("Display dustbins information"), GLDI_ICON_NAME_INFO, _cd_dustbin_show_info, CD_APPLET_MY_MENU);
154
CD_APPLET_ON_BUILD_MENU_END
157
static void _cd_dustbin_action_after_unmount (gboolean bMounting, gboolean bSuccess, const gchar *cName, gpointer data)
159
g_return_if_fail (myIcon != NULL && ! bMounting);
163
cMessage = g_strdup_printf (D_("%s successfully unmounted"), cName);
167
cMessage = g_strdup_printf (D_("Failed to unmount %s"), cName);
170
gldi_dialogs_remove_on_icon (myIcon);
171
gldi_dialog_show_temporary (cMessage, myIcon, myContainer, 4000);
174
CD_APPLET_ON_DROP_DATA_BEGIN
175
cd_message (" '%s' --> a la poubelle !", CD_APPLET_RECEIVED_DATA);
176
gchar *cName=NULL, *cURI=NULL, *cIconName=NULL;
177
gboolean bIsDirectory;
180
if (cairo_dock_fm_get_file_info (CD_APPLET_RECEIVED_DATA,
191
gldi_dialog_show_temporary_with_icon (D_("Unmouting this volume ..."), myIcon, myContainer, 15000., "same icon"); // le dialogue sera enleve lorsque le volume sera demonte.
192
cairo_dock_fm_unmount_full (cURI, iVolumeID, (CairoDockFMMountCallback) _cd_dustbin_action_after_unmount, myApplet);
195
cairo_dock_fm_delete_file (cURI, FALSE);
199
cd_warning ("can't get info for '%s'", CD_APPLET_RECEIVED_DATA);
204
CD_APPLET_ON_DROP_DATA_END
207
CD_APPLET_ON_CLICK_BEGIN
208
_cd_dustbin_show_trash (NULL, myApplet);
209
CD_APPLET_ON_CLICK_END
212
CD_APPLET_ON_MIDDLE_CLICK_BEGIN
213
_cd_dustbin_delete_trash (NULL, myApplet);
214
CD_APPLET_ON_MIDDLE_CLICK_END