~do-plugins/do-plugins/trunk

« back to all changes in this revision

Viewing changes to Vinagre/VNCHostSource.cs

Merge non-b0rked GCal & Vinagre plugins

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* VNCHostSource.cs
 
2
 
 
3
 * GNOME Do is the legal property of its developers. Please refer to the
 
4
 * COPYRIGHT file distributed with this
 
5
 * source distribution.
 
6
 *
 
7
 * This program is free software: you can redistribute it and/or modify
 
8
 * it under the terms of the GNU General Public License as published by
 
9
 * the Free Software Foundation, either version 3 of the License, or
 
10
 * (at your option) any later version.
 
11
 *
 
12
 * This program is distributed in the hope that it will be useful,
 
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 
15
 * GNU General Public License for more details.
 
16
 *
 
17
 * You should have received a copy of the GNU General Public License
 
18
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 
19
 */
 
20
 
 
21
using System;
 
22
using System.IO;
 
23
using System.Collections.Generic;
 
24
 
 
25
using Do.Universe;
 
26
 
 
27
namespace GnomeDoVNC {  
 
28
    public class VNCHostItem : IItemSource {
 
29
        List<IItem> items;
 
30
 
 
31
        public VNCHostItem ()
 
32
        {
 
33
            items = new List<IItem> ();
 
34
            UpdateItems ();
 
35
        }
 
36
 
 
37
        public string Name { 
 
38
            get { return "Vinagre Bookmarks"; }
 
39
        }
 
40
 
 
41
        public string Description { 
 
42
            get { return "Indexes your Vinagre Bookmarks"; }
 
43
        }
 
44
 
 
45
        public string Icon {
 
46
            get { return "gnome-globe"; }
 
47
        }
 
48
 
 
49
        public Type[] SupportedItemTypes {
 
50
            get {
 
51
                return new Type[] {
 
52
                    typeof (VNCHostItem), 
 
53
                    typeof (HostItem) 
 
54
                };
 
55
            }
 
56
        }
 
57
 
 
58
        public ICollection<IItem> Items {
 
59
            get { return items; }
 
60
        }
 
61
 
 
62
        public ICollection<IItem> ChildrenOfItem (IItem parent)
 
63
        {
 
64
            return null;  
 
65
        }
 
66
 
 
67
        public void UpdateItems ()
 
68
        {
 
69
            items.Clear ();
 
70
            string bookmarks_file = Environment.GetEnvironmentVariable ("HOME") + "/.gnome2/vinagre.bookmarks";
 
71
            string s, host, port;
 
72
            try {
 
73
                StreamReader reader = File.OpenText(bookmarks_file);
 
74
                while ((s = reader.ReadLine ()) != null) {
 
75
                    if (s.Length > 1) {
 
76
                        if ((s.Substring (0,1).Equals ("[")) && (s.Substring (s.Length - 1,1).Equals ("]"))) {
 
77
                            s = s.Substring (1, s.Length - 2);
 
78
                            host = reader.ReadLine ();
 
79
                            port = reader.ReadLine ();
 
80
                            host = host.Substring (5, host.Length - 5);
 
81
                            port = port.Substring (5, port.Length - 5);
 
82
                            items.Add (new HostItem(s, host, port));
 
83
                        }
 
84
                    }
 
85
                }
 
86
            } catch { 
 
87
                Console.Error.WriteLine ("[ERROR] " + bookmarks_file + " cannot be read!");
 
88
            } 
 
89
        }
 
90
    }
 
91
}
 
92