Merge lp:~alexlauni/do/xdg-user-dirs-icons into lp:do
- xdg-user-dirs-icons
- Merge into trunk
Status: | Rejected |
---|---|
Rejected by: | Alex Launi |
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 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Chris S. | Needs Fixing | ||
Review via email: mp+9904@code.launchpad.net |
Commit message
Description of the change
Alex Launi (alexlauni) wrote : | # |
David Siegel (djsiegel-deactivatedaccount) wrote : | # |
MaybePathForXdg
agree that it should be somewhere standard -- maybe
Do.Platform.
plugins have to link against Do.Platform.Linux, which isn't such a big
deal.
On Aug 9, 2009, at 20:05, Alex Launi <email address hidden> wrote:
> Alex Launi has proposed merging lp:~alexlauni/do/xdg-user-dirs-icons
> into lp:do.
>
> Requested reviews:
> GNOME Do Core Team (do-core)
>
> Supercedes David's merge https:/
> Addresses my comments with regards to XDG method in FileItem. Once
> this is merged we should update any plugins that copied and pasted
> the xdg code.
> --
> https:/
> Your team GNOME Do Core Team is subscribed to branch lp:do.
> === modified file 'Do.Interface.
> IconProvider.cs' --- Do.Interface.
> IconProvider.cs 2008-12-17 09:59:21 +0000 +++ Do.Interface.
> Do.Interface/
> +165,9 @@ if (pixbuf != null) return true; } - // After this point,
> we assume that the caller's icon cannot be found, so we attempt - //
> to provide a suitable alternative. We return false to indicate that
> an alternative - // icon selection was made. + // After this
> point, we assume that the caller's icon cannot be found, so + // we
> attempt to provide a suitable alternative. We return false to + //
> indicate that an alternative icon selection was made. // Try to load
> a pretty "no icon found" icon. if (name != MissingIconIcon) { ===
> modified file 'Do.Platform.
> Makefile.am 2009-07-23 07:17:00 +0000 +++ Do.Platform.Linux/
> Makefile.am 2009-08-09 18:54:34 +0000 @@ -29,7 +29,9 @@ src/
> Do.Universe/
> src/Do.
> GNOMEBookmarkIt
> GNOMESpecialLoc
> GNOMETrashItem.cs \ src/Do.
> Do.Widgets/
> 'Do.Platform.
> EnvironmentServ
> Do.Platform.
> + Do.Platform.
> EnvironmentServ
> path_matcher = new Regex (PathPattern, RegexOptions.
> #region IEnvironmentService +#region IEnvironmentService public void
> OpenEmail (IEnumerable to, IEnumerable cc, IEnumerable bcc, string
> subject, string body, IEnumerable attachments) @@ -101,6 +101,7 @@
> string text = ""; try { + // TODO: this is absolute garbage
> if (item is ITextItem) text = (item as ITextItem).Text; else if
> (item is IFileItem) @@ -140,7 +141,84 @@ } } - #endregion
> +#endregion + + /// + /// Find the path of the directory that maps
> to the given XDG dir + ...
Alex Launi (alexlauni) wrote : | # |
On Sun, Aug 9, 2009 at 10:15 PM, David Siegel <email address hidden>wrote:
> MaybePathForXdg
> agree that it should be somewhere standard -- maybe
> Do.Platform.
No, it's not meaningful on other platforms, but that's why I made it an
extension method inside of Do.Platform.
that plugins that need this link against Do.Platform.Linux, because any
plugin that needs and XDG helper method is clearly Linux only.
--
-- Alex Launi
Chris Halse Rogers (raof) wrote : | # |
On Mon, 2009-08-10 at 02:21 +0000, Alex Launi wrote:
> On Sun, Aug 9, 2009 at 10:15 PM, David Siegel <email address hidden>wrote:
>
> > MaybePathForXdg
> > agree that it should be somewhere standard -- maybe
> > Do.Platform.
>
>
> No, it's not meaningful on other platforms, but that's why I made it an
> extension method inside of Do.Platform.
> that plugins that need this link against Do.Platform.Linux, because any
> plugin that needs and XDG helper method is clearly Linux only.
Actually, it _is_ kind of meaningful for other platforms. See, for
example, Environment.
for the music library etc.
We could define ourselves a nice enum like that.
Chris S. (cszikszoy) wrote : | # |
This won't compile as is. I branched and got errors about the extension methods not being in a static class. It was a pretty easy fix, see the diff for my branch here: http://
I don't know if it would be better to move these extension methods to another file? I sorta just hacked that so it would compile.
The only other thing I would do is simplify the foreach statement on line 395. This does the same thing and is a bit clearer:
ReadBookmarkItems ().ForEach (i => items.Add (i as Item));
David Siegel (djsiegel-deactivatedaccount) wrote : | # |
Defining our own enum sounds like a great idea. Then the XDG-bits don't
have to appear in any Do.Platform interface and plugins won't need to
link against Do.Platform.Linux. Alex, do you want to do this? I probably
can't work on it until next weekend so if you want to merge, go ahead.
David
Chris S. (cszikszoy) wrote : | # |
For what it's worth, Windows doesn't implement the XDG spec, but most
of those XDG folders exist in windows (xp - through win7). I think
the only one that doesn't is the downloads directory. Windows uses a
massive enum called CSIDL to refer to the windows special folders. It
would be nice if we can keep windows in mind when writing this,
because now that Core is fully stripped of all linux native code, I'd
like to start working on the windows port again, this time more in
sync with do-core.
Take a look at this:
http://
That enum (which I called WinAPIFolder) maps to shell32.dll's CSIDL enum.
The only tricky thing about windows is that A) Icons aren't strings.
When I use the native shell functions to get an icon it basically
returns a bitmap. The windows icons for special folders are no
different. B) Some of these windows special folders don't actually
have a path. For example, Network Places, there is no "path", but it
is possible to open this "folder" using a special shell API function.
This shouldn't be _too_ much of a problem though, because all of those
XDG folders map to windows folders that actually have a path
(downloads directory not included)
It would be nice to have the enum in Do.Platform, but let the various
OS dependant platform libs define the rest, like the paths and the
icons. It would be stupid to use gtk icon theme for the music folder,
when win7 already has a great looking, high-res icon for music.
Alex Launi (alexlauni) wrote : | # |
I'm moving this discussion to a blueprint -
https:/
--
-- Alex Launi
Unmerged revisions
Preview Diff
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/Makefile.am' |
19 | --- Do.Platform.Linux/Makefile.am 2009-07-23 07:17:00 +0000 |
20 | +++ Do.Platform.Linux/Makefile.am 2009-08-09 18:54:34 +0000 |
21 | @@ -29,7 +29,9 @@ |
22 | src/Do.Universe/NullApplicationItem.cs \ |
23 | src/Do.Universe/FileItem.cs \ |
24 | src/Do.Universe/ApplicationItemSource.cs \ |
25 | + src/Do.Universe/GNOMEBookmarkItem.cs \ |
26 | src/Do.Universe/GNOMESpecialLocationsItemSource.cs \ |
27 | + src/Do.Universe/GNOMETrashItem.cs \ |
28 | src/Do.Widgets/AbstractLoginWidget.cs \ |
29 | src/Do.Widgets/PluginAvailableDialog.cs |
30 | |
31 | |
32 | === modified file 'Do.Platform.Linux/src/Do.Platform/Do.Platform.Linux/EnvironmentService.cs' |
33 | --- Do.Platform.Linux/src/Do.Platform/Do.Platform.Linux/EnvironmentService.cs 2009-06-26 10:01:03 +0000 |
34 | +++ Do.Platform.Linux/src/Do.Platform/Do.Platform.Linux/EnvironmentService.cs 2009-08-10 01:01:47 +0000 |
35 | @@ -44,7 +44,7 @@ |
36 | path_matcher = new Regex (PathPattern, RegexOptions.Compiled); |
37 | } |
38 | |
39 | - #region IEnvironmentService |
40 | +#region IEnvironmentService |
41 | |
42 | public void OpenEmail (IEnumerable<string> to, IEnumerable<string> cc, IEnumerable<string> bcc, |
43 | string subject, string body, IEnumerable<string> attachments) |
44 | @@ -101,6 +101,7 @@ |
45 | string text = ""; |
46 | |
47 | try { |
48 | + // TODO: this is absolute garbage |
49 | if (item is ITextItem) |
50 | text = (item as ITextItem).Text; |
51 | else if (item is IFileItem) |
52 | @@ -140,7 +141,84 @@ |
53 | } |
54 | } |
55 | |
56 | - #endregion |
57 | +#endregion |
58 | + |
59 | + /// <summary> |
60 | + /// Find the path of the directory that maps to the given XDG dir |
61 | + /// if the xdg variable is not set, return null |
62 | + /// </summary> |
63 | + /// <param name="key"> |
64 | + /// A <see cref="System.String"/> XDG directory variable name |
65 | + /// </param> |
66 | + /// <returns> |
67 | + /// A <see cref="System.String"/> path for the XDG directory env. variable |
68 | + /// </returns> |
69 | + public static string MaybePathForXdgVariable (this IEnvironmentService envService, string key) |
70 | + { |
71 | + return PathForXdgVariable (key, null); |
72 | + } |
73 | + |
74 | + /// <summary> |
75 | + /// Find the path of the directory that maps to the given XDG dir |
76 | + /// if the xdg variable is not set, use the fallback value passed in |
77 | + /// </summary> |
78 | + /// <param name="key"> |
79 | + /// A <see cref="System.String"/> XDG directory variable name |
80 | + /// </param> |
81 | + /// <param name="fallback"> |
82 | + /// A <see cref="System.String"/> default XDG directory name to fallback |
83 | + /// on if the variable is not set. |
84 | + /// </param> |
85 | + /// <returns> |
86 | + /// A <see cref="System.String"/> path for the XDG directory env. variable |
87 | + /// </returns> |
88 | + public static string PathForXdgVariable (this IEnvironmentService envService, string key, string fallback) |
89 | + { |
90 | + string home_dir, config_dir, env_path, user_dirs_path; |
91 | + |
92 | + home_dir = Environment.GetFolderPath (Environment.SpecialFolder.Personal); |
93 | + config_dir = Environment.GetFolderPath (Environment.SpecialFolder.ApplicationData); |
94 | + |
95 | + env_path = Environment.GetEnvironmentVariable (key); |
96 | + if (!String.IsNullOrEmpty (env_path)) { |
97 | + return env_path; |
98 | + } |
99 | + |
100 | + user_dirs_path = Path.Combine (config_dir, "user-dirs.dirs"); |
101 | + if (!File.Exists (user_dirs_path)) { |
102 | + return Path.Combine (home_dir, fallback); |
103 | + } |
104 | + |
105 | + try { |
106 | + using (StreamReader reader = new StreamReader (user_dirs_path)) { |
107 | + string line; |
108 | + while ((line = reader.ReadLine ()) != null) { |
109 | + line = line.Trim (); |
110 | + int delim_index = line.IndexOf ('='); |
111 | + if (delim_index > 8 && line.Substring (0, delim_index) == key) { |
112 | + string path = line.Substring (delim_index + 1).Trim ('"'); |
113 | + bool relative = false; |
114 | + |
115 | + if (path.StartsWith ("$HOME/")) { |
116 | + relative = true; |
117 | + path = path.Substring (6); |
118 | + } else if (path.StartsWith ("~")) { |
119 | + relative = true; |
120 | + path = path.Substring (1); |
121 | + } else if (!path.StartsWith ("/")) { |
122 | + relative = true; |
123 | + } |
124 | + return relative ? Path.Combine (home_dir, path) : path; |
125 | + } |
126 | + } |
127 | + } |
128 | + } catch (FileNotFoundException) { |
129 | + } |
130 | + |
131 | + return fallback == null |
132 | + ? null |
133 | + : Path.Combine (home_dir, fallback); |
134 | + } |
135 | |
136 | void Open (string open) |
137 | { |
138 | @@ -191,6 +269,5 @@ |
139 | } |
140 | return false; |
141 | } |
142 | - |
143 | } |
144 | } |
145 | |
146 | === modified file 'Do.Platform.Linux/src/Do.Universe/FileItem.cs' |
147 | --- Do.Platform.Linux/src/Do.Universe/FileItem.cs 2009-02-06 23:40:50 +0000 |
148 | +++ Do.Platform.Linux/src/Do.Universe/FileItem.cs 2009-08-10 01:01:47 +0000 |
149 | @@ -20,12 +20,14 @@ |
150 | using System; |
151 | using IO = System.IO; |
152 | using System.Collections.Generic; |
153 | +using SpecialFolder = System.Environment.SpecialFolder; |
154 | |
155 | using Gnome; |
156 | using Mono.Unix; |
157 | |
158 | using Do.Platform; |
159 | using Do.Universe; |
160 | +using Do.Platform.Linux; |
161 | |
162 | namespace Do.Universe.Linux { |
163 | |
164 | @@ -36,11 +38,51 @@ |
165 | /// </summary> |
166 | internal class FileItem : Item, IFileItem, IOpenableItem { |
167 | |
168 | + // A map from absolute paths to icon names. |
169 | + static readonly Dictionary<string, string> SpecialFolderIcons; |
170 | + |
171 | + // A map from XDG user-dir names to icons names. |
172 | + static readonly Dictionary<string, string> SpecialFolderIconsXDG |
173 | + = new Dictionary<string, string> () { |
174 | + { "XDG_DESKTOP_DIR", "desktop" }, |
175 | + { "XDG_DOWNLOAD_DIR", "folder-downloads" }, |
176 | + { "XDG_TEMPLATES_DIR", "folder-templates" }, |
177 | + { "XDG_PUBLICSHARE_DIR", "folder-publicshare" }, |
178 | + { "XDG_DOCUMENTS_DIR", "folder-documents" }, |
179 | + { "XDG_MUSIC_DIR", "folder-music" }, |
180 | + { "XDG_PICTURES_DIR", "folder-pictures" }, |
181 | + { "XDG_VIDEOS_DIR", "folder-videos" }, |
182 | + }; |
183 | + |
184 | + static string MaybeGetSpecialFolderIconForPath (string path) |
185 | + { |
186 | + return SpecialFolderIcons.ContainsKey (path) |
187 | + ? SpecialFolderIcons [path] |
188 | + : null; |
189 | + } |
190 | + |
191 | static FileItem () |
192 | { |
193 | Gnome.Vfs.Vfs.Initialize (); |
194 | + |
195 | + // Initialize SpecialFolderIcons by expanding paths in |
196 | + // SpecialFolderIconsXDG. |
197 | + // |
198 | + // If an icon already exists in SpecialFolderIcons for a given path, we |
199 | + // don't overwrite it. This way SpecialFolderIconsXDG defines an ordering |
200 | + // for which icons take precedent; for example, XDG_DOWNLOAD_DIR and |
201 | + // XDG_DESKTOP_DIR are often the same folder, so we use the icon for |
202 | + // whichever one comes first in SpecialFolderIconsXDG. |
203 | + SpecialFolderIcons = new Dictionary<string, string> (); |
204 | + foreach (KeyValuePair<string, string> kv in SpecialFolderIconsXDG) { |
205 | + string path = Services.Environment.MaybePathForXdgVariable (kv.Key); |
206 | + if (path != null && !SpecialFolderIcons.ContainsKey (path)) { |
207 | + SpecialFolderIcons [path] = kv.Value; |
208 | + } |
209 | + } |
210 | + |
211 | } |
212 | - |
213 | + |
214 | /// <summary> |
215 | /// Abbreviates an absolute path by replacing $HOME with ~. |
216 | /// </summary> |
217 | @@ -54,7 +96,7 @@ |
218 | { |
219 | if (null == path) throw new ArgumentNullException (); |
220 | |
221 | - return path.Replace (Environment.GetFolderPath (Environment.SpecialFolder.Personal), "~"); |
222 | + return path.Replace (Environment.GetFolderPath (SpecialFolder.Personal), "~"); |
223 | } |
224 | |
225 | string name, description, icon; |
226 | @@ -93,11 +135,16 @@ |
227 | |
228 | public override string Icon { |
229 | get { |
230 | + // Icon is memoized. |
231 | if (null != icon) return icon; |
232 | |
233 | - // TODO Filenames with spaces are not |
234 | + // See if the Path is a special folder with a special icon. |
235 | + icon = MaybeGetSpecialFolderIconForPath (Path); |
236 | + if (icon != null) return icon; |
237 | + |
238 | string large_thumb = Thumbnail.PathForUri (Uri, ThumbnailSize.Large); |
239 | string normal_thumb = Thumbnail.PathForUri (Uri, ThumbnailSize.Normal); |
240 | + |
241 | // Generating the thumbnail ourself is too slow for large files. |
242 | // Suggestion: generate thumbnails asynchronously. Banshee's |
243 | // notion of job queues may be useful. |
244 | |
245 | === added file 'Do.Platform.Linux/src/Do.Universe/GNOMEBookmarkItem.cs' |
246 | --- Do.Platform.Linux/src/Do.Universe/GNOMEBookmarkItem.cs 1970-01-01 00:00:00 +0000 |
247 | +++ Do.Platform.Linux/src/Do.Universe/GNOMEBookmarkItem.cs 2009-08-09 18:54:34 +0000 |
248 | @@ -0,0 +1,67 @@ |
249 | +// GNOMEBookmarkItem.cs |
250 | +// |
251 | +// GNOME Do is the legal property of its developers, whose names are too numerous |
252 | +// to list here. Please refer to the COPYRIGHT file distributed with this |
253 | +// source distribution. |
254 | +// |
255 | +// This program is free software: you can redistribute it and/or modify |
256 | +// it under the terms of the GNU General Public License as published by |
257 | +// the Free Software Foundation, either version 3 of the License, or |
258 | +// (at your option) any later version. |
259 | +// |
260 | +// This program is distributed in the hope that it will be useful, |
261 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
262 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
263 | +// GNU General Public License for more details. |
264 | +// |
265 | +// You should have received a copy of the GNU General Public License |
266 | +// along with this program. If not, see <http://www.gnu.org/licenses/>. |
267 | + |
268 | +using System; |
269 | +using System.IO; |
270 | +using System.Linq; |
271 | +using System.Collections.Generic; |
272 | + |
273 | +using Mono.Unix; |
274 | + |
275 | +using Do.Platform; |
276 | +using Do.Universe; |
277 | + |
278 | +namespace Do.Universe.Linux { |
279 | + |
280 | + class GNOMEBookmarkItem : Item, IUriItem |
281 | + { |
282 | + string uri, icon, name; |
283 | + |
284 | + public GNOMEBookmarkItem (string name, string uri) |
285 | + { |
286 | + this.name = name; |
287 | + this.uri = uri; |
288 | + |
289 | + icon = "user-bookmarks"; |
290 | + } |
291 | + |
292 | + public GNOMEBookmarkItem (string name, string uri, string icon) |
293 | + : this (name, uri) |
294 | + { |
295 | + this.icon = icon; |
296 | + } |
297 | + |
298 | + public override string Name { |
299 | + get { return name; } |
300 | + } |
301 | + |
302 | + public override string Description { |
303 | + get { return Uri; } |
304 | + } |
305 | + |
306 | + public string Uri { |
307 | + get { return uri; } |
308 | + } |
309 | + |
310 | + public override string Icon { |
311 | + get { return icon; } |
312 | + } |
313 | + |
314 | + } |
315 | +} |
316 | |
317 | === modified file 'Do.Platform.Linux/src/Do.Universe/GNOMESpecialLocationsItemSource.cs' |
318 | --- Do.Platform.Linux/src/Do.Universe/GNOMESpecialLocationsItemSource.cs 2008-12-20 00:31:54 +0000 |
319 | +++ Do.Platform.Linux/src/Do.Universe/GNOMESpecialLocationsItemSource.cs 2009-08-09 18:54:34 +0000 |
320 | @@ -22,6 +22,7 @@ |
321 | using System.Linq; |
322 | using System.Collections.Generic; |
323 | using System.Text.RegularExpressions; |
324 | + |
325 | using Mono.Unix; |
326 | |
327 | using Do.Platform; |
328 | @@ -30,6 +31,10 @@ |
329 | namespace Do.Universe.Linux { |
330 | |
331 | public class GNOMESpecialLocationsItemSource : ItemSource { |
332 | + |
333 | + static readonly string BookmarksFile = |
334 | + Path.Combine (Environment.GetFolderPath (Environment.SpecialFolder.Personal), ".gtk-bookmarks"); |
335 | + |
336 | List<Item> items; |
337 | |
338 | public GNOMESpecialLocationsItemSource() |
339 | @@ -37,38 +42,20 @@ |
340 | items = new List<Item> (); |
341 | } |
342 | |
343 | - class GNOMEURItem : Item, IUriItem { |
344 | - protected string uri, name, icon; |
345 | - |
346 | - public GNOMEURItem (string uri, string name, string icon) |
347 | - { |
348 | - this.uri = uri; |
349 | - this.name = name; |
350 | - this.icon = icon; |
351 | - } |
352 | - |
353 | - public override string Name { get { return name; } } |
354 | - public override string Description { get { return Uri; } } |
355 | - public override string Icon { get { return icon; } } |
356 | - public string Uri { get { return uri; } } |
357 | - } |
358 | - |
359 | - public override string Name { |
360 | + public override string Name { |
361 | get { return Catalog.GetString ("GNOME Special Locations"); } |
362 | } |
363 | |
364 | - public override string Description { |
365 | - get { return Catalog.GetString ("Special locations in GNOME, " |
366 | - + "such as Computer and Network."); |
367 | + public override string Description { |
368 | + get { |
369 | + return Catalog.GetString ("Special locations in GNOME, such as Computer and Network."); |
370 | } |
371 | } |
372 | |
373 | - public override string Icon { get { return "user-home"; } } |
374 | + public override string Icon { get { return "user-bookmarks"; } } |
375 | |
376 | public override IEnumerable<Type> SupportedItemTypes { |
377 | - get { |
378 | - yield return typeof (IUriItem); |
379 | - } |
380 | + get { yield return typeof (IUriItem); } |
381 | } |
382 | |
383 | public override IEnumerable<Item> Items { |
384 | @@ -78,167 +65,42 @@ |
385 | public override void UpdateItems () |
386 | { |
387 | items.Clear (); |
388 | - items.Add (new GNOMETrashFileItem ()); |
389 | - items.Add (new GNOMEURItem ("computer:///", "Computer", "computer")); |
390 | - items.Add (new GNOMEURItem ("network://", "Network", "network")); |
391 | - FillGNOMEBookmarkItems (); |
392 | + items.Add (new GNOMETrashItem ()); |
393 | + items.Add (new GNOMEBookmarkItem ("Computer", "computer://", "computer")); |
394 | + items.Add (new GNOMEBookmarkItem ("Network", "network://", "network")); |
395 | + foreach (Item item in ReadBookmarkItems ()) items.Add (item); |
396 | } |
397 | |
398 | - private void FillGNOMEBookmarkItems () |
399 | + IEnumerable<IUriItem> ReadBookmarkItems () |
400 | { |
401 | - // Assemble the path to the bookmarks file. |
402 | - string bookmarks_file = Path.Combine (Environment.GetFolderPath (Environment.SpecialFolder.Personal), ".gtk-bookmarks"); |
403 | - |
404 | - try { |
405 | - string line; |
406 | - Regex regex = new Regex ("([^ ]*) (.*)"); |
407 | - |
408 | - string URI; |
409 | - string name; |
410 | - string path; |
411 | - bool network; |
412 | - |
413 | - using (StreamReader reader = new StreamReader (bookmarks_file)) { |
414 | - while ((line = reader.ReadLine ()) != null) { |
415 | - Match match = regex.Match (line); |
416 | - network = (match.Groups.Count == 3); |
417 | - if (network) { |
418 | - name = match.Groups [2].ToString (); |
419 | - URI = GetURI(match.Groups [1].ToString ()); |
420 | - path = GetPath(match.Groups [1].ToString ()); |
421 | - } |
422 | - else { |
423 | - URI = GetURI (line); |
424 | - path = GetPath (line); |
425 | - name = GetDirectory (line); |
426 | - } |
427 | - |
428 | - items.Add (new GNOMEBookmarkItem (name, URI, path, network)); |
429 | + string line, uri, name; |
430 | + Regex regex = new Regex ("([^ ]*) (.*)"); |
431 | + |
432 | + using (StreamReader reader = new StreamReader (BookmarksFile)) { |
433 | + while ((line = reader.ReadLine ()) != null) { |
434 | + |
435 | + Match match = regex.Match (line); |
436 | + bool isNetworkBookmark = match.Groups.Count == 3; |
437 | + |
438 | + if (line.StartsWith ("file://")) { |
439 | + string path = line; |
440 | + |
441 | + path = path.Substring ("file://".Length); |
442 | + // Some entries contain more information after the URI. We |
443 | + // discard it. |
444 | + if (line.Contains (" ")) |
445 | + path = path.Substring (0, path.IndexOf (" ")); |
446 | + path = Uri.UnescapeDataString (path); |
447 | + |
448 | + yield return Services.UniverseFactory.NewFileItem (path); |
449 | + } else if (isNetworkBookmark) { |
450 | + name = match.Groups [2].ToString (); |
451 | + uri = match.Groups [1].ToString (); |
452 | + yield return new GNOMEBookmarkItem (name, uri, "network"); |
453 | } |
454 | } |
455 | - } catch (Exception e) { |
456 | - // Something went horribly wrong, so we print the error message. |
457 | - Console.Error.WriteLine ("Could not read Gnome Bookmarks file {0}: {1}", bookmarks_file, e.Message); |
458 | - } |
459 | - } |
460 | - |
461 | - private int GetURIDelimiter (string fullPath) |
462 | - { |
463 | - return fullPath.IndexOf ("//"); |
464 | - } |
465 | - |
466 | - private string GetURI (string fullpath) |
467 | - { |
468 | - int delimindex = GetURIDelimiter (fullpath); |
469 | - |
470 | - if (delimindex > -1) |
471 | - return fullpath.Substring (0, delimindex+2 ); |
472 | - else |
473 | - return "file://"; |
474 | - } |
475 | - |
476 | - private string GetPath (string fullpath) |
477 | - { |
478 | - int delimindex = GetURIDelimiter (fullpath); |
479 | - |
480 | - if (delimindex > -1) |
481 | - return fullpath.Substring (delimindex+2, fullpath.Length - delimindex-2); |
482 | - else |
483 | - return Environment.GetFolderPath (Environment.SpecialFolder.Personal); |
484 | - } |
485 | - |
486 | - private string GetDirectory (string fullpath) |
487 | - { |
488 | - int lastSlashPosition = fullpath.LastIndexOf ("/"); |
489 | - return fullpath.Substring(lastSlashPosition+1, fullpath.Length-lastSlashPosition-1); |
490 | - } |
491 | - |
492 | - } |
493 | - |
494 | - class GNOMETrashFileItem : Item, IFileItem, IOpenableItem |
495 | - { |
496 | - |
497 | - string path; |
498 | - public string Path { |
499 | - get { |
500 | - if (path != null) return path; |
501 | - |
502 | - return path = new [] { |
503 | - Environment.GetFolderPath (Environment.SpecialFolder.LocalApplicationData), |
504 | - "Trash", |
505 | - "files", |
506 | - }.Aggregate (System.IO.Path.Combine); |
507 | - } |
508 | - } |
509 | - |
510 | - public override string Name { |
511 | - get { return "Trash"; } |
512 | - } |
513 | - |
514 | - public override string Description { |
515 | - get { return "Trash"; } |
516 | - } |
517 | - |
518 | - public string Uri { |
519 | - get { return "trash://"; } |
520 | - } |
521 | - |
522 | - public override string Icon |
523 | - { |
524 | - get { |
525 | - if (Directory.Exists (Path) && |
526 | - Directory.GetFileSystemEntries (Path).Length > 0) { |
527 | - return "user-trash-full"; |
528 | - } else { |
529 | - return "user-trash"; |
530 | - } |
531 | - } |
532 | - } |
533 | - |
534 | - public void Open () |
535 | - { |
536 | - Services.Environment.OpenUrl ("trash://"); |
537 | - } |
538 | - } |
539 | - |
540 | - class GNOMEBookmarkItem : Item, IFileItem, IOpenableItem |
541 | - { |
542 | - private string uri; |
543 | - private string icon; |
544 | - private string name; |
545 | - private string path; |
546 | - |
547 | - public GNOMEBookmarkItem (string fullname, string fullURI, string fullpath, bool networkType) |
548 | - { |
549 | - uri = fullURI; |
550 | - name = fullname; |
551 | - path = fullpath; |
552 | - icon = networkType ? "network" : "folder"; |
553 | - } |
554 | - |
555 | - public string Path { |
556 | - get { return path; } |
557 | - } |
558 | - |
559 | - public override string Name { |
560 | - get { return name; } |
561 | - } |
562 | - |
563 | - public override string Description { |
564 | - get { return uri + path; } |
565 | - } |
566 | - |
567 | - public string Uri { |
568 | - get { return uri; } |
569 | - } |
570 | - |
571 | - public override string Icon { |
572 | - get { return icon; } |
573 | - } |
574 | - |
575 | - public void Open () |
576 | - { |
577 | - Services.Environment.OpenUrl (Uri + Path); |
578 | - } |
579 | + } |
580 | + } |
581 | + |
582 | } |
583 | } |
584 | |
585 | === added file 'Do.Platform.Linux/src/Do.Universe/GNOMETrashItem.cs' |
586 | --- Do.Platform.Linux/src/Do.Universe/GNOMETrashItem.cs 1970-01-01 00:00:00 +0000 |
587 | +++ Do.Platform.Linux/src/Do.Universe/GNOMETrashItem.cs 2009-08-09 18:54:34 +0000 |
588 | @@ -0,0 +1,76 @@ |
589 | +// GNOMETrashItem.cs |
590 | +// |
591 | +// GNOME Do is the legal property of its developers, whose names are too numerous |
592 | +// to list here. Please refer to the COPYRIGHT file distributed with this |
593 | +// source distribution. |
594 | +// |
595 | +// This program is free software: you can redistribute it and/or modify |
596 | +// it under the terms of the GNU General Public License as published by |
597 | +// the Free Software Foundation, either version 3 of the License, or |
598 | +// (at your option) any later version. |
599 | +// |
600 | +// This program is distributed in the hope that it will be useful, |
601 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
602 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
603 | +// GNU General Public License for more details. |
604 | +// |
605 | +// You should have received a copy of the GNU General Public License |
606 | +// along with this program. If not, see <http://www.gnu.org/licenses/>. |
607 | + |
608 | +using System; |
609 | +using System.IO; |
610 | +using System.Linq; |
611 | +using System.Collections.Generic; |
612 | + |
613 | +using Mono.Unix; |
614 | + |
615 | +using Do.Platform; |
616 | +using Do.Universe; |
617 | + |
618 | +namespace Do.Universe.Linux { |
619 | + |
620 | + class GNOMETrashItem : Item, IFileItem, IOpenableItem |
621 | + { |
622 | + |
623 | + string path; |
624 | + public string Path { |
625 | + get { |
626 | + if (path != null) return path; |
627 | + |
628 | + return path = new [] { |
629 | + Environment.GetFolderPath (Environment.SpecialFolder.LocalApplicationData), |
630 | + "Trash", |
631 | + "files", |
632 | + }.Aggregate (System.IO.Path.Combine); |
633 | + } |
634 | + } |
635 | + |
636 | + public override string Name { |
637 | + get { return "Trash"; } |
638 | + } |
639 | + |
640 | + public override string Description { |
641 | + get { return "Trash"; } |
642 | + } |
643 | + |
644 | + public string Uri { |
645 | + get { return "trash://"; } |
646 | + } |
647 | + |
648 | + public override string Icon |
649 | + { |
650 | + get { |
651 | + if (Directory.Exists (Path) && Directory.GetFileSystemEntries (Path).Any ()) { |
652 | + return "user-trash-full"; |
653 | + } else { |
654 | + return "user-trash"; |
655 | + } |
656 | + } |
657 | + } |
658 | + |
659 | + public void Open () |
660 | + { |
661 | + Services.Environment.OpenUrl ("trash://"); |
662 | + } |
663 | + } |
664 | +} |
Supercedes David's merge https:/ /code.launchpad .net/~djsiegel/ do/xdg- user-dirs- icons/+ merge/9896
Addresses my comments with regards to XDG method in FileItem. Once this is merged we should update any plugins that copied and pasted the xdg code.