3
// Copyright (C) 2008 GNOME Do
5
// This program is free software: you can redistribute it and/or modify
6
// it under the terms of the GNU General Public License as published by
7
// the Free Software Foundation, either version 3 of the License, or
8
// (at your option) any later version.
10
// This program is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
// GNU General Public License for more details.
15
// You should have received a copy of the GNU General Public License
16
// along with this program. If not, see <http://www.gnu.org/licenses/>.
20
using System.Collections.Generic;
28
using Do.Interface.CairoUtils;
31
using Docky.Utilities;
33
namespace Docky.Interface
37
public class TrashDockItem : BaseDockItem
39
const string TrashEmptyIcon = "gnome-stock-trash";
40
const string TrashFullIcon = "gnome-stock-trash-full";
44
return System.IO.Path.Combine (Environment.GetFolderPath (Environment.SpecialFolder.LocalApplicationData), "Trash/files/");
48
public override bool IsAcceptingDrops {
52
public TrashDockItem()
56
protected override Pixbuf GetSurfacePixbuf ()
58
if (Directory.GetFiles (Trash).Any ())
59
return IconProvider.PixbufFromIconName (TrashFullIcon, DockPreferences.FullIconSize);
60
return IconProvider.PixbufFromIconName (TrashEmptyIcon, DockPreferences.FullIconSize);
63
#region IDockDragAwareItem implementation
65
public override bool ReceiveItem (string item)
67
bool trashHadFiles = Directory.GetFiles (Trash).Any ();
69
if (item.StartsWith ("file://"))
70
item = item.Substring ("file://".Length);
72
// if the file doesn't exist for whatever reason, we bail
73
if (!System.IO.File.Exists (item) && !System.IO.Directory.Exists (item))
77
System.IO.File.Move (item, Path.Combine (Trash, Path.GetFileName (item)));
78
} catch (Exception e) {
79
Log.Error (e.Message);
80
Log.Error ("Could not move {0} to trash", item);
84
// we just added to the trash, so it has files now for sure
93
public override string Description {
95
return Catalog.GetString ("Trash");
99
public override void Clicked (uint button)
102
Services.Environment.OpenUrl ("trash://");
103
AnimationType = ClickAnimationType.Bounce;
105
AnimationType = ClickAnimationType.None;
108
base.Clicked (button);