Merge lp:~joehillen/do-plugins/FirefoxKeywordSearch into lp:do-plugins

Proposed by JoE
Status: Needs review
Proposed branch: lp:~joehillen/do-plugins/FirefoxKeywordSearch
Merge into: lp:do-plugins
Diff against target: 540 lines (+363/-61)
8 files modified
Firefox/Makefile.am (+8/-2)
Firefox/Resources/Firefox.addin.xml.in (+7/-3)
Firefox/src/FirefoxDB.cs (+89/-0)
Firefox/src/IKeywordSearchItem.cs (+40/-0)
Firefox/src/KeywordSearch.cs (+149/-0)
Firefox/src/KeywordSearchItem.cs (+63/-0)
Firefox/src/PlaceItem.cs (+0/-1)
Firefox/src/PlacesItemSource.cs (+7/-55)
To merge this branch: bzr merge lp:~joehillen/do-plugins/FirefoxKeywordSearch
Reviewer Review Type Date Requested Status
Do Plugins Team Pending
Review via email: mp+15353@code.launchpad.net
To post a comment you must log in.
Revision history for this message
JoE (joehillen) wrote :

Integrated Smart Keyword Search action into Firefox plugin.

An outline of the feature is here:
http://do.davebsd.com/wiki/index.php?title=FirefoxKeywordSearch_Plugin
I will integrate this description into the "Firefox Plugin" page, once this is merged.

The mailing list discussion of this plugin is here:
http://groups.google.com/group/gnome-do/browse_thread/thread/effb0a87336aa8f?hl=en

676. By JoE

Minor fixes to Firefox plugin

Unmerged revisions

676. By JoE

Minor fixes to Firefox plugin

675. By JoE

