Do

Merge lp:~alexlauni/do/xdg-user-dirs-icons into lp:do

Proposed by Alex Launi
Status: Merged
Approved by: Alex Launi
Approved revision: 1293
Merged at revision: not available
Proposed branch: lp:~alexlauni/do/xdg-user-dirs-icons
Merge into: lp:do
Diff against target: None lines
To merge this branch: bzr merge lp:~alexlauni/do/xdg-user-dirs-icons
Reviewer Review Type Date Requested Status
Chris S. Approve
Review via email: mp+10187@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Alex Launi (alexlauni) wrote :

After working on this I'm pretty sure that this really is the best way to implement this feature. It's platform independent, simple, and flexible.

Revision history for this message
Chris S. (cszikszoy) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Do.Interface.Linux/src/Do.Interface/IconProvider.cs'
2--- Do.Interface.Linux/src/Do.Interface/IconProvider.cs 2008-12-17 09:59:21 +0000
3+++ Do.Interface.Linux/src/Do.Interface/IconProvider.cs 2009-08-09 17:18:22 +0000
4@@ -165,9 +165,9 @@
5 if (pixbuf != null) return true;
6 }
7
8- // After this point, we assume that the caller's icon cannot be found, so we attempt
9- // to provide a suitable alternative. We return false to indicate that an alternative
10- // icon selection was made.
11+ // After this point, we assume that the caller's icon cannot be found, so
12+ // we attempt to provide a suitable alternative. We return false to
13+ // indicate that an alternative icon selection was made.
14
15 // Try to load a pretty "no icon found" icon.
16 if (name != MissingIconIcon) {
17
18=== modified file 'Do.Platform.Linux/Do.Platform.Linux.mdp'
19--- Do.Platform.Linux/Do.Platform.Linux.mdp 2009-07-22 01:12:59 +0000
20+++ Do.Platform.Linux/Do.Platform.Linux.mdp 2009-08-14 17:47:47 +0000
21@@ -53,6 +53,7 @@
22 <File name="src/Do.Widgets/PluginAvailableDialog.cs" subtype="Code" buildaction="Compile" />
23 <File name="gtk-gui/Do.Platform.Linux.PluginAvailableDialog.cs" subtype="Code" buildaction="Compile" />
24 <File name="src/Do.Platform/Do.Platform.Linux/KeyBindingService.cs" subtype="Code" buildaction="Compile" />
25+ <File name="src/Do.Platform/Do.Platform.Linux/EnvironmentServiceExtensions.cs" subtype="Code" buildaction="Compile" />
26 </Contents>
27 <References>
28 <ProjectReference type="Gac" localcopy="True" refto="System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
29
30=== modified file 'Do.Platform.Linux/Makefile.am'
31--- Do.Platform.Linux/Makefile.am 2009-07-23 07:17:00 +0000
32+++ Do.Platform.Linux/Makefile.am 2009-08-14 17:47:47 +0000
33@@ -14,6 +14,7 @@
34 src/Do.Platform/Do.Platform.Linux/Do.Platform.Linux.DBus/Registrar.cs \
35 src/Do.Platform/Do.Platform.Linux/ConsoleLogService.cs \
36 src/Do.Platform/Do.Platform.Linux/EnvironmentService.cs \
37+ src/Do.Platform/Do.Platform.Linux/EnvironmentServiceExtensions.cs \
38 src/Do.Platform/Do.Platform.Linux/SystemService.cs \
39 src/Do.Platform/Do.Platform.Linux/GConfPreferencesService.cs \
40 src/Do.Platform/Do.Platform.Linux/GnomeKeyringSecurePreferencesService.cs \
41@@ -29,7 +30,9 @@
42 src/Do.Universe/NullApplicationItem.cs \
43 src/Do.Universe/FileItem.cs \
44 src/Do.Universe/ApplicationItemSource.cs \
45+ src/Do.Universe/GNOMEBookmarkItem.cs \
46 src/Do.Universe/GNOMESpecialLocationsItemSource.cs \
47+ src/Do.Universe/GNOMETrashItem.cs \
48 src/Do.Widgets/AbstractLoginWidget.cs \
49 src/Do.Widgets/PluginAvailableDialog.cs
50
51
52=== modified file 'Do.Platform.Linux/src/Do.Platform/Do.Platform.Linux/EnvironmentService.cs'
53--- Do.Platform.Linux/src/Do.Platform/Do.Platform.Linux/EnvironmentService.cs 2009-06-26 10:01:03 +0000
54+++ Do.Platform.Linux/src/Do.Platform/Do.Platform.Linux/EnvironmentService.cs 2009-08-14 17:47:47 +0000
55@@ -44,7 +44,7 @@
56 path_matcher = new Regex (PathPattern, RegexOptions.Compiled);
57 }
58
59- #region IEnvironmentService
60+#region IEnvironmentService
61
62 public void OpenEmail (IEnumerable<string> to, IEnumerable<string> cc, IEnumerable<string> bcc,
63 string subject, string body, IEnumerable<string> attachments)
64@@ -101,6 +101,7 @@
65 string text = "";
66
67 try {
68+ // TODO: this is absolute garbage
69 if (item is ITextItem)
70 text = (item as ITextItem).Text;
71 else if (item is IFileItem)
72@@ -139,8 +140,7 @@
73 return (pw == null) ? path : pw.pw_dir + m.Groups[2].Value;
74 }
75 }
76-
77- #endregion
78+#endregion
79
80 void Open (string open)
81 {
82@@ -191,6 +191,5 @@
83 }
84 return false;
85 }
86-
87 }
88 }
89
90=== added file 'Do.Platform.Linux/src/Do.Platform/Do.Platform.Linux/EnvironmentServiceExtensions.cs'
91--- Do.Platform.Linux/src/Do.Platform/Do.Platform.Linux/EnvironmentServiceExtensions.cs 1970-01-01 00:00:00 +0000
92+++ Do.Platform.Linux/src/Do.Platform/Do.Platform.Linux/EnvironmentServiceExtensions.cs 2009-08-14 17:47:47 +0000
93@@ -0,0 +1,106 @@
94+// EnvironmentServieExtensions
95+//
96+// GNOME Do is the legal property of its developers. Please refer to the
97+// COPYRIGHT file distributed with this
98+// source distribution.
99+//
100+// This program is free software: you can redistribute it and/or modify
101+// it under the terms of the GNU General Public License as published by
102+// the Free Software Foundation, either version 3 of the License, or
103+// (at your option) any later version.
104+//
105+// This program is distributed in the hope that it will be useful,
106+// but WITHOUT ANY WARRANTY; without even the implied warranty of
107+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
108+// GNU General Public License for more details.
109+//
110+// You should have received a copy of the GNU General Public License
111+// along with this program. If not, see <http://www.gnu.org/licenses/>
112+
113+using System;
114+using System.IO;
115+
116+using Do.Platform;
117+
118+namespace Do.Platform.Linux
119+{
120+ public static class EnvironmentServiceExtensions
121+ {
122+ /// <summary>
123+ /// Find the path of the directory that maps to the given XDG dir
124+ /// if the xdg variable is not set, return null
125+ /// </summary>
126+ /// <param name="key">
127+ /// A <see cref="System.String"/> XDG directory variable name
128+ /// </param>
129+ /// <returns>
130+ /// A <see cref="System.String"/> path for the XDG directory env. variable
131+ /// </returns>
132+ public static string MaybePathForXdgVariable (this IEnvironmentService envService, string key)
133+ {
134+ return PathForXdgVariable (envService, key, null);
135+ }
136+
137+ /// <summary>
138+ /// Find the path of the directory that maps to the given XDG dir
139+ /// if the xdg variable is not set, use the fallback value passed in
140+ /// </summary>
141+ /// <param name="key">
142+ /// A <see cref="System.String"/> XDG directory variable name
143+ /// </param>
144+ /// <param name="fallback">
145+ /// A <see cref="System.String"/> default XDG directory name to fallback
146+ /// on if the variable is not set.
147+ /// </param>
148+ /// <returns>
149+ /// A <see cref="System.String"/> path for the XDG directory env. variable
150+ /// </returns>
151+ public static string PathForXdgVariable (this IEnvironmentService envService, string key, string fallback)
152+ {
153+ string homeDir, configDir, envPath, userDirsPath;
154+
155+ homeDir = Environment.GetFolderPath (Environment.SpecialFolder.Personal);
156+ configDir = Environment.GetFolderPath (Environment.SpecialFolder.ApplicationData);
157+
158+ envPath = Environment.GetEnvironmentVariable (key);
159+ if (!String.IsNullOrEmpty (envPath)) {
160+ return envPath;
161+ }
162+
163+ userDirsPath = Path.Combine (configDir, "user-dirs.dirs");
164+ if (!File.Exists (userDirsPath)) {
165+ return Path.Combine (homeDir, fallback);
166+ }
167+
168+ try {
169+ using (StreamReader reader = new StreamReader (userDirsPath)) {
170+ string line;
171+ while ((line = reader.ReadLine ()) != null) {
172+ line = line.Trim ();
173+ int delimIndex = line.IndexOf ('=');
174+ if (delimIndex > 8 && line.Substring (0, delimIndex) == key) {
175+ string path = line.Substring (delimIndex + 1).Trim ('"');
176+ bool relative = false;
177+
178+ if (path.StartsWith ("$HOME/")) {
179+ relative = true;
180+ path = path.Substring (6);
181+ } else if (path.StartsWith ("~")) {
182+ relative = true;
183+ path = path.Substring (1);
184+ } else if (!path.StartsWith ("/")) {
185+ relative = true;
186+ }
187+ return relative ? Path.Combine (homeDir, path) : path;
188+ }
189+ }
190+ }
191+ } catch (FileNotFoundException) {
192+ }
193+
194+ return fallback == null
195+ ? null
196+ : Path.Combine (homeDir, fallback);
197+ }
198+ }
199+}
200
201=== modified file 'Do.Platform.Linux/src/Do.Universe/FileItem.cs'
202--- Do.Platform.Linux/src/Do.Universe/FileItem.cs 2009-02-06 23:40:50 +0000
203+++ Do.Platform.Linux/src/Do.Universe/FileItem.cs 2009-08-10 01:01:47 +0000
204@@ -20,12 +20,14 @@
205 using System;
206 using IO = System.IO;
207 using System.Collections.Generic;
208+using SpecialFolder = System.Environment.SpecialFolder;
209
210 using Gnome;
211 using Mono.Unix;
212
213 using Do.Platform;
214 using Do.Universe;
215+using Do.Platform.Linux;
216
217 namespace Do.Universe.Linux {
218
219@@ -36,11 +38,51 @@
220 /// </summary>
221 internal class FileItem : Item, IFileItem, IOpenableItem {
222
223+ // A map from absolute paths to icon names.
224+ static readonly Dictionary<string, string> SpecialFolderIcons;
225+
226+ // A map from XDG user-dir names to icons names.
227+ static readonly Dictionary<string, string> SpecialFolderIconsXDG
228+ = new Dictionary<string, string> () {
229+ { "XDG_DESKTOP_DIR", "desktop" },
230+ { "XDG_DOWNLOAD_DIR", "folder-downloads" },
231+ { "XDG_TEMPLATES_DIR", "folder-templates" },
232+ { "XDG_PUBLICSHARE_DIR", "folder-publicshare" },
233+ { "XDG_DOCUMENTS_DIR", "folder-documents" },
234+ { "XDG_MUSIC_DIR", "folder-music" },
235+ { "XDG_PICTURES_DIR", "folder-pictures" },
236+ { "XDG_VIDEOS_DIR", "folder-videos" },
237+ };
238+
239+ static string MaybeGetSpecialFolderIconForPath (string path)
240+ {
241+ return SpecialFolderIcons.ContainsKey (path)
242+ ? SpecialFolderIcons [path]
243+ : null;
244+ }
245+
246 static FileItem ()
247 {
248 Gnome.Vfs.Vfs.Initialize ();
249+
250+ // Initialize SpecialFolderIcons by expanding paths in
251+ // SpecialFolderIconsXDG.
252+ //
253+ // If an icon already exists in SpecialFolderIcons for a given path, we
254+ // don't overwrite it. This way SpecialFolderIconsXDG defines an ordering
255+ // for which icons take precedent; for example, XDG_DOWNLOAD_DIR and
256+ // XDG_DESKTOP_DIR are often the same folder, so we use the icon for
257+ // whichever one comes first in SpecialFolderIconsXDG.
258+ SpecialFolderIcons = new Dictionary<string, string> ();
259+ foreach (KeyValuePair<string, string> kv in SpecialFolderIconsXDG) {
260+ string path = Services.Environment.MaybePathForXdgVariable (kv.Key);
261+ if (path != null && !SpecialFolderIcons.ContainsKey (path)) {
262+ SpecialFolderIcons [path] = kv.Value;
263+ }
264+ }
265+
266 }
267-
268+
269 /// <summary>
270 /// Abbreviates an absolute path by replacing $HOME with ~.
271 /// </summary>
272@@ -54,7 +96,7 @@
273 {
274 if (null == path) throw new ArgumentNullException ();
275
276- return path.Replace (Environment.GetFolderPath (Environment.SpecialFolder.Personal), "~");
277+ return path.Replace (Environment.GetFolderPath (SpecialFolder.Personal), "~");
278 }
279
280 string name, description, icon;
281@@ -93,11 +135,16 @@
282
283 public override string Icon {
284 get {
285+ // Icon is memoized.
286 if (null != icon) return icon;
287
288- // TODO Filenames with spaces are not
289+ // See if the Path is a special folder with a special icon.
290+ icon = MaybeGetSpecialFolderIconForPath (Path);
291+ if (icon != null) return icon;
292+
293 string large_thumb = Thumbnail.PathForUri (Uri, ThumbnailSize.Large);
294 string normal_thumb = Thumbnail.PathForUri (Uri, ThumbnailSize.Normal);
295+
296 // Generating the thumbnail ourself is too slow for large files.
297 // Suggestion: generate thumbnails asynchronously. Banshee's
298 // notion of job queues may be useful.
299
300=== added file 'Do.Platform.Linux/src/Do.Universe/GNOMEBookmarkItem.cs'
301--- Do.Platform.Linux/src/Do.Universe/GNOMEBookmarkItem.cs 1970-01-01 00:00:00 +0000
302+++ Do.Platform.Linux/src/Do.Universe/GNOMEBookmarkItem.cs 2009-08-09 18:54:34 +0000
303@@ -0,0 +1,67 @@
304+// GNOMEBookmarkItem.cs
305+//
306+// GNOME Do is the legal property of its developers, whose names are too numerous
307+// to list here. Please refer to the COPYRIGHT file distributed with this
308+// source distribution.
309+//
310+// This program is free software: you can redistribute it and/or modify
311+// it under the terms of the GNU General Public License as published by
312+// the Free Software Foundation, either version 3 of the License, or
313+// (at your option) any later version.
314+//
315+// This program is distributed in the hope that it will be useful,
316+// but WITHOUT ANY WARRANTY; without even the implied warranty of
317+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
318+// GNU General Public License for more details.
319+//
320+// You should have received a copy of the GNU General Public License
321+// along with this program. If not, see <http://www.gnu.org/licenses/>.
322+
323+using System;
324+using System.IO;
325+using System.Linq;
326+using System.Collections.Generic;
327+
328+using Mono.Unix;
329+
330+using Do.Platform;
331+using Do.Universe;
332+
333+namespace Do.Universe.Linux {
334+
335+ class GNOMEBookmarkItem : Item, IUriItem
336+ {
337+ string uri, icon, name;
338+
339+ public GNOMEBookmarkItem (string name, string uri)
340+ {
341+ this.name = name;
342+ this.uri = uri;
343+
344+ icon = "user-bookmarks";
345+ }
346+
347+ public GNOMEBookmarkItem (string name, string uri, string icon)
348+ : this (name, uri)
349+ {
350+ this.icon = icon;
351+ }
352+
353+ public override string Name {
354+ get { return name; }
355+ }
356+
357+ public override string Description {
358+ get { return Uri; }
359+ }
360+
361+ public string Uri {
362+ get { return uri; }
363+ }
364+
365+ public override string Icon {
366+ get { return icon; }
367+ }
368+
369+ }
370+}
371
372=== modified file 'Do.Platform.Linux/src/Do.Universe/GNOMESpecialLocationsItemSource.cs'
373--- Do.Platform.Linux/src/Do.Universe/GNOMESpecialLocationsItemSource.cs 2008-12-20 00:31:54 +0000
374+++ Do.Platform.Linux/src/Do.Universe/GNOMESpecialLocationsItemSource.cs 2009-08-09 18:54:34 +0000
375@@ -22,6 +22,7 @@
376 using System.Linq;
377 using System.Collections.Generic;
378 using System.Text.RegularExpressions;
379+
380 using Mono.Unix;
381
382 using Do.Platform;
383@@ -30,6 +31,10 @@
384 namespace Do.Universe.Linux {
385
386 public class GNOMESpecialLocationsItemSource : ItemSource {
387+
388+ static readonly string BookmarksFile =
389+ Path.Combine (Environment.GetFolderPath (Environment.SpecialFolder.Personal), ".gtk-bookmarks");
390+
391 List<Item> items;
392
393 public GNOMESpecialLocationsItemSource()
394@@ -37,38 +42,20 @@
395 items = new List<Item> ();
396 }
397
398- class GNOMEURItem : Item, IUriItem {
399- protected string uri, name, icon;
400-
401- public GNOMEURItem (string uri, string name, string icon)
402- {
403- this.uri = uri;
404- this.name = name;
405- this.icon = icon;
406- }
407-
408- public override string Name { get { return name; } }
409- public override string Description { get { return Uri; } }
410- public override string Icon { get { return icon; } }
411- public string Uri { get { return uri; } }
412- }
413-
414- public override string Name {
415+ public override string Name {
416 get { return Catalog.GetString ("GNOME Special Locations"); }
417 }
418
419- public override string Description {
420- get { return Catalog.GetString ("Special locations in GNOME, "
421- + "such as Computer and Network.");
422+ public override string Description {
423+ get {
424+ return Catalog.GetString ("Special locations in GNOME, such as Computer and Network.");
425 }
426 }
427
428- public override string Icon { get { return "user-home"; } }
429+ public override string Icon { get { return "user-bookmarks"; } }
430
431 public override IEnumerable<Type> SupportedItemTypes {
432- get {
433- yield return typeof (IUriItem);
434- }
435+ get { yield return typeof (IUriItem); }
436 }
437
438 public override IEnumerable<Item> Items {
439@@ -78,167 +65,42 @@
440 public override void UpdateItems ()
441 {
442 items.Clear ();
443- items.Add (new GNOMETrashFileItem ());
444- items.Add (new GNOMEURItem ("computer:///", "Computer", "computer"));
445- items.Add (new GNOMEURItem ("network://", "Network", "network"));
446- FillGNOMEBookmarkItems ();
447+ items.Add (new GNOMETrashItem ());
448+ items.Add (new GNOMEBookmarkItem ("Computer", "computer://", "computer"));
449+ items.Add (new GNOMEBookmarkItem ("Network", "network://", "network"));
450+ foreach (Item item in ReadBookmarkItems ()) items.Add (item);
451 }
452
453- private void FillGNOMEBookmarkItems ()
454+ IEnumerable<IUriItem> ReadBookmarkItems ()
455 {
456- // Assemble the path to the bookmarks file.
457- string bookmarks_file = Path.Combine (Environment.GetFolderPath (Environment.SpecialFolder.Personal), ".gtk-bookmarks");
458-
459- try {
460- string line;
461- Regex regex = new Regex ("([^ ]*) (.*)");
462-
463- string URI;
464- string name;
465- string path;
466- bool network;
467-
468- using (StreamReader reader = new StreamReader (bookmarks_file)) {
469- while ((line = reader.ReadLine ()) != null) {
470- Match match = regex.Match (line);
471- network = (match.Groups.Count == 3);
472- if (network) {
473- name = match.Groups [2].ToString ();
474- URI = GetURI(match.Groups [1].ToString ());
475- path = GetPath(match.Groups [1].ToString ());
476- }
477- else {
478- URI = GetURI (line);
479- path = GetPath (line);
480- name = GetDirectory (line);
481- }
482-
483- items.Add (new GNOMEBookmarkItem (name, URI, path, network));
484+ string line, uri, name;
485+ Regex regex = new Regex ("([^ ]*) (.*)");
486+
487+ using (StreamReader reader = new StreamReader (BookmarksFile)) {
488+ while ((line = reader.ReadLine ()) != null) {
489+
490+ Match match = regex.Match (line);
491+ bool isNetworkBookmark = match.Groups.Count == 3;
492+
493+ if (line.StartsWith ("file://")) {
494+ string path = line;
495+
496+ path = path.Substring ("file://".Length);
497+ // Some entries contain more information after the URI. We
498+ // discard it.
499+ if (line.Contains (" "))
500+ path = path.Substring (0, path.IndexOf (" "));
501+ path = Uri.UnescapeDataString (path);
502+
503+ yield return Services.UniverseFactory.NewFileItem (path);
504+ } else if (isNetworkBookmark) {
505+ name = match.Groups [2].ToString ();
506+ uri = match.Groups [1].ToString ();
507+ yield return new GNOMEBookmarkItem (name, uri, "network");
508 }
509 }
510- } catch (Exception e) {
511- // Something went horribly wrong, so we print the error message.
512- Console.Error.WriteLine ("Could not read Gnome Bookmarks file {0}: {1}", bookmarks_file, e.Message);
513- }
514- }
515-
516- private int GetURIDelimiter (string fullPath)
517- {
518- return fullPath.IndexOf ("//");
519- }
520-
521- private string GetURI (string fullpath)
522- {
523- int delimindex = GetURIDelimiter (fullpath);
524-
525- if (delimindex > -1)
526- return fullpath.Substring (0, delimindex+2 );
527- else
528- return "file://";
529- }
530-
531- private string GetPath (string fullpath)
532- {
533- int delimindex = GetURIDelimiter (fullpath);
534-
535- if (delimindex > -1)
536- return fullpath.Substring (delimindex+2, fullpath.Length - delimindex-2);
537- else
538- return Environment.GetFolderPath (Environment.SpecialFolder.Personal);
539- }
540-
541- private string GetDirectory (string fullpath)
542- {
543- int lastSlashPosition = fullpath.LastIndexOf ("/");
544- return fullpath.Substring(lastSlashPosition+1, fullpath.Length-lastSlashPosition-1);
545- }
546-
547- }
548-
549- class GNOMETrashFileItem : Item, IFileItem, IOpenableItem
550- {
551-
552- string path;
553- public string Path {
554- get {
555- if (path != null) return path;
556-
557- return path = new [] {
558- Environment.GetFolderPath (Environment.SpecialFolder.LocalApplicationData),
559- "Trash",
560- "files",
561- }.Aggregate (System.IO.Path.Combine);
562- }
563- }
564-
565- public override string Name {
566- get { return "Trash"; }
567- }
568-
569- public override string Description {
570- get { return "Trash"; }
571- }
572-
573- public string Uri {
574- get { return "trash://"; }
575- }
576-
577- public override string Icon
578- {
579- get {
580- if (Directory.Exists (Path) &&
581- Directory.GetFileSystemEntries (Path).Length > 0) {
582- return "user-trash-full";
583- } else {
584- return "user-trash";
585- }
586- }
587- }
588-
589- public void Open ()
590- {
591- Services.Environment.OpenUrl ("trash://");
592- }
593- }
594-
595- class GNOMEBookmarkItem : Item, IFileItem, IOpenableItem
596- {
597- private string uri;
598- private string icon;
599- private string name;
600- private string path;
601-
602- public GNOMEBookmarkItem (string fullname, string fullURI, string fullpath, bool networkType)
603- {
604- uri = fullURI;
605- name = fullname;
606- path = fullpath;
607- icon = networkType ? "network" : "folder";
608- }
609-
610- public string Path {
611- get { return path; }
612- }
613-
614- public override string Name {
615- get { return name; }
616- }
617-
618- public override string Description {
619- get { return uri + path; }
620- }
621-
622- public string Uri {
623- get { return uri; }
624- }
625-
626- public override string Icon {
627- get { return icon; }
628- }
629-
630- public void Open ()
631- {
632- Services.Environment.OpenUrl (Uri + Path);
633- }
634+ }
635+ }
636+
637 }
638 }
639
640=== added file 'Do.Platform.Linux/src/Do.Universe/GNOMETrashItem.cs'
641--- Do.Platform.Linux/src/Do.Universe/GNOMETrashItem.cs 1970-01-01 00:00:00 +0000
642+++ Do.Platform.Linux/src/Do.Universe/GNOMETrashItem.cs 2009-08-09 18:54:34 +0000
643@@ -0,0 +1,76 @@
644+// GNOMETrashItem.cs
645+//
646+// GNOME Do is the legal property of its developers, whose names are too numerous
647+// to list here. Please refer to the COPYRIGHT file distributed with this
648+// source distribution.
649+//
650+// This program is free software: you can redistribute it and/or modify
651+// it under the terms of the GNU General Public License as published by
652+// the Free Software Foundation, either version 3 of the License, or
653+// (at your option) any later version.
654+//
655+// This program is distributed in the hope that it will be useful,
656+// but WITHOUT ANY WARRANTY; without even the implied warranty of
657+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
658+// GNU General Public License for more details.
659+//
660+// You should have received a copy of the GNU General Public License
661+// along with this program. If not, see <http://www.gnu.org/licenses/>.
662+
663+using System;
664+using System.IO;
665+using System.Linq;
666+using System.Collections.Generic;
667+
668+using Mono.Unix;
669+
670+using Do.Platform;
671+using Do.Universe;
672+
673+namespace Do.Universe.Linux {
674+
675+ class GNOMETrashItem : Item, IFileItem, IOpenableItem
676+ {
677+
678+ string path;
679+ public string Path {
680+ get {
681+ if (path != null) return path;
682+
683+ return path = new [] {
684+ Environment.GetFolderPath (Environment.SpecialFolder.LocalApplicationData),
685+ "Trash",
686+ "files",
687+ }.Aggregate (System.IO.Path.Combine);
688+ }
689+ }
690+
691+ public override string Name {
692+ get { return "Trash"; }
693+ }
694+
695+ public override string Description {
696+ get { return "Trash"; }
697+ }
698+
699+ public string Uri {
700+ get { return "trash://"; }
701+ }
702+
703+ public override string Icon
704+ {
705+ get {
706+ if (Directory.Exists (Path) && Directory.GetFileSystemEntries (Path).Any ()) {
707+ return "user-trash-full";
708+ } else {
709+ return "user-trash";
710+ }
711+ }
712+ }
713+
714+ public void Open ()
715+ {
716+ Services.Environment.OpenUrl ("trash://");
717+ }
718+ }
719+}