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
=== modified file 'Firefox/Firefox.mdp'
--- Firefox/Firefox.mdp 2009-06-29 08:47:41 +0000
+++ Firefox/Firefox.mdp 2009-11-30 12:05:22 +0000
@@ -31,8 +31,9 @@
31 <ProjectReference type="Gac" localcopy="True" refto="System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />31 <ProjectReference type="Gac" localcopy="True" refto="System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
32 <ProjectReference type="Gac" localcopy="True" refto="Mono.Data.SqliteClient, Version=2.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756" />32 <ProjectReference type="Gac" localcopy="True" refto="Mono.Data.SqliteClient, Version=2.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756" />
33 <ProjectReference type="Gac" localcopy="True" refto="Mono.Addins, Version=0.4.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756" />33 <ProjectReference type="Gac" localcopy="True" refto="Mono.Addins, Version=0.4.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756" />
34 <ProjectReference type="Gac" localcopy="True" refto="gdk-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
34 <ProjectReference type="Gac" localcopy="True" refto="Do.Platform, Version=0.9.0.0, Culture=neutral" />35 <ProjectReference type="Gac" localcopy="True" refto="Do.Platform, Version=0.9.0.0, Culture=neutral" />
35 <ProjectReference type="Gac" localcopy="True" refto="Do.Platform.Linux, Version=0.9.0.0, Culture=neutral" />36 <ProjectReference type="Gac" localcopy="True" refto="Do.Platform.Linux, Version=0.9.0.0, Culture=neutral" />
36 <ProjectReference type="Gac" localcopy="True" refto="Do.Universe, Version=0.9.0.0, Culture=neutral" />37 <ProjectReference type="Gac" localcopy="True" refto="Do.Universe, Version=0.9.0.0, Culture=neutral" />
37 </References>38 </References>
38</Project>
39\ No newline at end of file39\ No newline at end of file
40</Project>
4041
=== modified file 'Firefox/Makefile.am'
--- Firefox/Makefile.am 2009-06-22 04:05:16 +0000
+++ Firefox/Makefile.am 2009-11-30 12:05:22 +0000
@@ -17,5 +17,6 @@
17 System.Core \17 System.Core \
18 System.Data \18 System.Data \
19 Mono.Data.SqliteClient \19 Mono.Data.SqliteClient \
20 $(GTK_SHARP_20_LIBS) \
20 $(DO_PLATFORM_LIBS) \21 $(DO_PLATFORM_LIBS) \
21 $(DO_UNIVERSE_LIBS)22 $(DO_UNIVERSE_LIBS)
2223
=== modified file 'Firefox/src/PlaceItem.cs'
--- Firefox/src/PlaceItem.cs 2009-06-22 04:05:16 +0000
+++ Firefox/src/PlaceItem.cs 2009-11-30 12:05:22 +0000
@@ -30,19 +30,21 @@
30 30
31 public class PlaceItem : Item, IBookmarkItem31 public class PlaceItem : Item, IBookmarkItem
32 {32 {
33 string title, url;33 string title, url, icon;
34 34
35 public PlaceItem (string title, string url)35 public PlaceItem (string title, string url, string icon)
36 {36 {
37 this.url = url;37 this.url = url;
38 this.title = title;38 this.title = title;
39 this.icon = icon;
39 }40 }
40 41
41 public PlaceItem (string title, string url, int parentId)42 public PlaceItem (string title, string url, string icon, int parentId)
42 {43 {
43 this.url = url;44 this.url = url;
44 this.title = title;45 this.title = title;
45 ParentId = parentId;46 ParentId = parentId;
47 this.icon = icon;
46 }48 }
4749
48 public override string Name { 50 public override string Name {
@@ -54,7 +56,7 @@
54 }56 }
55 57
56 public override string Icon {58 public override string Icon {
57 get { return "www"; } 59 get { return icon; }
58 }60 }
59 61
60 public string Url { 62 public string Url {
6163
=== modified file 'Firefox/src/PlacesItemSource.cs'
--- Firefox/src/PlacesItemSource.cs 2009-09-05 02:06:59 +0000
+++ Firefox/src/PlacesItemSource.cs 2009-11-30 12:05:22 +0000
@@ -28,6 +28,7 @@
28using Do.Universe;28using Do.Universe;
29using Do.Universe.Common;29using Do.Universe.Common;
3030
31using Gdk;
31using Mono.Addins;32using Mono.Addins;
32using Mono.Data.SqliteClient;33using Mono.Data.SqliteClient;
33 34
@@ -44,6 +45,7 @@
44 IEnumerable<FolderItem> folders;45 IEnumerable<FolderItem> folders;
45 46
46 string stored_temp_db_path;47 string stored_temp_db_path;
48 string tmp_favicon_folder;
47 49
48 public PlacesItemSource ()50 public PlacesItemSource ()
49 {51 {
@@ -52,6 +54,8 @@
52 folders = Enumerable.Empty<FolderItem> ();54 folders = Enumerable.Empty<FolderItem> ();
5355
54 ProfilePath = FindProfilePath ();56 ProfilePath = FindProfilePath ();
57 tmp_favicon_folder = Path.Combine (Path.GetTempPath(), "do-firefox-favicons");
58 Directory.CreateDirectory (tmp_favicon_folder);
55 }59 }
5660
57 ~PlacesItemSource ()61 ~PlacesItemSource ()
@@ -63,6 +67,13 @@
63 Log<PlacesItemSource>.Error ("Could not delete stored db file: {0}", e.Message);67 Log<PlacesItemSource>.Error ("Could not delete stored db file: {0}", e.Message);
64 Log<PlacesItemSource>.Debug (e.StackTrace);68 Log<PlacesItemSource>.Debug (e.StackTrace);
65 }69 }
70 try {
71 if (Directory.Exists (tmp_favicon_folder))
72 Directory.Delete (tmp_favicon_folder, true);
73 } catch (IOException e) {
74 Log<PlacesItemSource>.Error ("Could not delete temporary favicons folder: {0}", e.Message);
75 Log<PlacesItemSource>.Debug (e.StackTrace);
76 }
66 }77 }
6778
68 public override string Name {79 public override string Name {
@@ -275,9 +286,14 @@
275 dbcon.Open ();286 dbcon.Open ();
276 287
277 using (IDbCommand dbcmd = dbcon.CreateCommand ()) {288 using (IDbCommand dbcmd = dbcon.CreateCommand ()) {
278 dbcmd.CommandText = "SELECT moz_places.title, moz_places.url, moz_bookmarks.parent, moz_bookmarks.title "289 dbcmd.CommandText = "SELECT moz_places.title, moz_places.url, "
290 + "moz_bookmarks.parent, moz_bookmarks.title, "
291 + "moz_favicons.data, moz_favicons.id "
279 + "FROM moz_places LEFT OUTER JOIN moz_bookmarks "292 + "FROM moz_places LEFT OUTER JOIN moz_bookmarks "
280 + "ON moz_places.id=moz_bookmarks.fk "293 + "ON moz_places.id=moz_bookmarks.fk "
294 + "LEFT OUTER JOIN moz_favicons "
295 + "ON moz_places.favicon_id=moz_favicons.id "
296
281 + "ORDER BY moz_places.frecency DESC "297 + "ORDER BY moz_places.frecency DESC "
282 + "LIMIT 500";298 + "LIMIT 500";
283 299
@@ -285,20 +301,36 @@
285 while (reader.Read () ) { 301 while (reader.Read () ) {
286 string title = reader.GetString (0);302 string title = reader.GetString (0);
287 string url = reader.GetString (1);303 string url = reader.GetString (1);
288 304 string icon = "www";
305
289 // Firefox stores some interesting non-url places. Ignore them.306 // Firefox stores some interesting non-url places. Ignore them.
290 if (url [0] != 'p') {307 if (url [0] != 'p') {
308 // Check if the place has a stored favicon
309 if (!reader.IsDBNull(5) && !reader.IsDBNull(4)) {
310 string id = reader.GetString (5);
311 icon = Path.Combine (tmp_favicon_folder, id + ".png");
312
313 // Firefox reuses favicons, and so do we
314 if (!File.Exists(icon)) {
315 byte[] data = (byte[]) reader["data"];
316 Pixbuf pix = new Pixbuf (data);
317 Pixbuf dest = Gtk.IconTheme.Default.LoadIcon ("www", 80, 0);
318 pix.Composite (dest, 0, 0, pix.Width, pix.Height, 0, 0, 1, 1, InterpType.Bilinear , 200);
319 dest.Save (icon, "png");
320 }
321 }
322
291 // If the place is a bookmark, use the title stored in Bookmarks.323 // If the place is a bookmark, use the title stored in Bookmarks.
292 if (!reader.IsDBNull (2)) {324 if (!reader.IsDBNull (2)) {
293 int parent = reader.GetInt32 (2);325 int parent = reader.GetInt32 (2);
294 string bookmarkTitle = reader.GetString (3);326 string bookmarkTitle = reader.GetString (3);
295 327
296 yield return new PlaceItem (bookmarkTitle, url, parent);328 yield return new PlaceItem (bookmarkTitle, url, icon, parent);
297 } else if (string.IsNullOrEmpty (title)) {329 } else if (string.IsNullOrEmpty (title)) {
298 // If the place has no title, use the url as a title so it's searchable.330 // If the place has no title, use the url as a title so it's searchable.
299 yield return new PlaceItem (url, url);331 yield return new PlaceItem (url, url, icon);
300 } else {332 } else {
301 yield return new PlaceItem (title, url);333 yield return new PlaceItem (title, url, icon);
302 }334 }
303 }335 }
304 }336 }
@@ -309,4 +341,4 @@
309 }341 }
310 }342 }
311 }343 }
312}
313\ No newline at end of file344\ No newline at end of file
345}

Subscribers

People subscribed via source and target branches