Add Keyword Search feature to Firefox Plugin

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'Firefox/Makefile.am'
--- Firefox/Makefile.am 2009-06-22 04:05:16 +0000
+++ Firefox/Makefile.am 2009-11-30 09:33:10 +0000
@@ -7,10 +7,16 @@
7 src/BrowseHistoryItem.cs \7 src/BrowseHistoryItem.cs \
8 src/FolderItem.cs \8 src/FolderItem.cs \
9 src/PlaceItem.cs \9 src/PlaceItem.cs \
10 src/PlacesItemSource.cs10 src/PlacesItemSource.cs \
11 src/FirefoxDB.cs \
12 src/KeywordSearch.cs \
13 src/IKeywordSearchItem.cs \
14 src/KeywordSearchItem.cs
1115
12RESOURCES = \16RESOURCES = \
13 Resources/Firefox.addin.xml17 Resources/Firefox.addin.xml \
18 Resources/icons/firefox-search-icon.png \
19 Resources/icons/search-icon.png
1420
15REFERENCES = \21REFERENCES = \
16 System \22 System \
1723
=== modified file 'Firefox/Resources/Firefox.addin.xml.in'
--- Firefox/Resources/Firefox.addin.xml.in 2009-06-26 15:47:18 +0000
+++ Firefox/Resources/Firefox.addin.xml.in 2009-11-30 09:33:10 +0000
@@ -1,10 +1,10 @@
1<Addin1<Addin
2 id="Firefox"2 id="Firefox"
3 namespace="Do"3 namespace="Do"
4 version="3.0"4 version="3.5"
5 name="Firefox"5 name="Firefox"
6 description="Search Firefox 3 bookmarks, bookmark directories, and history."6 description="Search Firefox 3 bookmarks, history, and use Smart Keyword searches."
7 author="David Siegel, Neal Stewart, Alex Launi"7 author="David Siegel, Neal Stewart, Alex Launi, Joe Hillenbrand"
8 category="Official"8 category="Official"
9 defaultEnabled="false"9 defaultEnabled="false"
10 url="http://do.davebsd.com/wiki/Firefox_Plugin"10 url="http://do.davebsd.com/wiki/Firefox_Plugin"
@@ -23,4 +23,8 @@
23 <Extension path="/Do/ItemSource">23 <Extension path="/Do/ItemSource">
24 <ItemSource type="Firefox.PlacesItemSource" />24 <ItemSource type="Firefox.PlacesItemSource" />
25 </Extension>25 </Extension>
26
27 <Extension path="/Do/Action">
28 <Action type="Firefox.KeywordSearch"/>
29 </Extension>
26</Addin>30</Addin>
2731
=== added directory 'Firefox/Resources/icons'
=== added file 'Firefox/Resources/icons/firefox-search-icon.png'
28Binary files Firefox/Resources/icons/firefox-search-icon.png 1970-01-01 00:00:00 +0000 and Firefox/Resources/icons/firefox-search-icon.png 2009-11-30 09:33:10 +0000 differ32Binary files Firefox/Resources/icons/firefox-search-icon.png 1970-01-01 00:00:00 +0000 and Firefox/Resources/icons/firefox-search-icon.png 2009-11-30 09:33:10 +0000 differ
=== added file 'Firefox/Resources/icons/search-icon.png'
29Binary files Firefox/Resources/icons/search-icon.png 1970-01-01 00:00:00 +0000 and Firefox/Resources/icons/search-icon.png 2009-11-30 09:33:10 +0000 differ33Binary files Firefox/Resources/icons/search-icon.png 1970-01-01 00:00:00 +0000 and Firefox/Resources/icons/search-icon.png 2009-11-30 09:33:10 +0000 differ
=== added file 'Firefox/src/FirefoxDB.cs'
--- Firefox/src/FirefoxDB.cs 1970-01-01 00:00:00 +0000
+++ Firefox/src/FirefoxDB.cs 2009-11-30 09:33:10 +0000
@@ -0,0 +1,89 @@
1// FirefoxDB.cs
2//
3// GNOME Do is the legal property of its developers. Please refer to the
4// COPYRIGHT file distributed with this source distribution.
5//
6// This program is free software: you can redistribute it and/or modify
7// it under the terms of the GNU General Public License as published by
8// the Free Software Foundation, either version 3 of the License, or
9// (at your option) any later version.
10//
11// This program is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15//
16// You should have received a copy of the GNU General Public License
17// along with this program. If not, see <http://www.gnu.org/licenses/>.
18//
19
20using System;
21using System.IO;
22using System.Data;
23using System.Linq;
24using System.Collections.Generic;
25
26using Do.Platform;
27using Do.Platform.Common;
28using Do.Universe;
29using Do.Universe.Common;
30
31using Mono.Addins;
32using Mono.Data.SqliteClient;
33
34namespace Firefox
35{
36 /// <summary>
37 /// This is a class of helper functions moved from PlacesItemSource
38 /// so that they can be shared with FirefoxKeywordSearch
39 /// </summary>
40 public static class FirefoxDB
41 {
42 const string BeginProfileName = "Path=";
43 const string BeginDefaultProfile = "Default=1";
44
45 public static bool IsFirefox (Item item)
46 {
47 return item.Equals (Do.Platform.Services.UniverseFactory.MaybeApplicationItemFromCommand ("firefox"));
48 }
49
50 /// <summary>
51 /// Looks in the firefox profiles file (~/.mozilla/firefox/profiles.ini)
52 /// for the name of the default profile, and returns the path to the
53 /// default profile.
54 /// </summary>
55 /// <returns>
56 /// A <see cref="System.String"/> containing the absolute path to the
57 /// bookmarks.html file of the default firefox profile for the current
58 /// user.
59 /// </returns>
60 public static string FirefoxDBPath
61 {
62 get {
63 string line, profile, home;
64 string path = "";
65 if (path == "") {
66 profile = null;
67 home = Environment.GetFolderPath (Environment.SpecialFolder.Personal);
68
69 path = Path.Combine (home, ".mozilla/firefox/profiles.ini");
70 using (StreamReader r = File.OpenText (path)) {
71 while ((line = r.ReadLine ()) != null) {
72 if (line.StartsWith (BeginDefaultProfile)) {
73 break;
74 } else if (line.StartsWith (BeginProfileName)) {
75 line = line.Trim ();
76 line = line.Substring (BeginProfileName.Length);
77 profile = line;
78 }
79 }
80 }
81 path = new [] {home, ".mozilla", "firefox", profile, "places.sqlite"}.Aggregate (Path.Combine);
82 }
83 return path;
84 }
85 }
86
87
88 }
89}
090
=== added file 'Firefox/src/IKeywordSearchItem.cs'
--- Firefox/src/IKeywordSearchItem.cs 1970-01-01 00:00:00 +0000
+++ Firefox/src/IKeywordSearchItem.cs 2009-11-30 09:33:10 +0000
@@ -0,0 +1,40 @@
1// IKeywordSearchItem.cs
2// by Joe Hillenbrand <joehillen@gmail.com>
3//
4// GNOME Do is the legal property of its developers, whose names are too numerous
5// to list here. Please refer to the COPYRIGHT file distributed with this
6// source distribution.
7//
8// This program is free software: you can redistribute it and/or modify
9// it under the terms of the GNU General Public License as published by
10// the Free Software Foundation, either version 3 of the License, or
11// (at your option) any later version.
12//
13// This program is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16// GNU General Public License for more details.
17//
18// You should have received a copy of the GNU General Public License
19// along with this program. If not, see <http://www.gnu.org/licenses/>.
20
21using Do.Universe;
22
23namespace Firefox
24{
25 public interface IKeywordSearchItem : IItem
26 {
27 string Url { get; }
28
29 /// <summary>
30 /// Build a search URL for this OpenSearch item using the provided search terms.
31 /// </summary>
32 /// <param name="searchTerms">
33 /// The search terms to use in the URL template.
34 /// </param>
35 /// <returns>
36 /// A formatted search URL, using the provided search terms.
37 /// </returns>
38 string BuildSearchUrl (string searchTerms);
39 }
40}
041
=== added file 'Firefox/src/KeywordSearch.cs'
--- Firefox/src/KeywordSearch.cs 1970-01-01 00:00:00 +0000
+++ Firefox/src/KeywordSearch.cs 2009-11-30 09:33:10 +0000
@@ -0,0 +1,149 @@
1// KeywordSearch.cs
2// by Joe Hillenbrand <joehillen@gmail.com>
3//
4// This is the Action for the FirefoxKeywordSearch plugin
5//
6// GNOME Do is the legal property of its developers. Please refer to the
7// COPYRIGHT file distributed with this source distribution.
8//
9// This program is free software: you can redistribute it and/or modify
10// it under the terms of the GNU General Public License as published by
11// the Free Software Foundation, either version 3 of the License, or
12// (at your option) any later version.
13//
14// This program is distributed in the hope that it will be useful,
15// but WITHOUT ANY WARRANTY; without even the implied warranty of
16// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17// GNU General Public License for more details.
18//
19// You should have received a copy of the GNU General Public License
20// along with this program. If not, see <http://www.gnu.org/licenses/>.
21//
22
23using System;
24using System.IO;
25using System.Data;
26using System.Linq;
27using System.Collections.Generic;
28
29using Do.Platform;
30using Do.Platform.Common;
31using Do.Universe;
32using Do.Universe.Common;
33
34using Mono.Addins;
35using Mono.Data.SqliteClient;
36
37namespace Firefox {
38
39 public class KeywordSearch : Act {
40
41 public override string Name {
42 get { return AddinManager.CurrentLocalizer.GetString ("Firefox Keyword Search"); }
43 }
44
45 public override string Description {
46 get { return AddinManager.CurrentLocalizer.GetString ("Search the Web using Firefox's Smart Keywords."); }
47 }
48
49 public override string Icon {
50 get { return "firefox-search-icon.png@" + GetType ().Assembly.FullName; }
51 }
52
53 public override IEnumerable<Type> SupportedItemTypes {
54 get { yield return typeof (ITextItem); }
55 }
56
57 public override IEnumerable<Type> SupportedModifierItemTypes {
58 get { yield return typeof (IKeywordSearchItem); }
59 }
60
61 public override bool ModifierItemsOptional {
62 get { return false; }
63 }
64
65 public override IEnumerable<Item> DynamicModifierItemsForItem (Item item)
66 {
67 Log<Firefox>.Debug("Indexing Keyword Search items...");
68 using (IDbConnection dbcon = (IDbConnection) new SqliteConnection (ConnectionString)) {
69 dbcon.Open ();
70
71 using (IDbCommand dbcmd = dbcon.CreateCommand ()) {
72 dbcmd.CommandText = "SELECT DISTINCT moz_keywords.keyword, moz_bookmarks.title, moz_places.url FROM moz_places "
73 + "LEFT OUTER JOIN moz_bookmarks ON moz_places.id=moz_bookmarks.fk "
74 + "JOIN moz_keywords ON moz_keywords.id=moz_bookmarks.keyword_id "
75 + "WHERE moz_places.url LIKE '%\\%s%' ESCAPE '\\' ORDER BY moz_places.frecency DESC "
76 + "LIMIT 500";
77
78 using (IDataReader reader = dbcmd.ExecuteReader ()) {
79 while (reader.Read () ) {
80 string keyword = (string)reader.GetValue (0);
81 string title = (string)reader.GetValue (1);
82 string url = (string)reader.GetValue (2);
83
84 // Firefox stores some interesting non-url places. Ignore them.
85 if (url [0] != 'p') {
86 if (string.IsNullOrEmpty (title)) {
87 yield return new KeywordSearchItem (keyword, url, url);
88 } else {
89 yield return new KeywordSearchItem (keyword, title + " [" + url + "] " , url);
90 }
91 }
92 }
93 }
94 }
95 // this shouldn't be necessary, but: https://bugzilla.novell.com/show_bug.cgi?id=499864
96 dbcon.Close ();
97 }
98 }
99
100 public override IEnumerable<Item> Perform (IEnumerable<Item> items, IEnumerable<Item> modItems)
101 {
102 foreach (Item i in items) {
103 string query = (i as ITextItem).Text;
104 foreach (Item modi in modItems)
105 Services.Environment.OpenUrl ((modi as KeywordSearchItem).BuildSearchUrl (query));
106 }
107 yield break;
108 }
109
110 /// <summary>
111 /// Looks at the file currently saved in the temp folder and sees if it
112 /// needs to be updated.
113 /// </summary>
114 /// <returns>
115 /// The path of the current database file in memory.
116 /// </returns>
117 string stored_temp_db_path;
118
119 string TempDatabasePath {
120 get {
121 // Check if the stored temp file exists and if it doesn't, make one.
122 if (string.IsNullOrEmpty (stored_temp_db_path) || !File.Exists (stored_temp_db_path)) {
123 stored_temp_db_path = Path.GetTempFileName ();
124 System.IO.File.Copy (FirefoxDB.FirefoxDBPath, stored_temp_db_path, true);
125 } else if (File.Exists (stored_temp_db_path)) {
126 FileInfo firefoxDBFileInfo = new FileInfo (FirefoxDB.FirefoxDBPath);
127 FileInfo tempDBFileInfo = new FileInfo (stored_temp_db_path);
128
129 if (firefoxDBFileInfo.LastWriteTimeUtc > tempDBFileInfo.LastWriteTimeUtc)
130 System.IO.File.Copy (FirefoxDB.FirefoxDBPath, stored_temp_db_path, true);
131 }
132 return stored_temp_db_path;
133 }
134 }
135
136 /// <summary>
137 /// Creates the current SQL connection string to the temporary database in use.
138 /// </summary>
139 /// <returns>
140 /// The current SQL connection string to the temporary database in use.
141 /// </returns>
142 string ConnectionString {
143 get { return String.Format ("URI=file:{0},version=3", TempDatabasePath); }
144 }
145
146
147
148 }
149}
0150
=== added file 'Firefox/src/KeywordSearchItem.cs'
--- Firefox/src/KeywordSearchItem.cs 1970-01-01 00:00:00 +0000
+++ Firefox/src/KeywordSearchItem.cs 2009-11-30 09:33:10 +0000
@@ -0,0 +1,63 @@
1// KeywordSearchItem.cs
2// by Joe Hillenbrand <joehillen@gmail.com>
3//
4// This is the Item for the FirefoxKeywordSearch plugin
5//
6// GNOME Do is the legal property of its developers, whose names are too numerous
7// to list here. Please refer to the COPYRIGHT file distributed with this
8// source distribution.
9//
10// This program is free software: you can redistribute it and/or modify
11// it under the terms of the GNU General Public License as published by
12// the Free Software Foundation, either version 3 of the License, or
13// (at your option) any later version.
14//
15// This program is distributed in the hope that it will be useful,
16// but WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18// GNU General Public License for more details.
19//
20// You should have received a copy of the GNU General Public License
21// along with this program. If not, see <http://www.gnu.org/licenses/>.
22
23using Do.Universe;
24
25namespace Firefox
26{
27 public class KeywordSearchItem : Item, IKeywordSearchItem
28 {
29 private string keyword, title, url;
30
31 public KeywordSearchItem (string keyword, string title, string url)
32 {
33 this.keyword = keyword;
34 this.title = title;
35 this.url = url;
36 }
37
38 public override string Name
39 {
40 get { return keyword; }
41 }
42
43 public override string Description
44 {
45 get { return "Search " + title; }
46 }
47
48 public override string Icon
49 {
50 get { return "search-icon.png@" + GetType ().Assembly.FullName; }
51 }
52
53 public string Url
54 {
55 get { return url; }
56 }
57
58 public string BuildSearchUrl (string query)
59 {
60 return Url.Replace ("%s", query);
61 }
62 }
63}
064
=== modified file 'Firefox/src/PlaceItem.cs'
--- Firefox/src/PlaceItem.cs 2009-06-22 04:05:16 +0000
+++ Firefox/src/PlaceItem.cs 2009-11-30 09:33:10 +0000
@@ -27,7 +27,6 @@
2727
28namespace Firefox28namespace Firefox
29{29{
30
31 public class PlaceItem : Item, IBookmarkItem30 public class PlaceItem : Item, IBookmarkItem
32 {31 {
33 string title, url;32 string title, url;
3433
=== modified file 'Firefox/src/PlacesItemSource.cs'
--- Firefox/src/PlacesItemSource.cs 2009-09-05 02:06:59 +0000
+++ Firefox/src/PlacesItemSource.cs 2009-11-30 09:33:10 +0000
@@ -43,15 +43,11 @@
43 IEnumerable<PlaceItem> places;43 IEnumerable<PlaceItem> places;
44 IEnumerable<FolderItem> folders;44 IEnumerable<FolderItem> folders;
45 45
46 string stored_temp_db_path;
47
48 public PlacesItemSource ()46 public PlacesItemSource ()
49 {47 {
50 items = new List<Item> ();48 items = new List<Item> ();
51 places = Enumerable.Empty<PlaceItem> (); 49 places = Enumerable.Empty<PlaceItem> ();
52 folders = Enumerable.Empty<FolderItem> ();50 folders = Enumerable.Empty<FolderItem> ();
53
54 ProfilePath = FindProfilePath ();
55 }51 }
5652
57 ~PlacesItemSource ()53 ~PlacesItemSource ()
@@ -94,7 +90,7 @@
9490
95 public override IEnumerable<Item> ChildrenOfItem (Item item) 91 public override IEnumerable<Item> ChildrenOfItem (Item item)
96 {92 {
97 if (IsFirefox (item)) {93 if (FirefoxDB.IsFirefox (item)) {
98 yield return new BrowseHistoryItem ();94 yield return new BrowseHistoryItem ();
99 yield return new BrowseBookmarkItem ();95 yield return new BrowseBookmarkItem ();
100 } else if (item is BrowseBookmarkItem || item is BrowseHistoryItem) {96 } else if (item is BrowseBookmarkItem || item is BrowseHistoryItem) {
@@ -137,52 +133,6 @@
137 get { return places.Where (place => place.ParentId.HasValue); }133 get { return places.Where (place => place.ParentId.HasValue); }
138 }134 }
139 135
140 bool IsFirefox (Item item)
141 {
142 return item.Equals (Do.Platform.Services.UniverseFactory.MaybeApplicationItemFromCommand ("firefox"));
143 }
144
145 /// <summary>
146 /// Looks in the firefox profiles file (~/.mozilla/firefox/profiles.ini)
147 /// for the name of the default profile, and returns the path to the
148 /// default profile.
149 /// </summary>
150 /// <returns>
151 /// A <see cref="System.String"/> containing the absolute path to the
152 /// bookmarks.html file of the default firefox profile for the current
153 /// user.
154 /// </returns>
155 string ProfilePath { get; set; }
156
157 string FindProfilePath ()
158 {
159 string line, profile, path, home;
160
161 profile = null;
162 home = Environment.GetFolderPath (Environment.SpecialFolder.Personal);
163
164 path = Path.Combine (home, ".mozilla/firefox/profiles.ini");
165 using (StreamReader r = File.OpenText (path)) {
166 while ((line = r.ReadLine ()) != null) {
167 if (line.StartsWith (BeginDefaultProfile)) {
168 break;
169 } else if (line.StartsWith (BeginProfileName)) {
170 line = line.Trim ();
171 line = line.Substring (BeginProfileName.Length);
172 profile = line;
173 }
174 }
175 }
176 return new [] {home, ".mozilla", "firefox", profile}.Aggregate (Path.Combine);
177 }
178
179
180 string FirefoxDBPath {
181 get {
182 return Path.Combine (ProfilePath, "places.sqlite");
183 }
184 }
185
186 /// <summary>136 /// <summary>
187 /// Looks at the file currently saved in the temp folder and sees if it137 /// Looks at the file currently saved in the temp folder and sees if it
188 /// needs to be updated.138 /// needs to be updated.
@@ -190,18 +140,20 @@
190 /// <returns>140 /// <returns>
191 /// The path of the current database file in memory.141 /// The path of the current database file in memory.
192 /// </returns>142 /// </returns>
143 string stored_temp_db_path;
144
193 string TempDatabasePath {145 string TempDatabasePath {
194 get { 146 get {
195 // Check if the stored temp file exists and if it doesn't, make one.147 // Check if the stored temp file exists and if it doesn't, make one.
196 if (string.IsNullOrEmpty (stored_temp_db_path) || !File.Exists (stored_temp_db_path)) {148 if (string.IsNullOrEmpty (stored_temp_db_path) || !File.Exists (stored_temp_db_path)) {
197 stored_temp_db_path = Path.GetTempFileName ();149 stored_temp_db_path = Path.GetTempFileName ();
198 System.IO.File.Copy (FirefoxDBPath, stored_temp_db_path, true);150 System.IO.File.Copy (FirefoxDB.FirefoxDBPath, stored_temp_db_path, true);
199 } else if (File.Exists (stored_temp_db_path)) {151 } else if (File.Exists (stored_temp_db_path)) {
200 FileInfo firefoxDBFileInfo = new FileInfo (FirefoxDBPath);152 FileInfo firefoxDBFileInfo = new FileInfo (FirefoxDB.FirefoxDBPath);
201 FileInfo tempDBFileInfo = new FileInfo (stored_temp_db_path);153 FileInfo tempDBFileInfo = new FileInfo (stored_temp_db_path);
202 154
203 if (firefoxDBFileInfo.LastWriteTimeUtc > tempDBFileInfo.LastWriteTimeUtc)155 if (firefoxDBFileInfo.LastWriteTimeUtc > tempDBFileInfo.LastWriteTimeUtc)
204 System.IO.File.Copy (FirefoxDBPath, stored_temp_db_path, true);156 System.IO.File.Copy (FirefoxDB.FirefoxDBPath, stored_temp_db_path, true);
205 }157 }
206 return stored_temp_db_path;158 return stored_temp_db_path;
207 }159 }
@@ -309,4 +261,4 @@
309 }261 }
310 }262 }
311 }263 }
312}
313\ No newline at end of file264\ No newline at end of file
265}

Subscribers

People subscribed via source and target branches