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
1=== modified file 'Firefox/Makefile.am'
2--- Firefox/Makefile.am 2009-06-22 04:05:16 +0000
3+++ Firefox/Makefile.am 2009-11-30 09:33:10 +0000
4@@ -7,10 +7,16 @@
5 src/BrowseHistoryItem.cs \
6 src/FolderItem.cs \
7 src/PlaceItem.cs \
8- src/PlacesItemSource.cs
9+ src/PlacesItemSource.cs \
10+ src/FirefoxDB.cs \
11+ src/KeywordSearch.cs \
12+ src/IKeywordSearchItem.cs \
13+ src/KeywordSearchItem.cs
14
15 RESOURCES = \
16- Resources/Firefox.addin.xml
17+ Resources/Firefox.addin.xml \
18+ Resources/icons/firefox-search-icon.png \
19+ Resources/icons/search-icon.png
20
21 REFERENCES = \
22 System \
23
24=== modified file 'Firefox/Resources/Firefox.addin.xml.in'
25--- Firefox/Resources/Firefox.addin.xml.in 2009-06-26 15:47:18 +0000
26+++ Firefox/Resources/Firefox.addin.xml.in 2009-11-30 09:33:10 +0000
27@@ -1,10 +1,10 @@
28 <Addin
29 id="Firefox"
30 namespace="Do"
31- version="3.0"
32+ version="3.5"
33 name="Firefox"
34- description="Search Firefox 3 bookmarks, bookmark directories, and history."
35- author="David Siegel, Neal Stewart, Alex Launi"
36+ description="Search Firefox 3 bookmarks, history, and use Smart Keyword searches."
37+ author="David Siegel, Neal Stewart, Alex Launi, Joe Hillenbrand"
38 category="Official"
39 defaultEnabled="false"
40 url="http://do.davebsd.com/wiki/Firefox_Plugin"
41@@ -23,4 +23,8 @@
42 <Extension path="/Do/ItemSource">
43 <ItemSource type="Firefox.PlacesItemSource" />
44 </Extension>
45+
46+ <Extension path="/Do/Action">
47+ <Action type="Firefox.KeywordSearch"/>
48+ </Extension>
49 </Addin>
50
51=== added directory 'Firefox/Resources/icons'
52=== added file 'Firefox/Resources/icons/firefox-search-icon.png'
53Binary 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
54=== added file 'Firefox/Resources/icons/search-icon.png'
55Binary 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
56=== added file 'Firefox/src/FirefoxDB.cs'
57--- Firefox/src/FirefoxDB.cs 1970-01-01 00:00:00 +0000
58+++ Firefox/src/FirefoxDB.cs 2009-11-30 09:33:10 +0000
59@@ -0,0 +1,89 @@
60+// FirefoxDB.cs
61+//
62+// GNOME Do is the legal property of its developers. Please refer to the
63+// COPYRIGHT file distributed with this source distribution.
64+//
65+// This program is free software: you can redistribute it and/or modify
66+// it under the terms of the GNU General Public License as published by
67+// the Free Software Foundation, either version 3 of the License, or
68+// (at your option) any later version.
69+//
70+// This program is distributed in the hope that it will be useful,
71+// but WITHOUT ANY WARRANTY; without even the implied warranty of
72+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
73+// GNU General Public License for more details.
74+//
75+// You should have received a copy of the GNU General Public License
76+// along with this program. If not, see <http://www.gnu.org/licenses/>.
77+//
78+
79+using System;
80+using System.IO;
81+using System.Data;
82+using System.Linq;
83+using System.Collections.Generic;
84+
85+using Do.Platform;
86+using Do.Platform.Common;
87+using Do.Universe;
88+using Do.Universe.Common;
89+
90+using Mono.Addins;
91+using Mono.Data.SqliteClient;
92+
93+namespace Firefox
94+{
95+ /// <summary>
96+ /// This is a class of helper functions moved from PlacesItemSource
97+ /// so that they can be shared with FirefoxKeywordSearch
98+ /// </summary>
99+ public static class FirefoxDB
100+ {
101+ const string BeginProfileName = "Path=";
102+ const string BeginDefaultProfile = "Default=1";
103+
104+ public static bool IsFirefox (Item item)
105+ {
106+ return item.Equals (Do.Platform.Services.UniverseFactory.MaybeApplicationItemFromCommand ("firefox"));
107+ }
108+
109+ /// <summary>
110+ /// Looks in the firefox profiles file (~/.mozilla/firefox/profiles.ini)
111+ /// for the name of the default profile, and returns the path to the
112+ /// default profile.
113+ /// </summary>
114+ /// <returns>
115+ /// A <see cref="System.String"/> containing the absolute path to the
116+ /// bookmarks.html file of the default firefox profile for the current
117+ /// user.
118+ /// </returns>
119+ public static string FirefoxDBPath
120+ {
121+ get {
122+ string line, profile, home;
123+ string path = "";
124+ if (path == "") {
125+ profile = null;
126+ home = Environment.GetFolderPath (Environment.SpecialFolder.Personal);
127+
128+ path = Path.Combine (home, ".mozilla/firefox/profiles.ini");
129+ using (StreamReader r = File.OpenText (path)) {
130+ while ((line = r.ReadLine ()) != null) {
131+ if (line.StartsWith (BeginDefaultProfile)) {
132+ break;
133+ } else if (line.StartsWith (BeginProfileName)) {
134+ line = line.Trim ();
135+ line = line.Substring (BeginProfileName.Length);
136+ profile = line;
137+ }
138+ }
139+ }
140+ path = new [] {home, ".mozilla", "firefox", profile, "places.sqlite"}.Aggregate (Path.Combine);
141+ }
142+ return path;
143+ }
144+ }
145+
146+
147+ }
148+}
149
150=== added file 'Firefox/src/IKeywordSearchItem.cs'
151--- Firefox/src/IKeywordSearchItem.cs 1970-01-01 00:00:00 +0000
152+++ Firefox/src/IKeywordSearchItem.cs 2009-11-30 09:33:10 +0000
153@@ -0,0 +1,40 @@
154+// IKeywordSearchItem.cs
155+// by Joe Hillenbrand <joehillen@gmail.com>
156+//
157+// GNOME Do is the legal property of its developers, whose names are too numerous
158+// to list here. Please refer to the COPYRIGHT file distributed with this
159+// source distribution.
160+//
161+// This program is free software: you can redistribute it and/or modify
162+// it under the terms of the GNU General Public License as published by
163+// the Free Software Foundation, either version 3 of the License, or
164+// (at your option) any later version.
165+//
166+// This program is distributed in the hope that it will be useful,
167+// but WITHOUT ANY WARRANTY; without even the implied warranty of
168+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
169+// GNU General Public License for more details.
170+//
171+// You should have received a copy of the GNU General Public License
172+// along with this program. If not, see <http://www.gnu.org/licenses/>.
173+
174+using Do.Universe;
175+
176+namespace Firefox
177+{
178+ public interface IKeywordSearchItem : IItem
179+ {
180+ string Url { get; }
181+
182+ /// <summary>
183+ /// Build a search URL for this OpenSearch item using the provided search terms.
184+ /// </summary>
185+ /// <param name="searchTerms">
186+ /// The search terms to use in the URL template.
187+ /// </param>
188+ /// <returns>
189+ /// A formatted search URL, using the provided search terms.
190+ /// </returns>
191+ string BuildSearchUrl (string searchTerms);
192+ }
193+}
194
195=== added file 'Firefox/src/KeywordSearch.cs'
196--- Firefox/src/KeywordSearch.cs 1970-01-01 00:00:00 +0000
197+++ Firefox/src/KeywordSearch.cs 2009-11-30 09:33:10 +0000
198@@ -0,0 +1,149 @@
199+// KeywordSearch.cs
200+// by Joe Hillenbrand <joehillen@gmail.com>
201+//
202+// This is the Action for the FirefoxKeywordSearch plugin
203+//
204+// GNOME Do is the legal property of its developers. Please refer to the
205+// COPYRIGHT file distributed with this source distribution.
206+//
207+// This program is free software: you can redistribute it and/or modify
208+// it under the terms of the GNU General Public License as published by
209+// the Free Software Foundation, either version 3 of the License, or
210+// (at your option) any later version.
211+//
212+// This program is distributed in the hope that it will be useful,
213+// but WITHOUT ANY WARRANTY; without even the implied warranty of
214+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
215+// GNU General Public License for more details.
216+//
217+// You should have received a copy of the GNU General Public License
218+// along with this program. If not, see <http://www.gnu.org/licenses/>.
219+//
220+
221+using System;
222+using System.IO;
223+using System.Data;
224+using System.Linq;
225+using System.Collections.Generic;
226+
227+using Do.Platform;
228+using Do.Platform.Common;
229+using Do.Universe;
230+using Do.Universe.Common;
231+
232+using Mono.Addins;
233+using Mono.Data.SqliteClient;
234+
235+namespace Firefox {
236+
237+ public class KeywordSearch : Act {
238+
239+ public override string Name {
240+ get { return AddinManager.CurrentLocalizer.GetString ("Firefox Keyword Search"); }
241+ }
242+
243+ public override string Description {
244+ get { return AddinManager.CurrentLocalizer.GetString ("Search the Web using Firefox's Smart Keywords."); }
245+ }
246+
247+ public override string Icon {
248+ get { return "firefox-search-icon.png@" + GetType ().Assembly.FullName; }
249+ }
250+
251+ public override IEnumerable<Type> SupportedItemTypes {
252+ get { yield return typeof (ITextItem); }
253+ }
254+
255+ public override IEnumerable<Type> SupportedModifierItemTypes {
256+ get { yield return typeof (IKeywordSearchItem); }
257+ }
258+
259+ public override bool ModifierItemsOptional {
260+ get { return false; }
261+ }
262+
263+ public override IEnumerable<Item> DynamicModifierItemsForItem (Item item)
264+ {
265+ Log<Firefox>.Debug("Indexing Keyword Search items...");
266+ using (IDbConnection dbcon = (IDbConnection) new SqliteConnection (ConnectionString)) {
267+ dbcon.Open ();
268+
269+ using (IDbCommand dbcmd = dbcon.CreateCommand ()) {
270+ dbcmd.CommandText = "SELECT DISTINCT moz_keywords.keyword, moz_bookmarks.title, moz_places.url FROM moz_places "
271+ + "LEFT OUTER JOIN moz_bookmarks ON moz_places.id=moz_bookmarks.fk "
272+ + "JOIN moz_keywords ON moz_keywords.id=moz_bookmarks.keyword_id "
273+ + "WHERE moz_places.url LIKE '%\\%s%' ESCAPE '\\' ORDER BY moz_places.frecency DESC "
274+ + "LIMIT 500";
275+
276+ using (IDataReader reader = dbcmd.ExecuteReader ()) {
277+ while (reader.Read () ) {
278+ string keyword = (string)reader.GetValue (0);
279+ string title = (string)reader.GetValue (1);
280+ string url = (string)reader.GetValue (2);
281+
282+ // Firefox stores some interesting non-url places. Ignore them.
283+ if (url [0] != 'p') {
284+ if (string.IsNullOrEmpty (title)) {
285+ yield return new KeywordSearchItem (keyword, url, url);
286+ } else {
287+ yield return new KeywordSearchItem (keyword, title + " [" + url + "] " , url);
288+ }
289+ }
290+ }
291+ }
292+ }
293+ // this shouldn't be necessary, but: https://bugzilla.novell.com/show_bug.cgi?id=499864
294+ dbcon.Close ();
295+ }
296+ }
297+
298+ public override IEnumerable<Item> Perform (IEnumerable<Item> items, IEnumerable<Item> modItems)
299+ {
300+ foreach (Item i in items) {
301+ string query = (i as ITextItem).Text;
302+ foreach (Item modi in modItems)
303+ Services.Environment.OpenUrl ((modi as KeywordSearchItem).BuildSearchUrl (query));
304+ }
305+ yield break;
306+ }
307+
308+ /// <summary>
309+ /// Looks at the file currently saved in the temp folder and sees if it
310+ /// needs to be updated.
311+ /// </summary>
312+ /// <returns>
313+ /// The path of the current database file in memory.
314+ /// </returns>
315+ string stored_temp_db_path;
316+
317+ string TempDatabasePath {
318+ get {
319+ // Check if the stored temp file exists and if it doesn't, make one.
320+ if (string.IsNullOrEmpty (stored_temp_db_path) || !File.Exists (stored_temp_db_path)) {
321+ stored_temp_db_path = Path.GetTempFileName ();
322+ System.IO.File.Copy (FirefoxDB.FirefoxDBPath, stored_temp_db_path, true);
323+ } else if (File.Exists (stored_temp_db_path)) {
324+ FileInfo firefoxDBFileInfo = new FileInfo (FirefoxDB.FirefoxDBPath);
325+ FileInfo tempDBFileInfo = new FileInfo (stored_temp_db_path);
326+
327+ if (firefoxDBFileInfo.LastWriteTimeUtc > tempDBFileInfo.LastWriteTimeUtc)
328+ System.IO.File.Copy (FirefoxDB.FirefoxDBPath, stored_temp_db_path, true);
329+ }
330+ return stored_temp_db_path;
331+ }
332+ }
333+
334+ /// <summary>
335+ /// Creates the current SQL connection string to the temporary database in use.
336+ /// </summary>
337+ /// <returns>
338+ /// The current SQL connection string to the temporary database in use.
339+ /// </returns>
340+ string ConnectionString {
341+ get { return String.Format ("URI=file:{0},version=3", TempDatabasePath); }
342+ }
343+
344+
345+
346+ }
347+}
348
349=== added file 'Firefox/src/KeywordSearchItem.cs'
350--- Firefox/src/KeywordSearchItem.cs 1970-01-01 00:00:00 +0000
351+++ Firefox/src/KeywordSearchItem.cs 2009-11-30 09:33:10 +0000
352@@ -0,0 +1,63 @@
353+// KeywordSearchItem.cs
354+// by Joe Hillenbrand <joehillen@gmail.com>
355+//
356+// This is the Item for the FirefoxKeywordSearch plugin
357+//
358+// GNOME Do is the legal property of its developers, whose names are too numerous
359+// to list here. Please refer to the COPYRIGHT file distributed with this
360+// source distribution.
361+//
362+// This program is free software: you can redistribute it and/or modify
363+// it under the terms of the GNU General Public License as published by
364+// the Free Software Foundation, either version 3 of the License, or
365+// (at your option) any later version.
366+//
367+// This program is distributed in the hope that it will be useful,
368+// but WITHOUT ANY WARRANTY; without even the implied warranty of
369+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
370+// GNU General Public License for more details.
371+//
372+// You should have received a copy of the GNU General Public License
373+// along with this program. If not, see <http://www.gnu.org/licenses/>.
374+
375+using Do.Universe;
376+
377+namespace Firefox
378+{
379+ public class KeywordSearchItem : Item, IKeywordSearchItem
380+ {
381+ private string keyword, title, url;
382+
383+ public KeywordSearchItem (string keyword, string title, string url)
384+ {
385+ this.keyword = keyword;
386+ this.title = title;
387+ this.url = url;
388+ }
389+
390+ public override string Name
391+ {
392+ get { return keyword; }
393+ }
394+
395+ public override string Description
396+ {
397+ get { return "Search " + title; }
398+ }
399+
400+ public override string Icon
401+ {
402+ get { return "search-icon.png@" + GetType ().Assembly.FullName; }
403+ }
404+
405+ public string Url
406+ {
407+ get { return url; }
408+ }
409+
410+ public string BuildSearchUrl (string query)
411+ {
412+ return Url.Replace ("%s", query);
413+ }
414+ }
415+}
416
417=== modified file 'Firefox/src/PlaceItem.cs'
418--- Firefox/src/PlaceItem.cs 2009-06-22 04:05:16 +0000
419+++ Firefox/src/PlaceItem.cs 2009-11-30 09:33:10 +0000
420@@ -27,7 +27,6 @@
421
422 namespace Firefox
423 {
424-
425 public class PlaceItem : Item, IBookmarkItem
426 {
427 string title, url;
428
429=== modified file 'Firefox/src/PlacesItemSource.cs'
430--- Firefox/src/PlacesItemSource.cs 2009-09-05 02:06:59 +0000
431+++ Firefox/src/PlacesItemSource.cs 2009-11-30 09:33:10 +0000
432@@ -43,15 +43,11 @@
433 IEnumerable<PlaceItem> places;
434 IEnumerable<FolderItem> folders;
435
436- string stored_temp_db_path;
437-
438 public PlacesItemSource ()
439 {
440 items = new List<Item> ();
441 places = Enumerable.Empty<PlaceItem> ();
442 folders = Enumerable.Empty<FolderItem> ();
443-
444- ProfilePath = FindProfilePath ();
445 }
446
447 ~PlacesItemSource ()
448@@ -94,7 +90,7 @@
449
450 public override IEnumerable<Item> ChildrenOfItem (Item item)
451 {
452- if (IsFirefox (item)) {
453+ if (FirefoxDB.IsFirefox (item)) {
454 yield return new BrowseHistoryItem ();
455 yield return new BrowseBookmarkItem ();
456 } else if (item is BrowseBookmarkItem || item is BrowseHistoryItem) {
457@@ -137,52 +133,6 @@
458 get { return places.Where (place => place.ParentId.HasValue); }
459 }
460
461- bool IsFirefox (Item item)
462- {
463- return item.Equals (Do.Platform.Services.UniverseFactory.MaybeApplicationItemFromCommand ("firefox"));
464- }
465-
466- /// <summary>
467- /// Looks in the firefox profiles file (~/.mozilla/firefox/profiles.ini)
468- /// for the name of the default profile, and returns the path to the
469- /// default profile.
470- /// </summary>
471- /// <returns>
472- /// A <see cref="System.String"/> containing the absolute path to the
473- /// bookmarks.html file of the default firefox profile for the current
474- /// user.
475- /// </returns>
476- string ProfilePath { get; set; }
477-
478- string FindProfilePath ()
479- {
480- string line, profile, path, home;
481-
482- profile = null;
483- home = Environment.GetFolderPath (Environment.SpecialFolder.Personal);
484-
485- path = Path.Combine (home, ".mozilla/firefox/profiles.ini");
486- using (StreamReader r = File.OpenText (path)) {
487- while ((line = r.ReadLine ()) != null) {
488- if (line.StartsWith (BeginDefaultProfile)) {
489- break;
490- } else if (line.StartsWith (BeginProfileName)) {
491- line = line.Trim ();
492- line = line.Substring (BeginProfileName.Length);
493- profile = line;
494- }
495- }
496- }
497- return new [] {home, ".mozilla", "firefox", profile}.Aggregate (Path.Combine);
498- }
499-
500-
501- string FirefoxDBPath {
502- get {
503- return Path.Combine (ProfilePath, "places.sqlite");
504- }
505- }
506-
507 /// <summary>
508 /// Looks at the file currently saved in the temp folder and sees if it
509 /// needs to be updated.
510@@ -190,18 +140,20 @@
511 /// <returns>
512 /// The path of the current database file in memory.
513 /// </returns>
514+ string stored_temp_db_path;
515+
516 string TempDatabasePath {
517 get {
518 // Check if the stored temp file exists and if it doesn't, make one.
519 if (string.IsNullOrEmpty (stored_temp_db_path) || !File.Exists (stored_temp_db_path)) {
520 stored_temp_db_path = Path.GetTempFileName ();
521- System.IO.File.Copy (FirefoxDBPath, stored_temp_db_path, true);
522+ System.IO.File.Copy (FirefoxDB.FirefoxDBPath, stored_temp_db_path, true);
523 } else if (File.Exists (stored_temp_db_path)) {
524- FileInfo firefoxDBFileInfo = new FileInfo (FirefoxDBPath);
525+ FileInfo firefoxDBFileInfo = new FileInfo (FirefoxDB.FirefoxDBPath);
526 FileInfo tempDBFileInfo = new FileInfo (stored_temp_db_path);
527
528 if (firefoxDBFileInfo.LastWriteTimeUtc > tempDBFileInfo.LastWriteTimeUtc)
529- System.IO.File.Copy (FirefoxDBPath, stored_temp_db_path, true);
530+ System.IO.File.Copy (FirefoxDB.FirefoxDBPath, stored_temp_db_path, true);
531 }
532 return stored_temp_db_path;
533 }
534@@ -309,4 +261,4 @@
535 }
536 }
537 }
538-}
539\ No newline at end of file
540+}

Subscribers

People subscribed via source and target branches