Merge lp:~felix-velasco/do-plugins/firefox-favicons into lp:do-plugins

Proposed by Félix Velasco
Status: Needs review
Proposed branch: lp:~felix-velasco/do-plugins/firefox-favicons
Merge into: lp:do-plugins
Diff against target: 171 lines (+47/-11)
4 files modified
Firefox/Firefox.mdp (+2/-1)
Firefox/Makefile.am (+1/-0)
Firefox/src/PlaceItem.cs (+6/-4)
Firefox/src/PlacesItemSource.cs (+38/-6)
To merge this branch: bzr merge lp:~felix-velasco/do-plugins/firefox-favicons
Reviewer Review Type Date Requested Status
Do Plugins Team Pending
Review via email: mp+15413@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Félix Velasco (felix-velasco) wrote :

If there's a stored favicon in the firefox db, compose it with the current "www" icon used for it. I was not sure of the proper size as to retrieve the stock icon. With bigger sizes, the favicons need to be scaled or are way too small, and it may take a second or two to reload the Firefox Places plugin

Unmerged revisions

675. By Félix Velasco

Retrieve favicon info from firefox's sqlite database and use it composed with the current icon

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Firefox/Firefox.mdp'
2--- Firefox/Firefox.mdp 2009-06-29 08:47:41 +0000
3+++ Firefox/Firefox.mdp 2009-11-30 12:05:22 +0000
4@@ -31,8 +31,9 @@
5 <ProjectReference type="Gac" localcopy="True" refto="System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
6 <ProjectReference type="Gac" localcopy="True" refto="Mono.Data.SqliteClient, Version=2.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756" />
7 <ProjectReference type="Gac" localcopy="True" refto="Mono.Addins, Version=0.4.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756" />
8+ <ProjectReference type="Gac" localcopy="True" refto="gdk-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
9 <ProjectReference type="Gac" localcopy="True" refto="Do.Platform, Version=0.9.0.0, Culture=neutral" />
10 <ProjectReference type="Gac" localcopy="True" refto="Do.Platform.Linux, Version=0.9.0.0, Culture=neutral" />
11 <ProjectReference type="Gac" localcopy="True" refto="Do.Universe, Version=0.9.0.0, Culture=neutral" />
12 </References>
13-</Project>
14\ No newline at end of file
15+</Project>
16
17=== modified file 'Firefox/Makefile.am'
18--- Firefox/Makefile.am 2009-06-22 04:05:16 +0000
19+++ Firefox/Makefile.am 2009-11-30 12:05:22 +0000
20@@ -17,5 +17,6 @@
21 System.Core \
22 System.Data \
23 Mono.Data.SqliteClient \
24+ $(GTK_SHARP_20_LIBS) \
25 $(DO_PLATFORM_LIBS) \
26 $(DO_UNIVERSE_LIBS)
27
28=== modified file 'Firefox/src/PlaceItem.cs'
29--- Firefox/src/PlaceItem.cs 2009-06-22 04:05:16 +0000
30+++ Firefox/src/PlaceItem.cs 2009-11-30 12:05:22 +0000
31@@ -30,19 +30,21 @@
32
33 public class PlaceItem : Item, IBookmarkItem
34 {
35- string title, url;
36+ string title, url, icon;
37
38- public PlaceItem (string title, string url)
39+ public PlaceItem (string title, string url, string icon)
40 {
41 this.url = url;
42 this.title = title;
43+ this.icon = icon;
44 }
45
46- public PlaceItem (string title, string url, int parentId)
47+ public PlaceItem (string title, string url, string icon, int parentId)
48 {
49 this.url = url;
50 this.title = title;
51 ParentId = parentId;
52+ this.icon = icon;
53 }
54
55 public override string Name {
56@@ -54,7 +56,7 @@
57 }
58
59 public override string Icon {
60- get { return "www"; }
61+ get { return icon; }
62 }
63
64 public string Url {
65
66=== modified file 'Firefox/src/PlacesItemSource.cs'
67--- Firefox/src/PlacesItemSource.cs 2009-09-05 02:06:59 +0000
68+++ Firefox/src/PlacesItemSource.cs 2009-11-30 12:05:22 +0000
69@@ -28,6 +28,7 @@
70 using Do.Universe;
71 using Do.Universe.Common;
72
73+using Gdk;
74 using Mono.Addins;
75 using Mono.Data.SqliteClient;
76
77@@ -44,6 +45,7 @@
78 IEnumerable<FolderItem> folders;
79
80 string stored_temp_db_path;
81+ string tmp_favicon_folder;
82
83 public PlacesItemSource ()
84 {
85@@ -52,6 +54,8 @@
86 folders = Enumerable.Empty<FolderItem> ();
87
88 ProfilePath = FindProfilePath ();
89+ tmp_favicon_folder = Path.Combine (Path.GetTempPath(), "do-firefox-favicons");
90+ Directory.CreateDirectory (tmp_favicon_folder);
91 }
92
93 ~PlacesItemSource ()
94@@ -63,6 +67,13 @@
95 Log<PlacesItemSource>.Error ("Could not delete stored db file: {0}", e.Message);
96 Log<PlacesItemSource>.Debug (e.StackTrace);
97 }
98+ try {
99+ if (Directory.Exists (tmp_favicon_folder))
100+ Directory.Delete (tmp_favicon_folder, true);
101+ } catch (IOException e) {
102+ Log<PlacesItemSource>.Error ("Could not delete temporary favicons folder: {0}", e.Message);
103+ Log<PlacesItemSource>.Debug (e.StackTrace);
104+ }
105 }
106
107 public override string Name {
108@@ -275,9 +286,14 @@
109 dbcon.Open ();
110
111 using (IDbCommand dbcmd = dbcon.CreateCommand ()) {
112- dbcmd.CommandText = "SELECT moz_places.title, moz_places.url, moz_bookmarks.parent, moz_bookmarks.title "
113+ dbcmd.CommandText = "SELECT moz_places.title, moz_places.url, "
114+ + "moz_bookmarks.parent, moz_bookmarks.title, "
115+ + "moz_favicons.data, moz_favicons.id "
116 + "FROM moz_places LEFT OUTER JOIN moz_bookmarks "
117 + "ON moz_places.id=moz_bookmarks.fk "
118+ + "LEFT OUTER JOIN moz_favicons "
119+ + "ON moz_places.favicon_id=moz_favicons.id "
120+
121 + "ORDER BY moz_places.frecency DESC "
122 + "LIMIT 500";
123
124@@ -285,20 +301,36 @@
125 while (reader.Read () ) {
126 string title = reader.GetString (0);
127 string url = reader.GetString (1);
128-
129+ string icon = "www";
130+
131 // Firefox stores some interesting non-url places. Ignore them.
132 if (url [0] != 'p') {
133+ // Check if the place has a stored favicon
134+ if (!reader.IsDBNull(5) && !reader.IsDBNull(4)) {
135+ string id = reader.GetString (5);
136+ icon = Path.Combine (tmp_favicon_folder, id + ".png");
137+
138+ // Firefox reuses favicons, and so do we
139+ if (!File.Exists(icon)) {
140+ byte[] data = (byte[]) reader["data"];
141+ Pixbuf pix = new Pixbuf (data);
142+ Pixbuf dest = Gtk.IconTheme.Default.LoadIcon ("www", 80, 0);
143+ pix.Composite (dest, 0, 0, pix.Width, pix.Height, 0, 0, 1, 1, InterpType.Bilinear , 200);
144+ dest.Save (icon, "png");
145+ }
146+ }
147+
148 // If the place is a bookmark, use the title stored in Bookmarks.
149 if (!reader.IsDBNull (2)) {
150 int parent = reader.GetInt32 (2);
151 string bookmarkTitle = reader.GetString (3);
152
153- yield return new PlaceItem (bookmarkTitle, url, parent);
154+ yield return new PlaceItem (bookmarkTitle, url, icon, parent);
155 } else if (string.IsNullOrEmpty (title)) {
156 // If the place has no title, use the url as a title so it's searchable.
157- yield return new PlaceItem (url, url);
158+ yield return new PlaceItem (url, url, icon);
159 } else {
160- yield return new PlaceItem (title, url);
161+ yield return new PlaceItem (title, url, icon);
162 }
163 }
164 }
165@@ -309,4 +341,4 @@
166 }
167 }
168 }
169-}
170\ No newline at end of file
171+}

Subscribers

People subscribed via source and target branches