~ubuntu-branches/debian/sid/docky/sid

« back to all changes in this revision

Viewing changes to StandardPlugins/Trash/src/TrashDockItem.cs

  • Committer: Package Import Robot
  • Author(s): Rico Tzschichholz
  • Date: 2012-01-19 19:03:38 UTC
  • mfrom: (1.1.14) (10.1.9 experimental)
  • Revision ID: package-import@ubuntu.com-20120119190338-n44q7tmqsrkudvk7
Tags: 2.1.3-2
* Upload to unstable
* debian/watch:
  + Look for xz tarballs from now on

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
16
// 
17
17
 
18
 
using System;
 
18
using System.Linq;
19
19
using System.Collections.Generic;
20
 
using System.Collections.ObjectModel;
21
 
using System.Linq;
22
 
using System.Text;
23
20
 
24
21
using Mono.Unix;
25
22
 
26
 
using GConf;
27
23
using GLib;
28
24
 
29
25
using Docky.Items;
30
26
using Docky.Menus;
31
27
using Docky.Services;
 
28
using Docky.Services.Prefs;
32
29
 
33
30
namespace Trash
34
31
{
35
32
        public class TrashDockItem : IconDockItem
36
33
        {
 
34
                
 
35
                IPreferences trashPrefs = DockServices.Preferences.Get ("/apps/nautilus/preferences");
 
36
                bool ConfirmTrashDelete {
 
37
                        get {
 
38
                                return trashPrefs.Get<bool> ("confirm_trash", true);
 
39
                        }
 
40
                }
 
41
                
37
42
                uint ItemsInTrash {
38
43
                        get {
39
44
                                return OwnedFile.QueryInfo<uint> ("trash::item-count");
160
165
                {
161
166
                        // intentionally dont inherit
162
167
                        MenuList list = new MenuList ();
163
 
                        list[MenuListContainer.Actions].Add (
 
168
                        
 
169
                        list.SetContainerTitle (MenuListContainer.CustomOne, Catalog.GetString ("Restore Files"));
 
170
                        
 
171
                        FileEnumerator enumerator = OwnedFile.EnumerateChildren ("standard::type,standard::name", FileQueryInfoFlags.NofollowSymlinks, null);
 
172
                        List<File> files = new List<File> ();
 
173
                        
 
174
                        if (enumerator != null) {
 
175
                                FileInfo info;
 
176
                                
 
177
                                while ((info = enumerator.NextFile ()) != null) {
 
178
                                        files.Add (OwnedFile.GetChild (info.Name));
 
179
                                        info.Dispose ();
 
180
                                }
 
181
                                
 
182
                                if (info != null)
 
183
                                        info.Dispose ();
 
184
                                enumerator.Close (null);
 
185
                                enumerator.Dispose ();
 
186
                        }
 
187
                        
 
188
                        /* FIXME
 
189
                                - this code should work, but GetFiles() currently uses .net IO instead of GIO
 
190
                                  when this starts working, the enumeration block above can go away too
 
191
                        foreach (File _f in OwnedFile.GetFiles ().OrderByDescending (f => f.QueryInfo<string> ("trash::deletion-date")).Take (5)) {
 
192
                        */
 
193
                        foreach (File _f in files.OrderByDescending (f => f.QueryInfo<string> ("trash::deletion-date")).Take (5)) {
 
194
                                File f = _f;
 
195
                                MenuItem item = new IconMenuItem (f.Basename, f.Icon (), (o, a) => RestoreFile (f));
 
196
                                item.Mnemonic = null;
 
197
                                list[MenuListContainer.CustomOne].Add (item);
 
198
                        }
 
199
                        
 
200
                        list[MenuListContainer.CustomTwo].Add (
164
201
                                new MenuItem (Catalog.GetString ("_Open Trash"), Icon, (o, a) => OpenTrash ()));
165
 
                        list[MenuListContainer.Actions].Add (
 
202
                        list[MenuListContainer.CustomTwo].Add (
166
203
                                new MenuItem (Catalog.GetString ("Empty _Trash"), "gtk-clear", (o, a) => EmptyTrash (), !TrashFull));
 
204
                        
167
205
                        return list;
168
206
                }
169
207
                
 
208
                void RestoreFile (File f)
 
209
                {
 
210
                        File destFile = FileFactory.NewForPath (f.QueryInfo<string> ("trash::orig-path"));
 
211
                        f.Move (destFile, FileCopyFlags.NofollowSymlinks | FileCopyFlags.AllMetadata | FileCopyFlags.NoFallbackForMove, null, null);
 
212
                }
 
213
                
170
214
                void OpenTrash ()
171
215
                {
172
216
                        DockServices.System.Open (OwnedFile);
174
218
                
175
219
                void EmptyTrash ()
176
220
                {
177
 
                        bool confirm = true;
178
 
                        
179
 
                        try {
180
 
                                confirm = (bool) new Client ().Get ("/apps/nautilus/preferences/confirm_trash");
181
 
                        } catch {}
182
 
                        
183
 
                        if (confirm) {
 
221
                        if (ConfirmTrashDelete) {
184
222
                                Gtk.MessageDialog md = new Gtk.MessageDialog (null, 
185
223
                                                  0,
186
224
                                                  Gtk.MessageType.Warning, 
192
230
                                        "can also delete them separately.");
193
231
                                md.Modal = false;
194
232
                                
195
 
                                Gtk.Button cancel_button = new Gtk.Button();
196
 
                                cancel_button.CanFocus = true;
197
 
                                cancel_button.Name = "cancel_button";
198
 
                                cancel_button.UseStock = true;
199
 
                                cancel_button.UseUnderline = true;
200
 
                                cancel_button.Label = "gtk-cancel";
201
 
                                cancel_button.Show ();
202
 
                                md.AddActionWidget (cancel_button, Gtk.ResponseType.Cancel);
 
233
                                md.AddButton (Gtk.Stock.Cancel, Gtk.ResponseType.Cancel);
203
234
                                md.AddButton (Catalog.GetString ("Empty _Trash"), Gtk.ResponseType.Ok);
204
235
                                md.DefaultResponse = Gtk.ResponseType.Ok;
205
236