~cszikszoy/do-plugins/fix-confluence

« back to all changes in this revision

Viewing changes to Opera/src/OperaBookmarkItemSource.cs

  • Committer: David Siegel
  • Date: 2009-01-07 19:40:53 UTC
  • mfrom: (407.1.4 trunk)
  • Revision ID: david@x-20090107194053-wseaq4rkw4y12bka
Merge.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
using System;
 
2
using System.IO;
 
3
using System.Collections.Generic;
 
4
 
 
5
using Mono.Unix;
 
6
 
 
7
using Do.Platform;
 
8
using Do.Universe;
 
9
using Do.Universe.Common;
 
10
 
 
11
namespace Opera 
 
12
{
 
13
        public class OperaBookmarkItemSource : ItemSource 
 
14
        {
 
15
                
 
16
                List<Item> items;
 
17
                
 
18
                public OperaBookmarkItemSource()
 
19
                {
 
20
                        items = new List<Item> ();
 
21
                }
 
22
                
 
23
                public override string Name { 
 
24
                        get { return Catalog.GetString ("Opera Bookmarks"); } 
 
25
                }
 
26
 
 
27
                public override string Description { 
 
28
                        get { return Catalog.GetString ("Indexes your Opera 6 bookmarks"); } 
 
29
                }
 
30
 
 
31
                public override string Icon { 
 
32
                        get { return "opera"; } 
 
33
                }
 
34
                
 
35
                public override  IEnumerable<Type> SupportedItemTypes {
 
36
                        get { yield return typeof (BookmarkItem); }
 
37
                }
 
38
                public override IEnumerable<Item> Items {
 
39
                        get { return items; }
 
40
                }
 
41
                
 
42
                public override void UpdateItems ()
 
43
                {
 
44
                        string home = Environment.GetFolderPath (Environment.SpecialFolder.Personal);
 
45
                        string path = "~/.opera/opera6.adr".Replace ("~", home);
 
46
                        
 
47
                        items.Clear();
 
48
                        try {
 
49
                                using (StreamReader streamReader = new StreamReader (path)) {
 
50
                                        string strName;
 
51
                                        string strURL;
 
52
                                        while((strName = streamReader.ReadLine ()) != null) {
 
53
                                                if (!strName.Contains ("NAME")) continue;
 
54
 
 
55
                                                strURL = streamReader.ReadLine ();
 
56
 
 
57
                                                if (string.IsNullOrEmpty (strURL) || !strURL.Contains ("URL")) continue;
 
58
 
 
59
                                                strName = strName.Replace ("NAME=", "");
 
60
                                                strURL = strURL.Replace ("URL=", "");
 
61
                                                items.Add (new BookmarkItem (strName, strURL));                                         
 
62
                                        }
 
63
                                }
 
64
                        }
 
65
                        catch (Exception e) {
 
66
                                Log.Error ("Could not read Opera Bookmarks file {0}: {1}", path, e.Message);
 
67
                                Log.Debug (e.StackTrace);
 
68
                        }
 
69
                }
 
70
        }
 
71
}
 
72