~ubuntu-branches/ubuntu/wily/gnome-do/wily

« back to all changes in this revision

Viewing changes to Do.Interface.Linux.Docky/src/Docky.Interface/Docky.Interface.Items/TrashDockItem.cs

  • Committer: Bazaar Package Importer
  • Author(s): Christopher James Halse Rogers
  • Date: 2011-02-15 21:50:02 UTC
  • mfrom: (1.1.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20110215215002-1j8ylb69o15asb06
Tags: 0.8.4-0ubuntu1
* The Race Against FF upload.  Merge from unreleased Debian git.
  Remaining Ubuntu changes:
  + debian/patches/05_disable_resize_grips.patch.diff:
    Disable resize handles for the Do windows.
  + debian/control:
    Bump gtk# build dep for HasResizeGrip API.
* New Debian changes:
* The long fortold release
  + Fixes a threadsafety issue resulting in 100% CPU usage (Closes: 565591,
    LP: #450852).
  + Proxies all keyring calls to the GTK main thread, as required by the new
    gnome-keyring (Closes: 603876, LP: #553643)
* debian/patches/00_bundledlibs.dpatch:
* debian/rules:
  + Upstream has dropped bundled gmcs binary; now 100% DFSG-free, so we don't
    have to repack the tarball or patch the buildsystem.
* debian/patches/03_disable_docky.dpatch:
  + Drop.  Docky is now gone in the upstream tarball.
* debian/rules:
* debian/control:
* debian/patches/*:
  + Switch to quilt to harmonise with other pkg-cli-* packages.
* debian/control:
  + Drop recommends on gnome-do-docklets.  Docky is now a separate package,
    so the docklets are useless for Do.
  + Bump Breaks on gnome-do-plugins to 0.8.3.  Do no longer provides the Wink
    library, which has been imported into the 0.8.3 do-plugins sources.
  + Bump standards-version; no changes needed.
  + Migrate to git and update VCS fields appropriately

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// TrashDockItem.cs
2
 
// 
3
 
// Copyright (C) 2008 GNOME Do
4
 
//
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.
9
 
//
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.
14
 
//
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/>.
17
 
//
18
 
 
19
 
using System;
20
 
using System.Collections.Generic;
21
 
using System.IO;
22
 
using System.Linq;
23
 
 
24
 
using Gdk;
25
 
using Gtk;
26
 
using Mono.Unix;
27
 
 
28
 
using Do.Interface;
29
 
using Do.Interface.CairoUtils;
30
 
using Do.Platform;
31
 
 
32
 
using Docky.Utilities;
33
 
using Docky.Interface.Menus;
34
 
 
35
 
namespace Docky.Interface
36
 
{
37
 
        
38
 
        
39
 
        public class TrashDockItem :  AbstractDockletItem, IRightClickable
40
 
        {
41
 
                const string TrashEmptyIcon = "gnome-stock-trash";
42
 
                const string TrashFullIcon = "gnome-stock-trash-full";
43
 
                
44
 
                FileSystemWatcher fsw;
45
 
                
46
 
                string Trash {
47
 
                        get { 
48
 
                                return Path.Combine (Environment.GetFolderPath (Environment.SpecialFolder.LocalApplicationData), "Trash/files/");
49
 
                        }
50
 
                }
51
 
                
52
 
                public override bool IsAcceptingDrops {
53
 
                        get { return true; }
54
 
                }
55
 
                
56
 
                public override string Name {
57
 
                        get { return "Trash"; }
58
 
                }
59
 
 
60
 
                protected override string Icon {
61
 
                        get {
62
 
                                if (Directory.Exists (Trash) && (Directory.GetFiles (Trash).Any () || Directory.GetDirectories (Trash).Any ()))
63
 
                                        return TrashFullIcon;
64
 
                                return TrashEmptyIcon;
65
 
                        }
66
 
                }
67
 
                
68
 
                public TrashDockItem()
69
 
                {
70
 
                        if (!Directory.Exists (Trash))
71
 
                                Directory.CreateDirectory (Trash);
72
 
 
73
 
                        SetText (Catalog.GetString ("Trash"));
74
 
                        
75
 
                        SetupFileSystemWatch ();
76
 
                }
77
 
                
78
 
                void SetupFileSystemWatch ()
79
 
                {
80
 
                        fsw = new FileSystemWatcher (Trash);
81
 
                        fsw.IncludeSubdirectories = false;
82
 
                        fsw.NotifyFilter = NotifyFilters.FileName | NotifyFilters.DirectoryName;
83
 
 
84
 
                        fsw.Changed += HandleChanged;
85
 
                        fsw.Created += HandleChanged;
86
 
                        fsw.Deleted += HandleChanged;
87
 
                        fsw.EnableRaisingEvents = true;
88
 
                }
89
 
 
90
 
                void HandleChanged(object sender, FileSystemEventArgs e)
91
 
                {
92
 
                        Gtk.Application.Invoke (delegate {
93
 
                                RedrawIcon ();
94
 
                        });
95
 
                }
96
 
 
97
 
                public override bool ReceiveItem (string item)
98
 
                {
99
 
                        if (item.StartsWith ("file://"))
100
 
                                item = item.Substring ("file://".Length);
101
 
                        
102
 
                        // if the file doesn't exist for whatever reason, we bail
103
 
                        if (!File.Exists (item) && !Directory.Exists (item))
104
 
                                return false;
105
 
                        
106
 
                        try {
107
 
                                Services.Environment.Execute (string.Format ("gvfs-trash \"{0}\"", item));
108
 
                        } catch (Exception e) { 
109
 
                                Log.Error (e.Message);
110
 
                                Log.Error ("Could not move {0} to trash", item); 
111
 
                                return false;
112
 
                        }
113
 
                        
114
 
                        RedrawIcon ();
115
 
                        return true;
116
 
                }
117
 
                
118
 
                public override void Clicked (uint button, ModifierType state, Cairo.PointD position)
119
 
                {
120
 
                        if (button == 1) {
121
 
                                Services.Environment.OpenUrl ("trash://");
122
 
                                AnimationType = ClickAnimationType.Bounce;
123
 
                        } else {
124
 
                                AnimationType = ClickAnimationType.None;
125
 
                        }
126
 
                        
127
 
                        base.Clicked (button, state, position);
128
 
                }
129
 
 
130
 
                void EmptyTrash ()
131
 
                {
132
 
                        fsw.Dispose ();
133
 
                        fsw = null;
134
 
                        
135
 
                        string message = Catalog.GetString ("<big><b>Empty all of the items from the trash?</b></big>\n\n" + 
136
 
                                                            "If you choose to empty the trash, all items in it\nwill be permanently lost. " + 
137
 
                                                            "Please note that you\ncan also delete them separately.");
138
 
                        MessageDialog md = new MessageDialog (null, 
139
 
                                                                                                  DialogFlags.Modal,
140
 
                                                                                                  MessageType.Warning, 
141
 
                                                                                                  ButtonsType.None,
142
 
                                                                                                  message);
143
 
                        md.AddButton ("_Cancel", ResponseType.Cancel);
144
 
                        md.AddButton ("Empty _Trash", ResponseType.Ok);
145
 
 
146
 
                        ResponseType result = (ResponseType) md.Run ();
147
 
                        md.Destroy ();
148
 
 
149
 
                        if (result != ResponseType.Cancel && 
150
 
                                Directory.Exists (Trash)) {
151
 
                                try {
152
 
                                        Directory.Delete (Trash, true);
153
 
                                        Directory.CreateDirectory (Trash);
154
 
                                } catch { /* do nothing */ }
155
 
                        }
156
 
                                
157
 
                        SetupFileSystemWatch ();
158
 
                        
159
 
                        RedrawIcon ();
160
 
                }
161
 
 
162
 
                #region IRightClickable implementation 
163
 
                
164
 
                public event EventHandler RemoveClicked;
165
 
                
166
 
                public IEnumerable<AbstractMenuArgs> GetMenuItems ()
167
 
                {
168
 
                        yield return new SeparatorMenuButtonArgs ();
169
 
                        
170
 
                        yield return new SimpleMenuButtonArgs (
171
 
                                        () => Services.Environment.OpenUrl ("trash://"),
172
 
                                        Catalog.GetString ("Open Trash"), TrashFullIcon);
173
 
                        yield return new SimpleMenuButtonArgs (EmptyTrash,
174
 
                                        Catalog.GetString ("Empty Trash"), Gtk.Stock.Delete);
175
 
                }
176
 
                
177
 
                #endregion 
178
 
                
179
 
        }
180
 
}