Merge lp://qastaging/~alexlauni/do-plugins/vinagre-indexing-fix into lp://qastaging/do-plugins

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

Fixes indexing of vinagre bookmarks due to upstream file format and location changes.

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 'Vinagre/Makefile.am'
2--- Vinagre/Makefile.am 2009-01-09 08:49:53 +0000
3+++ Vinagre/Makefile.am 2009-04-20 22:17:34 +0000
4@@ -13,6 +13,7 @@
5 REFERENCES = \
6 Mono.Posix \
7 System \
8+ System.Xml \
9 System.Core \
10 $(DO_PLATFORM_LIBS) \
11 $(DO_UNIVERSE_LIBS)
12
13=== modified file 'Vinagre/Vinagre.mdp'
14--- Vinagre/Vinagre.mdp 2009-02-28 16:16:48 +0000
15+++ Vinagre/Vinagre.mdp 2009-04-20 22:17:34 +0000
16@@ -26,5 +26,6 @@
17 <ProjectReference type="Gac" localcopy="True" refto="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
18 <ProjectReference type="Gac" localcopy="True" refto="Do.Universe, Version=0.8.0.0, Culture=neutral, PublicKeyToken=null" />
19 <ProjectReference type="Gac" localcopy="True" refto="Do.Platform, Version=0.8.0.0, Culture=neutral, PublicKeyToken=null" />
20+ <ProjectReference type="Gac" localcopy="True" refto="System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
21 </References>
22 </Project>
23\ No newline at end of file
24
25=== modified file 'Vinagre/src/VNCHost.cs'
26--- Vinagre/src/VNCHost.cs 2008-12-21 23:44:34 +0000
27+++ Vinagre/src/VNCHost.cs 2009-04-20 22:17:34 +0000
28@@ -24,35 +24,33 @@
29
30 using Do.Universe;
31
32-namespace VinagreVNC {
33- public class HostItem : Item {
34- string bookmark, hostname, port;
35-
36- public HostItem (string bookmark, string hostname, string port )
37+namespace VinagreVNC
38+{
39+ public class HostItem : Item
40+ {
41+ public HostItem (string bookmark, string hostname, string port)
42 {
43- this.bookmark = bookmark;
44- this.hostname = hostname;
45- this.port = port;
46+ port = port;
47+ Bookmark = bookmark;
48+ Hostname = hostname;
49 }
50
51 public override string Name {
52- get { return bookmark; }
53+ get { return Bookmark; }
54 }
55
56 public override string Description {
57- get { return hostname; }
58+ get { return Hostname; }
59 }
60
61 public override string Icon {
62 get { return "gnome-globe"; }
63 }
64-
65- public string Text {
66- get { return bookmark; }
67- }
68-
69- public string Port {
70- get { return port; }
71- }
72+
73+ public string Hostname { get; private set; }
74+
75+ public string Bookmark { get; private set; }
76+
77+ public string Port { get; private set; }
78 }
79 }
80
81=== modified file 'Vinagre/src/VNCHostSource.cs'
82--- Vinagre/src/VNCHostSource.cs 2008-12-21 23:44:34 +0000
83+++ Vinagre/src/VNCHostSource.cs 2009-04-20 22:20:13 +0000
84@@ -20,19 +20,24 @@
85
86 using System;
87 using System.IO;
88+using System.Xml;
89+using System.Linq;
90 using System.Collections.Generic;
91+
92 using Mono.Unix;
93
94+using Do.Platform;
95 using Do.Universe;
96
97-namespace VinagreVNC {
98- public class VNCHostItem : ItemSource {
99+namespace VinagreVNC
100+{
101+ public class VNCHostItem : ItemSource
102+ {
103 List<Item> items;
104
105 public VNCHostItem ()
106 {
107 items = new List<Item> ();
108- //UpdateItems ();
109 }
110
111 public override string Name {
112@@ -49,10 +54,8 @@
113
114 public override IEnumerable<Type> SupportedItemTypes {
115 get {
116- return new Type[] {
117- typeof (VNCHostItem),
118- typeof (HostItem)
119- };
120+ yield return typeof (HostItem);
121+ yield return typeof (VNCHostItem);
122 }
123 }
124
125@@ -60,33 +63,91 @@
126 get { return items; }
127 }
128
129- public override IEnumerable<Item> ChildrenOfItem (Item parent)
130- {
131- return null;
132- }
133-
134 public override void UpdateItems ()
135 {
136- items.Clear ();
137- string bookmarks_file = Environment.GetEnvironmentVariable ("HOME") + "/.gnome2/vinagre.bookmarks";
138- string s, host, port;
139- try {
140- StreamReader reader = File.OpenText(bookmarks_file);
141- while ((s = reader.ReadLine ()) != null) {
142- if (s.Length > 1) {
143- if ((s.Substring (0,1).Equals ("[")) && (s.Substring (s.Length - 1,1).Equals ("]"))) {
144- s = s.Substring (1, s.Length - 2);
145- host = reader.ReadLine ();
146- port = reader.ReadLine ();
147- host = host.Substring (5, host.Length - 5);
148- port = port.Substring (5, port.Length - 5);
149- items.Add (new HostItem(s, host, port));
150- }
151- }
152- }
153- } catch {
154- }
155+ XmlDocument xml;
156+ XmlNodeList elements;
157+ string bookmarksFile;
158+
159+ items.Clear ();
160+ xml = new XmlDocument ();
161+ bookmarksFile = new [] {ReadXdgUserDir ("XDG_DATA_HOME", ".local/share"), "vinagre", "vinagre-bookmarks.xml"}.Aggregate (Path.Combine);
162+
163+ try {
164+ xml.Load (bookmarksFile);
165+
166+ elements = xml.GetElementsByTagName ("item");
167+
168+ foreach (XmlNode node in elements) {
169+ string bookmark = "", host = "", port = "";
170+
171+ foreach (XmlNode child in node.ChildNodes) {
172+ switch (child.Name) {
173+ case "name":
174+ bookmark = child.InnerText;
175+ break;
176+ case "host":
177+ host = child.InnerText;
178+ break;
179+ case "port":
180+ port = child.InnerText;
181+ break;
182+ }
183+ }
184+
185+ items.Add (new HostItem (bookmark, host, port));
186+ }
187+ } catch (FileNotFoundException e) {
188+ Log.Debug ("Cound not find vinagre bookmarks file {0}", bookmarksFile);
189+ } catch (XmlException e) {
190+ Log.Debug ("An error occured parsing bookmarks file {0}:", e.Message);
191+ }
192 }
193+
194+ string ReadXdgUserDir (string key, string fallback)
195+ {
196+ string home_dir, config_dir, env_path, user_dirs_path;
197+
198+ home_dir = Environment.GetFolderPath (Environment.SpecialFolder.Personal);
199+ config_dir = Environment.GetFolderPath (Environment.SpecialFolder.ApplicationData);
200+
201+ env_path = Environment.GetEnvironmentVariable (key);
202+ if (!String.IsNullOrEmpty (env_path)) {
203+ return env_path;
204+ }
205+
206+ user_dirs_path = Path.Combine (config_dir, "user-dirs.dirs");
207+ if (!File.Exists (user_dirs_path)) {
208+ return Path.Combine (home_dir, fallback);
209+ }
210+
211+ try {
212+ using (StreamReader reader = new StreamReader (user_dirs_path)) {
213+ string line;
214+ while ((line = reader.ReadLine ()) != null) {
215+ line = line.Trim ();
216+ int delim_index = line.IndexOf ('=');
217+ if (delim_index > 8 && line.Substring (0, delim_index) == key) {
218+ string path = line.Substring (delim_index + 1).Trim ('"');
219+ bool relative = false;
220+
221+ if (path.StartsWith ("$HOME/")) {
222+ relative = true;
223+ path = path.Substring (6);
224+ } else if (path.StartsWith ("~")) {
225+ relative = true;
226+ path = path.Substring (1);
227+ } else if (!path.StartsWith ("/")) {
228+ relative = true;
229+ }
230+ return relative ? Path.Combine (home_dir, path) : path;
231+ }
232+ }
233+ }
234+ } catch (FileNotFoundException) {
235+ }
236+ return Path.Combine (home_dir, fallback);
237+ }
238 }
239 }
240
241
242=== modified file 'Vinagre/src/Vinagre.cs'
243--- Vinagre/src/Vinagre.cs 2008-12-21 23:44:34 +0000
244+++ Vinagre/src/Vinagre.cs 2009-04-20 22:17:34 +0000
245@@ -22,12 +22,15 @@
246 using System.Collections.Generic;
247 using System.Diagnostics;
248 using System.Linq;
249+
250 using Mono.Unix;
251
252 using Do.Universe;
253
254-namespace VinagreVNC {
255- public class VNCAction : Act {
256+namespace VinagreVNC
257+{
258+ public class VNCAction : Act
259+ {
260 public override string Name {
261 get { return Catalog.GetString ("Connect with VNC"); }
262 }
263@@ -42,33 +45,28 @@
264
265 public override IEnumerable<Type> SupportedItemTypes {
266 get {
267- return new Type[] {
268- typeof(HostItem),
269- typeof(VNCHostItem),
270- typeof(ITextItem),
271- };
272+ yield return typeof (HostItem);
273+ yield return typeof (ITextItem);
274+ yield return typeof (VNCHostItem);
275 }
276 }
277
278- public override bool SupportsItem (Item item) {
279- return true;
280- }
281-
282 public override IEnumerable<Item> Perform (IEnumerable<Item> items, IEnumerable<Item> modItems) {
283 string hostname;
284+
285 if (items.First () is ITextItem) {
286- ITextItem textitem = items.First () as ITextItem;
287- hostname = textitem.Text;
288- }
289- else {
290+ hostname = (items.First () as ITextItem).Text;
291+ } else {
292 HostItem hostitem = items.First () as HostItem;
293- hostname = hostitem.Description + ":" + hostitem.Port;
294+ hostname = hostitem.Hostname + ":" + hostitem.Port;
295 }
296+
297 Process vinagre = new Process ();
298 vinagre.StartInfo.FileName = "vinagre";
299 vinagre.StartInfo.Arguments = hostname;
300 vinagre.Start ();
301- return null;
302+
303+ yield break;
304 }
305 }
306 }

Subscribers

People subscribed via source and target branches