-rw-r--r-- | content/Makefile.am | 2 | ||||
-rw-r--r-- | content/fireflix-panel.xul | 1 | ||||
-rw-r--r-- | content/flickr.js | 50 | ||||
-rw-r--r-- | content/util.js | 61 |
4 files changed, 63 insertions, 51 deletions
diff --git a/content/Makefile.am b/content/Makefile.am index 8548400..d8607fb 100644 --- a/content/Makefile.am +++ b/content/Makefile.am | |||
@@ -1,22 +1,22 @@ | |||
1 | xpichromecontent_DATA = \ | 1 | xpichromecontent_DATA = \ |
2 | autoconf.dtd \ | 2 | autoconf.dtd \ |
3 | browser.xul about.xul fireflix-panel.xul photoset-props.xul \ | 3 | browser.xul about.xul fireflix-panel.xul photoset-props.xul \ |
4 | generated-content.xul \ | 4 | generated-content.xul \ |
5 | photoset-props.js fireflix.js flickr.js md5.js \ | 5 | photoset-props.js fireflix.js flickr.js util.js md5.js \ |
6 | generated-content.js \ | 6 | generated-content.js \ |
7 | fireflix.css \ | 7 | fireflix.css \ |
8 | background.jpeg | 8 | background.jpeg |
9 | 9 | ||
10 | sized_icons = \ | 10 | sized_icons = \ |
11 | $(addsuffix .png, \ | 11 | $(addsuffix .png, \ |
12 | fireflix \ | 12 | fireflix \ |
13 | ) | 13 | ) |
14 | 14 | ||
15 | nobase_xpichromecontent_DATA = \ | 15 | nobase_xpichromecontent_DATA = \ |
16 | $(addprefix icons/, \ | 16 | $(addprefix icons/, \ |
17 | $(addprefix 16x16/,${sized_icons}) \ | 17 | $(addprefix 16x16/,${sized_icons}) \ |
18 | $(addprefix 32x32/,${sized_icons}) \ | 18 | $(addprefix 32x32/,${sized_icons}) \ |
19 | ) | 19 | ) |
20 | 20 | ||
21 | EXTRA_DIST = \ | 21 | EXTRA_DIST = \ |
22 | ${xpichromecontent_DATA} ${nobase_xpichromecontent_DATA} | 22 | ${xpichromecontent_DATA} ${nobase_xpichromecontent_DATA} |
diff --git a/content/fireflix-panel.xul b/content/fireflix-panel.xul index 569beb0..2a15a51 100644 --- a/content/fireflix-panel.xul +++ b/content/fireflix-panel.xul | |||
@@ -1,64 +1,65 @@ | |||
1 | <?xml version="1.0"?> | 1 | <?xml version="1.0"?> |
2 | <?xml-stylesheet href="chrome://global/skin/" type="text/css"?> | 2 | <?xml-stylesheet href="chrome://global/skin/" type="text/css"?> |
3 | <?xml-stylesheet href="fireflix.css" type="text/css"?> | 3 | <?xml-stylesheet href="fireflix.css" type="text/css"?> |
4 | <!DOCTYPE page SYSTEM "chrome://fireflix/locale/fireflix.dtd"> | 4 | <!DOCTYPE page SYSTEM "chrome://fireflix/locale/fireflix.dtd"> |
5 | <page | 5 | <page |
6 | xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" | 6 | xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" |
7 | id="fireflixwindow" title="Fireflix" | 7 | id="fireflixwindow" title="Fireflix" |
8 | onload="fireflix.init()" | 8 | onload="fireflix.init()" |
9 | orient="vertical" | 9 | orient="vertical" |
10 | ondragover="nsDragAndDrop.dragOver(event,fireflix.uploadObserver)" | 10 | ondragover="nsDragAndDrop.dragOver(event,fireflix.uploadObserver)" |
11 | ondragdrop="nsDragAndDrop.drop(event,fireflix.uploadObserver)" | 11 | ondragdrop="nsDragAndDrop.drop(event,fireflix.uploadObserver)" |
12 | > | 12 | > |
13 | 13 | ||
14 | <script src="chrome://global/content/nsDragAndDrop.js"/> | 14 | <script src="chrome://global/content/nsDragAndDrop.js"/> |
15 | <script src="chrome://global/content/nsTransferable.js"/> | 15 | <script src="chrome://global/content/nsTransferable.js"/> |
16 | <script type="application/x-javascript" src="md5.js" /> | 16 | <script type="application/x-javascript" src="md5.js" /> |
17 | <script type="application/x-javascript" src="util.js" /> | ||
17 | <script type="application/x-javascript" src="flickr.js" /> | 18 | <script type="application/x-javascript" src="flickr.js" /> |
18 | <script type="application/x-javascript" src="fireflix.js" /> | 19 | <script type="application/x-javascript" src="fireflix.js" /> |
19 | 20 | ||
20 | <stringbundleset> | 21 | <stringbundleset> |
21 | <stringbundle id="loc_strings" src="chrome://fireflix/locale/fireflix.properties" /> | 22 | <stringbundle id="loc_strings" src="chrome://fireflix/locale/fireflix.properties" /> |
22 | </stringbundleset> | 23 | </stringbundleset> |
23 | 24 | ||
24 | <commandset> | 25 | <commandset> |
25 | <command id="cmd_auth_auth" label="&panel.auth.auth.label;" | 26 | <command id="cmd_auth_auth" label="&panel.auth.auth.label;" |
26 | oncommand="fireflix.on_cmd_auth()"/> | 27 | oncommand="fireflix.on_cmd_auth()"/> |
27 | <command id="cmd_auth_done" label="&panel.auth.done.label;" | 28 | <command id="cmd_auth_done" label="&panel.auth.done.label;" |
28 | oncommand="fireflix.on_cmd_auth_done()" disabled="true"/> | 29 | oncommand="fireflix.on_cmd_auth_done()" disabled="true"/> |
29 | <command id="cmd_auth_open_flickr" label="&panel.auth.flickr.label;" | 30 | <command id="cmd_auth_open_flickr" label="&panel.auth.flickr.label;" |
30 | oncommand="fireflix.openTab('htp://www.flickr.com/')" /> | 31 | oncommand="fireflix.openTab('htp://www.flickr.com/')" /> |
31 | <command id="cmd_auth_unauth" label="&panel.auth.unauth.label;" | 32 | <command id="cmd_auth_unauth" label="&panel.auth.unauth.label;" |
32 | oncommand="fireflix.on_cmd_auth_unauth()" /> | 33 | oncommand="fireflix.on_cmd_auth_unauth()" /> |
33 | </commandset> | 34 | </commandset> |
34 | 35 | ||
35 | <popupset> | 36 | <popupset> |
36 | <popup id="auth_menu"> | 37 | <popup id="auth_menu"> |
37 | <menuitem command="cmd_auth_auth"/> | 38 | <menuitem command="cmd_auth_auth"/> |
38 | <menuitem command="cmd_auth_done" hidden="true" id="menu_auth_done"/> | 39 | <menuitem command="cmd_auth_done" hidden="true" id="menu_auth_done"/> |
39 | <menuitem command="cmd_auth_unauth" /> | 40 | <menuitem command="cmd_auth_unauth" /> |
40 | <menuseparator/> | 41 | <menuseparator/> |
41 | <menuitem command="cmd_auth_open_flickr"/> | 42 | <menuitem command="cmd_auth_open_flickr"/> |
42 | </popup> | 43 | </popup> |
43 | </popupset> | 44 | </popupset> |
44 | 45 | ||
45 | <commandset id="cmdset_search"> | 46 | <commandset id="cmdset_search"> |
46 | <command id="cmd_search" label="&panel.search.cmd_search.label;" | 47 | <command id="cmd_search" label="&panel.search.cmd_search.label;" |
47 | oncommand="fireflix.foundphotos.search_photos()"/> | 48 | oncommand="fireflix.foundphotos.search_photos()"/> |
48 | <command id="cmd_search_open" label="&panel.search.cmd_search_open.label;" | 49 | <command id="cmd_search_open" label="&panel.search.cmd_search_open.label;" |
49 | oncommand="fireflix.foundphotos.on_cmd_open(event)" /> | 50 | oncommand="fireflix.foundphotos.on_cmd_open(event)" /> |
50 | </commandset> | 51 | </commandset> |
51 | 52 | ||
52 | <commandset id="cmdset_sets"> | 53 | <commandset id="cmdset_sets"> |
53 | <command id="cmd_refresh_sets" label="&panel.sets.cmd_refresh_sets;" | 54 | <command id="cmd_refresh_sets" label="&panel.sets.cmd_refresh_sets;" |
54 | oncommand="fireflix.on_refresh_sets()" /> | 55 | oncommand="fireflix.on_refresh_sets()" /> |
55 | <command id="cmd_set_props" label="&panel.sets.cmd_properties;" | 56 | <command id="cmd_set_props" label="&panel.sets.cmd_properties;" |
56 | oncommand="fireflix.on_set_props()" disabled="true" /> | 57 | oncommand="fireflix.on_set_props()" disabled="true" /> |
57 | </commandset> | 58 | </commandset> |
58 | 59 | ||
59 | <popupset> | 60 | <popupset> |
60 | <popup id="sets_menu"> | 61 | <popup id="sets_menu"> |
61 | <menuitem command="cmd_set_props"/> | 62 | <menuitem command="cmd_set_props"/> |
62 | <menuitem command="cmd_refresh_sets"/> | 63 | <menuitem command="cmd_refresh_sets"/> |
63 | <menuseparator/> | 64 | <menuseparator/> |
64 | <menu label="&panel.sets.generate_html;" id="sets_html_menu"/> | 65 | <menu label="&panel.sets.generate_html;" id="sets_html_menu"/> |
diff --git a/content/flickr.js b/content/flickr.js index 3554796..add628a 100644 --- a/content/flickr.js +++ b/content/flickr.js | |||
@@ -44,146 +44,96 @@ Photo.prototype = { | |||
44 | isprimary: null, | 44 | isprimary: null, |
45 | license: null, | 45 | license: null, |
46 | dateupload: null, datetaken: null, datetakengranularity: null, | 46 | dateupload: null, datetaken: null, datetakengranularity: null, |
47 | ownername: null, | 47 | ownername: null, |
48 | iconserver: null, | 48 | iconserver: null, |
49 | originalformat: null, | 49 | originalformat: null, |
50 | lastupdate: null, | 50 | lastupdate: null, |
51 | fromNode: function(n) { | 51 | fromNode: function(n) { |
52 | this.id = n.getAttribute('id'); this.secret = n.getAttribute('secret'); | 52 | this.id = n.getAttribute('id'); this.secret = n.getAttribute('secret'); |
53 | this.server = n.getAttribute('server'); | 53 | this.server = n.getAttribute('server'); |
54 | this.title = n.getAttribute('title'); | 54 | this.title = n.getAttribute('title'); |
55 | this.isprimary = n.getAttribute('isprimary'); | 55 | this.isprimary = n.getAttribute('isprimary'); |
56 | this.license = n.getAttribute('license'); | 56 | this.license = n.getAttribute('license'); |
57 | this.dateupload = n.getAttribute('dateupload'); | 57 | this.dateupload = n.getAttribute('dateupload'); |
58 | this.datetaken = n.getAttribute('datetaken'); this.datetakengranularity = n.getAttribute('datetakengranularity'); | 58 | this.datetaken = n.getAttribute('datetaken'); this.datetakengranularity = n.getAttribute('datetakengranularity'); |
59 | this.ownername = n.getAttribute('ownername'); | 59 | this.ownername = n.getAttribute('ownername'); |
60 | this.iconserver = n.getAttribute('iconserver'); | 60 | this.iconserver = n.getAttribute('iconserver'); |
61 | this.originalformat = n.getAttribute('originalformat'); | 61 | this.originalformat = n.getAttribute('originalformat'); |
62 | this.lastupdate = n.getAttribute('lastupdate'); | 62 | this.lastupdate = n.getAttribute('lastupdate'); |
63 | }, | 63 | }, |
64 | fromNode_: function(n) { | 64 | fromNode_: function(n) { |
65 | var t; | 65 | var t; |
66 | // TODO: @rotation @isfavorite | 66 | // TODO: @rotation @isfavorite |
67 | this.owner = {}; | 67 | this.owner = {}; |
68 | t = n.getElementsByTagName('owner').item(0); | 68 | t = n.getElementsByTagName('owner').item(0); |
69 | if(t) { | 69 | if(t) { |
70 | this.owner.nsid=t.getAttribute('nsid'); | 70 | this.owner.nsid=t.getAttribute('nsid'); |
71 | this.owner.username=t.getAttribute('username'); | 71 | this.owner.username=t.getAttribute('username'); |
72 | this.owner.realname=t.getAttribute('realname'); | 72 | this.owner.realname=t.getAttribute('realname'); |
73 | this.owner.location=t.getAttribute.location; | 73 | this.owner.location=t.getAttribute.location; |
74 | } | 74 | } |
75 | t = n.getElementsByTagName('description').item(0); | 75 | t = n.getElementsByTagName('description').item(0); |
76 | if(t && t.firstChild) { | 76 | if(t && t.firstChild) { |
77 | this.description = t.firstChild.nodeValue; | 77 | this.description = t.firstChild.nodeValue; |
78 | } | 78 | } |
79 | // TODO: visibility/@ispublic visibility/@isfriend visibility/@isfamily | 79 | // TODO: visibility/@ispublic visibility/@isfriend visibility/@isfamily |
80 | // TODO: dates/@posted dates/@taken dates/@takengranularity dates/@lastupdate | 80 | // TODO: dates/@posted dates/@taken dates/@takengranularity dates/@lastupdate |
81 | // TODO: permissions/@permcomment permsiions/@permaddmeta | 81 | // TODO: permissions/@permcomment permsiions/@permaddmeta |
82 | // TODO: editability/@canaddcomment editability/@canaddmeta | 82 | // TODO: editability/@canaddcomment editability/@canaddmeta |
83 | // TODO: comments | 83 | // TODO: comments |
84 | // TODO: notes/note/@id notes/note/@author notes/note/@authorname | 84 | // TODO: notes/note/@id notes/note/@author notes/note/@authorname |
85 | // TODO: notes/note/@x notes/note/@y notes/note/@w notes/note/@h | 85 | // TODO: notes/note/@x notes/note/@y notes/note/@w notes/note/@h |
86 | // TODO: notes/note | 86 | // TODO: notes/note |
87 | // TODO: tags/tag/@id tags/tag/@author tags/tag/@raw tags/tag | 87 | // TODO: tags/tag/@id tags/tag/@author tags/tag/@raw tags/tag |
88 | // TODO: urls/url/@type urls/url | 88 | // TODO: urls/url/@type urls/url |
89 | } | 89 | } |
90 | }; | 90 | }; |
91 | 91 | ||
92 | function toutf8(ucode) { | ||
93 | var rv = ''; | ||
94 | for(var i=0;i<ucode.length;++i) { | ||
95 | var cc = ucode.charCodeAt(i); | ||
96 | if(cc<=0x7F) | ||
97 | rv += ucode.charAt(i); | ||
98 | else if(cc<=0x7ff) | ||
99 | rv += String.fromCharCode( | ||
100 | 0xc0|((cc>> 6)&0x1f), | ||
101 | 0x80|( cc &0x3f) ); | ||
102 | else if(cc<=0xffff) | ||
103 | rv += String.fromCharCode( | ||
104 | 0xe0|((cc>>12)&0x0f), | ||
105 | 0x80|((cc>> 6)&0x3f), | ||
106 | 0x80|( cc &0x3f) ); | ||
107 | else if(cc<=0x1fffff) | ||
108 | rv += String.fromCharCode( | ||
109 | 0xf0|((cc>>18)&0x07), | ||
110 | 0x80|((cc>>12)&0x3f), | ||
111 | 0x80|((cc>> 6)&0x3f), | ||
112 | 0x80|( cc &0x3f) ); | ||
113 | else if(cc<=0x03ffffff) | ||
114 | rv += String.fromCharCode( | ||
115 | 0xf8|((cc>>24)&0x03), | ||
116 | 0x80|((cc>>18)&0x3f), | ||
117 | 0x80|((cc>>12)&0x3f), | ||
118 | 0x80|((cc>> 6)&0x3f), | ||
119 | 0x80|( cc &0x3f) ); | ||
120 | else if(cc<=0x7fffffff) | ||
121 | rv += String.fromCharCode( | ||
122 | 0xfc|((cc>>30)&0x01), | ||
123 | 0x80|((cc>>24)&0x3f), | ||
124 | 0x80|((cc>>18)&0x3f), | ||
125 | 0x80|((cc>>12)&0x3f), | ||
126 | 0x80|((cc>> 6)&0x3f), | ||
127 | 0x80|( cc &0x3f) ); | ||
128 | } | ||
129 | return rv; | ||
130 | } | ||
131 | function xp_str(xp,x) { | ||
132 | var rv = x.evaluate( | ||
133 | xp, x, null, XPathResult.STRING_TYPE, null ); | ||
134 | return rv.stringValue; | ||
135 | } | ||
136 | function xp_node(xp,x) { | ||
137 | var rv = x.evaluate( | ||
138 | xp, x, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null ); | ||
139 | return rv.singleNodeValue; | ||
140 | } | ||
141 | |||
142 | function Flickr() { } | 92 | function Flickr() { } |
143 | Flickr.prototype = { | 93 | Flickr.prototype = { |
144 | 94 | ||
145 | rest_url: 'http://www.flickr.com/services/rest/', | 95 | rest_url: 'http://www.flickr.com/services/rest/', |
146 | auth_url: 'http://flickr.com/services/auth/', | 96 | auth_url: 'http://flickr.com/services/auth/', |
147 | photo_url: 'http://static.flickr.com/', | 97 | photo_url: 'http://static.flickr.com/', |
148 | photos_url: 'http://www.flickr.com/photos/', | 98 | photos_url: 'http://www.flickr.com/photos/', |
149 | upload_url: 'http://www.flickr.com/services/upload/', | 99 | upload_url: 'http://www.flickr.com/services/upload/', |
150 | 100 | ||
151 | api_sig: function(paramstr) { | 101 | api_sig: function(paramstr) { |
152 | return MD5(toutf8(this.api_shs+paramstr)); | 102 | return MD5(toutf8(this.api_shs+paramstr)); |
153 | }, | 103 | }, |
154 | api_call_url: function(params,url) { | 104 | api_call_url: function(params,url) { |
155 | params.api_key = this.api_key; | 105 | params.api_key = this.api_key; |
156 | var pp = new Array(); | 106 | var pp = new Array(); |
157 | for(var p in params) { | 107 | for(var p in params) { |
158 | pp.push(p); | 108 | pp.push(p); |
159 | } | 109 | } |
160 | var pstr = ''; | 110 | var pstr = ''; |
161 | var rv = (url?url:this.rest_url)+'?'; | 111 | var rv = (url?url:this.rest_url)+'?'; |
162 | for(var p in pp.sort()) { | 112 | for(var p in pp.sort()) { |
163 | var pn = pp[p]; | 113 | var pn = pp[p]; |
164 | pstr += pn+params[pn]; | 114 | pstr += pn+params[pn]; |
165 | rv += pn+'='+params[pn]+'&'; | 115 | rv += pn+'='+params[pn]+'&'; |
166 | } | 116 | } |
167 | rv += 'api_sig='+this.api_sig(pstr); | 117 | rv += 'api_sig='+this.api_sig(pstr); |
168 | return rv; | 118 | return rv; |
169 | }, | 119 | }, |
170 | api_call: function(params, on_success, on_failure) { | 120 | api_call: function(params, on_success, on_failure) { |
171 | if(params.auth_token == 'default') | 121 | if(params.auth_token == 'default') |
172 | params.auth_token = this.token; | 122 | params.auth_token = this.token; |
173 | var x = new XMLHttpRequest(); | 123 | var x = new XMLHttpRequest(); |
174 | x.open("GET",this.api_call_url(params)); | 124 | x.open("GET",this.api_call_url(params)); |
175 | x.onreadystatechange=function() { | 125 | x.onreadystatechange=function() { |
176 | if(x.readyState!=4) return false; | 126 | if(x.readyState!=4) return false; |
177 | if(x.status==200) { | 127 | if(x.status==200) { |
178 | var stat = x.responseXML.firstChild.getAttribute('stat'); | 128 | var stat = x.responseXML.firstChild.getAttribute('stat'); |
179 | if(stat=='ok') { | 129 | if(stat=='ok') { |
180 | if(on_success) on_success(x); | 130 | if(on_success) on_success(x); |
181 | }else{ | 131 | }else{ |
182 | var e = x.responseXML.getElementsByTagName('err').item(0); | 132 | var e = x.responseXML.getElementsByTagName('err').item(0); |
183 | var ecode = e.getAttribute('code'); | 133 | var ecode = e.getAttribute('code'); |
184 | var emsg = e.getAttribute('msg'); | 134 | var emsg = e.getAttribute('msg'); |
185 | dump(params.method+' failed: '+ecode+' '+emsg+'\n'); | 135 | dump(params.method+' failed: '+ecode+' '+emsg+'\n'); |
186 | if(on_failure) on_failure(x,stat,ecode,emsg); | 136 | if(on_failure) on_failure(x,stat,ecode,emsg); |
187 | } | 137 | } |
188 | }else{ | 138 | }else{ |
189 | if(on_failure) on_failure(x); | 139 | if(on_failure) on_failure(x); |
diff --git a/content/util.js b/content/util.js new file mode 100644 index 0000000..5af0978 --- a/dev/null +++ b/content/util.js | |||
@@ -0,0 +1,61 @@ | |||
1 | /* | ||
2 | * convert unicode string to utf-8 representation. | ||
3 | * needed for correct md5 hash calculation. | ||
4 | */ | ||
5 | function toutf8(ucode) { | ||
6 | var rv = ''; | ||
7 | for(var i=0;i<ucode.length;++i) { | ||
8 | var cc = ucode.charCodeAt(i); | ||
9 | if(cc<=0x7F) | ||
10 | rv += ucode.charAt(i); | ||
11 | else if(cc<=0x7ff) | ||
12 | rv += String.fromCharCode( | ||
13 | 0xc0|((cc>> 6)&0x1f), | ||
14 | 0x80|( cc &0x3f) ); | ||
15 | else if(cc<=0xffff) | ||
16 | rv += String.fromCharCode( | ||
17 | 0xe0|((cc>>12)&0x0f), | ||
18 | 0x80|((cc>> 6)&0x3f), | ||
19 | 0x80|( cc &0x3f) ); | ||
20 | else if(cc<=0x1fffff) | ||
21 | rv += String.fromCharCode( | ||
22 | 0xf0|((cc>>18)&0x07), | ||
23 | 0x80|((cc>>12)&0x3f), | ||
24 | 0x80|((cc>> 6)&0x3f), | ||
25 | 0x80|( cc &0x3f) ); | ||
26 | else if(cc<=0x03ffffff) | ||
27 | rv += String.fromCharCode( | ||
28 | 0xf8|((cc>>24)&0x03), | ||
29 | 0x80|((cc>>18)&0x3f), | ||
30 | 0x80|((cc>>12)&0x3f), | ||
31 | 0x80|((cc>> 6)&0x3f), | ||
32 | 0x80|( cc &0x3f) ); | ||
33 | else if(cc<=0x7fffffff) | ||
34 | rv += String.fromCharCode( | ||
35 | 0xfc|((cc>>30)&0x01), | ||
36 | 0x80|((cc>>24)&0x3f), | ||
37 | 0x80|((cc>>18)&0x3f), | ||
38 | 0x80|((cc>>12)&0x3f), | ||
39 | 0x80|((cc>> 6)&0x3f), | ||
40 | 0x80|( cc &0x3f) ); | ||
41 | } | ||
42 | return rv; | ||
43 | } | ||
44 | |||
45 | /* | ||
46 | * extract xpath-specified string value | ||
47 | */ | ||
48 | function xp_str(xp,x) { | ||
49 | var rv = x.evaluate( | ||
50 | xp, x, null, XPathResult.STRING_TYPE, null ); | ||
51 | return rv.stringValue; | ||
52 | } | ||
53 | /* | ||
54 | * extract xpath-specified node | ||
55 | */ | ||
56 | function xp_node(xp,x) { | ||
57 | var rv = x.evaluate( | ||
58 | xp, x, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null ); | ||
59 | return rv.singleNodeValue; | ||
60 | } | ||
61 | |||