Merge lp:~urbanape/bindwood/xpi-refinement into lp:~urbanape/bindwood/trunk
- xpi-refinement
- Merge into trunk
Proposed by
Zachery Bir
Status: | Merged |
---|---|
Approved by: | Rick McBride |
Approved revision: | 18 |
Merge reported by: | Zachery Bir |
Merged at revision: | not available |
Proposed branch: | lp:~urbanape/bindwood/xpi-refinement |
Merge into: | lp:~urbanape/bindwood/trunk |
Diff against target: | None lines |
To merge this branch: | bzr merge lp:~urbanape/bindwood/xpi-refinement |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Rick McBride (community) | Approve | ||
Elliot Murphy (community) | Approve | ||
Review via email: mp+8775@code.launchpad.net |
Commit message
Description of the change
To post a comment you must log in.
Revision history for this message
Zachery Bir (urbanape) wrote : | # |
Revision history for this message
Elliot Murphy (statik) wrote : | # |
this looks ready to merge to trunk.
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === added file '.bzrignore' |
2 | --- .bzrignore 1970-01-01 00:00:00 +0000 |
3 | +++ .bzrignore 2009-07-14 14:09:22 +0000 |
4 | @@ -0,0 +1,1 @@ |
5 | +bindwood.xpi |
6 | |
7 | === added file 'README' |
8 | --- README 1970-01-01 00:00:00 +0000 |
9 | +++ README 2009-07-14 14:09:22 +0000 |
10 | @@ -0,0 +1,7 @@ |
11 | +This is a Firefox extension that syncs bookmarks with a desktop CouchDB instance. |
12 | +To build it, run ./build.sh. |
13 | + |
14 | +The project home page is https://launchpad.net/bindwood. |
15 | +To submit patches, please make a branch on launchpad and 'propose for merging'. |
16 | +You can discuss this extension on the ubuntuone-users@lists.launchpad.net |
17 | +mailing list. |
18 | |
19 | === added file 'build.sh' |
20 | --- build.sh 1970-01-01 00:00:00 +0000 |
21 | +++ build.sh 2009-07-14 14:09:22 +0000 |
22 | @@ -0,0 +1,128 @@ |
23 | +#!/bin/bash |
24 | +# build.sh -- builds JAR and XPI files for mozilla extensions |
25 | +# by Nickolay Ponomarev <asqueella@gmail.com> |
26 | +# (original version based on Nathan Yergler's build script) |
27 | +# Most recent version is at <http://kb.mozillazine.org/Bash_build_script> |
28 | + |
29 | +# This script assumes the following directory structure: |
30 | +# ./ |
31 | +# chrome.manifest (optional - for newer extensions) |
32 | +# install.rdf |
33 | +# (other files listed in $ROOT_FILES) |
34 | +# |
35 | +# content/ | |
36 | +# locale/ |} these can be named arbitrary and listed in $CHROME_PROVIDERS |
37 | +# skin/ | |
38 | +# |
39 | +# defaults/ | |
40 | +# components/ |} these must be listed in $ROOT_DIRS in order to be packaged |
41 | +# ... | |
42 | +# |
43 | +# It uses a temporary directory ./build when building; don't use that! |
44 | +# Script's output is: |
45 | +# ./$APP_NAME.xpi |
46 | +# ./$APP_NAME.jar (only if $KEEP_JAR=1) |
47 | +# ./files -- the list of packaged files |
48 | +# |
49 | +# Note: It modifies chrome.manifest when packaging so that it points to |
50 | +# chrome/$APP_NAME.jar!/* |
51 | + |
52 | +# |
53 | +# default configuration file is ./config_build.sh, unless another file is |
54 | +# specified in command-line. Available config variables: |
55 | +APP_NAME= # short-name, jar and xpi files name. Must be lowercase with no spaces |
56 | +CHROME_PROVIDERS= # which chrome providers we have (space-separated list) |
57 | +CLEAN_UP= # delete the jar / "files" when done? (1/0) |
58 | +ROOT_FILES= # put these files in root of xpi (space separated list of leaf filenames) |
59 | +ROOT_DIRS= # ...and these directories (space separated list) |
60 | +BEFORE_BUILD= # run this before building (bash command) |
61 | +AFTER_BUILD= # ...and this after the build (bash command) |
62 | + |
63 | +if [ -z $1 ]; then |
64 | + . ./config_build.sh |
65 | +else |
66 | + . $1 |
67 | +fi |
68 | + |
69 | +if [ -z $APP_NAME ]; then |
70 | + echo "You need to create build config file first!" |
71 | + echo "Read comments at the beginning of this script for more info." |
72 | + exit; |
73 | +fi |
74 | + |
75 | +ROOT_DIR=`pwd` |
76 | +TMP_DIR=build |
77 | + |
78 | +#uncomment to debug |
79 | +#set -x |
80 | + |
81 | +# remove any left-over files from previous build |
82 | +rm -f $APP_NAME.jar $APP_NAME.xpi files |
83 | +rm -rf $TMP_DIR |
84 | + |
85 | +$BEFORE_BUILD |
86 | + |
87 | +mkdir --parents --verbose $TMP_DIR/chrome |
88 | + |
89 | +# generate the JAR file, excluding CVS and temporary files |
90 | +JAR_FILE=$TMP_DIR/chrome/$APP_NAME.jar |
91 | +echo "Generating $JAR_FILE..." |
92 | +for CHROME_SUBDIR in $CHROME_PROVIDERS; do |
93 | + find $CHROME_SUBDIR -path '*CVS*' -prune -o -type f -print | grep -v \~ >> files |
94 | +done |
95 | + |
96 | +zip -0 -r $JAR_FILE `cat files` |
97 | +# The following statement should be used instead if you don't wish to use the JAR file |
98 | +#cp --verbose --parents `cat files` $TMP_DIR/chrome |
99 | + |
100 | +# prepare components and defaults |
101 | +echo "Copying various files to $TMP_DIR folder..." |
102 | +for DIR in $ROOT_DIRS; do |
103 | + mkdir $TMP_DIR/$DIR |
104 | + FILES="`find $DIR -path '*CVS*' -prune -o -type f -print | grep -v \~`" |
105 | + echo $FILES >> files |
106 | + cp --verbose --parents $FILES $TMP_DIR |
107 | +done |
108 | + |
109 | +# Copy other files to the root of future XPI. |
110 | +for ROOT_FILE in $ROOT_FILES install.rdf chrome.manifest; do |
111 | + cp --verbose $ROOT_FILE $TMP_DIR |
112 | + if [ -f $ROOT_FILE ]; then |
113 | + echo $ROOT_FILE >> files |
114 | + fi |
115 | +done |
116 | + |
117 | +cd $TMP_DIR |
118 | + |
119 | +if [ -f "chrome.manifest" ]; then |
120 | + echo "Preprocessing chrome.manifest..." |
121 | + # You think this is scary? |
122 | + #s/^(content\s+\S*\s+)(\S*\/)$/\1jar:chrome\/$APP_NAME\.jar!\/\2/ |
123 | + #s/^(skin|locale)(\s+\S*\s+\S*\s+)(.*\/)$/\1\2jar:chrome\/$APP_NAME\.jar!\/\3/ |
124 | + # |
125 | + # Then try this! (Same, but with characters escaped for bash :) |
126 | + sed -i -r s/^\(content\\s+\\S*\\s+\)\(\\S*\\/\)$/\\1jar:chrome\\/$APP_NAME\\.jar!\\/\\2/ chrome.manifest |
127 | + sed -i -r s/^\(skin\|locale\)\(\\s+\\S*\\s+\\S*\\s+\)\(.*\\/\)$/\\1\\2jar:chrome\\/$APP_NAME\\.jar!\\/\\3/ chrome.manifest |
128 | + |
129 | + # (it simply adds jar:chrome/whatever.jar!/ at appropriate positions of chrome.manifest) |
130 | +fi |
131 | + |
132 | +# generate the XPI file |
133 | +echo "Generating $APP_NAME.xpi..." |
134 | +zip -r ../$APP_NAME.xpi * |
135 | + |
136 | +cd "$ROOT_DIR" |
137 | + |
138 | +echo "Cleanup..." |
139 | +if [ $CLEAN_UP = 0 ]; then |
140 | + # save the jar file |
141 | + mv $TMP_DIR/chrome/$APP_NAME.jar . |
142 | +else |
143 | + rm ./files |
144 | +fi |
145 | + |
146 | +# remove the working files |
147 | +rm -rf $TMP_DIR |
148 | +echo "Done!" |
149 | + |
150 | +$AFTER_BUILD |
151 | |
152 | === removed directory 'chrome' |
153 | === modified file 'chrome.manifest' |
154 | --- chrome.manifest 2009-07-02 13:41:07 +0000 |
155 | +++ chrome.manifest 2009-07-14 14:09:22 +0000 |
156 | @@ -1,3 +1,3 @@ |
157 | -content bindwood chrome/content/ |
158 | -locale bindwood en chrome/locale/en/ |
159 | +content bindwood content/ |
160 | +locale bindwood en locale/en/ |
161 | overlay chrome://browser/content/browser.xul chrome://bindwood/content/browserOverlay.xul |
162 | |
163 | === added file 'config_build.sh' |
164 | --- config_build.sh 1970-01-01 00:00:00 +0000 |
165 | +++ config_build.sh 2009-07-14 19:27:48 +0000 |
166 | @@ -0,0 +1,9 @@ |
167 | +#!/bin/bash |
168 | +# Build config for build.sh |
169 | +APP_NAME=bindwood |
170 | +CHROME_PROVIDERS="content locale" |
171 | +CLEAN_UP=1 |
172 | +ROOT_FILES="dbus.sh" |
173 | +ROOT_DIRS="defaults" |
174 | +BEFORE_BUILD= |
175 | +AFTER_BUILD= |
176 | |
177 | === renamed directory 'chrome/content' => 'content' |
178 | === modified file 'content/sync.js' |
179 | --- chrome/content/sync.js 2009-07-09 13:32:21 +0000 |
180 | +++ content/sync.js 2009-07-14 19:27:48 +0000 |
181 | @@ -20,8 +20,8 @@ |
182 | return Bindwood.uuidService.generateUUID().toString(); |
183 | }, |
184 | |
185 | - annotateItemWithUUID: function(itemId) { |
186 | - var uuid = Bindwood.generateUUIDString(); |
187 | + annotateItemWithUUID: function(itemId, uuid) { |
188 | + var uuid = uuid ? uuid : Bindwood.generateUUIDString(); |
189 | Bindwood.annotationService.setItemAnnotation(itemId, Bindwood.annotationKey, uuid, 0, Bindwood.annotationService.EXPIRE_NEVER); |
190 | // Whenever we create a new UUID, stash it and the itemId in |
191 | // our local cache. |
192 | @@ -55,7 +55,7 @@ |
193 | uuid = Bindwood.annotationService.getItemAnnotation(itemId, Bindwood.annotationKey); |
194 | found = true; |
195 | } catch(e) { |
196 | - uuid = Bindwood.annotateItemWithUUID(itemId); |
197 | + uuid = Bindwood.annotateItemWithUUID(itemId, null); |
198 | } |
199 | |
200 | return uuid; |
201 | @@ -80,6 +80,7 @@ |
202 | if(Components.classes["@mozilla.org/appshell/window-mediator;1"] |
203 | .getService(Components.interfaces.nsIWindowMediator) |
204 | .getEnumerator("").getNext() == window) { |
205 | + Bindwood.writeMessage("Getting a Couch Port"); |
206 | Bindwood.getCouchPortNumber(Bindwood.startProcess); |
207 | } |
208 | }, |
209 | @@ -105,8 +106,8 @@ |
210 | var MY_ID = "bindwood@ubuntu.com"; |
211 | var em = Components.classes["@mozilla.org/extensions/manager;1"]. |
212 | getService(Components.interfaces.nsIExtensionManager); |
213 | - var dbus_script = em.getInstallLocation(MY_ID).getItemFile(MY_ID, |
214 | - "chrome/content/dbus.sh"); |
215 | + var dbus_script = em.getInstallLocation(MY_ID).getItemFile(MY_ID, "dbus.sh"); |
216 | + Bindwood.writeMessage("Found path to dbus_script: " + dbus_script.path); |
217 | // create an nsILocalFile for the executable |
218 | var nsifile = Components.classes["@mozilla.org/file/local;1"] |
219 | .createInstance(Components.interfaces.nsILocalFile); |
220 | @@ -312,7 +313,7 @@ |
221 | } |
222 | }); |
223 | } catch(e) { |
224 | - Bindwood.writeError("Problem fetching all bookmarks from Couch:", e); |
225 | + Bindwood.writeError("Problem fetching all bookmarks from Couch: ", e); |
226 | } |
227 | for (var i = 0; i < rows.rows.length; i++) { |
228 | var recordid = rows.rows[i].id; |
229 | @@ -322,8 +323,9 @@ |
230 | bm.application_annotations.Firefox.uuid) { |
231 | // this bookmark has a uuid, so check its values haven't changed |
232 | // find the bookmark with this uuid |
233 | - var itemId = Bindwood.itemIdForUUID( |
234 | - bm.application_annotations.Firefox.uuid); |
235 | + var couch_uuid = bm.application_annotations.Firefox.uuid; |
236 | + Bindwood.writeMessage("Row uuid: " + couch_uuid); |
237 | + var itemId = Bindwood.itemIdForUUID(couch_uuid); |
238 | if (!itemId) { |
239 | // This bookmark has a uuid, but it's not one of ours. |
240 | // We need to work out whether (a) it's the same as one |
241 | @@ -331,67 +333,101 @@ |
242 | // make the uuids the same), or (b) it's a new one |
243 | // that happens to have been created on a different |
244 | // machine. |
245 | - // For the moment, punt on this. |
246 | + try { |
247 | + var uri = Bindwood.ioService.newURI(bm.uri, null, null); |
248 | + } catch(e) { |
249 | + Bindwood.writeError("Problem creating URI (" + bm.uri + ") for bookmark: ", e); |
250 | + continue; |
251 | + } |
252 | + var ids = Bindwood.bookmarksService.getBookmarkIdsForURI(uri, {}); |
253 | + if (ids.length > 1) { |
254 | + // punt for now, too many problems. |
255 | + } else if (ids.length) { |
256 | + // Found one local bookmark. Replace its uuid to |
257 | + // be the one from Couch. |
258 | + var itemId = ids[0]; |
259 | + var old_uuid = Bindwood.uuidForItemId(itemId); |
260 | + delete Bindwood.uuidItemIdMap[old_uuid]; |
261 | + Bindwood.annotateItemWithUUID(itemId, couch_uuid); |
262 | + } else { |
263 | + /// No local bookmarks |
264 | + Bindwood.addLocalBookmark(bm, recordid, couch_uuid); |
265 | + } |
266 | } else { |
267 | - var title = Bindwood.bookmarksService.getItemTitle(itemId); |
268 | - var metadata = Bindwood.bookmarksService.getBookmarkURI(itemId); |
269 | - if (title != bm.title) { |
270 | - Bindwood.bookmarksService.setItemTitle(itemId, bm.title); |
271 | - } |
272 | - if (metadata.spec != bm.uri) { |
273 | - try { |
274 | - metadata = Bindwood.ioService.newURI(bm.uri, null, null); |
275 | - } catch(e) { |
276 | - Bindwood.writeError("Problem creating a new URI for bookmark", e); |
277 | - } |
278 | - Bindwood.bookmarksService.changeBookmarkURI(itemId, metadata); |
279 | + if (bm.deleted) { |
280 | + // This bookmark exists on Couch, but has been |
281 | + // flagged for deletion by another Client. We |
282 | + // want to respect that, and delete it |
283 | + // locally. |
284 | + Bindwood.bookmarksService.removeItem(itemId); |
285 | + } else { |
286 | + var title = Bindwood.bookmarksService.getItemTitle(itemId); |
287 | + var metadata = Bindwood.bookmarksService.getBookmarkURI(itemId); |
288 | + if (title != bm.title) { |
289 | + Bindwood.bookmarksService.setItemTitle(itemId, bm.title); |
290 | + } |
291 | + if (metadata.spec != bm.uri) { |
292 | + try { |
293 | + metadata = Bindwood.ioService.newURI(bm.uri, null, null); |
294 | + Bindwood.bookmarksService.changeBookmarkURI(itemId, metadata); |
295 | + } catch(e) { |
296 | + Bindwood.writeError("Problem creating a new URI for bookmark: ", e); |
297 | + } |
298 | + } |
299 | } |
300 | } |
301 | } else { |
302 | - // this bookmark has no uuid, so create it from fresh in Firefox |
303 | - var list; |
304 | - if (bm.application_annotations && |
305 | - bm.application_annotations.Firefox && |
306 | - bm.application_annotations.Firefox.list) { |
307 | - switch (bm.application_annotations.Firefox.list) { |
308 | - case "toolbarFolder": |
309 | - list = Bindwood.bookmarksService.toolbarFolder; |
310 | - break; |
311 | - case "bookmarksMenuFolder": |
312 | - list = Bindwood.bookmarksService.bookmarksMenuFolder; |
313 | - break; |
314 | - default: |
315 | - list = Bindwood.bookmarksService.toolbarFolder; |
316 | - break; |
317 | - } |
318 | - } else { |
319 | - list = Bindwood.bookmarksService.toolbarFolder; |
320 | - } |
321 | - var metadata = Bindwood.ioService.newURI(bm.uri, null, null); |
322 | - |
323 | - var itemId = Bindwood.bookmarksService.insertBookmark(list, |
324 | - metadata, -1, bm.title); |
325 | - // and then write the new uuid back to the record |
326 | - var uuid = Bindwood.uuidForItemId(itemId); |
327 | - var doc = couch.open(recordid); |
328 | - if (!doc.application_annotations) { |
329 | - doc.application_annotations = {}; |
330 | - } |
331 | - if (!doc.application_annotations.Firefox) { |
332 | - doc.application_annotations.Firefox = {}; |
333 | - } |
334 | - doc.application_annotations.Firefox.uuid = uuid; |
335 | - try { |
336 | - couch.save(doc); |
337 | - } catch(e) { |
338 | - Bindwood.writeError("Problem writing record for new bookmark: ",e); |
339 | - } |
340 | + // This bookmark has no uuid, so create it from fresh |
341 | + // in Firefox. Passing in null to addLocalBookmar will |
342 | + // generate a new uuid. |
343 | + Bindwood.addLocalBookmark(bm, recordid, null); |
344 | } |
345 | } |
346 | // reschedule ourself |
347 | setTimeout(Bindwood.pullBookmarks, 30000); |
348 | }, |
349 | |
350 | + addLocalBookmark: function(bm, recordid, uuid) { |
351 | + var couch = new CouchDB('bookmarks'); |
352 | + var list; |
353 | + if (bm.application_annotations && |
354 | + bm.application_annotations.Firefox && |
355 | + bm.application_annotations.Firefox.list) { |
356 | + switch (bm.application_annotations.Firefox.list) { |
357 | + case "toolbarFolder": |
358 | + list = Bindwood.bookmarksService.toolbarFolder; |
359 | + break; |
360 | + case "bookmarksMenuFolder": |
361 | + list = Bindwood.bookmarksService.bookmarksMenuFolder; |
362 | + break; |
363 | + default: |
364 | + list = Bindwood.bookmarksService.toolbarFolder; |
365 | + break; |
366 | + } |
367 | + } else { |
368 | + list = Bindwood.bookmarksService.toolbarFolder; |
369 | + } |
370 | + var metadata = Bindwood.ioService.newURI(bm.uri, null, null); |
371 | + |
372 | + var itemId = Bindwood.bookmarksService.insertBookmark(list, |
373 | + metadata, -1, bm.title); |
374 | + // and then write the new uuid back to the record |
375 | + var uuid = uuid ? uuid : Bindwood.uuidForItemId(itemId); |
376 | + var doc = couch.open(recordid); |
377 | + if (!doc.application_annotations) { |
378 | + doc.application_annotations = {}; |
379 | + } |
380 | + if (!doc.application_annotations.Firefox) { |
381 | + doc.application_annotations.Firefox = {}; |
382 | + } |
383 | + doc.application_annotations.Firefox.uuid = uuid; |
384 | + try { |
385 | + couch.save(doc); |
386 | + } catch(e) { |
387 | + Bindwood.writeError("Problem writing record for new bookmark: ",e); |
388 | + } |
389 | + }, |
390 | + |
391 | Observer: { |
392 | // An nsINavBookmarkObserver |
393 | onItemAdded: function(aItemId, aFolder, aIndex) { |
394 | @@ -429,7 +465,7 @@ |
395 | try { |
396 | var result = couch.save(doc); |
397 | } catch(e) { |
398 | - Bindwood.writeError("Problem saving new bookmark to Couch", e); |
399 | + Bindwood.writeError("Problem saving new bookmark to Couch: ", e); |
400 | } |
401 | }, |
402 | onBeforeItemRemoved: function(aItemId) { |
403 | @@ -458,14 +494,17 @@ |
404 | } |
405 | |
406 | var doc = couch.open(results.rows[0].id); |
407 | + // Update the doc in Couch to inform other clients that it |
408 | + // should be deleted locally. |
409 | + doc.deleted = true; |
410 | |
411 | try { |
412 | - var result = couch.deleteDoc(doc); |
413 | + var result = couch.save(doc); |
414 | // Also remove from our local cache and remove |
415 | // annotation from service. |
416 | delete Bindwood.uuidItemIdMap[uuid]; |
417 | } catch(e) { |
418 | - Bindwood.writeError("Problem deleting record from Couch", e); |
419 | + Bindwood.writeError("Problem pushing deleted record to Couch: ", e); |
420 | } |
421 | }, |
422 | onItemRemoved: function(aItemId, aFolder, aIndex) { |
423 | @@ -502,7 +541,7 @@ |
424 | try { |
425 | var result = couch.save(doc); |
426 | } catch(e) { |
427 | - Bindwood.writeError("Problem saving updated bookmark to Couch", e); |
428 | + Bindwood.writeError("Problem saving updated bookmark to Couch: ", e); |
429 | } |
430 | }, |
431 | |
432 | |
433 | === renamed file 'chrome/content/dbus.sh' => 'dbus.sh' |
434 | === modified file 'install.rdf' |
435 | --- install.rdf 2009-07-06 20:00:16 +0000 |
436 | +++ install.rdf 2009-07-14 19:27:48 +0000 |
437 | @@ -12,8 +12,8 @@ |
438 | <em:targetApplication> |
439 | <Description> |
440 | <em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id> |
441 | - <em:minVersion>3.0</em:minVersion> |
442 | - <em:maxVersion>3.*</em:maxVersion> |
443 | + <em:minVersion>3.5</em:minVersion> |
444 | + <em:maxVersion>3.5.*</em:maxVersion> |
445 | </Description> |
446 | </em:targetApplication> |
447 | |
448 | @@ -21,6 +21,6 @@ |
449 | <em:name>Bindwood</em:name> |
450 | <em:description>An extension to synchronize your bookmarks to a local CouchDB.</em:description> |
451 | <em:creator>Zachery Bir</em:creator> |
452 | - <em:homepageURL>http://launchpad.net/bindwood</em:homepageURL> |
453 | + <em:homepageURL>https://launchpad.net/bindwood</em:homepageURL> |
454 | </Description> |
455 | </RDF> |
456 | |
457 | === renamed directory 'chrome/locale' => 'locale' |
Added back some debug information and moved the dbus.sh script out to top-level.
One of the things lp:~sil and I talked about was setting some sort of flag to spilling the beans in debugging. Now that we're moving towards a Makefile approach, I think it might be nice to be able to specify a debug build that includes all the messages, and leave them all in the code.