summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--content/fireflix.js1
1 files changed, 1 insertions, 0 deletions
diff --git a/content/fireflix.js b/content/fireflix.js
index 2ee408f..24894df 100644
--- a/content/fireflix.js
+++ b/content/fireflix.js
@@ -1,326 +1,327 @@
1function splitascii(s) { 1function splitascii(s) {
2 var rv=''; 2 var rv='';
3 for(var i=0;i<s.length;++i) { 3 for(var i=0;i<s.length;++i) {
4 var w = s.charCodeAt(i); 4 var w = s.charCodeAt(i);
5 rv += String.fromCharCode( 5 rv += String.fromCharCode(
6 w&0xff, (w>>8)&0xff ); 6 w&0xff, (w>>8)&0xff );
7 } 7 }
8 return rv; 8 return rv;
9} 9}
10 10
11 11
12var fireflix = { 12var fireflix = {
13 flickr: new Flickr(), 13 flickr: new Flickr(),
14 init: function() { 14 init: function() {
15 pull_elements(this,document,[ 15 pull_elements(this,document,[
16 'cmd_auth_auth','cmd_auth_done','cmd_auth_unauth', 16 'cmd_auth_auth','cmd_auth_done','cmd_auth_unauth',
17 'menu_auth_done','b_auth','b_auth_done','auth_info', 17 'menu_auth_done','b_auth','b_auth_done','auth_info',
18 'loc_strings','cmd_set_props' 18 'loc_strings','cmd_set_props'
19 ]); 19 ]);
20 this.build_menus(); 20 this.build_menus();
21 this.foundphotos.init(this); 21 this.foundphotos.init(this);
22 this.photosets.init(this); 22 this.photosets.init(this);
23 this.photoset.init(this); 23 this.photoset.init(this);
24 this.uploads.init(this); 24 this.uploads.init(this);
25 this.uploadObserver.init(this); 25 this.uploadObserver.init(this);
26 this.flickr.api_key = '9c43cd66947a57e6f29db1a9da3f72e3'; 26 this.flickr.api_key = '9c43cd66947a57e6f29db1a9da3f72e3';
27 this.flickr.api_shs = '9c33c9e2f0f0cfd5'; 27 this.flickr.api_shs = '9c33c9e2f0f0cfd5';
28 this.flickr.prefs_root = 'net.klever.kin.fireflix'; 28 this.flickr.prefs_root = 'net.klever.kin.fireflix';
29 this.flickr.load_token(); 29 this.flickr.load_token();
30 this.no_auth_info_label = this.auth_info.value; 30 this.no_auth_info_label = this.auth_info.value;
31 this.set_auth_state(this.flickr.token,false); 31 this.set_auth_state(this.flickr.token,false);
32 if(this.flickr.token) { 32 if(this.flickr.token) {
33 this.refresh_stuff(); 33 this.refresh_stuff();
34 }else{ 34 }else{
35 this.on_cmd_auth(); 35 this.on_cmd_auth();
36 } 36 }
37 }, 37 },
38 set_auth_state: function(au,inp) { /* authorized, in progress */ 38 set_auth_state: function(au,inp) { /* authorized, in progress */
39 this.cmd_auth_unauth.disabled = !au; 39 this.cmd_auth_unauth.disabled = !au;
40 this.b_auth.hidden = au || inp; 40 this.b_auth.hidden = au || inp;
41 this.b_auth_done.hidden = !inp; 41 this.b_auth_done.hidden = !inp;
42 this.menu_auth_done.hidden = !inp; 42 this.menu_auth_done.hidden = !inp;
43 this.cmd_auth_done.setAttribute('disabled',!inp); 43 this.cmd_auth_done.setAttribute('disabled',!inp);
44 this.auth_info.disabled = !au; 44 this.auth_info.disabled = !au;
45 if(au) { 45 if(au) {
46 this.auth_info.value = this.flickr.user.fullname+' ['+this.flickr.user.username+']'; /* TODO: move to locale */ 46 this.auth_info.value = this.flickr.user.fullname+' ['+this.flickr.user.username+']'; /* TODO: move to locale */
47 }else{ 47 }else{
48 this.auth_info.value = this.no_auth_info_label; 48 this.auth_info.value = this.no_auth_info_label;
49 } 49 }
50 }, 50 },
51 on_cmd_auth: function() { 51 on_cmd_auth: function() {
52 var _this = this; 52 var _this = this;
53 this.flickr.authorize_0( 53 this.flickr.authorize_0(
54 'delete', 54 'delete',
55 function(x,f,u) { 55 function(x,f,u) {
56 _this.openTab(u); 56 _this.openTab(u);
57 _this.set_auth_state(_this.flickr.token,true); 57 _this.set_auth_state(_this.flickr.token,true);
58 }, function(x,s,c,m) { 58 }, function(x,s,c,m) {
59 _this.flickr_failure(x,s,c,m); 59 _this.flickr_failure(x,s,c,m);
60 } 60 }
61 ); 61 );
62 }, 62 },
63 on_cmd_auth_done: function() { 63 on_cmd_auth_done: function() {
64 this.set_auth_state(this.flickr.token,false); 64 this.set_auth_state(this.flickr.token,false);
65 var _this = this; 65 var _this = this;
66 this.flickr.authorize_1( 66 this.flickr.authorize_1(
67 function() { 67 function() {
68 _this.flickr.save_token(); 68 _this.flickr.save_token();
69 _this.refresh_stuff(); 69 _this.refresh_stuff();
70 _this.set_auth_state(_this.flickr.token,false); 70 _this.set_auth_state(_this.flickr.token,false);
71 _this.auth_info.value = 71 _this.auth_info.value =
72 _this.flickr.user.fullname+' ['+_this.flickr.user.username+']'; 72 _this.flickr.user.fullname+' ['+_this.flickr.user.username+']';
73 }, function(x,s,c,m) { 73 }, function(x,s,c,m) {
74 _this.set_auth_state(_this.flickr.token,false); /* XXX: no reset token? */ 74 _this.set_auth_state(_this.flickr.token,false); /* XXX: no reset token? */
75 _this.flickr_failure(x,s,c,m); 75 _this.flickr_failure(x,s,c,m);
76 } 76 }
77 ); 77 );
78 }, 78 },
79 on_cmd_auth_unauth: function() { 79 on_cmd_auth_unauth: function() {
80 this.flickr.reset_token(); 80 this.flickr.reset_token();
81 this.set_auth_state(false,false); 81 this.set_auth_state(false,false);
82 }, 82 },
83 83
84 refresh_sets: function() { this.photosets.refresh_sets(); }, 84 refresh_sets: function() { this.photosets.refresh_sets(); },
85 refresh_stuff: function() { 85 refresh_stuff: function() {
86 this.refresh_sets(); 86 this.refresh_sets();
87 this.refresh_user_tags(); 87 this.refresh_user_tags();
88 }, 88 },
89 89
90 /* photoset treeview */ 90 /* photoset treeview */
91 photoset: { 91 photoset: {
92 photos: new Array(), 92 photos: new Array(),
93 fireflix: null, 93 fireflix: null,
94 init: function(f) { 94 init: function(f) {
95 this.fireflix = f; 95 this.fireflix = f;
96 pull_elements(this,document,[ 'set_photo' ]); 96 pull_elements(this,document,[ 'set_photo' ]);
97 document.getElementById('setphotos').view = this; 97 document.getElementById('setphotos').view = this;
98 }, 98 },
99 rowCount: 0, 99 rowCount: 0,
100 getCellText: function(r,c) { 100 getCellText: function(r,c) {
101 var p = this.photos[r]; 101 var p = this.photos[r];
102 if(c.id=='sp_title') return p.title; 102 if(c.id=='sp_title') return p.title;
103 if(c.id=='sp_taken') return p.datetaken; 103 if(c.id=='sp_taken') return p.datetaken;
104 if(c.id=='sp_upload') { 104 if(c.id=='sp_upload') {
105 var du = new Date(p.dateupload*1000); 105 var du = new Date(p.dateupload*1000);
106 var rv = du.getFullYear()+'-'+(du.getMonth()+1)+'-'+du.getDate() 106 var rv = du.getFullYear()+'-'+(du.getMonth()+1)+'-'+du.getDate()
107 +' '+ 107 +' '+
108 du.getHours()+':'+du.getMinutes()+':'+du.getSeconds(); 108 du.getHours()+':'+du.getMinutes()+':'+du.getSeconds();
109 return rv.replace(/(\D)(\d)(\D)/,'$10$2$3'); 109 return rv.replace(/(\D)(\d)(\D)/,'$10$2$3');
110 } 110 }
111 return c.id; 111 return c.id;
112 }, 112 },
113 setTree: function(t) { this.tree = t }, 113 setTree: function(t) { this.tree = t },
114 isContainer: function(r) { return false; }, 114 isContainer: function(r) { return false; },
115 isSeparator: function(r) { return false; }, 115 isSeparator: function(r) { return false; },
116 isSorted: function(r) { return false; }, 116 isSorted: function(r) { return false; },
117 getLevel: function(r) { return 0; }, 117 getLevel: function(r) { return 0; },
118 getImageSrc: function(r,c) { return null }, 118 getImageSrc: function(r,c) { return null },
119 getRowProperties: function(r,p) {}, 119 getRowProperties: function(r,p) {},
120 getCellProperties: function(cid,cel,p) {}, 120 getCellProperties: function(cid,cel,p) {},
121 getColumnProperties: function(cid,cel,p) { }, 121 getColumnProperties: function(cid,cel,p) { },
122 cycleHeader: function(cid,e) { }, 122 cycleHeader: function(cid,e) { },
123 getParentIndex: function(r) { return -1; }, 123 getParentIndex: function(r) { return -1; },
124 drop: function(r,o) { }, 124 drop: function(r,o) { },
125 canDropBeforeAfter: function(r,b) { return false }, 125 canDropBeforeAfter: function(r,b) { return false },
126 126
127 importXPR: function(xp) { 127 importXPR: function(xp) {
128 this.tree.beginUpdateBatch(); 128 this.tree.beginUpdateBatch();
129 this.photos = new Array(); 129 this.photos = new Array();
130 var n; while(n=xp.iterateNext()) { 130 var n; while(n=xp.iterateNext()) {
131 this.photos.push(new Photo(n)); 131 this.photos.push(new Photo(n));
132 } 132 }
133 this.rowCount = this.photos.length; 133 this.rowCount = this.photos.length;
134 this.tree.endUpdateBatch(); 134 this.tree.endUpdateBatch();
135 this.selection.clearSelection();
135 }, 136 },
136 load_photos: function(psid) { 137 load_photos: function(psid) {
137 var _this = this; 138 var _this = this;
138 this.fireflix.flickr.api_call( 139 this.fireflix.flickr.api_call(
139 { 140 {
140 method: 'flickr.photosets.getPhotos', 141 method: 'flickr.photosets.getPhotos',
141 auth_token: 'default', 142 auth_token: 'default',
142 photoset_id: psid, 143 photoset_id: psid,
143 extras: 'license,date_upload,date_taken,owner_name,icon_server,original_format,last_update' 144 extras: 'license,date_upload,date_taken,owner_name,icon_server,original_format,last_update'
144 }, function(xr) { 145 }, function(xr) {
145 var x = xr.responseXML; 146 var x = xr.responseXML;
146 var xp = x.evaluate( 147 var xp = x.evaluate(
147 '/rsp/photoset/photo', x, null, 148 '/rsp/photoset/photo', x, null,
148 XPathResult.ORDERED_NODE_ITERATOR_TYPE, null ); 149 XPathResult.ORDERED_NODE_ITERATOR_TYPE, null );
149 _this.importXPR(xp); 150 _this.importXPR(xp);
150 }, function(x,s,c,m) { 151 }, function(x,s,c,m) {
151 _this.fireflix.flickr_failure(x,s,c,m); 152 _this.fireflix.flickr_failure(x,s,c,m);
152 } 153 }
153 ); 154 );
154 }, 155 },
155 on_select: function() { 156 on_select: function() {
156 if(this.selection.count==1) { 157 if(this.selection.count==1) {
157 var p = this.photos[this.selection.currentIndex]; 158 var p = this.photos[this.selection.currentIndex];
158 this.set_photo.src = 159 this.set_photo.src =
159 this.fireflix.flickr.get_photo_url(p.server,p.id,p.secret,'t'); 160 this.fireflix.flickr.get_photo_url(p.server,p.id,p.secret,'t');
160 this.set_photo.hidden = false; 161 this.set_photo.hidden = false;
161 }else{ 162 }else{
162 this.set_photo.hidden = true; 163 this.set_photo.hidden = true;
163 } 164 }
164 }, 165 },
165 on_cmd_open: function(ev) { 166 on_cmd_open: function(ev) {
166 if(this.selection.currentIndex<0) 167 if(this.selection.currentIndex<0)
167 return; 168 return;
168 var p = this.photos[this.selection.currentIndex]; 169 var p = this.photos[this.selection.currentIndex];
169 if(!p.id) 170 if(!p.id)
170 return; 171 return;
171 this.fireflix.openTab(this.fireflix.flickr.make_photo_url(p,'p')); 172 this.fireflix.openTab(this.fireflix.flickr.make_photo_url(p,'p'));
172 } 173 }
173 }, 174 },
174 175
175 /* photosets treeview */ 176 /* photosets treeview */
176 photosets: { 177 photosets: {
177 sets: new Array(), 178 sets: new Array(),
178 fireflix: null, 179 fireflix: null,
179 init: function(f) { 180 init: function(f) {
180 this.fireflix = f; 181 this.fireflix = f;
181 document.getElementById('setslist').view = this; 182 document.getElementById('setslist').view = this;
182 }, 183 },
183 rowCount: 0, 184 rowCount: 0,
184 getCellText: function(r,c) { 185 getCellText: function(r,c) {
185 var s = this.sets[r]; 186 var s = this.sets[r];
186 if(c.id=='sl_name') return s.title; 187 if(c.id=='sl_name') return s.title;
187 if(c.id=='sl_photos') return s.photos; 188 if(c.id=='sl_photos') return s.photos;
188 return c.id; 189 return c.id;
189 }, 190 },
190 setTree: function(t) { this.tree = t }, 191 setTree: function(t) { this.tree = t },
191 isContainer: function(r) { return false; }, 192 isContainer: function(r) { return false; },
192 isSeparator: function(r) { return false; }, 193 isSeparator: function(r) { return false; },
193 isSorted: function() { return false; }, 194 isSorted: function() { return false; },
194 getLevel: function(r) { return 0; }, 195 getLevel: function(r) { return 0; },
195 getImageSrc: function(r,c) { return null }, 196 getImageSrc: function(r,c) { return null },
196 getRowProperties: function(r,p) {}, 197 getRowProperties: function(r,p) {},
197 getCellProperties: function(cid,cel,p) { }, 198 getCellProperties: function(cid,cel,p) { },
198 getColumnProperties: function(cid,cel,p) { }, 199 getColumnProperties: function(cid,cel,p) { },
199 cycleHeader: function(cid,e) { }, 200 cycleHeader: function(cid,e) { },
200 getParentIndex: function(r) { return -1; }, 201 getParentIndex: function(r) { return -1; },
201 drop: function(r,o) { }, 202 drop: function(r,o) { },
202 canDropBeforeAfter: function(r,b) { return false }, 203 canDropBeforeAfter: function(r,b) { return false },
203 204
204 importXPR: function(xp) { 205 importXPR: function(xp) {
205 this.tree.beginUpdateBatch(); 206 this.tree.beginUpdateBatch();
206 this.sets = new Array(); 207 this.sets = new Array();
207 var n; while(n=xp.iterateNext()) { 208 var n; while(n=xp.iterateNext()) {
208 this.sets.push(new Photoset(n)); 209 this.sets.push(new Photoset(n));
209 } 210 }
210 this.rowCount = this.sets.length; 211 this.rowCount = this.sets.length;
211 this.tree.endUpdateBatch(); 212 this.tree.endUpdateBatch();
212 }, 213 },
213 refresh_sets: function() { 214 refresh_sets: function() {
214 var _this = this; 215 var _this = this;
215 this.fireflix.flickr.api_call( 216 this.fireflix.flickr.api_call(
216 { 217 {
217 method: 'flickr.photosets.getList', 218 method: 'flickr.photosets.getList',
218 auth_token: 'default' 219 auth_token: 'default'
219 }, function(xr) { 220 }, function(xr) {
220 var x = xr.responseXML; 221 var x = xr.responseXML;
221 var xp = x.evaluate( 222 var xp = x.evaluate(
222 '/rsp/photosets/photoset', x, null, 223 '/rsp/photosets/photoset', x, null,
223 XPathResult.ORDERED_NODE_ITERATOR_TYPE, null ); 224 XPathResult.ORDERED_NODE_ITERATOR_TYPE, null );
224 _this.importXPR(xp); 225 _this.importXPR(xp);
225 }, function(x,s,c,m) { 226 }, function(x,s,c,m) {
226 _this.fireflix.flickr_failure(x,s,c,m); 227 _this.fireflix.flickr_failure(x,s,c,m);
227 } 228 }
228 ); 229 );
229 }, 230 },
230 on_select: function() { 231 on_select: function() {
231 if(this.selection.count==1) { 232 if(this.selection.count==1) {
232 this.fireflix.cmd_set_props.setAttribute('disabled','false'); 233 this.fireflix.cmd_set_props.setAttribute('disabled','false');
233 var s = this.sets[this.selection.currentIndex]; 234 var s = this.sets[this.selection.currentIndex];
234 this.fireflix.photoset.load_photos(s.id); 235 this.fireflix.photoset.load_photos(s.id);
235 }else{ 236 }else{
236 this.fireflix.cmd_set_props.setAttribute('disabled','true'); 237 this.fireflix.cmd_set_props.setAttribute('disabled','true');
237 } 238 }
238 } 239 }
239 }, 240 },
240 241
241 refresh_user_tags: function() { 242 refresh_user_tags: function() {
242 var lb = document.getElementById('tagslist'); 243 var lb = document.getElementById('tagslist');
243 var _this = this; 244 var _this = this;
244 this.flickr.api_call( 245 this.flickr.api_call(
245 { 246 {
246 method: 'flickr.tags.getListUser', 247 method: 'flickr.tags.getListUser',
247 auth_token: 'default', 248 auth_token: 'default',
248 }, function(xr) { 249 }, function(xr) {
249 var x = xr.responseXML; 250 var x = xr.responseXML;
250 var xp = x.evaluate( 251 var xp = x.evaluate(
251 '/rsp/who/tags/tag', x, null, 252 '/rsp/who/tags/tag', x, null,
252 XPathResult.ORDERED_NODE_ITERATOR_TYPE, null ); 253 XPathResult.ORDERED_NODE_ITERATOR_TYPE, null );
253 // TODO: clear list 254 // TODO: clear list
254 var n; while(n=xp.iterateNext()) { 255 var n; while(n=xp.iterateNext()) {
255 lb.appendItem(n.firstChild.nodeValue); 256 lb.appendItem(n.firstChild.nodeValue);
256 } 257 }
257 }, function(x,s,c,m) { 258 }, function(x,s,c,m) {
258 _this.flickr_failure(x,s,c,m); 259 _this.flickr_failure(x,s,c,m);
259 } 260 }
260 ); 261 );
261 }, 262 },
262 263
263 uploadObserver: { 264 uploadObserver: {
264 fireflix: null, 265 fireflix: null,
265 init: function(f) { 266 init: function(f) {
266 this.fireflix = f; 267 this.fireflix = f;
267 }, 268 },
268 getSupportedFlavours: function() { 269 getSupportedFlavours: function() {
269 var rv = new FlavourSet(); 270 var rv = new FlavourSet();
270 rv.appendFlavour('application/x-moz-file','nsIFile'); 271 rv.appendFlavour('application/x-moz-file','nsIFile');
271 rv.appendFlavour('application/x-moz-url'); 272 rv.appendFlavour('application/x-moz-url');
272 rv.appendFlavour('text/uri-list'); 273 rv.appendFlavour('text/uri-list');
273 rv.appendFlavour('text/unicode'); 274 rv.appendFlavour('text/unicode');
274 return rv; 275 return rv;
275 }, 276 },
276 canHandleMultipleItems: true, 277 canHandleMultipleItems: true,
277 onDragOver: function(ev,fl,sess) { 278 onDragOver: function(ev,fl,sess) {
278 return true; 279 return true;
279 }, 280 },
280 onDrop: function(ev,dd,s) { 281 onDrop: function(ev,dd,s) {
281 var ldf = null; 282 var ldf = null;
282 for(var i in dd.dataList) { 283 for(var i in dd.dataList) {
283 var di = dd.dataList[i]; 284 var di = dd.dataList[i];
284 var dif = di.first; 285 var dif = di.first;
285 if( 286 if(
286 ldf==null 287 ldf==null
287 || ldf.flavour.contentType!=dif.flavour.contentType 288 || ldf.flavour.contentType!=dif.flavour.contentType
288 || ldf.contentLength!=dif.contentLength 289 || ldf.contentLength!=dif.contentLength
289 || ldf.data!=dif.data ) 290 || ldf.data!=dif.data )
290 this.drop_item(ev,di,s); 291 this.drop_item(ev,di,s);
291 ldf = dif; 292 ldf = dif;
292 } 293 }
293 }, 294 },
294 drop_item: function(ev,di,s) { 295 drop_item: function(ev,di,s) {
295 var d = di.first; 296 var d = di.first;
296 switch(d.flavour.contentType) { 297 switch(d.flavour.contentType) {
297 case 'text/unicode': 298 case 'text/unicode':
298 this.drop_urilist(ev,d.data,s); 299 this.drop_urilist(ev,d.data,s);
299 break; 300 break;
300 case 'application/x-moz-file': 301 case 'application/x-moz-file':
301 this.fireflix.uploads.add(d.data.path); 302 this.fireflix.uploads.add(d.data.path);
302 document.getElementById('fireflix_tabs').selectedTab 303 document.getElementById('fireflix_tabs').selectedTab
303 = document.getElementById('tab_upload'); 304 = document.getElementById('tab_upload');
304 break; 305 break;
305 case 'text/uri-list': 306 case 'text/uri-list':
306 // is it ascii or could it be utf8? 307 // is it ascii or could it be utf8?
307 this.drop_urilist(ev,splitascii(d.data),s); 308 this.drop_urilist(ev,splitascii(d.data),s);
308 break; 309 break;
309 default: alert(d.flavour.contentType+':'+d.data); break; 310 default: alert(d.flavour.contentType+':'+d.data); break;
310 }; 311 };
311 }, 312 },
312 drop_urilist: function(ev,ul,s) { 313 drop_urilist: function(ev,ul,s) {
313 // TODO: check for being a file? 314 // TODO: check for being a file?
314 var us = decodeURIComponent(ul).split(/[\r\n]/); 315 var us = decodeURIComponent(ul).split(/[\r\n]/);
315 for(var ui in us) 316 for(var ui in us)
316 if(/\S/.test(us[ui])) 317 if(/\S/.test(us[ui]))
317 this.fireflix.uploads.add(us[ui]); 318 this.fireflix.uploads.add(us[ui]);
318 document.getElementById('fireflix_tabs').selectedTab 319 document.getElementById('fireflix_tabs').selectedTab
319 = document.getElementById('tab_upload'); 320 = document.getElementById('tab_upload');
320 } 321 }
321 }, 322 },
322 323
323 uploads: { 324 uploads: {
324 fireflix: null, 325 fireflix: null,
325 init: function(f) { 326 init: function(f) {
326 this.fireflix=f; 327 this.fireflix=f;