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